@openchamber/web 2.0.2 → 2.0.4
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/lib/DOCUMENTATION.md +1 -1
- package/bin/lib/commands-connect-url.js +6 -5
- package/bin/lib/commands-tunnel.js +24 -5
- package/dist/assets/{CodeMirrorCommentWidgets-CmKmyb9T.js → CodeMirrorCommentWidgets-C_zL-eri.js} +1 -1
- package/dist/assets/{DiffView-8-PFpZ2p.js → DiffView-BeN2_YYF.js} +3 -3
- package/dist/assets/FilesView-CN34wm_N.js +17 -0
- package/dist/assets/{GitView-DNUSu00w.js → GitView-DLDazOo1.js} +4 -4
- package/dist/assets/{GuestAttachDialog-Cv6QzjHC.js → GuestAttachDialog-C0xe_Lyy.js} +1 -1
- package/dist/assets/{GuestSurfacePane-Bt3jB_Ye.js → GuestSurfacePane-BdaurnDr.js} +1 -1
- package/dist/assets/{JsonTreeView-BlyHTRhM.js → JsonTreeView-B1Xq-k2t.js} +1 -1
- package/dist/assets/LinearIssuesView-BryoAHow.js +1 -0
- package/dist/assets/{MarkdownImageGallery-2UXJF-5B.js → MarkdownImageGallery-DfuEoaGq.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-B_ZcWOvX.js +12 -0
- package/dist/assets/OnboardingScreen-C22bGmnP.js +1 -0
- package/dist/assets/{PatchDiff-ByvnbG5T.js → PatchDiff-0xd6UeFB.js} +1 -1
- package/dist/assets/{PierreDiffViewer-BXieg0mH.js → PierreDiffViewer-BC950e3F.js} +3 -3
- package/dist/assets/PlanView-B7Xgihqk.js +5 -0
- package/dist/assets/PluginPane-2C71F8uF.js +3 -0
- package/dist/assets/SettingsView-m_zoFiaT.js +30 -0
- package/dist/assets/{SettingsWindow-BIz224xs.js → SettingsWindow-CofS020b.js} +1 -1
- package/dist/assets/{SubmoduleDiffSummary-CXKmlps9.js → SubmoduleDiffSummary-BSA9gnIO.js} +1 -1
- package/dist/assets/{ToolOutputDialog-BsgAK8xu.js → ToolOutputDialog-DprkVKcj.js} +7 -7
- package/dist/assets/{ToolPartDiffPreview-vdPObXOf.js → ToolPartDiffPreview-Dq0go_fX.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-BkFNKWS5.js → VirtualizedFileDiff-Kp8hKJdT.js} +1 -1
- package/dist/assets/WalkthroughView-DGnTzqIU.js +4 -0
- package/dist/assets/{appThemeRegistry-aHUNHoqP.js → appThemeRegistry-BdEHBA4s.js} +1 -1
- package/dist/assets/{commitAndPush-Bon9r94r.js → commitAndPush-LwtVa2Oc.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-DKqr_1AQ.js → computeVirtualFileMetrics-6V1xNpO9.js} +2 -2
- package/dist/assets/de-DlgBHUAI.js +10 -0
- package/dist/assets/es-BC8G41U8.js +16 -0
- package/dist/assets/fr-I0z3vVjy.js +14 -0
- package/dist/assets/index-CgR5rJq_.js +41 -0
- package/dist/assets/{index-DpFttslC.js → index-CmNPYddV.js} +1 -1
- package/dist/assets/index-adyy_sEk.css +1 -0
- package/dist/assets/{isDiffPlainText-kzAgpIgi.js → isDiffPlainText-1bXcWCrw.js} +1 -1
- package/dist/assets/{isFilePlainText-Uj6y-jzz.js → isFilePlainText-CBAppvy1.js} +1 -1
- package/dist/assets/ja-BIElEsY8.js +16 -0
- package/dist/assets/ko-DRnnHetA.js +16 -0
- package/dist/assets/{main-CbfMxn-I.js → main-CzjTMTfW.js} +2 -2
- package/dist/assets/main-DVX34beR.js +886 -0
- package/dist/assets/markdownCore-Cxbkn5NR.js +7 -0
- package/dist/assets/{miniChat-CiAKBC10.js → miniChat-CP68IL8Q.js} +2 -2
- package/dist/assets/{mobile-CsT4sJwC.js → mobile-BrlBrNfZ.js} +2 -2
- package/dist/assets/nl-DzUV-kwp.js +16 -0
- package/dist/assets/{patchFileDiff-DeaE08W0.js → patchFileDiff-pqRSHLHI.js} +2 -2
- package/dist/assets/pl-Bb-cb7k7.js +16 -0
- package/dist/assets/pt-BR-CyIWrTcE.js +16 -0
- package/dist/assets/renderElectronMiniChatApp-DKIilR7N.js +2 -0
- package/dist/assets/renderMobileApp-B0z6-x58.js +25 -0
- package/dist/assets/runtimeEndpointReset-uu1DBwLL.js +52 -0
- package/dist/assets/{scheduledTasksApi-BZCNJ588.js → scheduledTasksApi-BuzWT445.js} +1 -1
- package/dist/assets/{shikiHighlight-BSUEa3yF.js → shikiHighlight-BWGrY5YU.js} +1 -1
- package/dist/assets/{textMateThemeFromAppTheme-CsATFZIV.js → textMateThemeFromAppTheme-BSUFChBY.js} +1 -1
- package/dist/assets/tr-DXEDSoYO.js +7 -0
- package/dist/assets/uk-C8hN--q_.js +16 -0
- package/dist/assets/useAppFontEffects-Dsl_sLrj.js +7366 -0
- package/dist/assets/useInlineCommentController-d5vntsQ_.js +2 -0
- package/dist/assets/{useRootScrollLock-Cp1eFoM2.js → useRootScrollLock-2rd5Y6gR.js} +2 -2
- package/dist/assets/{vendor-base-ui-CsXYnR5c.js → vendor-base-ui-DnNniUWp.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-BwwommM0.js → vendor-codemirror-language-data-B1EetJur.js} +2 -2
- package/dist/assets/vendor-opencode-client-DSZl7jSi.js +12 -0
- package/dist/assets/{vendor-tanstack-react-virtual-ClYN8CzB.js → vendor-tanstack-react-virtual--0sBrLRh.js} +1 -1
- package/dist/assets/{vendor-tanstack-virtual-core-BewVQryB.js → vendor-tanstack-virtual-core-BoA4iGMw.js} +1 -1
- package/dist/assets/{vendor-zod-BSoePkpP.js → vendor-zod-CxRSdNoV.js} +4 -4
- package/dist/assets/{web-components-D3Yjr4Zx.js → web-components-ngpHPEDU.js} +1 -1
- package/dist/assets/zh-CN-CtzXdjMZ.js +16 -0
- package/dist/assets/zh-TW-Ds0CADSz.js +16 -0
- package/dist/index.html +5 -5
- package/dist/mini-chat.html +5 -5
- package/dist/mobile.html +5 -5
- package/package.json +5 -5
- package/server/index.js +82 -4
- package/server/lib/agent-tool/DOCUMENTATION.md +8 -1
- package/server/lib/agent-tool/runtime.js +13 -4
- package/server/lib/agent-tool/runtime.test.js +15 -0
- package/server/lib/context-obligatory/DOCUMENTATION.md +10 -7
- package/server/lib/context-obligatory/runtime.js +2 -1
- package/server/lib/context-obligatory/runtime.test.js +76 -30
- package/server/lib/dictation/DOCUMENTATION.md +4 -1
- package/server/lib/dictation/openai-compatible-session.js +7 -0
- package/server/lib/enterprise-mode.d.ts +30 -0
- package/server/lib/enterprise-mode.js +253 -0
- package/server/lib/enterprise-mode.test.js +247 -0
- package/server/lib/event-stream/translate-v2.js +6 -0
- package/server/lib/event-stream/translate-v2.test.js +6 -0
- package/server/lib/git/DOCUMENTATION.md +2 -1
- package/server/lib/git/routes.js +44 -1
- package/server/lib/git/routes.test.js +98 -1
- package/server/lib/git/service.js +146 -11
- package/server/lib/git/service.test.js +195 -0
- package/server/lib/github/routes.js +9 -19
- package/server/lib/github/routes.test.js +112 -0
- package/server/lib/guests/DOCUMENTATION.md +4 -2
- package/server/lib/guests/background.test.js +1 -1
- package/server/lib/guests/catalog.js +56 -2
- package/server/lib/guests/catalog.test.js +24 -1
- package/server/lib/guests/clone-network.test.js +52 -0
- package/server/lib/guests/clone.js +30 -4
- package/server/lib/guests/enterprise.js +68 -0
- package/server/lib/guests/enterprise.test.js +106 -0
- package/server/lib/guests/grant-scope.js +8 -2
- package/server/lib/guests/grant-scope.test.js +9 -0
- package/server/lib/guests/html-styles.js +16 -2
- package/server/lib/guests/html-styles.test.js +53 -4
- package/server/lib/guests/install.js +10 -0
- package/server/lib/guests/persist.js +1 -0
- package/server/lib/guests/routes.js +40 -5
- package/server/lib/guests/updates.js +9 -2
- package/server/lib/notifications/DOCUMENTATION.md +1 -1
- package/server/lib/notifications/runtime.js +22 -8
- package/server/lib/notifications/trigger-runtime.test.js +45 -0
- package/server/lib/openchamber-sessions/session-metadata-store.js +27 -0
- package/server/lib/openchamber-sessions/session-metadata-store.test.js +18 -0
- package/server/lib/opencode/DOCUMENTATION.md +13 -9
- package/server/lib/opencode/auth-state-runtime.js +2 -2
- package/server/lib/opencode/config-paths.test.js +1 -0
- package/server/lib/opencode/env-runtime.js +26 -3
- package/server/lib/opencode/env-runtime.test.js +57 -0
- package/server/lib/opencode/feature-routes-runtime.js +2 -0
- package/server/lib/opencode/hmr-state-runtime.js +4 -3
- package/server/lib/opencode/lifecycle.js +10 -5
- package/server/lib/opencode/lifecycle.test.js +6 -2
- package/server/lib/opencode/managed-config-file.js +2 -1
- package/server/lib/opencode/managed-config-file.test.js +18 -0
- package/server/lib/opencode/npm-registry-config.d.ts +1 -0
- package/server/lib/opencode/npm-registry-config.js +123 -0
- package/server/lib/opencode/npm-registry-config.test.js +167 -0
- package/server/lib/opencode/npm-registry.js +5 -6
- package/server/lib/opencode/npm-registry.test.js +30 -0
- package/server/lib/opencode/openchamber-routes.js +8 -0
- package/server/lib/opencode/project-icon-routes.js +2 -2
- package/server/lib/opencode/project-icon-routes.test.js +44 -0
- package/server/lib/opencode/provider-source-route.test.js +32 -0
- package/server/lib/opencode/routes.js +17 -2
- package/server/lib/opencode/settings-helpers.js +26 -3
- package/server/lib/opencode/settings-helpers.test.js +12 -5
- package/server/lib/opencode/settings-registry.json +35 -1
- package/server/lib/opencode/settings-runtime.js +1 -0
- package/server/lib/opencode/shutdown-runtime.js +2 -0
- package/server/lib/opencode/static-routes-runtime.js +9 -1
- package/server/lib/opencode/static-routes-runtime.test.js +58 -1
- package/server/lib/package-manager.js +4 -1
- package/server/lib/package-manager.test.js +24 -0
- package/server/lib/permission-auto-accept/DOCUMENTATION.md +23 -15
- package/server/lib/permission-auto-accept/modes.js +26 -0
- package/server/lib/permission-auto-accept/runtime.js +146 -40
- package/server/lib/permission-auto-accept/runtime.test.js +93 -9
- package/server/lib/quota/DOCUMENTATION.md +6 -0
- package/server/lib/quota/providers/zhipuai-coding-plan.js +74 -30
- package/server/lib/quota/providers/zhipuai-coding-plan.test.js +124 -0
- package/server/lib/relay/DOCUMENTATION.md +1 -1
- package/server/lib/relay/service.js +32 -12
- package/server/lib/relay/service.test.js +30 -0
- package/server/lib/routing/DOCUMENTATION.md +150 -41
- package/server/lib/routing/classifier.js +156 -0
- package/server/lib/routing/defaults.js +27 -0
- package/server/lib/routing/jev.js +5 -17
- package/server/lib/routing/routes.http.test.js +9 -0
- package/server/lib/routing/routes.js +27 -1
- package/server/lib/routing/runtime.js +199 -33
- package/server/lib/routing/runtime.test.js +299 -15
- package/server/lib/routing/store.js +57 -0
- package/server/lib/routing/store.test.js +37 -0
- package/server/lib/session-assist/DOCUMENTATION.md +17 -7
- package/server/lib/session-assist/context.js +42 -2
- package/server/lib/session-assist/context.test.js +38 -1
- package/server/lib/session-assist/runtime.js +57 -13
- package/server/lib/session-assist/runtime.test.js +45 -0
- package/server/lib/session-goal/DOCUMENTATION.md +47 -22
- package/server/lib/session-goal/audit.js +112 -0
- package/server/lib/session-goal/audit.test.js +58 -0
- package/server/lib/session-goal/runtime.js +113 -134
- package/server/lib/session-goal/runtime.test.js +146 -13
- package/server/lib/session-lineage.js +52 -0
- package/server/lib/session-lineage.test.js +45 -0
- package/server/lib/session-work/DOCUMENTATION.md +108 -0
- package/server/lib/session-work/questions.js +126 -0
- package/server/lib/session-work/runtime.js +278 -0
- package/server/lib/session-work/runtime.test.js +255 -0
- package/server/lib/session-work/state.js +48 -0
- package/server/lib/session-work/state.test.js +34 -0
- package/server/lib/small-model/DOCUMENTATION.md +14 -7
- package/server/lib/small-model/client.js +7 -4
- package/server/lib/small-model/index.js +11 -21
- package/server/lib/small-model/index.test.js +13 -26
- package/server/lib/spaces/DOCUMENTATION.md +79 -25
- package/server/lib/spaces/gatekeeper-channel.js +63 -11
- package/server/lib/spaces/gatekeeper-channel.test.js +34 -4
- package/server/lib/spaces/gatekeeper-program.cjs +64 -13
- package/server/lib/spaces/gatekeeper-program.test.js +115 -3
- package/server/lib/spaces/host.js +58 -13
- package/server/lib/spaces/host.test.js +34 -1
- package/server/lib/spaces/idle-stop.js +98 -0
- package/server/lib/spaces/idle-stop.test.js +130 -0
- package/server/lib/spaces/journey.js +427 -17
- package/server/lib/spaces/journey.test.js +592 -5
- package/server/lib/spaces/layout.js +27 -6
- package/server/lib/spaces/manager.test.js +1 -1
- package/server/lib/spaces/places/contract-suite.js +4 -2
- package/server/lib/spaces/places/docker-live-support.js +27 -4
- package/server/lib/spaces/places/docker.js +32 -5
- package/server/lib/spaces/places/docker.test.js +38 -8
- package/server/lib/spaces/places/escape-suite.js +32 -0
- package/server/lib/spaces/places/fake-docker.js +3 -1
- package/server/lib/spaces/places/grants.docker.live.test.js +197 -0
- package/server/lib/spaces/places/memory-place.js +3 -3
- package/server/lib/spaces/places/sessions.docker.live.test.js +4 -2
- package/server/lib/spaces/routes.js +49 -1
- package/server/lib/spaces/routes.test.js +31 -3
- package/server/lib/spaces/space-opencode.js +52 -0
- package/server/lib/spaces/space-opencode.test.js +41 -0
- package/server/lib/spaces/space-records.js +90 -2
- package/server/lib/spaces/space-records.test.js +58 -1
- package/server/lib/spaces/space-server.js +13 -1
- package/server/lib/spaces/space-server.test.js +13 -0
- package/server/lib/spaces/space-setup.js +173 -0
- package/server/lib/spaces/space-setup.test.js +174 -0
- package/server/lib/tts/DOCUMENTATION.md +3 -0
- package/server/lib/tts/base-url.js +8 -0
- package/server/lib/tts/routes.js +13 -1
- package/server/lib/tts/routes.test.js +26 -0
- package/server/lib/tunnels/DOCUMENTATION.md +2 -0
- package/server/lib/tunnels/routes.js +14 -0
- package/server/lib/tunnels/routes.test.js +26 -0
- package/server/lib/walkthrough/index.js +11 -7
- package/server/lib/walkthrough/jobs.test.js +8 -0
- package/server/lib/walkthrough/languages.js +1 -0
- package/server/lib/walkthrough/routes.js +7 -1
- package/dist/assets/FilesView-0Ie20mEk.js +0 -17
- package/dist/assets/LinearIssuesView-CSl2MUfA.js +0 -1
- package/dist/assets/MarkdownRendererImpl-DVHqZoug.js +0 -12
- package/dist/assets/OnboardingScreen-CIdXJpfc.js +0 -1
- package/dist/assets/PlanView-DEIi3Q7M.js +0 -5
- package/dist/assets/PluginPane-BEPUWVho.js +0 -3
- package/dist/assets/SettingsView-CiNh-RbW.js +0 -30
- package/dist/assets/WalkthroughView-6oE-MuDL.js +0 -4
- package/dist/assets/de-CgAJ51z7.js +0 -10
- package/dist/assets/es-zGi_ravM.js +0 -16
- package/dist/assets/fr-CPfogrWx.js +0 -14
- package/dist/assets/index-CHfphYL3.js +0 -41
- package/dist/assets/index-DvMJ3w6V.css +0 -1
- package/dist/assets/ja-DMk6wd-U.js +0 -16
- package/dist/assets/ko-BFpzJ8jc.js +0 -16
- package/dist/assets/main-anyZFMIs.js +0 -896
- package/dist/assets/markdownCore-CmM47cAE.js +0 -7
- package/dist/assets/pl-VdRPcZrB.js +0 -16
- package/dist/assets/pt-BR-BRys_lOW.js +0 -16
- package/dist/assets/renderElectronMiniChatApp-C5677jy0.js +0 -2
- package/dist/assets/renderMobileApp-D4dBBAqQ.js +0 -25
- package/dist/assets/runtimeEndpointReset-5r0hkd-2.js +0 -27
- package/dist/assets/tr-CA9ckNnm.js +0 -7
- package/dist/assets/uk-byjR-y8D.js +0 -16
- package/dist/assets/useAppFontEffects-BWQZ5DeI.js +0 -7341
- package/dist/assets/useInlineCommentController-DlFyVfBu.js +0 -2
- package/dist/assets/vendor-opencode-client-DYdsLbCM.js +0 -12
- package/dist/assets/zh-CN-DRabgxdG.js +0 -16
- package/dist/assets/zh-TW-rbY5c9UK.js +0 -16
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
## Purpose
|
|
4
4
|
|
|
5
|
-
Jev model routing
|
|
6
|
-
model selected, the server asks
|
|
7
|
-
System One decision model) which
|
|
8
|
-
it with that category's model,
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
Jev model routing, the permission safety net, and the classification provider
|
|
6
|
+
that answers both. With the `openchamber/auto` model selected, the server asks
|
|
7
|
+
[Jev](https://docs.typesafe.ai) (TypeSafe's System One decision model) which
|
|
8
|
+
task category a message belongs to and sends it with that category's model,
|
|
9
|
+
thinking variant and agent. In a session whose permission mode is `safety`
|
|
10
|
+
(`../permission-auto-accept/DOCUMENTATION.md`), the same kind of call decides
|
|
11
|
+
whether a permission is accepted or stays on screen for the user.
|
|
11
12
|
|
|
12
13
|
Routing needs the OpenChamber server, so it is present wherever that server is
|
|
13
14
|
and absent everywhere else: VS Code talks to OpenCode directly and never offers
|
|
@@ -17,25 +18,37 @@ Auto. There is no env gate — the feature shipped dark behind
|
|
|
17
18
|
|
|
18
19
|
## Files
|
|
19
20
|
|
|
20
|
-
- `defaults.js` — the Auto sentinel,
|
|
21
|
-
|
|
22
|
-
limits.
|
|
23
|
-
- `
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
- `defaults.js` — the Auto sentinel, the Jev endpoints and models, the
|
|
22
|
+
`ZEN_JEV_PROMOTION_ACTIVE` switch, built-in categories, the question wording
|
|
23
|
+
for routing and for the safety net, history excerpt limits.
|
|
24
|
+
- `classifier.js` — the classification providers: `resolveClassifier` (the
|
|
25
|
+
user's pick, what is usable, and the source that actually answers) and
|
|
26
|
+
`classifierEndpoint` (where a request for a source goes),
|
|
27
|
+
`legacyClassifier` (the view older clients parse) and
|
|
28
|
+
`normalizeCustomEndpointUrl` (the custom endpoint's request URL).
|
|
29
|
+
- `store.js` — `routing.json` (only deviations from the built-ins),
|
|
30
|
+
`routing-auth.json` (the TypeSafe key alone, mode 0600),
|
|
31
|
+
`classification.json` (the classification provider pick) and
|
|
32
|
+
`classifier-endpoint.json` (the custom endpoint, mode 0600) in the
|
|
33
|
+
OpenChamber data dir. An unreadable pick file reads as no pick, an
|
|
34
|
+
unreadable endpoint file as no endpoint. `resolveEffectiveConfig` merges built-ins with stored overrides;
|
|
26
35
|
`toStoredConfig` is its inverse. A missing file is the defaults, a malformed
|
|
27
36
|
one throws.
|
|
28
|
-
- `jev.js` — request builders, answer parsing, the HTTP call with a
|
|
29
|
-
|
|
37
|
+
- `jev.js` — request builders, answer parsing, and the HTTP call with a
|
|
38
|
+
timeout to the endpoint `classifierEndpoint` chose.
|
|
30
39
|
- `history.js` — the last three settled turns through session assist's
|
|
31
40
|
`loadAssistContext` (text parts only, attached quotes included, no files or
|
|
32
41
|
tool payloads), each user message cut to its head and each answer to head
|
|
33
42
|
plus tail. The new request is never cut.
|
|
34
|
-
- `runtime.js` — `createRoutingRuntime`: `describe`, `
|
|
43
|
+
- `runtime.js` — `createRoutingRuntime`: `describe`, `classifierEndpoint` (the
|
|
44
|
+
endpoint a Jev request goes to now, or null; also used by
|
|
45
|
+
`../session-work` and `../session-goal`), `noteModelSelection`,
|
|
35
46
|
`isAutoSession`, `resolveAutoSelection`, `applySessionSelection`, `routeSend`,
|
|
36
|
-
`evaluatePermission`, config
|
|
37
|
-
|
|
38
|
-
|
|
47
|
+
`evaluatePermission`, `legacySafetyNetEnabled`, config, token, classifier and
|
|
48
|
+
custom endpoint writes, event broadcasts.
|
|
49
|
+
- `routes.js` — `/api/routing` (GET, PUT), `/api/routing/token` (PUT, DELETE),
|
|
50
|
+
`/api/routing/classifier` (PUT), `/api/routing/classifier/custom` (PUT,
|
|
51
|
+
DELETE) and `registerRoutingPromptRewrite`.
|
|
39
52
|
|
|
40
53
|
## Invariants
|
|
41
54
|
|
|
@@ -56,15 +69,23 @@ Auto. There is no env gate — the feature shipped dark behind
|
|
|
56
69
|
before switching the session.
|
|
57
70
|
- The mark lives in process memory. A server restart between the model switch
|
|
58
71
|
and the next send drops it (see the TODO in `runtime.js`).
|
|
59
|
-
-
|
|
60
|
-
category or low confidence routes to the fallback model
|
|
61
|
-
the reason.
|
|
62
|
-
|
|
72
|
+
- Routing failures keep the user's own behaviour: a Jev error, timeout, unknown
|
|
73
|
+
category or low confidence routes to the fallback model, and the decision
|
|
74
|
+
carries the reason.
|
|
75
|
+
- The safety net accepts only on a verdict from Jev. With no usable
|
|
76
|
+
classification provider it holds quietly (the session behaves like `ask`);
|
|
77
|
+
when Jev fails it holds, broadcasts `openchamber:routing.safety-skipped` with
|
|
78
|
+
the error, and does not remember the failure, so reconnect reconciliation asks
|
|
79
|
+
again. It runs whether or not Auto routing is enabled: the routing config's
|
|
80
|
+
`safetyNet.enabled` is no longer read except once, by
|
|
81
|
+
`legacySafetyNetEnabled`, when the permission policy converts pre-modes
|
|
82
|
+
entries. `safetyNet.threshold` still applies.
|
|
63
83
|
- A category without a model uses the fallback model *and* variant; a variant
|
|
64
84
|
only travels with the model it was chosen for. A category agent replaces the
|
|
65
85
|
composer's agent; an empty one keeps it.
|
|
66
|
-
- Auto is offered (`autoReady`) with
|
|
67
|
-
|
|
86
|
+
- Auto is offered (`autoReady`) with a usable classification provider
|
|
87
|
+
(`jevAvailable`), `enabled`, a fallback model and at least two enabled
|
|
88
|
+
categories.
|
|
68
89
|
- Held permission decisions are cached for 15 minutes per request id so
|
|
69
90
|
reconnect reconciliation in `permission-auto-accept` does not re-ask Jev;
|
|
70
91
|
`permission.replied` forgets them.
|
|
@@ -74,41 +95,129 @@ Auto. There is no env gate — the feature shipped dark behind
|
|
|
74
95
|
|
|
75
96
|
## Where a Jev request goes
|
|
76
97
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
`
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
98
|
+
The user picks a classification provider in Settings → Providers →
|
|
99
|
+
Classification providers:
|
|
100
|
+
|
|
101
|
+
- `off`: no Jev at all. Every Jev feature takes its no-provider path.
|
|
102
|
+
- `zen-promo`: `opencode.ai/zen/v1/systemone` as `jev-1.13-free`, which OpenCode
|
|
103
|
+
Zen answers with no credential at all. Usable while
|
|
104
|
+
`ZEN_JEV_PROMOTION_ACTIVE` is true; flip it when OpenCode ends the promotion.
|
|
105
|
+
- `zen-key`: the same endpoint as `jev-1.13` with a Zen API key read from
|
|
106
|
+
OpenCode's credentials (`opencode/auth.js`, entry `opencode`, type `api`).
|
|
107
|
+
An OpenCode account sign-in is an OAuth credential, and zen rejects it as a
|
|
108
|
+
key ("Invalid API key", checked 2026-09-27), so it does not count. The paid
|
|
109
|
+
call itself is not verified live yet.
|
|
110
|
+
- `openrouter`: `openrouter.ai/api/v1/systemone` as `jev-latest` (OpenRouter's
|
|
111
|
+
`~typesafe/jev-latest` alias) with the OpenRouter API key saved in OpenCode
|
|
112
|
+
(entry `openrouter`, type `api`), billed to that OpenRouter account.
|
|
113
|
+
- `vercel`: `ai-gateway.vercel.sh/typesafe/v1/systemone` as `typesafe-ai/jev`
|
|
114
|
+
with the Vercel AI Gateway API key saved in OpenCode (entry `vercel`, type
|
|
115
|
+
`api`). Both gateways implement TypeSafe's request and response shapes, so
|
|
116
|
+
`jev.js` is the same for every source. Both answer 401 without a key
|
|
117
|
+
(checked 2026-09-27); a paid call is not verified live yet.
|
|
118
|
+
- `typesafe`: `api.typesafe.ai/v1/systemone` as `jev-latest` with the key saved
|
|
119
|
+
in `routing-auth.json`. Saving a key also picks it.
|
|
120
|
+
- `custom`: any endpoint that speaks the System One API, with the URL, model
|
|
121
|
+
and optional key the user saved (`classifier-endpoint.json`, mode 0600, its
|
|
122
|
+
own file so a token write never rewrites it). The key goes as a bearer when
|
|
123
|
+
present; `describe` returns `customEndpoint` as URL, model and `keyPresent`,
|
|
124
|
+
never the key. `setCustomEndpoint` accepts the full `.../systemone` URL, an
|
|
125
|
+
OpenAI-style base ending in `/v1` (what "base URL" means to most users), or
|
|
126
|
+
an API root the way TypeSafe's SDKs take `baseURL`, and stores the resolved
|
|
127
|
+
request URL, which the page shows back. Only http(s), no credentials in the
|
|
128
|
+
URL. It does not go through the TTS remote-URL gate: a remote classifier is
|
|
129
|
+
the user's explicit choice, the same as the hosted sources. Saving picks it;
|
|
130
|
+
a missing `key` keeps the saved one, null removes it without changing the
|
|
131
|
+
pick.
|
|
132
|
+
An administrator can pin the endpoint (`readPinnedCustomEndpoint`): `jev` in
|
|
133
|
+
the machine policy file, else `OPENCHAMBER_JEV_URL`, `OPENCHAMBER_JEV_MODEL`
|
|
134
|
+
defaulting to `jev-latest`, optional `OPENCHAMBER_JEV_API_KEY` (source rules
|
|
135
|
+
in `../enterprise-mode.js`). The pin
|
|
136
|
+
replaces the saved endpoint, `customEndpoint.pinned` tells the page to show
|
|
137
|
+
it read-only, and `setCustomEndpoint` / `clearCustomEndpoint` answer 409.
|
|
138
|
+
|
|
139
|
+
In enterprise mode (policy file or `OPENCHAMBER_ENTERPRISE_MODE`, `../enterprise-mode.js`)
|
|
140
|
+
`resolveAccess` treats the pick as `off` whatever is stored (the stored pick is
|
|
141
|
+
kept for when the mode is lifted), `setClassifierSource` refuses anything but
|
|
142
|
+
`off` and `setToken` and `setCustomEndpoint` refuse every write with 403, and `describe` reports
|
|
143
|
+
`enterpriseMode` so the page shows why only Off is offered. With a pinned
|
|
144
|
+
endpoint it is the administrator's own infrastructure, so it becomes the
|
|
145
|
+
default (`custom` unless the stored pick is `off`) and `custom` is the one
|
|
146
|
+
other pick allowed.
|
|
147
|
+
|
|
148
|
+
Jev reads conversation excerpts, so it is opt-in. Without a stored pick the
|
|
149
|
+
default is `typesafe` when a key is saved (saving a key is choosing it, and it
|
|
150
|
+
always won before the pick existed) and `off` otherwise. Until v2.0.3 the
|
|
151
|
+
default was `zen-promo`, which sent every message of users who never opened
|
|
152
|
+
this page to zen (#4109); an install without a stored pick now reads as `off`
|
|
153
|
+
with no conversion. A pick that cannot be used falls back to the first usable
|
|
154
|
+
key (`typesafe`, `custom`, `openrouter`, `vercel`, `zen-key`: what the user set
|
|
155
|
+
up in OpenChamber for Jev before keys borrowed from OpenCode); none usable
|
|
156
|
+
means no Jev.
|
|
157
|
+
`zen-promo` needs no credential, so it is never a fallback: only an explicit
|
|
158
|
+
pick sends anything there, and `off` never falls back.
|
|
159
|
+
The OpenCode keys are read on every request, so a key added or removed in
|
|
160
|
+
OpenCode counts from the next request on.
|
|
161
|
+
|
|
162
|
+
OpenRouter and Vercel also count a key in `OPENROUTER_API_KEY` /
|
|
163
|
+
`AI_GATEWAY_API_KEY` (`readOpenCodeKeys`), because OpenCode connects those
|
|
164
|
+
providers from the variable live and never stores it (v2 `integration.ts`
|
|
165
|
+
`resolveConnections`). A key saved in OpenCode wins. The server's
|
|
166
|
+
`process.env` already carries the login-shell snapshot and a managed OpenCode
|
|
167
|
+
is spawned from it, so both see the same variable; an external OpenCode
|
|
168
|
+
started elsewhere may not, and then the variable simply is not seen. Zen has
|
|
169
|
+
no variable.
|
|
170
|
+
|
|
171
|
+
Every zen call is tagged `x-opencode-client: openchamber`. Dax approved the
|
|
172
|
+
free use in Slack on 2026-09-22 on terms the code and the copy keep together:
|
|
173
|
+
zen can identify and throttle our calls through that header, and the
|
|
174
|
+
Classification providers page tells the user in plain words that the free model
|
|
175
|
+
is a limited-time OpenCode promotion. Zen rejects the `jev-latest` alias, so
|
|
176
|
+
versioned ids are sent.
|
|
86
177
|
|
|
87
178
|
Never make the free tier the only path: the zen docs call it "available for a
|
|
88
|
-
limited time", and the
|
|
179
|
+
limited time", and the keys are what users fall back to when it ends.
|
|
89
180
|
|
|
90
181
|
## Events
|
|
91
182
|
|
|
92
183
|
Broadcast on the OpenChamber control stream: `openchamber:routing.updated`
|
|
93
|
-
(availability), `openchamber:routing.decision` (per
|
|
94
|
-
`openchamber:routing.permission-held`,
|
|
184
|
+
(availability, including `jevAvailable`), `openchamber:routing.decision` (per
|
|
185
|
+
send), `openchamber:routing.permission-held`,
|
|
186
|
+
`openchamber:routing.safety-skipped`. The last two carry the request's
|
|
187
|
+
directory so the UI can raise the permission toast for a held request.
|
|
188
|
+
|
|
189
|
+
`/api/routing` keeps `jevSource` (`typesafe` or `zen-free`) for clients from
|
|
190
|
+
before the classifier pick and adds `jevAvailable`, `classifier` and
|
|
191
|
+
`classification` (both `selected`, `effective`, `sources`). `classification`
|
|
192
|
+
is the full picture. `classifier` is what v2.0.2 clients parse: their schema
|
|
193
|
+
knows only `zen-promo`, `zen-key` and `typesafe` and rejects the whole state
|
|
194
|
+
on any other id, so it lists only those and is null while OpenRouter,
|
|
195
|
+
Vercel or a custom endpoint is picked or answering (`legacyClassifier`). Current clients read
|
|
196
|
+
`classification` and drop source ids they do not know.
|
|
95
197
|
|
|
96
198
|
## UI
|
|
97
199
|
|
|
98
200
|
`packages/ui/src/stores/useRoutingStore.ts` projects `/api/routing` and these
|
|
99
|
-
events
|
|
100
|
-
|
|
201
|
+
events (`selectSafetyNetAvailable` gates the safety-net mode everywhere);
|
|
202
|
+
`hooks/useRoutingSync.ts` keeps it current, shows the skipped-check toast and
|
|
203
|
+
raises the permission toast for a held request (`notifyHeldPermission`). `lib/routing/autoModel.ts` owns the sentinel; `useConfigStore` accepts it
|
|
101
204
|
as a valid selection while `autoReady`. `ModelPickerList` renders it as the
|
|
102
205
|
pinned `leadingEntry`; `ModelControls` hides the agent and thinking controls
|
|
103
206
|
while Auto is selected. `PermissionCard` shows the hold reason. Settings →
|
|
104
207
|
Routing (`components/sections/routing/RoutingPage.tsx`) edits the config with
|
|
105
|
-
debounced saves
|
|
208
|
+
debounced saves. Settings → Providers → Classification providers
|
|
209
|
+
(`components/sections/classification/ClassificationProvidersPage.tsx`) picks
|
|
210
|
+
the source and manages the TypeSafe key and, through `CustomEndpointFields.tsx`,
|
|
211
|
+
the custom endpoint; `JevAccessNote` links there from the
|
|
212
|
+
features that need Jev.
|
|
106
213
|
|
|
107
214
|
## Tests
|
|
108
215
|
|
|
109
216
|
`store.test.js` (defaults, deviation round-trip, deleted built-ins, malformed
|
|
110
|
-
file, token file mode), `runtime.test.js` (request text,
|
|
111
|
-
|
|
217
|
+
file, token file mode, classifier pick, custom endpoint file), `runtime.test.js` (request text,
|
|
218
|
+
excerpts, decisions, endpoints, custom URL normalization and setter,
|
|
219
|
+
classifier fallback, rewrite and fallback
|
|
220
|
+
paths, safety net accept/hold/skip/unavailable), `routes.http.test.js`
|
|
112
221
|
(sentinel dropped from a create and swallowed on the model switch, routed send
|
|
113
222
|
ahead of a stand-in proxy, the routes). The queue and auto-accept tests cover
|
|
114
223
|
their hooks.
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which service answers Jev requests: the classification provider.
|
|
3
|
+
*
|
|
4
|
+
* - `off`: nothing. Jev sees conversation excerpts, so it is off until the
|
|
5
|
+
* user picks a source.
|
|
6
|
+
* - `zen-promo`: OpenCode Zen's free promotional model, no credential.
|
|
7
|
+
* - `zen-key`: the paid model on the same endpoint, with a Zen API key the user
|
|
8
|
+
* saved in OpenCode.
|
|
9
|
+
* - `openrouter`, `vercel`: the same System One API through OpenRouter or
|
|
10
|
+
* Vercel AI Gateway, with the key the user saved for that provider in
|
|
11
|
+
* OpenCode.
|
|
12
|
+
* - `typesafe`: TypeSafe's own API with a key saved in OpenChamber.
|
|
13
|
+
* - `custom`: any endpoint that speaks the System One API (a self-hosted
|
|
14
|
+
* gateway, a company proxy), with the URL, model and optional key saved in
|
|
15
|
+
* OpenChamber.
|
|
16
|
+
*
|
|
17
|
+
* The user picks one. A pick that cannot be used right now (the promotion
|
|
18
|
+
* ended, the key was removed) falls back to the first usable key, so Jev
|
|
19
|
+
* stays available while the user has one. The promotion needs no credential,
|
|
20
|
+
* so it is never a fallback: only a pick sends anything there. No usable
|
|
21
|
+
* source means no Jev: the safety net and Auto are not offered.
|
|
22
|
+
*/
|
|
23
|
+
import {
|
|
24
|
+
JEV_API_URL,
|
|
25
|
+
JEV_MODEL,
|
|
26
|
+
OPENROUTER_JEV_API_URL,
|
|
27
|
+
OPENROUTER_JEV_MODEL,
|
|
28
|
+
VERCEL_JEV_API_URL,
|
|
29
|
+
VERCEL_JEV_MODEL,
|
|
30
|
+
ZEN_CLIENT_ID,
|
|
31
|
+
ZEN_JEV_API_URL,
|
|
32
|
+
ZEN_JEV_MODEL,
|
|
33
|
+
ZEN_JEV_PAID_MODEL,
|
|
34
|
+
} from './defaults.js';
|
|
35
|
+
import { readEnterprisePolicy } from '../enterprise-mode.js';
|
|
36
|
+
|
|
37
|
+
export const CLASSIFIER_SOURCES = ['off', 'zen-promo', 'zen-key', 'openrouter', 'vercel', 'typesafe', 'custom'];
|
|
38
|
+
// What the user set up in OpenChamber for Jev comes before keys borrowed from OpenCode.
|
|
39
|
+
const FALLBACK_ORDER = ['typesafe', 'custom', 'openrouter', 'vercel', 'zen-key'];
|
|
40
|
+
|
|
41
|
+
const SYSTEM_ONE_PATH = '/systemone';
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The request URL for a custom endpoint, from what the user pasted: the full
|
|
45
|
+
* `.../v1/systemone` URL as is, an OpenAI-style base URL ending in `/v1`, or
|
|
46
|
+
* an API root the way TypeSafe's SDKs take `baseURL` (`https://api.typesafe.ai`).
|
|
47
|
+
* Only http(s), and no credentials in the URL: the key has its own field and
|
|
48
|
+
* the URL is shown back in Settings. Throws with status 400 otherwise.
|
|
49
|
+
*/
|
|
50
|
+
export const normalizeCustomEndpointUrl = (input) => {
|
|
51
|
+
const invalid = (message) => Object.assign(new Error(message), { status: 400 });
|
|
52
|
+
let url;
|
|
53
|
+
try {
|
|
54
|
+
url = new URL(String(input ?? '').trim());
|
|
55
|
+
} catch {
|
|
56
|
+
throw invalid('Enter a full http:// or https:// URL');
|
|
57
|
+
}
|
|
58
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:') throw invalid('Only http:// and https:// URLs are supported');
|
|
59
|
+
if (url.username || url.password) throw invalid('Put the key in the API key field, not in the URL');
|
|
60
|
+
url.hash = '';
|
|
61
|
+
const base = url.pathname.replace(/\/+$/, '');
|
|
62
|
+
if (base.endsWith(SYSTEM_ONE_PATH)) url.pathname = base;
|
|
63
|
+
else if (base.endsWith('/v1')) url.pathname = `${base}${SYSTEM_ONE_PATH}`;
|
|
64
|
+
else url.pathname = `${base}/v1${SYSTEM_ONE_PATH}`;
|
|
65
|
+
return url.toString();
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
let warnedInvalidPin = false;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* A custom endpoint an administrator pinned: `jev` in the machine policy file,
|
|
72
|
+
* else `OPENCHAMBER_JEV_URL` (any form `normalizeCustomEndpointUrl` accepts),
|
|
73
|
+
* `OPENCHAMBER_JEV_MODEL` (default `jev-latest`) and an optional
|
|
74
|
+
* `OPENCHAMBER_JEV_API_KEY` (see ../enterprise-mode.js). It replaces the one
|
|
75
|
+
* saved in Settings, which then cannot be edited, and it is the one Jev source
|
|
76
|
+
* enterprise mode allows. Null when unset or not a valid URL.
|
|
77
|
+
*/
|
|
78
|
+
export const readPinnedCustomEndpoint = (options) => {
|
|
79
|
+
const pinned = readEnterprisePolicy(options).jev;
|
|
80
|
+
if (!pinned) return null;
|
|
81
|
+
let url;
|
|
82
|
+
try {
|
|
83
|
+
url = normalizeCustomEndpointUrl(pinned.url);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if (!warnedInvalidPin) console.warn('[routing] the pinned Jev endpoint is ignored:', error.message);
|
|
86
|
+
warnedInvalidPin = true;
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
const model = pinned.model || JEV_MODEL;
|
|
90
|
+
return pinned.apiKey ? { url, model, key: pinned.apiKey } : { url, model };
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/** The sources clients from v2.0.2 parse; any other id fails their whole routing state. */
|
|
94
|
+
const LEGACY_SOURCES = ['zen-promo', 'zen-key', 'typesafe'];
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* `selected` is the stored pick or null. Before the pick existed a saved
|
|
98
|
+
* TypeSafe key always won, so that stays the default when one is present;
|
|
99
|
+
* otherwise nothing is sent anywhere until the user picks.
|
|
100
|
+
*/
|
|
101
|
+
export const resolveClassifier = ({ selected, typesafeKey, zenKey, openrouterKey, vercelKey, customEndpoint, zenPromotionActive }) => {
|
|
102
|
+
const chosen = selected ?? (typesafeKey ? 'typesafe' : 'off');
|
|
103
|
+
const usable = {
|
|
104
|
+
off: true,
|
|
105
|
+
'zen-promo': Boolean(zenPromotionActive),
|
|
106
|
+
'zen-key': Boolean(zenKey),
|
|
107
|
+
openrouter: Boolean(openrouterKey),
|
|
108
|
+
vercel: Boolean(vercelKey),
|
|
109
|
+
typesafe: Boolean(typesafeKey),
|
|
110
|
+
custom: Boolean(customEndpoint),
|
|
111
|
+
};
|
|
112
|
+
const effective = chosen === 'off'
|
|
113
|
+
? null
|
|
114
|
+
: usable[chosen] ? chosen : FALLBACK_ORDER.find((source) => usable[source]) ?? null;
|
|
115
|
+
return {
|
|
116
|
+
selected: chosen,
|
|
117
|
+
effective,
|
|
118
|
+
sources: CLASSIFIER_SOURCES.map((id) => ({ id, usable: usable[id] })),
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* `classifier` as clients from v2.0.2 read it: their schema knows only the
|
|
124
|
+
* first three sources and rejects the whole routing state on any other id,
|
|
125
|
+
* which would hide Auto and the safety net on an older phone app connected to
|
|
126
|
+
* a newer server. With Off, OpenRouter, Vercel or a custom endpoint in play they get null and
|
|
127
|
+
* show the provider page as unavailable; the features keep working.
|
|
128
|
+
*/
|
|
129
|
+
export const legacyClassifier = (classifier) => {
|
|
130
|
+
const legacy = (source) => source === null || LEGACY_SOURCES.includes(source);
|
|
131
|
+
if (!legacy(classifier.selected) || !legacy(classifier.effective)) return null;
|
|
132
|
+
return { ...classifier, sources: classifier.sources.filter((source) => LEGACY_SOURCES.includes(source.id)) };
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/** The request target for a usable source. */
|
|
136
|
+
export const classifierEndpoint = (source, { typesafeKey, zenKey, openrouterKey, vercelKey, customEndpoint }) => {
|
|
137
|
+
if (source === 'custom') {
|
|
138
|
+
const headers = {};
|
|
139
|
+
if (customEndpoint.key) headers.authorization = `Bearer ${customEndpoint.key}`;
|
|
140
|
+
return { url: customEndpoint.url, model: customEndpoint.model, headers };
|
|
141
|
+
}
|
|
142
|
+
if (source === 'typesafe') {
|
|
143
|
+
return { url: JEV_API_URL, model: JEV_MODEL, headers: { authorization: `Bearer ${typesafeKey}` } };
|
|
144
|
+
}
|
|
145
|
+
if (source === 'openrouter') {
|
|
146
|
+
return { url: OPENROUTER_JEV_API_URL, model: OPENROUTER_JEV_MODEL, headers: { authorization: `Bearer ${openrouterKey}` } };
|
|
147
|
+
}
|
|
148
|
+
if (source === 'vercel') {
|
|
149
|
+
return { url: VERCEL_JEV_API_URL, model: VERCEL_JEV_MODEL, headers: { authorization: `Bearer ${vercelKey}` } };
|
|
150
|
+
}
|
|
151
|
+
// Every Zen call names OpenChamber, so zen can see or throttle it.
|
|
152
|
+
if (source === 'zen-key') {
|
|
153
|
+
return { url: ZEN_JEV_API_URL, model: ZEN_JEV_PAID_MODEL, headers: { authorization: `Bearer ${zenKey}`, 'x-opencode-client': ZEN_CLIENT_ID } };
|
|
154
|
+
}
|
|
155
|
+
return { url: ZEN_JEV_API_URL, model: ZEN_JEV_MODEL, headers: { 'x-opencode-client': ZEN_CLIENT_ID } };
|
|
156
|
+
};
|
|
@@ -41,6 +41,33 @@ export const ZEN_JEV_API_URL = 'https://opencode.ai/zen/v1/systemone';
|
|
|
41
41
|
export const ZEN_JEV_MODEL = 'jev-1.13-free';
|
|
42
42
|
export const ZEN_CLIENT_ID = 'openchamber';
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Whether the free promotion is still on. When OpenCode ends it, flip this and
|
|
46
|
+
* the promotion stops being offered; users keep Jev through a Zen or TypeSafe
|
|
47
|
+
* key, or lose the safety net and Auto until they add one.
|
|
48
|
+
*/
|
|
49
|
+
export const ZEN_JEV_PROMOTION_ACTIVE = true;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The paid model behind a Zen API key, same endpoint. Not verified live: an
|
|
53
|
+
* OpenCode account sign-in (OAuth) is rejected there as "Invalid API key", so
|
|
54
|
+
* only a Zen API key saved in OpenCode is offered.
|
|
55
|
+
*/
|
|
56
|
+
export const ZEN_JEV_PAID_MODEL = 'jev-1.13';
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* OpenRouter and Vercel AI Gateway serve TypeSafe's System One API under their
|
|
60
|
+
* own base URLs and bill the call to the account behind the key the user saved
|
|
61
|
+
* for that provider in OpenCode. OpenRouter maps the bare `jev-latest` onto its
|
|
62
|
+
* `~typesafe/jev-latest` alias; AI Gateway knows Jev only as `typesafe-ai/jev`.
|
|
63
|
+
* Both answer 401 without a key (checked 2026-09-27); a paid call is not
|
|
64
|
+
* verified live yet.
|
|
65
|
+
*/
|
|
66
|
+
export const OPENROUTER_JEV_API_URL = 'https://openrouter.ai/api/v1/systemone';
|
|
67
|
+
export const OPENROUTER_JEV_MODEL = 'jev-latest';
|
|
68
|
+
export const VERCEL_JEV_API_URL = 'https://ai-gateway.vercel.sh/typesafe/v1/systemone';
|
|
69
|
+
export const VERCEL_JEV_MODEL = 'typesafe-ai/jev';
|
|
70
|
+
|
|
44
71
|
/** Per-attempt timeout; the lab measured 250–700 ms warm, ~1 s on a cold TLS handshake. */
|
|
45
72
|
export const JEV_TIMEOUT_MS = 4000;
|
|
46
73
|
|
|
@@ -4,26 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import {
|
|
7
|
-
JEV_API_URL,
|
|
8
|
-
JEV_MODEL,
|
|
9
7
|
JEV_TIMEOUT_MS,
|
|
10
8
|
ROUTING_INSTRUCTIONS,
|
|
11
9
|
SAFETY_INSTRUCTIONS,
|
|
12
10
|
SAFETY_KINDS,
|
|
13
|
-
ZEN_CLIENT_ID,
|
|
14
|
-
ZEN_JEV_API_URL,
|
|
15
|
-
ZEN_JEV_MODEL,
|
|
16
11
|
} from './defaults.js';
|
|
17
12
|
|
|
18
|
-
/**
|
|
19
|
-
* Where one request goes. A saved TypeSafe key wins: the user chose it and it
|
|
20
|
-
* carries their own quota. Without one, the same questions go to the free Jev
|
|
21
|
-
* model OpenCode Zen serves without a credential, identified as OpenChamber.
|
|
22
|
-
*/
|
|
23
|
-
export const jevEndpoint = (token) => (token
|
|
24
|
-
? { url: JEV_API_URL, model: JEV_MODEL, headers: { authorization: `Bearer ${token}` }, source: 'typesafe' }
|
|
25
|
-
: { url: ZEN_JEV_API_URL, model: ZEN_JEV_MODEL, headers: { 'x-opencode-client': ZEN_CLIENT_ID }, source: 'zen-free' });
|
|
26
|
-
|
|
27
13
|
export const buildRoutingRequest = ({ categories, history, request }) => {
|
|
28
14
|
const criteria = {};
|
|
29
15
|
for (const category of categories) criteria[category.id] = category.description;
|
|
@@ -78,13 +64,15 @@ export const decidePermission = (answers, { threshold }) => {
|
|
|
78
64
|
const responseSchema = z.object({ answers: z.record(z.string(), z.unknown()) });
|
|
79
65
|
|
|
80
66
|
export const createJevClient = ({ fetchImpl = fetch, timeoutMs = JEV_TIMEOUT_MS } = {}) => ({
|
|
81
|
-
/**
|
|
82
|
-
|
|
67
|
+
/**
|
|
68
|
+
* `endpoint` comes from `classifierEndpoint`. Resolves to the parsed answers;
|
|
69
|
+
* throws with `status` on an HTTP error and `code: 'timeout'` on abort.
|
|
70
|
+
*/
|
|
71
|
+
ask: async (request, endpoint) => {
|
|
83
72
|
const abort = new AbortController();
|
|
84
73
|
const timer = setTimeout(() => abort.abort(), timeoutMs);
|
|
85
74
|
const started = Date.now();
|
|
86
75
|
try {
|
|
87
|
-
const endpoint = jevEndpoint(token);
|
|
88
76
|
const response = await fetchImpl(endpoint.url, {
|
|
89
77
|
method: 'POST',
|
|
90
78
|
headers: { ...endpoint.headers, 'content-type': 'application/json' },
|
|
@@ -28,6 +28,9 @@ const createApp = ({ routeSend, autoSessions = new Set() } = {}) => {
|
|
|
28
28
|
updateConfig: vi.fn(async () => ({ available: true })),
|
|
29
29
|
setToken: vi.fn(async () => ({ available: true, tokenPresent: true })),
|
|
30
30
|
clearToken: vi.fn(async () => ({ available: true, tokenPresent: false })),
|
|
31
|
+
setClassifierSource: vi.fn(async () => ({ available: true })),
|
|
32
|
+
setCustomEndpoint: vi.fn(async () => ({ available: true })),
|
|
33
|
+
clearCustomEndpoint: vi.fn(async () => ({ available: true })),
|
|
31
34
|
};
|
|
32
35
|
const app = express();
|
|
33
36
|
registerRoutingRoutes(app, runtime);
|
|
@@ -130,6 +133,12 @@ describe('routing routes', () => {
|
|
|
130
133
|
expect(runtime.setToken).toHaveBeenCalledWith('ts-key');
|
|
131
134
|
await request(app).delete('/api/routing/token').expect(200);
|
|
132
135
|
expect(runtime.clearToken).toHaveBeenCalled();
|
|
136
|
+
await request(app).put('/api/routing/classifier').send({ source: 'zen-key' }).expect(200);
|
|
137
|
+
expect(runtime.setClassifierSource).toHaveBeenCalledWith('zen-key');
|
|
138
|
+
await request(app).put('/api/routing/classifier/custom').send({ url: 'https://jev.example.com/v1', model: 'jev-latest', key: 'k', extra: true }).expect(200);
|
|
139
|
+
expect(runtime.setCustomEndpoint).toHaveBeenCalledWith({ url: 'https://jev.example.com/v1', model: 'jev-latest', key: 'k' });
|
|
140
|
+
await request(app).delete('/api/routing/classifier/custom').expect(200);
|
|
141
|
+
expect(runtime.clearCustomEndpoint).toHaveBeenCalled();
|
|
133
142
|
});
|
|
134
143
|
|
|
135
144
|
});
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `/api/routing` — configuration
|
|
2
|
+
* `/api/routing` — configuration, the Jev key, the classification provider
|
|
3
|
+
* pick (`/api/routing/classifier`) and the custom endpoint
|
|
4
|
+
* (`/api/routing/classifier/custom`). Normal authenticated
|
|
3
5
|
* OpenChamber routes: do not add them to browser URL-token allowlists.
|
|
4
6
|
*
|
|
5
7
|
* The send-path rewrite, registered ahead of the generic OpenCode proxy. In
|
|
@@ -65,6 +67,30 @@ export function registerRoutingRoutes(app, runtime) {
|
|
|
65
67
|
sendError(res, error);
|
|
66
68
|
}
|
|
67
69
|
});
|
|
70
|
+
|
|
71
|
+
app.put('/api/routing/classifier', express.json({ limit: '4kb' }), async (req, res) => {
|
|
72
|
+
try {
|
|
73
|
+
res.json(await runtime.setClassifierSource(req.body?.source));
|
|
74
|
+
} catch (error) {
|
|
75
|
+
sendError(res, error);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
app.put('/api/routing/classifier/custom', express.json({ limit: '16kb' }), async (req, res) => {
|
|
80
|
+
try {
|
|
81
|
+
res.json(await runtime.setCustomEndpoint({ url: req.body?.url, model: req.body?.model, key: req.body?.key }));
|
|
82
|
+
} catch (error) {
|
|
83
|
+
sendError(res, error);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
app.delete('/api/routing/classifier/custom', async (_req, res) => {
|
|
88
|
+
try {
|
|
89
|
+
res.json(await runtime.clearCustomEndpoint());
|
|
90
|
+
} catch (error) {
|
|
91
|
+
sendError(res, error);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
68
94
|
}
|
|
69
95
|
|
|
70
96
|
export function registerRoutingPromptRewrite(app, runtime) {
|