@firstpick/pi-package-webui 0.9.2 → 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 +13 -7
- package/bin/pi-webui.mjs +256 -39
- package/index.ts +266 -1
- package/lib/git-workflow-preferences.mjs +8 -25
- package/lib/intercom-conversations.mjs +491 -0
- package/lib/intercom-transcript-filter.mjs +99 -0
- package/lib/resource-selection.mjs +140 -0
- package/package.json +2 -2
- package/public/app.js +1025 -115
- package/public/index.html +31 -6
- package/public/service-worker.js +2 -1
- package/public/stream-output-controller.mjs +15 -0
- package/public/styles.css +394 -0
- package/public/syntax-highlight.mjs +622 -0
- package/tests/boot-failure-diagnostics.test.mjs +3 -3
- package/tests/browser/interaction-continuity.spec.mjs +34 -0
- package/tests/browser/intercom-conversation-viewer.spec.mjs +355 -0
- package/tests/browser/persistent-ui-layout.spec.mjs +61 -0
- package/tests/browser/resource-profiles.spec.mjs +200 -0
- package/tests/browser/subagent-observability.spec.mjs +29 -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/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 +4 -0
- package/tests/controls-layout-static.test.mjs +3 -3
- 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-viewer-image-static.test.mjs +69 -0
- package/tests/fixtures/fake-pi.mjs +105 -6
- 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 +4 -4
- package/tests/http-endpoints-harness.test.mjs +124 -2
- 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 +63 -39
- package/tests/native-parity.test.mjs +8 -7
- package/tests/open-issue-wizard-static.test.mjs +1 -1
- 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 +3 -3
- 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-section-height-removal-static.test.mjs +3 -3
- 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 +1 -1
- package/tests/subagent-launch-slots.test.mjs +1 -1
- package/tests/subagent-observability-static.test.mjs +3 -3
- package/tests/subagent-reliability-integration.test.mjs +23 -1
- package/tests/subagent-workflow-section-static.test.mjs +67 -0
- package/tests/subagents-helper.test.mjs +204 -1
- package/tests/syntax-highlight.test.mjs +235 -0
- package/tests/syntax-highlighting-static.test.mjs +84 -0
- package/tests/theme-customizer-static.test.mjs +5 -5
- package/tests/thinking-format-parser.test.mjs +64 -0
- package/tests/webui-settings-locking.test.mjs +1 -1
- package/webui-rpc-helper.mjs +291 -69
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,
|
|
@@ -57,6 +58,8 @@ const elements = {
|
|
|
57
58
|
contextMeterBar: $("#contextMeterBar"),
|
|
58
59
|
serverOfflinePanel: $("#serverOfflinePanel"),
|
|
59
60
|
serverRestartPanel: $("#serverRestartPanel"),
|
|
61
|
+
serverRestartKicker: $("#serverRestartKicker"),
|
|
62
|
+
serverRestartTitle: $("#serverRestartTitle"),
|
|
60
63
|
serverRestartMessage: $("#serverRestartMessage"),
|
|
61
64
|
updateNotification: $("#updateNotification"),
|
|
62
65
|
updateNotificationTitle: $("#updateNotificationTitle"),
|
|
@@ -94,6 +97,7 @@ const elements = {
|
|
|
94
97
|
subagentCancelSubmitButton: $("#subagentCancelSubmitButton"),
|
|
95
98
|
stickyUserPromptButton: $("#stickyUserPromptButton"),
|
|
96
99
|
chat: $("#chat"),
|
|
100
|
+
mainOutputLoading: $("#mainOutputLoading"),
|
|
97
101
|
runIndicatorHost: $("#runIndicatorHost"),
|
|
98
102
|
chatSearchBar: $("#chatSearchBar"),
|
|
99
103
|
chatSearchInput: $("#chatSearchInput"),
|
|
@@ -127,6 +131,13 @@ const elements = {
|
|
|
127
131
|
busyPromptBehaviorTag: $("#busyPromptBehaviorTag"),
|
|
128
132
|
busyPromptBehaviorMenu: $("#busyPromptBehaviorMenu"),
|
|
129
133
|
sessionSkillTags: $("#sessionSkillTags"),
|
|
134
|
+
intercomConversationTags: $("#intercomConversationTags"),
|
|
135
|
+
intercomConversationDialog: $("#intercomConversationDialog"),
|
|
136
|
+
intercomConversationTitle: $("#intercomConversationTitle"),
|
|
137
|
+
intercomConversationParticipants: $("#intercomConversationParticipants"),
|
|
138
|
+
intercomConversationTranscript: $("#intercomConversationTranscript"),
|
|
139
|
+
intercomConversationStatus: $("#intercomConversationStatus"),
|
|
140
|
+
intercomConversationCloseButton: $("#intercomConversationCloseButton"),
|
|
130
141
|
featureCategoryTag: $("#featureCategoryTag"),
|
|
131
142
|
featureDecisionDialog: $("#featureDecisionDialog"),
|
|
132
143
|
featureDecisionDialogOutput: $("#featureDecisionDialogOutput"),
|
|
@@ -189,6 +200,8 @@ const elements = {
|
|
|
189
200
|
optionsWorkflowSetupButton: $("#optionsWorkflowSetupButton"),
|
|
190
201
|
optionsSafetyGuardSetupButton: $("#optionsSafetyGuardSetupButton"),
|
|
191
202
|
optionsGitWorkflowSetupButton: $("#optionsGitWorkflowSetupButton"),
|
|
203
|
+
optionsToolsSetupButton: $("#optionsToolsSetupButton"),
|
|
204
|
+
optionsSkillsSetupButton: $("#optionsSkillsSetupButton"),
|
|
192
205
|
optionsExportButton: $("#optionsExportButton"),
|
|
193
206
|
optionsForkButton: $("#optionsForkButton"),
|
|
194
207
|
optionsTreeButton: $("#optionsTreeButton"),
|
|
@@ -321,6 +334,8 @@ const elements = {
|
|
|
321
334
|
fileViewerEditor: $("#fileViewerEditor"),
|
|
322
335
|
fileViewerSearchOverlay: $("#fileViewerSearchOverlay"),
|
|
323
336
|
fileViewerPreview: $("#fileViewerPreview"),
|
|
337
|
+
fileViewerImage: $("#fileViewerImage"),
|
|
338
|
+
fileViewerImageElement: $("#fileViewerImageElement"),
|
|
324
339
|
fileViewerChanges: $("#fileViewerChanges"),
|
|
325
340
|
fileViewerStatus: $("#fileViewerStatus"),
|
|
326
341
|
fileViewerSearchBar: $("#fileViewerSearchBar"),
|
|
@@ -572,6 +587,12 @@ let tabWorkspaceCache = new Map();
|
|
|
572
587
|
let tabs = [];
|
|
573
588
|
let activeTabId = null;
|
|
574
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;
|
|
575
596
|
let tabDrafts = new Map();
|
|
576
597
|
let tabAttachments = new Map();
|
|
577
598
|
let activeTextAttachmentEditor = null;
|
|
@@ -722,9 +743,17 @@ const streamOutputController = createStreamOutputController({
|
|
|
722
743
|
isOwnerCurrent: (owner) => owner === transcriptStreamOwner(),
|
|
723
744
|
applyTextUpdate: (event) => handleMessageUpdate(event),
|
|
724
745
|
applyThinkingUpdate: (event) => handleMessageUpdate(event),
|
|
725
|
-
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
|
+
},
|
|
726
755
|
applyToolExecutionUpdate: (event) => {
|
|
727
|
-
if (!compactOutputActive()) applyTranscriptToolExecutionUpdate(event);
|
|
756
|
+
if (!compactOutputActive() && !isIntercomTransportToolName(event?.toolName)) applyTranscriptToolExecutionUpdate(event);
|
|
728
757
|
},
|
|
729
758
|
applyStreamError: (event) => handleMessageUpdate(event),
|
|
730
759
|
applyFollowScroll: () => {
|
|
@@ -773,6 +802,9 @@ let runIndicatorActivity = "Waiting for output or action…";
|
|
|
773
802
|
let refreshMessagesTimer = null;
|
|
774
803
|
let refreshStateTimer = null;
|
|
775
804
|
let refreshFooterTimer = null;
|
|
805
|
+
const mainOutputLoadingRequests = new Set();
|
|
806
|
+
let mainOutputLoadingRevealTimer = null;
|
|
807
|
+
const MAIN_OUTPUT_LOADING_REVEAL_DELAY_MS = 120;
|
|
776
808
|
let refreshTabsTimer = null;
|
|
777
809
|
let tabsRenderFrame = null;
|
|
778
810
|
let foregroundReconcileTimer = null;
|
|
@@ -925,6 +957,7 @@ let subagentsClearingFinished = false;
|
|
|
925
957
|
let subagentAutoClearEnabled = false;
|
|
926
958
|
let refreshSubagentsTimer = null;
|
|
927
959
|
const dismissedSubagentGateKeys = new Set();
|
|
960
|
+
const collapsedSubagentWorkflowRunKeys = new Set();
|
|
928
961
|
let subagentOverlaySelection = null;
|
|
929
962
|
let subagentOverlayData = null;
|
|
930
963
|
let subagentOverlayError = "";
|
|
@@ -2552,6 +2585,7 @@ const OPTIONAL_FEATURES = [
|
|
|
2552
2585
|
packageName: "@firstpick/pi-extension-setup-skills",
|
|
2553
2586
|
capabilityLabel: "RPC /skills from setup-skills extension",
|
|
2554
2587
|
description: "Terminal-native skill setup command alongside WebUI-native /skills toggles.",
|
|
2588
|
+
setup: "skills",
|
|
2555
2589
|
},
|
|
2556
2590
|
{
|
|
2557
2591
|
id: "todoProgressWidget",
|
|
@@ -2566,6 +2600,7 @@ const OPTIONAL_FEATURES = [
|
|
|
2566
2600
|
packageName: "@firstpick/pi-extension-tools",
|
|
2567
2601
|
capabilityLabel: "RPC /tools from tools extension",
|
|
2568
2602
|
description: "Terminal-native active-tool manager alongside WebUI-native /tools toggles.",
|
|
2603
|
+
setup: "tools",
|
|
2569
2604
|
},
|
|
2570
2605
|
{
|
|
2571
2606
|
id: "remoteWebui",
|
|
@@ -2581,7 +2616,6 @@ const OPTIONAL_FEATURES = [
|
|
|
2581
2616
|
capabilityLabel: "questionnaire tool in /tools",
|
|
2582
2617
|
description: "Native TUI and WebUI single- or multi-select question series with Other answers and resumable clarification.",
|
|
2583
2618
|
manageWith: "tools",
|
|
2584
|
-
setup: "tools",
|
|
2585
2619
|
},
|
|
2586
2620
|
{
|
|
2587
2621
|
id: "naturalConversation",
|
|
@@ -6010,13 +6044,35 @@ function skillKindsLabel(entry) {
|
|
|
6010
6044
|
|
|
6011
6045
|
let sessionSkillTagLayoutFrame = 0;
|
|
6012
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
|
+
}
|
|
6013
6068
|
|
|
6014
6069
|
function fitSessionSkillTags() {
|
|
6015
6070
|
const container = elements.sessionSkillTags;
|
|
6016
6071
|
if (!container || container.hidden) return;
|
|
6017
|
-
const tags = [...container.querySelectorAll("button.composer-skill-tag")];
|
|
6018
|
-
const overflow = container.querySelector(".composer-skill-tag.overflow");
|
|
6019
|
-
|
|
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;
|
|
6020
6076
|
|
|
6021
6077
|
const availableWidth = container.clientWidth;
|
|
6022
6078
|
if (availableWidth <= 0) return;
|
|
@@ -6048,11 +6104,17 @@ function fitSessionSkillTags() {
|
|
|
6048
6104
|
}
|
|
6049
6105
|
|
|
6050
6106
|
tags.forEach((tag, index) => { tag.hidden = index >= visibleCount; });
|
|
6107
|
+
menuItems.forEach((item, index) => { item.hidden = index < visibleCount; });
|
|
6051
6108
|
const hiddenCount = tags.length - visibleCount;
|
|
6052
6109
|
overflow.hidden = hiddenCount === 0;
|
|
6053
6110
|
if (hiddenCount) {
|
|
6111
|
+
const label = `Show ${hiddenCount} more tracked skill${hiddenCount === 1 ? "" : "s"}`;
|
|
6054
6112
|
overflow.textContent = `+${hiddenCount}`;
|
|
6055
|
-
overflow.title = `${
|
|
6113
|
+
overflow.title = `${label}.`;
|
|
6114
|
+
overflow.setAttribute("aria-label", label);
|
|
6115
|
+
if (sessionSkillOverflowOpen) setSessionSkillOverflowOpen(true);
|
|
6116
|
+
} else {
|
|
6117
|
+
setSessionSkillOverflowOpen(false);
|
|
6056
6118
|
}
|
|
6057
6119
|
}
|
|
6058
6120
|
|
|
@@ -6074,12 +6136,28 @@ function installSessionSkillTagResizeHandling() {
|
|
|
6074
6136
|
} else {
|
|
6075
6137
|
window.addEventListener("resize", scheduleSessionSkillTagLayout, { passive: true });
|
|
6076
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
|
+
});
|
|
6077
6153
|
}
|
|
6078
6154
|
|
|
6079
6155
|
function renderSessionSkillTags(tabId = activeTabId) {
|
|
6080
6156
|
const container = elements.sessionSkillTags;
|
|
6081
6157
|
if (!container) return;
|
|
6082
6158
|
const entries = sortedSkillUsageEntries(tabId).filter((entry) => entry.kinds.has("read"));
|
|
6159
|
+
sessionSkillOverflowOpen = false;
|
|
6160
|
+
container.classList.remove("overflow-open");
|
|
6083
6161
|
container.replaceChildren();
|
|
6084
6162
|
if (!entries.length) {
|
|
6085
6163
|
container.hidden = true;
|
|
@@ -6096,13 +6174,370 @@ function renderSessionSkillTags(tabId = activeTabId) {
|
|
|
6096
6174
|
tag.addEventListener("click", () => openSkillEditor(entry));
|
|
6097
6175
|
container.append(tag);
|
|
6098
6176
|
}
|
|
6099
|
-
const overflow = make("
|
|
6177
|
+
const overflow = make("button", "composer-skill-tag overflow", `+${entries.length}`);
|
|
6178
|
+
overflow.type = "button";
|
|
6100
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
|
+
});
|
|
6101
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);
|
|
6102
6208
|
container.hidden = false;
|
|
6103
6209
|
scheduleSessionSkillTagLayout();
|
|
6104
6210
|
}
|
|
6105
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
|
+
|
|
6106
6541
|
function normalizeFeatureCategory(value) {
|
|
6107
6542
|
return value === "lightweight-feature" || value === "complex-feature" ? value : "";
|
|
6108
6543
|
}
|
|
@@ -7363,10 +7798,16 @@ function renderServerOfflinePanel() {
|
|
|
7363
7798
|
if (elements.serverOfflineSlashCommand) elements.serverOfflineSlashCommand.textContent = serverStartSlashCommandText();
|
|
7364
7799
|
}
|
|
7365
7800
|
|
|
7366
|
-
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" } = {}) {
|
|
7367
7802
|
serverRestartInProgress = !!active;
|
|
7803
|
+
const updating = phase === "updating";
|
|
7368
7804
|
document.body.classList.toggle("server-restarting", serverRestartInProgress);
|
|
7369
|
-
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";
|
|
7370
7811
|
if (elements.serverRestartMessage) elements.serverRestartMessage.textContent = message;
|
|
7371
7812
|
if (serverRestartInProgress) hideUpdateNotification();
|
|
7372
7813
|
if (serverRestartInProgress && elements.serverOfflinePanel) elements.serverOfflinePanel.hidden = true;
|
|
@@ -8189,7 +8630,8 @@ function componentUpdateButtonState(target) {
|
|
|
8189
8630
|
const pkg = latestUpdateStatus?.[target] || {};
|
|
8190
8631
|
if (job?.state === "running") return { disabled: true, label: "Updating…" };
|
|
8191
8632
|
if (job && job.canStart === false) return { disabled: true, label: `Update ${label}` };
|
|
8192
|
-
if (componentUpdateStartInProgress
|
|
8633
|
+
if (componentUpdateStartInProgress) return { disabled: true, label: "Starting…" };
|
|
8634
|
+
if (updateRequestInProgress || latestUpdateStatus?.updateInProgress || anyComponentUpdateRunning()) {
|
|
8193
8635
|
return { disabled: true, label: `Update ${label}` };
|
|
8194
8636
|
}
|
|
8195
8637
|
if (job?.state === "failed") return { disabled: false, label: `Retry ${label} update` };
|
|
@@ -8279,6 +8721,7 @@ async function startComponentUpdate(target) {
|
|
|
8279
8721
|
if (!confirmed) return;
|
|
8280
8722
|
componentUpdateStartInProgress = true;
|
|
8281
8723
|
renderComponentUpdateDialogs();
|
|
8724
|
+
setServerRestartOverlay(true, `Starting exact ${label} update…`, { phase: "updating" });
|
|
8282
8725
|
try {
|
|
8283
8726
|
const response = await api("/api/update/apply", { method: "POST", body: { transactionId: plan.transactionId, planDigest: plan.digest }, scoped: false });
|
|
8284
8727
|
const acceptedState = ["applying", "verifying", "activating"].includes(response?.data?.state)
|
|
@@ -8298,6 +8741,7 @@ async function startComponentUpdate(target) {
|
|
|
8298
8741
|
if (error?.statusCode === 409) await refreshUpdateStatus({ notify: false }).catch(() => {});
|
|
8299
8742
|
} finally {
|
|
8300
8743
|
componentUpdateStartInProgress = false;
|
|
8744
|
+
setServerRestartOverlay(false);
|
|
8301
8745
|
renderComponentUpdateIndicators();
|
|
8302
8746
|
renderComponentUpdateDialogs();
|
|
8303
8747
|
syncComponentUpdatePolling();
|
|
@@ -8372,7 +8816,7 @@ async function runPiUpdateAndRestart({ all = false } = {}) {
|
|
|
8372
8816
|
hideUpdateNotification();
|
|
8373
8817
|
setServerActionBusy("Updating…");
|
|
8374
8818
|
setServerActionStatus(progressMessage, "warn");
|
|
8375
|
-
|
|
8819
|
+
setServerRestartOverlay(true, progressMessage, { phase: "updating" });
|
|
8376
8820
|
try {
|
|
8377
8821
|
const applyData = (await api("/api/update/apply", { method: "POST", body: { transactionId: plan.transactionId, planDigest: plan.digest }, scoped: false }))?.data || null;
|
|
8378
8822
|
if (applyData?.state !== "activating") {
|
|
@@ -10467,6 +10911,15 @@ function applyTheme(theme, { persist = false, announce = false } = {}) {
|
|
|
10467
10911
|
"--background-glow-pink": colorWithAlpha(pink, isLight ? 0.16 : 0.34, pink),
|
|
10468
10912
|
"--background-glow-blue": colorWithAlpha(accent, isLight ? 0.15 : 0.32, accent),
|
|
10469
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),
|
|
10470
10923
|
"--theme-background-image": themeExportCssValue(theme, "backgroundImage", "none", LOCAL_BACKGROUND_IMAGE_PATTERN),
|
|
10471
10924
|
"--theme-background-overlay": themeExportCssValue(theme, "backgroundOverlay", "linear-gradient(180deg, rgba(17, 17, 27, 0), rgba(17, 17, 27, 0))", BACKGROUND_OVERLAY_PATTERN),
|
|
10472
10925
|
"--theme-background-size": themeExportCssValue(theme, "backgroundSize", "cover", SAFE_BACKGROUND_TOKEN_PATTERN),
|
|
@@ -11202,11 +11655,17 @@ function setActiveTabId(tabId, { remember = false } = {}) {
|
|
|
11202
11655
|
const nextTabId = tabId || null;
|
|
11203
11656
|
if (nextTabId !== activeTabId) {
|
|
11204
11657
|
activeTabGeneration += 1;
|
|
11658
|
+
intercomSummaryRequestSerial += 1;
|
|
11659
|
+
clearTimeout(intercomSummaryRefreshTimer);
|
|
11660
|
+
intercomSummaryRefreshTimer = null;
|
|
11661
|
+
closeIntercomConversationDialog({ restoreFocus: false });
|
|
11205
11662
|
closeFeatureDecisionDialog({ restoreFocus: false });
|
|
11206
11663
|
closeSessionSummaryOverlay({ restoreFocus: false });
|
|
11207
11664
|
}
|
|
11208
11665
|
activeTabId = nextTabId;
|
|
11666
|
+
renderMainOutputLoading();
|
|
11209
11667
|
bindGitWorkflowToActiveTab();
|
|
11668
|
+
renderIntercomConversationTags(nextTabId);
|
|
11210
11669
|
renderFeatureCategoryTag(nextTabId);
|
|
11211
11670
|
renderSessionSummaryControls();
|
|
11212
11671
|
if (remember) rememberActiveTab();
|
|
@@ -13400,12 +13859,22 @@ async function openFileTreeEntryInWebui(entry = fileContextMenuState?.entry) {
|
|
|
13400
13859
|
await openFileInViewer(path);
|
|
13401
13860
|
}
|
|
13402
13861
|
|
|
13403
|
-
|
|
13404
|
-
|
|
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.
|
|
13405
13873
|
function resolveFileViewerMode(viewer) {
|
|
13406
13874
|
if (!viewer) return "source";
|
|
13407
13875
|
const hasChanges = !!viewer.gitChanges;
|
|
13408
|
-
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";
|
|
13409
13878
|
if (viewer.sourceAvailable === false) return hasChanges ? "changes" : "source";
|
|
13410
13879
|
return viewer.mode === "preview" && viewer.language === "markdown" ? "preview" : "source";
|
|
13411
13880
|
}
|
|
@@ -13444,6 +13913,7 @@ function updateFileViewerUi() {
|
|
|
13444
13913
|
const viewer = activeFileViewer;
|
|
13445
13914
|
captureFileViewerEditorContinuity(viewer);
|
|
13446
13915
|
const isMarkdown = viewer.language === "markdown";
|
|
13916
|
+
const isImage = viewer.kind === "image";
|
|
13447
13917
|
const hasChanges = !!viewer.gitChanges;
|
|
13448
13918
|
const sourceAvailable = viewer.sourceAvailable !== false;
|
|
13449
13919
|
const mode = resolveFileViewerMode(viewer);
|
|
@@ -13451,7 +13921,9 @@ function updateFileViewerUi() {
|
|
|
13451
13921
|
if (elements.fileViewerTitle) elements.fileViewerTitle.textContent = viewer.name || fileDisplayName(viewer.path);
|
|
13452
13922
|
if (elements.fileViewerMeta) {
|
|
13453
13923
|
const lineCount = textLineCount(viewer.content || "");
|
|
13454
|
-
const sourceMeta =
|
|
13924
|
+
const sourceMeta = isImage
|
|
13925
|
+
? [formatBytes(viewer.size), viewer.mimeType]
|
|
13926
|
+
: sourceAvailable ? [formatBytes(viewer.size), `${lineCount} ${lineCount === 1 ? "line" : "lines"}`] : ["source unavailable"];
|
|
13455
13927
|
elements.fileViewerMeta.textContent = [viewer.path, ...sourceMeta].filter(Boolean).join(" · ");
|
|
13456
13928
|
}
|
|
13457
13929
|
if (elements.fileViewerChangesModeButton) {
|
|
@@ -13467,10 +13939,10 @@ function updateFileViewerUi() {
|
|
|
13467
13939
|
elements.fileViewerSourceModeButton.classList.toggle("active", mode === "source");
|
|
13468
13940
|
}
|
|
13469
13941
|
if (elements.fileViewerPreviewModeButton) {
|
|
13470
|
-
elements.fileViewerPreviewModeButton.hidden = !isMarkdown;
|
|
13471
|
-
elements.fileViewerPreviewModeButton.disabled = !isMarkdown || !sourceAvailable;
|
|
13472
|
-
elements.fileViewerPreviewModeButton.setAttribute("aria-pressed",
|
|
13473
|
-
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));
|
|
13474
13946
|
}
|
|
13475
13947
|
if (elements.fileViewerEditor) {
|
|
13476
13948
|
elements.fileViewerEditor.hidden = mode !== "source";
|
|
@@ -13482,6 +13954,17 @@ function updateFileViewerUi() {
|
|
|
13482
13954
|
if (elements.fileViewerPreview) {
|
|
13483
13955
|
elements.fileViewerPreview.hidden = mode !== "preview";
|
|
13484
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
|
+
}
|
|
13485
13968
|
}
|
|
13486
13969
|
if (elements.fileViewerChanges) {
|
|
13487
13970
|
elements.fileViewerChanges.hidden = mode !== "changes";
|
|
@@ -13494,6 +13977,10 @@ function updateFileViewerUi() {
|
|
|
13494
13977
|
elements.fileViewerOpenDefaultButton.dataset.path = viewerPath;
|
|
13495
13978
|
elements.fileViewerOpenDefaultButton.disabled = viewer.readOnly === true || !viewerPath;
|
|
13496
13979
|
}
|
|
13980
|
+
if (isImage) {
|
|
13981
|
+
clearFileViewerSelection();
|
|
13982
|
+
closeFileViewerSearch({ restoreFocus: false });
|
|
13983
|
+
}
|
|
13497
13984
|
renderFileViewerSelectionBar();
|
|
13498
13985
|
if (elements.fileViewerSearchBar && !elements.fileViewerSearchBar.hidden) {
|
|
13499
13986
|
fileViewerSearchIndex = -1;
|
|
@@ -13509,6 +13996,7 @@ function fileViewerSearchQueryText() {
|
|
|
13509
13996
|
|
|
13510
13997
|
function fileViewerSearchSurface() {
|
|
13511
13998
|
const mode = resolveFileViewerMode(activeFileViewer);
|
|
13999
|
+
if (mode === "image") return null;
|
|
13512
14000
|
if (mode === "preview") return elements.fileViewerPreview;
|
|
13513
14001
|
if (mode === "changes") return elements.fileViewerChanges;
|
|
13514
14002
|
return elements.fileViewerEditor;
|
|
@@ -13672,7 +14160,7 @@ function stepFileViewerSearch(step) {
|
|
|
13672
14160
|
}
|
|
13673
14161
|
|
|
13674
14162
|
function openFileViewerSearch() {
|
|
13675
|
-
if (!activeFileViewer || !elements.fileViewerSearchBar) return;
|
|
14163
|
+
if (!activeFileViewer || activeFileViewer.kind === "image" || !elements.fileViewerSearchBar) return;
|
|
13676
14164
|
closeChatSearch();
|
|
13677
14165
|
const editor = fileViewerSearchSurface() === elements.fileViewerEditor ? elements.fileViewerEditor : null;
|
|
13678
14166
|
const selectedText = editor && editor.selectionEnd > editor.selectionStart
|
|
@@ -13700,7 +14188,8 @@ function closeFileViewerSearch({ restoreFocus = true } = {}) {
|
|
|
13700
14188
|
updateFileViewerSearchCount();
|
|
13701
14189
|
if (!restoreFocus) return;
|
|
13702
14190
|
const mode = resolveFileViewerMode(activeFileViewer);
|
|
13703
|
-
if (mode === "
|
|
14191
|
+
if (mode === "image") elements.fileViewerImage?.focus({ preventScroll: true });
|
|
14192
|
+
else if (mode === "preview") elements.fileViewerPreview?.focus({ preventScroll: true });
|
|
13704
14193
|
else if (mode === "changes") elements.fileViewerChanges?.focus({ preventScroll: true });
|
|
13705
14194
|
else elements.fileViewerEditor?.focus({ preventScroll: true });
|
|
13706
14195
|
}
|
|
@@ -13953,6 +14442,11 @@ function resetFileViewerUi() {
|
|
|
13953
14442
|
elements.fileViewerEditor.readOnly = false;
|
|
13954
14443
|
}
|
|
13955
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
|
+
}
|
|
13956
14450
|
if (elements.fileViewerChanges) {
|
|
13957
14451
|
elements.fileViewerChanges.hidden = true;
|
|
13958
14452
|
elements.fileViewerChanges.replaceChildren();
|
|
@@ -14043,25 +14537,31 @@ async function openFileInViewer(path = "", { gitCategory = "", gitPath = "" } =
|
|
|
14043
14537
|
if (!isCurrentTabContext(tabContext) || openRequestSerial !== fileViewerOpenRequestSerial) return;
|
|
14044
14538
|
const data = response.data || {};
|
|
14045
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");
|
|
14046
14543
|
activeFileViewer = {
|
|
14047
14544
|
path: normalizeFileTreePath(data.path || normalized),
|
|
14048
14545
|
name: data.name || fileDisplayName(normalized),
|
|
14049
|
-
content: String(data.content || ""),
|
|
14546
|
+
content: kind === "text" ? String(data.content || "") : "",
|
|
14050
14547
|
size: Number(data.size) || 0,
|
|
14051
14548
|
mtimeMs: Number(data.mtimeMs) || 0,
|
|
14052
14549
|
extension: data.extension || "",
|
|
14053
|
-
language: data.language || "text",
|
|
14054
|
-
|
|
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",
|
|
14055
14555
|
dirty: false,
|
|
14056
|
-
readOnly:
|
|
14057
|
-
sourceAvailable:
|
|
14556
|
+
readOnly: kind === "image",
|
|
14557
|
+
sourceAvailable: kind === "text",
|
|
14058
14558
|
gitChanges,
|
|
14059
14559
|
};
|
|
14060
14560
|
if (elements.fileViewerEditor) elements.fileViewerEditor.value = activeFileViewer.content;
|
|
14061
14561
|
clearFileViewerSelection();
|
|
14062
14562
|
cacheActiveFileViewerForTab();
|
|
14063
14563
|
updateFileViewerUi();
|
|
14064
|
-
setFileViewerStatus("Opened in WebUI.", "success");
|
|
14564
|
+
setFileViewerStatus(kind === "image" ? "Image opened in WebUI (read-only)." : "Opened in WebUI.", "success");
|
|
14065
14565
|
if (changesRequest) void applyGitFileChangesSnapshot(changesRequest, tabContext, activeFileViewer.path, changesRequestSerial);
|
|
14066
14566
|
} catch (error) {
|
|
14067
14567
|
const message = error.message || String(error);
|
|
@@ -16067,6 +16567,9 @@ async function refreshTabs({ selectStored = false } = {}) {
|
|
|
16067
16567
|
tabs = nextTabs;
|
|
16068
16568
|
syncTabMetadata(tabs);
|
|
16069
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
|
+
}
|
|
16070
16573
|
for (const view of [...subagentTerminalViews.values()]) {
|
|
16071
16574
|
if (!liveParentTabIds.has(view.parentTabId)) removeSubagentTerminalViewsForParent(view.parentTabId);
|
|
16072
16575
|
}
|
|
@@ -23223,6 +23726,64 @@ function subagentAgentStatus(run = {}, agent = null) {
|
|
|
23223
23726
|
return SUBAGENT_LIFECYCLE_STATES.has(status) ? status : status === "pending" ? "queued" : "running";
|
|
23224
23727
|
}
|
|
23225
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
|
+
|
|
23226
23787
|
function subagentCapabilities(run = {}, agent = null) {
|
|
23227
23788
|
const agentCapabilities = agent?.capabilities && typeof agent.capabilities === "object" ? agent.capabilities : null;
|
|
23228
23789
|
const runCapabilities = run?.capabilities && typeof run.capabilities === "object" ? run.capabilities : null;
|
|
@@ -23238,6 +23799,7 @@ function subagentOverviewGroups(data = latestSubagents) {
|
|
|
23238
23799
|
const legacy = legacyTabs.get(group.tabId) || {};
|
|
23239
23800
|
const gates = visibleSubagentGates({ ...legacy, gates: group.gates || legacy.gates || [] }, dismissedSubagentGateKeys, now);
|
|
23240
23801
|
const runs = Array.isArray(group.runs) ? group.runs : [];
|
|
23802
|
+
const agentCounts = subagentRunAgentCounts(runs);
|
|
23241
23803
|
return {
|
|
23242
23804
|
...legacy,
|
|
23243
23805
|
...group,
|
|
@@ -23251,15 +23813,27 @@ function subagentOverviewGroups(data = latestSubagents) {
|
|
|
23251
23813
|
gates,
|
|
23252
23814
|
gateCount: gates.length,
|
|
23253
23815
|
displayRuns: runs,
|
|
23254
|
-
agentCount:
|
|
23255
|
-
runningAgents:
|
|
23256
|
-
staleAgents:
|
|
23816
|
+
agentCount: agentCounts.total,
|
|
23817
|
+
runningAgents: agentCounts.running,
|
|
23818
|
+
staleAgents: agentCounts.stale,
|
|
23257
23819
|
};
|
|
23258
23820
|
});
|
|
23259
23821
|
}
|
|
23260
23822
|
return (Array.isArray(data?.tabs) ? data.tabs : []).map((tab) => {
|
|
23261
23823
|
const gates = visibleSubagentGates(tab, dismissedSubagentGateKeys, now);
|
|
23262
|
-
|
|
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
|
+
};
|
|
23263
23837
|
});
|
|
23264
23838
|
}
|
|
23265
23839
|
|
|
@@ -23384,7 +23958,7 @@ function subagentCancelTargetLabel(selection = subagentCancelSelection) {
|
|
|
23384
23958
|
|
|
23385
23959
|
function openSubagentCancelDialog(tab, run, agent = null) {
|
|
23386
23960
|
if (!tab?.groupId || !run?.id || !subagentRunCanCancel(run, agent) || !elements.subagentCancelDialog) return;
|
|
23387
|
-
const agentCount =
|
|
23961
|
+
const agentCount = subagentRunAgents(run).length;
|
|
23388
23962
|
subagentCancelSelection = {
|
|
23389
23963
|
groupId: tab.groupId,
|
|
23390
23964
|
tabId: tab.tabId,
|
|
@@ -24210,7 +24784,7 @@ function materializeRetainedSubagentTerminalViews() {
|
|
|
24210
24784
|
subagentTerminalRestoredParentTabs.add(restoreKey);
|
|
24211
24785
|
for (const run of tab.displayRuns) {
|
|
24212
24786
|
if (["queued", "running", "stale"].includes(subagentAgentStatus(run)) || run?.source === "workflow") continue;
|
|
24213
|
-
for (const agent of
|
|
24787
|
+
for (const agent of subagentRunAgents(run)) {
|
|
24214
24788
|
const id = subagentTerminalViewId(tab, run, agent);
|
|
24215
24789
|
if (subagentTerminalViews.has(id)) continue;
|
|
24216
24790
|
if (ensureSubagentTerminalView(tab, run, agent)) materialized = true;
|
|
@@ -24351,6 +24925,40 @@ function openSubagentOutput(tab, run, agent) {
|
|
|
24351
24925
|
return subagentOpenMode === "tab" ? openSubagentTerminal(tab, run, agent) : openSubagentOverlay(tab, run, agent);
|
|
24352
24926
|
}
|
|
24353
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
|
+
|
|
24354
24962
|
function renderSubagentAgent(tab, run, agent) {
|
|
24355
24963
|
const status = subagentAgentStatus(run, agent);
|
|
24356
24964
|
const running = ["queued", "running"].includes(status);
|
|
@@ -24385,15 +24993,18 @@ function renderSubagentAgent(tab, run, agent) {
|
|
|
24385
24993
|
return row;
|
|
24386
24994
|
}
|
|
24387
24995
|
|
|
24388
|
-
function renderSubagentRun(tab, run) {
|
|
24996
|
+
function renderSubagentRun(tab, run, workflowAgents = null) {
|
|
24389
24997
|
const running = subagentRunIsRunning(run);
|
|
24390
24998
|
const card = make("section", `subagent-run ${running ? "running" : run?.status || "done"}`);
|
|
24391
|
-
const
|
|
24999
|
+
const controller = subagentWorkflowController(run);
|
|
25000
|
+
const agents = subagentRunAgents(run)
|
|
24392
25001
|
.slice()
|
|
24393
25002
|
.sort((a, b) => Number(a.index || 0) - Number(b.index || 0) || String(a.name || "").localeCompare(String(b.name || "")));
|
|
24394
|
-
|
|
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"}`);
|
|
24395
25005
|
const list = make("div", "subagent-run-agents");
|
|
24396
|
-
|
|
25006
|
+
if (controller) list.append(renderSubagentWorkflow(tab, run, controller, presentedAgents));
|
|
25007
|
+
else for (const agent of agents) list.append(renderSubagentAgent(tab, run, agent));
|
|
24397
25008
|
if (!list.childElementCount) list.append(make("div", "subagents-empty", "No agents were captured."));
|
|
24398
25009
|
card.append(list);
|
|
24399
25010
|
|
|
@@ -24523,11 +25134,12 @@ function renderSubagentTabGroup(tab) {
|
|
|
24523
25134
|
const runs = (Array.isArray(tab.displayRuns) ? tab.displayRuns : ungatedSubagentRuns(tab))
|
|
24524
25135
|
.slice()
|
|
24525
25136
|
.sort((a, b) => Number(a.startedAt || 0) - Number(b.startedAt || 0) || String(a.id || "").localeCompare(String(b.id || "")));
|
|
24526
|
-
const
|
|
24527
|
-
const
|
|
25137
|
+
const agentCounts = subagentRunAgentCounts(runs);
|
|
25138
|
+
const runningAgents = agentCounts.running;
|
|
25139
|
+
const staleAgents = agentCounts.stale;
|
|
24528
25140
|
const retainedRuns = runs.filter((run) => !["queued", "running", "stale"].includes(subagentAgentStatus(run))).length;
|
|
24529
25141
|
const countLabel = [
|
|
24530
|
-
`${
|
|
25142
|
+
`${agentCounts.total} total`,
|
|
24531
25143
|
runningAgents ? `${runningAgents} running` : "",
|
|
24532
25144
|
staleAgents ? `${staleAgents} stale` : "",
|
|
24533
25145
|
retainedRuns ? `${retainedRuns} retained` : "",
|
|
@@ -24538,7 +25150,7 @@ function renderSubagentTabGroup(tab) {
|
|
|
24538
25150
|
group.append(header);
|
|
24539
25151
|
|
|
24540
25152
|
const list = make("div", "subagent-agent-list");
|
|
24541
|
-
for (const
|
|
25153
|
+
for (const presentation of subagentRunPresentations(runs)) list.append(renderSubagentRun(tab, presentation.run, presentation.agents));
|
|
24542
25154
|
for (const gate of (Array.isArray(tab.gates) ? tab.gates : []).slice().sort((a, b) => Number(a.startedAt || 0) - Number(b.startedAt || 0))) {
|
|
24543
25155
|
list.append(renderSubagentGate(tab, gate));
|
|
24544
25156
|
}
|
|
@@ -24559,9 +25171,9 @@ function renderSubagents() {
|
|
|
24559
25171
|
const restoreFocus = () => restoreScopedControlContinuity(box, continuityContextKey, focusSnapshot, (key) => [...box.querySelectorAll("[data-subagent-continuity-key]")].find((node) => subagentPanelControlKey(node) === key));
|
|
24560
25172
|
const activeTabs = subagentTabsWithRunningAgents();
|
|
24561
25173
|
const finishedRuns = finishedSubagentRunSelections();
|
|
24562
|
-
const totalAgents =
|
|
24563
|
-
const runningAgents =
|
|
24564
|
-
const staleAgents =
|
|
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);
|
|
24565
25177
|
const totalRuns = activeTabs.reduce((count, tab) => count + tab.displayRuns.length, 0);
|
|
24566
25178
|
const runningRuns = activeTabs.reduce((count, tab) => count + tab.displayRuns.filter((run) => run?.status === "running").length, 0);
|
|
24567
25179
|
const retainedRuns = Math.max(0, totalRuns - runningRuns);
|
|
@@ -33249,6 +33861,22 @@ function appendMarkdownMermaidBlock(parent, code) {
|
|
|
33249
33861
|
queueMicrotask(() => renderMermaidDiagram(diagram, status, source));
|
|
33250
33862
|
}
|
|
33251
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
|
+
|
|
33252
33880
|
function appendMarkdownCodeBlock(parent, code, language = "", { closed = true } = {}) {
|
|
33253
33881
|
if (closed && isMermaidLanguage(language)) {
|
|
33254
33882
|
appendMarkdownMermaidBlock(parent, code);
|
|
@@ -33258,7 +33886,7 @@ function appendMarkdownCodeBlock(parent, code, language = "", { closed = true }
|
|
|
33258
33886
|
if (language) wrapper.append(make("div", "markdown-code-language", language));
|
|
33259
33887
|
const pre = make("pre", "code-block markdown-code");
|
|
33260
33888
|
const codeNode = make("code", language ? `language-${language.replace(/[^a-z0-9_-]/gi, "")}` : "");
|
|
33261
|
-
codeNode
|
|
33889
|
+
appendMarkdownCodeTokens(codeNode, String(code || "").replace(/\n+$/g, ""), language);
|
|
33262
33890
|
pre.append(codeNode);
|
|
33263
33891
|
wrapper.append(pre);
|
|
33264
33892
|
attachMarkdownCodeCopyButton(wrapper);
|
|
@@ -33883,11 +34511,28 @@ function joinedThinkingFormatParts(parts) {
|
|
|
33883
34511
|
function thinkingFormatOpenMatch(text) {
|
|
33884
34512
|
const value = String(text || "");
|
|
33885
34513
|
const think = THINKING_FORMAT_OPEN_TAG_REGEX.exec(value);
|
|
33886
|
-
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>" };
|
|
33887
34515
|
const channel = CHANNEL_THINKING_FORMAT_OPEN_TAG_REGEX.exec(value);
|
|
33888
34516
|
if (!channel) return null;
|
|
33889
34517
|
const name = channel[1];
|
|
33890
|
-
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;
|
|
33891
34536
|
}
|
|
33892
34537
|
|
|
33893
34538
|
function splitThinkingFormatText(text, { streaming = false } = {}) {
|
|
@@ -33903,7 +34548,7 @@ function splitThinkingFormatText(text, { streaming = false } = {}) {
|
|
|
33903
34548
|
let open = thinkingFormatOpenMatch(rest);
|
|
33904
34549
|
while (open) {
|
|
33905
34550
|
const afterOpen = rest.slice(open.raw.length);
|
|
33906
|
-
const close =
|
|
34551
|
+
const close = thinkingFormatCloseMatch(afterOpen, open);
|
|
33907
34552
|
if (!close) {
|
|
33908
34553
|
thinkingParts.push(streaming ? stripPartialThinkingFormatClose(afterOpen, open.closeTag) : afterOpen);
|
|
33909
34554
|
return { hasThinkingFormat: true, thinkingText: joinedThinkingFormatParts(thinkingParts), finalText: "", complete: false };
|
|
@@ -33945,6 +34590,17 @@ function assistantToolCallName(part) {
|
|
|
33945
34590
|
return String(part?.name || part?.toolName || part?.toolCall?.name || "unknown");
|
|
33946
34591
|
}
|
|
33947
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
|
+
|
|
33948
34604
|
function assistantToolCallArguments(part) {
|
|
33949
34605
|
return part?.arguments || part?.args || part?.input || part?.toolCall?.arguments || {};
|
|
33950
34606
|
}
|
|
@@ -38049,9 +38705,9 @@ function optionalFeatureStatus(featureId) {
|
|
|
38049
38705
|
label: "Disabled",
|
|
38050
38706
|
className: "disabled",
|
|
38051
38707
|
detail: `Tool access is disabled for the active Pi session${versionSuffix}`,
|
|
38052
|
-
hint: "Enable it here for this session
|
|
38708
|
+
hint: "Enable it here for this session.",
|
|
38053
38709
|
};
|
|
38054
|
-
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 || "" };
|
|
38055
38711
|
if (detected && !disabled) return { label: "Enabled", className: "enabled", detail: doneDetail || `Detected and enabled in Web UI${versionSuffix}`, command: installState?.command || "" };
|
|
38056
38712
|
if (detected && disabled) return { label: "Disabled", className: "disabled", detail: `Detected, but disabled in Web UI${versionSuffix}` };
|
|
38057
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}` };
|
|
@@ -38212,6 +38868,7 @@ function optionalFeatureSetupAvailable(feature) {
|
|
|
38212
38868
|
case "git-workflow": return hasAvailableCommand("git-workflow-setup");
|
|
38213
38869
|
case "workflows": return hasLoadedRpcCommand("workflow-setup");
|
|
38214
38870
|
case "safety-guard": return hasAvailableCommand("safety-guard-setup");
|
|
38871
|
+
case "skills": return hasLoadedRpcCommand("skills");
|
|
38215
38872
|
case "tools": return feature.manageWith !== "tools" || isOptionalFeatureDetected(feature.id);
|
|
38216
38873
|
default: return false;
|
|
38217
38874
|
}
|
|
@@ -38222,6 +38879,7 @@ function openOptionalFeatureSetup(feature) {
|
|
|
38222
38879
|
case "git-workflow": return openNativeGitWorkflowSetupDialog();
|
|
38223
38880
|
case "workflows": return openNativeWorkflowSetupDialog();
|
|
38224
38881
|
case "safety-guard": return openNativeSafetyGuardSetupDialog();
|
|
38882
|
+
case "skills": return openNativeSkillsSelector();
|
|
38225
38883
|
case "tools": return openNativeToolsSelector();
|
|
38226
38884
|
default: return undefined;
|
|
38227
38885
|
}
|
|
@@ -38432,6 +39090,8 @@ function renderOptionalFeatureControls() {
|
|
|
38432
39090
|
const hasNativeCommandMenu = isOptionalFeatureEnabled("tuiSkillsCommand") || isOptionalFeatureEnabled("tuiToolsCommand");
|
|
38433
39091
|
elements.nativeSkillsButton.hidden = !isOptionalFeatureEnabled("tuiSkillsCommand");
|
|
38434
39092
|
elements.nativeToolsButton.hidden = !isOptionalFeatureEnabled("tuiToolsCommand");
|
|
39093
|
+
if (elements.optionsSkillsSetupButton) elements.optionsSkillsSetupButton.hidden = !isOptionalFeatureEnabled("tuiSkillsCommand");
|
|
39094
|
+
if (elements.optionsToolsSetupButton) elements.optionsToolsSetupButton.hidden = !isOptionalFeatureEnabled("tuiToolsCommand");
|
|
38435
39095
|
const nativeCommandMenuContainer = elements.nativeCommandMenuButton.parentElement;
|
|
38436
39096
|
if (nativeCommandMenuContainer) nativeCommandMenuContainer.hidden = !hasNativeCommandMenu;
|
|
38437
39097
|
elements.nativeCommandMenuButton.hidden = !hasNativeCommandMenu;
|
|
@@ -39247,6 +39907,7 @@ function renderNativeSelectorItems(items, { emptyText = "No choices.", onSelect,
|
|
|
39247
39907
|
const button = make("button", `native-selector-item${item.id === activeId ? " active" : ""}`);
|
|
39248
39908
|
button.type = "button";
|
|
39249
39909
|
button.disabled = item.disabled === true;
|
|
39910
|
+
if (typeof item.pressed === "boolean") button.setAttribute("aria-pressed", String(item.pressed));
|
|
39250
39911
|
button.addEventListener("click", () => onSelect?.(item));
|
|
39251
39912
|
const title = make("span", "native-selector-title");
|
|
39252
39913
|
if (numbered) title.append(make("span", "native-selector-index", `${index + 1}.`));
|
|
@@ -40965,6 +41626,7 @@ function renderNativeResourceToggles(resources, { savingName, filter = "all", on
|
|
|
40965
41626
|
meta: nativeResourceSourceLabel(resource),
|
|
40966
41627
|
badge: resource.enabled === false ? "disabled" : "enabled",
|
|
40967
41628
|
badgeClass: resource.enabled === false ? "disabled native-selector-badge-disabled" : "enabled native-selector-badge-enabled",
|
|
41629
|
+
pressed: resource.enabled !== false,
|
|
40968
41630
|
tags: resourceTag ? [resourceTag] : [],
|
|
40969
41631
|
disabled: Boolean(savingName),
|
|
40970
41632
|
resource,
|
|
@@ -40978,7 +41640,7 @@ function renderNativeResourceToggles(resources, { savingName, filter = "all", on
|
|
|
40978
41640
|
elements.nativeCommandBody.prepend(make("div", "native-resource-summary muted", `${counts.total} total · ${counts.enabled} enabled · ${counts.disabled} disabled · showing ${filterLabel}`));
|
|
40979
41641
|
}
|
|
40980
41642
|
|
|
40981
|
-
function renderNativeResourceFilterActions(filter, setFilter, render) {
|
|
41643
|
+
function renderNativeResourceFilterActions(filter, setFilter, render, extraActions = []) {
|
|
40982
41644
|
elements.nativeCommandActions.replaceChildren();
|
|
40983
41645
|
for (const option of [
|
|
40984
41646
|
{ value: "all", label: "All" },
|
|
@@ -40990,40 +41652,79 @@ function renderNativeResourceFilterActions(filter, setFilter, render) {
|
|
|
40990
41652
|
render();
|
|
40991
41653
|
}, filter === option.value ? "primary" : undefined);
|
|
40992
41654
|
}
|
|
41655
|
+
for (const action of extraActions) {
|
|
41656
|
+
const button = addNativeCommandAction(action.label, action.handler);
|
|
41657
|
+
button.disabled = !!action.disabled;
|
|
41658
|
+
}
|
|
40993
41659
|
addNativeCommandAction("Cancel", closeNativeCommandDialog);
|
|
40994
41660
|
}
|
|
40995
41661
|
|
|
40996
41662
|
function nativeResourceScopeControl(scope, { configured = false, saving = false, onChange } = {}) {
|
|
40997
|
-
const
|
|
40998
|
-
|
|
40999
|
-
|
|
41663
|
+
const hints = {
|
|
41664
|
+
session: "Applies immediately and persists only on the current session branch.",
|
|
41665
|
+
global: configured
|
|
41000
41666
|
? "Saved as the default for future sessions. Existing session-specific choices are unchanged."
|
|
41001
|
-
: "No global default is saved yet. The current session is shown as the starting point."
|
|
41002
|
-
:
|
|
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
|
+
};
|
|
41003
41677
|
const control = nativeSettingSelect("Apply changes to", scope, [
|
|
41004
41678
|
{ value: "session", label: "Session only" },
|
|
41005
41679
|
{ value: "global", label: "Global default" },
|
|
41006
|
-
|
|
41680
|
+
{ value: "model", label: "Model default" },
|
|
41681
|
+
], hints[scope] || hints.session, badges[scope] || badges.session);
|
|
41007
41682
|
control.field.classList.add("native-resource-scope");
|
|
41008
41683
|
control.select.disabled = !!saving;
|
|
41009
41684
|
control.select.addEventListener("change", () => onChange?.(control.select.value));
|
|
41010
41685
|
return control.field;
|
|
41011
41686
|
}
|
|
41012
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
|
+
|
|
41013
41707
|
async function openNativeToolsSelector() {
|
|
41014
|
-
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…" });
|
|
41015
41709
|
let tools = [];
|
|
41016
41710
|
let savingName = "";
|
|
41017
41711
|
let filter = "all";
|
|
41018
41712
|
let scope = "session";
|
|
41019
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
|
+
: "";
|
|
41020
41720
|
|
|
41021
41721
|
const load = async () => {
|
|
41022
|
-
renderNativeLoading(`Loading ${scope === "global" ? "global tool defaults" : "session tools"}…`);
|
|
41722
|
+
renderNativeLoading(`Loading ${scope === "global" ? "global tool defaults" : scope === "model" ? "model tool defaults" : "session tools"}…`);
|
|
41023
41723
|
try {
|
|
41024
|
-
const response = await nativeCommandApi(`/api/tools?scope=${encodeURIComponent(scope)}`);
|
|
41724
|
+
const response = await nativeCommandApi(`/api/tools?scope=${encodeURIComponent(scope)}${modelQuery()}`);
|
|
41025
41725
|
tools = Array.isArray(response.data?.tools) ? response.data.tools : [];
|
|
41026
41726
|
configured = response.data?.configured === true;
|
|
41727
|
+
if (scope === "model" && Array.isArray(response.data?.models)) models = response.data.models;
|
|
41027
41728
|
render();
|
|
41028
41729
|
} catch (error) {
|
|
41029
41730
|
setNativeCommandError(error.message || String(error));
|
|
@@ -41031,6 +41732,51 @@ async function openNativeToolsSelector() {
|
|
|
41031
41732
|
}
|
|
41032
41733
|
};
|
|
41033
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
|
+
|
|
41034
41780
|
const render = () => {
|
|
41035
41781
|
renderNativeResourceToggles(tools, {
|
|
41036
41782
|
savingName,
|
|
@@ -41045,13 +41791,20 @@ async function openNativeToolsSelector() {
|
|
|
41045
41791
|
setNativeCommandError("");
|
|
41046
41792
|
render();
|
|
41047
41793
|
try {
|
|
41048
|
-
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 });
|
|
41049
41800
|
tools = Array.isArray(response.data?.tools) ? response.data.tools : [];
|
|
41050
41801
|
configured = response.data?.configured === true;
|
|
41051
41802
|
const enabled = enabledTools.has(tool.name);
|
|
41052
|
-
const content = scope === "
|
|
41053
|
-
? `
|
|
41054
|
-
:
|
|
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.`;
|
|
41055
41808
|
addTransientMessage({ role: "native", title: "/tools", content, level: "info" });
|
|
41056
41809
|
} catch (error) {
|
|
41057
41810
|
setNativeCommandError(error.message || String(error));
|
|
@@ -41061,16 +41814,32 @@ async function openNativeToolsSelector() {
|
|
|
41061
41814
|
}
|
|
41062
41815
|
},
|
|
41063
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
|
+
}
|
|
41064
41827
|
elements.nativeCommandBody.prepend(nativeResourceScopeControl(scope, {
|
|
41065
41828
|
configured,
|
|
41066
41829
|
saving: !!savingName,
|
|
41067
41830
|
onChange: async (nextScope) => {
|
|
41068
41831
|
if (nextScope === scope || savingName) return;
|
|
41832
|
+
if (nextScope === "model" && !(await applyModelScope())) {
|
|
41833
|
+
render();
|
|
41834
|
+
return;
|
|
41835
|
+
}
|
|
41069
41836
|
scope = nextScope;
|
|
41070
41837
|
await load();
|
|
41071
41838
|
},
|
|
41072
41839
|
}));
|
|
41073
|
-
renderNativeResourceFilterActions(filter, (value) => { filter = value; }, render
|
|
41840
|
+
renderNativeResourceFilterActions(filter, (value) => { filter = value; }, render, [
|
|
41841
|
+
{ label: "Use inherited defaults", handler: inheritSelection, disabled: !!savingName },
|
|
41842
|
+
]);
|
|
41074
41843
|
};
|
|
41075
41844
|
|
|
41076
41845
|
elements.nativeCommandSearch.oninput = render;
|
|
@@ -41078,19 +41847,26 @@ async function openNativeToolsSelector() {
|
|
|
41078
41847
|
}
|
|
41079
41848
|
|
|
41080
41849
|
async function openNativeSkillsSelector() {
|
|
41081
|
-
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…" });
|
|
41082
41851
|
let skills = [];
|
|
41083
41852
|
let savingName = "";
|
|
41084
41853
|
let filter = "all";
|
|
41085
41854
|
let scope = "session";
|
|
41086
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
|
+
: "";
|
|
41087
41862
|
|
|
41088
41863
|
const load = async () => {
|
|
41089
|
-
renderNativeLoading(`Loading ${scope === "global" ? "global skill defaults" : "session skills"}…`);
|
|
41864
|
+
renderNativeLoading(`Loading ${scope === "global" ? "global skill defaults" : scope === "model" ? "model skill defaults" : "session skills"}…`);
|
|
41090
41865
|
try {
|
|
41091
|
-
const response = await nativeCommandApi(`/api/skills?scope=${encodeURIComponent(scope)}`);
|
|
41866
|
+
const response = await nativeCommandApi(`/api/skills?scope=${encodeURIComponent(scope)}${modelQuery()}`);
|
|
41092
41867
|
skills = Array.isArray(response.data?.skills) ? response.data.skills : [];
|
|
41093
41868
|
configured = response.data?.configured === true;
|
|
41869
|
+
if (scope === "model" && Array.isArray(response.data?.models)) models = response.data.models;
|
|
41094
41870
|
render();
|
|
41095
41871
|
} catch (error) {
|
|
41096
41872
|
setNativeCommandError(error.message || String(error));
|
|
@@ -41098,6 +41874,52 @@ async function openNativeSkillsSelector() {
|
|
|
41098
41874
|
}
|
|
41099
41875
|
};
|
|
41100
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
|
+
|
|
41101
41923
|
const render = () => {
|
|
41102
41924
|
renderNativeResourceToggles(skills, {
|
|
41103
41925
|
savingName,
|
|
@@ -41111,13 +41933,20 @@ async function openNativeSkillsSelector() {
|
|
|
41111
41933
|
setNativeCommandError("");
|
|
41112
41934
|
render();
|
|
41113
41935
|
try {
|
|
41114
|
-
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 });
|
|
41115
41942
|
skills = Array.isArray(response.data?.skills) ? response.data.skills : [];
|
|
41116
41943
|
configured = response.data?.configured === true;
|
|
41117
41944
|
const enabled = enabledSkills.has(skill.name);
|
|
41118
|
-
const content = scope === "
|
|
41119
|
-
? `
|
|
41120
|
-
:
|
|
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.`;
|
|
41121
41950
|
addTransientMessage({ role: "native", title: "/skills", content, level: "info" });
|
|
41122
41951
|
if (scope === "session") refreshCommands(activeTabContext()).catch((error) => addEvent(error.message || String(error), "error"));
|
|
41123
41952
|
} catch (error) {
|
|
@@ -41128,16 +41957,32 @@ async function openNativeSkillsSelector() {
|
|
|
41128
41957
|
}
|
|
41129
41958
|
},
|
|
41130
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
|
+
}
|
|
41131
41970
|
elements.nativeCommandBody.prepend(nativeResourceScopeControl(scope, {
|
|
41132
41971
|
configured,
|
|
41133
41972
|
saving: !!savingName,
|
|
41134
41973
|
onChange: async (nextScope) => {
|
|
41135
41974
|
if (nextScope === scope || savingName) return;
|
|
41975
|
+
if (nextScope === "model" && !(await applyModelScope())) {
|
|
41976
|
+
render();
|
|
41977
|
+
return;
|
|
41978
|
+
}
|
|
41136
41979
|
scope = nextScope;
|
|
41137
41980
|
await load();
|
|
41138
41981
|
},
|
|
41139
41982
|
}));
|
|
41140
|
-
renderNativeResourceFilterActions(filter, (value) => { filter = value; }, render
|
|
41983
|
+
renderNativeResourceFilterActions(filter, (value) => { filter = value; }, render, [
|
|
41984
|
+
{ label: "Use inherited defaults", handler: inheritSelection, disabled: !!savingName },
|
|
41985
|
+
]);
|
|
41141
41986
|
};
|
|
41142
41987
|
|
|
41143
41988
|
elements.nativeCommandSearch.oninput = render;
|
|
@@ -41950,8 +42795,11 @@ function streamingThinkingTextFallback(event) {
|
|
|
41950
42795
|
return assistantThinkingTextFromMessage(assistantStreamingMessage(event), { streaming: true });
|
|
41951
42796
|
}
|
|
41952
42797
|
|
|
41953
|
-
function setStreamThinkingRawText(text) {
|
|
41954
|
-
const
|
|
42798
|
+
function setStreamThinkingRawText(text, { reconcile = false } = {}) {
|
|
42799
|
+
const snapshot = visibleThinkingText(text);
|
|
42800
|
+
const thinking = reconcile
|
|
42801
|
+
? reconcileTranscriptThinkingSnapshot(streamThinkingRawText, snapshot)
|
|
42802
|
+
: snapshot;
|
|
41955
42803
|
if (thinking === streamThinkingRawText) return false;
|
|
41956
42804
|
streamThinkingRawText = thinking;
|
|
41957
42805
|
return true;
|
|
@@ -41976,10 +42824,10 @@ function syncStreamingThinkingFromUpdate(event, update, { placeholder = "" } = {
|
|
|
41976
42824
|
return streamThinkingRawText ? setStreamingThinkingText(streamThinkingRawText || placeholder) : false;
|
|
41977
42825
|
}
|
|
41978
42826
|
if (update.type === "thinking_end") {
|
|
41979
|
-
if (delta) setStreamThinkingRawText(delta);
|
|
42827
|
+
if (delta) setStreamThinkingRawText(delta, { reconcile: true });
|
|
41980
42828
|
else {
|
|
41981
42829
|
const fallback = streamingThinkingTextFallback(event);
|
|
41982
|
-
if (fallback !== null) setStreamThinkingRawText(fallback);
|
|
42830
|
+
if (fallback !== null) setStreamThinkingRawText(fallback, { reconcile: true });
|
|
41983
42831
|
}
|
|
41984
42832
|
return setStreamingThinkingText(streamThinkingRawText || placeholder);
|
|
41985
42833
|
}
|
|
@@ -42310,45 +43158,86 @@ function mergeMessagesDelta(previous, data) {
|
|
|
42310
43158
|
return previous.slice(0, since).concat(data.messages);
|
|
42311
43159
|
}
|
|
42312
43160
|
|
|
42313
|
-
|
|
42314
|
-
|
|
42315
|
-
|
|
42316
|
-
|
|
42317
|
-
|
|
42318
|
-
|
|
42319
|
-
|
|
42320
|
-
|
|
42321
|
-
|
|
42322
|
-
|
|
42323
|
-
|
|
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;
|
|
42324
43174
|
}
|
|
42325
|
-
if (
|
|
42326
|
-
|
|
42327
|
-
|
|
42328
|
-
nextMessages = response.data?.messages || [];
|
|
43175
|
+
if (reveal) {
|
|
43176
|
+
elements.mainOutputLoading.hidden = false;
|
|
43177
|
+
return;
|
|
42329
43178
|
}
|
|
42330
|
-
|
|
42331
|
-
|
|
42332
|
-
|
|
42333
|
-
|
|
42334
|
-
|
|
42335
|
-
|
|
42336
|
-
|
|
42337
|
-
|
|
42338
|
-
|
|
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);
|
|
42339
43240
|
}
|
|
42340
|
-
renderMessages(latestMessages);
|
|
42341
|
-
if (preserveCompactStream) restoreCompactLiveOutputAfterChatRebuild();
|
|
42342
|
-
else if (preserveNormalStream) restoreStreamRenderAfterChatRebuild();
|
|
42343
|
-
restoreChatTextSelection(selectionSnapshot);
|
|
42344
|
-
markTabOutputSeen();
|
|
42345
|
-
// Authoritative content just landed: derive the todo-progress record once
|
|
42346
|
-
// here instead of from raw token cadence, and let the coalesced semantic
|
|
42347
|
-
// reconciler own the footer/widget chrome that message data can change.
|
|
42348
|
-
// syncLiveTodoProgressWidgetFromText owns the frame-coalesced widget render
|
|
42349
|
-
// and only fires when the parsed checklist value actually changed.
|
|
42350
|
-
reconcileTodoProgressFromMessages(latestMessages, tabContext.tabId);
|
|
42351
|
-
scheduleSemanticReconcile({ footer: true }, tabContext);
|
|
42352
43241
|
}
|
|
42353
43242
|
|
|
42354
43243
|
async function refreshModels(tabContext = activeTabContext()) {
|
|
@@ -43354,6 +44243,7 @@ async function refreshAll(tabContext = activeTabContext()) {
|
|
|
43354
44243
|
const results = await Promise.allSettled([
|
|
43355
44244
|
refreshState(tabContext),
|
|
43356
44245
|
refreshMessages(tabContext),
|
|
44246
|
+
refreshIntercomConversationSummaries(tabContext),
|
|
43357
44247
|
...supplementalRefreshRequests(tabContext),
|
|
43358
44248
|
]);
|
|
43359
44249
|
if (!isCurrentTabContext(tabContext)) return;
|
|
@@ -44719,6 +45609,7 @@ function handleEvent(event) {
|
|
|
44719
45609
|
return;
|
|
44720
45610
|
}
|
|
44721
45611
|
const tabContext = activeTabContext(event.tabId || activeTabId);
|
|
45612
|
+
if (["webui_connected", "agent_end", "message_end", "tool_execution_end"].includes(event.type)) scheduleIntercomConversationRefresh(tabContext);
|
|
44722
45613
|
switch (event.type) {
|
|
44723
45614
|
case "webui_connected": {
|
|
44724
45615
|
const connectedTabId = event.tabId || activeTabId;
|
|
@@ -44942,6 +45833,11 @@ function handleEvent(event) {
|
|
|
44942
45833
|
case "tool_execution_start":
|
|
44943
45834
|
streamToolCallSeen = true;
|
|
44944
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
|
+
}
|
|
44945
45841
|
if (compactOutputActive()) {
|
|
44946
45842
|
compactLiveScheduler.flushNow();
|
|
44947
45843
|
renderCompactToolShell(event);
|
|
@@ -44955,6 +45851,12 @@ function handleEvent(event) {
|
|
|
44955
45851
|
break;
|
|
44956
45852
|
case "tool_execution_end": {
|
|
44957
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
|
+
}
|
|
44958
45860
|
const imagePayloadError = toolImagePayloadError(event);
|
|
44959
45861
|
if (imagePayloadError) surfaceRuntimeDiagnostic("Tool image payload error", imagePayloadError);
|
|
44960
45862
|
if (compactOutputActive()) {
|
|
@@ -45093,6 +45995,7 @@ function connectEvents(tabContext = activeTabContext(), { requestedMode = "auto"
|
|
|
45093
45995
|
source.onopen = () => {
|
|
45094
45996
|
if (eventSource !== source || !isCurrentTabContext(tabContext)) return;
|
|
45095
45997
|
if (!eventStreamPausedForBackground) refreshOptionalFeaturePackageStatuses().catch(() => {});
|
|
45998
|
+
scheduleIntercomConversationRefresh(tabContext, 0);
|
|
45096
45999
|
};
|
|
45097
46000
|
source.onmessage = (message) => {
|
|
45098
46001
|
if (eventSource !== source || !isCurrentTabContext(tabContext)) return;
|
|
@@ -45167,6 +46070,11 @@ elements.skillEditorDialog?.addEventListener("keydown", (event) => {
|
|
|
45167
46070
|
if (!elements.skillEditorSaveButton?.disabled) saveSkillEditor();
|
|
45168
46071
|
});
|
|
45169
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
|
+
});
|
|
45170
46078
|
elements.featureCategoryTag?.addEventListener("click", openFeatureDecisionDialog);
|
|
45171
46079
|
elements.featureDecisionDialog?.addEventListener("close", () => {
|
|
45172
46080
|
featureDecisionDialogTabId = null;
|
|
@@ -45461,6 +46369,8 @@ elements.optionsSummarySetupButton?.addEventListener("click", () => runNativeCom
|
|
|
45461
46369
|
elements.optionsWorkflowSetupButton?.addEventListener("click", () => runNativeCommandMenu("/workflow-setup"));
|
|
45462
46370
|
elements.optionsSafetyGuardSetupButton?.addEventListener("click", () => runNativeCommandMenu("/safety-guard-setup"));
|
|
45463
46371
|
elements.optionsGitWorkflowSetupButton?.addEventListener("click", () => runNativeCommandMenu("/git-workflow-setup"));
|
|
46372
|
+
elements.optionsToolsSetupButton?.addEventListener("click", () => runNativeCommandMenu("/tools"));
|
|
46373
|
+
elements.optionsSkillsSetupButton?.addEventListener("click", () => runNativeCommandMenu("/skills"));
|
|
45464
46374
|
elements.optionsExportButton.addEventListener("click", () => runNativeCommandMenu("/export"));
|
|
45465
46375
|
elements.optionsForkButton.addEventListener("click", () => runNativeCommandMenu("/fork"));
|
|
45466
46376
|
elements.optionsTreeButton.addEventListener("click", () => runNativeCommandMenu("/tree"));
|