feat: background agent creation

This commit is contained in:
Tomasz Stefaniak 2025-10-09 15:30:21 -07:00
parent 3c00349c2f
commit d9c16e4103
4 changed files with 30 additions and 10 deletions

View file

@ -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 };

View file

@ -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<{

View file

@ -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(

View file

@ -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" ? (
<BackgroundModeView
onCreateAgent={(prompt) => {
ideMessenger.post("createBackgroundAgent", { prompt });
const organizationId = currentOrg?.id;
ideMessenger.post("createBackgroundAgent", {
prompt,
organizationId,
});
}}
/>
) : (