From 0b6560a60789a5a96400ec68ae73f9522b6d4c1f Mon Sep 17 00:00:00 2001 From: Aarush-wadhia Date: Wed, 11 Sep 2024 14:26:50 +0530 Subject: [PATCH 01/20] WIP: Private agent dialog --- vscode/media/command-deck/command-deck.js | 1 - vscode/media/onboarding/onboarding.js | 1 - vscode/src/providers/chat_view_provider.ts | 46 ++++++++----------- .../lib/components/CreateAgentDialog.svelte | 14 ++++-- .../lib/components/PrivateAgentDialog.svelte | 20 ++++++++ .../lib/components/icons/IconInternet.svelte | 28 +++++++++++ web/src/routes/+page.svelte | 8 ++++ 7 files changed, 86 insertions(+), 32 deletions(-) create mode 100644 web/src/lib/components/PrivateAgentDialog.svelte create mode 100644 web/src/lib/components/icons/IconInternet.svelte diff --git a/vscode/media/command-deck/command-deck.js b/vscode/media/command-deck/command-deck.js index 23feeec0..8ed0cd0b 100644 --- a/vscode/media/command-deck/command-deck.js +++ b/vscode/media/command-deck/command-deck.js @@ -133,7 +133,6 @@ class CommandDeck { this.ref.innerHTML = textContent.substring(0, atIndex) + textContent.substring(atIndex + 1); } if (option?.name.startsWith('@')) { - console.log('agents options', option?.metadata); activeAgentAttach.style = "color: #497BEF; !important"; agentName = option?.metadata.display_name; diff --git a/vscode/media/onboarding/onboarding.js b/vscode/media/onboarding/onboarding.js index 1b64c84c..138bf32c 100644 --- a/vscode/media/onboarding/onboarding.js +++ b/vscode/media/onboarding/onboarding.js @@ -1047,7 +1047,6 @@ function handleSubmit(event) { } else { matchingItems = getAgents().filter(item => { - console.log('name', item); return item.search?.toLowerCase().startsWith(query.toLowerCase()); }); } diff --git a/vscode/src/providers/chat_view_provider.ts b/vscode/src/providers/chat_view_provider.ts index 8776b72c..dc8eb504 100644 --- a/vscode/src/providers/chat_view_provider.ts +++ b/vscode/src/providers/chat_view_provider.ts @@ -174,7 +174,6 @@ export class FlutterGPTViewProvider implements vscode.WebviewViewProvider { // StorageManager.instance.deleteAgents(); webviewView.onDidChangeVisibility(() => { - console.log("webview", webviewView.visible); if (webviewView.visible && this._view) { this._view?.webview.postMessage({ type: "focusChatInput" }); } @@ -454,6 +453,7 @@ export class FlutterGPTViewProvider implements vscode.WebviewViewProvider { private: false, }; try { + console.log(JSON.stringify(data)); const modelResponse = await makeHttpRequest<{ response: string, references: Array }>({ url: "https://api.commanddash.dev/v2/ai/agent/answer", method: "post", @@ -468,19 +468,15 @@ export class FlutterGPTViewProvider implements vscode.WebviewViewProvider { value: this._publicConversationHistory, }); } catch (error) { - this._publicConversationHistory.push({ - [this._activeAgent]: { - role: "error", - text: - error instanceof Error - ? (error as Error).message - : (error as any).toString(), - }, - }); - this._view?.webview.postMessage({ - type: "displayMessages", - value: this._publicConversationHistory, - }); + // this._publicConversationHistory.push({ + // [this._activeAgent]: { + // role: "error", + // text: + // error instanceof Error + // ? (error as Error).message + // : (error as any).toString(), + // }, + // }); } finally { this?._view?.webview?.postMessage({ type: "hideLoadingIndicator" }); } @@ -730,19 +726,15 @@ export class FlutterGPTViewProvider implements vscode.WebviewViewProvider { } catch (error) { console.error(error); logError("command-deck-conversation-error", error); - this._publicConversationHistory.push({ - [this._activeAgent]: { - role: "error", - text: - error instanceof Error - ? (error as Error).message - : (error as any).toString(), - }, - }); - this._view?.webview.postMessage({ - type: "displayMessages", - value: this._publicConversationHistory, - }); + // this._publicConversationHistory.push({ + // [this._activeAgent]: { + // role: "error", + // text: + // error instanceof Error + // ? (error as Error).message + // : (error as any).toString(), + // }, + // }); } finally { this._view?.webview.postMessage({ type: "hideLoadingIndicator" }); this._view?.webview.postMessage({ diff --git a/web/src/lib/components/CreateAgentDialog.svelte b/web/src/lib/components/CreateAgentDialog.svelte index a709b2a1..6c5ed0b6 100644 --- a/web/src/lib/components/CreateAgentDialog.svelte +++ b/web/src/lib/components/CreateAgentDialog.svelte @@ -4,12 +4,13 @@ import { toastStore } from "$lib/stores/ToastStores"; import { ToastType } from "$lib/types/Toast"; import appInsights from "$lib/utils/appInsights"; - import IconClose from "~icons/carbon/close"; import CarbonGithub from "~icons/carbon/logo-github"; import { validateURL } from "$lib/utils/validateURL"; + import IconInternet from "$lib/components/icons/IconInternet.svelte"; export let showModal: boolean; export let onClose: () => void; + export let onPrivateAgent: () => void; let value: string = ""; let selectedPlatform: string = "github"; @@ -68,8 +69,9 @@

Create Agent with URL

-
@@ -118,6 +120,12 @@ > Submit +
{/if} diff --git a/web/src/lib/components/PrivateAgentDialog.svelte b/web/src/lib/components/PrivateAgentDialog.svelte new file mode 100644 index 00000000..cfb66422 --- /dev/null +++ b/web/src/lib/components/PrivateAgentDialog.svelte @@ -0,0 +1,20 @@ + + +{#if showPrivateModal} +
+ + + +
+{/if} diff --git a/web/src/lib/components/icons/IconInternet.svelte b/web/src/lib/components/icons/IconInternet.svelte new file mode 100644 index 00000000..c05abaac --- /dev/null +++ b/web/src/lib/components/icons/IconInternet.svelte @@ -0,0 +1,28 @@ + + + diff --git a/web/src/routes/+page.svelte b/web/src/routes/+page.svelte index 39253d42..369070f8 100644 --- a/web/src/routes/+page.svelte +++ b/web/src/routes/+page.svelte @@ -11,12 +11,14 @@ import { debounce } from "$lib/utils/debounce"; import { base } from "$app/paths"; import CreateAgentDialog from "$lib/components/CreateAgentDialog.svelte"; + import PrivateAgentDialog from "$lib/components/PrivateAgentDialog.svelte"; const SEARCH_DEBOUNCE_DELAY = 400; let agents: Agent[] = []; let filteredAgents: Agent[] = []; let searchValue: string = ""; let showModal: boolean = false; + let showPrivateModal: boolean = false; let currentAgent: Agent; let sections: { [key: string]: Agent[] } = {}; @@ -304,7 +306,13 @@ onClose={() => { showModal = false; }} + onPrivateAgent={() => { + showModal = false; + showPrivateModal = true; + }} /> + + \ No newline at end of file + .promoted-card { + border: 2px solid #1e90ff; /* Blue border */ + background-color: #e6f7ff; /* Light blue background */ + } + + .promoted-indicator { + position: absolute; + top: 0; + right: 0; + background-color: #1e90ff; /* Blue background */ + color: #fff; /* White text */ + padding: 0.2em 0.5em; + font-size: 0.75em; + font-weight: bold; + border-bottom-left-radius: 0.5em; + } + + .promoted-text { + color: #003366; /* Dark blue text */ + text-shadow: 0.5px 0.5px 1px rgba(0, 0, 0, 0.1); /* Subtle text shadow */ + } + From d135c9fd7f737927340b53bb0587c9ac848f687a Mon Sep 17 00:00:00 2001 From: Aarush-wadhia Date: Tue, 17 Sep 2024 14:16:50 +0530 Subject: [PATCH 03/20] fix(Create Agent, REST): Removed unnecessary fields from create agents modals and REST API migration from prod to stage --- .../lib/components/PrivateAgentDialog.svelte | 255 ++++++++++-------- web/src/lib/components/SettingsAgent.svelte | 2 +- .../components/chat/ChatIntroduction.svelte | 2 +- web/src/lib/components/chat/ChatWindow.svelte | 6 +- web/src/routes/+page.svelte | 4 +- web/src/routes/agent/+page.svelte | 2 +- web/src/routes/agent/[id]/+page.svelte | 2 +- 7 files changed, 145 insertions(+), 128 deletions(-) diff --git a/web/src/lib/components/PrivateAgentDialog.svelte b/web/src/lib/components/PrivateAgentDialog.svelte index 27e52456..c0af4bcc 100644 --- a/web/src/lib/components/PrivateAgentDialog.svelte +++ b/web/src/lib/components/PrivateAgentDialog.svelte @@ -11,6 +11,8 @@ import CarbonWorld from "~icons/carbon/wikis"; import IconInternet from "./icons/IconInternet.svelte"; + import { ToastType } from "$lib/types/Toast"; + import { goto } from "$app/navigation"; type ActionData = { error: boolean; @@ -49,15 +51,9 @@ "https://stage.commanddash.dev/account/github/url/web?override_uri=http://localhost:5173" ); const _response = await response.json(); - console.log("response", _response); if (response.ok) { const oauthWindow = window.open(_response.github_oauth_url, "_blank"); - console.log("oatuhwidnwo", oauthWindow?.location.origin); - - window.addEventListener('message', (event) => { - console.log('event', event); - }) const interval = setInterval(() => { try { @@ -68,7 +64,6 @@ accessToken = urlParams.get("access_token"); refreshToken = urlParams.get("refresh_token"); if (accessToken && refreshToken) { - localStorage.setItem("accessToken", accessToken); localStorage.setItem("refreshToken", refreshToken); // Close the OAuth window @@ -88,11 +83,8 @@ } async function handleSubmitDataSources() { - debugger; if (urlType === "github") { - await validatingRepositoryAccess( - "https://github.com/wadhia-yash/shopping-demo" - ); + await validatingRepositoryAccess(url); } else { agentDataSources = [...agentDataSources, { uri: url, type: urlType }]; } @@ -113,7 +105,7 @@ agentDataSources = [...agentDataSources, { uri: url, type: urlType }]; } - if (response.status === 422) { + if (response.status === 422 || response.status === 404) { openPopup( "https://github.com/apps/staging-commanddash/installations/select_target" ); @@ -135,39 +127,54 @@ } } - async function handleSubmitAgentCreation(e: any) { - const ACTION_URL = e.target.action; - + async function handleSubmitAgentCreation() { const body = { - agent_info: { - agent_id: "x_test", - metadata: { - display_name: agentName, - avatar_profile: agentAvatar, - tags: [], - description: agentDescription, - }, - chat_mode: { - system_prompt: agentSystemPrompt, - data_source: agentDataSources, - }, + name: agentName.toLowerCase().replace(/ /g, "_"), + metadata: { + display_name: agentName, + avatar_profile: agentAvatar, + tags: [], + description: agentDescription, }, - testing: false, + chat_mode: { + system_prompt: agentSystemPrompt, + }, + is_private: false, data_sources: agentDataSources, }; - const response = await fetch(ACTION_URL, { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(body), - }); + try { + const response = await fetch( + "https://stage.commanddash.dev/agent/deploy-agent/web", + { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: "Bearer " + accessToken, + }, + body: JSON.stringify(body), + } + ); + const _response = await response.json(); + + if (!response.ok) { + toastStore.set({ + message: _response.message, + type: ToastType.ERROR, + }); + return; + } + onClose(); + goto(`/agent/${agentName.toLowerCase().replace(/ /g, "_")}`); + } catch (error) { + console.log("error", error); + } } function onFilesChange(e: Event) { const inputEl = e.target as HTMLInputElement; if (inputEl.files?.length && inputEl.files[0].size > 0) { + const file = inputEl.files[0]; if (!inputEl.files[0].type.includes("image")) { inputEl.files = null; files = null; @@ -178,6 +185,14 @@ }; return; } + + const reader = new FileReader(); + reader.onloadend = () => { + const base64String = reader.result as string; + agentAvatar = base64String; + }; + reader.readAsDataURL(file); + files = inputEl.files; resetErrors(); deleteExistingAvatar = false; @@ -194,16 +209,7 @@ // Fetch tokens from localStorage when the component mounts accessToken = localStorage.getItem("accessToken"); refreshToken = localStorage.getItem("refreshToken"); - - if (accessToken && refreshToken) { - console.log("Access Token:", accessToken); - console.log("Refresh Token:", refreshToken); - } else { - console.log("No tokens found in local storage."); - } }); - - console.log('files', files) {#if showPrivateModal} @@ -214,22 +220,18 @@ -
+

Create new agent

Create and share your own AI Agents.

-
+ -
- {#if !!accessToken && !!refreshToken} -
-
- - Add data sources - -
-
- { + urlType = target?.value; + }} + > + + + + + + +
+ +
+ Data sources + {#each agentDataSources as sourceData} + - - - - - - -
+
+ {sourceData.uri} +
+
+ {#if sourceData.type === "github"} + + {:else if sourceData.type === "web_page"} + + {:else} + + {/if} +
+
+ {/each} +
+
- + Cancel + +
+
+
- +
{/if} diff --git a/web/src/lib/components/SettingsAgent.svelte b/web/src/lib/components/SettingsAgent.svelte index 6bdc09d1..0ebd6a7f 100644 --- a/web/src/lib/components/SettingsAgent.svelte +++ b/web/src/lib/components/SettingsAgent.svelte @@ -214,7 +214,7 @@ method="POST" on:submit|preventDefault={handleSubmitContribution} class="w-full" - action="https://api.commanddash.dev/agent/contribute-source" + action="https://stage.commanddash.dev/agent/contribute-source" >
p.id === selectedPlatform).placeholder} - class="w-full pl-10 pr-3 py-2 bg-gray-800 border border-gray-700 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 text-gray-100 placeholder-gray-500" +
+ {#each platforms as platform} + + {:else} + {platform.label} + {/if}
+ {platform.label} + + {/each} +
- - +
+
+ {#if selectedPlatform === "github"} + + {:else} + p.id === selectedPlatform).icon} + alt={selectedPlatform} + class="w-5 h-5" + /> + {/if}
+ p.id === selectedPlatform) + .placeholder} + class="w-full pl-10 pr-3 py-2 bg-gray-800 border border-gray-700 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 text-gray-100 placeholder-gray-500" + /> +
+ + + {/if} \ No newline at end of file + .selected { + transform: scale(1.1); + } + .selected span { + color: #60a5fa; /* blue-400 */ + font-weight: bold; + } + diff --git a/web/src/lib/components/PrivateAgentDialog.svelte b/web/src/lib/components/PrivateAgentDialog.svelte index 3fdbb7e3..ef78d4d4 100644 --- a/web/src/lib/components/PrivateAgentDialog.svelte +++ b/web/src/lib/components/PrivateAgentDialog.svelte @@ -35,6 +35,7 @@ let agentSystemPrompt: string = ""; let agentAvatar: string = ""; let agentDataSources: Array<{ uri: string; type: string }> = []; + let agentIsPrivate: string = "private"; let accessToken: string | null = ""; let refreshToken: string | null = ""; @@ -96,12 +97,12 @@ ...options, headers: { ...options.headers, - 'Authorization': 'Bearer ' + accessToken - } - }) + Authorization: "Bearer " + accessToken, + }, + }); if (response.status === 401) { - const refreshed = await refreshAccessToken() + const refreshed = await refreshAccessToken(); if (refreshed) { // Retry the request with the refreshed token options.headers = { @@ -114,13 +115,13 @@ return response; } catch (error) { - throw error + throw error; } } async function refreshAccessToken() { try { - const refreshToken = localStorage.getItem("refreshToken") + const refreshToken = localStorage.getItem("refreshToken"); debugger; const response = await fetch( "https://stage.commanddash.dev/account/github/refresh", @@ -128,7 +129,7 @@ method: "POST", headers: { Authorization: `Bearer ${refreshToken}`, - } + }, } ); const _response = await response.json(); @@ -146,7 +147,7 @@ console.error("refreshAccessToken: error", error); return false; } - }; + } async function validatingRepositoryAccess(url: string) { try { @@ -197,13 +198,13 @@ chat_mode: { system_prompt: agentSystemPrompt, }, - is_private: false, + is_private: agentIsPrivate === "private", data_sources: agentDataSources, }; try { const response = await apiRequest( - "https://stage.commanddash.dev/agent/deploy-agent/web", + "https://stage.commanddash.dev/agent/deploy-agent/webw", { method: "POST", headers: { @@ -376,59 +377,61 @@ {getError("description", form)}

--> +
+
+ + Add data sources + +
+
+ + +
+ +
Internet access
-
- - Add data sources - -
-
- - -
- -
+
Data sources {#each agentDataSources as sourceData} Date: Wed, 18 Sep 2024 17:21:43 +0530 Subject: [PATCH 07/20] feat(Repo access): When creating agents if the repo is not accessible instead of directly navigating to github showing pop up button to configure with github --- .../lib/components/PrivateAgentDialog.svelte | 40 ++++++++++++++----- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/web/src/lib/components/PrivateAgentDialog.svelte b/web/src/lib/components/PrivateAgentDialog.svelte index ef78d4d4..11773d41 100644 --- a/web/src/lib/components/PrivateAgentDialog.svelte +++ b/web/src/lib/components/PrivateAgentDialog.svelte @@ -35,7 +35,8 @@ let agentSystemPrompt: string = ""; let agentAvatar: string = ""; let agentDataSources: Array<{ uri: string; type: string }> = []; - let agentIsPrivate: string = "private"; + let agentIsPrivate: boolean = false; + let isRepoAccessible: boolean = true; let accessToken: string | null = ""; let refreshToken: string | null = ""; @@ -160,14 +161,14 @@ }, } ); + const _response = await response.json(); + agentIsPrivate = _response.private; if (response.ok) { agentDataSources = [...agentDataSources, { uri: url, type: urlType }]; } if (response.status === 422 || response.status === 404) { - openPopup( - "https://github.com/apps/staging-commanddash/installations/select_target" - ); + isRepoAccessible = false; } } catch (error) { console.log("validatingRepositoryAccess: error", error); @@ -186,6 +187,12 @@ } } + function adjustGithubPermissions() { + openPopup( + "https://github.com/apps/staging-commanddash/installations/select_target" + ); + } + async function handleSubmitAgentCreation() { const body = { name: agentName.toLowerCase().replace(/ /g, "_"), @@ -198,7 +205,7 @@ chat_mode: { system_prompt: agentSystemPrompt, }, - is_private: agentIsPrivate === "private", + is_private: agentIsPrivate, data_sources: agentDataSources, }; @@ -406,12 +413,23 @@ bind:value={url} />
- + {#if !isRepoAccessible} + + {/if} +
-
+
Data sources {#each agentDataSources as sourceData} From c1b1ad87a09f756f3cc62f25fa65e4e024b59413 Mon Sep 17 00:00:00 2001 From: Aarush-wadhia Date: Thu, 19 Sep 2024 09:43:33 +0530 Subject: [PATCH 08/20] feat(Create agent): Authenticate while creating quick agent, and allow private agent to be in create agent --- .../lib/components/CreateAgentDialog.svelte | 188 +++++++++++++++++- .../lib/components/PrivateAgentDialog.svelte | 8 +- web/src/routes/agent/[id]/+page.svelte | 5 + 3 files changed, 188 insertions(+), 13 deletions(-) diff --git a/web/src/lib/components/CreateAgentDialog.svelte b/web/src/lib/components/CreateAgentDialog.svelte index 316b309d..c47b0459 100644 --- a/web/src/lib/components/CreateAgentDialog.svelte +++ b/web/src/lib/components/CreateAgentDialog.svelte @@ -1,4 +1,5 @@ {#if showModal} @@ -157,13 +308,32 @@ class="w-full pl-10 pr-3 py-2 bg-gray-800 border border-gray-700 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 text-gray-100 placeholder-gray-500" />
- - + {#if !isRepoAccessible} + + {/if} + {#if !!accessToken && !!refreshToken} + + {:else} + + {/if}
{/if} diff --git a/web/src/lib/components/PrivateAgentDialog.svelte b/web/src/lib/components/PrivateAgentDialog.svelte index 11773d41..0d5e956d 100644 --- a/web/src/lib/components/PrivateAgentDialog.svelte +++ b/web/src/lib/components/PrivateAgentDialog.svelte @@ -37,8 +37,8 @@ let agentDataSources: Array<{ uri: string; type: string }> = []; let agentIsPrivate: boolean = false; let isRepoAccessible: boolean = true; - let accessToken: string | null = ""; - let refreshToken: string | null = ""; + let accessToken: string | null = "Hi"; + let refreshToken: string | null = "Hi"; function resetErrors() { if (form) { @@ -231,7 +231,7 @@ return; } onClose(); - goto(`/agent/${agentName.toLowerCase().replace(/ /g, "_")}`); + goto(`/agent/${agentName.toLowerCase().replace(/ /g, "_")}?private=${agentIsPrivate}`); } catch (error) { console.log("error", error); } @@ -271,7 +271,7 @@ ); } - onMount(() => { + onMount(async () => { // Fetch tokens from localStorage when the component mounts accessToken = localStorage.getItem("accessToken"); refreshToken = localStorage.getItem("refreshToken"); diff --git a/web/src/routes/agent/[id]/+page.svelte b/web/src/routes/agent/[id]/+page.svelte index 3a4ecadf..8a6196c7 100644 --- a/web/src/routes/agent/[id]/+page.svelte +++ b/web/src/routes/agent/[id]/+page.svelte @@ -20,6 +20,7 @@ loading = true; const id: string = $page.params?.id; const ref: string = $page.url.searchParams.get("github") || ""; + const private: string = $page.url.searchParams.get("private") || ""; const response = await fetch( "https://stage.commanddash.dev/agent/get-latest-agent", @@ -44,6 +45,10 @@ loading = false; }); + const getLatestAgent = () => { + + } + const extractUris = ( data: { id: string; uri: { type: string; uri: string }[] }[], ): { type: string; uri: string }[] => { From 1f9ebea5c2ad62d94ebcbac7f95367556c72f8fb Mon Sep 17 00:00:00 2001 From: Aarush-wadhia Date: Thu, 19 Sep 2024 10:46:14 +0530 Subject: [PATCH 09/20] fix(Github login): using reactive declaration to get the access token from local storage instead of just depending on onMount function --- .../lib/components/CreateAgentDialog.svelte | 20 +- .../lib/components/PrivateAgentDialog.svelte | 21 +- web/src/routes/+page.svelte | 1 + web/src/routes/agent/[id]/+page.svelte | 215 +++++++++++------- 4 files changed, 170 insertions(+), 87 deletions(-) diff --git a/web/src/lib/components/CreateAgentDialog.svelte b/web/src/lib/components/CreateAgentDialog.svelte index c47b0459..f88e0fbe 100644 --- a/web/src/lib/components/CreateAgentDialog.svelte +++ b/web/src/lib/components/CreateAgentDialog.svelte @@ -16,8 +16,8 @@ let value: string = ""; let selectedPlatform: string = "github"; - let accessToken: string | null = ""; - let refreshToken: string | null = ""; + let accessToken: string = ""; + let refreshToken: string = ""; let isRepoAccessible: boolean = true; const platforms = [ @@ -205,8 +205,8 @@ const urlParams = new URLSearchParams( oauthWindow.location.search ); - accessToken = urlParams.get("access_token"); - refreshToken = urlParams.get("refresh_token"); + accessToken = urlParams.get("access_token") ?? ""; + refreshToken = urlParams.get("refresh_token") ?? ""; if (accessToken && refreshToken) { localStorage.setItem("accessToken", accessToken); localStorage.setItem("refreshToken", refreshToken); @@ -226,15 +226,21 @@ } } + function getStorageData() { + accessToken = localStorage.getItem("accessToken") ?? ""; + refreshToken = localStorage.getItem("refreshToken") ?? ""; + } + $: if (showModal) { appInsights.trackEvent({ name: "CreateAgentDialogOpened" }); + getStorageData(); } onMount(() => { // Fetch tokens from localStorage when the component mounts - accessToken = localStorage.getItem("accessToken"); - refreshToken = localStorage.getItem("refreshToken"); + getStorageData(); }); + {#if showModal} @@ -318,7 +324,7 @@ > {/if} - {#if !!accessToken && !!refreshToken} + {#if accessToken?.length > 0 && refreshToken?.length > 0} {/if} - {#if accessToken?.length > 0 && refreshToken?.length > 0} - - {:else} + {#if !isRepoAccessible && !accessToken} + {:else} + {/if} diff --git a/web/src/lib/components/PrivateAgentDialog.svelte b/web/src/lib/components/PrivateAgentDialog.svelte index 6709042a..afbb49ae 100644 --- a/web/src/lib/components/PrivateAgentDialog.svelte +++ b/web/src/lib/components/PrivateAgentDialog.svelte @@ -164,7 +164,7 @@ async function validatingRepositoryAccess(_url: string) { try { const response = await apiRequest( - `https://stage.commanddash.dev/github/repo/verify-access?repo=${_url}`, + `https://stage.commanddash.dev/github/repo/verify-access-auth?repo=${_url}`, { method: "GET", headers: { From 43f053cfa8a1b1a0f447383a62fca9e3d9f74c64 Mon Sep 17 00:00:00 2001 From: Aarush-wadhia Date: Fri, 20 Sep 2024 11:44:14 +0530 Subject: [PATCH 15/20] fix: API's auth token is now used based on the availablity of accessToken --- .../lib/components/CreateAgentDialog.svelte | 41 +++++++---------- web/src/routes/agent/+page.svelte | 41 +++++++---------- web/src/routes/agent/[id]/+page.svelte | 44 ++++++++----------- 3 files changed, 48 insertions(+), 78 deletions(-) diff --git a/web/src/lib/components/CreateAgentDialog.svelte b/web/src/lib/components/CreateAgentDialog.svelte index 7deab882..2464c6e1 100644 --- a/web/src/lib/components/CreateAgentDialog.svelte +++ b/web/src/lib/components/CreateAgentDialog.svelte @@ -90,9 +90,21 @@ }; async function validatingRepositoryAccess(url: string) { + const headers = { + "Content-Type": "application/json", + }; + if (accessToken) { + headers.Authorization = "Bearer " + accessToken; + } try { - const response = await getVerifyAccess(url); - + const response = await apiRequest( + `https://stage.commanddash.dev/github/repo/verify-access?repo=${url}`, + { + method: "GET", + headers: headers, + } + ); + if (response.ok) { goto(`${base}/agent?${selectedPlatform}=${url}`); } @@ -105,34 +117,12 @@ } } - async function getVerifyAccess(_url: string) { - if (accessToken?.length === 0 || accessToken === null || accessToken === undefined) { - return await apiRequest( - `https://stage.commanddash.dev/github/repo/verify-access?repo=${_url}`, - { - method: "GET", - } - ); - } else { - return await apiRequest( - `https://stage.commanddash.dev/github/repo/verify-access-auth?repo=${_url}`, - { - method: "GET", - headers: { - Authorization: "Bearer " + accessToken, - }, - } - ) - } - } - async function apiRequest(url: string, options: RequestInit) { try { const response = await fetch(url, { ...options, headers: { ...options.headers, - Authorization: "Bearer " + accessToken, }, }); @@ -253,7 +243,6 @@ // Fetch tokens from localStorage when the component mounts getStorageData(); }); - {#if showModal} @@ -346,7 +335,7 @@ Sign in with GitHub {:else} -
{/if} diff --git a/web/src/lib/components/PrivateAgentDialog.svelte b/web/src/lib/components/PrivateAgentDialog.svelte index 5fa6947e..13ab2813 100644 --- a/web/src/lib/components/PrivateAgentDialog.svelte +++ b/web/src/lib/components/PrivateAgentDialog.svelte @@ -38,6 +38,7 @@ let accessToken: string | null = "Hi"; let refreshToken: string | null = "Hi"; let agentPurpose: string = ""; + let isLoading: boolean = false; // Add a reactive variable for loading state function resetErrors() { if (form) { @@ -49,26 +50,16 @@ async function onSigninGithub() { try { const response = await fetch( - "https://stage.commanddash.dev/account/github/url/web?override_uri=http://localhost:5173" + "https://api.commanddash.dev/account/github/url/web?override_uri=https://app.commanddash.io" ); const _response = await response.json(); if (response.ok) { const oauthWindow = window.open(_response.github_oauth_url, "_blank"); - // if (!oauthWindow) { - // const isAllow = window.confirm("Popup blocked! Please allow popups for this site."); - // if (isAllow) { - // const a = document.createElement('a'); - // a.href = _response.github_oauth_url; - // a.target = "_blank"; - // a.click(); - // } - // } - const interval = setInterval(() => { try { - if (oauthWindow?.location.origin === "http://localhost:5173") { + if (oauthWindow?.location.origin === "https://app.commanddash.io") { const urlParams = new URLSearchParams( oauthWindow.location.search ); @@ -133,9 +124,8 @@ async function refreshAccessToken() { try { const refreshToken = localStorage.getItem("refreshToken"); - debugger; const response = await fetch( - "https://stage.commanddash.dev/account/github/refresh", + "https://api.commanddash.dev/account/github/refresh", { method: "POST", headers: { @@ -169,14 +159,14 @@ } try { const response = await apiRequest( - `https://stage.commanddash.dev/github/repo/verify-access?repo=${_url}`, + `https://api.commanddash.dev/github/repo/verify-access?repo=${_url}`, { method: "GET", headers: headers } ); const _response = await response.json(); - + if (response.ok) { agentDataSources = [...agentDataSources, { uri: _url, type: urlType, is_private: _response.private }]; url = "" @@ -204,7 +194,7 @@ function adjustGithubPermissions() { openPopup( - "https://github.com/apps/staging-commanddash/installations/select_target" + "https://github.com/apps/commanddash/installations/select_target" ); } @@ -213,8 +203,8 @@ name: agentName, metadata: { display_name: agentName, - avatar_profile: agentAvatar, tags: [], + description: agentPurpose }, chat_mode: { system_prompt: agentPurpose, @@ -222,11 +212,10 @@ is_private: agentDataSources.some(({is_private}) => is_private === true), data_sources: agentDataSources, }; - - debugger; + try { const response = await apiRequest( - "https://stage.commanddash.dev/agent/deploy-agent/web", + "https://api.commanddash.dev/agent/deploy-agent/web", { method: "POST", headers: { @@ -237,7 +226,7 @@ } ); const _response = await response.json(); - debugger; + if (!response.ok) { toastStore.set({ message: _response.message, @@ -246,6 +235,9 @@ return; } onClose(); + isLoading = true; // Set loading state to true + await new Promise(resolve => setTimeout(resolve, 2000)); // Add a 5-second delay + isLoading = false; // Set loading state to false goto(`/agent/${_response.agent_id}`); } catch (error) { console.log("error", error); @@ -315,252 +307,139 @@

Create and share your own AI Code Agents.

-
+ {/if} -{/if} +{/if} \ No newline at end of file diff --git a/web/src/lib/components/SettingsAgent.svelte b/web/src/lib/components/SettingsAgent.svelte index 0ebd6a7f..6bdc09d1 100644 --- a/web/src/lib/components/SettingsAgent.svelte +++ b/web/src/lib/components/SettingsAgent.svelte @@ -214,7 +214,7 @@ method="POST" on:submit|preventDefault={handleSubmitContribution} class="w-full" - action="https://stage.commanddash.dev/agent/contribute-source" + action="https://api.commanddash.dev/agent/contribute-source" >