@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,237 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { mkdir, mkdtemp, symlink, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
|
|
6
|
+
import visuals, { MAX_PAGE_CHARS, renderHtml, TOOL_NAME } from '../../../plugins/visuals/extension.js';
|
|
7
|
+
import {
|
|
8
|
+
CHOICES_TOOL_NAME,
|
|
9
|
+
MAX_CHOICES_CHARS,
|
|
10
|
+
askChoice,
|
|
11
|
+
choiceResult,
|
|
12
|
+
renderChoices,
|
|
13
|
+
} from '../../../plugins/visuals/choices.js';
|
|
14
|
+
import { MAX_IMAGE_BYTES } from '../../../plugins/visuals/files.js';
|
|
15
|
+
|
|
16
|
+
const project = async () => {
|
|
17
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-visuals-'));
|
|
18
|
+
const cwd = join(root, 'project');
|
|
19
|
+
await mkdir(join(cwd, 'out'), { recursive: true });
|
|
20
|
+
await writeFile(join(cwd, 'out', 'chart.html'), '<h1>Chart</h1>');
|
|
21
|
+
await writeFile(join(cwd, 'notes.txt'), 'not html');
|
|
22
|
+
await writeFile(join(root, 'secret.html'), '<p>outside</p>');
|
|
23
|
+
return { root, cwd };
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const fakePi = (activeTools = ['read', 'bash']) => {
|
|
27
|
+
const handlers = new Map();
|
|
28
|
+
const pi = {
|
|
29
|
+
tools: [],
|
|
30
|
+
active: [...activeTools],
|
|
31
|
+
registerTool: (tool) => pi.tools.push(tool),
|
|
32
|
+
on: (event, handler) => handlers.set(event, handler),
|
|
33
|
+
getActiveTools: () => [...pi.active],
|
|
34
|
+
setActiveTools: (names) => { pi.active = [...names]; },
|
|
35
|
+
start: (cwd) => handlers.get('session_start')?.({ type: 'session_start', reason: 'startup' }, { cwd }),
|
|
36
|
+
};
|
|
37
|
+
return pi;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
describe('Visuals render_html', () => {
|
|
41
|
+
it('returns a short line and the page in details', async () => {
|
|
42
|
+
await expect(renderHtml({ title: ' Sales ', html: '<p>x</p>', height: 300 })).resolves.toEqual({
|
|
43
|
+
content: [{ type: 'text', text: 'Rendered "Sales".' }],
|
|
44
|
+
details: { title: 'Sales', html: '<p>x</p>', height: 300 },
|
|
45
|
+
});
|
|
46
|
+
await expect(renderHtml({ title: 'No height', html: '<p>x</p>' })).resolves.toMatchObject({ details: { title: 'No height', html: '<p>x</p>' } });
|
|
47
|
+
expect((await renderHtml({ title: 'No height', html: '<p>x</p>' })).details).not.toHaveProperty('height');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('reads a page file inside the project and keeps its content in details', async () => {
|
|
51
|
+
const { cwd } = await project();
|
|
52
|
+
await expect(renderHtml({ title: 'Chart', path: 'out/chart.html' }, { cwd })).resolves.toMatchObject({
|
|
53
|
+
details: { title: 'Chart', html: '<h1>Chart</h1>' },
|
|
54
|
+
});
|
|
55
|
+
await expect(renderHtml({ title: 'Chart', path: join(cwd, 'out', 'chart.html') }, { cwd })).resolves.toMatchObject({ details: { html: '<h1>Chart</h1>' } });
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('keeps file reads inside the project', async () => {
|
|
59
|
+
const { root, cwd } = await project();
|
|
60
|
+
await expect(renderHtml({ title: 't', path: '../secret.html' }, { cwd })).rejects.toThrow(/inside the project/);
|
|
61
|
+
await expect(renderHtml({ title: 't', path: join(root, 'secret.html') }, { cwd })).rejects.toThrow(/inside the project/);
|
|
62
|
+
await symlink(join(root, 'secret.html'), join(cwd, 'link.html'));
|
|
63
|
+
await expect(renderHtml({ title: 't', path: 'link.html' }, { cwd })).rejects.toThrow(/inside the project/);
|
|
64
|
+
await expect(renderHtml({ title: 't', path: 'notes.txt' }, { cwd })).rejects.toThrow(/\.html/);
|
|
65
|
+
await expect(renderHtml({ title: 't', path: 'missing.html' }, { cwd })).rejects.toThrow(/not found/);
|
|
66
|
+
await expect(renderHtml({ title: 't', path: 'out/chart.html' }, {})).rejects.toThrow(/project folder/);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('validates the call', async () => {
|
|
70
|
+
await expect(renderHtml({ title: '', html: '<p>' })).rejects.toThrow(/title/);
|
|
71
|
+
await expect(renderHtml({ title: 'x'.repeat(121), html: '<p>' })).rejects.toThrow(/title/);
|
|
72
|
+
await expect(renderHtml({ title: 't' })).rejects.toThrow(/exactly one/);
|
|
73
|
+
await expect(renderHtml({ title: 't', html: '<p>', path: 'a.html' })).rejects.toThrow(/exactly one/);
|
|
74
|
+
await expect(renderHtml({ title: 't', html: '<p>', height: 50 })).rejects.toThrow(/height/);
|
|
75
|
+
await expect(renderHtml({ title: 't', html: '<p>', height: 2001 })).rejects.toThrow(/height/);
|
|
76
|
+
await expect(renderHtml({ title: 't', html: '<p>', height: 300.5 })).rejects.toThrow(/height/);
|
|
77
|
+
await expect(renderHtml({ title: 't', html: ' ' })).rejects.toThrow(/empty/);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('caps pages at 512,000 characters', async () => {
|
|
81
|
+
await expect(renderHtml({ title: 't', html: 'x'.repeat(MAX_PAGE_CHARS) })).resolves.toBeTruthy();
|
|
82
|
+
await expect(renderHtml({ title: 't', html: 'x'.repeat(MAX_PAGE_CHARS + 1) })).rejects.toThrow(/512000/);
|
|
83
|
+
const { cwd } = await project();
|
|
84
|
+
await writeFile(join(cwd, 'big.html'), 'x'.repeat(MAX_PAGE_CHARS + 1));
|
|
85
|
+
await expect(renderHtml({ title: 't', path: 'big.html' }, { cwd })).rejects.toThrow(/512000/);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('Visuals extension', () => {
|
|
90
|
+
it('registers render_html with the short description and no prompt snippet', () => {
|
|
91
|
+
const pi = fakePi();
|
|
92
|
+
visuals(pi);
|
|
93
|
+
expect(pi.tools.map((tool) => tool.name)).toEqual([TOOL_NAME, CHOICES_TOOL_NAME]);
|
|
94
|
+
expect(pi.tools[0]).toMatchObject({ name: TOOL_NAME, parameters: { required: ['title'] } });
|
|
95
|
+
expect(pi.tools[0].description).toMatch(/^Show a finished, self-contained HTML page/);
|
|
96
|
+
expect(pi.tools[0]).not.toHaveProperty('promptSnippet');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('adds its tools at session start and keeps the other active tools', () => {
|
|
100
|
+
const pi = fakePi(['read', 'bash']);
|
|
101
|
+
visuals(pi);
|
|
102
|
+
pi.start('/p');
|
|
103
|
+
expect(pi.active).toEqual(['read', 'bash', TOOL_NAME, CHOICES_TOOL_NAME]);
|
|
104
|
+
pi.start('/p');
|
|
105
|
+
expect(pi.active).toEqual(['read', 'bash', TOOL_NAME, CHOICES_TOOL_NAME]);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('shows the options, then asks through pichamber.ui.choose with its own tool call id', async () => {
|
|
109
|
+
const pi = fakePi();
|
|
110
|
+
const order = [];
|
|
111
|
+
const asked = [];
|
|
112
|
+
const ctx = { cwd: '/p', ui: {} };
|
|
113
|
+
const pichamber = {
|
|
114
|
+
ui: {
|
|
115
|
+
choose: async (askedCtx, title, choices, opts) => {
|
|
116
|
+
order.push('asked');
|
|
117
|
+
asked.push({ ctx: askedCtx, title, choices, opts });
|
|
118
|
+
return { id: 'b', note: 'darker header' };
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
visuals(pi, pichamber);
|
|
123
|
+
const tool = pi.tools.find((entry) => entry.name === CHOICES_TOOL_NAME);
|
|
124
|
+
const signal = new AbortController().signal;
|
|
125
|
+
const result = await tool.execute('call-9', {
|
|
126
|
+
title: 'Which header?',
|
|
127
|
+
options: [
|
|
128
|
+
{ label: 'Compact', description: 'One row', html: '<p>a</p>' },
|
|
129
|
+
{ label: 'Tall', html: '<p>b</p>' },
|
|
130
|
+
],
|
|
131
|
+
}, signal, (update) => { order.push('shown'); expect(update.details.options).toHaveLength(2); }, ctx);
|
|
132
|
+
|
|
133
|
+
expect(order).toEqual(['shown', 'asked']);
|
|
134
|
+
expect(asked).toEqual([{
|
|
135
|
+
ctx,
|
|
136
|
+
title: 'Which header?',
|
|
137
|
+
choices: [{ id: 'a', label: 'A: Compact', description: 'One row' }, { id: 'b', label: 'B: Tall' }],
|
|
138
|
+
opts: { toolCallId: 'call-9', allowNote: true, signal },
|
|
139
|
+
}]);
|
|
140
|
+
expect(result.content).toEqual([{ type: 'text', text: 'The user chose B: "Tall". Their note: "darker header"' }]);
|
|
141
|
+
expect(result.details).toEqual({
|
|
142
|
+
title: 'Which header?',
|
|
143
|
+
options: [
|
|
144
|
+
{ id: 'a', label: 'Compact', description: 'One row', html: '<p>a</p>' },
|
|
145
|
+
{ id: 'b', label: 'Tall', html: '<p>b</p>' },
|
|
146
|
+
],
|
|
147
|
+
answer: { id: 'b', note: 'darker header' },
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
describe('Visuals render_choices', () => {
|
|
153
|
+
const two = [{ label: 'One', html: '<p>1</p>' }, { label: 'Two', html: '<p>2</p>' }];
|
|
154
|
+
|
|
155
|
+
it('reads pages and images from the project and letters the options', async () => {
|
|
156
|
+
const { cwd } = await project();
|
|
157
|
+
const png = Buffer.from('89504e470d0a1a0a', 'hex');
|
|
158
|
+
await writeFile(join(cwd, 'out', 'shot.png'), png);
|
|
159
|
+
await writeFile(join(cwd, 'out', 'logo.svg'), '<svg xmlns="http://www.w3.org/2000/svg"/>');
|
|
160
|
+
const choices = await renderChoices({
|
|
161
|
+
title: ' Which one? ',
|
|
162
|
+
options: [
|
|
163
|
+
{ label: ' Chart ', path: 'out/chart.html' },
|
|
164
|
+
{ label: 'Shot', description: ' A screenshot ', path: 'out/shot.png' },
|
|
165
|
+
{ label: 'Logo', path: 'out/logo.svg' },
|
|
166
|
+
],
|
|
167
|
+
}, { cwd });
|
|
168
|
+
expect(choices).toEqual({
|
|
169
|
+
title: 'Which one?',
|
|
170
|
+
options: [
|
|
171
|
+
{ id: 'a', label: 'Chart', html: '<h1>Chart</h1>' },
|
|
172
|
+
{ id: 'b', label: 'Shot', description: 'A screenshot', image: `data:image/png;base64,${png.toString('base64')}` },
|
|
173
|
+
{ id: 'c', label: 'Logo', image: expect.stringMatching(/^data:image\/svg\+xml;base64,/) },
|
|
174
|
+
],
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('keeps file reads inside the project and to pages and images', async () => {
|
|
179
|
+
const { root, cwd } = await project();
|
|
180
|
+
await symlink(join(root, 'secret.html'), join(cwd, 'out', 'link.html'));
|
|
181
|
+
const withPath = (path) => renderChoices({ title: 'T', options: [{ label: 'One', html: '<p>1</p>' }, { label: 'Two', path }] }, { cwd });
|
|
182
|
+
await expect(withPath('../secret.html')).rejects.toThrow('Option 2: The file must be inside the project folder.');
|
|
183
|
+
await expect(withPath('out/link.html')).rejects.toThrow(/inside the project folder/);
|
|
184
|
+
await expect(withPath('notes.txt')).rejects.toThrow(/must be \.html, \.htm, \.png/);
|
|
185
|
+
await expect(withPath('out/none.png')).rejects.toThrow(/was not found/);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('validates the call', async () => {
|
|
189
|
+
await expect(renderChoices({ options: two })).rejects.toThrow('title is required.');
|
|
190
|
+
await expect(renderChoices({ title: 'T', options: [two[0]] })).rejects.toThrow('Give 2 to 6 options.');
|
|
191
|
+
await expect(renderChoices({ title: 'T', options: Array(7).fill(two[0]) })).rejects.toThrow('Give 2 to 6 options.');
|
|
192
|
+
await expect(renderChoices({ title: 'T', options: [two[0], { html: '<p>2</p>' }] })).rejects.toThrow('Option 2 needs a label.');
|
|
193
|
+
await expect(renderChoices({ title: 'T', options: [two[0], { label: 'Two' }] })).rejects.toThrow('Option 2 needs exactly one of html or path.');
|
|
194
|
+
await expect(renderChoices({ title: 'T', options: [two[0], { label: 'Two', html: '<p>2</p>', path: 'a.html' }] })).rejects.toThrow('exactly one of html or path');
|
|
195
|
+
await expect(renderChoices({ title: 'T', options: [two[0], { label: 'Two', html: ' ' }] })).rejects.toThrow("Option 2's page is empty.");
|
|
196
|
+
await expect(renderChoices({ title: 'T', options: [two[0], { label: 'x'.repeat(61), html: '<p>2</p>' }] })).rejects.toThrow(/label is longer/);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('caps a page, an image, and the options together', async () => {
|
|
200
|
+
const { cwd } = await project();
|
|
201
|
+
await expect(renderChoices({ title: 'T', options: [two[0], { label: 'Two', html: 'x'.repeat(MAX_PAGE_CHARS + 1) }] }))
|
|
202
|
+
.rejects.toThrow(/Option 2's page is longer/);
|
|
203
|
+
await writeFile(join(cwd, 'out', 'big.png'), Buffer.alloc(MAX_IMAGE_BYTES + 1));
|
|
204
|
+
await expect(renderChoices({ title: 'T', options: [two[0], { label: 'Two', path: 'out/big.png' }] }, { cwd }))
|
|
205
|
+
.rejects.toThrow('Option 2: The image is larger than 750 KB.');
|
|
206
|
+
const page = 'x'.repeat(MAX_PAGE_CHARS);
|
|
207
|
+
const count = Math.floor(MAX_CHOICES_CHARS / MAX_PAGE_CHARS) + 1;
|
|
208
|
+
await expect(renderChoices({ title: 'T', options: Array.from({ length: count }, (_, index) => ({ label: `O${index}`, html: page })) }))
|
|
209
|
+
.rejects.toThrow(/larger than 1500 KB together/);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('asks with a plain list in Pi, and says so when it cannot ask', async () => {
|
|
213
|
+
const choices = await renderChoices({ title: 'Which?', options: two });
|
|
214
|
+
const listed = [];
|
|
215
|
+
const withSelect = { hasUI: true, ui: { select: async (title, names) => { listed.push({ title, names }); return 'B: Two'; } } };
|
|
216
|
+
await expect(askChoice(undefined, withSelect, 'call-1', choices)).resolves.toEqual({ asked: true, id: 'b' });
|
|
217
|
+
expect(listed).toEqual([{ title: 'Which?', names: ['A: One', 'B: Two'] }]);
|
|
218
|
+
await expect(askChoice(undefined, { hasUI: true, ui: { select: async () => undefined } }, 'call-1', choices)).resolves.toEqual({ asked: true });
|
|
219
|
+
await expect(askChoice(undefined, { hasUI: false, ui: {} }, 'call-1', choices)).resolves.toEqual({ asked: false });
|
|
220
|
+
// An id the question never offered counts as no answer.
|
|
221
|
+
await expect(askChoice({ ui: { choose: async () => ({ id: 'z' }) } }, {}, 'call-1', choices)).resolves.toEqual({ asked: true });
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('tells the agent what happened and keeps the answer in details', async () => {
|
|
225
|
+
const choices = await renderChoices({ title: 'Which?', options: two });
|
|
226
|
+
expect(choiceResult(choices, { asked: true, id: 'a' })).toEqual({
|
|
227
|
+
content: [{ type: 'text', text: 'The user chose A: "One".' }],
|
|
228
|
+
details: { ...choices, answer: { id: 'a' } },
|
|
229
|
+
});
|
|
230
|
+
const closed = choiceResult(choices, { asked: true });
|
|
231
|
+
expect(closed.content[0].text).toMatch(/^The user closed the question without choosing\./);
|
|
232
|
+
expect(closed.details).toEqual({ ...choices, answer: null });
|
|
233
|
+
const unasked = choiceResult(choices, { asked: false });
|
|
234
|
+
expect(unasked.content[0].text).toMatch(/cannot ask for a choice/);
|
|
235
|
+
expect(unasked.details).toEqual(choices);
|
|
236
|
+
});
|
|
237
|
+
});
|
|
@@ -38,7 +38,8 @@ preview proxy (`../preview/proxy-runtime.js`); this module does not.
|
|
|
38
38
|
leave-page dialog, dismissed otherwise);
|
|
39
39
|
- `page-scripts.js`: scripts in an isolated world (copy recording, title
|
|
40
40
|
watching, inspect, cursor).
|
|
41
|
-
- `downloads.js`:
|
|
41
|
+
- `downloads.js`: downloads: progress, files in the temp directory, cancel,
|
|
42
|
+
and Save to server.
|
|
42
43
|
- `uploads.js`: files picked for a page's file chooser, in memory until the
|
|
43
44
|
chooser answer takes them.
|
|
44
45
|
- `dev-servers.js`: lists web servers listening on the server's loopback
|
|
@@ -49,8 +50,9 @@ preview proxy (`../preview/proxy-runtime.js`); this module does not.
|
|
|
49
50
|
- `runtime.js`: HTTP routes and the viewer WebSocket.
|
|
50
51
|
|
|
51
52
|
Files live under `<dataDir>/server-browser/`: `profile/` (cookies, logins,
|
|
52
|
-
site data)
|
|
53
|
-
|
|
53
|
+
site data) and `settings.json`, both owner-only. `uploads/` and `downloads/`
|
|
54
|
+
directories from older versions are deleted on start. Downloads wait in a
|
|
55
|
+
per-run directory in the system temp directory (see Downloads below).
|
|
54
56
|
|
|
55
57
|
## Routes
|
|
56
58
|
|
|
@@ -71,7 +73,13 @@ site data), `downloads/`, and `settings.json`, all owner-only. An
|
|
|
71
73
|
holds the files itself, so a form sent later still has them, and nothing
|
|
72
74
|
is written to the server's disk. A file the page cannot take sends an
|
|
73
75
|
`upload-failed` notice.
|
|
74
|
-
- `GET /api/server-browser/downloads/:id`: a finished download
|
|
76
|
+
- `GET /api/server-browser/downloads/:id`: a finished download, with its
|
|
77
|
+
`Content-Length`.
|
|
78
|
+
- `POST /api/server-browser/downloads/:id/save-to-server`: copies a finished
|
|
79
|
+
download into `~/Downloads` on the server under its own name (`name (1).ext`
|
|
80
|
+
when taken) and returns `{ path }`. Overlapping calls share one copy, and a
|
|
81
|
+
later call returns the same copy while it exists. The temp copy stays, so
|
|
82
|
+
Save to this device keeps working.
|
|
75
83
|
- `GET /api/server-browser/dev-servers?directory=`: web servers on the
|
|
76
84
|
server, the project's own first. Each entry has the port, page title,
|
|
77
85
|
process name, and whether the process runs inside `directory`; never
|
|
@@ -120,13 +128,13 @@ a desktop browser.
|
|
|
120
128
|
|
|
121
129
|
Text messages from the server: `state` (address, title, loading, history,
|
|
122
130
|
crashed), `cursor`, `dialog` / `dialog-closed`, `file-chooser`
|
|
123
|
-
/ `file-chooser-closed`, `download
|
|
131
|
+
/ `file-chooser-closed`, `download` and `download-removed` (see Downloads), `clipboard`, `inspect-hover`,
|
|
124
132
|
`inspect-pick`, `notice`, `popup` (`id`, a page opened a popup for this
|
|
125
133
|
device to show), and `unavailable`.
|
|
126
134
|
|
|
127
135
|
Messages from the viewer: `viewport`, `mouse`, `key`, `text`,
|
|
128
136
|
`navigate`, `back`, `forward`, `reload`, `stop`, `dialog`, `file-chooser`,
|
|
129
|
-
`inspect`, and `ack`. They apply in arrival order; acks skip the queue.
|
|
137
|
+
`download-cancel` (`id`), `inspect`, and `ack`. They apply in arrival order; acks skip the queue.
|
|
130
138
|
Mouse moves and wheel events never wait for Chrome: while one is on its way
|
|
131
139
|
to the page, newer moves replace it and newer wheel movement is added up into
|
|
132
140
|
one event (a change of modifiers starts a new one). Chrome answers a wheel
|
|
@@ -227,7 +235,24 @@ reopens the tab at its last address.
|
|
|
227
235
|
is set. The panel offers it when Chrome refuses its sandbox as root or
|
|
228
236
|
cannot create one (no user namespaces).
|
|
229
237
|
- **Downloads.** Headless Chrome has no PDF viewer, so PDFs arrive as
|
|
230
|
-
downloads.
|
|
238
|
+
downloads. Playwright delivers the file but no progress, so each tab's
|
|
239
|
+
DevTools session also listens to `Page.downloadWillBegin` and
|
|
240
|
+
`Page.downloadProgress`; the two are paired by tab and address in the order
|
|
241
|
+
they arrive (either may come first). A `download` message carries `id`,
|
|
242
|
+
`filename`, `url`, `state` (`inProgress`, `completed`, `canceled` by a
|
|
243
|
+
viewer, or `failed`), `receivedBytes`, `totalBytes` (0 while unknown),
|
|
244
|
+
`path` (once completed), `savedPath` (after Save to server), and
|
|
245
|
+
`startedAt`. Progress goes out at most four times a second; state changes
|
|
246
|
+
at once. Messages go to the viewers of the tab the download came from, and
|
|
247
|
+
a viewer that connects gets the tab's downloads at once. A finished file
|
|
248
|
+
waits at `<tmp>/pichamber-downloads-<random>/<id>/<filename>` (directories
|
|
249
|
+
owner-only, the file `0600`), so the path a viewer copies ends in the real
|
|
250
|
+
name. The temp directory is made on the first download and deleted on
|
|
251
|
+
shutdown; the index is in memory only. Save to server copies the file and
|
|
252
|
+
leaves the temp copy in place. The newest 50 downloads are kept; an older
|
|
253
|
+
one is canceled or deleted, and its viewers get `download-removed` (`id`)
|
|
254
|
+
so they drop the row. On Linux `/tmp` is often in memory,
|
|
255
|
+
so large downloads use RAM until saved elsewhere.
|
|
231
256
|
|
|
232
257
|
## Limits
|
|
233
258
|
|
|
@@ -64,7 +64,7 @@ const navigationError = (error) => {
|
|
|
64
64
|
*
|
|
65
65
|
* Viewers are `{ sendJson(message), sendFrame(buffer), close(reason) }`.
|
|
66
66
|
*/
|
|
67
|
-
export const createServerBrowserTab = ({ key, openPage, guard, onEmpty, onClosed, onPopup = () => {}, onDownload = () => {}, log = () => {} }) => {
|
|
67
|
+
export const createServerBrowserTab = ({ key, openPage, guard, onEmpty, onClosed, onPopup = () => {}, onDownload = () => {}, onDownloadProgress = () => {}, log = () => {} }) => {
|
|
68
68
|
const viewers = new Set();
|
|
69
69
|
const state = {
|
|
70
70
|
url: 'about:blank',
|
|
@@ -312,6 +312,9 @@ export const createServerBrowserTab = ({ key, openPage, guard, onEmpty, onClosed
|
|
|
312
312
|
if (current()) onClosed?.(tab);
|
|
313
313
|
});
|
|
314
314
|
nextPage.on('download', (download) => onDownload(tab, download));
|
|
315
|
+
// Chrome reports progress on the page's session; Playwright does not.
|
|
316
|
+
nextSession.on('Page.downloadWillBegin', ({ guid, url }) => onDownloadProgress(tab, { guid, url }));
|
|
317
|
+
nextSession.on('Page.downloadProgress', ({ guid, receivedBytes, totalBytes, state }) => onDownloadProgress(tab, { guid, receivedBytes, totalBytes, state }));
|
|
315
318
|
nextPage.on('popup', (popup) => {
|
|
316
319
|
if (current()) onPopup(tab, popup);
|
|
317
320
|
else void popup.close().catch(() => {});
|