@openchamber/web 1.21.1 → 1.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{CodeMirrorCommentWidgets-BGj8TJxW.js → CodeMirrorCommentWidgets-BO_2OW4E.js} +1 -1
- package/dist/assets/DiffView-CNnDxRmO.js +4 -0
- package/dist/assets/DirtyBranchSwitchDialog-jADfXQnR.js +1 -0
- package/dist/assets/FilesView-8wdiG2mj.js +17 -0
- package/dist/assets/GitView-Cv2xH-S6.js +6 -0
- package/dist/assets/{JsonTreeView-CggOsLot.js → JsonTreeView-DUiIpERC.js} +1 -1
- package/dist/assets/LinearIssuesView-CoZ7pQN5.js +1 -0
- package/dist/assets/MarkdownImageGallery-DffjmciG.js +1 -0
- package/dist/assets/MarkdownRendererImpl-DxqdYDAx.js +12 -0
- package/dist/assets/OnboardingScreen-CTZe6HZn.js +1 -0
- package/dist/assets/{PatchDiff-DJYMUiXA.js → PatchDiff-BymkP9JA.js} +1 -1
- package/dist/assets/{PierreDiffViewer-CY2bx_SB.js → PierreDiffViewer-BvwtCxW4.js} +3 -3
- package/dist/assets/{PlanView-PkiOY_9H.js → PlanView-C1qvAm7m.js} +3 -3
- package/dist/assets/SettingsView-xGONHFGS.js +28 -0
- package/dist/assets/{SettingsWindow-oyOm2fHR.js → SettingsWindow-COzgfFxM.js} +1 -1
- package/dist/assets/{ToolOutputDialog-lKyeQTPL.js → ToolOutputDialog-Dlhh_-oe.js} +6 -6
- package/dist/assets/ToolPartDiffPreview-b9joNtXH.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-BP7ebDFF.js → VirtualizedFileDiff-vqW3KKo5.js} +1 -1
- package/dist/assets/WalkthroughView-D-HFgdmM.js +4 -0
- package/dist/assets/{computeVirtualFileMetrics-CZ0xPeaT.js → computeVirtualFileMetrics-DUnyszhW.js} +1 -1
- package/dist/assets/{contextPanelEmbeddedChat-C9abMBTb.js → contextPanelEmbeddedChat-CV-DwAiX.js} +1 -1
- package/dist/assets/{de-CEoCz3j6.js → de-Cv_4FoXm.js} +6 -5
- package/dist/assets/es-BIWNEbnS.js +16 -0
- package/dist/assets/{fr-CS7Csln9.js → fr-SD3OfMHJ.js} +6 -5
- package/dist/assets/index-CHUT_bDS.css +1 -0
- package/dist/assets/index-DDInLQDd.js +40 -0
- package/dist/assets/{index-CaPAjwXQ.js → index-DLiD86ge.js} +1 -1
- package/dist/assets/{isDiffPlainText-ZBvDxhVB.js → isDiffPlainText-TNageFjy.js} +1 -1
- package/dist/assets/{isFilePlainText-DiLRrkJr.js → isFilePlainText-JPmZOYSp.js} +1 -1
- package/dist/assets/{ja-vnwqLcx6.js → ja-D7I9HofF.js} +7 -6
- package/dist/assets/{ko-CXuSfZv5.js → ko-BsVJM_PQ.js} +7 -6
- package/dist/assets/{main-D5RWr6sJ.js → main-DCB4JgVe.js} +2 -2
- package/dist/assets/main-De8Z5w49.js +928 -0
- package/dist/assets/markdownCore-BoQVG5-a.js +3 -0
- package/dist/assets/{miniChat-CqR3icsk.js → miniChat-BtV7N5OF.js} +2 -2
- package/dist/assets/{mobile-RN_UTTlB.js → mobile-DZV_sfX7.js} +2 -2
- package/dist/assets/{patchFileDiff-CjRR5ESs.js → patchFileDiff-Chmiz6hq.js} +4 -4
- package/dist/assets/{pl-BJxry0Mi.js → pl-XR9Bs8Be.js} +6 -5
- package/dist/assets/pt-BR-Due4be8g.js +16 -0
- package/dist/assets/{renderElectronMiniChatApp-1wC94fQK.js → renderElectronMiniChatApp-8tXADjfl.js} +2 -2
- package/dist/assets/renderMobileApp-Cji7Hma5.js +25 -0
- package/dist/assets/runtimeEndpointReset-gWt3Lb5D.js +16 -0
- package/dist/assets/scheduledTasksApi-9e-UX6im.js +1 -0
- package/dist/assets/{shikiHighlight-fGmFkxAM.js → shikiHighlight-CRpCl7UT.js} +1 -1
- package/dist/assets/tr-DBJcAv4y.js +7 -0
- package/dist/assets/uk-COYh2BaN.js +16 -0
- package/dist/assets/{useAppFontEffects-KP8_yiGW.js → useAppFontEffects-CCgvcQ6u.js} +178 -170
- package/dist/assets/useInlineCommentController-BkfXnjNZ.js +2 -0
- package/dist/assets/useRootScrollLock-KzOUytpn.js +1 -0
- package/dist/assets/{vendor-codemirror-language-data-DrTPkHl4.js → vendor-codemirror-language-data-BxpoC5Fp.js} +2 -2
- package/dist/assets/vendor-zod-DVWEh-IS.js +39 -0
- package/dist/assets/{web-components-DOXvU-tB.js → web-components-B6QgbmTo.js} +4 -4
- package/dist/assets/zh-CN-Cjk6lzhc.js +16 -0
- package/dist/assets/{zh-TW-Dv8yyhN1.js → zh-TW-Dk0dOg03.js} +6 -5
- package/dist/index.html +5 -5
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +2 -2
- package/server/index.js +35 -4
- package/server/lib/agent-tool/runtime.js +2 -19
- package/server/lib/dev-tunnel/DOCUMENTATION.md +13 -4
- package/server/lib/dev-tunnel/runtime.js +4 -4
- package/server/lib/dev-tunnel/tunnel.test.js +20 -0
- package/server/lib/dictation/DOCUMENTATION.md +19 -6
- package/server/lib/dictation/local/model-catalog.js +220 -0
- package/server/lib/dictation/local/model-catalog.test.js +42 -0
- package/server/lib/dictation/local/sherpa-tts.js +41 -20
- package/server/lib/dictation/local/worker-process.js +2 -0
- package/server/lib/dictation/runtime.js +4 -0
- package/server/lib/dictation/service.js +27 -4
- package/server/lib/fs/DOCUMENTATION.md +4 -0
- package/server/lib/fs/routes.js +129 -0
- package/server/lib/fs/routes.test.js +219 -0
- package/server/lib/git/DOCUMENTATION.md +3 -1
- package/server/lib/git/routes.js +16 -0
- package/server/lib/git/service.js +97 -17
- package/server/lib/git/service.test.js +153 -0
- package/server/lib/linear/DOCUMENTATION.md +97 -0
- package/server/lib/linear/OAUTH-BROKER-HANDOFF.md +91 -0
- package/server/lib/linear/auth.js +436 -0
- package/server/lib/linear/auth.test.js +242 -0
- package/server/lib/linear/client.js +191 -0
- package/server/lib/linear/index.js +61 -0
- package/server/lib/linear/issues.js +499 -0
- package/server/lib/linear/issues.test.js +512 -0
- package/server/lib/linear/mapping.js +188 -0
- package/server/lib/linear/mapping.test.js +147 -0
- package/server/lib/linear/oauth.js +345 -0
- package/server/lib/linear/oauth.test.js +166 -0
- package/server/lib/linear/parse.js +23 -0
- package/server/lib/linear/routes.js +432 -0
- package/server/lib/linear/routes.test.js +661 -0
- package/server/lib/linear/status-runtime.js +64 -0
- package/server/lib/linear/status-runtime.test.js +167 -0
- package/server/lib/linear/status.js +280 -0
- package/server/lib/linear/status.test.js +271 -0
- package/server/lib/linear/teams.js +72 -0
- package/server/lib/linear/teams.test.js +94 -0
- package/server/lib/mcp-reconnect/DOCUMENTATION.md +55 -0
- package/server/lib/mcp-reconnect/runtime.js +122 -0
- package/server/lib/mcp-reconnect/runtime.test.js +140 -0
- package/server/lib/message-queue/DOCUMENTATION.md +148 -0
- package/server/lib/message-queue/runtime.js +818 -0
- package/server/lib/message-queue/runtime.test.js +426 -0
- package/server/lib/openchamber-sessions/routes.js +102 -0
- package/server/lib/openchamber-sessions/routes.test.js +88 -0
- package/server/lib/opencode/DOCUMENTATION.md +5 -1
- package/server/lib/opencode/core-routes.js +1 -0
- package/server/lib/opencode/feature-routes-runtime.js +5 -0
- package/server/lib/opencode/managed-plugin-config.js +35 -0
- package/server/lib/opencode/settings-runtime.js +2 -2
- package/server/lib/opencode/settings-runtime.test.js +29 -0
- package/server/lib/opencode/shutdown-runtime.js +2 -0
- package/server/lib/opencode/static-routes-runtime.js +3 -3
- package/server/lib/projects/project-config.js +33 -5
- package/server/lib/projects/project-config.test.js +85 -0
- package/server/lib/quota/DOCUMENTATION.md +2 -1
- package/server/lib/quota/credentials/providers.js +4 -0
- package/server/lib/quota/credentials/store.js +1 -1
- package/server/lib/quota/credentials/store.test.js +4 -4
- package/server/lib/quota/providers/exe-dev.js +75 -0
- package/server/lib/quota/providers/exe-dev.test.js +47 -0
- package/server/lib/quota/providers/index.js +7 -0
- package/server/lib/quota/providers/opencode-go.js +1 -0
- package/server/lib/quota/providers/opencode-go.test.js +5 -1
- package/server/lib/quota/routes.js +2 -0
- package/server/lib/relay/DOCUMENTATION.md +1 -1
- package/server/lib/relay/tunnel-host.js +3 -1
- package/server/lib/relay/tunnel-host.test.js +9 -1
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +7 -0
- package/server/lib/security/request-security.js +21 -6
- package/server/lib/security/request-security.test.js +42 -8
- package/server/lib/session-assist/runtime.js +1 -0
- package/server/lib/session-goal/create.js +3 -1
- package/server/lib/session-goal/runtime.js +1 -0
- package/server/lib/small-model/DOCUMENTATION.md +4 -0
- package/server/lib/small-model/call.js +8 -2
- package/server/lib/small-model/call.test.js +23 -0
- package/server/lib/small-model/index.js +2 -1
- package/server/lib/small-model/routes.js +2 -1
- package/server/lib/system-prompt/runtime.js +2 -21
- package/server/lib/terminal/runtime.js +30 -7
- package/server/lib/tts/DOCUMENTATION.md +1 -0
- package/server/lib/tts/language-detect.js +210 -0
- package/server/lib/tts/language-detect.test.js +76 -0
- package/server/lib/tts/routes.js +23 -1
- package/server/lib/tts/routes.test.js +26 -0
- package/server/lib/ui-auth/ui-auth.js +4 -1
- package/server/lib/ui-auth/ui-auth.test.js +16 -0
- package/server/lib/walkthrough/index.js +1 -0
- package/dist/assets/CommitSection-DwGiXyjf.js +0 -1
- package/dist/assets/DiffView-Db6bjVv1.js +0 -4
- package/dist/assets/FilesView-DQOa7Lgz.js +0 -17
- package/dist/assets/GitView-CHzJxTi0.js +0 -6
- package/dist/assets/MarkdownImageGallery-DoZpaHev.js +0 -1
- package/dist/assets/MarkdownRendererImpl-B5Y5xCOz.js +0 -12
- package/dist/assets/OnboardingScreen-C98d69Fp.js +0 -1
- package/dist/assets/SettingsView-D-K3ELCM.js +0 -28
- package/dist/assets/ToolPartDiffPreview-C7kBQNAA.js +0 -8
- package/dist/assets/WalkthroughView-MuJodAHD.js +0 -4
- package/dist/assets/es-DwyXCqaL.js +0 -15
- package/dist/assets/index-CUKcHnUA.css +0 -1
- package/dist/assets/index-DIvDEKE-.js +0 -7
- package/dist/assets/main-DLlfDjQ_.js +0 -926
- package/dist/assets/markdownCore-CcTcLsQF.js +0 -3
- package/dist/assets/pt-BR-DxLmkhdv.js +0 -15
- package/dist/assets/renderMobileApp-ltva2Plg.js +0 -25
- package/dist/assets/runtimeEndpointReset-D6SmNZaP.js +0 -15
- package/dist/assets/scheduledTasksApi-mjMDet_H.js +0 -1
- package/dist/assets/tr-5Mk_hQ2Q.js +0 -6
- package/dist/assets/uk-ClgQjmlw.js +0 -15
- package/dist/assets/useInlineCommentController-HIjtuhxD.js +0 -2
- package/dist/assets/useRootScrollLock-BSiQ5F75.js +0 -1
- package/dist/assets/vendor-zod-BLfBSgBh.js +0 -39
- package/dist/assets/zh-CN-Ba6y8H-i.js +0 -15
|
@@ -2,8 +2,10 @@ import express from 'express';
|
|
|
2
2
|
import { deleteManagedCredential, getManagedCredentialStatus, normalizers, readManagedCredential, writeManagedCredential } from './credentials/providers.js';
|
|
3
3
|
import { fetchOllamaCloudUsage } from './providers/ollama-cloud.js';
|
|
4
4
|
import { importCursorCredential, validateCursorCredential } from './providers/cursor.js';
|
|
5
|
+
import { fetchExeDevUsage } from './providers/exe-dev.js';
|
|
5
6
|
|
|
6
7
|
const validators = {
|
|
8
|
+
'exe-dev': fetchExeDevUsage,
|
|
7
9
|
'ollama-cloud': fetchOllamaCloudUsage,
|
|
8
10
|
cursor: validateCursorCredential,
|
|
9
11
|
};
|
|
@@ -41,7 +41,7 @@ Relay is not a separate link format: it is one transport candidate inside the un
|
|
|
41
41
|
Everything a client normally sends to the single OpenChamber origin:
|
|
42
42
|
- **HTTP** — REST endpoints and proxied OpenCode SDK calls under `/api/*`, plus `/auth/*` and `/health`.
|
|
43
43
|
- **SSE** — long-lived streamed responses (the event stream and notifications). These are just HTTP responses whose body streams; the tunnel needs no special SSE handling.
|
|
44
|
-
- **WebSocket** — the endpoints that use a real socket (the global event stream on platforms that support WS, terminal I/O, dictation).
|
|
44
|
+
- **WebSocket** — the endpoints that use a real socket (the global event stream on platforms that support WS, terminal I/O, dictation, and desktop dev-server previews).
|
|
45
45
|
|
|
46
46
|
The host dispatcher restricts tunneled traffic to explicit path allowlists (one for HTTP, one for WS).
|
|
47
47
|
|
|
@@ -33,7 +33,9 @@ const ALLOWED_WS_PATHS = new Set([
|
|
|
33
33
|
'/api/event/ws',
|
|
34
34
|
'/api/terminal/ws',
|
|
35
35
|
'/api/dictation/ws',
|
|
36
|
+
'/api/dev-tunnel',
|
|
36
37
|
]);
|
|
38
|
+
export const isAllowedRelayWebSocketPath = (pathname) => ALLOWED_WS_PATHS.has(pathname);
|
|
37
39
|
|
|
38
40
|
// Hop-by-hop headers stripped from tunneled requests; `host` is set by fetch
|
|
39
41
|
// to the loopback origin. content-length is dropped too because the body is
|
|
@@ -425,7 +427,7 @@ export const createTunnelHost = ({ connectionId, getLocalPort, sendFrame, getBuf
|
|
|
425
427
|
void sendAbort(streamId, error?.message ?? 'malformed ws open');
|
|
426
428
|
return;
|
|
427
429
|
}
|
|
428
|
-
if (!
|
|
430
|
+
if (!isAllowedRelayWebSocketPath(open.path)) {
|
|
429
431
|
void sendAbort(streamId, 'Path is not allowed through the relay');
|
|
430
432
|
return;
|
|
431
433
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, test, expect } from 'bun:test';
|
|
2
2
|
import http from 'node:http';
|
|
3
3
|
|
|
4
|
-
import { createTunnelHost } from './tunnel-host.js';
|
|
4
|
+
import { createTunnelHost, isAllowedRelayWebSocketPath } from './tunnel-host.js';
|
|
5
5
|
import { decodeTunnelFrame, encodeTunnelFrame, encodeJsonPayload, TunnelFrameType } from './tunnel-codec.js';
|
|
6
6
|
|
|
7
7
|
const startLoopback = () =>
|
|
@@ -145,3 +145,11 @@ describe('tunnel-host HTTP body forwarding', () => {
|
|
|
145
145
|
await loopback.stop();
|
|
146
146
|
});
|
|
147
147
|
});
|
|
148
|
+
|
|
149
|
+
describe('relay host WebSocket allowlist', () => {
|
|
150
|
+
test('allows only the exact dev-server tunnel path', () => {
|
|
151
|
+
expect(isAllowedRelayWebSocketPath('/api/dev-tunnel')).toBe(true);
|
|
152
|
+
expect(isAllowedRelayWebSocketPath('/api/dev-tunnel/')).toBe(false);
|
|
153
|
+
expect(isAllowedRelayWebSocketPath('/api/database/ws')).toBe(false);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
@@ -25,6 +25,13 @@ in shared project config under the project write lock:
|
|
|
25
25
|
from the winner's persisted `nextRunAt`.
|
|
26
26
|
- Project config writes also take a cross-process `.json.lock` file so the
|
|
27
27
|
read-modify-write is serialized across processes, not only within one process.
|
|
28
|
+
- The sharing processes may run different OpenChamber versions. Normalization
|
|
29
|
+
keeps only the fields a build knows, so every writer persists tasks it did
|
|
30
|
+
not change verbatim from disk and swaps only `state` onto a task whose state
|
|
31
|
+
it updated; a task goes out normalized only when it was deliberately
|
|
32
|
+
replaced (upsert, loop adoption). An older server touching the file after a
|
|
33
|
+
run therefore cannot strip fields a newer build added, such as a task's goal
|
|
34
|
+
or auto-accept settings.
|
|
28
35
|
- Lock timeout / filesystem errors on claim, manual-start, or completion state
|
|
29
36
|
writes always release the in-process running slot (via `finally`) and best-effort
|
|
30
37
|
re-arm the **next future** occurrence; they must not leave the task permanently
|
|
@@ -67,6 +67,7 @@ export const createRequestSecurityRuntime = (deps) => {
|
|
|
67
67
|
|
|
68
68
|
const getRequestOriginCandidates = async (req) => {
|
|
69
69
|
const origins = new Set();
|
|
70
|
+
const hosts = new Set();
|
|
70
71
|
const forwardedProto = typeof req.headers['x-forwarded-proto'] === 'string'
|
|
71
72
|
? req.headers['x-forwarded-proto'].split(',')[0].trim().toLowerCase()
|
|
72
73
|
: '';
|
|
@@ -78,6 +79,7 @@ export const createRequestSecurityRuntime = (deps) => {
|
|
|
78
79
|
const host = forwardedHost || (typeof req.headers.host === 'string' ? req.headers.host.trim() : '');
|
|
79
80
|
|
|
80
81
|
if (host) {
|
|
82
|
+
hosts.add(host.toLowerCase());
|
|
81
83
|
origins.add(`${protocol}://${host}`);
|
|
82
84
|
const [hostname, port] = host.split(':');
|
|
83
85
|
const normalizedHost = typeof hostname === 'string' ? hostname.toLowerCase() : '';
|
|
@@ -98,10 +100,10 @@ export const createRequestSecurityRuntime = (deps) => {
|
|
|
98
100
|
} catch {
|
|
99
101
|
}
|
|
100
102
|
|
|
101
|
-
return origins;
|
|
103
|
+
return { origins, hosts };
|
|
102
104
|
};
|
|
103
105
|
|
|
104
|
-
const isRequestOriginAllowed =
|
|
106
|
+
const isRequestOriginAllowed = (req) => {
|
|
105
107
|
const originHeader = typeof req.headers.origin === 'string' ? req.headers.origin.trim() : '';
|
|
106
108
|
if (!originHeader) {
|
|
107
109
|
return false;
|
|
@@ -111,15 +113,28 @@ export const createRequestSecurityRuntime = (deps) => {
|
|
|
111
113
|
return true;
|
|
112
114
|
}
|
|
113
115
|
|
|
114
|
-
let
|
|
116
|
+
let origin;
|
|
115
117
|
try {
|
|
116
|
-
|
|
118
|
+
origin = new URL(originHeader);
|
|
117
119
|
} catch {
|
|
118
120
|
return false;
|
|
119
121
|
}
|
|
120
122
|
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
+
const forwardedHostHeader = req.headers['x-forwarded-host'];
|
|
124
|
+
const forwardedHost = (Array.isArray(forwardedHostHeader) ? forwardedHostHeader[0] : forwardedHostHeader || '')
|
|
125
|
+
.split(',')[0].trim().toLowerCase();
|
|
126
|
+
const hostHeader = req.headers.host;
|
|
127
|
+
const host = forwardedHost || (Array.isArray(hostHeader) ? hostHeader[0] : hostHeader || '').trim().toLowerCase();
|
|
128
|
+
if (host && host === origin.host.toLowerCase()) return true;
|
|
129
|
+
|
|
130
|
+
// TLS commonly ends at a cloud edge before an HTTP hop to OpenChamber.
|
|
131
|
+
// In that setup the browser's Origin is https while a generic reverse
|
|
132
|
+
// proxy reports the upstream request as http. The external host remains
|
|
133
|
+
// authoritative, so compare it directly instead of requiring the proxy to
|
|
134
|
+
// preserve the browser-facing protocol.
|
|
135
|
+
return getRequestOriginCandidates(req).then((candidates) => (
|
|
136
|
+
candidates.origins.has(origin.origin) || candidates.hosts.has(origin.host.toLowerCase())
|
|
137
|
+
));
|
|
123
138
|
};
|
|
124
139
|
|
|
125
140
|
return {
|
|
@@ -9,41 +9,75 @@ describe('request security runtime', () => {
|
|
|
9
9
|
test('allows packaged client origins for remote client transports', async () => {
|
|
10
10
|
const runtime = createRuntime();
|
|
11
11
|
|
|
12
|
-
await
|
|
12
|
+
expect(await runtime.isRequestOriginAllowed({
|
|
13
13
|
headers: {
|
|
14
14
|
origin: 'openchamber-ui://app',
|
|
15
15
|
host: '192.168.1.130:1202',
|
|
16
16
|
},
|
|
17
17
|
socket: {},
|
|
18
|
-
})).
|
|
18
|
+
})).toBe(true);
|
|
19
19
|
|
|
20
|
-
await
|
|
20
|
+
expect(await runtime.isRequestOriginAllowed({
|
|
21
21
|
headers: {
|
|
22
22
|
origin: 'capacitor://localhost',
|
|
23
23
|
host: '192.168.1.130:1202',
|
|
24
24
|
},
|
|
25
25
|
socket: {},
|
|
26
|
-
})).
|
|
26
|
+
})).toBe(true);
|
|
27
27
|
|
|
28
28
|
// Android Capacitor WebView (androidScheme 'https') reports this origin.
|
|
29
|
-
await
|
|
29
|
+
expect(await runtime.isRequestOriginAllowed({
|
|
30
30
|
headers: {
|
|
31
31
|
origin: 'https://localhost',
|
|
32
32
|
host: '192.168.1.130:1202',
|
|
33
33
|
},
|
|
34
34
|
socket: {},
|
|
35
|
-
})).
|
|
35
|
+
})).toBe(true);
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
test('rejects unknown origins', async () => {
|
|
39
39
|
const runtime = createRuntime();
|
|
40
40
|
|
|
41
|
-
await
|
|
41
|
+
expect(await runtime.isRequestOriginAllowed({
|
|
42
42
|
headers: {
|
|
43
43
|
origin: 'https://evil.example.com',
|
|
44
44
|
host: '192.168.1.130:1202',
|
|
45
45
|
},
|
|
46
46
|
socket: {},
|
|
47
|
-
})).
|
|
47
|
+
})).toBe(false);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('allows the external host when TLS terminates before an HTTP proxy hop', async () => {
|
|
51
|
+
const runtime = createRuntime();
|
|
52
|
+
|
|
53
|
+
expect(await runtime.isRequestOriginAllowed({
|
|
54
|
+
headers: {
|
|
55
|
+
origin: 'https://devchamber.example.com',
|
|
56
|
+
host: 'devchamber.example.com',
|
|
57
|
+
'x-forwarded-proto': 'http',
|
|
58
|
+
},
|
|
59
|
+
socket: {},
|
|
60
|
+
})).toBe(true);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('uses the forwarded external host without trusting a different origin', async () => {
|
|
64
|
+
const runtime = createRuntime();
|
|
65
|
+
const request = {
|
|
66
|
+
headers: {
|
|
67
|
+
host: '127.0.0.1:3000',
|
|
68
|
+
'x-forwarded-host': 'devchamber.example.com',
|
|
69
|
+
'x-forwarded-proto': 'http',
|
|
70
|
+
},
|
|
71
|
+
socket: {},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
expect(await runtime.isRequestOriginAllowed({
|
|
75
|
+
...request,
|
|
76
|
+
headers: { ...request.headers, origin: 'https://devchamber.example.com' },
|
|
77
|
+
})).toBe(true);
|
|
78
|
+
expect(await runtime.isRequestOriginAllowed({
|
|
79
|
+
...request,
|
|
80
|
+
headers: { ...request.headers, origin: 'https://evil.example.com' },
|
|
81
|
+
})).toBe(false);
|
|
48
82
|
});
|
|
49
83
|
});
|
|
@@ -257,6 +257,7 @@ export const createSessionAssistRuntime = ({
|
|
|
257
257
|
prompt: `The latest exchange in the conversation:\n\n${transcript}\n\nWrite ${requestedFields} in the SAME language as this sample from the conversation: "${languageSample}"`,
|
|
258
258
|
system: buildAssistSystemPrompt(targets),
|
|
259
259
|
directory,
|
|
260
|
+
sessionID: sessionId,
|
|
260
261
|
preferredProviderID: typeof lastAssistantInfo.providerID === 'string' ? lastAssistantInfo.providerID : undefined,
|
|
261
262
|
preferredModelID: typeof lastAssistantInfo.modelID === 'string' ? lastAssistantInfo.modelID : undefined,
|
|
262
263
|
});
|
|
@@ -14,7 +14,7 @@ export const buildGoalIntroText = (tokenBudget) => {
|
|
|
14
14
|
+ '\n</system-reminder>';
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
const fitObjective = async ({ objective, directory, providerID, modelID, warn }) => {
|
|
17
|
+
const fitObjective = async ({ objective, directory, sessionID, providerID, modelID, warn }) => {
|
|
18
18
|
if (objective.length <= GOAL_OBJECTIVE_CHAR_LIMIT) return objective;
|
|
19
19
|
|
|
20
20
|
let distilled = null;
|
|
@@ -32,6 +32,7 @@ const fitObjective = async ({ objective, directory, providerID, modelID, warn })
|
|
|
32
32
|
'Write in the same language as the task text.',
|
|
33
33
|
].join('\n'),
|
|
34
34
|
directory,
|
|
35
|
+
sessionID,
|
|
35
36
|
preferredProviderID: providerID,
|
|
36
37
|
preferredModelID: modelID,
|
|
37
38
|
});
|
|
@@ -66,6 +67,7 @@ export const createSessionGoal = async ({
|
|
|
66
67
|
const objectiveText = await fitObjective({
|
|
67
68
|
objective: String(objective ?? '').trim(),
|
|
68
69
|
directory,
|
|
70
|
+
sessionID,
|
|
69
71
|
providerID,
|
|
70
72
|
modelID,
|
|
71
73
|
warn,
|
|
@@ -378,6 +378,7 @@ export const createSessionGoalRuntime = ({
|
|
|
378
378
|
prompt: `The goal objective:\n\n<objective>\n${goal.objective}\n</objective>\n\nThe agent's latest turn:\n\n${assistantText}\n\nReturn the verdict JSON. Write the note in the SAME language as this sample from the objective: "${goal.objective.slice(0, 200).replace(/\s+/g, ' ').trim()}"`,
|
|
379
379
|
system: buildAuditSystemPrompt(),
|
|
380
380
|
directory,
|
|
381
|
+
sessionID: typeof lastAssistantInfo?.sessionID === 'string' ? lastAssistantInfo.sessionID : undefined,
|
|
381
382
|
preferredProviderID: typeof lastAssistantInfo?.providerID === 'string' ? lastAssistantInfo.providerID : undefined,
|
|
382
383
|
preferredModelID: typeof lastAssistantInfo?.modelID === 'string' ? lastAssistantInfo.modelID : undefined,
|
|
383
384
|
});
|
|
@@ -91,6 +91,10 @@ other runtime API.
|
|
|
91
91
|
a blocker instead of a raw 500 message.
|
|
92
92
|
- `call.js` — wire formats and per-provider auth, replicating OpenCode's
|
|
93
93
|
plugin auth loaders:
|
|
94
|
+
- OpenCode-hosted providers receive `x-opencode-session`. Session-backed
|
|
95
|
+
features reuse the real OpenCode session id, walkthrough retries reuse the
|
|
96
|
+
walkthrough cache key, and standalone one-shot actions receive a fresh
|
|
97
|
+
opaque id for that generation.
|
|
94
98
|
- **GitHub Copilot**: fetches the requested model's authenticated `/models`
|
|
95
99
|
metadata from `https://api.githubcopilot.com` (or
|
|
96
100
|
`copilot-api.<enterprise>`) and honors its advertised endpoint, preferring
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import os from 'os';
|
|
3
3
|
import path from 'path';
|
|
4
|
+
import { randomUUID } from 'node:crypto';
|
|
4
5
|
import { readAuthFile, writeAuthFile } from '../opencode/auth.js';
|
|
5
6
|
import { readConfig, readConfigLayers, isPlainObject } from '../opencode/shared.js';
|
|
6
7
|
import { getCatalogProvider } from './catalog.js';
|
|
@@ -645,7 +646,7 @@ export async function resolveProviderLogin({ auth, workingDirectory, providerID
|
|
|
645
646
|
|| null;
|
|
646
647
|
}
|
|
647
648
|
|
|
648
|
-
export async function callSmallModel({ auth, catalog, workingDirectory, providerID, modelID, prompt, system, maxOutputTokens, responseSchema, timeoutMs, signal }) {
|
|
649
|
+
export async function callSmallModel({ auth, catalog, workingDirectory, sessionID, providerID, modelID, prompt, system, maxOutputTokens, responseSchema, timeoutMs, signal }) {
|
|
649
650
|
const tokens = Number(maxOutputTokens) > 0 ? Number(maxOutputTokens) : DEFAULT_MAX_OUTPUT_TOKENS;
|
|
650
651
|
const providerConfig = readProviderConfig(workingDirectory, providerID);
|
|
651
652
|
const runtimeProvider = await getRuntimeProvider(providerID);
|
|
@@ -795,7 +796,12 @@ export async function callSmallModel({ auth, catalog, workingDirectory, provider
|
|
|
795
796
|
baseURL,
|
|
796
797
|
// Configured headers last: a gateway that authenticates on its own header
|
|
797
798
|
// must be able to override the bearer default rather than sit beside it.
|
|
798
|
-
headers: mergeHeadersCaseInsensitive(
|
|
799
|
+
headers: mergeHeadersCaseInsensitive(
|
|
800
|
+
mergeHeadersCaseInsensitive({ Authorization: `Bearer ${apiKey}` }, providerConfig?.headers),
|
|
801
|
+
providerID.startsWith('opencode')
|
|
802
|
+
? { 'x-opencode-session': typeof sessionID === 'string' && sessionID.trim() ? sessionID.trim() : randomUUID() }
|
|
803
|
+
: null,
|
|
804
|
+
),
|
|
799
805
|
modelID,
|
|
800
806
|
prompt,
|
|
801
807
|
system,
|
|
@@ -483,6 +483,29 @@ describe('callSmallModel — custom provider config', () => {
|
|
|
483
483
|
});
|
|
484
484
|
|
|
485
485
|
describe('catalog-based base URL (no config override)', () => {
|
|
486
|
+
it('identifies OpenCode Go requests with the owning conversation', async () => {
|
|
487
|
+
readConfig.mockReturnValue({});
|
|
488
|
+
fetchMock.mockResolvedValue(ok('ok'));
|
|
489
|
+
|
|
490
|
+
await callSmallModel({
|
|
491
|
+
auth: { 'opencode-go': { type: 'api', key: 'go-key' } },
|
|
492
|
+
catalog: {
|
|
493
|
+
'opencode-go': {
|
|
494
|
+
id: 'opencode-go',
|
|
495
|
+
api: 'https://opencode.ai/zen/go/v1',
|
|
496
|
+
models: { utility: { id: 'utility' } },
|
|
497
|
+
},
|
|
498
|
+
},
|
|
499
|
+
workingDirectory: '/proj',
|
|
500
|
+
sessionID: 'ses_conversation',
|
|
501
|
+
providerID: 'opencode-go',
|
|
502
|
+
modelID: 'utility',
|
|
503
|
+
prompt: 'hi',
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
expect(lastCall(fetchMock).init.headers['x-opencode-session']).toBe('ses_conversation');
|
|
507
|
+
});
|
|
508
|
+
|
|
486
509
|
it('uses the catalog api field when no config baseURL is set', async () => {
|
|
487
510
|
readConfig.mockReturnValue({});
|
|
488
511
|
fetchMock.mockResolvedValue(ok('ok'));
|
|
@@ -102,7 +102,7 @@ const readConfiguredSmallModel = (workingDirectory) => {
|
|
|
102
102
|
* Generates text with the user's small model, resolved and authenticated
|
|
103
103
|
* entirely server-side from the OpenCode config and auth store.
|
|
104
104
|
*/
|
|
105
|
-
export async function generateSmallModelText({ prompt, system, maxOutputTokens, model, directory, preferredProviderID, preferredModelID, restrictToPreferredProvider = false, responseSchema, timeoutMs, signal, onOverflow = 'truncate' }) {
|
|
105
|
+
export async function generateSmallModelText({ prompt, system, maxOutputTokens, model, directory, sessionID, preferredProviderID, preferredModelID, restrictToPreferredProvider = false, responseSchema, timeoutMs, signal, onOverflow = 'truncate' }) {
|
|
106
106
|
if (typeof prompt !== 'string' || !prompt.trim()) {
|
|
107
107
|
throw Object.assign(new Error('prompt is required'), { statusCode: 400 });
|
|
108
108
|
}
|
|
@@ -169,6 +169,7 @@ export async function generateSmallModelText({ prompt, system, maxOutputTokens,
|
|
|
169
169
|
auth,
|
|
170
170
|
catalog,
|
|
171
171
|
workingDirectory: directory,
|
|
172
|
+
sessionID,
|
|
172
173
|
providerID: resolved.providerID,
|
|
173
174
|
modelID: resolved.modelID,
|
|
174
175
|
prompt: clamped.prompt,
|
|
@@ -21,13 +21,14 @@ export function registerSmallModelRoutes(app, { getSmallModelService }) {
|
|
|
21
21
|
app.post('/api/small-model/generate', async (req, res) => {
|
|
22
22
|
try {
|
|
23
23
|
const { generateSmallModelText } = await getSmallModelService();
|
|
24
|
-
const { prompt, system, maxOutputTokens, model, directory, preferredProviderID, preferredModelID, restrictToPreferredProvider } = req.body || {};
|
|
24
|
+
const { prompt, system, maxOutputTokens, model, directory, sessionID, preferredProviderID, preferredModelID, restrictToPreferredProvider } = req.body || {};
|
|
25
25
|
const result = await generateSmallModelText({
|
|
26
26
|
prompt,
|
|
27
27
|
system,
|
|
28
28
|
maxOutputTokens,
|
|
29
29
|
model,
|
|
30
30
|
directory,
|
|
31
|
+
sessionID,
|
|
31
32
|
preferredProviderID,
|
|
32
33
|
preferredModelID,
|
|
33
34
|
restrictToPreferredProvider: restrictToPreferredProvider === true,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { parse as parseJsonc } from 'jsonc-parser';
|
|
2
1
|
import { pathToFileURL } from 'node:url';
|
|
2
|
+
import { appendManagedPlugin } from '../opencode/managed-plugin-config.js';
|
|
3
3
|
|
|
4
4
|
const PROVIDER_PROMPT_BOUNDARY = 'You are powered by the model named';
|
|
5
5
|
const MINIMAL_IDENTITY = 'You are OpenCode, a coding agent.';
|
|
@@ -33,25 +33,6 @@ export const OpenChamberSystemPromptPlugin = async () => ({
|
|
|
33
33
|
})
|
|
34
34
|
`;
|
|
35
35
|
|
|
36
|
-
const mergePluginConfig = (rawConfig, pluginUrl) => {
|
|
37
|
-
const errors = [];
|
|
38
|
-
const parsed = typeof rawConfig === 'string' && rawConfig.trim()
|
|
39
|
-
? parseJsonc(rawConfig, errors, { allowTrailingComma: true })
|
|
40
|
-
: {};
|
|
41
|
-
if (errors.length > 0 || !parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
42
|
-
throw new Error('OPENCODE_CONFIG_CONTENT must contain a valid JSON object before OpenChamber can inject its system prompt optimizer');
|
|
43
|
-
}
|
|
44
|
-
if (parsed.plugin !== undefined && !Array.isArray(parsed.plugin)) {
|
|
45
|
-
throw new Error('OPENCODE_CONFIG_CONTENT plugin must be an array before OpenChamber can inject its system prompt optimizer');
|
|
46
|
-
}
|
|
47
|
-
const configured = Array.isArray(parsed.plugin) ? parsed.plugin : [];
|
|
48
|
-
parsed.plugin = [
|
|
49
|
-
...configured.filter((value) => value !== pluginUrl && (!Array.isArray(value) || value[0] !== pluginUrl)),
|
|
50
|
-
pluginUrl,
|
|
51
|
-
];
|
|
52
|
-
return JSON.stringify(parsed);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
36
|
export const createSystemPromptRuntime = ({ fsPromises, path, dataDir }) => {
|
|
56
37
|
const pluginDirectory = path.join(dataDir, 'system-prompt');
|
|
57
38
|
const pluginPath = path.join(pluginDirectory, 'openchamber-system-prompt-plugin.js');
|
|
@@ -60,7 +41,7 @@ export const createSystemPromptRuntime = ({ fsPromises, path, dataDir }) => {
|
|
|
60
41
|
await fsPromises.mkdir(pluginDirectory, { recursive: true });
|
|
61
42
|
await fsPromises.writeFile(pluginPath, createPluginSource(), { mode: 0o600 });
|
|
62
43
|
return {
|
|
63
|
-
OPENCODE_CONFIG_CONTENT:
|
|
44
|
+
OPENCODE_CONFIG_CONTENT: appendManagedPlugin(rawConfig, pathToFileURL(pluginPath).href, 'system prompt optimizer'),
|
|
64
45
|
};
|
|
65
46
|
};
|
|
66
47
|
|
|
@@ -276,16 +276,39 @@ export function createTerminalRuntime({
|
|
|
276
276
|
|
|
277
277
|
const upgradeHandler = (req, socket, head) => {
|
|
278
278
|
if (parseRequestPathname(req.url) !== TERMINAL_WS_PATH) return;
|
|
279
|
-
|
|
279
|
+
const accept = () => {
|
|
280
|
+
if (!wsServer) { rejectWebSocketUpgrade(socket, 500, 'Terminal WebSocket unavailable'); return; }
|
|
280
281
|
try {
|
|
281
|
-
if (uiAuthController?.enabled) {
|
|
282
|
-
if (!await uiAuthController.ensureSessionToken(req, null)) { rejectWebSocketUpgrade(socket, 401, 'UI authentication required'); return; }
|
|
283
|
-
if (!await isRequestOriginAllowed(req)) { rejectWebSocketUpgrade(socket, 403, 'Invalid origin'); return; }
|
|
284
|
-
}
|
|
285
|
-
if (!wsServer) { rejectWebSocketUpgrade(socket, 500, 'Terminal WebSocket unavailable'); return; }
|
|
286
282
|
wsServer.handleUpgrade(req, socket, head, (ws) => wsServer.emit('connection', ws, req));
|
|
287
283
|
} catch { rejectWebSocketUpgrade(socket, 500, 'Upgrade failed'); }
|
|
288
|
-
}
|
|
284
|
+
};
|
|
285
|
+
const checkOrigin = () => {
|
|
286
|
+
try {
|
|
287
|
+
const result = isRequestOriginAllowed(req);
|
|
288
|
+
if (!(result instanceof Promise)) {
|
|
289
|
+
if (result) accept();
|
|
290
|
+
else rejectWebSocketUpgrade(socket, 403, 'Invalid origin');
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
void result.then((allowed) => {
|
|
294
|
+
if (allowed) accept();
|
|
295
|
+
else rejectWebSocketUpgrade(socket, 403, 'Invalid origin');
|
|
296
|
+
}).catch(() => rejectWebSocketUpgrade(socket, 500, 'Upgrade failed'));
|
|
297
|
+
} catch { rejectWebSocketUpgrade(socket, 500, 'Upgrade failed'); }
|
|
298
|
+
};
|
|
299
|
+
if (!uiAuthController?.enabled) { accept(); return; }
|
|
300
|
+
try {
|
|
301
|
+
const result = uiAuthController.ensureSessionToken(req, null);
|
|
302
|
+
if (!(result instanceof Promise)) {
|
|
303
|
+
if (result) checkOrigin();
|
|
304
|
+
else rejectWebSocketUpgrade(socket, 401, 'UI authentication required');
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
void result.then((sessionToken) => {
|
|
308
|
+
if (sessionToken) checkOrigin();
|
|
309
|
+
else rejectWebSocketUpgrade(socket, 401, 'UI authentication required');
|
|
310
|
+
}).catch(() => rejectWebSocketUpgrade(socket, 500, 'Upgrade failed'));
|
|
311
|
+
} catch { rejectWebSocketUpgrade(socket, 500, 'Upgrade failed'); }
|
|
289
312
|
};
|
|
290
313
|
server.on('upgrade', upgradeHandler);
|
|
291
314
|
|
|
@@ -11,6 +11,7 @@ This module provides server-side Text-to-Speech services using OpenAI's TTS API.
|
|
|
11
11
|
- `packages/web/server/lib/text/summarization.js`: Shared text summarization stub and sanitization utilities. It performs no external Zen calls.
|
|
12
12
|
- `packages/web/server/lib/tts/stt.js`: STT proxy for OpenAI-compatible transcription endpoints.
|
|
13
13
|
- `packages/web/server/lib/tts/base-url.js`: shared base URL validation and normalization for custom OpenAI-compatible endpoints.
|
|
14
|
+
- `packages/web/server/lib/tts/language-detect.js`: dependency-free language detection for voice selection (`detectTextLanguage`, `pickVoiceForLanguage`, `languageOfLocale`). Used by the macOS `say` route (`language: 'auto'` switches to an installed voice whose locale matches the text; the response carries `X-Speech-Voice` and `X-Speech-Language`) and by the dictation module's local TTS model choice.
|
|
14
15
|
|
|
15
16
|
## Public exports
|
|
16
17
|
|