@openchamber/web 1.18.0 → 1.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{DiagramView-1-LZVuzn.js → DiagramView-DZmf30ko.js} +1 -1
- package/dist/assets/{FilesView-BDRX8vU2.js → FilesView-cJPeFhDe.js} +6 -6
- package/dist/assets/{MarkdownRendererImpl-fZSdR7PD.js → MarkdownRendererImpl-DZezL90a.js} +1 -1
- package/dist/assets/{OnboardingScreen-D81UrlA4.js → OnboardingScreen-ChYr0xqs.js} +1 -1
- package/dist/assets/{SessionSwitcherDropdown-cSK3t3TR.js → SessionSwitcherDropdown-BV7FfPbT.js} +1 -1
- package/dist/assets/{SettingsWindow-CozowJLm.js → SettingsWindow-UybkBD1p.js} +1 -1
- package/dist/assets/{contextPanelEmbeddedChat-CQYNvKbk.js → contextPanelEmbeddedChat-DW3atb4h.js} +1 -1
- package/dist/assets/{de-C2n4oo1Z.js → de-rVJ-hXrd.js} +3 -3
- package/dist/assets/es-D7ZyOToq.js +15 -0
- package/dist/assets/{fr-DDFUp5jS.js → fr-hl5i-ZI0.js} +2 -2
- package/dist/assets/{index-BCCcokur.css → index-CL9MYe8V.css} +1 -1
- package/dist/assets/{ja-B7SxobKm.js → ja-DqakdvOp.js} +2 -2
- package/dist/assets/{ko-CWGq93SO.js → ko-dNl8A3Xf.js} +2 -2
- package/dist/assets/main-B5TIsU2y.js +209 -0
- package/dist/assets/{main-Cts0BwVk.js → main-_m6HD9-a.js} +2 -2
- package/dist/assets/{markdownCore-BqzEkymd.js → markdownCore-DpT1vbbv.js} +2 -2
- package/dist/assets/{miniChat-ChuQD2KK.js → miniChat-wYb8p9vG.js} +2 -2
- package/dist/assets/{mobile-c-CRD1Cz.js → mobile-ExXAVUcv.js} +2 -2
- package/dist/assets/{pl-DZmyxLo7.js → pl-C5HQx1Hf.js} +3 -3
- package/dist/assets/pt-BR-CNCoBDAM.js +15 -0
- package/dist/assets/{renderElectronMiniChatApp-9uaZAJjw.js → renderElectronMiniChatApp-DPDzIT8W.js} +2 -2
- package/dist/assets/{renderMobileApp-Dm1tmU2a.js → renderMobileApp-CzWvxR9e.js} +3 -3
- package/dist/assets/runtimeEndpointReset-DKzVWH1w.js +180 -0
- package/dist/assets/uk-Bn-3AMpk.js +15 -0
- package/dist/assets/{useAppFontEffects-pyTMaGQu.js → useAppFontEffects-DdvGxoPX.js} +133 -133
- package/dist/assets/zh-CN-BCwvQpZm.js +15 -0
- package/dist/assets/zh-TW-TRHrkN9l.js +15 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +2 -2
- package/server/lib/openchamber-control/DOCUMENTATION.md +9 -1
- package/server/lib/openchamber-sessions/routes.js +117 -4
- package/server/lib/openchamber-sessions/routes.test.js +129 -16
- package/server/lib/opencode/DOCUMENTATION.md +2 -0
- package/server/lib/opencode/proxy.js +21 -3
- package/server/lib/small-model/DOCUMENTATION.md +11 -4
- package/server/lib/small-model/call.js +19 -3
- package/server/lib/small-model/call.test.js +9 -2
- package/server/lib/small-model/index.js +10 -1
- package/server/lib/small-model/index.test.js +20 -1
- package/server/lib/walkthrough/DOCUMENTATION.md +23 -0
- package/server/lib/walkthrough/index.js +17 -0
- package/server/lib/walkthrough/reproduce-2607.test.js +148 -0
- package/server/opencode-proxy.test.js +83 -0
- package/dist/assets/es-DP7jRKkr.js +0 -15
- package/dist/assets/main-Cqfcxvqq.js +0 -209
- package/dist/assets/pt-BR-BKR5oHQ7.js +0 -15
- package/dist/assets/runtimeEndpointReset-DL5z84w2.js +0 -180
- package/dist/assets/uk-D7oAI_Wc.js +0 -15
- package/dist/assets/zh-CN-Ddjz1_9w.js +0 -15
- package/dist/assets/zh-TW-D3X01YXj.js +0 -15
- /package/dist/assets/{index-ChZvuURI.js → index-DjZ4W8hy.js} +0 -0
package/dist/index.html
CHANGED
|
@@ -515,15 +515,15 @@
|
|
|
515
515
|
pointer-events: none;
|
|
516
516
|
}
|
|
517
517
|
</style>
|
|
518
|
-
<script type="module" crossorigin src="/assets/main-
|
|
518
|
+
<script type="module" crossorigin src="/assets/main-_m6HD9-a.js"></script>
|
|
519
519
|
<link rel="modulepreload" crossorigin href="/assets/vendor-vite-runtime-DD1OZmLC.js">
|
|
520
520
|
<link rel="modulepreload" crossorigin href="/assets/vendor-opencode-sdk-BJ73u-bH.js">
|
|
521
521
|
<link rel="modulepreload" crossorigin href="/assets/vendor-scheduler-7OC5HNn7.js">
|
|
522
522
|
<link rel="modulepreload" crossorigin href="/assets/vendor-react-BUCujlKS.js">
|
|
523
523
|
<link rel="modulepreload" crossorigin href="/assets/vendor-zustand-BAGL70zf.js">
|
|
524
|
-
<link rel="modulepreload" crossorigin href="/assets/index-
|
|
525
|
-
<link rel="modulepreload" crossorigin href="/assets/contextPanelEmbeddedChat-
|
|
526
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
524
|
+
<link rel="modulepreload" crossorigin href="/assets/index-DjZ4W8hy.js">
|
|
525
|
+
<link rel="modulepreload" crossorigin href="/assets/contextPanelEmbeddedChat-DW3atb4h.js">
|
|
526
|
+
<link rel="stylesheet" crossorigin href="/assets/index-CL9MYe8V.css">
|
|
527
527
|
</head>
|
|
528
528
|
<body class="h-full bg-background text-foreground">
|
|
529
529
|
<div id="root" class="h-full">
|
package/dist/mini-chat.html
CHANGED
|
@@ -74,14 +74,14 @@
|
|
|
74
74
|
}
|
|
75
75
|
</style>
|
|
76
76
|
|
|
77
|
-
<script type="module" crossorigin src="/assets/miniChat-
|
|
77
|
+
<script type="module" crossorigin src="/assets/miniChat-wYb8p9vG.js"></script>
|
|
78
78
|
<link rel="modulepreload" crossorigin href="/assets/vendor-vite-runtime-DD1OZmLC.js">
|
|
79
79
|
<link rel="modulepreload" crossorigin href="/assets/vendor-opencode-sdk-BJ73u-bH.js">
|
|
80
80
|
<link rel="modulepreload" crossorigin href="/assets/vendor-scheduler-7OC5HNn7.js">
|
|
81
81
|
<link rel="modulepreload" crossorigin href="/assets/vendor-react-BUCujlKS.js">
|
|
82
82
|
<link rel="modulepreload" crossorigin href="/assets/vendor-zustand-BAGL70zf.js">
|
|
83
|
-
<link rel="modulepreload" crossorigin href="/assets/index-
|
|
84
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
83
|
+
<link rel="modulepreload" crossorigin href="/assets/index-DjZ4W8hy.js">
|
|
84
|
+
<link rel="stylesheet" crossorigin href="/assets/index-CL9MYe8V.css">
|
|
85
85
|
</head>
|
|
86
86
|
<body class="h-full bg-background text-foreground">
|
|
87
87
|
<div id="root" class="h-full">
|
package/dist/mobile.html
CHANGED
|
@@ -63,14 +63,14 @@
|
|
|
63
63
|
})();
|
|
64
64
|
</script>
|
|
65
65
|
|
|
66
|
-
<script type="module" crossorigin src="/assets/mobile-
|
|
66
|
+
<script type="module" crossorigin src="/assets/mobile-ExXAVUcv.js"></script>
|
|
67
67
|
<link rel="modulepreload" crossorigin href="/assets/vendor-vite-runtime-DD1OZmLC.js">
|
|
68
68
|
<link rel="modulepreload" crossorigin href="/assets/vendor-opencode-sdk-BJ73u-bH.js">
|
|
69
69
|
<link rel="modulepreload" crossorigin href="/assets/vendor-scheduler-7OC5HNn7.js">
|
|
70
70
|
<link rel="modulepreload" crossorigin href="/assets/vendor-react-BUCujlKS.js">
|
|
71
71
|
<link rel="modulepreload" crossorigin href="/assets/vendor-zustand-BAGL70zf.js">
|
|
72
|
-
<link rel="modulepreload" crossorigin href="/assets/index-
|
|
73
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
72
|
+
<link rel="modulepreload" crossorigin href="/assets/index-DjZ4W8hy.js">
|
|
73
|
+
<link rel="stylesheet" crossorigin href="/assets/index-CL9MYe8V.css">
|
|
74
74
|
</head>
|
|
75
75
|
<body class="h-full bg-background text-foreground">
|
|
76
76
|
<div id="root" class="h-full"></div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openchamber/web",
|
|
3
|
-
"version": "1.18.
|
|
3
|
+
"version": "1.18.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./server/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@clack/prompts": "^1.1.0",
|
|
27
27
|
"@octokit/rest": "^22.0.1",
|
|
28
|
-
"@opencode-ai/sdk": "1.18.
|
|
28
|
+
"@opencode-ai/sdk": "1.18.12",
|
|
29
29
|
"@simplewebauthn/server": "13.3.1",
|
|
30
30
|
"adm-zip": "^0.5.16",
|
|
31
31
|
"bun-pty": "^0.4.5",
|
|
@@ -32,7 +32,15 @@ other.
|
|
|
32
32
|
requires observed activity or a newly completed assistant message.
|
|
33
33
|
- Timeout and cancellation are failures, never authoritative idle results.
|
|
34
34
|
- Validation that protects side effects runs before session creation or
|
|
35
|
-
dispatch.
|
|
35
|
+
dispatch. An explicitly requested model, agent, or variant is checked against
|
|
36
|
+
the directory's own OpenCode agent and provider lists before any session,
|
|
37
|
+
worktree, or goal is created, because `prompt_async` accepts an unusable
|
|
38
|
+
selection and then fails only on the event stream. A failed or empty lookup
|
|
39
|
+
never turns a valid selection into a rejection.
|
|
40
|
+
- `promptDispatched` reports an observed dispatch, never an accepted request.
|
|
41
|
+
After `prompt_async` the service confirms a new user message reached the
|
|
42
|
+
session; when it does not, the result reports `promptDispatched: false` with
|
|
43
|
+
`promptError` instead of claiming success.
|
|
36
44
|
- Send and fork dispatches without an explicit model/agent/variant reuse the
|
|
37
45
|
target session's last user-message selection before falling back to the
|
|
38
46
|
configured defaults; only session creation resolves defaults directly.
|
|
@@ -272,6 +272,41 @@ const resolveRequestedDirectory = async ({ payload, readSettingsFromDiskMigrated
|
|
|
272
272
|
: { ok: false, status: 400, error: validated.error || 'Invalid directory' };
|
|
273
273
|
};
|
|
274
274
|
|
|
275
|
+
const PROMPT_LANDED_TIMEOUT_MS = 5_000;
|
|
276
|
+
const PROMPT_LANDED_POLL_MS = 150;
|
|
277
|
+
|
|
278
|
+
const latestUserMessageID = async ({ client, sessionID, directory }) => {
|
|
279
|
+
let response;
|
|
280
|
+
try {
|
|
281
|
+
response = await client.session.messages({ sessionID, directory, limit: 100 });
|
|
282
|
+
} catch {
|
|
283
|
+
return { ok: false, messageID: null };
|
|
284
|
+
}
|
|
285
|
+
const messages = Array.isArray(response?.data) ? response.data : [];
|
|
286
|
+
let latest = null;
|
|
287
|
+
for (const message of messages) {
|
|
288
|
+
const info = message?.info;
|
|
289
|
+
if (info?.role !== 'user') continue;
|
|
290
|
+
if (!latest || (info.time?.created || 0) >= (latest.time?.created || 0)) latest = info;
|
|
291
|
+
}
|
|
292
|
+
return { ok: true, messageID: asNonEmptyString(latest?.id) };
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
// `prompt_async` answers 204 as soon as OpenCode forks the run, and every later
|
|
296
|
+
// failure is reported only on the session event stream. Confirm the prompt was
|
|
297
|
+
// actually recorded so `promptDispatched` never claims a dispatch that vanished.
|
|
298
|
+
const waitForPromptLanded = async ({ client, sessionID, directory, baselineUserMessageID }) => {
|
|
299
|
+
const deadline = Date.now() + PROMPT_LANDED_TIMEOUT_MS;
|
|
300
|
+
for (;;) {
|
|
301
|
+
const latest = await latestUserMessageID({ client, sessionID, directory });
|
|
302
|
+
// A failed lookup is not authoritative evidence that the prompt was lost.
|
|
303
|
+
if (!latest.ok) return true;
|
|
304
|
+
if (latest.messageID && latest.messageID !== baselineUserMessageID) return true;
|
|
305
|
+
if (Date.now() >= deadline) return false;
|
|
306
|
+
await new Promise((resolve) => setTimeout(resolve, PROMPT_LANDED_POLL_MS));
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
|
|
275
310
|
const resolveWorktreeInput = (payload) => {
|
|
276
311
|
if (!payload?.worktree || typeof payload.worktree !== 'object') return null;
|
|
277
312
|
const name = asNonEmptyString(payload.worktree.name);
|
|
@@ -322,6 +357,48 @@ export const createOpenChamberSessionService = (dependencies) => {
|
|
|
322
357
|
return null;
|
|
323
358
|
};
|
|
324
359
|
|
|
360
|
+
// Explicit model/agent/variant are never checked by `prompt_async`: an unknown
|
|
361
|
+
// agent makes the forked run fail silently, leaving a session with no message.
|
|
362
|
+
// Reject them before any session, worktree, or goal side effect happens.
|
|
363
|
+
const validateRequestedSelection = async ({ directory, requestedModel, requestedAgent, requestedVariant }) => {
|
|
364
|
+
if (!requestedModel && !requestedAgent && !requestedVariant) return;
|
|
365
|
+
const authHeaders = getOpenCodeAuthHeaders();
|
|
366
|
+
const { providers, agents } = await fetchSelectionInputs({
|
|
367
|
+
buildOpenCodeUrl,
|
|
368
|
+
authHeaders,
|
|
369
|
+
directory,
|
|
370
|
+
readSettingsFromDiskMigrated,
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
// An empty list means the lookup failed or returned nothing authoritative;
|
|
374
|
+
// it must not turn a valid selection into a rejection.
|
|
375
|
+
if (requestedAgent && agents.length > 0) {
|
|
376
|
+
const agent = agents.find((entry) => entry?.name === requestedAgent) || null;
|
|
377
|
+
if (!agent) {
|
|
378
|
+
throw new OpenChamberControlError(`Unknown agent '${requestedAgent}' for ${directory}`, 400);
|
|
379
|
+
}
|
|
380
|
+
if (!isPrimaryAgentMode(agent.mode)) {
|
|
381
|
+
throw new OpenChamberControlError(`Agent '${requestedAgent}' is a subagent and cannot receive a prompt directly`, 400);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if (requestedModel && providers.length > 0) {
|
|
386
|
+
if (!hasProviderModel(providers, requestedModel.providerID, requestedModel.modelID)) {
|
|
387
|
+
throw new OpenChamberControlError(
|
|
388
|
+
`Unknown model '${requestedModel.providerID}/${requestedModel.modelID}' for ${directory}`,
|
|
389
|
+
400,
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
if (requestedVariant
|
|
393
|
+
&& !resolveVariant(providers, requestedModel.providerID, requestedModel.modelID, requestedVariant)) {
|
|
394
|
+
throw new OpenChamberControlError(
|
|
395
|
+
`Unknown variant '${requestedVariant}' for model '${requestedModel.providerID}/${requestedModel.modelID}'`,
|
|
396
|
+
400,
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
|
|
325
402
|
const dispatchPrompt = async ({
|
|
326
403
|
client,
|
|
327
404
|
baseUrl,
|
|
@@ -417,6 +494,7 @@ export const createOpenChamberSessionService = (dependencies) => {
|
|
|
417
494
|
throw markGoalPartial(error);
|
|
418
495
|
}
|
|
419
496
|
} else {
|
|
497
|
+
const baseline = await latestUserMessageID({ client, sessionID, directory });
|
|
420
498
|
try {
|
|
421
499
|
await runPromptAsync({
|
|
422
500
|
baseUrl,
|
|
@@ -438,6 +516,22 @@ export const createOpenChamberSessionService = (dependencies) => {
|
|
|
438
516
|
} catch (error) {
|
|
439
517
|
throw markGoalPartial(error);
|
|
440
518
|
}
|
|
519
|
+
const landed = await waitForPromptLanded({
|
|
520
|
+
client,
|
|
521
|
+
sessionID,
|
|
522
|
+
directory,
|
|
523
|
+
baselineUserMessageID: baseline.messageID,
|
|
524
|
+
});
|
|
525
|
+
if (!landed) {
|
|
526
|
+
return {
|
|
527
|
+
model,
|
|
528
|
+
agent,
|
|
529
|
+
variant,
|
|
530
|
+
promptDispatched: false,
|
|
531
|
+
dispatchedAsCommand: false,
|
|
532
|
+
promptError: 'OpenCode accepted the prompt but it never appeared in the session',
|
|
533
|
+
};
|
|
534
|
+
}
|
|
441
535
|
}
|
|
442
536
|
|
|
443
537
|
return { model, agent, variant, promptDispatched: true, dispatchedAsCommand: Boolean(resolvedCommand) };
|
|
@@ -470,13 +564,23 @@ export const createOpenChamberSessionService = (dependencies) => {
|
|
|
470
564
|
if (payload?.worktree && !worktreeInput) {
|
|
471
565
|
throw new OpenChamberControlError('worktree.name is required when worktree is provided', 400);
|
|
472
566
|
}
|
|
567
|
+
|
|
568
|
+
if (typeof waitForOpenCodeReady === 'function') await waitForOpenCodeReady(10_000, 250);
|
|
569
|
+
|
|
570
|
+
if (prompt) {
|
|
571
|
+
await validateRequestedSelection({
|
|
572
|
+
directory: resolvedDirectory.directory,
|
|
573
|
+
requestedModel: model,
|
|
574
|
+
requestedAgent: agent,
|
|
575
|
+
requestedVariant: variant,
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
|
|
473
579
|
if (worktreeInput) {
|
|
474
580
|
worktree = await createWorktree(resolvedDirectory.directory, worktreeInput);
|
|
475
581
|
sessionDirectory = worktree.path;
|
|
476
582
|
}
|
|
477
583
|
|
|
478
|
-
if (typeof waitForOpenCodeReady === 'function') await waitForOpenCodeReady(10_000, 250);
|
|
479
|
-
|
|
480
584
|
const baseUrl = buildOpenCodeUrl('/', '').replace(/\/$/, '');
|
|
481
585
|
const authHeaders = getOpenCodeAuthHeaders();
|
|
482
586
|
const client = createOpencodeClient({ baseUrl, headers: authHeaders });
|
|
@@ -514,6 +618,7 @@ export const createOpenChamberSessionService = (dependencies) => {
|
|
|
514
618
|
...(prompt && dispatch.agent ? { agent: dispatch.agent } : {}),
|
|
515
619
|
...(prompt && dispatch.variant ? { variant: dispatch.variant } : {}),
|
|
516
620
|
promptDispatched: dispatch.promptDispatched,
|
|
621
|
+
...(dispatch.promptError ? { promptError: dispatch.promptError } : {}),
|
|
517
622
|
dispatchedAsCommand: dispatch.dispatchedAsCommand,
|
|
518
623
|
...(goalInput.enabled ? { goalEnabled: true } : {}),
|
|
519
624
|
...(goalInput.tokenBudget ? { goalTokenBudget: goalInput.tokenBudget } : {}),
|
|
@@ -566,6 +671,13 @@ export const createOpenChamberSessionService = (dependencies) => {
|
|
|
566
671
|
directory = resolvedDirectory.directory;
|
|
567
672
|
if (typeof waitForOpenCodeReady === 'function') await waitForOpenCodeReady(10_000, 250);
|
|
568
673
|
|
|
674
|
+
await validateRequestedSelection({
|
|
675
|
+
directory,
|
|
676
|
+
requestedModel,
|
|
677
|
+
requestedAgent: asNonEmptyString(payload.agent),
|
|
678
|
+
requestedVariant: asNonEmptyString(payload.variant),
|
|
679
|
+
});
|
|
680
|
+
|
|
569
681
|
const baseUrl = buildOpenCodeUrl('/', '').replace(/\/$/, '');
|
|
570
682
|
const authHeaders = getOpenCodeAuthHeaders();
|
|
571
683
|
const client = createOpencodeClient({ baseUrl, headers: authHeaders });
|
|
@@ -608,7 +720,8 @@ export const createOpenChamberSessionService = (dependencies) => {
|
|
|
608
720
|
model: dispatch.model,
|
|
609
721
|
...(dispatch.agent ? { agent: dispatch.agent } : {}),
|
|
610
722
|
...(dispatch.variant ? { variant: dispatch.variant } : {}),
|
|
611
|
-
promptDispatched:
|
|
723
|
+
promptDispatched: dispatch.promptDispatched,
|
|
724
|
+
...(dispatch.promptError ? { promptError: dispatch.promptError } : {}),
|
|
612
725
|
dispatchedAsCommand: dispatch.dispatchedAsCommand,
|
|
613
726
|
...(goalInput.enabled ? { goalEnabled: true } : {}),
|
|
614
727
|
...(goalInput.tokenBudget ? { goalTokenBudget: goalInput.tokenBudget } : {}),
|
|
@@ -624,7 +737,7 @@ export const createOpenChamberSessionService = (dependencies) => {
|
|
|
624
737
|
model: dispatch.model,
|
|
625
738
|
...(dispatch.agent ? { agent: dispatch.agent } : {}),
|
|
626
739
|
...(dispatch.variant ? { variant: dispatch.variant } : {}),
|
|
627
|
-
promptDispatched:
|
|
740
|
+
promptDispatched: dispatch.promptDispatched,
|
|
628
741
|
dispatchedAsCommand: dispatch.dispatchedAsCommand,
|
|
629
742
|
...(goalInput.enabled ? { goalEnabled: true } : {}),
|
|
630
743
|
...(goalInput.tokenBudget ? { goalTokenBudget: goalInput.tokenBudget } : {}),
|
|
@@ -11,6 +11,53 @@ const createWorktreeMock = vi.fn(async () => ({
|
|
|
11
11
|
const sessionCreateMock = vi.fn(async () => ({ data: { id: 'ses_123' } }));
|
|
12
12
|
const sessionForkMock = vi.fn(async () => ({ data: { id: 'ses_fork', title: 'Forked session' } }));
|
|
13
13
|
const sessionMessagesMock = vi.fn(async () => ({ data: [] }));
|
|
14
|
+
|
|
15
|
+
let existingSessionMessages = [];
|
|
16
|
+
let dispatchedUserMessageSeq = 0;
|
|
17
|
+
|
|
18
|
+
// The service confirms a prompt landed by watching for a new user message, so
|
|
19
|
+
// the default mock behaves like OpenCode recording each dispatched prompt.
|
|
20
|
+
const setSessionMessages = (messages) => {
|
|
21
|
+
existingSessionMessages = messages;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const recordedSessionMessages = async () => {
|
|
25
|
+
dispatchedUserMessageSeq += 1;
|
|
26
|
+
return {
|
|
27
|
+
data: [
|
|
28
|
+
...existingSessionMessages,
|
|
29
|
+
{
|
|
30
|
+
info: {
|
|
31
|
+
id: `msg_dispatched_${dispatchedUserMessageSeq}`,
|
|
32
|
+
role: 'user',
|
|
33
|
+
time: { created: 1000 + dispatchedUserMessageSeq },
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// Selection inputs are fetched whenever a request names a model, agent, or
|
|
41
|
+
// variant, so every prompt-dispatching fetch mock must answer them.
|
|
42
|
+
const selectionInputResponse = (url) => {
|
|
43
|
+
const text = String(url);
|
|
44
|
+
if (text.includes('/config/providers')) {
|
|
45
|
+
return {
|
|
46
|
+
ok: true,
|
|
47
|
+
json: async () => ({
|
|
48
|
+
providers: [
|
|
49
|
+
{ id: 'openai', models: [{ id: 'gpt-5.5', variants: { high: {} } }] },
|
|
50
|
+
{ id: 'anthropic', models: [{ id: 'claude-sonnet-5', variants: { high: {} } }] },
|
|
51
|
+
],
|
|
52
|
+
}),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
if (text.includes('/agent')) {
|
|
56
|
+
return { ok: true, json: async () => [{ name: 'build', mode: 'primary' }, { name: 'plan', mode: 'primary' }] };
|
|
57
|
+
}
|
|
58
|
+
if (text.includes('/config')) return { ok: true, json: async () => ({}) };
|
|
59
|
+
return null;
|
|
60
|
+
};
|
|
14
61
|
const sessionCommandMock = vi.fn(async () => ({ data: {} }));
|
|
15
62
|
const commandListMock = vi.fn(async () => ({ data: [] }));
|
|
16
63
|
globalThis.__openchamberCreateWorktreeMock = createWorktreeMock;
|
|
@@ -62,8 +109,10 @@ describe('openchamber session routes', () => {
|
|
|
62
109
|
createWorktreeMock.mockClear();
|
|
63
110
|
sessionCreateMock.mockClear();
|
|
64
111
|
sessionForkMock.mockClear();
|
|
112
|
+
existingSessionMessages = [];
|
|
113
|
+
dispatchedUserMessageSeq = 0;
|
|
65
114
|
sessionMessagesMock.mockReset();
|
|
66
|
-
sessionMessagesMock.
|
|
115
|
+
sessionMessagesMock.mockImplementation(recordedSessionMessages);
|
|
67
116
|
sessionCommandMock.mockReset();
|
|
68
117
|
sessionCommandMock.mockResolvedValue({ data: {} });
|
|
69
118
|
commandListMock.mockReset();
|
|
@@ -319,13 +368,11 @@ describe('openchamber session routes', () => {
|
|
|
319
368
|
|
|
320
369
|
it('sends a goal prompt to an existing session after creating goal metadata', async () => {
|
|
321
370
|
const originalFetch = globalThis.fetch;
|
|
322
|
-
const fetchMock = vi.fn(async () => ({ ok: true, text: async () => '' })
|
|
371
|
+
const fetchMock = vi.fn(async (url) => selectionInputResponse(url) || { ok: true, text: async () => '' });
|
|
323
372
|
const createSessionGoal = vi.fn(async () => undefined);
|
|
324
373
|
globalThis.fetch = fetchMock;
|
|
325
374
|
try {
|
|
326
|
-
|
|
327
|
-
data: [{ info: { id: 'msg_before', role: 'assistant', time: { created: 10, completed: 20 } } }],
|
|
328
|
-
});
|
|
375
|
+
setSessionMessages([{ info: { id: 'msg_before', role: 'assistant', time: { created: 10, completed: 20 } } }]);
|
|
329
376
|
const { app } = createApp({ createSessionGoal });
|
|
330
377
|
const response = await request(app)
|
|
331
378
|
.post('/api/openchamber/sessions/ses_source/send')
|
|
@@ -370,7 +417,7 @@ describe('openchamber session routes', () => {
|
|
|
370
417
|
template: 'Take $ARGUMENTS from issue through a verified pull request. Confirm the PR covers $ARGUMENTS.',
|
|
371
418
|
}],
|
|
372
419
|
});
|
|
373
|
-
globalThis.fetch = vi.fn();
|
|
420
|
+
globalThis.fetch = vi.fn(async (url) => selectionInputResponse(url));
|
|
374
421
|
try {
|
|
375
422
|
const { app } = createApp({ createSessionGoal });
|
|
376
423
|
const response = await request(app)
|
|
@@ -393,7 +440,7 @@ describe('openchamber session routes', () => {
|
|
|
393
440
|
}));
|
|
394
441
|
expect(createSessionGoal.mock.invocationCallOrder[0]).toBeLessThan(sessionCommandMock.mock.invocationCallOrder[0]);
|
|
395
442
|
expect(response.body).toMatchObject({ goalEnabled: true, dispatchedAsCommand: true });
|
|
396
|
-
expect(globalThis.fetch).
|
|
443
|
+
expect(globalThis.fetch.mock.calls.some(([url]) => String(url).includes('/prompt_async'))).toBe(false);
|
|
397
444
|
} finally {
|
|
398
445
|
globalThis.fetch = originalFetch;
|
|
399
446
|
}
|
|
@@ -401,11 +448,10 @@ describe('openchamber session routes', () => {
|
|
|
401
448
|
|
|
402
449
|
it('reuses the previous session selection when send omits model, agent, and variant', async () => {
|
|
403
450
|
const originalFetch = globalThis.fetch;
|
|
404
|
-
const fetchMock = vi.fn(async () => ({ ok: true, text: async () => '' })
|
|
451
|
+
const fetchMock = vi.fn(async (url) => selectionInputResponse(url) || { ok: true, text: async () => '' });
|
|
405
452
|
globalThis.fetch = fetchMock;
|
|
406
453
|
try {
|
|
407
|
-
|
|
408
|
-
data: [
|
|
454
|
+
setSessionMessages([
|
|
409
455
|
{
|
|
410
456
|
info: {
|
|
411
457
|
id: 'msg_user',
|
|
@@ -416,8 +462,7 @@ describe('openchamber session routes', () => {
|
|
|
416
462
|
},
|
|
417
463
|
},
|
|
418
464
|
{ info: { id: 'msg_before', role: 'assistant', time: { created: 10, completed: 20 } } },
|
|
419
|
-
|
|
420
|
-
});
|
|
465
|
+
]);
|
|
421
466
|
const { app } = createApp();
|
|
422
467
|
const response = await request(app)
|
|
423
468
|
.post('/api/openchamber/sessions/ses_source/send')
|
|
@@ -449,7 +494,7 @@ describe('openchamber session routes', () => {
|
|
|
449
494
|
it('forks from a message, dispatches the prompt, and emits the new session', async () => {
|
|
450
495
|
const originalFetch = globalThis.fetch;
|
|
451
496
|
const emitSessionCreatedEvent = vi.fn();
|
|
452
|
-
globalThis.fetch = vi.fn(async () => ({ ok: true, text: async () => '' })
|
|
497
|
+
globalThis.fetch = vi.fn(async (url) => selectionInputResponse(url) || { ok: true, text: async () => '' });
|
|
453
498
|
try {
|
|
454
499
|
const { app } = createApp({ emitSessionCreatedEvent });
|
|
455
500
|
const response = await request(app)
|
|
@@ -519,7 +564,7 @@ describe('openchamber session routes', () => {
|
|
|
519
564
|
|
|
520
565
|
it('reports the forked session when prompt dispatch fails', async () => {
|
|
521
566
|
const originalFetch = globalThis.fetch;
|
|
522
|
-
globalThis.fetch = vi.fn(async () => ({ ok: false, status: 500, text: async () => 'dispatch failed' })
|
|
567
|
+
globalThis.fetch = vi.fn(async (url) => selectionInputResponse(url) || { ok: false, status: 500, text: async () => 'dispatch failed' });
|
|
523
568
|
try {
|
|
524
569
|
const { app } = createApp();
|
|
525
570
|
const response = await request(app)
|
|
@@ -584,9 +629,77 @@ describe('openchamber session routes', () => {
|
|
|
584
629
|
}
|
|
585
630
|
});
|
|
586
631
|
|
|
632
|
+
it('rejects an unknown agent before creating a session or worktree', async () => {
|
|
633
|
+
const originalFetch = globalThis.fetch;
|
|
634
|
+
const fetchMock = vi.fn(async (url) => selectionInputResponse(url) || { ok: true, json: async () => ({ id: 'ses_123' }) });
|
|
635
|
+
globalThis.fetch = fetchMock;
|
|
636
|
+
try {
|
|
637
|
+
const { app } = createApp();
|
|
638
|
+
await request(app)
|
|
639
|
+
.post('/api/openchamber/sessions')
|
|
640
|
+
.send({
|
|
641
|
+
directory: '/repo/app',
|
|
642
|
+
prompt: 'Run this',
|
|
643
|
+
agent: 'not-an-agent',
|
|
644
|
+
worktree: { name: 'side-task' },
|
|
645
|
+
})
|
|
646
|
+
.expect(400, { error: "Unknown agent 'not-an-agent' for /repo/app" });
|
|
647
|
+
|
|
648
|
+
expect(createWorktreeMock).not.toHaveBeenCalled();
|
|
649
|
+
expect(fetchMock.mock.calls.some(([url]) => String(url) === 'http://opencode.test/session?directory=%2Frepo%2Fapp')).toBe(false);
|
|
650
|
+
expect(fetchMock.mock.calls.some(([url]) => String(url).includes('/prompt_async'))).toBe(false);
|
|
651
|
+
} finally {
|
|
652
|
+
globalThis.fetch = originalFetch;
|
|
653
|
+
}
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
it('rejects an unknown model and an unknown variant before dispatching', async () => {
|
|
657
|
+
const originalFetch = globalThis.fetch;
|
|
658
|
+
const fetchMock = vi.fn(async (url) => selectionInputResponse(url) || { ok: true, json: async () => ({ id: 'ses_123' }) });
|
|
659
|
+
globalThis.fetch = fetchMock;
|
|
660
|
+
try {
|
|
661
|
+
const { app } = createApp();
|
|
662
|
+
await request(app)
|
|
663
|
+
.post('/api/openchamber/sessions')
|
|
664
|
+
.send({ directory: '/repo/app', prompt: 'Run this', model: 'openai/gpt-nope' })
|
|
665
|
+
.expect(400, { error: "Unknown model 'openai/gpt-nope' for /repo/app" });
|
|
666
|
+
await request(app)
|
|
667
|
+
.post('/api/openchamber/sessions')
|
|
668
|
+
.send({ directory: '/repo/app', prompt: 'Run this', model: 'openai/gpt-5.5', variant: 'ultra' })
|
|
669
|
+
.expect(400, { error: "Unknown variant 'ultra' for model 'openai/gpt-5.5'" });
|
|
670
|
+
|
|
671
|
+
expect(fetchMock.mock.calls.some(([url]) => String(url).includes('/prompt_async'))).toBe(false);
|
|
672
|
+
} finally {
|
|
673
|
+
globalThis.fetch = originalFetch;
|
|
674
|
+
}
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
it('reports promptDispatched false when the accepted prompt never reaches the session', async () => {
|
|
678
|
+
const originalFetch = globalThis.fetch;
|
|
679
|
+
const fetchMock = vi.fn(async (url) => {
|
|
680
|
+
if (String(url).includes('/prompt_async')) return { ok: true, text: async () => '' };
|
|
681
|
+
return selectionInputResponse(url) || { ok: true, json: async () => ({ id: 'ses_123' }) };
|
|
682
|
+
});
|
|
683
|
+
globalThis.fetch = fetchMock;
|
|
684
|
+
sessionMessagesMock.mockResolvedValue({ data: [] });
|
|
685
|
+
try {
|
|
686
|
+
const { app } = createApp();
|
|
687
|
+
const response = await request(app)
|
|
688
|
+
.post('/api/openchamber/sessions')
|
|
689
|
+
.send({ directory: '/repo/app', prompt: 'Run this', model: 'openai/gpt-5.5' })
|
|
690
|
+
.expect(200);
|
|
691
|
+
|
|
692
|
+
expect(response.body.sessionId).toBe('ses_123');
|
|
693
|
+
expect(response.body.promptDispatched).toBe(false);
|
|
694
|
+
expect(response.body.promptError).toBeTruthy();
|
|
695
|
+
} finally {
|
|
696
|
+
globalThis.fetch = originalFetch;
|
|
697
|
+
}
|
|
698
|
+
}, 20_000);
|
|
699
|
+
|
|
587
700
|
it('does not retry a failed slash command as a normal prompt', async () => {
|
|
588
701
|
const originalFetch = globalThis.fetch;
|
|
589
|
-
const fetchMock = vi.fn();
|
|
702
|
+
const fetchMock = vi.fn(async (url) => selectionInputResponse(url));
|
|
590
703
|
commandListMock.mockResolvedValue({ data: [{ name: 'review' }] });
|
|
591
704
|
sessionCommandMock.mockRejectedValue(new Error('command response failed'));
|
|
592
705
|
globalThis.fetch = fetchMock;
|
|
@@ -604,7 +717,7 @@ describe('openchamber session routes', () => {
|
|
|
604
717
|
.expect(500);
|
|
605
718
|
|
|
606
719
|
expect(sessionCommandMock).toHaveBeenCalledTimes(1);
|
|
607
|
-
expect(fetchMock).
|
|
720
|
+
expect(fetchMock.mock.calls.some(([url]) => String(url).includes('/prompt_async'))).toBe(false);
|
|
608
721
|
} finally {
|
|
609
722
|
globalThis.fetch = originalFetch;
|
|
610
723
|
}
|
|
@@ -375,6 +375,8 @@ an authoritative loopback callback URL even when OpenChamber binds port `0`.
|
|
|
375
375
|
- SSE forwarders: `GET /api/global/event`, `GET /api/event`
|
|
376
376
|
- Downstream heartbeats keep clients and intermediaries alive, while a separate upstream-only stall watchdog closes the downstream response when OpenCode stops producing bytes so clients reconnect instead of trusting synthetic heartbeats indefinitely. Each watchdog reset uses the current load-aware timeout, matching the shared event transport.
|
|
377
377
|
- Session message forwarder: `POST /api/session/:sessionId/message`
|
|
378
|
+
- Interactive OAuth forwarder: `POST /api/provider/:providerID/oauth/callback`
|
|
379
|
+
- Upstream blocks inside this call for the whole browser sign-in (device-code polling or a loopback redirect), so it is exempt from the ordinary request deadline and uses a 15-minute proxy timeout instead of `LONG_REQUEST_TIMEOUT_MS`. All other `/api/provider/*` routes, including `oauth/authorize`, keep the ordinary deadline.
|
|
378
380
|
- Generic `/api/*` forwarding with hop-by-hop header filtering
|
|
379
381
|
- Windows `/session` merge fallback path behavior
|
|
380
382
|
- OpenCode readiness gate for proxied `/api` requests
|
|
@@ -309,6 +309,16 @@ export const registerOpenCodeProxy = (app, deps) => {
|
|
|
309
309
|
const PROXY_REQUEST_TIMEOUT_MS = normalizeProxyTimeout(LONG_REQUEST_TIMEOUT_MS);
|
|
310
310
|
const PROXY_TIMEOUT_MARKER = Symbol('openchamberProxyTimedOut');
|
|
311
311
|
|
|
312
|
+
// A provider OAuth callback blocks upstream for as long as the user takes to
|
|
313
|
+
// sign in in their browser (device-code polling, or a loopback redirect), so
|
|
314
|
+
// it cannot share the ordinary request deadline. Bounded by the shortest
|
|
315
|
+
// upstream expiry we know of — GitHub device codes last ~15 minutes.
|
|
316
|
+
const INTERACTIVE_OAUTH_TIMEOUT_MS = 15 * 60 * 1000;
|
|
317
|
+
const INTERACTIVE_OAUTH_PATH = /^\/provider\/[^/]+\/oauth\/callback\/?$/;
|
|
318
|
+
|
|
319
|
+
const isInteractiveOAuthCallback = (req) =>
|
|
320
|
+
req.method === 'POST' && INTERACTIVE_OAUTH_PATH.test(req.path);
|
|
321
|
+
|
|
312
322
|
const isProxyTimeoutError = (error) => {
|
|
313
323
|
const code = typeof error?.code === 'string' ? error.code : '';
|
|
314
324
|
const message = typeof error?.message === 'string' ? error.message.toLowerCase() : '';
|
|
@@ -327,6 +337,10 @@ export const registerOpenCodeProxy = (app, deps) => {
|
|
|
327
337
|
};
|
|
328
338
|
|
|
329
339
|
const applyProxyResponseDeadline = (req, res, next) => {
|
|
340
|
+
if (isInteractiveOAuthCallback(req)) {
|
|
341
|
+
return next();
|
|
342
|
+
}
|
|
343
|
+
|
|
330
344
|
const timeout = setTimeout(() => {
|
|
331
345
|
req[PROXY_TIMEOUT_MARKER] = true;
|
|
332
346
|
if (sendProxyErrorResponse(res, 504)) {
|
|
@@ -753,12 +767,12 @@ export const registerOpenCodeProxy = (app, deps) => {
|
|
|
753
767
|
});
|
|
754
768
|
|
|
755
769
|
// Generic proxy for non-SSE OpenCode API routes.
|
|
756
|
-
const
|
|
770
|
+
const createApiProxy = (timeoutMs) => createProxyMiddleware({
|
|
757
771
|
target: resolveProxyTarget(),
|
|
758
772
|
changeOrigin: true,
|
|
759
773
|
pathRewrite: { '^/api': '' },
|
|
760
|
-
timeout:
|
|
761
|
-
proxyTimeout:
|
|
774
|
+
timeout: timeoutMs,
|
|
775
|
+
proxyTimeout: timeoutMs,
|
|
762
776
|
// Dynamic target — port can change after restart
|
|
763
777
|
router: () => resolveProxyTarget(),
|
|
764
778
|
on: {
|
|
@@ -805,6 +819,9 @@ export const registerOpenCodeProxy = (app, deps) => {
|
|
|
805
819
|
},
|
|
806
820
|
});
|
|
807
821
|
|
|
822
|
+
const apiProxy = createApiProxy(PROXY_REQUEST_TIMEOUT_MS);
|
|
823
|
+
const interactiveOAuthProxy = createApiProxy(INTERACTIVE_OAUTH_TIMEOUT_MS);
|
|
824
|
+
|
|
808
825
|
// Best-effort fallback for stale clients still sending symlink paths.
|
|
809
826
|
// Settings and project selection normalize at source; this cached async path
|
|
810
827
|
// avoids blocking the proxy hot path on every directory-scoped request.
|
|
@@ -821,5 +838,6 @@ export const registerOpenCodeProxy = (app, deps) => {
|
|
|
821
838
|
});
|
|
822
839
|
|
|
823
840
|
app.use('/api', applyProxyResponseDeadline);
|
|
841
|
+
app.post('/api/provider/:providerID/oauth/callback', interactiveOAuthProxy);
|
|
824
842
|
app.use('/api', apiProxy);
|
|
825
843
|
};
|
|
@@ -69,10 +69,17 @@ other runtime API.
|
|
|
69
69
|
- `timeoutMs` overrides the 60s default per call; `signal` lets a caller abort
|
|
70
70
|
a request that is no longer wanted. Both apply to every wire format.
|
|
71
71
|
- `describeSmallModel()` additionally reports `inputCharBudget`,
|
|
72
|
-
`contextTokens`, `contextKnown`, and `
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
`contextTokens`, `contextKnown`, `structuredOutput`, and `hasLogin`. The last
|
|
73
|
+
is whether the resolved provider has a usable credential (`auth.json` or
|
|
74
|
+
config `provider.<id>.options.apiKey`) — settings/config overrides can name a
|
|
75
|
+
provider with none, and callers such as the walkthrough refuse before the
|
|
76
|
+
request. `structuredOutput` is tri-state: `true`/`false` from the catalog,
|
|
77
|
+
`null` when the catalog omits the field — which it does for roughly half of
|
|
78
|
+
all models, aggregators and proxies especially. Callers must treat `null` as
|
|
79
|
+
"try it", not "unsupported".
|
|
80
|
+
- Missing credentials throw with `statusCode: 401` and
|
|
81
|
+
`code: 'no-provider-login'` rather than a bare `Error`, so UI callers can show
|
|
82
|
+
a blocker instead of a raw 500 message.
|
|
76
83
|
- `call.js` — wire formats and per-provider auth, replicating OpenCode's
|
|
77
84
|
plugin auth loaders:
|
|
78
85
|
- **GitHub Copilot**: fetches the requested model's authenticated `/models`
|
|
@@ -566,15 +566,31 @@ const readProviderConfig = (workingDirectory, providerID) => {
|
|
|
566
566
|
// Dispatch
|
|
567
567
|
// ---------------------------------------------------------------------------
|
|
568
568
|
|
|
569
|
+
/**
|
|
570
|
+
* Same credential resolution the request path uses: config
|
|
571
|
+
* `provider.<id>.options.apiKey` wins, then the auth.json entry.
|
|
572
|
+
* Callers that need to refuse before spending a request (walkthrough readiness)
|
|
573
|
+
* must use this rather than inventing a second rule.
|
|
574
|
+
*/
|
|
575
|
+
export function resolveProviderLogin({ auth, workingDirectory, providerID }) {
|
|
576
|
+
const providerConfig = readProviderConfig(workingDirectory, providerID);
|
|
577
|
+
return providerConfig?.auth || getAuthEntryForProvider(auth, providerID) || null;
|
|
578
|
+
}
|
|
579
|
+
|
|
569
580
|
export async function callSmallModel({ auth, catalog, workingDirectory, providerID, modelID, prompt, system, maxOutputTokens, responseSchema, timeoutMs, signal }) {
|
|
570
581
|
const tokens = Number(maxOutputTokens) > 0 ? Number(maxOutputTokens) : DEFAULT_MAX_OUTPUT_TOKENS;
|
|
571
582
|
const providerConfig = readProviderConfig(workingDirectory, providerID);
|
|
572
583
|
// Match OpenCode's resolveSDK precedence:
|
|
573
|
-
// config provider.<id>.options.apiKey
|
|
574
|
-
// auth.json entry is only a fallback.
|
|
584
|
+
// config provider.<id>.options.apiKey wins; the auth.json entry is only a fallback.
|
|
575
585
|
const entry = providerConfig?.auth || getAuthEntryForProvider(auth, providerID);
|
|
576
586
|
if (!entry) {
|
|
577
|
-
|
|
587
|
+
// Structured so the walkthrough (and any other caller) can show a blocker
|
|
588
|
+
// instead of a raw 500 banner with this developer-oriented sentence.
|
|
589
|
+
throw Object.assign(new Error(`No OpenCode login found for provider "${providerID}"`), {
|
|
590
|
+
statusCode: 401,
|
|
591
|
+
code: 'no-provider-login',
|
|
592
|
+
providerID,
|
|
593
|
+
});
|
|
578
594
|
}
|
|
579
595
|
|
|
580
596
|
if (providerID === 'github-copilot') {
|