@firstpick/pi-package-webui 0.11.1 → 0.11.3
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/DEVELOPMENT.md +151 -12
- package/README.md +34 -6
- package/TECHNICAL.md +75 -8
- package/bin/pi-webui.mjs +5390 -11423
- package/index.ts +10 -3
- package/lib/component-update-state.mjs +2 -2
- package/lib/git-workflow-preference-values.mjs +122 -0
- package/lib/git-workflow-preferences.mjs +35 -563
- package/lib/package-updates.mjs +260 -0
- package/lib/rpc-supervisor-client.mjs +8 -4
- package/lib/server/app-runners.mjs +1667 -0
- package/lib/server/codex-fast-mode.mjs +161 -0
- package/lib/server/conversation-mode.mjs +218 -0
- package/lib/server/conversation-voice.mjs +318 -0
- package/lib/server/extension-ui-requests.mjs +114 -0
- package/lib/server/git-generation.mjs +459 -0
- package/lib/server/git-mutations.mjs +1827 -0
- package/lib/server/git-reads.mjs +608 -0
- package/lib/server/git-worktree-sessions.mjs +408 -0
- package/lib/server/helper-requests.mjs +82 -0
- package/lib/server/no-project-workspaces.mjs +103 -0
- package/lib/server/rpc-transports.mjs +394 -0
- package/lib/server/settings-store.mjs +544 -0
- package/lib/server/sse-delivery.mjs +138 -0
- package/lib/server/workspace-files.mjs +563 -0
- package/lib/update/supervisor.mjs +4 -0
- package/lib/webui-workspaces.mjs +2 -0
- package/package.json +4 -4
- package/public/activity-agents-controller.mjs +269 -0
- package/public/activity-events-controller.mjs +236 -0
- package/public/activity-intercom-controller.mjs +627 -0
- package/public/activity-queue-controller.mjs +534 -0
- package/public/activity-todo-view.mjs +89 -0
- package/public/activity-usage-controller.mjs +589 -0
- package/public/app.js +3761 -3886
- package/public/conversation-overview.css +84 -0
- package/public/conversation-overview.mjs +193 -0
- package/public/draft-conversations.mjs +135 -0
- package/public/focused-composer-controls.css +111 -0
- package/public/focused-composer-controls.mjs +143 -0
- package/public/focused-composer-disclosure.mjs +223 -0
- package/public/focused-shell-adapter.css +264 -0
- package/public/focused-shell-adapter.mjs +257 -0
- package/public/index.html +137 -80
- package/public/model-catalog-order.mjs +63 -0
- package/public/platform-event-stream.mjs +64 -0
- package/public/project-artifact-controller.mjs +218 -0
- package/public/project-file-viewer-controller.mjs +383 -0
- package/public/project-git-tools-controller.mjs +181 -0
- package/public/project-runners-controller.mjs +220 -0
- package/public/service-worker.js +52 -1
- package/public/session-attention-scheduler.mjs +182 -0
- package/public/session-composer-store.mjs +56 -0
- package/public/session-context.mjs +51 -0
- package/public/session-extension-requests.mjs +63 -0
- package/public/session-shelf-state.mjs +151 -0
- package/public/session-shelves.css +171 -0
- package/public/session-shelves.mjs +95 -0
- package/public/settings-navigation-controller.mjs +249 -0
- package/public/settings-navigation.css +61 -0
- package/public/settings-resource-controller.mjs +232 -0
- package/public/settings-workspace.css +19 -0
- package/public/settings-workspace.mjs +175 -0
- package/public/shell-actions.mjs +87 -0
- package/public/shell-attention-inbox.css +72 -0
- package/public/shell-attention-inbox.mjs +198 -0
- package/public/shell-context-actions.css +61 -0
- package/public/shell-context-actions.mjs +168 -0
- package/public/shell-inspector-resize.mjs +124 -0
- package/public/shell-navigation-resize.mjs +107 -0
- package/public/shell-navigation.mjs +127 -0
- package/public/shell-preferences.mjs +108 -0
- package/public/shell-surfaces.mjs +99 -0
- package/public/shell-tools-launcher.css +97 -0
- package/public/shell-tools-launcher.mjs +222 -0
- package/public/shell-view-host.mjs +115 -0
- package/public/shell-workspace.css +266 -0
- package/public/shell-workspace.mjs +402 -0
- package/public/sidebar-update-menu.css +190 -0
- package/public/sidebar-update-menu.mjs +512 -0
- package/public/styles.css +322 -169
- package/public/subagent-launch-slot-state.mjs +2 -2
- package/public/themed-selects.css +156 -0
- package/public/workspace-choices.mjs +104 -0
- package/tests/activity-agents-controller.test.mjs +652 -0
- package/tests/activity-events-controller.test.mjs +511 -0
- package/tests/app-runner-terminal-static.test.mjs +3 -3
- package/tests/append-system-http.test.mjs +7 -6
- package/tests/append-system-selector-static.test.mjs +6 -6
- package/tests/aur-review-widget-static.test.mjs +11 -3
- package/tests/boot-failure-diagnostics.test.mjs +8 -3
- package/tests/browser/action-feedback-gutter.spec.mjs +251 -0
- package/tests/browser/activity-intercom-controller.spec.mjs +457 -0
- package/tests/browser/activity-navigation-integration.spec.mjs +45 -0
- package/tests/browser/activity-owner-integration.spec.mjs +201 -0
- package/tests/browser/activity-queue-controller.spec.mjs +405 -0
- package/tests/browser/activity-section-picker.spec.mjs +294 -0
- package/tests/browser/activity-todo-view.spec.mjs +60 -0
- package/tests/browser/activity-usage-controller.spec.mjs +416 -0
- package/tests/browser/compact-layout-integration.spec.mjs +58 -0
- package/tests/browser/composer-action-grid-reorder.spec.mjs +16 -0
- package/tests/browser/composer-disclosure.spec.mjs +389 -0
- package/tests/browser/composer-toolbar-polish.spec.mjs +343 -0
- package/tests/browser/control-deck-component-updates.spec.mjs +5 -14
- package/tests/browser/control-deck-side-panels.spec.mjs +27 -12
- package/tests/browser/control-visibility.spec.mjs +5 -0
- package/tests/browser/controls-layout.spec.mjs +21 -2
- package/tests/browser/conversation-overview.spec.mjs +251 -0
- package/tests/browser/draft-conversations.spec.mjs +276 -0
- package/tests/browser/empty-startup-fixture.mjs +135 -0
- package/tests/browser/empty-startup.spec.mjs +282 -0
- package/tests/browser/events-tree-context-menu.spec.mjs +1 -0
- package/tests/browser/focused-composer-more.spec.mjs +127 -0
- package/tests/browser/focused-model-shortcuts.spec.mjs +120 -0
- package/tests/browser/focused-navigation-fixture.mjs +32 -0
- package/tests/browser/focused-project-activity.spec.mjs +111 -0
- package/tests/browser/focused-shell-integration.spec.mjs +208 -0
- package/tests/browser/folder-picker-layout-fixture.mjs +13 -0
- package/tests/browser/folder-picker-layout.spec.mjs +302 -0
- package/tests/browser/footer-model-advanced-layout.spec.mjs +27 -14
- package/tests/browser/git-setup-cancel.spec.mjs +251 -0
- package/tests/browser/guided-git-fallback.spec.mjs +40 -21
- package/tests/browser/inspector-header.spec.mjs +221 -0
- package/tests/browser/inspector-overview-integration.spec.mjs +104 -0
- package/tests/browser/inspector-resize.spec.mjs +227 -0
- package/tests/browser/inspector-topic-overflow.spec.mjs +56 -0
- package/tests/browser/interaction-action-discovery.spec.mjs +332 -0
- package/tests/browser/interaction-attention-inbox.spec.mjs +364 -0
- package/tests/browser/interaction-attention-integration.spec.mjs +53 -0
- package/tests/browser/interaction-composer-controls.spec.mjs +267 -0
- package/tests/browser/interaction-composer-integration.spec.mjs +175 -0
- package/tests/browser/interaction-continuity.spec.mjs +50 -26
- package/tests/browser/interaction-model-picker.spec.mjs +86 -0
- package/tests/browser/last-terminal-close.spec.mjs +280 -0
- package/tests/browser/mobile-foundation.spec.mjs +172 -20
- package/tests/browser/model-catalog-groups.spec.mjs +104 -0
- package/tests/browser/more-row-menus.spec.mjs +258 -0
- package/tests/browser/new-tab-hit-target.spec.mjs +228 -0
- package/tests/browser/no-project-conversation.spec.mjs +113 -0
- package/tests/browser/optimistic-prompt.spec.mjs +3 -0
- package/tests/browser/overhaul-w7-accessibility.spec.mjs +227 -0
- package/tests/browser/overhaul-w7-capabilities.spec.mjs +298 -0
- package/tests/browser/overhaul-w7-companions.spec.mjs +290 -0
- package/tests/browser/overhaul-w7-focus-repairs.spec.mjs +210 -0
- package/tests/browser/overhaul-w7-layout-repairs.spec.mjs +183 -0
- package/tests/browser/overhaul-w7-parent-repairs.spec.mjs +97 -0
- package/tests/browser/overhaul-w7-pwa.spec.mjs +247 -0
- package/tests/browser/overhaul-w7-responsive.spec.mjs +450 -0
- package/tests/browser/overhaul-w7-update.spec.mjs +215 -0
- package/tests/browser/overhaul-w7-zoom.spec.mjs +243 -0
- package/tests/browser/overview-agent-ownership.spec.mjs +45 -0
- package/tests/browser/persistent-ui-layout.spec.mjs +3 -0
- package/tests/browser/project-artifact-controller.spec.mjs +324 -0
- package/tests/browser/project-artifact-integration.spec.mjs +103 -0
- package/tests/browser/project-file-buffer-integration.spec.mjs +230 -0
- package/tests/browser/project-git-tools-integration.spec.mjs +369 -0
- package/tests/browser/session-fixture.mjs +118 -0
- package/tests/browser/session-ownership.spec.mjs +175 -0
- package/tests/browser/session-shelves-integration.spec.mjs +219 -0
- package/tests/browser/session-shelves.spec.mjs +340 -0
- package/tests/browser/session-sidebar-resize.spec.mjs +138 -0
- package/tests/browser/session-summary.spec.mjs +17 -12
- package/tests/browser/settings-complete-home.spec.mjs +463 -0
- package/tests/browser/settings-entrypoint.spec.mjs +104 -0
- package/tests/browser/settings-navigation-controller.spec.mjs +383 -0
- package/tests/browser/settings-navigation-integration.spec.mjs +348 -0
- package/tests/browser/settings-resource-lifetime.spec.mjs +349 -0
- package/tests/browser/settings-workspace-integration.spec.mjs +132 -0
- package/tests/browser/shell-ownership.spec.mjs +398 -0
- package/tests/browser/shell-rollout-fixture.mjs +259 -0
- package/tests/browser/shell-rollout.spec.mjs +357 -0
- package/tests/browser/shell-tools-launcher.spec.mjs +260 -0
- package/tests/browser/shell-workspace.spec.mjs +433 -0
- package/tests/browser/side-panel-section-reorder.spec.mjs +3 -1
- package/tests/browser/sidebar-floating-tooltips.spec.mjs +37 -0
- package/tests/browser/sidebar-update-integration.spec.mjs +277 -0
- package/tests/browser/sidebar-update-menu.spec.mjs +402 -0
- package/tests/browser/sidebar-update-progress.spec.mjs +472 -0
- package/tests/browser/stream-output-isolation.spec.mjs +6 -3
- package/tests/browser/themed-selects.spec.mjs +297 -0
- package/tests/browser/thread-start-flow.spec.mjs +481 -0
- package/tests/browser/ui-polish-activity-controls.spec.mjs +177 -0
- package/tests/browser/ui-polish-features.spec.mjs +85 -0
- package/tests/browser/ui-polish-file-header.spec.mjs +43 -0
- package/tests/browser/ui-polish-local-git.spec.mjs +183 -0
- package/tests/browser/ui-polish-mobile-recovery.spec.mjs +36 -0
- package/tests/browser/ui-polish-navigation.spec.mjs +127 -0
- package/tests/browser/ui-polish-session-actions.spec.mjs +282 -0
- package/tests/browser/user-noticeable-fixes.spec.mjs +10 -3
- package/tests/browser/windows-drive-parent.spec.mjs +4 -2
- package/tests/browser/workspace-draft-selection.spec.mjs +266 -0
- package/tests/codex-fast-mode-static.test.mjs +16 -11
- package/tests/codex-speed-mode-browser-state.test.mjs +6 -3
- package/tests/codex-usage-source.test.mjs +4 -3
- package/tests/component-update-api-static.test.mjs +2 -2
- package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
- package/tests/control-deck-component-updates-static.test.mjs +9 -4
- package/tests/control-visibility-static.test.mjs +3 -3
- package/tests/controls-layout-static.test.mjs +5 -5
- package/tests/conversation-overview-adapter.test.mjs +100 -0
- package/tests/document-artifact-static.test.mjs +2 -1
- package/tests/draft-conversations.test.mjs +205 -0
- package/tests/empty-startup-launcher.test.mjs +197 -0
- package/tests/events-tree-context-menu-static.test.mjs +22 -18
- package/tests/fake-pi-session-ownership.test.mjs +302 -0
- package/tests/fast-mode-client-static.test.mjs +1 -1
- package/tests/feature-decision-output-popup-static.test.mjs +2 -2
- package/tests/feature-system-prompt-optional-feature-static.test.mjs +1 -1
- package/tests/file-viewer-image-static.test.mjs +15 -11
- package/tests/file-viewer-search-static.test.mjs +5 -5
- package/tests/fixtures/fake-pi.mjs +41 -9
- package/tests/footer-provider-usage-visual-static.test.mjs +7 -6
- package/tests/foreground-transcript-catch-up-static.test.mjs +7 -4
- package/tests/git-footer-context-menu-static.test.mjs +1 -1
- package/tests/git-panel-file-preview-static.test.mjs +41 -48
- package/tests/git-panel-live-updates-static.test.mjs +2 -1
- package/tests/git-workflow-dispatch.test.mjs +66 -0
- package/tests/git-workflow-preferences.test.mjs +9 -1
- package/tests/guided-git-activation-static.test.mjs +14 -11
- package/tests/guided-git-fallback-ui-static.test.mjs +8 -5
- package/tests/guided-git-message-reliability-static.test.mjs +10 -6
- package/tests/guided-git-publication-backend-static.test.mjs +16 -11
- package/tests/http-endpoints-harness.test.mjs +21 -9
- package/tests/interaction-state-stability-static.test.mjs +4 -3
- package/tests/intercom-conversation-viewer-static.test.mjs +29 -17
- package/tests/intercom-tag-layout-static.test.mjs +13 -12
- package/tests/intercom-tag-overflow-layout.test.mjs +11 -10
- package/tests/main-output-loading-static.test.mjs +4 -4
- package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
- package/tests/mobile-compact-layout.test.mjs +2 -2
- package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
- package/tests/mobile-foundation-static.test.mjs +10 -7
- package/tests/mobile-phone-experience-static.test.mjs +3 -2
- package/tests/mobile-static.test.mjs +173 -135
- package/tests/model-catalog-order.test.mjs +103 -0
- package/tests/native-parity.test.mjs +6 -4
- package/tests/native-session-choice-owner.test.mjs +102 -0
- package/tests/native-update-lifecycle.test.mjs +10 -5
- package/tests/no-project-http-harness.test.mjs +328 -0
- package/tests/no-project-navigation.test.mjs +54 -0
- package/tests/no-project-workspaces.test.mjs +77 -0
- package/tests/open-issue-wizard-static.test.mjs +1 -1
- package/tests/optional-feature-migration-frontend.test.mjs +4 -4
- package/tests/optional-feature-prompt-impact-static.test.mjs +3 -3
- package/tests/package-updates.test.mjs +630 -0
- package/tests/persistent-ui-layout-static.test.mjs +3 -3
- package/tests/platform-event-stream.test.mjs +253 -0
- package/tests/project-file-viewer-controller.test.mjs +652 -0
- package/tests/project-git-tools-adapter.test.mjs +103 -0
- package/tests/project-git-tools-controller.test.mjs +577 -0
- package/tests/project-runners-controller.test.mjs +453 -0
- package/tests/prompt-input-vertical-scroll-static.test.mjs +3 -3
- package/tests/prompt-routing-input-clear-static.test.mjs +2 -2
- package/tests/questionnaire-dialog.test.mjs +6 -6
- package/tests/queue-edit-reorder-static.test.mjs +48 -51
- package/tests/rpc-supervisor-host.test.mjs +4 -1
- package/tests/safety-guard-auto-review-static.test.mjs +1 -1
- package/tests/sampling-native-controls-user-flow.test.mjs +7 -1
- package/tests/server-app-runners.test.mjs +536 -0
- package/tests/server-codex-fast-mode.test.mjs +346 -0
- package/tests/server-conversation-mode.test.mjs +386 -0
- package/tests/server-conversation-voice.test.mjs +426 -0
- package/tests/server-extension-ui-requests.test.mjs +357 -0
- package/tests/server-git-generation.test.mjs +558 -0
- package/tests/server-git-mutations.test.mjs +729 -0
- package/tests/server-git-reads.test.mjs +381 -0
- package/tests/server-git-worktree-sessions.test.mjs +502 -0
- package/tests/server-helper-requests.test.mjs +364 -0
- package/tests/server-rpc-transports.test.mjs +553 -0
- package/tests/server-settings-store.test.mjs +132 -0
- package/tests/server-shell-rollout.test.mjs +478 -0
- package/tests/server-sse-delivery.test.mjs +410 -0
- package/tests/server-workspace-files.test.mjs +546 -0
- package/tests/session-attention-scheduler.test.mjs +514 -0
- package/tests/session-composer-store.test.mjs +153 -0
- package/tests/session-context.test.mjs +134 -0
- package/tests/session-extension-requests.test.mjs +193 -0
- package/tests/session-ownership-adapter.test.mjs +130 -0
- package/tests/session-sampling-ui-static.test.mjs +10 -4
- package/tests/session-send-lifetime.test.mjs +140 -0
- package/tests/session-shelf-state.test.mjs +348 -0
- package/tests/session-shelves-adapter.test.mjs +79 -0
- package/tests/session-summary-lifetime.test.mjs +54 -0
- package/tests/settings-resource-controller.test.mjs +548 -0
- package/tests/shell-action-adapter.test.mjs +169 -0
- package/tests/shell-actions.test.mjs +182 -0
- package/tests/shell-navigation.test.mjs +348 -0
- package/tests/shell-preferences.test.mjs +367 -0
- package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
- package/tests/stream-output-isolation-static.test.mjs +1 -1
- package/tests/subagent-gate-visibility.test.mjs +1 -1
- package/tests/subagent-launch-slot-state.test.mjs +2 -2
- package/tests/subagent-launch-slots-static.test.mjs +1 -1
- package/tests/subagent-observability-static.test.mjs +2 -2
- package/tests/subagent-reliability-integration.test.mjs +13 -30
- package/tests/syntax-highlighting-static.test.mjs +3 -3
- package/tests/tab-close-continuity-static.test.mjs +1 -1
- package/tests/tab-metadata-ordering.test.mjs +99 -0
- package/tests/terminal-cwd-grouping-static.test.mjs +2 -2
- package/tests/terminal-tab-prompt-tooltip-static.test.mjs +2 -0
- package/tests/terminal-tab-workspace-static.test.mjs +5 -4
- package/tests/terminal-tabs-resize-static.test.mjs +1 -1
- package/tests/theme-customizer-static.test.mjs +1 -1
- package/tests/thread-display-title.test.mjs +44 -0
- package/tests/update-api-harness.test.mjs +15 -14
- package/tests/update-tab-restore-harness.test.mjs +3 -0
- package/tests/webui-settings-locking.test.mjs +2 -2
- package/tests/windows-drive-cwd-picker-static.test.mjs +7 -9
- package/tests/workspace-choices.test.mjs +114 -0
- package/tests/workspace-save-load-static.test.mjs +7 -4
|
@@ -0,0 +1,534 @@
|
|
|
1
|
+
export function normalizeQueuedMessages(event) {
|
|
2
|
+
const normalize = (items) => (Array.isArray(items) ? items.map((item) => String(item || "")).filter((item) => item.trim()) : []);
|
|
3
|
+
const source = event?.source === "webui-compaction" ? "webui-compaction" : "pi-runtime";
|
|
4
|
+
return {
|
|
5
|
+
source,
|
|
6
|
+
revision: source === "webui-compaction" && Number.isSafeInteger(event?.revision) && event.revision >= 0 ? event.revision : undefined,
|
|
7
|
+
draining: source === "webui-compaction" && event?.draining === true,
|
|
8
|
+
steering: normalize(event?.steering),
|
|
9
|
+
followUp: normalize(event?.followUp),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function queueMessageCount(snapshot) {
|
|
14
|
+
return (snapshot?.steering?.length || 0) + (snapshot?.followUp?.length || 0);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function queueMutationBody(snapshot, operation) {
|
|
18
|
+
const body = {
|
|
19
|
+
source: snapshot.source,
|
|
20
|
+
kind: "followUp",
|
|
21
|
+
expected: { steering: [...snapshot.steering], followUp: [...snapshot.followUp] },
|
|
22
|
+
operation,
|
|
23
|
+
};
|
|
24
|
+
if (snapshot.source === "webui-compaction") body.revision = snapshot.revision;
|
|
25
|
+
return body;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function preservedFocusedFollowUpQueueDraft(draft, followUps) {
|
|
29
|
+
if (!draft || !Array.isArray(followUps) || !Number.isSafeInteger(draft.index) || draft.index < 0) return null;
|
|
30
|
+
const authoritativeText = String(draft.authoritativeText ?? "");
|
|
31
|
+
const value = String(draft.value ?? "");
|
|
32
|
+
if (value === authoritativeText || followUps[draft.index] !== authoritativeText) return null;
|
|
33
|
+
const selectionStart = Math.max(0, Math.min(value.length, Number.isSafeInteger(draft.selectionStart) ? draft.selectionStart : value.length));
|
|
34
|
+
const selectionEnd = Math.max(selectionStart, Math.min(value.length, Number.isSafeInteger(draft.selectionEnd) ? draft.selectionEnd : selectionStart));
|
|
35
|
+
return { index: draft.index, value, selectionStart, selectionEnd };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function createActivityQueueController({
|
|
39
|
+
document, nodes, api, getContext, isCurrent, isAlive, getSnapshot, setSnapshot,
|
|
40
|
+
onBeforeOpen = () => {}, onAfterClose = () => {}, onProjectionChange = () => {},
|
|
41
|
+
onEvent = () => {}, deferRender = () => false,
|
|
42
|
+
captureContinuity = () => null, restoreContinuity = () => {},
|
|
43
|
+
isFileDrag = (event) => Array.from(event.dataTransfer?.types || []).includes("Files"),
|
|
44
|
+
requestAnimationFrame = document.defaultView.requestAnimationFrame.bind(document.defaultView),
|
|
45
|
+
cancelAnimationFrame = document.defaultView.cancelAnimationFrame.bind(document.defaultView),
|
|
46
|
+
}) {
|
|
47
|
+
let disposed = false;
|
|
48
|
+
let open = false;
|
|
49
|
+
let status = { text: "", level: "" };
|
|
50
|
+
let restoreFocusTarget = null;
|
|
51
|
+
let drag = null;
|
|
52
|
+
let suppressBlurFor = null;
|
|
53
|
+
let presentation = 0;
|
|
54
|
+
let overlaySerial = 0;
|
|
55
|
+
const locks = new Map();
|
|
56
|
+
const frames = new Set();
|
|
57
|
+
const alive = (context) => !disposed && !!context?.tabId && isAlive(context);
|
|
58
|
+
const current = (context) => alive(context) && isCurrent(context);
|
|
59
|
+
const snapshotFor = (tabId = getContext()?.tabId) => getSnapshot(tabId) || normalizeQueuedMessages({});
|
|
60
|
+
const make = (tag, className, text) => {
|
|
61
|
+
const node = document.createElement(tag);
|
|
62
|
+
if (className) node.className = className;
|
|
63
|
+
if (text !== undefined) node.textContent = text;
|
|
64
|
+
return node;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
function frame(callback) {
|
|
68
|
+
const epoch = presentation;
|
|
69
|
+
const id = requestAnimationFrame(() => {
|
|
70
|
+
frames.delete(id);
|
|
71
|
+
if (!disposed && epoch === presentation) callback();
|
|
72
|
+
});
|
|
73
|
+
frames.add(id);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function cancelFrames() {
|
|
77
|
+
for (const id of frames) cancelAnimationFrame(id);
|
|
78
|
+
frames.clear();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function defer(key, callback) {
|
|
82
|
+
const context = getContext();
|
|
83
|
+
const epoch = presentation;
|
|
84
|
+
return deferRender(key, () => {
|
|
85
|
+
if (current(context) && epoch === presentation) callback();
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function isMutationInFlight(tabId = getContext()?.tabId) {
|
|
90
|
+
const token = locks.get(tabId);
|
|
91
|
+
return !!token && alive(token.context);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function setStatus(text = "", level = "") {
|
|
95
|
+
if (disposed) return;
|
|
96
|
+
status = { text, level };
|
|
97
|
+
if (!nodes.followUpQueueStatus) return;
|
|
98
|
+
nodes.followUpQueueStatus.textContent = text;
|
|
99
|
+
nodes.followUpQueueStatus.className = `follow-up-queue-status${level ? ` ${level}` : ""}`;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function syncControls() {
|
|
103
|
+
const locked = isMutationInFlight();
|
|
104
|
+
const draining = snapshotFor().draining;
|
|
105
|
+
nodes.followUpQueueOverlay?.classList.toggle("is-busy", locked);
|
|
106
|
+
nodes.followUpQueueOverlay?.classList.toggle("is-draining", draining);
|
|
107
|
+
for (const control of nodes.followUpQueueRows?.querySelectorAll("[data-follow-up-queue-mutation-control]") || []) {
|
|
108
|
+
control.disabled = locked || draining || control.dataset.queueBoundary === "true";
|
|
109
|
+
}
|
|
110
|
+
for (const handle of nodes.followUpQueueRows?.querySelectorAll(".follow-up-queue-drag-handle") || []) handle.draggable = !locked && !draining;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function clearDragVisuals() {
|
|
114
|
+
for (const row of nodes.followUpQueueRows?.querySelectorAll(".is-dragging, .is-drop-target") || []) row.classList.remove("is-dragging", "is-drop-target");
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function setOpen(value, { restoreFocus = false } = {}) {
|
|
118
|
+
if (disposed) return;
|
|
119
|
+
const shouldOpen = !!value && snapshotFor().followUp.length > 0;
|
|
120
|
+
cancelFrames();
|
|
121
|
+
if (shouldOpen && !open) {
|
|
122
|
+
restoreFocusTarget = document.activeElement instanceof document.defaultView.HTMLElement ? document.activeElement : nodes.followUpQueueTrigger;
|
|
123
|
+
onBeforeOpen();
|
|
124
|
+
}
|
|
125
|
+
open = shouldOpen;
|
|
126
|
+
nodes.followUpQueueTrigger?.setAttribute("aria-expanded", shouldOpen ? "true" : "false");
|
|
127
|
+
if (nodes.followUpQueueOverlay) nodes.followUpQueueOverlay.hidden = !shouldOpen;
|
|
128
|
+
if (!shouldOpen) {
|
|
129
|
+
drag = null;
|
|
130
|
+
clearDragVisuals();
|
|
131
|
+
onAfterClose();
|
|
132
|
+
if (restoreFocus) {
|
|
133
|
+
const context = getContext();
|
|
134
|
+
const target = restoreFocusTarget?.isConnected ? restoreFocusTarget : nodes.followUpQueueTrigger;
|
|
135
|
+
frame(() => { if (!open && current(context)) target?.focus({ preventScroll: true }); });
|
|
136
|
+
}
|
|
137
|
+
restoreFocusTarget = null;
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
renderOverlay();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function ingest(event) {
|
|
144
|
+
if (disposed) return;
|
|
145
|
+
const context = getContext(event?.tabId || getContext()?.tabId);
|
|
146
|
+
if (!alive(context)) return;
|
|
147
|
+
setSnapshot(context.tabId, normalizeQueuedMessages(event));
|
|
148
|
+
if (current(context)) render();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function applyAuthoritative(context, queue) {
|
|
152
|
+
if (!alive(context) || !queue) return;
|
|
153
|
+
setSnapshot(context.tabId, normalizeQueuedMessages(queue));
|
|
154
|
+
// Navigation may advance generation while the originating lifetime stays alive.
|
|
155
|
+
const foreground = getContext(context.tabId);
|
|
156
|
+
if (alive(context) && current(foreground)) render();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function operationMatches(snapshot, operation) {
|
|
160
|
+
if (!operation || !["edit", "delete", "move"].includes(operation.type)) return false;
|
|
161
|
+
const index = operation.type === "move" ? operation.from : operation.index;
|
|
162
|
+
if (!Number.isSafeInteger(index) || index < 0 || index >= snapshot.followUp.length || snapshot.followUp[index] !== operation.expectedText) return false;
|
|
163
|
+
if (operation.type === "edit") return typeof operation.text === "string" && !!operation.text.trim();
|
|
164
|
+
return operation.type !== "move" || (Number.isSafeInteger(operation.to) && operation.to >= 0 && operation.to < snapshot.followUp.length && operation.to !== index);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async function mutate(operation, context = getContext()) {
|
|
168
|
+
if (!alive(context) || isMutationInFlight(context.tabId)) return false;
|
|
169
|
+
const snapshot = snapshotFor(context.tabId);
|
|
170
|
+
if (!snapshot.followUp.length || snapshot.draining) {
|
|
171
|
+
if (current(context)) setStatus("Queue is draining; follow-ups can no longer be changed.", "warn");
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
if (!operationMatches(snapshot, operation)) return false;
|
|
175
|
+
const token = { context };
|
|
176
|
+
locks.set(context.tabId, token);
|
|
177
|
+
if (current(context)) {
|
|
178
|
+
syncControls();
|
|
179
|
+
setStatus(operation.type === "edit" ? "Saving queued follow-up…" : operation.type === "delete" ? "Removing queued follow-up…" : "Reordering queued follow-ups…");
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
const response = await api("/api/queue/mutate", { method: "POST", body: queueMutationBody(snapshot, operation), tabId: context.tabId });
|
|
183
|
+
if (!alive(context)) return false;
|
|
184
|
+
const result = response?.data || {};
|
|
185
|
+
if (result.queue) applyAuthoritative(context, result.queue);
|
|
186
|
+
if (!alive(context)) return false;
|
|
187
|
+
if (!result.mutated) {
|
|
188
|
+
if (current(context)) setStatus("Queue changed before the update could be applied.", "warn");
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
if (current(context)) setStatus(operation.type === "edit" ? `Saved queued follow-up ${operation.index + 1}.` : operation.type === "delete" ? `Removed queued follow-up ${operation.index + 1}.` : `Moved queued follow-up ${operation.from + 1} to position ${operation.to + 1}.`, "success");
|
|
192
|
+
return true;
|
|
193
|
+
} catch (error) {
|
|
194
|
+
if (!alive(context)) return false;
|
|
195
|
+
const result = error?.data?.data || {};
|
|
196
|
+
if (result.queue) applyAuthoritative(context, result.queue);
|
|
197
|
+
if (current(context)) {
|
|
198
|
+
if (error?.statusCode === 409) setStatus(result.reason === "queue-draining" ? "Queue is draining; refreshed the authoritative queue." : "Queue changed elsewhere; refreshed the authoritative queue.", "warn");
|
|
199
|
+
else setStatus(error.message || "Unable to update the queued follow-up.", "error");
|
|
200
|
+
}
|
|
201
|
+
return false;
|
|
202
|
+
} finally {
|
|
203
|
+
// A retired operation may share a tab ID with replacement-session work.
|
|
204
|
+
if (locks.get(context.tabId) === token) {
|
|
205
|
+
locks.delete(context.tabId);
|
|
206
|
+
const foreground = getContext(context.tabId);
|
|
207
|
+
if (alive(context) && current(foreground)) renderOverlay();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
async function remove(index, text, context = getContext()) {
|
|
213
|
+
const removed = await mutate({ type: "delete", index, expectedText: text }, context);
|
|
214
|
+
if (removed && current(context)) onEvent(`removed queued follow-up #${index + 1}`);
|
|
215
|
+
return removed && alive(context);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function saveText(index, expectedText, value, context) {
|
|
219
|
+
const text = String(value ?? "");
|
|
220
|
+
if (!current(context) || text === expectedText) return;
|
|
221
|
+
if (!text.trim()) {
|
|
222
|
+
const draft = focusedFollowUpQueueDraft();
|
|
223
|
+
if (draft?.index === index && draft.authoritativeText === expectedText) draft.textarea.value = expectedText;
|
|
224
|
+
setStatus("Queued follow-ups cannot be empty; restored the authoritative text.", "warn");
|
|
225
|
+
renderOverlay();
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
void mutate({ type: "edit", index, expectedText, text }, context);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function updateQueueHeaderBadge(total) {
|
|
232
|
+
if (!nodes.queueCountBadge) return;
|
|
233
|
+
nodes.queueCountBadge.hidden = total === 0;
|
|
234
|
+
nodes.queueCountBadge.textContent = String(total);
|
|
235
|
+
nodes.queueCountBadge.setAttribute("aria-label", `${total} queued message${total === 1 ? "" : "s"}`);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function queueSummaryPill(label, count, tone) {
|
|
239
|
+
const pill = make("span", `queue-summary-pill ${tone}`.trim());
|
|
240
|
+
pill.append(make("strong", undefined, String(count)), make("span", undefined, label));
|
|
241
|
+
return pill;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function focusedFollowUpQueueDraft() {
|
|
245
|
+
const textarea = document.activeElement;
|
|
246
|
+
if (!textarea?.matches?.("textarea.follow-up-queue-textarea") || !nodes.followUpQueueRows?.contains(textarea)) return null;
|
|
247
|
+
const index = Number(textarea.closest(".follow-up-queue-row")?.dataset.followUpIndex);
|
|
248
|
+
if (!Number.isSafeInteger(index) || index < 0) return null;
|
|
249
|
+
const authoritativeText = String(textarea.dataset.followUpQueueAuthoritativeText ?? "");
|
|
250
|
+
if (textarea.value === authoritativeText) return null;
|
|
251
|
+
return {
|
|
252
|
+
textarea,
|
|
253
|
+
scrollTop: textarea.scrollTop,
|
|
254
|
+
scrollLeft: textarea.scrollLeft,
|
|
255
|
+
index,
|
|
256
|
+
authoritativeText,
|
|
257
|
+
value: textarea.value,
|
|
258
|
+
selectionStart: textarea.selectionStart,
|
|
259
|
+
selectionEnd: textarea.selectionEnd,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function renderOverlay() {
|
|
264
|
+
if (disposed || defer("follow-up-queue", renderOverlay)) return;
|
|
265
|
+
const context = getContext();
|
|
266
|
+
const epoch = presentation;
|
|
267
|
+
const serial = ++overlaySerial;
|
|
268
|
+
const snapshot = snapshotFor();
|
|
269
|
+
const followUps = snapshot.followUp;
|
|
270
|
+
const count = followUps.length;
|
|
271
|
+
const trigger = nodes.followUpQueueTrigger;
|
|
272
|
+
if (trigger) {
|
|
273
|
+
trigger.hidden = count === 0;
|
|
274
|
+
trigger.setAttribute("aria-expanded", open && count ? "true" : "false");
|
|
275
|
+
trigger.setAttribute("aria-label", `${count} queued follow-up${count === 1 ? "" : "s"}`);
|
|
276
|
+
}
|
|
277
|
+
if (nodes.followUpQueueTriggerCount) nodes.followUpQueueTriggerCount.textContent = String(count);
|
|
278
|
+
if (nodes.followUpQueueOverlayCount) nodes.followUpQueueOverlayCount.textContent = String(count);
|
|
279
|
+
if (!count) {
|
|
280
|
+
if (open) setOpen(false);
|
|
281
|
+
if (nodes.followUpQueueRows) nodes.followUpQueueRows.replaceChildren();
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
if (!open || !nodes.followUpQueueRows) return;
|
|
285
|
+
|
|
286
|
+
const locked = isMutationInFlight();
|
|
287
|
+
const unavailable = locked || snapshot.draining;
|
|
288
|
+
const focusedDraft = focusedFollowUpQueueDraft();
|
|
289
|
+
const preservedDraft = preservedFocusedFollowUpQueueDraft(focusedDraft, followUps);
|
|
290
|
+
const rows = followUps.map((item, index) => {
|
|
291
|
+
const row = make("article", "follow-up-queue-row");
|
|
292
|
+
row.dataset.followUpIndex = String(index);
|
|
293
|
+
row.draggable = false;
|
|
294
|
+
const rowCurrent = () => open && current(context) && epoch === presentation && row.isConnected;
|
|
295
|
+
const dragHandle = make("span", "follow-up-queue-drag-handle", "⠿");
|
|
296
|
+
dragHandle.draggable = !unavailable;
|
|
297
|
+
dragHandle.setAttribute("aria-hidden", "true");
|
|
298
|
+
dragHandle.title = "Drag to reorder";
|
|
299
|
+
const textarea = make("textarea", "follow-up-queue-textarea");
|
|
300
|
+
const textareaDraft = preservedDraft?.index === index ? preservedDraft : null;
|
|
301
|
+
textarea.value = textareaDraft ? textareaDraft.value : item;
|
|
302
|
+
textarea.dataset.followUpQueueAuthoritativeText = item;
|
|
303
|
+
textarea.rows = Math.max(2, Math.min(6, item.split("\n").length + 1));
|
|
304
|
+
textarea.disabled = unavailable;
|
|
305
|
+
textarea.setAttribute("aria-label", `Queued follow-up ${index + 1}`);
|
|
306
|
+
textarea.dataset.followUpQueueMutationControl = "true";
|
|
307
|
+
textarea.addEventListener("blur", () => {
|
|
308
|
+
if (textarea === suppressBlurFor) return;
|
|
309
|
+
if (rowCurrent()) saveText(index, item, textarea.value, context);
|
|
310
|
+
});
|
|
311
|
+
textarea.addEventListener("keydown", (event) => {
|
|
312
|
+
if (!rowCurrent()) return;
|
|
313
|
+
if ((event.ctrlKey || event.metaKey) && !event.altKey && event.key === "Enter") {
|
|
314
|
+
event.preventDefault();
|
|
315
|
+
saveText(index, item, textarea.value, context);
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
if (event.key !== "Escape") return;
|
|
319
|
+
event.preventDefault();
|
|
320
|
+
event.stopPropagation();
|
|
321
|
+
if (textarea.value !== item) {
|
|
322
|
+
textarea.value = item;
|
|
323
|
+
setStatus(`Restored queued follow-up ${index + 1}.`, "warn");
|
|
324
|
+
} else {
|
|
325
|
+
setOpen(false, { restoreFocus: true });
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
const controls = make("div", "follow-up-queue-row-controls");
|
|
329
|
+
const moveUp = make("button", "follow-up-queue-move-button", "↑");
|
|
330
|
+
moveUp.type = "button";
|
|
331
|
+
moveUp.dataset.followUpQueueMutationControl = "true";
|
|
332
|
+
moveUp.dataset.queueBoundary = index === 0 ? "true" : "false";
|
|
333
|
+
moveUp.disabled = unavailable || index === 0;
|
|
334
|
+
moveUp.title = `Move queued follow-up ${index + 1} up`;
|
|
335
|
+
moveUp.setAttribute("aria-label", `Move queued follow-up ${index + 1} up`);
|
|
336
|
+
moveUp.addEventListener("click", () => { if (rowCurrent()) void mutate({ type: "move", from: index, to: index - 1, expectedText: item }, context); });
|
|
337
|
+
const moveDown = make("button", "follow-up-queue-move-button", "↓");
|
|
338
|
+
moveDown.type = "button";
|
|
339
|
+
moveDown.dataset.followUpQueueMutationControl = "true";
|
|
340
|
+
moveDown.dataset.queueBoundary = index === followUps.length - 1 ? "true" : "false";
|
|
341
|
+
moveDown.disabled = unavailable || index === followUps.length - 1;
|
|
342
|
+
moveDown.title = `Move queued follow-up ${index + 1} down`;
|
|
343
|
+
moveDown.setAttribute("aria-label", `Move queued follow-up ${index + 1} down`);
|
|
344
|
+
moveDown.addEventListener("click", () => { if (rowCurrent()) void mutate({ type: "move", from: index, to: index + 1, expectedText: item }, context); });
|
|
345
|
+
const removeButton = make("button", "follow-up-queue-remove-button", "Remove");
|
|
346
|
+
removeButton.type = "button";
|
|
347
|
+
removeButton.dataset.followUpQueueMutationControl = "true";
|
|
348
|
+
removeButton.title = `Remove queued follow-up ${index + 1}`;
|
|
349
|
+
removeButton.setAttribute("aria-label", `Remove queued follow-up ${index + 1}`);
|
|
350
|
+
removeButton.addEventListener("pointerdown", () => { if (rowCurrent()) suppressBlurFor = textarea; });
|
|
351
|
+
removeButton.addEventListener("pointercancel", () => {
|
|
352
|
+
if (suppressBlurFor === textarea) suppressBlurFor = null;
|
|
353
|
+
});
|
|
354
|
+
removeButton.addEventListener("click", () => {
|
|
355
|
+
if (suppressBlurFor === textarea) suppressBlurFor = null;
|
|
356
|
+
if (rowCurrent()) void remove(index, item, context);
|
|
357
|
+
});
|
|
358
|
+
controls.append(moveUp, moveDown, removeButton);
|
|
359
|
+
row.append(dragHandle, textarea, controls);
|
|
360
|
+
row.addEventListener("dragstart", (event) => {
|
|
361
|
+
if (!rowCurrent() || isMutationInFlight(context.tabId) || snapshotFor(context.tabId).draining || unavailable || event.target?.closest?.(".follow-up-queue-drag-handle") !== dragHandle) {
|
|
362
|
+
event.preventDefault();
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
drag = { context, index, expectedText: item };
|
|
366
|
+
event.dataTransfer?.setData("application/x-pi-webui-follow-up", JSON.stringify({ tabId: context.tabId, index, expectedText: item }));
|
|
367
|
+
if (event.dataTransfer) event.dataTransfer.effectAllowed = "move";
|
|
368
|
+
row.classList.add("is-dragging");
|
|
369
|
+
});
|
|
370
|
+
row.addEventListener("dragover", (event) => {
|
|
371
|
+
if (!rowCurrent() || !drag || !current(drag.context) || isMutationInFlight(context.tabId) || snapshotFor(context.tabId).draining || unavailable || isFileDrag(event)) return;
|
|
372
|
+
event.preventDefault();
|
|
373
|
+
event.stopPropagation();
|
|
374
|
+
if (event.dataTransfer) event.dataTransfer.dropEffect = "move";
|
|
375
|
+
clearDragVisuals();
|
|
376
|
+
row.classList.add("is-drop-target");
|
|
377
|
+
});
|
|
378
|
+
row.addEventListener("dragleave", (event) => {
|
|
379
|
+
if (!row.contains(event.relatedTarget)) row.classList.remove("is-drop-target");
|
|
380
|
+
});
|
|
381
|
+
row.addEventListener("drop", (event) => {
|
|
382
|
+
if (!rowCurrent() || !drag || !current(drag.context) || isMutationInFlight(context.tabId) || snapshotFor(context.tabId).draining || unavailable || isFileDrag(event)) return;
|
|
383
|
+
event.preventDefault();
|
|
384
|
+
event.stopPropagation();
|
|
385
|
+
const source = drag;
|
|
386
|
+
clearDragVisuals();
|
|
387
|
+
drag = null;
|
|
388
|
+
if (source.index !== index) void mutate({ type: "move", from: source.index, to: index, expectedText: source.expectedText }, source.context);
|
|
389
|
+
});
|
|
390
|
+
row.addEventListener("dragend", () => {
|
|
391
|
+
if (!rowCurrent()) return;
|
|
392
|
+
drag = null;
|
|
393
|
+
clearDragVisuals();
|
|
394
|
+
});
|
|
395
|
+
return row;
|
|
396
|
+
});
|
|
397
|
+
const scrollTop = nodes.followUpQueueRows.scrollTop;
|
|
398
|
+
const scrollLeft = nodes.followUpQueueRows.scrollLeft;
|
|
399
|
+
drag = null;
|
|
400
|
+
suppressBlurFor = focusedDraft?.textarea || null;
|
|
401
|
+
try {
|
|
402
|
+
nodes.followUpQueueRows.replaceChildren(...rows);
|
|
403
|
+
} finally {
|
|
404
|
+
suppressBlurFor = null;
|
|
405
|
+
}
|
|
406
|
+
nodes.followUpQueueRows.scrollTop = scrollTop;
|
|
407
|
+
nodes.followUpQueueRows.scrollLeft = scrollLeft;
|
|
408
|
+
if (preservedDraft && !unavailable) {
|
|
409
|
+
frame(() => {
|
|
410
|
+
if (!open || !current(context) || epoch !== presentation || serial !== overlaySerial) return;
|
|
411
|
+
const activeElement = document.activeElement;
|
|
412
|
+
if (activeElement && activeElement !== document.body && activeElement !== document.documentElement) return;
|
|
413
|
+
const textarea = nodes.followUpQueueRows?.querySelector(`.follow-up-queue-row[data-follow-up-index="${preservedDraft.index}"] textarea`);
|
|
414
|
+
if (!textarea) return;
|
|
415
|
+
textarea.focus({ preventScroll: true });
|
|
416
|
+
textarea.setSelectionRange(preservedDraft.selectionStart, preservedDraft.selectionEnd);
|
|
417
|
+
textarea.scrollTop = focusedDraft.scrollTop;
|
|
418
|
+
textarea.scrollLeft = focusedDraft.scrollLeft;
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
setStatus(status.text, status.level);
|
|
422
|
+
syncControls();
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
function renderQueueGroup(label, items, tone, { removable = false, context } = {}) {
|
|
426
|
+
const epoch = presentation;
|
|
427
|
+
const tabId = context?.tabId;
|
|
428
|
+
const group = make("section", `queue-group ${tone}`.trim());
|
|
429
|
+
const heading = make("h3", "queue-group-title");
|
|
430
|
+
heading.append(make("span", undefined, label), make("span", "queue-group-count", String(items.length)));
|
|
431
|
+
const list = make("ol", "queue-list");
|
|
432
|
+
items.forEach((item, index) => {
|
|
433
|
+
const row = make("li", `queue-item${removable ? " can-remove" : ""}`);
|
|
434
|
+
row.append(make("span", "queue-item-number", `#${index + 1}`), make("div", "queue-item-text", item));
|
|
435
|
+
if (removable) {
|
|
436
|
+
const removeButton = make("button", "queue-remove-button", "Remove");
|
|
437
|
+
removeButton.type = "button";
|
|
438
|
+
removeButton.dataset.queueContinuityKey = `remove:${tabId || ""}:${index}:${item}`;
|
|
439
|
+
removeButton.title = `Remove queued follow-up #${index + 1}`;
|
|
440
|
+
removeButton.setAttribute("aria-label", `Remove queued follow-up #${index + 1}`);
|
|
441
|
+
removeButton.addEventListener("click", async () => {
|
|
442
|
+
if (!current(context) || epoch !== presentation || !removeButton.isConnected) return;
|
|
443
|
+
removeButton.disabled = true;
|
|
444
|
+
removeButton.textContent = "Removing…";
|
|
445
|
+
const removed = await remove(index, item, context);
|
|
446
|
+
if (!removed && current(context) && epoch === presentation && removeButton.isConnected) {
|
|
447
|
+
removeButton.disabled = false;
|
|
448
|
+
removeButton.textContent = "Remove";
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
row.append(removeButton);
|
|
452
|
+
}
|
|
453
|
+
list.append(row);
|
|
454
|
+
});
|
|
455
|
+
group.append(heading, list);
|
|
456
|
+
return group;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
function render() {
|
|
460
|
+
if (disposed || defer("queue", render)) return;
|
|
461
|
+
const context = getContext();
|
|
462
|
+
const tabId = context?.tabId;
|
|
463
|
+
const snapshot = snapshotFor(tabId);
|
|
464
|
+
if (!nodes.queueBox) { renderOverlay(); onProjectionChange(); return; }
|
|
465
|
+
const continuityContextKey = `${tabId || ""}:${context?.generation ?? ""}:queue`;
|
|
466
|
+
const focusSnapshot = captureContinuity(nodes.queueBox, continuityContextKey, (node) => node?.dataset?.queueContinuityKey || "");
|
|
467
|
+
const scrollTop = nodes.queueBox.scrollTop;
|
|
468
|
+
const scrollLeft = nodes.queueBox.scrollLeft;
|
|
469
|
+
const restore = () => {
|
|
470
|
+
restoreContinuity(nodes.queueBox, continuityContextKey, focusSnapshot, (key) => [...nodes.queueBox.querySelectorAll("[data-queue-continuity-key]")]
|
|
471
|
+
.find((node) => node.dataset.queueContinuityKey === key));
|
|
472
|
+
nodes.queueBox.scrollTop = scrollTop;
|
|
473
|
+
nodes.queueBox.scrollLeft = scrollLeft;
|
|
474
|
+
};
|
|
475
|
+
const steering = snapshot.steering;
|
|
476
|
+
const followUp = snapshot.followUp;
|
|
477
|
+
const total = queueMessageCount(snapshot);
|
|
478
|
+
updateQueueHeaderBadge(total);
|
|
479
|
+
nodes.queueBox.replaceChildren();
|
|
480
|
+
nodes.queueBox.classList.toggle("muted", total === 0);
|
|
481
|
+
nodes.queueBox.classList.toggle("has-items", total > 0);
|
|
482
|
+
if (total === 0) {
|
|
483
|
+
nodes.queueBox.append(make("div", "queue-empty", "No queued messages."));
|
|
484
|
+
renderOverlay();
|
|
485
|
+
onProjectionChange();
|
|
486
|
+
restore();
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
const summary = make("div", "queue-summary");
|
|
491
|
+
summary.append(make("strong", undefined, `${total} queued message${total === 1 ? "" : "s"}`));
|
|
492
|
+
const counts = make("div", "queue-summary-counts");
|
|
493
|
+
if (steering.length) counts.append(queueSummaryPill("steering", steering.length, "steering"));
|
|
494
|
+
if (followUp.length) counts.append(queueSummaryPill("follow-up", followUp.length, "follow-up"));
|
|
495
|
+
summary.append(counts);
|
|
496
|
+
|
|
497
|
+
nodes.queueBox.append(summary);
|
|
498
|
+
if (steering.length) nodes.queueBox.append(renderQueueGroup("Steering", steering, "steering", { context }));
|
|
499
|
+
if (followUp.length) nodes.queueBox.append(renderQueueGroup("Follow-up", followUp, "follow-up", { removable: !snapshot.draining, context }));
|
|
500
|
+
nodes.queueBox.append(make("div", "queue-hint", snapshot.source === "pi-runtime"
|
|
501
|
+
? "Alt+Up restores this queue snapshot to the composer without clearing Pi's queue. Use Remove beside follow-ups to drop them from the queue."
|
|
502
|
+
: "Alt+Up restores this queue snapshot to the composer without clearing Pi's queue. Edit, reorder, or remove compaction-held follow-ups with the composer Queue control."));
|
|
503
|
+
renderOverlay();
|
|
504
|
+
onProjectionChange();
|
|
505
|
+
restore();
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
function activate() {
|
|
509
|
+
if (disposed) return;
|
|
510
|
+
presentation += 1;
|
|
511
|
+
cancelFrames();
|
|
512
|
+
nodes.followUpQueueRows?.replaceChildren();
|
|
513
|
+
setOpen(false);
|
|
514
|
+
setStatus();
|
|
515
|
+
render();
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
function dispose() {
|
|
519
|
+
if (disposed) return;
|
|
520
|
+
disposed = true;
|
|
521
|
+
presentation += 1;
|
|
522
|
+
cancelFrames();
|
|
523
|
+
open = false;
|
|
524
|
+
drag = null;
|
|
525
|
+
suppressBlurFor = null;
|
|
526
|
+
restoreFocusTarget = null;
|
|
527
|
+
locks.clear();
|
|
528
|
+
if (nodes.followUpQueueOverlay) nodes.followUpQueueOverlay.hidden = true;
|
|
529
|
+
nodes.followUpQueueTrigger?.setAttribute("aria-expanded", "false");
|
|
530
|
+
nodes.followUpQueueRows?.replaceChildren();
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
return { ingest, render, renderOverlay, setOpen, isOpen: () => open, mutate, remove, setStatus, isMutationInFlight, activate, dispose };
|
|
534
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/** Renders the existing todo projection; session expansion and live data stay with the caller. */
|
|
2
|
+
export function createActivityTodoView({ document, stripAnsi, parseItem }) {
|
|
3
|
+
function make(tag, className, text) {
|
|
4
|
+
const node = document.createElement(tag);
|
|
5
|
+
if (className) node.className = className;
|
|
6
|
+
if (text !== undefined) node.textContent = text;
|
|
7
|
+
return node;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function parse(lines) {
|
|
11
|
+
const cleanLines = lines.map(stripAnsi).map((line) => line.trim()).filter(Boolean);
|
|
12
|
+
const goalLine = cleanLines.find((line) => /^Goal\s*[::]/i.test(line));
|
|
13
|
+
const goal = goalLine ? goalLine.replace(/^Goal\s*[::]\s*/i, "").trim() : "";
|
|
14
|
+
const headerIndex = cleanLines.findIndex((line) => /^Todo\s+\d+\/\d+\s+done/i.test(line));
|
|
15
|
+
if (headerIndex === -1) return null;
|
|
16
|
+
|
|
17
|
+
const header = cleanLines[headerIndex];
|
|
18
|
+
const match = header.match(/^Todo\s+(\d+)\/(\d+)\s+done(?:,\s+(\d+)\s+partial)?/i);
|
|
19
|
+
if (!match) return null;
|
|
20
|
+
|
|
21
|
+
const items = [];
|
|
22
|
+
let footer = "";
|
|
23
|
+
for (const line of cleanLines.slice(headerIndex + 1)) {
|
|
24
|
+
const item = parseItem(line);
|
|
25
|
+
if (item) {
|
|
26
|
+
items.push(item);
|
|
27
|
+
} else if (/^Scroll\s+/i.test(line)) {
|
|
28
|
+
footer = line;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
goal,
|
|
34
|
+
done: Number.parseInt(match[1], 10) || 0,
|
|
35
|
+
total: Number.parseInt(match[2], 10) || items.length,
|
|
36
|
+
partial: Number.parseInt(match[3] || "0", 10) || 0,
|
|
37
|
+
items,
|
|
38
|
+
footer,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function render(lines, { expanded = false, onExpandedChange = () => {} } = {}) {
|
|
43
|
+
const todo = parse(lines);
|
|
44
|
+
if (!todo) return null;
|
|
45
|
+
|
|
46
|
+
const node = make("details", "widget todo-widget");
|
|
47
|
+
node.open = expanded === true;
|
|
48
|
+
node.setAttribute("aria-label", "Todo progress");
|
|
49
|
+
node.addEventListener("toggle", () => {
|
|
50
|
+
onExpandedChange(node.open);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const percent = todo.total > 0 ? Math.max(0, Math.min(100, (todo.done / todo.total) * 100)) : 0;
|
|
54
|
+
const summary = make("summary", "todo-widget-summary");
|
|
55
|
+
const header = make("div", "todo-widget-header");
|
|
56
|
+
header.append(
|
|
57
|
+
make("span", "todo-widget-toggle", "›"),
|
|
58
|
+
make("span", "todo-widget-title", "Todo progress"),
|
|
59
|
+
make("span", "todo-widget-count", `${todo.done}/${todo.total}`),
|
|
60
|
+
make("span", "todo-widget-meta", todo.partial ? `${todo.partial} partial` : "active"),
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const progress = make("div", "todo-widget-progress");
|
|
64
|
+
const fill = make("span", "todo-widget-progress-fill");
|
|
65
|
+
fill.style.width = `${percent}%`;
|
|
66
|
+
progress.append(fill);
|
|
67
|
+
if (todo.goal) summary.append(make("div", "todo-widget-goal", `Goal: ${todo.goal}`));
|
|
68
|
+
summary.append(header, progress);
|
|
69
|
+
|
|
70
|
+
const body = make("div", "todo-widget-body");
|
|
71
|
+
const list = make("ol", "todo-widget-list");
|
|
72
|
+
for (const item of todo.items) {
|
|
73
|
+
const row = make("li", `todo-widget-item ${item.status}`);
|
|
74
|
+
row.append(
|
|
75
|
+
make("span", "todo-widget-marker", item.status === "done" ? "✓" : item.status === "partial" ? "–" : ""),
|
|
76
|
+
make("span", "todo-widget-text", item.text),
|
|
77
|
+
);
|
|
78
|
+
list.append(row);
|
|
79
|
+
}
|
|
80
|
+
if (todo.items.length) body.append(list);
|
|
81
|
+
if (todo.footer) body.append(make("div", "todo-widget-footer", todo.footer));
|
|
82
|
+
|
|
83
|
+
node.append(summary);
|
|
84
|
+
if (body.children.length) node.append(body);
|
|
85
|
+
return node;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return { parse, render };
|
|
89
|
+
}
|