Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

Merge #317: feat: per-project model modes

ogsamrat8d0a7958928f
diff --cc apps/server/src/box/service.ts
index b63dc6c7,ef1772ab..7a4f71e7
--- a/apps/server/src/box/service.ts
+++ b/apps/server/src/box/service.ts
@@@ -845,15 -835,11 +855,17 @@@ export class BoxService
await this.writeProjects();
this.log("info", "box: a chat that ran on this machine stays there", { sessionId, turnsBefore, required: true });
}
- const run = required && !this.nativeChats.has(sessionId) ? await this.waitForBox(workspace, signal) : await this.ensure(workspace).catch(() => null);
+ // One pin per chat: a chat that started in the box keeps it, whatever the project's setting says now.
+ const keep = this.chatPin(sessionId)?.box === true;
- const run = required && !this.nativeChats.has(sessionId) ? await this.waitForBox(workspace) : await this.ensure(workspace, { keep }).catch(() => null);
++ const run = required && !this.nativeChats.has(sessionId) ? await this.waitForBox(workspace, signal) : await this.ensure(workspace, { keep }).catch(() => null);
+ // The send was stopped while it waited: no checkpoint and no pin, the caller does not dispatch it, and the
+ // chat counts as not having run this turn (a retry waits for the box again).
+ if (signal?.aborted) {
+ this.promptCancelled(sessionId);
+ return null;
+ }
if (!run || run.native) {
- if (capture) await this.pin(sessionId, false);
+ await this.pin(sessionId, false);
return null;
}
// A chat with turns but no checkpoint ran on this machine (reopened, or started in this run before the
diff --cc apps/server/src/server.ts
index b700b968,88cfa570..b09d586e
--- a/apps/server/src/server.ts
+++ b/apps/server/src/server.ts
@@@ -2138,11 -2141,11 +2147,12 @@@ export async function proxyOpencodeV2Re
const turnsBefore = capture && uploadedSessionId && engine ? await turnsBeforeCapture(capture, uploadedSessionId, engine) : 0;
// The Linux sandbox (box/): a prompt of a workspace whose box is on starts the box, and takes the turn's checkpoint when it is captured.
// One pin per chat: a chat that runs in the box is not moved to this computer when its project's box is off.
- if (promptDispatch && sessionId && await boxServiceFor(input.config).pinnedBoxGone(sessionId, input.workspace)) throw new ApiError(409, "chat_pinned_box", PINNED_BOX_MESSAGE);
+ const pinnedBoxWhy = promptDispatch && sessionId ? await boxServiceFor(input.config).pinnedBoxUnavailable(sessionId, input.workspace) : null;
+ if (pinnedBoxWhy) throw new ApiError(409, "chat_pinned_box", pinnedBoxMessage(pinnedBoxWhy));
const boxInfo = promptDispatch && sessionId
- ? await boxServiceFor(input.config).beforePrompt(sessionId, input.workspace, { capture: Boolean(uploadedSessionId && engine), turnsBefore, nativeModel: await promptsNativeOnlyModel(input.config, body) })
+ ? await boxServiceFor(input.config).beforePrompt(sessionId, input.workspace, { capture: Boolean(uploadedSessionId && engine), turnsBefore, nativeModel: await promptsNativeOnlyModel(input.config, body), signal: input.request.signal })
: null;
+ if (promptDispatch && input.request.signal.aborted) return stoppedSendResponse(input.config, sessionId);
if (capture && uploadedSessionId && engine) {
// The turn before's background processes finish writing (at most 10 s after it ended), its project
// delta is taken (at most 5 s more, only when it ended a moment ago), then capture v2's session-start
@@@ -2580,14 -2583,11 +2591,15 @@@ export async function proxyOpencodeRequ
const turnsBefore = capture && captured && uploadedSessionId && workspace && !steer && isUploadPromptDispatch(method, proxyPath)
? await turnsBeforeCapture(capture, uploadedSessionId, engineTarget(baseUrl, headers, search))
: 0;
- if (workspace && uploadedSessionId && isUploadPromptDispatch(method, proxyPath) && await boxServiceFor(input.config).pinnedBoxGone(uploadedSessionId, workspace)) throw new ApiError(409, "chat_pinned_box", PINNED_BOX_MESSAGE);
+ const pinnedBoxWhy = workspace && uploadedSessionId && isUploadPromptDispatch(method, proxyPath) ? await boxServiceFor(input.config).pinnedBoxUnavailable(uploadedSessionId, workspace) : null;
+ if (pinnedBoxWhy) throw new ApiError(409, "chat_pinned_box", pinnedBoxMessage(pinnedBoxWhy));
const boxInfo = workspace && uploadedSessionId && isUploadPromptDispatch(method, proxyPath)
- ? await boxServiceFor(input.config).beforePrompt(uploadedSessionId, workspace, { capture: captured && !steer, turnsBefore, nativeModel: await promptsNativeOnlyModel(input.config, body) })
+ ? await boxServiceFor(input.config).beforePrompt(uploadedSessionId, workspace, { capture: captured && !steer, turnsBefore, nativeModel: await promptsNativeOnlyModel(input.config, body), signal: input.request.signal })
: null;
+ const dispatch = isUploadPromptDispatch(method, proxyPath) || isSessionCommandProxyRequest(method, proxyPath);
+ // The chat whose turn beforePrompt counted for this request (undone when it is stopped before the engine).
+ const boxSession = workspace && uploadedSessionId && isUploadPromptDispatch(method, proxyPath) ? uploadedSessionId : null;
+ if (dispatch && input.request.signal.aborted) return stoppedSendResponse(input.config, boxSession);
if (capture && captured && uploadedSessionId && workspace && !steer) {
const promptDispatch = isUploadPromptDispatch(method, proxyPath);
// The turn before's background processes finish writing (at most 10 s after it ended), its project