@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,269 @@
|
|
|
1
|
+
const ACTIVE_REFRESH_MS = 1500;
|
|
2
|
+
const IDLE_REFRESH_MS = 4000;
|
|
3
|
+
const HIDDEN_REFRESH_MS = 10_000;
|
|
4
|
+
|
|
5
|
+
export function createActivityAgentsController({
|
|
6
|
+
api,
|
|
7
|
+
getVisibility,
|
|
8
|
+
getAutoClear,
|
|
9
|
+
finishedSelections,
|
|
10
|
+
canCancel,
|
|
11
|
+
canDismiss,
|
|
12
|
+
isAttachedProjection,
|
|
13
|
+
agentCount,
|
|
14
|
+
onOverview = () => {},
|
|
15
|
+
onRefreshSettled = () => {},
|
|
16
|
+
onChange = () => {},
|
|
17
|
+
onEvent = () => {},
|
|
18
|
+
onCancelStatus = () => {},
|
|
19
|
+
onCancelClosed = () => {},
|
|
20
|
+
setTimeout = globalThis.setTimeout,
|
|
21
|
+
clearTimeout = globalThis.clearTimeout,
|
|
22
|
+
}) {
|
|
23
|
+
let data = null;
|
|
24
|
+
let error = null;
|
|
25
|
+
let loading = false;
|
|
26
|
+
let clearingFinished = false;
|
|
27
|
+
let cancelSelection = null;
|
|
28
|
+
let cancelRequest = null;
|
|
29
|
+
let refreshPromise = null;
|
|
30
|
+
let refreshQueued = false;
|
|
31
|
+
let timer = null;
|
|
32
|
+
let scheduleVersion = 0;
|
|
33
|
+
let started = false;
|
|
34
|
+
let disposed = false;
|
|
35
|
+
|
|
36
|
+
function getSnapshot() {
|
|
37
|
+
// Overview data is borrowed read-only by the host, without a render-time copy.
|
|
38
|
+
return Object.freeze({ data, error, loading, clearingFinished, cancelSelection, cancelSubmitting: cancelRequest !== null });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function stopTimer() {
|
|
42
|
+
clearTimeout(timer);
|
|
43
|
+
timer = null;
|
|
44
|
+
return ++scheduleVersion;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function schedule(delay) {
|
|
48
|
+
if (disposed) return;
|
|
49
|
+
const version = stopTimer();
|
|
50
|
+
const tabs = Array.isArray(data?.tabs) ? data.tabs : [];
|
|
51
|
+
const hasRunningGate = tabs.some((tab) => (Array.isArray(tab?.gates) ? tab.gates : []).some((gate) => gate?.status === "running"));
|
|
52
|
+
const nextDelay = delay ?? (getVisibility() === "hidden" ? HIDDEN_REFRESH_MS : Number(data?.runningAgents || 0) > 0 || hasRunningGate ? ACTIVE_REFRESH_MS : IDLE_REFRESH_MS);
|
|
53
|
+
timer = setTimeout(() => {
|
|
54
|
+
if (disposed || version !== scheduleVersion) return;
|
|
55
|
+
timer = null;
|
|
56
|
+
return refresh().finally(() => {
|
|
57
|
+
if (!disposed && version === scheduleVersion) schedule();
|
|
58
|
+
});
|
|
59
|
+
}, nextDelay);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function runRefresh(owner) {
|
|
63
|
+
let refreshed = false;
|
|
64
|
+
try {
|
|
65
|
+
do {
|
|
66
|
+
refreshQueued = false;
|
|
67
|
+
try {
|
|
68
|
+
if (disposed) break;
|
|
69
|
+
const response = await api("/api/subagents", { scoped: false });
|
|
70
|
+
if (disposed || refreshPromise !== owner) break;
|
|
71
|
+
data = response.data || null;
|
|
72
|
+
error = null;
|
|
73
|
+
refreshed = true;
|
|
74
|
+
onOverview(data);
|
|
75
|
+
} catch (failure) {
|
|
76
|
+
if (disposed || refreshPromise !== owner) break;
|
|
77
|
+
error = failure;
|
|
78
|
+
}
|
|
79
|
+
} while (!disposed && refreshQueued);
|
|
80
|
+
} finally {
|
|
81
|
+
if (!disposed && refreshPromise === owner) {
|
|
82
|
+
refreshPromise = null;
|
|
83
|
+
loading = false;
|
|
84
|
+
onChange();
|
|
85
|
+
if (!disposed) onRefreshSettled();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return refreshed;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function refresh() {
|
|
92
|
+
if (disposed) return Promise.resolve(false);
|
|
93
|
+
if (refreshPromise) {
|
|
94
|
+
refreshQueued = true;
|
|
95
|
+
return refreshPromise;
|
|
96
|
+
}
|
|
97
|
+
let resolve;
|
|
98
|
+
let reject;
|
|
99
|
+
const pending = new Promise((accept, fail) => { resolve = accept; reject = fail; });
|
|
100
|
+
refreshPromise = pending;
|
|
101
|
+
loading = true;
|
|
102
|
+
onChange();
|
|
103
|
+
runRefresh(pending).then(resolve, reject);
|
|
104
|
+
// Release the overview request before Auto-Clear refreshes the resulting list.
|
|
105
|
+
return pending.then(async (refreshed) => {
|
|
106
|
+
if (!disposed && refreshed && getAutoClear() && finishedSelections(data).length) {
|
|
107
|
+
await clearFinished({ automatic: true });
|
|
108
|
+
}
|
|
109
|
+
return refreshed;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function start() {
|
|
114
|
+
if (disposed || started) return;
|
|
115
|
+
started = true;
|
|
116
|
+
const version = scheduleVersion;
|
|
117
|
+
return refresh().finally(() => {
|
|
118
|
+
if (!disposed && version === scheduleVersion) schedule();
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function beginCancel(tab, run, agent = null) {
|
|
123
|
+
if (disposed || cancelRequest || !tab?.groupId || !run?.id || !canCancel(run, agent)) return null;
|
|
124
|
+
cancelSelection = Object.freeze({
|
|
125
|
+
groupId: tab.groupId,
|
|
126
|
+
tabId: tab.tabId,
|
|
127
|
+
runId: run.id,
|
|
128
|
+
agentId: agent?.instanceId || agent?.id || "",
|
|
129
|
+
agentCount: agentCount(run),
|
|
130
|
+
});
|
|
131
|
+
onCancelStatus("");
|
|
132
|
+
onChange();
|
|
133
|
+
return cancelSelection;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function resetCancel() {
|
|
137
|
+
if (disposed) return;
|
|
138
|
+
cancelSelection = null;
|
|
139
|
+
cancelRequest = null;
|
|
140
|
+
onCancelStatus("");
|
|
141
|
+
onChange();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async function submitCancel({ reason = "", note = "" } = {}) {
|
|
145
|
+
if (disposed || !cancelSelection || cancelRequest) return false;
|
|
146
|
+
const selection = cancelSelection;
|
|
147
|
+
const request = {};
|
|
148
|
+
cancelRequest = request;
|
|
149
|
+
const isCurrent = () => !disposed && cancelSelection === selection && cancelRequest === request;
|
|
150
|
+
reason = String(reason || "").trim();
|
|
151
|
+
note = String(note || "").trim();
|
|
152
|
+
onChange();
|
|
153
|
+
onCancelStatus("Cancelling subagent…");
|
|
154
|
+
try {
|
|
155
|
+
if (!isCurrent()) return false;
|
|
156
|
+
await api("/api/subagents/cancel", {
|
|
157
|
+
method: "POST",
|
|
158
|
+
scoped: false,
|
|
159
|
+
body: {
|
|
160
|
+
group: selection.groupId,
|
|
161
|
+
runId: selection.runId,
|
|
162
|
+
...(selection.agentId ? { agentId: selection.agentId } : {}),
|
|
163
|
+
...(reason ? { reason } : {}),
|
|
164
|
+
...(note ? { note } : {}),
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
if (!isCurrent()) return false;
|
|
168
|
+
onCancelClosed(selection);
|
|
169
|
+
if (disposed) return false;
|
|
170
|
+
onEvent(`cancelled run ${selection.runId}; the parent agent was notified`, "info");
|
|
171
|
+
await refresh();
|
|
172
|
+
if (!disposed) schedule();
|
|
173
|
+
return !disposed;
|
|
174
|
+
} catch (failure) {
|
|
175
|
+
if (!isCurrent()) return false;
|
|
176
|
+
const message = `subagent cancel failed: ${failure.message || String(failure)}`;
|
|
177
|
+
onCancelStatus(message, "error");
|
|
178
|
+
onEvent(message, "error");
|
|
179
|
+
return false;
|
|
180
|
+
} finally {
|
|
181
|
+
// Closing/resetting can open a different selection while this refresh awaits.
|
|
182
|
+
if (isCurrent()) {
|
|
183
|
+
cancelRequest = null;
|
|
184
|
+
onChange();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async function dismiss(tab, run) {
|
|
190
|
+
if (disposed || !tab?.groupId || !run?.id || !canDismiss(run)) return false;
|
|
191
|
+
const groupId = tab.groupId;
|
|
192
|
+
const runId = run.id;
|
|
193
|
+
const attachedProjection = isAttachedProjection(run);
|
|
194
|
+
try {
|
|
195
|
+
await api("/api/subagents/dismiss", { method: "POST", scoped: false, body: { group: groupId, runId } });
|
|
196
|
+
if (disposed) return false;
|
|
197
|
+
onEvent(attachedProjection ? `detached persisted session projection ${runId}` : `dismissed finished subagent run ${runId}`, "info");
|
|
198
|
+
await refresh();
|
|
199
|
+
if (!disposed) schedule();
|
|
200
|
+
return !disposed;
|
|
201
|
+
} catch (failure) {
|
|
202
|
+
if (!disposed) onEvent(`subagent dismiss failed: ${failure.message || String(failure)}`, "error");
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
async function clearFinished({ automatic = false } = {}) {
|
|
208
|
+
if (disposed || clearingFinished || loading) return;
|
|
209
|
+
const selections = finishedSelections(data)
|
|
210
|
+
.filter((selection) => selection.groupId && selection.runId)
|
|
211
|
+
.map(({ groupId, runId }) => ({ groupId, runId }));
|
|
212
|
+
if (!selections.length) return;
|
|
213
|
+
const version = stopTimer();
|
|
214
|
+
clearingFinished = true;
|
|
215
|
+
onChange();
|
|
216
|
+
let dismissed = 0;
|
|
217
|
+
let failures = 0;
|
|
218
|
+
try {
|
|
219
|
+
for (const selection of selections) {
|
|
220
|
+
if (disposed) return;
|
|
221
|
+
try {
|
|
222
|
+
await api("/api/subagents/dismiss", {
|
|
223
|
+
method: "POST",
|
|
224
|
+
scoped: false,
|
|
225
|
+
body: { group: selection.groupId, runId: selection.runId },
|
|
226
|
+
});
|
|
227
|
+
dismissed += 1;
|
|
228
|
+
} catch {
|
|
229
|
+
failures += 1;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (disposed) return;
|
|
233
|
+
await refresh();
|
|
234
|
+
} finally {
|
|
235
|
+
if (!disposed) {
|
|
236
|
+
clearingFinished = false;
|
|
237
|
+
onChange();
|
|
238
|
+
if (!disposed && version === scheduleVersion) schedule();
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (disposed) return;
|
|
242
|
+
if (dismissed) {
|
|
243
|
+
if (automatic) {
|
|
244
|
+
onEvent("auto-cleared", "info", {
|
|
245
|
+
aggregateKey: "subagent-auto-clear",
|
|
246
|
+
aggregateIncrement: dismissed,
|
|
247
|
+
aggregateSingular: "finished subagent run",
|
|
248
|
+
aggregatePlural: "finished subagent runs",
|
|
249
|
+
});
|
|
250
|
+
} else {
|
|
251
|
+
onEvent(`cleared ${dismissed} finished subagent ${dismissed === 1 ? "run" : "runs"}`, "info");
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if (failures) onEvent(`could not ${automatic ? "auto-clear" : "clear"} ${failures} finished subagent ${failures === 1 ? "run" : "runs"}`, "warn");
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function dispose() {
|
|
258
|
+
if (disposed) return;
|
|
259
|
+
disposed = true;
|
|
260
|
+
stopTimer();
|
|
261
|
+
refreshPromise = null;
|
|
262
|
+
refreshQueued = false;
|
|
263
|
+
loading = false;
|
|
264
|
+
clearingFinished = false;
|
|
265
|
+
cancelRequest = null;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return { start, refresh, schedule, getSnapshot, beginCancel, resetCancel, submitCancel, dismiss, clearFinished, dispose };
|
|
269
|
+
}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
export const EVENT_DISPLAY_MODE_STORAGE_KEY = "pi-webui-event-display-mode-v1";
|
|
2
|
+
export const EVENT_FILTER_STORAGE_KEY = "pi-webui-event-filter-v1";
|
|
3
|
+
export const EVENT_FILTER_VALUES = new Set(["all", "errors", "warnings", "tools", "tree"]);
|
|
4
|
+
|
|
5
|
+
export function normalizeEventDisplayMode(value) {
|
|
6
|
+
return value === "compact" ? "compact" : "detailed";
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function normalizeEventFilter(value) {
|
|
10
|
+
return EVENT_FILTER_VALUES.has(value) ? value : "all";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function createActivityEventsController({
|
|
14
|
+
document,
|
|
15
|
+
nodes,
|
|
16
|
+
readPreference,
|
|
17
|
+
writePreference,
|
|
18
|
+
isVisible,
|
|
19
|
+
onJump,
|
|
20
|
+
onNotice,
|
|
21
|
+
onUnreadChange,
|
|
22
|
+
}) {
|
|
23
|
+
let disposed = false;
|
|
24
|
+
let eventFilter = readStoredEventFilter();
|
|
25
|
+
let eventDisplayMode = readStoredEventDisplayMode();
|
|
26
|
+
let eventsUnreadCount = 0;
|
|
27
|
+
|
|
28
|
+
function make(tag, className, text) {
|
|
29
|
+
const node = document.createElement(tag);
|
|
30
|
+
if (className) node.className = className;
|
|
31
|
+
if (text !== undefined) node.textContent = text;
|
|
32
|
+
return node;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function jumpToEvent(event) {
|
|
36
|
+
if (disposed) return;
|
|
37
|
+
let row = event.target;
|
|
38
|
+
while (row && row.parentNode !== nodes.eventLog) row = row.parentNode;
|
|
39
|
+
if (row?.classList?.contains("event")) onJump(row);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function readStoredEventDisplayMode() {
|
|
43
|
+
try {
|
|
44
|
+
return normalizeEventDisplayMode(readPreference(EVENT_DISPLAY_MODE_STORAGE_KEY));
|
|
45
|
+
} catch {
|
|
46
|
+
return "detailed";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function readStoredEventFilter() {
|
|
51
|
+
try {
|
|
52
|
+
return normalizeEventFilter(readPreference(EVENT_FILTER_STORAGE_KEY));
|
|
53
|
+
} catch {
|
|
54
|
+
return "all";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function eventRowMatchesFilter(line, filter = eventFilter) {
|
|
59
|
+
if (!line?.classList?.contains("event") || filter === "all") return true;
|
|
60
|
+
if (filter === "errors") return line.dataset.eventLevel === "error";
|
|
61
|
+
if (filter === "warnings") return line.dataset.eventLevel === "warn";
|
|
62
|
+
if (filter === "tools") return ["start", "finish"].includes(line.dataset.eventToolPhase);
|
|
63
|
+
if (filter === "tree") return line.dataset.eventTreeAvailable === "true";
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function applyEventFilter() {
|
|
68
|
+
const rows = [...(nodes.eventLog?.children || [])].filter((line) => line.classList?.contains("event"));
|
|
69
|
+
let shown = 0;
|
|
70
|
+
for (const line of rows) {
|
|
71
|
+
const matches = eventRowMatchesFilter(line);
|
|
72
|
+
line.hidden = !matches;
|
|
73
|
+
if (matches) shown += 1;
|
|
74
|
+
}
|
|
75
|
+
const total = rows.length;
|
|
76
|
+
if (nodes.eventFilterStatus) {
|
|
77
|
+
nodes.eventFilterStatus.textContent = total === 0
|
|
78
|
+
? "No events yet"
|
|
79
|
+
: eventFilter === "all"
|
|
80
|
+
? `${total} event${total === 1 ? "" : "s"}`
|
|
81
|
+
: `${shown} of ${total}`;
|
|
82
|
+
}
|
|
83
|
+
if (nodes.eventFilterEmpty) {
|
|
84
|
+
nodes.eventFilterEmpty.hidden = total === 0 || shown > 0;
|
|
85
|
+
const label = nodes.eventFilterSelect?.selectedOptions?.[0]?.textContent?.trim() || "this filter";
|
|
86
|
+
nodes.eventFilterEmpty.textContent = `No events match ${label.toLowerCase()}.`;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function syncEventFilterUi() {
|
|
91
|
+
if (nodes.eventFilterSelect) nodes.eventFilterSelect.value = eventFilter;
|
|
92
|
+
applyEventFilter();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function setEventFilter(value, { persist = true } = {}) {
|
|
96
|
+
if (disposed) return;
|
|
97
|
+
eventFilter = normalizeEventFilter(value);
|
|
98
|
+
syncEventFilterUi();
|
|
99
|
+
if (!persist) return;
|
|
100
|
+
try {
|
|
101
|
+
writePreference(EVENT_FILTER_STORAGE_KEY, eventFilter);
|
|
102
|
+
} catch {
|
|
103
|
+
// The filter remains active for this page when storage is unavailable.
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function syncEventDisplayModeUi() {
|
|
108
|
+
if (nodes.eventLog) nodes.eventLog.dataset.displayMode = eventDisplayMode;
|
|
109
|
+
nodes.eventDisplayDetailedAction?.setAttribute("aria-checked", String(eventDisplayMode === "detailed"));
|
|
110
|
+
nodes.eventDisplayCompactAction?.setAttribute("aria-checked", String(eventDisplayMode === "compact"));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function setEventDisplayMode(value, { persist = true } = {}) {
|
|
114
|
+
if (disposed) return;
|
|
115
|
+
eventDisplayMode = normalizeEventDisplayMode(value);
|
|
116
|
+
syncEventDisplayModeUi();
|
|
117
|
+
if (!persist) return;
|
|
118
|
+
try {
|
|
119
|
+
writePreference(EVENT_DISPLAY_MODE_STORAGE_KEY, eventDisplayMode);
|
|
120
|
+
} catch {
|
|
121
|
+
// Display mode remains active for this page when storage is unavailable.
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function addEvent(message, level = "info", { toolCallId = "", toolEventPhase = "", details = [], notify = true, occurredAt = Date.now(), aggregateKey = "", aggregateIncrement = 1, aggregateSingular = "", aggregatePlural = "" } = {}) {
|
|
126
|
+
if (disposed) return;
|
|
127
|
+
const stableAggregateKey = String(aggregateKey || "").trim();
|
|
128
|
+
const priorAggregate = stableAggregateKey
|
|
129
|
+
? [...(nodes.eventLog?.children || [])].find((candidate) => candidate.dataset.eventAggregateKey === stableAggregateKey)
|
|
130
|
+
: null;
|
|
131
|
+
const aggregateCount = stableAggregateKey
|
|
132
|
+
? Math.max(0, Number.parseInt(priorAggregate?.dataset.eventAggregateCount || "0", 10) || 0) + Math.max(1, Math.trunc(Number(aggregateIncrement) || 1))
|
|
133
|
+
: 0;
|
|
134
|
+
const eventMessage = stableAggregateKey && aggregateSingular
|
|
135
|
+
? `${message} ${aggregateCount} ${aggregateCount === 1 ? aggregateSingular : aggregatePlural || aggregateSingular}`
|
|
136
|
+
: String(message || "");
|
|
137
|
+
priorAggregate?.remove();
|
|
138
|
+
const line = make("button", `event ${level}`.trim());
|
|
139
|
+
line.type = "button";
|
|
140
|
+
line.dataset.eventLevel = String(level || "info").trim().toLowerCase() || "info";
|
|
141
|
+
line.dataset.chatEventTimestamp = String(occurredAt);
|
|
142
|
+
if (stableAggregateKey) {
|
|
143
|
+
line.dataset.eventAggregateKey = stableAggregateKey;
|
|
144
|
+
line.dataset.eventAggregateCount = String(aggregateCount);
|
|
145
|
+
}
|
|
146
|
+
const stableToolCallId = String(toolCallId || "").trim();
|
|
147
|
+
const toolLifecycle = ["start", "finish"].includes(toolEventPhase);
|
|
148
|
+
const treeEligible = stableToolCallId && toolLifecycle;
|
|
149
|
+
line.dataset.eventTreeAvailable = String(!!treeEligible);
|
|
150
|
+
if (stableToolCallId) line.dataset.chatToolCallId = stableToolCallId;
|
|
151
|
+
if (toolLifecycle) line.dataset.eventToolPhase = toolEventPhase;
|
|
152
|
+
line.setAttribute("aria-keyshortcuts", "ContextMenu Shift+F10");
|
|
153
|
+
const time = make("span", "event-time", `[${new Date(occurredAt).toLocaleTimeString()}]`);
|
|
154
|
+
const summary = make("span", "event-summary", eventMessage);
|
|
155
|
+
const main = make("span", "event-main");
|
|
156
|
+
main.append(time, summary);
|
|
157
|
+
line.append(main);
|
|
158
|
+
if (Array.isArray(details) && details.length) {
|
|
159
|
+
const meta = make("span", "event-details");
|
|
160
|
+
for (const detail of details) {
|
|
161
|
+
if (!detail?.label || !detail?.value) continue;
|
|
162
|
+
const item = make("span", `event-detail${detail.tone ? ` ${detail.tone}` : ""}`);
|
|
163
|
+
item.append(make("span", "event-detail-label", `${detail.label}:`), document.createTextNode(` ${detail.value}`));
|
|
164
|
+
meta.append(item);
|
|
165
|
+
}
|
|
166
|
+
if (meta.childElementCount) line.append(meta);
|
|
167
|
+
}
|
|
168
|
+
const accessibleText = line.textContent.trim();
|
|
169
|
+
line.title = `Jump to this event in the chat; open the context menu for display options${treeEligible ? " and Tree navigation" : ""}`;
|
|
170
|
+
line.setAttribute("aria-label", `${accessibleText}. Jump to this event in the chat. Context menu: display options${treeEligible ? " and Tree navigation" : ""}.`);
|
|
171
|
+
nodes.eventLog.prepend(line);
|
|
172
|
+
while (nodes.eventLog.children.length > 120) nodes.eventLog.lastElementChild?.remove();
|
|
173
|
+
applyEventFilter();
|
|
174
|
+
if (notify && (level === "error" || level === "warn")) {
|
|
175
|
+
onNotice(eventMessage, level);
|
|
176
|
+
noteUnreadEvent();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function renderEventsUnreadBadge() {
|
|
181
|
+
const badge = nodes.eventsUnreadBadge;
|
|
182
|
+
if (!badge) return;
|
|
183
|
+
badge.textContent = eventsUnreadCount > 99 ? "99+" : String(eventsUnreadCount);
|
|
184
|
+
badge.hidden = eventsUnreadCount === 0;
|
|
185
|
+
badge.setAttribute("aria-label", `${eventsUnreadCount} unread warning${eventsUnreadCount === 1 ? "" : "s"} or errors`);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function noteUnreadEvent() {
|
|
189
|
+
if (isVisible()) return;
|
|
190
|
+
eventsUnreadCount += 1;
|
|
191
|
+
renderEventsUnreadBadge();
|
|
192
|
+
onUnreadChange(eventsUnreadCount);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function clearUnreadEvents() {
|
|
196
|
+
if (disposed || !eventsUnreadCount) return;
|
|
197
|
+
eventsUnreadCount = 0;
|
|
198
|
+
renderEventsUnreadBadge();
|
|
199
|
+
onUnreadChange(eventsUnreadCount);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function syncUi() {
|
|
203
|
+
if (disposed) return;
|
|
204
|
+
syncEventFilterUi();
|
|
205
|
+
syncEventDisplayModeUi();
|
|
206
|
+
renderEventsUnreadBadge();
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function syncVisibility() {
|
|
210
|
+
if (!disposed && isVisible()) clearUnreadEvents();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function getSnapshot() {
|
|
214
|
+
return { filter: eventFilter, displayMode: eventDisplayMode, unreadCount: eventsUnreadCount };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function dispose() {
|
|
218
|
+
if (disposed) return;
|
|
219
|
+
disposed = true;
|
|
220
|
+
nodes.eventLog.removeEventListener("click", jumpToEvent);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
nodes.eventLog.addEventListener("click", jumpToEvent);
|
|
224
|
+
syncUi();
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
add: addEvent,
|
|
228
|
+
setFilter: setEventFilter,
|
|
229
|
+
setDisplayMode: setEventDisplayMode,
|
|
230
|
+
syncUi,
|
|
231
|
+
clearUnread: clearUnreadEvents,
|
|
232
|
+
syncVisibility,
|
|
233
|
+
getSnapshot,
|
|
234
|
+
dispose,
|
|
235
|
+
};
|
|
236
|
+
}
|