@openchamber/web 1.24.0 → 1.24.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/bin/cli.test.js +29 -6
- package/bin/lib/cli-http.js +5 -1
- package/bin/lib/commands-status.js +5 -0
- package/dist/assets/{CodeMirrorCommentWidgets-C9kV-n7r.js → CodeMirrorCommentWidgets-B_vBPQYm.js} +1 -1
- package/dist/assets/DiffView-Ce0oBXXQ.js +4 -0
- package/dist/assets/{FilesView-vjJx7VaM.js → FilesView-DtXueAWP.js} +6 -6
- package/dist/assets/GitView-k0hUF8KB.js +6 -0
- package/dist/assets/GuestAttachDialog-DIf2U85Z.js +1 -0
- package/dist/assets/{JsonTreeView-D_4G5X6-.js → JsonTreeView-4AnJ04Pw.js} +1 -1
- package/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/dist/assets/{LinearIssuesView-1uKhePfH.js → LinearIssuesView-z_9p2GuO.js} +1 -1
- package/dist/assets/{MarkdownImageGallery-Ix7N_2wp.js → MarkdownImageGallery-BC-BNN-s.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-Deel_y5S.js → MarkdownRendererImpl-DyaBTUbH.js} +6 -6
- package/dist/assets/{OnboardingScreen-ToIakxb_.js → OnboardingScreen-DKU_yTb6.js} +1 -1
- package/dist/assets/{PatchDiff-BjMgezr1.js → PatchDiff-DpGmHRnV.js} +1 -1
- package/dist/assets/PierreDiffViewer-CgLl_tp7.js +210 -0
- package/dist/assets/{PlanView-BGAzxDwD.js → PlanView-CrfB4qqY.js} +4 -4
- package/dist/assets/PluginPane-B5cn-jPy.js +3 -0
- package/dist/assets/SettingsView-DMKKwezx.js +29 -0
- package/dist/assets/SettingsWindow-DwbnVzOC.js +1 -0
- package/dist/assets/{SubmoduleDiffSummary--YFqK6Ih.js → SubmoduleDiffSummary-hkGcvs0E.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DRWBvdaJ.js → ToolOutputDialog-DuoIOc0j.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-BxZJCU28.js → ToolPartDiffPreview-t1Bvq_2Y.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-DCXjBGRf.js → VirtualizedFileDiff-BK4aU5qJ.js} +1 -1
- package/dist/assets/{WalkthroughView-CfIPvWWa.js → WalkthroughView-Bk6TPNFw.js} +2 -2
- package/dist/assets/{appThemeRegistry-DDROzcUO.js → appThemeRegistry-DnOVbJjF.js} +1 -1
- package/dist/assets/commitAndPush-DLWNZkkY.js +1 -0
- package/dist/assets/{computeVirtualFileMetrics-DHgQIkUq.js → computeVirtualFileMetrics-BVTujWSX.js} +1 -1
- package/dist/assets/{de-CX_f-T5U.js → de-zEHaAIi3.js} +4 -4
- package/dist/assets/{es-BERmWNn_.js → es-CBDgEzgk.js} +4 -4
- package/dist/assets/{fr-BjYYE_-z.js → fr-DjiTptT_.js} +4 -4
- package/dist/assets/index-AgOdanig.css +1 -0
- package/dist/assets/index-B-2_X4DD.js +40 -0
- package/dist/assets/{index-WjufPkIV.js → index-CkA4p2IK.js} +1 -1
- package/dist/assets/{isDiffPlainText-D9faP70y.js → isDiffPlainText-D3yX_vx4.js} +1 -1
- package/dist/assets/{isFilePlainText-6qOcz5Ky.js → isFilePlainText-CZR9TcHV.js} +1 -1
- package/dist/assets/ja-CerMgj3r.js +16 -0
- package/dist/assets/{ko-Dty1aUod.js → ko-DHYDAze5.js} +4 -4
- package/dist/assets/main-BDka4W43.js +896 -0
- package/dist/assets/main-Dl7Dyge_.js +2 -0
- package/dist/assets/markdownCore-DFmr0rUR.js +5 -0
- package/dist/assets/miniChat-CLKQPPpO.js +2 -0
- package/dist/assets/mobile--giD2Q1L.js +2 -0
- package/dist/assets/{patchFileDiff-BvU6KOQC.js → patchFileDiff-DRh-AQvd.js} +1 -1
- package/dist/assets/{pl-CX-_ROkr.js → pl-BTB_93bq.js} +6 -6
- package/dist/assets/{pt-BR-DhRR1arx.js → pt-BR-BwA3oyCK.js} +4 -4
- package/dist/assets/renderElectronMiniChatApp-DmB7zpVK.js +2 -0
- package/dist/assets/renderMobileApp-pMfOuQfl.js +25 -0
- package/dist/assets/runtimeEndpointReset-Gqhmkm3U.js +25 -0
- package/dist/assets/{scheduledTasksApi-DW3xqMQ8.js → scheduledTasksApi-CeRAIUmW.js} +1 -1
- package/dist/assets/{shikiHighlight-DsxD9QEa.js → shikiHighlight-BfjuB3CD.js} +1 -1
- package/dist/assets/{textMateThemeFromAppTheme-Da7ed8qM.js → textMateThemeFromAppTheme-BP60t9SX.js} +1 -1
- package/dist/assets/tr-CcPsJoNM.js +7 -0
- package/dist/assets/{uk-CD21CXFV.js → uk-B68WibXi.js} +4 -4
- package/dist/assets/{useAppFontEffects-hfv2s6mZ.js → useAppFontEffects-DcdrFv2Z.js} +147 -147
- package/dist/assets/{useInlineCommentController-BmtfVbo8.js → useInlineCommentController-Cq4SUjsA.js} +2 -2
- package/dist/assets/useRootScrollLock-CSdR6Wnm.js +2 -0
- package/dist/assets/{vendor-codemirror-language-data-BPMJpOpT.js → vendor-codemirror-language-data-BFm1Ju2w.js} +2 -2
- package/dist/assets/vendor-katex-Cp579UoJ.css +1 -0
- package/dist/assets/{vendor-tanstack-react-virtual-g05Cx3z9.js → vendor-tanstack-react-virtual-ClYN8CzB.js} +1 -1
- package/dist/assets/{vendor-tanstack-virtual-core-Dubg10g5.js → vendor-tanstack-virtual-core-BewVQryB.js} +1 -1
- package/dist/assets/{vendor-zod-fZppILAM.js → vendor-zod-CgAdXWZO.js} +4 -4
- package/dist/assets/{web-components-U-hWbgJo.js → web-components-2vo9YsZc.js} +1 -1
- package/dist/assets/zh-CN-DbFHYXwP.js +16 -0
- package/dist/assets/{zh-TW-CRp5dJU2.js → zh-TW-DmXAwdty.js} +4 -4
- package/dist/index.html +6 -4
- package/dist/mini-chat.html +6 -4
- package/dist/mobile.html +6 -4
- package/package.json +6 -5
- package/server/index.js +29 -7
- package/server/lib/agent-tool/DOCUMENTATION.md +17 -4
- package/server/lib/agent-tool/runtime.js +62 -15
- package/server/lib/agent-tool/runtime.test.js +88 -2
- package/server/lib/changelog/update-notes.js +2 -1
- package/server/lib/changelog/update-notes.test.js +19 -0
- package/server/lib/event-stream/DOCUMENTATION.md +23 -0
- package/server/lib/event-stream/delta-coalescer.js +0 -0
- package/server/lib/event-stream/delta-coalescer.test.js +292 -0
- package/server/lib/event-stream/global-hub.js +53 -23
- package/server/lib/event-stream/global-hub.test.js +160 -0
- package/server/lib/event-stream/global-ws-bridge.js +1 -0
- package/server/lib/event-stream/index.js +4 -0
- package/server/lib/fs/DOCUMENTATION.md +2 -1
- package/server/lib/fs/routes.js +56 -4
- package/server/lib/fs/routes.test.js +116 -0
- package/server/lib/git/DOCUMENTATION.md +18 -5
- package/server/lib/git/routes.js +1 -1
- package/server/lib/git/serial-refresh.js +93 -0
- package/server/lib/git/serial-refresh.test.js +112 -0
- package/server/lib/git/service.js +325 -70
- package/server/lib/git/service.test.js +291 -0
- package/server/lib/github/pr-status.js +5 -5
- package/server/lib/github/pr-status.test.js +1 -1
- package/server/lib/github/routes.js +4 -4
- package/server/lib/guests/DOCUMENTATION.md +5 -3
- package/server/lib/guests/background.test.js +83 -0
- package/server/lib/guests/catalog.js +20 -9
- package/server/lib/guests/catalog.test.js +5 -5
- package/server/lib/guests/routes.js +2 -2
- package/server/lib/message-queue/DOCUMENTATION.md +10 -1
- package/server/lib/message-queue/runtime.js +21 -1
- package/server/lib/message-queue/runtime.test.js +52 -5
- package/server/lib/notifications/routes.js +5 -0
- package/server/lib/openchamber-sessions/routes.js +18 -18
- package/server/lib/openchamber-sessions/routes.test.js +49 -0
- package/server/lib/opencode/DOCUMENTATION.md +1 -1
- package/server/lib/opencode/bootstrap-runtime.js +1 -0
- package/server/lib/opencode/feature-routes-runtime.js +5 -0
- package/server/lib/opencode/session-runtime.js +68 -0
- package/server/lib/opencode/session-runtime.test.js +43 -0
- package/server/lib/opencode/settings-helpers.js +3 -0
- package/server/lib/opencode/settings-registry.json +8 -0
- package/server/lib/permission-auto-accept/DOCUMENTATION.md +8 -0
- package/server/lib/permission-auto-accept/runtime.js +13 -0
- package/server/lib/permission-auto-accept/runtime.test.js +37 -1
- package/server/lib/projects/project-config.js +2 -2
- package/server/lib/realtime-proxy-terminal.test.js +150 -0
- package/server/lib/realtime-proxy.js +2 -0
- package/server/lib/routing/DOCUMENTATION.md +83 -0
- package/server/lib/routing/defaults.js +98 -0
- package/server/lib/routing/feature-flag.js +11 -0
- package/server/lib/routing/history.js +34 -0
- package/server/lib/routing/jev.js +98 -0
- package/server/lib/routing/routes.http.test.js +100 -0
- package/server/lib/routing/routes.js +81 -0
- package/server/lib/routing/runtime.js +217 -0
- package/server/lib/routing/runtime.test.js +188 -0
- package/server/lib/routing/store.js +249 -0
- package/server/lib/routing/store.test.js +96 -0
- package/server/lib/scheduled-tasks/runtime.js +2 -2
- package/server/lib/scheduled-tasks/runtime.test.js +14 -0
- package/server/lib/security/request-security.js +9 -5
- package/server/lib/security/request-security.test.js +37 -0
- package/server/lib/small-model/DOCUMENTATION.md +14 -2
- package/server/lib/small-model/call.js +37 -6
- package/server/lib/small-model/call.test.js +182 -0
- package/server/lib/terminal/DOCUMENTATION.md +21 -2
- package/server/lib/terminal/runtime.js +10 -3
- package/server/lib/terminal/runtime.test.js +22 -0
- package/server/lib/terminal/shutdown.js +106 -0
- package/server/lib/terminal/shutdown.test.js +84 -0
- package/server/lib/tts/service.test.js +78 -0
- package/server/lib/ui-auth/DOCUMENTATION.md +8 -0
- package/server/lib/ui-auth/session-cookie.js +51 -0
- package/server/lib/ui-auth/session-cookie.test.js +46 -0
- package/server/lib/ui-auth/ui-auth.js +13 -9
- package/server/lib/ui-auth/ui-auth.test.js +56 -0
- package/dist/assets/DiffView-B7YkbY-u.js +0 -4
- package/dist/assets/DirtyBranchSwitchDialog-CU0A93Zx.js +0 -1
- package/dist/assets/GitView-BLhlMYEY.js +0 -6
- package/dist/assets/GuestAttachDialog-B-fwE8r3.js +0 -3
- package/dist/assets/PierreDiffViewer-53Ghfnlr.js +0 -161
- package/dist/assets/SettingsView-n2X-jfBB.js +0 -29
- package/dist/assets/SettingsWindow-Bi8LE9XI.js +0 -1
- package/dist/assets/index-DpzTz2UH.css +0 -1
- package/dist/assets/index-Dy8xgawx.js +0 -40
- package/dist/assets/ja-DxqeAk9N.js +0 -16
- package/dist/assets/main-BOYSXfYn.js +0 -896
- package/dist/assets/main-Bjcre_GE.js +0 -2
- package/dist/assets/markdownCore-DPrwM1rU.js +0 -5
- package/dist/assets/miniChat-Dz_bPgMc.js +0 -2
- package/dist/assets/mobile-BbZPBJrK.js +0 -2
- package/dist/assets/renderElectronMiniChatApp-uNEUkeAI.js +0 -2
- package/dist/assets/renderMobileApp-BK1kFlcJ.js +0 -25
- package/dist/assets/runtimeEndpointReset-BULHvOwb.js +0 -25
- package/dist/assets/tr-cIQtYBpg.js +0 -7
- package/dist/assets/useRootScrollLock-Cwc4kSl2.js +0 -1
- package/dist/assets/zh-CN-BWvlPHY-.js +0 -16
- /package/dist/assets/{vendor-katex-k3Ppq1Ha.js → vendor-katex-CHD9BdDO.js} +0 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Routing configuration on disk.
|
|
3
|
+
*
|
|
4
|
+
* `routing.json` holds only deviations from the built-in defaults: a patched or
|
|
5
|
+
* disabled built-in category, a user category, the fallback model, thresholds.
|
|
6
|
+
* `routing-auth.json` holds the Jev API key alone, mode 0600, so the config
|
|
7
|
+
* file can be read, shown and exported without carrying a secret.
|
|
8
|
+
*
|
|
9
|
+
* Reads never throw on a missing file (a fresh install is the defaults); a
|
|
10
|
+
* malformed file is an error, not an empty config, so a bad write cannot
|
|
11
|
+
* silently reset the user's categories.
|
|
12
|
+
*/
|
|
13
|
+
import fs from 'node:fs/promises';
|
|
14
|
+
import path from 'node:path';
|
|
15
|
+
import { z } from 'zod';
|
|
16
|
+
import {
|
|
17
|
+
BUILTIN_CATEGORIES,
|
|
18
|
+
DEFAULT_MIN_CONFIDENCE,
|
|
19
|
+
DEFAULT_SAFETY_THRESHOLD,
|
|
20
|
+
THINKING_LEVELS,
|
|
21
|
+
isAutoModel,
|
|
22
|
+
} from './defaults.js';
|
|
23
|
+
|
|
24
|
+
const FILE_VERSION = 1;
|
|
25
|
+
const CATEGORY_ID = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
26
|
+
|
|
27
|
+
// The Auto sentinel is what routing resolves *from*; as a fallback or category
|
|
28
|
+
// model it would send itself to OpenCode.
|
|
29
|
+
const modelSchema = z.object({
|
|
30
|
+
providerID: z.string().trim().min(1).max(200),
|
|
31
|
+
modelID: z.string().trim().min(1).max(200),
|
|
32
|
+
}).strict().refine((model) => !isAutoModel(model), { message: 'The Auto model cannot be a routing target' });
|
|
33
|
+
|
|
34
|
+
const variantSchema = z.string().trim().min(1).max(80).nullable();
|
|
35
|
+
const agentSchema = z.string().trim().min(1).max(80).nullable();
|
|
36
|
+
|
|
37
|
+
/** A built-in category on disk carries only what the user changed. */
|
|
38
|
+
const builtinOverrideSchema = z.object({
|
|
39
|
+
builtin: z.literal(true),
|
|
40
|
+
disabled: z.boolean().optional(),
|
|
41
|
+
deleted: z.boolean().optional(),
|
|
42
|
+
name: z.string().trim().min(1).max(60).optional(),
|
|
43
|
+
description: z.string().trim().min(1).max(2000).optional(),
|
|
44
|
+
model: modelSchema.nullable().optional(),
|
|
45
|
+
variant: variantSchema.optional(),
|
|
46
|
+
agent: agentSchema.optional(),
|
|
47
|
+
}).strict();
|
|
48
|
+
|
|
49
|
+
const userCategorySchema = z.object({
|
|
50
|
+
builtin: z.literal(false),
|
|
51
|
+
disabled: z.boolean().optional(),
|
|
52
|
+
name: z.string().trim().min(1).max(60),
|
|
53
|
+
description: z.string().trim().min(1).max(2000),
|
|
54
|
+
model: modelSchema.nullable().optional(),
|
|
55
|
+
variant: variantSchema.optional(),
|
|
56
|
+
agent: agentSchema.optional(),
|
|
57
|
+
}).strict();
|
|
58
|
+
|
|
59
|
+
const fileSchema = z.object({
|
|
60
|
+
version: z.literal(FILE_VERSION),
|
|
61
|
+
enabled: z.boolean().optional(),
|
|
62
|
+
fallback: z.object({ model: modelSchema, variant: variantSchema.optional() }).strict().nullable().optional(),
|
|
63
|
+
minConfidence: z.number().min(0).max(1).optional(),
|
|
64
|
+
safetyNet: z.object({ enabled: z.boolean(), threshold: z.number().min(0).max(1) }).strict().optional(),
|
|
65
|
+
categories: z.record(z.string().regex(CATEGORY_ID), z.discriminatedUnion('builtin', [builtinOverrideSchema, userCategorySchema])).optional(),
|
|
66
|
+
}).strict();
|
|
67
|
+
|
|
68
|
+
/** The effective category the runtime and the UI work with. */
|
|
69
|
+
const effectiveCategorySchema = z.object({
|
|
70
|
+
id: z.string().regex(CATEGORY_ID),
|
|
71
|
+
builtin: z.boolean(),
|
|
72
|
+
enabled: z.boolean(),
|
|
73
|
+
name: z.string().trim().min(1).max(60),
|
|
74
|
+
description: z.string().trim().min(1).max(2000),
|
|
75
|
+
model: modelSchema.nullable(),
|
|
76
|
+
variant: variantSchema,
|
|
77
|
+
agent: agentSchema,
|
|
78
|
+
}).strict();
|
|
79
|
+
|
|
80
|
+
const effectiveConfigSchema = z.object({
|
|
81
|
+
enabled: z.boolean(),
|
|
82
|
+
fallback: z.object({ model: modelSchema, variant: variantSchema }).strict().nullable(),
|
|
83
|
+
minConfidence: z.number().min(0).max(1),
|
|
84
|
+
safetyNet: z.object({ enabled: z.boolean(), threshold: z.number().min(0).max(1) }).strict(),
|
|
85
|
+
categories: z.array(effectiveCategorySchema).max(32),
|
|
86
|
+
}).strict();
|
|
87
|
+
|
|
88
|
+
const authSchema = z.object({ token: z.string().min(1).max(4000) }).strict();
|
|
89
|
+
|
|
90
|
+
const routingConfigPath = (dataDir) => path.join(dataDir, 'routing.json');
|
|
91
|
+
const routingAuthPath = (dataDir) => path.join(dataDir, 'routing-auth.json');
|
|
92
|
+
|
|
93
|
+
const readJsonFile = async (file, schema) => {
|
|
94
|
+
let raw;
|
|
95
|
+
try {
|
|
96
|
+
raw = await fs.readFile(file, 'utf8');
|
|
97
|
+
} catch (error) {
|
|
98
|
+
if (error?.code === 'ENOENT') return null;
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
const text = raw.replace(/^/, '').trim();
|
|
102
|
+
if (text === '') return null;
|
|
103
|
+
const parsed = schema.safeParse(JSON.parse(text));
|
|
104
|
+
if (!parsed.success) throw new Error(`Invalid ${path.basename(file)}: ${parsed.error.issues[0]?.message ?? 'schema mismatch'}`);
|
|
105
|
+
return parsed.data;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const writeJsonFile = async (file, value, mode) => {
|
|
109
|
+
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
110
|
+
const tmp = `${file}.tmp-${process.pid}-${Date.now()}`;
|
|
111
|
+
await fs.writeFile(tmp, `${JSON.stringify(value, null, 2)}\n`, { encoding: 'utf8', mode });
|
|
112
|
+
await fs.rename(tmp, file);
|
|
113
|
+
if (mode) await fs.chmod(file, mode);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const emptyFile = () => ({ version: FILE_VERSION });
|
|
117
|
+
|
|
118
|
+
/** Built-ins plus the stored deviations, in built-in order followed by user categories. */
|
|
119
|
+
export const resolveEffectiveConfig = (stored) => {
|
|
120
|
+
const file = stored ?? emptyFile();
|
|
121
|
+
const overrides = file.categories ?? {};
|
|
122
|
+
const categories = [];
|
|
123
|
+
for (const builtin of BUILTIN_CATEGORIES) {
|
|
124
|
+
const override = overrides[builtin.id];
|
|
125
|
+
if (override && override.builtin !== true) continue; // a user id colliding with a built-in is ignored
|
|
126
|
+
if (override?.deleted) continue;
|
|
127
|
+
categories.push({
|
|
128
|
+
id: builtin.id,
|
|
129
|
+
builtin: true,
|
|
130
|
+
enabled: !(override?.disabled === true),
|
|
131
|
+
name: override?.name ?? builtin.name,
|
|
132
|
+
description: override?.description ?? builtin.description,
|
|
133
|
+
model: override?.model ?? null,
|
|
134
|
+
variant: override?.variant ?? null,
|
|
135
|
+
agent: override?.agent ?? null,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
for (const [id, entry] of Object.entries(overrides)) {
|
|
139
|
+
if (entry.builtin !== false) continue;
|
|
140
|
+
categories.push({
|
|
141
|
+
id,
|
|
142
|
+
builtin: false,
|
|
143
|
+
enabled: !(entry.disabled === true),
|
|
144
|
+
name: entry.name,
|
|
145
|
+
description: entry.description,
|
|
146
|
+
model: entry.model ?? null,
|
|
147
|
+
variant: entry.variant ?? null,
|
|
148
|
+
agent: entry.agent ?? null,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
enabled: file.enabled ?? false,
|
|
153
|
+
fallback: file.fallback ? { model: file.fallback.model, variant: file.fallback.variant ?? null } : null,
|
|
154
|
+
minConfidence: file.minConfidence ?? DEFAULT_MIN_CONFIDENCE,
|
|
155
|
+
safetyNet: file.safetyNet ?? { enabled: false, threshold: DEFAULT_SAFETY_THRESHOLD },
|
|
156
|
+
categories,
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/** The stored shape for an effective config: built-ins keep only their deviations. */
|
|
161
|
+
export const toStoredConfig = (config) => {
|
|
162
|
+
const categories = {};
|
|
163
|
+
const builtinIds = new Set(BUILTIN_CATEGORIES.map((c) => c.id));
|
|
164
|
+
const present = new Set();
|
|
165
|
+
for (const category of config.categories) {
|
|
166
|
+
present.add(category.id);
|
|
167
|
+
if (category.builtin) {
|
|
168
|
+
const builtin = BUILTIN_CATEGORIES.find((c) => c.id === category.id);
|
|
169
|
+
if (!builtin) continue;
|
|
170
|
+
const override = { builtin: true };
|
|
171
|
+
if (!category.enabled) override.disabled = true;
|
|
172
|
+
if (category.name !== builtin.name) override.name = category.name;
|
|
173
|
+
if (category.description !== builtin.description) override.description = category.description;
|
|
174
|
+
if (category.model) override.model = category.model;
|
|
175
|
+
if (category.variant) override.variant = category.variant;
|
|
176
|
+
if (category.agent) override.agent = category.agent;
|
|
177
|
+
if (Object.keys(override).length > 1) categories[category.id] = override;
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
if (builtinIds.has(category.id)) continue;
|
|
181
|
+
const entry = { builtin: false, name: category.name, description: category.description };
|
|
182
|
+
if (!category.enabled) entry.disabled = true;
|
|
183
|
+
if (category.model) entry.model = category.model;
|
|
184
|
+
if (category.variant) entry.variant = category.variant;
|
|
185
|
+
if (category.agent) entry.agent = category.agent;
|
|
186
|
+
categories[category.id] = entry;
|
|
187
|
+
}
|
|
188
|
+
for (const builtin of BUILTIN_CATEGORIES) {
|
|
189
|
+
if (!present.has(builtin.id)) categories[builtin.id] = { builtin: true, deleted: true };
|
|
190
|
+
}
|
|
191
|
+
const stored = { version: FILE_VERSION, enabled: config.enabled, minConfidence: config.minConfidence, safetyNet: config.safetyNet };
|
|
192
|
+
if (config.fallback) {
|
|
193
|
+
stored.fallback = { model: config.fallback.model };
|
|
194
|
+
if (config.fallback.variant) stored.fallback.variant = config.fallback.variant;
|
|
195
|
+
}
|
|
196
|
+
if (Object.keys(categories).length > 0) stored.categories = categories;
|
|
197
|
+
return stored;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
/** Parses an untrusted effective config (a PUT body) into the trusted shape, or throws. */
|
|
201
|
+
export const parseEffectiveConfig = (input) => {
|
|
202
|
+
const parsed = effectiveConfigSchema.safeParse(input);
|
|
203
|
+
if (!parsed.success) {
|
|
204
|
+
const issue = parsed.error.issues[0];
|
|
205
|
+
throw Object.assign(new Error(`Invalid routing config at ${issue?.path.join('.') || 'root'}: ${issue?.message ?? 'schema mismatch'}`), { status: 400 });
|
|
206
|
+
}
|
|
207
|
+
const config = parsed.data;
|
|
208
|
+
const ids = new Set();
|
|
209
|
+
for (const category of config.categories) {
|
|
210
|
+
if (ids.has(category.id)) throw Object.assign(new Error(`Duplicate category id ${category.id}`), { status: 400 });
|
|
211
|
+
ids.add(category.id);
|
|
212
|
+
if (category.variant && !THINKING_LEVELS.includes(category.variant) && !/^[\w.-]+$/.test(category.variant)) {
|
|
213
|
+
throw Object.assign(new Error(`Invalid variant for ${category.id}`), { status: 400 });
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return config;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
export const createRoutingStore = ({ dataDir }) => {
|
|
220
|
+
const configFile = routingConfigPath(dataDir);
|
|
221
|
+
const authFile = routingAuthPath(dataDir);
|
|
222
|
+
let writeChain = Promise.resolve();
|
|
223
|
+
const serialize = (run) => {
|
|
224
|
+
const next = writeChain.catch(() => undefined).then(run);
|
|
225
|
+
writeChain = next;
|
|
226
|
+
return next;
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
return {
|
|
230
|
+
/** Effective config; a missing file is the defaults, a broken file throws. */
|
|
231
|
+
readConfig: async () => resolveEffectiveConfig(await readJsonFile(configFile, fileSchema)),
|
|
232
|
+
writeConfig: (config) => serialize(async () => {
|
|
233
|
+
await writeJsonFile(configFile, toStoredConfig(config));
|
|
234
|
+
return config;
|
|
235
|
+
}),
|
|
236
|
+
readToken: async () => {
|
|
237
|
+
try {
|
|
238
|
+
return (await readJsonFile(authFile, authSchema))?.token ?? null;
|
|
239
|
+
} catch (error) {
|
|
240
|
+
console.warn('[routing] routing-auth.json is unreadable:', error?.message ?? error);
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
writeToken: (token) => serialize(() => writeJsonFile(authFile, { token }, 0o600)),
|
|
245
|
+
clearToken: () => serialize(async () => {
|
|
246
|
+
await fs.rm(authFile, { force: true });
|
|
247
|
+
}),
|
|
248
|
+
};
|
|
249
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { createRoutingStore, parseEffectiveConfig, resolveEffectiveConfig, toStoredConfig } from './store.js';
|
|
6
|
+
import { BUILTIN_CATEGORIES } from './defaults.js';
|
|
7
|
+
|
|
8
|
+
const tempDir = () => fs.mkdtemp(path.join(os.tmpdir(), 'routing-store-'));
|
|
9
|
+
|
|
10
|
+
const sampleConfig = (patch = {}) => ({
|
|
11
|
+
enabled: true,
|
|
12
|
+
fallback: { model: { providerID: 'anthropic', modelID: 'claude-sonnet-5' }, variant: 'medium' },
|
|
13
|
+
minConfidence: 0.6,
|
|
14
|
+
safetyNet: { enabled: true, threshold: 0.6 },
|
|
15
|
+
categories: resolveEffectiveConfig(null).categories,
|
|
16
|
+
...patch,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe('routing store', () => {
|
|
20
|
+
it('resolves the defaults when nothing is stored', async () => {
|
|
21
|
+
const store = createRoutingStore({ dataDir: await tempDir() });
|
|
22
|
+
const config = await store.readConfig();
|
|
23
|
+
expect(config.enabled).toBe(false);
|
|
24
|
+
expect(config.fallback).toBeNull();
|
|
25
|
+
expect(config.categories.map((c) => c.id)).toEqual(BUILTIN_CATEGORIES.map((c) => c.id));
|
|
26
|
+
expect(config.categories.every((c) => c.builtin && c.enabled && c.model === null)).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('stores only deviations from the built-ins and round-trips them', async () => {
|
|
30
|
+
const dir = await tempDir();
|
|
31
|
+
const store = createRoutingStore({ dataDir: dir });
|
|
32
|
+
const config = sampleConfig();
|
|
33
|
+
config.categories[0] = { ...config.categories[0], enabled: false };
|
|
34
|
+
config.categories[3] = { ...config.categories[3], model: { providerID: 'openai', modelID: 'gpt-6-astra' }, variant: 'high', agent: 'plan' };
|
|
35
|
+
config.categories.push({ id: 'my-refactors', builtin: false, enabled: true, name: 'My refactors', description: 'Refactors across modules.', model: null, variant: null, agent: null });
|
|
36
|
+
await store.writeConfig(config);
|
|
37
|
+
|
|
38
|
+
const stored = JSON.parse(await fs.readFile(path.join(dir, 'routing.json'), 'utf8'));
|
|
39
|
+
expect(stored.categories).toEqual({
|
|
40
|
+
trivial: { builtin: true, disabled: true },
|
|
41
|
+
hard: { builtin: true, model: { providerID: 'openai', modelID: 'gpt-6-astra' }, variant: 'high', agent: 'plan' },
|
|
42
|
+
'my-refactors': { builtin: false, name: 'My refactors', description: 'Refactors across modules.' },
|
|
43
|
+
});
|
|
44
|
+
expect(await store.readConfig()).toEqual(config);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('records a removed built-in as deleted and keeps the others', async () => {
|
|
48
|
+
const config = sampleConfig();
|
|
49
|
+
config.categories = config.categories.filter((c) => c.id !== 'research');
|
|
50
|
+
const stored = toStoredConfig(config);
|
|
51
|
+
expect(stored.categories.research).toEqual({ builtin: true, deleted: true });
|
|
52
|
+
const resolved = resolveEffectiveConfig(stored);
|
|
53
|
+
expect(resolved.categories.map((c) => c.id)).toEqual(['trivial', 'implement', 'hard']);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('applies later built-in text to an untouched category but keeps an edited one', () => {
|
|
57
|
+
const edited = resolveEffectiveConfig({ version: 1, categories: { hard: { builtin: true, description: 'My own hard.' } } });
|
|
58
|
+
expect(edited.categories.find((c) => c.id === 'hard').description).toBe('My own hard.');
|
|
59
|
+
expect(edited.categories.find((c) => c.id === 'trivial').description).toBe(BUILTIN_CATEGORIES[0].description);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('rejects a malformed file instead of treating it as empty', async () => {
|
|
63
|
+
const dir = await tempDir();
|
|
64
|
+
await fs.writeFile(path.join(dir, 'routing.json'), '{"version":1,"categories":{"x":{"builtin":false}}}');
|
|
65
|
+
const store = createRoutingStore({ dataDir: dir });
|
|
66
|
+
await expect(store.readConfig()).rejects.toThrow(/Invalid routing.json/);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('rejects an invalid PUT body with a 400 status', () => {
|
|
70
|
+
expect(() => parseEffectiveConfig({ enabled: true })).toThrow(expect.objectContaining({ status: 400 }));
|
|
71
|
+
const duplicate = sampleConfig();
|
|
72
|
+
duplicate.categories = [...duplicate.categories, { ...duplicate.categories[0], builtin: false }];
|
|
73
|
+
expect(() => parseEffectiveConfig(duplicate)).toThrow(/Duplicate category id/);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('refuses the Auto sentinel as a fallback or category model', () => {
|
|
77
|
+
const asFallback = sampleConfig({ fallback: { model: { providerID: 'openchamber', modelID: 'auto' }, variant: null } });
|
|
78
|
+
expect(() => parseEffectiveConfig(asFallback)).toThrow(/Auto model cannot be a routing target/);
|
|
79
|
+
const asCategory = sampleConfig();
|
|
80
|
+
asCategory.categories = asCategory.categories.map((c, i) => (i === 0 ? { ...c, model: { providerID: 'openchamber', modelID: 'auto' } } : c));
|
|
81
|
+
expect(() => parseEffectiveConfig(asCategory)).toThrow(/Auto model cannot be a routing target/);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('keeps the token in its own 0600 file and clears it', async () => {
|
|
85
|
+
const dir = await tempDir();
|
|
86
|
+
const store = createRoutingStore({ dataDir: dir });
|
|
87
|
+
expect(await store.readToken()).toBeNull();
|
|
88
|
+
await store.writeToken('ts-secret');
|
|
89
|
+
expect(await store.readToken()).toBe('ts-secret');
|
|
90
|
+
const stat = await fs.stat(path.join(dir, 'routing-auth.json'));
|
|
91
|
+
if (process.platform !== 'win32') expect(stat.mode & 0o777).toBe(0o600);
|
|
92
|
+
expect(JSON.stringify(JSON.parse(await fs.readFile(path.join(dir, 'routing.json'), 'utf8').catch(() => '{}')))).not.toContain('ts-secret');
|
|
93
|
+
await store.clearToken();
|
|
94
|
+
expect(await store.readToken()).toBeNull();
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createOpencodeClient } from '@opencode-ai/sdk/v2';
|
|
2
2
|
import { DateTime } from 'luxon';
|
|
3
|
-
import
|
|
3
|
+
import { CronExpressionParser } from 'cron-parser';
|
|
4
4
|
import { expandSnippets } from '../opencode/snippets.js';
|
|
5
5
|
import { buildGoalIntroText, createSessionGoal } from '../session-goal/create.js';
|
|
6
6
|
import { discoverLoops } from './loops.js';
|
|
@@ -216,7 +216,7 @@ export const computeNextRunAt = (task, nowMs = Date.now()) => {
|
|
|
216
216
|
|
|
217
217
|
if (schedule.kind === 'cron') {
|
|
218
218
|
try {
|
|
219
|
-
const iterator =
|
|
219
|
+
const iterator = CronExpressionParser.parse(schedule.cron, {
|
|
220
220
|
tz: zone,
|
|
221
221
|
currentDate: new Date(nowMs),
|
|
222
222
|
});
|
|
@@ -12,6 +12,20 @@ import {
|
|
|
12
12
|
import { createProjectConfigRuntime } from '../projects/project-config.js';
|
|
13
13
|
|
|
14
14
|
describe('scheduled-tasks runtime helpers', () => {
|
|
15
|
+
it.each([
|
|
16
|
+
['*/15 * * * *', 'UTC', '2026-09-18T08:07:00Z', '2026-09-18T08:15:00Z'],
|
|
17
|
+
['30 */5 * * * *', 'UTC', '2026-09-18T08:07:00Z', '2026-09-18T08:10:30Z'],
|
|
18
|
+
['0 9 * * MON-FRI', 'Europe/Kyiv', '2026-09-18T07:00:00Z', '2026-09-21T06:00:00Z'],
|
|
19
|
+
['0 9 * * *', 'Europe/Kyiv', '2026-03-28T08:00:00Z', '2026-03-29T06:00:00Z'],
|
|
20
|
+
['0 9 * * *', 'Europe/Kyiv', '2026-10-24T08:00:00Z', '2026-10-25T07:00:00Z'],
|
|
21
|
+
['0 0 L * *', 'UTC', '2026-02-01T00:00:00Z', '2026-02-28T00:00:00Z'],
|
|
22
|
+
])('computes cron %s in %s from %s', (cron, timezone, now, expected) => {
|
|
23
|
+
expect(computeNextRunAt({
|
|
24
|
+
enabled: true,
|
|
25
|
+
schedule: { kind: 'cron', cron, timezone },
|
|
26
|
+
}, Date.parse(now))).toBe(Date.parse(expected));
|
|
27
|
+
});
|
|
28
|
+
|
|
15
29
|
it('computes next daily run in timezone', () => {
|
|
16
30
|
const nowUtc = Date.UTC(2025, 0, 1, 8, 0, 0);
|
|
17
31
|
const next = computeNextRunAt({
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { sessionCookieNameForRequest } from '../ui-auth/session-cookie.js';
|
|
2
|
+
|
|
1
3
|
export const createRequestSecurityRuntime = (deps) => {
|
|
2
4
|
const { readSettingsFromDiskMigrated } = deps;
|
|
3
5
|
// Origins of packaged (non-browser) clients whose WebView origin never
|
|
@@ -17,12 +19,14 @@ export const createRequestSecurityRuntime = (deps) => {
|
|
|
17
19
|
if (!cookieHeader || typeof cookieHeader !== 'string') {
|
|
18
20
|
return null;
|
|
19
21
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
// Match the exact slot for the host:port this request arrived on. A browser
|
|
23
|
+
// shares cookies across ports on LAN and loopback hosts. This extracts
|
|
24
|
+
// notification/session identity, not a CSRF token, using the same name
|
|
25
|
+
// as ui-auth's session issuance and validation.
|
|
26
|
+
const expected = sessionCookieNameForRequest(req);
|
|
27
|
+
for (const segment of cookieHeader.split(';')) {
|
|
22
28
|
const [rawName, ...rest] = segment.split('=');
|
|
23
|
-
|
|
24
|
-
if (!name) continue;
|
|
25
|
-
if (name !== 'oc_ui_session') continue;
|
|
29
|
+
if (rawName?.trim() !== expected) continue;
|
|
26
30
|
const value = rest.join('=').trim();
|
|
27
31
|
try {
|
|
28
32
|
return decodeURIComponent(value || '');
|
|
@@ -80,4 +80,41 @@ describe('request security runtime', () => {
|
|
|
80
80
|
headers: { ...request.headers, origin: 'https://evil.example.com' },
|
|
81
81
|
})).toBe(false);
|
|
82
82
|
});
|
|
83
|
+
|
|
84
|
+
test('reads the slot for the request port when a browser shares jars across LAN ports', () => {
|
|
85
|
+
const runtime = createRuntime();
|
|
86
|
+
// Two instances on one LAN IP: the browser sends BOTH session cookies to
|
|
87
|
+
// either port (browsers key cookie jars on host, not port — issue #2377).
|
|
88
|
+
const req = {
|
|
89
|
+
headers: {
|
|
90
|
+
host: '192.168.0.1:3001',
|
|
91
|
+
cookie: 'oc_ui_session_3000=token-a; oc_ui_session_3001=token-b',
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
expect(runtime.getUiSessionTokenFromRequest(req)).toBe('token-b');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('never reads another port cookie when this port has none of its own', () => {
|
|
98
|
+
const runtime = createRuntime();
|
|
99
|
+
// Reaching :3001 with only the :3000 cookie in the jar must NOT borrow the
|
|
100
|
+
// other instance's session — it stays unauthenticated for this port.
|
|
101
|
+
const req = {
|
|
102
|
+
headers: { host: '192.168.0.1:3001', cookie: 'oc_ui_session_3000=token-a' },
|
|
103
|
+
};
|
|
104
|
+
expect(runtime.getUiSessionTokenFromRequest(req)).toBeNull();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('reads the bare cookie for a host without an explicit port', () => {
|
|
108
|
+
const runtime = createRuntime();
|
|
109
|
+
const req = {
|
|
110
|
+
headers: { host: '192.168.0.1', cookie: 'oc_ui_session=token-bare' },
|
|
111
|
+
};
|
|
112
|
+
expect(runtime.getUiSessionTokenFromRequest(req)).toBe('token-bare');
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('returns null when no session cookie is present', () => {
|
|
116
|
+
const runtime = createRuntime();
|
|
117
|
+
const req = { headers: { host: '192.168.0.1:3000', cookie: 'theme=dark; oc_url_token=x' } };
|
|
118
|
+
expect(runtime.getUiSessionTokenFromRequest(req)).toBeNull();
|
|
119
|
+
});
|
|
83
120
|
});
|
|
@@ -118,14 +118,26 @@ other runtime API.
|
|
|
118
118
|
provider's base URL, resolved from (1) `provider.<id>.options.baseURL`
|
|
119
119
|
in the OpenCode config, (2) the hardcoded `https://api.openai.com/v1`
|
|
120
120
|
endpoint, (3) the selected model's endpoint OpenCode resolved at runtime,
|
|
121
|
-
(4) the provider-level runtime endpoint,
|
|
122
|
-
from the models.dev catalog
|
|
121
|
+
(4) the provider-level runtime endpoint, (5) the provider's `api` field
|
|
122
|
+
from the models.dev catalog, or (6) `SDK_DEFAULT_BASE_URLS` — providers
|
|
123
|
+
such as Groq, xAI, and Mistral keep their endpoint inside a dedicated AI
|
|
124
|
+
SDK package, so neither the catalog nor OpenCode reports one. The
|
|
125
|
+
credential follows
|
|
123
126
|
the same shape: config `options.apiKey`, then the runtime credential, then
|
|
124
127
|
the auth.json entry. `provider.<id>.options.headers` is sent with the
|
|
125
128
|
request and overrides the bearer default, so gateways that authenticate on
|
|
126
129
|
their own header work here exactly as they do in a chat turn. Configured API
|
|
127
130
|
keys and header values honor OpenCode's `{env:NAME}` and `{file:path}`
|
|
128
131
|
substitutions; file contents and resolved credentials remain server-side.
|
|
132
|
+
- `thinking: { type: 'disabled' }` is sent in two cases, mirroring OpenCode's
|
|
133
|
+
`transform.ts`. The GLM switch belongs to the endpoint, not the model
|
|
134
|
+
family: it goes to a provider whose id contains `zai`/`zhipu` or whose
|
|
135
|
+
base URL is on `api.z.ai`/`bigmodel.cn`, because the same GLM model served
|
|
136
|
+
by another provider (OpenCode Go) rejects the unknown field with a 400.
|
|
137
|
+
The MiniMax M3 switch goes only behind the `@ai-sdk/openai-compatible` and
|
|
138
|
+
`@ai-sdk/anthropic` adapters (runtime model, then catalog model, then
|
|
139
|
+
catalog provider `npm`); a provider that reports no adapter counts as
|
|
140
|
+
OpenAI-compatible.
|
|
129
141
|
- The runtime credential is refused for providers listed in
|
|
130
142
|
`OWN_CREDENTIAL_HANDLING`. Their branches need the stored entry rather than
|
|
131
143
|
a bearer token: the clearest case is the ChatGPT-plan `openai` login, whose
|
|
@@ -20,6 +20,25 @@ const DEFAULT_MAX_OUTPUT_TOKENS = 4_000;
|
|
|
20
20
|
|
|
21
21
|
const USER_AGENT = 'opencode/1.0 openchamber';
|
|
22
22
|
|
|
23
|
+
// Providers whose endpoint lives inside their dedicated AI SDK package, so the
|
|
24
|
+
// models.dev catalog carries no `api` URL and OpenCode reports none at runtime.
|
|
25
|
+
// Each of these serves OpenAI-compatible `/chat/completions` at the URL below.
|
|
26
|
+
const SDK_DEFAULT_BASE_URLS = new Map([
|
|
27
|
+
['groq', 'https://api.groq.com/openai/v1'],
|
|
28
|
+
['xai', 'https://api.x.ai/v1'],
|
|
29
|
+
['mistral', 'https://api.mistral.ai/v1'],
|
|
30
|
+
['cerebras', 'https://api.cerebras.ai/v1'],
|
|
31
|
+
['togetherai', 'https://api.together.xyz/v1'],
|
|
32
|
+
['deepinfra', 'https://api.deepinfra.com/v1/openai'],
|
|
33
|
+
['perplexity', 'https://api.perplexity.ai'],
|
|
34
|
+
['cohere', 'https://api.cohere.ai/compatibility/v1'],
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
// Where `thinking: { type: 'disabled' }` is a real switch rather than an
|
|
38
|
+
// unknown field (mirrors the gates in OpenCode's provider/transform.ts).
|
|
39
|
+
const ZAI_ENDPOINT_HOSTS = ['api.z.ai', 'bigmodel.cn'];
|
|
40
|
+
const MINIMAX_THINKING_ADAPTERS = new Set(['@ai-sdk/openai-compatible', '@ai-sdk/anthropic']);
|
|
41
|
+
|
|
23
42
|
const mergeHeadersCaseInsensitive = (base, overrides) => {
|
|
24
43
|
const merged = { ...base };
|
|
25
44
|
for (const [name, value] of Object.entries(overrides || {})) {
|
|
@@ -765,7 +784,8 @@ export async function callSmallModel({ auth, catalog, workingDirectory, sessionI
|
|
|
765
784
|
// selected model's endpoint OpenCode resolved at runtime, then to the
|
|
766
785
|
// provider-level runtime endpoint. For a plugin provider, the runtime listing
|
|
767
786
|
// is the only place those endpoints exist, and several are local proxies the
|
|
768
|
-
// plugin itself runs.
|
|
787
|
+
// plugin itself runs. Last comes SDK_DEFAULT_BASE_URLS, for providers whose
|
|
788
|
+
// endpoint only their SDK package knows. The openai provider also respects
|
|
769
789
|
// provider.openai.options.baseURL — OpenCode itself uses the same config for
|
|
770
790
|
// all providers including openai.
|
|
771
791
|
const provider = getCatalogProvider(catalog, providerID);
|
|
@@ -779,7 +799,7 @@ export async function callSmallModel({ auth, catalog, workingDirectory, sessionI
|
|
|
779
799
|
?? runtimeProvider?.baseURL
|
|
780
800
|
?? (typeof provider?.api === 'string' && provider.api
|
|
781
801
|
? provider.api
|
|
782
|
-
: null);
|
|
802
|
+
: SDK_DEFAULT_BASE_URLS.get(providerID) ?? null);
|
|
783
803
|
if (!baseURL) {
|
|
784
804
|
throw new Error(`Provider "${providerID}" has no known API base URL`);
|
|
785
805
|
}
|
|
@@ -790,11 +810,22 @@ export async function callSmallModel({ auth, catalog, workingDirectory, sessionI
|
|
|
790
810
|
// parameter: unknown body fields 400 on some providers, so this stays an
|
|
791
811
|
// explicit allowlist. Models without a switch (DeepSeek, Qwen, Kimi, …)
|
|
792
812
|
// just get the generous output budget.
|
|
793
|
-
|
|
794
|
-
|
|
813
|
+
// GLM's switch belongs to the Z.ai/Zhipu endpoints, not to the model: the
|
|
814
|
+
// same GLM served by another provider (OpenCode Go) rejects the field. The
|
|
815
|
+
// host check keeps the switch for a custom-named provider pointed at them.
|
|
816
|
+
const servedByZai = providerID.includes('zai')
|
|
795
817
|
|| providerID.includes('zhipu')
|
|
796
|
-
||
|
|
797
|
-
|
|
818
|
+
|| ZAI_ENDPOINT_HOSTS.some((host) => baseURL.includes(host));
|
|
819
|
+
// MiniMax M3's switch is understood only behind the adapters OpenCode sends
|
|
820
|
+
// it through. An adapter nobody reports (a custom provider) is OpenAI-
|
|
821
|
+
// compatible by OpenCode's own default.
|
|
822
|
+
const adapter = runtimeModel?.api?.npm
|
|
823
|
+
?? provider?.models?.[modelID]?.provider?.npm
|
|
824
|
+
?? provider?.npm
|
|
825
|
+
?? null;
|
|
826
|
+
const minimaxSwitch = modelID.toLowerCase().includes('minimax-m3')
|
|
827
|
+
&& (adapter === null || MINIMAX_THINKING_ADAPTERS.has(adapter));
|
|
828
|
+
const supportsThinkingToggle = servedByZai || minimaxSwitch;
|
|
798
829
|
const extraBody = supportsThinkingToggle ? { thinking: { type: 'disabled' } } : undefined;
|
|
799
830
|
|
|
800
831
|
return callOpenaiCompatible({
|