@openchamber/web 2.0.0 → 2.0.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-hJbl3JX4.js → CodeMirrorCommentWidgets-zm3C1FvM.js} +1 -1
- package/dist/assets/DiffView-DNExNi1z.js +4 -0
- package/dist/assets/FilesView-DUCLmHBi.js +17 -0
- package/dist/assets/{GitView-DY4pelsO.js → GitView-Bz9z6gZA.js} +4 -4
- package/dist/assets/{GuestAttachDialog-D6mHDTB2.js → GuestAttachDialog-UGp4KDlK.js} +1 -1
- package/dist/assets/GuestSurfacePane-B3pdB_2u.js +1 -0
- package/dist/assets/{JsonTreeView-DEXI2NvJ.js → JsonTreeView-7lVecnZl.js} +1 -1
- package/dist/assets/{LinearIssuesView-BTNc-4dN.js → LinearIssuesView-CTGRS9Vq.js} +1 -1
- package/dist/assets/{MarkdownImageGallery-wcUUcf8l.js → MarkdownImageGallery-DQk5adUs.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-DPF8fZpX.js +12 -0
- package/dist/assets/{OnboardingScreen-FJUreEgI.js → OnboardingScreen-CBx6cXPP.js} +1 -1
- package/dist/assets/{PatchDiff-C0oOkKnO.js → PatchDiff-D7VVpR_l.js} +1 -1
- package/dist/assets/{PierreDiffViewer-asuSQAsf.js → PierreDiffViewer-Gbfks1pk.js} +3 -3
- package/dist/assets/{PlanView-DGbasNHP.js → PlanView-CPSK0x97.js} +4 -4
- package/dist/assets/PluginPane-BIGsUx69.js +3 -0
- package/dist/assets/SettingsView-Dql7z6Ww.js +30 -0
- package/dist/assets/{SettingsWindow-By4cqnqy.js → SettingsWindow-D6oi-UmV.js} +1 -1
- package/dist/assets/{SubmoduleDiffSummary-C0P2tXLU.js → SubmoduleDiffSummary-BXA0FAWj.js} +1 -1
- package/dist/assets/{ToolOutputDialog-Cayc-yIM.js → ToolOutputDialog-BQJsSbDm.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-B0jmpPQz.js → ToolPartDiffPreview-FY9w0TVT.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-DsOpvWZD.js → VirtualizedFileDiff-B9YhAya5.js} +1 -1
- package/dist/assets/{WalkthroughView-CCakjyn9.js → WalkthroughView-CmFgOUFN.js} +2 -2
- package/dist/assets/{appThemeRegistry-Bw5oTm41.js → appThemeRegistry-BebxalUt.js} +1 -1
- package/dist/assets/changesTree-CePHbFcj.js +1 -0
- package/dist/assets/commitAndPush-Wfxng_IK.js +1 -0
- package/dist/assets/{computeVirtualFileMetrics-B-4aLf4A.js → computeVirtualFileMetrics-BCOqgixN.js} +2 -2
- package/dist/assets/de-CMA45TC-.js +10 -0
- package/dist/assets/es-DPL4fBtl.js +16 -0
- package/dist/assets/fr-OHBKBseP.js +14 -0
- package/dist/assets/{index-B6r0Kv-B.js → index-3TiDNtfN.js} +1 -1
- package/dist/assets/index-BLUZa5u0.js +41 -0
- package/dist/assets/index-Cm2rrq69.css +1 -0
- package/dist/assets/{isDiffPlainText-Ok-kgtJA.js → isDiffPlainText-DnDYQmWK.js} +1 -1
- package/dist/assets/{isFilePlainText-0dLnkYm8.js → isFilePlainText-BA_AHX7d.js} +1 -1
- package/dist/assets/ja-DvX4WSRf.js +16 -0
- package/dist/assets/ko-BUcLd8YZ.js +16 -0
- package/dist/assets/main-B_jri4i-.js +896 -0
- package/dist/assets/{main-CjXBM_Xe.js → main-DtUmJp9B.js} +2 -2
- package/dist/assets/{markdown-shiki.worker-CahLvHIq.js → markdown-shiki.worker-Bg8SoAJJ.js} +8 -5
- package/dist/assets/markdownCore-BSnlUXBf.js +7 -0
- package/dist/assets/{miniChat-DZ3OAeLN.js → miniChat-BYfLUnDK.js} +2 -2
- package/dist/assets/{mobile-CH0LOIF-.js → mobile-DH3hI6gd.js} +2 -2
- package/dist/assets/patchFileDiff--L7lt_GZ.js +13 -0
- package/dist/assets/pl-BkI_xHqz.js +16 -0
- package/dist/assets/pt-BR-7wFtQlV9.js +16 -0
- package/dist/assets/{renderElectronMiniChatApp-CB1uLYvh.js → renderElectronMiniChatApp-C7kpNW_-.js} +2 -2
- package/dist/assets/renderMobileApp-i0nq7Dwy.js +25 -0
- package/dist/assets/runtimeEndpointReset-CfEYbcCc.js +27 -0
- package/dist/assets/scheduledTasksApi-Cy7uZCaI.js +1 -0
- package/dist/assets/{shikiHighlight-CocY80VR.js → shikiHighlight-D4vxipfr.js} +1 -1
- package/dist/assets/{textMateThemeFromAppTheme-CF77r8FA.js → textMateThemeFromAppTheme-BYAHtJwQ.js} +1 -1
- package/dist/assets/tr-TsD-AqEH.js +7 -0
- package/dist/assets/uk-B-qspCmD.js +16 -0
- package/dist/assets/{useAppFontEffects-Dc5nTHi8.js → useAppFontEffects-DHZ9-L30.js} +158 -157
- package/dist/assets/{useInlineCommentController-Dbza5c8l.js → useInlineCommentController-CvpOMK-R.js} +2 -2
- package/dist/assets/{useRootScrollLock-CSCLv396.js → useRootScrollLock-DzNFi-fn.js} +2 -2
- package/dist/assets/{vendor-codemirror-language-data-CkmYWcRI.js → vendor-codemirror-language-data-j3fhlwUM.js} +2 -2
- package/dist/assets/{vendor-opencode-client-_BAHQo4R.js → vendor-opencode-client-DYdsLbCM.js} +2 -2
- package/dist/assets/vendor-zod-BSoePkpP.js +39 -0
- package/dist/assets/{web-components-nsStrYq9.js → web-components-BvHNFSEG.js} +1 -1
- package/dist/assets/zh-CN-DYuPJV5i.js +16 -0
- package/dist/assets/zh-TW-BX_2D_lV.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 +4 -4
- package/server/index.js +18 -0
- package/server/lib/agent-tool/DOCUMENTATION.md +5 -0
- package/server/lib/agent-tool/runtime.js +34 -6
- package/server/lib/agent-tool/runtime.test.js +15 -0
- package/server/lib/browser-control/DOCUMENTATION.md +14 -2
- package/server/lib/git/DOCUMENTATION.md +1 -1
- package/server/lib/git/service.js +22 -0
- package/server/lib/git/service.test.js +8 -0
- package/server/lib/guests/DOCUMENTATION.md +4 -3
- package/server/lib/guests/catalog.js +19 -1
- package/server/lib/guests/catalog.test.js +22 -0
- package/server/lib/guests/html-styles.js +5 -3
- package/server/lib/guests/html-styles.test.js +3 -1
- package/server/lib/guests/routes.js +11 -3
- package/server/lib/guests/service.js +5 -0
- package/server/lib/guests/surface.js +55 -9
- package/server/lib/guests/surface.test.js +56 -6
- package/server/lib/notifications/DOCUMENTATION.md +10 -0
- package/server/lib/notifications/emit-route.js +118 -0
- package/server/lib/notifications/emit-route.test.js +112 -0
- package/server/lib/openchamber-control/actions.js +16 -2
- package/server/lib/openchamber-control/service.js +23 -0
- package/server/lib/openchamber-control/service.test.js +31 -0
- package/server/lib/openchamber-sessions/fork-inheritance.js +103 -0
- package/server/lib/openchamber-sessions/fork-inheritance.test.js +69 -0
- package/server/lib/openchamber-sessions/routes.js +11 -0
- package/server/lib/openchamber-sessions/routes.test.js +18 -0
- package/server/lib/opencode/DOCUMENTATION.md +31 -22
- package/server/lib/opencode/bootstrap-runtime.js +12 -0
- package/server/lib/opencode/compatibility.js +6 -3
- package/server/lib/opencode/compatibility.test.js +8 -0
- package/server/lib/opencode/config-v2.d.ts +2 -0
- package/server/lib/opencode/config-v2.js +42 -0
- package/server/lib/opencode/config-v2.test.js +17 -0
- package/server/lib/opencode/core-routes.js +3 -0
- package/server/lib/opencode/core-routes.test.js +15 -0
- package/server/lib/opencode/env-runtime.js +1 -8
- package/server/lib/opencode/feature-routes-runtime.js +2 -1
- package/server/lib/opencode/lifecycle.js +30 -2
- package/server/lib/opencode/lifecycle.test.js +27 -0
- package/server/lib/opencode/managed-config-file.js +18 -6
- package/server/lib/opencode/managed-config-file.test.js +23 -7
- package/server/lib/opencode/openchamber-routes.js +29 -11
- package/server/lib/opencode/openchamber-routes.test.js +18 -0
- package/server/lib/opencode/provider-source-route.test.js +59 -0
- package/server/lib/opencode/providers.js +3 -0
- package/server/lib/opencode/providers.test.js +62 -0
- package/server/lib/opencode/routes-upgrade.test.js +1 -1
- package/server/lib/opencode/routes.js +18 -1
- package/server/lib/opencode/settings-helpers.js +7 -0
- package/server/lib/opencode/settings-helpers.test.js +2 -2
- package/server/lib/opencode/settings-registry.json +14 -0
- package/server/lib/opencode/settings-runtime.js +1 -0
- package/server/lib/opencode/shared.js +32 -2
- package/server/lib/opencode/shared.test.js +79 -1
- package/server/lib/opencode/skill-routes.js +28 -12
- package/server/lib/opencode/skill-routes.test.js +121 -1
- package/server/lib/opencode/upgrade-capability.js +0 -14
- package/server/lib/opencode/v1-migration-topup.js +21 -15
- package/server/lib/opencode/v1-migration-topup.test.js +14 -6
- package/server/lib/opencode/v2-install.d.ts +1 -0
- package/server/lib/opencode/v2-install.js +8 -7
- package/server/lib/opencode/v2-install.test.js +13 -4
- package/server/lib/opencode/websearch-config.js +13 -1
- package/server/lib/quota/providers/kimi.js +1 -1
- package/server/lib/session-assist/DOCUMENTATION.md +17 -5
- package/server/lib/session-assist/runtime.js +19 -2
- package/server/lib/session-assist/runtime.test.js +8 -0
- package/server/lib/session-goal/DOCUMENTATION.md +11 -0
- package/dist/assets/DiffView-BucGEJYa.js +0 -4
- package/dist/assets/FilesView-CQcaaAVP.js +0 -17
- package/dist/assets/GuestSurfacePane--DJ7rsmY.js +0 -1
- package/dist/assets/MarkdownRendererImpl-BPe2TVV2.js +0 -12
- package/dist/assets/PluginPane-DImv8hV2.js +0 -3
- package/dist/assets/SettingsView-DOjuOljf.js +0 -29
- package/dist/assets/commitAndPush-sGEelpjh.js +0 -1
- package/dist/assets/de-CD9utsNj.js +0 -10
- package/dist/assets/es-NNum2rX8.js +0 -16
- package/dist/assets/fr-CJLGmduQ.js +0 -14
- package/dist/assets/index-DjGPR5vW.js +0 -41
- package/dist/assets/index-fCXJ-8Qt.css +0 -1
- package/dist/assets/ja-BuddHNi6.js +0 -16
- package/dist/assets/ko-BrwMbHmf.js +0 -16
- package/dist/assets/main-CxVyUDU_.js +0 -896
- package/dist/assets/markdownCore-B6PpX409.js +0 -5
- package/dist/assets/patchFileDiff-BFRGKaGH.js +0 -13
- package/dist/assets/pl-BwN4TNlP.js +0 -16
- package/dist/assets/pt-BR-BhMtownO.js +0 -16
- package/dist/assets/renderMobileApp-nQ4sjQtb.js +0 -25
- package/dist/assets/runtimeEndpointReset-9ZGlXU4J.js +0 -27
- package/dist/assets/scheduledTasksApi-6DsL_SwM.js +0 -1
- package/dist/assets/tr-DRzvqMdi.js +0 -7
- package/dist/assets/uk-b2aYOSNh.js +0 -16
- package/dist/assets/vendor-zod-Gea9uBlY.js +0 -39
- package/dist/assets/zh-CN-DZeUThm_.js +0 -16
- package/dist/assets/zh-TW-2fRE7uc6.js +0 -16
|
@@ -552,6 +552,7 @@ const ensureGuestService = async (params) => {
|
|
|
552
552
|
* query?: Record<string, string>,
|
|
553
553
|
* body?: string,
|
|
554
554
|
* accept?: string,
|
|
555
|
+
* headers?: Record<string, string>,
|
|
555
556
|
* timeoutMs?: number,
|
|
556
557
|
* idleStopMs?: number,
|
|
557
558
|
* signal?: AbortSignal,
|
|
@@ -572,6 +573,7 @@ export const openGuestServiceRequest = async ({
|
|
|
572
573
|
query,
|
|
573
574
|
body,
|
|
574
575
|
accept = 'application/json',
|
|
576
|
+
headers: extraHeaders,
|
|
575
577
|
timeoutMs = GUEST_REQUEST_TIMEOUT_MS,
|
|
576
578
|
idleStopMs,
|
|
577
579
|
signal,
|
|
@@ -645,6 +647,9 @@ export const openGuestServiceRequest = async ({
|
|
|
645
647
|
|
|
646
648
|
/** @type {Record<string, string>} */
|
|
647
649
|
const headers = {
|
|
650
|
+
// Host-set context (surface viewer headers) first: nothing in it can
|
|
651
|
+
// replace the bearer or the content type below.
|
|
652
|
+
...extraHeaders,
|
|
648
653
|
Accept: accept,
|
|
649
654
|
[OPENCHAMBER_SERVICE_AUTH_HEADER]: `Bearer ${runtime.token}`,
|
|
650
655
|
};
|
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
* holding it releases it.
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
|
+
import { randomUUID } from 'node:crypto';
|
|
24
|
+
|
|
23
25
|
import { WebSocketServer } from 'ws';
|
|
24
26
|
|
|
25
27
|
import {
|
|
@@ -30,6 +32,7 @@ import {
|
|
|
30
32
|
SURFACE_FRAME_MAX_BYTES,
|
|
31
33
|
SURFACE_FRAME_MIMES,
|
|
32
34
|
SURFACE_FRAME_PATH,
|
|
35
|
+
SURFACE_FRAME_SEQ_HEADER,
|
|
33
36
|
SURFACE_FRAME_WAIT_MS,
|
|
34
37
|
SURFACE_HEIGHT_HEADER,
|
|
35
38
|
SURFACE_INPUT_PATH,
|
|
@@ -37,6 +40,8 @@ import {
|
|
|
37
40
|
SURFACE_SEQ_HEADER,
|
|
38
41
|
SURFACE_TITLE_HEADER,
|
|
39
42
|
SURFACE_TITLE_MAX,
|
|
43
|
+
SURFACE_VIEWER_CONTROLS_HEADER,
|
|
44
|
+
SURFACE_VIEWER_HEADER,
|
|
40
45
|
SURFACE_WIDTH_HEADER,
|
|
41
46
|
isGuestApproved,
|
|
42
47
|
requestedGuestCapabilities,
|
|
@@ -97,7 +102,9 @@ export const createGuestSurfaceRuntime = ({
|
|
|
97
102
|
idleStopMs,
|
|
98
103
|
openServiceRequest = openGuestServiceRequest,
|
|
99
104
|
holdService = holdGuestService,
|
|
100
|
-
|
|
105
|
+
// Unguessable: a page call that names a viewer is told whether that viewer
|
|
106
|
+
// holds control, so the id works as the viewer's lease.
|
|
107
|
+
createViewerId = () => `viewer-${randomUUID()}`,
|
|
101
108
|
setTimer = setTimeout,
|
|
102
109
|
clearTimer = clearTimeout,
|
|
103
110
|
}) => {
|
|
@@ -109,13 +116,15 @@ export const createGuestSurfaceRuntime = ({
|
|
|
109
116
|
* id: string,
|
|
110
117
|
* ws: import('ws').WebSocket,
|
|
111
118
|
* sentSeq: number,
|
|
119
|
+
* sentServiceSeq: number,
|
|
120
|
+
* shownServiceSeq: number,
|
|
112
121
|
* awaitingAck: boolean,
|
|
113
122
|
* }} Viewer
|
|
114
123
|
* @typedef {{
|
|
115
124
|
* guestId: string,
|
|
116
125
|
* guest: object,
|
|
117
126
|
* viewers: Map<string, Viewer>,
|
|
118
|
-
* latest: { seq: number, width: number, height: number, mime: string, title?: string, agentActive: boolean, bytes: Buffer } | null,
|
|
127
|
+
* latest: { seq: number, serviceSeq: number, width: number, height: number, mime: string, title?: string, agentActive: boolean, bytes: Buffer } | null,
|
|
119
128
|
* controller: 'none' | 'agent' | string,
|
|
120
129
|
* agentTimer: ReturnType<typeof setTimeout> | null,
|
|
121
130
|
* pumpAbort: AbortController | null,
|
|
@@ -164,13 +173,13 @@ export const createGuestSurfaceRuntime = ({
|
|
|
164
173
|
return run;
|
|
165
174
|
};
|
|
166
175
|
|
|
167
|
-
const notifyService = async (session, controller) => {
|
|
176
|
+
const notifyService = async (session, controller, viewerId) => {
|
|
168
177
|
if (session.ended) return;
|
|
169
178
|
try {
|
|
170
179
|
const { response, finished } = await serviceRequest(session, {
|
|
171
180
|
method: 'POST',
|
|
172
181
|
path: SURFACE_CONTROL_PATH,
|
|
173
|
-
body: JSON.stringify({ controller }),
|
|
182
|
+
body: JSON.stringify(controller === 'user' && viewerId ? { controller, viewer: viewerId } : { controller }),
|
|
174
183
|
timeoutMs: QUICK_REQUEST_TIMEOUT_MS,
|
|
175
184
|
});
|
|
176
185
|
await response.arrayBuffer().catch(() => undefined);
|
|
@@ -186,7 +195,8 @@ export const createGuestSurfaceRuntime = ({
|
|
|
186
195
|
for (const viewer of session.viewers.values()) {
|
|
187
196
|
send(viewer, { type: 'control', controller: kind, mine: session.controller === viewer.id });
|
|
188
197
|
}
|
|
189
|
-
|
|
198
|
+
const holder = kind === 'user' ? session.controller : undefined;
|
|
199
|
+
void enqueue(session, () => notifyService(session, kind, holder));
|
|
190
200
|
};
|
|
191
201
|
|
|
192
202
|
const clearAgentTimer = (session) => {
|
|
@@ -208,6 +218,7 @@ export const createGuestSurfaceRuntime = ({
|
|
|
208
218
|
if (!frame || viewer.awaitingAck || viewer.sentSeq >= frame.seq || viewer.ws.readyState !== 1) return;
|
|
209
219
|
viewer.awaitingAck = true;
|
|
210
220
|
viewer.sentSeq = frame.seq;
|
|
221
|
+
viewer.sentServiceSeq = frame.serviceSeq;
|
|
211
222
|
const meta = {
|
|
212
223
|
type: 'frame',
|
|
213
224
|
seq: frame.seq,
|
|
@@ -260,6 +271,9 @@ export const createGuestSurfaceRuntime = ({
|
|
|
260
271
|
const title = (response.headers.get(SURFACE_TITLE_HEADER) || '').slice(0, SURFACE_TITLE_MAX);
|
|
261
272
|
const frame = {
|
|
262
273
|
seq,
|
|
274
|
+
// The service's own number, kept when `seq` is bumped below: input is
|
|
275
|
+
// stamped with it, and only the service knows which view it belongs to.
|
|
276
|
+
serviceSeq: seq,
|
|
263
277
|
width,
|
|
264
278
|
height,
|
|
265
279
|
mime,
|
|
@@ -357,7 +371,7 @@ export const createGuestSurfaceRuntime = ({
|
|
|
357
371
|
* control back: the user already let go, and re-taking it from a queued
|
|
358
372
|
* click would lock the agent out with nobody to press the button.
|
|
359
373
|
*/
|
|
360
|
-
const handleInput = async (session, viewer, events, handoff) => {
|
|
374
|
+
const handleInput = async (session, viewer, events, handoff, frameSeq) => {
|
|
361
375
|
if (viewer.gone) return;
|
|
362
376
|
if (session.controller !== viewer.id) {
|
|
363
377
|
if (session.controller !== 'none' && session.controller !== 'agent') {
|
|
@@ -373,10 +387,20 @@ export const createGuestSurfaceRuntime = ({
|
|
|
373
387
|
method: 'POST',
|
|
374
388
|
path: SURFACE_INPUT_PATH,
|
|
375
389
|
body: JSON.stringify({ events }),
|
|
390
|
+
headers: {
|
|
391
|
+
[SURFACE_VIEWER_HEADER]: viewer.id,
|
|
392
|
+
[SURFACE_FRAME_SEQ_HEADER]: String(frameSeq),
|
|
393
|
+
},
|
|
376
394
|
timeoutMs: QUICK_REQUEST_TIMEOUT_MS,
|
|
377
395
|
});
|
|
378
396
|
await response.arrayBuffer().catch(() => undefined);
|
|
379
397
|
finished();
|
|
398
|
+
// 409: made on a picture the service no longer shows. Nothing reached
|
|
399
|
+
// the page, and the next frame shows the viewer what is there now.
|
|
400
|
+
if (response.status === 409) {
|
|
401
|
+
send(viewer, { type: 'error', code: 'INPUT_STALE', message: 'The picture changed before this input arrived; it was not applied.' });
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
380
404
|
if (response.status < 200 || response.status >= 300) {
|
|
381
405
|
send(viewer, { type: 'error', code: 'INPUT_REJECTED', message: `The extension refused this input (HTTP ${response.status}).` });
|
|
382
406
|
}
|
|
@@ -445,7 +469,8 @@ export const createGuestSurfaceRuntime = ({
|
|
|
445
469
|
const handleViewerMessage = (session, viewer, raw) => {
|
|
446
470
|
let parsed;
|
|
447
471
|
try {
|
|
448
|
-
|
|
472
|
+
// Node's `ws` delivers a Buffer, Bun's a Uint8Array; both decode here.
|
|
473
|
+
parsed = surfaceViewerMessageSchema.safeParse(JSON.parse(Buffer.from(raw).toString('utf8')));
|
|
449
474
|
} catch {
|
|
450
475
|
parsed = { success: false };
|
|
451
476
|
}
|
|
@@ -458,12 +483,17 @@ export const createGuestSurfaceRuntime = ({
|
|
|
458
483
|
case 'ack':
|
|
459
484
|
if (message.seq === viewer.sentSeq) {
|
|
460
485
|
viewer.awaitingAck = false;
|
|
486
|
+
// Acknowledged after drawing: this is the picture its next input is made on.
|
|
487
|
+
viewer.shownServiceSeq = viewer.sentServiceSeq;
|
|
461
488
|
deliverLatest(session, viewer);
|
|
462
489
|
}
|
|
463
490
|
return;
|
|
464
491
|
case 'input': {
|
|
465
492
|
const handoff = session.handoffs;
|
|
466
|
-
|
|
493
|
+
// Read on arrival, not when the queue reaches the batch: the socket
|
|
494
|
+
// delivers acks and input in the order the viewer drew and acted.
|
|
495
|
+
const frameSeq = viewer.shownServiceSeq;
|
|
496
|
+
void enqueue(session, () => handleInput(session, viewer, message.events, handoff, frameSeq));
|
|
467
497
|
return;
|
|
468
498
|
}
|
|
469
499
|
case 'release':
|
|
@@ -485,7 +515,7 @@ export const createGuestSurfaceRuntime = ({
|
|
|
485
515
|
|
|
486
516
|
const attachViewer = (guestId, guest, ws) => {
|
|
487
517
|
const session = ensureSession(guestId, guest);
|
|
488
|
-
const viewer = { id: createViewerId(), ws, sentSeq: 0, awaitingAck: false, gone: false };
|
|
518
|
+
const viewer = { id: createViewerId(), ws, sentSeq: 0, sentServiceSeq: 0, shownServiceSeq: 0, awaitingAck: false, gone: false };
|
|
489
519
|
session.viewers.set(viewer.id, viewer);
|
|
490
520
|
// Started with the first viewer in place: the pump's loop condition is
|
|
491
521
|
// the viewer count, and it is checked before the first await.
|
|
@@ -609,6 +639,22 @@ export const createGuestSurfaceRuntime = ({
|
|
|
609
639
|
if (session) endSession(session, 'extension-unavailable');
|
|
610
640
|
},
|
|
611
641
|
|
|
642
|
+
/**
|
|
643
|
+
* Headers for a page `serviceRequest` made from the window that holds
|
|
644
|
+
* `viewerId`, or null when that id is not a live viewer of this
|
|
645
|
+
* extension (then the request goes out without any).
|
|
646
|
+
*/
|
|
647
|
+
viewerHeaders(guestId, viewerId) {
|
|
648
|
+
const session = sessions.get(guestId);
|
|
649
|
+
const viewer = session && !session.ended ? session.viewers.get(viewerId) : undefined;
|
|
650
|
+
if (!viewer || viewer.gone) return null;
|
|
651
|
+
return {
|
|
652
|
+
[SURFACE_VIEWER_HEADER]: viewer.id,
|
|
653
|
+
[SURFACE_VIEWER_CONTROLS_HEADER]: session.controller === viewer.id ? '1' : '0',
|
|
654
|
+
[SURFACE_FRAME_SEQ_HEADER]: String(viewer.shownServiceSeq),
|
|
655
|
+
};
|
|
656
|
+
},
|
|
657
|
+
|
|
612
658
|
/** Test seam. */
|
|
613
659
|
sessionOf(guestId) {
|
|
614
660
|
return sessions.get(guestId) ?? null;
|
|
@@ -35,8 +35,9 @@ const createFakeService = () => {
|
|
|
35
35
|
};
|
|
36
36
|
const nextFrameAfter = (seq) => frames.find((frame) => frame.seq > seq) ?? null;
|
|
37
37
|
const completed = [];
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
let inputStatus = 204;
|
|
39
|
+
const openServiceRequest = async ({ path, method, body, query, headers, signal }) => {
|
|
40
|
+
calls.push({ path, method, body: body ? JSON.parse(body) : undefined, query, headers });
|
|
40
41
|
if (failWith) throw failWith;
|
|
41
42
|
if (path === SURFACE_INPUT_PATH && inputGate) {
|
|
42
43
|
const gate = inputGate;
|
|
@@ -75,6 +76,8 @@ const createFakeService = () => {
|
|
|
75
76
|
response = Response.json({ width: 640, height: 400 });
|
|
76
77
|
} else if (path === SURFACE_CLIPBOARD_PATH) {
|
|
77
78
|
response = Response.json({ text: 'copied inside' });
|
|
79
|
+
} else if (path === SURFACE_INPUT_PATH) {
|
|
80
|
+
response = new Response(null, { status: inputStatus });
|
|
78
81
|
} else {
|
|
79
82
|
response = new Response(null, { status: 204 });
|
|
80
83
|
}
|
|
@@ -85,6 +88,7 @@ const createFakeService = () => {
|
|
|
85
88
|
completed,
|
|
86
89
|
pushFrame,
|
|
87
90
|
gateNextInput: (promise) => { inputGate = promise; },
|
|
91
|
+
answerInputWith: (status) => { inputStatus = status; },
|
|
88
92
|
fail: (error) => { failWith = error; for (const wake of waiters.splice(0)) wake(); },
|
|
89
93
|
openServiceRequest,
|
|
90
94
|
callsTo: (path) => calls.filter((call) => call.path === path),
|
|
@@ -101,7 +105,8 @@ const openViewer = (port, guestId = 'sim') => new Promise((resolve, reject) => {
|
|
|
101
105
|
const inbox = [];
|
|
102
106
|
const waiting = [];
|
|
103
107
|
ws.on('message', (data, isBinary) => {
|
|
104
|
-
|
|
108
|
+
// Bun's `ws` hands text frames over as a Uint8Array, not a Buffer.
|
|
109
|
+
const item = isBinary ? { binary: Buffer.from(data) } : JSON.parse(Buffer.from(data).toString('utf8'));
|
|
105
110
|
const waiter = waiting.shift();
|
|
106
111
|
if (waiter) waiter(item);
|
|
107
112
|
else inbox.push(item);
|
|
@@ -214,13 +219,13 @@ describe('guest surface runtime', () => {
|
|
|
214
219
|
await settle();
|
|
215
220
|
expect(runtime.userControls('sim')).toBe(true);
|
|
216
221
|
expect(service.callsTo(SURFACE_INPUT_PATH)[0].body).toEqual({ events: [click] });
|
|
217
|
-
expect(service.callsTo(SURFACE_CONTROL_PATH).map((call) => call.body)).toEqual([{ controller: 'user' }]);
|
|
222
|
+
expect(service.callsTo(SURFACE_CONTROL_PATH).map((call) => call.body)).toEqual([{ controller: 'user', viewer: 'viewer-1' }]);
|
|
218
223
|
|
|
219
224
|
viewer.send({ type: 'release' });
|
|
220
225
|
expect(await viewer.next()).toEqual({ type: 'control', controller: 'none', mine: false });
|
|
221
226
|
await settle();
|
|
222
227
|
expect(runtime.userControls('sim')).toBe(false);
|
|
223
|
-
expect(service.callsTo(SURFACE_CONTROL_PATH).map((call) => call.body)).toEqual([{ controller: 'user' }, { controller: 'none' }]);
|
|
228
|
+
expect(service.callsTo(SURFACE_CONTROL_PATH).map((call) => call.body)).toEqual([{ controller: 'user', viewer: 'viewer-1' }, { controller: 'none' }]);
|
|
224
229
|
});
|
|
225
230
|
|
|
226
231
|
test('a second viewer cannot take control from the first and is told who has it', async () => {
|
|
@@ -367,7 +372,7 @@ describe('guest surface runtime', () => {
|
|
|
367
372
|
viewer.ws.close();
|
|
368
373
|
await viewer.closed;
|
|
369
374
|
await settle();
|
|
370
|
-
expect(service.callsTo(SURFACE_CONTROL_PATH).map((call) => call.body)).toEqual([{ controller: 'user' }, { controller: 'none' }]);
|
|
375
|
+
expect(service.callsTo(SURFACE_CONTROL_PATH).map((call) => call.body)).toEqual([{ controller: 'user', viewer: 'viewer-1' }, { controller: 'none' }]);
|
|
371
376
|
});
|
|
372
377
|
|
|
373
378
|
test('a queued input from before a hand-back does not take control again', async () => {
|
|
@@ -483,4 +488,49 @@ describe('guest surface runtime', () => {
|
|
|
483
488
|
await again.closed;
|
|
484
489
|
expect(runtime.sessionOf('sim')).toBeNull();
|
|
485
490
|
});
|
|
491
|
+
|
|
492
|
+
test('stamps input with the viewer and the service frame it last drew', async () => {
|
|
493
|
+
const { port, service, runtime } = await createHarness();
|
|
494
|
+
const viewer = await openViewer(port);
|
|
495
|
+
await viewer.next(); // hello
|
|
496
|
+
await viewer.next(); // control
|
|
497
|
+
const click = { type: 'pointer', action: 'down', x: 1, y: 1, button: 0, buttons: 1, modifiers: { alt: false, ctrl: false, meta: false, shift: false } };
|
|
498
|
+
|
|
499
|
+
// Nothing drawn yet: frame 0.
|
|
500
|
+
viewer.send({ type: 'input', events: [click] });
|
|
501
|
+
await settle();
|
|
502
|
+
expect(service.callsTo(SURFACE_INPUT_PATH)[0].headers).toEqual({ 'x-surface-viewer': 'viewer-1', 'x-surface-frame-seq': '0' });
|
|
503
|
+
expect(service.callsTo(SURFACE_CONTROL_PATH).at(-1).body).toEqual({ controller: 'user', viewer: 'viewer-1' });
|
|
504
|
+
await viewer.next(); // control: mine
|
|
505
|
+
|
|
506
|
+
service.pushFrame({ seq: 7, bytes: Buffer.from('frame-7') });
|
|
507
|
+
await viewer.next();
|
|
508
|
+
await viewer.next();
|
|
509
|
+
// Sent but not yet drawn: input still counts as made on the old picture.
|
|
510
|
+
viewer.send({ type: 'input', events: [click] });
|
|
511
|
+
viewer.send({ type: 'ack', seq: 7 });
|
|
512
|
+
viewer.send({ type: 'input', events: [click] });
|
|
513
|
+
await settle();
|
|
514
|
+
const stamped = service.callsTo(SURFACE_INPUT_PATH).map((call) => call.headers['x-surface-frame-seq']);
|
|
515
|
+
expect(stamped).toEqual(['0', '0', '7']);
|
|
516
|
+
|
|
517
|
+
expect(runtime.viewerHeaders('sim', 'viewer-1')).toEqual({ 'x-surface-viewer': 'viewer-1', 'x-surface-viewer-controls': '1', 'x-surface-frame-seq': '7' });
|
|
518
|
+
expect(runtime.viewerHeaders('sim', 'viewer-2')).toBeNull();
|
|
519
|
+
expect(runtime.viewerHeaders('other', 'viewer-1')).toBeNull();
|
|
520
|
+
|
|
521
|
+
viewer.send({ type: 'release' });
|
|
522
|
+
await settle();
|
|
523
|
+
expect(runtime.viewerHeaders('sim', 'viewer-1')['x-surface-viewer-controls']).toBe('0');
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
test('tells the viewer when the service refuses input made on an old picture', async () => {
|
|
527
|
+
const { port, service } = await createHarness();
|
|
528
|
+
const viewer = await openViewer(port);
|
|
529
|
+
await viewer.next();
|
|
530
|
+
await viewer.next();
|
|
531
|
+
service.answerInputWith(409);
|
|
532
|
+
viewer.send({ type: 'input', events: [{ type: 'text', text: 'hi' }] });
|
|
533
|
+
await viewer.next(); // control: mine
|
|
534
|
+
expect(await viewer.next()).toMatchObject({ type: 'error', code: 'INPUT_STALE' });
|
|
535
|
+
});
|
|
486
536
|
});
|
|
@@ -9,6 +9,7 @@ This module provides notification message preparation utilities for the web serv
|
|
|
9
9
|
- `packages/web/server/lib/notifications/push-runtime.js`: push subscription persistence, VAPID initialization, and UI visibility runtime.
|
|
10
10
|
- `packages/web/server/lib/notifications/apns-runtime.js`: native iOS APNs device-token persistence + delivery. Two modes: **relay** (default — sign + POST tokens + generic text to the central Cloudflare relay `https://api.openchamber.dev/v1/push/send`, which holds the single project APNs key) and **direct** (fallback — sign ES256 JWT with Node crypto + HTTP/2, when `OPENCHAMBER_PUSH_RELAY_DISABLED=true`). Each server has an auto-generated ECDSA P-256 keypair (`getOrCreateRelayKeypair`, persisted in settings); it binds tokens on the relay (`/v1/push/register-token`) and signs every relay request, so the relay only delivers to tokens bound to that server. APNs is the native app's sole notification channel (no local notifications) and is NOT gated on UI visibility — iOS suppresses the foreground banner instead. Mobile push carries only generic text (scenario title + session name) — see `APNS.md`.
|
|
11
11
|
- `packages/web/server/lib/notifications/emitter-runtime.js`: desktop/stdout + UI SSE notification emission runtime.
|
|
12
|
+
- `packages/web/server/lib/notifications/emit-route.js`: `POST /api/notifications/emit` for OpenCode plugins.
|
|
12
13
|
- `packages/web/server/lib/notifications/runtime.js`: trigger runtime for OpenCode event-driven notification fanout.
|
|
13
14
|
- `packages/web/server/lib/notifications/template-runtime.js`: notification template variables and session text/title enrichment runtime. Zen-model helpers are retained as compatibility stubs only.
|
|
14
15
|
- `packages/web/server/lib/notifications/message.js`: helper implementation module.
|
|
@@ -82,6 +83,15 @@ This module provides notification message preparation utilities for the web serv
|
|
|
82
83
|
- `emitDesktopNotification(payload)`
|
|
83
84
|
- `broadcastUiNotification(payload)`
|
|
84
85
|
|
|
86
|
+
### Plugin notification route (emit-route.js)
|
|
87
|
+
- `createPluginNotificationEmitter(dependencies)` owns validation, the rate window and delivery; one instance is shared by the HTTP route and the `openchamber_notify` agent tool (`notify.send`).
|
|
88
|
+
- `registerNotificationEmitRoutes(app, dependencies)` returns `registerPluginRoute()` and `registerApiRoute()`. Bootstrap calls the first before API auth and the second after it.
|
|
89
|
+
- Callers: a plugin in the managed OpenCode (agent-tool bearer token, the only reason for the pre-auth registration) or any client that passes regular API auth. No other auth path exists.
|
|
90
|
+
- Body `{ title?, body?, tag?, sessionId?, directory?, showWhenFocused? }`, at least one of title/body; title ≤120, body ≤500 chars, 16kb JSON. `kind` is always `plugin` so callers cannot trigger kinds the UI treats specially.
|
|
91
|
+
- One shared rate window: 10 notifications per 10s, then 429 with `Retry-After`.
|
|
92
|
+
- Follows `nativeNotificationsEnabled` (returns `{ delivered: false }`) and `notificationMode` (`requireHidden`); `showWhenFocused: true` sends `requireHidden: false` so the notice shows even while OpenChamber is focused. Live delivery only: no web push or APNs fanout.
|
|
93
|
+
- Advertised as the `api.notifications.emit.v1` server capability.
|
|
94
|
+
|
|
85
95
|
### Template runtime API (template-runtime.js)
|
|
86
96
|
- `createNotificationTemplateRuntime(dependencies)`: creates shared notification/template runtime. Model-backed summarization was retired after the Zen provider became unavailable.
|
|
87
97
|
- Returned API:
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
const NOTIFICATION_EMIT_PATH = '/api/notifications/emit';
|
|
4
|
+
|
|
5
|
+
const RATE_WINDOW_MS = 10_000;
|
|
6
|
+
const RATE_MAX_PER_WINDOW = 10;
|
|
7
|
+
|
|
8
|
+
const optionalText = (max) => z.string().trim().min(1).max(max).optional();
|
|
9
|
+
|
|
10
|
+
const emitBodySchema = z.object({
|
|
11
|
+
title: optionalText(120),
|
|
12
|
+
body: optionalText(500),
|
|
13
|
+
tag: optionalText(128),
|
|
14
|
+
sessionId: optionalText(128),
|
|
15
|
+
directory: optionalText(4096),
|
|
16
|
+
// Opt-in for notices that matter even while OpenChamber is in front.
|
|
17
|
+
showWhenFocused: z.boolean().optional(),
|
|
18
|
+
}).refine((value) => value.title || value.body, { message: 'title or body required' });
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Raises a notification on behalf of a plugin or the agent, through the same
|
|
22
|
+
* live delivery the built-in triggers use. `kind` is always `plugin`, so a
|
|
23
|
+
* caller cannot impersonate kinds the UI treats specially. One rate window is
|
|
24
|
+
* shared by every caller, the HTTP route and the agent tool alike.
|
|
25
|
+
*
|
|
26
|
+
* `emit` resolves to `{ status, body }`: 200 delivered or skipped by settings,
|
|
27
|
+
* 400 invalid input, 429 rate limited (with `retryAfter` seconds).
|
|
28
|
+
*/
|
|
29
|
+
export const createPluginNotificationEmitter = (dependencies) => {
|
|
30
|
+
const {
|
|
31
|
+
readSettingsFromDiskMigrated,
|
|
32
|
+
emitDesktopNotification,
|
|
33
|
+
broadcastUiNotification,
|
|
34
|
+
now = Date.now,
|
|
35
|
+
} = dependencies;
|
|
36
|
+
|
|
37
|
+
let windowStartedAt = 0;
|
|
38
|
+
let windowCount = 0;
|
|
39
|
+
|
|
40
|
+
const takeRateSlot = () => {
|
|
41
|
+
const current = now();
|
|
42
|
+
if (current - windowStartedAt >= RATE_WINDOW_MS) {
|
|
43
|
+
windowStartedAt = current;
|
|
44
|
+
windowCount = 0;
|
|
45
|
+
}
|
|
46
|
+
if (windowCount >= RATE_MAX_PER_WINDOW) {
|
|
47
|
+
return Math.ceil((windowStartedAt + RATE_WINDOW_MS - current) / 1000);
|
|
48
|
+
}
|
|
49
|
+
windowCount += 1;
|
|
50
|
+
return 0;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const emit = async (input) => {
|
|
54
|
+
const parsed = emitBodySchema.safeParse(input);
|
|
55
|
+
if (!parsed.success) {
|
|
56
|
+
return { status: 400, body: { error: parsed.error.issues[0]?.message ?? 'invalid notification' } };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const retryAfter = takeRateSlot();
|
|
60
|
+
if (retryAfter > 0) {
|
|
61
|
+
return { status: 429, retryAfter, body: { error: 'too many notifications' } };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const settings = await readSettingsFromDiskMigrated();
|
|
65
|
+
if (settings.nativeNotificationsEnabled === false) {
|
|
66
|
+
return { status: 200, body: { delivered: false, reason: 'notifications-disabled' } };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const payload = {
|
|
70
|
+
title: parsed.data.title ?? 'OpenChamber',
|
|
71
|
+
body: parsed.data.body,
|
|
72
|
+
tag: parsed.data.tag,
|
|
73
|
+
kind: 'plugin',
|
|
74
|
+
sessionId: parsed.data.sessionId,
|
|
75
|
+
directory: parsed.data.directory,
|
|
76
|
+
requireHidden: parsed.data.showWhenFocused !== true && settings.notificationMode !== 'always',
|
|
77
|
+
};
|
|
78
|
+
const desktopNotificationDelivered = emitDesktopNotification(payload) === true;
|
|
79
|
+
broadcastUiNotification(payload, { desktopNotificationDelivered });
|
|
80
|
+
return { status: 200, body: { delivered: true } };
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
return { emit };
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* `POST /api/notifications/emit`. Two callers are accepted: a plugin inside
|
|
88
|
+
* the managed OpenCode (the agent-tool bearer token, checked before API auth)
|
|
89
|
+
* and any client that passes the regular API auth.
|
|
90
|
+
*/
|
|
91
|
+
export const registerNotificationEmitRoutes = (app, dependencies) => {
|
|
92
|
+
const { express, isAgentToolRequestAuthorized, emitter } = dependencies;
|
|
93
|
+
|
|
94
|
+
const jsonBody = express.json({ limit: '16kb' });
|
|
95
|
+
|
|
96
|
+
const respond = async (req, res, next) => {
|
|
97
|
+
try {
|
|
98
|
+
const result = await emitter.emit(req.body);
|
|
99
|
+
if (result.retryAfter) res.setHeader('Retry-After', String(result.retryAfter));
|
|
100
|
+
return res.status(result.status).json(result.body);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
return next(error);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
// Registered before API auth: a managed plugin carries no UI session.
|
|
108
|
+
registerPluginRoute: () => {
|
|
109
|
+
app.post(NOTIFICATION_EMIT_PATH, jsonBody, (req, res, next) => (
|
|
110
|
+
isAgentToolRequestAuthorized(req) ? respond(req, res, next) : next()
|
|
111
|
+
));
|
|
112
|
+
},
|
|
113
|
+
// Registered after API auth: everything else is an ordinary API caller.
|
|
114
|
+
registerApiRoute: () => {
|
|
115
|
+
app.post(NOTIFICATION_EMIT_PATH, jsonBody, respond);
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import request from 'supertest';
|
|
4
|
+
import { createPluginNotificationEmitter, registerNotificationEmitRoutes } from './emit-route.js';
|
|
5
|
+
|
|
6
|
+
const PLUGIN_TOKEN = 'Bearer plugin-token';
|
|
7
|
+
const UI_TOKEN = 'Bearer ui-token';
|
|
8
|
+
|
|
9
|
+
const createApp = ({ settings = { nativeNotificationsEnabled: true, notificationMode: 'hidden-only' }, now = () => 0 } = {}) => {
|
|
10
|
+
const delivered = [];
|
|
11
|
+
const app = express();
|
|
12
|
+
const emitter = createPluginNotificationEmitter({
|
|
13
|
+
readSettingsFromDiskMigrated: async () => settings,
|
|
14
|
+
emitDesktopNotification: () => false,
|
|
15
|
+
broadcastUiNotification: (payload, options) => delivered.push({ payload, options }),
|
|
16
|
+
now,
|
|
17
|
+
});
|
|
18
|
+
const routes = registerNotificationEmitRoutes(app, {
|
|
19
|
+
express,
|
|
20
|
+
isAgentToolRequestAuthorized: (req) => req.headers.authorization === PLUGIN_TOKEN,
|
|
21
|
+
emitter,
|
|
22
|
+
});
|
|
23
|
+
routes.registerPluginRoute();
|
|
24
|
+
// Stands in for the server's API auth gate between the two registrations.
|
|
25
|
+
app.use('/api', (req, res, next) => (
|
|
26
|
+
req.headers.authorization === UI_TOKEN ? next() : res.status(401).json({ error: 'UI session missing' })
|
|
27
|
+
));
|
|
28
|
+
routes.registerApiRoute();
|
|
29
|
+
return { app, delivered };
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
describe('POST /api/notifications/emit', () => {
|
|
33
|
+
it('delivers a plugin notification without a UI session', async () => {
|
|
34
|
+
const { app, delivered } = createApp();
|
|
35
|
+
const response = await request(app)
|
|
36
|
+
.post('/api/notifications/emit')
|
|
37
|
+
.set('Authorization', PLUGIN_TOKEN)
|
|
38
|
+
.send({ title: ' Build done ', body: 'Ready', sessionId: 'ses_1' });
|
|
39
|
+
|
|
40
|
+
expect(response.status).toBe(200);
|
|
41
|
+
expect(response.body).toEqual({ delivered: true });
|
|
42
|
+
expect(delivered).toEqual([{
|
|
43
|
+
payload: {
|
|
44
|
+
title: 'Build done',
|
|
45
|
+
body: 'Ready',
|
|
46
|
+
tag: undefined,
|
|
47
|
+
kind: 'plugin',
|
|
48
|
+
sessionId: 'ses_1',
|
|
49
|
+
directory: undefined,
|
|
50
|
+
requireHidden: true,
|
|
51
|
+
},
|
|
52
|
+
options: { desktopNotificationDelivered: false },
|
|
53
|
+
}]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('accepts an ordinary API caller and rejects an unauthenticated one', async () => {
|
|
57
|
+
const { app, delivered } = createApp();
|
|
58
|
+
await request(app).post('/api/notifications/emit').set('Authorization', UI_TOKEN).send({ body: 'Hi' }).expect(200);
|
|
59
|
+
await request(app).post('/api/notifications/emit').send({ body: 'Hi' }).expect(401);
|
|
60
|
+
await request(app).post('/api/notifications/emit').set('Authorization', 'Bearer wrong').send({ body: 'Hi' }).expect(401);
|
|
61
|
+
expect(delivered.map(({ payload }) => payload.title)).toEqual(['OpenChamber']);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('never lets a caller choose the notification kind', async () => {
|
|
65
|
+
const { app, delivered } = createApp();
|
|
66
|
+
await request(app)
|
|
67
|
+
.post('/api/notifications/emit')
|
|
68
|
+
.set('Authorization', PLUGIN_TOKEN)
|
|
69
|
+
.send({ title: 'x', kind: 'opencode-restart-interrupted' })
|
|
70
|
+
.expect(200);
|
|
71
|
+
expect(delivered[0].payload.kind).toBe('plugin');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('rejects empty and oversized payloads', async () => {
|
|
75
|
+
const { app, delivered } = createApp();
|
|
76
|
+
const post = (body) => request(app).post('/api/notifications/emit').set('Authorization', PLUGIN_TOKEN).send(body);
|
|
77
|
+
await post({}).expect(400);
|
|
78
|
+
await post({ title: ' ' }).expect(400);
|
|
79
|
+
await post({ title: 'x'.repeat(121) }).expect(400);
|
|
80
|
+
await post({ body: 'x'.repeat(501) }).expect(400);
|
|
81
|
+
expect(delivered).toEqual([]);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('limits the rate and recovers after the window', async () => {
|
|
85
|
+
let clock = 0;
|
|
86
|
+
const { app, delivered } = createApp({ now: () => clock });
|
|
87
|
+
const post = () => request(app).post('/api/notifications/emit').set('Authorization', PLUGIN_TOKEN).send({ body: 'tick' });
|
|
88
|
+
for (let index = 0; index < 10; index += 1) await post().expect(200);
|
|
89
|
+
const limited = await post();
|
|
90
|
+
expect(limited.status).toBe(429);
|
|
91
|
+
expect(limited.headers['retry-after']).toBe('10');
|
|
92
|
+
clock = 10_000;
|
|
93
|
+
await post().expect(200);
|
|
94
|
+
expect(delivered).toHaveLength(11);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('follows the notifications setting and the always mode', async () => {
|
|
98
|
+
const off = createApp({ settings: { nativeNotificationsEnabled: false } });
|
|
99
|
+
const skipped = await request(off.app).post('/api/notifications/emit').set('Authorization', PLUGIN_TOKEN).send({ body: 'x' });
|
|
100
|
+
expect(skipped.body).toEqual({ delivered: false, reason: 'notifications-disabled' });
|
|
101
|
+
expect(off.delivered).toEqual([]);
|
|
102
|
+
|
|
103
|
+
const always = createApp({ settings: { nativeNotificationsEnabled: true, notificationMode: 'always' } });
|
|
104
|
+
await request(always.app).post('/api/notifications/emit').set('Authorization', PLUGIN_TOKEN).send({ body: 'x' }).expect(200);
|
|
105
|
+
expect(always.delivered[0].payload.requireHidden).toBe(false);
|
|
106
|
+
|
|
107
|
+
const focused = createApp();
|
|
108
|
+
await request(focused.app).post('/api/notifications/emit').set('Authorization', PLUGIN_TOKEN).send({ body: 'x', showWhenFocused: true }).expect(200);
|
|
109
|
+
expect(focused.delivered[0].payload.requireHidden).toBe(false);
|
|
110
|
+
await request(focused.app).post('/api/notifications/emit').set('Authorization', PLUGIN_TOKEN).send({ body: 'x', showWhenFocused: 'yes' }).expect(400);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -38,8 +38,8 @@ export const OPENCHAMBER_AGENT_TOOL_ACTIONS = Object.freeze(
|
|
|
38
38
|
);
|
|
39
39
|
|
|
40
40
|
export const OPENCHAMBER_WEB_ACTION_DEFINITIONS = Object.freeze([
|
|
41
|
-
{ action: 'browser.open', title: 'Open a page in the browser panel', description: 'Open url in the in-app browser panel; use it to look at the running app. Set viewport to mobile, tablet or desktop to lay the page out at that size' },
|
|
42
|
-
{ action: 'browser.snapshot', title: 'Read the open page', description: 'Read the open page: url, title, visible text, and interactive elements with the selectors the other browser actions accept. Pass selector to read only that part of a long page. Reports any errors the page logged' },
|
|
41
|
+
{ action: 'browser.open', title: 'Open a page in the browser panel', description: 'Open url in the in-app browser panel; use it to look at the running app. Without tabId it opens a new background tab and answers with its tabId: pass that tabId to the following actions to keep working there. With tabId it loads url in that tab. Set viewport to mobile, tablet or desktop to lay the page out at that size' },
|
|
42
|
+
{ action: 'browser.snapshot', title: 'Read the open page', description: 'Read the open page: url, title, visible text, and interactive elements with the selectors the other browser actions accept. Pass selector to read only that part of a long page. Reports any errors the page logged, and lists the open tabs with the ids tabId accepts' },
|
|
43
43
|
{ action: 'browser.click', title: 'Click on the open page', description: 'Click an element; give selector, or text to match a link or button by its visible label' },
|
|
44
44
|
{ action: 'browser.type', title: 'Type into the open page', description: 'Type value into the field matched by selector; set submit to press Enter afterwards' },
|
|
45
45
|
{ action: 'browser.scroll', title: 'Scroll the open page', description: 'Scroll the page; direction is up, down, top, or bottom, or pass selector to bring one element into view' },
|
|
@@ -76,6 +76,18 @@ export const OPENCHAMBER_MEMORY_ACTIONS = Object.freeze(
|
|
|
76
76
|
OPENCHAMBER_MEMORY_ACTION_DEFINITIONS.map(({ action }) => action),
|
|
77
77
|
);
|
|
78
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Notify is its own tool so it can stay off by default and disappear
|
|
81
|
+
* completely: an agent that can page the user is a choice the user makes.
|
|
82
|
+
*/
|
|
83
|
+
export const OPENCHAMBER_NOTIFY_ACTION_DEFINITIONS = Object.freeze([
|
|
84
|
+
{ action: 'notify.send', title: 'Notify the user', description: 'Send the user a notification; requires title, body is optional. By default it appears only while the user is away from OpenChamber; set showWhenFocused only when it cannot wait' },
|
|
85
|
+
]);
|
|
86
|
+
|
|
87
|
+
export const OPENCHAMBER_NOTIFY_ACTIONS = Object.freeze(
|
|
88
|
+
OPENCHAMBER_NOTIFY_ACTION_DEFINITIONS.map(({ action }) => action),
|
|
89
|
+
);
|
|
90
|
+
|
|
79
91
|
/**
|
|
80
92
|
* Which actions each managed tool may ask for.
|
|
81
93
|
*
|
|
@@ -90,6 +102,7 @@ const ACTIONS_BY_TOOL = Object.freeze({
|
|
|
90
102
|
openchamber: OPENCHAMBER_AGENT_TOOL_ACTIONS,
|
|
91
103
|
openchamber_web: OPENCHAMBER_WEB_ACTIONS,
|
|
92
104
|
openchamber_memory: OPENCHAMBER_MEMORY_ACTIONS,
|
|
105
|
+
openchamber_notify: OPENCHAMBER_NOTIFY_ACTIONS,
|
|
93
106
|
});
|
|
94
107
|
|
|
95
108
|
const bareName = (action) => {
|
|
@@ -136,4 +149,5 @@ export const OPENCHAMBER_ALL_ACTIONS = Object.freeze([
|
|
|
136
149
|
...OPENCHAMBER_CONTROL_ACTIONS,
|
|
137
150
|
...OPENCHAMBER_WEB_ACTIONS,
|
|
138
151
|
...OPENCHAMBER_MEMORY_ACTIONS,
|
|
152
|
+
...OPENCHAMBER_NOTIFY_ACTIONS,
|
|
139
153
|
]);
|
|
@@ -154,6 +154,7 @@ export const createOpenChamberControlService = (dependencies) => {
|
|
|
154
154
|
scheduledTaskService,
|
|
155
155
|
browserControl = null,
|
|
156
156
|
fileOpen = null,
|
|
157
|
+
notifyUser = null,
|
|
157
158
|
agentMemoryActions = null,
|
|
158
159
|
// Archive lives in OpenChamber's own store now — v2 has no route that sets
|
|
159
160
|
// Session.time.archived — so an unwired store simply means nothing is archived.
|
|
@@ -365,6 +366,12 @@ export const createOpenChamberControlService = (dependencies) => {
|
|
|
365
366
|
*/
|
|
366
367
|
const browserAction = async (action, input, signal, contextDirectory, contextSessionId) => {
|
|
367
368
|
const parameters = {};
|
|
369
|
+
// Any action may name a tab; the browser that issued the id resolves it.
|
|
370
|
+
const tabId = asNonEmptyString(input.tabId);
|
|
371
|
+
if (tabId) {
|
|
372
|
+
if (tabId.length > 128) throw new OpenChamberControlError('tabId must be an id from browser.snapshot tabs', 400);
|
|
373
|
+
parameters.tabId = tabId;
|
|
374
|
+
}
|
|
368
375
|
|
|
369
376
|
const readViewport = (required) => {
|
|
370
377
|
const viewport = asNonEmptyString(input.viewport);
|
|
@@ -511,6 +518,22 @@ export const createOpenChamberControlService = (dependencies) => {
|
|
|
511
518
|
}
|
|
512
519
|
return browserAction(action, input, options.signal, contextDirectory, options.contextSessionId);
|
|
513
520
|
}
|
|
521
|
+
if (action === 'notify.send') {
|
|
522
|
+
if (!notifyUser) {
|
|
523
|
+
throw new OpenChamberControlError('Notifications are not available on this server', 503);
|
|
524
|
+
}
|
|
525
|
+
const result = await notifyUser({
|
|
526
|
+
title: input.title,
|
|
527
|
+
body: input.body,
|
|
528
|
+
showWhenFocused: input.showWhenFocused,
|
|
529
|
+
sessionId: asNonEmptyString(options.contextSessionId) || undefined,
|
|
530
|
+
directory: asNonEmptyString(contextDirectory) || undefined,
|
|
531
|
+
});
|
|
532
|
+
if (result.status !== 200) {
|
|
533
|
+
throw new OpenChamberControlError(result.body.error, result.status);
|
|
534
|
+
}
|
|
535
|
+
return result.body;
|
|
536
|
+
}
|
|
514
537
|
if (action === 'file.open') {
|
|
515
538
|
if (!fileOpen) {
|
|
516
539
|
throw new OpenChamberControlError('The file viewer is not available on this server', 503);
|