diff --git a/core/control-plane/client.ts b/core/control-plane/client.ts index c299cfc1f..d98320f9a 100644 --- a/core/control-plane/client.ts +++ b/core/control-plane/client.ts @@ -449,22 +449,29 @@ export class ControlPlaneClient { repoUrl: string, name: string, branch?: string, + organizationId?: string, ): Promise<{ id: string }> { if (!(await this.isSignedIn())) { throw new Error("Not signed in to Continue"); } + const requestBody: any = { + prompt, + repoUrl, + name, + branchName: branch, + }; + + if (organizationId) { + requestBody.organizationId = organizationId; + } + const resp = await this.requestAndHandleError("agents", { method: "POST", headers: { "Content-Type": "application/json", }, - body: JSON.stringify({ - prompt, - repoUrl, - name, - branchName: branch, - }), + body: JSON.stringify(requestBody), }); return (await resp.json()) as { id: string }; diff --git a/core/protocol/ideWebview.ts b/core/protocol/ideWebview.ts index 0c3dfd1fc..13f012828 100644 --- a/core/protocol/ideWebview.ts +++ b/core/protocol/ideWebview.ts @@ -50,7 +50,7 @@ export type ToIdeFromWebviewProtocol = ToIdeFromWebviewOrCoreProtocol & { "edit/addCurrentSelection": [undefined, void]; "edit/clearDecorations": [undefined, void]; "session/share": [{ sessionId: string }, void]; - createBackgroundAgent: [{ editorState: any }, void]; + createBackgroundAgent: [{ editorState: any; organizationId?: string }, void]; listBackgroundAgents: [ undefined, Array<{ diff --git a/extensions/vscode/src/extension/VsCodeMessenger.ts b/extensions/vscode/src/extension/VsCodeMessenger.ts index 9f8c7a2dc..3afad6f95 100644 --- a/extensions/vscode/src/extension/VsCodeMessenger.ts +++ b/extensions/vscode/src/extension/VsCodeMessenger.ts @@ -265,7 +265,7 @@ export class VsCodeMessenger { this.onWebview("createBackgroundAgent", async (msg) => { const configHandler = await configHandlerPromise; - const { editorState } = msg.data; + const { editorState, organizationId } = msg.data; // Import utilities for processing editor content const { stripImages } = await import("core/util/messageContent"); @@ -347,6 +347,8 @@ export class VsCodeMessenger { name = `Agent for ${repoName || "repository"}`; } + // debugger; + // Create the background agent try { console.log("Creating background agent with:", { @@ -362,6 +364,7 @@ export class VsCodeMessenger { repoUrl, name, branch, + organizationId, ); vscode.window.showInformationMessage( diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 0d7f1a71b..c01f59726 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -31,6 +31,7 @@ import { selectDoneApplyStates, selectPendingToolCalls, } from "../../redux/selectors/selectToolCalls"; +import { selectCurrentOrg } from "../../redux/slices/profilesSlice"; import { cancelToolCall, ChatHistoryItemWithMessageId, @@ -127,6 +128,7 @@ export function Chat() { (state) => state.ui.hasDismissedExploreDialog, ); const mode = useAppSelector((state) => state.session.mode); + const currentOrg = useAppSelector(selectCurrentOrg); const jetbrains = useMemo(() => { return isJetBrains(); }, []); @@ -176,7 +178,11 @@ export function Chat() { // Handle background mode specially if (currentMode === "background" && !isCurrentlyInEdit) { // Background mode triggers agent creation instead of chat - ideMessenger.post("createBackgroundAgent", { editorState }); + const organizationId = selectCurrentOrg(stateSnapshot)?.id; + ideMessenger.post("createBackgroundAgent", { + editorState, + organizationId, + }); if (editorToClearOnSend) { editorToClearOnSend.commands.clearContent(); } @@ -473,7 +479,11 @@ export function Chat() { {mode === "background" ? ( { - ideMessenger.post("createBackgroundAgent", { prompt }); + const organizationId = currentOrg?.id; + ideMessenger.post("createBackgroundAgent", { + prompt, + organizationId, + }); }} /> ) : (