@firstpick/pi-package-webui 0.7.7 → 0.7.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/bin/pi-webui-rpc-supervisor.mjs +115 -21
- package/bin/pi-webui.mjs +447 -88
- package/lib/queue-mutation.mjs +109 -0
- package/lib/rpc-supervisor-client.mjs +18 -2
- package/lib/rpc-supervisor-protocol.mjs +11 -2
- package/lib/scoped-models.mjs +19 -0
- package/lib/webui-workspaces.mjs +265 -0
- package/package.json +4 -4
- package/public/app.js +2227 -195
- package/public/index.html +143 -2
- package/public/issue-bot-client.mjs +344 -0
- package/public/issue-wizard-state.mjs +443 -0
- package/public/service-worker.js +3 -1
- package/public/styles.css +787 -56
- package/public/voice-conversation.mjs +1 -1
- package/tests/boot-failure-diagnostics.test.mjs +3 -3
- package/tests/compaction-mutation-contract.test.mjs +166 -0
- package/tests/compaction-resume-harness.test.mjs +113 -2
- package/tests/compaction-static.test.mjs +5 -0
- package/tests/completion-signal-contract.test.mjs +156 -0
- package/tests/cwd-footer-reliability-static.test.mjs +112 -0
- package/tests/durable-rpc-supervisor-harness.test.mjs +25 -2
- package/tests/fast-mode-client-static.test.mjs +1 -1
- package/tests/file-selection-overlay-static.test.mjs +21 -0
- package/tests/file-viewer-search-static.test.mjs +65 -0
- package/tests/fixtures/compacting-pi.mjs +0 -0
- package/tests/fixtures/fake-pi.mjs +186 -49
- package/tests/footer-context-contrast-static.test.mjs +10 -0
- package/tests/git-panel-file-preview-static.test.mjs +20 -5
- package/tests/git-panel-render-stability-static.test.mjs +11 -1
- package/tests/http-endpoints-harness.test.mjs +160 -1
- package/tests/issue-bot-client.test.mjs +135 -0
- package/tests/issue-wizard-state.test.mjs +126 -0
- package/tests/mobile-static.test.mjs +61 -42
- package/tests/native-parity.test.mjs +3 -3
- package/tests/open-issue-wizard-static.test.mjs +75 -0
- package/tests/prompt-routing-tab-status.test.mjs +5 -0
- package/tests/queue-edit-reorder-static.test.mjs +101 -0
- package/tests/queue-mutation-contract.test.mjs +143 -0
- package/tests/rpc-supervisor-host.test.mjs +135 -2
- package/tests/rpc-supervisor-protocol.test.mjs +26 -0
- package/tests/scoped-models.test.mjs +42 -0
- package/tests/streaming-ui-coupling.test.mjs +3 -2
- package/tests/subagents-helper.test.mjs +216 -3
- package/tests/terminal-tab-workspace-static.test.mjs +101 -0
- package/tests/webui-workspaces-harness.test.mjs +223 -0
- package/tests/webui-workspaces.test.mjs +106 -0
- package/tests/workspace-save-load-static.test.mjs +69 -0
- package/webui-rpc-helper.mjs +300 -41
package/public/index.html
CHANGED
|
@@ -12,7 +12,17 @@
|
|
|
12
12
|
<link rel="manifest" href="/manifest.webmanifest" />
|
|
13
13
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
|
14
14
|
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
|
|
15
|
-
<link rel="stylesheet" href="/styles.css?v=
|
|
15
|
+
<link rel="stylesheet" href="/styles.css?v=86" />
|
|
16
|
+
<script>
|
|
17
|
+
// Public-only issue-bot runtime configuration. Keep disabled unless the gateway,
|
|
18
|
+
// Turnstile site key, exact CORS origin, and private-report destination are approved.
|
|
19
|
+
window.__PI_WEBUI_ISSUE_BOT_CONFIG__ ??= Object.freeze({
|
|
20
|
+
enabled: false,
|
|
21
|
+
gatewayBaseUrl: "",
|
|
22
|
+
turnstileSiteKey: "",
|
|
23
|
+
privateSecurityReportUrl: "",
|
|
24
|
+
});
|
|
25
|
+
</script>
|
|
16
26
|
<style id="webuiBootFailureStyles">
|
|
17
27
|
.webui-boot-failure[hidden] { display: none !important; }
|
|
18
28
|
.webui-boot-failure {
|
|
@@ -132,6 +142,7 @@
|
|
|
132
142
|
</div>
|
|
133
143
|
<div class="terminal-sidebar-actions" aria-label="Tab and workspace actions">
|
|
134
144
|
<button id="splitTabButton" class="terminal-split-button" type="button" aria-label="Split the active terminal to the right" aria-pressed="false"><svg class="terminal-split-icon terminal-split-icon-split" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><rect x="4" y="5" width="16" height="14" rx="2" fill="none" stroke="currentColor" stroke-width="2"/><path d="M12 5v14M15 12h4m0 0-2-2m2 2-2 2" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg><svg class="terminal-split-icon terminal-split-icon-unsplit" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><rect x="4" y="5" width="16" height="14" rx="2" fill="none" stroke="currentColor" stroke-width="2"/><path d="M12 5v14M19 12h-4m0 0 2-2m-2 2 2 2" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg><span class="terminal-sidebar-action-label terminal-sidebar-action-label-split">Split</span><span class="terminal-sidebar-action-label terminal-sidebar-action-label-unsplit">Unsplit</span></button>
|
|
145
|
+
<button id="workspaceSaveButton" class="terminal-workspace-save-button" type="button" aria-label="Save workspace" data-tooltip="Save workspace: • Captures all open tabs, sessions, order, custom groups, and the active tab. • Available when at least one tab is open."><svg class="terminal-workspace-save-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M5 4h11l3 3v13H5z" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/><path d="M8 4v6h7V4M8 19v-5h8v5" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/></svg><span class="terminal-sidebar-action-label">Save workspace</span></button>
|
|
135
146
|
<button id="commandPaletteButton" class="terminal-command-palette-button" type="button" aria-label="Open command palette" data-tooltip="Command palette: • Search and run actions, slash commands, models, and tabs. • Shortcut: Ctrl/Cmd+K."><svg class="composer-icon command-palette-launcher-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M5 7.5h14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/><path d="M5 12h9" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/><path d="M5 16.5h5" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/><path d="M17 14.5 19.5 17 17 19.5" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg><span class="terminal-sidebar-action-label">Commands</span></button>
|
|
136
147
|
<button id="workspaceDashboardToggleButton" class="terminal-dashboard-button" type="button" aria-controls="workspaceDashboard" aria-expanded="false" aria-label="Show workspace overview" data-tooltip="Workspace overview: • Shows current tab, cwd, model, context, session, and queue. • Opens common workspace/session actions from one place."><svg class="composer-icon workspace-overview-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M4 11.4 12 4l8 7.4" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/><path d="M6.5 10.5V20h11v-9.5" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/><path d="M10 20v-5h4v5" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg><span class="terminal-sidebar-action-label">Overview</span></button>
|
|
137
148
|
</div>
|
|
@@ -148,6 +159,7 @@
|
|
|
148
159
|
<span id="subagentTerminalMeta" class="subagent-terminal-meta muted"></span>
|
|
149
160
|
</div>
|
|
150
161
|
<div class="subagent-terminal-actions">
|
|
162
|
+
<button id="subagentTerminalCancelButton" class="danger" type="button" hidden>Cancel…</button>
|
|
151
163
|
<button id="subagentTerminalCopyButton" type="button">Copy output</button>
|
|
152
164
|
<button id="subagentTerminalRefreshButton" type="button">Refresh</button>
|
|
153
165
|
</div>
|
|
@@ -240,6 +252,9 @@
|
|
|
240
252
|
</button>
|
|
241
253
|
</div>
|
|
242
254
|
<textarea id="promptInput" rows="1" enterkeyhint="enter" placeholder="Ask Pi…" role="combobox" aria-autocomplete="list" aria-controls="commandSuggest" aria-expanded="false" autofocus></textarea>
|
|
255
|
+
<button id="followUpQueueTrigger" class="follow-up-queue-trigger" type="button" aria-controls="followUpQueueOverlay" aria-expanded="false" hidden>
|
|
256
|
+
<span>Queue</span><span id="followUpQueueTriggerCount" class="follow-up-queue-trigger-count">0</span>
|
|
257
|
+
</button>
|
|
243
258
|
<button
|
|
244
259
|
id="attachButton"
|
|
245
260
|
class="composer-icon-button composer-attach-button"
|
|
@@ -250,6 +265,14 @@
|
|
|
250
265
|
><svg class="composer-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M21.44 11.05 12.25 20.24a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.82-2.82l8.48-8.49" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
|
|
251
266
|
<input id="attachmentInput" class="attachment-input" type="file" multiple accept="image/*,video/*,audio/*,text/*,application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/json,application/xml,.md,.markdown,.csv,.ts,.tsx,.js,.jsx,.mjs,.cjs,.py,.rs,.go,.java,.c,.cpp,.h,.hpp,.sh,.bash,.zsh,.fish,.yaml,.yml,.toml,.ini,.log" />
|
|
252
267
|
</div>
|
|
268
|
+
<section id="followUpQueueOverlay" class="follow-up-queue-overlay" aria-label="Queued follow-ups" hidden>
|
|
269
|
+
<header class="follow-up-queue-overlay-header">
|
|
270
|
+
<div><strong>Queued follow-ups</strong><span id="followUpQueueOverlayCount" class="follow-up-queue-overlay-count">0</span></div>
|
|
271
|
+
<button id="followUpQueueCloseButton" class="follow-up-queue-close-button" type="button" aria-label="Close queued follow-ups">×</button>
|
|
272
|
+
</header>
|
|
273
|
+
<div id="followUpQueueRows" class="follow-up-queue-rows"></div>
|
|
274
|
+
<p id="followUpQueueStatus" class="follow-up-queue-status" role="status" aria-live="polite" aria-atomic="true"></p>
|
|
275
|
+
</section>
|
|
253
276
|
<div id="attachmentTray" class="attachment-tray" aria-live="polite" hidden></div>
|
|
254
277
|
<div class="composer-row">
|
|
255
278
|
<button id="composerActionsButton" class="composer-actions-button" type="button" aria-controls="composerActionsPanel" aria-expanded="false" title="Open session, workflow, and follow-up actions">Actions</button>
|
|
@@ -466,6 +489,13 @@
|
|
|
466
489
|
<input id="fileSelectionCommentInput" class="file-selection-comment" type="text" placeholder="Comment for Pi about this selection…" autocomplete="off" />
|
|
467
490
|
<button id="fileSelectionSendButton" class="primary" type="button">Send</button>
|
|
468
491
|
</div>
|
|
492
|
+
<div id="fileViewerSearchBar" class="file-viewer-search-bar" role="search" hidden>
|
|
493
|
+
<input id="fileViewerSearchInput" class="file-viewer-search-input" type="search" placeholder="Search this file…" autocomplete="off" spellcheck="false" aria-label="Search this file" aria-controls="fileViewerEditor" />
|
|
494
|
+
<span id="fileViewerSearchCount" class="file-viewer-search-count muted" aria-live="polite"></span>
|
|
495
|
+
<button id="fileViewerSearchPrevButton" class="file-viewer-search-button" type="button" aria-label="Previous match" title="Previous match (Shift+Enter)">↑</button>
|
|
496
|
+
<button id="fileViewerSearchNextButton" class="file-viewer-search-button" type="button" aria-label="Next match" title="Next match (Enter)">↓</button>
|
|
497
|
+
<button id="fileViewerSearchCloseButton" class="file-viewer-search-button" type="button" aria-label="Close file search" title="Close (Escape)">✕</button>
|
|
498
|
+
</div>
|
|
469
499
|
<div class="file-viewer-mode-row">
|
|
470
500
|
<div class="file-viewer-mode-toggle" role="group" aria-label="File view mode">
|
|
471
501
|
<button id="fileViewerChangesModeButton" type="button" aria-pressed="false" hidden>Changes</button>
|
|
@@ -902,6 +932,9 @@
|
|
|
902
932
|
</div>
|
|
903
933
|
</section>
|
|
904
934
|
</div>
|
|
935
|
+
<footer class="side-panel-footer">
|
|
936
|
+
<button id="openIssueButton" class="open-issue-button" type="button" aria-haspopup="dialog" aria-controls="issueWizardDialog">Open Issue</button>
|
|
937
|
+
</footer>
|
|
905
938
|
</aside>
|
|
906
939
|
</main>
|
|
907
940
|
|
|
@@ -922,6 +955,47 @@
|
|
|
922
955
|
<span class="undo-toast-progress" aria-hidden="true"></span>
|
|
923
956
|
</aside>
|
|
924
957
|
|
|
958
|
+
<dialog id="issueWizardDialog" class="extension-dialog issue-wizard-dialog" aria-labelledby="issueWizardTitle" aria-describedby="issueWizardDescription">
|
|
959
|
+
<form method="dialog">
|
|
960
|
+
<header class="issue-wizard-header">
|
|
961
|
+
<div>
|
|
962
|
+
<span class="issue-wizard-kicker">GitHub issue</span>
|
|
963
|
+
<h2 id="issueWizardTitle">Open an issue</h2>
|
|
964
|
+
<p id="issueWizardDescription" class="muted">Use this five-step wizard to prepare a complete issue you can copy to GitHub.</p>
|
|
965
|
+
</div>
|
|
966
|
+
<button id="issueWizardCloseButton" type="button" aria-label="Close Open Issue wizard">Close</button>
|
|
967
|
+
</header>
|
|
968
|
+
<div class="issue-wizard-progress-row">
|
|
969
|
+
<span id="issueWizardProgress" class="issue-wizard-progress">Step 1 of 5</span>
|
|
970
|
+
<span>1 Category · 2 Component · 3 Template · 4 Details · 5 Review</span>
|
|
971
|
+
</div>
|
|
972
|
+
<div id="issueWizardPages" class="issue-wizard-pages">
|
|
973
|
+
<section class="issue-wizard-page" data-issue-wizard-page="1" aria-label="Step 1: choose issue category" hidden></section>
|
|
974
|
+
<section class="issue-wizard-page" data-issue-wizard-page="2" aria-label="Step 2: choose affected component" hidden></section>
|
|
975
|
+
<section class="issue-wizard-page" data-issue-wizard-page="3" aria-label="Step 3: choose issue template" hidden></section>
|
|
976
|
+
<section class="issue-wizard-page" data-issue-wizard-page="4" aria-label="Step 4: add issue details" hidden></section>
|
|
977
|
+
<section class="issue-wizard-page" data-issue-wizard-page="5" aria-label="Step 5: review GitHub issue" hidden></section>
|
|
978
|
+
</div>
|
|
979
|
+
<p id="issueWizardStatus" class="issue-wizard-status muted" role="status" aria-live="polite" aria-atomic="true">Start by choosing an issue category.</p>
|
|
980
|
+
<section id="issueWizardSubmissionStatus" class="issue-wizard-submission-status" role="status" aria-live="polite" aria-atomic="true" hidden>
|
|
981
|
+
<p id="issueWizardSubmissionMessage" class="issue-wizard-submission-message"></p>
|
|
982
|
+
<div class="issue-wizard-submission-actions">
|
|
983
|
+
<a id="issueWizardSubmissionLink" target="_blank" rel="noopener noreferrer" hidden></a>
|
|
984
|
+
<button id="issueWizardRefreshButton" type="button" hidden>Refresh status</button>
|
|
985
|
+
</div>
|
|
986
|
+
<p id="issueWizardSecurityGuidance" class="issue-wizard-security-guidance" hidden>Do not include security details or credentials in a public issue. <a id="issueWizardSecurityLink" target="_blank" rel="noopener noreferrer" hidden>Use private vulnerability reporting</a>.</p>
|
|
987
|
+
</section>
|
|
988
|
+
<div id="issueWizardTurnstile" class="issue-wizard-turnstile" aria-label="Bot protection challenge"></div>
|
|
989
|
+
<menu class="issue-wizard-actions">
|
|
990
|
+
<button id="issueWizardBackButton" type="button">Back</button>
|
|
991
|
+
<button id="issueWizardContinueButton" class="primary" type="button" disabled>Continue</button>
|
|
992
|
+
<button id="issueWizardCopyButton" type="button" hidden>Copy complete issue</button>
|
|
993
|
+
<button id="issueWizardBotButton" type="button" disabled hidden aria-describedby="issueWizardBotHint issueWizardSubmissionStatus">Send</button>
|
|
994
|
+
</menu>
|
|
995
|
+
<p id="issueWizardBotHint" class="issue-wizard-bot-hint muted" hidden>Automated submission is not enabled. Copy the issue and create it manually instead.</p>
|
|
996
|
+
</form>
|
|
997
|
+
</dialog>
|
|
998
|
+
|
|
925
999
|
<dialog id="piReleaseNotesDialog" class="extension-dialog pi-release-notes-dialog" aria-labelledby="piReleaseNotesTitle">
|
|
926
1000
|
<form method="dialog">
|
|
927
1001
|
<div class="pi-release-notes-header">
|
|
@@ -955,6 +1029,46 @@
|
|
|
955
1029
|
</form>
|
|
956
1030
|
</dialog>
|
|
957
1031
|
|
|
1032
|
+
<dialog id="workspaceLoadDialog" class="extension-dialog workspace-load-dialog" aria-labelledby="workspaceLoadDialogTitle" aria-describedby="workspaceLoadDialogDescription">
|
|
1033
|
+
<form method="dialog">
|
|
1034
|
+
<header class="workspace-load-dialog-header">
|
|
1035
|
+
<div>
|
|
1036
|
+
<span class="workspace-load-dialog-kicker">Saved workspaces</span>
|
|
1037
|
+
<h2 id="workspaceLoadDialogTitle">Load workspace</h2>
|
|
1038
|
+
</div>
|
|
1039
|
+
<button id="workspaceLoadDialogCloseButton" type="button" aria-label="Close saved workspace picker">Close</button>
|
|
1040
|
+
</header>
|
|
1041
|
+
<p id="workspaceLoadDialogDescription" class="muted">Choose a saved tab constellation to restore.</p>
|
|
1042
|
+
<p id="workspaceLoadDialogStatus" class="workspace-load-dialog-status muted" role="status" aria-live="polite"></p>
|
|
1043
|
+
<div id="workspaceLoadDialogList" class="workspace-load-dialog-list" aria-label="Saved workspaces"></div>
|
|
1044
|
+
</form>
|
|
1045
|
+
</dialog>
|
|
1046
|
+
|
|
1047
|
+
<dialog id="workspaceReplaceDialog" class="extension-dialog workspace-replace-dialog" aria-labelledby="workspaceReplaceDialogTitle" aria-describedby="workspaceReplaceDialogDescription">
|
|
1048
|
+
<form method="dialog">
|
|
1049
|
+
<span class="workspace-replace-dialog-kicker">Replace open tabs</span>
|
|
1050
|
+
<h2 id="workspaceReplaceDialogTitle">Load saved workspace</h2>
|
|
1051
|
+
<p id="workspaceReplaceDialogDescription">Loading <strong id="workspaceReplaceTargetName"></strong> will terminate the current Pi processes. Choose whether to save the open tabs first.</p>
|
|
1052
|
+
<section class="workspace-replace-current-tabs" aria-labelledby="workspaceReplaceCurrentTabsTitle">
|
|
1053
|
+
<div class="workspace-replace-current-tabs-heading">
|
|
1054
|
+
<strong id="workspaceReplaceCurrentTabsTitle">Current tabs</strong>
|
|
1055
|
+
<span id="workspaceReplaceCurrentTabsCount" class="muted"></span>
|
|
1056
|
+
</div>
|
|
1057
|
+
<ul id="workspaceReplaceCurrentTabsList" class="workspace-replace-current-tabs-list"></ul>
|
|
1058
|
+
</section>
|
|
1059
|
+
<label class="workspace-replace-save-name" for="workspaceReplaceSaveName">
|
|
1060
|
+
<span>Save current workspace as</span>
|
|
1061
|
+
<input id="workspaceReplaceSaveName" class="dialog-input" type="text" maxlength="160" autocomplete="off" />
|
|
1062
|
+
</label>
|
|
1063
|
+
<p id="workspaceReplaceDialogStatus" class="workspace-replace-dialog-status muted" role="status" aria-live="polite">Cancel leaves every current tab unchanged.</p>
|
|
1064
|
+
<menu>
|
|
1065
|
+
<button id="workspaceReplaceCancelButton" type="button">Cancel</button>
|
|
1066
|
+
<button id="workspaceReplaceDiscardButton" class="danger" type="button">Load without saving</button>
|
|
1067
|
+
<button id="workspaceReplaceSaveButton" class="primary" type="button">Save & load</button>
|
|
1068
|
+
</menu>
|
|
1069
|
+
</form>
|
|
1070
|
+
</dialog>
|
|
1071
|
+
|
|
958
1072
|
<dialog id="gitWorktreeBaseDialog" class="extension-dialog git-worktree-base-dialog">
|
|
959
1073
|
<form method="dialog">
|
|
960
1074
|
<h2>Choose branch starting point</h2>
|
|
@@ -1228,7 +1342,34 @@
|
|
|
1228
1342
|
</form>
|
|
1229
1343
|
</dialog>
|
|
1230
1344
|
|
|
1231
|
-
<
|
|
1345
|
+
<dialog id="subagentCancelDialog" class="extension-dialog subagent-cancel-dialog" aria-labelledby="subagentCancelDialogTitle" aria-describedby="subagentCancelDialogSubtitle">
|
|
1346
|
+
<form method="dialog">
|
|
1347
|
+
<h2 id="subagentCancelDialogTitle">Cancel subagent</h2>
|
|
1348
|
+
<p id="subagentCancelDialogSubtitle" class="muted">Cancel this entire subagent run? Every agent in the run will be stopped and the parent agent will be notified.</p>
|
|
1349
|
+
<label class="subagent-cancel-field" for="subagentCancelReason">Reason <span class="muted">(optional)</span>
|
|
1350
|
+
<select id="subagentCancelReason">
|
|
1351
|
+
<option value="" selected>No reason</option>
|
|
1352
|
+
<option value="Wrong model/provider/thinking effort">Wrong model/provider/thinking effort</option>
|
|
1353
|
+
<option value="Wrong agent or task">Wrong agent or task</option>
|
|
1354
|
+
<option value="Taking too long">Taking too long</option>
|
|
1355
|
+
<option value="Wrong approach or direction">Wrong approach or direction</option>
|
|
1356
|
+
<option value="Output no longer needed">Output no longer needed</option>
|
|
1357
|
+
<option value="Started by mistake">Started by mistake</option>
|
|
1358
|
+
<option value="Other">Other</option>
|
|
1359
|
+
</select>
|
|
1360
|
+
</label>
|
|
1361
|
+
<label class="subagent-cancel-field" for="subagentCancelNote">Note <span class="muted">(optional)</span>
|
|
1362
|
+
<textarea id="subagentCancelNote" class="dialog-editor subagent-cancel-note" spellcheck="true" placeholder="Optional note for the parent agent"></textarea>
|
|
1363
|
+
</label>
|
|
1364
|
+
<p id="subagentCancelStatus" class="subagent-cancel-status muted" role="status" aria-live="polite" hidden></p>
|
|
1365
|
+
<menu>
|
|
1366
|
+
<button id="subagentCancelKeepRunningButton" type="button">Keep running</button>
|
|
1367
|
+
<button id="subagentCancelSubmitButton" class="danger" type="submit">Cancel subagent</button>
|
|
1368
|
+
</menu>
|
|
1369
|
+
</form>
|
|
1370
|
+
</dialog>
|
|
1371
|
+
|
|
1372
|
+
<script id="webuiBootLoader" data-app-src="/app.js?v=92">
|
|
1232
1373
|
(() => {
|
|
1233
1374
|
"use strict";
|
|
1234
1375
|
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
const DEFAULT_POLL_AFTER_MS = 2_500;
|
|
2
|
+
const MIN_POLL_AFTER_MS = 500;
|
|
3
|
+
const MAX_POLL_AFTER_MS = 10_000;
|
|
4
|
+
const DEFAULT_MAX_POLL_DURATION_MS = 120_000;
|
|
5
|
+
const TURNSTILE_SCRIPT_URL = "https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit";
|
|
6
|
+
const TURNSTILE_SCRIPT_ID = "piWebuiIssueBotTurnstile";
|
|
7
|
+
const UUID_V4 = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u;
|
|
8
|
+
const SUBMISSION_ID = /^[A-Za-z0-9_-]{22}$/u;
|
|
9
|
+
const STATUS_TOKEN = /^[A-Za-z0-9_-]{43}$/u;
|
|
10
|
+
|
|
11
|
+
export const ISSUE_BOT_PUBLIC_STATUSES = Object.freeze(["queued", "checking", "created", "rejected", "review", "unavailable", "unknown"]);
|
|
12
|
+
export const ISSUE_BOT_SAFE_REASON_CODES = Object.freeze([
|
|
13
|
+
"invalid_submission", "sensitive_content", "rate_limited", "not_accepted", "manual_review", "admission_disabled", "unavailable", "unknown",
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
/** This public configuration intentionally contains no credential and is disabled by default. */
|
|
17
|
+
export const ISSUE_BOT_DEFAULT_RUNTIME_CONFIG = Object.freeze({
|
|
18
|
+
enabled: false,
|
|
19
|
+
gatewayBaseUrl: "",
|
|
20
|
+
turnstileSiteKey: "",
|
|
21
|
+
privateSecurityReportUrl: "",
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
function isPlainObject(value) {
|
|
25
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function exactObject(value, keys) {
|
|
29
|
+
if (!isPlainObject(value)) return false;
|
|
30
|
+
const actual = Object.keys(value).sort();
|
|
31
|
+
const expected = [...keys].sort();
|
|
32
|
+
return actual.length === expected.length && actual.every((key, index) => key === expected[index]);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function safeHttpsUrl(value, { allowPath = true } = {}) {
|
|
36
|
+
if (typeof value !== "string" || !value.trim()) return "";
|
|
37
|
+
try {
|
|
38
|
+
const url = new URL(value);
|
|
39
|
+
if (url.protocol !== "https:" || url.username || url.password || url.search || url.hash) return "";
|
|
40
|
+
if (!allowPath && url.pathname !== "/") return "";
|
|
41
|
+
return url.href.replace(/\/$/u, "");
|
|
42
|
+
} catch {
|
|
43
|
+
return "";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Read only an explicit, pre-app-load public configuration object. Query strings,
|
|
49
|
+
* storage, and server credentials are deliberately not configuration channels.
|
|
50
|
+
*/
|
|
51
|
+
export function readIssueBotRuntimeConfig(value = globalThis.__PI_WEBUI_ISSUE_BOT_CONFIG__) {
|
|
52
|
+
const source = isPlainObject(value) ? value : ISSUE_BOT_DEFAULT_RUNTIME_CONFIG;
|
|
53
|
+
const gatewayBaseUrl = safeHttpsUrl(source.gatewayBaseUrl);
|
|
54
|
+
const privateSecurityReportUrl = safeHttpsUrl(source.privateSecurityReportUrl);
|
|
55
|
+
const turnstileSiteKey = typeof source.turnstileSiteKey === "string" && /^[A-Za-z0-9_-]{1,2048}$/u.test(source.turnstileSiteKey)
|
|
56
|
+
? source.turnstileSiteKey
|
|
57
|
+
: "";
|
|
58
|
+
const enabled = source.enabled === true && !!gatewayBaseUrl && !!turnstileSiteKey;
|
|
59
|
+
return Object.freeze({ enabled, gatewayBaseUrl, turnstileSiteKey, privateSecurityReportUrl });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function abortError() {
|
|
63
|
+
return new DOMException("Issue bot request aborted.", "AbortError");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function throwIfAborted(signal) {
|
|
67
|
+
if (signal?.aborted) throw abortError();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function waitForDelay(delayMs, signal) {
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
72
|
+
throwIfAborted(signal);
|
|
73
|
+
const timer = setTimeout(() => {
|
|
74
|
+
signal?.removeEventListener("abort", onAbort);
|
|
75
|
+
resolve();
|
|
76
|
+
}, delayMs);
|
|
77
|
+
const onAbort = () => {
|
|
78
|
+
clearTimeout(timer);
|
|
79
|
+
reject(abortError());
|
|
80
|
+
};
|
|
81
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function safeIssue(issue) {
|
|
86
|
+
if (!isPlainObject(issue) || !isPlainObject(issue.fields)) return null;
|
|
87
|
+
const identifiers = ["categoryId", "componentId", "templateId"];
|
|
88
|
+
const output = {};
|
|
89
|
+
for (const key of identifiers) {
|
|
90
|
+
if (typeof issue[key] !== "string" || !issue[key] || issue[key].length > 128) return null;
|
|
91
|
+
output[key] = issue[key];
|
|
92
|
+
}
|
|
93
|
+
if (typeof issue.summary !== "string" || !issue.summary || issue.summary.length > 160) return null;
|
|
94
|
+
const fields = {};
|
|
95
|
+
for (const [key, value] of Object.entries(issue.fields)) {
|
|
96
|
+
if (!key || key.length > 128 || typeof value !== "string" || !value || value.length > 4_000) return null;
|
|
97
|
+
fields[key] = value;
|
|
98
|
+
}
|
|
99
|
+
return { ...output, summary: issue.summary, fields };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function safePollAfterMs(value) {
|
|
103
|
+
return Number.isInteger(value) && value >= MIN_POLL_AFTER_MS && value <= 60_000 ? value : null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function safeSubmissionId(value) {
|
|
107
|
+
return typeof value === "string" && SUBMISSION_ID.test(value) ? value : "";
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function safeReasonCode(value) {
|
|
111
|
+
return typeof value === "string" && ISSUE_BOT_SAFE_REASON_CODES.includes(value) ? value : "";
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function safeGithubIssue(value, number) {
|
|
115
|
+
if (!Number.isSafeInteger(number) || number < 1) return "";
|
|
116
|
+
if (typeof value !== "string") return "";
|
|
117
|
+
try {
|
|
118
|
+
const url = new URL(value);
|
|
119
|
+
if (url.protocol !== "https:" || url.hostname !== "github.com" || url.port || url.username || url.password || url.search || url.hash) return "";
|
|
120
|
+
const match = url.pathname.match(/^\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+\/issues\/([1-9]\d*)$/u);
|
|
121
|
+
if (!match || Number(match[1]) !== number) return "";
|
|
122
|
+
return url.href;
|
|
123
|
+
} catch {
|
|
124
|
+
return "";
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function parseStatusEnvelope(value, { admission = false } = {}) {
|
|
129
|
+
const extra = admission ? ["statusToken"] : [];
|
|
130
|
+
const inFlightKeys = ["ok", "status", "submissionId", "pollAfterMs", ...extra];
|
|
131
|
+
const createdKeys = ["ok", "status", "submissionId", "issueUrl", "issueNumber", ...extra];
|
|
132
|
+
const terminalKeys = ["ok", "status", "submissionId", "reasonCode", ...extra];
|
|
133
|
+
if (!isPlainObject(value) || value.ok !== true || !safeSubmissionId(value.submissionId)) return null;
|
|
134
|
+
if (admission && (typeof value.statusToken !== "string" || !STATUS_TOKEN.test(value.statusToken))) return null;
|
|
135
|
+
if (value.status === "queued" || value.status === "checking") {
|
|
136
|
+
const pollAfterMs = safePollAfterMs(value.pollAfterMs);
|
|
137
|
+
if (!exactObject(value, inFlightKeys) || pollAfterMs === null) return null;
|
|
138
|
+
return Object.freeze({ ok: true, status: value.status, submissionId: value.submissionId, pollAfterMs });
|
|
139
|
+
}
|
|
140
|
+
if (value.status === "created") {
|
|
141
|
+
const issueUrl = safeGithubIssue(value.issueUrl, value.issueNumber);
|
|
142
|
+
if (!exactObject(value, createdKeys) || !issueUrl) return null;
|
|
143
|
+
return Object.freeze({ ok: true, status: "created", submissionId: value.submissionId, issueUrl, issueNumber: value.issueNumber });
|
|
144
|
+
}
|
|
145
|
+
if (["rejected", "review", "unavailable", "unknown"].includes(value.status)) {
|
|
146
|
+
const reasonCode = safeReasonCode(value.reasonCode);
|
|
147
|
+
if (!exactObject(value, terminalKeys) || !reasonCode) return null;
|
|
148
|
+
return Object.freeze({ ok: true, status: value.status, submissionId: value.submissionId, reasonCode });
|
|
149
|
+
}
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function unavailableResult() {
|
|
154
|
+
return Object.freeze({ ok: false, status: "unavailable", reasonCode: "unavailable" });
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function isInFlight(result) {
|
|
158
|
+
return result?.status === "queued" || result?.status === "checking";
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function endpoint(baseUrl, path) {
|
|
162
|
+
return `${baseUrl}${path}`;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async function parseJsonResponse(response) {
|
|
166
|
+
if (!response?.ok) return null;
|
|
167
|
+
try { return await response.json(); } catch { return null; }
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
let turnstileApiPromise = null;
|
|
171
|
+
|
|
172
|
+
function loadTurnstileApi(documentRef) {
|
|
173
|
+
if (globalThis.turnstile?.render) return Promise.resolve(globalThis.turnstile);
|
|
174
|
+
if (turnstileApiPromise) return turnstileApiPromise;
|
|
175
|
+
turnstileApiPromise = new Promise((resolve, reject) => {
|
|
176
|
+
const existing = documentRef.getElementById(TURNSTILE_SCRIPT_ID);
|
|
177
|
+
const script = existing || documentRef.createElement("script");
|
|
178
|
+
const finish = () => globalThis.turnstile?.render ? resolve(globalThis.turnstile) : reject(new Error("Turnstile did not initialize."));
|
|
179
|
+
script.addEventListener("load", finish, { once: true });
|
|
180
|
+
script.addEventListener("error", () => reject(new Error("Turnstile failed to load.")), { once: true });
|
|
181
|
+
if (!existing) {
|
|
182
|
+
script.id = TURNSTILE_SCRIPT_ID;
|
|
183
|
+
script.src = TURNSTILE_SCRIPT_URL;
|
|
184
|
+
script.async = true;
|
|
185
|
+
script.defer = true;
|
|
186
|
+
documentRef.head.append(script);
|
|
187
|
+
}
|
|
188
|
+
}).catch((error) => {
|
|
189
|
+
turnstileApiPromise = null;
|
|
190
|
+
throw error;
|
|
191
|
+
});
|
|
192
|
+
return turnstileApiPromise;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** Acquire one non-persisted Turnstile token for the current dialog submission. */
|
|
196
|
+
export async function getIssueBotTurnstileToken({ siteKey, idempotencyKey, container, signal, documentRef = globalThis.document } = {}) {
|
|
197
|
+
throwIfAborted(signal);
|
|
198
|
+
if (!documentRef || !container || typeof siteKey !== "string" || !siteKey || typeof idempotencyKey !== "string" || !UUID_V4.test(idempotencyKey)) {
|
|
199
|
+
throw new Error("Turnstile is unavailable.");
|
|
200
|
+
}
|
|
201
|
+
const api = await loadTurnstileApi(documentRef);
|
|
202
|
+
throwIfAborted(signal);
|
|
203
|
+
return new Promise((resolve, reject) => {
|
|
204
|
+
let widgetId;
|
|
205
|
+
let settled = false;
|
|
206
|
+
const cleanup = () => {
|
|
207
|
+
signal?.removeEventListener("abort", onAbort);
|
|
208
|
+
if (widgetId !== undefined) {
|
|
209
|
+
try { api.remove?.(widgetId); } catch { /* Turnstile cleanup is best effort. */ }
|
|
210
|
+
}
|
|
211
|
+
container.replaceChildren();
|
|
212
|
+
};
|
|
213
|
+
const finish = (callback) => (value) => {
|
|
214
|
+
if (settled) return;
|
|
215
|
+
settled = true;
|
|
216
|
+
cleanup();
|
|
217
|
+
callback(value);
|
|
218
|
+
};
|
|
219
|
+
const onAbort = finish(() => reject(abortError()));
|
|
220
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
221
|
+
try {
|
|
222
|
+
widgetId = api.render(container, {
|
|
223
|
+
sitekey: siteKey,
|
|
224
|
+
action: "issue_bot_submit",
|
|
225
|
+
cData: idempotencyKey,
|
|
226
|
+
size: "invisible",
|
|
227
|
+
callback: finish((token) => typeof token === "string" && token ? resolve(token) : reject(new Error("Turnstile returned no token."))),
|
|
228
|
+
"error-callback": finish(() => reject(new Error("Turnstile verification failed."))),
|
|
229
|
+
"expired-callback": finish(() => reject(new Error("Turnstile token expired."))),
|
|
230
|
+
"timeout-callback": finish(() => reject(new Error("Turnstile timed out."))),
|
|
231
|
+
});
|
|
232
|
+
api.execute?.(widgetId);
|
|
233
|
+
} catch (error) {
|
|
234
|
+
finish(() => reject(error))();
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Dependency-injected browser adapter. It owns network protocol validation and never
|
|
241
|
+
* persists the status capability; callers retain only an opaque in-memory refresh handle.
|
|
242
|
+
*/
|
|
243
|
+
export function createIssueBotClient({
|
|
244
|
+
config = readIssueBotRuntimeConfig(),
|
|
245
|
+
fetchImpl = globalThis.fetch?.bind(globalThis),
|
|
246
|
+
getTurnstileToken = getIssueBotTurnstileToken,
|
|
247
|
+
uuidFactory = () => globalThis.crypto?.randomUUID?.(),
|
|
248
|
+
now = () => Date.now(),
|
|
249
|
+
sleep = waitForDelay,
|
|
250
|
+
maxPollDurationMs = DEFAULT_MAX_POLL_DURATION_MS,
|
|
251
|
+
turnstileContainer = null,
|
|
252
|
+
} = {}) {
|
|
253
|
+
const runtimeConfig = readIssueBotRuntimeConfig(config);
|
|
254
|
+
const available = runtimeConfig.enabled && typeof fetchImpl === "function" && typeof getTurnstileToken === "function" && typeof uuidFactory === "function";
|
|
255
|
+
|
|
256
|
+
async function requestAdmission(issue, signal) {
|
|
257
|
+
const idempotencyKey = uuidFactory();
|
|
258
|
+
if (typeof idempotencyKey !== "string" || !UUID_V4.test(idempotencyKey)) return null;
|
|
259
|
+
const turnstileToken = await getTurnstileToken({ siteKey: runtimeConfig.turnstileSiteKey, idempotencyKey, container: turnstileContainer, signal });
|
|
260
|
+
throwIfAborted(signal);
|
|
261
|
+
if (typeof turnstileToken !== "string" || !turnstileToken || turnstileToken.length > 2_048) return null;
|
|
262
|
+
const response = await fetchImpl(endpoint(runtimeConfig.gatewayBaseUrl, "/v1/submissions"), {
|
|
263
|
+
method: "POST",
|
|
264
|
+
mode: "cors",
|
|
265
|
+
credentials: "omit",
|
|
266
|
+
cache: "no-store",
|
|
267
|
+
signal,
|
|
268
|
+
headers: { "content-type": "application/json" },
|
|
269
|
+
body: JSON.stringify({ schemaVersion: 1, idempotencyKey, turnstileToken, issue }),
|
|
270
|
+
});
|
|
271
|
+
const body = await parseJsonResponse(response);
|
|
272
|
+
const envelope = parseStatusEnvelope(body, { admission: true });
|
|
273
|
+
if (!envelope || typeof body?.statusToken !== "string" || !STATUS_TOKEN.test(body.statusToken)) return null;
|
|
274
|
+
return { envelope, statusToken: body.statusToken };
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
async function requestStatus(submissionId, statusToken, signal) {
|
|
278
|
+
const response = await fetchImpl(endpoint(runtimeConfig.gatewayBaseUrl, `/v1/submissions/${submissionId}`), {
|
|
279
|
+
method: "GET",
|
|
280
|
+
mode: "cors",
|
|
281
|
+
credentials: "omit",
|
|
282
|
+
cache: "no-store",
|
|
283
|
+
signal,
|
|
284
|
+
headers: { authorization: `Bearer ${statusToken}` },
|
|
285
|
+
});
|
|
286
|
+
return parseStatusEnvelope(await parseJsonResponse(response));
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function createRefreshHandle(admission, statusToken) {
|
|
290
|
+
let latest = admission;
|
|
291
|
+
const poll = async ({ signal, onStatus } = {}) => {
|
|
292
|
+
if (!isInFlight(latest)) return latest;
|
|
293
|
+
const startedAt = now();
|
|
294
|
+
let delayMs = latest.pollAfterMs;
|
|
295
|
+
onStatus?.(latest);
|
|
296
|
+
while (isInFlight(latest)) {
|
|
297
|
+
throwIfAborted(signal);
|
|
298
|
+
const elapsed = now() - startedAt;
|
|
299
|
+
if (!Number.isFinite(elapsed) || elapsed >= maxPollDurationMs) return Object.freeze({ ...latest, timedOut: true });
|
|
300
|
+
await sleep(Math.min(delayMs, Math.max(0, maxPollDurationMs - elapsed)), signal);
|
|
301
|
+
throwIfAborted(signal);
|
|
302
|
+
let next;
|
|
303
|
+
try { next = await requestStatus(latest.submissionId, statusToken, signal); } catch (error) {
|
|
304
|
+
if (error?.name === "AbortError") throw error;
|
|
305
|
+
latest = unavailableResult();
|
|
306
|
+
onStatus?.(latest);
|
|
307
|
+
return latest;
|
|
308
|
+
}
|
|
309
|
+
if (!next || next.submissionId !== latest.submissionId) {
|
|
310
|
+
latest = unavailableResult();
|
|
311
|
+
onStatus?.(latest);
|
|
312
|
+
return latest;
|
|
313
|
+
}
|
|
314
|
+
latest = next;
|
|
315
|
+
onStatus?.(latest);
|
|
316
|
+
delayMs = Math.min(MAX_POLL_AFTER_MS, Math.max(delayMs * 2, latest.pollAfterMs || DEFAULT_POLL_AFTER_MS));
|
|
317
|
+
}
|
|
318
|
+
return latest;
|
|
319
|
+
};
|
|
320
|
+
return Object.freeze({ refresh: poll });
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
return Object.freeze({
|
|
324
|
+
available,
|
|
325
|
+
runtimeConfig,
|
|
326
|
+
async submit({ issue, signal, onStatus } = {}) {
|
|
327
|
+
if (!available) return Object.freeze({ result: unavailableResult(), handle: null });
|
|
328
|
+
const structuredIssue = safeIssue(issue);
|
|
329
|
+
if (!structuredIssue) return Object.freeze({ result: unavailableResult(), handle: null });
|
|
330
|
+
let admission;
|
|
331
|
+
try { admission = await requestAdmission(structuredIssue, signal); } catch (error) {
|
|
332
|
+
if (error?.name === "AbortError") throw error;
|
|
333
|
+
return Object.freeze({ result: unavailableResult(), handle: null });
|
|
334
|
+
}
|
|
335
|
+
if (!admission) return Object.freeze({ result: unavailableResult(), handle: null });
|
|
336
|
+
const { envelope, statusToken } = admission;
|
|
337
|
+
onStatus?.(envelope);
|
|
338
|
+
if (!isInFlight(envelope)) return Object.freeze({ result: envelope, handle: null });
|
|
339
|
+
const handle = createRefreshHandle(envelope, statusToken);
|
|
340
|
+
const result = await handle.refresh({ signal, onStatus });
|
|
341
|
+
return Object.freeze({ result, handle });
|
|
342
|
+
},
|
|
343
|
+
});
|
|
344
|
+
}
|