@pi-chamber/web 1.0.4-rc.4 → 1.0.5-rc.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/README.md +1 -1
- package/bin/cli.js +21 -2
- package/bin/cli.test.js +164 -4
- package/bin/lib/DOCUMENTATION.md +3 -3
- package/bin/lib/cli-args.js +96 -13
- package/bin/lib/commands-connect-url-tailscale.test.js +136 -0
- package/bin/lib/commands-connect-url.js +146 -39
- package/bin/lib/commands-connect-url.test.js +126 -0
- package/bin/lib/commands-serve.js +45 -2
- package/bin/lib/commands-status.js +28 -5
- package/bin/lib/commands-status.test.js +107 -0
- package/bin/lib/commands-tunnel.js +36 -10
- package/dist/assets/{DiagramView--BGR3PRZ.js → DiagramView-D-OSWTbO.js} +1 -1
- package/dist/assets/DiffView-BKT-MIH4.js +18 -0
- package/dist/assets/{FileSaveConflictDialog-CcrWHRvd.js → FileSaveConflictDialog-DBkVFssC.js} +2 -2
- package/dist/assets/FilesView-B7GIuRlh.js +6 -0
- package/dist/assets/{GitHubDetailScaffold-BZhP67Va.js → GitHubDetailScaffold-C9rCZMUT.js} +2 -2
- package/dist/assets/{GitHubLinkPicker-CJZmDljp.js → GitHubLinkPicker-Bm09hvhJ.js} +1 -1
- package/dist/assets/{GitHubListPrimitives-DhF42guB.js → GitHubListPrimitives-DlhAlxI6.js} +1 -1
- package/dist/assets/{GitView-JK-QCK9R.js → GitView-BgqdMb0m.js} +4 -4
- package/dist/assets/{IssuesSurface-CAqQzrsv.js → IssuesSurface-BZXAvt49.js} +3 -3
- package/dist/assets/{JsonTreeView-CKTqB1CD.js → JsonTreeView-BKgCQjh_.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-B5kJy9Nt.js → MarkdownRendererImpl-BdcyMPw-.js} +1 -1
- package/dist/assets/{PatchDiff-BQnRFN30.js → PatchDiff-2MmWXcGe.js} +1 -1
- package/dist/assets/PierreDiffViewer-D1F2WvD0.js +135 -0
- package/dist/assets/PullRequestsSurface-CN2z3DFv.js +2 -0
- package/dist/assets/SessionSwitcherContent-CCljxAZb.js +1 -0
- package/dist/assets/SessionSwitcherDropdown-DtNt3qw4.js +2 -0
- package/dist/assets/SessionUnreadDot-B9bHMy5q.js +1 -0
- package/dist/assets/SettingsView-DaZVCInW.js +6 -0
- package/dist/assets/{SettingsWindow-CAxKgYOu.js → SettingsWindow-C-ydfopH.js} +1 -1
- package/dist/assets/StickyHorizontalScrollbar-BMITjK4e.js +8 -0
- package/dist/assets/{ToolOutputDialog-lz5exVQ4.js → ToolOutputDialog-DJUAx_Oj.js} +4 -4
- package/dist/assets/{ToolPartDiffPreview-nIUiNLpP.js → ToolPartDiffPreview-DFyuJM4c.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-IWqCJNXu.js → VirtualizedFileDiff-BS-af6rn.js} +4 -4
- package/dist/assets/{Virtualizer-Cp_cJWbI.js → Virtualizer-DP6HbEeC.js} +1 -1
- package/dist/assets/{collapsible-C7oyikVm.js → collapsible-BOcd0lzY.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-CyhUKEfv.js → computeVirtualFileMetrics-BI6wORhM.js} +1 -1
- package/dist/assets/{contextFileOpenGuard-DkjmJ-NU.js → contextFileOpenGuard-DUMSGR4M.js} +1 -1
- package/dist/assets/{gitStatusPredicates-DBmUY3kA.js → gitStatusPredicates-FdKYDZe3.js} +1 -1
- package/dist/assets/{githubLink-BdbPMMAK.js → githubLink-B3-BaGpb.js} +5 -5
- package/dist/assets/index-DWSrsQWl.js +11 -0
- package/dist/assets/{index-CKgYIOis.js → index-Df-vmvzu.js} +1 -1
- package/dist/assets/index-DsQIBAWK.css +1 -0
- package/dist/assets/main-61_cd7S7.js +2 -0
- package/dist/assets/main-q43jqZ2I.js +136 -0
- package/dist/assets/{markdownCore-D7V46WY9.js → markdownCore-CqHYlXi_.js} +2 -2
- package/dist/assets/{miniChat-PanPmbEK.js → miniChat-vOuWN5pV.js} +2 -2
- package/dist/assets/mobile-mrXWV5ky.js +2 -0
- package/dist/assets/{nativeFileSave-BzhtrDoD.js → nativeFileSave-CFuugNKV.js} +1 -1
- package/dist/assets/pi-session-focus-preference-BEufpwC6.js +9 -0
- package/dist/assets/{renderDiffWithHighlighter-ByZtK9za.js → renderDiffWithHighlighter-BD9CAhZU.js} +1 -1
- package/dist/assets/renderElectronMiniChatApp-QQFXkY5Y.js +2 -0
- package/dist/assets/{renderFileWithHighlighter-CnN0Tv_8.js → renderFileWithHighlighter-KiEWMtzI.js} +1 -1
- package/dist/assets/renderMobileApp-DIZYvrhi.js +11 -0
- package/dist/assets/runtimeEndpointReset-BA2uP2rj.js +62 -0
- package/dist/assets/{runtimeSurface-DBiUWYK2.js → runtimeSurface-Der4qUnI.js} +1 -1
- package/dist/assets/useAppFontEffects-Bfw_d5eB.js +212 -0
- package/dist/assets/{useFilesViewSearch-BWABG6pS.js → useFilesViewSearch-Budwejnx.js} +3 -3
- package/dist/assets/useGitHubRemoteSearch-gUdylYy3.js +1 -0
- package/dist/assets/{useSwitcherItems-BSTSev5C.js → useSwitcherItems-yHSMduoo.js} +1 -1
- package/dist/assets/{vendor-aparajita-capacitor-secure-storage-BYohCVY0.js → vendor-aparajita-capacitor-secure-storage-BDrMx_CE.js} +1 -1
- package/dist/assets/{vendor-base-ui-BscvGUFt.js → vendor-base-ui-CKRUCG-f.js} +1 -1
- package/dist/assets/{vendor-boot-Dgb9NVFe.js → vendor-boot-EC6IyLt1.js} +13 -13
- package/dist/assets/{vendor-capacitor-app-BjdQVib9.js → vendor-capacitor-app-BaupizkW.js} +1 -1
- package/dist/assets/{vendor-capacitor-keyboard-eTtI5go3.js → vendor-capacitor-keyboard-9BVxykO7.js} +1 -1
- package/dist/assets/{vendor-capacitor-status-bar-9rNIGxlO.js → vendor-capacitor-status-bar-BsrUwiaA.js} +1 -1
- package/dist/assets/{vendor-codemirror-autocomplete-DxS3jwvE.js → vendor-codemirror-autocomplete-CGpAsPWp.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-angular-DdjXl9e2.js → vendor-codemirror-lang-angular-CDJoHJSY.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-cpp--aMr7NVt.js → vendor-codemirror-lang-cpp-BmHofQls.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-css-CZ_qxZY9.js → vendor-codemirror-lang-css-RM2HqXZ0.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-go-Ca-y2Alu.js → vendor-codemirror-lang-go-Crwca_X7.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-html-COZ0L5wT.js → vendor-codemirror-lang-html-CHSHUpwq.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-java-D3Rf3QNJ.js → vendor-codemirror-lang-java-lhQXgWu0.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-javascript-DwJ-IvCs.js → vendor-codemirror-lang-javascript-Dw4kFO4e.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-jinja-D_5lod6k.js → vendor-codemirror-lang-jinja-_pAC3UTN.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-json-BG8C7OpC.js → vendor-codemirror-lang-json-B-b1vAv-.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-less-CVEkoaTw.js → vendor-codemirror-lang-less-xIgOi1ze.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-liquid-U9vj0m8w.js → vendor-codemirror-lang-liquid-CP49m5dB.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-markdown-DqlYH9gY.js → vendor-codemirror-lang-markdown-BTht2ATe.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-php-BFEiEVA1.js → vendor-codemirror-lang-php-BguZDhaO.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-python-Cz1dQXQd.js → vendor-codemirror-lang-python-CH6_em9L.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-rust-C_CoD9mj.js → vendor-codemirror-lang-rust-EG_DtGyi.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sass-BuR0aKh5.js → vendor-codemirror-lang-sass-BknY5Qpo.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sql-DggNUjdM.js → vendor-codemirror-lang-sql-B0f-qCZo.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-vue-DFZHi2J3.js → vendor-codemirror-lang-vue-CyGn9snv.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-wast-zuTN3SHT.js → vendor-codemirror-lang-wast-CsFfSyyB.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-xml-CrcvhI-k.js → vendor-codemirror-lang-xml-Cdan_Jp1.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-yaml-DcVWsakb.js → vendor-codemirror-lang-yaml-COI5hck8.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-CCLITgCF.js → vendor-codemirror-language-data-CqU7kHmg.js} +2 -2
- package/dist/assets/{vendor-codemirror-search-H7NOEdbX.js → vendor-codemirror-search-DUfSCF9S.js} +1 -1
- package/dist/assets/{vendor-lezer-cpp-C8aD2KAr.js → vendor-lezer-cpp-DMZOJzBa.js} +1 -1
- package/dist/assets/{vendor-lezer-css-2lbTJF-Y.js → vendor-lezer-css-DUkkbMp7.js} +1 -1
- package/dist/assets/{vendor-lezer-go-Bw6LFTrZ.js → vendor-lezer-go-CHIhCNY6.js} +1 -1
- package/dist/assets/{vendor-lezer-html-D7ym2z7S.js → vendor-lezer-html-B3h0MOrG.js} +1 -1
- package/dist/assets/{vendor-lezer-java-CZhK7w21.js → vendor-lezer-java-tMazV_6X.js} +1 -1
- package/dist/assets/{vendor-lezer-javascript-rpKeTHZp.js → vendor-lezer-javascript-ctwLWf4v.js} +1 -1
- package/dist/assets/{vendor-lezer-json-C7jwsd2G.js → vendor-lezer-json-BP_UAzLL.js} +1 -1
- package/dist/assets/{vendor-lezer-lr-DR-ylqNN.js → vendor-lezer-lr-B8TQctNw.js} +1 -1
- package/dist/assets/{vendor-lezer-markdown-Bir0m5nB.js → vendor-lezer-markdown-aGLZf_3h.js} +1 -1
- package/dist/assets/{vendor-lezer-php-y0hIEfo1.js → vendor-lezer-php-D5zCNzlt.js} +1 -1
- package/dist/assets/{vendor-lezer-python-D64A9lNV.js → vendor-lezer-python-EJ4Im4y2.js} +1 -1
- package/dist/assets/{vendor-lezer-rust-E3ZA9T2L.js → vendor-lezer-rust-DO5c7OtA.js} +1 -1
- package/dist/assets/{vendor-lezer-sass-C5UFI9SP.js → vendor-lezer-sass-CMi6zfXI.js} +1 -1
- package/dist/assets/{vendor-lezer-xml-DOy7FzCR.js → vendor-lezer-xml-0MHMeZDp.js} +1 -1
- package/dist/assets/{vendor-lezer-yaml-kEjaSCvZ.js → vendor-lezer-yaml-BE2EFjpA.js} +1 -1
- package/dist/assets/{vendor-replit-codemirror-vim-BLfh0LPy.js → vendor-replit-codemirror-vim-AnOuN8yJ.js} +1 -1
- package/dist/assets/{web-components-CdMfsnXE.js → web-components-CeHLxvED.js} +3 -3
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/dist/sw.js +1 -1
- package/package.json +1 -2
- package/server/index.js +69 -30
- package/server/lib/client-auth/DOCUMENTATION.md +15 -1
- package/server/lib/client-auth/pairing.js +2 -12
- package/server/lib/client-auth/remote-clients.js +2 -12
- package/server/lib/cloudflare-tunnel.js +0 -132
- package/server/lib/fs/DOCUMENTATION.md +8 -0
- package/server/lib/fs/atomic-write.js +111 -0
- package/server/lib/fs/atomic-write.test.js +133 -0
- package/server/lib/notifications/DOCUMENTATION.md +43 -32
- package/server/lib/notifications/pi-notification-watcher.js +8 -7
- package/server/lib/notifications/pi-notification-watcher.test.js +88 -2
- package/server/lib/pi/routes-extension-events.test.js +231 -0
- package/server/lib/pi/routes.js +137 -4
- package/server/lib/pi/routes.test.js +248 -2
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +17 -4
- package/server/lib/pi/session-daemon/daemon-process.js +2 -0
- package/server/lib/pi/session-daemon/engines/index.js +6 -0
- package/server/lib/pi/session-daemon/extension-bridge-draft.test.js +1 -1
- package/server/lib/pi/session-daemon/extension-bridge.js +24 -0
- package/server/lib/pi/session-daemon/extension-message-render.js +74 -0
- package/server/lib/pi/session-daemon/extension-message-render.test.js +164 -0
- package/server/lib/pi/session-daemon/extension-tool-render.js +13 -6
- package/server/lib/pi/session-daemon/pending-input.js +188 -0
- package/server/lib/pi/session-daemon/pending-input.test.js +202 -0
- package/server/lib/pi/session-daemon/session-daemon-engines.test.js +828 -0
- package/server/lib/pi/session-daemon/session-daemon-extensions.test.js +296 -6
- package/server/lib/pi/session-daemon/session-daemon-turn.e2e.test.js +9 -0
- package/server/lib/pi/session-daemon/session-daemon.js +219 -19
- package/server/lib/pi/session-daemon/session-daemon.test.js +30 -2
- package/server/lib/pi/session-daemon/session-engine-router.js +390 -0
- package/server/lib/pi/session-daemon/session-engine-router.test.js +515 -0
- package/server/lib/pi/session-daemon/session-engines.js +467 -0
- package/server/lib/pi/session-daemon/session-engines.test.js +383 -0
- package/server/lib/pi/snippets-store.js +8 -17
- package/server/lib/pi/ui-settings-store.js +6 -10
- package/server/lib/pi/ui-settings-store.test.js +37 -1
- package/server/lib/relay/DOCUMENTATION.md +6 -4
- package/server/lib/relay/identity-store.js +116 -0
- package/server/lib/relay/identity-store.test.js +169 -0
- package/server/lib/relay/identity.js +6 -4
- package/server/lib/relay/server-id.js +63 -0
- package/server/lib/relay/server-id.test.js +132 -0
- package/server/lib/relay/signing-key.js +14 -11
- package/server/lib/security/bind-host.js +6 -2
- package/server/lib/security/bind-host.test.js +17 -0
- package/server/lib/server/core-routes.js +27 -1
- package/server/lib/server/lan-addresses.js +18 -6
- package/server/lib/server/lan-addresses.test.js +28 -0
- package/server/lib/server/tunnel-auth.js +47 -7
- package/server/lib/server/tunnel-auth.rate-limit.test.js +164 -0
- package/server/lib/server/tunnel-service.DOCUMENTATION.md +3 -4
- package/server/lib/server/tunnel-service.js +23 -20
- package/server/lib/server/tunnel-service.test.js +19 -2
- package/server/lib/stt/config-store.js +5 -15
- package/server/lib/tailscale/DOCUMENTATION.md +264 -0
- package/server/lib/tailscale/routes.js +45 -0
- package/server/lib/tailscale/service.js +959 -0
- package/server/lib/tailscale/tailscale.js +302 -0
- package/server/lib/tailscale/tailscale.test.js +1861 -0
- package/server/lib/tunnels/DOCUMENTATION.md +3 -4
- package/server/lib/tunnels/providers/cloudflare.js +1 -22
- package/server/lib/tunnels/types.js +0 -2
- package/server/lib/ui-auth/DOCUMENTATION.md +31 -0
- package/server/lib/ui-auth/ui-auth.js +80 -6
- package/server/lib/ui-auth/ui-auth.test.js +136 -0
- package/server/lib/ui-auth/ui-passkeys.js +2 -13
- package/server/lib/update-job-store.js +4 -6
- package/dist/assets/DiffView-hz90_htv.js +0 -18
- package/dist/assets/FilesView-DaqkPMqx.js +0 -6
- package/dist/assets/PierreDiffViewer-BeGpdI0x.js +0 -134
- package/dist/assets/PullRequestsSurface-D9beq2x9.js +0 -2
- package/dist/assets/SessionSwitcherContent-DElQ_cjm.js +0 -1
- package/dist/assets/SessionSwitcherDropdown-JaIDcDIj.js +0 -2
- package/dist/assets/SessionUnreadDot-Czfvjbdi.js +0 -1
- package/dist/assets/SettingsView-C_GC1Mx3.js +0 -6
- package/dist/assets/index-BnZVqcki.js +0 -11
- package/dist/assets/index-BnieExes.css +0 -1
- package/dist/assets/main-6YKi4QM2.js +0 -2
- package/dist/assets/main-CWdWdhdL.js +0 -136
- package/dist/assets/mobile-0LY-2fxw.js +0 -2
- package/dist/assets/pi-session-focus-preference-BC-ze1oC.js +0 -10
- package/dist/assets/renderElectronMiniChatApp-DETQLjFi.js +0 -2
- package/dist/assets/renderMobileApp-DS0FDQLg.js +0 -11
- package/dist/assets/runtimeEndpointReset-BqqXMwE9.js +0 -62
- package/dist/assets/useAppFontEffects-BisjofNZ.js +0 -212
- package/dist/assets/useGitHubRemoteSearch-Bsf2YeQP.js +0 -1
- package/dist/assets/vendor-capacitor-push-notifications-CBKq2Arn.js +0 -1
- package/server/lib/notifications/delivery-runtime.js +0 -314
- package/server/lib/notifications/delivery-runtime.test.js +0 -85
- package/server/lib/notifications/routes.js +0 -74
- package/server/lib/relay/service.js +0 -9
package/server/lib/pi/routes.js
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
import { createPiUiSettingsStore } from './ui-settings-store.js';
|
|
25
25
|
import { createPiSnippetsStore } from './snippets-store.js';
|
|
26
26
|
import { isValidSendOperationId, isValidStreamEpoch } from './session-daemon/send-operation-registry.js';
|
|
27
|
+
import { ENGINE_HANDLER_COMMANDS, ENGINE_UNSUPPORTED_OPERATION, isValidEngineId } from './session-daemon/session-engines.js';
|
|
27
28
|
import {
|
|
28
29
|
DEFAULT_EVENT_STREAM_MAX_BUFFERED_BYTES,
|
|
29
30
|
createPiEventStreamRegistry,
|
|
@@ -69,6 +70,7 @@ const writeDaemonError = (res, error) => {
|
|
|
69
70
|
: code === 'INVALID_SESSION'
|
|
70
71
|
? 404
|
|
71
72
|
: code === 'SESSION_IN_USE' || code === 'OPERATION_PAYLOAD_MISMATCH' || code === 'STALE_STREAM_EPOCH'
|
|
73
|
+
|| code === ENGINE_UNSUPPORTED_OPERATION
|
|
72
74
|
? 409
|
|
73
75
|
: code === 'OPERATION_EXPIRED'
|
|
74
76
|
? 410
|
|
@@ -108,6 +110,7 @@ const projectSession = (value) => {
|
|
|
108
110
|
return {
|
|
109
111
|
id: value.id,
|
|
110
112
|
directory: value.directory,
|
|
113
|
+
...(isValidEngineId(value.engine) ? { engine: value.engine } : {}),
|
|
111
114
|
...(typeof value.title === 'string' ? { title: value.title } : {}),
|
|
112
115
|
...(typeof value.parentId === 'string' || value.parentId === null ? { parentId: value.parentId } : {}),
|
|
113
116
|
createdAt: value.createdAt,
|
|
@@ -142,15 +145,71 @@ const projectSessionList = (sessions) => {
|
|
|
142
145
|
return sessions.map((item) => {
|
|
143
146
|
if (!item || typeof item !== 'object' || !Number.isFinite(item.updatedAt)) throw protocolMismatch();
|
|
144
147
|
const live = projectListLiveStatus(item.live);
|
|
148
|
+
const inputState = projectInputState(item.inputState, { withSequence: true });
|
|
145
149
|
return {
|
|
146
150
|
session: projectSession(item.session),
|
|
147
151
|
...(typeof item.preview === 'string' ? { preview: item.preview } : {}),
|
|
148
152
|
updatedAt: item.updatedAt,
|
|
149
153
|
...(live ? { live } : {}),
|
|
154
|
+
...(inputState ? { inputState } : {}),
|
|
150
155
|
};
|
|
151
156
|
});
|
|
152
157
|
};
|
|
153
158
|
|
|
159
|
+
// Daemon-level pending input: whether a session is blocked waiting for the
|
|
160
|
+
// user. `null` means authoritatively nothing pending; `undefined` means
|
|
161
|
+
// unknown (older daemon) or malformed. Unknown kind strings normalize to
|
|
162
|
+
// 'input'; a zero count normalizes to null. Only the three wire keys cross
|
|
163
|
+
// the public boundary.
|
|
164
|
+
const projectPendingInputSummary = (value) => {
|
|
165
|
+
if (value === null) return null;
|
|
166
|
+
if (value === undefined) return undefined;
|
|
167
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return undefined;
|
|
168
|
+
if (typeof value.count !== 'number' || !Number.isSafeInteger(value.count)) return undefined;
|
|
169
|
+
if (value.count === 0) return null;
|
|
170
|
+
if (value.count < 0) return undefined;
|
|
171
|
+
if (typeof value.since !== 'number' || !Number.isFinite(value.since) || value.since <= 0) return undefined;
|
|
172
|
+
return {
|
|
173
|
+
count: Math.min(value.count, 99),
|
|
174
|
+
kind: typeof value.kind === 'string' && ['input', 'approval'].includes(value.kind) ? value.kind : 'input',
|
|
175
|
+
since: value.since,
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// Projects `inputState` like `projectListLiveStatus` projects `live`: a
|
|
180
|
+
// malformed value is omitted (unknown) rather than failing the row, and
|
|
181
|
+
// only whitelisted fields cross the public boundary. List rows carry
|
|
182
|
+
// `{ pending, sequence }`; snapshots and details carry `{ pending }`.
|
|
183
|
+
const projectInputState = (value, { withSequence = false } = {}) => {
|
|
184
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return undefined;
|
|
185
|
+
const pending = projectPendingInputSummary(value.pending);
|
|
186
|
+
if (pending === undefined) return undefined;
|
|
187
|
+
if (withSequence) {
|
|
188
|
+
if (!Number.isSafeInteger(value.sequence) || value.sequence < 0) return undefined;
|
|
189
|
+
return { pending, sequence: value.sequence };
|
|
190
|
+
}
|
|
191
|
+
return { pending };
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
const projectPendingInputList = (value) => {
|
|
195
|
+
if (!value || typeof value !== 'object' || !Array.isArray(value.sessions)) throw protocolMismatch();
|
|
196
|
+
const sessions = [];
|
|
197
|
+
for (const item of value.sessions) {
|
|
198
|
+
if (!item || typeof item !== 'object'
|
|
199
|
+
|| typeof item.sessionId !== 'string' || item.sessionId.length === 0
|
|
200
|
+
|| typeof item.directory !== 'string' || item.directory.length === 0) continue;
|
|
201
|
+
const pending = projectPendingInputSummary(item.pending);
|
|
202
|
+
if (!pending) continue;
|
|
203
|
+
sessions.push({ sessionId: item.sessionId, directory: item.directory, pending });
|
|
204
|
+
}
|
|
205
|
+
if (!Number.isSafeInteger(value.sequence) || value.sequence < 0) throw protocolMismatch();
|
|
206
|
+
return {
|
|
207
|
+
sessions,
|
|
208
|
+
sequence: value.sequence,
|
|
209
|
+
...(typeof value.streamEpoch === 'string' && value.streamEpoch ? { streamEpoch: value.streamEpoch } : {}),
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
|
|
154
213
|
/**
|
|
155
214
|
* Public-protocol sanitizer for Pi `Usage`. The server already coerces each
|
|
156
215
|
* numeric field to a finite, non-negative value before the message leaves
|
|
@@ -239,10 +298,10 @@ const sanitizeNavigation = (value) => {
|
|
|
239
298
|
};
|
|
240
299
|
};
|
|
241
300
|
|
|
242
|
-
|
|
301
|
+
const projectRenderLines = (render, keys) => {
|
|
243
302
|
if (!render || typeof render !== 'object' || Array.isArray(render)) return undefined;
|
|
244
303
|
const projected = {};
|
|
245
|
-
for (const key of
|
|
304
|
+
for (const key of keys) {
|
|
246
305
|
const lines = render[key];
|
|
247
306
|
if (Array.isArray(lines)) {
|
|
248
307
|
const sanitized = [];
|
|
@@ -260,6 +319,17 @@ export const projectToolRender = (render) => {
|
|
|
260
319
|
return Object.keys(projected).length > 0 ? projected : undefined;
|
|
261
320
|
};
|
|
262
321
|
|
|
322
|
+
export const projectToolRender = (render) => projectRenderLines(render, ['call', 'result', 'resultExpanded']);
|
|
323
|
+
|
|
324
|
+
// Extension message renders share the tool-render line bounds. An expanded
|
|
325
|
+
// slot without a collapsed slot is dropped; malformed shapes degrade to
|
|
326
|
+
// undefined instead of failing the frame or message.
|
|
327
|
+
export const projectMessageRender = (render) => {
|
|
328
|
+
const projected = projectRenderLines(render, ['message', 'messageExpanded']);
|
|
329
|
+
if (!projected || !projected.message) return undefined;
|
|
330
|
+
return projected.messageExpanded ? projected : { message: projected.message };
|
|
331
|
+
};
|
|
332
|
+
|
|
263
333
|
const projectFilePart = (part) => {
|
|
264
334
|
// Optional fields degrade instead of failing the whole message. The daemon
|
|
265
335
|
// only emits inline data URLs; never pass a filesystem or remote URL on.
|
|
@@ -278,6 +348,7 @@ const projectSessionDetail = (value) => {
|
|
|
278
348
|
const message = item.message;
|
|
279
349
|
if (typeof message.id !== 'string' || typeof message.sessionId !== 'string' || typeof message.directory !== 'string'
|
|
280
350
|
|| !Number.isFinite(message.createdAt) || (message.role !== 'user' && message.role !== 'assistant' && message.role !== 'extension')) throw protocolMismatch();
|
|
351
|
+
const messageRender = message.role === 'extension' ? projectMessageRender(message.render) : undefined;
|
|
281
352
|
const projected = {
|
|
282
353
|
id: message.id, sessionId: message.sessionId, directory: message.directory, role: message.role, createdAt: message.createdAt,
|
|
283
354
|
...(typeof message.parentId === 'string' ? { parentId: message.parentId } : {}),
|
|
@@ -296,6 +367,7 @@ const projectSessionDetail = (value) => {
|
|
|
296
367
|
...(message.role === 'extension' && typeof message.customType === 'string' ? { customType: message.customType } : {}),
|
|
297
368
|
...(message.role === 'extension' && message.data !== undefined ? { data: message.data } : {}),
|
|
298
369
|
...(message.role === 'extension' && message.details !== undefined ? { details: message.details } : {}),
|
|
370
|
+
...(messageRender ? { render: messageRender } : {}),
|
|
299
371
|
};
|
|
300
372
|
const parts = item.parts.map((part) => {
|
|
301
373
|
if (!part || typeof part !== 'object' || typeof part.type !== 'string' || typeof part.id !== 'string' || !Number.isSafeInteger(part.index)) throw protocolMismatch();
|
|
@@ -329,6 +401,7 @@ const projectSessionDetail = (value) => {
|
|
|
329
401
|
: (isStreaming ? 'busy' : 'idle');
|
|
330
402
|
const retry = lifecycle === 'retry' ? projectRetryInfo(value.retry) : null;
|
|
331
403
|
const compaction = projectCompactionInfo(value.compaction);
|
|
404
|
+
const inputState = projectInputState(value.inputState);
|
|
332
405
|
return {
|
|
333
406
|
session: projectSession(value.session),
|
|
334
407
|
messages,
|
|
@@ -348,6 +421,7 @@ const projectSessionDetail = (value) => {
|
|
|
348
421
|
? { streamEpoch: value.streamEpoch }
|
|
349
422
|
: {}),
|
|
350
423
|
...projectExtensionSnapshotState(value),
|
|
424
|
+
...(inputState ? { inputState } : {}),
|
|
351
425
|
};
|
|
352
426
|
};
|
|
353
427
|
|
|
@@ -377,6 +451,21 @@ const projectProviders = (value) => {
|
|
|
377
451
|
};
|
|
378
452
|
};
|
|
379
453
|
|
|
454
|
+
const projectEngines = (value) => {
|
|
455
|
+
if (!value || typeof value !== 'object' || !Array.isArray(value.engines)) throw protocolMismatch();
|
|
456
|
+
return {
|
|
457
|
+
engines: value.engines.map((engine) => {
|
|
458
|
+
if (!engine || typeof engine !== 'object' || !isValidEngineId(engine.id)
|
|
459
|
+
|| typeof engine.label !== 'string' || !Array.isArray(engine.commands)) throw protocolMismatch();
|
|
460
|
+
return {
|
|
461
|
+
id: engine.id,
|
|
462
|
+
label: engine.label,
|
|
463
|
+
commands: engine.commands.filter((command) => ENGINE_HANDLER_COMMANDS.has(command)),
|
|
464
|
+
};
|
|
465
|
+
}),
|
|
466
|
+
};
|
|
467
|
+
};
|
|
468
|
+
|
|
380
469
|
const projectProviderConfig = (value) => {
|
|
381
470
|
const config = value?.config;
|
|
382
471
|
if (config === null) return { config: null, ...(value?.deferred === true ? { deferred: true } : {}) };
|
|
@@ -437,7 +526,12 @@ const projectProviderLogin = (value) => {
|
|
|
437
526
|
...(Number.isFinite(login.deviceCode.expiresInSeconds) ? { expiresInSeconds: login.deviceCode.expiresInSeconds } : {}),
|
|
438
527
|
};
|
|
439
528
|
}
|
|
440
|
-
if (login.error && typeof login.error.code === 'string')
|
|
529
|
+
if (login.error && typeof login.error.code === 'string') {
|
|
530
|
+
projected.error = {
|
|
531
|
+
code: login.error.code,
|
|
532
|
+
...(typeof login.error.message === 'string' && login.error.message.length <= 1_000 ? { message: login.error.message } : {}),
|
|
533
|
+
};
|
|
534
|
+
}
|
|
441
535
|
return { login: projected };
|
|
442
536
|
};
|
|
443
537
|
|
|
@@ -577,6 +671,7 @@ function projectExtensionSnapshotState(snapshot) {
|
|
|
577
671
|
...(Number.isFinite(entry.timeoutMs) ? { timeoutMs: Math.floor(entry.timeoutMs) } : {}),
|
|
578
672
|
}))
|
|
579
673
|
: undefined;
|
|
674
|
+
|
|
580
675
|
const extensionPanels = Array.isArray(snapshot.extensionPanels)
|
|
581
676
|
? snapshot.extensionPanels.filter((entry) => entry && typeof entry.id === 'string' && entry.id.length > 0).slice(0, 24).map(projectExtensionPanelPayload)
|
|
582
677
|
: undefined;
|
|
@@ -617,12 +712,24 @@ export const projectEventFrame = (frame) => {
|
|
|
617
712
|
: undefined;
|
|
618
713
|
const common = { protocolVersion: 1, kind: 'event', name: frame.event, sequence: frame.sequence, sessionId, directory, ...(streamEpoch ? { streamEpoch } : {}) };
|
|
619
714
|
switch (frame.event) {
|
|
715
|
+
case 'session.input': {
|
|
716
|
+
const pending = projectPendingInputSummary(frame.payload.pending);
|
|
717
|
+
if (pending === undefined) return null;
|
|
718
|
+
return {
|
|
719
|
+
...common,
|
|
720
|
+
payload: {
|
|
721
|
+
pending,
|
|
722
|
+
...(Number.isFinite(frame.payload.serverNow) ? { serverNow: frame.payload.serverNow } : {}),
|
|
723
|
+
},
|
|
724
|
+
};
|
|
725
|
+
}
|
|
620
726
|
case 'session.snapshot': {
|
|
621
727
|
const snapshot = frame.payload;
|
|
622
728
|
const extensionSnapshot = projectExtensionSnapshotState(snapshot);
|
|
623
729
|
const lifecycle = ['idle', 'busy', 'retry', 'error', 'interrupted'].includes(snapshot.lifecycle) ? snapshot.lifecycle : 'idle';
|
|
624
730
|
const retry = lifecycle === 'retry' ? projectRetryInfo(snapshot.retry) : null;
|
|
625
731
|
const compaction = projectCompactionInfo(snapshot.compaction);
|
|
732
|
+
const inputState = projectInputState(snapshot.inputState);
|
|
626
733
|
return { ...common, payload: { snapshot: {
|
|
627
734
|
sessionId, directory, isStreaming: snapshot.isStreaming === true,
|
|
628
735
|
lifecycle,
|
|
@@ -638,6 +745,7 @@ export const projectEventFrame = (frame) => {
|
|
|
638
745
|
lastSequence: Number.isSafeInteger(snapshot.lastSequence) ? snapshot.lastSequence : frame.sequence,
|
|
639
746
|
...(snapshot.resync === true ? { resync: true } : {}),
|
|
640
747
|
...extensionSnapshot,
|
|
748
|
+
...(inputState ? { inputState } : {}),
|
|
641
749
|
} } };
|
|
642
750
|
}
|
|
643
751
|
case 'session.lifecycle': {
|
|
@@ -734,7 +842,8 @@ export const projectEventFrame = (frame) => {
|
|
|
734
842
|
if (typeof frame.payload.customType !== 'string' || frame.payload.customType.length === 0 || frame.payload.customType.length > 256) return null;
|
|
735
843
|
if (typeof frame.payload.text !== 'string') return null;
|
|
736
844
|
if (!Number.isFinite(frame.payload.createdAt)) return null;
|
|
737
|
-
|
|
845
|
+
const render = projectMessageRender(frame.payload.render);
|
|
846
|
+
return { ...common, payload: { id: frame.payload.id.slice(0, 512), customType: frame.payload.customType.slice(0, 256), text: frame.payload.text.slice(0, 50000), ...(frame.payload.details !== undefined ? { details: frame.payload.details } : {}), ...(render ? { render } : {}), createdAt: frame.payload.createdAt } };
|
|
738
847
|
}
|
|
739
848
|
case 'extension.notify': {
|
|
740
849
|
if (typeof frame.payload.message !== 'string' || frame.payload.message.length === 0) return null;
|
|
@@ -1113,6 +1222,15 @@ export const registerPiRuntimeRoutes = (app, {
|
|
|
1113
1222
|
}
|
|
1114
1223
|
});
|
|
1115
1224
|
|
|
1225
|
+
app.get('/api/pi/engines', async (_req, res) => {
|
|
1226
|
+
try {
|
|
1227
|
+
const result = await getDaemonRuntime(getPiSessionDaemonRuntime).request('engines.list');
|
|
1228
|
+
res.json(projectEngines(result));
|
|
1229
|
+
} catch (error) {
|
|
1230
|
+
writeDaemonError(res, error);
|
|
1231
|
+
}
|
|
1232
|
+
});
|
|
1233
|
+
|
|
1116
1234
|
app.post('/api/pi/providers/refresh', async (req, res) => {
|
|
1117
1235
|
const directory = typeof req.body?.directory === 'string' && req.body.directory.length > 0 ? req.body.directory : undefined;
|
|
1118
1236
|
try {
|
|
@@ -1689,8 +1807,12 @@ export const registerPiRuntimeRoutes = (app, {
|
|
|
1689
1807
|
...(typeof directory === 'string' ? { directory } : {}),
|
|
1690
1808
|
});
|
|
1691
1809
|
const archived = await archiveStore.read();
|
|
1810
|
+
const incompleteEngines = Array.isArray(result?.incompleteEngines)
|
|
1811
|
+
? result.incompleteEngines.filter((engineId) => isValidEngineId(engineId))
|
|
1812
|
+
: [];
|
|
1692
1813
|
res.json({
|
|
1693
1814
|
...(typeof result?.streamEpoch === 'string' && result.streamEpoch ? { streamEpoch: result.streamEpoch } : {}),
|
|
1815
|
+
...(incompleteEngines.length > 0 ? { incompleteEngines } : {}),
|
|
1694
1816
|
sessions: projectSessionList(result?.sessions).map((item) => archived[item.session.id]
|
|
1695
1817
|
? { ...item, session: { ...item.session, archived: true, timeArchived: archived[item.session.id] } }
|
|
1696
1818
|
: item),
|
|
@@ -1700,6 +1822,17 @@ export const registerPiRuntimeRoutes = (app, {
|
|
|
1700
1822
|
}
|
|
1701
1823
|
});
|
|
1702
1824
|
|
|
1825
|
+
// Registered before any `/api/pi/sessions/:id` route so `pending-input`
|
|
1826
|
+
// is not captured as a session id.
|
|
1827
|
+
app.get('/api/pi/sessions/pending-input', async (_req, res) => {
|
|
1828
|
+
try {
|
|
1829
|
+
const result = await getDaemonRuntime(getPiSessionDaemonRuntime).request('sessions.pendingInput');
|
|
1830
|
+
res.json(projectPendingInputList(result));
|
|
1831
|
+
} catch (error) {
|
|
1832
|
+
writeDaemonError(res, error);
|
|
1833
|
+
}
|
|
1834
|
+
});
|
|
1835
|
+
|
|
1703
1836
|
app.patch('/api/pi/sessions/:sessionId', async (req, res) => {
|
|
1704
1837
|
const sessionId = req.params.sessionId;
|
|
1705
1838
|
const title = req.body?.title;
|
|
@@ -528,7 +528,10 @@ describe('Pi runtime route', () => {
|
|
|
528
528
|
id: 'login-1', providerId: 'provider', state: 'pending',
|
|
529
529
|
deviceCode: { userCode: 'ABCD', verificationUri: 'https://example.test/device', secret: 'never-public' },
|
|
530
530
|
} };
|
|
531
|
-
if (command === 'providers.login.respond') return { login: {
|
|
531
|
+
if (command === 'providers.login.respond') return { login: {
|
|
532
|
+
id: 'login-1', providerId: 'provider', state: 'failed',
|
|
533
|
+
error: { code: 'PROVIDER_AUTH_REQUIRED', message: 'OAuth state mismatch', stack: 'never-public' },
|
|
534
|
+
} };
|
|
532
535
|
if (command === 'providers.logout') return { providerId: 'provider', authenticated: false };
|
|
533
536
|
throw new Error(`Unexpected command ${command}`);
|
|
534
537
|
},
|
|
@@ -543,7 +546,9 @@ describe('Pi runtime route', () => {
|
|
|
543
546
|
const login = await fetch(`${base}/login`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ type: 'api_key', apiKey: 'never-return-this' }) });
|
|
544
547
|
expect(login.status).toBe(202);
|
|
545
548
|
await expect(login.json()).resolves.toEqual({ login: { id: 'login-1', providerId: 'provider', state: 'pending', deviceCode: { userCode: 'ABCD', verificationUri: 'https://example.test/device' } } });
|
|
546
|
-
await expect((await fetch(`${base}/login/login-1/respond`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ value: 'manual-code' }) })).json()).resolves.toEqual({
|
|
549
|
+
await expect((await fetch(`${base}/login/login-1/respond`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ value: 'manual-code' }) })).json()).resolves.toEqual({
|
|
550
|
+
login: { id: 'login-1', providerId: 'provider', state: 'failed', error: { code: 'PROVIDER_AUTH_REQUIRED', message: 'OAuth state mismatch' } },
|
|
551
|
+
});
|
|
547
552
|
await expect((await fetch(`${base}/logout`, { method: 'POST' })).json()).resolves.toEqual({ providerId: 'provider', authenticated: false });
|
|
548
553
|
expect(calls).toEqual([
|
|
549
554
|
{ command: 'providers.status', payload: { providerId: 'provider' } },
|
|
@@ -953,6 +958,139 @@ describe('Pi runtime route', () => {
|
|
|
953
958
|
}
|
|
954
959
|
});
|
|
955
960
|
|
|
961
|
+
it('whitelists pending input state on list rows and drops malformed values', async () => {
|
|
962
|
+
const row = (id, inputState) => ({
|
|
963
|
+
session: { id, directory: '/workspace', createdAt: 1, updatedAt: 2 },
|
|
964
|
+
updatedAt: 2,
|
|
965
|
+
...(inputState !== undefined ? { inputState } : {}),
|
|
966
|
+
});
|
|
967
|
+
const runtime = {
|
|
968
|
+
health: async () => ({ state: 'ready', protocolVersion: 1, capabilities: ['sessions.list'] }),
|
|
969
|
+
request: async () => ({
|
|
970
|
+
streamEpoch: 'epoch-1',
|
|
971
|
+
sessions: [
|
|
972
|
+
row('pending', { pending: { count: 2, kind: 'approval', since: 50, sessionId: 'sneaky' }, sequence: 7 }),
|
|
973
|
+
row('none', { pending: null, sequence: 8 }),
|
|
974
|
+
row('bad-pending', { pending: { count: 'many' }, sequence: 1 }),
|
|
975
|
+
row('bad-sequence', { pending: { count: 1, kind: 'input', since: 5 }, sequence: -1 }),
|
|
976
|
+
row('unknown'),
|
|
977
|
+
],
|
|
978
|
+
}),
|
|
979
|
+
};
|
|
980
|
+
const app = express();
|
|
981
|
+
registerPiRuntimeRoutes(app, { getPiSessionDaemonRuntime: () => runtime });
|
|
982
|
+
server = await listen(app);
|
|
983
|
+
|
|
984
|
+
const response = await fetch(`http://127.0.0.1:${server.address().port}/api/pi/sessions?directory=%2Fworkspace`);
|
|
985
|
+
expect(response.status).toBe(200);
|
|
986
|
+
const body = await response.json();
|
|
987
|
+
const byId = new Map(body.sessions.map((item) => [item.session.id, item]));
|
|
988
|
+
expect(body.sessions).toHaveLength(5);
|
|
989
|
+
expect(byId.get('pending').inputState).toEqual({ pending: { count: 2, kind: 'approval', since: 50 }, sequence: 7 });
|
|
990
|
+
expect(byId.get('none').inputState).toEqual({ pending: null, sequence: 8 });
|
|
991
|
+
for (const id of ['bad-pending', 'bad-sequence', 'unknown']) {
|
|
992
|
+
expect(byId.get(id).inputState).toBeUndefined();
|
|
993
|
+
}
|
|
994
|
+
});
|
|
995
|
+
|
|
996
|
+
it('projects pending input state on session details and omits malformed values', async () => {
|
|
997
|
+
const detail = (inputState) => ({
|
|
998
|
+
session: { id: 'pi-session-9', directory: '/workspace', createdAt: 1, updatedAt: 2 },
|
|
999
|
+
messages: [],
|
|
1000
|
+
lastSequence: 4,
|
|
1001
|
+
isStreaming: false,
|
|
1002
|
+
lifecycle: 'idle',
|
|
1003
|
+
...(inputState !== undefined ? { inputState } : {}),
|
|
1004
|
+
});
|
|
1005
|
+
const seen = [];
|
|
1006
|
+
const runtime = {
|
|
1007
|
+
health: async () => ({ state: 'ready', protocolVersion: 1, capabilities: [] }),
|
|
1008
|
+
request: async (command) => {
|
|
1009
|
+
seen.push(command);
|
|
1010
|
+
return detail(seen.length === 1
|
|
1011
|
+
? { pending: { count: 1, kind: 'input', since: 9 } }
|
|
1012
|
+
: { pending: { count: 1, kind: 'input' } });
|
|
1013
|
+
},
|
|
1014
|
+
};
|
|
1015
|
+
const app = express();
|
|
1016
|
+
registerPiRuntimeRoutes(app, { getPiSessionDaemonRuntime: () => runtime, archiveStore: { read: async () => ({}) } });
|
|
1017
|
+
server = await listen(app);
|
|
1018
|
+
const base = `http://127.0.0.1:${server.address().port}/api/pi/sessions/pi-session-9`;
|
|
1019
|
+
|
|
1020
|
+
const first = await fetch(base);
|
|
1021
|
+
expect(first.status).toBe(200);
|
|
1022
|
+
await expect(first.json()).resolves.toMatchObject({ inputState: { pending: { count: 1, kind: 'input', since: 9 } } });
|
|
1023
|
+
|
|
1024
|
+
const second = await fetch(base);
|
|
1025
|
+
expect(second.status).toBe(200);
|
|
1026
|
+
const secondBody = await second.json();
|
|
1027
|
+
expect(secondBody.inputState).toBeUndefined();
|
|
1028
|
+
expect(seen).toEqual(['sessions.open', 'sessions.open']);
|
|
1029
|
+
});
|
|
1030
|
+
|
|
1031
|
+
it('serves sessions.pendingInput without capturing it as a session id', async () => {
|
|
1032
|
+
const calls = [];
|
|
1033
|
+
const runtime = {
|
|
1034
|
+
health: async () => ({ state: 'ready', protocolVersion: 1, capabilities: [] }),
|
|
1035
|
+
request: async (command, payload) => {
|
|
1036
|
+
calls.push({ command, payload });
|
|
1037
|
+
if (command === 'sessions.pendingInput') {
|
|
1038
|
+
return {
|
|
1039
|
+
sessions: [
|
|
1040
|
+
{ sessionId: 's1', directory: '/workspace', pending: { count: 1, kind: 'input', since: 50 } },
|
|
1041
|
+
{ sessionId: 's2', directory: '/workspace', pending: null },
|
|
1042
|
+
{ sessionId: '', directory: '/workspace', pending: { count: 1, kind: 'input', since: 51 } },
|
|
1043
|
+
{ sessionId: 's3', directory: '/workspace', pending: { count: 'many' } },
|
|
1044
|
+
],
|
|
1045
|
+
sequence: 12,
|
|
1046
|
+
streamEpoch: 'epoch-pending',
|
|
1047
|
+
credential: 'never-expose-this',
|
|
1048
|
+
};
|
|
1049
|
+
}
|
|
1050
|
+
return {
|
|
1051
|
+
session: { id: 'pi-session-9', directory: '/workspace', createdAt: 1, updatedAt: 2 },
|
|
1052
|
+
messages: [],
|
|
1053
|
+
lastSequence: 1,
|
|
1054
|
+
};
|
|
1055
|
+
},
|
|
1056
|
+
};
|
|
1057
|
+
const app = express();
|
|
1058
|
+
registerPiRuntimeRoutes(app, { getPiSessionDaemonRuntime: () => runtime, archiveStore: { read: async () => ({}) } });
|
|
1059
|
+
server = await listen(app);
|
|
1060
|
+
const base = `http://127.0.0.1:${server.address().port}/api/pi/sessions`;
|
|
1061
|
+
|
|
1062
|
+
const response = await fetch(`${base}/pending-input`);
|
|
1063
|
+
expect(response.status).toBe(200);
|
|
1064
|
+
await expect(response.json()).resolves.toEqual({
|
|
1065
|
+
sessions: [{ sessionId: 's1', directory: '/workspace', pending: { count: 1, kind: 'input', since: 50 } }],
|
|
1066
|
+
sequence: 12,
|
|
1067
|
+
streamEpoch: 'epoch-pending',
|
|
1068
|
+
});
|
|
1069
|
+
// The literal segment routes to the pending-input command, never to a
|
|
1070
|
+
// `:sessionId` detail read.
|
|
1071
|
+
expect(calls).toEqual([{ command: 'sessions.pendingInput', payload: undefined }]);
|
|
1072
|
+
|
|
1073
|
+
const detail = await fetch(`${base}/other-session`);
|
|
1074
|
+
expect(detail.status).toBe(200);
|
|
1075
|
+
expect(calls.at(-1)).toEqual({ command: 'sessions.open', payload: { sessionId: 'other-session' } });
|
|
1076
|
+
});
|
|
1077
|
+
|
|
1078
|
+
it('maps pending-input daemon errors instead of returning an empty list', async () => {
|
|
1079
|
+
const error = new Error('The Pi session does not exist.');
|
|
1080
|
+
error.code = 'INVALID_SESSION';
|
|
1081
|
+
const runtime = {
|
|
1082
|
+
health: async () => ({ state: 'ready', protocolVersion: 1, capabilities: [] }),
|
|
1083
|
+
request: async () => { throw error; },
|
|
1084
|
+
};
|
|
1085
|
+
const app = express();
|
|
1086
|
+
registerPiRuntimeRoutes(app, { getPiSessionDaemonRuntime: () => runtime });
|
|
1087
|
+
server = await listen(app);
|
|
1088
|
+
|
|
1089
|
+
const response = await fetch(`http://127.0.0.1:${server.address().port}/api/pi/sessions/pending-input`);
|
|
1090
|
+
expect(response.status).toBe(404);
|
|
1091
|
+
await expect(response.json()).resolves.toEqual({ error: { code: 'INVALID_SESSION' } });
|
|
1092
|
+
});
|
|
1093
|
+
|
|
956
1094
|
it('renames a session through the daemon without accepting a body session identity', async () => {
|
|
957
1095
|
const runtime = {
|
|
958
1096
|
health: async () => ({ state: 'ready', protocolVersion: 1, capabilities: ['sessions.rename'] }),
|
|
@@ -1093,6 +1231,114 @@ describe('Pi runtime route', () => {
|
|
|
1093
1231
|
}
|
|
1094
1232
|
});
|
|
1095
1233
|
|
|
1234
|
+
it('projects engine sessions and filters incompleteEngines without touching Pi rows', async () => {
|
|
1235
|
+
const listResult = {
|
|
1236
|
+
streamEpoch: 'epoch-engines',
|
|
1237
|
+
sessions: [
|
|
1238
|
+
{ session: { id: 'engine-session-1', directory: '/workspace', createdAt: 1, updatedAt: 2, engine: 'example-engine' }, updatedAt: 2 },
|
|
1239
|
+
{ session: { id: 'pi-session-1', directory: '/workspace', createdAt: 1, updatedAt: 2 }, updatedAt: 2 },
|
|
1240
|
+
{ session: { id: 'reserved', directory: '/workspace', createdAt: 1, updatedAt: 2, engine: 'pi' }, updatedAt: 2 },
|
|
1241
|
+
{ session: { id: 'bad', directory: '/workspace', createdAt: 1, updatedAt: 2, engine: 'Bad Id' }, updatedAt: 2 },
|
|
1242
|
+
{ session: { id: 'num', directory: '/workspace', createdAt: 1, updatedAt: 2, engine: 42 }, updatedAt: 2 },
|
|
1243
|
+
],
|
|
1244
|
+
incompleteEngines: ['example-engine', 'pi', 'Bad Id', 42],
|
|
1245
|
+
};
|
|
1246
|
+
const detail = {
|
|
1247
|
+
session: { id: 'engine-session-1', directory: '/workspace', createdAt: 1, updatedAt: 2, engine: 'example-engine' },
|
|
1248
|
+
messages: [],
|
|
1249
|
+
lastSequence: 4,
|
|
1250
|
+
isStreaming: false,
|
|
1251
|
+
lifecycle: 'idle',
|
|
1252
|
+
};
|
|
1253
|
+
const runtime = {
|
|
1254
|
+
request: async (command) => (command === 'sessions.list' ? listResult : detail),
|
|
1255
|
+
};
|
|
1256
|
+
const app = express();
|
|
1257
|
+
registerPiRuntimeRoutes(app, { getPiSessionDaemonRuntime: () => runtime, archiveStore: { read: async () => ({}) } });
|
|
1258
|
+
server = await listen(app);
|
|
1259
|
+
const base = `http://127.0.0.1:${server.address().port}/api/pi`;
|
|
1260
|
+
const listed = await fetch(`${base}/sessions?directory=%2Fworkspace`);
|
|
1261
|
+
expect(listed.status).toBe(200);
|
|
1262
|
+
await expect(listed.json()).resolves.toEqual({
|
|
1263
|
+
streamEpoch: 'epoch-engines',
|
|
1264
|
+
incompleteEngines: ['example-engine'],
|
|
1265
|
+
sessions: [
|
|
1266
|
+
{ session: { id: 'engine-session-1', directory: '/workspace', createdAt: 1, updatedAt: 2, engine: 'example-engine' }, updatedAt: 2 },
|
|
1267
|
+
{ session: { id: 'pi-session-1', directory: '/workspace', createdAt: 1, updatedAt: 2 }, updatedAt: 2 },
|
|
1268
|
+
{ session: { id: 'reserved', directory: '/workspace', createdAt: 1, updatedAt: 2 }, updatedAt: 2 },
|
|
1269
|
+
{ session: { id: 'bad', directory: '/workspace', createdAt: 1, updatedAt: 2 }, updatedAt: 2 },
|
|
1270
|
+
{ session: { id: 'num', directory: '/workspace', createdAt: 1, updatedAt: 2 }, updatedAt: 2 },
|
|
1271
|
+
],
|
|
1272
|
+
});
|
|
1273
|
+
|
|
1274
|
+
const read = await fetch(`${base}/sessions/engine-session-1`);
|
|
1275
|
+
expect(read.status).toBe(200);
|
|
1276
|
+
await expect(read.json()).resolves.toMatchObject({ session: { id: 'engine-session-1', engine: 'example-engine' } });
|
|
1277
|
+
});
|
|
1278
|
+
|
|
1279
|
+
it('omits incompleteEngines when absent or invalid and maps engine errors to 409', async () => {
|
|
1280
|
+
const runtime = {
|
|
1281
|
+
request: async (command) => {
|
|
1282
|
+
if (command === 'sessions.list') return { sessions: [], incompleteEngines: ['pi', 42] };
|
|
1283
|
+
const error = new Error('ENGINE_UNSUPPORTED_OPERATION');
|
|
1284
|
+
error.code = 'ENGINE_UNSUPPORTED_OPERATION';
|
|
1285
|
+
throw error;
|
|
1286
|
+
},
|
|
1287
|
+
};
|
|
1288
|
+
const app = express();
|
|
1289
|
+
registerPiRuntimeRoutes(app, { getPiSessionDaemonRuntime: () => runtime, archiveStore: { read: async () => ({}) } });
|
|
1290
|
+
server = await listen(app);
|
|
1291
|
+
const base = `http://127.0.0.1:${server.address().port}/api/pi`;
|
|
1292
|
+
const listed = await fetch(`${base}/sessions?directory=%2Fworkspace`);
|
|
1293
|
+
expect(listed.status).toBe(200);
|
|
1294
|
+
await expect(listed.json()).resolves.toEqual({ sessions: [] });
|
|
1295
|
+
|
|
1296
|
+
const unsupported = await fetch(`${base}/sessions/engine-session-9`);
|
|
1297
|
+
expect(unsupported.status).toBe(409);
|
|
1298
|
+
await expect(unsupported.json()).resolves.toEqual({ error: { code: 'ENGINE_UNSUPPORTED_OPERATION' } });
|
|
1299
|
+
});
|
|
1300
|
+
|
|
1301
|
+
it('projects the engine collection through a whitelisting projector', async () => {
|
|
1302
|
+
const runtime = {
|
|
1303
|
+
request: async (command) => {
|
|
1304
|
+
expect(command).toBe('engines.list');
|
|
1305
|
+
return {
|
|
1306
|
+
engines: [
|
|
1307
|
+
{ id: 'example-engine', label: 'Example', commands: ['sessions.open', 'sessions.create', 'bogus', 42] },
|
|
1308
|
+
{ id: 'other', label: 'Other', commands: [] },
|
|
1309
|
+
],
|
|
1310
|
+
};
|
|
1311
|
+
},
|
|
1312
|
+
};
|
|
1313
|
+
const app = express();
|
|
1314
|
+
registerPiRuntimeRoutes(app, { getPiSessionDaemonRuntime: () => runtime });
|
|
1315
|
+
server = await listen(app);
|
|
1316
|
+
const response = await fetch(`http://127.0.0.1:${server.address().port}/api/pi/engines`);
|
|
1317
|
+
expect(response.status).toBe(200);
|
|
1318
|
+
await expect(response.json()).resolves.toEqual({
|
|
1319
|
+
engines: [
|
|
1320
|
+
{ id: 'example-engine', label: 'Example', commands: ['sessions.open', 'sessions.create'] },
|
|
1321
|
+
{ id: 'other', label: 'Other', commands: [] },
|
|
1322
|
+
],
|
|
1323
|
+
});
|
|
1324
|
+
});
|
|
1325
|
+
|
|
1326
|
+
it('maps engine listing failures instead of returning an empty list', async () => {
|
|
1327
|
+
const runtime = {
|
|
1328
|
+
request: async () => {
|
|
1329
|
+
const error = new Error('ENGINE_TIMEOUT');
|
|
1330
|
+
error.code = 'ENGINE_TIMEOUT';
|
|
1331
|
+
throw error;
|
|
1332
|
+
},
|
|
1333
|
+
};
|
|
1334
|
+
const app = express();
|
|
1335
|
+
registerPiRuntimeRoutes(app, { getPiSessionDaemonRuntime: () => runtime });
|
|
1336
|
+
server = await listen(app);
|
|
1337
|
+
const response = await fetch(`http://127.0.0.1:${server.address().port}/api/pi/engines`);
|
|
1338
|
+
expect(response.status).toBe(400);
|
|
1339
|
+
await expect(response.json()).resolves.toEqual({ error: { code: 'ENGINE_TIMEOUT' } });
|
|
1340
|
+
});
|
|
1341
|
+
|
|
1096
1342
|
it('validates and forwards older transcript page requests', async () => {
|
|
1097
1343
|
const calls = [];
|
|
1098
1344
|
const detail = {
|