@pi-chamber/web 1.0.7 → 1.0.8-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/dist/assets/AgentsSurface-BmHImX8m.js +1 -0
- package/dist/assets/ChoicesArtifact-C71fGOm2.js +1 -0
- package/dist/assets/DiagramView-BZQxoiZu.js +1 -0
- package/dist/assets/{DiffView-BxW6BuOC.js → DiffView-C70pbgk-.js} +6 -6
- package/dist/assets/FileSaveConflictDialog-Cu8c3gBV.js +3 -0
- package/dist/assets/FilesView-nFJYEdRw.js +6 -0
- package/dist/assets/GitHubDetailScaffold-Jvv_tgbl.js +11 -0
- package/dist/assets/GitHubLinkPicker-BXD2ODRi.js +1 -0
- package/dist/assets/GitHubListPrimitives-BWI706F0.js +1 -0
- package/dist/assets/{GitView-DD33ngnM.js → GitView-MIDG5RYW.js} +5 -5
- package/dist/assets/{IssuesSurface-BAY_eyX5.js → IssuesSurface-uNlozeu0.js} +2 -2
- package/dist/assets/{JsonTreeView-DpXbUrAl.js → JsonTreeView-CSLsTriz.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-Cn63lAmn.js → MarkdownRendererImpl-Cs-7BfWi.js} +3 -3
- package/dist/assets/PatchDiff-axbsnbTJ.js +1 -0
- package/dist/assets/PierreDiffViewer-lwn6w_5w.js +147 -0
- package/dist/assets/PullRequestsSurface-o_AXDjbO.js +2 -0
- package/dist/assets/{SessionSwitcherContent-CscYekC1.js → SessionSwitcherContent-C4CMlcbv.js} +1 -1
- package/dist/assets/SessionSwitcherDropdown-DCBVuCoo.js +2 -0
- package/dist/assets/SessionUnreadDot-DyeIrsro.js +1 -0
- package/dist/assets/SettingsView-BHBpt2Um.js +7 -0
- package/dist/assets/{SettingsWindow-gxjULdm1.js → SettingsWindow-Cb4st5y5.js} +1 -1
- package/dist/assets/{StickyHorizontalScrollbar-DNsbTLS7.js → StickyHorizontalScrollbar-CMbTn5WQ.js} +1 -1
- package/dist/assets/SubagentsArtifact-BzeMEoFP.js +1 -0
- package/dist/assets/ToolOutputDialog-BP2mOWdV.js +8 -0
- package/dist/assets/ToolPartDiffPreview-D49XBR9b.js +1 -0
- package/dist/assets/{VirtualizedFileDiff-BrbPymTL.js → VirtualizedFileDiff-CLgDONEQ.js} +4 -4
- package/dist/assets/{Virtualizer-okhy9Aq3.js → Virtualizer-PxblpQn6.js} +1 -1
- package/dist/assets/VisualFrame-CJrAvWSo.js +22 -0
- package/dist/assets/VisualsArtifact-DqLGgU-Q.js +1 -0
- package/dist/assets/{collapsible-D6qdoq7-.js → collapsible-BeyKtQGB.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-G4csGiKs.js → computeVirtualFileMetrics-DmO6H8u6.js} +2 -2
- package/dist/assets/contextFileOpenGuard-DOK251YW.js +1 -0
- package/dist/assets/{fileTreeStatus-Bskhj4qT.js → fileTreeStatus-CnzR7kxA.js} +2 -2
- package/dist/assets/gitStatusPredicates-4kPg2t6j.js +1 -0
- package/dist/assets/githubLink-QvaLfNNT.js +10 -0
- package/dist/assets/{index-I2QYqABE.js → index-B2v0_mez.js} +8 -8
- package/dist/assets/index-D3F4JrPN.css +1 -0
- package/dist/assets/{index-ComwtfT4.js → index-DMX9wT1Z.js} +1 -1
- package/dist/assets/{main-DoiadX0a.js → main-BW9J3Y72.js} +2 -2
- package/dist/assets/main-BirYxac2.js +137 -0
- package/dist/assets/{markdownCore-DczkEluO.js → markdownCore-CxmcPur8.js} +2 -2
- package/dist/assets/miniChat-BRB11eEs.js +2 -0
- package/dist/assets/{mobile-BucKVm1P.js → mobile-DJZYYCuB.js} +2 -2
- package/dist/assets/{nativeFileSave-Cp9i5QGd.js → nativeFileSave-B6QpoPRn.js} +1 -1
- package/dist/assets/pi-session-focus-preference-PWoh3LNA.js +9 -0
- package/dist/assets/{renderDiffWithHighlighter-PL82AR81.js → renderDiffWithHighlighter-C48T6YFJ.js} +1 -1
- package/dist/assets/renderElectronMiniChatApp-N-BQdJl0.js +2 -0
- package/dist/assets/{renderFileWithHighlighter-CYgfbA4F.js → renderFileWithHighlighter-8Kt2MyTN.js} +1 -1
- package/dist/assets/{renderMobileApp-Bp74b_Lo.js → renderMobileApp-B7cT7m5b.js} +3 -3
- package/dist/assets/runtimeEndpointReset-BC6yGnxN.js +62 -0
- package/dist/assets/runtimeSurface-kIEoYsPP.js +1 -0
- package/dist/assets/selection-BTEdLRVK.js +1 -0
- package/dist/assets/useAppFontEffects-EcTZ_I_I.js +225 -0
- package/dist/assets/useGitHubRemoteSearch-DIBHNu8r.js +1 -0
- package/dist/assets/useSwitcherItems-DfLbfX37.js +1 -0
- package/dist/assets/{vendor-aparajita-capacitor-secure-storage-DVZvgYu4.js → vendor-aparajita-capacitor-secure-storage-DUoR8t1G.js} +1 -1
- package/dist/assets/{vendor-base-ui-BCqPBzDj.js → vendor-base-ui-DE6jnTiC.js} +1 -1
- package/dist/assets/{vendor-boot-3SaHYVb1.js → vendor-boot-D-KEJjsM.js} +29 -29
- package/dist/assets/{vendor-capacitor-app-NbQ-WiPS.js → vendor-capacitor-app-CO5jS31X.js} +1 -1
- package/dist/assets/{vendor-capacitor-keyboard-CgrHt8iN.js → vendor-capacitor-keyboard-335osRpd.js} +1 -1
- package/dist/assets/{vendor-capacitor-status-bar-CWt0OF5t.js → vendor-capacitor-status-bar-lB9y4H9d.js} +1 -1
- package/dist/assets/{vendor-codemirror-autocomplete-WThuuUAz.js → vendor-codemirror-autocomplete-BKvJ8PfM.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-angular-BbLGCxF6.js → vendor-codemirror-lang-angular-wjCUD0bM.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-cpp-Cceks-9O.js → vendor-codemirror-lang-cpp-LJzlG8sJ.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-css-D1wpUg3Z.js → vendor-codemirror-lang-css-DoEEdEpW.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-go-Cv0zXHHM.js → vendor-codemirror-lang-go-DexsLPb8.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-html-DbL8oT9H.js → vendor-codemirror-lang-html-h25V-Hp5.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-java-CNugenuC.js → vendor-codemirror-lang-java-D8xoT8cv.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-javascript-Bx_FIyZF.js → vendor-codemirror-lang-javascript-DF3GDYje.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-jinja-DDGjB3Zq.js → vendor-codemirror-lang-jinja-BboTHFdn.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-json-DIvqf9Pb.js → vendor-codemirror-lang-json-DCqvG1nE.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-less-D8r9dGG1.js → vendor-codemirror-lang-less-B8ZrSKJM.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-liquid-B24mguYi.js → vendor-codemirror-lang-liquid-DF9S5m5F.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-markdown-v3yG2sbf.js → vendor-codemirror-lang-markdown-6BNbCEPe.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-php-BcZGalqy.js → vendor-codemirror-lang-php-CQwAz1Hd.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-python-b-JqEwQy.js → vendor-codemirror-lang-python-DQym-8Tx.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-rust-B1uZxDW-.js → vendor-codemirror-lang-rust-DknzOTkO.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sass-DqPrngKp.js → vendor-codemirror-lang-sass-dB0Rm5HI.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sql-UyCnpt-k.js → vendor-codemirror-lang-sql-CCQUnnD-.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-vue-xDwYkovV.js → vendor-codemirror-lang-vue-h1M5bF00.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-wast-CF3169p_.js → vendor-codemirror-lang-wast-DWgtlGfu.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-xml-FCtVhuOb.js → vendor-codemirror-lang-xml-DncwoCUY.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-yaml-g0sPmAnv.js → vendor-codemirror-lang-yaml-C7QkS5ER.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-B03xgzP2.js → vendor-codemirror-language-data-BUZIlm3G.js} +2 -2
- package/dist/assets/{vendor-codemirror-search-Dw3Wpu15.js → vendor-codemirror-search-BlDCaCMK.js} +1 -1
- package/dist/assets/{vendor-lezer-cpp-Cu3E-KUI.js → vendor-lezer-cpp-B4JK1BC1.js} +1 -1
- package/dist/assets/{vendor-lezer-css-Cb8vp67u.js → vendor-lezer-css-DRxDmhcy.js} +1 -1
- package/dist/assets/{vendor-lezer-go-BTsIaOm7.js → vendor-lezer-go-DsUgfmxi.js} +1 -1
- package/dist/assets/{vendor-lezer-html-UQMsUwj-.js → vendor-lezer-html-qr9pUPmM.js} +1 -1
- package/dist/assets/{vendor-lezer-java-BIWrFrAx.js → vendor-lezer-java-6UyNiQiB.js} +1 -1
- package/dist/assets/{vendor-lezer-javascript-BH2Etgoy.js → vendor-lezer-javascript-CUdJ0VGA.js} +1 -1
- package/dist/assets/{vendor-lezer-json-CE-QUCwM.js → vendor-lezer-json-BKYAA8Hu.js} +1 -1
- package/dist/assets/{vendor-lezer-lr-HY6Yc0Vr.js → vendor-lezer-lr-DluApmOX.js} +1 -1
- package/dist/assets/{vendor-lezer-markdown-xFL3Evwf.js → vendor-lezer-markdown-B-uzYzYT.js} +1 -1
- package/dist/assets/{vendor-lezer-php-Cr_mQGrG.js → vendor-lezer-php-DI6PNjlz.js} +1 -1
- package/dist/assets/{vendor-lezer-python-BNRFWCb0.js → vendor-lezer-python-Bj232yb5.js} +1 -1
- package/dist/assets/{vendor-lezer-rust-BvfOK5cU.js → vendor-lezer-rust-DlPG_Yau.js} +1 -1
- package/dist/assets/{vendor-lezer-sass-qoxiLisk.js → vendor-lezer-sass-CBsyWB2A.js} +1 -1
- package/dist/assets/{vendor-lezer-xml--x8SSpqU.js → vendor-lezer-xml-C1FmgtmE.js} +1 -1
- package/dist/assets/{vendor-lezer-yaml-BDo1JaEr.js → vendor-lezer-yaml-DpHmjriG.js} +1 -1
- package/dist/assets/{vendor-replit-codemirror-vim-D1Fe7FiY.js → vendor-replit-codemirror-vim-Cvk64got.js} +1 -1
- package/dist/assets/{web-components-CGDpzixf.js → web-components-C_DsTJis.js} +4 -4
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +2 -1
- package/plugins/registry.json +7 -0
- package/plugins/subagents/LICENSE +25 -0
- package/plugins/subagents/agents/planner.md +36 -0
- package/plugins/subagents/agents/reviewer.md +34 -0
- package/plugins/subagents/agents/scout.md +49 -0
- package/plugins/subagents/agents/worker.md +23 -0
- package/plugins/subagents/extension.js +631 -0
- package/plugins/subagents/extension.test.js +295 -0
- package/plugins/subagents/package.json +41 -0
- package/plugins/visuals/choices.js +168 -0
- package/plugins/visuals/extension.js +87 -0
- package/plugins/visuals/files.js +74 -0
- package/plugins/visuals/package.json +32 -0
- package/server/index.js +20 -0
- package/server/lib/github/DOCUMENTATION.md +4 -2
- package/server/lib/github/gh-cli.js +35 -9
- package/server/lib/github/gh-cli.test.js +122 -0
- package/server/lib/notifications/pi-notification-watcher.js +3 -0
- package/server/lib/notifications/pi-notification-watcher.test.js +10 -0
- package/server/lib/open-url/DOCUMENTATION.md +1 -1
- package/server/lib/pi/extension-protocol.js +54 -0
- package/server/lib/pi/fixtures/pichamber-gui-demo.ts +12 -13
- package/server/lib/pi/routes-extension-events.test.js +115 -0
- package/server/lib/pi/routes.js +307 -5
- package/server/lib/pi/routes.test.js +296 -1
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +25 -8
- package/server/lib/pi/session-daemon/extension-bridge.js +89 -29
- package/server/lib/pi/session-daemon/extension-config.js +719 -0
- package/server/lib/pi/session-daemon/extension-config.test.js +618 -0
- package/server/lib/pi/session-daemon/extension-controls.js +177 -0
- package/server/lib/pi/session-daemon/extension-controls.test.js +181 -0
- package/server/lib/pi/session-daemon/extension-name.js +6 -0
- package/server/lib/pi/session-daemon/extension-name.test.js +5 -0
- package/server/lib/pi/session-daemon/extension-palette.js +146 -0
- package/server/lib/pi/session-daemon/extension-palette.test.js +107 -0
- package/server/lib/pi/session-daemon/extension-replacements.js +138 -0
- package/server/lib/pi/session-daemon/extension-replacements.test.js +116 -0
- package/server/lib/pi/session-daemon/extension-ui-mode.js +30 -0
- package/server/lib/pi/session-daemon/extension-ui-mode.test.js +34 -0
- package/server/lib/pi/session-daemon/pichamber-ui.js +44 -0
- package/server/lib/pi/session-daemon/plugin-host.js +245 -0
- package/server/lib/pi/session-daemon/plugin-host.test.js +192 -0
- package/server/lib/pi/session-daemon/session-daemon-controls.e2e.test.js +205 -0
- package/server/lib/pi/session-daemon/session-daemon-drafts.e2e.test.js +409 -0
- package/server/lib/pi/session-daemon/session-daemon-extension-config.e2e.test.js +196 -0
- package/server/lib/pi/session-daemon/session-daemon-extensions.test.js +137 -6
- package/server/lib/pi/session-daemon/session-daemon-plugins.e2e.test.js +272 -0
- package/server/lib/pi/session-daemon/session-daemon-providers.e2e.test.js +153 -0
- package/server/lib/pi/session-daemon/session-daemon.js +568 -61
- package/server/lib/pi/session-daemon/session-daemon.test.js +164 -4
- package/server/lib/pi/session-daemon/session-engine-router.js +7 -0
- package/server/lib/pi/session-daemon/session-engine-router.test.js +20 -0
- package/server/lib/pi/session-daemon/supervisor.js +22 -3
- package/server/lib/pi/settings-store.js +14 -0
- package/server/lib/pi/settings-store.test.js +11 -0
- package/server/lib/plugins/DOCUMENTATION.md +186 -0
- package/server/lib/plugins/daemon-sync.js +78 -0
- package/server/lib/plugins/daemon-sync.supervisor.test.js +83 -0
- package/server/lib/plugins/daemon-sync.test.js +96 -0
- package/server/lib/plugins/impact.js +139 -0
- package/server/lib/plugins/impact.test.js +82 -0
- package/server/lib/plugins/manifest.js +195 -0
- package/server/lib/plugins/manifest.test.js +118 -0
- package/server/lib/plugins/registry.js +59 -0
- package/server/lib/plugins/routes.js +92 -0
- package/server/lib/plugins/routes.test.js +219 -0
- package/server/lib/plugins/service.js +161 -0
- package/server/lib/plugins/store.js +261 -0
- package/server/lib/plugins/store.test.js +188 -0
- package/server/lib/plugins/visuals-extension.test.js +237 -0
- package/server/lib/server-browser/DOCUMENTATION.md +32 -7
- package/server/lib/server-browser/browser-tab.js +4 -1
- package/server/lib/server-browser/downloads.js +261 -34
- package/server/lib/server-browser/downloads.test.js +171 -0
- package/server/lib/server-browser/runtime.integration.test.js +47 -0
- package/server/lib/server-browser/runtime.js +16 -0
- package/server/lib/server-browser/server-browser.js +25 -6
- package/server/lib/tunnels/executable-search.js +5 -1
- package/server/lib/tunnels/executable-search.test.js +26 -0
- package/dist/assets/DiagramView-BB-aZobi.js +0 -1
- package/dist/assets/FileSaveConflictDialog-Bzz8FNMq.js +0 -3
- package/dist/assets/FilesView-DECxN8Z0.js +0 -6
- package/dist/assets/GitHubDetailScaffold-CWsWycRd.js +0 -11
- package/dist/assets/GitHubLinkPicker-BVYdg_e8.js +0 -1
- package/dist/assets/GitHubListPrimitives-Dlv3tC4d.js +0 -1
- package/dist/assets/PatchDiff-BklyOEHs.js +0 -1
- package/dist/assets/PierreDiffViewer-wc6cB6qw.js +0 -147
- package/dist/assets/PullRequestsSurface-BZvJkT1I.js +0 -2
- package/dist/assets/SessionSwitcherDropdown-DShvvGwC.js +0 -2
- package/dist/assets/SessionUnreadDot-CbqRq6h_.js +0 -1
- package/dist/assets/SettingsView-DcF-At5E.js +0 -6
- package/dist/assets/ToolOutputDialog-DdMIfrnK.js +0 -8
- package/dist/assets/ToolPartDiffPreview-C6Sm4eVf.js +0 -1
- package/dist/assets/contextFileOpenGuard-UU86YHgI.js +0 -1
- package/dist/assets/gitStatusPredicates-DQEO4Psc.js +0 -1
- package/dist/assets/githubLink-ByPAyFjh.js +0 -10
- package/dist/assets/index-BaLCg7tL.css +0 -1
- package/dist/assets/main-DyFfbllq.js +0 -137
- package/dist/assets/miniChat-Ck6MEZ9Q.js +0 -2
- package/dist/assets/pi-session-focus-preference-Dx0UXPoO.js +0 -9
- package/dist/assets/renderElectronMiniChatApp-Cb7s7dWl.js +0 -2
- package/dist/assets/runtimeEndpointReset-7nWYnKd4.js +0 -62
- package/dist/assets/runtimeSurface-CFwnvks_.js +0 -1
- package/dist/assets/useAppFontEffects-ZTyNwFk6.js +0 -213
- package/dist/assets/useGitHubRemoteSearch-BF3ohpsh.js +0 -1
- package/dist/assets/useSwitcherItems-BJzwyDGX.js +0 -1
package/server/lib/pi/routes.js
CHANGED
|
@@ -25,6 +25,9 @@ import {
|
|
|
25
25
|
projectCustomFrame,
|
|
26
26
|
projectCustomSurface,
|
|
27
27
|
projectCustomSurfaces,
|
|
28
|
+
MAX_EXTENSION_CHOICE_ID_CHARS,
|
|
29
|
+
MAX_EXTENSION_CHOICE_NOTE_CHARS,
|
|
30
|
+
projectExtensionChooseFields,
|
|
28
31
|
sanitizeExtensionFormFields,
|
|
29
32
|
} from './extension-protocol.js';
|
|
30
33
|
import { createPiUiSettingsStore } from './ui-settings-store.js';
|
|
@@ -32,6 +35,7 @@ import { createPiSnippetsStore } from './snippets-store.js';
|
|
|
32
35
|
import { isValidSendOperationId, isValidStreamEpoch } from './session-daemon/send-operation-registry.js';
|
|
33
36
|
import { ENGINE_HANDLER_COMMANDS, ENGINE_UNSUPPORTED_OPERATION, isValidEngineId } from './session-daemon/session-engines.js';
|
|
34
37
|
import { normalizeOpenRequestUrl } from './session-daemon/open-request.js';
|
|
38
|
+
import { MAX_CONTROLS_PER_SESSION, parseComposerControl } from './session-daemon/extension-controls.js';
|
|
35
39
|
import {
|
|
36
40
|
DEFAULT_EVENT_STREAM_MAX_BUFFERED_BYTES,
|
|
37
41
|
createPiEventStreamRegistry,
|
|
@@ -78,7 +82,7 @@ const writeDaemonError = (res, error) => {
|
|
|
78
82
|
: code === 'INVALID_SESSION'
|
|
79
83
|
? 404
|
|
80
84
|
: code === 'SESSION_IN_USE' || code === 'OPERATION_PAYLOAD_MISMATCH' || code === 'STALE_STREAM_EPOCH'
|
|
81
|
-
|| code === ENGINE_UNSUPPORTED_OPERATION
|
|
85
|
+
|| code === ENGINE_UNSUPPORTED_OPERATION || code === 'CONTROL_UNAVAILABLE'
|
|
82
86
|
? 409
|
|
83
87
|
: code === 'OPERATION_EXPIRED'
|
|
84
88
|
? 410
|
|
@@ -641,6 +645,40 @@ const projectExtensionAppPayload = (app) => ({
|
|
|
641
645
|
const EXTENSION_COMMAND_PATTERN = /^[A-Za-z0-9][A-Za-z0-9:_-]{0,127}$/;
|
|
642
646
|
const OPAQUE_EXTENSION_ID_PATTERN = /^[a-f0-9]{16}$/;
|
|
643
647
|
|
|
648
|
+
const HEX_COLOR_PATTERN = /^#[0-9a-f]{6}$/i;
|
|
649
|
+
const PALETTE_TOKEN_PATTERN = /^[A-Za-z]{1,40}$/;
|
|
650
|
+
|
|
651
|
+
/** `{ background, foreground, palette[16] }` of `#rrggbb` colours, or null. */
|
|
652
|
+
const projectTerminalColors = (value) => {
|
|
653
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
|
|
654
|
+
const { background, foreground, palette } = value;
|
|
655
|
+
if (typeof background !== 'string' || !HEX_COLOR_PATTERN.test(background)) return null;
|
|
656
|
+
if (typeof foreground !== 'string' || !HEX_COLOR_PATTERN.test(foreground)) return null;
|
|
657
|
+
if (!Array.isArray(palette) || palette.length !== 16) return null;
|
|
658
|
+
if (!palette.every((color) => typeof color === 'string' && HEX_COLOR_PATTERN.test(color))) return null;
|
|
659
|
+
return { background, foreground, palette: [...palette] };
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
/** Pi's theme name, appearance, optional page background and token colours, or null. */
|
|
663
|
+
const projectExtensionPalette = (result) => {
|
|
664
|
+
if (!result || typeof result !== 'object') return null;
|
|
665
|
+
if (typeof result.theme !== 'string' || result.theme.length === 0 || result.theme.length > 128) return null;
|
|
666
|
+
if (result.appearance !== 'light' && result.appearance !== 'dark') return null;
|
|
667
|
+
if (result.background !== undefined && (typeof result.background !== 'string' || !HEX_COLOR_PATTERN.test(result.background))) return null;
|
|
668
|
+
if (!result.colors || typeof result.colors !== 'object' || Array.isArray(result.colors)) return null;
|
|
669
|
+
const colors = {};
|
|
670
|
+
for (const [token, color] of Object.entries(result.colors)) {
|
|
671
|
+
if (!PALETTE_TOKEN_PATTERN.test(token) || typeof color !== 'string' || !HEX_COLOR_PATTERN.test(color)) continue;
|
|
672
|
+
colors[token] = color;
|
|
673
|
+
}
|
|
674
|
+
return {
|
|
675
|
+
theme: result.theme,
|
|
676
|
+
appearance: result.appearance,
|
|
677
|
+
...(result.background !== undefined ? { background: result.background } : {}),
|
|
678
|
+
colors,
|
|
679
|
+
};
|
|
680
|
+
};
|
|
681
|
+
|
|
644
682
|
export const projectExtensionList = (result) => {
|
|
645
683
|
if (!result || typeof result !== 'object' || typeof result.directory !== 'string'
|
|
646
684
|
|| !Array.isArray(result.extensions) || !Array.isArray(result.commands)) throw protocolMismatch();
|
|
@@ -666,6 +704,96 @@ export const projectExtensionList = (result) => {
|
|
|
666
704
|
return { directory: result.directory, extensions, commands };
|
|
667
705
|
};
|
|
668
706
|
|
|
707
|
+
// `pi config` / `pi list` for extensions (session-daemon/extension-config.js).
|
|
708
|
+
// Ids are opaque sha256 base64url; names and sources are display forms the
|
|
709
|
+
// daemon already made path-free, re-checked here so nothing path-like or
|
|
710
|
+
// unexpected crosses.
|
|
711
|
+
const EXTENSION_CONFIG_ID_PATTERN = /^[A-Za-z0-9_-]{43}$/;
|
|
712
|
+
const EXTENSION_CONFIG_OVERRIDE_STATES = new Set(['inherit', 'load', 'unload']);
|
|
713
|
+
const EXTENSION_CONFIG_GROUPS = new Set(['package', 'auto', 'settings', 'builtin']);
|
|
714
|
+
const EXTENSION_CONFIG_SCOPES = new Set(['user', 'project']);
|
|
715
|
+
const EXTENSION_CONFIG_PACKAGE_KINDS = new Set(['npm', 'git', 'local']);
|
|
716
|
+
|
|
717
|
+
const isDisplayText = (value, max = 256) => typeof value === 'string' && value.length > 0 && value.length <= max
|
|
718
|
+
&& !value.includes('\\') && !value.startsWith('/') && !value.startsWith('~') && !/^[A-Za-z]:/.test(value);
|
|
719
|
+
|
|
720
|
+
// `replaced`: plugins and built-ins a live runtime left out because another
|
|
721
|
+
// extension took their tool, command, or flag. Present (even empty) only when
|
|
722
|
+
// the daemon answered from a live runtime. A bad entry is dropped; a bad
|
|
723
|
+
// optional part (`registers`, `by`) is left out of an otherwise good entry.
|
|
724
|
+
const EXTENSION_CONFIG_REPLACED_KINDS = new Set(['plugin', 'builtin']);
|
|
725
|
+
const EXTENSION_CONFIG_REGISTER_KINDS = new Set(['tool', 'command', 'flag']);
|
|
726
|
+
const PLUGIN_ID_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
727
|
+
|
|
728
|
+
const projectReplacedExtensions = (replaced) => {
|
|
729
|
+
if (!Array.isArray(replaced)) return undefined;
|
|
730
|
+
return replaced.flatMap((entry) => {
|
|
731
|
+
if (!entry || typeof entry !== 'object' || !EXTENSION_CONFIG_REPLACED_KINDS.has(entry.kind) || typeof entry.id !== 'string'
|
|
732
|
+
|| !(entry.kind === 'plugin' ? entry.id.length <= 40 && PLUGIN_ID_PATTERN.test(entry.id) : EXTENSION_CONFIG_ID_PATTERN.test(entry.id))) return [];
|
|
733
|
+
const registers = entry.registers;
|
|
734
|
+
const by = entry.by;
|
|
735
|
+
const validRegisters = registers && typeof registers === 'object' && EXTENSION_CONFIG_REGISTER_KINDS.has(registers.kind)
|
|
736
|
+
&& isDisplayText(registers.name) && !registers.name.startsWith('--');
|
|
737
|
+
const validBy = by && typeof by === 'object' && isDisplayText(by.name);
|
|
738
|
+
return [{
|
|
739
|
+
kind: entry.kind,
|
|
740
|
+
id: entry.id,
|
|
741
|
+
...(validRegisters ? { registers: { kind: registers.kind, name: registers.name } } : {}),
|
|
742
|
+
...(validBy ? {
|
|
743
|
+
by: {
|
|
744
|
+
...(typeof by.id === 'string' && EXTENSION_CONFIG_ID_PATTERN.test(by.id) ? { id: by.id } : {}),
|
|
745
|
+
name: by.name,
|
|
746
|
+
},
|
|
747
|
+
} : {}),
|
|
748
|
+
}];
|
|
749
|
+
});
|
|
750
|
+
};
|
|
751
|
+
|
|
752
|
+
const projectExtensionConfig = (result) => {
|
|
753
|
+
if (!result || typeof result !== 'object' || !result.project || typeof result.project !== 'object'
|
|
754
|
+
|| !Array.isArray(result.packages) || !Array.isArray(result.extensions) || !Array.isArray(result.installFailures)
|
|
755
|
+
|| (result.directory !== undefined && typeof result.directory !== 'string')) throw protocolMismatch();
|
|
756
|
+
const trusted = result.project.trusted === true;
|
|
757
|
+
const packages = result.packages.map((pkg) => {
|
|
758
|
+
if (!pkg || typeof pkg !== 'object' || typeof pkg.id !== 'string' || !EXTENSION_CONFIG_ID_PATTERN.test(pkg.id)
|
|
759
|
+
|| !EXTENSION_CONFIG_SCOPES.has(pkg.scope) || !EXTENSION_CONFIG_PACKAGE_KINDS.has(pkg.kind)
|
|
760
|
+
|| (pkg.kind === 'local' ? !isDisplayText(pkg.source) || pkg.source.includes('/') : !isDisplayText(pkg.source))) throw protocolMismatch();
|
|
761
|
+
return { id: pkg.id, source: pkg.source, scope: pkg.scope, kind: pkg.kind, installed: pkg.installed === true, filtered: pkg.filtered === true };
|
|
762
|
+
});
|
|
763
|
+
const packageIds = new Set(packages.map((pkg) => pkg.id));
|
|
764
|
+
const extensions = result.extensions.map((extension) => {
|
|
765
|
+
if (!extension || typeof extension !== 'object' || typeof extension.id !== 'string' || !EXTENSION_CONFIG_ID_PATTERN.test(extension.id)
|
|
766
|
+
|| !isDisplayText(extension.name) || !EXTENSION_CONFIG_GROUPS.has(extension.group) || !EXTENSION_CONFIG_SCOPES.has(extension.scope)
|
|
767
|
+
|| (extension.global !== undefined && typeof extension.global !== 'boolean')) throw protocolMismatch();
|
|
768
|
+
const project = extension.project;
|
|
769
|
+
if (project !== undefined && (!trusted || !project || typeof project !== 'object' || !EXTENSION_CONFIG_OVERRIDE_STATES.has(project.state)
|
|
770
|
+
|| typeof project.inherited !== 'boolean' || typeof project.enabled !== 'boolean')) throw protocolMismatch();
|
|
771
|
+
return {
|
|
772
|
+
id: extension.id,
|
|
773
|
+
name: extension.name,
|
|
774
|
+
group: extension.group,
|
|
775
|
+
...(extension.group === 'package' && packageIds.has(extension.packageId) ? { packageId: extension.packageId } : {}),
|
|
776
|
+
scope: extension.scope,
|
|
777
|
+
...(typeof extension.global === 'boolean' ? { global: extension.global } : {}),
|
|
778
|
+
...(project ? { project: { state: project.state, inherited: project.inherited, enabled: project.enabled } } : {}),
|
|
779
|
+
};
|
|
780
|
+
});
|
|
781
|
+
const installFailures = result.installFailures.flatMap((failure) => (
|
|
782
|
+
failure && typeof failure === 'object' && isDisplayText(failure.source) && typeof failure.message === 'string'
|
|
783
|
+
? [{ source: failure.source, message: failure.message.slice(0, 300) }]
|
|
784
|
+
: []
|
|
785
|
+
));
|
|
786
|
+
return {
|
|
787
|
+
...(typeof result.directory === 'string' && result.directory.length > 0 ? { directory: result.directory } : {}),
|
|
788
|
+
project: { available: result.project.available === true, trusted },
|
|
789
|
+
packages,
|
|
790
|
+
extensions,
|
|
791
|
+
installFailures,
|
|
792
|
+
...(Array.isArray(result.replaced) ? { replaced: projectReplacedExtensions(result.replaced) } : {}),
|
|
793
|
+
...(result.deferred === true ? { deferred: true } : {}),
|
|
794
|
+
};
|
|
795
|
+
};
|
|
796
|
+
|
|
669
797
|
// User shell commands (`!cmd`). Command text is user-authored; output is a
|
|
670
798
|
// bounded tail. Field caps mirror the daemon's live/recorded limits.
|
|
671
799
|
const BASH_COMMAND_MAX_CHARS = 100_000;
|
|
@@ -694,7 +822,16 @@ const projectBashExecutions = (value) => (Array.isArray(value)
|
|
|
694
822
|
? value.slice(0, 8).map(projectBashExecution).filter(Boolean)
|
|
695
823
|
: undefined);
|
|
696
824
|
|
|
825
|
+
// Composer controls are checked again here with the daemon's own parser, so
|
|
826
|
+
// the browser only ever sees the validated shape.
|
|
827
|
+
const projectComposerControls = (value) => {
|
|
828
|
+
if (!Array.isArray(value)) return undefined;
|
|
829
|
+
// An empty list stays: it tells the browser the session has none.
|
|
830
|
+
return value.slice(0, MAX_CONTROLS_PER_SESSION).map(parseComposerControl).filter((control) => control && !control.remove);
|
|
831
|
+
};
|
|
832
|
+
|
|
697
833
|
function projectExtensionSnapshotState(snapshot) {
|
|
834
|
+
const extensionControls = projectComposerControls(snapshot.extensionControls);
|
|
698
835
|
const extensionStatuses = Array.isArray(snapshot.extensionStatuses)
|
|
699
836
|
? snapshot.extensionStatuses.filter((entry) => entry && typeof entry.key === 'string' && typeof entry.text === 'string' && entry.key.length > 0 && entry.key.length <= 128 && entry.text.length <= 1000).slice(0, 50).map((entry) => ({ key: entry.key.slice(0, 128), text: entry.text.slice(0, 1000) }))
|
|
700
837
|
: undefined;
|
|
@@ -708,8 +845,9 @@ function projectExtensionSnapshotState(snapshot) {
|
|
|
708
845
|
const extensionDialogs = Array.isArray(snapshot.extensionDialogs)
|
|
709
846
|
? snapshot.extensionDialogs.filter((entry) => entry && typeof entry.requestId === 'string' && typeof entry.method === 'string' && typeof entry.title === 'string').slice(0, 20).map((entry) => ({
|
|
710
847
|
requestId: entry.requestId.slice(0, 512),
|
|
711
|
-
method: ['select', 'confirm', 'input', 'editor', 'form'].includes(entry.method) ? entry.method : 'confirm',
|
|
848
|
+
method: ['select', 'confirm', 'input', 'editor', 'form', 'choose'].includes(entry.method) ? entry.method : 'confirm',
|
|
712
849
|
title: entry.title.slice(0, 512),
|
|
850
|
+
...(entry.method === 'choose' ? projectExtensionChooseFields(entry) : {}),
|
|
713
851
|
...(typeof entry.message === 'string' ? { message: entry.message.slice(0, 2000) } : {}),
|
|
714
852
|
...(Array.isArray(entry.options) ? { options: entry.options.filter((option) => typeof option === 'string').map((option) => option.slice(0, 256)).slice(0, 20) } : {}),
|
|
715
853
|
...(typeof entry.placeholder === 'string' ? { placeholder: entry.placeholder.slice(0, 512) } : {}),
|
|
@@ -735,6 +873,7 @@ function projectExtensionSnapshotState(snapshot) {
|
|
|
735
873
|
: undefined;
|
|
736
874
|
return {
|
|
737
875
|
...(extensionStatuses ? { extensionStatuses } : {}),
|
|
876
|
+
...(extensionControls ? { extensionControls } : {}),
|
|
738
877
|
...(extensionWidgets ? { extensionWidgets } : {}),
|
|
739
878
|
...(extensionDialogs ? { extensionDialogs } : {}),
|
|
740
879
|
...(extensionPanels ? { extensionPanels } : {}),
|
|
@@ -758,7 +897,13 @@ export const projectEventFrame = (frame) => {
|
|
|
758
897
|
const streamEpoch = typeof frame.streamEpoch === 'string' && frame.streamEpoch.length > 0 && frame.streamEpoch.length <= 128
|
|
759
898
|
? frame.streamEpoch
|
|
760
899
|
: undefined;
|
|
761
|
-
|
|
900
|
+
// `draft` marks a draft session's events (a runtime warmed for a
|
|
901
|
+
// new-session draft): clients keep them out of the session list.
|
|
902
|
+
const common = {
|
|
903
|
+
protocolVersion: 1, kind: 'event', name: frame.event, sequence: frame.sequence, sessionId, directory,
|
|
904
|
+
...(streamEpoch ? { streamEpoch } : {}),
|
|
905
|
+
...(frame.draft === true ? { draft: true } : {}),
|
|
906
|
+
};
|
|
762
907
|
switch (frame.event) {
|
|
763
908
|
case 'session.input': {
|
|
764
909
|
const pending = projectPendingInputSummary(frame.payload.pending);
|
|
@@ -983,6 +1128,15 @@ export const projectEventFrame = (frame) => {
|
|
|
983
1128
|
if (frame.payload.text !== undefined && typeof frame.payload.text !== 'string') return null;
|
|
984
1129
|
return { ...common, payload: { key: frame.payload.key.slice(0, 128), ...(typeof frame.payload.text === 'string' ? { text: frame.payload.text.slice(0, 1000) } : {}) } };
|
|
985
1130
|
}
|
|
1131
|
+
case 'extension.control': {
|
|
1132
|
+
if (frame.payload.removed === true) {
|
|
1133
|
+
if (typeof frame.payload.id !== 'string' || frame.payload.id.length === 0 || frame.payload.id.length > 64) return null;
|
|
1134
|
+
return { ...common, payload: { id: frame.payload.id, removed: true } };
|
|
1135
|
+
}
|
|
1136
|
+
const control = parseComposerControl(frame.payload.control);
|
|
1137
|
+
if (!control || control.remove) return null;
|
|
1138
|
+
return { ...common, payload: { control } };
|
|
1139
|
+
}
|
|
986
1140
|
case 'extension.widget': {
|
|
987
1141
|
if (typeof frame.payload.key !== 'string' || frame.payload.key.length === 0 || frame.payload.key.length > 128) return null;
|
|
988
1142
|
if (frame.payload.lines !== undefined) {
|
|
@@ -1002,14 +1156,18 @@ export const projectEventFrame = (frame) => {
|
|
|
1002
1156
|
}
|
|
1003
1157
|
case 'extension.dialog': {
|
|
1004
1158
|
if (typeof frame.payload.requestId !== 'string' || frame.payload.requestId.length === 0 || frame.payload.requestId.length > 512) return null;
|
|
1005
|
-
if (!['select', 'confirm', 'input', 'editor', 'form'].includes(frame.payload.method)) return null;
|
|
1159
|
+
if (!['select', 'confirm', 'input', 'editor', 'form', 'choose'].includes(frame.payload.method)) return null;
|
|
1006
1160
|
if (typeof frame.payload.title !== 'string' || frame.payload.title.length === 0 || frame.payload.title.length > 512) return null;
|
|
1161
|
+
const chooseFields = frame.payload.method === 'choose' ? projectExtensionChooseFields(frame.payload) : null;
|
|
1162
|
+
// A question nobody could answer is dropped, like any malformed event.
|
|
1163
|
+
if (chooseFields && chooseFields.choices.length === 0) return null;
|
|
1007
1164
|
return {
|
|
1008
1165
|
...common,
|
|
1009
1166
|
payload: {
|
|
1010
1167
|
requestId: frame.payload.requestId.slice(0, 512),
|
|
1011
1168
|
method: frame.payload.method,
|
|
1012
1169
|
title: frame.payload.title.slice(0, 512),
|
|
1170
|
+
...(chooseFields ?? {}),
|
|
1013
1171
|
...(typeof frame.payload.message === 'string' ? { message: frame.payload.message.slice(0, 2000) } : {}),
|
|
1014
1172
|
...(Array.isArray(frame.payload.options) ? { options: frame.payload.options.filter((option) => typeof option === 'string').map((option) => option.slice(0, 256)).slice(0, 20) } : {}),
|
|
1015
1173
|
...(typeof frame.payload.placeholder === 'string' ? { placeholder: frame.payload.placeholder.slice(0, 512) } : {}),
|
|
@@ -1138,6 +1296,9 @@ export const registerPiRuntimeRoutes = (app, {
|
|
|
1138
1296
|
smallModelGenerator = async (input) => (await import('./small-model-generation.js')).generateWithSmallModel(input),
|
|
1139
1297
|
eventHeartbeatMs = 15_000,
|
|
1140
1298
|
eventStreamMaxBufferedBytes = DEFAULT_EVENT_STREAM_MAX_BUFFERED_BYTES,
|
|
1299
|
+
// Called with the id after a session is deleted, for PiChamber state kept
|
|
1300
|
+
// per session elsewhere (plugin switches). Must not throw.
|
|
1301
|
+
onSessionDeleted = () => {},
|
|
1141
1302
|
}) => {
|
|
1142
1303
|
const eventStreamRegistry = createPiEventStreamRegistry();
|
|
1143
1304
|
// Tell every device an archive mark changed (a `session.archive` event on
|
|
@@ -1685,6 +1846,8 @@ export const registerPiRuntimeRoutes = (app, {
|
|
|
1685
1846
|
...(Number.isSafeInteger(snippet.updatedAt) ? { updatedAt: snippet.updatedAt } : {}),
|
|
1686
1847
|
};
|
|
1687
1848
|
}),
|
|
1849
|
+
// Where the server keeps every snippet, so a user can point an agent at it.
|
|
1850
|
+
...(typeof snippetsStore.file === 'string' && snippetsStore.file.length > 0 ? { file: snippetsStore.file } : {}),
|
|
1688
1851
|
};
|
|
1689
1852
|
};
|
|
1690
1853
|
|
|
@@ -2052,6 +2215,14 @@ export const registerPiRuntimeRoutes = (app, {
|
|
|
2052
2215
|
}
|
|
2053
2216
|
});
|
|
2054
2217
|
|
|
2218
|
+
// Stop a draft session's runtime when its draft closes. Only a draft can be
|
|
2219
|
+
// discarded; any other session answers `{ discarded: false }` untouched.
|
|
2220
|
+
app.post('/api/pi/sessions/:sessionId/discard-draft', async (req, res) => {
|
|
2221
|
+
const result = await requestSessionOperation(req, res, getPiSessionDaemonRuntime, 'sessions.discardDraft');
|
|
2222
|
+
if (result === undefined) return;
|
|
2223
|
+
res.json({ discarded: result?.discarded === true });
|
|
2224
|
+
});
|
|
2225
|
+
|
|
2055
2226
|
app.delete('/api/pi/sessions/:sessionId', async (req, res) => {
|
|
2056
2227
|
const result = await requestSessionOperation(req, res, getPiSessionDaemonRuntime, 'sessions.delete');
|
|
2057
2228
|
if (result === undefined) return;
|
|
@@ -2060,6 +2231,11 @@ export const registerPiRuntimeRoutes = (app, {
|
|
|
2060
2231
|
} catch (error) {
|
|
2061
2232
|
console.warn('[pi] could not remove a deleted session from the shelf', error?.code ?? error);
|
|
2062
2233
|
}
|
|
2234
|
+
try {
|
|
2235
|
+
await onSessionDeleted(req.params.sessionId);
|
|
2236
|
+
} catch (error) {
|
|
2237
|
+
console.warn('[pi] could not drop a deleted session\'s plugin switches', error?.code ?? error);
|
|
2238
|
+
}
|
|
2063
2239
|
res.status(204).end();
|
|
2064
2240
|
});
|
|
2065
2241
|
|
|
@@ -2174,11 +2350,108 @@ export const registerPiRuntimeRoutes = (app, {
|
|
|
2174
2350
|
}
|
|
2175
2351
|
});
|
|
2176
2352
|
|
|
2353
|
+
// Extension config (`pi config`, `pi list`, `pi remove`). Toggles and
|
|
2354
|
+
// removal change what code runs on this server; the daemon re-resolves
|
|
2355
|
+
// every id and enforces trust (session-daemon/extension-config.js).
|
|
2356
|
+
const extensionConfigDirectory = (value) => {
|
|
2357
|
+
if (value === undefined) return { ok: true };
|
|
2358
|
+
if (typeof value !== 'string' || value.length > 4096) return { ok: false };
|
|
2359
|
+
return { ok: true, ...(value.length > 0 ? { directory: value } : {}) };
|
|
2360
|
+
};
|
|
2361
|
+
|
|
2362
|
+
app.get('/api/pi/extensions/config', async (req, res) => {
|
|
2363
|
+
const target = extensionConfigDirectory(req.query?.directory);
|
|
2364
|
+
if (!target.ok) {
|
|
2365
|
+
res.status(400).json({ error: { code: 'INVALID_ARGUMENT' } });
|
|
2366
|
+
return;
|
|
2367
|
+
}
|
|
2368
|
+
try {
|
|
2369
|
+
const result = await getDaemonRuntime(getPiSessionDaemonRuntime).request('extensions.config.list', {
|
|
2370
|
+
...(target.directory ? { directory: target.directory } : {}),
|
|
2371
|
+
});
|
|
2372
|
+
res.json(projectExtensionConfig(result));
|
|
2373
|
+
} catch (error) {
|
|
2374
|
+
writeDaemonError(res, error);
|
|
2375
|
+
}
|
|
2376
|
+
});
|
|
2377
|
+
|
|
2378
|
+
app.put('/api/pi/extensions/config/:id', async (req, res) => {
|
|
2379
|
+
const id = req.params.id;
|
|
2380
|
+
const body = req.body;
|
|
2381
|
+
let payload = null;
|
|
2382
|
+
if (typeof id === 'string' && EXTENSION_CONFIG_ID_PATTERN.test(id) && body && typeof body === 'object' && !Array.isArray(body)) {
|
|
2383
|
+
const keys = Object.keys(body);
|
|
2384
|
+
if (body.scope === 'global' && typeof body.enabled === 'boolean'
|
|
2385
|
+
&& keys.every((key) => ['scope', 'enabled', 'directory'].includes(key))) {
|
|
2386
|
+
const target = extensionConfigDirectory(body.directory);
|
|
2387
|
+
if (target.ok) payload = { id, scope: 'global', enabled: body.enabled, ...(target.directory ? { directory: target.directory } : {}) };
|
|
2388
|
+
} else if (body.scope === 'project'
|
|
2389
|
+
&& typeof body.directory === 'string' && body.directory.length > 0 && body.directory.length <= 4096) {
|
|
2390
|
+
// The override itself, or on/off for the daemon to turn into one.
|
|
2391
|
+
if (EXTENSION_CONFIG_OVERRIDE_STATES.has(body.state) && keys.every((key) => ['scope', 'state', 'directory'].includes(key))) {
|
|
2392
|
+
payload = { id, scope: 'project', state: body.state, directory: body.directory };
|
|
2393
|
+
} else if (typeof body.enabled === 'boolean' && keys.every((key) => ['scope', 'enabled', 'directory'].includes(key))) {
|
|
2394
|
+
payload = { id, scope: 'project', enabled: body.enabled, directory: body.directory };
|
|
2395
|
+
}
|
|
2396
|
+
}
|
|
2397
|
+
}
|
|
2398
|
+
if (!payload) {
|
|
2399
|
+
res.status(400).json({ error: { code: 'INVALID_ARGUMENT' } });
|
|
2400
|
+
return;
|
|
2401
|
+
}
|
|
2402
|
+
try {
|
|
2403
|
+
res.json(projectExtensionConfig(await getDaemonRuntime(getPiSessionDaemonRuntime).request('extensions.config.set', payload)));
|
|
2404
|
+
} catch (error) {
|
|
2405
|
+
writeDaemonError(res, error);
|
|
2406
|
+
}
|
|
2407
|
+
});
|
|
2408
|
+
|
|
2409
|
+
app.delete('/api/pi/extensions/packages/:id', async (req, res) => {
|
|
2410
|
+
const id = req.params.id;
|
|
2411
|
+
const target = extensionConfigDirectory(req.query?.directory);
|
|
2412
|
+
if (typeof id !== 'string' || !EXTENSION_CONFIG_ID_PATTERN.test(id) || !target.ok) {
|
|
2413
|
+
res.status(400).json({ error: { code: 'INVALID_ARGUMENT' } });
|
|
2414
|
+
return;
|
|
2415
|
+
}
|
|
2416
|
+
try {
|
|
2417
|
+
res.json(projectExtensionConfig(await getDaemonRuntime(getPiSessionDaemonRuntime).request('extensions.packages.remove', {
|
|
2418
|
+
id,
|
|
2419
|
+
...(target.directory ? { directory: target.directory } : {}),
|
|
2420
|
+
})));
|
|
2421
|
+
} catch (error) {
|
|
2422
|
+
writeDaemonError(res, error);
|
|
2423
|
+
}
|
|
2424
|
+
});
|
|
2425
|
+
|
|
2426
|
+
// Pi's colours for extension surfaces drawn with the given terminal
|
|
2427
|
+
// colours (session-daemon/extension-palette.js).
|
|
2428
|
+
app.post('/api/pi/extensions/palette', async (req, res) => {
|
|
2429
|
+
const terminal = projectTerminalColors(req.body?.terminal);
|
|
2430
|
+
if (!terminal) {
|
|
2431
|
+
res.status(400).json({ error: { code: 'INVALID_ARGUMENT' } });
|
|
2432
|
+
return;
|
|
2433
|
+
}
|
|
2434
|
+
try {
|
|
2435
|
+
const result = await getDaemonRuntime(getPiSessionDaemonRuntime).request('extensions.palette', { terminal });
|
|
2436
|
+
const palette = projectExtensionPalette(result);
|
|
2437
|
+
if (!palette) {
|
|
2438
|
+
res.status(502).json({ error: { code: 'MALFORMED_DAEMON_RESPONSE' } });
|
|
2439
|
+
return;
|
|
2440
|
+
}
|
|
2441
|
+
res.json(palette);
|
|
2442
|
+
} catch (error) {
|
|
2443
|
+
writeDaemonError(res, error);
|
|
2444
|
+
}
|
|
2445
|
+
});
|
|
2446
|
+
|
|
2177
2447
|
app.post('/api/pi/extensions/respond', async (req, res) => {
|
|
2178
2448
|
const body = req.body;
|
|
2179
2449
|
if (!body || typeof body !== 'object' || Array.isArray(body)
|
|
2180
2450
|
|| typeof body.requestId !== 'string' || body.requestId.length === 0
|
|
2181
|
-
|| (body.directory !== undefined && typeof body.directory !== 'string')
|
|
2451
|
+
|| (body.directory !== undefined && typeof body.directory !== 'string')
|
|
2452
|
+
// A `choose` answer: the choice id travels as `value`, with an optional note.
|
|
2453
|
+
|| (body.note !== undefined && (typeof body.note !== 'string' || body.note.length > MAX_EXTENSION_CHOICE_NOTE_CHARS
|
|
2454
|
+
|| typeof body.value !== 'string' || body.value.length > MAX_EXTENSION_CHOICE_ID_CHARS))) {
|
|
2182
2455
|
res.status(400).json({ error: { code: 'INVALID_ARGUMENT' } });
|
|
2183
2456
|
return;
|
|
2184
2457
|
}
|
|
@@ -2204,6 +2477,7 @@ export const registerPiRuntimeRoutes = (app, {
|
|
|
2204
2477
|
...(body.cancelled === true ? { cancelled: true } : {}),
|
|
2205
2478
|
...(body.confirmed === true ? { confirmed: true } : {}),
|
|
2206
2479
|
...(typeof body.value === 'string' ? { value: body.value } : {}),
|
|
2480
|
+
...(typeof body.note === 'string' ? { note: body.note } : {}),
|
|
2207
2481
|
...(values ? { values } : {}),
|
|
2208
2482
|
});
|
|
2209
2483
|
if (!result || typeof result !== 'object' || result.resolved !== true) {
|
|
@@ -2216,6 +2490,32 @@ export const registerPiRuntimeRoutes = (app, {
|
|
|
2216
2490
|
}
|
|
2217
2491
|
});
|
|
2218
2492
|
|
|
2493
|
+
// A click on a composer control an extension declared. The daemon picks the
|
|
2494
|
+
// command from its own copy of the control; the browser only names the
|
|
2495
|
+
// control and the value it wants.
|
|
2496
|
+
app.post('/api/pi/extensions/control', async (req, res) => {
|
|
2497
|
+
const body = req.body;
|
|
2498
|
+
if (!body || typeof body !== 'object' || Array.isArray(body)
|
|
2499
|
+
|| typeof body.sessionId !== 'string' || body.sessionId.length === 0 || body.sessionId.length > 256
|
|
2500
|
+
|| typeof body.id !== 'string' || body.id.length === 0 || body.id.length > 64
|
|
2501
|
+
|| (body.value !== undefined && typeof body.value !== 'boolean' && (typeof body.value !== 'string' || body.value.length > 64))
|
|
2502
|
+
|| (body.clientId !== undefined && (typeof body.clientId !== 'string' || body.clientId.length > 128))) {
|
|
2503
|
+
res.status(400).json({ error: { code: 'INVALID_ARGUMENT' } });
|
|
2504
|
+
return;
|
|
2505
|
+
}
|
|
2506
|
+
try {
|
|
2507
|
+
const result = await getDaemonRuntime(getPiSessionDaemonRuntime).request('extensions.control', {
|
|
2508
|
+
sessionId: body.sessionId,
|
|
2509
|
+
id: body.id,
|
|
2510
|
+
...(body.value !== undefined ? { value: body.value } : {}),
|
|
2511
|
+
...(typeof body.clientId === 'string' && body.clientId.length > 0 ? { clientId: body.clientId } : {}),
|
|
2512
|
+
});
|
|
2513
|
+
res.json({ ran: result?.ran === true });
|
|
2514
|
+
} catch (error) {
|
|
2515
|
+
writeDaemonError(res, error);
|
|
2516
|
+
}
|
|
2517
|
+
});
|
|
2518
|
+
|
|
2219
2519
|
// `ctx.ui.custom()` surfaces: keys, the sender's viewport, Close, picking a
|
|
2220
2520
|
// panel in a tab stack, and a full-frame refresh after a missed patch. A surface that already closed
|
|
2221
2521
|
// answers 404 so the browser drops it without retrying.
|
|
@@ -2393,9 +2693,11 @@ export const registerPiRuntimeRoutes = (app, {
|
|
|
2393
2693
|
res.status(400).json({ error: { code: 'INVALID_ARGUMENT' } });
|
|
2394
2694
|
return;
|
|
2395
2695
|
}
|
|
2696
|
+
const clientId = typeof body.clientId === 'string' && body.clientId.length > 0 && body.clientId.length <= 128 ? body.clientId : undefined;
|
|
2396
2697
|
const result = await requestSessionOperation(req, res, getPiSessionDaemonRuntime, 'sessions.bash', {
|
|
2397
2698
|
command: body.command,
|
|
2398
2699
|
...(body.excludeFromContext === true ? { excludeFromContext: true } : {}),
|
|
2700
|
+
...(clientId ? { clientId } : {}),
|
|
2399
2701
|
});
|
|
2400
2702
|
if (result === undefined) return;
|
|
2401
2703
|
if (!result || result.accepted !== true || typeof result.id !== 'string') {
|