@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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it, vi } from 'vitest';
|
|
2
2
|
import { createPermissionAutoAcceptRuntime } from './runtime.js';
|
|
3
3
|
|
|
4
|
-
const createRuntime = ({ stored, fetchImpl, retryDelaysMs = [0], evaluatePermission, onPermissionReplied } = {}) => {
|
|
4
|
+
const createRuntime = ({ stored, fetchImpl, retryDelaysMs = [0], evaluatePermission, onPermissionReplied, resolveLegacyEnabledMode } = {}) => {
|
|
5
5
|
let settings = stored ?? { permissionAutoAccept: { sessions: {} } };
|
|
6
6
|
let eventHandler;
|
|
7
7
|
let statusHandler;
|
|
@@ -18,6 +18,7 @@ const createRuntime = ({ stored, fetchImpl, retryDelaysMs = [0], evaluatePermiss
|
|
|
18
18
|
retryDelaysMs,
|
|
19
19
|
evaluatePermission,
|
|
20
20
|
onPermissionReplied,
|
|
21
|
+
resolveLegacyEnabledMode,
|
|
21
22
|
});
|
|
22
23
|
runtime.start();
|
|
23
24
|
return {
|
|
@@ -39,17 +40,64 @@ const flush = async () => {
|
|
|
39
40
|
};
|
|
40
41
|
|
|
41
42
|
describe('permission auto-accept runtime', () => {
|
|
42
|
-
it('persists explicit session
|
|
43
|
+
it('persists explicit session modes across runtime restarts', async () => {
|
|
43
44
|
const first = createRuntime();
|
|
44
|
-
await first.runtime.setSessionPolicy('root',
|
|
45
|
+
await first.runtime.setSessionPolicy('root', 'safety');
|
|
46
|
+
await first.runtime.setSessionPolicy('manual', 'ask');
|
|
45
47
|
|
|
46
48
|
const second = createRuntime({ stored: first.getSettings() });
|
|
49
|
+
// `sessions` keeps the on/off shape older clients read.
|
|
47
50
|
await expect(second.runtime.load()).resolves.toEqual({
|
|
48
|
-
sessions: { root: true },
|
|
49
|
-
|
|
51
|
+
sessions: { root: true, manual: false },
|
|
52
|
+
modes: { root: 'safety', manual: 'ask' },
|
|
53
|
+
revision: 2,
|
|
50
54
|
});
|
|
51
55
|
});
|
|
52
56
|
|
|
57
|
+
it('takes on/off from clients that predate the modes as auto and ask', async () => {
|
|
58
|
+
const { runtime } = createRuntime();
|
|
59
|
+
await runtime.setSessionPolicy('on', true);
|
|
60
|
+
await runtime.setSessionPolicy('off', false);
|
|
61
|
+
expect((await runtime.load()).modes).toEqual({ on: 'auto', off: 'ask' });
|
|
62
|
+
await expect(runtime.setSessionPolicy('bad', 'always')).rejects.toThrow(TypeError);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('converts a pre-modes policy once, as safety when the old safety net was on', async () => {
|
|
66
|
+
const resolveLegacyEnabledMode = vi.fn(async () => 'safety');
|
|
67
|
+
const { runtime, getSettings } = createRuntime({
|
|
68
|
+
stored: { permissionAutoAccept: { sessions: { root: true, child: false }, revision: 3 } },
|
|
69
|
+
resolveLegacyEnabledMode,
|
|
70
|
+
});
|
|
71
|
+
expect((await runtime.load()).modes).toEqual({ root: 'safety', child: 'ask' });
|
|
72
|
+
expect(getSettings().permissionAutoAccept).toEqual({ sessions: { root: 'safety', child: 'ask' }, revision: 3 });
|
|
73
|
+
|
|
74
|
+
const restarted = createRuntime({ stored: getSettings(), resolveLegacyEnabledMode });
|
|
75
|
+
await restarted.runtime.load();
|
|
76
|
+
expect(resolveLegacyEnabledMode).toHaveBeenCalledTimes(1);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('writes the default mode onto a new top-level session only', async () => {
|
|
80
|
+
const { runtime, emit, getSettings } = createRuntime();
|
|
81
|
+
await runtime.load();
|
|
82
|
+
getSettings().permissionDefaultMode = 'safety';
|
|
83
|
+
emit({ type: 'session.created', properties: { info: { id: 'root' } } });
|
|
84
|
+
emit({ type: 'session.created', properties: { info: { id: 'child', parentID: 'root' } } });
|
|
85
|
+
await flush();
|
|
86
|
+
await expect(runtime.resolveSessionMode('root', '/project')).resolves.toBe('safety');
|
|
87
|
+
expect((await runtime.load()).modes).toEqual({ root: 'safety' });
|
|
88
|
+
// The subagent inherits instead.
|
|
89
|
+
await expect(runtime.resolveSessionMode('child', '/project')).resolves.toBe('safety');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('keeps a mode the creating flow already set over the default', async () => {
|
|
93
|
+
const { runtime, emit, getSettings } = createRuntime();
|
|
94
|
+
await runtime.setSessionPolicy('root', 'ask');
|
|
95
|
+
getSettings().permissionDefaultMode = 'auto';
|
|
96
|
+
emit({ type: 'session.created', properties: { info: { id: 'root' } } });
|
|
97
|
+
await flush();
|
|
98
|
+
await expect(runtime.resolveSessionMode('root', '/project')).resolves.toBe('ask');
|
|
99
|
+
});
|
|
100
|
+
|
|
53
101
|
it('increments the authoritative policy revision', async () => {
|
|
54
102
|
const { runtime, getSettings } = createRuntime();
|
|
55
103
|
|
|
@@ -134,8 +182,11 @@ describe('permission auto-accept runtime', () => {
|
|
|
134
182
|
fetchImpl,
|
|
135
183
|
});
|
|
136
184
|
connect();
|
|
137
|
-
|
|
138
|
-
|
|
185
|
+
// The reconcile chain reads settings and response bodies, so its length in
|
|
186
|
+
// microtasks is not fixed; wait for the reply instead of counting ticks.
|
|
187
|
+
await vi.waitFor(() => {
|
|
188
|
+
expect(fetchImpl.mock.calls.some(([url]) => new URL(url).pathname === '/api/session/root/permission/pending/reply')).toBe(true);
|
|
189
|
+
});
|
|
139
190
|
});
|
|
140
191
|
|
|
141
192
|
it('accepts existing pending permissions when a session policy is enabled', async () => {
|
|
@@ -164,7 +215,7 @@ describe('permission auto-accept runtime', () => {
|
|
|
164
215
|
expect(replyPaths).toEqual(['/api/session/root/permission/root-pending/reply']);
|
|
165
216
|
// OpenCode 2.x scopes the pending list by header, not by query.
|
|
166
217
|
expect(fetchImpl.mock.calls.some(([, init]) => directoryHeader(init) === '/project')).toBe(true);
|
|
167
|
-
expect(await runtime.load()).toEqual({ sessions: { root: true }, revision: 1 });
|
|
218
|
+
expect(await runtime.load()).toEqual({ sessions: { root: true }, modes: { root: 'auto' }, revision: 1 });
|
|
168
219
|
});
|
|
169
220
|
|
|
170
221
|
it('leaves a request held by the safety net unanswered and forgets it once replied', async () => {
|
|
@@ -173,7 +224,7 @@ describe('permission auto-accept runtime', () => {
|
|
|
173
224
|
const evaluatePermission = vi.fn(async (permission) => verdicts[permission.id]);
|
|
174
225
|
const onPermissionReplied = vi.fn();
|
|
175
226
|
const { runtime, emit } = createRuntime({
|
|
176
|
-
stored: { permissionAutoAccept: { sessions: { root:
|
|
227
|
+
stored: { permissionAutoAccept: { sessions: { root: 'safety' } } },
|
|
177
228
|
fetchImpl,
|
|
178
229
|
evaluatePermission,
|
|
179
230
|
onPermissionReplied,
|
|
@@ -189,10 +240,43 @@ describe('permission auto-accept runtime', () => {
|
|
|
189
240
|
expect(directoryHeader(replies[0]?.[1])).toBe('/project');
|
|
190
241
|
expect(evaluatePermission).toHaveBeenCalledTimes(2);
|
|
191
242
|
|
|
243
|
+
// Notifications skip only the request that was answered.
|
|
244
|
+
await expect(runtime.isPermissionAutoAnswered('root', '/project', 'safe')).resolves.toBe(true);
|
|
245
|
+
await expect(runtime.isPermissionAutoAnswered('root', '/project', 'held')).resolves.toBe(false);
|
|
246
|
+
|
|
192
247
|
emit({ type: 'permission.replied', properties: { sessionID: 'root', requestID: 'held', reply: 'once' } });
|
|
193
248
|
expect(onPermissionReplied).toHaveBeenCalledWith('held');
|
|
194
249
|
});
|
|
195
250
|
|
|
251
|
+
it('never consults the safety net in an auto session', async () => {
|
|
252
|
+
const fetchImpl = vi.fn(async () => new Response('[]'));
|
|
253
|
+
const evaluatePermission = vi.fn(async () => ({ action: 'hold' }));
|
|
254
|
+
const { runtime, emit } = createRuntime({
|
|
255
|
+
stored: { permissionAutoAccept: { sessions: { root: 'auto' } } },
|
|
256
|
+
fetchImpl,
|
|
257
|
+
evaluatePermission,
|
|
258
|
+
});
|
|
259
|
+
await runtime.load();
|
|
260
|
+
emit({ type: 'permission.asked', properties: { id: 'p', sessionID: 'root', permission: 'bash', metadata: {} } });
|
|
261
|
+
await flush();
|
|
262
|
+
expect(evaluatePermission).not.toHaveBeenCalled();
|
|
263
|
+
expect(fetchImpl.mock.calls.some(([url]) => String(url).endsWith('/permission/p/reply'))).toBe(true);
|
|
264
|
+
await expect(runtime.isPermissionAutoAnswered('root', '/project', 'p')).resolves.toBe(true);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it('leaves a safety request for the user when the safety net gives no verdict', async () => {
|
|
268
|
+
const fetchImpl = vi.fn(async () => new Response('[]'));
|
|
269
|
+
const { runtime, emit } = createRuntime({
|
|
270
|
+
stored: { permissionAutoAccept: { sessions: { root: 'safety' } } },
|
|
271
|
+
fetchImpl,
|
|
272
|
+
evaluatePermission: async () => ({ action: 'hold', skipped: 'Jev timed out' }),
|
|
273
|
+
});
|
|
274
|
+
await runtime.load();
|
|
275
|
+
emit({ type: 'permission.asked', properties: { id: 'p', sessionID: 'root', permission: 'bash', metadata: {} } });
|
|
276
|
+
await flush();
|
|
277
|
+
expect(fetchImpl.mock.calls.some(([url]) => String(url).includes('/reply'))).toBe(false);
|
|
278
|
+
});
|
|
279
|
+
|
|
196
280
|
it('does not consult the safety net for sessions that are not auto-accepting', async () => {
|
|
197
281
|
const evaluatePermission = vi.fn(async () => ({ action: 'hold' }));
|
|
198
282
|
const { runtime, emit } = createRuntime({ evaluatePermission });
|
|
@@ -157,6 +157,12 @@ Unlimited keys report `usage_monthly` in a `monthly` window with no percent. `li
|
|
|
157
157
|
|
|
158
158
|
Keep `packages/web/server/lib/quota/providers/openrouter.js` and `packages/vscode/src/quotaProviders.ts` in sync, as with the Kimi and Copilot providers; the VS Code extension duplicates this parsing logic rather than importing the web provider.
|
|
159
159
|
|
|
160
|
+
## Zhipu AI Coding Plan semantics
|
|
161
|
+
|
|
162
|
+
`GET https://open.bigmodel.cn/api/monitor/usage/quota/limit` reports business failures inside HTTP 200 bodies (`{code, msg, success: false}`; an invalid token yields code 401 with `msg` "令牌已过期或验证不正确"). Providers must validate the envelope (`success === false` or a `code` other than 200) and return the failure with `msg` instead of parsing an empty `data.limits`; a missing envelope is treated as legacy success.
|
|
163
|
+
|
|
164
|
+
The limit type was renamed from `TOKENS_LIMIT` to `CREDIT_LIMIT` with unchanged `unit`/`number` window semantics: unit 3 marks hourly blocks (`5h`), unit 6 weekly. `CREDIT_LIMIT` entries carry `usage` (total), `currentValue` (consumed), and `remaining`, surfaced as a credit `valueLabel`; when `percentage` is absent the used percent is derived from `currentValue/usage`. `data.level` (for example `lite`) becomes `planLabel`. `TIME_LIMIT` stays the monthly `MCP Tools` window. Keep `packages/web/server/lib/quota/providers/zhipuai-coding-plan.js` and `packages/vscode/src/quotaProviders.ts` (`fetchZhipuaiCodingPlanQuota`) in sync.
|
|
165
|
+
|
|
160
166
|
## Notes for contributors
|
|
161
167
|
- Keep provider IDs stable; clients use them directly.
|
|
162
168
|
- Avoid adding alias-based dispatch in `fetchQuotaForProvider`; dispatch currently expects exact provider IDs.
|
|
@@ -3,27 +3,18 @@
|
|
|
3
3
|
*
|
|
4
4
|
* API: https://open.bigmodel.cn/api/monitor/usage/quota/limit
|
|
5
5
|
*
|
|
6
|
+
* bigmodel.cn reports business failures inside HTTP 200 bodies
|
|
7
|
+
* (`{code, msg, success: false}`), so the envelope must be validated before
|
|
8
|
+
* `data.limits` is parsed. A missing envelope is treated as legacy success.
|
|
9
|
+
*
|
|
6
10
|
* Response limits:
|
|
7
|
-
* - TOKENS_LIMIT:
|
|
11
|
+
* - TOKENS_LIMIT / CREDIT_LIMIT: token/credit usage windows (5-hour and weekly).
|
|
12
|
+
* The API renamed TOKENS_LIMIT to CREDIT_LIMIT; CREDIT_LIMIT entries
|
|
13
|
+
* additionally carry `usage` (total), `currentValue` (consumed), `remaining`,
|
|
14
|
+
* and `percentage` (used percent, derived from currentValue/usage when absent).
|
|
8
15
|
* - TIME_LIMIT: MCP tools usage (monthly window)
|
|
9
16
|
*
|
|
10
|
-
*
|
|
11
|
-
* @property {string} type - 'TOKENS_LIMIT'
|
|
12
|
-
* @property {number} [unit]
|
|
13
|
-
* @property {number} [number]
|
|
14
|
-
* @property {number} [nextResetTime]
|
|
15
|
-
* @property {number} [percentage]
|
|
16
|
-
*
|
|
17
|
-
* @typedef {Object} McpToolsTimeLimit
|
|
18
|
-
* @property {string} type - 'TIME_LIMIT'
|
|
19
|
-
* @property {number} [unit]
|
|
20
|
-
* @property {number} [number]
|
|
21
|
-
* @property {number} [usage]
|
|
22
|
-
* @property {number} [currentValue]
|
|
23
|
-
* @property {number} [remaining]
|
|
24
|
-
* @property {number} [percentage]
|
|
25
|
-
* @property {number} [nextResetTime]
|
|
26
|
-
* @property {Array<{modelCode: string, usage: number}>} [usageDetails]
|
|
17
|
+
* `data.level` is the plan tier (for example "lite") and becomes `planLabel`.
|
|
27
18
|
*/
|
|
28
19
|
import { readAuthFile } from '../../opencode/auth.js';
|
|
29
20
|
import { readConfigLayers } from '../../opencode/shared.js';
|
|
@@ -32,7 +23,10 @@ import {
|
|
|
32
23
|
normalizeAuthEntry,
|
|
33
24
|
buildResult,
|
|
34
25
|
toUsageWindow,
|
|
26
|
+
toNumber,
|
|
27
|
+
asNonEmptyString,
|
|
35
28
|
resolveWindowSeconds,
|
|
29
|
+
resolveWindowLabel,
|
|
36
30
|
normalizeTimestamp
|
|
37
31
|
} from '../utils/index.js';
|
|
38
32
|
|
|
@@ -40,6 +34,42 @@ export const providerId = 'zhipuai-coding-plan';
|
|
|
40
34
|
export const providerName = 'Zhipu AI Coding Plan';
|
|
41
35
|
const aliases = ['zhipuai-coding-plan', 'zhipuai', 'zhipu'];
|
|
42
36
|
|
|
37
|
+
// Mirrors the Z.ai credit label (same monitor API family): `usage` is the
|
|
38
|
+
// total, `currentValue` the consumed amount.
|
|
39
|
+
const formatCreditAmount = (value) => {
|
|
40
|
+
if (value < 1000) return value.toLocaleString('en-US');
|
|
41
|
+
return `${Math.round(value / 100) / 10}k`;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const formatCreditValueLabel = (limit) => {
|
|
45
|
+
const used = toNumber(limit?.currentValue);
|
|
46
|
+
const total = toNumber(limit?.usage);
|
|
47
|
+
if (used === null || total === null) return null;
|
|
48
|
+
return `${formatCreditAmount(used)} / ${formatCreditAmount(total)} credits`;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// `percentage` is the used percent; when the API omits it, derive it from
|
|
52
|
+
// currentValue/usage (observed percentages are integers).
|
|
53
|
+
const resolveUsedPercent = (limit) => {
|
|
54
|
+
const percentage = toNumber(limit?.percentage);
|
|
55
|
+
if (percentage !== null) {
|
|
56
|
+
return percentage;
|
|
57
|
+
}
|
|
58
|
+
const used = toNumber(limit?.currentValue);
|
|
59
|
+
const total = toNumber(limit?.usage);
|
|
60
|
+
if (used === null || total === null || total <= 0) return null;
|
|
61
|
+
return Math.round((used / total) * 100);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const envelopeError = (payload) => {
|
|
65
|
+
const code = payload?.code;
|
|
66
|
+
if (payload?.success !== false && !(code !== undefined && code !== null && code !== 200)) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
const msg = asNonEmptyString(payload?.msg);
|
|
70
|
+
return msg ?? `API error: ${code ?? 'unknown'}`;
|
|
71
|
+
};
|
|
72
|
+
|
|
43
73
|
function getApiKey() {
|
|
44
74
|
const auth = readAuthFile();
|
|
45
75
|
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
@@ -102,27 +132,40 @@ export const fetchQuota = async () => {
|
|
|
102
132
|
}
|
|
103
133
|
|
|
104
134
|
const payload = await response.json();
|
|
105
|
-
const limits = Array.isArray(payload?.data?.limits) ? payload.data.limits : [];
|
|
106
135
|
|
|
107
|
-
const
|
|
108
|
-
|
|
136
|
+
const failure = envelopeError(payload);
|
|
137
|
+
if (failure) {
|
|
138
|
+
return buildResult({
|
|
139
|
+
providerId,
|
|
140
|
+
providerName,
|
|
141
|
+
ok: false,
|
|
142
|
+
configured: true,
|
|
143
|
+
error: failure
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const limits = Array.isArray(payload?.data?.limits) ? payload.data.limits : [];
|
|
109
148
|
|
|
110
149
|
const windows = {};
|
|
111
150
|
|
|
112
|
-
//
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const
|
|
151
|
+
// The API renamed TOKENS_LIMIT to CREDIT_LIMIT; field semantics stayed the
|
|
152
|
+
// same, so both limit types map to the same windows. Unit 3 marks hourly
|
|
153
|
+
// blocks (5h), unit 6 weekly.
|
|
154
|
+
for (const limit of limits.filter((entry) => entry?.type === 'TOKENS_LIMIT' || entry?.type === 'CREDIT_LIMIT')) {
|
|
155
|
+
const windowSeconds = resolveWindowSeconds(limit);
|
|
156
|
+
const windowLabel = resolveWindowLabel(windowSeconds);
|
|
157
|
+
const resetAt = limit?.nextResetTime ? normalizeTimestamp(limit.nextResetTime) : null;
|
|
117
158
|
|
|
118
|
-
windows[
|
|
119
|
-
usedPercent,
|
|
159
|
+
windows[windowLabel] = toUsageWindow({
|
|
160
|
+
usedPercent: resolveUsedPercent(limit),
|
|
120
161
|
windowSeconds,
|
|
121
|
-
resetAt
|
|
162
|
+
resetAt,
|
|
163
|
+
valueLabel: formatCreditValueLabel(limit)
|
|
122
164
|
});
|
|
123
165
|
}
|
|
124
166
|
|
|
125
167
|
// Handle TIME_LIMIT (MCP tools monthly window)
|
|
168
|
+
const mcpToolsTimeLimit = limits.find((limit) => limit?.type === 'TIME_LIMIT');
|
|
126
169
|
if (mcpToolsTimeLimit) {
|
|
127
170
|
// TIME_LIMIT unit=5 means 1 month (30 days)
|
|
128
171
|
const monthSeconds = 30 * 24 * 60 * 60;
|
|
@@ -141,7 +184,8 @@ export const fetchQuota = async () => {
|
|
|
141
184
|
providerName,
|
|
142
185
|
ok: true,
|
|
143
186
|
configured: true,
|
|
144
|
-
usage: { windows }
|
|
187
|
+
usage: { windows },
|
|
188
|
+
planLabel: asNonEmptyString(payload?.data?.level)
|
|
145
189
|
});
|
|
146
190
|
} catch (error) {
|
|
147
191
|
return buildResult({
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
vi.mock('../../opencode/auth.js', () => ({
|
|
4
|
+
readAuthFile: () => ({ 'zhipuai-coding-plan': { key: 'test-token' } }),
|
|
5
|
+
}));
|
|
6
|
+
|
|
7
|
+
import { fetchQuota } from './zhipuai-coding-plan.js';
|
|
8
|
+
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
vi.unstubAllGlobals();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const mockResponse = (body) => ({
|
|
14
|
+
ok: true,
|
|
15
|
+
status: 200,
|
|
16
|
+
json: async () => body,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe('Zhipu AI Coding Plan quota provider', () => {
|
|
20
|
+
it('maps CREDIT_LIMIT entries to 5-hour and weekly windows with credit labels and plan level', async () => {
|
|
21
|
+
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(mockResponse({
|
|
22
|
+
code: 200,
|
|
23
|
+
msg: '操作成功',
|
|
24
|
+
success: true,
|
|
25
|
+
data: {
|
|
26
|
+
limits: [
|
|
27
|
+
{ type: 'CREDIT_LIMIT', unit: 3, number: 5, usage: 2000, currentValue: 900, remaining: 1100, percentage: 45, nextResetTime: 1797930060000 },
|
|
28
|
+
{ type: 'CREDIT_LIMIT', unit: 6, number: 1, usage: 10000, currentValue: 6000, remaining: 4000, percentage: 60, nextResetTime: 1798425600000 },
|
|
29
|
+
{ type: 'TIME_LIMIT', unit: 5, number: 1, percentage: 5, nextResetTime: 1798425600000 },
|
|
30
|
+
],
|
|
31
|
+
level: 'lite',
|
|
32
|
+
},
|
|
33
|
+
})));
|
|
34
|
+
|
|
35
|
+
const result = await fetchQuota();
|
|
36
|
+
const windows = result.usage.windows;
|
|
37
|
+
|
|
38
|
+
expect(result.ok).toBe(true);
|
|
39
|
+
expect(result.planLabel).toBe('lite');
|
|
40
|
+
expect(windows['5h']).toMatchObject({
|
|
41
|
+
usedPercent: 45,
|
|
42
|
+
remainingPercent: 55,
|
|
43
|
+
windowSeconds: 5 * 60 * 60,
|
|
44
|
+
resetAt: 1797930060000,
|
|
45
|
+
valueLabel: '900 / 2k credits',
|
|
46
|
+
});
|
|
47
|
+
expect(windows.weekly).toMatchObject({
|
|
48
|
+
usedPercent: 60,
|
|
49
|
+
remainingPercent: 40,
|
|
50
|
+
windowSeconds: 7 * 24 * 60 * 60,
|
|
51
|
+
resetAt: 1798425600000,
|
|
52
|
+
valueLabel: '6k / 10k credits',
|
|
53
|
+
});
|
|
54
|
+
expect(windows['MCP Tools']).toMatchObject({
|
|
55
|
+
usedPercent: 5,
|
|
56
|
+
windowSeconds: 30 * 24 * 60 * 60,
|
|
57
|
+
resetAt: 1798425600000,
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('still maps legacy TOKENS_LIMIT entries without credit labels', async () => {
|
|
62
|
+
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(mockResponse({
|
|
63
|
+
data: {
|
|
64
|
+
limits: [
|
|
65
|
+
{ type: 'TOKENS_LIMIT', unit: 3, number: 5, percentage: 30 },
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
})));
|
|
69
|
+
|
|
70
|
+
const result = await fetchQuota();
|
|
71
|
+
|
|
72
|
+
expect(result.ok).toBe(true);
|
|
73
|
+
expect(result.usage.windows['5h']).toMatchObject({
|
|
74
|
+
usedPercent: 30,
|
|
75
|
+
windowSeconds: 5 * 60 * 60,
|
|
76
|
+
});
|
|
77
|
+
expect(result.usage.windows['5h'].valueLabel).toBeUndefined();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('derives the used percent from currentValue/usage when percentage is missing', async () => {
|
|
81
|
+
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(mockResponse({
|
|
82
|
+
code: 200,
|
|
83
|
+
success: true,
|
|
84
|
+
data: {
|
|
85
|
+
limits: [
|
|
86
|
+
{ type: 'CREDIT_LIMIT', unit: 3, number: 5, usage: 2000, currentValue: 900 },
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
})));
|
|
90
|
+
|
|
91
|
+
const result = await fetchQuota();
|
|
92
|
+
|
|
93
|
+
expect(result.ok).toBe(true);
|
|
94
|
+
expect(result.usage.windows['5h'].usedPercent).toBe(45);
|
|
95
|
+
expect(result.usage.windows['5h'].valueLabel).toBe('900 / 2k credits');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('surfaces business failures reported inside HTTP 200 bodies', async () => {
|
|
99
|
+
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(mockResponse({
|
|
100
|
+
code: 401,
|
|
101
|
+
msg: '令牌已过期或验证不正确',
|
|
102
|
+
success: false,
|
|
103
|
+
})));
|
|
104
|
+
|
|
105
|
+
const result = await fetchQuota();
|
|
106
|
+
|
|
107
|
+
expect(result.ok).toBe(false);
|
|
108
|
+
expect(result.configured).toBe(true);
|
|
109
|
+
expect(result.error).toBe('令牌已过期或验证不正确');
|
|
110
|
+
expect(result.usage).toBeNull();
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('falls back to the code when the envelope carries no message', async () => {
|
|
114
|
+
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(mockResponse({
|
|
115
|
+
code: 1001,
|
|
116
|
+
success: false,
|
|
117
|
+
})));
|
|
118
|
+
|
|
119
|
+
const result = await fetchQuota();
|
|
120
|
+
|
|
121
|
+
expect(result.ok).toBe(false);
|
|
122
|
+
expect(result.error).toBe('API error: 1001');
|
|
123
|
+
});
|
|
124
|
+
});
|
|
@@ -19,7 +19,7 @@ Traffic is modeled as three stacked layers. The relay understands only Layer 1;
|
|
|
19
19
|
## Entrypoints and structure
|
|
20
20
|
|
|
21
21
|
Host side (`packages/web/server/lib/relay/`):
|
|
22
|
-
- `service.js` — thin entrypoint: relay config (enabled flag + relay URL), the management routes (`GET/POST /api/openchamber/relay/{status,enable,disable}`), a `getPairingCandidate()` accessor (the relay transport candidate folded into pairing-v2 links when enabled, consumed by the pairing-session route in `core-routes.js`), and lifecycle wiring. Started from `packages/web/server/index.js` only when the user has explicitly enabled the relay. The relay endpoint defaults to the OpenChamber-hosted relay but can be pinned to a self-hosted relay
|
|
22
|
+
- `service.js` — thin entrypoint: relay config (enabled flag + relay URL), the management routes (`GET/POST /api/openchamber/relay/{status,enable,disable}`), a `getPairingCandidate()` accessor (the relay transport candidate folded into pairing-v2 links when enabled, consumed by the pairing-session route in `core-routes.js`), and lifecycle wiring. Started from `packages/web/server/index.js` only when the user has explicitly enabled the relay. The relay endpoint defaults to the OpenChamber-hosted relay but can be pinned to a self-hosted relay (`pinnedRelayUrl`: `relayUrl` in the machine policy file, else the `OPENCHAMBER_RELAY_URL` env var; see `../enterprise-mode.js`; must be `ws://`/`wss://`, an invalid value pins nothing); when set it overrides the stored setting for the host connection, the pairing candidate, and status, so paired clients inherit the endpoint automatically. In enterprise mode (`../enterprise-mode.js`) the relay runs only with that pin (`relayBlockedByEnterprise`): `start()` refuses otherwise (every path in passes through it), `enable` answers 403, `getPairingCandidate()` is null, `ensureEnabledForPairing()` throws (the pairing route drops the candidate and direct pairing still works), status carries `blockedByEnterprise`, and `resolvePairingTransports` in `index.js` reports `relayAvailable: false`.
|
|
23
23
|
- `identity.js` — the host's stable identity: the long-lived signing keypair (shared with the push relay, defines the routing id) plus a long-lived encryption keypair (the E2EE trust anchor). Reused across restarts; never rotated implicitly.
|
|
24
24
|
- `signing-key.js` — storage/derivation of the signing keypair and the routing id, shared with the notifications runtime.
|
|
25
25
|
- `host-client.js` — the long-lived connection manager: one outbound control connection to the relay, a per-client data connection for each connected device, reconnect/backoff, and the E2EE responder handshake per connection.
|
|
@@ -15,6 +15,7 @@ import express from 'express';
|
|
|
15
15
|
|
|
16
16
|
import { createRelayIdentityRuntime } from './identity.js';
|
|
17
17
|
import { startRelayHost } from './host-client.js';
|
|
18
|
+
import { isEnterpriseMode, readEnterprisePolicy } from '../enterprise-mode.js';
|
|
18
19
|
|
|
19
20
|
export const DEFAULT_RELAY_URL = 'wss://relay.openchamber.dev/ws';
|
|
20
21
|
|
|
@@ -35,16 +36,24 @@ const normalizeRelayUrl = (value) => {
|
|
|
35
36
|
return trimmed;
|
|
36
37
|
};
|
|
37
38
|
|
|
38
|
-
// A deployment can pin the relay endpoint
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
// A deployment can pin the relay endpoint (e.g. a self-hosted relay on your
|
|
40
|
+
// own Cloudflare account/domain): `relayUrl` in the machine policy file, else
|
|
41
|
+
// OPENCHAMBER_RELAY_URL (see ../enterprise-mode.js). When set and valid it
|
|
42
|
+
// overrides the stored setting entirely, so the host connection, the pairing
|
|
43
|
+
// offer, and the status all point at it — clients then inherit it from the
|
|
44
|
+
// offer automatically. An invalid pinned value pins nothing.
|
|
45
|
+
export const pinnedRelayUrl = () => {
|
|
46
|
+
const raw = readEnterprisePolicy().relayUrl;
|
|
47
|
+
return raw && isValidRelayUrl(raw) ? raw.trim() : null;
|
|
46
48
|
};
|
|
47
49
|
|
|
50
|
+
// Enterprise mode keeps remote access inside the company: the relay runs only
|
|
51
|
+
// on a pinned self-hosted endpoint, never on ours.
|
|
52
|
+
// Traffic is end-to-end encrypted either way; what stays in-house is the
|
|
53
|
+
// metadata and the path into this machine.
|
|
54
|
+
const RELAY_BLOCKED_ERROR = 'In enterprise mode the relay runs on your own endpoint: set relayUrl in the policy file or OPENCHAMBER_RELAY_URL to a self-hosted relay.';
|
|
55
|
+
export const relayBlockedByEnterprise = () => isEnterpriseMode() && pinnedRelayUrl() === null;
|
|
56
|
+
|
|
48
57
|
/**
|
|
49
58
|
* @param {{
|
|
50
59
|
* crypto: typeof import('node:crypto'),
|
|
@@ -96,12 +105,12 @@ export const createRelayService = ({
|
|
|
96
105
|
const readConfig = async () => {
|
|
97
106
|
const settings = await readSettingsFromDiskMigrated();
|
|
98
107
|
const stored = settings?.privateRelay;
|
|
99
|
-
const override =
|
|
108
|
+
const override = pinnedRelayUrl();
|
|
100
109
|
return {
|
|
101
110
|
enabled: stored?.enabled === true,
|
|
102
111
|
relayUrl: override ?? normalizeRelayUrl(stored?.relayUrl),
|
|
103
|
-
// True when
|
|
104
|
-
//
|
|
112
|
+
// True when an administrator pinned the endpoint (a self-hosted relay);
|
|
113
|
+
// the stored setting is ignored while it is set.
|
|
105
114
|
relayUrlLocked: override !== null,
|
|
106
115
|
};
|
|
107
116
|
};
|
|
@@ -177,6 +186,11 @@ export const createRelayService = ({
|
|
|
177
186
|
|
|
178
187
|
const start = async (relayUrl, { claim = 'try' } = {}) => {
|
|
179
188
|
if (hostClient) return;
|
|
189
|
+
// Every path into the relay host passes here: boot, demand, enable, pairing.
|
|
190
|
+
if (relayBlockedByEnterprise()) {
|
|
191
|
+
status = { state: 'disabled', lastError: RELAY_BLOCKED_ERROR, connectedClients: 0 };
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
180
194
|
if (claim !== 'force' && !allowPassiveHost) {
|
|
181
195
|
status = {
|
|
182
196
|
state: 'standby',
|
|
@@ -269,6 +283,7 @@ export const createRelayService = ({
|
|
|
269
283
|
connectedClients: live.connectedClients,
|
|
270
284
|
relayUrl: config.relayUrl,
|
|
271
285
|
relayUrlLocked: config.relayUrlLocked,
|
|
286
|
+
blockedByEnterprise: relayBlockedByEnterprise(),
|
|
272
287
|
...(live.lastError ? { lastError: live.lastError } : {}),
|
|
273
288
|
};
|
|
274
289
|
};
|
|
@@ -293,7 +308,7 @@ export const createRelayService = ({
|
|
|
293
308
|
|
|
294
309
|
const getPairingCandidate = async () => {
|
|
295
310
|
const config = await readConfig();
|
|
296
|
-
if (!config.enabled) return null;
|
|
311
|
+
if (!config.enabled || relayBlockedByEnterprise()) return null;
|
|
297
312
|
return buildPairingCandidate();
|
|
298
313
|
};
|
|
299
314
|
|
|
@@ -302,6 +317,8 @@ export const createRelayService = ({
|
|
|
302
317
|
// rather than requiring a separate manual toggle. Idempotent: a no-op when the
|
|
303
318
|
// relay is already enabled and running.
|
|
304
319
|
const ensureEnabledForPairing = async () => {
|
|
320
|
+
// Direct pairing still works: the pairing route drops a failed relay candidate.
|
|
321
|
+
if (relayBlockedByEnterprise()) throw Object.assign(new Error(RELAY_BLOCKED_ERROR), { statusCode: 403 });
|
|
305
322
|
const config = await readConfig();
|
|
306
323
|
if (!config.enabled) {
|
|
307
324
|
await writeConfig({ enabled: true, relayUrl: config.relayUrl });
|
|
@@ -327,6 +344,9 @@ export const createRelayService = ({
|
|
|
327
344
|
});
|
|
328
345
|
|
|
329
346
|
app.post('/api/openchamber/relay/enable', express.json({ limit: '16kb' }), async (req, res) => {
|
|
347
|
+
if (relayBlockedByEnterprise()) {
|
|
348
|
+
return res.status(403).json({ error: RELAY_BLOCKED_ERROR, code: 'enterprise_mode' });
|
|
349
|
+
}
|
|
330
350
|
try {
|
|
331
351
|
const current = await readConfig();
|
|
332
352
|
const relayUrl = typeof req.body?.relayUrl === 'string' ? normalizeRelayUrl(req.body.relayUrl) : current.relayUrl;
|
|
@@ -56,6 +56,36 @@ describe('relay service passive hosting', () => {
|
|
|
56
56
|
}
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
+
it('in enterprise mode runs only on a relay pinned by OPENCHAMBER_RELAY_URL', async () => {
|
|
60
|
+
process.env.OPENCHAMBER_ENTERPRISE_MODE = '1';
|
|
61
|
+
delete process.env.OPENCHAMBER_RELAY_URL;
|
|
62
|
+
const blocked = makeService();
|
|
63
|
+
try {
|
|
64
|
+
await blocked.service.startIfEnabled();
|
|
65
|
+
await blocked.service.reconcile();
|
|
66
|
+
const status = await blocked.service.getStatus();
|
|
67
|
+
expect(status).toMatchObject({ state: 'disabled', blockedByEnterprise: true });
|
|
68
|
+
expect(blocked.hostLock.tryClaim).not.toHaveBeenCalled();
|
|
69
|
+
expect(await blocked.service.getPairingCandidate()).toBeNull();
|
|
70
|
+
await expect(blocked.service.ensureEnabledForPairing()).rejects.toMatchObject({ statusCode: 403 });
|
|
71
|
+
expect(blocked.hostLock.forceClaim).not.toHaveBeenCalled();
|
|
72
|
+
|
|
73
|
+
process.env.OPENCHAMBER_RELAY_URL = 'wss://relay.company.test/ws';
|
|
74
|
+
const own = makeService();
|
|
75
|
+
try {
|
|
76
|
+
const candidate = await own.service.ensureEnabledForPairing();
|
|
77
|
+
expect(candidate).toMatchObject({ type: 'relay', relayUrl: 'wss://relay.company.test/ws' });
|
|
78
|
+
expect((await own.service.getStatus()).blockedByEnterprise).toBe(false);
|
|
79
|
+
} finally {
|
|
80
|
+
own.service.stop();
|
|
81
|
+
}
|
|
82
|
+
} finally {
|
|
83
|
+
blocked.service.stop();
|
|
84
|
+
delete process.env.OPENCHAMBER_ENTERPRISE_MODE;
|
|
85
|
+
delete process.env.OPENCHAMBER_RELAY_URL;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
59
89
|
it('force-claims for an explicit pairing even when passive hosting is disabled', async () => {
|
|
60
90
|
const { service, hostLock } = makeService({ allowPassiveHost: false });
|
|
61
91
|
try {
|