@firstpick/pi-package-webui 0.9.1 → 0.9.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/README.md +31 -9
- package/bin/pi-webui-launcher.mjs +23 -12
- package/bin/pi-webui.mjs +729 -93
- package/index.ts +266 -1
- package/lib/agent-run-adapters.mjs +500 -0
- package/lib/agent-run-protocol.mjs +262 -0
- package/lib/agent-run-registry.mjs +339 -0
- package/lib/git-workflow-preferences.mjs +18 -28
- package/lib/intercom-conversations.mjs +491 -0
- package/lib/intercom-transcript-filter.mjs +99 -0
- package/lib/resource-selection.mjs +140 -0
- package/lib/trust-boundaries.mjs +2 -0
- package/lib/ui-layout-settings.mjs +172 -28
- package/lib/update/package-layout.mjs +50 -0
- package/lib/update/plan.mjs +11 -0
- package/package.json +2 -2
- package/public/app.js +2276 -419
- package/public/index.html +142 -72
- package/public/service-worker.js +2 -1
- package/public/stream-output-controller.mjs +15 -0
- package/public/styles.css +764 -92
- package/public/syntax-highlight.mjs +622 -0
- package/tests/agent-run-adapters.test.mjs +217 -0
- package/tests/agent-run-launcher.test.mjs +41 -0
- package/tests/agent-run-protocol.test.mjs +82 -0
- package/tests/agent-run-registry.test.mjs +102 -0
- package/tests/boot-failure-diagnostics.test.mjs +3 -3
- package/tests/browser/control-deck-side-panels.spec.mjs +354 -0
- package/tests/browser/controls-layout.spec.mjs +122 -0
- package/tests/browser/file-tree-git-ignored.spec.mjs +113 -0
- package/tests/browser/interaction-continuity.spec.mjs +161 -0
- package/tests/browser/intercom-conversation-viewer.spec.mjs +355 -0
- package/tests/browser/mobile-foundation.spec.mjs +26 -0
- package/tests/browser/model-search-focus.spec.mjs +96 -0
- package/tests/browser/optimistic-prompt.spec.mjs +22 -0
- package/tests/browser/persistent-ui-layout.spec.mjs +285 -66
- package/tests/browser/resource-profiles.spec.mjs +200 -0
- package/tests/browser/subagent-observability.spec.mjs +116 -0
- package/tests/codex-fast-mode-static.test.mjs +7 -6
- package/tests/common-options-submenus-interaction-static.test.mjs +2 -0
- package/tests/common-options-submenus-markup-static.test.mjs +1 -0
- package/tests/component-update-api-static.test.mjs +2 -1
- package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
- package/tests/composer-skill-tag-layout.test.mjs +32 -2
- package/tests/control-deck-component-updates-static.test.mjs +6 -0
- package/tests/control-deck-side-panels-static.test.mjs +68 -0
- package/tests/controls-layout-static.test.mjs +22 -0
- package/tests/fast-mode-client-static.test.mjs +2 -2
- package/tests/feature-decision-output-popup-static.test.mjs +2 -2
- package/tests/feature-system-prompt-optional-feature-static.test.mjs +5 -5
- package/tests/file-tree-git-ignored-static.test.mjs +152 -0
- package/tests/file-tree-search-layout-static.test.mjs +2 -1
- package/tests/file-viewer-image-static.test.mjs +69 -0
- package/tests/fixtures/fake-pi.mjs +147 -12
- package/tests/foreground-transcript-catch-up-static.test.mjs +1 -1
- package/tests/git-panel-file-preview-static.test.mjs +5 -5
- package/tests/git-panel-live-updates-static.test.mjs +3 -3
- package/tests/git-workflow-preferences.test.mjs +55 -6
- package/tests/http-endpoints-harness.test.mjs +295 -14
- package/tests/intercom-conversation-viewer-static.test.mjs +105 -0
- package/tests/intercom-conversations-http.test.mjs +252 -0
- package/tests/intercom-conversations.test.mjs +374 -0
- package/tests/intercom-main-transcript-suppression-static.test.mjs +52 -0
- package/tests/intercom-tag-layout-static.test.mjs +46 -0
- package/tests/intercom-transcript-filter.test.mjs +98 -0
- package/tests/main-output-loading-static.test.mjs +59 -0
- package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
- package/tests/mobile-compact-layout.test.mjs +2 -3
- package/tests/mobile-continuity-tablet-static.test.mjs +6 -6
- package/tests/mobile-foundation-static.test.mjs +3 -3
- package/tests/mobile-phone-experience-static.test.mjs +1 -1
- package/tests/mobile-static.test.mjs +76 -42
- package/tests/native-parity.test.mjs +8 -7
- package/tests/open-issue-wizard-static.test.mjs +2 -2
- package/tests/optional-feature-migration-frontend.test.mjs +5 -5
- package/tests/optional-feature-resource-setup-static.test.mjs +29 -0
- package/tests/persistent-ui-layout-static.test.mjs +13 -13
- package/tests/questionnaire-dialog.test.mjs +3 -3
- package/tests/remote-auth-settings-harness.test.mjs +1 -1
- package/tests/resource-defaults-helper.test.mjs +60 -6
- package/tests/resource-selection.test.mjs +114 -0
- package/tests/resource-tui-extension.test.mjs +23 -0
- package/tests/session-sampling-ui-static.test.mjs +3 -3
- package/tests/side-panel-context-menu-static.test.mjs +1 -1
- package/tests/side-panel-resize-static.test.mjs +26 -16
- package/tests/side-panel-section-height-removal-static.test.mjs +4 -4
- package/tests/side-panel-section-reorder-static.test.mjs +16 -70
- package/tests/stream-output-controller.test.mjs +8 -0
- package/tests/stream-output-isolation-static.test.mjs +2 -2
- package/tests/streaming-ui-coupling.test.mjs +5 -0
- package/tests/subagent-gate-visibility.test.mjs +2 -1
- package/tests/subagent-launch-slots.test.mjs +1 -1
- package/tests/subagent-observability-static.test.mjs +32 -0
- package/tests/subagent-reliability-integration.test.mjs +183 -0
- package/tests/subagent-workflow-section-static.test.mjs +67 -0
- package/tests/subagents-helper.test.mjs +548 -5
- package/tests/syntax-highlight.test.mjs +235 -0
- package/tests/syntax-highlighting-static.test.mjs +84 -0
- package/tests/terminal-tabs-resize-static.test.mjs +35 -0
- package/tests/theme-customizer-static.test.mjs +5 -5
- package/tests/thinking-format-parser.test.mjs +64 -0
- package/tests/ui-layout-settings.test.mjs +104 -32
- package/tests/update-api-harness.test.mjs +24 -10
- package/tests/update-package-layout.test.mjs +38 -0
- package/tests/update-plan.test.mjs +11 -1
- package/tests/webui-settings-locking.test.mjs +33 -3
- package/webui-rpc-helper.mjs +700 -89
package/public/app.js
CHANGED
|
@@ -9,8 +9,9 @@ import { buildIssuePayload, createIssueWizardCatalog, createIssueWizardState, ge
|
|
|
9
9
|
import { createIssueBotClient, readIssueBotRuntimeConfig } from "./issue-bot-client.mjs";
|
|
10
10
|
import { MOBILE_SHELL_STORAGE_KEY, TABLET_SHELL_STORAGE_KEY, createMobileShellState, isMobileShellV2Enabled, mobileNavigationTargetFromSearch, normalizeMobileNavigationTarget, reduceMobileShellState, resolveMobileShellFeatureMode, resolveTabletShellFeatureMode } from "./mobile-shell-state.mjs";
|
|
11
11
|
import { createTranscriptRenderer } from "./transcript-renderer.mjs";
|
|
12
|
-
import { classifyTranscriptStreamEvent, createStreamOutputController } from "./stream-output-controller.mjs";
|
|
12
|
+
import { classifyTranscriptStreamEvent, createStreamOutputController, reconcileTranscriptThinkingSnapshot } from "./stream-output-controller.mjs";
|
|
13
13
|
import { installMiddleButtonDragScroll } from "./middle-button-drag-scroll.mjs";
|
|
14
|
+
import { tokenizeCode } from "./syntax-highlight.mjs";
|
|
14
15
|
import { PI_THEME_EXPORT_FIELDS, THEME_TOKEN_GROUPS, canonicalizeTheme, serializeTheme, themeColorToRgb, validateTheme } from "./theme-contract.mjs";
|
|
15
16
|
import {
|
|
16
17
|
SAMPLING_PARAMETER_CATALOG,
|
|
@@ -33,6 +34,7 @@ const elements = {
|
|
|
33
34
|
tabBar: $("#tabBar"),
|
|
34
35
|
terminalTabsToggleButton: $("#terminalTabsToggleButton"),
|
|
35
36
|
terminalTabsShell: $(".terminal-tabs-shell"),
|
|
37
|
+
terminalTabsResizeHandle: $("#terminalTabsResizeHandle"),
|
|
36
38
|
terminalTabsDrawerContent: $("#terminalTabsDrawerContent"),
|
|
37
39
|
terminalTabsBackdrop: $("#terminalTabsBackdrop"),
|
|
38
40
|
workspaceSaveButton: $("#workspaceSaveButton"),
|
|
@@ -56,6 +58,8 @@ const elements = {
|
|
|
56
58
|
contextMeterBar: $("#contextMeterBar"),
|
|
57
59
|
serverOfflinePanel: $("#serverOfflinePanel"),
|
|
58
60
|
serverRestartPanel: $("#serverRestartPanel"),
|
|
61
|
+
serverRestartKicker: $("#serverRestartKicker"),
|
|
62
|
+
serverRestartTitle: $("#serverRestartTitle"),
|
|
59
63
|
serverRestartMessage: $("#serverRestartMessage"),
|
|
60
64
|
updateNotification: $("#updateNotification"),
|
|
61
65
|
updateNotificationTitle: $("#updateNotificationTitle"),
|
|
@@ -93,6 +97,7 @@ const elements = {
|
|
|
93
97
|
subagentCancelSubmitButton: $("#subagentCancelSubmitButton"),
|
|
94
98
|
stickyUserPromptButton: $("#stickyUserPromptButton"),
|
|
95
99
|
chat: $("#chat"),
|
|
100
|
+
mainOutputLoading: $("#mainOutputLoading"),
|
|
96
101
|
runIndicatorHost: $("#runIndicatorHost"),
|
|
97
102
|
chatSearchBar: $("#chatSearchBar"),
|
|
98
103
|
chatSearchInput: $("#chatSearchInput"),
|
|
@@ -126,6 +131,13 @@ const elements = {
|
|
|
126
131
|
busyPromptBehaviorTag: $("#busyPromptBehaviorTag"),
|
|
127
132
|
busyPromptBehaviorMenu: $("#busyPromptBehaviorMenu"),
|
|
128
133
|
sessionSkillTags: $("#sessionSkillTags"),
|
|
134
|
+
intercomConversationTags: $("#intercomConversationTags"),
|
|
135
|
+
intercomConversationDialog: $("#intercomConversationDialog"),
|
|
136
|
+
intercomConversationTitle: $("#intercomConversationTitle"),
|
|
137
|
+
intercomConversationParticipants: $("#intercomConversationParticipants"),
|
|
138
|
+
intercomConversationTranscript: $("#intercomConversationTranscript"),
|
|
139
|
+
intercomConversationStatus: $("#intercomConversationStatus"),
|
|
140
|
+
intercomConversationCloseButton: $("#intercomConversationCloseButton"),
|
|
129
141
|
featureCategoryTag: $("#featureCategoryTag"),
|
|
130
142
|
featureDecisionDialog: $("#featureDecisionDialog"),
|
|
131
143
|
featureDecisionDialogOutput: $("#featureDecisionDialogOutput"),
|
|
@@ -188,6 +200,8 @@ const elements = {
|
|
|
188
200
|
optionsWorkflowSetupButton: $("#optionsWorkflowSetupButton"),
|
|
189
201
|
optionsSafetyGuardSetupButton: $("#optionsSafetyGuardSetupButton"),
|
|
190
202
|
optionsGitWorkflowSetupButton: $("#optionsGitWorkflowSetupButton"),
|
|
203
|
+
optionsToolsSetupButton: $("#optionsToolsSetupButton"),
|
|
204
|
+
optionsSkillsSetupButton: $("#optionsSkillsSetupButton"),
|
|
191
205
|
optionsExportButton: $("#optionsExportButton"),
|
|
192
206
|
optionsForkButton: $("#optionsForkButton"),
|
|
193
207
|
optionsTreeButton: $("#optionsTreeButton"),
|
|
@@ -320,6 +334,8 @@ const elements = {
|
|
|
320
334
|
fileViewerEditor: $("#fileViewerEditor"),
|
|
321
335
|
fileViewerSearchOverlay: $("#fileViewerSearchOverlay"),
|
|
322
336
|
fileViewerPreview: $("#fileViewerPreview"),
|
|
337
|
+
fileViewerImage: $("#fileViewerImage"),
|
|
338
|
+
fileViewerImageElement: $("#fileViewerImageElement"),
|
|
323
339
|
fileViewerChanges: $("#fileViewerChanges"),
|
|
324
340
|
fileViewerStatus: $("#fileViewerStatus"),
|
|
325
341
|
fileViewerSearchBar: $("#fileViewerSearchBar"),
|
|
@@ -336,6 +352,15 @@ const elements = {
|
|
|
336
352
|
sidePanelContextMenu: $("#sidePanelContextMenu"),
|
|
337
353
|
gitFooterContextMenu: $("#gitFooterContextMenu"),
|
|
338
354
|
sidePanelResizeHandle: $("#sidePanelResizeHandle"),
|
|
355
|
+
sidePanelResizeHandleLeft: $("#sidePanelLeftResizeHandle"),
|
|
356
|
+
sidePanelLeftExpandButton: $("#sidePanelLeftExpandButton"),
|
|
357
|
+
sidePanelLeft: $("#sidePanelLeft"),
|
|
358
|
+
sidePanelBodyLeft: $("#sidePanelBodyLeft"),
|
|
359
|
+
sidePanelBodyRight: $("#sidePanelBodyRight"),
|
|
360
|
+
toggleSidePanelLeftButton: $("#toggleSidePanelLeftButton"),
|
|
361
|
+
controlDeckPlacementSelect: $("#controlDeckPlacementSelect"),
|
|
362
|
+
controlDeckPlacementStatus: $("#controlDeckPlacementStatus"),
|
|
363
|
+
controlDeckMovementAnnouncer: $("#controlDeckMovementAnnouncer"),
|
|
339
364
|
sidePanelEditButton: $("#sidePanelEditButton"),
|
|
340
365
|
sidePanelEditHint: $("#sidePanelEditHint"),
|
|
341
366
|
toggleSidePanelButton: $("#toggleSidePanelButton"),
|
|
@@ -556,9 +581,18 @@ const transcriptRenderer = createTranscriptRenderer({
|
|
|
556
581
|
const PI_WEBUI_NPM_URL = "https://www.npmjs.com/package/@firstpick/pi-package-webui";
|
|
557
582
|
|
|
558
583
|
let currentState = null;
|
|
584
|
+
let tabStateCache = new Map();
|
|
585
|
+
let tabStatsCache = new Map();
|
|
586
|
+
let tabWorkspaceCache = new Map();
|
|
559
587
|
let tabs = [];
|
|
560
588
|
let activeTabId = null;
|
|
561
589
|
let activeTabGeneration = 0;
|
|
590
|
+
const intercomConversationSummariesByTab = new Map();
|
|
591
|
+
let intercomSummaryRequestSerial = 0;
|
|
592
|
+
let intercomSummaryRefreshTimer = null;
|
|
593
|
+
let intercomDetailRequestSerial = 0;
|
|
594
|
+
let intercomDetailRefreshTimer = null;
|
|
595
|
+
let intercomConversationDialogState = null;
|
|
562
596
|
let tabDrafts = new Map();
|
|
563
597
|
let tabAttachments = new Map();
|
|
564
598
|
let activeTextAttachmentEditor = null;
|
|
@@ -582,6 +616,8 @@ let sidePanelSectionEditMode = false;
|
|
|
582
616
|
let sidePanelSectionPointerDrag = null;
|
|
583
617
|
let sidePanelSectionLastDragOverKey = "";
|
|
584
618
|
let sidePanelSectionSuppressClickUntil = 0;
|
|
619
|
+
let controlDeckPresentationReconcileFrame = null;
|
|
620
|
+
let controlDeckPresentationReconcileActive = false;
|
|
585
621
|
let composerActionPointerDrag = null;
|
|
586
622
|
let composerActionLastDragOverKey = "";
|
|
587
623
|
let composerActionSuppressClickUntil = 0;
|
|
@@ -591,6 +627,7 @@ let composerActionLayoutRestoreFrame = null;
|
|
|
591
627
|
let fileTreeDragState = null;
|
|
592
628
|
let fileViewerResizeState = null;
|
|
593
629
|
let sidePanelResizeState = null;
|
|
630
|
+
let terminalTabsResizeState = null;
|
|
594
631
|
let sidePanelWidthPreferenceRevision = 0;
|
|
595
632
|
let fileTreeSearchTimer = null;
|
|
596
633
|
let fileTreeSearchRequestSerial = 0;
|
|
@@ -706,9 +743,17 @@ const streamOutputController = createStreamOutputController({
|
|
|
706
743
|
isOwnerCurrent: (owner) => owner === transcriptStreamOwner(),
|
|
707
744
|
applyTextUpdate: (event) => handleMessageUpdate(event),
|
|
708
745
|
applyThinkingUpdate: (event) => handleMessageUpdate(event),
|
|
709
|
-
applyToolCallUpdate: (event) =>
|
|
746
|
+
applyToolCallUpdate: (event) => {
|
|
747
|
+
if (isIntercomToolCallUpdate(event)) {
|
|
748
|
+
streamToolCallSeen = true;
|
|
749
|
+
suppressStreamingAssistantTextBeforeToolCall();
|
|
750
|
+
resetStreamingToolCallState({ remove: true });
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
handleMessageUpdate(event);
|
|
754
|
+
},
|
|
710
755
|
applyToolExecutionUpdate: (event) => {
|
|
711
|
-
if (!compactOutputActive()) applyTranscriptToolExecutionUpdate(event);
|
|
756
|
+
if (!compactOutputActive() && !isIntercomTransportToolName(event?.toolName)) applyTranscriptToolExecutionUpdate(event);
|
|
712
757
|
},
|
|
713
758
|
applyStreamError: (event) => handleMessageUpdate(event),
|
|
714
759
|
applyFollowScroll: () => {
|
|
@@ -757,6 +802,9 @@ let runIndicatorActivity = "Waiting for output or action…";
|
|
|
757
802
|
let refreshMessagesTimer = null;
|
|
758
803
|
let refreshStateTimer = null;
|
|
759
804
|
let refreshFooterTimer = null;
|
|
805
|
+
const mainOutputLoadingRequests = new Set();
|
|
806
|
+
let mainOutputLoadingRevealTimer = null;
|
|
807
|
+
const MAIN_OUTPUT_LOADING_REVEAL_DELAY_MS = 120;
|
|
760
808
|
let refreshTabsTimer = null;
|
|
761
809
|
let tabsRenderFrame = null;
|
|
762
810
|
let foregroundReconcileTimer = null;
|
|
@@ -804,6 +852,7 @@ let nativeSettingsDirty = false;
|
|
|
804
852
|
let sessionSummaryOverlayTabId = null;
|
|
805
853
|
let sessionSummaryOverlayFocusReturn = null;
|
|
806
854
|
let sessionSummaryOverlayFocusReturnKey = "";
|
|
855
|
+
let sessionSummaryControlsRenderSignature = "";
|
|
807
856
|
const sessionSummaryByTab = new Map();
|
|
808
857
|
let pathPickerState = null;
|
|
809
858
|
let firstTerminalCwdPromptShown = false;
|
|
@@ -902,10 +951,13 @@ let claudeUsageRenderSignature = "";
|
|
|
902
951
|
let latestSubagents = null;
|
|
903
952
|
let subagentsError = null;
|
|
904
953
|
let subagentsLoading = false;
|
|
954
|
+
let subagentsRefreshQueued = false;
|
|
955
|
+
let subagentsRefreshPromise = null;
|
|
905
956
|
let subagentsClearingFinished = false;
|
|
906
957
|
let subagentAutoClearEnabled = false;
|
|
907
958
|
let refreshSubagentsTimer = null;
|
|
908
959
|
const dismissedSubagentGateKeys = new Set();
|
|
960
|
+
const collapsedSubagentWorkflowRunKeys = new Set();
|
|
909
961
|
let subagentOverlaySelection = null;
|
|
910
962
|
let subagentOverlayData = null;
|
|
911
963
|
let subagentOverlayError = "";
|
|
@@ -1052,6 +1104,9 @@ const INTERFACE_DENSITY_STORAGE_KEY = "pi-webui-interface-density";
|
|
|
1052
1104
|
const SIDE_PANEL_SECTION_STORAGE_KEY = "pi-webui-side-panel-sections-collapsed";
|
|
1053
1105
|
const SIDE_PANEL_SECTION_VISIBILITY_STORAGE_KEY = "pi-webui-side-panel-sections-hidden";
|
|
1054
1106
|
const SIDE_PANEL_SECTION_ORDER_STORAGE_KEY = "pi-webui-side-panel-section-order-v1";
|
|
1107
|
+
const CONTROL_DECK_LAYOUT_STORAGE_KEY = "pi-webui-control-deck-layout-v2";
|
|
1108
|
+
const CONTROL_DECK_DEFAULT_PLACEMENT = "right";
|
|
1109
|
+
const CONTROL_DECK_SIDES = ["left", "right"];
|
|
1055
1110
|
const SIDE_PANEL_SECTION_POINTER_DRAG_THRESHOLD_PX = 6;
|
|
1056
1111
|
const COMPOSER_ACTION_ORDER_STORAGE_KEY = "pi-webui-composer-action-order-v1";
|
|
1057
1112
|
const COMPOSER_ACTION_LAYOUT_STORAGE_KEY = "pi-webui-composer-action-layout-v2";
|
|
@@ -1071,6 +1126,7 @@ const THINKING_VISIBILITY_STORAGE_KEY = "pi-webui-thinking-visible";
|
|
|
1071
1126
|
const BUSY_PROMPT_BEHAVIOR_STORAGE_KEY = "pi-webui-busy-prompt-behavior";
|
|
1072
1127
|
const SKILL_USAGE_STORAGE_KEY = "pi-webui-skill-usage-v1";
|
|
1073
1128
|
const TERMINAL_TABS_LAYOUT_STORAGE_KEY = "pi-webui-terminal-tabs-layout";
|
|
1129
|
+
const TERMINAL_TABS_SIDEBAR_WIDTH_STORAGE_KEY = "pi-webui-terminal-tabs-sidebar-width";
|
|
1074
1130
|
const SUBAGENT_OPEN_MODE_STORAGE_KEY = "pi-webui-subagent-open-mode";
|
|
1075
1131
|
const SUBAGENT_AUTO_CLEAR_STORAGE_KEY = "pi-webui-subagent-auto-clear";
|
|
1076
1132
|
const TERMINAL_CUSTOM_GROUPS_STORAGE_KEY = "pi-webui-terminal-custom-groups-v1";
|
|
@@ -1196,6 +1252,8 @@ const SIDE_PANEL_WIDTH_STORAGE_KEY = "pi-webui-side-panel-width";
|
|
|
1196
1252
|
const SIDE_PANEL_WIDTH_DEFAULT_PX = 384;
|
|
1197
1253
|
const SIDE_PANEL_WIDTH_MIN_PX = 320;
|
|
1198
1254
|
const SIDE_PANEL_WIDTH_MAX_PX = 4096;
|
|
1255
|
+
const TERMINAL_TABS_SIDEBAR_WIDTH_MIN_PX = 208;
|
|
1256
|
+
const TERMINAL_TABS_SIDEBAR_WIDTH_MAX_PX = 4096;
|
|
1199
1257
|
const FILE_VIEWER_CONTEXT_RADIUS_LINES = 6;
|
|
1200
1258
|
const FILE_TREE_ROOT_PATH = "";
|
|
1201
1259
|
const FILE_TREE_DRAG_MIME = "application/x-pi-webui-file-path";
|
|
@@ -1230,7 +1288,7 @@ let themeCatalogScopes = { global: { available: true }, project: { available: fa
|
|
|
1230
1288
|
let themeCustomizerGeneration = 0;
|
|
1231
1289
|
let themeCustomizerState = null;
|
|
1232
1290
|
const TERMINAL_TABS_LAYOUTS = new Set(["top", "left"]);
|
|
1233
|
-
const TERMINAL_TABS_LAYOUT_LABELS = { top: "Top bar", left: "
|
|
1291
|
+
const TERMINAL_TABS_LAYOUT_LABELS = { top: "Top bar", left: "Sidebar" };
|
|
1234
1292
|
const SUBAGENT_OPEN_MODES = new Set(["overlay", "tab"]);
|
|
1235
1293
|
const SUBAGENT_OPEN_MODE_LABELS = { overlay: "Overlay", tab: "Tab / terminal" };
|
|
1236
1294
|
const BUSY_PROMPT_BEHAVIOR_VALUES = new Set(["followUp", "steer"]);
|
|
@@ -2161,6 +2219,11 @@ function renderMobilePhoneExperience({ focus = false } = {}) {
|
|
|
2161
2219
|
}
|
|
2162
2220
|
document.documentElement.dataset.mobilePresentation = mobilePresentation;
|
|
2163
2221
|
const route = mobileShellState.route;
|
|
2222
|
+
const surface = mobileShellElement("mobileShellSurface");
|
|
2223
|
+
// Capture focus before route rendering can temporarily unmount canonical
|
|
2224
|
+
// Settings controls. Streaming state refreshes rebuild the mobile shell, and
|
|
2225
|
+
// the surface renderer remounts those same controls later in this pass.
|
|
2226
|
+
const surfaceFocusSnapshot = captureMobileSurfaceRenderFocus(surface);
|
|
2164
2227
|
const activeTabRecord = activeTab();
|
|
2165
2228
|
const activeState = activeTabRecord ? mobileTabActivityState(activeTabRecord) : "idle";
|
|
2166
2229
|
const title = mobileShellElement("mobileSessionTitle");
|
|
@@ -2207,8 +2270,6 @@ function renderMobilePhoneExperience({ focus = false } = {}) {
|
|
|
2207
2270
|
mobileWidgetAreaUnmount();
|
|
2208
2271
|
mobileCanonicalUnmount();
|
|
2209
2272
|
}
|
|
2210
|
-
const surface = mobileShellElement("mobileShellSurface");
|
|
2211
|
-
const surfaceFocusSnapshot = captureMobileSurfaceRenderFocus(surface);
|
|
2212
2273
|
if (mobileShellState.surface === "none") mobileSurfaceRenderFocus = null;
|
|
2213
2274
|
if (surface) {
|
|
2214
2275
|
surface.hidden = mobileShellState.surface === "none";
|
|
@@ -2524,6 +2585,7 @@ const OPTIONAL_FEATURES = [
|
|
|
2524
2585
|
packageName: "@firstpick/pi-extension-setup-skills",
|
|
2525
2586
|
capabilityLabel: "RPC /skills from setup-skills extension",
|
|
2526
2587
|
description: "Terminal-native skill setup command alongside WebUI-native /skills toggles.",
|
|
2588
|
+
setup: "skills",
|
|
2527
2589
|
},
|
|
2528
2590
|
{
|
|
2529
2591
|
id: "todoProgressWidget",
|
|
@@ -2538,6 +2600,7 @@ const OPTIONAL_FEATURES = [
|
|
|
2538
2600
|
packageName: "@firstpick/pi-extension-tools",
|
|
2539
2601
|
capabilityLabel: "RPC /tools from tools extension",
|
|
2540
2602
|
description: "Terminal-native active-tool manager alongside WebUI-native /tools toggles.",
|
|
2603
|
+
setup: "tools",
|
|
2541
2604
|
},
|
|
2542
2605
|
{
|
|
2543
2606
|
id: "remoteWebui",
|
|
@@ -2553,7 +2616,6 @@ const OPTIONAL_FEATURES = [
|
|
|
2553
2616
|
capabilityLabel: "questionnaire tool in /tools",
|
|
2554
2617
|
description: "Native TUI and WebUI single- or multi-select question series with Other answers and resumable clarification.",
|
|
2555
2618
|
manageWith: "tools",
|
|
2556
|
-
setup: "tools",
|
|
2557
2619
|
},
|
|
2558
2620
|
{
|
|
2559
2621
|
id: "naturalConversation",
|
|
@@ -3655,7 +3717,7 @@ function isMobileView() {
|
|
|
3655
3717
|
}
|
|
3656
3718
|
|
|
3657
3719
|
function isSidePanelOverlayView() {
|
|
3658
|
-
return
|
|
3720
|
+
return isControlDeckOverlayPresentation();
|
|
3659
3721
|
}
|
|
3660
3722
|
|
|
3661
3723
|
function mobileDropdownViewportHeight() {
|
|
@@ -3698,8 +3760,8 @@ function readStoredSidePanelCollapsed() {
|
|
|
3698
3760
|
}
|
|
3699
3761
|
}
|
|
3700
3762
|
|
|
3701
|
-
function
|
|
3702
|
-
return Array.from(
|
|
3763
|
+
function controlDeckSectionRecords() {
|
|
3764
|
+
return Array.from(document.querySelectorAll("[data-side-panel-section]"))
|
|
3703
3765
|
.map((section) => {
|
|
3704
3766
|
const id = section.dataset.sidePanelSection || "";
|
|
3705
3767
|
const button = section.querySelector("[data-side-panel-section-toggle]");
|
|
@@ -3710,6 +3772,157 @@ function sidePanelSectionRecords() {
|
|
|
3710
3772
|
.filter((record) => record.id && record.button && record.content);
|
|
3711
3773
|
}
|
|
3712
3774
|
|
|
3775
|
+
const sidePanelSectionRecords = controlDeckSectionRecords;
|
|
3776
|
+
|
|
3777
|
+
function isControlDeckSidebarPresentation() {
|
|
3778
|
+
return terminalTabsLayout === "left";
|
|
3779
|
+
}
|
|
3780
|
+
|
|
3781
|
+
function reconcileControlDeckPlacementConstraint() {
|
|
3782
|
+
const sidebarPresentation = isControlDeckSidebarPresentation();
|
|
3783
|
+
const bothOption = elements.controlDeckPlacementSelect?.querySelector('option[value="both"]');
|
|
3784
|
+
if (bothOption) bothOption.disabled = sidebarPresentation;
|
|
3785
|
+
const placement = normalizeControlDeckPlacement(controlDeckLayout.placement);
|
|
3786
|
+
if (!sidebarPresentation || placement !== "both") return placement;
|
|
3787
|
+
controlDeckLayout.placement = "right";
|
|
3788
|
+
cacheControlDeckLayout(controlDeckLayout, "placement");
|
|
3789
|
+
markDurableUiLayoutDirty("sidePanel", "placement");
|
|
3790
|
+
return "right";
|
|
3791
|
+
}
|
|
3792
|
+
|
|
3793
|
+
function isControlDeckOverlayPresentation() {
|
|
3794
|
+
if (document.body.classList.contains("embedded-split")) return false;
|
|
3795
|
+
if (sidePanelOverlayMedia?.matches) return true;
|
|
3796
|
+
const layout = document.querySelector(".layout");
|
|
3797
|
+
if (!layout) return false;
|
|
3798
|
+
const placement = normalizeControlDeckPlacement(controlDeckLayout.placement);
|
|
3799
|
+
const panelCount = placement === "both" ? 2 : 1;
|
|
3800
|
+
const splitCount = document.body.classList.contains("terminal-split-open") ? 1 : 0;
|
|
3801
|
+
const viewerCount = document.body.classList.contains("file-viewer-open") ? 1 : 0;
|
|
3802
|
+
const terminalRail = isControlDeckSidebarPresentation() ? Math.max(TERMINAL_TABS_SIDEBAR_WIDTH_MIN_PX, currentTerminalTabsSidebarWidth()) : 0;
|
|
3803
|
+
const centralMinimum = 320 + (splitCount * 320) + (viewerCount * FILE_VIEWER_WIDTH_MIN_PX) + terminalRail;
|
|
3804
|
+
const columnCount = panelCount + 1 + splitCount + viewerCount;
|
|
3805
|
+
const minimum = (panelCount * SIDE_PANEL_WIDTH_MIN_PX) + centralMinimum + (16 * Math.max(0, columnCount - 1)) + 32;
|
|
3806
|
+
return (layout.getBoundingClientRect?.().width || window.innerWidth || 0) < minimum;
|
|
3807
|
+
}
|
|
3808
|
+
|
|
3809
|
+
function effectiveControlDeckPresentation() {
|
|
3810
|
+
if (document.body.classList.contains("embedded-split")) return "embedded";
|
|
3811
|
+
if (isControlDeckOverlayPresentation()) return "overlay";
|
|
3812
|
+
return normalizeControlDeckPlacement(controlDeckLayout.placement);
|
|
3813
|
+
}
|
|
3814
|
+
|
|
3815
|
+
function controlDeckSectionSide(id) {
|
|
3816
|
+
return controlDeckLayout.sectionLayout?.leftSectionIds?.includes(id) ? "left" : "right";
|
|
3817
|
+
}
|
|
3818
|
+
|
|
3819
|
+
function reconcileControlDeckHosts() {
|
|
3820
|
+
const records = controlDeckSectionRecords();
|
|
3821
|
+
if (!records.length) return;
|
|
3822
|
+
const byId = new Map(records.map((record) => [record.id, record]));
|
|
3823
|
+
const known = records.map(({ id }) => id);
|
|
3824
|
+
const storedOrder = Array.isArray(controlDeckLayout.sectionLayout?.order) ? controlDeckLayout.sectionLayout.order : [];
|
|
3825
|
+
const completeOrder = [...storedOrder, ...known.filter((id) => !storedOrder.includes(id))];
|
|
3826
|
+
const order = completeOrder.filter((id) => byId.has(id));
|
|
3827
|
+
const storedLeftIds = Array.isArray(controlDeckLayout.sectionLayout?.leftSectionIds) ? controlDeckLayout.sectionLayout.leftSectionIds : [];
|
|
3828
|
+
controlDeckLayout.sectionLayout = { order: completeOrder, leftSectionIds: storedLeftIds.filter((id) => completeOrder.includes(id)) };
|
|
3829
|
+
const placement = reconcileControlDeckPlacementConstraint();
|
|
3830
|
+
const presentation = effectiveControlDeckPresentation();
|
|
3831
|
+
const leftIds = new Set(controlDeckLayout.sectionLayout.leftSectionIds);
|
|
3832
|
+
const leftBody = elements.sidePanelBodyLeft;
|
|
3833
|
+
const rightBody = elements.sidePanelBodyRight || elements.sidePanel?.querySelector(".side-panel-body");
|
|
3834
|
+
const targetBody = presentation === "left" || presentation === "sidebar" ? leftBody : rightBody;
|
|
3835
|
+
const desiredSectionsByBody = new Map();
|
|
3836
|
+
for (const id of order) {
|
|
3837
|
+
const record = byId.get(id);
|
|
3838
|
+
if (!record) continue;
|
|
3839
|
+
const body = presentation === "both" ? (leftIds.has(id) ? leftBody : rightBody) : targetBody;
|
|
3840
|
+
if (!body) continue;
|
|
3841
|
+
if (!desiredSectionsByBody.has(body)) desiredSectionsByBody.set(body, []);
|
|
3842
|
+
desiredSectionsByBody.get(body).push(record.section);
|
|
3843
|
+
}
|
|
3844
|
+
for (const [body, desiredSections] of desiredSectionsByBody) {
|
|
3845
|
+
const currentSections = [...body.children].filter((child) => child.matches?.("[data-side-panel-section]"));
|
|
3846
|
+
const alreadyReconciled = currentSections.length === desiredSections.length
|
|
3847
|
+
&& desiredSections.every((section, index) => currentSections[index] === section);
|
|
3848
|
+
if (!alreadyReconciled) desiredSections.forEach((section) => body.append(section));
|
|
3849
|
+
}
|
|
3850
|
+
const sidebarPresentation = isControlDeckSidebarPresentation();
|
|
3851
|
+
document.body.classList.toggle("control-deck-both", presentation === "both");
|
|
3852
|
+
document.body.classList.toggle("control-deck-sidebar", sidebarPresentation);
|
|
3853
|
+
document.body.classList.toggle("terminal-tabs-sidebar-start", sidebarPresentation && placement === "right");
|
|
3854
|
+
document.body.classList.toggle("control-deck-overlay", presentation === "overlay");
|
|
3855
|
+
document.body.classList.toggle("control-deck-left", presentation === "left");
|
|
3856
|
+
document.body.classList.toggle("control-deck-right", presentation === "right" || presentation === "both" || presentation === "overlay");
|
|
3857
|
+
if (elements.sidePanelLeft) elements.sidePanelLeft.hidden = presentation !== "both" && presentation !== "left";
|
|
3858
|
+
if (elements.sidePanel) elements.sidePanel.hidden = presentation === "embedded" || presentation === "left";
|
|
3859
|
+
const activeShell = presentation === "left" ? elements.sidePanelLeft : elements.sidePanel;
|
|
3860
|
+
activeShell?.setAttribute("aria-label", presentation === "overlay" ? "Control Deck" : activeShell === elements.sidePanelLeft ? "Left Control Deck" : "Right Control Deck");
|
|
3861
|
+
const sharedFooter = document.querySelector("[data-control-deck-shared-footer]");
|
|
3862
|
+
const footerHost = activeShell === elements.sidePanelLeft
|
|
3863
|
+
? elements.sidePanelLeft?.querySelector("[data-control-deck-footer-slot]")
|
|
3864
|
+
: elements.sidePanel;
|
|
3865
|
+
if (sharedFooter && footerHost && sharedFooter.parentElement !== footerHost) footerHost.append(sharedFooter);
|
|
3866
|
+
const versionRow = document.querySelector(".side-panel-version-row");
|
|
3867
|
+
const versionHost = activeShell === elements.sidePanelLeft
|
|
3868
|
+
? elements.sidePanelLeft?.querySelector("[data-control-deck-version-slot]")
|
|
3869
|
+
: elements.sidePanel?.querySelector(".side-panel-heading");
|
|
3870
|
+
if (versionRow && versionHost && versionRow.parentElement !== versionHost) versionHost.append(versionRow);
|
|
3871
|
+
const editButton = elements.sidePanelEditButton;
|
|
3872
|
+
const editHost = activeShell === elements.sidePanelLeft
|
|
3873
|
+
? elements.sidePanelLeft?.querySelector("[data-control-deck-edit-slot]")
|
|
3874
|
+
: elements.toggleSidePanelButton?.parentElement;
|
|
3875
|
+
if (editButton && editHost && editButton.parentElement !== editHost) editHost.prepend(editButton);
|
|
3876
|
+
editButton?.setAttribute("aria-controls", activeShell?.id || "sidePanel");
|
|
3877
|
+
if (elements.controlDeckPlacementSelect) elements.controlDeckPlacementSelect.value = placement;
|
|
3878
|
+
if (elements.controlDeckPlacementStatus) {
|
|
3879
|
+
const label = `${placement[0].toUpperCase()}${placement.slice(1)}`;
|
|
3880
|
+
const statusText = sidebarPresentation
|
|
3881
|
+
? placement === "right"
|
|
3882
|
+
? `${label} · Control Deck right, terminal/tabs left`
|
|
3883
|
+
: placement === "left"
|
|
3884
|
+
? `${label} · Control Deck left, terminal/tabs right`
|
|
3885
|
+
: `${label} · Control Deck on both sides, terminal/tabs right`
|
|
3886
|
+
: `${label} · saved in WebUI layout`;
|
|
3887
|
+
if (elements.controlDeckPlacementStatus.textContent !== statusText) elements.controlDeckPlacementStatus.textContent = statusText;
|
|
3888
|
+
}
|
|
3889
|
+
syncControlDeckCollapsedClasses();
|
|
3890
|
+
updateSidePanelResizeHandle(controlDeckLayout.panelWidths?.left || SIDE_PANEL_WIDTH_DEFAULT_PX, "left");
|
|
3891
|
+
updateSidePanelResizeHandle(controlDeckLayout.panelWidths?.right || readStoredSidePanelWidth() || SIDE_PANEL_WIDTH_DEFAULT_PX, "right");
|
|
3892
|
+
requestAnimationFrame(syncResizablePanelWidthsForViewport);
|
|
3893
|
+
for (const record of records) updateSidePanelSectionEditAffordance(record);
|
|
3894
|
+
}
|
|
3895
|
+
|
|
3896
|
+
function reconcileControlDeckPresentation() {
|
|
3897
|
+
if (controlDeckPresentationReconcileActive) return;
|
|
3898
|
+
controlDeckPresentationReconcileActive = true;
|
|
3899
|
+
try {
|
|
3900
|
+
const wasOverlay = document.body.classList.contains("control-deck-overlay");
|
|
3901
|
+
const willOverlay = isControlDeckOverlayPresentation();
|
|
3902
|
+
reconcileControlDeckHosts();
|
|
3903
|
+
if (willOverlay && !wasOverlay) {
|
|
3904
|
+
setSidePanelCollapsed(true, { persist: false });
|
|
3905
|
+
} else if (!willOverlay && wasOverlay) {
|
|
3906
|
+
restoreSidePanelState();
|
|
3907
|
+
} else {
|
|
3908
|
+
syncMobileSidePanelState(willOverlay ? document.body.classList.contains("side-panel-collapsed") : true);
|
|
3909
|
+
}
|
|
3910
|
+
if (willOverlay !== wasOverlay) updateTerminalSplitUi();
|
|
3911
|
+
updateTerminalSplitControls(Boolean(terminalSplitTab()) && !embeddedSplitMode && !willOverlay);
|
|
3912
|
+
syncResizablePanelWidthsForViewport();
|
|
3913
|
+
} finally {
|
|
3914
|
+
controlDeckPresentationReconcileActive = false;
|
|
3915
|
+
}
|
|
3916
|
+
}
|
|
3917
|
+
|
|
3918
|
+
function scheduleControlDeckPresentationReconciliation() {
|
|
3919
|
+
if (controlDeckPresentationReconcileFrame !== null) return;
|
|
3920
|
+
controlDeckPresentationReconcileFrame = requestAnimationFrame(() => {
|
|
3921
|
+
controlDeckPresentationReconcileFrame = null;
|
|
3922
|
+
reconcileControlDeckPresentation();
|
|
3923
|
+
});
|
|
3924
|
+
}
|
|
3925
|
+
|
|
3713
3926
|
function readStoredSidePanelSectionOrder() {
|
|
3714
3927
|
try {
|
|
3715
3928
|
const parsed = JSON.parse(localStorage.getItem(SIDE_PANEL_SECTION_ORDER_STORAGE_KEY) || "[]");
|
|
@@ -3719,27 +3932,26 @@ function readStoredSidePanelSectionOrder() {
|
|
|
3719
3932
|
}
|
|
3720
3933
|
}
|
|
3721
3934
|
|
|
3935
|
+
function persistControlDeckSectionLayout() {
|
|
3936
|
+
const known = controlDeckSectionRecords().map(({ id }) => id);
|
|
3937
|
+
const previousOrder = Array.isArray(controlDeckLayout.sectionLayout?.order) ? controlDeckLayout.sectionLayout.order : [];
|
|
3938
|
+
const order = [...previousOrder.filter((id) => known.includes(id)), ...known.filter((id) => !previousOrder.includes(id))];
|
|
3939
|
+
const leftSectionIds = (controlDeckLayout.sectionLayout?.leftSectionIds || []).filter((id) => order.includes(id));
|
|
3940
|
+
controlDeckLayout.sectionLayout = { order, leftSectionIds };
|
|
3941
|
+
cacheControlDeckLayout(controlDeckLayout, "sectionLayout");
|
|
3942
|
+
try { localStorage.setItem(SIDE_PANEL_SECTION_ORDER_STORAGE_KEY, JSON.stringify(order)); } catch { /* cache is best effort */ }
|
|
3943
|
+
markDurableUiLayoutDirty("sidePanel", "sectionLayout");
|
|
3944
|
+
}
|
|
3945
|
+
|
|
3722
3946
|
function persistSidePanelSectionOrder() {
|
|
3723
|
-
|
|
3724
|
-
localStorage.setItem(SIDE_PANEL_SECTION_ORDER_STORAGE_KEY, JSON.stringify(sidePanelSectionRecords().map(({ id }) => id)));
|
|
3725
|
-
} catch {
|
|
3726
|
-
// Ignore storage failures; ordering should still work for this page load.
|
|
3727
|
-
}
|
|
3728
|
-
markDurableUiLayoutDirty("sidePanel", "sectionOrder");
|
|
3947
|
+
persistControlDeckSectionLayout();
|
|
3729
3948
|
}
|
|
3730
3949
|
|
|
3731
3950
|
function restoreSidePanelSectionOrder() {
|
|
3732
3951
|
if (sidePanelSectionPointerDrag?.active) return;
|
|
3733
|
-
const
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
const rank = new Map(readStoredSidePanelSectionOrder().map((id, index) => [id, index]));
|
|
3737
|
-
records.sort((a, b) => {
|
|
3738
|
-
const aRank = rank.has(a.id) ? rank.get(a.id) : Number.MAX_SAFE_INTEGER;
|
|
3739
|
-
const bRank = rank.has(b.id) ? rank.get(b.id) : Number.MAX_SAFE_INTEGER;
|
|
3740
|
-
return aRank - bRank;
|
|
3741
|
-
});
|
|
3742
|
-
for (const { section } of records) parent.append(section);
|
|
3952
|
+
const storedOrder = controlDeckLayout.sectionLayout?.order || readStoredSidePanelSectionOrder() || [];
|
|
3953
|
+
controlDeckLayout.sectionLayout = { order: storedOrder, leftSectionIds: controlDeckLayout.sectionLayout?.leftSectionIds || [] };
|
|
3954
|
+
reconcileControlDeckHosts();
|
|
3743
3955
|
}
|
|
3744
3956
|
|
|
3745
3957
|
function visibleSidePanelSectionRecords() {
|
|
@@ -3761,11 +3973,14 @@ function updateSidePanelSectionEditAffordance(record) {
|
|
|
3761
3973
|
const label = record.button.querySelector(".side-panel-section-label")?.textContent?.trim() || "side panel";
|
|
3762
3974
|
const action = `${collapsed ? "Expand" : "Collapse"} ${label} section`;
|
|
3763
3975
|
const reorderingEnabled = isSidePanelSectionReorderingEnabled();
|
|
3976
|
+
const horizontalEnabled = reorderingEnabled && effectiveControlDeckPresentation() === "both";
|
|
3764
3977
|
record.button.setAttribute("aria-label", action);
|
|
3765
3978
|
record.button.setAttribute("title", reorderingEnabled
|
|
3766
|
-
? `${action} · drag to reorder · Alt+↑/↓ moves`
|
|
3979
|
+
? `${action} · drag to reorder · ${horizontalEnabled ? "Alt+↑/↓ reorders · Alt+←/→ moves sides" : "Alt+↑/↓ moves"}`
|
|
3767
3980
|
: action);
|
|
3768
|
-
if (reorderingEnabled) record.button.setAttribute("aria-keyshortcuts",
|
|
3981
|
+
if (reorderingEnabled) record.button.setAttribute("aria-keyshortcuts", horizontalEnabled
|
|
3982
|
+
? "Alt+ArrowUp Alt+ArrowDown Alt+ArrowLeft Alt+ArrowRight"
|
|
3983
|
+
: "Alt+ArrowUp Alt+ArrowDown");
|
|
3769
3984
|
else record.button.removeAttribute("aria-keyshortcuts");
|
|
3770
3985
|
}
|
|
3771
3986
|
|
|
@@ -3778,6 +3993,7 @@ function cancelSidePanelSectionPointerDrag() {
|
|
|
3778
3993
|
sidePanelSectionRecords().find(({ id }) => id === drag.sectionId)?.section.classList.remove("dragging");
|
|
3779
3994
|
sidePanelSectionPointerDrag = null;
|
|
3780
3995
|
sidePanelSectionLastDragOverKey = "";
|
|
3996
|
+
document.body.classList.remove("control-deck-section-dragging");
|
|
3781
3997
|
clearSidePanelSectionDragMarkers();
|
|
3782
3998
|
}
|
|
3783
3999
|
|
|
@@ -3799,31 +4015,84 @@ function setSidePanelSectionEditMode(enabled) {
|
|
|
3799
4015
|
for (const record of sidePanelSectionRecords()) updateSidePanelSectionEditAffordance(record);
|
|
3800
4016
|
}
|
|
3801
4017
|
|
|
3802
|
-
function moveSidePanelSectionRelative(fromId, targetRecord, insertBefore) {
|
|
4018
|
+
function moveSidePanelSectionRelative(fromId, targetRecord, insertBefore, targetSide = null) {
|
|
3803
4019
|
if (!isSidePanelSectionReorderingEnabled()) return false;
|
|
3804
4020
|
const sourceRecord = sidePanelSectionRecords().find(({ id }) => id === fromId);
|
|
3805
4021
|
if (!sourceRecord || !targetRecord || sourceRecord.section === targetRecord.section) return false;
|
|
3806
|
-
const parent =
|
|
3807
|
-
if (!parent
|
|
4022
|
+
const parent = targetRecord.section.parentElement;
|
|
4023
|
+
if (!parent) return false;
|
|
4024
|
+
const side = targetSide || (parent === elements.sidePanelBodyLeft ? "left" : "right");
|
|
3808
4025
|
clearSidePanelSectionDragMarkers();
|
|
3809
4026
|
targetRecord.section.classList.add(insertBefore ? "drag-over-before" : "drag-over-after");
|
|
3810
|
-
sidePanelSectionLastDragOverKey = `${targetRecord.id}:${insertBefore ? "before" : "after"}`;
|
|
4027
|
+
sidePanelSectionLastDragOverKey = `${side}:${targetRecord.id}:${insertBefore ? "before" : "after"}`;
|
|
3811
4028
|
if (insertBefore) parent.insertBefore(sourceRecord.section, targetRecord.section);
|
|
3812
4029
|
else parent.insertBefore(sourceRecord.section, targetRecord.section.nextSibling);
|
|
3813
|
-
|
|
4030
|
+
controlDeckLayout.sectionLayout = controlDeckLayout.sectionLayout || { order: [], leftSectionIds: [] };
|
|
4031
|
+
const order = controlDeckLayout.sectionLayout.order.filter((id) => id !== fromId);
|
|
4032
|
+
const targetIndex = order.indexOf(targetRecord.id);
|
|
4033
|
+
order.splice(Math.max(0, targetIndex + (insertBefore ? 0 : 1)), 0, fromId);
|
|
4034
|
+
controlDeckLayout.sectionLayout.order = order;
|
|
4035
|
+
if (effectiveControlDeckPresentation() === "both" && controlDeckSectionSide(fromId) !== side) {
|
|
4036
|
+
const left = new Set(controlDeckLayout.sectionLayout.leftSectionIds || []);
|
|
4037
|
+
if (side === "left") left.add(fromId); else left.delete(fromId);
|
|
4038
|
+
controlDeckLayout.sectionLayout.leftSectionIds = [...left].filter((id) => order.includes(id));
|
|
4039
|
+
}
|
|
3814
4040
|
return true;
|
|
3815
4041
|
}
|
|
3816
4042
|
|
|
4043
|
+
function completeControlDeckSectionSideMove(record, side) {
|
|
4044
|
+
if (!record) return;
|
|
4045
|
+
if (!record.section.classList.contains("collapsed")) setOnlySidePanelSectionExpanded(record);
|
|
4046
|
+
const sideRecords = sidePanelSectionRecords()
|
|
4047
|
+
.filter(({ id, section }) => !section.hidden && controlDeckSectionSide(id) === side)
|
|
4048
|
+
.sort((a, b) => controlDeckLayout.sectionLayout.order.indexOf(a.id) - controlDeckLayout.sectionLayout.order.indexOf(b.id));
|
|
4049
|
+
const ordinal = Math.max(1, sideRecords.findIndex(({ id }) => id === record.id) + 1);
|
|
4050
|
+
const label = record.button.querySelector(".side-panel-section-label")?.textContent?.trim() || record.id;
|
|
4051
|
+
if (elements.controlDeckMovementAnnouncer) elements.controlDeckMovementAnnouncer.textContent = `${label} moved to the ${side} Control Deck, position ${ordinal} of ${sideRecords.length}.`;
|
|
4052
|
+
queueMicrotask(() => record.button.focus({ preventScroll: true }));
|
|
4053
|
+
}
|
|
4054
|
+
|
|
4055
|
+
function moveSidePanelSectionToSide(sectionId, side) {
|
|
4056
|
+
if (!isSidePanelSectionReorderingEnabled() || effectiveControlDeckPresentation() !== "both") return false;
|
|
4057
|
+
if (controlDeckSectionSide(sectionId) === side) return false;
|
|
4058
|
+
const record = sidePanelSectionRecords().find(({ id }) => id === sectionId);
|
|
4059
|
+
const body = side === "left" ? elements.sidePanelBodyLeft : elements.sidePanelBodyRight;
|
|
4060
|
+
if (!record || !body) return false;
|
|
4061
|
+
const targetSection = [...body.querySelectorAll(":scope > [data-side-panel-section]")].at(-1);
|
|
4062
|
+
let moved = false;
|
|
4063
|
+
if (targetSection) {
|
|
4064
|
+
const target = sidePanelSectionRecords().find(({ section }) => section === targetSection);
|
|
4065
|
+
if (target) moved = moveSidePanelSectionRelative(sectionId, target, false, side);
|
|
4066
|
+
} else {
|
|
4067
|
+
body.append(record.section);
|
|
4068
|
+
const order = controlDeckLayout.sectionLayout.order.filter((id) => id !== sectionId);
|
|
4069
|
+
order.push(sectionId);
|
|
4070
|
+
const left = new Set(controlDeckLayout.sectionLayout.leftSectionIds || []);
|
|
4071
|
+
if (side === "left") left.add(sectionId); else left.delete(sectionId);
|
|
4072
|
+
controlDeckLayout.sectionLayout = { order, leftSectionIds: [...left] };
|
|
4073
|
+
moved = true;
|
|
4074
|
+
}
|
|
4075
|
+
if (moved && !sidePanelSectionPointerDrag?.active) completeControlDeckSectionSideMove(record, side);
|
|
4076
|
+
return moved;
|
|
4077
|
+
}
|
|
4078
|
+
|
|
3817
4079
|
function moveSidePanelSectionByOffset(sectionId, offset) {
|
|
3818
4080
|
if (!isSidePanelSectionReorderingEnabled()) return false;
|
|
3819
|
-
const
|
|
4081
|
+
const sourceSide = controlDeckSectionSide(sectionId);
|
|
4082
|
+
const rank = new Map((controlDeckLayout.sectionLayout?.order || []).map((id, index) => [id, index]));
|
|
4083
|
+
const records = visibleSidePanelSectionRecords()
|
|
4084
|
+
.filter(({ id }) => controlDeckSectionSide(id) === sourceSide)
|
|
4085
|
+
.sort((a, b) => (rank.get(a.id) ?? Number.MAX_SAFE_INTEGER) - (rank.get(b.id) ?? Number.MAX_SAFE_INTEGER));
|
|
3820
4086
|
const fromIndex = records.findIndex(({ id }) => id === sectionId);
|
|
3821
4087
|
const toIndex = fromIndex + offset;
|
|
3822
4088
|
if (fromIndex < 0 || toIndex < 0 || toIndex >= records.length) return false;
|
|
3823
4089
|
const targetRecord = records[toIndex];
|
|
3824
4090
|
const moved = moveSidePanelSectionRelative(sectionId, targetRecord, offset < 0);
|
|
3825
4091
|
clearSidePanelSectionDragMarkers();
|
|
3826
|
-
if (moved)
|
|
4092
|
+
if (moved) {
|
|
4093
|
+
persistControlDeckSectionLayout();
|
|
4094
|
+
queueMicrotask(() => sidePanelSectionRecords().find(({ id }) => id === sectionId)?.button.focus({ preventScroll: true }));
|
|
4095
|
+
}
|
|
3827
4096
|
return moved;
|
|
3828
4097
|
}
|
|
3829
4098
|
|
|
@@ -3833,7 +4102,7 @@ function sidePanelSectionToggleFromPoint(clientX, clientY) {
|
|
|
3833
4102
|
|
|
3834
4103
|
function beginSidePanelSectionPointerDrag(event, sectionId) {
|
|
3835
4104
|
if (!isSidePanelSectionReorderingEnabled() || event.button !== 0 || !sectionId || sidePanelSectionPointerDrag) return;
|
|
3836
|
-
sidePanelSectionPointerDrag = { sectionId, pointerId: event.pointerId, startX: event.clientX, startY: event.clientY, active: false };
|
|
4105
|
+
sidePanelSectionPointerDrag = { sectionId, pointerId: event.pointerId, startX: event.clientX, startY: event.clientY, startSide: controlDeckSectionSide(sectionId), active: false };
|
|
3837
4106
|
window.addEventListener("pointermove", updateSidePanelSectionPointerDrag, { capture: true });
|
|
3838
4107
|
window.addEventListener("pointerup", endSidePanelSectionPointerDrag, { capture: true });
|
|
3839
4108
|
window.addEventListener("pointercancel", endSidePanelSectionPointerDrag, { capture: true });
|
|
@@ -3848,6 +4117,7 @@ function updateSidePanelSectionPointerDrag(event) {
|
|
|
3848
4117
|
if (!drag.active) {
|
|
3849
4118
|
drag.active = true;
|
|
3850
4119
|
sidePanelSectionLastDragOverKey = "";
|
|
4120
|
+
document.body.classList.add("control-deck-section-dragging");
|
|
3851
4121
|
clearTimeout(pointerActivationTimeout);
|
|
3852
4122
|
pointerActivationTimeout = null;
|
|
3853
4123
|
activePointerActivation = null;
|
|
@@ -3858,12 +4128,16 @@ function updateSidePanelSectionPointerDrag(event) {
|
|
|
3858
4128
|
const targetRecord = targetToggle
|
|
3859
4129
|
? sidePanelSectionRecords().find(({ button }) => button === targetToggle)
|
|
3860
4130
|
: null;
|
|
3861
|
-
if (
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
4131
|
+
if (targetRecord && targetRecord.id !== drag.sectionId && !targetRecord.section.hidden) {
|
|
4132
|
+
const rect = targetToggle.getBoundingClientRect();
|
|
4133
|
+
const insertBefore = event.clientY < rect.top + rect.height / 2;
|
|
4134
|
+
const targetSide = targetRecord.section.parentElement === elements.sidePanelBodyLeft ? "left" : "right";
|
|
4135
|
+
const markerKey = `${targetSide}:${targetRecord.id}:${insertBefore ? "before" : "after"}`;
|
|
4136
|
+
if (markerKey !== sidePanelSectionLastDragOverKey) moveSidePanelSectionRelative(drag.sectionId, targetRecord, insertBefore, targetSide);
|
|
4137
|
+
return;
|
|
4138
|
+
}
|
|
4139
|
+
const dropTarget = document.elementFromPoint(event.clientX, event.clientY)?.closest?.("[data-control-deck-drop-target]");
|
|
4140
|
+
if (dropTarget) moveSidePanelSectionToSide(drag.sectionId, dropTarget.dataset.controlDeckDropTarget);
|
|
3867
4141
|
}
|
|
3868
4142
|
|
|
3869
4143
|
function endSidePanelSectionPointerDrag(event) {
|
|
@@ -3875,11 +4149,14 @@ function endSidePanelSectionPointerDrag(event) {
|
|
|
3875
4149
|
const sourceRecord = sidePanelSectionRecords().find(({ id }) => id === drag.sectionId);
|
|
3876
4150
|
sidePanelSectionPointerDrag = null;
|
|
3877
4151
|
sidePanelSectionLastDragOverKey = "";
|
|
4152
|
+
document.body.classList.remove("control-deck-section-dragging");
|
|
3878
4153
|
clearSidePanelSectionDragMarkers();
|
|
3879
4154
|
sourceRecord?.section.classList.remove("dragging");
|
|
3880
4155
|
if (drag.active) {
|
|
3881
4156
|
sidePanelSectionSuppressClickUntil = Date.now() + 250;
|
|
3882
4157
|
event.preventDefault();
|
|
4158
|
+
const destinationSide = controlDeckSectionSide(drag.sectionId);
|
|
4159
|
+
if (destinationSide !== drag.startSide) completeControlDeckSectionSideMove(sourceRecord, destinationSide);
|
|
3883
4160
|
persistSidePanelSectionOrder();
|
|
3884
4161
|
queueMicrotask(() => sourceRecord?.button.focus({ preventScroll: true }));
|
|
3885
4162
|
}
|
|
@@ -3971,7 +4248,9 @@ function setSidePanelSectionCollapsed(record, collapsed, { persist = true } = {}
|
|
|
3971
4248
|
|
|
3972
4249
|
function setOnlySidePanelSectionExpanded(targetRecord, { persist = true } = {}) {
|
|
3973
4250
|
const targetId = targetRecord?.id || null;
|
|
4251
|
+
const targetSide = controlDeckSectionSide(targetId);
|
|
3974
4252
|
for (const record of sidePanelSectionRecords()) {
|
|
4253
|
+
if (controlDeckSectionSide(record.id) !== targetSide) continue;
|
|
3975
4254
|
setSidePanelSectionCollapsed(record, record.id !== targetId, { persist: false });
|
|
3976
4255
|
}
|
|
3977
4256
|
if (persist) persistSidePanelSectionState();
|
|
@@ -3980,10 +4259,15 @@ function setOnlySidePanelSectionExpanded(targetRecord, { persist = true } = {})
|
|
|
3980
4259
|
function restoreSidePanelSectionState() {
|
|
3981
4260
|
const records = sidePanelSectionRecords();
|
|
3982
4261
|
const collapsedIds = readStoredSidePanelSectionCollapsedIds();
|
|
3983
|
-
const
|
|
3984
|
-
|
|
4262
|
+
const expandedBySide = new Map();
|
|
4263
|
+
if (collapsedIds) {
|
|
4264
|
+
for (const record of records) {
|
|
4265
|
+
const side = controlDeckSectionSide(record.id);
|
|
4266
|
+
if (!collapsedIds.has(record.id) && !expandedBySide.has(side)) expandedBySide.set(side, record.id);
|
|
4267
|
+
}
|
|
4268
|
+
}
|
|
3985
4269
|
for (const record of records) {
|
|
3986
|
-
setSidePanelSectionCollapsed(record, record.id !==
|
|
4270
|
+
setSidePanelSectionCollapsed(record, expandedBySide.get(controlDeckSectionSide(record.id)) !== record.id, { persist: false });
|
|
3987
4271
|
}
|
|
3988
4272
|
}
|
|
3989
4273
|
|
|
@@ -4053,9 +4337,16 @@ function bindSidePanelSectionToggles() {
|
|
|
4053
4337
|
}
|
|
4054
4338
|
});
|
|
4055
4339
|
record.button.addEventListener("keydown", (event) => {
|
|
4056
|
-
if (!isSidePanelSectionReorderingEnabled() || !event.altKey ||
|
|
4057
|
-
event.
|
|
4058
|
-
|
|
4340
|
+
if (!isSidePanelSectionReorderingEnabled() || !event.altKey || !["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].includes(event.key)) return;
|
|
4341
|
+
if ((event.key === "ArrowLeft" || event.key === "ArrowRight") && effectiveControlDeckPresentation() === "both") {
|
|
4342
|
+
event.preventDefault();
|
|
4343
|
+
if (moveSidePanelSectionToSide(record.id, event.key === "ArrowLeft" ? "left" : "right")) persistControlDeckSectionLayout();
|
|
4344
|
+
return;
|
|
4345
|
+
}
|
|
4346
|
+
if (event.key === "ArrowUp" || event.key === "ArrowDown") {
|
|
4347
|
+
event.preventDefault();
|
|
4348
|
+
moveSidePanelSectionByOffset(record.id, event.key === "ArrowUp" ? -1 : 1);
|
|
4349
|
+
}
|
|
4059
4350
|
});
|
|
4060
4351
|
record.button.addEventListener("pointerdown", (event) => beginSidePanelSectionPointerDrag(event, record.id));
|
|
4061
4352
|
}
|
|
@@ -4537,20 +4828,22 @@ function initializeComposerActionOrdering() {
|
|
|
4537
4828
|
}
|
|
4538
4829
|
|
|
4539
4830
|
function bindSidePanelContextMenu() {
|
|
4540
|
-
elements.
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
|
|
4831
|
+
for (const shell of [elements.sidePanelLeft, elements.sidePanel]) {
|
|
4832
|
+
shell?.addEventListener("contextmenu", showSidePanelContextMenu);
|
|
4833
|
+
shell?.addEventListener("keydown", (event) => {
|
|
4834
|
+
if (event.key !== "ContextMenu" && !(event.shiftKey && event.key === "F10")) return;
|
|
4835
|
+
const trigger = event.target instanceof Element ? event.target : shell;
|
|
4836
|
+
const rect = trigger.getBoundingClientRect();
|
|
4837
|
+
showSidePanelContextMenu({
|
|
4838
|
+
preventDefault: () => event.preventDefault(),
|
|
4839
|
+
stopPropagation: () => event.stopPropagation(),
|
|
4840
|
+
clientX: rect.left + Math.min(rect.width, 24),
|
|
4841
|
+
clientY: rect.bottom,
|
|
4842
|
+
currentTarget: trigger,
|
|
4843
|
+
target: trigger,
|
|
4844
|
+
});
|
|
4552
4845
|
});
|
|
4553
|
-
}
|
|
4846
|
+
}
|
|
4554
4847
|
}
|
|
4555
4848
|
|
|
4556
4849
|
function readStoredAgentDoneNotificationsEnabled() {
|
|
@@ -4701,6 +4994,8 @@ function setTerminalTabsLayout(layout, { persist = true, announce = false } = {}
|
|
|
4701
4994
|
if (next === "left" && mobileTabsExpanded) setMobileTabsExpanded(false);
|
|
4702
4995
|
if (persist) persistTerminalTabsLayout(next);
|
|
4703
4996
|
renderTerminalTabsLayoutControl();
|
|
4997
|
+
reconcileControlDeckHosts?.();
|
|
4998
|
+
requestAnimationFrame(syncTerminalTabsSidebarWidthForViewport);
|
|
4704
4999
|
if (announce) addEvent(`terminal tabs layout changed to ${terminalTabsLayoutStatusText(next).toLowerCase()}`);
|
|
4705
5000
|
}
|
|
4706
5001
|
|
|
@@ -4708,6 +5003,133 @@ function restoreTerminalTabsLayoutSetting() {
|
|
|
4708
5003
|
setTerminalTabsLayout(readStoredTerminalTabsLayout(), { persist: false });
|
|
4709
5004
|
}
|
|
4710
5005
|
|
|
5006
|
+
function readStoredTerminalTabsSidebarWidth() {
|
|
5007
|
+
try {
|
|
5008
|
+
const width = Number.parseFloat(localStorage.getItem(TERMINAL_TABS_SIDEBAR_WIDTH_STORAGE_KEY) || "");
|
|
5009
|
+
return Number.isFinite(width) && width >= TERMINAL_TABS_SIDEBAR_WIDTH_MIN_PX && width <= TERMINAL_TABS_SIDEBAR_WIDTH_MAX_PX ? width : null;
|
|
5010
|
+
} catch {
|
|
5011
|
+
return null;
|
|
5012
|
+
}
|
|
5013
|
+
}
|
|
5014
|
+
|
|
5015
|
+
function persistTerminalTabsSidebarWidth(width) {
|
|
5016
|
+
try {
|
|
5017
|
+
localStorage.setItem(TERMINAL_TABS_SIDEBAR_WIDTH_STORAGE_KEY, String(Math.round(width)));
|
|
5018
|
+
} catch {
|
|
5019
|
+
// Browser storage is only the immediate fallback for durable layout state.
|
|
5020
|
+
}
|
|
5021
|
+
markDurableUiLayoutDirty("terminalTabs", "sidebarWidth");
|
|
5022
|
+
}
|
|
5023
|
+
|
|
5024
|
+
function terminalTabsSidebarResizeAvailable() {
|
|
5025
|
+
if (terminalTabsLayout !== "left" || isSidePanelOverlayView() || isMobileShellV2Active()) return false;
|
|
5026
|
+
return !!elements.terminalTabsShell && getComputedStyle(elements.terminalTabsShell).display !== "none";
|
|
5027
|
+
}
|
|
5028
|
+
|
|
5029
|
+
function terminalTabsSidebarMaxWidth() {
|
|
5030
|
+
const panel = elements.terminalTabsShell?.closest?.(".chat-panel");
|
|
5031
|
+
const panelWidth = panel?.getBoundingClientRect?.().width || window.innerWidth || TERMINAL_TABS_SIDEBAR_WIDTH_MIN_PX;
|
|
5032
|
+
const transcriptMinWidth = 320;
|
|
5033
|
+
return Math.max(
|
|
5034
|
+
TERMINAL_TABS_SIDEBAR_WIDTH_MIN_PX,
|
|
5035
|
+
Math.min(TERMINAL_TABS_SIDEBAR_WIDTH_MAX_PX, Math.floor(panelWidth * 0.72), Math.floor(panelWidth - transcriptMinWidth)),
|
|
5036
|
+
);
|
|
5037
|
+
}
|
|
5038
|
+
|
|
5039
|
+
function clampTerminalTabsSidebarWidth(width) {
|
|
5040
|
+
const number = Number(width);
|
|
5041
|
+
const fallback = readStoredTerminalTabsSidebarWidth() || elements.terminalTabsShell?.getBoundingClientRect?.().width || TERMINAL_TABS_SIDEBAR_WIDTH_MIN_PX;
|
|
5042
|
+
return Math.max(TERMINAL_TABS_SIDEBAR_WIDTH_MIN_PX, Math.min(terminalTabsSidebarMaxWidth(), Number.isFinite(number) ? number : fallback));
|
|
5043
|
+
}
|
|
5044
|
+
|
|
5045
|
+
function currentTerminalTabsSidebarWidth() {
|
|
5046
|
+
const width = elements.terminalTabsShell?.getBoundingClientRect?.().width;
|
|
5047
|
+
return Number.isFinite(width) && width > 0 ? width : readStoredTerminalTabsSidebarWidth() || TERMINAL_TABS_SIDEBAR_WIDTH_MIN_PX;
|
|
5048
|
+
}
|
|
5049
|
+
|
|
5050
|
+
function updateTerminalTabsSidebarResizeHandle(width = currentTerminalTabsSidebarWidth()) {
|
|
5051
|
+
const handle = elements.terminalTabsResizeHandle;
|
|
5052
|
+
if (!handle) return;
|
|
5053
|
+
const resizeAvailable = terminalTabsSidebarResizeAvailable();
|
|
5054
|
+
handle.hidden = !resizeAvailable;
|
|
5055
|
+
handle.setAttribute("aria-valuemin", String(TERMINAL_TABS_SIDEBAR_WIDTH_MIN_PX));
|
|
5056
|
+
handle.setAttribute("aria-valuemax", String(terminalTabsSidebarMaxWidth()));
|
|
5057
|
+
handle.setAttribute("aria-valuenow", String(Math.round(width)));
|
|
5058
|
+
handle.setAttribute("aria-valuetext", `${Math.round(width)} pixels wide`);
|
|
5059
|
+
}
|
|
5060
|
+
|
|
5061
|
+
function applyTerminalTabsSidebarWidth(width, { persist = false } = {}) {
|
|
5062
|
+
const clamped = clampTerminalTabsSidebarWidth(width);
|
|
5063
|
+
document.documentElement.style.setProperty("--terminal-tabs-sidebar-width", `${Math.round(clamped)}px`);
|
|
5064
|
+
updateTerminalTabsSidebarResizeHandle(clamped);
|
|
5065
|
+
if (persist) persistTerminalTabsSidebarWidth(clamped);
|
|
5066
|
+
return clamped;
|
|
5067
|
+
}
|
|
5068
|
+
|
|
5069
|
+
function restoreTerminalTabsSidebarWidthPreference() {
|
|
5070
|
+
const width = readStoredTerminalTabsSidebarWidth();
|
|
5071
|
+
if (width) document.documentElement.style.setProperty("--terminal-tabs-sidebar-width", `${Math.round(width)}px`);
|
|
5072
|
+
if (terminalTabsSidebarResizeAvailable()) applyTerminalTabsSidebarWidth(width || currentTerminalTabsSidebarWidth());
|
|
5073
|
+
else updateTerminalTabsSidebarResizeHandle(width || currentTerminalTabsSidebarWidth());
|
|
5074
|
+
}
|
|
5075
|
+
|
|
5076
|
+
function beginTerminalTabsSidebarResize(event) {
|
|
5077
|
+
if (!terminalTabsSidebarResizeAvailable()) return;
|
|
5078
|
+
if (event.button !== undefined && event.button !== 0) return;
|
|
5079
|
+
event.preventDefault();
|
|
5080
|
+
const startWidth = currentTerminalTabsSidebarWidth();
|
|
5081
|
+
terminalTabsResizeState = { pointerId: event.pointerId, startX: event.clientX, startWidth, width: startWidth };
|
|
5082
|
+
document.body.classList.add("terminal-tabs-resizing");
|
|
5083
|
+
elements.terminalTabsResizeHandle?.setPointerCapture?.(event.pointerId);
|
|
5084
|
+
window.addEventListener("pointermove", updateTerminalTabsSidebarResize, { passive: false });
|
|
5085
|
+
window.addEventListener("pointerup", finishTerminalTabsSidebarResize, { passive: false });
|
|
5086
|
+
window.addEventListener("pointercancel", finishTerminalTabsSidebarResize, { passive: false });
|
|
5087
|
+
}
|
|
5088
|
+
|
|
5089
|
+
function updateTerminalTabsSidebarResize(event) {
|
|
5090
|
+
const state = terminalTabsResizeState;
|
|
5091
|
+
if (!state || (event.pointerId !== undefined && event.pointerId !== state.pointerId)) return;
|
|
5092
|
+
event.preventDefault();
|
|
5093
|
+
const delta = event.clientX - state.startX;
|
|
5094
|
+
state.width = applyTerminalTabsSidebarWidth(state.startWidth + (document.body.classList.contains("terminal-tabs-sidebar-start") ? delta : -delta));
|
|
5095
|
+
}
|
|
5096
|
+
|
|
5097
|
+
function finishTerminalTabsSidebarResize(event) {
|
|
5098
|
+
const state = terminalTabsResizeState;
|
|
5099
|
+
if (!state || (event.pointerId !== undefined && event.pointerId !== state.pointerId)) return;
|
|
5100
|
+
event.preventDefault?.();
|
|
5101
|
+
elements.terminalTabsResizeHandle?.releasePointerCapture?.(state.pointerId);
|
|
5102
|
+
window.removeEventListener("pointermove", updateTerminalTabsSidebarResize);
|
|
5103
|
+
window.removeEventListener("pointerup", finishTerminalTabsSidebarResize);
|
|
5104
|
+
window.removeEventListener("pointercancel", finishTerminalTabsSidebarResize);
|
|
5105
|
+
document.body.classList.remove("terminal-tabs-resizing");
|
|
5106
|
+
applyTerminalTabsSidebarWidth(state.width, { persist: true });
|
|
5107
|
+
terminalTabsResizeState = null;
|
|
5108
|
+
}
|
|
5109
|
+
|
|
5110
|
+
function handleTerminalTabsSidebarResizeKeydown(event) {
|
|
5111
|
+
if (!terminalTabsSidebarResizeAvailable()) return;
|
|
5112
|
+
const step = event.shiftKey ? 80 : 24;
|
|
5113
|
+
const current = currentTerminalTabsSidebarWidth();
|
|
5114
|
+
let next = current;
|
|
5115
|
+
const sidebarAtStart = document.body.classList.contains("terminal-tabs-sidebar-start");
|
|
5116
|
+
if (event.key === "ArrowLeft") next = current + (sidebarAtStart ? -step : step);
|
|
5117
|
+
else if (event.key === "ArrowRight") next = current + (sidebarAtStart ? step : -step);
|
|
5118
|
+
else if (event.key === "Home") next = TERMINAL_TABS_SIDEBAR_WIDTH_MIN_PX;
|
|
5119
|
+
else if (event.key === "End") next = terminalTabsSidebarMaxWidth();
|
|
5120
|
+
else return;
|
|
5121
|
+
event.preventDefault();
|
|
5122
|
+
applyTerminalTabsSidebarWidth(next, { persist: true });
|
|
5123
|
+
}
|
|
5124
|
+
|
|
5125
|
+
function syncTerminalTabsSidebarWidthForViewport() {
|
|
5126
|
+
if (!terminalTabsSidebarResizeAvailable()) {
|
|
5127
|
+
updateTerminalTabsSidebarResizeHandle();
|
|
5128
|
+
return;
|
|
5129
|
+
}
|
|
5130
|
+
applyTerminalTabsSidebarWidth(readStoredTerminalTabsSidebarWidth() || currentTerminalTabsSidebarWidth());
|
|
5131
|
+
}
|
|
5132
|
+
|
|
4711
5133
|
function normalizeSubagentOpenMode(value) {
|
|
4712
5134
|
return SUBAGENT_OPEN_MODES.has(value) ? value : "overlay";
|
|
4713
5135
|
}
|
|
@@ -5622,13 +6044,35 @@ function skillKindsLabel(entry) {
|
|
|
5622
6044
|
|
|
5623
6045
|
let sessionSkillTagLayoutFrame = 0;
|
|
5624
6046
|
let sessionSkillTagResizeObserver = null;
|
|
6047
|
+
let sessionSkillOverflowOpen = false;
|
|
6048
|
+
|
|
6049
|
+
function setSessionSkillOverflowOpen(open, { focusMenu = false, restoreFocus = false } = {}) {
|
|
6050
|
+
const container = elements.sessionSkillTags;
|
|
6051
|
+
const overflow = container?.querySelector("button.composer-skill-tag.overflow");
|
|
6052
|
+
const menu = container?.querySelector(".composer-skill-overflow-menu");
|
|
6053
|
+
if (!container || !overflow || !menu) {
|
|
6054
|
+
sessionSkillOverflowOpen = false;
|
|
6055
|
+
return;
|
|
6056
|
+
}
|
|
6057
|
+
|
|
6058
|
+
const availableItems = [...menu.querySelectorAll("button:not([hidden])")];
|
|
6059
|
+
const expanded = Boolean(open && !overflow.hidden && availableItems.length);
|
|
6060
|
+
sessionSkillOverflowOpen = expanded;
|
|
6061
|
+
container.classList.toggle("overflow-open", expanded);
|
|
6062
|
+
overflow.setAttribute("aria-expanded", expanded ? "true" : "false");
|
|
6063
|
+
menu.hidden = !expanded;
|
|
6064
|
+
|
|
6065
|
+
if (expanded && focusMenu) availableItems[0]?.focus();
|
|
6066
|
+
else if (!expanded && restoreFocus) overflow.focus();
|
|
6067
|
+
}
|
|
5625
6068
|
|
|
5626
6069
|
function fitSessionSkillTags() {
|
|
5627
6070
|
const container = elements.sessionSkillTags;
|
|
5628
6071
|
if (!container || container.hidden) return;
|
|
5629
|
-
const tags = [...container.querySelectorAll("button.composer-skill-tag")];
|
|
5630
|
-
const overflow = container.querySelector(".composer-skill-tag.overflow");
|
|
5631
|
-
|
|
6072
|
+
const tags = [...container.querySelectorAll(":scope > button.composer-skill-tag:not(.overflow)")];
|
|
6073
|
+
const overflow = container.querySelector("button.composer-skill-tag.overflow");
|
|
6074
|
+
const menuItems = [...container.querySelectorAll(".composer-skill-overflow-menu-item")];
|
|
6075
|
+
if (!tags.length || !overflow || menuItems.length !== tags.length) return;
|
|
5632
6076
|
|
|
5633
6077
|
const availableWidth = container.clientWidth;
|
|
5634
6078
|
if (availableWidth <= 0) return;
|
|
@@ -5660,11 +6104,17 @@ function fitSessionSkillTags() {
|
|
|
5660
6104
|
}
|
|
5661
6105
|
|
|
5662
6106
|
tags.forEach((tag, index) => { tag.hidden = index >= visibleCount; });
|
|
6107
|
+
menuItems.forEach((item, index) => { item.hidden = index < visibleCount; });
|
|
5663
6108
|
const hiddenCount = tags.length - visibleCount;
|
|
5664
6109
|
overflow.hidden = hiddenCount === 0;
|
|
5665
6110
|
if (hiddenCount) {
|
|
6111
|
+
const label = `Show ${hiddenCount} more tracked skill${hiddenCount === 1 ? "" : "s"}`;
|
|
5666
6112
|
overflow.textContent = `+${hiddenCount}`;
|
|
5667
|
-
overflow.title = `${
|
|
6113
|
+
overflow.title = `${label}.`;
|
|
6114
|
+
overflow.setAttribute("aria-label", label);
|
|
6115
|
+
if (sessionSkillOverflowOpen) setSessionSkillOverflowOpen(true);
|
|
6116
|
+
} else {
|
|
6117
|
+
setSessionSkillOverflowOpen(false);
|
|
5668
6118
|
}
|
|
5669
6119
|
}
|
|
5670
6120
|
|
|
@@ -5686,12 +6136,28 @@ function installSessionSkillTagResizeHandling() {
|
|
|
5686
6136
|
} else {
|
|
5687
6137
|
window.addEventListener("resize", scheduleSessionSkillTagLayout, { passive: true });
|
|
5688
6138
|
}
|
|
6139
|
+
container.addEventListener("keydown", (event) => {
|
|
6140
|
+
if (event.key !== "Escape" || !sessionSkillOverflowOpen) return;
|
|
6141
|
+
event.preventDefault();
|
|
6142
|
+
event.stopPropagation();
|
|
6143
|
+
setSessionSkillOverflowOpen(false, { restoreFocus: true });
|
|
6144
|
+
});
|
|
6145
|
+
container.addEventListener("focusout", () => {
|
|
6146
|
+
queueMicrotask(() => {
|
|
6147
|
+
if (sessionSkillOverflowOpen && !container.contains(document.activeElement)) setSessionSkillOverflowOpen(false);
|
|
6148
|
+
});
|
|
6149
|
+
});
|
|
6150
|
+
document.addEventListener("pointerdown", (event) => {
|
|
6151
|
+
if (sessionSkillOverflowOpen && !container.contains(event.target)) setSessionSkillOverflowOpen(false);
|
|
6152
|
+
});
|
|
5689
6153
|
}
|
|
5690
6154
|
|
|
5691
6155
|
function renderSessionSkillTags(tabId = activeTabId) {
|
|
5692
6156
|
const container = elements.sessionSkillTags;
|
|
5693
6157
|
if (!container) return;
|
|
5694
6158
|
const entries = sortedSkillUsageEntries(tabId).filter((entry) => entry.kinds.has("read"));
|
|
6159
|
+
sessionSkillOverflowOpen = false;
|
|
6160
|
+
container.classList.remove("overflow-open");
|
|
5695
6161
|
container.replaceChildren();
|
|
5696
6162
|
if (!entries.length) {
|
|
5697
6163
|
container.hidden = true;
|
|
@@ -5708,13 +6174,370 @@ function renderSessionSkillTags(tabId = activeTabId) {
|
|
|
5708
6174
|
tag.addEventListener("click", () => openSkillEditor(entry));
|
|
5709
6175
|
container.append(tag);
|
|
5710
6176
|
}
|
|
5711
|
-
const overflow = make("
|
|
6177
|
+
const overflow = make("button", "composer-skill-tag overflow", `+${entries.length}`);
|
|
6178
|
+
overflow.type = "button";
|
|
5712
6179
|
overflow.hidden = true;
|
|
6180
|
+
overflow.setAttribute("aria-haspopup", "dialog");
|
|
6181
|
+
overflow.setAttribute("aria-expanded", "false");
|
|
6182
|
+
overflow.setAttribute("aria-controls", "sessionSkillOverflowMenu");
|
|
6183
|
+
overflow.addEventListener("click", () => {
|
|
6184
|
+
const opening = !sessionSkillOverflowOpen;
|
|
6185
|
+
setSessionSkillOverflowOpen(opening, { focusMenu: opening });
|
|
6186
|
+
});
|
|
5713
6187
|
container.append(overflow);
|
|
6188
|
+
|
|
6189
|
+
const menu = make("div", "composer-skill-overflow-menu");
|
|
6190
|
+
menu.id = "sessionSkillOverflowMenu";
|
|
6191
|
+
menu.hidden = true;
|
|
6192
|
+
menu.setAttribute("role", "dialog");
|
|
6193
|
+
menu.setAttribute("aria-label", "More tracked skills");
|
|
6194
|
+
for (const entry of entries) {
|
|
6195
|
+
const item = make("button", "composer-skill-tag read composer-skill-overflow-menu-item", entry.name);
|
|
6196
|
+
item.type = "button";
|
|
6197
|
+
item.dataset.skillName = entry.name;
|
|
6198
|
+
item.dataset.skillPath = skillPathForEntry(entry);
|
|
6199
|
+
item.title = `Open and edit skill ${entry.name} (${skillKindsLabel(entry)}) tracked in this tab/session.`;
|
|
6200
|
+
item.setAttribute("aria-label", `Open skill ${entry.name}`);
|
|
6201
|
+
item.addEventListener("click", () => {
|
|
6202
|
+
setSessionSkillOverflowOpen(false);
|
|
6203
|
+
openSkillEditor(entry);
|
|
6204
|
+
});
|
|
6205
|
+
menu.append(item);
|
|
6206
|
+
}
|
|
6207
|
+
container.append(menu);
|
|
5714
6208
|
container.hidden = false;
|
|
5715
6209
|
scheduleSessionSkillTagLayout();
|
|
5716
6210
|
}
|
|
5717
6211
|
|
|
6212
|
+
const INTERCOM_CONVERSATION_ID_PATTERN = /^conv_[A-Za-z0-9_-]{24}$/;
|
|
6213
|
+
const INTERCOM_MESSAGE_ID_PATTERN = /^msg_[A-Za-z0-9_-]{24}$/;
|
|
6214
|
+
const INTERCOM_DETAIL_REFRESH_MS = 5_000;
|
|
6215
|
+
const intercomMessageRenderSignatures = new WeakMap();
|
|
6216
|
+
|
|
6217
|
+
function intercomBoundedString(value, maxLength = 240) {
|
|
6218
|
+
if (typeof value !== "string") return "";
|
|
6219
|
+
return value.trim().slice(0, maxLength);
|
|
6220
|
+
}
|
|
6221
|
+
|
|
6222
|
+
function normalizeIntercomParticipant(value, fallback) {
|
|
6223
|
+
const participant = value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
6224
|
+
const id = intercomBoundedString(participant.id, 240);
|
|
6225
|
+
const name = intercomBoundedString(participant.name, 160);
|
|
6226
|
+
return { id: id || null, name: name || id || fallback };
|
|
6227
|
+
}
|
|
6228
|
+
|
|
6229
|
+
function intercomParticipantLabel(participant, fallback = "Agent") {
|
|
6230
|
+
const normalized = normalizeIntercomParticipant(participant, fallback);
|
|
6231
|
+
return normalized.id && normalized.id !== normalized.name ? `${normalized.name} (${normalized.id})` : normalized.name;
|
|
6232
|
+
}
|
|
6233
|
+
|
|
6234
|
+
function normalizeIntercomConversationSummary(value) {
|
|
6235
|
+
if (!value || typeof value !== "object" || !INTERCOM_CONVERSATION_ID_PATTERN.test(String(value.id || ""))) return null;
|
|
6236
|
+
const participants = value.participants && typeof value.participants === "object" ? value.participants : {};
|
|
6237
|
+
const messageCount = Number(value.messageCount);
|
|
6238
|
+
return {
|
|
6239
|
+
id: String(value.id),
|
|
6240
|
+
participants: {
|
|
6241
|
+
local: normalizeIntercomParticipant(participants.local, "Local agent"),
|
|
6242
|
+
peer: normalizeIntercomParticipant(participants.peer, "Peer agent"),
|
|
6243
|
+
},
|
|
6244
|
+
messageCount: Number.isSafeInteger(messageCount) && messageCount >= 0 ? messageCount : 0,
|
|
6245
|
+
lastMessageAt: typeof value.lastMessageAt === "string" ? value.lastMessageAt : null,
|
|
6246
|
+
truncatedBefore: value.truncatedBefore === true,
|
|
6247
|
+
};
|
|
6248
|
+
}
|
|
6249
|
+
|
|
6250
|
+
function normalizeIntercomConversationDetail(value) {
|
|
6251
|
+
const summary = normalizeIntercomConversationSummary(value);
|
|
6252
|
+
if (!summary) return null;
|
|
6253
|
+
const messages = [];
|
|
6254
|
+
const seenMessageIds = new Set();
|
|
6255
|
+
for (const candidate of Array.isArray(value.messages) ? value.messages.slice(-200) : []) {
|
|
6256
|
+
const id = String(candidate?.id || "");
|
|
6257
|
+
if (!candidate || typeof candidate !== "object" || !INTERCOM_MESSAGE_ID_PATTERN.test(id) || seenMessageIds.has(id)
|
|
6258
|
+
|| !["local", "peer"].includes(candidate.direction) || typeof candidate.text !== "string") continue;
|
|
6259
|
+
seenMessageIds.add(id);
|
|
6260
|
+
const timestamp = typeof candidate.timestamp === "string" && Number.isFinite(Date.parse(candidate.timestamp)) ? candidate.timestamp : null;
|
|
6261
|
+
messages.push({
|
|
6262
|
+
id,
|
|
6263
|
+
direction: candidate.direction,
|
|
6264
|
+
text: candidate.text.slice(0, 65_536),
|
|
6265
|
+
timestamp,
|
|
6266
|
+
truncatedText: candidate.truncatedText === true,
|
|
6267
|
+
});
|
|
6268
|
+
}
|
|
6269
|
+
return { ...summary, messages };
|
|
6270
|
+
}
|
|
6271
|
+
|
|
6272
|
+
function intercomConversationLabel(conversation) {
|
|
6273
|
+
const local = intercomParticipantLabel(conversation?.participants?.local, "Local agent");
|
|
6274
|
+
const peer = intercomParticipantLabel(conversation?.participants?.peer, "Peer agent");
|
|
6275
|
+
return `${local} ↔ ${peer}`;
|
|
6276
|
+
}
|
|
6277
|
+
|
|
6278
|
+
function intercomConversationSummarySignature(conversations) {
|
|
6279
|
+
return JSON.stringify((conversations || []).map((conversation) => [
|
|
6280
|
+
conversation.id,
|
|
6281
|
+
intercomConversationLabel(conversation),
|
|
6282
|
+
conversation.messageCount,
|
|
6283
|
+
conversation.lastMessageAt,
|
|
6284
|
+
conversation.truncatedBefore,
|
|
6285
|
+
]));
|
|
6286
|
+
}
|
|
6287
|
+
|
|
6288
|
+
function renderIntercomConversationTags(tabId = activeTabId) {
|
|
6289
|
+
const container = elements.intercomConversationTags;
|
|
6290
|
+
if (!container) return;
|
|
6291
|
+
const conversations = intercomConversationSummariesByTab.get(tabId) || [];
|
|
6292
|
+
const existingTags = new Map([...container.querySelectorAll(".composer-intercom-tag[data-intercom-conversation-id]")]
|
|
6293
|
+
.map((tag) => [tag.dataset.intercomConversationId, tag]));
|
|
6294
|
+
const orderedTags = [];
|
|
6295
|
+
const seenConversationIds = new Set();
|
|
6296
|
+
for (const conversation of conversations) {
|
|
6297
|
+
if (seenConversationIds.has(conversation.id)) continue;
|
|
6298
|
+
seenConversationIds.add(conversation.id);
|
|
6299
|
+
const label = intercomConversationLabel(conversation);
|
|
6300
|
+
let tag = existingTags.get(conversation.id);
|
|
6301
|
+
if (tag) existingTags.delete(conversation.id);
|
|
6302
|
+
else {
|
|
6303
|
+
tag = make("button", "composer-intercom-tag");
|
|
6304
|
+
tag.type = "button";
|
|
6305
|
+
tag.dataset.intercomConversationId = conversation.id;
|
|
6306
|
+
tag.setAttribute("aria-haspopup", "dialog");
|
|
6307
|
+
tag.setAttribute("aria-controls", "intercomConversationDialog");
|
|
6308
|
+
tag.addEventListener("click", () => openIntercomConversation(tag.dataset.intercomConversationId));
|
|
6309
|
+
}
|
|
6310
|
+
tag.setAttribute("aria-label", `Open agent conversation ${label}`);
|
|
6311
|
+
tag.title = `${label} · ${conversation.messageCount} message${conversation.messageCount === 1 ? "" : "s"}`;
|
|
6312
|
+
const visualSignature = JSON.stringify([label, conversation.messageCount]);
|
|
6313
|
+
if (tag.dataset.intercomVisualSignature !== visualSignature) {
|
|
6314
|
+
const children = [make("span", "composer-intercom-tag-icon", "↔"), make("span", "composer-intercom-tag-label", label)];
|
|
6315
|
+
if (conversation.messageCount > 0) children.push(make("span", "composer-intercom-tag-count", String(conversation.messageCount)));
|
|
6316
|
+
tag.replaceChildren(...children);
|
|
6317
|
+
tag.dataset.intercomVisualSignature = visualSignature;
|
|
6318
|
+
}
|
|
6319
|
+
orderedTags.push(tag);
|
|
6320
|
+
}
|
|
6321
|
+
container.classList.toggle("dense", orderedTags.length > 8);
|
|
6322
|
+
for (const staleTag of existingTags.values()) staleTag.remove();
|
|
6323
|
+
const currentTags = [...container.querySelectorAll(":scope > .composer-intercom-tag")];
|
|
6324
|
+
if (currentTags.length !== orderedTags.length || orderedTags.some((tag, index) => currentTags[index] !== tag)) {
|
|
6325
|
+
for (const tag of orderedTags) container.append(tag);
|
|
6326
|
+
}
|
|
6327
|
+
container.hidden = orderedTags.length === 0;
|
|
6328
|
+
}
|
|
6329
|
+
|
|
6330
|
+
async function refreshIntercomConversationSummaries(tabContext = activeTabContext()) {
|
|
6331
|
+
if (!tabContext.tabId) return;
|
|
6332
|
+
const requestSerial = ++intercomSummaryRequestSerial;
|
|
6333
|
+
const response = await api("/api/intercom/conversations", { tabId: tabContext.tabId });
|
|
6334
|
+
if (requestSerial !== intercomSummaryRequestSerial || !isCurrentTabContext(tabContext)) return;
|
|
6335
|
+
const seenConversationIds = new Set();
|
|
6336
|
+
const conversations = [];
|
|
6337
|
+
for (const value of Array.isArray(response.data?.conversations) ? response.data.conversations : []) {
|
|
6338
|
+
const conversation = normalizeIntercomConversationSummary(value);
|
|
6339
|
+
if (!conversation || seenConversationIds.has(conversation.id)) continue;
|
|
6340
|
+
seenConversationIds.add(conversation.id);
|
|
6341
|
+
conversations.push(conversation);
|
|
6342
|
+
}
|
|
6343
|
+
const previous = intercomConversationSummariesByTab.get(tabContext.tabId) || [];
|
|
6344
|
+
intercomConversationSummariesByTab.set(tabContext.tabId, conversations);
|
|
6345
|
+
if (intercomConversationSummarySignature(previous) !== intercomConversationSummarySignature(conversations) && !elements.intercomConversationDialog?.open) {
|
|
6346
|
+
renderIntercomConversationTags(tabContext.tabId);
|
|
6347
|
+
}
|
|
6348
|
+
if (intercomConversationDialogState?.tabId === tabContext.tabId && !seenConversationIds.has(intercomConversationDialogState.conversationId)) {
|
|
6349
|
+
closeIntercomConversationDialog({ restoreFocus: false });
|
|
6350
|
+
}
|
|
6351
|
+
}
|
|
6352
|
+
|
|
6353
|
+
function scheduleIntercomConversationRefresh(tabContext = activeTabContext(), delayMs = 180) {
|
|
6354
|
+
clearTimeout(intercomSummaryRefreshTimer);
|
|
6355
|
+
const scheduledContext = { ...tabContext };
|
|
6356
|
+
intercomSummaryRefreshTimer = setTimeout(() => {
|
|
6357
|
+
intercomSummaryRefreshTimer = null;
|
|
6358
|
+
if (!isCurrentTabContext(scheduledContext)) return;
|
|
6359
|
+
refreshIntercomConversationSummaries(scheduledContext).catch((error) => {
|
|
6360
|
+
if (isCurrentTabContext(scheduledContext)) addEvent(`agent conversation refresh failed: ${error.message || String(error)}`, "warn");
|
|
6361
|
+
});
|
|
6362
|
+
}, delayMs);
|
|
6363
|
+
}
|
|
6364
|
+
|
|
6365
|
+
function setIntercomConversationStatus(message = "", level = "") {
|
|
6366
|
+
const status = elements.intercomConversationStatus;
|
|
6367
|
+
if (!status) return;
|
|
6368
|
+
status.textContent = message;
|
|
6369
|
+
status.classList.toggle("error", level === "error");
|
|
6370
|
+
status.classList.toggle("warn", level === "warn");
|
|
6371
|
+
}
|
|
6372
|
+
|
|
6373
|
+
function formatIntercomMessageTime(value) {
|
|
6374
|
+
const timestamp = Date.parse(value || "");
|
|
6375
|
+
if (!Number.isFinite(timestamp)) return "";
|
|
6376
|
+
return new Date(timestamp).toLocaleString([], { dateStyle: "medium", timeStyle: "short" });
|
|
6377
|
+
}
|
|
6378
|
+
|
|
6379
|
+
function renderIntercomConversationMessage(article, message, conversation) {
|
|
6380
|
+
const participant = message.direction === "local" ? conversation.participants.local : conversation.participants.peer;
|
|
6381
|
+
const senderLabel = intercomParticipantLabel(participant, message.direction === "local" ? "Local agent" : "Peer agent");
|
|
6382
|
+
const formattedTime = formatIntercomMessageTime(message.timestamp);
|
|
6383
|
+
const signature = JSON.stringify([message.direction, senderLabel, message.text, message.timestamp, message.truncatedText]);
|
|
6384
|
+
if (intercomMessageRenderSignatures.get(article) === signature) return;
|
|
6385
|
+
|
|
6386
|
+
article.className = `intercom-conversation-message ${message.direction}`;
|
|
6387
|
+
article.dataset.intercomMessageId = message.id;
|
|
6388
|
+
article.setAttribute("aria-label", `${senderLabel} message`);
|
|
6389
|
+
const header = make("header", "intercom-conversation-message-header");
|
|
6390
|
+
header.append(make("strong", "intercom-conversation-message-sender", senderLabel));
|
|
6391
|
+
if (formattedTime) {
|
|
6392
|
+
const time = make("time", "intercom-conversation-message-time", formattedTime);
|
|
6393
|
+
time.dateTime = message.timestamp;
|
|
6394
|
+
header.append(time);
|
|
6395
|
+
}
|
|
6396
|
+
const text = make("p", "intercom-conversation-message-text");
|
|
6397
|
+
text.textContent = message.text;
|
|
6398
|
+
const children = [header, text];
|
|
6399
|
+
if (message.truncatedText) children.push(make("span", "intercom-conversation-truncated", "Message truncated"));
|
|
6400
|
+
article.replaceChildren(...children);
|
|
6401
|
+
intercomMessageRenderSignatures.set(article, signature);
|
|
6402
|
+
}
|
|
6403
|
+
|
|
6404
|
+
function renderIntercomConversationDetail(conversation) {
|
|
6405
|
+
const transcript = elements.intercomConversationTranscript;
|
|
6406
|
+
if (!transcript || !conversation) return;
|
|
6407
|
+
const state = intercomConversationDialogState;
|
|
6408
|
+
const signature = JSON.stringify([
|
|
6409
|
+
conversation.id,
|
|
6410
|
+
conversation.truncatedBefore,
|
|
6411
|
+
intercomConversationLabel(conversation),
|
|
6412
|
+
conversation.messages.map((message) => [message.id, message.direction, message.text, message.timestamp, message.truncatedText]),
|
|
6413
|
+
]);
|
|
6414
|
+
if (state?.detailSignature === signature) return;
|
|
6415
|
+
if (state) state.detailSignature = signature;
|
|
6416
|
+
|
|
6417
|
+
const existingArticles = new Map([...transcript.querySelectorAll(":scope > .intercom-conversation-message[data-intercom-message-id]")]
|
|
6418
|
+
.map((article) => [article.dataset.intercomMessageId, article]));
|
|
6419
|
+
const shouldFollow = !existingArticles.size || transcript.scrollHeight - transcript.scrollTop - transcript.clientHeight < 80;
|
|
6420
|
+
const previousScrollTop = transcript.scrollTop;
|
|
6421
|
+
const anchor = shouldFollow ? null : [...existingArticles.values()]
|
|
6422
|
+
.find((article) => article.offsetTop + article.offsetHeight > transcript.scrollTop);
|
|
6423
|
+
const anchorOffset = anchor ? anchor.getBoundingClientRect().top - transcript.getBoundingClientRect().top : 0;
|
|
6424
|
+
const orderedArticles = [];
|
|
6425
|
+
|
|
6426
|
+
for (const message of conversation.messages) {
|
|
6427
|
+
let article = existingArticles.get(message.id);
|
|
6428
|
+
if (article) existingArticles.delete(message.id);
|
|
6429
|
+
else article = make("article", `intercom-conversation-message ${message.direction}`);
|
|
6430
|
+
renderIntercomConversationMessage(article, message, conversation);
|
|
6431
|
+
orderedArticles.push(article);
|
|
6432
|
+
}
|
|
6433
|
+
for (const staleArticle of existingArticles.values()) staleArticle.remove();
|
|
6434
|
+
transcript.querySelector(":scope > .intercom-conversation-empty")?.remove();
|
|
6435
|
+
|
|
6436
|
+
let cursor = transcript.firstElementChild;
|
|
6437
|
+
for (const article of orderedArticles) {
|
|
6438
|
+
if (article === cursor) cursor = cursor.nextElementSibling;
|
|
6439
|
+
else transcript.insertBefore(article, cursor);
|
|
6440
|
+
}
|
|
6441
|
+
if (!orderedArticles.length) transcript.append(make("p", "intercom-conversation-empty", "No messages are available in this conversation."));
|
|
6442
|
+
|
|
6443
|
+
requestAnimationFrame(() => {
|
|
6444
|
+
if (state !== intercomConversationDialogState) return;
|
|
6445
|
+
if (shouldFollow) transcript.scrollTop = transcript.scrollHeight;
|
|
6446
|
+
else if (anchor?.isConnected) {
|
|
6447
|
+
const currentAnchorOffset = anchor.getBoundingClientRect().top - transcript.getBoundingClientRect().top;
|
|
6448
|
+
transcript.scrollTop += currentAnchorOffset - anchorOffset;
|
|
6449
|
+
}
|
|
6450
|
+
else transcript.scrollTop = previousScrollTop;
|
|
6451
|
+
});
|
|
6452
|
+
}
|
|
6453
|
+
|
|
6454
|
+
function updateIntercomSummaryFromDetail(conversation) {
|
|
6455
|
+
const state = intercomConversationDialogState;
|
|
6456
|
+
if (!state || !conversation) return;
|
|
6457
|
+
const summaries = intercomConversationSummariesByTab.get(state.tabId) || [];
|
|
6458
|
+
const index = summaries.findIndex((summary) => summary.id === conversation.id);
|
|
6459
|
+
if (index < 0) return;
|
|
6460
|
+
const next = [...summaries];
|
|
6461
|
+
next[index] = { ...next[index], ...normalizeIntercomConversationSummary(conversation) };
|
|
6462
|
+
intercomConversationSummariesByTab.set(state.tabId, next);
|
|
6463
|
+
}
|
|
6464
|
+
|
|
6465
|
+
function scheduleIntercomConversationDetailRefresh() {
|
|
6466
|
+
clearTimeout(intercomDetailRefreshTimer);
|
|
6467
|
+
intercomDetailRefreshTimer = null;
|
|
6468
|
+
const state = intercomConversationDialogState;
|
|
6469
|
+
if (!state || !elements.intercomConversationDialog?.open) return;
|
|
6470
|
+
intercomDetailRefreshTimer = setTimeout(() => {
|
|
6471
|
+
intercomDetailRefreshTimer = null;
|
|
6472
|
+
refreshIntercomConversationDetail({ announceLoading: false });
|
|
6473
|
+
}, INTERCOM_DETAIL_REFRESH_MS);
|
|
6474
|
+
}
|
|
6475
|
+
|
|
6476
|
+
async function refreshIntercomConversationDetail({ announceLoading = false } = {}) {
|
|
6477
|
+
const state = intercomConversationDialogState;
|
|
6478
|
+
if (!state || !elements.intercomConversationDialog?.open) return;
|
|
6479
|
+
const requestSerial = ++intercomDetailRequestSerial;
|
|
6480
|
+
if (announceLoading) setIntercomConversationStatus("Loading agent messages…");
|
|
6481
|
+
try {
|
|
6482
|
+
const path = `/api/intercom/conversations?conversation=${encodeURIComponent(state.conversationId)}`;
|
|
6483
|
+
const response = await api(path, { tabId: state.tabId });
|
|
6484
|
+
if (requestSerial !== intercomDetailRequestSerial || state !== intercomConversationDialogState || !isCurrentTabContext(state)) return;
|
|
6485
|
+
const conversation = normalizeIntercomConversationDetail(response.data?.conversation);
|
|
6486
|
+
if (!conversation || conversation.id !== state.conversationId) throw new Error("Agent conversation is unavailable.");
|
|
6487
|
+
elements.intercomConversationTitle.textContent = intercomParticipantLabel(conversation.participants.peer, "Agent conversation");
|
|
6488
|
+
elements.intercomConversationParticipants.textContent = intercomConversationLabel(conversation);
|
|
6489
|
+
renderIntercomConversationDetail(conversation);
|
|
6490
|
+
updateIntercomSummaryFromDetail(conversation);
|
|
6491
|
+
const notices = [];
|
|
6492
|
+
if (conversation.truncatedBefore) notices.push("Earlier messages are unavailable.");
|
|
6493
|
+
if (conversation.messages.some((message) => message.truncatedText)) notices.push("One or more messages were truncated.");
|
|
6494
|
+
setIntercomConversationStatus(notices.join(" "), notices.length ? "warn" : "");
|
|
6495
|
+
} catch (error) {
|
|
6496
|
+
if (requestSerial === intercomDetailRequestSerial && state === intercomConversationDialogState && isCurrentTabContext(state)) {
|
|
6497
|
+
setIntercomConversationStatus(error.message || String(error), "error");
|
|
6498
|
+
}
|
|
6499
|
+
} finally {
|
|
6500
|
+
if (requestSerial === intercomDetailRequestSerial && state === intercomConversationDialogState) scheduleIntercomConversationDetailRefresh();
|
|
6501
|
+
}
|
|
6502
|
+
}
|
|
6503
|
+
|
|
6504
|
+
function openIntercomConversation(conversationId) {
|
|
6505
|
+
if (!activeTabId || !INTERCOM_CONVERSATION_ID_PATTERN.test(String(conversationId || "")) || !elements.intercomConversationDialog) return;
|
|
6506
|
+
const summary = (intercomConversationSummariesByTab.get(activeTabId) || []).find((conversation) => conversation.id === conversationId);
|
|
6507
|
+
if (!summary) return;
|
|
6508
|
+
intercomDetailRequestSerial += 1;
|
|
6509
|
+
clearTimeout(intercomDetailRefreshTimer);
|
|
6510
|
+
intercomConversationDialogState = { ...activeTabContext(), conversationId, detailSignature: "" };
|
|
6511
|
+
elements.intercomConversationTitle.textContent = intercomParticipantLabel(summary.participants.peer, "Agent conversation");
|
|
6512
|
+
elements.intercomConversationParticipants.textContent = intercomConversationLabel(summary);
|
|
6513
|
+
elements.intercomConversationTranscript.replaceChildren();
|
|
6514
|
+
setIntercomConversationStatus("Loading agent messages…");
|
|
6515
|
+
if (!elements.intercomConversationDialog.open) elements.intercomConversationDialog.showModal();
|
|
6516
|
+
queueMicrotask(() => elements.intercomConversationCloseButton?.focus({ preventScroll: true }));
|
|
6517
|
+
refreshIntercomConversationDetail({ announceLoading: false });
|
|
6518
|
+
}
|
|
6519
|
+
|
|
6520
|
+
function resetIntercomConversationDialog() {
|
|
6521
|
+
intercomDetailRequestSerial += 1;
|
|
6522
|
+
clearTimeout(intercomDetailRefreshTimer);
|
|
6523
|
+
intercomDetailRefreshTimer = null;
|
|
6524
|
+
intercomConversationDialogState = null;
|
|
6525
|
+
elements.intercomConversationTranscript?.replaceChildren();
|
|
6526
|
+
if (elements.intercomConversationParticipants) elements.intercomConversationParticipants.textContent = "";
|
|
6527
|
+
setIntercomConversationStatus("");
|
|
6528
|
+
renderIntercomConversationTags(activeTabId);
|
|
6529
|
+
}
|
|
6530
|
+
|
|
6531
|
+
function closeIntercomConversationDialog({ restoreFocus = true } = {}) {
|
|
6532
|
+
const dialog = elements.intercomConversationDialog;
|
|
6533
|
+
if (!dialog?.open) {
|
|
6534
|
+
resetIntercomConversationDialog();
|
|
6535
|
+
return;
|
|
6536
|
+
}
|
|
6537
|
+
if (!restoreFocus) modalSurfaceState.delete(dialog);
|
|
6538
|
+
dialog.close();
|
|
6539
|
+
}
|
|
6540
|
+
|
|
5718
6541
|
function normalizeFeatureCategory(value) {
|
|
5719
6542
|
return value === "lightweight-feature" || value === "complex-feature" ? value : "";
|
|
5720
6543
|
}
|
|
@@ -6699,50 +7522,82 @@ function deactivateDrawerModal(surface, { restoreFocus = true } = {}) {
|
|
|
6699
7522
|
}
|
|
6700
7523
|
|
|
6701
7524
|
function syncMobileSidePanelState(collapsed) {
|
|
6702
|
-
const
|
|
7525
|
+
const overlay = isControlDeckOverlayPresentation();
|
|
7526
|
+
const showBackdrop = !collapsed && overlay;
|
|
6703
7527
|
elements.sidePanelBackdrop.hidden = !showBackdrop;
|
|
6704
7528
|
if (showBackdrop) {
|
|
7529
|
+
mobileCanonicalUnmount();
|
|
6705
7530
|
activateDrawerModal(elements.sidePanel, elements.sidePanelExpandButton, {
|
|
6706
7531
|
close: () => setSidePanelCollapsed(true, { persist: false }),
|
|
6707
7532
|
});
|
|
6708
7533
|
} else {
|
|
6709
7534
|
deactivateDrawerModal(elements.sidePanel);
|
|
7535
|
+
if (collapsed && overlay && isMobileShellV2Active()) queueMicrotask(() => renderMobilePhoneExperience());
|
|
7536
|
+
}
|
|
7537
|
+
}
|
|
7538
|
+
|
|
7539
|
+
function syncControlDeckCollapsedClasses() {
|
|
7540
|
+
const presentation = effectiveControlDeckPresentation();
|
|
7541
|
+
const activeSide = presentation === "left" ? "left" : "right";
|
|
7542
|
+
if (presentation !== "overlay") {
|
|
7543
|
+
const singleCollapsed = presentation !== "both" && Boolean(controlDeckLayout.collapsedPanels?.[activeSide]);
|
|
7544
|
+
document.body.classList.toggle("side-panel-collapsed", singleCollapsed);
|
|
6710
7545
|
}
|
|
7546
|
+
const overlayClosed = presentation === "overlay" && document.body.classList.contains("side-panel-collapsed");
|
|
7547
|
+
const leftCollapsed = presentation !== "overlay" && Boolean(controlDeckLayout.collapsedPanels?.left);
|
|
7548
|
+
const rightCollapsed = presentation !== "overlay" && Boolean(controlDeckLayout.collapsedPanels?.right);
|
|
7549
|
+
document.body.classList.toggle("side-panel-left-collapsed", leftCollapsed);
|
|
7550
|
+
document.body.classList.toggle("side-panel-right-collapsed", rightCollapsed);
|
|
7551
|
+
elements.toggleSidePanelButton?.setAttribute("aria-expanded", rightCollapsed ? "false" : "true");
|
|
7552
|
+
elements.toggleSidePanelLeftButton?.setAttribute("aria-expanded", leftCollapsed ? "false" : "true");
|
|
7553
|
+
elements.sidePanelExpandButton?.setAttribute("aria-expanded", overlayClosed || rightCollapsed ? "false" : "true");
|
|
7554
|
+
elements.sidePanelLeftExpandButton?.setAttribute("aria-expanded", leftCollapsed ? "false" : "true");
|
|
6711
7555
|
}
|
|
6712
7556
|
|
|
6713
|
-
function setSidePanelCollapsed(collapsed, { persist = true, focusPanel = false } = {}) {
|
|
7557
|
+
function setSidePanelCollapsed(collapsed, { persist = true, focusPanel = false, side = null } = {}) {
|
|
6714
7558
|
if (collapsed) setSidePanelSectionEditMode(false);
|
|
6715
|
-
|
|
6716
|
-
|
|
6717
|
-
|
|
6718
|
-
|
|
6719
|
-
|
|
6720
|
-
|
|
6721
|
-
|
|
7559
|
+
const presentation = effectiveControlDeckPresentation();
|
|
7560
|
+
const targetSide = side || (presentation === "left" ? "left" : "right");
|
|
7561
|
+
if (presentation === "overlay") {
|
|
7562
|
+
document.body.classList.toggle("side-panel-collapsed", collapsed);
|
|
7563
|
+
} else {
|
|
7564
|
+
controlDeckLayout.collapsedPanels = { ...controlDeckLayout.collapsedPanels, [targetSide]: collapsed };
|
|
7565
|
+
document.body.classList.toggle("side-panel-collapsed", collapsed && presentation !== "both");
|
|
7566
|
+
}
|
|
7567
|
+
syncControlDeckCollapsedClasses();
|
|
7568
|
+
elements.toggleSidePanelButton?.setAttribute("title", controlDeckLayout.collapsedPanels.right ? "Expand right Control Deck" : "Collapse right Control Deck");
|
|
7569
|
+
elements.toggleSidePanelButton?.setAttribute("aria-label", controlDeckLayout.collapsedPanels.right ? "Expand right Control Deck" : "Collapse right Control Deck");
|
|
7570
|
+
elements.toggleSidePanelLeftButton?.setAttribute("title", controlDeckLayout.collapsedPanels.left ? "Expand left Control Deck" : "Collapse left Control Deck");
|
|
7571
|
+
elements.toggleSidePanelLeftButton?.setAttribute("aria-label", controlDeckLayout.collapsedPanels.left ? "Expand left Control Deck" : "Collapse left Control Deck");
|
|
7572
|
+
syncMobileSidePanelState(presentation === "overlay" ? collapsed : true);
|
|
7573
|
+
updateSidePanelResizeHandle(currentSidePanelWidth(targetSide), targetSide);
|
|
7574
|
+
reconcileControlDeckHosts();
|
|
6722
7575
|
requestAnimationFrame(syncResizablePanelWidthsForViewport);
|
|
6723
7576
|
if (collapsed) closeSidePanelContextMenu({ returnFocus: false });
|
|
6724
|
-
|
|
6725
|
-
if (!
|
|
6726
|
-
|
|
7577
|
+
if (focusPanel && !collapsed) (targetSide === "left" ? elements.toggleSidePanelLeftButton : elements.toggleSidePanelButton)?.focus?.({ preventScroll: true });
|
|
7578
|
+
if (!persist || presentation === "overlay") return;
|
|
7579
|
+
if (targetSide === "right") {
|
|
7580
|
+
try { localStorage.setItem(SIDE_PANEL_STORAGE_KEY, collapsed ? "1" : "0"); } catch { /* cache is best effort */ }
|
|
6727
7581
|
}
|
|
6728
|
-
|
|
6729
|
-
|
|
6730
|
-
try {
|
|
6731
|
-
localStorage.setItem(SIDE_PANEL_STORAGE_KEY, collapsed ? "1" : "0");
|
|
6732
|
-
} catch {
|
|
6733
|
-
// Ignore storage failures; the toggle should still work for this page load.
|
|
6734
|
-
}
|
|
6735
|
-
markDurableUiLayoutDirty("sidePanel", "collapsed");
|
|
7582
|
+
cacheControlDeckLayout(controlDeckLayout, "collapsedPanels");
|
|
7583
|
+
markDurableUiLayoutDirty("sidePanel", "collapsedPanels");
|
|
6736
7584
|
}
|
|
6737
7585
|
|
|
6738
7586
|
function restoreSidePanelState() {
|
|
6739
7587
|
if (isMobileShellV2Active()) return;
|
|
6740
|
-
if (
|
|
7588
|
+
if (isControlDeckOverlayPresentation()) {
|
|
6741
7589
|
setSidePanelCollapsed(true, { persist: false });
|
|
6742
7590
|
return;
|
|
6743
7591
|
}
|
|
6744
7592
|
const stored = readStoredSidePanelCollapsed();
|
|
6745
|
-
|
|
7593
|
+
const panels = controlDeckLayout.collapsedPanels || {};
|
|
7594
|
+
if (effectiveControlDeckPresentation() === "both") {
|
|
7595
|
+
setSidePanelCollapsed(Boolean(panels.right ?? stored ?? false), { persist: false, side: "right" });
|
|
7596
|
+
setSidePanelCollapsed(Boolean(panels.left ?? false), { persist: false, side: "left" });
|
|
7597
|
+
} else {
|
|
7598
|
+
const side = effectiveControlDeckPresentation() === "left" ? "left" : "right";
|
|
7599
|
+
setSidePanelCollapsed(Boolean(panels[side] ?? stored ?? false), { persist: false, side });
|
|
7600
|
+
}
|
|
6746
7601
|
}
|
|
6747
7602
|
|
|
6748
7603
|
function readStoredWorkspaceDashboardCollapsed() {
|
|
@@ -6943,10 +7798,16 @@ function renderServerOfflinePanel() {
|
|
|
6943
7798
|
if (elements.serverOfflineSlashCommand) elements.serverOfflineSlashCommand.textContent = serverStartSlashCommandText();
|
|
6944
7799
|
}
|
|
6945
7800
|
|
|
6946
|
-
function setServerRestartOverlay(active, message = "Waiting for the server to come back…") {
|
|
7801
|
+
function setServerRestartOverlay(active, message = "Waiting for the server to come back…", { phase = "restarting" } = {}) {
|
|
6947
7802
|
serverRestartInProgress = !!active;
|
|
7803
|
+
const updating = phase === "updating";
|
|
6948
7804
|
document.body.classList.toggle("server-restarting", serverRestartInProgress);
|
|
6949
|
-
if (elements.serverRestartPanel)
|
|
7805
|
+
if (elements.serverRestartPanel) {
|
|
7806
|
+
elements.serverRestartPanel.hidden = !serverRestartInProgress;
|
|
7807
|
+
elements.serverRestartPanel.dataset.phase = updating ? "updating" : "restarting";
|
|
7808
|
+
}
|
|
7809
|
+
if (elements.serverRestartKicker) elements.serverRestartKicker.textContent = updating ? "Updating" : "Restarting";
|
|
7810
|
+
if (elements.serverRestartTitle) elements.serverRestartTitle.textContent = updating ? "Applying exact update" : "Restarting Pi Web UI server";
|
|
6950
7811
|
if (elements.serverRestartMessage) elements.serverRestartMessage.textContent = message;
|
|
6951
7812
|
if (serverRestartInProgress) hideUpdateNotification();
|
|
6952
7813
|
if (serverRestartInProgress && elements.serverOfflinePanel) elements.serverOfflinePanel.hidden = true;
|
|
@@ -7769,7 +8630,8 @@ function componentUpdateButtonState(target) {
|
|
|
7769
8630
|
const pkg = latestUpdateStatus?.[target] || {};
|
|
7770
8631
|
if (job?.state === "running") return { disabled: true, label: "Updating…" };
|
|
7771
8632
|
if (job && job.canStart === false) return { disabled: true, label: `Update ${label}` };
|
|
7772
|
-
if (componentUpdateStartInProgress
|
|
8633
|
+
if (componentUpdateStartInProgress) return { disabled: true, label: "Starting…" };
|
|
8634
|
+
if (updateRequestInProgress || latestUpdateStatus?.updateInProgress || anyComponentUpdateRunning()) {
|
|
7773
8635
|
return { disabled: true, label: `Update ${label}` };
|
|
7774
8636
|
}
|
|
7775
8637
|
if (job?.state === "failed") return { disabled: false, label: `Retry ${label} update` };
|
|
@@ -7859,6 +8721,7 @@ async function startComponentUpdate(target) {
|
|
|
7859
8721
|
if (!confirmed) return;
|
|
7860
8722
|
componentUpdateStartInProgress = true;
|
|
7861
8723
|
renderComponentUpdateDialogs();
|
|
8724
|
+
setServerRestartOverlay(true, `Starting exact ${label} update…`, { phase: "updating" });
|
|
7862
8725
|
try {
|
|
7863
8726
|
const response = await api("/api/update/apply", { method: "POST", body: { transactionId: plan.transactionId, planDigest: plan.digest }, scoped: false });
|
|
7864
8727
|
const acceptedState = ["applying", "verifying", "activating"].includes(response?.data?.state)
|
|
@@ -7878,6 +8741,7 @@ async function startComponentUpdate(target) {
|
|
|
7878
8741
|
if (error?.statusCode === 409) await refreshUpdateStatus({ notify: false }).catch(() => {});
|
|
7879
8742
|
} finally {
|
|
7880
8743
|
componentUpdateStartInProgress = false;
|
|
8744
|
+
setServerRestartOverlay(false);
|
|
7881
8745
|
renderComponentUpdateIndicators();
|
|
7882
8746
|
renderComponentUpdateDialogs();
|
|
7883
8747
|
syncComponentUpdatePolling();
|
|
@@ -7926,20 +8790,56 @@ async function runPiUpdateAndRestart({ all = false } = {}) {
|
|
|
7926
8790
|
try {
|
|
7927
8791
|
plan = (await api("/api/update/plan", { method: "POST", body: { targets: all ? ["pi", "webui"] : ["pi"] }, scoped: false }))?.data?.plan;
|
|
7928
8792
|
} catch (error) {
|
|
7929
|
-
|
|
8793
|
+
const message = error.message || String(error);
|
|
8794
|
+
setServerActionStatus(message, "error");
|
|
8795
|
+
addEvent(message, "error");
|
|
8796
|
+
renderUpdateNotification(latestUpdateStatus, { force: true });
|
|
8797
|
+
return;
|
|
8798
|
+
}
|
|
8799
|
+
const planTargets = Array.isArray(plan?.targets) ? plan.targets : [];
|
|
8800
|
+
if (planTargets.length === 0) {
|
|
8801
|
+
const refused = Array.isArray(plan?.refusals) ? plan.refusals.map((item) => `${item.id}: ${item.guidance}`).join(" · ") : "";
|
|
8802
|
+
const message = refused ? `No update targets were accepted. ${refused}` : "No update targets were accepted; nothing was changed.";
|
|
8803
|
+
setServerActionStatus(message, "error");
|
|
8804
|
+
addEvent(message, "error");
|
|
8805
|
+
renderUpdateNotification(latestUpdateStatus, { force: true });
|
|
7930
8806
|
return;
|
|
7931
8807
|
}
|
|
7932
8808
|
if (!(await appConfirmText(piUpdateConfirmationText({ all, plan }), { affected: "Only targets accepted by the exact server-owned plan", confirmLabel: all ? "Apply exact update plan" : "Apply exact Pi plan" }))) return;
|
|
7933
8809
|
|
|
7934
8810
|
const updateLabel = all ? "Pi and Web UI exact updates" : "Pi exact update";
|
|
8811
|
+
const plannedRestart = planTargets.some((target) => target?.metadata?.managedRuntime === true);
|
|
8812
|
+
const progressMessage = plannedRestart
|
|
8813
|
+
? `Running ${updateLabel}. The server will restart after activation…`
|
|
8814
|
+
: `Running ${updateLabel}…`;
|
|
7935
8815
|
updateRequestInProgress = true;
|
|
7936
8816
|
hideUpdateNotification();
|
|
7937
8817
|
setServerActionBusy("Updating…");
|
|
7938
|
-
setServerActionStatus(
|
|
7939
|
-
setServerRestartOverlay(true,
|
|
8818
|
+
setServerActionStatus(progressMessage, "warn");
|
|
8819
|
+
setServerRestartOverlay(true, progressMessage, { phase: "updating" });
|
|
7940
8820
|
try {
|
|
7941
|
-
await api("/api/update/apply", { method: "POST", body: { transactionId: plan.transactionId, planDigest: plan.digest }, scoped: false });
|
|
7942
|
-
|
|
8821
|
+
const applyData = (await api("/api/update/apply", { method: "POST", body: { transactionId: plan.transactionId, planDigest: plan.digest }, scoped: false }))?.data || null;
|
|
8822
|
+
if (applyData?.state !== "activating") {
|
|
8823
|
+
updateRequestInProgress = false;
|
|
8824
|
+
setServerRestartOverlay(false);
|
|
8825
|
+
resetServerActionControls();
|
|
8826
|
+
const outcome = applyData?.outcome || applyData?.state || "failed";
|
|
8827
|
+
const succeeded = outcome === "success";
|
|
8828
|
+
const partial = outcome === "partial";
|
|
8829
|
+
const message = succeeded
|
|
8830
|
+
? `${updateLabel} completed without a Web UI restart.`
|
|
8831
|
+
: partial
|
|
8832
|
+
? `${updateLabel} completed partially; review the update receipts before retrying.`
|
|
8833
|
+
: `${updateLabel} did not complete; no Web UI restart was requested.`;
|
|
8834
|
+
const level = succeeded ? "success" : partial ? "warn" : "error";
|
|
8835
|
+
setServerActionStatus(message, level);
|
|
8836
|
+
addEvent(message, level === "success" ? "info" : level);
|
|
8837
|
+
if (succeeded) hideUpdateNotification({ remember: true });
|
|
8838
|
+
else renderUpdateNotification(latestUpdateStatus, { force: true });
|
|
8839
|
+
refreshUpdateStatus({ force: true, notify: false }).catch(() => {});
|
|
8840
|
+
return;
|
|
8841
|
+
}
|
|
8842
|
+
addEvent(`${updateLabel} verified; Pi Web UI server activation requested`, "warn");
|
|
7943
8843
|
} catch (error) {
|
|
7944
8844
|
if (!error?.backendOffline) {
|
|
7945
8845
|
updateRequestInProgress = false;
|
|
@@ -7951,10 +8851,10 @@ async function runPiUpdateAndRestart({ all = false } = {}) {
|
|
|
7951
8851
|
renderUpdateNotification(latestUpdateStatus, { force: true });
|
|
7952
8852
|
return;
|
|
7953
8853
|
}
|
|
7954
|
-
addEvent("Pi Web UI server connection dropped during update
|
|
8854
|
+
addEvent("Pi Web UI server connection dropped during update activation", "warn");
|
|
7955
8855
|
}
|
|
7956
8856
|
|
|
7957
|
-
setBackendOffline(true, new Error("update requested from side panel"));
|
|
8857
|
+
setBackendOffline(true, new Error("update activation requested from side panel"));
|
|
7958
8858
|
const restarted = await waitForServerRestart(serverBootIdentity);
|
|
7959
8859
|
updateRequestInProgress = false;
|
|
7960
8860
|
resetServerActionControls();
|
|
@@ -7965,8 +8865,8 @@ async function runPiUpdateAndRestart({ all = false } = {}) {
|
|
|
7965
8865
|
} else {
|
|
7966
8866
|
setServerRestartOverlay(false);
|
|
7967
8867
|
setBackendOffline(true, new Error("update restart reconnect timed out"));
|
|
7968
|
-
setServerActionStatus("Update
|
|
7969
|
-
addEvent("Pi Web UI server did not come back online after update
|
|
8868
|
+
setServerActionStatus("Update activation started, but the server did not reconnect automatically.", "error");
|
|
8869
|
+
addEvent("Pi Web UI server did not come back online after update activation", "error");
|
|
7970
8870
|
}
|
|
7971
8871
|
}
|
|
7972
8872
|
|
|
@@ -10011,6 +10911,15 @@ function applyTheme(theme, { persist = false, announce = false } = {}) {
|
|
|
10011
10911
|
"--background-glow-pink": colorWithAlpha(pink, isLight ? 0.16 : 0.34, pink),
|
|
10012
10912
|
"--background-glow-blue": colorWithAlpha(accent, isLight ? 0.15 : 0.32, accent),
|
|
10013
10913
|
"--background-glow-teal": colorWithAlpha(accent2, isLight ? 0.12 : 0.20, accent2),
|
|
10914
|
+
"--syntax-comment": themeColor(theme, "syntaxComment", muted),
|
|
10915
|
+
"--syntax-keyword": themeColor(theme, "syntaxKeyword", mauve),
|
|
10916
|
+
"--syntax-function": themeColor(theme, "syntaxFunction", accent),
|
|
10917
|
+
"--syntax-variable": themeColor(theme, "syntaxVariable", text),
|
|
10918
|
+
"--syntax-string": themeColor(theme, "syntaxString", green),
|
|
10919
|
+
"--syntax-number": themeColor(theme, "syntaxNumber", peach),
|
|
10920
|
+
"--syntax-type": themeColor(theme, "syntaxType", yellow),
|
|
10921
|
+
"--syntax-operator": themeColor(theme, "syntaxOperator", accent2),
|
|
10922
|
+
"--syntax-punctuation": themeColor(theme, "syntaxPunctuation", muted),
|
|
10014
10923
|
"--theme-background-image": themeExportCssValue(theme, "backgroundImage", "none", LOCAL_BACKGROUND_IMAGE_PATTERN),
|
|
10015
10924
|
"--theme-background-overlay": themeExportCssValue(theme, "backgroundOverlay", "linear-gradient(180deg, rgba(17, 17, 27, 0), rgba(17, 17, 27, 0))", BACKGROUND_OVERLAY_PATTERN),
|
|
10016
10925
|
"--theme-background-size": themeExportCssValue(theme, "backgroundSize", "cover", SAFE_BACKGROUND_TOKEN_PATTERN),
|
|
@@ -10746,11 +11655,17 @@ function setActiveTabId(tabId, { remember = false } = {}) {
|
|
|
10746
11655
|
const nextTabId = tabId || null;
|
|
10747
11656
|
if (nextTabId !== activeTabId) {
|
|
10748
11657
|
activeTabGeneration += 1;
|
|
11658
|
+
intercomSummaryRequestSerial += 1;
|
|
11659
|
+
clearTimeout(intercomSummaryRefreshTimer);
|
|
11660
|
+
intercomSummaryRefreshTimer = null;
|
|
11661
|
+
closeIntercomConversationDialog({ restoreFocus: false });
|
|
10749
11662
|
closeFeatureDecisionDialog({ restoreFocus: false });
|
|
10750
11663
|
closeSessionSummaryOverlay({ restoreFocus: false });
|
|
10751
11664
|
}
|
|
10752
11665
|
activeTabId = nextTabId;
|
|
11666
|
+
renderMainOutputLoading();
|
|
10753
11667
|
bindGitWorkflowToActiveTab();
|
|
11668
|
+
renderIntercomConversationTags(nextTabId);
|
|
10754
11669
|
renderFeatureCategoryTag(nextTabId);
|
|
10755
11670
|
renderSessionSummaryControls();
|
|
10756
11671
|
if (remember) rememberActiveTab();
|
|
@@ -10806,6 +11721,14 @@ function fileTreeGitStatusForEntry(entry = {}) {
|
|
|
10806
11721
|
return fileTreeState.gitStatusByPath.get(normalizeFileTreePath(entry.path || "")) || null;
|
|
10807
11722
|
}
|
|
10808
11723
|
|
|
11724
|
+
function fileTreeEntryGitIgnored(entry = {}) {
|
|
11725
|
+
return entry?.gitIgnored === true;
|
|
11726
|
+
}
|
|
11727
|
+
|
|
11728
|
+
function fileTreeGitIgnoredTitle(gitIgnored = false) {
|
|
11729
|
+
return gitIgnored ? "Ignored by Git" : "";
|
|
11730
|
+
}
|
|
11731
|
+
|
|
10809
11732
|
function fileTreeGitStatusClasses(status) {
|
|
10810
11733
|
const normalized = normalizeFileTreeGitStatus(status);
|
|
10811
11734
|
if (!normalized) return "";
|
|
@@ -10926,6 +11849,7 @@ function fileTreeEntryRenderSignature(entry = {}) {
|
|
|
10926
11849
|
entry.directory === true,
|
|
10927
11850
|
String(entry.extension || ""),
|
|
10928
11851
|
String(entry.error || ""),
|
|
11852
|
+
fileTreeEntryGitIgnored(entry),
|
|
10929
11853
|
];
|
|
10930
11854
|
}
|
|
10931
11855
|
|
|
@@ -11044,7 +11968,8 @@ function appendFileSearchEntry(parent, entry) {
|
|
|
11044
11968
|
const loading = isDirectory && fileTreeState.loading.has(path);
|
|
11045
11969
|
const gitStatus = fileTreeGitStatusForEntry(entry);
|
|
11046
11970
|
const gitStatusClasses = fileTreeGitStatusClasses(gitStatus);
|
|
11047
|
-
const
|
|
11971
|
+
const gitIgnored = fileTreeEntryGitIgnored(entry);
|
|
11972
|
+
const item = make("li", `file-tree-node file-tree-search-node ${entry.type || "file"}${gitStatusClasses ? ` ${gitStatusClasses}` : ""}${gitIgnored ? " git-ignored" : ""}${expanded ? " expanded" : ""}${fileTreeState.selectedPath === path ? " selected" : ""}`);
|
|
11048
11973
|
item.setAttribute("role", "none");
|
|
11049
11974
|
const button = make("button", "file-tree-item file-tree-search-item");
|
|
11050
11975
|
button.type = "button";
|
|
@@ -11057,7 +11982,7 @@ function appendFileSearchEntry(parent, entry) {
|
|
|
11057
11982
|
button.setAttribute("aria-expanded", expanded ? "true" : "false");
|
|
11058
11983
|
button.setAttribute("aria-label", `${expanded ? "Collapse" : "Expand"} ${entry.name || fileDisplayName(path)}`);
|
|
11059
11984
|
}
|
|
11060
|
-
button.title = [path || ".", fileTreeGitStatusTitle(gitStatus), entry.error || ""].filter(Boolean).join("\n");
|
|
11985
|
+
button.title = [path || ".", fileTreeGitIgnoredTitle(gitIgnored), fileTreeGitStatusTitle(gitStatus), entry.error || ""].filter(Boolean).join("\n");
|
|
11061
11986
|
const contextPath = fileParentPath(path) || ".";
|
|
11062
11987
|
const label = make("span", "file-tree-search-label");
|
|
11063
11988
|
label.append(
|
|
@@ -11123,7 +12048,8 @@ function appendFileTreeEntry(parent, entry, depth = 0) {
|
|
|
11123
12048
|
const loading = isDirectory && fileTreeState.loading.has(path);
|
|
11124
12049
|
const gitStatus = fileTreeGitStatusForEntry(entry);
|
|
11125
12050
|
const gitStatusClasses = fileTreeGitStatusClasses(gitStatus);
|
|
11126
|
-
const
|
|
12051
|
+
const gitIgnored = fileTreeEntryGitIgnored(entry);
|
|
12052
|
+
const item = make("li", `file-tree-node ${entry.type || "file"}${gitStatusClasses ? ` ${gitStatusClasses}` : ""}${gitIgnored ? " git-ignored" : ""}${expanded ? " expanded" : ""}${fileTreeState.selectedPath === path ? " selected" : ""}`);
|
|
11127
12053
|
item.setAttribute("role", "none");
|
|
11128
12054
|
const button = make("button", "file-tree-item");
|
|
11129
12055
|
button.type = "button";
|
|
@@ -11136,7 +12062,7 @@ function appendFileTreeEntry(parent, entry, depth = 0) {
|
|
|
11136
12062
|
button.setAttribute("aria-expanded", expanded ? "true" : "false");
|
|
11137
12063
|
button.setAttribute("aria-label", `${expanded ? "Collapse" : "Expand"} ${entry.name || fileDisplayName(path)}`);
|
|
11138
12064
|
}
|
|
11139
|
-
button.title = [path || ".", fileTreeGitStatusTitle(gitStatus), entry.error || ""].filter(Boolean).join("\n");
|
|
12065
|
+
button.title = [path || ".", fileTreeGitIgnoredTitle(gitIgnored), fileTreeGitStatusTitle(gitStatus), entry.error || ""].filter(Boolean).join("\n");
|
|
11140
12066
|
button.append(
|
|
11141
12067
|
isDirectory ? fileTreeExpander(expanded) : make("span", "file-tree-expander-spacer"),
|
|
11142
12068
|
make("span", `file-tree-icon ${isDirectory && expanded ? "expanded" : ""}`, loading ? "…" : fileEntryIcon(entry)),
|
|
@@ -11878,16 +12804,17 @@ async function moveFileTreeEntry(entry = fileContextMenuState?.entry) {
|
|
|
11878
12804
|
// per-user layout lives in the WebUI settings file behind
|
|
11879
12805
|
// GET/PUT /api/interface-preferences. Local writes always apply first; server
|
|
11880
12806
|
// reconciliation is non-blocking, coalesced, and revision guarded.
|
|
11881
|
-
const UI_LAYOUT_SCHEMA_VERSION =
|
|
12807
|
+
const UI_LAYOUT_SCHEMA_VERSION = 2;
|
|
11882
12808
|
const UI_LAYOUT_ENDPOINT = "/api/interface-preferences";
|
|
11883
12809
|
const UI_LAYOUT_SAVE_DEBOUNCE_MS = 250;
|
|
11884
12810
|
const UI_LAYOUT_MAX_CONFLICT_RETRIES = 1;
|
|
11885
12811
|
const UI_LAYOUT_FIELDS = ["sidePanel", "composerActions", "footerScopedModelOrder", "terminalTabs", "fileViewerWidth"];
|
|
11886
|
-
const UI_LAYOUT_SIDE_PANEL_FIELDS = ["
|
|
12812
|
+
const UI_LAYOUT_SIDE_PANEL_FIELDS = ["placement", "sectionLayout", "collapsedSectionIds", "hiddenSectionIds", "collapsedPanels", "panelWidths"];
|
|
11887
12813
|
const REMOVED_SIDE_PANEL_SECTION_HEIGHT_STORAGE_KEY = "pi-webui-side-panel-section-heights-v1";
|
|
11888
12814
|
const UI_LAYOUT_COMPOSER_FIELDS = ["order", "grid"];
|
|
11889
|
-
const UI_LAYOUT_TERMINAL_FIELDS = ["layout", "customGroups"];
|
|
11890
|
-
const UI_LAYOUT_PENDING_STORAGE_PREFIX = "pi-webui-ui-layout-pending-
|
|
12815
|
+
const UI_LAYOUT_TERMINAL_FIELDS = ["layout", "customGroups", "sidebarWidth"];
|
|
12816
|
+
const UI_LAYOUT_PENDING_STORAGE_PREFIX = "pi-webui-ui-layout-pending-v4:";
|
|
12817
|
+
const UI_LAYOUT_LEGACY_PENDING_STORAGE_PREFIX = "pi-webui-ui-layout-pending-v3:";
|
|
11891
12818
|
const UI_LAYOUT_PENDING_WRITER_ID = globalThis.crypto?.randomUUID?.() || `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
11892
12819
|
let durableLayoutPendingMutationSerial = 0;
|
|
11893
12820
|
const UI_LAYOUT_ID_MAX_LENGTH = 256;
|
|
@@ -11952,13 +12879,79 @@ function durableLayoutStoredIdList(key) {
|
|
|
11952
12879
|
}
|
|
11953
12880
|
}
|
|
11954
12881
|
|
|
11955
|
-
function
|
|
12882
|
+
function normalizeControlDeckPlacement(value) {
|
|
12883
|
+
return ["right", "left", "both"].includes(value) ? value : CONTROL_DECK_DEFAULT_PLACEMENT;
|
|
12884
|
+
}
|
|
12885
|
+
|
|
12886
|
+
function defaultControlDeckLayout() {
|
|
12887
|
+
return {
|
|
12888
|
+
placement: CONTROL_DECK_DEFAULT_PLACEMENT,
|
|
12889
|
+
sectionLayout: { order: null, leftSectionIds: [] },
|
|
12890
|
+
collapsedSectionIds: null,
|
|
12891
|
+
hiddenSectionIds: null,
|
|
12892
|
+
collapsedPanels: { left: false, right: false },
|
|
12893
|
+
panelWidths: { left: SIDE_PANEL_WIDTH_DEFAULT_PX, right: SIDE_PANEL_WIDTH_DEFAULT_PX },
|
|
12894
|
+
};
|
|
12895
|
+
}
|
|
12896
|
+
|
|
12897
|
+
function readStoredControlDeckLayout() {
|
|
12898
|
+
const fallback = defaultControlDeckLayout();
|
|
12899
|
+
try {
|
|
12900
|
+
const raw = localStorage.getItem(CONTROL_DECK_LAYOUT_STORAGE_KEY);
|
|
12901
|
+
if (raw) {
|
|
12902
|
+
const parsed = JSON.parse(raw);
|
|
12903
|
+
return {
|
|
12904
|
+
...fallback,
|
|
12905
|
+
...parsed,
|
|
12906
|
+
placement: normalizeControlDeckPlacement(parsed?.placement),
|
|
12907
|
+
sectionLayout: parsed?.sectionLayout || fallback.sectionLayout,
|
|
12908
|
+
collapsedPanels: { ...fallback.collapsedPanels, ...(parsed?.collapsedPanels || {}) },
|
|
12909
|
+
panelWidths: { ...fallback.panelWidths, ...(parsed?.panelWidths || {}) },
|
|
12910
|
+
};
|
|
12911
|
+
}
|
|
12912
|
+
} catch { /* fall through to legacy cache */ }
|
|
12913
|
+
const order = durableLayoutStoredIdList(SIDE_PANEL_SECTION_ORDER_STORAGE_KEY);
|
|
11956
12914
|
const collapsed = readStoredSidePanelCollapsed();
|
|
12915
|
+
const width = readStoredSidePanelWidth();
|
|
12916
|
+
const migrated = { ...fallback, sectionLayout: { order, leftSectionIds: [] } };
|
|
12917
|
+
if (typeof collapsed === "boolean") migrated.collapsedPanels.right = collapsed;
|
|
12918
|
+
if (width) migrated.panelWidths.right = width;
|
|
12919
|
+
return migrated;
|
|
12920
|
+
}
|
|
12921
|
+
|
|
12922
|
+
let controlDeckLayout = readStoredControlDeckLayout();
|
|
12923
|
+
|
|
12924
|
+
function normalizedControlDeckLayout(next = {}) {
|
|
12925
|
+
return {
|
|
12926
|
+
...defaultControlDeckLayout(),
|
|
12927
|
+
...next,
|
|
12928
|
+
placement: normalizeControlDeckPlacement(next?.placement),
|
|
12929
|
+
sectionLayout: next?.sectionLayout || { order: null, leftSectionIds: [] },
|
|
12930
|
+
collapsedPanels: { left: false, right: false, ...(next?.collapsedPanels || {}) },
|
|
12931
|
+
panelWidths: { left: SIDE_PANEL_WIDTH_DEFAULT_PX, right: SIDE_PANEL_WIDTH_DEFAULT_PX, ...(next?.panelWidths || {}) },
|
|
12932
|
+
};
|
|
12933
|
+
}
|
|
12934
|
+
|
|
12935
|
+
function cacheControlDeckLayout(next = controlDeckLayout, subfield = null) {
|
|
12936
|
+
const incoming = normalizedControlDeckLayout(next);
|
|
12937
|
+
const current = readStoredControlDeckLayout();
|
|
12938
|
+
const cached = subfield ? normalizedControlDeckLayout({ ...current, [subfield]: incoming[subfield] }) : incoming;
|
|
12939
|
+
writeDurableLayoutCache(CONTROL_DECK_LAYOUT_STORAGE_KEY, JSON.stringify(cached));
|
|
12940
|
+
controlDeckLayout = subfield ? normalizedControlDeckLayout({ ...incoming, [subfield]: cached[subfield] }) : cached;
|
|
12941
|
+
return controlDeckLayout;
|
|
12942
|
+
}
|
|
12943
|
+
|
|
12944
|
+
function collectDurableSidePanelLayout() {
|
|
12945
|
+
const records = typeof controlDeckSectionRecords === "function" ? controlDeckSectionRecords() : [];
|
|
12946
|
+
const order = controlDeckLayout.sectionLayout?.order || records.map(({ id }) => id);
|
|
12947
|
+
const left = controlDeckLayout.sectionLayout?.leftSectionIds || [];
|
|
11957
12948
|
return {
|
|
11958
|
-
|
|
12949
|
+
placement: normalizeControlDeckPlacement(controlDeckLayout.placement),
|
|
12950
|
+
sectionLayout: { order, leftSectionIds: left.filter((id) => order.includes(id)) },
|
|
11959
12951
|
collapsedSectionIds: durableLayoutStoredIdList(SIDE_PANEL_SECTION_STORAGE_KEY),
|
|
11960
12952
|
hiddenSectionIds: durableLayoutStoredIdList(SIDE_PANEL_SECTION_VISIBILITY_STORAGE_KEY),
|
|
11961
|
-
|
|
12953
|
+
collapsedPanels: controlDeckLayout.collapsedPanels,
|
|
12954
|
+
panelWidths: controlDeckLayout.panelWidths,
|
|
11962
12955
|
};
|
|
11963
12956
|
}
|
|
11964
12957
|
|
|
@@ -12015,7 +13008,11 @@ function collectDurableTerminalTabsLayout() {
|
|
|
12015
13008
|
}
|
|
12016
13009
|
customGroups = { version: 1, groups };
|
|
12017
13010
|
}
|
|
12018
|
-
return {
|
|
13011
|
+
return {
|
|
13012
|
+
layout: TERMINAL_TABS_LAYOUTS.has(rawLayout) ? rawLayout : null,
|
|
13013
|
+
customGroups,
|
|
13014
|
+
sidebarWidth: readStoredTerminalTabsSidebarWidth(),
|
|
13015
|
+
};
|
|
12019
13016
|
}
|
|
12020
13017
|
|
|
12021
13018
|
function collectDurableFileViewerWidth() {
|
|
@@ -12053,6 +13050,14 @@ function durableUiLayoutValuePresent(value) {
|
|
|
12053
13050
|
return value !== null && value !== undefined;
|
|
12054
13051
|
}
|
|
12055
13052
|
|
|
13053
|
+
function durableUiLayoutSubfieldValuePresent(field, subfield, value) {
|
|
13054
|
+
if (!durableUiLayoutValuePresent(value)) return false;
|
|
13055
|
+
if (field === "sidePanel" && subfield === "sectionLayout") return Array.isArray(value?.order) && Array.isArray(value?.leftSectionIds);
|
|
13056
|
+
if (field === "sidePanel" && subfield === "collapsedPanels") return typeof value?.left === "boolean" || typeof value?.right === "boolean";
|
|
13057
|
+
if (field === "sidePanel" && subfield === "panelWidths") return Number.isFinite(value?.left) || Number.isFinite(value?.right);
|
|
13058
|
+
return true;
|
|
13059
|
+
}
|
|
13060
|
+
|
|
12056
13061
|
function durableUiLayoutMutationValue(field, subfield = null) {
|
|
12057
13062
|
const value = collectDurableUiLayoutField(field);
|
|
12058
13063
|
return subfield ? value?.[subfield] ?? null : value;
|
|
@@ -12068,23 +13073,38 @@ function durableUiLayoutPendingMutationRecords() {
|
|
|
12068
13073
|
try {
|
|
12069
13074
|
for (let index = 0; index < localStorage.length; index += 1) {
|
|
12070
13075
|
const key = localStorage.key(index);
|
|
12071
|
-
if (!key?.startsWith(UI_LAYOUT_PENDING_STORAGE_PREFIX)) continue;
|
|
13076
|
+
if (!key?.startsWith(UI_LAYOUT_PENDING_STORAGE_PREFIX) && !key?.startsWith(UI_LAYOUT_LEGACY_PENDING_STORAGE_PREFIX)) continue;
|
|
12072
13077
|
let value;
|
|
12073
13078
|
try {
|
|
12074
13079
|
value = JSON.parse(localStorage.getItem(key) || "null");
|
|
12075
13080
|
} catch {
|
|
12076
13081
|
continue;
|
|
12077
13082
|
}
|
|
12078
|
-
if (!value || value.version
|
|
13083
|
+
if (!value || ![3, 4].includes(value.version) || !UI_LAYOUT_FIELDS.includes(value.field)) continue;
|
|
12079
13084
|
const allowedSubfields = durableUiLayoutSubFields(value.field);
|
|
12080
|
-
|
|
13085
|
+
let subfield = typeof value.subfield === "string" ? value.subfield : null;
|
|
13086
|
+
let mutationValue = value.value;
|
|
13087
|
+
// v3 journals written before schema v2 used the four legacy side-panel
|
|
13088
|
+
// identities below. Translate at read time and retain the old immutable
|
|
13089
|
+
// key until the corresponding v2 mutation is acknowledged.
|
|
13090
|
+
if (value.field === "sidePanel" && subfield === "sectionOrder") {
|
|
13091
|
+
subfield = "sectionLayout";
|
|
13092
|
+
mutationValue = { order: durableLayoutIdList(value.value), leftSectionIds: [] };
|
|
13093
|
+
} else if (value.field === "sidePanel" && subfield === "collapsedSectionIds") {
|
|
13094
|
+
mutationValue = durableLayoutIdList(value.value);
|
|
13095
|
+
} else if (value.field === "sidePanel" && subfield === "hiddenSectionIds") {
|
|
13096
|
+
mutationValue = durableLayoutIdList(value.value);
|
|
13097
|
+
} else if (value.field === "sidePanel" && subfield === "collapsed") {
|
|
13098
|
+
subfield = "collapsedPanels";
|
|
13099
|
+
mutationValue = { right: typeof value.value === "boolean" ? value.value : null };
|
|
13100
|
+
}
|
|
12081
13101
|
if (subfield && !allowedSubfields?.includes(subfield)) continue;
|
|
12082
13102
|
if (allowedSubfields && value.field !== "composerActions" && !subfield) continue;
|
|
12083
13103
|
records.push({
|
|
12084
13104
|
key,
|
|
12085
13105
|
field: value.field,
|
|
12086
13106
|
subfield,
|
|
12087
|
-
value:
|
|
13107
|
+
value: mutationValue,
|
|
12088
13108
|
updatedAt: Number(value.updatedAt) || 0,
|
|
12089
13109
|
});
|
|
12090
13110
|
}
|
|
@@ -12099,7 +13119,7 @@ function writeDurableUiLayoutPendingMutation(field, subfield, value) {
|
|
|
12099
13119
|
durableLayoutPendingMutationSerial += 1;
|
|
12100
13120
|
const key = `${UI_LAYOUT_PENDING_STORAGE_PREFIX}${UI_LAYOUT_PENDING_WRITER_ID}:${Date.now().toString(36)}:${durableLayoutPendingMutationSerial.toString(36)}`;
|
|
12101
13121
|
localStorage.setItem(key, JSON.stringify({
|
|
12102
|
-
version:
|
|
13122
|
+
version: 4,
|
|
12103
13123
|
field,
|
|
12104
13124
|
subfield,
|
|
12105
13125
|
value,
|
|
@@ -12181,9 +13201,13 @@ function restoreDurableUiLayoutPendingJournal() {
|
|
|
12181
13201
|
? new Map(fieldCandidates.map((candidate) => [candidate.subfield, candidate.key]))
|
|
12182
13202
|
: null;
|
|
12183
13203
|
durableLayoutGenerations.set(field, generation);
|
|
13204
|
+
const restoredValue = collectDurableUiLayoutField(field);
|
|
13205
|
+
if (subfields) {
|
|
13206
|
+
for (const candidate of fieldCandidates) restoredValue[candidate.subfield] = candidate.value;
|
|
13207
|
+
}
|
|
12184
13208
|
durableLayoutDirtyFields.set(field, {
|
|
12185
13209
|
generation,
|
|
12186
|
-
value:
|
|
13210
|
+
value: restoredValue,
|
|
12187
13211
|
subfields,
|
|
12188
13212
|
subfieldGenerations,
|
|
12189
13213
|
subfieldMutationIds,
|
|
@@ -12195,9 +13219,15 @@ function restoreDurableUiLayoutPendingJournal() {
|
|
|
12195
13219
|
|
|
12196
13220
|
function applyDurableSidePanelLayout(value) {
|
|
12197
13221
|
if (!value) return;
|
|
12198
|
-
|
|
12199
|
-
|
|
12200
|
-
|
|
13222
|
+
const adoptedSubfields = [];
|
|
13223
|
+
if (value.placement) {
|
|
13224
|
+
controlDeckLayout.placement = normalizeControlDeckPlacement(value.placement);
|
|
13225
|
+
adoptedSubfields.push("placement");
|
|
13226
|
+
}
|
|
13227
|
+
if (value.sectionLayout) {
|
|
13228
|
+
controlDeckLayout.sectionLayout = value.sectionLayout;
|
|
13229
|
+
if (Array.isArray(value.sectionLayout.order)) writeDurableLayoutCache(SIDE_PANEL_SECTION_ORDER_STORAGE_KEY, JSON.stringify(value.sectionLayout.order));
|
|
13230
|
+
adoptedSubfields.push("sectionLayout");
|
|
12201
13231
|
}
|
|
12202
13232
|
if (Array.isArray(value.hiddenSectionIds)) {
|
|
12203
13233
|
writeDurableLayoutCache(SIDE_PANEL_SECTION_VISIBILITY_STORAGE_KEY, JSON.stringify(value.hiddenSectionIds));
|
|
@@ -12207,10 +13237,18 @@ function applyDurableSidePanelLayout(value) {
|
|
|
12207
13237
|
writeDurableLayoutCache(SIDE_PANEL_SECTION_STORAGE_KEY, JSON.stringify(value.collapsedSectionIds));
|
|
12208
13238
|
restoreSidePanelSectionState();
|
|
12209
13239
|
}
|
|
12210
|
-
if (typeof value.
|
|
12211
|
-
|
|
12212
|
-
|
|
13240
|
+
if (value.collapsedPanels && typeof value.collapsedPanels === "object") {
|
|
13241
|
+
controlDeckLayout.collapsedPanels = { ...controlDeckLayout.collapsedPanels, ...value.collapsedPanels };
|
|
13242
|
+
adoptedSubfields.push("collapsedPanels");
|
|
13243
|
+
}
|
|
13244
|
+
if (value.panelWidths && typeof value.panelWidths === "object") {
|
|
13245
|
+
controlDeckLayout.panelWidths = { ...controlDeckLayout.panelWidths, ...value.panelWidths };
|
|
13246
|
+
adoptedSubfields.push("panelWidths");
|
|
12213
13247
|
}
|
|
13248
|
+
for (const subfield of adoptedSubfields) cacheControlDeckLayout(controlDeckLayout, subfield);
|
|
13249
|
+
restoreSidePanelSectionOrder();
|
|
13250
|
+
reconcileControlDeckHosts();
|
|
13251
|
+
restoreSidePanelState();
|
|
12214
13252
|
}
|
|
12215
13253
|
|
|
12216
13254
|
function applyDurableComposerActionsLayout(value) {
|
|
@@ -12241,6 +13279,10 @@ function applyDurableTerminalTabsLayout(value) {
|
|
|
12241
13279
|
writeDurableLayoutCache(TERMINAL_TABS_LAYOUT_STORAGE_KEY, value.layout);
|
|
12242
13280
|
setTerminalTabsLayout(value.layout, { persist: false });
|
|
12243
13281
|
}
|
|
13282
|
+
if (Number.isFinite(value.sidebarWidth) && value.sidebarWidth >= TERMINAL_TABS_SIDEBAR_WIDTH_MIN_PX) {
|
|
13283
|
+
writeDurableLayoutCache(TERMINAL_TABS_SIDEBAR_WIDTH_STORAGE_KEY, String(Math.round(value.sidebarWidth)));
|
|
13284
|
+
restoreTerminalTabsSidebarWidthPreference();
|
|
13285
|
+
}
|
|
12244
13286
|
if (value.customGroups && value.customGroups.version === 1) {
|
|
12245
13287
|
writeDurableLayoutCache(TERMINAL_CUSTOM_GROUPS_STORAGE_KEY, JSON.stringify(value.customGroups));
|
|
12246
13288
|
restoreTerminalCustomGroups();
|
|
@@ -12268,10 +13310,10 @@ function applyDurableUiLayoutField(field, value) {
|
|
|
12268
13310
|
|
|
12269
13311
|
function durableUiLayoutInteractionActive(field = null) {
|
|
12270
13312
|
const activeByField = {
|
|
12271
|
-
sidePanel: Boolean(sidePanelSectionPointerDrag?.active),
|
|
13313
|
+
sidePanel: Boolean(sidePanelSectionPointerDrag?.active || sidePanelResizeState),
|
|
12272
13314
|
composerActions: Boolean(composerActionPointerDrag?.active),
|
|
12273
13315
|
footerScopedModelOrder: Boolean(footerScopedModelPointerDrag?.active),
|
|
12274
|
-
terminalTabs: Boolean(terminalTabDragId),
|
|
13316
|
+
terminalTabs: Boolean(terminalTabDragId || terminalTabsResizeState),
|
|
12275
13317
|
fileViewerWidth: Boolean(fileViewerResizeState),
|
|
12276
13318
|
};
|
|
12277
13319
|
return field ? activeByField[field] === true : Object.values(activeByField).some(Boolean);
|
|
@@ -12356,20 +13398,23 @@ function applyDurableUiLayoutSnapshot(data, { generations = null, readEpoch = 0
|
|
|
12356
13398
|
const subfields = durableUiLayoutSubFields(field);
|
|
12357
13399
|
const dirtySubfields = dirtyEntry?.subfields;
|
|
12358
13400
|
|
|
12359
|
-
|
|
12360
|
-
|
|
12361
|
-
if (subfields && field !== "composerActions") {
|
|
13401
|
+
if (subfields && field !== "composerActions") {
|
|
12362
13402
|
const applicable = {};
|
|
12363
13403
|
let hasApplicable = false;
|
|
12364
13404
|
for (const subfield of subfields) {
|
|
12365
13405
|
const isDirty = dirtySubfields?.has(subfield) === true;
|
|
13406
|
+
const activelyManipulated = field === "sidePanel" && (
|
|
13407
|
+
(subfield === "sectionLayout" && Boolean(sidePanelSectionPointerDrag?.active))
|
|
13408
|
+
|| (subfield === "panelWidths" && Boolean(sidePanelResizeState))
|
|
13409
|
+
);
|
|
12366
13410
|
const remote = serverValue?.[subfield] ?? null;
|
|
12367
13411
|
const local = localValue?.[subfield] ?? null;
|
|
12368
|
-
|
|
13412
|
+
const remotePresent = durableUiLayoutSubfieldValuePresent(field, subfield, remote);
|
|
13413
|
+
if (!isDirty && !activelyManipulated && !generationChanged && remotePresent) {
|
|
12369
13414
|
applicable[subfield] = remote;
|
|
12370
13415
|
hasApplicable = true;
|
|
12371
13416
|
}
|
|
12372
|
-
if (!isDirty && !
|
|
13417
|
+
if (!isDirty && !remotePresent && durableUiLayoutValuePresent(local)) {
|
|
12373
13418
|
markDurableUiLayoutDirty(field, subfield);
|
|
12374
13419
|
}
|
|
12375
13420
|
}
|
|
@@ -12420,10 +13465,15 @@ async function flushDurableUiLayoutSave() {
|
|
|
12420
13465
|
}]));
|
|
12421
13466
|
const patch = { version: UI_LAYOUT_SCHEMA_VERSION };
|
|
12422
13467
|
for (const [field, entry] of snapshot) patch[field] = durableUiLayoutEntryPatch(field, entry);
|
|
13468
|
+
const mixedWidth = patch.sidePanel?.panelWidths?.right;
|
|
12423
13469
|
const response = await api(UI_LAYOUT_ENDPOINT, {
|
|
12424
13470
|
method: "PUT",
|
|
12425
13471
|
scoped: false,
|
|
12426
|
-
body: {
|
|
13472
|
+
body: {
|
|
13473
|
+
layout: patch,
|
|
13474
|
+
...(Number.isFinite(mixedWidth) ? { sidePanelWidth: mixedWidth } : {}),
|
|
13475
|
+
expectedLayoutRevision: durableLayoutRevision,
|
|
13476
|
+
},
|
|
12427
13477
|
});
|
|
12428
13478
|
// A successful write is newer than every GET that began before this
|
|
12429
13479
|
// acknowledgement, even if one of those reads completes afterward.
|
|
@@ -12494,18 +13544,16 @@ function cacheSidePanelWidth(width) {
|
|
|
12494
13544
|
}
|
|
12495
13545
|
}
|
|
12496
13546
|
|
|
12497
|
-
function persistSidePanelWidth(width) {
|
|
13547
|
+
function persistSidePanelWidth(width, side = "right") {
|
|
12498
13548
|
const rounded = Math.round(width);
|
|
12499
13549
|
sidePanelWidthPreferenceRevision += 1;
|
|
12500
|
-
cacheSidePanelWidth(rounded);
|
|
12501
|
-
|
|
12502
|
-
|
|
12503
|
-
|
|
12504
|
-
scoped: false,
|
|
12505
|
-
}).catch((error) => addEvent(`Could not save Control Deck width for this user: ${error.message || String(error)}`, "warn"));
|
|
13550
|
+
if (side === "right") cacheSidePanelWidth(rounded);
|
|
13551
|
+
controlDeckLayout.panelWidths = { ...controlDeckLayout.panelWidths, [side]: rounded };
|
|
13552
|
+
cacheControlDeckLayout(controlDeckLayout, "panelWidths");
|
|
13553
|
+
markDurableUiLayoutDirty("sidePanel", "panelWidths");
|
|
12506
13554
|
}
|
|
12507
13555
|
|
|
12508
|
-
function sidePanelMaxWidth() {
|
|
13556
|
+
function sidePanelMaxWidth(side = "right") {
|
|
12509
13557
|
const layout = document.querySelector(".layout");
|
|
12510
13558
|
const layoutRect = layout?.getBoundingClientRect?.();
|
|
12511
13559
|
const layoutWidth = layoutRect?.width || window.innerWidth || SIDE_PANEL_WIDTH_DEFAULT_PX;
|
|
@@ -12514,50 +13562,69 @@ function sidePanelMaxWidth() {
|
|
|
12514
13562
|
const horizontalPadding = (Number.parseFloat(layoutStyle?.paddingLeft || "0") || 0) + (Number.parseFloat(layoutStyle?.paddingRight || "0") || 0);
|
|
12515
13563
|
const contentWidth = Math.max(0, layoutWidth - horizontalPadding);
|
|
12516
13564
|
const fileViewerVisible = !!activeFileViewer && elements.fileViewerPane && getComputedStyle(elements.fileViewerPane).display !== "none";
|
|
12517
|
-
const fileViewerWidth = fileViewerVisible ? elements.fileViewerPane.getBoundingClientRect().width : 0;
|
|
13565
|
+
const fileViewerWidth = fileViewerVisible ? Math.max(FILE_VIEWER_WIDTH_MIN_PX, elements.fileViewerPane.getBoundingClientRect().width) : 0;
|
|
12518
13566
|
const splitOpen = document.body.classList.contains("terminal-split-open");
|
|
12519
|
-
const
|
|
12520
|
-
const
|
|
12521
|
-
const
|
|
13567
|
+
const terminalRailWidth = isControlDeckSidebarPresentation() ? Math.max(TERMINAL_TABS_SIDEBAR_WIDTH_MIN_PX, currentTerminalTabsSidebarWidth()) : 0;
|
|
13568
|
+
const centralMinimum = 320 + (splitOpen ? 320 : 0) + fileViewerWidth + terminalRailWidth;
|
|
13569
|
+
const otherSide = side === "left" ? "right" : "left";
|
|
13570
|
+
const otherPanelVisible = effectiveControlDeckPresentation() === "both" && !controlDeckLayout.collapsedPanels?.[otherSide];
|
|
13571
|
+
const otherPanelWidth = otherPanelVisible ? Math.max(SIDE_PANEL_WIDTH_MIN_PX, currentSidePanelWidth(otherSide)) : 0;
|
|
13572
|
+
const otherColumnCount = 1 + (splitOpen ? 1 : 0) + (fileViewerVisible ? 1 : 0) + (otherPanelVisible ? 1 : 0);
|
|
13573
|
+
const available = contentWidth - otherPanelWidth - centralMinimum - (gap * otherColumnCount);
|
|
12522
13574
|
return Math.max(SIDE_PANEL_WIDTH_MIN_PX, Math.min(Math.floor(contentWidth * 0.72), Math.floor(available)));
|
|
12523
13575
|
}
|
|
12524
13576
|
|
|
12525
|
-
function clampSidePanelWidth(width) {
|
|
13577
|
+
function clampSidePanelWidth(width, side = "right") {
|
|
12526
13578
|
const number = Number(width);
|
|
12527
|
-
const max = sidePanelMaxWidth();
|
|
12528
|
-
const fallback = readStoredSidePanelWidth() || SIDE_PANEL_WIDTH_DEFAULT_PX;
|
|
13579
|
+
const max = sidePanelMaxWidth(side);
|
|
13580
|
+
const fallback = controlDeckLayout.panelWidths?.[side] || (side === "right" ? readStoredSidePanelWidth() : null) || SIDE_PANEL_WIDTH_DEFAULT_PX;
|
|
12529
13581
|
return Math.max(SIDE_PANEL_WIDTH_MIN_PX, Math.min(max, Number.isFinite(number) ? number : fallback));
|
|
12530
13582
|
}
|
|
12531
13583
|
|
|
12532
|
-
function currentSidePanelWidth() {
|
|
12533
|
-
const
|
|
12534
|
-
|
|
13584
|
+
function currentSidePanelWidth(side = "right") {
|
|
13585
|
+
const shell = side === "left" ? elements.sidePanelLeft : elements.sidePanel;
|
|
13586
|
+
const width = shell?.getBoundingClientRect?.().width;
|
|
13587
|
+
return Number.isFinite(width) && width > 0 ? width : controlDeckLayout.panelWidths?.[side] || (side === "right" ? readStoredSidePanelWidth() : null) || SIDE_PANEL_WIDTH_DEFAULT_PX;
|
|
13588
|
+
}
|
|
13589
|
+
|
|
13590
|
+
function controlDeckSideResizeAvailable(side = "right") {
|
|
13591
|
+
const presentation = effectiveControlDeckPresentation();
|
|
13592
|
+
if (presentation === "overlay" || presentation === "embedded" || controlDeckLayout.collapsedPanels?.[side]) return false;
|
|
13593
|
+
return side === "left"
|
|
13594
|
+
? presentation === "left" || presentation === "both"
|
|
13595
|
+
: presentation === "right" || presentation === "both";
|
|
12535
13596
|
}
|
|
12536
13597
|
|
|
12537
|
-
function updateSidePanelResizeHandle(width = currentSidePanelWidth()) {
|
|
12538
|
-
const handle = elements.sidePanelResizeHandle;
|
|
13598
|
+
function updateSidePanelResizeHandle(width = currentSidePanelWidth("right"), side = "right") {
|
|
13599
|
+
const handle = side === "left" ? elements.sidePanelResizeHandleLeft : elements.sidePanelResizeHandle;
|
|
12539
13600
|
if (!handle) return;
|
|
12540
|
-
|
|
12541
|
-
handle.hidden = !resizeAvailable;
|
|
13601
|
+
handle.hidden = !controlDeckSideResizeAvailable(side);
|
|
12542
13602
|
handle.setAttribute("aria-valuemin", String(SIDE_PANEL_WIDTH_MIN_PX));
|
|
12543
|
-
handle.setAttribute("aria-valuemax", String(sidePanelMaxWidth()));
|
|
13603
|
+
handle.setAttribute("aria-valuemax", String(sidePanelMaxWidth(side)));
|
|
12544
13604
|
handle.setAttribute("aria-valuenow", String(Math.round(width)));
|
|
12545
13605
|
handle.setAttribute("aria-valuetext", `${Math.round(width)} pixels wide`);
|
|
12546
13606
|
}
|
|
12547
13607
|
|
|
12548
|
-
function applySidePanelWidth(width, { persist = false } = {}) {
|
|
12549
|
-
const clamped = clampSidePanelWidth(width);
|
|
12550
|
-
|
|
12551
|
-
|
|
12552
|
-
if (
|
|
13608
|
+
function applySidePanelWidth(width, { persist = false, side = "right" } = {}) {
|
|
13609
|
+
const clamped = clampSidePanelWidth(width, side);
|
|
13610
|
+
const variable = side === "left" ? "--side-panel-left-width" : "--side-panel-right-width";
|
|
13611
|
+
document.documentElement.style.setProperty(variable, `${Math.round(clamped)}px`);
|
|
13612
|
+
if (side === "right") document.documentElement.style.setProperty("--side-panel-width", `${Math.round(clamped)}px`);
|
|
13613
|
+
updateSidePanelResizeHandle(clamped, side);
|
|
13614
|
+
if (persist) persistSidePanelWidth(clamped, side);
|
|
12553
13615
|
return clamped;
|
|
12554
13616
|
}
|
|
12555
13617
|
|
|
12556
13618
|
async function restoreSidePanelWidthPreference() {
|
|
12557
13619
|
const localWidth = readStoredSidePanelWidth();
|
|
12558
13620
|
if (localWidth) document.documentElement.style.setProperty("--side-panel-width", `${Math.round(localWidth)}px`);
|
|
12559
|
-
if (!isSidePanelOverlayView())
|
|
12560
|
-
|
|
13621
|
+
if (!isSidePanelOverlayView()) {
|
|
13622
|
+
applySidePanelWidth(controlDeckLayout.panelWidths?.left || SIDE_PANEL_WIDTH_DEFAULT_PX, { side: "left" });
|
|
13623
|
+
applySidePanelWidth(controlDeckLayout.panelWidths?.right || localWidth || SIDE_PANEL_WIDTH_DEFAULT_PX, { side: "right" });
|
|
13624
|
+
} else {
|
|
13625
|
+
updateSidePanelResizeHandle(currentSidePanelWidth("left"), "left");
|
|
13626
|
+
updateSidePanelResizeHandle(localWidth || currentSidePanelWidth("right"), "right");
|
|
13627
|
+
}
|
|
12561
13628
|
|
|
12562
13629
|
const restoreRevision = sidePanelWidthPreferenceRevision;
|
|
12563
13630
|
const layoutGenerations = new Map(UI_LAYOUT_FIELDS.map((field) => [field, durableUiLayoutGeneration(field)]));
|
|
@@ -12582,14 +13649,15 @@ async function restoreSidePanelWidthPreference() {
|
|
|
12582
13649
|
}
|
|
12583
13650
|
}
|
|
12584
13651
|
|
|
12585
|
-
function beginSidePanelResize(event) {
|
|
12586
|
-
|
|
13652
|
+
function beginSidePanelResize(event, forcedSide = null) {
|
|
13653
|
+
const side = forcedSide || (event.currentTarget === elements.sidePanelResizeHandleLeft ? "left" : "right");
|
|
13654
|
+
if (!controlDeckSideResizeAvailable(side)) return;
|
|
12587
13655
|
if (event.button !== undefined && event.button !== 0) return;
|
|
12588
13656
|
event.preventDefault();
|
|
12589
|
-
const startWidth = currentSidePanelWidth();
|
|
12590
|
-
sidePanelResizeState = { pointerId: event.pointerId, startX: event.clientX, startWidth, width: startWidth };
|
|
13657
|
+
const startWidth = currentSidePanelWidth(side);
|
|
13658
|
+
sidePanelResizeState = { side, pointerId: event.pointerId, startX: event.clientX, startWidth, width: startWidth };
|
|
12591
13659
|
document.body.classList.add("side-panel-resizing");
|
|
12592
|
-
elements.sidePanelResizeHandle?.setPointerCapture?.(event.pointerId);
|
|
13660
|
+
(side === "left" ? elements.sidePanelResizeHandleLeft : elements.sidePanelResizeHandle)?.setPointerCapture?.(event.pointerId);
|
|
12593
13661
|
window.addEventListener("pointermove", updateSidePanelResize, { passive: false });
|
|
12594
13662
|
window.addEventListener("pointerup", finishSidePanelResize, { passive: false });
|
|
12595
13663
|
window.addEventListener("pointercancel", finishSidePanelResize, { passive: false });
|
|
@@ -12599,45 +13667,49 @@ function updateSidePanelResize(event) {
|
|
|
12599
13667
|
const state = sidePanelResizeState;
|
|
12600
13668
|
if (!state || (event.pointerId !== undefined && event.pointerId !== state.pointerId)) return;
|
|
12601
13669
|
event.preventDefault();
|
|
12602
|
-
state.
|
|
13670
|
+
const delta = state.side === "left" ? event.clientX - state.startX : state.startX - event.clientX;
|
|
13671
|
+
state.width = applySidePanelWidth(state.startWidth + delta, { side: state.side });
|
|
12603
13672
|
}
|
|
12604
13673
|
|
|
12605
13674
|
function finishSidePanelResize(event) {
|
|
12606
13675
|
const state = sidePanelResizeState;
|
|
12607
13676
|
if (!state || (event.pointerId !== undefined && event.pointerId !== state.pointerId)) return;
|
|
12608
13677
|
event.preventDefault?.();
|
|
12609
|
-
elements.sidePanelResizeHandle?.releasePointerCapture?.(state.pointerId);
|
|
13678
|
+
(state.side === "left" ? elements.sidePanelResizeHandleLeft : elements.sidePanelResizeHandle)?.releasePointerCapture?.(state.pointerId);
|
|
12610
13679
|
window.removeEventListener("pointermove", updateSidePanelResize);
|
|
12611
13680
|
window.removeEventListener("pointerup", finishSidePanelResize);
|
|
12612
13681
|
window.removeEventListener("pointercancel", finishSidePanelResize);
|
|
12613
13682
|
document.body.classList.remove("side-panel-resizing");
|
|
12614
|
-
applySidePanelWidth(state.width, { persist: true });
|
|
13683
|
+
applySidePanelWidth(state.width, { persist: true, side: state.side });
|
|
12615
13684
|
sidePanelResizeState = null;
|
|
12616
13685
|
}
|
|
12617
13686
|
|
|
12618
13687
|
function handleSidePanelResizeKeydown(event) {
|
|
12619
|
-
|
|
13688
|
+
const side = event.currentTarget === elements.sidePanelResizeHandleLeft ? "left" : "right";
|
|
13689
|
+
if (!controlDeckSideResizeAvailable(side)) return;
|
|
12620
13690
|
const step = event.shiftKey ? 80 : 24;
|
|
12621
|
-
const current = currentSidePanelWidth();
|
|
13691
|
+
const current = currentSidePanelWidth(side);
|
|
12622
13692
|
let next = current;
|
|
12623
|
-
if (event.key === "ArrowLeft") next = current + step;
|
|
12624
|
-
else if (event.key === "ArrowRight") next = current - step;
|
|
13693
|
+
if (event.key === "ArrowLeft") next = side === "left" ? current - step : current + step;
|
|
13694
|
+
else if (event.key === "ArrowRight") next = side === "left" ? current + step : current - step;
|
|
12625
13695
|
else if (event.key === "Home") next = SIDE_PANEL_WIDTH_MIN_PX;
|
|
12626
|
-
else if (event.key === "End") next = sidePanelMaxWidth();
|
|
13696
|
+
else if (event.key === "End") next = sidePanelMaxWidth(side);
|
|
12627
13697
|
else return;
|
|
12628
13698
|
event.preventDefault();
|
|
12629
|
-
applySidePanelWidth(next, { persist: true });
|
|
13699
|
+
applySidePanelWidth(next, { persist: true, side });
|
|
12630
13700
|
}
|
|
12631
13701
|
|
|
12632
13702
|
function syncSidePanelWidthForViewport() {
|
|
12633
|
-
if (isSidePanelOverlayView()
|
|
12634
|
-
updateSidePanelResizeHandle();
|
|
13703
|
+
if (isSidePanelOverlayView()) {
|
|
13704
|
+
updateSidePanelResizeHandle(currentSidePanelWidth("left"), "left");
|
|
13705
|
+
updateSidePanelResizeHandle(currentSidePanelWidth("right"), "right");
|
|
12635
13706
|
return;
|
|
12636
13707
|
}
|
|
12637
|
-
// Keep viewport/layout reconciliation anchored to the durable
|
|
12638
|
-
// Reading
|
|
12639
|
-
// during hard-reset startup and permanently freeze
|
|
12640
|
-
applySidePanelWidth(
|
|
13708
|
+
// Keep viewport/layout reconciliation anchored to the durable preferences.
|
|
13709
|
+
// Reading rendered widths here can capture an in-progress CSS transition
|
|
13710
|
+
// during hard-reset startup and permanently freeze a panel below its saved width.
|
|
13711
|
+
applySidePanelWidth(controlDeckLayout.panelWidths?.left || currentSidePanelWidth("left"), { side: "left" });
|
|
13712
|
+
applySidePanelWidth(controlDeckLayout.panelWidths?.right || readStoredSidePanelWidth() || currentSidePanelWidth("right"), { side: "right" });
|
|
12641
13713
|
}
|
|
12642
13714
|
|
|
12643
13715
|
function readStoredFileViewerWidth() {
|
|
@@ -12772,6 +13844,7 @@ function syncFileViewerWidthForViewport() {
|
|
|
12772
13844
|
function syncResizablePanelWidthsForViewport() {
|
|
12773
13845
|
syncSidePanelWidthForViewport();
|
|
12774
13846
|
syncFileViewerWidthForViewport();
|
|
13847
|
+
syncTerminalTabsSidebarWidthForViewport();
|
|
12775
13848
|
}
|
|
12776
13849
|
|
|
12777
13850
|
async function openFileTreeEntryInWebui(entry = fileContextMenuState?.entry) {
|
|
@@ -12786,12 +13859,22 @@ async function openFileTreeEntryInWebui(entry = fileContextMenuState?.entry) {
|
|
|
12786
13859
|
await openFileInViewer(path);
|
|
12787
13860
|
}
|
|
12788
13861
|
|
|
12789
|
-
|
|
12790
|
-
|
|
13862
|
+
const FILE_VIEWER_IMAGE_MIME_TYPES = new Set(["image/png", "image/jpeg", "image/gif", "image/webp", "image/avif"]);
|
|
13863
|
+
|
|
13864
|
+
function fileViewerImageDataUrl(data = {}) {
|
|
13865
|
+
const mimeType = String(data.mimeType || "").toLowerCase();
|
|
13866
|
+
const encoded = String(data.data || "");
|
|
13867
|
+
if (!FILE_VIEWER_IMAGE_MIME_TYPES.has(mimeType) || !encoded) return "";
|
|
13868
|
+
return `data:${mimeType};base64,${encoded}`;
|
|
13869
|
+
}
|
|
13870
|
+
|
|
13871
|
+
// Changes mode only exists for Git-originated opens. Image previews are
|
|
13872
|
+
// read-only, while text keeps the original Source/Markdown-Preview behavior.
|
|
12791
13873
|
function resolveFileViewerMode(viewer) {
|
|
12792
13874
|
if (!viewer) return "source";
|
|
12793
13875
|
const hasChanges = !!viewer.gitChanges;
|
|
12794
|
-
if (viewer.mode === "changes") return hasChanges ? "changes" : "source";
|
|
13876
|
+
if (viewer.mode === "changes") return hasChanges ? "changes" : viewer.kind === "image" ? "image" : "source";
|
|
13877
|
+
if (viewer.kind === "image") return "image";
|
|
12795
13878
|
if (viewer.sourceAvailable === false) return hasChanges ? "changes" : "source";
|
|
12796
13879
|
return viewer.mode === "preview" && viewer.language === "markdown" ? "preview" : "source";
|
|
12797
13880
|
}
|
|
@@ -12820,7 +13903,7 @@ function updateFileViewerUi() {
|
|
|
12820
13903
|
document.body.classList.toggle("file-viewer-open", open);
|
|
12821
13904
|
syncMobileShellInteractivity();
|
|
12822
13905
|
if (elements.fileViewerPane) elements.fileViewerPane.hidden = !open;
|
|
12823
|
-
|
|
13906
|
+
scheduleControlDeckPresentationReconciliation();
|
|
12824
13907
|
updateFileViewerResizeHandle();
|
|
12825
13908
|
if (!open) {
|
|
12826
13909
|
closeFileViewerSearch({ restoreFocus: false });
|
|
@@ -12830,6 +13913,7 @@ function updateFileViewerUi() {
|
|
|
12830
13913
|
const viewer = activeFileViewer;
|
|
12831
13914
|
captureFileViewerEditorContinuity(viewer);
|
|
12832
13915
|
const isMarkdown = viewer.language === "markdown";
|
|
13916
|
+
const isImage = viewer.kind === "image";
|
|
12833
13917
|
const hasChanges = !!viewer.gitChanges;
|
|
12834
13918
|
const sourceAvailable = viewer.sourceAvailable !== false;
|
|
12835
13919
|
const mode = resolveFileViewerMode(viewer);
|
|
@@ -12837,7 +13921,9 @@ function updateFileViewerUi() {
|
|
|
12837
13921
|
if (elements.fileViewerTitle) elements.fileViewerTitle.textContent = viewer.name || fileDisplayName(viewer.path);
|
|
12838
13922
|
if (elements.fileViewerMeta) {
|
|
12839
13923
|
const lineCount = textLineCount(viewer.content || "");
|
|
12840
|
-
const sourceMeta =
|
|
13924
|
+
const sourceMeta = isImage
|
|
13925
|
+
? [formatBytes(viewer.size), viewer.mimeType]
|
|
13926
|
+
: sourceAvailable ? [formatBytes(viewer.size), `${lineCount} ${lineCount === 1 ? "line" : "lines"}`] : ["source unavailable"];
|
|
12841
13927
|
elements.fileViewerMeta.textContent = [viewer.path, ...sourceMeta].filter(Boolean).join(" · ");
|
|
12842
13928
|
}
|
|
12843
13929
|
if (elements.fileViewerChangesModeButton) {
|
|
@@ -12853,10 +13939,10 @@ function updateFileViewerUi() {
|
|
|
12853
13939
|
elements.fileViewerSourceModeButton.classList.toggle("active", mode === "source");
|
|
12854
13940
|
}
|
|
12855
13941
|
if (elements.fileViewerPreviewModeButton) {
|
|
12856
|
-
elements.fileViewerPreviewModeButton.hidden = !isMarkdown;
|
|
12857
|
-
elements.fileViewerPreviewModeButton.disabled = !isMarkdown || !sourceAvailable;
|
|
12858
|
-
elements.fileViewerPreviewModeButton.setAttribute("aria-pressed",
|
|
12859
|
-
elements.fileViewerPreviewModeButton.classList.toggle("active",
|
|
13942
|
+
elements.fileViewerPreviewModeButton.hidden = !isMarkdown && !isImage;
|
|
13943
|
+
elements.fileViewerPreviewModeButton.disabled = (!isMarkdown || !sourceAvailable) && !isImage;
|
|
13944
|
+
elements.fileViewerPreviewModeButton.setAttribute("aria-pressed", ["preview", "image"].includes(mode) ? "true" : "false");
|
|
13945
|
+
elements.fileViewerPreviewModeButton.classList.toggle("active", ["preview", "image"].includes(mode));
|
|
12860
13946
|
}
|
|
12861
13947
|
if (elements.fileViewerEditor) {
|
|
12862
13948
|
elements.fileViewerEditor.hidden = mode !== "source";
|
|
@@ -12868,6 +13954,17 @@ function updateFileViewerUi() {
|
|
|
12868
13954
|
if (elements.fileViewerPreview) {
|
|
12869
13955
|
elements.fileViewerPreview.hidden = mode !== "preview";
|
|
12870
13956
|
if (mode === "preview") renderMarkdown(elements.fileViewerPreview, viewer.content || "");
|
|
13957
|
+
else elements.fileViewerPreview.replaceChildren();
|
|
13958
|
+
}
|
|
13959
|
+
if (elements.fileViewerImage) elements.fileViewerImage.hidden = mode !== "image";
|
|
13960
|
+
if (elements.fileViewerImageElement) {
|
|
13961
|
+
if (isImage) {
|
|
13962
|
+
if (elements.fileViewerImageElement.src !== viewer.imageUrl) elements.fileViewerImageElement.src = viewer.imageUrl;
|
|
13963
|
+
elements.fileViewerImageElement.alt = `Preview of ${viewer.name || fileDisplayName(viewer.path)}`;
|
|
13964
|
+
} else {
|
|
13965
|
+
elements.fileViewerImageElement.removeAttribute("src");
|
|
13966
|
+
elements.fileViewerImageElement.alt = "";
|
|
13967
|
+
}
|
|
12871
13968
|
}
|
|
12872
13969
|
if (elements.fileViewerChanges) {
|
|
12873
13970
|
elements.fileViewerChanges.hidden = mode !== "changes";
|
|
@@ -12880,6 +13977,10 @@ function updateFileViewerUi() {
|
|
|
12880
13977
|
elements.fileViewerOpenDefaultButton.dataset.path = viewerPath;
|
|
12881
13978
|
elements.fileViewerOpenDefaultButton.disabled = viewer.readOnly === true || !viewerPath;
|
|
12882
13979
|
}
|
|
13980
|
+
if (isImage) {
|
|
13981
|
+
clearFileViewerSelection();
|
|
13982
|
+
closeFileViewerSearch({ restoreFocus: false });
|
|
13983
|
+
}
|
|
12883
13984
|
renderFileViewerSelectionBar();
|
|
12884
13985
|
if (elements.fileViewerSearchBar && !elements.fileViewerSearchBar.hidden) {
|
|
12885
13986
|
fileViewerSearchIndex = -1;
|
|
@@ -12895,6 +13996,7 @@ function fileViewerSearchQueryText() {
|
|
|
12895
13996
|
|
|
12896
13997
|
function fileViewerSearchSurface() {
|
|
12897
13998
|
const mode = resolveFileViewerMode(activeFileViewer);
|
|
13999
|
+
if (mode === "image") return null;
|
|
12898
14000
|
if (mode === "preview") return elements.fileViewerPreview;
|
|
12899
14001
|
if (mode === "changes") return elements.fileViewerChanges;
|
|
12900
14002
|
return elements.fileViewerEditor;
|
|
@@ -13058,7 +14160,7 @@ function stepFileViewerSearch(step) {
|
|
|
13058
14160
|
}
|
|
13059
14161
|
|
|
13060
14162
|
function openFileViewerSearch() {
|
|
13061
|
-
if (!activeFileViewer || !elements.fileViewerSearchBar) return;
|
|
14163
|
+
if (!activeFileViewer || activeFileViewer.kind === "image" || !elements.fileViewerSearchBar) return;
|
|
13062
14164
|
closeChatSearch();
|
|
13063
14165
|
const editor = fileViewerSearchSurface() === elements.fileViewerEditor ? elements.fileViewerEditor : null;
|
|
13064
14166
|
const selectedText = editor && editor.selectionEnd > editor.selectionStart
|
|
@@ -13086,7 +14188,8 @@ function closeFileViewerSearch({ restoreFocus = true } = {}) {
|
|
|
13086
14188
|
updateFileViewerSearchCount();
|
|
13087
14189
|
if (!restoreFocus) return;
|
|
13088
14190
|
const mode = resolveFileViewerMode(activeFileViewer);
|
|
13089
|
-
if (mode === "
|
|
14191
|
+
if (mode === "image") elements.fileViewerImage?.focus({ preventScroll: true });
|
|
14192
|
+
else if (mode === "preview") elements.fileViewerPreview?.focus({ preventScroll: true });
|
|
13090
14193
|
else if (mode === "changes") elements.fileViewerChanges?.focus({ preventScroll: true });
|
|
13091
14194
|
else elements.fileViewerEditor?.focus({ preventScroll: true });
|
|
13092
14195
|
}
|
|
@@ -13331,7 +14434,7 @@ function resetFileViewerUi() {
|
|
|
13331
14434
|
syncMobileShellInteractivity();
|
|
13332
14435
|
updateFileViewerResizeHandle();
|
|
13333
14436
|
if (elements.fileViewerPane) elements.fileViewerPane.hidden = true;
|
|
13334
|
-
|
|
14437
|
+
scheduleControlDeckPresentationReconciliation();
|
|
13335
14438
|
if (elements.fileViewerOpenDefaultButton) elements.fileViewerOpenDefaultButton.dataset.path = "";
|
|
13336
14439
|
if (elements.fileViewerEditor) {
|
|
13337
14440
|
elements.fileViewerEditor.value = "";
|
|
@@ -13339,6 +14442,11 @@ function resetFileViewerUi() {
|
|
|
13339
14442
|
elements.fileViewerEditor.readOnly = false;
|
|
13340
14443
|
}
|
|
13341
14444
|
if (elements.fileViewerPreview) elements.fileViewerPreview.replaceChildren();
|
|
14445
|
+
if (elements.fileViewerImage) elements.fileViewerImage.hidden = true;
|
|
14446
|
+
if (elements.fileViewerImageElement) {
|
|
14447
|
+
elements.fileViewerImageElement.removeAttribute("src");
|
|
14448
|
+
elements.fileViewerImageElement.alt = "";
|
|
14449
|
+
}
|
|
13342
14450
|
if (elements.fileViewerChanges) {
|
|
13343
14451
|
elements.fileViewerChanges.hidden = true;
|
|
13344
14452
|
elements.fileViewerChanges.replaceChildren();
|
|
@@ -13429,25 +14537,31 @@ async function openFileInViewer(path = "", { gitCategory = "", gitPath = "" } =
|
|
|
13429
14537
|
if (!isCurrentTabContext(tabContext) || openRequestSerial !== fileViewerOpenRequestSerial) return;
|
|
13430
14538
|
const data = response.data || {};
|
|
13431
14539
|
const gitChanges = changesRequest ? gitFileChangesPlaceholder(category, changesPath, changesRequestSerial) : null;
|
|
14540
|
+
const kind = data.kind === "image" ? "image" : "text";
|
|
14541
|
+
const imageUrl = kind === "image" ? fileViewerImageDataUrl(data) : "";
|
|
14542
|
+
if (kind === "image" && !imageUrl) throw new Error("Image preview data is invalid or unsupported");
|
|
13432
14543
|
activeFileViewer = {
|
|
13433
14544
|
path: normalizeFileTreePath(data.path || normalized),
|
|
13434
14545
|
name: data.name || fileDisplayName(normalized),
|
|
13435
|
-
content: String(data.content || ""),
|
|
14546
|
+
content: kind === "text" ? String(data.content || "") : "",
|
|
13436
14547
|
size: Number(data.size) || 0,
|
|
13437
14548
|
mtimeMs: Number(data.mtimeMs) || 0,
|
|
13438
14549
|
extension: data.extension || "",
|
|
13439
|
-
language: data.language || "text",
|
|
13440
|
-
|
|
14550
|
+
language: kind === "text" ? data.language || "text" : "image",
|
|
14551
|
+
kind,
|
|
14552
|
+
mimeType: kind === "image" ? String(data.mimeType || "") : "",
|
|
14553
|
+
imageUrl,
|
|
14554
|
+
mode: gitChanges ? "changes" : kind === "image" ? "image" : data.language === "markdown" ? "preview" : "source",
|
|
13441
14555
|
dirty: false,
|
|
13442
|
-
readOnly:
|
|
13443
|
-
sourceAvailable:
|
|
14556
|
+
readOnly: kind === "image",
|
|
14557
|
+
sourceAvailable: kind === "text",
|
|
13444
14558
|
gitChanges,
|
|
13445
14559
|
};
|
|
13446
14560
|
if (elements.fileViewerEditor) elements.fileViewerEditor.value = activeFileViewer.content;
|
|
13447
14561
|
clearFileViewerSelection();
|
|
13448
14562
|
cacheActiveFileViewerForTab();
|
|
13449
14563
|
updateFileViewerUi();
|
|
13450
|
-
setFileViewerStatus("Opened in WebUI.", "success");
|
|
14564
|
+
setFileViewerStatus(kind === "image" ? "Image opened in WebUI (read-only)." : "Opened in WebUI.", "success");
|
|
13451
14565
|
if (changesRequest) void applyGitFileChangesSnapshot(changesRequest, tabContext, activeFileViewer.path, changesRequestSerial);
|
|
13452
14566
|
} catch (error) {
|
|
13453
14567
|
const message = error.message || String(error);
|
|
@@ -13635,6 +14749,9 @@ function syncTabMetadata(nextTabs = []) {
|
|
|
13635
14749
|
if (voiceConversationTabId === tabId) stopVoiceConversationLoop();
|
|
13636
14750
|
clearGitWorkflowForTab(tabId);
|
|
13637
14751
|
commandCatalogsByTab.delete(tabId);
|
|
14752
|
+
tabStateCache.delete(tabId);
|
|
14753
|
+
tabStatsCache.delete(tabId);
|
|
14754
|
+
tabWorkspaceCache.delete(tabId);
|
|
13638
14755
|
sessionSummaryByTab.delete(tabId);
|
|
13639
14756
|
if (sessionSummaryOverlayTabId === tabId) closeSessionSummaryOverlay({ restoreFocus: false });
|
|
13640
14757
|
clearGitFooterPayloadState(tabId);
|
|
@@ -14045,23 +15162,37 @@ function clearWidgetsForTab(tabId = activeTabId) {
|
|
|
14045
15162
|
}
|
|
14046
15163
|
}
|
|
14047
15164
|
|
|
15165
|
+
function cachedStateForTabSwitch(tabId = activeTabId) {
|
|
15166
|
+
if (!tabId) return null;
|
|
15167
|
+
const cached = tabStateCache.get(tabId) || null;
|
|
15168
|
+
const activity = tabActivities.get(tabId);
|
|
15169
|
+
if (!activity) return cached;
|
|
15170
|
+
const isWorking = activity.isWorking === true;
|
|
15171
|
+
return {
|
|
15172
|
+
...(cached || {}),
|
|
15173
|
+
isStreaming: isWorking,
|
|
15174
|
+
isCompacting: isWorking && cached?.isCompacting === true,
|
|
15175
|
+
};
|
|
15176
|
+
}
|
|
15177
|
+
|
|
14048
15178
|
function resetActiveTabUi() {
|
|
14049
15179
|
clearRefreshTimers();
|
|
14050
15180
|
eventSource?.close();
|
|
14051
15181
|
eventSource = null;
|
|
14052
|
-
currentState =
|
|
14053
|
-
latestStats = null;
|
|
15182
|
+
currentState = cachedStateForTabSwitch(activeTabId);
|
|
15183
|
+
latestStats = activeTabId ? tabStatsCache.get(activeTabId) || null : null;
|
|
14054
15184
|
latestStatsOverlayPayload = null;
|
|
14055
15185
|
latestBtwWidgetPayload = null;
|
|
14056
15186
|
btwWidgetComposerOpen = false;
|
|
14057
15187
|
btwWidgetInputDraft = "";
|
|
14058
|
-
latestWorkspace = null;
|
|
15188
|
+
latestWorkspace = activeTabId ? tabWorkspaceCache.get(activeTabId) || null : null;
|
|
14059
15189
|
latestMessages = [];
|
|
14060
15190
|
latestMessagesSessionKey = "";
|
|
14061
15191
|
resetFileViewerUi();
|
|
14062
15192
|
resetFileTreeState();
|
|
14063
15193
|
restoreFileViewerForActiveTab();
|
|
14064
15194
|
clearRunIndicatorActivity({ render: false });
|
|
15195
|
+
if (currentState) syncRunIndicatorFromState(currentState);
|
|
14065
15196
|
statusEntries.clear();
|
|
14066
15197
|
restoreWidgetsForActiveTab();
|
|
14067
15198
|
transientMessages = [];
|
|
@@ -14071,6 +15202,7 @@ function resetActiveTabUi() {
|
|
|
14071
15202
|
availableCommands = commandCatalog?.available || [];
|
|
14072
15203
|
rawAvailableCommands = commandCatalog?.raw || [];
|
|
14073
15204
|
resetOptionalFeatureAvailability();
|
|
15205
|
+
if (commandCatalog) updateOptionalFeatureAvailability();
|
|
14074
15206
|
commandSuggestions = [];
|
|
14075
15207
|
pathSuggestions = [];
|
|
14076
15208
|
suggestionMode = "none";
|
|
@@ -14099,6 +15231,7 @@ function resetActiveTabUi() {
|
|
|
14099
15231
|
restoreCachedMessagesForActiveTab();
|
|
14100
15232
|
renderFooter();
|
|
14101
15233
|
renderFeedbackTray();
|
|
15234
|
+
restoreComposerActionSlotLayout();
|
|
14102
15235
|
}
|
|
14103
15236
|
|
|
14104
15237
|
function tabGroupStatusRank(state) {
|
|
@@ -15219,6 +16352,29 @@ function initializeTerminalHeaderTooltips() {
|
|
|
15219
16352
|
applyStyledTooltip(elements.closeAllTabsButton, "Close all terminal tabs", { ariaLabel: "Close all terminal tabs" });
|
|
15220
16353
|
}
|
|
15221
16354
|
|
|
16355
|
+
function initializeControlSettingTooltips() {
|
|
16356
|
+
document.querySelectorAll("#sidePanelSectionControls .control-row-label[data-tooltip]").forEach((label) => {
|
|
16357
|
+
bindStyledTooltipEvents(label);
|
|
16358
|
+
label.addEventListener("click", (event) => {
|
|
16359
|
+
const modelLabel = label.contains(elements.modelControlLabel);
|
|
16360
|
+
const themeLabel = label.contains(elements.themeControlLabel);
|
|
16361
|
+
showFooterTooltip(label);
|
|
16362
|
+
if (!modelLabel && !themeLabel) return;
|
|
16363
|
+
if (event.target === elements.modelControlLabel || event.target === elements.themeControlLabel) return;
|
|
16364
|
+
event.preventDefault();
|
|
16365
|
+
if (modelLabel) toggleModelSearchInput();
|
|
16366
|
+
else toggleThemeSearchInput();
|
|
16367
|
+
});
|
|
16368
|
+
label.addEventListener("keydown", (event) => {
|
|
16369
|
+
if (event.key !== "Enter" && event.key !== " ") return;
|
|
16370
|
+
event.preventDefault();
|
|
16371
|
+
showFooterTooltip(label);
|
|
16372
|
+
if (label.contains(elements.modelControlLabel)) toggleModelSearchInput();
|
|
16373
|
+
else if (label.contains(elements.themeControlLabel)) toggleThemeSearchInput();
|
|
16374
|
+
});
|
|
16375
|
+
});
|
|
16376
|
+
}
|
|
16377
|
+
|
|
15222
16378
|
function openNewTabMenu() {
|
|
15223
16379
|
setPublishMenuOpen(false);
|
|
15224
16380
|
setNativeCommandMenuOpen(false);
|
|
@@ -15342,17 +16498,84 @@ function prefetchInactiveTabCommandCatalogs() {
|
|
|
15342
16498
|
}
|
|
15343
16499
|
}
|
|
15344
16500
|
|
|
16501
|
+
function tabsSnapshotSignature(tabList = []) {
|
|
16502
|
+
try {
|
|
16503
|
+
return JSON.stringify(tabList);
|
|
16504
|
+
} catch {
|
|
16505
|
+
return "";
|
|
16506
|
+
}
|
|
16507
|
+
}
|
|
16508
|
+
|
|
16509
|
+
function tabsRenderSnapshotSignature(tabList = []) {
|
|
16510
|
+
return tabsSnapshotSignature(tabList.map((tab) => {
|
|
16511
|
+
const activity = normalizeTabActivity(tab?.activity || {});
|
|
16512
|
+
const runner = tab?.appRunner || null;
|
|
16513
|
+
const conversation = normalizeConversationModeState(tab?.conversationMode || {});
|
|
16514
|
+
const summary = tab?.sessionSummary || null;
|
|
16515
|
+
const pendingExtensionUiRequestCount = normalizePendingExtensionUiRequestCount(tab?.pendingExtensionUiRequestCount);
|
|
16516
|
+
const seenCompletionSerial = tabSeenCompletionSerials.get(tab?.id) ?? activity.completionSerial;
|
|
16517
|
+
const activityState = tab?.running && pendingExtensionUiRequestCount > 0
|
|
16518
|
+
? "blocked"
|
|
16519
|
+
: tab?.running && activity.isWorking
|
|
16520
|
+
? "working"
|
|
16521
|
+
: tab?.running && activity.completionSerial > seenCompletionSerial
|
|
16522
|
+
? "done"
|
|
16523
|
+
: tab?.running ? "idle" : "stopped";
|
|
16524
|
+
return {
|
|
16525
|
+
id: tab?.id || "",
|
|
16526
|
+
index: Number(tab?.index) || 0,
|
|
16527
|
+
title: tab?.title || "",
|
|
16528
|
+
titleSource: tab?.titleSource || "",
|
|
16529
|
+
running: tab?.running === true,
|
|
16530
|
+
cwd: tab?.cwd || "",
|
|
16531
|
+
gitWorkspace: tab?.gitWorkspace || null,
|
|
16532
|
+
pendingExtensionUiRequestCount,
|
|
16533
|
+
activityState,
|
|
16534
|
+
appRunner: runner ? {
|
|
16535
|
+
status: runner.status || "",
|
|
16536
|
+
stopping: runner.stopping === true,
|
|
16537
|
+
displayCommand: runner.displayCommand || runner.label || runner.command || "",
|
|
16538
|
+
} : null,
|
|
16539
|
+
conversationMode: {
|
|
16540
|
+
available: conversation.available,
|
|
16541
|
+
enabled: conversation.enabled,
|
|
16542
|
+
uiState: conversation.uiState,
|
|
16543
|
+
statusText: conversation.statusText,
|
|
16544
|
+
},
|
|
16545
|
+
sessionSummary: summary ? {
|
|
16546
|
+
status: summary.status || "",
|
|
16547
|
+
configured: summary.configured === true,
|
|
16548
|
+
enabled: summary.enabled === true,
|
|
16549
|
+
durable: summary.durable === true,
|
|
16550
|
+
hasSummary: Boolean(summary.summaryMarkdown),
|
|
16551
|
+
message: summary.message || "",
|
|
16552
|
+
} : null,
|
|
16553
|
+
};
|
|
16554
|
+
}));
|
|
16555
|
+
}
|
|
16556
|
+
|
|
15345
16557
|
async function refreshTabs({ selectStored = false } = {}) {
|
|
15346
16558
|
const previousTabs = tabs;
|
|
16559
|
+
const previousTabsSignature = tabsSnapshotSignature(previousTabs);
|
|
16560
|
+
const previousTabsRenderSignature = tabsRenderSnapshotSignature(previousTabs);
|
|
16561
|
+
const previousActiveTabId = activeTabId;
|
|
15347
16562
|
const response = await api("/api/tabs", { scoped: false });
|
|
15348
|
-
|
|
15349
|
-
|
|
15350
|
-
const
|
|
15351
|
-
|
|
15352
|
-
|
|
16563
|
+
const nextTabs = response.data?.tabs || [];
|
|
16564
|
+
const tabsChanged = previousTabsSignature !== tabsSnapshotSignature(nextTabs);
|
|
16565
|
+
const tabsRenderChanged = previousTabsRenderSignature !== tabsRenderSnapshotSignature(nextTabs);
|
|
16566
|
+
if (tabsChanged) {
|
|
16567
|
+
tabs = nextTabs;
|
|
16568
|
+
syncTabMetadata(tabs);
|
|
16569
|
+
const liveParentTabIds = new Set(tabs.map((tab) => tab.id));
|
|
16570
|
+
for (const tabId of intercomConversationSummariesByTab.keys()) {
|
|
16571
|
+
if (!liveParentTabIds.has(tabId)) intercomConversationSummariesByTab.delete(tabId);
|
|
16572
|
+
}
|
|
16573
|
+
for (const view of [...subagentTerminalViews.values()]) {
|
|
16574
|
+
if (!liveParentTabIds.has(view.parentTabId)) removeSubagentTerminalViewsForParent(view.parentTabId);
|
|
16575
|
+
}
|
|
16576
|
+
syncBlockedTabNotificationsFromTabs(tabs, previousTabs);
|
|
16577
|
+
syncAgentDoneNotificationsFromTabs(tabs, previousTabs);
|
|
15353
16578
|
}
|
|
15354
|
-
syncBlockedTabNotificationsFromTabs(tabs, previousTabs);
|
|
15355
|
-
syncAgentDoneNotificationsFromTabs(tabs, previousTabs);
|
|
15356
16579
|
const requested = selectStored ? requestedTabIdFromUrl() : null;
|
|
15357
16580
|
const stored = selectStored ? restoreStoredTabId() : null;
|
|
15358
16581
|
if (!activeTabId || !tabs.some((tab) => tab.id === activeTabId)) {
|
|
@@ -15365,7 +16588,8 @@ async function refreshTabs({ selectStored = false } = {}) {
|
|
|
15365
16588
|
setWorkspaceDashboardCollapsed(false, { persist: false });
|
|
15366
16589
|
}
|
|
15367
16590
|
renderSessionSkillTags(activeTabId);
|
|
15368
|
-
renderTabs();
|
|
16591
|
+
if (tabsRenderChanged || activeTabId !== previousActiveTabId || selectStored) renderTabs();
|
|
16592
|
+
else syncTabPolling();
|
|
15369
16593
|
prefetchInactiveTabCommandCatalogs();
|
|
15370
16594
|
return tabs;
|
|
15371
16595
|
}
|
|
@@ -15397,6 +16621,9 @@ async function switchTab(tabId) {
|
|
|
15397
16621
|
cacheMessagesForTab(activeTabId);
|
|
15398
16622
|
cacheWidgetsForTab(activeTabId);
|
|
15399
16623
|
cacheActiveFileViewerForTab(activeTabId);
|
|
16624
|
+
if (activeTabId && currentState) tabStateCache.set(activeTabId, currentState);
|
|
16625
|
+
if (activeTabId && latestStats) tabStatsCache.set(activeTabId, latestStats);
|
|
16626
|
+
if (activeTabId && latestWorkspace) tabWorkspaceCache.set(activeTabId, latestWorkspace);
|
|
15400
16627
|
const tabContext = setActiveTabId(tabId, { remember: true });
|
|
15401
16628
|
if (voiceConversation && voiceConversationTabId !== tabId) stopVoiceConversationLoop();
|
|
15402
16629
|
resetActiveTabUi();
|
|
@@ -15447,10 +16674,11 @@ function updateTerminalSplitControls(canShowSplit, splitTab = terminalSplitTab()
|
|
|
15447
16674
|
|
|
15448
16675
|
function updateTerminalSplitUi() {
|
|
15449
16676
|
const tab = terminalSplitTab();
|
|
15450
|
-
const
|
|
16677
|
+
const overlayDrawerOpen = isControlDeckOverlayPresentation() && !document.body.classList.contains("side-panel-collapsed");
|
|
16678
|
+
const canShowSplit = !!tab && !embeddedSplitMode && !overlayDrawerOpen;
|
|
15451
16679
|
document.body.classList.toggle("terminal-split-open", canShowSplit);
|
|
15452
16680
|
if (elements.terminalSplitShell) elements.terminalSplitShell.hidden = !canShowSplit;
|
|
15453
|
-
|
|
16681
|
+
scheduleControlDeckPresentationReconciliation();
|
|
15454
16682
|
updateTerminalSplitControls(canShowSplit, tab);
|
|
15455
16683
|
if (!canShowSplit) return;
|
|
15456
16684
|
if (elements.terminalSplitTitle) elements.terminalSplitTitle.textContent = tab.title || "Split terminal";
|
|
@@ -22481,15 +23709,136 @@ function initializeClaudeUsage() {
|
|
|
22481
23709
|
claudeUsageRenderTimer = setInterval(renderClaudeUsage, CLAUDE_USAGE_RENDER_TICK_MS);
|
|
22482
23710
|
}
|
|
22483
23711
|
|
|
22484
|
-
|
|
22485
|
-
|
|
23712
|
+
const SUBAGENT_LAUNCHER_LABELS = Object.freeze({
|
|
23713
|
+
sdk: "SDK", "pi-rpc": "Pi RPC", "pi-json": "Pi JSON", "pi-print": "Pi print",
|
|
23714
|
+
interactive: "Pi session", tmux: "tmux", "pi-subagents": "pi-subagents",
|
|
23715
|
+
schedule: "scheduled", gate: "gate", workflow: "workflow", custom: "custom",
|
|
23716
|
+
});
|
|
23717
|
+
const SUBAGENT_LIFECYCLE_STATES = new Set(["queued", "running", "stale", "lost", "done", "failed", "cancelled"]);
|
|
23718
|
+
|
|
23719
|
+
function subagentLauncherLabel(value = "") {
|
|
23720
|
+
const launcher = String(value || "").trim();
|
|
23721
|
+
return SUBAGENT_LAUNCHER_LABELS[launcher] || launcher || "agent";
|
|
23722
|
+
}
|
|
23723
|
+
|
|
23724
|
+
function subagentAgentStatus(run = {}, agent = null) {
|
|
23725
|
+
const status = String(agent?.status || run?.status || "running").toLowerCase();
|
|
23726
|
+
return SUBAGENT_LIFECYCLE_STATES.has(status) ? status : status === "pending" ? "queued" : "running";
|
|
23727
|
+
}
|
|
23728
|
+
|
|
23729
|
+
function subagentIsWorkflowController(run = {}, agent = {}) {
|
|
23730
|
+
if (String(agent?.name || "").trim().toLowerCase() !== "workflow") return false;
|
|
23731
|
+
if (String(agent?.model || "").trim() || String(agent?.thinking || "").trim()) return false;
|
|
23732
|
+
const launcher = String(agent?.launcher || run?.launcher || "").trim();
|
|
23733
|
+
const legacyProvisional = run?.source === "foreground" && /(?:^|:)workflow$/i.test(String(agent?.id || ""));
|
|
23734
|
+
return launcher === "pi-subagents" || legacyProvisional;
|
|
23735
|
+
}
|
|
23736
|
+
|
|
23737
|
+
function subagentWorkflowController(run = {}) {
|
|
23738
|
+
return (Array.isArray(run?.agents) ? run.agents : []).find((agent) => subagentIsWorkflowController(run, agent)) || null;
|
|
23739
|
+
}
|
|
23740
|
+
|
|
23741
|
+
function subagentRunAgents(run = {}) {
|
|
23742
|
+
const controller = subagentWorkflowController(run);
|
|
23743
|
+
return (Array.isArray(run?.agents) ? run.agents : []).filter((agent) => agent !== controller);
|
|
23744
|
+
}
|
|
23745
|
+
|
|
23746
|
+
function subagentRunAgentCounts(runs = []) {
|
|
23747
|
+
return (Array.isArray(runs) ? runs : []).reduce((counts, run) => {
|
|
23748
|
+
for (const agent of subagentRunAgents(run)) {
|
|
23749
|
+
counts.total += 1;
|
|
23750
|
+
const status = subagentAgentStatus(run, agent);
|
|
23751
|
+
if (status === "running") counts.running += 1;
|
|
23752
|
+
if (status === "stale") counts.stale += 1;
|
|
23753
|
+
}
|
|
23754
|
+
return counts;
|
|
23755
|
+
}, { total: 0, running: 0, stale: 0 });
|
|
23756
|
+
}
|
|
23757
|
+
|
|
23758
|
+
function subagentRunPresentations(runs = []) {
|
|
23759
|
+
const presentations = [];
|
|
23760
|
+
let recoveredWorkflow = null;
|
|
23761
|
+
for (const run of Array.isArray(runs) ? runs : []) {
|
|
23762
|
+
const controller = subagentWorkflowController(run);
|
|
23763
|
+
const agents = subagentRunAgents(run).map((agent) => ({ run, agent }));
|
|
23764
|
+
if (controller) {
|
|
23765
|
+
const presentation = { run, controller, agents };
|
|
23766
|
+
presentations.push(presentation);
|
|
23767
|
+
const launcher = String(controller?.launcher || run?.launcher || "").trim();
|
|
23768
|
+
recoveredWorkflow = run?.source === "recovered" && launcher === "pi-subagents" ? presentation : null;
|
|
23769
|
+
continue;
|
|
23770
|
+
}
|
|
23771
|
+
const launcher = String(run?.launcher || "").trim();
|
|
23772
|
+
if (recoveredWorkflow && run?.source === "recovered" && launcher === "pi-subagents" && agents.length) {
|
|
23773
|
+
recoveredWorkflow.agents.push(...agents);
|
|
23774
|
+
continue;
|
|
23775
|
+
}
|
|
23776
|
+
recoveredWorkflow = null;
|
|
23777
|
+
presentations.push({ run, controller: null, agents });
|
|
23778
|
+
}
|
|
23779
|
+
return presentations;
|
|
23780
|
+
}
|
|
23781
|
+
|
|
23782
|
+
function subagentWorkflowPresentationStatus(run = {}, agents = []) {
|
|
23783
|
+
const statuses = [subagentAgentStatus(run), ...(Array.isArray(agents) ? agents : []).map((entry) => subagentAgentStatus(entry.run, entry.agent))];
|
|
23784
|
+
return ["running", "queued", "stale", "lost", "failed", "cancelled", "done"].find((status) => statuses.includes(status)) || "running";
|
|
23785
|
+
}
|
|
23786
|
+
|
|
23787
|
+
function subagentCapabilities(run = {}, agent = null) {
|
|
23788
|
+
const agentCapabilities = agent?.capabilities && typeof agent.capabilities === "object" ? agent.capabilities : null;
|
|
23789
|
+
const runCapabilities = run?.capabilities && typeof run.capabilities === "object" ? run.capabilities : null;
|
|
23790
|
+
return agentCapabilities || runCapabilities || null;
|
|
23791
|
+
}
|
|
23792
|
+
|
|
23793
|
+
function subagentOverviewGroups(data = latestSubagents) {
|
|
23794
|
+
const serverNow = Number(data?.updatedAt);
|
|
22486
23795
|
const now = Number.isFinite(serverNow) ? serverNow : Date.now();
|
|
22487
|
-
|
|
22488
|
-
.map((tab) =>
|
|
22489
|
-
|
|
22490
|
-
const
|
|
22491
|
-
|
|
22492
|
-
|
|
23796
|
+
if (Number(data?.version) === 2 && Array.isArray(data?.groups)) {
|
|
23797
|
+
const legacyTabs = new Map((Array.isArray(data.tabs) ? data.tabs : []).map((tab) => [tab.tabId, tab]));
|
|
23798
|
+
return data.groups.map((group, index) => {
|
|
23799
|
+
const legacy = legacyTabs.get(group.tabId) || {};
|
|
23800
|
+
const gates = visibleSubagentGates({ ...legacy, gates: group.gates || legacy.gates || [] }, dismissedSubagentGateKeys, now);
|
|
23801
|
+
const runs = Array.isArray(group.runs) ? group.runs : [];
|
|
23802
|
+
const agentCounts = subagentRunAgentCounts(runs);
|
|
23803
|
+
return {
|
|
23804
|
+
...legacy,
|
|
23805
|
+
...group,
|
|
23806
|
+
groupId: group.id,
|
|
23807
|
+
groupKind: group.kind,
|
|
23808
|
+
tabId: group.tabId || activeTabId || "external",
|
|
23809
|
+
tabIndex: group.tabIndex || legacy.tabIndex || index + 1,
|
|
23810
|
+
tabTitle: group.title || legacy.tabTitle || (group.kind === "external" ? "External agents" : `Terminal ${index + 1}`),
|
|
23811
|
+
sessionName: group.cwdLabel || legacy.sessionName || "registered agents",
|
|
23812
|
+
available: true,
|
|
23813
|
+
gates,
|
|
23814
|
+
gateCount: gates.length,
|
|
23815
|
+
displayRuns: runs,
|
|
23816
|
+
agentCount: agentCounts.total,
|
|
23817
|
+
runningAgents: agentCounts.running,
|
|
23818
|
+
staleAgents: agentCounts.stale,
|
|
23819
|
+
};
|
|
23820
|
+
});
|
|
23821
|
+
}
|
|
23822
|
+
return (Array.isArray(data?.tabs) ? data.tabs : []).map((tab) => {
|
|
23823
|
+
const gates = visibleSubagentGates(tab, dismissedSubagentGateKeys, now);
|
|
23824
|
+
const displayRuns = ungatedSubagentRuns(tab);
|
|
23825
|
+
const agentCounts = subagentRunAgentCounts(displayRuns);
|
|
23826
|
+
return {
|
|
23827
|
+
...tab,
|
|
23828
|
+
groupId: `tab:${tab.tabId}`,
|
|
23829
|
+
groupKind: "tab",
|
|
23830
|
+
gates,
|
|
23831
|
+
gateCount: gates.length,
|
|
23832
|
+
displayRuns,
|
|
23833
|
+
agentCount: agentCounts.total,
|
|
23834
|
+
runningAgents: agentCounts.running,
|
|
23835
|
+
staleAgents: agentCounts.stale,
|
|
23836
|
+
};
|
|
23837
|
+
});
|
|
23838
|
+
}
|
|
23839
|
+
|
|
23840
|
+
function subagentTabsWithRunningAgents() {
|
|
23841
|
+
return subagentOverviewGroups()
|
|
22493
23842
|
.filter((tab) => tab.displayRuns.length > 0 || Number(tab?.gateCount || 0) > 0)
|
|
22494
23843
|
.sort((a, b) => Number(a.tabIndex || 0) - Number(b.tabIndex || 0) || String(a.tabTitle || "").localeCompare(String(b.tabTitle || "")));
|
|
22495
23844
|
}
|
|
@@ -22511,9 +23860,14 @@ function subagentRunElapsed(run) {
|
|
|
22511
23860
|
}
|
|
22512
23861
|
|
|
22513
23862
|
function subagentSourceLabel(source = "") {
|
|
23863
|
+
if (source === "recovered") return "recovered active child";
|
|
22514
23864
|
return source === "foreground" || source === "workflow" ? source : "async";
|
|
22515
23865
|
}
|
|
22516
23866
|
|
|
23867
|
+
function subagentRunSupportsInteraction(run = {}) {
|
|
23868
|
+
return run?.source !== "recovered" && run?.provisional !== true && run?.controllable !== false;
|
|
23869
|
+
}
|
|
23870
|
+
|
|
22517
23871
|
function subagentExecutionValues(agent = {}) {
|
|
22518
23872
|
const thinking = String(agent?.thinking || "").trim();
|
|
22519
23873
|
let model = String(agent?.model || "").trim();
|
|
@@ -22540,20 +23894,45 @@ function subagentGateAttemptViewFacts(attempt) {
|
|
|
22540
23894
|
}
|
|
22541
23895
|
|
|
22542
23896
|
function subagentRunIsRunning(run = {}, agent = null) {
|
|
22543
|
-
|
|
22544
|
-
|
|
22545
|
-
|
|
23897
|
+
return ["queued", "running"].includes(subagentAgentStatus(run, agent));
|
|
23898
|
+
}
|
|
23899
|
+
|
|
23900
|
+
function subagentRunIsTerminal(run = {}, agent = null) {
|
|
23901
|
+
return ["done", "failed", "cancelled"].includes(subagentAgentStatus(run, agent));
|
|
23902
|
+
}
|
|
23903
|
+
|
|
23904
|
+
function subagentRunIsAttachedProjection(run = {}) {
|
|
23905
|
+
return run?.provider === "webui-registry"
|
|
23906
|
+
&& run?.source === "explicit-attach"
|
|
23907
|
+
&& ["stale", "lost"].includes(subagentAgentStatus(run));
|
|
23908
|
+
}
|
|
23909
|
+
|
|
23910
|
+
function subagentRunCanOpen(run = {}, agent = null) {
|
|
23911
|
+
const capabilities = subagentCapabilities(run, agent);
|
|
23912
|
+
return capabilities ? capabilities.open === true : subagentRunSupportsInteraction(run);
|
|
23913
|
+
}
|
|
23914
|
+
|
|
23915
|
+
function subagentRunCanRefresh(run = {}, agent = null) {
|
|
23916
|
+
const capabilities = subagentCapabilities(run, agent);
|
|
23917
|
+
return capabilities ? capabilities.refresh === true : subagentRunSupportsInteraction(run);
|
|
22546
23918
|
}
|
|
22547
23919
|
|
|
22548
23920
|
function subagentRunCanCancel(run = {}, agent = null) {
|
|
22549
|
-
|
|
23921
|
+
const capabilities = subagentCapabilities(run, agent);
|
|
23922
|
+
return capabilities ? capabilities.cancel === true && subagentRunIsRunning(run, agent) : subagentRunSupportsInteraction(run) && run?.source !== "workflow" && subagentRunIsRunning(run, agent);
|
|
23923
|
+
}
|
|
23924
|
+
|
|
23925
|
+
function subagentRunCanDismiss(run = {}) {
|
|
23926
|
+
if (subagentRunIsAttachedProjection(run)) return true;
|
|
23927
|
+
if (!subagentRunIsTerminal(run)) return false;
|
|
23928
|
+
if (run?.provider === "webui-registry") return true;
|
|
23929
|
+
const capabilities = subagentCapabilities(run);
|
|
23930
|
+
return capabilities ? capabilities.open === true && ["webui-helper", "pi-subagents"].includes(run.provider) : run?.source !== "workflow" && subagentRunSupportsInteraction(run);
|
|
22550
23931
|
}
|
|
22551
23932
|
|
|
22552
|
-
function subagentRunStateLabel(run = {}) {
|
|
22553
|
-
|
|
22554
|
-
|
|
22555
|
-
if (run?.status === "done") return "done";
|
|
22556
|
-
return "running";
|
|
23933
|
+
function subagentRunStateLabel(run = {}, agent = null) {
|
|
23934
|
+
const status = subagentAgentStatus(run, agent);
|
|
23935
|
+
return status === "cancelled" ? "cancelled" : status;
|
|
22557
23936
|
}
|
|
22558
23937
|
|
|
22559
23938
|
function setSubagentCancelStatus(message = "", level = "muted") {
|
|
@@ -22578,11 +23957,13 @@ function subagentCancelTargetLabel(selection = subagentCancelSelection) {
|
|
|
22578
23957
|
}
|
|
22579
23958
|
|
|
22580
23959
|
function openSubagentCancelDialog(tab, run, agent = null) {
|
|
22581
|
-
if (!tab?.
|
|
22582
|
-
const agentCount =
|
|
23960
|
+
if (!tab?.groupId || !run?.id || !subagentRunCanCancel(run, agent) || !elements.subagentCancelDialog) return;
|
|
23961
|
+
const agentCount = subagentRunAgents(run).length;
|
|
22583
23962
|
subagentCancelSelection = {
|
|
23963
|
+
groupId: tab.groupId,
|
|
22584
23964
|
tabId: tab.tabId,
|
|
22585
23965
|
runId: run.id,
|
|
23966
|
+
agentId: agent?.instanceId || agent?.id || "",
|
|
22586
23967
|
agentCount,
|
|
22587
23968
|
};
|
|
22588
23969
|
if (elements.subagentCancelDialogSubtitle) {
|
|
@@ -22614,8 +23995,9 @@ async function submitSubagentCancel() {
|
|
|
22614
23995
|
method: "POST",
|
|
22615
23996
|
scoped: false,
|
|
22616
23997
|
body: {
|
|
22617
|
-
|
|
23998
|
+
group: selection.groupId,
|
|
22618
23999
|
runId: selection.runId,
|
|
24000
|
+
...(selection.agentId ? { agentId: selection.agentId } : {}),
|
|
22619
24001
|
...(reason ? { reason } : {}),
|
|
22620
24002
|
...(note ? { note } : {}),
|
|
22621
24003
|
},
|
|
@@ -22634,14 +24016,15 @@ async function submitSubagentCancel() {
|
|
|
22634
24016
|
}
|
|
22635
24017
|
|
|
22636
24018
|
async function dismissSubagentRun(tab, run) {
|
|
22637
|
-
if (!tab?.
|
|
24019
|
+
if (!tab?.groupId || !run?.id || !subagentRunCanDismiss(run)) return;
|
|
24020
|
+
const attachedProjection = subagentRunIsAttachedProjection(run);
|
|
22638
24021
|
try {
|
|
22639
24022
|
await api("/api/subagents/dismiss", {
|
|
22640
24023
|
method: "POST",
|
|
22641
24024
|
scoped: false,
|
|
22642
|
-
body: {
|
|
24025
|
+
body: { group: tab.groupId, runId: run.id },
|
|
22643
24026
|
});
|
|
22644
|
-
addEvent(`dismissed finished subagent run ${run.id}`, "info");
|
|
24027
|
+
addEvent(attachedProjection ? `detached persisted session projection ${run.id}` : `dismissed finished subagent run ${run.id}`, "info");
|
|
22645
24028
|
await refreshSubagents();
|
|
22646
24029
|
scheduleRefreshSubagents();
|
|
22647
24030
|
} catch (error) {
|
|
@@ -22650,12 +24033,10 @@ async function dismissSubagentRun(tab, run) {
|
|
|
22650
24033
|
}
|
|
22651
24034
|
|
|
22652
24035
|
function finishedSubagentRunSelections(data = latestSubagents) {
|
|
22653
|
-
return (
|
|
22654
|
-
|
|
22655
|
-
|
|
22656
|
-
|
|
22657
|
-
.filter((selection) => selection.tabId && selection.runId)
|
|
22658
|
-
));
|
|
24036
|
+
return subagentOverviewGroups(data).flatMap((tab) => tab.displayRuns
|
|
24037
|
+
.filter((run) => subagentRunIsTerminal(run) && subagentRunCanDismiss(run))
|
|
24038
|
+
.map((run) => ({ groupId: tab.groupId, runId: run.id }))
|
|
24039
|
+
.filter((selection) => selection.groupId && selection.runId));
|
|
22659
24040
|
}
|
|
22660
24041
|
|
|
22661
24042
|
async function clearFinishedSubagentRuns({ automatic = false } = {}) {
|
|
@@ -22673,7 +24054,7 @@ async function clearFinishedSubagentRuns({ automatic = false } = {}) {
|
|
|
22673
24054
|
await api("/api/subagents/dismiss", {
|
|
22674
24055
|
method: "POST",
|
|
22675
24056
|
scoped: false,
|
|
22676
|
-
body: {
|
|
24057
|
+
body: { group: selection.groupId, runId: selection.runId },
|
|
22677
24058
|
});
|
|
22678
24059
|
dismissed += 1;
|
|
22679
24060
|
} catch (error) {
|
|
@@ -22883,7 +24264,7 @@ function renderSubagentOverlayWidget() {
|
|
|
22883
24264
|
const transcriptMessages = subagentOverlayTranscriptMessages(data);
|
|
22884
24265
|
const hasStructuredTranscript = transcriptMessages.length > 0;
|
|
22885
24266
|
const outputText = subagentOverlayOutputText(data);
|
|
22886
|
-
const fallbackText = outputText || (running && agent.currentTool ? "" : running ? "Waiting for the first agent activity…" : "No recent output was captured.");
|
|
24267
|
+
const fallbackText = outputText || agent.unavailableReason || (agent.unavailable ? "Output is unavailable for this registered agent." : running && agent.currentTool ? "" : running ? "Waiting for the first agent activity…" : "No recent output was captured.");
|
|
22887
24268
|
const shownLineCount = outputText ? outputText.split("\n").length : fallbackText ? fallbackText.split("\n").length : 0;
|
|
22888
24269
|
const widget = make("section", `widget release-npm-widget app-runner-widget subagent-overlay-widget${running ? " app-runner-live-widget" : " app-runner-log-widget"}`);
|
|
22889
24270
|
widget.setAttribute("aria-label", `Live output for subagent ${agent.name || "subagent"}`);
|
|
@@ -22925,11 +24306,13 @@ function renderSubagentOverlayWidget() {
|
|
|
22925
24306
|
}, "subagent-overlay-refresh-action");
|
|
22926
24307
|
refreshButton.disabled = subagentOverlayLoading || selection.finished;
|
|
22927
24308
|
if (subagentRunCanCancel(selection.run, agent)) {
|
|
22928
|
-
actions.append(appRunnerActionButton("Cancel…", () => openSubagentCancelDialog(tab, selection.run, agent), "subagent-overlay-cancel-action danger"));
|
|
24309
|
+
actions.append(appRunnerActionButton("Cancel…", () => openSubagentCancelDialog(selection.tab, selection.run, agent), "subagent-overlay-cancel-action danger"));
|
|
22929
24310
|
}
|
|
22930
|
-
actions.append(copyButton
|
|
24311
|
+
actions.append(copyButton);
|
|
24312
|
+
if (subagentRunCanRefresh(selection.run, agent)) actions.append(refreshButton);
|
|
24313
|
+
actions.append(appRunnerActionButton("Close", closeSubagentOverlay, "subagent-overlay-close-action"));
|
|
22931
24314
|
const details = [
|
|
22932
|
-
`${tab?.title || `Terminal ${selection.tabIndex || "?"}`} · run ${selection.runId}`,
|
|
24315
|
+
`${selection.tab?.tabTitle || tab?.title || `Terminal ${selection.tabIndex || "?"}`} · run ${selection.runId}`,
|
|
22933
24316
|
agent.currentPath ? `path: ${agent.currentPath}` : "",
|
|
22934
24317
|
agent.activityState ? `activity: ${agent.activityState}` : "",
|
|
22935
24318
|
agent.error ? `status warning: ${agent.error}` : "",
|
|
@@ -22960,7 +24343,7 @@ async function refreshSubagentOverlay() {
|
|
|
22960
24343
|
const previousSignature = subagentOverlayMeaningfulSignature();
|
|
22961
24344
|
subagentOverlayLoading = true;
|
|
22962
24345
|
try {
|
|
22963
|
-
const query = new URLSearchParams({
|
|
24346
|
+
const query = new URLSearchParams({ group: selection.groupId, run: selection.runId, agent: selection.agentId });
|
|
22964
24347
|
const response = await api(`/api/subagents/output?${query}`, { scoped: false });
|
|
22965
24348
|
if (requestSerial !== subagentOverlayRequestSerial || subagentOverlaySelection !== selection) return;
|
|
22966
24349
|
subagentOverlayData = response.data || null;
|
|
@@ -22980,11 +24363,12 @@ async function refreshSubagentOverlay() {
|
|
|
22980
24363
|
}
|
|
22981
24364
|
|
|
22982
24365
|
async function openSubagentOverlay(tab, run, agent) {
|
|
22983
|
-
if (!tab?.
|
|
24366
|
+
if (!tab?.groupId || !run?.id || !agent?.id || !subagentRunCanOpen(run, agent)) return;
|
|
22984
24367
|
if (activeSubagentTerminalId) deactivateSubagentTerminalView({ render: false });
|
|
22985
24368
|
try {
|
|
22986
24369
|
if (activeTabId !== tab.tabId) await switchTab(tab.tabId);
|
|
22987
24370
|
subagentOverlaySelection = {
|
|
24371
|
+
groupId: tab.groupId,
|
|
22988
24372
|
tabId: tab.tabId,
|
|
22989
24373
|
tabIndex: tab.tabIndex,
|
|
22990
24374
|
tab,
|
|
@@ -23062,6 +24446,7 @@ function updateSubagentTerminalRefreshState(view, { running = subagentTerminalVi
|
|
|
23062
24446
|
elements.subagentTerminalStatus.setAttribute("aria-live", view.error ? "polite" : "off");
|
|
23063
24447
|
elements.subagentTerminalStatus.textContent = status;
|
|
23064
24448
|
elements.subagentTerminalStatus.classList.toggle("warning", !!view.error);
|
|
24449
|
+
elements.subagentTerminalRefreshButton.hidden = !subagentRunCanRefresh(view.run, view.data?.agent || view.agent);
|
|
23065
24450
|
elements.subagentTerminalRefreshButton.disabled = view.loading || view.finished === true;
|
|
23066
24451
|
elements.subagentTerminalRefreshButton.textContent = view.loading ? "Refreshing…" : "Refresh";
|
|
23067
24452
|
}
|
|
@@ -23112,7 +24497,7 @@ function renderSubagentTerminalView() {
|
|
|
23112
24497
|
const transcriptMessages = subagentOverlayTranscriptMessages({ agent });
|
|
23113
24498
|
const hasStructuredTranscript = transcriptMessages.length > 0;
|
|
23114
24499
|
const outputText = subagentOverlayOutputText({ agent });
|
|
23115
|
-
const fallbackText = outputText || (running && agent.currentTool ? "" : running ? "Waiting for the first agent activity…" : "No recent output was captured.");
|
|
24500
|
+
const fallbackText = outputText || agent.unavailableReason || (agent.unavailable ? "Output is unavailable for this registered agent." : running && agent.currentTool ? "" : running ? "Waiting for the first agent activity…" : "No recent output was captured.");
|
|
23116
24501
|
const parent = tabs.find((tab) => tab.id === view.parentTabId);
|
|
23117
24502
|
const elapsed = subagentRunElapsed(view.run);
|
|
23118
24503
|
const facts = [
|
|
@@ -23150,6 +24535,7 @@ function renderSubagentTerminalView() {
|
|
|
23150
24535
|
if (running) appendSubagentRunIndicator(elements.subagentTerminalTranscript, { agent, run: view.run });
|
|
23151
24536
|
|
|
23152
24537
|
updateSubagentTerminalRefreshState(view, { running });
|
|
24538
|
+
elements.subagentTerminalCopyButton.hidden = !outputText;
|
|
23153
24539
|
elements.subagentTerminalCopyButton.disabled = !outputText;
|
|
23154
24540
|
if (elements.subagentTerminalCancelButton) {
|
|
23155
24541
|
const cancellable = subagentRunCanCancel(view.run, agent);
|
|
@@ -23178,7 +24564,7 @@ async function refreshSubagentTerminalView(viewId = activeSubagentTerminalId, {
|
|
|
23178
24564
|
view.loading = true;
|
|
23179
24565
|
if (showLoading) updateSubagentTerminalRefreshState(view);
|
|
23180
24566
|
try {
|
|
23181
|
-
const query = new URLSearchParams({
|
|
24567
|
+
const query = new URLSearchParams({ group: view.groupId, run: view.runId, agent: view.agentId });
|
|
23182
24568
|
const response = await api(`/api/subagents/output?${query}`, { scoped: false });
|
|
23183
24569
|
if (view.requestSerial !== requestSerial || !subagentTerminalViews.has(view.id)) return;
|
|
23184
24570
|
view.data = response.data || null;
|
|
@@ -23233,10 +24619,11 @@ async function activateSubagentTerminalView(viewId) {
|
|
|
23233
24619
|
}
|
|
23234
24620
|
|
|
23235
24621
|
function ensureSubagentTerminalView(tab, run, agent) {
|
|
23236
|
-
if (!tab?.tabId || !run?.id || !agent?.id) return null;
|
|
24622
|
+
if (!tab?.groupId || !tab?.tabId || !run?.id || !agent?.id || !subagentRunCanOpen(run, agent)) return null;
|
|
23237
24623
|
const id = subagentTerminalViewId(tab, run, agent);
|
|
23238
24624
|
const existing = subagentTerminalViews.get(id);
|
|
23239
24625
|
if (existing) {
|
|
24626
|
+
existing.groupId = tab.groupId;
|
|
23240
24627
|
existing.tab = tab;
|
|
23241
24628
|
existing.run = run;
|
|
23242
24629
|
existing.agent = agent;
|
|
@@ -23246,6 +24633,7 @@ function ensureSubagentTerminalView(tab, run, agent) {
|
|
|
23246
24633
|
}
|
|
23247
24634
|
const view = {
|
|
23248
24635
|
id,
|
|
24636
|
+
groupId: tab.groupId,
|
|
23249
24637
|
parentTabId: tab.tabId,
|
|
23250
24638
|
parentTitle: tab.tabTitle,
|
|
23251
24639
|
tabIndex: tab.tabIndex,
|
|
@@ -23267,6 +24655,7 @@ function ensureSubagentTerminalView(tab, run, agent) {
|
|
|
23267
24655
|
}
|
|
23268
24656
|
|
|
23269
24657
|
async function openSubagentTerminal(tab, run, agent) {
|
|
24658
|
+
if (!subagentRunCanOpen(run, agent)) return;
|
|
23270
24659
|
const view = ensureSubagentTerminalView(tab, run, agent);
|
|
23271
24660
|
if (!view) return;
|
|
23272
24661
|
try {
|
|
@@ -23328,10 +24717,17 @@ function removeSubagentTerminalViewsForParent(parentTabId) {
|
|
|
23328
24717
|
|
|
23329
24718
|
function syncSubagentTerminalViewsFromOverview() {
|
|
23330
24719
|
let changed = false;
|
|
23331
|
-
const overviewTabs =
|
|
23332
|
-
for (const view of subagentTerminalViews.values()) {
|
|
23333
|
-
const tab = overviewTabs.find((candidate) => candidate.
|
|
24720
|
+
const overviewTabs = subagentOverviewGroups();
|
|
24721
|
+
for (const view of [...subagentTerminalViews.values()]) {
|
|
24722
|
+
const tab = overviewTabs.find((candidate) => candidate.groupId === view.groupId);
|
|
23334
24723
|
const run = (Array.isArray(tab?.runs) ? tab.runs : []).find((candidate) => candidate.id === view.runId);
|
|
24724
|
+
if (run && !subagentRunCanOpen(run, (Array.isArray(run.agents) ? run.agents : []).find((candidate) => candidate.id === view.agentId))) {
|
|
24725
|
+
view.requestSerial += 1;
|
|
24726
|
+
subagentTerminalViews.delete(view.id);
|
|
24727
|
+
if (activeSubagentTerminalId === view.id) activeSubagentTerminalId = null;
|
|
24728
|
+
changed = true;
|
|
24729
|
+
continue;
|
|
24730
|
+
}
|
|
23335
24731
|
const agent = (Array.isArray(run?.agents) ? run.agents : []).find((candidate) => candidate.id === view.agentId);
|
|
23336
24732
|
if (tab) {
|
|
23337
24733
|
view.tab = tab;
|
|
@@ -23350,18 +24746,29 @@ function syncSubagentTerminalViewsFromOverview() {
|
|
|
23350
24746
|
}
|
|
23351
24747
|
const selection = subagentOverlaySelection;
|
|
23352
24748
|
if (selection) {
|
|
23353
|
-
const tab = overviewTabs.find((candidate) => candidate.
|
|
24749
|
+
const tab = overviewTabs.find((candidate) => candidate.groupId === selection.groupId);
|
|
23354
24750
|
const run = (Array.isArray(tab?.runs) ? tab.runs : []).find((candidate) => candidate.id === selection.runId);
|
|
23355
|
-
|
|
23356
|
-
|
|
23357
|
-
|
|
23358
|
-
|
|
23359
|
-
|
|
23360
|
-
|
|
23361
|
-
|
|
23362
|
-
|
|
23363
|
-
if (subagentOverlayData?.agent) subagentOverlayData = { ...subagentOverlayData, agent: { ...subagentOverlayData.agent, ...agent } };
|
|
24751
|
+
if (run && !subagentRunCanOpen(run, (Array.isArray(run.agents) ? run.agents : []).find((candidate) => candidate.id === selection.agentId))) {
|
|
24752
|
+
clearTimeout(subagentOverlayRefreshTimer);
|
|
24753
|
+
subagentOverlayRefreshTimer = null;
|
|
24754
|
+
subagentOverlayRequestSerial += 1;
|
|
24755
|
+
subagentOverlaySelection = null;
|
|
24756
|
+
subagentOverlayData = null;
|
|
24757
|
+
subagentOverlayError = "";
|
|
24758
|
+
subagentOverlayLoading = false;
|
|
23364
24759
|
changed = true;
|
|
24760
|
+
} else {
|
|
24761
|
+
const agent = (Array.isArray(run?.agents) ? run.agents : []).find((candidate) => candidate.id === selection.agentId);
|
|
24762
|
+
if (tab) selection.tab = tab;
|
|
24763
|
+
if (run) {
|
|
24764
|
+
selection.run = run;
|
|
24765
|
+
changed = true;
|
|
24766
|
+
}
|
|
24767
|
+
if (agent) {
|
|
24768
|
+
selection.agent = agent;
|
|
24769
|
+
if (subagentOverlayData?.agent) subagentOverlayData = { ...subagentOverlayData, agent: { ...subagentOverlayData.agent, ...agent } };
|
|
24770
|
+
changed = true;
|
|
24771
|
+
}
|
|
23365
24772
|
}
|
|
23366
24773
|
}
|
|
23367
24774
|
return changed;
|
|
@@ -23370,14 +24777,14 @@ function syncSubagentTerminalViewsFromOverview() {
|
|
|
23370
24777
|
function materializeRetainedSubagentTerminalViews() {
|
|
23371
24778
|
if (subagentOpenMode !== "tab") return false;
|
|
23372
24779
|
let materialized = false;
|
|
23373
|
-
for (const tab of
|
|
24780
|
+
for (const tab of subagentOverviewGroups()) {
|
|
23374
24781
|
if (tab?.available !== true || !tab?.tabId) continue;
|
|
23375
24782
|
const restoreKey = `${tab.tabId}\u0000${tab.sessionFile || ""}`;
|
|
23376
24783
|
if (subagentTerminalRestoredParentTabs.has(restoreKey)) continue;
|
|
23377
24784
|
subagentTerminalRestoredParentTabs.add(restoreKey);
|
|
23378
|
-
for (const run of
|
|
23379
|
-
if (
|
|
23380
|
-
for (const agent of
|
|
24785
|
+
for (const run of tab.displayRuns) {
|
|
24786
|
+
if (["queued", "running", "stale"].includes(subagentAgentStatus(run)) || run?.source === "workflow") continue;
|
|
24787
|
+
for (const agent of subagentRunAgents(run)) {
|
|
23381
24788
|
const id = subagentTerminalViewId(tab, run, agent);
|
|
23382
24789
|
if (subagentTerminalViews.has(id)) continue;
|
|
23383
24790
|
if (ensureSubagentTerminalView(tab, run, agent)) materialized = true;
|
|
@@ -23514,42 +24921,90 @@ function renderSubagentTerminalTabGroup(group) {
|
|
|
23514
24921
|
}
|
|
23515
24922
|
|
|
23516
24923
|
function openSubagentOutput(tab, run, agent) {
|
|
24924
|
+
if (!subagentRunCanOpen(run, agent)) return;
|
|
23517
24925
|
return subagentOpenMode === "tab" ? openSubagentTerminal(tab, run, agent) : openSubagentOverlay(tab, run, agent);
|
|
23518
24926
|
}
|
|
23519
24927
|
|
|
24928
|
+
function subagentWorkflowRunKey(tab, run) {
|
|
24929
|
+
return `${tab?.groupId || tab?.tabId || ""}:${run?.id || ""}`;
|
|
24930
|
+
}
|
|
24931
|
+
|
|
24932
|
+
function renderSubagentWorkflow(tab, run, controller, agents) {
|
|
24933
|
+
const status = subagentWorkflowPresentationStatus(run, agents);
|
|
24934
|
+
const key = subagentWorkflowRunKey(tab, run);
|
|
24935
|
+
const details = make("details", `subagent-workflow state-${status}`);
|
|
24936
|
+
details.open = !collapsedSubagentWorkflowRunKeys.has(key);
|
|
24937
|
+
details.addEventListener("toggle", () => {
|
|
24938
|
+
if (details.open) collapsedSubagentWorkflowRunKeys.delete(key);
|
|
24939
|
+
else collapsedSubagentWorkflowRunKeys.add(key);
|
|
24940
|
+
});
|
|
24941
|
+
|
|
24942
|
+
const summary = make("summary", "subagent-workflow-header");
|
|
24943
|
+
summary.dataset.subagentContinuityKey = `workflow:${tab?.tabId || ""}:${run?.id || ""}`;
|
|
24944
|
+
summary.setAttribute("aria-label", `Workflow ${status}, ${agents.length} ${agents.length === 1 ? "agent" : "agents"}`);
|
|
24945
|
+
const dot = make("span", `subagent-state-dot ${status}`);
|
|
24946
|
+
dot.setAttribute("aria-hidden", "true");
|
|
24947
|
+
const identity = make("span", "subagent-agent-identity");
|
|
24948
|
+
identity.append(
|
|
24949
|
+
make("strong", "subagent-workflow-name", "Workflow"),
|
|
24950
|
+
make("span", "subagent-source-badge", subagentLauncherLabel(controller?.launcher || run?.launcher)),
|
|
24951
|
+
make("span", "subagent-agent-inline-meta", `· ${status} · ${agents.length} ${agents.length === 1 ? "agent" : "agents"}`),
|
|
24952
|
+
);
|
|
24953
|
+
summary.append(dot, identity);
|
|
24954
|
+
|
|
24955
|
+
const children = make("div", "subagent-workflow-agents");
|
|
24956
|
+
for (const entry of agents) children.append(renderSubagentAgent(tab, entry.run, entry.agent));
|
|
24957
|
+
if (!children.childElementCount) children.append(make("div", "subagents-empty", "Waiting for workflow agents…"));
|
|
24958
|
+
details.append(summary, children);
|
|
24959
|
+
return details;
|
|
24960
|
+
}
|
|
24961
|
+
|
|
23520
24962
|
function renderSubagentAgent(tab, run, agent) {
|
|
23521
|
-
const
|
|
24963
|
+
const status = subagentAgentStatus(run, agent);
|
|
24964
|
+
const running = ["queued", "running"].includes(status);
|
|
24965
|
+
const interactive = subagentRunCanOpen(run, agent);
|
|
23522
24966
|
const name = agent?.name || "subagent";
|
|
23523
24967
|
const [model, thinking] = subagentExecutionValues(agent);
|
|
23524
|
-
const
|
|
23525
|
-
row
|
|
24968
|
+
const launcher = subagentLauncherLabel(agent?.launcher || run?.launcher);
|
|
24969
|
+
const row = make(interactive ? "button" : "div", `subagent-agent-row state-${status}${agent?.nested ? " nested" : ""}${running ? " running" : " finished"}${interactive ? "" : " metadata-only"}`);
|
|
24970
|
+
if (interactive) row.type = "button";
|
|
23526
24971
|
row.dataset.subagentContinuityKey = `agent:${tab?.tabId || ""}:${run?.id || ""}:${agent?.id || ""}`;
|
|
23527
|
-
const dot = make("span",
|
|
24972
|
+
const dot = make("span", `subagent-state-dot ${status}`);
|
|
23528
24973
|
dot.setAttribute("aria-hidden", "true");
|
|
23529
24974
|
const identity = make("span", "subagent-agent-identity");
|
|
23530
24975
|
identity.append(
|
|
23531
24976
|
make("strong", "subagent-agent-name", name),
|
|
23532
|
-
make("span", "subagent-
|
|
24977
|
+
make("span", "subagent-source-badge", launcher),
|
|
24978
|
+
make("span", "subagent-agent-inline-meta", `· ${status} · ${model} · ${thinking}`),
|
|
23533
24979
|
);
|
|
23534
|
-
|
|
23535
|
-
|
|
23536
|
-
|
|
23537
|
-
|
|
23538
|
-
|
|
23539
|
-
|
|
23540
|
-
|
|
24980
|
+
row.append(dot, identity);
|
|
24981
|
+
if (interactive) {
|
|
24982
|
+
const open = make("span", "subagent-agent-open", "›");
|
|
24983
|
+
open.setAttribute("aria-hidden", "true");
|
|
24984
|
+
row.append(open);
|
|
24985
|
+
const destination = subagentOpenMode === "tab" ? "subagent tab" : "output overlay";
|
|
24986
|
+
row.title = `${name} · ${launcher} · ${status} · ${model} · ${thinking} · open ${destination}`;
|
|
24987
|
+
row.setAttribute("aria-label", `Open ${destination} for ${name}, launched by ${launcher}, ${status}, model ${model}, reasoning ${thinking}, in ${tab?.tabTitle || `Terminal ${tab?.tabIndex || "?"}`}`);
|
|
24988
|
+
row.addEventListener("click", () => openSubagentOutput(tab, run, agent));
|
|
24989
|
+
} else {
|
|
24990
|
+
row.title = `${name} · ${launcher} · ${status} · output is unavailable from this provider`;
|
|
24991
|
+
row.setAttribute("aria-label", `${name}, launched by ${launcher}, ${status}; output and controls are unavailable from this provider`);
|
|
24992
|
+
}
|
|
23541
24993
|
return row;
|
|
23542
24994
|
}
|
|
23543
24995
|
|
|
23544
|
-
function renderSubagentRun(tab, run) {
|
|
24996
|
+
function renderSubagentRun(tab, run, workflowAgents = null) {
|
|
23545
24997
|
const running = subagentRunIsRunning(run);
|
|
23546
24998
|
const card = make("section", `subagent-run ${running ? "running" : run?.status || "done"}`);
|
|
23547
|
-
const
|
|
24999
|
+
const controller = subagentWorkflowController(run);
|
|
25000
|
+
const agents = subagentRunAgents(run)
|
|
23548
25001
|
.slice()
|
|
23549
25002
|
.sort((a, b) => Number(a.index || 0) - Number(b.index || 0) || String(a.name || "").localeCompare(String(b.name || "")));
|
|
23550
|
-
|
|
25003
|
+
const presentedAgents = controller && Array.isArray(workflowAgents) ? workflowAgents : agents.map((agent) => ({ run, agent }));
|
|
25004
|
+
card.setAttribute("aria-label", `${controller ? "Workflow" : "Subagent"} run with ${presentedAgents.length} ${presentedAgents.length === 1 ? "agent" : "agents"}`);
|
|
23551
25005
|
const list = make("div", "subagent-run-agents");
|
|
23552
|
-
|
|
25006
|
+
if (controller) list.append(renderSubagentWorkflow(tab, run, controller, presentedAgents));
|
|
25007
|
+
else for (const agent of agents) list.append(renderSubagentAgent(tab, run, agent));
|
|
23553
25008
|
if (!list.childElementCount) list.append(make("div", "subagents-empty", "No agents were captured."));
|
|
23554
25009
|
card.append(list);
|
|
23555
25010
|
|
|
@@ -23561,11 +25016,12 @@ function renderSubagentRun(tab, run) {
|
|
|
23561
25016
|
applyStyledTooltip(cancel, "Cancel entire subagent run…", { ariaLabel: "Cancel entire subagent run" });
|
|
23562
25017
|
cancel.addEventListener("click", () => openSubagentCancelDialog(tab, run));
|
|
23563
25018
|
actions.append(cancel);
|
|
23564
|
-
} else if (
|
|
25019
|
+
} else if (subagentRunCanDismiss(run)) {
|
|
23565
25020
|
const dismiss = make("button", "subagent-run-dismiss", "×");
|
|
23566
25021
|
dismiss.type = "button";
|
|
23567
25022
|
dismiss.dataset.subagentContinuityKey = `run:${tab?.tabId || ""}:${run?.id || ""}:dismiss`;
|
|
23568
|
-
|
|
25023
|
+
const dismissLabel = subagentRunIsAttachedProjection(run) ? "Detach persisted session from WebUI" : "Dismiss finished run";
|
|
25024
|
+
applyStyledTooltip(dismiss, dismissLabel, { ariaLabel: dismissLabel });
|
|
23569
25025
|
dismiss.addEventListener("click", () => dismissSubagentRun(tab, run));
|
|
23570
25026
|
actions.append(dismiss);
|
|
23571
25027
|
}
|
|
@@ -23578,13 +25034,13 @@ function subagentGateStatusLabel(status) {
|
|
|
23578
25034
|
}
|
|
23579
25035
|
|
|
23580
25036
|
function subagentGateAttemptTarget(tab, attempt) {
|
|
23581
|
-
if (!tab?.
|
|
23582
|
-
const run = (Array.isArray(tab.
|
|
25037
|
+
if (!tab?.groupId || !attempt?.runId) return null;
|
|
25038
|
+
const run = (Array.isArray(tab.displayRuns) ? tab.displayRuns : []).find((candidate) => candidate?.id === attempt.runId);
|
|
23583
25039
|
if (!run) return null;
|
|
23584
25040
|
const agents = Array.isArray(run.agents) ? run.agents : [];
|
|
23585
|
-
let agent = agents.find((candidate) => candidate?.name === attempt.agent);
|
|
25041
|
+
let agent = agents.find((candidate) => candidate?.id === attempt.instanceId || candidate?.instanceId === attempt.instanceId || candidate?.name === attempt.agent);
|
|
23586
25042
|
if (!agent && agents.length === 1) [agent] = agents;
|
|
23587
|
-
return agent?.id ? { run, agent } : null;
|
|
25043
|
+
return agent?.id && subagentRunCanOpen(run, agent) ? { run, agent } : null;
|
|
23588
25044
|
}
|
|
23589
25045
|
|
|
23590
25046
|
function subagentGateAttemptExecutionValues(attempt = {}) {
|
|
@@ -23664,32 +25120,37 @@ function renderSubagentGate(tab, gate) {
|
|
|
23664
25120
|
}
|
|
23665
25121
|
|
|
23666
25122
|
function renderSubagentTabGroup(tab) {
|
|
23667
|
-
const
|
|
23668
|
-
const
|
|
23669
|
-
header
|
|
25123
|
+
const isExternal = tab.groupKind === "external";
|
|
25124
|
+
const group = make("section", `subagent-tab-group${isExternal ? " external" : ""}${tab.tabId === activeTabId && !isExternal ? " active" : ""}`);
|
|
25125
|
+
const header = make(isExternal ? "div" : "button", "subagent-tab-header");
|
|
25126
|
+
if (!isExternal) header.type = "button";
|
|
23670
25127
|
header.dataset.subagentContinuityKey = `tab:${tab?.tabId || ""}`;
|
|
23671
|
-
header.setAttribute("aria-label", `Open ${tab.tabTitle || `Terminal ${tab.tabIndex || ""}`}`);
|
|
25128
|
+
if (!isExternal) header.setAttribute("aria-label", `Open ${tab.tabTitle || `Terminal ${tab.tabIndex || ""}`}`);
|
|
23672
25129
|
const title = make("span", "subagent-tab-title");
|
|
23673
25130
|
title.append(
|
|
23674
25131
|
make("strong", undefined, tab.tabTitle || `Terminal ${tab.tabIndex || "?"}`),
|
|
23675
|
-
make("span", "subagent-tab-session", `Terminal ${tab.tabIndex || "?"} · ${subagentTabMeta(tab)}`),
|
|
25132
|
+
make("span", "subagent-tab-session", isExternal ? "Registered outside open WebUI tabs" : `Terminal ${tab.tabIndex || "?"} · ${subagentTabMeta(tab)}`),
|
|
23676
25133
|
);
|
|
23677
25134
|
const runs = (Array.isArray(tab.displayRuns) ? tab.displayRuns : ungatedSubagentRuns(tab))
|
|
23678
25135
|
.slice()
|
|
23679
25136
|
.sort((a, b) => Number(a.startedAt || 0) - Number(b.startedAt || 0) || String(a.id || "").localeCompare(String(b.id || "")));
|
|
23680
|
-
const
|
|
23681
|
-
const
|
|
25137
|
+
const agentCounts = subagentRunAgentCounts(runs);
|
|
25138
|
+
const runningAgents = agentCounts.running;
|
|
25139
|
+
const staleAgents = agentCounts.stale;
|
|
25140
|
+
const retainedRuns = runs.filter((run) => !["queued", "running", "stale"].includes(subagentAgentStatus(run))).length;
|
|
23682
25141
|
const countLabel = [
|
|
23683
|
-
`${
|
|
25142
|
+
`${agentCounts.total} total`,
|
|
25143
|
+
runningAgents ? `${runningAgents} running` : "",
|
|
25144
|
+
staleAgents ? `${staleAgents} stale` : "",
|
|
23684
25145
|
retainedRuns ? `${retainedRuns} retained` : "",
|
|
23685
25146
|
Number(tab.gateCount || 0) ? `${tab.gateCount} gates` : "",
|
|
23686
25147
|
].filter(Boolean).join(" · ");
|
|
23687
25148
|
header.append(title, make("span", "subagent-tab-count", countLabel));
|
|
23688
|
-
header.addEventListener("click", () => switchTab(tab.tabId));
|
|
25149
|
+
if (!isExternal) header.addEventListener("click", () => switchTab(tab.tabId));
|
|
23689
25150
|
group.append(header);
|
|
23690
25151
|
|
|
23691
25152
|
const list = make("div", "subagent-agent-list");
|
|
23692
|
-
for (const
|
|
25153
|
+
for (const presentation of subagentRunPresentations(runs)) list.append(renderSubagentRun(tab, presentation.run, presentation.agents));
|
|
23693
25154
|
for (const gate of (Array.isArray(tab.gates) ? tab.gates : []).slice().sort((a, b) => Number(a.startedAt || 0) - Number(b.startedAt || 0))) {
|
|
23694
25155
|
list.append(renderSubagentGate(tab, gate));
|
|
23695
25156
|
}
|
|
@@ -23710,7 +25171,9 @@ function renderSubagents() {
|
|
|
23710
25171
|
const restoreFocus = () => restoreScopedControlContinuity(box, continuityContextKey, focusSnapshot, (key) => [...box.querySelectorAll("[data-subagent-continuity-key]")].find((node) => subagentPanelControlKey(node) === key));
|
|
23711
25172
|
const activeTabs = subagentTabsWithRunningAgents();
|
|
23712
25173
|
const finishedRuns = finishedSubagentRunSelections();
|
|
23713
|
-
const totalAgents =
|
|
25174
|
+
const totalAgents = activeTabs.reduce((count, tab) => count + Number(tab.agentCount || 0), 0);
|
|
25175
|
+
const runningAgents = activeTabs.reduce((count, tab) => count + Number(tab.runningAgents || 0), 0);
|
|
25176
|
+
const staleAgents = activeTabs.reduce((count, tab) => count + Number(tab.staleAgents || 0), 0);
|
|
23714
25177
|
const totalRuns = activeTabs.reduce((count, tab) => count + tab.displayRuns.length, 0);
|
|
23715
25178
|
const runningRuns = activeTabs.reduce((count, tab) => count + tab.displayRuns.filter((run) => run?.status === "running").length, 0);
|
|
23716
25179
|
const retainedRuns = Math.max(0, totalRuns - runningRuns);
|
|
@@ -23736,7 +25199,7 @@ function renderSubagents() {
|
|
|
23736
25199
|
}
|
|
23737
25200
|
if (elements.subagentsStatus) {
|
|
23738
25201
|
elements.subagentsStatus.textContent = hasItems
|
|
23739
|
-
? [`${totalAgents} running`, retainedRuns ? `${retainedRuns} retained ${retainedRuns === 1 ? "run" : "runs"}` : "", totalGates ? `${totalGates} retry ${totalGates === 1 ? "gate" : "gates"}` : "", `across ${activeTabs.length} ${activeTabs.length === 1 ? "
|
|
25202
|
+
? [`${totalAgents} total`, `${runningAgents} running`, staleAgents ? `${staleAgents} stale` : "", Number(latestSubagents?.fleet?.omitted || 0) ? `${latestSubagents.fleet.omitted} active ${latestSubagents.fleet.omitted === 1 ? "child" : "children"} omitted upstream` : "", retainedRuns ? `${retainedRuns} retained ${retainedRuns === 1 ? "run" : "runs"}` : "", totalGates ? `${totalGates} retry ${totalGates === 1 ? "gate" : "gates"}` : "", `across ${activeTabs.length} ${activeTabs.length === 1 ? "group" : "groups"}`].filter(Boolean).join(" · ")
|
|
23740
25203
|
: subagentsLoading && !latestSubagents
|
|
23741
25204
|
? "Checking subagents and retry gates…"
|
|
23742
25205
|
: "No running subagents, retained runs, or retry gates.";
|
|
@@ -23746,7 +25209,7 @@ function renderSubagents() {
|
|
|
23746
25209
|
box.classList.toggle("muted", !hasItems);
|
|
23747
25210
|
box.classList.toggle("has-items", hasItems);
|
|
23748
25211
|
if (!hasItems) {
|
|
23749
|
-
box.append(make("div", "subagents-empty", subagentsError ? `Subagent status unavailable: ${subagentsError.message || subagentsError}` : "
|
|
25212
|
+
box.append(make("div", "subagents-empty", subagentsError ? `Subagent status unavailable: ${subagentsError.message || subagentsError}` : "Managed and registered Pi agent runs will appear here, grouped by terminal or under External agents."));
|
|
23750
25213
|
restoreFocus();
|
|
23751
25214
|
return;
|
|
23752
25215
|
}
|
|
@@ -23756,32 +25219,51 @@ function renderSubagents() {
|
|
|
23756
25219
|
}
|
|
23757
25220
|
|
|
23758
25221
|
async function refreshSubagents() {
|
|
23759
|
-
if (
|
|
25222
|
+
if (subagentsRefreshPromise) {
|
|
25223
|
+
subagentsRefreshQueued = true;
|
|
25224
|
+
return subagentsRefreshPromise;
|
|
25225
|
+
}
|
|
23760
25226
|
let refreshed = false;
|
|
23761
25227
|
let subagentViewsChanged = false;
|
|
23762
25228
|
let materializedTerminalViews = false;
|
|
23763
25229
|
subagentsLoading = true;
|
|
23764
25230
|
renderSubagents();
|
|
23765
|
-
|
|
23766
|
-
|
|
23767
|
-
|
|
23768
|
-
|
|
23769
|
-
|
|
23770
|
-
|
|
23771
|
-
|
|
23772
|
-
|
|
23773
|
-
|
|
23774
|
-
|
|
23775
|
-
|
|
23776
|
-
|
|
23777
|
-
|
|
23778
|
-
|
|
23779
|
-
|
|
23780
|
-
|
|
23781
|
-
|
|
25231
|
+
let settleRefresh;
|
|
25232
|
+
let rejectRefresh;
|
|
25233
|
+
const refreshPromise = new Promise((resolve, reject) => {
|
|
25234
|
+
settleRefresh = resolve;
|
|
25235
|
+
rejectRefresh = reject;
|
|
25236
|
+
});
|
|
25237
|
+
subagentsRefreshPromise = refreshPromise;
|
|
25238
|
+
(async () => {
|
|
25239
|
+
try {
|
|
25240
|
+
do {
|
|
25241
|
+
subagentsRefreshQueued = false;
|
|
25242
|
+
try {
|
|
25243
|
+
const response = await api("/api/subagents", { scoped: false });
|
|
25244
|
+
latestSubagents = response.data || null;
|
|
25245
|
+
pruneDismissedSubagentGateKeys(latestSubagents?.tabs, dismissedSubagentGateKeys);
|
|
25246
|
+
subagentViewsChanged = syncSubagentTerminalViewsFromOverview() || subagentViewsChanged;
|
|
25247
|
+
materializedTerminalViews = materializeRetainedSubagentTerminalViews() || materializedTerminalViews;
|
|
25248
|
+
subagentsError = null;
|
|
25249
|
+
refreshed = true;
|
|
25250
|
+
} catch (error) {
|
|
25251
|
+
subagentsError = error;
|
|
25252
|
+
}
|
|
25253
|
+
} while (subagentsRefreshQueued);
|
|
25254
|
+
} finally {
|
|
25255
|
+
if (subagentsRefreshPromise === refreshPromise) subagentsRefreshPromise = null;
|
|
25256
|
+
subagentsLoading = false;
|
|
25257
|
+
renderSubagents();
|
|
25258
|
+
if (subagentOverlaySelection?.tabId === activeTabId) renderWidgets();
|
|
25259
|
+
if (activeSubagentTerminalId) {
|
|
25260
|
+
renderSubagentTerminalView();
|
|
25261
|
+
scheduleSubagentTerminalRefresh();
|
|
25262
|
+
}
|
|
25263
|
+
if (subagentViewsChanged || materializedTerminalViews) renderTabs();
|
|
23782
25264
|
}
|
|
23783
|
-
|
|
23784
|
-
|
|
25265
|
+
})().then(settleRefresh, rejectRefresh);
|
|
25266
|
+
await refreshPromise;
|
|
23785
25267
|
if (refreshed && subagentAutoClearEnabled && finishedSubagentRunSelections().length) {
|
|
23786
25268
|
await clearFinishedSubagentRuns({ automatic: true });
|
|
23787
25269
|
}
|
|
@@ -32379,6 +33861,22 @@ function appendMarkdownMermaidBlock(parent, code) {
|
|
|
32379
33861
|
queueMicrotask(() => renderMermaidDiagram(diagram, status, source));
|
|
32380
33862
|
}
|
|
32381
33863
|
|
|
33864
|
+
// Fenced code is rendered from the pure tokenizer as text nodes and span
|
|
33865
|
+
// textContent only. Source never reaches innerHTML, concatenated token text
|
|
33866
|
+
// reproduces the source exactly, and unknown/oversized blocks fall back to one
|
|
33867
|
+
// plain token so copy, selection, and transcript search stay unchanged.
|
|
33868
|
+
function appendMarkdownCodeTokens(codeNode, source, language) {
|
|
33869
|
+
const tokens = tokenizeCode(source, normalizedMarkdownLanguage(language));
|
|
33870
|
+
if (!tokens.length) {
|
|
33871
|
+
codeNode.textContent = source;
|
|
33872
|
+
return;
|
|
33873
|
+
}
|
|
33874
|
+
for (const { type, text } of tokens) {
|
|
33875
|
+
if (type === "plain") codeNode.append(document.createTextNode(text));
|
|
33876
|
+
else codeNode.append(make("span", `syntax-token syntax-${type}`, text));
|
|
33877
|
+
}
|
|
33878
|
+
}
|
|
33879
|
+
|
|
32382
33880
|
function appendMarkdownCodeBlock(parent, code, language = "", { closed = true } = {}) {
|
|
32383
33881
|
if (closed && isMermaidLanguage(language)) {
|
|
32384
33882
|
appendMarkdownMermaidBlock(parent, code);
|
|
@@ -32388,7 +33886,7 @@ function appendMarkdownCodeBlock(parent, code, language = "", { closed = true }
|
|
|
32388
33886
|
if (language) wrapper.append(make("div", "markdown-code-language", language));
|
|
32389
33887
|
const pre = make("pre", "code-block markdown-code");
|
|
32390
33888
|
const codeNode = make("code", language ? `language-${language.replace(/[^a-z0-9_-]/gi, "")}` : "");
|
|
32391
|
-
codeNode
|
|
33889
|
+
appendMarkdownCodeTokens(codeNode, String(code || "").replace(/\n+$/g, ""), language);
|
|
32392
33890
|
pre.append(codeNode);
|
|
32393
33891
|
wrapper.append(pre);
|
|
32394
33892
|
attachMarkdownCodeCopyButton(wrapper);
|
|
@@ -33013,11 +34511,28 @@ function joinedThinkingFormatParts(parts) {
|
|
|
33013
34511
|
function thinkingFormatOpenMatch(text) {
|
|
33014
34512
|
const value = String(text || "");
|
|
33015
34513
|
const think = THINKING_FORMAT_OPEN_TAG_REGEX.exec(value);
|
|
33016
|
-
if (think) return { raw: think[0], closeRegex: THINKING_FORMAT_CLOSE_TAG_REGEX, closeTag: "</think>" };
|
|
34514
|
+
if (think) return { kind: "think", raw: think[0], closeRegex: THINKING_FORMAT_CLOSE_TAG_REGEX, closeTag: "</think>" };
|
|
33017
34515
|
const channel = CHANNEL_THINKING_FORMAT_OPEN_TAG_REGEX.exec(value);
|
|
33018
34516
|
if (!channel) return null;
|
|
33019
34517
|
const name = channel[1];
|
|
33020
|
-
return { raw: channel[0], closeRegex: new RegExp(`<${escapeRegExp(name)}\\|>`, "i"), closeTag: `<${name}|>` };
|
|
34518
|
+
return { kind: "channel", raw: channel[0], closeRegex: new RegExp(`<${escapeRegExp(name)}\\|>`, "i"), closeTag: `<${name}|>` };
|
|
34519
|
+
}
|
|
34520
|
+
|
|
34521
|
+
function thinkingFormatCloseMatch(text, open) {
|
|
34522
|
+
const value = String(text || "");
|
|
34523
|
+
if (open?.kind !== "think") return open?.closeRegex?.exec(value) || null;
|
|
34524
|
+
const tokens = /<think\b[^>]*>|<\/think\s*>/gi;
|
|
34525
|
+
let depth = 1;
|
|
34526
|
+
let match = null;
|
|
34527
|
+
while ((match = tokens.exec(value))) {
|
|
34528
|
+
if (/^<\s*\/think/i.test(match[0])) {
|
|
34529
|
+
depth -= 1;
|
|
34530
|
+
if (depth === 0) return match;
|
|
34531
|
+
} else {
|
|
34532
|
+
depth += 1;
|
|
34533
|
+
}
|
|
34534
|
+
}
|
|
34535
|
+
return null;
|
|
33021
34536
|
}
|
|
33022
34537
|
|
|
33023
34538
|
function splitThinkingFormatText(text, { streaming = false } = {}) {
|
|
@@ -33033,7 +34548,7 @@ function splitThinkingFormatText(text, { streaming = false } = {}) {
|
|
|
33033
34548
|
let open = thinkingFormatOpenMatch(rest);
|
|
33034
34549
|
while (open) {
|
|
33035
34550
|
const afterOpen = rest.slice(open.raw.length);
|
|
33036
|
-
const close =
|
|
34551
|
+
const close = thinkingFormatCloseMatch(afterOpen, open);
|
|
33037
34552
|
if (!close) {
|
|
33038
34553
|
thinkingParts.push(streaming ? stripPartialThinkingFormatClose(afterOpen, open.closeTag) : afterOpen);
|
|
33039
34554
|
return { hasThinkingFormat: true, thinkingText: joinedThinkingFormatParts(thinkingParts), finalText: "", complete: false };
|
|
@@ -33075,6 +34590,17 @@ function assistantToolCallName(part) {
|
|
|
33075
34590
|
return String(part?.name || part?.toolName || part?.toolCall?.name || "unknown");
|
|
33076
34591
|
}
|
|
33077
34592
|
|
|
34593
|
+
function isIntercomTransportToolName(value) {
|
|
34594
|
+
return String(value || "").trim().toLowerCase() === "intercom";
|
|
34595
|
+
}
|
|
34596
|
+
|
|
34597
|
+
function isIntercomToolCallUpdate(event) {
|
|
34598
|
+
const update = event?.assistantMessageEvent || {};
|
|
34599
|
+
const part = assistantToolCallPartFromUpdate(event, update);
|
|
34600
|
+
const rawName = update.name || update.toolName || update.toolCall?.name || (part ? assistantToolCallName(part) : "");
|
|
34601
|
+
return isIntercomTransportToolName(rawName);
|
|
34602
|
+
}
|
|
34603
|
+
|
|
33078
34604
|
function assistantToolCallArguments(part) {
|
|
33079
34605
|
return part?.arguments || part?.args || part?.input || part?.toolCall?.arguments || {};
|
|
33080
34606
|
}
|
|
@@ -33590,9 +35116,11 @@ function updateStickyUserPromptButton() {
|
|
|
33590
35116
|
const targets = userPromptTargets();
|
|
33591
35117
|
const target = findStickyUserPromptTarget(targets);
|
|
33592
35118
|
if (!target) {
|
|
35119
|
+
if (button.hidden && button.childElementCount === 0) return;
|
|
33593
35120
|
button.hidden = true;
|
|
33594
35121
|
button.removeAttribute("data-message-index");
|
|
33595
35122
|
button.removeAttribute("data-compacted");
|
|
35123
|
+
delete button.dataset.renderSignature;
|
|
33596
35124
|
button.replaceChildren();
|
|
33597
35125
|
return;
|
|
33598
35126
|
}
|
|
@@ -33601,12 +35129,16 @@ function updateStickyUserPromptButton() {
|
|
|
33601
35129
|
const isLatest = target.compacted || ordinal === targets.length;
|
|
33602
35130
|
const label = target.compacted ? "Last user prompt (compacted)" : isLatest ? "Last user prompt" : "Previous user prompt";
|
|
33603
35131
|
const meta = target.compacted ? "summary ↑" : `${ordinal}/${targets.length} ↑`;
|
|
35132
|
+
const messageIndex = Number.isInteger(target.index) && target.index >= 0 ? String(target.index) : "";
|
|
35133
|
+
const baseTitle = target.compacted ? `Prompt was compacted; jump to compaction summary: ${target.preview}` : `Jump to ${label.toLowerCase()}: ${target.preview}`;
|
|
35134
|
+
const baseAriaLabel = target.compacted ? `Prompt was compacted; jump to compaction summary: ${target.preview}` : `Jump to ${label.toLowerCase()} (${ordinal} of ${targets.length}): ${target.preview}`;
|
|
35135
|
+
const renderSignature = JSON.stringify([target.compacted === true, messageIndex, baseTitle, baseAriaLabel, label, target.preview, meta]);
|
|
35136
|
+
if (!button.hidden && button.dataset.renderSignature === renderSignature) return;
|
|
33604
35137
|
button.hidden = false;
|
|
35138
|
+
button.dataset.renderSignature = renderSignature;
|
|
33605
35139
|
button.dataset.compacted = target.compacted ? "true" : "false";
|
|
33606
|
-
if (
|
|
35140
|
+
if (messageIndex) button.dataset.messageIndex = messageIndex;
|
|
33607
35141
|
else button.removeAttribute("data-message-index");
|
|
33608
|
-
const baseTitle = target.compacted ? `Prompt was compacted; jump to compaction summary: ${target.preview}` : `Jump to ${label.toLowerCase()}: ${target.preview}`;
|
|
33609
|
-
const baseAriaLabel = target.compacted ? `Prompt was compacted; jump to compaction summary: ${target.preview}` : `Jump to ${label.toLowerCase()} (${ordinal} of ${targets.length}): ${target.preview}`;
|
|
33610
35142
|
button.title = baseTitle;
|
|
33611
35143
|
button.setAttribute("aria-label", baseAriaLabel);
|
|
33612
35144
|
const children = [
|
|
@@ -37173,9 +38705,9 @@ function optionalFeatureStatus(featureId) {
|
|
|
37173
38705
|
label: "Disabled",
|
|
37174
38706
|
className: "disabled",
|
|
37175
38707
|
detail: `Tool access is disabled for the active Pi session${versionSuffix}`,
|
|
37176
|
-
hint: "Enable it here for this session
|
|
38708
|
+
hint: "Enable it here for this session.",
|
|
37177
38709
|
};
|
|
37178
|
-
if (detected && managedWithTools) return { label: "Enabled", className: "enabled", detail: doneDetail || `Tool access is enabled for the active Pi session${versionSuffix}`,
|
|
38710
|
+
if (detected && managedWithTools) return { label: "Enabled", className: "enabled", detail: doneDetail || `Tool access is enabled for the active Pi session${versionSuffix}`, command: installState?.command || "" };
|
|
37179
38711
|
if (detected && !disabled) return { label: "Enabled", className: "enabled", detail: doneDetail || `Detected and enabled in Web UI${versionSuffix}`, command: installState?.command || "" };
|
|
37180
38712
|
if (detected && disabled) return { label: "Disabled", className: "disabled", detail: `Detected, but disabled in Web UI${versionSuffix}` };
|
|
37181
38713
|
if (packageStatus?.locallyConfigured) return { label: "Available locally", className: "installed", detail: doneDetail || `Enabled as a top-level Pi resource; reload this tab if the capability is not detected yet${versionSuffix}` };
|
|
@@ -37336,6 +38868,7 @@ function optionalFeatureSetupAvailable(feature) {
|
|
|
37336
38868
|
case "git-workflow": return hasAvailableCommand("git-workflow-setup");
|
|
37337
38869
|
case "workflows": return hasLoadedRpcCommand("workflow-setup");
|
|
37338
38870
|
case "safety-guard": return hasAvailableCommand("safety-guard-setup");
|
|
38871
|
+
case "skills": return hasLoadedRpcCommand("skills");
|
|
37339
38872
|
case "tools": return feature.manageWith !== "tools" || isOptionalFeatureDetected(feature.id);
|
|
37340
38873
|
default: return false;
|
|
37341
38874
|
}
|
|
@@ -37346,6 +38879,7 @@ function openOptionalFeatureSetup(feature) {
|
|
|
37346
38879
|
case "git-workflow": return openNativeGitWorkflowSetupDialog();
|
|
37347
38880
|
case "workflows": return openNativeWorkflowSetupDialog();
|
|
37348
38881
|
case "safety-guard": return openNativeSafetyGuardSetupDialog();
|
|
38882
|
+
case "skills": return openNativeSkillsSelector();
|
|
37349
38883
|
case "tools": return openNativeToolsSelector();
|
|
37350
38884
|
default: return undefined;
|
|
37351
38885
|
}
|
|
@@ -37556,6 +39090,8 @@ function renderOptionalFeatureControls() {
|
|
|
37556
39090
|
const hasNativeCommandMenu = isOptionalFeatureEnabled("tuiSkillsCommand") || isOptionalFeatureEnabled("tuiToolsCommand");
|
|
37557
39091
|
elements.nativeSkillsButton.hidden = !isOptionalFeatureEnabled("tuiSkillsCommand");
|
|
37558
39092
|
elements.nativeToolsButton.hidden = !isOptionalFeatureEnabled("tuiToolsCommand");
|
|
39093
|
+
if (elements.optionsSkillsSetupButton) elements.optionsSkillsSetupButton.hidden = !isOptionalFeatureEnabled("tuiSkillsCommand");
|
|
39094
|
+
if (elements.optionsToolsSetupButton) elements.optionsToolsSetupButton.hidden = !isOptionalFeatureEnabled("tuiToolsCommand");
|
|
37559
39095
|
const nativeCommandMenuContainer = elements.nativeCommandMenuButton.parentElement;
|
|
37560
39096
|
if (nativeCommandMenuContainer) nativeCommandMenuContainer.hidden = !hasNativeCommandMenu;
|
|
37561
39097
|
elements.nativeCommandMenuButton.hidden = !hasNativeCommandMenu;
|
|
@@ -38137,6 +39673,17 @@ function createTerminalTabSessionSummaryButton(tab) {
|
|
|
38137
39673
|
function renderSessionSummaryControls() {
|
|
38138
39674
|
const setupAvailable = !!activeTabId && hasAvailableCommand("summary-setup", { tabId: activeTabId });
|
|
38139
39675
|
if (elements.optionsSummarySetupButton) elements.optionsSummarySetupButton.hidden = !setupAvailable;
|
|
39676
|
+
const state = sessionSummaryStateForTab(activeTabId);
|
|
39677
|
+
const renderSignature = JSON.stringify([
|
|
39678
|
+
activeTabId || "",
|
|
39679
|
+
setupAvailable,
|
|
39680
|
+
!!activeTabId && hasAvailableCommand("summary", { tabId: activeTabId }),
|
|
39681
|
+
state?.status || "",
|
|
39682
|
+
Boolean(state?.summaryMarkdown),
|
|
39683
|
+
state?.message || "",
|
|
39684
|
+
]);
|
|
39685
|
+
if (renderSignature === sessionSummaryControlsRenderSignature) return;
|
|
39686
|
+
sessionSummaryControlsRenderSignature = renderSignature;
|
|
38140
39687
|
scheduleTabsRender();
|
|
38141
39688
|
}
|
|
38142
39689
|
|
|
@@ -38207,8 +39754,10 @@ function openSessionSummaryOverlay(tabId, { loading = false, focusReturnKey = ""
|
|
|
38207
39754
|
|
|
38208
39755
|
function updateSessionSummaryForTab(tabId, value, { resetProjection = false } = {}) {
|
|
38209
39756
|
if (!tabId) return null;
|
|
38210
|
-
const
|
|
39757
|
+
const previous = sessionSummaryByTab.get(tabId);
|
|
39758
|
+
const normalized = normalizeSessionSummaryClientState(value, previous, { resetProjection });
|
|
38211
39759
|
if (!normalized) return null;
|
|
39760
|
+
if (previous && tabsSnapshotSignature(previous) === tabsSnapshotSignature(normalized)) return previous;
|
|
38212
39761
|
sessionSummaryByTab.set(tabId, normalized);
|
|
38213
39762
|
renderSessionSummaryControls();
|
|
38214
39763
|
if (sessionSummaryOverlayTabId === tabId) renderSessionSummaryOverlay();
|
|
@@ -38358,6 +39907,7 @@ function renderNativeSelectorItems(items, { emptyText = "No choices.", onSelect,
|
|
|
38358
39907
|
const button = make("button", `native-selector-item${item.id === activeId ? " active" : ""}`);
|
|
38359
39908
|
button.type = "button";
|
|
38360
39909
|
button.disabled = item.disabled === true;
|
|
39910
|
+
if (typeof item.pressed === "boolean") button.setAttribute("aria-pressed", String(item.pressed));
|
|
38361
39911
|
button.addEventListener("click", () => onSelect?.(item));
|
|
38362
39912
|
const title = make("span", "native-selector-title");
|
|
38363
39913
|
if (numbered) title.append(make("span", "native-selector-index", `${index + 1}.`));
|
|
@@ -40076,6 +41626,7 @@ function renderNativeResourceToggles(resources, { savingName, filter = "all", on
|
|
|
40076
41626
|
meta: nativeResourceSourceLabel(resource),
|
|
40077
41627
|
badge: resource.enabled === false ? "disabled" : "enabled",
|
|
40078
41628
|
badgeClass: resource.enabled === false ? "disabled native-selector-badge-disabled" : "enabled native-selector-badge-enabled",
|
|
41629
|
+
pressed: resource.enabled !== false,
|
|
40079
41630
|
tags: resourceTag ? [resourceTag] : [],
|
|
40080
41631
|
disabled: Boolean(savingName),
|
|
40081
41632
|
resource,
|
|
@@ -40089,7 +41640,7 @@ function renderNativeResourceToggles(resources, { savingName, filter = "all", on
|
|
|
40089
41640
|
elements.nativeCommandBody.prepend(make("div", "native-resource-summary muted", `${counts.total} total · ${counts.enabled} enabled · ${counts.disabled} disabled · showing ${filterLabel}`));
|
|
40090
41641
|
}
|
|
40091
41642
|
|
|
40092
|
-
function renderNativeResourceFilterActions(filter, setFilter, render) {
|
|
41643
|
+
function renderNativeResourceFilterActions(filter, setFilter, render, extraActions = []) {
|
|
40093
41644
|
elements.nativeCommandActions.replaceChildren();
|
|
40094
41645
|
for (const option of [
|
|
40095
41646
|
{ value: "all", label: "All" },
|
|
@@ -40101,40 +41652,79 @@ function renderNativeResourceFilterActions(filter, setFilter, render) {
|
|
|
40101
41652
|
render();
|
|
40102
41653
|
}, filter === option.value ? "primary" : undefined);
|
|
40103
41654
|
}
|
|
41655
|
+
for (const action of extraActions) {
|
|
41656
|
+
const button = addNativeCommandAction(action.label, action.handler);
|
|
41657
|
+
button.disabled = !!action.disabled;
|
|
41658
|
+
}
|
|
40104
41659
|
addNativeCommandAction("Cancel", closeNativeCommandDialog);
|
|
40105
41660
|
}
|
|
40106
41661
|
|
|
40107
41662
|
function nativeResourceScopeControl(scope, { configured = false, saving = false, onChange } = {}) {
|
|
40108
|
-
const
|
|
40109
|
-
|
|
40110
|
-
|
|
41663
|
+
const hints = {
|
|
41664
|
+
session: "Applies immediately and persists only on the current session branch.",
|
|
41665
|
+
global: configured
|
|
40111
41666
|
? "Saved as the default for future sessions. Existing session-specific choices are unchanged."
|
|
40112
|
-
: "No global default is saved yet. The current session is shown as the starting point."
|
|
40113
|
-
:
|
|
41667
|
+
: "No global default is saved yet. The current session is shown as the starting point.",
|
|
41668
|
+
model: configured
|
|
41669
|
+
? "Saved for this exact model. Sessions without their own choice apply it whenever this model is selected."
|
|
41670
|
+
: "No default is saved for this exact model yet. The inherited selection is shown as the starting point.",
|
|
41671
|
+
};
|
|
41672
|
+
const badges = {
|
|
41673
|
+
session: { label: "This session", tone: "now" },
|
|
41674
|
+
global: { label: "Global", tone: "startup" },
|
|
41675
|
+
model: { label: "Exact model", tone: "startup" },
|
|
41676
|
+
};
|
|
40114
41677
|
const control = nativeSettingSelect("Apply changes to", scope, [
|
|
40115
41678
|
{ value: "session", label: "Session only" },
|
|
40116
41679
|
{ value: "global", label: "Global default" },
|
|
40117
|
-
|
|
41680
|
+
{ value: "model", label: "Model default" },
|
|
41681
|
+
], hints[scope] || hints.session, badges[scope] || badges.session);
|
|
40118
41682
|
control.field.classList.add("native-resource-scope");
|
|
40119
41683
|
control.select.disabled = !!saving;
|
|
40120
41684
|
control.select.addEventListener("change", () => onChange?.(control.select.value));
|
|
40121
41685
|
return control.field;
|
|
40122
41686
|
}
|
|
40123
41687
|
|
|
41688
|
+
function nativeResourceModelControl(models, modelIndex, { saving = false, onChange } = {}) {
|
|
41689
|
+
const options = models.map((model, index) => ({
|
|
41690
|
+
value: String(index),
|
|
41691
|
+
label: `${model.provider}/${model.id}${model.name && model.name !== model.id ? ` — ${model.name}` : ""}`,
|
|
41692
|
+
}));
|
|
41693
|
+
const control = nativeSettingSelect("Model default for", String(modelIndex), options, "Chooses which exact model profile to edit. The active session model is not changed.", { label: "Exact model", tone: "startup" });
|
|
41694
|
+
control.field.classList.add("native-resource-model");
|
|
41695
|
+
control.select.disabled = !!saving;
|
|
41696
|
+
control.select.addEventListener("change", () => onChange?.(Number(control.select.value)));
|
|
41697
|
+
return control.field;
|
|
41698
|
+
}
|
|
41699
|
+
|
|
41700
|
+
async function loadNativeResourceModels() {
|
|
41701
|
+
const response = await nativeCommandApi("/api/models");
|
|
41702
|
+
return (Array.isArray(response.data?.models) ? response.data.models : [])
|
|
41703
|
+
.filter((model) => model?.provider && model?.id)
|
|
41704
|
+
.sort((left, right) => `${left.provider}/${left.id}`.localeCompare(`${right.provider}/${right.id}`));
|
|
41705
|
+
}
|
|
41706
|
+
|
|
40124
41707
|
async function openNativeToolsSelector() {
|
|
40125
|
-
openNativeCommandDialog({ title: "Tools Setup", message: "Enable or disable tool access for this session or save a
|
|
41708
|
+
openNativeCommandDialog({ title: "Tools Setup", message: "Enable or disable tool access for this session, or save a global or exact-model default.", searchPlaceholder: "Filter tools…" });
|
|
40126
41709
|
let tools = [];
|
|
40127
41710
|
let savingName = "";
|
|
40128
41711
|
let filter = "all";
|
|
40129
41712
|
let scope = "session";
|
|
40130
41713
|
let configured = false;
|
|
41714
|
+
let models = [];
|
|
41715
|
+
let modelIndex = 0;
|
|
41716
|
+
|
|
41717
|
+
const modelQuery = () => scope === "model" && models[modelIndex]
|
|
41718
|
+
? `&provider=${encodeURIComponent(models[modelIndex].provider)}&modelId=${encodeURIComponent(models[modelIndex].id)}`
|
|
41719
|
+
: "";
|
|
40131
41720
|
|
|
40132
41721
|
const load = async () => {
|
|
40133
|
-
renderNativeLoading(`Loading ${scope === "global" ? "global tool defaults" : "session tools"}…`);
|
|
41722
|
+
renderNativeLoading(`Loading ${scope === "global" ? "global tool defaults" : scope === "model" ? "model tool defaults" : "session tools"}…`);
|
|
40134
41723
|
try {
|
|
40135
|
-
const response = await nativeCommandApi(`/api/tools?scope=${encodeURIComponent(scope)}`);
|
|
41724
|
+
const response = await nativeCommandApi(`/api/tools?scope=${encodeURIComponent(scope)}${modelQuery()}`);
|
|
40136
41725
|
tools = Array.isArray(response.data?.tools) ? response.data.tools : [];
|
|
40137
41726
|
configured = response.data?.configured === true;
|
|
41727
|
+
if (scope === "model" && Array.isArray(response.data?.models)) models = response.data.models;
|
|
40138
41728
|
render();
|
|
40139
41729
|
} catch (error) {
|
|
40140
41730
|
setNativeCommandError(error.message || String(error));
|
|
@@ -40142,6 +41732,51 @@ async function openNativeToolsSelector() {
|
|
|
40142
41732
|
}
|
|
40143
41733
|
};
|
|
40144
41734
|
|
|
41735
|
+
const applyModelScope = async () => {
|
|
41736
|
+
if (!models.length) {
|
|
41737
|
+
try {
|
|
41738
|
+
models = await loadNativeResourceModels();
|
|
41739
|
+
} catch (error) {
|
|
41740
|
+
setNativeCommandError(error.message || String(error));
|
|
41741
|
+
return false;
|
|
41742
|
+
}
|
|
41743
|
+
}
|
|
41744
|
+
if (!models.length) {
|
|
41745
|
+
setNativeCommandError("No authenticated Pi models are available for a model default.");
|
|
41746
|
+
return false;
|
|
41747
|
+
}
|
|
41748
|
+
modelIndex = Math.min(Math.max(modelIndex, 0), models.length - 1);
|
|
41749
|
+
return true;
|
|
41750
|
+
};
|
|
41751
|
+
|
|
41752
|
+
const inheritSelection = async () => {
|
|
41753
|
+
if (savingName) return;
|
|
41754
|
+
savingName = "inherit";
|
|
41755
|
+
setNativeCommandError("");
|
|
41756
|
+
render();
|
|
41757
|
+
try {
|
|
41758
|
+
const body = { scope, inherit: true };
|
|
41759
|
+
if (scope === "model" && models[modelIndex]) {
|
|
41760
|
+
body.provider = models[modelIndex].provider;
|
|
41761
|
+
body.modelId = models[modelIndex].id;
|
|
41762
|
+
}
|
|
41763
|
+
const response = await nativeCommandApi("/api/tools", { method: "POST", body });
|
|
41764
|
+
tools = Array.isArray(response.data?.tools) ? response.data.tools : [];
|
|
41765
|
+
configured = response.data?.configured === true;
|
|
41766
|
+
const content = scope === "model"
|
|
41767
|
+
? `Tool default for ${body.provider}/${body.modelId} cleared. It now inherits the global or Pi runtime default.`
|
|
41768
|
+
: scope === "global"
|
|
41769
|
+
? "Global tool default cleared. Unpinned active tools now follow the Pi runtime default; pinned tools are unchanged."
|
|
41770
|
+
: "Tools for this session now follow the inherited model, global, or Pi runtime defaults.";
|
|
41771
|
+
addTransientMessage({ role: "native", title: "/tools", content, level: "info" });
|
|
41772
|
+
} catch (error) {
|
|
41773
|
+
setNativeCommandError(error.message || String(error));
|
|
41774
|
+
} finally {
|
|
41775
|
+
savingName = "";
|
|
41776
|
+
render();
|
|
41777
|
+
}
|
|
41778
|
+
};
|
|
41779
|
+
|
|
40145
41780
|
const render = () => {
|
|
40146
41781
|
renderNativeResourceToggles(tools, {
|
|
40147
41782
|
savingName,
|
|
@@ -40156,13 +41791,20 @@ async function openNativeToolsSelector() {
|
|
|
40156
41791
|
setNativeCommandError("");
|
|
40157
41792
|
render();
|
|
40158
41793
|
try {
|
|
40159
|
-
const
|
|
41794
|
+
const body = { enabledTools: [...enabledTools], scope };
|
|
41795
|
+
if (scope === "model" && models[modelIndex]) {
|
|
41796
|
+
body.provider = models[modelIndex].provider;
|
|
41797
|
+
body.modelId = models[modelIndex].id;
|
|
41798
|
+
}
|
|
41799
|
+
const response = await nativeCommandApi("/api/tools", { method: "POST", body });
|
|
40160
41800
|
tools = Array.isArray(response.data?.tools) ? response.data.tools : [];
|
|
40161
41801
|
configured = response.data?.configured === true;
|
|
40162
41802
|
const enabled = enabledTools.has(tool.name);
|
|
40163
|
-
const content = scope === "
|
|
40164
|
-
? `
|
|
40165
|
-
:
|
|
41803
|
+
const content = scope === "model"
|
|
41804
|
+
? `Model default for tool ${tool.name} ${enabled ? "enabled" : "disabled"} (${body.provider}/${body.modelId}). Unpinned active tools update immediately when this model is active; pinned tools are unchanged.`
|
|
41805
|
+
: scope === "global"
|
|
41806
|
+
? `Global default for tool ${tool.name} ${enabled ? "enabled" : "disabled"}. Unpinned active tools update immediately; pinned tools are unchanged.`
|
|
41807
|
+
: `Tool ${tool.name} ${enabled ? "enabled" : "disabled"} for this session.`;
|
|
40166
41808
|
addTransientMessage({ role: "native", title: "/tools", content, level: "info" });
|
|
40167
41809
|
} catch (error) {
|
|
40168
41810
|
setNativeCommandError(error.message || String(error));
|
|
@@ -40172,16 +41814,32 @@ async function openNativeToolsSelector() {
|
|
|
40172
41814
|
}
|
|
40173
41815
|
},
|
|
40174
41816
|
});
|
|
41817
|
+
if (scope === "model" && models.length) {
|
|
41818
|
+
elements.nativeCommandBody.prepend(nativeResourceModelControl(models, modelIndex, {
|
|
41819
|
+
saving: !!savingName,
|
|
41820
|
+
onChange: async (nextIndex) => {
|
|
41821
|
+
if (nextIndex === modelIndex || savingName || !models[nextIndex]) return;
|
|
41822
|
+
modelIndex = nextIndex;
|
|
41823
|
+
await load();
|
|
41824
|
+
},
|
|
41825
|
+
}));
|
|
41826
|
+
}
|
|
40175
41827
|
elements.nativeCommandBody.prepend(nativeResourceScopeControl(scope, {
|
|
40176
41828
|
configured,
|
|
40177
41829
|
saving: !!savingName,
|
|
40178
41830
|
onChange: async (nextScope) => {
|
|
40179
41831
|
if (nextScope === scope || savingName) return;
|
|
41832
|
+
if (nextScope === "model" && !(await applyModelScope())) {
|
|
41833
|
+
render();
|
|
41834
|
+
return;
|
|
41835
|
+
}
|
|
40180
41836
|
scope = nextScope;
|
|
40181
41837
|
await load();
|
|
40182
41838
|
},
|
|
40183
41839
|
}));
|
|
40184
|
-
renderNativeResourceFilterActions(filter, (value) => { filter = value; }, render
|
|
41840
|
+
renderNativeResourceFilterActions(filter, (value) => { filter = value; }, render, [
|
|
41841
|
+
{ label: "Use inherited defaults", handler: inheritSelection, disabled: !!savingName },
|
|
41842
|
+
]);
|
|
40185
41843
|
};
|
|
40186
41844
|
|
|
40187
41845
|
elements.nativeCommandSearch.oninput = render;
|
|
@@ -40189,19 +41847,26 @@ async function openNativeToolsSelector() {
|
|
|
40189
41847
|
}
|
|
40190
41848
|
|
|
40191
41849
|
async function openNativeSkillsSelector() {
|
|
40192
|
-
openNativeCommandDialog({ title: "Skills Setup", message: "Enable or disable skill invocation for this session or save a
|
|
41850
|
+
openNativeCommandDialog({ title: "Skills Setup", message: "Enable or disable skill invocation for this session, or save a global or exact-model default.", searchPlaceholder: "Filter skills…" });
|
|
40193
41851
|
let skills = [];
|
|
40194
41852
|
let savingName = "";
|
|
40195
41853
|
let filter = "all";
|
|
40196
41854
|
let scope = "session";
|
|
40197
41855
|
let configured = false;
|
|
41856
|
+
let models = [];
|
|
41857
|
+
let modelIndex = 0;
|
|
41858
|
+
|
|
41859
|
+
const modelQuery = () => scope === "model" && models[modelIndex]
|
|
41860
|
+
? `&provider=${encodeURIComponent(models[modelIndex].provider)}&modelId=${encodeURIComponent(models[modelIndex].id)}`
|
|
41861
|
+
: "";
|
|
40198
41862
|
|
|
40199
41863
|
const load = async () => {
|
|
40200
|
-
renderNativeLoading(`Loading ${scope === "global" ? "global skill defaults" : "session skills"}…`);
|
|
41864
|
+
renderNativeLoading(`Loading ${scope === "global" ? "global skill defaults" : scope === "model" ? "model skill defaults" : "session skills"}…`);
|
|
40201
41865
|
try {
|
|
40202
|
-
const response = await nativeCommandApi(`/api/skills?scope=${encodeURIComponent(scope)}`);
|
|
41866
|
+
const response = await nativeCommandApi(`/api/skills?scope=${encodeURIComponent(scope)}${modelQuery()}`);
|
|
40203
41867
|
skills = Array.isArray(response.data?.skills) ? response.data.skills : [];
|
|
40204
41868
|
configured = response.data?.configured === true;
|
|
41869
|
+
if (scope === "model" && Array.isArray(response.data?.models)) models = response.data.models;
|
|
40205
41870
|
render();
|
|
40206
41871
|
} catch (error) {
|
|
40207
41872
|
setNativeCommandError(error.message || String(error));
|
|
@@ -40209,6 +41874,52 @@ async function openNativeSkillsSelector() {
|
|
|
40209
41874
|
}
|
|
40210
41875
|
};
|
|
40211
41876
|
|
|
41877
|
+
const applyModelScope = async () => {
|
|
41878
|
+
if (!models.length) {
|
|
41879
|
+
try {
|
|
41880
|
+
models = await loadNativeResourceModels();
|
|
41881
|
+
} catch (error) {
|
|
41882
|
+
setNativeCommandError(error.message || String(error));
|
|
41883
|
+
return false;
|
|
41884
|
+
}
|
|
41885
|
+
}
|
|
41886
|
+
if (!models.length) {
|
|
41887
|
+
setNativeCommandError("No authenticated Pi models are available for a model default.");
|
|
41888
|
+
return false;
|
|
41889
|
+
}
|
|
41890
|
+
modelIndex = Math.min(Math.max(modelIndex, 0), models.length - 1);
|
|
41891
|
+
return true;
|
|
41892
|
+
};
|
|
41893
|
+
|
|
41894
|
+
const inheritSelection = async () => {
|
|
41895
|
+
if (savingName) return;
|
|
41896
|
+
savingName = "inherit";
|
|
41897
|
+
setNativeCommandError("");
|
|
41898
|
+
render();
|
|
41899
|
+
try {
|
|
41900
|
+
const body = { scope, inherit: true };
|
|
41901
|
+
if (scope === "model" && models[modelIndex]) {
|
|
41902
|
+
body.provider = models[modelIndex].provider;
|
|
41903
|
+
body.modelId = models[modelIndex].id;
|
|
41904
|
+
}
|
|
41905
|
+
const response = await nativeCommandApi("/api/skills", { method: "POST", body });
|
|
41906
|
+
skills = Array.isArray(response.data?.skills) ? response.data.skills : [];
|
|
41907
|
+
configured = response.data?.configured === true;
|
|
41908
|
+
const content = scope === "model"
|
|
41909
|
+
? `Skill default for ${body.provider}/${body.modelId} cleared. It now inherits the global or Pi runtime default.`
|
|
41910
|
+
: scope === "global"
|
|
41911
|
+
? "Global skill default cleared. Unpinned active skills now follow the Pi runtime default; pinned skills are unchanged."
|
|
41912
|
+
: "Skills for this session now follow the inherited model, global, or Pi runtime defaults.";
|
|
41913
|
+
addTransientMessage({ role: "native", title: "/skills", content, level: "info" });
|
|
41914
|
+
if (scope === "session") refreshCommands(activeTabContext()).catch((error) => addEvent(error.message || String(error), "error"));
|
|
41915
|
+
} catch (error) {
|
|
41916
|
+
setNativeCommandError(error.message || String(error));
|
|
41917
|
+
} finally {
|
|
41918
|
+
savingName = "";
|
|
41919
|
+
render();
|
|
41920
|
+
}
|
|
41921
|
+
};
|
|
41922
|
+
|
|
40212
41923
|
const render = () => {
|
|
40213
41924
|
renderNativeResourceToggles(skills, {
|
|
40214
41925
|
savingName,
|
|
@@ -40222,13 +41933,20 @@ async function openNativeSkillsSelector() {
|
|
|
40222
41933
|
setNativeCommandError("");
|
|
40223
41934
|
render();
|
|
40224
41935
|
try {
|
|
40225
|
-
const
|
|
41936
|
+
const body = { enabledSkills: [...enabledSkills], scope };
|
|
41937
|
+
if (scope === "model" && models[modelIndex]) {
|
|
41938
|
+
body.provider = models[modelIndex].provider;
|
|
41939
|
+
body.modelId = models[modelIndex].id;
|
|
41940
|
+
}
|
|
41941
|
+
const response = await nativeCommandApi("/api/skills", { method: "POST", body });
|
|
40226
41942
|
skills = Array.isArray(response.data?.skills) ? response.data.skills : [];
|
|
40227
41943
|
configured = response.data?.configured === true;
|
|
40228
41944
|
const enabled = enabledSkills.has(skill.name);
|
|
40229
|
-
const content = scope === "
|
|
40230
|
-
? `
|
|
40231
|
-
:
|
|
41945
|
+
const content = scope === "model"
|
|
41946
|
+
? `Model default for skill ${skill.name} ${enabled ? "enabled" : "disabled"} (${body.provider}/${body.modelId}). Unpinned active skills update immediately when this model is active; pinned skills are unchanged.`
|
|
41947
|
+
: scope === "global"
|
|
41948
|
+
? `Global default for skill ${skill.name} ${enabled ? "enabled" : "disabled"}. Unpinned active skills update immediately; pinned skills are unchanged.`
|
|
41949
|
+
: `Skill ${skill.name} ${enabled ? "enabled" : "disabled"} for this session.`;
|
|
40232
41950
|
addTransientMessage({ role: "native", title: "/skills", content, level: "info" });
|
|
40233
41951
|
if (scope === "session") refreshCommands(activeTabContext()).catch((error) => addEvent(error.message || String(error), "error"));
|
|
40234
41952
|
} catch (error) {
|
|
@@ -40239,16 +41957,32 @@ async function openNativeSkillsSelector() {
|
|
|
40239
41957
|
}
|
|
40240
41958
|
},
|
|
40241
41959
|
});
|
|
41960
|
+
if (scope === "model" && models.length) {
|
|
41961
|
+
elements.nativeCommandBody.prepend(nativeResourceModelControl(models, modelIndex, {
|
|
41962
|
+
saving: !!savingName,
|
|
41963
|
+
onChange: async (nextIndex) => {
|
|
41964
|
+
if (nextIndex === modelIndex || savingName || !models[nextIndex]) return;
|
|
41965
|
+
modelIndex = nextIndex;
|
|
41966
|
+
await load();
|
|
41967
|
+
},
|
|
41968
|
+
}));
|
|
41969
|
+
}
|
|
40242
41970
|
elements.nativeCommandBody.prepend(nativeResourceScopeControl(scope, {
|
|
40243
41971
|
configured,
|
|
40244
41972
|
saving: !!savingName,
|
|
40245
41973
|
onChange: async (nextScope) => {
|
|
40246
41974
|
if (nextScope === scope || savingName) return;
|
|
41975
|
+
if (nextScope === "model" && !(await applyModelScope())) {
|
|
41976
|
+
render();
|
|
41977
|
+
return;
|
|
41978
|
+
}
|
|
40247
41979
|
scope = nextScope;
|
|
40248
41980
|
await load();
|
|
40249
41981
|
},
|
|
40250
41982
|
}));
|
|
40251
|
-
renderNativeResourceFilterActions(filter, (value) => { filter = value; }, render
|
|
41983
|
+
renderNativeResourceFilterActions(filter, (value) => { filter = value; }, render, [
|
|
41984
|
+
{ label: "Use inherited defaults", handler: inheritSelection, disabled: !!savingName },
|
|
41985
|
+
]);
|
|
40252
41986
|
};
|
|
40253
41987
|
|
|
40254
41988
|
elements.nativeCommandSearch.oninput = render;
|
|
@@ -41061,8 +42795,11 @@ function streamingThinkingTextFallback(event) {
|
|
|
41061
42795
|
return assistantThinkingTextFromMessage(assistantStreamingMessage(event), { streaming: true });
|
|
41062
42796
|
}
|
|
41063
42797
|
|
|
41064
|
-
function setStreamThinkingRawText(text) {
|
|
41065
|
-
const
|
|
42798
|
+
function setStreamThinkingRawText(text, { reconcile = false } = {}) {
|
|
42799
|
+
const snapshot = visibleThinkingText(text);
|
|
42800
|
+
const thinking = reconcile
|
|
42801
|
+
? reconcileTranscriptThinkingSnapshot(streamThinkingRawText, snapshot)
|
|
42802
|
+
: snapshot;
|
|
41066
42803
|
if (thinking === streamThinkingRawText) return false;
|
|
41067
42804
|
streamThinkingRawText = thinking;
|
|
41068
42805
|
return true;
|
|
@@ -41087,10 +42824,10 @@ function syncStreamingThinkingFromUpdate(event, update, { placeholder = "" } = {
|
|
|
41087
42824
|
return streamThinkingRawText ? setStreamingThinkingText(streamThinkingRawText || placeholder) : false;
|
|
41088
42825
|
}
|
|
41089
42826
|
if (update.type === "thinking_end") {
|
|
41090
|
-
if (delta) setStreamThinkingRawText(delta);
|
|
42827
|
+
if (delta) setStreamThinkingRawText(delta, { reconcile: true });
|
|
41091
42828
|
else {
|
|
41092
42829
|
const fallback = streamingThinkingTextFallback(event);
|
|
41093
|
-
if (fallback !== null) setStreamThinkingRawText(fallback);
|
|
42830
|
+
if (fallback !== null) setStreamThinkingRawText(fallback, { reconcile: true });
|
|
41094
42831
|
}
|
|
41095
42832
|
return setStreamingThinkingText(streamThinkingRawText || placeholder);
|
|
41096
42833
|
}
|
|
@@ -41162,6 +42899,8 @@ async function refreshState(tabContext = activeTabContext()) {
|
|
|
41162
42899
|
if (!isCurrentTabContext(tabContext)) return;
|
|
41163
42900
|
const previousState = currentState;
|
|
41164
42901
|
currentState = response.data || null;
|
|
42902
|
+
if (currentState) tabStateCache.set(tabContext.tabId, currentState);
|
|
42903
|
+
else tabStateCache.delete(tabContext.tabId);
|
|
41165
42904
|
if (latestMessages.length) {
|
|
41166
42905
|
latestMessagesSessionKey = resolveMessagesSessionKey(tabContext.tabId);
|
|
41167
42906
|
cacheMessagesForTab(tabContext.tabId, latestMessages, latestMessagesSessionKey);
|
|
@@ -41184,6 +42923,8 @@ async function refreshStats(tabContext = activeTabContext()) {
|
|
|
41184
42923
|
const response = await api("/api/stats", { tabId: tabContext.tabId });
|
|
41185
42924
|
if (!isCurrentTabContext(tabContext)) return;
|
|
41186
42925
|
latestStats = response.data || null;
|
|
42926
|
+
if (latestStats) tabStatsCache.set(tabContext.tabId, latestStats);
|
|
42927
|
+
else tabStatsCache.delete(tabContext.tabId);
|
|
41187
42928
|
renderFooter();
|
|
41188
42929
|
renderContextMeter();
|
|
41189
42930
|
renderWorkspaceDashboard();
|
|
@@ -41210,6 +42951,8 @@ async function refreshWorkspace(tabContext = activeTabContext()) {
|
|
|
41210
42951
|
}
|
|
41211
42952
|
if (!isCurrentTabContext(tabContext)) return;
|
|
41212
42953
|
latestWorkspace = nextWorkspace;
|
|
42954
|
+
if (latestWorkspace) tabWorkspaceCache.set(tabContext.tabId, latestWorkspace);
|
|
42955
|
+
else tabWorkspaceCache.delete(tabContext.tabId);
|
|
41213
42956
|
rememberServerStartCwd(nextWorkspace?.cwd);
|
|
41214
42957
|
renderFooter();
|
|
41215
42958
|
renderWorkspaceDashboard();
|
|
@@ -41275,6 +43018,8 @@ function renderNetworkStatus() {
|
|
|
41275
43018
|
const authDetail = make("div", "network-status-detail", authText);
|
|
41276
43019
|
|
|
41277
43020
|
elements.networkStatus.replaceChildren(heading, detail, list, authDetail);
|
|
43021
|
+
const remoteAuthRow = elements.remoteAuthToggle?.closest(".remote-auth-control-row");
|
|
43022
|
+
if (remoteAuthRow) remoteAuthRow.hidden = false;
|
|
41278
43023
|
elements.remoteAuthToggle.checked = !!auth.enabled;
|
|
41279
43024
|
elements.remoteAuthToggle.disabled = rebinding;
|
|
41280
43025
|
elements.remoteAuthStatus.textContent = auth.enabled
|
|
@@ -41385,6 +43130,7 @@ function restoreCachedMessagesForActiveTab() {
|
|
|
41385
43130
|
latestMessages = cached.messages;
|
|
41386
43131
|
latestMessagesSessionKey = cached.sessionKey || resolveMessagesSessionKey(activeTabId);
|
|
41387
43132
|
renderMessages(latestMessages);
|
|
43133
|
+
if (autoFollowChat) setChatScrollTopInstant(elements.chat.scrollHeight);
|
|
41388
43134
|
return true;
|
|
41389
43135
|
}
|
|
41390
43136
|
|
|
@@ -41412,45 +43158,86 @@ function mergeMessagesDelta(previous, data) {
|
|
|
41412
43158
|
return previous.slice(0, since).concat(data.messages);
|
|
41413
43159
|
}
|
|
41414
43160
|
|
|
41415
|
-
|
|
41416
|
-
|
|
41417
|
-
|
|
41418
|
-
|
|
41419
|
-
|
|
41420
|
-
|
|
41421
|
-
|
|
41422
|
-
|
|
41423
|
-
|
|
41424
|
-
|
|
41425
|
-
|
|
43161
|
+
function mainOutputLoadingRequestIsCurrent(request) {
|
|
43162
|
+
return !!request?.tabContext && isCurrentTabContext(request.tabContext);
|
|
43163
|
+
}
|
|
43164
|
+
|
|
43165
|
+
function renderMainOutputLoading({ reveal = false } = {}) {
|
|
43166
|
+
const active = [...mainOutputLoadingRequests].some(mainOutputLoadingRequestIsCurrent);
|
|
43167
|
+
elements.chat?.setAttribute("aria-busy", active ? "true" : "false");
|
|
43168
|
+
clearTimeout(mainOutputLoadingRevealTimer);
|
|
43169
|
+
mainOutputLoadingRevealTimer = null;
|
|
43170
|
+
if (!elements.mainOutputLoading) return;
|
|
43171
|
+
if (!active) {
|
|
43172
|
+
elements.mainOutputLoading.hidden = true;
|
|
43173
|
+
return;
|
|
41426
43174
|
}
|
|
41427
|
-
if (
|
|
41428
|
-
|
|
41429
|
-
|
|
41430
|
-
nextMessages = response.data?.messages || [];
|
|
43175
|
+
if (reveal) {
|
|
43176
|
+
elements.mainOutputLoading.hidden = false;
|
|
43177
|
+
return;
|
|
41431
43178
|
}
|
|
41432
|
-
|
|
41433
|
-
|
|
41434
|
-
|
|
41435
|
-
|
|
41436
|
-
|
|
41437
|
-
|
|
41438
|
-
|
|
41439
|
-
|
|
41440
|
-
|
|
43179
|
+
mainOutputLoadingRevealTimer = setTimeout(() => {
|
|
43180
|
+
mainOutputLoadingRevealTimer = null;
|
|
43181
|
+
if ([...mainOutputLoadingRequests].some(mainOutputLoadingRequestIsCurrent)) elements.mainOutputLoading.hidden = false;
|
|
43182
|
+
}, MAIN_OUTPUT_LOADING_REVEAL_DELAY_MS);
|
|
43183
|
+
}
|
|
43184
|
+
|
|
43185
|
+
function beginMainOutputLoading(tabContext) {
|
|
43186
|
+
const request = { tabContext: { ...tabContext } };
|
|
43187
|
+
mainOutputLoadingRequests.add(request);
|
|
43188
|
+
renderMainOutputLoading();
|
|
43189
|
+
return request;
|
|
43190
|
+
}
|
|
43191
|
+
|
|
43192
|
+
function finishMainOutputLoading(request) {
|
|
43193
|
+
mainOutputLoadingRequests.delete(request);
|
|
43194
|
+
renderMainOutputLoading();
|
|
43195
|
+
}
|
|
43196
|
+
|
|
43197
|
+
async function refreshMessages(tabContext = activeTabContext(), { authoritative = false } = {}) {
|
|
43198
|
+
if (!tabContext.tabId) return;
|
|
43199
|
+
const loadingRequest = beginMainOutputLoading(tabContext);
|
|
43200
|
+
try {
|
|
43201
|
+
const previousMessages = latestMessages;
|
|
43202
|
+
const sessionKey = resolveMessagesSessionKey(tabContext.tabId);
|
|
43203
|
+
let nextMessages = null;
|
|
43204
|
+
if (!authoritative && previousMessages.length > 1 && sessionKey === latestMessagesSessionKey) {
|
|
43205
|
+
// Delta fetch with a one-message overlap: the last known message is
|
|
43206
|
+
// re-requested so retroactive changes are detected via mergeMessagesDelta.
|
|
43207
|
+
const response = await api(`/api/messages?since=${previousMessages.length - 1}`, { tabId: tabContext.tabId });
|
|
43208
|
+
if (!isCurrentTabContext(tabContext)) return;
|
|
43209
|
+
nextMessages = mergeMessagesDelta(previousMessages, response.data);
|
|
43210
|
+
}
|
|
43211
|
+
if (!nextMessages) {
|
|
43212
|
+
const response = await api("/api/messages", { tabId: tabContext.tabId });
|
|
43213
|
+
if (!isCurrentTabContext(tabContext)) return;
|
|
43214
|
+
nextMessages = response.data?.messages || [];
|
|
43215
|
+
}
|
|
43216
|
+
latestMessages = nextMessages;
|
|
43217
|
+
latestMessagesSessionKey = sessionKey;
|
|
43218
|
+
cacheMessagesForTab(tabContext.tabId, latestMessages, latestMessagesSessionKey);
|
|
43219
|
+
const selectionSnapshot = captureChatTextSelection();
|
|
43220
|
+
const preserveCompactStream = compactLiveStreamRenderActive();
|
|
43221
|
+
const preserveNormalStream = !preserveCompactStream && liveStreamRenderActive();
|
|
43222
|
+
if (!preserveCompactStream && !preserveNormalStream) {
|
|
43223
|
+
const adoptedOutput = adoptLiveAssistantBubble(latestMessages);
|
|
43224
|
+
resetStreamBubble({ preserveCompact: adoptedOutput === "compact" });
|
|
43225
|
+
}
|
|
43226
|
+
renderMessages(latestMessages);
|
|
43227
|
+
if (preserveCompactStream) restoreCompactLiveOutputAfterChatRebuild();
|
|
43228
|
+
else if (preserveNormalStream) restoreStreamRenderAfterChatRebuild();
|
|
43229
|
+
restoreChatTextSelection(selectionSnapshot);
|
|
43230
|
+
markTabOutputSeen();
|
|
43231
|
+
// Authoritative content just landed: derive the todo-progress record once
|
|
43232
|
+
// here instead of from raw token cadence, and let the coalesced semantic
|
|
43233
|
+
// reconciler own the footer/widget chrome that message data can change.
|
|
43234
|
+
// syncLiveTodoProgressWidgetFromText owns the frame-coalesced widget render
|
|
43235
|
+
// and only fires when the parsed checklist value actually changed.
|
|
43236
|
+
reconcileTodoProgressFromMessages(latestMessages, tabContext.tabId);
|
|
43237
|
+
scheduleSemanticReconcile({ footer: true }, tabContext);
|
|
43238
|
+
} finally {
|
|
43239
|
+
finishMainOutputLoading(loadingRequest);
|
|
41441
43240
|
}
|
|
41442
|
-
renderMessages(latestMessages);
|
|
41443
|
-
if (preserveCompactStream) restoreCompactLiveOutputAfterChatRebuild();
|
|
41444
|
-
else if (preserveNormalStream) restoreStreamRenderAfterChatRebuild();
|
|
41445
|
-
restoreChatTextSelection(selectionSnapshot);
|
|
41446
|
-
markTabOutputSeen();
|
|
41447
|
-
// Authoritative content just landed: derive the todo-progress record once
|
|
41448
|
-
// here instead of from raw token cadence, and let the coalesced semantic
|
|
41449
|
-
// reconciler own the footer/widget chrome that message data can change.
|
|
41450
|
-
// syncLiveTodoProgressWidgetFromText owns the frame-coalesced widget render
|
|
41451
|
-
// and only fires when the parsed checklist value actually changed.
|
|
41452
|
-
reconcileTodoProgressFromMessages(latestMessages, tabContext.tabId);
|
|
41453
|
-
scheduleSemanticReconcile({ footer: true }, tabContext);
|
|
41454
43241
|
}
|
|
41455
43242
|
|
|
41456
43243
|
async function refreshModels(tabContext = activeTabContext()) {
|
|
@@ -41548,19 +43335,23 @@ function populateModelSelect(models = availableModels, query = "") {
|
|
|
41548
43335
|
const previousValue = elements.modelSelect.value;
|
|
41549
43336
|
const normalizedQuery = String(query || "").trim().toLowerCase();
|
|
41550
43337
|
const matchingModels = models.filter((model) => !normalizedQuery || modelSelectOptionText(model).toLowerCase().includes(normalizedQuery));
|
|
41551
|
-
|
|
41552
|
-
|
|
41553
|
-
|
|
41554
|
-
|
|
41555
|
-
|
|
41556
|
-
|
|
41557
|
-
|
|
41558
|
-
|
|
41559
|
-
|
|
41560
|
-
|
|
41561
|
-
|
|
41562
|
-
|
|
41563
|
-
|
|
43338
|
+
const optionsSignature = JSON.stringify(matchingModels.map((model) => [modelSelectValue(model), modelSelectOptionText(model)]));
|
|
43339
|
+
if (elements.modelSelect.dataset.optionsSignature !== optionsSignature) {
|
|
43340
|
+
elements.modelSelect.dataset.optionsSignature = optionsSignature;
|
|
43341
|
+
elements.modelSelect.replaceChildren();
|
|
43342
|
+
for (const model of matchingModels) {
|
|
43343
|
+
const option = document.createElement("option");
|
|
43344
|
+
option.value = modelSelectValue(model);
|
|
43345
|
+
option.textContent = modelSelectOptionText(model);
|
|
43346
|
+
elements.modelSelect.append(option);
|
|
43347
|
+
}
|
|
43348
|
+
if (!matchingModels.length) {
|
|
43349
|
+
const option = document.createElement("option");
|
|
43350
|
+
option.value = "";
|
|
43351
|
+
option.textContent = "No models match the search";
|
|
43352
|
+
option.disabled = true;
|
|
43353
|
+
elements.modelSelect.append(option);
|
|
43354
|
+
}
|
|
41564
43355
|
}
|
|
41565
43356
|
if (previousValue && [...elements.modelSelect.options].some((option) => option.value === previousValue)) elements.modelSelect.value = previousValue;
|
|
41566
43357
|
renderModelSearchResults(matchingModels);
|
|
@@ -42243,8 +44034,9 @@ async function refreshCommands(tabContext = activeTabContext()) {
|
|
|
42243
44034
|
// Keep results for their originating tab even when the active tab changed
|
|
42244
44035
|
// while this request was in flight. Guided Git must never borrow another
|
|
42245
44036
|
// tab's extension availability or duplicate-command alias.
|
|
44037
|
+
const previousCatalog = commandCatalogsByTab.get(tabContext.tabId);
|
|
42246
44038
|
commandCatalogsByTab.set(tabContext.tabId, catalog);
|
|
42247
|
-
scheduleTabsRender();
|
|
44039
|
+
if (tabsSnapshotSignature(previousCatalog) !== tabsSnapshotSignature(catalog)) scheduleTabsRender();
|
|
42248
44040
|
if (!isCurrentTabContext(tabContext)) return;
|
|
42249
44041
|
rawAvailableCommands = catalog.raw;
|
|
42250
44042
|
availableCommands = catalog.available;
|
|
@@ -42451,6 +44243,7 @@ async function refreshAll(tabContext = activeTabContext()) {
|
|
|
42451
44243
|
const results = await Promise.allSettled([
|
|
42452
44244
|
refreshState(tabContext),
|
|
42453
44245
|
refreshMessages(tabContext),
|
|
44246
|
+
refreshIntercomConversationSummaries(tabContext),
|
|
42454
44247
|
...supplementalRefreshRequests(tabContext),
|
|
42455
44248
|
]);
|
|
42456
44249
|
if (!isCurrentTabContext(tabContext)) return;
|
|
@@ -43816,6 +45609,7 @@ function handleEvent(event) {
|
|
|
43816
45609
|
return;
|
|
43817
45610
|
}
|
|
43818
45611
|
const tabContext = activeTabContext(event.tabId || activeTabId);
|
|
45612
|
+
if (["webui_connected", "agent_end", "message_end", "tool_execution_end"].includes(event.type)) scheduleIntercomConversationRefresh(tabContext);
|
|
43819
45613
|
switch (event.type) {
|
|
43820
45614
|
case "webui_connected": {
|
|
43821
45615
|
const connectedTabId = event.tabId || activeTabId;
|
|
@@ -44039,6 +45833,11 @@ function handleEvent(event) {
|
|
|
44039
45833
|
case "tool_execution_start":
|
|
44040
45834
|
streamToolCallSeen = true;
|
|
44041
45835
|
if (voiceConversationActiveFor(event.tabId || activeTabId)) voiceConversation.setAssistantActivity({ toolRunning: true });
|
|
45836
|
+
if (isIntercomTransportToolName(event.toolName)) {
|
|
45837
|
+
resetStreamingToolCallState({ remove: true });
|
|
45838
|
+
setRunIndicatorActivity("Agent is coordinating with another agent…");
|
|
45839
|
+
break;
|
|
45840
|
+
}
|
|
44042
45841
|
if (compactOutputActive()) {
|
|
44043
45842
|
compactLiveScheduler.flushNow();
|
|
44044
45843
|
renderCompactToolShell(event);
|
|
@@ -44052,6 +45851,12 @@ function handleEvent(event) {
|
|
|
44052
45851
|
break;
|
|
44053
45852
|
case "tool_execution_end": {
|
|
44054
45853
|
if (voiceConversationActiveFor(event.tabId || activeTabId)) voiceConversation.setAssistantActivity({ toolRunning: false });
|
|
45854
|
+
if (isIntercomTransportToolName(event.toolName)) {
|
|
45855
|
+
resetStreamingToolCallState({ remove: true });
|
|
45856
|
+
setRunIndicatorActivity("Agent coordination finished; waiting for the next step…");
|
|
45857
|
+
scheduleSemanticReconcile({ messages: true, footerData: true }, tabContext);
|
|
45858
|
+
break;
|
|
45859
|
+
}
|
|
44055
45860
|
const imagePayloadError = toolImagePayloadError(event);
|
|
44056
45861
|
if (imagePayloadError) surfaceRuntimeDiagnostic("Tool image payload error", imagePayloadError);
|
|
44057
45862
|
if (compactOutputActive()) {
|
|
@@ -44190,6 +45995,7 @@ function connectEvents(tabContext = activeTabContext(), { requestedMode = "auto"
|
|
|
44190
45995
|
source.onopen = () => {
|
|
44191
45996
|
if (eventSource !== source || !isCurrentTabContext(tabContext)) return;
|
|
44192
45997
|
if (!eventStreamPausedForBackground) refreshOptionalFeaturePackageStatuses().catch(() => {});
|
|
45998
|
+
scheduleIntercomConversationRefresh(tabContext, 0);
|
|
44193
45999
|
};
|
|
44194
46000
|
source.onmessage = (message) => {
|
|
44195
46001
|
if (eventSource !== source || !isCurrentTabContext(tabContext)) return;
|
|
@@ -44264,6 +46070,11 @@ elements.skillEditorDialog?.addEventListener("keydown", (event) => {
|
|
|
44264
46070
|
if (!elements.skillEditorSaveButton?.disabled) saveSkillEditor();
|
|
44265
46071
|
});
|
|
44266
46072
|
elements.skillEditorDialog?.querySelector("form")?.addEventListener("submit", (event) => event.preventDefault());
|
|
46073
|
+
elements.intercomConversationDialog?.addEventListener("close", resetIntercomConversationDialog);
|
|
46074
|
+
elements.intercomConversationDialog?.addEventListener("cancel", () => {
|
|
46075
|
+
clearTimeout(intercomDetailRefreshTimer);
|
|
46076
|
+
intercomDetailRefreshTimer = null;
|
|
46077
|
+
});
|
|
44267
46078
|
elements.featureCategoryTag?.addEventListener("click", openFeatureDecisionDialog);
|
|
44268
46079
|
elements.featureDecisionDialog?.addEventListener("close", () => {
|
|
44269
46080
|
featureDecisionDialogTabId = null;
|
|
@@ -44558,6 +46369,8 @@ elements.optionsSummarySetupButton?.addEventListener("click", () => runNativeCom
|
|
|
44558
46369
|
elements.optionsWorkflowSetupButton?.addEventListener("click", () => runNativeCommandMenu("/workflow-setup"));
|
|
44559
46370
|
elements.optionsSafetyGuardSetupButton?.addEventListener("click", () => runNativeCommandMenu("/safety-guard-setup"));
|
|
44560
46371
|
elements.optionsGitWorkflowSetupButton?.addEventListener("click", () => runNativeCommandMenu("/git-workflow-setup"));
|
|
46372
|
+
elements.optionsToolsSetupButton?.addEventListener("click", () => runNativeCommandMenu("/tools"));
|
|
46373
|
+
elements.optionsSkillsSetupButton?.addEventListener("click", () => runNativeCommandMenu("/skills"));
|
|
44561
46374
|
elements.optionsExportButton.addEventListener("click", () => runNativeCommandMenu("/export"));
|
|
44562
46375
|
elements.optionsForkButton.addEventListener("click", () => runNativeCommandMenu("/fork"));
|
|
44563
46376
|
elements.optionsTreeButton.addEventListener("click", () => runNativeCommandMenu("/tree"));
|
|
@@ -45163,6 +46976,16 @@ if (elements.terminalTabsLayoutSelect) {
|
|
|
45163
46976
|
setTerminalTabsLayout(elements.terminalTabsLayoutSelect.value, { announce: true });
|
|
45164
46977
|
});
|
|
45165
46978
|
}
|
|
46979
|
+
if (elements.controlDeckPlacementSelect) {
|
|
46980
|
+
elements.controlDeckPlacementSelect.addEventListener("change", () => {
|
|
46981
|
+
const placement = normalizeControlDeckPlacement(elements.controlDeckPlacementSelect.value);
|
|
46982
|
+
controlDeckLayout.placement = placement;
|
|
46983
|
+
cacheControlDeckLayout(controlDeckLayout, "placement");
|
|
46984
|
+
markDurableUiLayoutDirty("sidePanel", "placement");
|
|
46985
|
+
reconcileControlDeckHosts();
|
|
46986
|
+
addEvent(`Control Deck placement changed to ${placement}.`);
|
|
46987
|
+
});
|
|
46988
|
+
}
|
|
45166
46989
|
if (elements.subagentOpenModeSelect) {
|
|
45167
46990
|
elements.subagentOpenModeSelect.addEventListener("change", () => {
|
|
45168
46991
|
setSubagentOpenMode(elements.subagentOpenModeSelect.value, { announce: true });
|
|
@@ -45270,10 +47093,16 @@ elements.sidePanelEditButton?.addEventListener("click", () => {
|
|
|
45270
47093
|
setSidePanelSectionEditMode(!sidePanelSectionEditMode);
|
|
45271
47094
|
});
|
|
45272
47095
|
elements.toggleSidePanelButton.addEventListener("click", () => {
|
|
45273
|
-
setSidePanelCollapsed(true);
|
|
47096
|
+
setSidePanelCollapsed(true, { side: "right" });
|
|
47097
|
+
});
|
|
47098
|
+
elements.toggleSidePanelLeftButton?.addEventListener("click", () => {
|
|
47099
|
+
setSidePanelCollapsed(true, { side: "left" });
|
|
45274
47100
|
});
|
|
45275
47101
|
elements.sidePanelExpandButton.addEventListener("click", () => {
|
|
45276
|
-
setSidePanelCollapsed(false, { focusPanel: true });
|
|
47102
|
+
setSidePanelCollapsed(false, { focusPanel: true, side: "right" });
|
|
47103
|
+
});
|
|
47104
|
+
elements.sidePanelLeftExpandButton?.addEventListener("click", () => {
|
|
47105
|
+
setSidePanelCollapsed(false, { focusPanel: true, side: "left" });
|
|
45277
47106
|
});
|
|
45278
47107
|
elements.sidePanelBackdrop.addEventListener("click", () => {
|
|
45279
47108
|
setSidePanelCollapsed(true);
|
|
@@ -45611,24 +47440,45 @@ window.addEventListener("offline", () => {
|
|
|
45611
47440
|
});
|
|
45612
47441
|
window.addEventListener("beforeunload", persistMobileContinuityState);
|
|
45613
47442
|
window.addEventListener("storage", (event) => {
|
|
47443
|
+
const sidePanelDirty = durableLayoutDirtyFields.get("sidePanel")?.subfields || new Set();
|
|
47444
|
+
const hasControlDeckV2Cache = (() => {
|
|
47445
|
+
try { return localStorage.getItem(CONTROL_DECK_LAYOUT_STORAGE_KEY) !== null; } catch { return false; }
|
|
47446
|
+
})();
|
|
47447
|
+
const ignoreLegacySidePanelEvent = (subfield, active = false) => hasControlDeckV2Cache || sidePanelDirty.has(subfield) || active;
|
|
45614
47448
|
if (event.key === OPTIONAL_FEATURES_STORAGE_KEY) reconcileDisabledOptionalFeaturesFromStorage();
|
|
45615
47449
|
if (event.key === OPTIONAL_FEATURE_MIGRATION_DISMISS_STORAGE_KEY && optionalFeatureMigrationCompletionIsDismissed()) {
|
|
45616
47450
|
optionalFeatureRestartNotice = null;
|
|
45617
47451
|
renderOptionalFeatureMigrationSurface();
|
|
45618
47452
|
}
|
|
45619
|
-
if (event.key === SIDE_PANEL_SECTION_VISIBILITY_STORAGE_KEY) restoreSidePanelSectionVisibility();
|
|
45620
|
-
if (event.key === SIDE_PANEL_SECTION_ORDER_STORAGE_KEY
|
|
47453
|
+
if (event.key === SIDE_PANEL_SECTION_VISIBILITY_STORAGE_KEY && !ignoreLegacySidePanelEvent("hiddenSectionIds")) restoreSidePanelSectionVisibility();
|
|
47454
|
+
if (event.key === SIDE_PANEL_SECTION_ORDER_STORAGE_KEY && !ignoreLegacySidePanelEvent("sectionLayout", Boolean(sidePanelSectionPointerDrag?.active))) {
|
|
47455
|
+
controlDeckLayout.sectionLayout = { ...controlDeckLayout.sectionLayout, order: readStoredSidePanelSectionOrder() || [] };
|
|
47456
|
+
restoreSidePanelSectionOrder();
|
|
47457
|
+
}
|
|
47458
|
+
if (event.key === CONTROL_DECK_LAYOUT_STORAGE_KEY) {
|
|
47459
|
+
const incoming = readStoredControlDeckLayout();
|
|
47460
|
+
const dirty = sidePanelDirty;
|
|
47461
|
+
const sectionActive = Boolean(sidePanelSectionPointerDrag?.active);
|
|
47462
|
+
const widthActive = Boolean(sidePanelResizeState);
|
|
47463
|
+
const cleanSiblings = {};
|
|
47464
|
+
for (const subfield of UI_LAYOUT_SIDE_PANEL_FIELDS) {
|
|
47465
|
+
const activelyManipulated = (subfield === "sectionLayout" && sectionActive) || (subfield === "panelWidths" && widthActive);
|
|
47466
|
+
if (!dirty.has(subfield) && !activelyManipulated && durableUiLayoutValuePresent(incoming?.[subfield])) cleanSiblings[subfield] = incoming[subfield];
|
|
47467
|
+
}
|
|
47468
|
+
applyDurableSidePanelLayout(cleanSiblings);
|
|
47469
|
+
}
|
|
45621
47470
|
if (event.key === COMPOSER_ACTION_ORDER_STORAGE_KEY) restoreComposerActionOrder();
|
|
45622
47471
|
if (event.key === COMPOSER_ACTION_LAYOUT_STORAGE_KEY) restoreComposerActionSlotLayout();
|
|
45623
|
-
if (event.key === SIDE_PANEL_WIDTH_STORAGE_KEY) {
|
|
47472
|
+
if (event.key === SIDE_PANEL_WIDTH_STORAGE_KEY && !ignoreLegacySidePanelEvent("panelWidths", Boolean(sidePanelResizeState))) {
|
|
45624
47473
|
const width = readStoredSidePanelWidth();
|
|
45625
47474
|
if (width && !isSidePanelOverlayView()) applySidePanelWidth(width);
|
|
45626
47475
|
}
|
|
45627
47476
|
// Another same-origin tab already saved these durable fields, so receiving
|
|
45628
47477
|
// tabs only adopt the shared local cache without repeating the server write.
|
|
45629
|
-
if (event.key === SIDE_PANEL_SECTION_STORAGE_KEY) restoreSidePanelSectionState();
|
|
45630
|
-
if (event.key === SIDE_PANEL_STORAGE_KEY) restoreSidePanelState();
|
|
47478
|
+
if (event.key === SIDE_PANEL_SECTION_STORAGE_KEY && !ignoreLegacySidePanelEvent("collapsedSectionIds")) restoreSidePanelSectionState();
|
|
47479
|
+
if (event.key === SIDE_PANEL_STORAGE_KEY && !ignoreLegacySidePanelEvent("collapsedPanels")) restoreSidePanelState();
|
|
45631
47480
|
if (event.key === TERMINAL_TABS_LAYOUT_STORAGE_KEY) restoreTerminalTabsLayoutSetting();
|
|
47481
|
+
if (event.key === TERMINAL_TABS_SIDEBAR_WIDTH_STORAGE_KEY) restoreTerminalTabsSidebarWidthPreference();
|
|
45632
47482
|
if (event.key === TERMINAL_CUSTOM_GROUPS_STORAGE_KEY) {
|
|
45633
47483
|
restoreTerminalCustomGroups();
|
|
45634
47484
|
syncTerminalCustomGroupsWithTabs(tabs, { persist: false });
|
|
@@ -45648,7 +47498,7 @@ window.addEventListener("pageshow", () => reconcileDurableUiLayout());
|
|
|
45648
47498
|
document.addEventListener("visibilitychange", () => {
|
|
45649
47499
|
if (document.visibilityState === "visible") reconcileDurableUiLayout();
|
|
45650
47500
|
});
|
|
45651
|
-
window.addEventListener("resize",
|
|
47501
|
+
window.addEventListener("resize", scheduleControlDeckPresentationReconciliation, { passive: true });
|
|
45652
47502
|
window.addEventListener("keydown", (event) => {
|
|
45653
47503
|
if (event.key !== "Escape") return;
|
|
45654
47504
|
if (event.defaultPrevented) return;
|
|
@@ -45885,6 +47735,10 @@ elements.fileContextMenu?.addEventListener("click", (event) => {
|
|
|
45885
47735
|
elements.fileViewerOpenDefaultButton?.addEventListener("click", () => openPathInDefaultEditor(currentFileViewerPath()));
|
|
45886
47736
|
elements.sidePanelResizeHandle?.addEventListener("pointerdown", beginSidePanelResize);
|
|
45887
47737
|
elements.sidePanelResizeHandle?.addEventListener("keydown", handleSidePanelResizeKeydown);
|
|
47738
|
+
elements.sidePanelResizeHandleLeft?.addEventListener("pointerdown", (event) => beginSidePanelResize(event, "left"));
|
|
47739
|
+
elements.sidePanelResizeHandleLeft?.addEventListener("keydown", handleSidePanelResizeKeydown);
|
|
47740
|
+
elements.terminalTabsResizeHandle?.addEventListener("pointerdown", beginTerminalTabsSidebarResize);
|
|
47741
|
+
elements.terminalTabsResizeHandle?.addEventListener("keydown", handleTerminalTabsSidebarResizeKeydown);
|
|
45888
47742
|
elements.fileViewerResizeHandle?.addEventListener("pointerdown", beginFileViewerResize);
|
|
45889
47743
|
elements.fileViewerResizeHandle?.addEventListener("keydown", handleFileViewerResizeKeydown);
|
|
45890
47744
|
elements.fileViewerSaveButton?.addEventListener("click", () => saveActiveFileViewer());
|
|
@@ -46077,6 +47931,7 @@ clearRemovedSidePanelSectionHeightState();
|
|
|
46077
47931
|
restoreDurableUiLayoutPendingJournal();
|
|
46078
47932
|
restoreSidePanelWidthPreference();
|
|
46079
47933
|
restoreFileViewerWidthPreference();
|
|
47934
|
+
restoreTerminalTabsSidebarWidthPreference();
|
|
46080
47935
|
focusPromptInput({ defer: true });
|
|
46081
47936
|
restoreStoredSkillUsage();
|
|
46082
47937
|
restoreBusyPromptBehaviorSetting();
|
|
@@ -46108,10 +47963,12 @@ restoreToolOutputExpansionSetting();
|
|
|
46108
47963
|
restoreWorkspaceDashboardState();
|
|
46109
47964
|
restoreInterfaceDensity();
|
|
46110
47965
|
initializeTerminalHeaderTooltips();
|
|
47966
|
+
initializeControlSettingTooltips();
|
|
46111
47967
|
initializeComposerActionOrdering();
|
|
46112
47968
|
restoreSidePanelSectionOrder();
|
|
46113
47969
|
restoreSidePanelSectionVisibility();
|
|
46114
47970
|
restoreSidePanelSectionState();
|
|
47971
|
+
reconcileControlDeckHosts();
|
|
46115
47972
|
setSidePanelSectionEditMode(false);
|
|
46116
47973
|
bindSidePanelSectionToggles();
|
|
46117
47974
|
restoreSidePanelState();
|