@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
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pi-chamber/plugin-visuals",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Lets the agent draw HTML pages in the chat.",
|
|
7
|
+
"keywords": ["pi-package"],
|
|
8
|
+
"pi": {
|
|
9
|
+
"extensions": ["./extension.js"]
|
|
10
|
+
},
|
|
11
|
+
"pichamber": {
|
|
12
|
+
"apiVersion": 1,
|
|
13
|
+
"id": "visuals",
|
|
14
|
+
"name": "Visuals",
|
|
15
|
+
"description": "Lets the agent show charts, diagrams, tables and mockups as HTML pages in the chat.",
|
|
16
|
+
"icon": "artboard",
|
|
17
|
+
"defaultEnabled": false,
|
|
18
|
+
"state": {
|
|
19
|
+
"allowNetwork": {
|
|
20
|
+
"type": "boolean",
|
|
21
|
+
"scope": "global",
|
|
22
|
+
"default": false,
|
|
23
|
+
"label": "Let pages load from the network",
|
|
24
|
+
"description": "Off: pages can only use what they contain."
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"contributes": {
|
|
28
|
+
"settings": ["allowNetwork"],
|
|
29
|
+
"ui": "visuals"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
package/server/index.js
CHANGED
|
@@ -17,6 +17,9 @@ import { createTailscaleService } from './lib/tailscale/service.js';
|
|
|
17
17
|
import { createServerIdResolver } from './lib/relay/server-id.js';
|
|
18
18
|
import { registerTailscaleRoutes } from './lib/tailscale/routes.js';
|
|
19
19
|
import { registerPiRuntimeRoutes } from './lib/pi/routes.js';
|
|
20
|
+
import { createPluginService } from './lib/plugins/service.js';
|
|
21
|
+
import { createPluginDaemonSync } from './lib/plugins/daemon-sync.js';
|
|
22
|
+
import { registerPluginRoutes } from './lib/plugins/routes.js';
|
|
20
23
|
import { createDockerInitialLocalSettings, createPiUiSettingsStore } from './lib/pi/ui-settings-store.js';
|
|
21
24
|
import { detectLinuxDistribution } from './lib/server/linux-distribution.js';
|
|
22
25
|
import { createPiNotificationWatcher } from './lib/notifications/pi-notification-watcher.js';
|
|
@@ -261,10 +264,22 @@ export async function startWebUiServer(options = {}) {
|
|
|
261
264
|
getServerId: serverIdResolver.getServerId,
|
|
262
265
|
getServerLabel: () => os.hostname() || 'PiChamber',
|
|
263
266
|
});
|
|
267
|
+
// Plugins: the server owns manifests and state and pushes the enabled set
|
|
268
|
+
// to the daemon (lib/plugins/DOCUMENTATION.md). A health probe runs the
|
|
269
|
+
// supervisor's onDaemonReady hook, which pushes.
|
|
270
|
+
const pluginService = createPluginService();
|
|
271
|
+
const pluginDaemonSync = createPluginDaemonSync({
|
|
272
|
+
buildConfig: () => pluginService.daemonConfig(),
|
|
273
|
+
refresh: () => piSessionDaemonRuntime?.health(),
|
|
274
|
+
});
|
|
264
275
|
const piRuntimeRoutes = registerPiRuntimeRoutes(app, {
|
|
265
276
|
getPiSessionDaemonRuntime: () => piSessionDaemonRuntime,
|
|
266
277
|
uiSettingsStore,
|
|
278
|
+
onSessionDeleted: async (sessionId) => {
|
|
279
|
+
if (await pluginService.forgetSession(sessionId)) pluginDaemonSync.changed();
|
|
280
|
+
},
|
|
267
281
|
});
|
|
282
|
+
registerPluginRoutes(app, { service: pluginService, onChange: pluginDaemonSync.changed });
|
|
268
283
|
// Cloudflare Tunnel external access (managed-remote and managed-local modes).
|
|
269
284
|
const requireTunnelAuth = (req, res, next) => uiAuthController.requireAuth(req, res, next);
|
|
270
285
|
app.get('/api/pichamber/tunnel/status', requireTunnelAuth, async (_req, res) => {
|
|
@@ -308,6 +323,7 @@ export async function startWebUiServer(options = {}) {
|
|
|
308
323
|
dataDir: PICHAMBER_DATA_DIR,
|
|
309
324
|
port: typeof resolvedPort === 'number' ? resolvedPort : port,
|
|
310
325
|
version: PICHAMBER_VERSION,
|
|
326
|
+
onDaemonReady: pluginDaemonSync.onDaemonReady,
|
|
311
327
|
});
|
|
312
328
|
if (typeof resolvedPort === 'number') {
|
|
313
329
|
process.send?.({
|
|
@@ -341,6 +357,10 @@ export async function startWebUiServer(options = {}) {
|
|
|
341
357
|
console.warn(`[open-url] Intake unavailable: ${error?.code ?? 'UNKNOWN'}`);
|
|
342
358
|
}
|
|
343
359
|
void piSessionDaemonRuntime.start()
|
|
360
|
+
.then(() => {
|
|
361
|
+
// Configure plugins on the started daemon; later requests re-check.
|
|
362
|
+
if (!stopped) void piSessionDaemonRuntime.health();
|
|
363
|
+
})
|
|
344
364
|
.catch((error) => {
|
|
345
365
|
console.warn(`[PiSessionDaemon] unavailable: ${error?.code ?? 'DAEMON_UNAVAILABLE'}`);
|
|
346
366
|
})
|
|
@@ -73,8 +73,10 @@ no per-route auth is added here.
|
|
|
73
73
|
- Minimum gh version: `2.4.0` (`MIN_GH_VERSION` in `gh-cli.js`), floored by
|
|
74
74
|
the flags used (`gh auth token --hostname`, plain `gh auth status`).
|
|
75
75
|
`gh auth status --json hosts` is attempted first and plain-text parsing
|
|
76
|
-
is the fallback
|
|
77
|
-
|
|
76
|
+
is the fallback for gh versions that reject `--json` (2.46 does). Current
|
|
77
|
+
gh lists every account signed in to a host; status reports one entry per
|
|
78
|
+
host, the active account, and counts it signed in only when its `state`
|
|
79
|
+
is `success`.
|
|
78
80
|
- Token: `gh auth token --hostname <host>` via `execFile` (arg array, no
|
|
79
81
|
shell), 5 s timeout, memory only, ~30 s cache per host.
|
|
80
82
|
- Pinning: `withPinnedCredential(host, task)` reads the token once per
|
|
@@ -92,24 +92,50 @@ export const parsePlainAuthStatus = (text) => {
|
|
|
92
92
|
};
|
|
93
93
|
|
|
94
94
|
const parseJsonAuthStatus = (text) => {
|
|
95
|
-
//
|
|
96
|
-
// `{ "hosts": { "github.com": { "
|
|
97
|
-
//
|
|
95
|
+
// `gh auth status --json hosts` shapes seen in the wild:
|
|
96
|
+
// `{ "hosts": { "github.com": [ { "login": "...", "state": "success", ... } ] } }`
|
|
97
|
+
// (current gh), a flat `{ "hosts": { "github.com": { ... } } }`, and
|
|
98
|
+
// `{ "hosts": [ { "hostname": "...", "user": "..." } ] }`.
|
|
98
99
|
const parsed = JSON.parse(String(text || ''));
|
|
99
100
|
const raw = parsed?.hosts;
|
|
100
|
-
const entries =
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
const entries = [];
|
|
102
|
+
const push = (hostname, info) => {
|
|
103
|
+
// A host maps to every account signed in there. The module follows gh's
|
|
104
|
+
// active account, so keep that one (or the first, if none is marked).
|
|
105
|
+
const accounts = (Array.isArray(info) ? info : [info])
|
|
106
|
+
.filter((account) => account && typeof account === 'object');
|
|
107
|
+
const account = accounts.find((candidate) => candidate.active === true) || accounts[0];
|
|
108
|
+
if (account) entries.push({ hostname, ...account });
|
|
109
|
+
};
|
|
110
|
+
if (Array.isArray(raw)) {
|
|
111
|
+
for (const info of raw) push(info?.hostname || info?.host, info);
|
|
112
|
+
} else if (raw && typeof raw === 'object') {
|
|
113
|
+
for (const [hostname, info] of Object.entries(raw)) push(hostname, info);
|
|
114
|
+
}
|
|
103
115
|
const hosts = [];
|
|
104
116
|
for (const entry of entries) {
|
|
105
117
|
const host = String(entry.hostname || entry.host || '').trim().toLowerCase();
|
|
106
118
|
if (!host) continue;
|
|
107
|
-
const login =
|
|
119
|
+
const login = [entry.login, entry.user].find((value) => typeof value === 'string' && value) || null;
|
|
120
|
+
// `scopes` is a comma-separated string on current gh; older shapes used an array.
|
|
121
|
+
const rawScopes = entry.tokenScopes ?? entry.scopes;
|
|
122
|
+
const scopes = Array.isArray(rawScopes)
|
|
123
|
+
? rawScopes.filter((scope) => typeof scope === 'string')
|
|
124
|
+
: (typeof rawScopes === 'string'
|
|
125
|
+
? rawScopes.split(',').map((scope) => scope.trim()).filter(Boolean)
|
|
126
|
+
: []);
|
|
127
|
+
// `state` is the verdict. A record for a rejected token still carries
|
|
128
|
+
// `active: true` (and can carry a login), so neither proves the token
|
|
129
|
+
// works: `gh` exits successfully in JSON mode and the error is only in
|
|
130
|
+
// `state`. Shapes without `state` fall back to the legacy predicate.
|
|
131
|
+
const authenticated = typeof entry.state === 'string'
|
|
132
|
+
? entry.state === 'success'
|
|
133
|
+
: Boolean(login || entry.active === true);
|
|
108
134
|
hosts.push({
|
|
109
135
|
host,
|
|
110
|
-
authenticated
|
|
136
|
+
authenticated,
|
|
111
137
|
login,
|
|
112
|
-
scopes
|
|
138
|
+
scopes,
|
|
113
139
|
});
|
|
114
140
|
}
|
|
115
141
|
return hosts;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { createGhCli } from './gh-cli.js';
|
|
4
|
+
|
|
5
|
+
const { parseJsonAuthStatus } = createGhCli()._internals;
|
|
6
|
+
|
|
7
|
+
describe('parseJsonAuthStatus', () => {
|
|
8
|
+
it('reads the current gh shape, where each host maps to a list of accounts', () => {
|
|
9
|
+
// `gh auth status --json hosts` on gh 2.103.
|
|
10
|
+
const hosts = parseJsonAuthStatus(JSON.stringify({
|
|
11
|
+
hosts: {
|
|
12
|
+
'github.com': [
|
|
13
|
+
{
|
|
14
|
+
state: 'success',
|
|
15
|
+
active: true,
|
|
16
|
+
host: 'github.com',
|
|
17
|
+
login: 'octocat',
|
|
18
|
+
tokenSource: 'keyring',
|
|
19
|
+
scopes: 'gist, read:org, repo, workflow',
|
|
20
|
+
gitProtocol: 'https',
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
expect(hosts).toEqual([
|
|
27
|
+
{
|
|
28
|
+
host: 'github.com',
|
|
29
|
+
authenticated: true,
|
|
30
|
+
login: 'octocat',
|
|
31
|
+
scopes: ['gist', 'read:org', 'repo', 'workflow'],
|
|
32
|
+
},
|
|
33
|
+
]);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('keeps only the active account when a host has several', () => {
|
|
37
|
+
const hosts = parseJsonAuthStatus(JSON.stringify({
|
|
38
|
+
hosts: {
|
|
39
|
+
'github.com': [
|
|
40
|
+
{ state: 'success', active: false, host: 'github.com', login: 'work-account', scopes: 'repo' },
|
|
41
|
+
{ state: 'success', active: true, host: 'github.com', login: 'octocat', scopes: 'gist, repo' },
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
}));
|
|
45
|
+
|
|
46
|
+
expect(hosts).toEqual([
|
|
47
|
+
{ host: 'github.com', authenticated: true, login: 'octocat', scopes: ['gist', 'repo'] },
|
|
48
|
+
]);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('reads a flat per-host object', () => {
|
|
52
|
+
const hosts = parseJsonAuthStatus(JSON.stringify({
|
|
53
|
+
hosts: { 'github.com': { user: 'octocat', tokenScopes: ['repo'] } },
|
|
54
|
+
}));
|
|
55
|
+
|
|
56
|
+
expect(hosts).toEqual([
|
|
57
|
+
{ host: 'github.com', authenticated: true, login: 'octocat', scopes: ['repo'] },
|
|
58
|
+
]);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('reads a top-level array of hosts', () => {
|
|
62
|
+
const hosts = parseJsonAuthStatus(JSON.stringify({
|
|
63
|
+
hosts: [{ hostname: 'github.com', user: 'octocat' }],
|
|
64
|
+
}));
|
|
65
|
+
|
|
66
|
+
expect(hosts).toEqual([
|
|
67
|
+
{ host: 'github.com', authenticated: true, login: 'octocat', scopes: [] },
|
|
68
|
+
]);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('reports a logged-out host as unauthenticated', () => {
|
|
72
|
+
const hosts = parseJsonAuthStatus(JSON.stringify({ hosts: { 'github.com': [] } }));
|
|
73
|
+
|
|
74
|
+
expect(hosts).toEqual([]);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('does not report a rejected token as authenticated', () => {
|
|
78
|
+
// gh 2.103.3 for an invalid token: it still exits successfully in JSON
|
|
79
|
+
// mode and still sets `active: true`, so only `state` is trustworthy.
|
|
80
|
+
const hosts = parseJsonAuthStatus(JSON.stringify({
|
|
81
|
+
hosts: {
|
|
82
|
+
'github.com': [
|
|
83
|
+
{
|
|
84
|
+
state: 'error',
|
|
85
|
+
error: 'non-200 OK status code: 401 Unauthorized',
|
|
86
|
+
active: true,
|
|
87
|
+
host: 'github.com',
|
|
88
|
+
login: '',
|
|
89
|
+
tokenSource: 'GH_TOKEN',
|
|
90
|
+
gitProtocol: 'https',
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
state: 'success',
|
|
94
|
+
active: false,
|
|
95
|
+
host: 'github.com',
|
|
96
|
+
login: 'octocat',
|
|
97
|
+
tokenSource: 'keyring',
|
|
98
|
+
scopes: 'repo',
|
|
99
|
+
gitProtocol: 'https',
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
},
|
|
103
|
+
}));
|
|
104
|
+
|
|
105
|
+
// The host reports its active account only. The valid inactive one is not
|
|
106
|
+
// what `gh auth token` hands out, so it must not make the host read as
|
|
107
|
+
// signed in.
|
|
108
|
+
expect(hosts).toEqual([
|
|
109
|
+
{ host: 'github.com', authenticated: false, login: null, scopes: [] },
|
|
110
|
+
]);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('trusts state over a login when the token was rejected', () => {
|
|
114
|
+
const hosts = parseJsonAuthStatus(JSON.stringify({
|
|
115
|
+
hosts: { 'github.com': { state: 'error', active: true, login: 'octocat' } },
|
|
116
|
+
}));
|
|
117
|
+
|
|
118
|
+
expect(hosts).toEqual([
|
|
119
|
+
{ host: 'github.com', authenticated: false, login: 'octocat', scopes: [] },
|
|
120
|
+
]);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
@@ -21,6 +21,9 @@ export const createPiNotificationTracker = ({ emit }) => {
|
|
|
21
21
|
|
|
22
22
|
const accept = (event) => {
|
|
23
23
|
if (!event || typeof event.sessionId !== 'string') return;
|
|
24
|
+
// A draft session (warmed for a new-session draft, nothing sent yet)
|
|
25
|
+
// only runs its extensions' control commands; that is not work to report.
|
|
26
|
+
if (event.draft === true) return;
|
|
24
27
|
if (event.name === 'session.snapshot') {
|
|
25
28
|
const snapshot = event.payload?.snapshot;
|
|
26
29
|
if (typeof snapshot?.title === 'string' && snapshot.title.trim()) {
|
|
@@ -29,6 +29,16 @@ describe('Pi notification tracker', () => {
|
|
|
29
29
|
})]);
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
+
it('ignores a draft session, whose only work is its extensions\' control commands', () => {
|
|
33
|
+
const notifications = [];
|
|
34
|
+
const tracker = createPiNotificationTracker({ emit: (payload) => notifications.push(payload) });
|
|
35
|
+
|
|
36
|
+
tracker.accept({ ...event('session.lifecycle', 1, { state: 'busy' }), draft: true });
|
|
37
|
+
tracker.accept({ ...event('session.lifecycle', 2, { state: 'idle' }), draft: true });
|
|
38
|
+
|
|
39
|
+
expect(notifications).toEqual([]);
|
|
40
|
+
});
|
|
41
|
+
|
|
32
42
|
it('collapses message and lifecycle error boundaries into one notification', () => {
|
|
33
43
|
const notifications = [];
|
|
34
44
|
const tracker = createPiNotificationTracker({ emit: (payload) => notifications.push(payload) });
|
|
@@ -12,7 +12,7 @@ When a tool on the server machine wants to show the person a URL (an extension s
|
|
|
12
12
|
4. Devices ask the person whether to open it (`packages/ui/src/components/chat/OpenRequestAlerts.tsx`). Nothing opens without a click.
|
|
13
13
|
5. The intake answers `{ delivered }`. `delivered` is true only when a device holds a live `/api/pi/events` stream and the daemon published. Otherwise the handler falls back to the original `$BROWSER` list, then `open` (macOS) or `xdg-open`, with `$BROWSER` restored in that child's environment so it cannot loop back.
|
|
14
14
|
|
|
15
|
-
Extensions in PiChamber can call `
|
|
15
|
+
Extensions in PiChamber can call `pichamber.ui.openUrl(ctx, url)` (`globalThis.pichamber`, absent in plain Pi). The older `ctx.ui.openUrl(url)` is removed. The call runs the same handler in-process with the exact session id and resolves whether the URL was shown or opened.
|
|
16
16
|
|
|
17
17
|
## Invariants
|
|
18
18
|
|
|
@@ -61,6 +61,60 @@ export const validateExtensionFormValues = (fields, values) => {
|
|
|
61
61
|
return true;
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
+
// ---------------------------------------------------------------- choose()
|
|
65
|
+
//
|
|
66
|
+
// `pichamber.ui.choose(ctx, title, choices, opts)`: one question, a short list of
|
|
67
|
+
// choices that each have an id, a label and an optional description, and an
|
|
68
|
+
// optional free-text note. A tool can name its own call (`toolCallId`), so a
|
|
69
|
+
// plugin's chat component can draw the question beside what the call shows.
|
|
70
|
+
|
|
71
|
+
const MAX_EXTENSION_CHOICES = 12;
|
|
72
|
+
export const MAX_EXTENSION_CHOICE_ID_CHARS = 64;
|
|
73
|
+
export const MAX_EXTENSION_CHOICE_NOTE_CHARS = 2_000;
|
|
74
|
+
const MAX_EXTENSION_TOOL_CALL_ID_CHARS = 256;
|
|
75
|
+
|
|
76
|
+
/** Choices with a usable id and label, first of each id, at most 12. */
|
|
77
|
+
const sanitizeExtensionChoices = (choices) => {
|
|
78
|
+
if (!Array.isArray(choices)) return [];
|
|
79
|
+
const seen = new Set();
|
|
80
|
+
const out = [];
|
|
81
|
+
for (const choice of choices) {
|
|
82
|
+
if (out.length >= MAX_EXTENSION_CHOICES) break;
|
|
83
|
+
if (!choice || typeof choice !== 'object') continue;
|
|
84
|
+
const id = typeof choice.id === 'string' ? choice.id : '';
|
|
85
|
+
const label = typeof choice.label === 'string' ? choice.label.trim().slice(0, 256) : '';
|
|
86
|
+
if (!id || id.length > MAX_EXTENSION_CHOICE_ID_CHARS || !label || seen.has(id)) continue;
|
|
87
|
+
seen.add(id);
|
|
88
|
+
const description = typeof choice.description === 'string' ? choice.description.trim().slice(0, 512) : '';
|
|
89
|
+
out.push({ id, label, ...(description ? { description } : {}) });
|
|
90
|
+
}
|
|
91
|
+
return out;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/** The fields a `choose` dialog adds to the dialog payload, cleaned. */
|
|
95
|
+
export const projectExtensionChooseFields = (payload) => ({
|
|
96
|
+
choices: sanitizeExtensionChoices(payload?.choices),
|
|
97
|
+
...(payload?.allowNote === true ? { allowNote: true } : {}),
|
|
98
|
+
...(typeof payload?.toolCallId === 'string' && payload.toolCallId.length > 0
|
|
99
|
+
&& payload.toolCallId.length <= MAX_EXTENSION_TOOL_CALL_ID_CHARS
|
|
100
|
+
? { toolCallId: payload.toolCallId }
|
|
101
|
+
: {}),
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Check a `choose` answer against the dialog that was sent. Answers
|
|
106
|
+
* `{ id, note? }`, or `null` when the id is not one of its choices or a note
|
|
107
|
+
* came for a dialog that takes none.
|
|
108
|
+
*/
|
|
109
|
+
export const validateExtensionChoiceAnswer = (dialog, value, note) => {
|
|
110
|
+
if (typeof value !== 'string' || !Array.isArray(dialog?.choices)) return null;
|
|
111
|
+
if (!dialog.choices.some((choice) => choice.id === value)) return null;
|
|
112
|
+
if (note === undefined) return { id: value };
|
|
113
|
+
if (typeof note !== 'string' || note.length > MAX_EXTENSION_CHOICE_NOTE_CHARS || dialog.allowNote !== true) return null;
|
|
114
|
+
const trimmed = note.trim();
|
|
115
|
+
return { id: value, ...(trimmed ? { note: trimmed } : {}) };
|
|
116
|
+
};
|
|
117
|
+
|
|
64
118
|
// ---------------------------------------------------------------- custom()
|
|
65
119
|
//
|
|
66
120
|
// Public shapes for `ctx.ui.custom()` surfaces (extension-custom-host.js).
|
|
@@ -168,21 +168,20 @@ export default function (pi: ExtensionAPI): void {
|
|
|
168
168
|
|
|
169
169
|
// Structured multi-input dialog. PiChamber renders a native form and
|
|
170
170
|
// resolves with a values object; plain pi falls back to sequential prompts.
|
|
171
|
+
type PichamberHandle = {
|
|
172
|
+
ui: { form: (ctx: unknown, title: string, fields: Array<Record<string, unknown>>) => Promise<Record<string, string> | undefined> };
|
|
173
|
+
};
|
|
171
174
|
type FormCtx = Parameters<NonNullable<Parameters<ExtensionAPI['registerCommand']>[1]['handler']>>[1];
|
|
172
175
|
const askAgent = async (ctx: FormCtx): Promise<{ name: string; task: string } | undefined> => {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
]);
|
|
183
|
-
if (!values?.name || !values.task) return undefined;
|
|
184
|
-
return { name: values.name, task: values.task };
|
|
185
|
-
}
|
|
176
|
+
const pichamber = (globalThis as { pichamber?: PichamberHandle }).pichamber;
|
|
177
|
+
if (isPiChamber(ctx) && pichamber) {
|
|
178
|
+
const values = await pichamber.ui.form(ctx, 'Spawn sub-agent', [
|
|
179
|
+
{ id: 'name', label: 'Name', type: 'text', required: true, placeholder: 'research' },
|
|
180
|
+
{ id: 'task', label: 'Task', type: 'textarea', required: true },
|
|
181
|
+
{ id: 'priority', label: 'Priority', type: 'select', options: ['low', 'normal', 'high'], initial: 'normal' },
|
|
182
|
+
]);
|
|
183
|
+
if (!values?.name || !values.task) return undefined;
|
|
184
|
+
return { name: values.name, task: values.task };
|
|
186
185
|
}
|
|
187
186
|
const name = await ctx.ui.input('Sub-agent name');
|
|
188
187
|
if (!name) return undefined;
|
|
@@ -139,6 +139,52 @@ describe('extension public projections', () => {
|
|
|
139
139
|
}))).toBeNull();
|
|
140
140
|
});
|
|
141
141
|
|
|
142
|
+
it('projects choose dialogs with cleaned choices and drops one with nothing to choose', () => {
|
|
143
|
+
const projected = projectEventFrame(frame('extension.dialog', {
|
|
144
|
+
requestId: 'choose-1',
|
|
145
|
+
method: 'choose',
|
|
146
|
+
title: 'Which header?',
|
|
147
|
+
choices: [
|
|
148
|
+
{ id: 'a', label: 'A: Compact', description: 'One row', path: '/secret/a.html' },
|
|
149
|
+
{ id: 'b', label: ' B: Tall ' },
|
|
150
|
+
{ id: 'a', label: 'Same id again' },
|
|
151
|
+
{ id: 'c' },
|
|
152
|
+
null,
|
|
153
|
+
],
|
|
154
|
+
allowNote: true,
|
|
155
|
+
toolCallId: 'call-7',
|
|
156
|
+
html: '<p>never public</p>',
|
|
157
|
+
}));
|
|
158
|
+
expect(projected?.payload).toEqual({
|
|
159
|
+
requestId: 'choose-1',
|
|
160
|
+
method: 'choose',
|
|
161
|
+
title: 'Which header?',
|
|
162
|
+
choices: [
|
|
163
|
+
{ id: 'a', label: 'A: Compact', description: 'One row' },
|
|
164
|
+
{ id: 'b', label: 'B: Tall' },
|
|
165
|
+
],
|
|
166
|
+
allowNote: true,
|
|
167
|
+
toolCallId: 'call-7',
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// No note unless asked for, and an oversized tool call id is left out.
|
|
171
|
+
expect(projectEventFrame(frame('extension.dialog', {
|
|
172
|
+
requestId: 'choose-2',
|
|
173
|
+
method: 'choose',
|
|
174
|
+
title: 'Pick',
|
|
175
|
+
choices: [{ id: 'x', label: 'X' }],
|
|
176
|
+
allowNote: 'yes',
|
|
177
|
+
toolCallId: 'c'.repeat(300),
|
|
178
|
+
}))?.payload).toEqual({ requestId: 'choose-2', method: 'choose', title: 'Pick', choices: [{ id: 'x', label: 'X' }] });
|
|
179
|
+
|
|
180
|
+
expect(projectEventFrame(frame('extension.dialog', {
|
|
181
|
+
requestId: 'choose-3',
|
|
182
|
+
method: 'choose',
|
|
183
|
+
title: 'Pick',
|
|
184
|
+
choices: [{ label: 'no id' }],
|
|
185
|
+
}))).toBeNull();
|
|
186
|
+
});
|
|
187
|
+
|
|
142
188
|
it('projects extension.working events and sanitizes/bounds payloads', () => {
|
|
143
189
|
expect(projectEventFrame(frame('extension.working', { message: 'Thinking\u0000 deeply', visible: true }))).toMatchObject({
|
|
144
190
|
name: 'extension.working',
|
|
@@ -645,3 +691,72 @@ describe('projectMessageRender and message render route passthrough', () => {
|
|
|
645
691
|
});
|
|
646
692
|
});
|
|
647
693
|
|
|
694
|
+
|
|
695
|
+
describe('composer controls', () => {
|
|
696
|
+
let server;
|
|
697
|
+
const listen = (app) => new Promise((resolve, reject) => {
|
|
698
|
+
const s = app.listen(0, '127.0.0.1', () => resolve(s));
|
|
699
|
+
s.once('error', reject);
|
|
700
|
+
});
|
|
701
|
+
afterEach(async () => {
|
|
702
|
+
await new Promise((resolve) => (server ? server.close(() => resolve()) : resolve()));
|
|
703
|
+
server = undefined;
|
|
704
|
+
});
|
|
705
|
+
|
|
706
|
+
it('projects extension.control with the daemon parser and passes removals', () => {
|
|
707
|
+
const control = {
|
|
708
|
+
id: 'mode',
|
|
709
|
+
kind: 'cycle',
|
|
710
|
+
label: 'Mode',
|
|
711
|
+
value: 'balance',
|
|
712
|
+
options: [{ value: 'economy', label: 'Economy', command: 'economy' }, { value: 'balance', label: 'Balance', command: 'balance' }],
|
|
713
|
+
extra: 'dropped',
|
|
714
|
+
};
|
|
715
|
+
expect(projectEventFrame(frame('extension.control', { control }))).toMatchObject({
|
|
716
|
+
name: 'extension.control',
|
|
717
|
+
payload: { control: { id: 'mode', kind: 'cycle', value: 'balance', options: control.options } },
|
|
718
|
+
});
|
|
719
|
+
expect(projectEventFrame(frame('extension.control', { control })).payload.control).not.toHaveProperty('extra');
|
|
720
|
+
expect(projectEventFrame(frame('extension.control', { id: 'mode', removed: true }))).toMatchObject({ payload: { id: 'mode', removed: true } });
|
|
721
|
+
expect(projectEventFrame(frame('extension.control', { control: { ...control, kind: 'slider' } }))).toBeNull();
|
|
722
|
+
expect(projectEventFrame(frame('extension.control', { control: { id: 'mode', remove: true } }))).toBeNull();
|
|
723
|
+
});
|
|
724
|
+
|
|
725
|
+
it('forwards a click and answers whether a command ran', async () => {
|
|
726
|
+
const calls = [];
|
|
727
|
+
let answer = { ran: true };
|
|
728
|
+
const runtime = {
|
|
729
|
+
request: async (command, payload) => {
|
|
730
|
+
calls.push({ command, payload });
|
|
731
|
+
if (answer instanceof Error) throw answer;
|
|
732
|
+
return answer;
|
|
733
|
+
},
|
|
734
|
+
};
|
|
735
|
+
const app = express();
|
|
736
|
+
app.use(express.json());
|
|
737
|
+
registerPiRuntimeRoutes(app, { getPiSessionDaemonRuntime: () => runtime });
|
|
738
|
+
server = await listen(app);
|
|
739
|
+
const url = `http://127.0.0.1:${server.address().port}/api/pi/extensions/control`;
|
|
740
|
+
const post = (body) => fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) });
|
|
741
|
+
|
|
742
|
+
const ok = await post({ sessionId: 's1', id: 'mode', value: 'balance', clientId: 'tab-1', command: '/rm -rf' });
|
|
743
|
+
expect(ok.status).toBe(200);
|
|
744
|
+
await expect(ok.json()).resolves.toEqual({ ran: true });
|
|
745
|
+
// The browser names the control and value only; a command it sends is never forwarded.
|
|
746
|
+
expect(calls).toEqual([{ command: 'extensions.control', payload: { sessionId: 's1', id: 'mode', value: 'balance', clientId: 'tab-1' } }]);
|
|
747
|
+
|
|
748
|
+
answer = { ran: false };
|
|
749
|
+
await expect((await post({ sessionId: 's1', id: 'plan', value: true })).json()).resolves.toEqual({ ran: false });
|
|
750
|
+
|
|
751
|
+
for (const bad of [{}, { sessionId: 's1' }, { sessionId: 's1', id: 'mode', value: 3 }, { sessionId: 's1', id: 'x'.repeat(65) }, { sessionId: 's1', id: 'mode', value: 'v'.repeat(65) }]) {
|
|
752
|
+
const res = await post(bad);
|
|
753
|
+
expect(res.status).toBe(400);
|
|
754
|
+
}
|
|
755
|
+
expect(calls).toHaveLength(2);
|
|
756
|
+
|
|
757
|
+
answer = Object.assign(new Error('gone'), { code: 'CONTROL_UNAVAILABLE' });
|
|
758
|
+
const unavailable = await post({ sessionId: 's1', id: 'ghost' });
|
|
759
|
+
expect(unavailable.status).toBe(409);
|
|
760
|
+
await expect(unavailable.json()).resolves.toEqual({ error: { code: 'CONTROL_UNAVAILABLE' } });
|
|
761
|
+
});
|
|
762
|
+
});
|