@openchamber/web 2.0.1 → 2.0.2
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/{CodeMirrorCommentWidgets-zm3C1FvM.js → CodeMirrorCommentWidgets-CmKmyb9T.js} +1 -1
- package/dist/assets/{DiffView-DNExNi1z.js → DiffView-8-PFpZ2p.js} +1 -1
- package/dist/assets/{FilesView-DUCLmHBi.js → FilesView-0Ie20mEk.js} +9 -9
- package/dist/assets/{GitView-Bz9z6gZA.js → GitView-DNUSu00w.js} +1 -1
- package/dist/assets/{GuestAttachDialog-UGp4KDlK.js → GuestAttachDialog-Cv6QzjHC.js} +1 -1
- package/dist/assets/{GuestSurfacePane-B3pdB_2u.js → GuestSurfacePane-Bt3jB_Ye.js} +1 -1
- package/dist/assets/{JsonTreeView-7lVecnZl.js → JsonTreeView-BlyHTRhM.js} +1 -1
- package/dist/assets/{LinearIssuesView-CTGRS9Vq.js → LinearIssuesView-CSl2MUfA.js} +1 -1
- package/dist/assets/MarkdownImageGallery-2UXJF-5B.js +1 -0
- package/dist/assets/MarkdownRendererImpl-DVHqZoug.js +12 -0
- package/dist/assets/{OnboardingScreen-CBx6cXPP.js → OnboardingScreen-CIdXJpfc.js} +1 -1
- package/dist/assets/{PatchDiff-D7VVpR_l.js → PatchDiff-ByvnbG5T.js} +1 -1
- package/dist/assets/{PierreDiffViewer-Gbfks1pk.js → PierreDiffViewer-BXieg0mH.js} +1 -1
- package/dist/assets/{PlanView-CPSK0x97.js → PlanView-DEIi3Q7M.js} +3 -3
- package/dist/assets/PluginPane-BEPUWVho.js +3 -0
- package/dist/assets/{SettingsView-Dql7z6Ww.js → SettingsView-CiNh-RbW.js} +16 -16
- package/dist/assets/{SettingsWindow-D6oi-UmV.js → SettingsWindow-BIz224xs.js} +1 -1
- package/dist/assets/{SubmoduleDiffSummary-BXA0FAWj.js → SubmoduleDiffSummary-CXKmlps9.js} +1 -1
- package/dist/assets/{ToolOutputDialog-BQJsSbDm.js → ToolOutputDialog-BsgAK8xu.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-FY9w0TVT.js → ToolPartDiffPreview-vdPObXOf.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-B9YhAya5.js → VirtualizedFileDiff-BkFNKWS5.js} +1 -1
- package/dist/assets/{WalkthroughView-CmFgOUFN.js → WalkthroughView-6oE-MuDL.js} +2 -2
- package/dist/assets/{appThemeRegistry-BebxalUt.js → appThemeRegistry-aHUNHoqP.js} +1 -1
- package/dist/assets/{commitAndPush-Wfxng_IK.js → commitAndPush-Bon9r94r.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-BCOqgixN.js → computeVirtualFileMetrics-DKqr_1AQ.js} +1 -1
- package/dist/assets/de-CgAJ51z7.js +10 -0
- package/dist/assets/es-zGi_ravM.js +16 -0
- package/dist/assets/fr-CPfogrWx.js +14 -0
- package/dist/assets/index-CHfphYL3.js +41 -0
- package/dist/assets/{index-3TiDNtfN.js → index-DpFttslC.js} +1 -1
- package/dist/assets/index-DvMJ3w6V.css +1 -0
- package/dist/assets/{isDiffPlainText-DnDYQmWK.js → isDiffPlainText-kzAgpIgi.js} +1 -1
- package/dist/assets/{isFilePlainText-BA_AHX7d.js → isFilePlainText-Uj6y-jzz.js} +1 -1
- package/dist/assets/ja-DMk6wd-U.js +16 -0
- package/dist/assets/ko-BFpzJ8jc.js +16 -0
- package/dist/assets/{main-DtUmJp9B.js → main-CbfMxn-I.js} +2 -2
- package/dist/assets/main-anyZFMIs.js +896 -0
- package/dist/assets/{markdownCore-BSnlUXBf.js → markdownCore-CmM47cAE.js} +5 -5
- package/dist/assets/{miniChat-BYfLUnDK.js → miniChat-CiAKBC10.js} +2 -2
- package/dist/assets/{mobile-DH3hI6gd.js → mobile-CsT4sJwC.js} +2 -2
- package/dist/assets/{patchFileDiff--L7lt_GZ.js → patchFileDiff-DeaE08W0.js} +1 -1
- package/dist/assets/{pl-BkI_xHqz.js → pl-VdRPcZrB.js} +5 -5
- package/dist/assets/pt-BR-BRys_lOW.js +16 -0
- package/dist/assets/{renderElectronMiniChatApp-C7kpNW_-.js → renderElectronMiniChatApp-C5677jy0.js} +2 -2
- package/dist/assets/{renderMobileApp-i0nq7Dwy.js → renderMobileApp-D4dBBAqQ.js} +7 -7
- package/dist/assets/runtimeEndpointReset-5r0hkd-2.js +27 -0
- package/dist/assets/{scheduledTasksApi-Cy7uZCaI.js → scheduledTasksApi-BZCNJ588.js} +1 -1
- package/dist/assets/{shikiHighlight-D4vxipfr.js → shikiHighlight-BSUEa3yF.js} +1 -1
- package/dist/assets/{textMateThemeFromAppTheme-BYAHtJwQ.js → textMateThemeFromAppTheme-CsATFZIV.js} +1 -1
- package/dist/assets/tr-CA9ckNnm.js +7 -0
- package/dist/assets/uk-byjR-y8D.js +16 -0
- package/dist/assets/{useAppFontEffects-DHZ9-L30.js → useAppFontEffects-BWQZ5DeI.js} +153 -150
- package/dist/assets/{useInlineCommentController-CvpOMK-R.js → useInlineCommentController-DlFyVfBu.js} +1 -1
- package/dist/assets/{useRootScrollLock-DzNFi-fn.js → useRootScrollLock-Cp1eFoM2.js} +2 -2
- package/dist/assets/{vendor-codemirror-language-data-j3fhlwUM.js → vendor-codemirror-language-data-BwwommM0.js} +2 -2
- package/dist/assets/{web-components-BvHNFSEG.js → web-components-D3Yjr4Zx.js} +1 -1
- package/dist/assets/zh-CN-DRabgxdG.js +16 -0
- package/dist/assets/zh-TW-rbY5c9UK.js +16 -0
- package/dist/index.html +3 -3
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +2 -2
- package/server/index.js +64 -0
- package/server/lib/event-stream/global-hub.js +23 -1
- package/server/lib/event-stream/global-hub.test.js +35 -0
- package/server/lib/event-stream/global-ws-bridge.js +3 -1
- package/server/lib/event-stream/upstream-reader.js +3 -2
- package/server/lib/opencode/DOCUMENTATION.md +6 -2
- package/server/lib/opencode/bootstrap-runtime.js +2 -1
- package/server/lib/opencode/config-entity-v2.test.js +27 -0
- package/server/lib/opencode/config-paths.test.js +12 -0
- package/server/lib/opencode/core-routes.js +17 -4
- package/server/lib/opencode/core-routes.test.js +26 -0
- package/server/lib/opencode/mcp.js +7 -2
- package/server/lib/opencode/project-directory-runtime.js +8 -0
- package/server/lib/opencode/project-directory-runtime.test.js +13 -0
- package/server/lib/opencode/proxy.js +38 -2
- package/server/lib/opencode/routes.js +18 -0
- package/server/lib/opencode/server-utils-runtime.js +5 -0
- package/server/lib/opencode/settings-helpers.js +3 -0
- package/server/lib/opencode/settings-helpers.test.js +1 -1
- package/server/lib/opencode/settings-registry.json +3 -0
- package/server/lib/opencode/shared.js +17 -2
- package/server/lib/opencode/shutdown-runtime.js +3 -0
- package/server/lib/opencode/watcher.js +3 -1
- package/server/lib/realtime-proxy.js +5 -1
- package/server/lib/realtime-proxy.test.js +29 -0
- package/server/lib/relay/tunnel-host.js +4 -1
- package/server/lib/relay/tunnel-host.test.js +11 -0
- package/server/lib/small-model/DOCUMENTATION.md +11 -10
- package/server/lib/small-model/index.js +27 -32
- package/server/lib/small-model/index.test.js +28 -16
- package/server/lib/spaces/DOCUMENTATION.md +381 -20
- package/server/lib/spaces/code-in-bait.js +145 -6
- package/server/lib/spaces/code-in.js +10 -150
- package/server/lib/spaces/code-in.test.js +7 -83
- package/server/lib/spaces/code-out.js +1819 -0
- package/server/lib/spaces/code-out.test.js +3945 -0
- package/server/lib/spaces/code-transfer.js +173 -0
- package/server/lib/spaces/command-stream.test.js +181 -0
- package/server/lib/spaces/dispatcher.js +670 -0
- package/server/lib/spaces/dispatcher.test.js +582 -0
- package/server/lib/spaces/gatekeeper-channel.js +2 -0
- package/server/lib/spaces/gatekeeper-channel.test.js +9 -3
- package/server/lib/spaces/gatekeeper-program.cjs +4 -1
- package/server/lib/spaces/gatekeeper-program.test.js +3 -0
- package/server/lib/spaces/hardening.js +20 -4
- package/server/lib/spaces/hardening.test.js +18 -3
- package/server/lib/spaces/host-git.js +7 -4
- package/server/lib/spaces/host-git.test.js +6 -2
- package/server/lib/spaces/host.js +304 -0
- package/server/lib/spaces/host.test.js +273 -0
- package/server/lib/spaces/journey.js +393 -0
- package/server/lib/spaces/journey.test.js +384 -0
- package/server/lib/spaces/layout.js +26 -2
- package/server/lib/spaces/manager.js +4 -3
- package/server/lib/spaces/manager.test.js +6 -0
- package/server/lib/spaces/places/code-out.docker.live.test.js +412 -0
- package/server/lib/spaces/places/contract-suite.js +36 -0
- package/server/lib/spaces/places/dispatcher.docker.live.test.js +296 -0
- package/server/lib/spaces/places/docker.js +15 -3
- package/server/lib/spaces/places/docker.test.js +33 -2
- package/server/lib/spaces/places/escape-suite.js +86 -14
- package/server/lib/spaces/places/memory-place.js +24 -1
- package/server/lib/spaces/places/registry.js +1 -1
- package/server/lib/spaces/places/server.docker.live.test.js +69 -33
- package/server/lib/spaces/places/sessions.docker.live.test.js +220 -0
- package/server/lib/spaces/routes.js +207 -0
- package/server/lib/spaces/routes.test.js +211 -0
- package/server/lib/spaces/run-command.js +261 -8
- package/server/lib/spaces/run-command.test.js +193 -3
- package/server/lib/spaces/space-events.js +153 -0
- package/server/lib/spaces/space-events.test.js +160 -0
- package/server/lib/spaces/space-records.js +98 -0
- package/server/lib/spaces/space-records.test.js +73 -0
- package/server/lib/spaces/space-sessions.js +210 -0
- package/server/lib/spaces/space-sessions.test.js +161 -0
- package/server/lib/spaces/websocket.js +329 -0
- package/server/lib/spaces/websocket.test.js +345 -0
- package/server/lib/ui-auth/ui-auth.js +8 -2
- package/server/lib/ui-auth/ui-auth.test.js +29 -0
- package/server/opencode-proxy.test.js +113 -0
- package/dist/assets/MarkdownImageGallery-DQk5adUs.js +0 -1
- package/dist/assets/MarkdownRendererImpl-DPF8fZpX.js +0 -12
- package/dist/assets/PluginPane-BIGsUx69.js +0 -3
- package/dist/assets/de-CMA45TC-.js +0 -10
- package/dist/assets/es-DPL4fBtl.js +0 -16
- package/dist/assets/fr-OHBKBseP.js +0 -14
- package/dist/assets/index-BLUZa5u0.js +0 -41
- package/dist/assets/index-Cm2rrq69.css +0 -1
- package/dist/assets/ja-DvX4WSRf.js +0 -16
- package/dist/assets/ko-BUcLd8YZ.js +0 -16
- package/dist/assets/main-B_jri4i-.js +0 -896
- package/dist/assets/pt-BR-7wFtQlV9.js +0 -16
- package/dist/assets/runtimeEndpointReset-CfEYbcCc.js +0 -27
- package/dist/assets/tr-TsD-AqEH.js +0 -7
- package/dist/assets/uk-B-qspCmD.js +0 -16
- package/dist/assets/zh-CN-DYuPJV5i.js +0 -16
- package/dist/assets/zh-TW-BX_2D_lV.js +0 -16
|
@@ -236,7 +236,7 @@ const SESSION_LIST_ALLOWED_FIELDS = [
|
|
|
236
236
|
'fork',
|
|
237
237
|
];
|
|
238
238
|
|
|
239
|
-
const sanitizeSessionListItem = (session) => {
|
|
239
|
+
export const sanitizeSessionListItem = (session) => {
|
|
240
240
|
if (!session || typeof session !== 'object' || Array.isArray(session)) {
|
|
241
241
|
return session;
|
|
242
242
|
}
|
|
@@ -307,6 +307,11 @@ export const registerOpenCodeProxy = (app, deps) => {
|
|
|
307
307
|
// migrated.
|
|
308
308
|
getArchivedSessions = null,
|
|
309
309
|
getStoredSessionMetadata = null,
|
|
310
|
+
// Isolated spaces, when the feature's switch is on: the merged session list, and the hub
|
|
311
|
+
// whose space events the global SSE stream carries beside the host's. Both absent means
|
|
312
|
+
// the host's own answers go out exactly as before spaces.
|
|
313
|
+
mergeSpaceSessionList = null,
|
|
314
|
+
spaceEventHub = null,
|
|
310
315
|
} = deps;
|
|
311
316
|
|
|
312
317
|
/**
|
|
@@ -550,6 +555,7 @@ export const registerOpenCodeProxy = (app, deps) => {
|
|
|
550
555
|
let heartbeatTimer = null;
|
|
551
556
|
let upstreamStallTimer = null;
|
|
552
557
|
let didUpstreamStall = false;
|
|
558
|
+
let unsubscribeSpaceEvents = null;
|
|
553
559
|
let writeQueue = Promise.resolve(true);
|
|
554
560
|
const sseBoundary = createSseBoundaryTracker();
|
|
555
561
|
|
|
@@ -644,6 +650,26 @@ export const registerOpenCodeProxy = (app, deps) => {
|
|
|
644
650
|
return writeQueue;
|
|
645
651
|
};
|
|
646
652
|
|
|
653
|
+
// The events of isolated spaces ride the global stream too, one block each, written
|
|
654
|
+
// only between the upstream's own blocks so a block of the host's is never cut.
|
|
655
|
+
// A directory in the query or in the header scopes the stream to the host's one directory.
|
|
656
|
+
const isGlobalStream = !new URL(requestUrl, 'http://localhost').searchParams.get('directory') && !req.get('x-opencode-directory');
|
|
657
|
+
const pendingSpaceBlocks = [];
|
|
658
|
+
const flushSpaceBlocks = async () => {
|
|
659
|
+
while (pendingSpaceBlocks.length > 0 && sseBoundary.isAtBoundary() && !abortController.signal.aborted) {
|
|
660
|
+
const canContinue = await enqueueSseWrite(pendingSpaceBlocks.shift());
|
|
661
|
+
if (!canContinue) return false;
|
|
662
|
+
}
|
|
663
|
+
return true;
|
|
664
|
+
};
|
|
665
|
+
if (spaceEventHub && isGlobalStream) {
|
|
666
|
+
unsubscribeSpaceEvents = spaceEventHub.subscribeEvent((event) => {
|
|
667
|
+
if (event.spaceId === null) return;
|
|
668
|
+
pendingSpaceBlocks.push(`data: ${JSON.stringify(event.payload)}\n\n`);
|
|
669
|
+
void flushSpaceBlocks();
|
|
670
|
+
}, { spaces: true });
|
|
671
|
+
}
|
|
672
|
+
|
|
647
673
|
scheduleHeartbeat();
|
|
648
674
|
resetUpstreamStallTimer();
|
|
649
675
|
|
|
@@ -660,6 +686,9 @@ export const registerOpenCodeProxy = (app, deps) => {
|
|
|
660
686
|
if (!canContinue) {
|
|
661
687
|
break;
|
|
662
688
|
}
|
|
689
|
+
if (!await flushSpaceBlocks()) {
|
|
690
|
+
break;
|
|
691
|
+
}
|
|
663
692
|
}
|
|
664
693
|
}
|
|
665
694
|
|
|
@@ -679,6 +708,7 @@ export const registerOpenCodeProxy = (app, deps) => {
|
|
|
679
708
|
res.end();
|
|
680
709
|
}
|
|
681
710
|
} finally {
|
|
711
|
+
unsubscribeSpaceEvents?.();
|
|
682
712
|
if (heartbeatTimer) {
|
|
683
713
|
clearTimeout(heartbeatTimer);
|
|
684
714
|
heartbeatTimer = null;
|
|
@@ -763,7 +793,13 @@ export const registerOpenCodeProxy = (app, deps) => {
|
|
|
763
793
|
}
|
|
764
794
|
|
|
765
795
|
res.setHeader('content-type', result.contentType);
|
|
766
|
-
|
|
796
|
+
const hostList = await overlayOwnedStateOnList(sanitizeSessionListPayload(result.payload));
|
|
797
|
+
// The first page of the global list carries every space's sessions after the host's; a
|
|
798
|
+
// later page, and a list scoped to one directory, are the host's alone.
|
|
799
|
+
const listQuery = new URL(upstreamPath, 'http://localhost').searchParams;
|
|
800
|
+
const scopedToDirectory = Boolean(listQuery.get('directory') || req.get('x-opencode-directory'));
|
|
801
|
+
const wantsSpaces = typeof mergeSpaceSessionList === 'function' && !listQuery.get('cursor') && !scopedToDirectory;
|
|
802
|
+
res.json(wantsSpaces ? await mergeSpaceSessionList(hostList) : hostList);
|
|
767
803
|
} catch (error) {
|
|
768
804
|
if (isAbortError(error)) {
|
|
769
805
|
return;
|
|
@@ -545,6 +545,24 @@ export const registerOpenCodeRoutes = (app, dependencies) => {
|
|
|
545
545
|
return res.status(413).json({ error: `Content exceeds maximum size of ${MAX_BEHAVIOR_PROMPT_SIZE} bytes` });
|
|
546
546
|
}
|
|
547
547
|
|
|
548
|
+
// `expectedContent` is what the editor loaded (null: no file). A file
|
|
549
|
+
// changed on disk since then is not overwritten with the stale copy.
|
|
550
|
+
if (req.body && Object.prototype.hasOwnProperty.call(req.body, 'expectedContent')) {
|
|
551
|
+
const expected = req.body.expectedContent;
|
|
552
|
+
let current = null;
|
|
553
|
+
try {
|
|
554
|
+
current = await fs.promises.readFile(AGENTS_MD_PATH, 'utf8');
|
|
555
|
+
} catch (error) {
|
|
556
|
+
if (error?.code !== 'ENOENT') throw error;
|
|
557
|
+
}
|
|
558
|
+
if (current !== expected) {
|
|
559
|
+
return res.status(409).json({
|
|
560
|
+
error: 'AGENTS.md changed on disk since it was loaded',
|
|
561
|
+
code: 'AGENTS_MD_CONFLICT',
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
|
|
548
566
|
// Ensure parent directory exists
|
|
549
567
|
const parentDir = path.dirname(AGENTS_MD_PATH);
|
|
550
568
|
try {
|
|
@@ -23,6 +23,8 @@ export const createServerUtilsRuntime = (dependencies) => {
|
|
|
23
23
|
clearLastOpenCodeError,
|
|
24
24
|
getLoginShellPath,
|
|
25
25
|
getArchivedSessions = null,
|
|
26
|
+
getMergeSpaceSessionList = null,
|
|
27
|
+
getSpaceEventHub = null,
|
|
26
28
|
getStoredSessionMetadata = null,
|
|
27
29
|
} = dependencies;
|
|
28
30
|
|
|
@@ -221,6 +223,9 @@ export const createServerUtilsRuntime = (dependencies) => {
|
|
|
221
223
|
getUiNotificationClients,
|
|
222
224
|
getArchivedSessions,
|
|
223
225
|
getStoredSessionMetadata,
|
|
226
|
+
// Read when the proxy is set up, after `main` decided whether the spaces host exists.
|
|
227
|
+
mergeSpaceSessionList: typeof getMergeSpaceSessionList === 'function' ? getMergeSpaceSessionList() : null,
|
|
228
|
+
spaceEventHub: typeof getSpaceEventHub === 'function' ? getSpaceEventHub() : null,
|
|
224
229
|
});
|
|
225
230
|
};
|
|
226
231
|
|
|
@@ -614,6 +614,9 @@ export const createSettingsHelpers = (dependencies) => {
|
|
|
614
614
|
if (typeof candidate.agentNotifyToolEnabled === 'boolean') {
|
|
615
615
|
result.agentNotifyToolEnabled = candidate.agentNotifyToolEnabled;
|
|
616
616
|
}
|
|
617
|
+
if (typeof candidate.isolatedSpacesEnabled === 'boolean') {
|
|
618
|
+
result.isolatedSpacesEnabled = candidate.isolatedSpacesEnabled;
|
|
619
|
+
}
|
|
617
620
|
if (typeof candidate.openCodeUpdateToastDismissedVersion === 'string') {
|
|
618
621
|
const version = candidate.openCodeUpdateToastDismissedVersion.trim();
|
|
619
622
|
result.openCodeUpdateToastDismissedVersion = version.slice(0, VERSION_STRING_MAX_LENGTH);
|
|
@@ -764,7 +764,7 @@ describe('settings registry gate', () => {
|
|
|
764
764
|
desktopLanAccessEnabled: true, desktopKeepAwakeEnabled: true, desktopMinimizeToTrayEnabled: true, desktopMacMenuBarEnabled: true,
|
|
765
765
|
desktopUiPassword: 'secret', githubClientId: 'client', githubScopes: 'repo', skillCatalogs: [{ id: 'c', label: 'C', source: 'https://x' }],
|
|
766
766
|
defaultGitIdentityId: 'global', permissionAutoAccept: { sessions: { s: true }, revision: 1 },
|
|
767
|
-
agentControlToolEnabled: true, agentWebToolEnabled: true, browserProvider: 'builtin', agentMemoryToolEnabled: true, agentNotifyToolEnabled: true, openCodeUpdateToastDismissedVersion: '1.0.0',
|
|
767
|
+
agentControlToolEnabled: true, agentWebToolEnabled: true, browserProvider: 'builtin', agentMemoryToolEnabled: true, agentNotifyToolEnabled: true, isolatedSpacesEnabled: true, openCodeUpdateToastDismissedVersion: '1.0.0',
|
|
768
768
|
autoDeleteEnabled: true, autoDeleteAfterDays: 30, sessionRetentionOnlyArchived: false, sessionRetentionAction: 'archive', terminalShell: 'zsh', terminalLoginShells: ['zsh'],
|
|
769
769
|
openInAppId: 'vscode', dictationEnabled: true, sttProvider: 'local', sttServerUrl: 'http://localhost:8001/v1', sttModel: 'm', sttLocalModel: 'm', sttLanguage: 'en',
|
|
770
770
|
tunnelProvider: 'cloudflare', tunnelMode: 'quick', tunnelBootstrapTtlMs: 600000, tunnelSessionTtlMs: 86400000, managedLocalTunnelConfigPath: '/tmp/x',
|
|
@@ -280,11 +280,16 @@ function readConfigLayer(filePath) {
|
|
|
280
280
|
function readConfigLayers(workingDirectory) {
|
|
281
281
|
const { userPaths, projectPath, customPath } = getConfigPaths(workingDirectory);
|
|
282
282
|
const userPath = getPrimaryUserConfigPath(userPaths);
|
|
283
|
+
// OpenCode loads every global config file in order, so an `opencode.jsonc`
|
|
284
|
+
// next to `opencode.json` overrides it. New entries still go to the primary
|
|
285
|
+
// file; entries found in the override are edited where they live.
|
|
286
|
+
const userOverridePath = userPaths.find((candidate) => candidate !== userPath && fs.existsSync(candidate)) ?? null;
|
|
283
287
|
const userLayer = readConfigLayer(userPath);
|
|
288
|
+
const userOverrideLayer = readConfigLayer(userOverridePath);
|
|
284
289
|
const projectLayer = readConfigLayer(projectPath);
|
|
285
290
|
const customLayer = readConfigLayer(customPath);
|
|
286
291
|
const mergedConfig = mergeConfigs(
|
|
287
|
-
mergeConfigs(userLayer.config, projectLayer.config),
|
|
292
|
+
mergeConfigs(mergeConfigs(userLayer.config, userOverrideLayer.config), projectLayer.config),
|
|
288
293
|
customLayer.config,
|
|
289
294
|
);
|
|
290
295
|
|
|
@@ -292,6 +297,9 @@ function readConfigLayers(workingDirectory) {
|
|
|
292
297
|
if (userLayer.error) {
|
|
293
298
|
layerErrors.push({ path: userPath, code: userLayer.error.code, message: userLayer.error.message });
|
|
294
299
|
}
|
|
300
|
+
if (userOverrideLayer.error && userOverridePath) {
|
|
301
|
+
layerErrors.push({ path: userOverridePath, code: userOverrideLayer.error.code, message: userOverrideLayer.error.message });
|
|
302
|
+
}
|
|
295
303
|
if (projectLayer.error && projectPath) {
|
|
296
304
|
layerErrors.push({ path: projectPath, code: projectLayer.error.code, message: projectLayer.error.message });
|
|
297
305
|
}
|
|
@@ -301,10 +309,11 @@ function readConfigLayers(workingDirectory) {
|
|
|
301
309
|
|
|
302
310
|
return {
|
|
303
311
|
userConfig: userLayer.config,
|
|
312
|
+
userOverrideConfig: userOverrideLayer.config,
|
|
304
313
|
projectConfig: projectLayer.config,
|
|
305
314
|
customConfig: customLayer.config,
|
|
306
315
|
mergedConfig,
|
|
307
|
-
paths: { userPath, projectPath, customPath },
|
|
316
|
+
paths: { userPath, userOverridePath, projectPath, customPath },
|
|
308
317
|
layerErrors,
|
|
309
318
|
};
|
|
310
319
|
}
|
|
@@ -407,6 +416,12 @@ function getJsonEntrySource(layers, sectionKind, entryName) {
|
|
|
407
416
|
if (project) return project;
|
|
408
417
|
}
|
|
409
418
|
|
|
419
|
+
if (paths.userOverridePath) {
|
|
420
|
+
throwIfLayerError(layers, paths.userOverridePath);
|
|
421
|
+
const userOverride = found(layers.userOverrideConfig, paths.userOverridePath);
|
|
422
|
+
if (userOverride) return userOverride;
|
|
423
|
+
}
|
|
424
|
+
|
|
410
425
|
throwIfLayerError(layers, paths.userPath);
|
|
411
426
|
const user = found(userConfig, paths.userPath);
|
|
412
427
|
if (user) return user;
|
|
@@ -38,6 +38,7 @@ export const createGracefulShutdownRuntime = (dependencies) => {
|
|
|
38
38
|
getDictationRuntime,
|
|
39
39
|
getRelayService,
|
|
40
40
|
getRelayReconcileTimer,
|
|
41
|
+
getSpacesHost = () => null,
|
|
41
42
|
} = dependencies;
|
|
42
43
|
|
|
43
44
|
let shutdownPromise = null;
|
|
@@ -74,6 +75,8 @@ export const createGracefulShutdownRuntime = (dependencies) => {
|
|
|
74
75
|
() => clearInterval(getRelayReconcileTimer()),
|
|
75
76
|
() => getGuestSurfaceRuntime()?.stop(),
|
|
76
77
|
() => getRealtimeProxyRuntime()?.stop(),
|
|
78
|
+
// The isolated-spaces host, when the switch is on: its connections into spaces end here.
|
|
79
|
+
() => getSpacesHost()?.close(),
|
|
77
80
|
() => getRelayService()?.stop(),
|
|
78
81
|
() => getDictationRuntime()?.stop(),
|
|
79
82
|
() => openCodeWatcherRuntime.stop(),
|
|
@@ -47,13 +47,15 @@ export const createOpenCodeWatcherRuntime = (deps) => {
|
|
|
47
47
|
const signal = abortController.signal;
|
|
48
48
|
|
|
49
49
|
if (globalEventHub) {
|
|
50
|
+
// The events of isolated spaces feed this watcher too, so live status, unread marks and
|
|
51
|
+
// notifications work for a space's sessions as for the host's.
|
|
50
52
|
unsubscribeEvent = globalEventHub.subscribeEvent((event) => {
|
|
51
53
|
const payload = unwrapGlobalEventPayload(event.payload);
|
|
52
54
|
if (!payload || typeof payload !== 'object') {
|
|
53
55
|
return;
|
|
54
56
|
}
|
|
55
57
|
emitTranslated(payload);
|
|
56
|
-
});
|
|
58
|
+
}, { spaces: true });
|
|
57
59
|
unsubscribeStatus = globalEventHub.subscribeStatus((status) => {
|
|
58
60
|
if (signal.aborted) {
|
|
59
61
|
return;
|
|
@@ -10,10 +10,14 @@ const isAllowedSsePath = (pathname) => {
|
|
|
10
10
|
|| pathname === '/api/notifications/stream';
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
// The same three sockets of an isolated space, under `/api/spaces/<id>/`, matched by shape.
|
|
14
|
+
const SPACE_WS_PATH = /^\/api\/spaces\/[0-9a-f]{12}\/(?:terminal\/ws|event\/ws|global\/event\/ws)$/;
|
|
15
|
+
|
|
13
16
|
const isAllowedWebSocketPath = (pathname) => {
|
|
14
17
|
return pathname === '/api/event/ws'
|
|
15
18
|
|| pathname === '/api/global/event/ws'
|
|
16
|
-
|| pathname === '/api/terminal/ws'
|
|
19
|
+
|| pathname === '/api/terminal/ws'
|
|
20
|
+
|| SPACE_WS_PATH.test(pathname);
|
|
17
21
|
};
|
|
18
22
|
|
|
19
23
|
const normalizeBaseUrl = (value) => {
|
|
@@ -228,6 +228,35 @@ describe('realtime proxy', () => {
|
|
|
228
228
|
}
|
|
229
229
|
});
|
|
230
230
|
|
|
231
|
+
it('proxies the sockets of an isolated space by path shape, and refuses another path under the prefix', async () => {
|
|
232
|
+
const seen = [];
|
|
233
|
+
const upstreamServer = http.createServer();
|
|
234
|
+
const upstreamWs = new WebSocketServer({ server: upstreamServer });
|
|
235
|
+
upstreamWs.on('connection', (socket, request) => {
|
|
236
|
+
seen.push(request.url);
|
|
237
|
+
socket.send('ready');
|
|
238
|
+
});
|
|
239
|
+
const upstreamOrigin = await listen(upstreamServer);
|
|
240
|
+
const { origin, runtime } = await startProxyServer({ apiBaseUrl: upstreamOrigin });
|
|
241
|
+
const attempt = (path) => new Promise((resolve, reject) => {
|
|
242
|
+
const client = new WebSocket(buildRealtimeProxyWsUrl(origin, `${upstreamOrigin.replace(/^http:/, 'ws:')}${path}`), { headers: { Origin: 'openchamber-ui://app' } });
|
|
243
|
+
client.once('message', (data) => { client.close(); resolve({ message: data.toString() }); });
|
|
244
|
+
client.once('close', (code) => resolve({ code }));
|
|
245
|
+
client.once('error', reject);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
try {
|
|
249
|
+
expect(await attempt('/api/spaces/a1b2c3d4e5f6/terminal/ws')).toEqual({ message: 'ready' });
|
|
250
|
+
expect(await attempt('/api/spaces/a1b2c3d4e5f6/event/ws?directory=%2Fspaces%2Fa1b2c3d4e5f6%2Frepo')).toEqual({ message: 'ready' });
|
|
251
|
+
expect(await attempt('/api/spaces/a1b2c3d4e5f6/dictation/ws')).toEqual({ code: 1008 });
|
|
252
|
+
expect(await attempt('/api/spaces/A1B2C3D4E5F6/terminal/ws')).toEqual({ code: 1008 });
|
|
253
|
+
expect(seen).toEqual(['/api/spaces/a1b2c3d4e5f6/terminal/ws', '/api/spaces/a1b2c3d4e5f6/event/ws?directory=%2Fspaces%2Fa1b2c3d4e5f6%2Frepo']);
|
|
254
|
+
upstreamWs.close();
|
|
255
|
+
} finally {
|
|
256
|
+
runtime.stop();
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
|
|
231
260
|
it('allows first passwordless WebSocket proxy upgrade without an existing cookie', async () => {
|
|
232
261
|
const upstreamServer = http.createServer();
|
|
233
262
|
const upstreamWs = new WebSocketServer({ server: upstreamServer });
|
|
@@ -37,7 +37,10 @@ const ALLOWED_WS_PATHS = new Set([
|
|
|
37
37
|
// Extension surfaces carry the extension id in the path, so they are matched
|
|
38
38
|
// by shape rather than listed.
|
|
39
39
|
const GUEST_SURFACE_WS_PATH = /^\/api\/guests\/[a-z][a-z0-9-]*\/surface\/ws$/;
|
|
40
|
-
|
|
40
|
+
// The sockets of an isolated space carry the space id in the path: the same four sockets,
|
|
41
|
+
// under `/api/spaces/<id>/`, matched by shape.
|
|
42
|
+
const SPACE_WS_PATH = /^\/api\/spaces\/[0-9a-f]{12}\/(?:terminal\/ws|dev-tunnel|event\/ws|global\/event\/ws)$/;
|
|
43
|
+
export const isAllowedRelayWebSocketPath = (pathname) => ALLOWED_WS_PATHS.has(pathname) || GUEST_SURFACE_WS_PATH.test(pathname) || SPACE_WS_PATH.test(pathname);
|
|
41
44
|
|
|
42
45
|
// Hop-by-hop headers stripped from tunneled requests; `host` is set by fetch
|
|
43
46
|
// to the loopback origin. content-length is dropped too because the body is
|
|
@@ -153,6 +153,17 @@ describe('relay host WebSocket allowlist', () => {
|
|
|
153
153
|
expect(isAllowedRelayWebSocketPath('/api/database/ws')).toBe(false);
|
|
154
154
|
});
|
|
155
155
|
|
|
156
|
+
test('allows the sockets of an isolated space by path shape only', () => {
|
|
157
|
+
for (const socket of ['terminal/ws', 'dev-tunnel', 'event/ws', 'global/event/ws']) {
|
|
158
|
+
expect(isAllowedRelayWebSocketPath(`/api/spaces/a1b2c3d4e5f6/${socket}`)).toBe(true);
|
|
159
|
+
}
|
|
160
|
+
expect(isAllowedRelayWebSocketPath('/api/spaces/a1b2c3d4e5f6/dictation/ws')).toBe(false);
|
|
161
|
+
expect(isAllowedRelayWebSocketPath('/api/spaces/A1B2C3D4E5F6/terminal/ws')).toBe(false);
|
|
162
|
+
expect(isAllowedRelayWebSocketPath('/api/spaces/a1b2c3d4e5f/terminal/ws')).toBe(false);
|
|
163
|
+
expect(isAllowedRelayWebSocketPath('/api/spaces/a1b2c3d4e5f6/terminal/ws/x')).toBe(false);
|
|
164
|
+
expect(isAllowedRelayWebSocketPath('/api/spaces//terminal/ws')).toBe(false);
|
|
165
|
+
});
|
|
166
|
+
|
|
156
167
|
test('allows an extension surface socket by path shape only', () => {
|
|
157
168
|
expect(isAllowedRelayWebSocketPath('/api/guests/server-chrome/surface/ws')).toBe(true);
|
|
158
169
|
expect(isAllowedRelayWebSocketPath('/api/guests/Server/surface/ws')).toBe(false);
|
|
@@ -81,12 +81,10 @@ Four things are decided here, in order:
|
|
|
81
81
|
5. Otherwise `GET /api/model/default` — `source: 'default'`. This is
|
|
82
82
|
OpenCode's default chat model, not a small one; it is the last resort.
|
|
83
83
|
|
|
84
|
-
Claude Code is
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
user's Claude subscription rate limit. An available endpoint does not lift the
|
|
89
|
-
refusal — the cost is the reason, not the transport.
|
|
84
|
+
Claude Code (`claude-code`, from the opencode-claude plugin) is a provider
|
|
85
|
+
like any other: its generate path runs a clean one-shot turn with no tools and
|
|
86
|
+
no session, so `claude-code/haiku` (family `claude-haiku`) is picked in the
|
|
87
|
+
normal family order.
|
|
90
88
|
|
|
91
89
|
## Prompt shape
|
|
92
90
|
|
|
@@ -120,10 +118,13 @@ model they got. The resolved value comes back as `outputTokens`.
|
|
|
120
118
|
longer wanted. The timeout covers generation, retry waits and structured-output
|
|
121
119
|
retries together.
|
|
122
120
|
|
|
123
|
-
OpenCode 2 can reject an explicit model before its cold catalog finishes loading
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
121
|
+
OpenCode 2 can reject an explicit model before its cold catalog finishes loading;
|
|
122
|
+
plugin-provided models (Claude Code) stay unavailable for 20-40 s after OpenCode
|
|
123
|
+
starts because plugins for the global location load lazily. An
|
|
124
|
+
`InvalidRequestError` whose message exactly names the selected model as
|
|
125
|
+
`Model unavailable: provider/model` is retried with exponential backoff (0.5, 1,
|
|
126
|
+
2, 4, 8, 16 s, ~31 s in total), with the same model and prompt. The rejection
|
|
127
|
+
precedes provider dispatch, so retries cost no tokens. Cancellation also stops the wait. Other errors are not retried.
|
|
127
128
|
If the model remains unavailable, the route returns 503 with
|
|
128
129
|
`code: 'small-model-unavailable'` and the model-specific reason. Commit and PR
|
|
129
130
|
generation own their error toast and suppress the shared request toast.
|
|
@@ -11,16 +11,20 @@ import {
|
|
|
11
11
|
listProviderInfos,
|
|
12
12
|
} from './client.js';
|
|
13
13
|
|
|
14
|
-
// Never a small model, whatever the transport looks like. A plugin can publish
|
|
15
|
-
// an OpenAI-compatible endpoint for Claude Code, but it is a façade over the
|
|
16
|
-
// Claude Agent SDK, which spawns the Claude Code CLI per request and spends
|
|
17
|
-
// the user's Claude subscription rate limit. Paying that for a session title
|
|
18
|
-
// or a summary is the wrong trade, so the refusal is unconditional rather than
|
|
19
|
-
// conditional on an endpoint existing.
|
|
20
|
-
const CLAUDE_CODE_PROVIDER = 'claude-code';
|
|
21
|
-
|
|
22
14
|
const DEFAULT_TIMEOUT_MS = 60_000;
|
|
23
15
|
|
|
16
|
+
// Waits between retries of `Model unavailable`, ~31 s in total. Right after
|
|
17
|
+
// OpenCode starts, plugin-provided models (claude-code) stay unavailable for
|
|
18
|
+
// 20-40 s while plugins for the global location load lazily. The rejection
|
|
19
|
+
// precedes provider dispatch, so a retry costs no tokens.
|
|
20
|
+
const UNAVAILABLE_RETRY_DELAYS_MS = [500, 1_000, 2_000, 4_000, 8_000, 16_000];
|
|
21
|
+
let unavailableRetryDelaysMs = UNAVAILABLE_RETRY_DELAYS_MS;
|
|
22
|
+
|
|
23
|
+
/** Test hook: replace the backoff schedule; no argument restores the default. */
|
|
24
|
+
export const setUnavailableRetryDelaysForTest = (delays = UNAVAILABLE_RETRY_DELAYS_MS) => {
|
|
25
|
+
unavailableRetryDelaysMs = delays;
|
|
26
|
+
};
|
|
27
|
+
|
|
24
28
|
const OPENCHAMBER_SETTINGS_FILE = path.join(
|
|
25
29
|
process.env.OPENCHAMBER_DATA_DIR
|
|
26
30
|
? path.resolve(process.env.OPENCHAMBER_DATA_DIR)
|
|
@@ -151,7 +155,6 @@ export const pickSmallModelAnywhere = (models) => pickSmallModel(models, () => t
|
|
|
151
155
|
const pickSmallModel = (models, accept) => {
|
|
152
156
|
const candidates = models
|
|
153
157
|
.filter((model) => model && accept(model)
|
|
154
|
-
&& model.providerID !== CLAUDE_CODE_PROVIDER
|
|
155
158
|
&& model.enabled !== false
|
|
156
159
|
&& (model.status === undefined || model.status === 'active')
|
|
157
160
|
&& (model.capabilities?.input ?? ['text']).some((item) => String(item).startsWith('text'))
|
|
@@ -260,13 +263,6 @@ export async function generateSmallModelText({ prompt, system, maxOutputTokens,
|
|
|
260
263
|
);
|
|
261
264
|
}
|
|
262
265
|
|
|
263
|
-
if (resolved.providerID === CLAUDE_CODE_PROVIDER) {
|
|
264
|
-
throw Object.assign(
|
|
265
|
-
new Error('Claude Code cannot be used for background small-model actions. Choose another Small Model in Settings → Sessions.'),
|
|
266
|
-
{ statusCode: 422, code: 'small-model-provider-unsupported' },
|
|
267
|
-
);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
266
|
// A caller that must stay on its session's provider is only overruled by an
|
|
271
267
|
// explicit user choice (the settings override or a request model).
|
|
272
268
|
if (restrictToPreferredProvider
|
|
@@ -302,7 +298,6 @@ export async function generateSmallModelText({ prompt, system, maxOutputTokens,
|
|
|
302
298
|
|
|
303
299
|
const generationOptions = requestOptions({ timeoutMs, signal });
|
|
304
300
|
const unavailableMessage = `Model unavailable: ${resolved.providerID}/${resolved.modelID}`;
|
|
305
|
-
let retriedUnavailable = false;
|
|
306
301
|
const send = async () => {
|
|
307
302
|
const result = await client.generate.text(
|
|
308
303
|
{ prompt: fullPrompt, model: { id: resolved.modelID, providerID: resolved.providerID } },
|
|
@@ -312,21 +307,22 @@ export async function generateSmallModelText({ prompt, system, maxOutputTokens,
|
|
|
312
307
|
};
|
|
313
308
|
|
|
314
309
|
const sendWithCatalogRetry = async () => {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
310
|
+
for (let attempt = 0; ; attempt += 1) {
|
|
311
|
+
try {
|
|
312
|
+
return await send();
|
|
313
|
+
} catch (error) {
|
|
314
|
+
if (error?._tag !== 'InvalidRequestError' || error.message !== unavailableMessage) throw error;
|
|
315
|
+
// OpenCode 2 can resolve a cold catalog before its models arrive.
|
|
316
|
+
// This rejection precedes provider dispatch; other failures must not retry.
|
|
317
|
+
if (attempt < unavailableRetryDelaysMs.length) {
|
|
318
|
+
await delay(unavailableRetryDelaysMs[attempt], undefined, { signal: generationOptions.signal });
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
throw Object.assign(new Error(unavailableMessage), {
|
|
322
|
+
statusCode: 503,
|
|
323
|
+
code: 'small-model-unavailable',
|
|
324
|
+
});
|
|
325
325
|
}
|
|
326
|
-
throw Object.assign(new Error(unavailableMessage), {
|
|
327
|
-
statusCode: 503,
|
|
328
|
-
code: 'small-model-unavailable',
|
|
329
|
-
});
|
|
330
326
|
}
|
|
331
327
|
};
|
|
332
328
|
|
|
@@ -386,7 +382,6 @@ export async function listAuthenticatedProviders() {
|
|
|
386
382
|
if (typeof provider?.id === 'string' && enabled.has(provider.id)) ids.add(provider.id);
|
|
387
383
|
}
|
|
388
384
|
for (const id of enabled) ids.add(id);
|
|
389
|
-
ids.delete(CLAUDE_CODE_PROVIDER);
|
|
390
385
|
return Array.from(ids);
|
|
391
386
|
} catch {
|
|
392
387
|
return [];
|
|
@@ -3,14 +3,14 @@ import { registerSmallModelRoutes } from './routes.js';
|
|
|
3
3
|
import http from 'node:http';
|
|
4
4
|
import os from 'os';
|
|
5
5
|
import path from 'path';
|
|
6
|
-
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'bun:test';
|
|
6
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from 'bun:test';
|
|
7
7
|
|
|
8
8
|
// The settings override is read straight from disk, so without this the suite
|
|
9
9
|
// would resolve whatever small model the developer running it has configured.
|
|
10
10
|
const TEMP_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), 'small-model-settings-'));
|
|
11
11
|
process.env.OPENCHAMBER_DATA_DIR = TEMP_DATA_DIR;
|
|
12
12
|
|
|
13
|
-
const { generateSmallModelText, describeSmallModel, listAuthenticatedProviders } = await import('./index.js');
|
|
13
|
+
const { generateSmallModelText, describeSmallModel, listAuthenticatedProviders, setUnavailableRetryDelaysForTest } = await import('./index.js');
|
|
14
14
|
const { configureOpenCodeRuntimeProviders, resetOpenCodeRuntimeProviders } = await import('./client.js');
|
|
15
15
|
|
|
16
16
|
// A real OpenCode stub over HTTP. The module talks to OpenCode through
|
|
@@ -103,7 +103,10 @@ describe('generateSmallModelText', () => {
|
|
|
103
103
|
const unavailable = { _tag: 'InvalidRequestError', message: 'Model unavailable: zai-coding-plan/glm-5.3-flash' };
|
|
104
104
|
const options = { prompt: 'write a commit', model: 'zai-coding-plan/glm-5.3-flash' };
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
beforeEach(() => setUnavailableRetryDelaysForTest([1, 1, 1]));
|
|
107
|
+
afterEach(() => setUnavailableRetryDelaysForTest());
|
|
108
|
+
|
|
109
|
+
it('retries a cold catalog with the same model and prompt', async () => {
|
|
107
110
|
state.generateErrors = [unavailable];
|
|
108
111
|
const result = await generateSmallModelText(options);
|
|
109
112
|
expect(result.text).toBe('generated');
|
|
@@ -112,12 +115,19 @@ describe('generateSmallModelText', () => {
|
|
|
112
115
|
expect(calls[0].body).toEqual(calls[1].body);
|
|
113
116
|
});
|
|
114
117
|
|
|
115
|
-
it('
|
|
116
|
-
state.generateErrors = [unavailable, unavailable];
|
|
118
|
+
it('keeps backing off while the plugin model loads', async () => {
|
|
119
|
+
state.generateErrors = [unavailable, unavailable, unavailable];
|
|
120
|
+
const result = await generateSmallModelText(options);
|
|
121
|
+
expect(result.text).toBe('generated');
|
|
122
|
+
expect(state.requests.filter((entry) => entry.path === '/api/experimental/generate')).toHaveLength(4);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('reports persistent model unavailability once the backoff runs out', async () => {
|
|
126
|
+
state.generateErrors = [unavailable, unavailable, unavailable, unavailable];
|
|
117
127
|
await expect(generateSmallModelText(options)).rejects.toMatchObject({
|
|
118
128
|
message: unavailable.message, statusCode: 503, code: 'small-model-unavailable',
|
|
119
129
|
});
|
|
120
|
-
expect(state.requests.filter((entry) => entry.path === '/api/experimental/generate')).toHaveLength(
|
|
130
|
+
expect(state.requests.filter((entry) => entry.path === '/api/experimental/generate')).toHaveLength(4);
|
|
121
131
|
});
|
|
122
132
|
|
|
123
133
|
it('does not retry other invalid requests', async () => {
|
|
@@ -133,6 +143,7 @@ describe('generateSmallModelText', () => {
|
|
|
133
143
|
});
|
|
134
144
|
|
|
135
145
|
it('cancels without sending the retry', async () => {
|
|
146
|
+
setUnavailableRetryDelaysForTest();
|
|
136
147
|
const controller = new AbortController();
|
|
137
148
|
state.generateErrors = [unavailable];
|
|
138
149
|
const pending = generateSmallModelText({ ...options, signal: controller.signal });
|
|
@@ -146,6 +157,7 @@ describe('generateSmallModelText', () => {
|
|
|
146
157
|
});
|
|
147
158
|
|
|
148
159
|
it('honors the timeout during the retry delay', async () => {
|
|
160
|
+
setUnavailableRetryDelaysForTest();
|
|
149
161
|
state.generateErrors = [unavailable];
|
|
150
162
|
await expect(generateSmallModelText({ ...options, timeoutMs: 100 })).rejects.toThrow();
|
|
151
163
|
expect(state.requests.filter((entry) => entry.path === '/api/experimental/generate')).toHaveLength(1);
|
|
@@ -182,11 +194,11 @@ describe('generateSmallModelText', () => {
|
|
|
182
194
|
expect(lastGenerate().body.model).toEqual({ id: 'gpt-5.6-luna', providerID: 'openai' });
|
|
183
195
|
});
|
|
184
196
|
|
|
185
|
-
it('
|
|
186
|
-
await
|
|
187
|
-
.rejects.toMatchObject({ statusCode: 422, code: 'small-model-provider-unsupported' });
|
|
197
|
+
it('sends an explicit Claude Code model like any other', async () => {
|
|
198
|
+
const result = await generateSmallModelText({ prompt: 'hi', model: 'claude-code/haiku', directory: '/proj' });
|
|
188
199
|
|
|
189
|
-
expect(
|
|
200
|
+
expect(result).toMatchObject({ providerID: 'claude-code', modelID: 'haiku', source: 'request' });
|
|
201
|
+
expect(lastGenerate().body.model).toEqual({ id: 'haiku', providerID: 'claude-code' });
|
|
190
202
|
});
|
|
191
203
|
|
|
192
204
|
it('stays on the session provider when the caller forbids switching', async () => {
|
|
@@ -276,14 +288,12 @@ describe('generateSmallModelText', () => {
|
|
|
276
288
|
expect(result).toMatchObject({ providerID: 'my-proxy', modelID: 'gemini-3.6-flash', source: 'session-provider-small' });
|
|
277
289
|
});
|
|
278
290
|
|
|
279
|
-
it('
|
|
291
|
+
it('picks Claude Code haiku as the small model like any other provider', async () => {
|
|
280
292
|
state.models = [MODEL({ id: 'haiku', modelID: 'haiku', providerID: 'claude-code', family: 'claude-haiku' })];
|
|
281
293
|
|
|
282
294
|
const result = await generateSmallModelText({ prompt: 'hi', directory: '/proj' });
|
|
283
295
|
|
|
284
|
-
|
|
285
|
-
// and OpenCode's default (the fixture's anthropic haiku) is used.
|
|
286
|
-
expect(result).toMatchObject({ providerID: 'anthropic', modelID: 'claude-haiku-4-5', source: 'default' });
|
|
296
|
+
expect(result).toMatchObject({ providerID: 'claude-code', modelID: 'haiku', source: 'small' });
|
|
287
297
|
});
|
|
288
298
|
|
|
289
299
|
it('ignores a disabled small model and falls back to the session model', async () => {
|
|
@@ -487,10 +497,10 @@ describe('listAuthenticatedProviders', () => {
|
|
|
487
497
|
expect(await listAuthenticatedProviders()).toEqual(['anthropic']);
|
|
488
498
|
});
|
|
489
499
|
|
|
490
|
-
it('
|
|
500
|
+
it('offers Claude Code', async () => {
|
|
491
501
|
state.models = [MODEL(), MODEL({ id: 'sonnet', modelID: 'sonnet', providerID: 'claude-code' })];
|
|
492
502
|
|
|
493
|
-
expect(await listAuthenticatedProviders()).
|
|
503
|
+
expect(await listAuthenticatedProviders()).toContain('claude-code');
|
|
494
504
|
});
|
|
495
505
|
|
|
496
506
|
it('answers an empty list when OpenCode is not reachable', async () => {
|
|
@@ -510,6 +520,7 @@ describe('small model failure response', () => {
|
|
|
510
520
|
}, {
|
|
511
521
|
getSmallModelService: async () => ({ generateSmallModelText }),
|
|
512
522
|
});
|
|
523
|
+
setUnavailableRetryDelaysForTest([1]);
|
|
513
524
|
state.generateErrors = [
|
|
514
525
|
{ _tag: 'InvalidRequestError', message: 'Model unavailable: zai-coding-plan/glm-5.3-flash' },
|
|
515
526
|
{ _tag: 'InvalidRequestError', message: 'Model unavailable: zai-coding-plan/glm-5.3-flash' },
|
|
@@ -526,5 +537,6 @@ describe('small model failure response', () => {
|
|
|
526
537
|
error: 'Model unavailable: zai-coding-plan/glm-5.3-flash',
|
|
527
538
|
code: 'small-model-unavailable',
|
|
528
539
|
});
|
|
540
|
+
setUnavailableRetryDelaysForTest();
|
|
529
541
|
});
|
|
530
542
|
});
|