@firstpick/pi-package-webui 0.7.3 → 0.7.4
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 +33 -20
- package/bin/pi-webui.mjs +203 -39
- package/index.ts +10 -1
- package/lib/git-workflow-preferences.mjs +10 -3
- package/lib/webui-output-mode.mjs +97 -0
- package/package.json +5 -5
- package/public/app.js +688 -24
- package/public/fast-output-live.mjs +179 -0
- package/public/index.html +28 -3
- package/public/service-worker.js +2 -1
- package/public/styles.css +391 -16
- package/tests/fast-mode-client-static.test.mjs +121 -0
- package/tests/fast-mode-output-work.test.mjs +69 -0
- package/tests/fast-mode-sse-harness.test.mjs +204 -0
- package/tests/fast-output-live.test.mjs +106 -0
- package/tests/fixtures/fake-pi.mjs +58 -0
- package/tests/fixtures/fast-mode-output-events.mjs +50 -0
- package/tests/git-workflow-preferences.test.mjs +8 -2
- package/tests/http-endpoints-harness.test.mjs +9 -0
- package/tests/mobile-static.test.mjs +58 -14
- package/tests/remote-auth-settings-harness.test.mjs +1 -1
- package/tests/webui-output-mode.test.mjs +73 -0
package/public/app.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { aurReviewSafePath as parsedAurReviewSafePath, parseAurReviewPayload as parseValidatedAurReviewPayload } from "./aur-review-payload.mjs";
|
|
2
2
|
import { guidedGitReviewAvailableForTabCatalog, resolveCommandForTabCatalog, resolveRpcSlashCommandForTabCatalog } from "./guided-git-command-state.mjs";
|
|
3
3
|
import { guidedGitReviewCanRequestStagedContent, guidedGitReviewHasApprovedBinding, guidedGitReviewProcessNavigationAllowed, guidedGitReviewProcessSelectionPatch, guidedGitReviewTransition, guidedGitReviewWidgetRemovalTransition } from "./guided-git-review-state.mjs";
|
|
4
|
+
import { createFastOutputLiveState, createSustainedFlushScheduler, fastOutputLiveTextAndThinking, reduceFastOutputLiveEvent, seedFastOutputLiveState, shouldConsumeFastOutputLiveEvent } from "./fast-output-live.mjs";
|
|
4
5
|
|
|
5
6
|
const $ = (selector) => document.querySelector(selector);
|
|
6
7
|
|
|
@@ -72,6 +73,7 @@ const elements = {
|
|
|
72
73
|
busyPromptBehaviorTag: $("#busyPromptBehaviorTag"),
|
|
73
74
|
busyPromptBehaviorMenu: $("#busyPromptBehaviorMenu"),
|
|
74
75
|
sessionSkillTags: $("#sessionSkillTags"),
|
|
76
|
+
featureCategoryTag: $("#featureCategoryTag"),
|
|
75
77
|
conversationModeChip: $("#conversationModeChip"),
|
|
76
78
|
workflowModeChip: $("#workflowModeChip"),
|
|
77
79
|
skillEditorDialog: $("#skillEditorDialog"),
|
|
@@ -163,6 +165,9 @@ const elements = {
|
|
|
163
165
|
setThinkingButton: $("#setThinkingButton"),
|
|
164
166
|
thinkingVisibilityToggle: $("#thinkingVisibilityToggle"),
|
|
165
167
|
thinkingVisibilityStatus: $("#thinkingVisibilityStatus"),
|
|
168
|
+
fastOutputModeSelect: $("#fastOutputModeSelect"),
|
|
169
|
+
setFastOutputModeButton: $("#setFastOutputModeButton"),
|
|
170
|
+
fastOutputModeStatus: $("#fastOutputModeStatus"),
|
|
166
171
|
terminalTabsLayoutSelect: $("#terminalTabsLayoutSelect"),
|
|
167
172
|
terminalTabsLayoutStatus: $("#terminalTabsLayoutStatus"),
|
|
168
173
|
themeControlLabel: $("#themeControlLabel"),
|
|
@@ -393,6 +398,17 @@ let streamThinkingBubble = null;
|
|
|
393
398
|
let streamThinking = null;
|
|
394
399
|
let streamMessageActive = false;
|
|
395
400
|
let streamProviderErrorText = "";
|
|
401
|
+
let compactLiveState = createFastOutputLiveState();
|
|
402
|
+
let compactTextBubble = null;
|
|
403
|
+
let compactTextNode = null;
|
|
404
|
+
let compactThinkingBubble = null;
|
|
405
|
+
let compactThinkingNode = null;
|
|
406
|
+
const compactToolShells = new Map();
|
|
407
|
+
let activeOutputMode = "normal";
|
|
408
|
+
let outputModeAcknowledged = false;
|
|
409
|
+
let eventSourceOutputModeRequest = "auto";
|
|
410
|
+
let eventSourceOutputModeFallbackAttempted = false;
|
|
411
|
+
const compactLiveScheduler = createSustainedFlushScheduler({ flush: () => flushCompactLiveOutput() });
|
|
396
412
|
let assistantErrorSurfacedThisRun = false;
|
|
397
413
|
let runIndicatorBubble = null;
|
|
398
414
|
let runIndicatorText = null;
|
|
@@ -723,6 +739,7 @@ const WORKFLOW_INSPECTOR_PAYLOAD_PREFIX = "WORKFLOW_RPC_PAYLOAD ";
|
|
|
723
739
|
const WORKFLOW_INSPECTOR_PAYLOAD_TYPE = "firstpick.pi-extension-workflows.inspector";
|
|
724
740
|
const WORKFLOW_INSPECTOR_PAYLOAD_VERSION = 1;
|
|
725
741
|
const WORKFLOW_MODE_STATUS_KEY = "workflow-mode";
|
|
742
|
+
const FEATURE_CATEGORY_STATUS_KEY = "feature-category";
|
|
726
743
|
const WORKFLOW_MODE_RPC_WIDGET_KEY = "workflow-mode:rpc";
|
|
727
744
|
const WORKFLOW_MODE_RPC_PAYLOAD_PREFIX = "WORKFLOW_MODE_RPC_PAYLOAD ";
|
|
728
745
|
const WORKFLOW_MODE_RPC_PAYLOAD_TYPE = "firstpick.pi-extension-workflows.mode";
|
|
@@ -827,12 +844,15 @@ const initialUrlParams = new URLSearchParams(window.location.search);
|
|
|
827
844
|
const embeddedSplitMode = initialUrlParams.get("embed") === "split";
|
|
828
845
|
document.body.classList.toggle("embedded-split", embeddedSplitMode);
|
|
829
846
|
const statusEntries = new Map();
|
|
847
|
+
const featureCategoryByTab = new Map();
|
|
830
848
|
const widgets = new Map();
|
|
831
849
|
const widgetsByTab = new Map();
|
|
832
850
|
const todoProgressWidgetExpandedByTab = new Map();
|
|
833
851
|
const todoProgressGoalByTab = new Map();
|
|
834
852
|
const todoProgressSignatureByTab = new Map();
|
|
835
853
|
const releaseNpmOutputExpandedByTab = new Map();
|
|
854
|
+
const workflowTerminalScrollByTab = new Map();
|
|
855
|
+
const workflowSubprocessMinimizedByTab = new Set();
|
|
836
856
|
const appRunnerDataByTab = new Map();
|
|
837
857
|
const conversationModeByTab = new Map();
|
|
838
858
|
const workflowModeByTab = new Map();
|
|
@@ -1072,6 +1092,10 @@ const SETTINGS_DOUBLE_ESCAPE_OPTIONS = [
|
|
|
1072
1092
|
{ value: "none", label: "do nothing" },
|
|
1073
1093
|
];
|
|
1074
1094
|
const SETTINGS_TREE_FILTER_OPTIONS = ["default", "no-tools", "user-only", "labeled-only", "all"];
|
|
1095
|
+
const SETTINGS_OUTPUT_MODE_OPTIONS = [
|
|
1096
|
+
{ value: "normal", label: "normal" },
|
|
1097
|
+
{ value: "compact-v1", label: "compact-v1" },
|
|
1098
|
+
];
|
|
1075
1099
|
const SETTINGS_IMAGE_WIDTH_OPTIONS = ["60", "80", "120"];
|
|
1076
1100
|
const SETTINGS_EDITOR_PADDING_OPTIONS = ["0", "1", "2", "3"];
|
|
1077
1101
|
const SETTINGS_AUTOCOMPLETE_OPTIONS = ["3", "5", "7", "10", "15", "20"];
|
|
@@ -2363,6 +2387,28 @@ function renderSessionSkillTags(tabId = activeTabId) {
|
|
|
2363
2387
|
container.hidden = false;
|
|
2364
2388
|
}
|
|
2365
2389
|
|
|
2390
|
+
function normalizeFeatureCategory(value) {
|
|
2391
|
+
return value === "lightweight-feature" || value === "complex-feature" ? value : "";
|
|
2392
|
+
}
|
|
2393
|
+
|
|
2394
|
+
function renderFeatureCategoryTag(tabId = activeTabId) {
|
|
2395
|
+
const tag = elements.featureCategoryTag;
|
|
2396
|
+
if (!tag) return;
|
|
2397
|
+
const category = normalizeFeatureCategory(featureCategoryByTab.get(tabId));
|
|
2398
|
+
tag.hidden = !category;
|
|
2399
|
+
tag.textContent = category;
|
|
2400
|
+
tag.classList.toggle("lightweight-feature", category === "lightweight-feature");
|
|
2401
|
+
tag.classList.toggle("complex-feature", category === "complex-feature");
|
|
2402
|
+
}
|
|
2403
|
+
|
|
2404
|
+
function handleFeatureCategoryStatus(statusText, tabId = activeTabId) {
|
|
2405
|
+
if (!tabId) return;
|
|
2406
|
+
const category = normalizeFeatureCategory(statusText);
|
|
2407
|
+
if (category) featureCategoryByTab.set(tabId, category);
|
|
2408
|
+
else featureCategoryByTab.delete(tabId);
|
|
2409
|
+
if (tabId === activeTabId) renderFeatureCategoryTag(tabId);
|
|
2410
|
+
}
|
|
2411
|
+
|
|
2366
2412
|
function trackSkillUsage(tabId, skillName, kind = "used", source = "", details = {}) {
|
|
2367
2413
|
const name = normalizeSkillName(skillName);
|
|
2368
2414
|
if (!tabId || !name) return;
|
|
@@ -6258,6 +6304,7 @@ function setActiveTabId(tabId, { remember = false } = {}) {
|
|
|
6258
6304
|
if (nextTabId !== activeTabId) activeTabGeneration += 1;
|
|
6259
6305
|
activeTabId = nextTabId;
|
|
6260
6306
|
bindGitWorkflowToActiveTab();
|
|
6307
|
+
renderFeatureCategoryTag(nextTabId);
|
|
6261
6308
|
if (remember) rememberActiveTab();
|
|
6262
6309
|
return activeTabContext(nextTabId);
|
|
6263
6310
|
}
|
|
@@ -7696,6 +7743,7 @@ function syncTabMetadata(nextTabs = []) {
|
|
|
7696
7743
|
suppressPendingAgentDoneNotificationsForTab(tabId, { markSeen: false });
|
|
7697
7744
|
actionFeedbackByTab.delete(tabId);
|
|
7698
7745
|
skillUsageByTab.delete(tabId);
|
|
7746
|
+
featureCategoryByTab.delete(tabId);
|
|
7699
7747
|
tabMessagesCache.delete(tabId);
|
|
7700
7748
|
widgetsByTab.delete(tabId);
|
|
7701
7749
|
appRunnerDataByTab.delete(tabId);
|
|
@@ -7705,6 +7753,7 @@ function syncTabMetadata(nextTabs = []) {
|
|
|
7705
7753
|
workflowInspectorByTab.delete(tabId);
|
|
7706
7754
|
workflowInspectorSelectionByTab.delete(tabId);
|
|
7707
7755
|
workflowInspectorMinimizedByTab.delete(tabId);
|
|
7756
|
+
workflowSubprocessMinimizedByTab.delete(tabId);
|
|
7708
7757
|
remoteMicConsentTabs.delete(tabId);
|
|
7709
7758
|
if (voiceConversationTabId === tabId) stopVoiceConversationLoop();
|
|
7710
7759
|
clearGitWorkflowForTab(tabId);
|
|
@@ -9448,6 +9497,7 @@ async function closeTerminalTabs(tabIds, { label = "selected terminal tabs" } =
|
|
|
9448
9497
|
tabDrafts.delete(id);
|
|
9449
9498
|
clearAttachments(id);
|
|
9450
9499
|
clearGitWorkflowForTab(id);
|
|
9500
|
+
featureCategoryByTab.delete(id);
|
|
9451
9501
|
commandCatalogsByTab.delete(id);
|
|
9452
9502
|
appRunnerDataByTab.delete(id);
|
|
9453
9503
|
tabMessagesCache.delete(id);
|
|
@@ -16588,7 +16638,9 @@ function renderReleaseNpmOutputDetails(key, streamHeader, terminal, controls = n
|
|
|
16588
16638
|
node.open = releaseNpmOutputExpandedByTab.get(stateKey) !== false;
|
|
16589
16639
|
node.addEventListener("toggle", () => {
|
|
16590
16640
|
releaseNpmOutputExpandedByTab.set(stateKey, node.open);
|
|
16591
|
-
if (node.open
|
|
16641
|
+
if (node.open && terminal.dataset.preserveScrollOnToggle !== "true") {
|
|
16642
|
+
requestAnimationFrame(() => { terminal.scrollTop = terminal.scrollHeight; });
|
|
16643
|
+
}
|
|
16592
16644
|
});
|
|
16593
16645
|
|
|
16594
16646
|
const summary = make("summary", "release-npm-output-summary");
|
|
@@ -17076,14 +17128,72 @@ function workflowTaskCountLabel(payload) {
|
|
|
17076
17128
|
return `${done}/${total} done${failed ? ` · ${failed} failed` : ""}${cancelled ? ` · ${cancelled} cancelled` : ""}`;
|
|
17077
17129
|
}
|
|
17078
17130
|
|
|
17131
|
+
function workflowMetaItem(label, value, className = "", description = "") {
|
|
17132
|
+
const item = make("span", `workflow-meta-item ${className}`.trim());
|
|
17133
|
+
item.append(
|
|
17134
|
+
make("span", "workflow-meta-label", label),
|
|
17135
|
+
make("strong", "workflow-meta-value", value),
|
|
17136
|
+
);
|
|
17137
|
+
if (description) item.append(make("span", "workflow-meta-description", description));
|
|
17138
|
+
return item;
|
|
17139
|
+
}
|
|
17140
|
+
|
|
17141
|
+
function bindWorkflowTerminalScroll(terminal, outputDetails, followStatus, { live = false, runId = "unknown" } = {}) {
|
|
17142
|
+
const statePrefix = `${activeTabId || "default"}:workflow:subprocess:`;
|
|
17143
|
+
const stateKey = `${statePrefix}${runId}`;
|
|
17144
|
+
for (const key of workflowTerminalScrollByTab.keys()) {
|
|
17145
|
+
if (key.startsWith(statePrefix) && key !== stateKey) workflowTerminalScrollByTab.delete(key);
|
|
17146
|
+
}
|
|
17147
|
+
const state = workflowTerminalScrollByTab.get(stateKey) || { following: true, scrollTop: 0 };
|
|
17148
|
+
const updateFollowStatus = () => {
|
|
17149
|
+
followStatus.textContent = live
|
|
17150
|
+
? (state.following ? "Following live output · scroll up to pause" : "Auto-follow paused · scroll to the bottom to resume")
|
|
17151
|
+
: "Output complete · scroll position is preserved";
|
|
17152
|
+
followStatus.classList.toggle("paused", live && !state.following);
|
|
17153
|
+
};
|
|
17154
|
+
const restorePosition = () => {
|
|
17155
|
+
if (!outputDetails.open) return;
|
|
17156
|
+
const maxScrollTop = Math.max(0, terminal.scrollHeight - terminal.clientHeight);
|
|
17157
|
+
terminal.scrollTop = state.following ? maxScrollTop : Math.min(state.scrollTop, maxScrollTop);
|
|
17158
|
+
};
|
|
17159
|
+
terminal.addEventListener("scroll", () => {
|
|
17160
|
+
const distanceFromBottom = terminal.scrollHeight - terminal.clientHeight - terminal.scrollTop;
|
|
17161
|
+
state.following = distanceFromBottom <= 24;
|
|
17162
|
+
state.scrollTop = terminal.scrollTop;
|
|
17163
|
+
workflowTerminalScrollByTab.set(stateKey, state);
|
|
17164
|
+
updateFollowStatus();
|
|
17165
|
+
}, { passive: true });
|
|
17166
|
+
outputDetails.addEventListener("toggle", () => {
|
|
17167
|
+
if (outputDetails.open) requestAnimationFrame(restorePosition);
|
|
17168
|
+
});
|
|
17169
|
+
updateFollowStatus();
|
|
17170
|
+
requestAnimationFrame(restorePosition);
|
|
17171
|
+
}
|
|
17172
|
+
|
|
17173
|
+
function workflowSubprocessSetMinimized(minimized) {
|
|
17174
|
+
if (!activeTabId) return;
|
|
17175
|
+
const tabId = activeTabId;
|
|
17176
|
+
if (minimized) workflowSubprocessMinimizedByTab.add(tabId);
|
|
17177
|
+
else workflowSubprocessMinimizedByTab.delete(tabId);
|
|
17178
|
+
renderWidgets();
|
|
17179
|
+
requestAnimationFrame(() => {
|
|
17180
|
+
if (activeTabId !== tabId) return;
|
|
17181
|
+
elements.widgetArea.querySelector(".workflow-subprocess-minimize-button")?.focus({ preventScroll: true });
|
|
17182
|
+
});
|
|
17183
|
+
}
|
|
17184
|
+
|
|
17079
17185
|
function renderWorkflowSubprocessWidget() {
|
|
17080
17186
|
if (!isOptionalFeatureEnabled("workflows")) return null;
|
|
17081
17187
|
const payload = parseWorkflowSubprocessPayload(getWidgetLines("workflow:subprocess"));
|
|
17082
17188
|
if (!payload) return null;
|
|
17083
17189
|
|
|
17084
17190
|
const live = workflowSubprocessIsLive(payload);
|
|
17085
|
-
const
|
|
17191
|
+
const minimized = Boolean(activeTabId && workflowSubprocessMinimizedByTab.has(activeTabId));
|
|
17192
|
+
const node = make("section", `widget release-npm-widget workflow-widget workflow-subprocess-widget ${live ? "workflow-live-widget" : "workflow-log-widget"}${minimized ? " minimized" : ""}`);
|
|
17086
17193
|
node.setAttribute("aria-label", "workflow subprocess output");
|
|
17194
|
+
const body = make("div", "workflow-subprocess-body");
|
|
17195
|
+
body.id = "workflowSubprocessBody";
|
|
17196
|
+
body.hidden = minimized;
|
|
17087
17197
|
|
|
17088
17198
|
const header = make("div", "release-npm-header");
|
|
17089
17199
|
const titleWrap = make("div", "release-npm-title-wrap");
|
|
@@ -17092,29 +17202,56 @@ function renderWorkflowSubprocessWidget() {
|
|
|
17092
17202
|
make("strong", "release-npm-title", payload.workflowName || payload.workflowKey || "workflow"),
|
|
17093
17203
|
);
|
|
17094
17204
|
|
|
17095
|
-
const meta = make("div", "release-npm-meta");
|
|
17096
|
-
meta.
|
|
17097
|
-
|
|
17098
|
-
meta.append(
|
|
17099
|
-
if (payload.
|
|
17205
|
+
const meta = make("div", "release-npm-meta workflow-meta");
|
|
17206
|
+
meta.setAttribute("role", "group");
|
|
17207
|
+
meta.setAttribute("aria-label", "Workflow run summary");
|
|
17208
|
+
meta.append(workflowMetaItem("Run", payload.status || "unknown", `workflow-status ${payload.status || "unknown"}`));
|
|
17209
|
+
if (payload.activePhase) meta.append(workflowMetaItem("Phase", String(payload.activePhase).replace(/^phases?(?::|\s)+/i, "")));
|
|
17210
|
+
meta.append(workflowMetaItem("Tasks", workflowTaskCountLabel(payload), "workflow-tasks"));
|
|
17211
|
+
if (payload.truncated) {
|
|
17212
|
+
meta.append(workflowMetaItem(
|
|
17213
|
+
"Output",
|
|
17214
|
+
"Limited history",
|
|
17215
|
+
"workflow-truncated",
|
|
17216
|
+
"Older output omitted from this view.",
|
|
17217
|
+
));
|
|
17218
|
+
}
|
|
17100
17219
|
|
|
17101
17220
|
const actions = make("div", "release-npm-actions");
|
|
17102
17221
|
actions.append(releaseNpmActionButton("Status", "/workflow status"));
|
|
17103
17222
|
if (live) actions.append(releaseNpmActionButton("Abort", "/workflow abort", "danger"));
|
|
17104
17223
|
actions.append(releaseNpmActionButton("Clear", "/workflow-clear"));
|
|
17224
|
+
const minimizeButton = make("button", "release-npm-action workflow-subprocess-minimize-button", minimized ? "Restore" : "Minimize");
|
|
17225
|
+
minimizeButton.type = "button";
|
|
17226
|
+
minimizeButton.setAttribute("aria-controls", body.id);
|
|
17227
|
+
minimizeButton.setAttribute("aria-expanded", minimized ? "false" : "true");
|
|
17228
|
+
minimizeButton.setAttribute("aria-label", minimized ? "Restore workflow subprocess output" : "Minimize workflow subprocess output");
|
|
17229
|
+
minimizeButton.setAttribute("title", minimized ? "Restore workflow subprocess output" : "Minimize workflow subprocess output");
|
|
17230
|
+
minimizeButton.addEventListener("click", () => workflowSubprocessSetMinimized(!minimized));
|
|
17231
|
+
actions.append(minimizeButton);
|
|
17105
17232
|
header.append(titleWrap, meta, actions);
|
|
17233
|
+
node.append(header, body);
|
|
17234
|
+
if (minimized) return node;
|
|
17106
17235
|
|
|
17107
17236
|
const lines = Array.isArray(payload.lines) && payload.lines.length ? payload.lines : ["Waiting for workflow subprocess output..."];
|
|
17108
17237
|
const streamHeader = releaseNpmStreamHeader(live ? "Live subprocess output" : "Subprocess output", lines.length, { live });
|
|
17109
17238
|
const terminal = make("div", "release-npm-terminal");
|
|
17239
|
+
terminal.dataset.preserveScrollOnToggle = "true";
|
|
17110
17240
|
terminal.setAttribute("role", "log");
|
|
17111
17241
|
terminal.setAttribute("aria-live", live ? "polite" : "off");
|
|
17112
17242
|
for (const line of lines) appendReleaseNpmTerminalLine(terminal, line);
|
|
17113
17243
|
|
|
17114
|
-
const controls = make("div", "release-npm-controls
|
|
17244
|
+
const controls = make("div", "release-npm-controls workflow-output-controls");
|
|
17245
|
+
const followStatus = make("span", "workflow-follow-status");
|
|
17246
|
+
followStatus.setAttribute("role", "status");
|
|
17247
|
+
followStatus.setAttribute("aria-live", "polite");
|
|
17248
|
+
controls.append(
|
|
17249
|
+
followStatus,
|
|
17250
|
+
make("span", "workflow-output-help", live ? "Use /workflow abort to stop the active run." : "The subprocess run has finished."),
|
|
17251
|
+
);
|
|
17115
17252
|
const outputDetails = renderReleaseNpmOutputDetails("workflow:subprocess", streamHeader, terminal, controls);
|
|
17116
|
-
|
|
17117
|
-
|
|
17253
|
+
body.append(outputDetails);
|
|
17254
|
+
bindWorkflowTerminalScroll(terminal, outputDetails, followStatus, { live, runId: payload.runId });
|
|
17118
17255
|
return node;
|
|
17119
17256
|
}
|
|
17120
17257
|
|
|
@@ -25761,6 +25898,93 @@ function httpIdleTimeoutOptions(settings) {
|
|
|
25761
25898
|
return [{ value: current, label }, ...SETTINGS_HTTP_IDLE_TIMEOUT_OPTIONS];
|
|
25762
25899
|
}
|
|
25763
25900
|
|
|
25901
|
+
function normalizeWebuiOutputModeMetadata(metadata = {}) {
|
|
25902
|
+
const modes = new Set(["normal", "compact-v1"]);
|
|
25903
|
+
const sources = new Set(["cli", "env", "persisted", "normal"]);
|
|
25904
|
+
return {
|
|
25905
|
+
persistedDefault: modes.has(metadata.persistedDefault) ? metadata.persistedDefault : "normal",
|
|
25906
|
+
effectiveDefault: modes.has(metadata.effectiveDefault) ? metadata.effectiveDefault : "normal",
|
|
25907
|
+
source: sources.has(metadata.source) ? metadata.source : "normal",
|
|
25908
|
+
overridden: metadata.overridden === true && (metadata.source === "cli" || metadata.source === "env"),
|
|
25909
|
+
};
|
|
25910
|
+
}
|
|
25911
|
+
|
|
25912
|
+
function webuiOutputModeMetadataText(metadata) {
|
|
25913
|
+
const sourceLabel = { cli: "CLI", env: "environment", persisted: "persisted setting", normal: "normal default" }[metadata.source] || "normal default";
|
|
25914
|
+
const overridden = metadata.overridden ? ` ${sourceLabel} overrides the persisted setting.` : "";
|
|
25915
|
+
return `Persisted default: ${metadata.persistedDefault}. Effective mode: ${metadata.effectiveDefault}. Source: ${sourceLabel}.${overridden}`;
|
|
25916
|
+
}
|
|
25917
|
+
|
|
25918
|
+
let sidebarOutputModeMetadata = normalizeWebuiOutputModeMetadata();
|
|
25919
|
+
let sidebarOutputModeDiagnostic = "";
|
|
25920
|
+
let sidebarOutputModeNotice = "";
|
|
25921
|
+
let sidebarOutputModeLoaded = false;
|
|
25922
|
+
let sidebarOutputModeBusy = false;
|
|
25923
|
+
|
|
25924
|
+
function updateSidebarOutputModeApplyState() {
|
|
25925
|
+
if (!elements.fastOutputModeSelect || !elements.setFastOutputModeButton) return;
|
|
25926
|
+
const unavailable = !sidebarOutputModeLoaded || !!sidebarOutputModeDiagnostic;
|
|
25927
|
+
elements.fastOutputModeSelect.disabled = unavailable || sidebarOutputModeBusy;
|
|
25928
|
+
elements.setFastOutputModeButton.disabled = unavailable
|
|
25929
|
+
|| sidebarOutputModeBusy
|
|
25930
|
+
|| elements.fastOutputModeSelect.value === sidebarOutputModeMetadata.persistedDefault;
|
|
25931
|
+
elements.setFastOutputModeButton.textContent = sidebarOutputModeBusy ? "Applying…" : "Apply";
|
|
25932
|
+
}
|
|
25933
|
+
|
|
25934
|
+
function renderSidebarOutputModeControl({ syncSelection = true } = {}) {
|
|
25935
|
+
if (!elements.fastOutputModeSelect || !elements.fastOutputModeStatus) return;
|
|
25936
|
+
if (syncSelection) elements.fastOutputModeSelect.value = sidebarOutputModeMetadata.persistedDefault;
|
|
25937
|
+
elements.fastOutputModeStatus.textContent = sidebarOutputModeDiagnostic
|
|
25938
|
+
|| sidebarOutputModeNotice
|
|
25939
|
+
|| webuiOutputModeMetadataText(sidebarOutputModeMetadata);
|
|
25940
|
+
elements.fastOutputModeStatus.classList.toggle("warning", !!sidebarOutputModeDiagnostic || !!sidebarOutputModeNotice);
|
|
25941
|
+
updateSidebarOutputModeApplyState();
|
|
25942
|
+
}
|
|
25943
|
+
|
|
25944
|
+
async function refreshSidebarOutputMode() {
|
|
25945
|
+
if (!elements.fastOutputModeSelect) return sidebarOutputModeMetadata;
|
|
25946
|
+
sidebarOutputModeLoaded = false;
|
|
25947
|
+
sidebarOutputModeDiagnostic = "";
|
|
25948
|
+
sidebarOutputModeNotice = "";
|
|
25949
|
+
renderSidebarOutputModeControl();
|
|
25950
|
+
try {
|
|
25951
|
+
const response = await api("/api/webui-output-mode", { scoped: false });
|
|
25952
|
+
sidebarOutputModeMetadata = normalizeWebuiOutputModeMetadata(response.data);
|
|
25953
|
+
} catch (error) {
|
|
25954
|
+
sidebarOutputModeMetadata = normalizeWebuiOutputModeMetadata();
|
|
25955
|
+
sidebarOutputModeDiagnostic = `Fast-mode control unavailable: ${error.message || String(error)}. Using the normal default.`;
|
|
25956
|
+
} finally {
|
|
25957
|
+
sidebarOutputModeLoaded = true;
|
|
25958
|
+
renderSidebarOutputModeControl();
|
|
25959
|
+
}
|
|
25960
|
+
return sidebarOutputModeMetadata;
|
|
25961
|
+
}
|
|
25962
|
+
|
|
25963
|
+
async function applySidebarOutputMode() {
|
|
25964
|
+
if (!elements.fastOutputModeSelect || sidebarOutputModeBusy) return;
|
|
25965
|
+
const outputModeDefault = elements.fastOutputModeSelect.value === "compact-v1" ? "compact-v1" : "normal";
|
|
25966
|
+
if (outputModeDefault === sidebarOutputModeMetadata.persistedDefault) return;
|
|
25967
|
+
sidebarOutputModeBusy = true;
|
|
25968
|
+
updateSidebarOutputModeApplyState();
|
|
25969
|
+
try {
|
|
25970
|
+
await api("/api/webui-output-mode", {
|
|
25971
|
+
method: "PUT",
|
|
25972
|
+
body: { outputModeDefault },
|
|
25973
|
+
scoped: false,
|
|
25974
|
+
});
|
|
25975
|
+
await refreshSidebarOutputMode();
|
|
25976
|
+
addEvent(outputModeDefault === "compact-v1" ? "Fast output mode enabled for auto-negotiated Web UI connections." : "Normal output processing restored for auto-negotiated Web UI connections.", "info");
|
|
25977
|
+
} catch (error) {
|
|
25978
|
+
sidebarOutputModeDiagnostic = "";
|
|
25979
|
+
sidebarOutputModeNotice = `Failed to update fast mode: ${error.message || String(error)}. You can retry.`;
|
|
25980
|
+
sidebarOutputModeLoaded = true;
|
|
25981
|
+
addEvent(sidebarOutputModeNotice, "error");
|
|
25982
|
+
} finally {
|
|
25983
|
+
sidebarOutputModeBusy = false;
|
|
25984
|
+
renderSidebarOutputModeControl();
|
|
25985
|
+
}
|
|
25986
|
+
}
|
|
25987
|
+
|
|
25764
25988
|
function collectNativeSettingsPayload(controls) {
|
|
25765
25989
|
return {
|
|
25766
25990
|
transport: controls.transport.select.value,
|
|
@@ -25807,6 +26031,15 @@ async function openNativeSettingsDialog() {
|
|
|
25807
26031
|
return;
|
|
25808
26032
|
}
|
|
25809
26033
|
|
|
26034
|
+
let outputModeMetadata = normalizeWebuiOutputModeMetadata();
|
|
26035
|
+
let outputModeApiDiagnostic = "";
|
|
26036
|
+
try {
|
|
26037
|
+
const response = await api("/api/webui-output-mode", { scoped: false });
|
|
26038
|
+
outputModeMetadata = normalizeWebuiOutputModeMetadata(response.data);
|
|
26039
|
+
} catch (error) {
|
|
26040
|
+
outputModeApiDiagnostic = `Output-mode API unavailable: ${error.message || String(error)}. Showing the normal default; other settings can still be applied.`;
|
|
26041
|
+
}
|
|
26042
|
+
|
|
25810
26043
|
const state = currentState || {};
|
|
25811
26044
|
const settings = settingsData.settings || {};
|
|
25812
26045
|
applyNativeSettingsForBrowser(settings);
|
|
@@ -25837,6 +26070,7 @@ async function openNativeSettingsDialog() {
|
|
|
25837
26070
|
autocompleteMax: nativeSettingSelect("Autocomplete max items", settings.autocompleteMaxVisible ?? autocompleteMaxVisible, SETTINGS_AUTOCOMPLETE_OPTIONS, "Maximum visible slash/path suggestions.", { label: "browser", tone: "browser" }),
|
|
25838
26071
|
doubleEscape: nativeSettingSelect("Double-escape action", settings.doubleEscapeAction || doubleEscapeAction, SETTINGS_DOUBLE_ESCAPE_OPTIONS, "Action when pressing Escape twice with an empty composer.", { label: "browser", tone: "browser" }),
|
|
25839
26072
|
treeFilter: nativeSettingSelect("Tree filter mode", settings.treeFilterMode || treeFilterMode, SETTINGS_TREE_FILTER_OPTIONS, "Default filter when opening /tree.", { label: "browser", tone: "browser" }),
|
|
26073
|
+
outputMode: nativeSettingSelect("Output processing", outputModeMetadata.persistedDefault, SETTINGS_OUTPUT_MODE_OPTIONS, "Server default for new and auto-negotiated Web UI connections. Compact reduces local output-processing and live fidelity, restores rich final output, and does not change model inference or token generation. Changes use server barriers without restarting Pi.", { label: "server", tone: "startup" }),
|
|
25840
26074
|
autoResizeImages: nativeSettingToggle("Auto-resize images", settings.autoResizeImages !== false, "Resize large images to 2000x2000 max for better model compatibility.", { label: "reload", tone: "reload" }),
|
|
25841
26075
|
blockImages: nativeSettingToggle("Block images", settings.blockImages === true, "Prevent images from being sent to LLM providers.", { label: "reload", tone: "reload" }),
|
|
25842
26076
|
showImages: nativeSettingToggle("Show terminal images", settings.showImages !== false, "Native TUI inline image rendering preference.", { label: "TUI", tone: "tui" }),
|
|
@@ -25851,6 +26085,14 @@ async function openNativeSettingsDialog() {
|
|
|
25851
26085
|
clearOnShrink: nativeSettingToggle("Clear on shrink", settings.clearOnShrink === true, "Native TUI row clearing when content shrinks; may flicker.", { label: "TUI", tone: "tui" }),
|
|
25852
26086
|
terminalProgress: nativeSettingToggle("Terminal progress", settings.showTerminalProgress === true, "Native TUI OSC 9;4 terminal progress indicators.", { label: "TUI", tone: "tui" }),
|
|
25853
26087
|
};
|
|
26088
|
+
const outputModeStatus = make("span", "native-settings-hint");
|
|
26089
|
+
controls.outputMode.field.append(outputModeStatus);
|
|
26090
|
+
const renderOutputModeMetadata = () => {
|
|
26091
|
+
controls.outputMode.select.value = outputModeMetadata.persistedDefault;
|
|
26092
|
+
controls.outputMode.select.disabled = !!outputModeApiDiagnostic;
|
|
26093
|
+
outputModeStatus.textContent = outputModeApiDiagnostic || webuiOutputModeMetadataText(outputModeMetadata);
|
|
26094
|
+
};
|
|
26095
|
+
renderOutputModeMetadata();
|
|
25854
26096
|
|
|
25855
26097
|
const remoteAccessSection = make("details", "native-settings-section native-settings-remote-access");
|
|
25856
26098
|
remoteAccessSection.open = false;
|
|
@@ -25892,7 +26134,7 @@ async function openNativeSettingsDialog() {
|
|
|
25892
26134
|
nativeSettingsNote("Scopes", "Each field says whether it affects this tab, this browser, global Pi settings, or the native TUI."),
|
|
25893
26135
|
remoteAccessSection,
|
|
25894
26136
|
nativeSettingsSection("Runtime", "Model behavior and request transport.", [controls.thinking, controls.autoCompact, controls.steering, controls.followUp, controls.transport, controls.httpIdleTimeout], { open: true }),
|
|
25895
|
-
nativeSettingsSection("Browser workflow", "Local Web UI behavior
|
|
26137
|
+
nativeSettingsSection("Browser workflow", "Local Web UI behavior, shared composer defaults, and server output processing.", [controls.busyBehavior, controls.density, controls.thinkingOutput, controls.doneNotifications, controls.autocompleteMax, controls.doubleEscape, controls.treeFilter, controls.outputMode], { open: true }),
|
|
25896
26138
|
nativeSettingsSection("Images", "Provider image policy and native terminal image display.", [controls.autoResizeImages, controls.blockImages, controls.showImages, controls.imageWidth], { open: true }),
|
|
25897
26139
|
nativeSettingsSection("Startup & safety", "Command registration, warnings, update/startup behavior.", [controls.skillCommands, controls.anthropicWarning, controls.collapseChangelog, controls.quietStartup, controls.installTelemetry], { open: false }),
|
|
25898
26140
|
nativeSettingsSection("Native TUI advanced", "Saved for the terminal UI; mostly informational in the browser.", [controls.hardwareCursor, controls.editorPadding, controls.clearOnShrink, controls.terminalProgress], { open: false })
|
|
@@ -25904,6 +26146,7 @@ async function openNativeSettingsDialog() {
|
|
|
25904
26146
|
addNativeCommandAction("Cancel", () => closeNativeCommandDialog());
|
|
25905
26147
|
|
|
25906
26148
|
const initialPayload = collectNativeSettingsPayload(controls);
|
|
26149
|
+
const initialOutputModeDefault = controls.outputMode.select.value;
|
|
25907
26150
|
const initialRuntime = JSON.stringify({
|
|
25908
26151
|
thinking: state.thinkingLevel || "off",
|
|
25909
26152
|
autoCompact: state.autoCompactionEnabled !== false,
|
|
@@ -25929,7 +26172,9 @@ async function openNativeSettingsDialog() {
|
|
|
25929
26172
|
});
|
|
25930
26173
|
let applyButton;
|
|
25931
26174
|
const updateDirtyState = () => {
|
|
25932
|
-
nativeSettingsDirty = currentRuntime() !== initialRuntime
|
|
26175
|
+
nativeSettingsDirty = currentRuntime() !== initialRuntime
|
|
26176
|
+
|| JSON.stringify(collectNativeSettingsPayload(controls)) !== JSON.stringify(initialPayload)
|
|
26177
|
+
|| controls.outputMode.select.value !== initialOutputModeDefault;
|
|
25933
26178
|
if (applyButton) {
|
|
25934
26179
|
applyButton.disabled = !nativeSettingsDirty;
|
|
25935
26180
|
applyButton.textContent = reloadNeeded() ? "Apply and reload" : "Apply";
|
|
@@ -25945,6 +26190,7 @@ async function openNativeSettingsDialog() {
|
|
|
25945
26190
|
try {
|
|
25946
26191
|
const requests = [];
|
|
25947
26192
|
const thinkingLevelChanged = controls.thinking.select.value !== (state.thinkingLevel || "off");
|
|
26193
|
+
const outputModeChanged = controls.outputMode.select.value !== initialOutputModeDefault;
|
|
25948
26194
|
if (thinkingLevelChanged) requests.push(nativeCommandApi("/api/thinking", { method: "POST", body: { level: controls.thinking.select.value } }));
|
|
25949
26195
|
if (controls.steering.select.value !== (state.steeringMode || "one-at-a-time")) requests.push(nativeCommandApi("/api/steering-mode", { method: "POST", body: { mode: controls.steering.select.value } }));
|
|
25950
26196
|
if (controls.followUp.select.value !== (state.followUpMode || "one-at-a-time")) requests.push(nativeCommandApi("/api/follow-up-mode", { method: "POST", body: { mode: controls.followUp.select.value } }));
|
|
@@ -25958,8 +26204,32 @@ async function openNativeSettingsDialog() {
|
|
|
25958
26204
|
const response = await nativeCommandApi("/api/settings", { method: "POST", body: { settings: payload, reload } });
|
|
25959
26205
|
applyResponseTab(response);
|
|
25960
26206
|
applyNativeSettingsForBrowser(response.data?.settings || payload);
|
|
26207
|
+
if (outputModeChanged) {
|
|
26208
|
+
try {
|
|
26209
|
+
await api("/api/webui-output-mode", {
|
|
26210
|
+
method: "PUT",
|
|
26211
|
+
body: { outputModeDefault: controls.outputMode.select.value },
|
|
26212
|
+
scoped: false,
|
|
26213
|
+
});
|
|
26214
|
+
const refreshedOutputMode = await api("/api/webui-output-mode", { scoped: false });
|
|
26215
|
+
outputModeMetadata = normalizeWebuiOutputModeMetadata(refreshedOutputMode.data);
|
|
26216
|
+
outputModeApiDiagnostic = "";
|
|
26217
|
+
sidebarOutputModeMetadata = outputModeMetadata;
|
|
26218
|
+
sidebarOutputModeDiagnostic = "";
|
|
26219
|
+
sidebarOutputModeNotice = "";
|
|
26220
|
+
sidebarOutputModeLoaded = true;
|
|
26221
|
+
renderSidebarOutputModeControl();
|
|
26222
|
+
} catch (error) {
|
|
26223
|
+
outputModeApiDiagnostic = `Output-mode API unavailable after saving: ${error.message || String(error)}. Showing the normal default; other settings can still be applied.`;
|
|
26224
|
+
outputModeMetadata = normalizeWebuiOutputModeMetadata();
|
|
26225
|
+
renderOutputModeMetadata();
|
|
26226
|
+
throw error;
|
|
26227
|
+
}
|
|
26228
|
+
renderOutputModeMetadata();
|
|
26229
|
+
}
|
|
25961
26230
|
if (thinkingLevelChanged) requestGitFooterWebuiPayload(activeTabContext(), { force: true });
|
|
25962
|
-
|
|
26231
|
+
const outputModeMessage = outputModeChanged ? ` ${webuiOutputModeMetadataText(outputModeMetadata)}` : "";
|
|
26232
|
+
addTransientMessage({ role: "native", title: "/settings", content: `${nativeSettingsChangedMessage(response, reload)}${outputModeMessage}`, level: response.data?.reloadRecommended?.length && !response.data?.reloaded ? "warn" : "info" });
|
|
25963
26233
|
nativeSettingsDirty = false;
|
|
25964
26234
|
closeNativeCommandDialog({ force: true });
|
|
25965
26235
|
await refreshAll();
|
|
@@ -26884,6 +27154,173 @@ function cancelStreamBubbleHide() {
|
|
|
26884
27154
|
streamBubbleHideTimer = null;
|
|
26885
27155
|
}
|
|
26886
27156
|
|
|
27157
|
+
function compactOutputActive() {
|
|
27158
|
+
return outputModeAcknowledged && activeOutputMode === "compact-v1";
|
|
27159
|
+
}
|
|
27160
|
+
|
|
27161
|
+
function outputModeAcknowledgement(event) {
|
|
27162
|
+
const outputMode = event?.outputMode;
|
|
27163
|
+
if (outputMode?.protocolVersion !== 1 || !["normal", "compact-v1"].includes(outputMode.activeMode)) return null;
|
|
27164
|
+
return outputMode;
|
|
27165
|
+
}
|
|
27166
|
+
|
|
27167
|
+
function removeCompactLiveBubble(bubble) {
|
|
27168
|
+
bubble?.remove();
|
|
27169
|
+
}
|
|
27170
|
+
|
|
27171
|
+
function resetCompactLiveOutput({ remove = true } = {}) {
|
|
27172
|
+
compactLiveScheduler.cancel();
|
|
27173
|
+
compactLiveState = createFastOutputLiveState();
|
|
27174
|
+
if (remove) {
|
|
27175
|
+
removeCompactLiveBubble(compactTextBubble);
|
|
27176
|
+
removeCompactLiveBubble(compactThinkingBubble);
|
|
27177
|
+
for (const shell of compactToolShells.values()) removeCompactLiveBubble(shell?.bubble);
|
|
27178
|
+
}
|
|
27179
|
+
compactTextBubble = null;
|
|
27180
|
+
compactTextNode = null;
|
|
27181
|
+
compactThinkingBubble = null;
|
|
27182
|
+
compactThinkingNode = null;
|
|
27183
|
+
compactToolShells.clear();
|
|
27184
|
+
}
|
|
27185
|
+
|
|
27186
|
+
function ensureCompactTextBubble() {
|
|
27187
|
+
if (compactTextBubble?.parentElement === elements.chat && compactTextNode) return;
|
|
27188
|
+
const created = appendMessage({ role: "assistant", title: "final output", timestamp: Date.now(), content: "" }, { streaming: true });
|
|
27189
|
+
compactTextBubble = created.bubble;
|
|
27190
|
+
compactTextBubble.classList.add("compact-live-output");
|
|
27191
|
+
compactTextNode = make("div", "compact-live-text");
|
|
27192
|
+
created.body.append(compactTextNode);
|
|
27193
|
+
renderRunIndicator({ scroll: false });
|
|
27194
|
+
}
|
|
27195
|
+
|
|
27196
|
+
function ensureCompactThinkingBubble() {
|
|
27197
|
+
if (!thinkingOutputVisible) return false;
|
|
27198
|
+
if (compactThinkingBubble?.parentElement === elements.chat && compactThinkingNode) return true;
|
|
27199
|
+
const created = appendMessage({ role: "thinking", title: "thinking", timestamp: Date.now(), content: "" }, { streaming: true });
|
|
27200
|
+
compactThinkingBubble = created.bubble;
|
|
27201
|
+
compactThinkingBubble.classList.add("compact-live-output");
|
|
27202
|
+
compactThinkingNode = make("div", "compact-live-thinking");
|
|
27203
|
+
created.body.append(compactThinkingNode);
|
|
27204
|
+
renderRunIndicator({ scroll: false });
|
|
27205
|
+
return true;
|
|
27206
|
+
}
|
|
27207
|
+
|
|
27208
|
+
function compactToolShellId(event) {
|
|
27209
|
+
const direct = String(event?.toolCallId || event?.id || "").trim();
|
|
27210
|
+
return direct || `compact-tool-${compactToolShells.size + 1}`;
|
|
27211
|
+
}
|
|
27212
|
+
|
|
27213
|
+
function renderCompactToolShell(event, { complete = false } = {}) {
|
|
27214
|
+
const id = compactToolShellId(event);
|
|
27215
|
+
let shell = compactToolShells.get(id);
|
|
27216
|
+
if (!shell) {
|
|
27217
|
+
const bubble = make("article", "message toolExecution compact-tool-shell streaming");
|
|
27218
|
+
const header = make("div", "message-header");
|
|
27219
|
+
const role = make("span", "message-role");
|
|
27220
|
+
const timestamp = make("span", "muted", formatDate(Date.now()));
|
|
27221
|
+
const body = make("div", "message-body");
|
|
27222
|
+
const status = make("div", "compact-tool-status");
|
|
27223
|
+
header.append(role, timestamp);
|
|
27224
|
+
body.append(status);
|
|
27225
|
+
bubble.append(header, body);
|
|
27226
|
+
bubble.dataset.toolCallId = id;
|
|
27227
|
+
appendChatMessageBubble(bubble);
|
|
27228
|
+
shell = { bubble, role, status };
|
|
27229
|
+
compactToolShells.set(id, shell);
|
|
27230
|
+
}
|
|
27231
|
+
const name = String(event?.toolName || event?.name || "tool");
|
|
27232
|
+
shell.role.textContent = `tool: ${name}`;
|
|
27233
|
+
shell.status.textContent = complete
|
|
27234
|
+
? `${name} ${event?.isError ? "failed" : "finished"}; restoring final details…`
|
|
27235
|
+
: `${name} running…`;
|
|
27236
|
+
shell.bubble.classList.toggle("tool-error", !!event?.isError);
|
|
27237
|
+
shell.bubble.classList.toggle("tool-running", !complete);
|
|
27238
|
+
shell.bubble.classList.toggle("tool-success", complete && !event?.isError);
|
|
27239
|
+
return shell;
|
|
27240
|
+
}
|
|
27241
|
+
|
|
27242
|
+
function flushCompactLiveOutput() {
|
|
27243
|
+
if (compactLiveState.text) {
|
|
27244
|
+
ensureCompactTextBubble();
|
|
27245
|
+
if (compactTextNode?.textContent !== compactLiveState.text) compactTextNode.textContent = compactLiveState.text;
|
|
27246
|
+
}
|
|
27247
|
+
if (compactLiveState.thinking && ensureCompactThinkingBubble()) {
|
|
27248
|
+
if (compactThinkingNode?.textContent !== compactLiveState.thinking) compactThinkingNode.textContent = compactLiveState.thinking;
|
|
27249
|
+
}
|
|
27250
|
+
scheduleChatFollowScroll();
|
|
27251
|
+
}
|
|
27252
|
+
|
|
27253
|
+
function finishCompactLiveOutput(tabContext = activeTabContext()) {
|
|
27254
|
+
compactLiveScheduler.flushNow();
|
|
27255
|
+
scheduleRefreshMessages(0, tabContext);
|
|
27256
|
+
}
|
|
27257
|
+
|
|
27258
|
+
function handleCompactMessageUpdate(event) {
|
|
27259
|
+
const reduced = reduceFastOutputLiveEvent(compactLiveState, event);
|
|
27260
|
+
if (!shouldConsumeFastOutputLiveEvent(reduced)) return false;
|
|
27261
|
+
if (!reduced.changed) return true;
|
|
27262
|
+
compactLiveState = reduced.state;
|
|
27263
|
+
if (reduced.kind.startsWith("thinking")) setRunIndicatorActivity("Thinking…", { scroll: false });
|
|
27264
|
+
else if (reduced.kind.startsWith("toolcall")) setRunIndicatorActivity("Building tool call…", { scroll: false });
|
|
27265
|
+
else setRunIndicatorActivity("Writing response…", { scroll: false });
|
|
27266
|
+
compactLiveScheduler.request();
|
|
27267
|
+
return true;
|
|
27268
|
+
}
|
|
27269
|
+
|
|
27270
|
+
function acceptOutputModeAcknowledgement(event) {
|
|
27271
|
+
const acknowledgement = outputModeAcknowledgement(event);
|
|
27272
|
+
if (acknowledgement) {
|
|
27273
|
+
activeOutputMode = acknowledgement.activeMode;
|
|
27274
|
+
outputModeAcknowledged = true;
|
|
27275
|
+
return true;
|
|
27276
|
+
}
|
|
27277
|
+
activeOutputMode = "normal";
|
|
27278
|
+
outputModeAcknowledged = false;
|
|
27279
|
+
if (!eventSourceOutputModeFallbackAttempted) {
|
|
27280
|
+
eventSourceOutputModeFallbackAttempted = true;
|
|
27281
|
+
queueMicrotask(() => connectEvents(activeTabContext(), { requestedMode: "normal", fallbackAttempted: true }));
|
|
27282
|
+
}
|
|
27283
|
+
return false;
|
|
27284
|
+
}
|
|
27285
|
+
|
|
27286
|
+
function transitionNormalLiveOutputToCompact() {
|
|
27287
|
+
compactLiveState = seedFastOutputLiveState({ text: streamRawText, thinking: streamThinkingRawText });
|
|
27288
|
+
setStreamRawText("");
|
|
27289
|
+
setStreamThinkingRawText("");
|
|
27290
|
+
removeStreamBubble();
|
|
27291
|
+
removeStreamingThinkingBubble();
|
|
27292
|
+
flushCompactLiveOutput();
|
|
27293
|
+
}
|
|
27294
|
+
|
|
27295
|
+
function transitionCompactLiveOutputToNormal(tabContext = activeTabContext()) {
|
|
27296
|
+
finishCompactLiveOutput(tabContext);
|
|
27297
|
+
const live = fastOutputLiveTextAndThinking(compactLiveState);
|
|
27298
|
+
resetCompactLiveOutput();
|
|
27299
|
+
setStreamRawText(live.text);
|
|
27300
|
+
setStreamThinkingRawText(live.thinking);
|
|
27301
|
+
if (live.thinking) setStreamingThinkingText(live.thinking);
|
|
27302
|
+
if (live.text) renderStreamingAssistantText();
|
|
27303
|
+
}
|
|
27304
|
+
|
|
27305
|
+
function applyOutputModeControl(event, tabContext = activeTabContext()) {
|
|
27306
|
+
if (event?.protocolVersion !== 1 || !["normal", "compact-v1"].includes(event.activeMode)) return false;
|
|
27307
|
+
const previousMode = activeOutputMode;
|
|
27308
|
+
if (previousMode === "normal" && event.activeMode === "compact-v1") {
|
|
27309
|
+
transitionNormalLiveOutputToCompact();
|
|
27310
|
+
} else if (previousMode === "compact-v1" && event.activeMode === "normal") {
|
|
27311
|
+
transitionCompactLiveOutputToNormal(tabContext);
|
|
27312
|
+
} else if (previousMode === "compact-v1") {
|
|
27313
|
+
finishCompactLiveOutput(tabContext);
|
|
27314
|
+
resetCompactLiveOutput();
|
|
27315
|
+
} else if (event.activeMode === "normal") {
|
|
27316
|
+
resetCompactLiveOutput();
|
|
27317
|
+
}
|
|
27318
|
+
activeOutputMode = event.activeMode;
|
|
27319
|
+
outputModeAcknowledged = true;
|
|
27320
|
+
addEvent(`live output mode changed to ${event.activeMode}`, "info");
|
|
27321
|
+
return true;
|
|
27322
|
+
}
|
|
27323
|
+
|
|
26887
27324
|
function cancelStreamingAssistantTextRender() {
|
|
26888
27325
|
clearTimeout(streamTextRenderTimer);
|
|
26889
27326
|
streamTextRenderTimer = null;
|
|
@@ -27079,6 +27516,7 @@ function showStreamingThinking(initialText = "") {
|
|
|
27079
27516
|
}
|
|
27080
27517
|
|
|
27081
27518
|
function resetStreamBubble() {
|
|
27519
|
+
resetCompactLiveOutput();
|
|
27082
27520
|
cancelStreamingAssistantTextRender();
|
|
27083
27521
|
cancelStreamBubbleHide();
|
|
27084
27522
|
streamBubble = null;
|
|
@@ -27282,6 +27720,7 @@ function assistantStreamErrorMessage(event, update = event?.assistantMessageEven
|
|
|
27282
27720
|
}
|
|
27283
27721
|
|
|
27284
27722
|
function handleMessageUpdate(event) {
|
|
27723
|
+
if (compactOutputActive() && handleCompactMessageUpdate(event)) return;
|
|
27285
27724
|
const update = event.assistantMessageEvent || {};
|
|
27286
27725
|
if (update.type === "thinking_start") {
|
|
27287
27726
|
setRunIndicatorActivity("Thinking…", { scroll: false });
|
|
@@ -29152,6 +29591,10 @@ function handleExtensionUiRequest(request) {
|
|
|
29152
29591
|
}
|
|
29153
29592
|
case "setStatus": {
|
|
29154
29593
|
const statusKey = request.statusKey || "extension";
|
|
29594
|
+
if (statusKey === FEATURE_CATEGORY_STATUS_KEY) {
|
|
29595
|
+
handleFeatureCategoryStatus(request.statusText, request.tabId || activeTabId);
|
|
29596
|
+
return;
|
|
29597
|
+
}
|
|
29155
29598
|
if (request.statusText) {
|
|
29156
29599
|
statusEntries.set(statusKey, request.statusText);
|
|
29157
29600
|
if (statusKey === GIT_FOOTER_WEBUI_STATUS_KEY) cacheGitFooterWebuiPayload(request.statusText, request.tabId);
|
|
@@ -29276,6 +29719,180 @@ function addDialogButton(label, handler, className) {
|
|
|
29276
29719
|
return button;
|
|
29277
29720
|
}
|
|
29278
29721
|
|
|
29722
|
+
const WORKFLOW_SCRIPT_TOKEN_PATTERN = /\/\/.*$|\/\*.*?\*\/|`(?:\\.|[^`])*`|"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\b(?:abstract|any|as|asserts|async|await|boolean|break|case|catch|class|const|continue|declare|default|delete|do|else|enum|export|extends|false|finally|for|from|function|get|if|implements|import|in|instanceof|interface|is|keyof|let|namespace|never|new|null|number|of|private|protected|public|readonly|return|satisfies|set|static|string|super|switch|symbol|this|throw|true|try|type|typeof|undefined|unknown|using|var|void|while|yield)\b|\b\d+(?:\.\d+)?\b/g;
|
|
29723
|
+
|
|
29724
|
+
function isWorkflowScriptPreviewRequest(request, prompt) {
|
|
29725
|
+
const title = String(prompt?.title || "");
|
|
29726
|
+
return request?.method === "editor"
|
|
29727
|
+
&& title.startsWith("Raw workflow script")
|
|
29728
|
+
&& /\binspection only;\s*edits are ignored\b/i.test(title);
|
|
29729
|
+
}
|
|
29730
|
+
|
|
29731
|
+
function workflowScriptTokenClass(token) {
|
|
29732
|
+
if (/^\/\//.test(token) || /^\/\*/.test(token)) return "comment";
|
|
29733
|
+
if (/^[`"']/.test(token)) return "string";
|
|
29734
|
+
if (/^\d/.test(token)) return "number";
|
|
29735
|
+
return "keyword";
|
|
29736
|
+
}
|
|
29737
|
+
|
|
29738
|
+
function appendWorkflowScriptTokens(parent, line) {
|
|
29739
|
+
let start = 0;
|
|
29740
|
+
WORKFLOW_SCRIPT_TOKEN_PATTERN.lastIndex = 0;
|
|
29741
|
+
for (let match = WORKFLOW_SCRIPT_TOKEN_PATTERN.exec(line); match; match = WORKFLOW_SCRIPT_TOKEN_PATTERN.exec(line)) {
|
|
29742
|
+
if (match.index > start) parent.append(document.createTextNode(line.slice(start, match.index)));
|
|
29743
|
+
parent.append(make("span", `workflow-script-token workflow-script-token-${workflowScriptTokenClass(match[0])}`, match[0]));
|
|
29744
|
+
start = match.index + match[0].length;
|
|
29745
|
+
}
|
|
29746
|
+
if (start < line.length) parent.append(document.createTextNode(line.slice(start)));
|
|
29747
|
+
}
|
|
29748
|
+
|
|
29749
|
+
function renderWorkflowScriptPreview(request) {
|
|
29750
|
+
const source = request.prefill ?? "";
|
|
29751
|
+
const sourceLines = source.split("\n");
|
|
29752
|
+
const searchableLines = sourceLines.map((line) => line.toLocaleLowerCase());
|
|
29753
|
+
const preview = make("section", "workflow-script-preview");
|
|
29754
|
+
preview.setAttribute("aria-label", "Read-only TypeScript workflow script");
|
|
29755
|
+
|
|
29756
|
+
const metadata = make("div", "workflow-script-meta");
|
|
29757
|
+
metadata.append(
|
|
29758
|
+
make("span", "workflow-script-language", "TypeScript · read-only"),
|
|
29759
|
+
make("span", "workflow-script-source-stats", `${sourceLines.length.toLocaleString()} ${sourceLines.length === 1 ? "line" : "lines"} · ${source.length.toLocaleString()} characters`),
|
|
29760
|
+
);
|
|
29761
|
+
|
|
29762
|
+
const toolbar = make("div", "workflow-script-toolbar");
|
|
29763
|
+
const search = make("input", "workflow-script-search");
|
|
29764
|
+
search.type = "search";
|
|
29765
|
+
search.placeholder = "Search source";
|
|
29766
|
+
search.setAttribute("aria-label", "Search workflow source");
|
|
29767
|
+
|
|
29768
|
+
const previous = make("button", "workflow-script-search-button", "Previous match");
|
|
29769
|
+
previous.type = "button";
|
|
29770
|
+
previous.title = "Previous search match";
|
|
29771
|
+
previous.setAttribute("aria-label", "Previous search match");
|
|
29772
|
+
previous.disabled = true;
|
|
29773
|
+
|
|
29774
|
+
const next = make("button", "workflow-script-search-button", "Next match");
|
|
29775
|
+
next.type = "button";
|
|
29776
|
+
next.title = "Next search match";
|
|
29777
|
+
next.setAttribute("aria-label", "Next search match");
|
|
29778
|
+
next.disabled = true;
|
|
29779
|
+
|
|
29780
|
+
const wrap = make("button", "workflow-script-wrap-button", "Wrap lines");
|
|
29781
|
+
wrap.type = "button";
|
|
29782
|
+
wrap.title = "Wrap long lines";
|
|
29783
|
+
wrap.setAttribute("aria-label", "Wrap long lines");
|
|
29784
|
+
wrap.setAttribute("aria-pressed", "false");
|
|
29785
|
+
|
|
29786
|
+
const copy = make("button", "workflow-script-copy-button", "Copy source");
|
|
29787
|
+
copy.type = "button";
|
|
29788
|
+
copy.title = "Copy workflow source";
|
|
29789
|
+
copy.setAttribute("aria-label", "Copy workflow source");
|
|
29790
|
+
|
|
29791
|
+
const searchStatus = make("span", "workflow-script-search-status", "Search source.");
|
|
29792
|
+
searchStatus.setAttribute("role", "status");
|
|
29793
|
+
searchStatus.setAttribute("aria-live", "polite");
|
|
29794
|
+
const copyStatus = make("span", "workflow-script-copy-status");
|
|
29795
|
+
copyStatus.setAttribute("role", "status");
|
|
29796
|
+
copyStatus.setAttribute("aria-live", "polite");
|
|
29797
|
+
toolbar.append(search, previous, next, wrap, copy, searchStatus, copyStatus);
|
|
29798
|
+
|
|
29799
|
+
const codeViewer = make("div", "workflow-script-code");
|
|
29800
|
+
codeViewer.id = "workflowScriptViewer";
|
|
29801
|
+
codeViewer.tabIndex = 0;
|
|
29802
|
+
codeViewer.setAttribute("role", "region");
|
|
29803
|
+
codeViewer.setAttribute("aria-label", "Read-only workflow source with line numbers");
|
|
29804
|
+
search.setAttribute("aria-controls", codeViewer.id);
|
|
29805
|
+
|
|
29806
|
+
const lineRows = sourceLines.map((line, index) => {
|
|
29807
|
+
const row = make("div", "workflow-script-line");
|
|
29808
|
+
row.dataset.line = String(index + 1);
|
|
29809
|
+
const number = make("span", "workflow-script-line-number", String(index + 1));
|
|
29810
|
+
number.setAttribute("aria-hidden", "true");
|
|
29811
|
+
const text = make("code", "workflow-script-line-text");
|
|
29812
|
+
appendWorkflowScriptTokens(text, line);
|
|
29813
|
+
row.append(number, text);
|
|
29814
|
+
codeViewer.append(row);
|
|
29815
|
+
return row;
|
|
29816
|
+
});
|
|
29817
|
+
|
|
29818
|
+
let matchingLineIndexes = [];
|
|
29819
|
+
let activeMatchIndex = -1;
|
|
29820
|
+
const setActiveMatch = (index, { scroll = true } = {}) => {
|
|
29821
|
+
if (matchingLineIndexes.length === 0) return;
|
|
29822
|
+
activeMatchIndex = (index + matchingLineIndexes.length) % matchingLineIndexes.length;
|
|
29823
|
+
const activeLine = matchingLineIndexes[activeMatchIndex];
|
|
29824
|
+
lineRows.forEach((row, lineIndex) => {
|
|
29825
|
+
const active = lineIndex === activeLine;
|
|
29826
|
+
row.classList.toggle("is-active-match", active);
|
|
29827
|
+
if (active) row.setAttribute("aria-current", "true");
|
|
29828
|
+
else row.removeAttribute("aria-current");
|
|
29829
|
+
});
|
|
29830
|
+
searchStatus.textContent = `${activeMatchIndex + 1} of ${matchingLineIndexes.length} matching ${matchingLineIndexes.length === 1 ? "line" : "lines"}.`;
|
|
29831
|
+
if (scroll) lineRows[activeLine].scrollIntoView({ block: "center" });
|
|
29832
|
+
};
|
|
29833
|
+
const updateMatches = () => {
|
|
29834
|
+
const query = search.value.toLocaleLowerCase();
|
|
29835
|
+
matchingLineIndexes = [];
|
|
29836
|
+
if (query) {
|
|
29837
|
+
searchableLines.forEach((line, index) => {
|
|
29838
|
+
if (line.includes(query)) matchingLineIndexes.push(index);
|
|
29839
|
+
});
|
|
29840
|
+
}
|
|
29841
|
+
const matchingLineSet = new Set(matchingLineIndexes);
|
|
29842
|
+
lineRows.forEach((row, index) => {
|
|
29843
|
+
const matched = matchingLineSet.has(index);
|
|
29844
|
+
row.classList.toggle("is-search-match", matched);
|
|
29845
|
+
row.classList.remove("is-active-match");
|
|
29846
|
+
row.removeAttribute("aria-current");
|
|
29847
|
+
});
|
|
29848
|
+
activeMatchIndex = -1;
|
|
29849
|
+
previous.disabled = matchingLineIndexes.length === 0;
|
|
29850
|
+
next.disabled = matchingLineIndexes.length === 0;
|
|
29851
|
+
if (matchingLineIndexes.length > 0) setActiveMatch(0);
|
|
29852
|
+
else searchStatus.textContent = query ? "No matching lines." : "Search source.";
|
|
29853
|
+
};
|
|
29854
|
+
|
|
29855
|
+
search.addEventListener("input", updateMatches);
|
|
29856
|
+
search.addEventListener("keydown", (event) => {
|
|
29857
|
+
if (event.key !== "Enter") return;
|
|
29858
|
+
event.preventDefault();
|
|
29859
|
+
if (matchingLineIndexes.length === 0) return;
|
|
29860
|
+
setActiveMatch(activeMatchIndex + (event.shiftKey ? -1 : 1));
|
|
29861
|
+
});
|
|
29862
|
+
previous.addEventListener("click", () => setActiveMatch(activeMatchIndex - 1));
|
|
29863
|
+
next.addEventListener("click", () => setActiveMatch(activeMatchIndex + 1));
|
|
29864
|
+
wrap.addEventListener("click", () => {
|
|
29865
|
+
const wrapped = codeViewer.classList.toggle("is-wrapped");
|
|
29866
|
+
wrap.textContent = wrapped ? "Unwrap lines" : "Wrap lines";
|
|
29867
|
+
wrap.title = wrapped ? "Do not wrap long lines" : "Wrap long lines";
|
|
29868
|
+
wrap.setAttribute("aria-label", wrap.title);
|
|
29869
|
+
wrap.setAttribute("aria-pressed", String(wrapped));
|
|
29870
|
+
});
|
|
29871
|
+
copy.addEventListener("click", async () => {
|
|
29872
|
+
copy.disabled = true;
|
|
29873
|
+
try {
|
|
29874
|
+
await copyText(source);
|
|
29875
|
+
copy.textContent = "Copied";
|
|
29876
|
+
copyStatus.textContent = "Workflow source copied.";
|
|
29877
|
+
} catch (error) {
|
|
29878
|
+
copy.textContent = "Copy failed";
|
|
29879
|
+
copyStatus.textContent = "Could not copy workflow source.";
|
|
29880
|
+
} finally {
|
|
29881
|
+
window.setTimeout(() => {
|
|
29882
|
+
if (!copy.isConnected) return;
|
|
29883
|
+
copy.textContent = "Copy source";
|
|
29884
|
+
copy.disabled = false;
|
|
29885
|
+
}, 1600);
|
|
29886
|
+
}
|
|
29887
|
+
});
|
|
29888
|
+
|
|
29889
|
+
preview.append(metadata, toolbar, codeViewer);
|
|
29890
|
+
elements.dialogBody.append(preview);
|
|
29891
|
+
addDialogButton("Cancel workflow", () => sendDialogResponse({ type: "extension_ui_response", id: request.id, cancelled: true, tabId: request.tabId }));
|
|
29892
|
+
addDialogButton("Back to approval", () => sendDialogResponse({ type: "extension_ui_response", id: request.id, value: request.prefill, tabId: request.tabId }), "primary");
|
|
29893
|
+
setTimeout(() => codeViewer.focus(), 0);
|
|
29894
|
+
}
|
|
29895
|
+
|
|
29279
29896
|
function showNextDialog() {
|
|
29280
29897
|
if (activeDialog || dialogQueue.length === 0) return;
|
|
29281
29898
|
activeDialog = dialogQueue.shift();
|
|
@@ -29287,8 +29904,10 @@ function showNextDialog() {
|
|
|
29287
29904
|
const displayPrompt = releasePrompt || prompt;
|
|
29288
29905
|
const isGuardrailDialog = isGuardrailDialogPrompt(displayPrompt);
|
|
29289
29906
|
const isReleaseDialog = !!releasePrompt;
|
|
29907
|
+
const isWorkflowScriptPreview = isWorkflowScriptPreviewRequest(request, prompt);
|
|
29290
29908
|
elements.dialog.classList.toggle("guardrail-dialog", isGuardrailDialog);
|
|
29291
29909
|
elements.dialog.classList.toggle("release-dialog", isReleaseDialog);
|
|
29910
|
+
elements.dialog.classList.toggle("workflow-script-dialog", isWorkflowScriptPreview);
|
|
29292
29911
|
elements.dialogTitle.textContent = displayPrompt.title;
|
|
29293
29912
|
if (isReleaseDialog) renderReleaseDialogMessage(elements.dialogMessage, displayPrompt.message);
|
|
29294
29913
|
else renderAnsiText(elements.dialogMessage, displayPrompt.message);
|
|
@@ -29328,6 +29947,8 @@ function showNextDialog() {
|
|
|
29328
29947
|
addDialogButton("Cancel", cancel);
|
|
29329
29948
|
addDialogButton("Submit", () => sendDialogResponse({ type: "extension_ui_response", id: request.id, value: input.value, tabId: request.tabId }), "primary");
|
|
29330
29949
|
setTimeout(() => input.focus(), 0);
|
|
29950
|
+
} else if (isWorkflowScriptPreview) {
|
|
29951
|
+
renderWorkflowScriptPreview(request);
|
|
29331
29952
|
} else if (request.method === "editor") {
|
|
29332
29953
|
const textarea = make("textarea", "dialog-editor");
|
|
29333
29954
|
textarea.value = request.prefill || "";
|
|
@@ -29378,7 +29999,11 @@ function handleEvent(event) {
|
|
|
29378
29999
|
}
|
|
29379
30000
|
const tabContext = activeTabContext(event.tabId || activeTabId);
|
|
29380
30001
|
switch (event.type) {
|
|
29381
|
-
case "webui_connected":
|
|
30002
|
+
case "webui_connected": {
|
|
30003
|
+
const connectedTabId = event.tabId || activeTabId;
|
|
30004
|
+
featureCategoryByTab.delete(connectedTabId);
|
|
30005
|
+
if (connectedTabId === activeTabId) renderFeatureCategoryTag(connectedTabId);
|
|
30006
|
+
acceptOutputModeAcknowledgement(event);
|
|
29382
30007
|
setWebuiVersion(event.version);
|
|
29383
30008
|
setPiVersion(event.piVersion);
|
|
29384
30009
|
setWebuiDevServer(isWebuiDevMetadata(event));
|
|
@@ -29390,6 +30015,10 @@ function handleEvent(event) {
|
|
|
29390
30015
|
addEvent(`connected to ${event.tabTitle || "terminal"} for ${event.cwd}`);
|
|
29391
30016
|
scheduleForegroundReconcile("event stream reconnect", 0);
|
|
29392
30017
|
break;
|
|
30018
|
+
}
|
|
30019
|
+
case "webui_output_mode":
|
|
30020
|
+
applyOutputModeControl(event, tabContext);
|
|
30021
|
+
break;
|
|
29393
30022
|
case "webui_tab_renamed":
|
|
29394
30023
|
applyTabMetadata(event.tab || { id: event.tabId, title: event.tabTitle, activity: event.tabActivity });
|
|
29395
30024
|
addEvent(`${event.previousTabTitle || "terminal"} renamed to ${event.tabTitle || "terminal"}`);
|
|
@@ -29485,11 +30114,13 @@ function handleEvent(event) {
|
|
|
29485
30114
|
renderNetworkStatus();
|
|
29486
30115
|
break;
|
|
29487
30116
|
case "pi_process_exit":
|
|
30117
|
+
if (compactOutputActive()) compactLiveScheduler.flushNow();
|
|
29488
30118
|
surfaceRuntimeDiagnostic("Pi process exited", `Pi RPC exited (${event.code ?? event.signal ?? "unknown"}).`);
|
|
29489
30119
|
clearRunIndicatorActivity();
|
|
29490
30120
|
refreshTabs().catch((error) => addEvent(error.message, "error"));
|
|
29491
30121
|
break;
|
|
29492
30122
|
case "pi_process_error":
|
|
30123
|
+
if (compactOutputActive()) compactLiveScheduler.flushNow();
|
|
29493
30124
|
surfaceRuntimeDiagnostic("Pi process error", event.error || "Pi RPC process error.");
|
|
29494
30125
|
clearRunIndicatorActivity();
|
|
29495
30126
|
refreshTabs().catch((error) => addEvent(error.message, "error"));
|
|
@@ -29536,6 +30167,7 @@ function handleEvent(event) {
|
|
|
29536
30167
|
renderFeedbackTray();
|
|
29537
30168
|
break;
|
|
29538
30169
|
case "agent_end":
|
|
30170
|
+
if (compactOutputActive()) finishCompactLiveOutput(tabContext);
|
|
29539
30171
|
streamMessageActive = false;
|
|
29540
30172
|
if (!assistantErrorSurfacedThisRun && event.willRetry !== true) {
|
|
29541
30173
|
const message = assistantErrorFromAgentEnd(event);
|
|
@@ -29584,6 +30216,7 @@ function handleEvent(event) {
|
|
|
29584
30216
|
handleMessageUpdate(event);
|
|
29585
30217
|
break;
|
|
29586
30218
|
case "message_end": {
|
|
30219
|
+
if (compactOutputActive()) finishCompactLiveOutput(tabContext);
|
|
29587
30220
|
streamMessageActive = false;
|
|
29588
30221
|
if (event.message?.role === "assistant" && event.message.stopReason === "error") {
|
|
29589
30222
|
const message = String(event.message.errorMessage || streamProviderErrorText || "The assistant request failed without an error message.").trim();
|
|
@@ -29600,26 +30233,36 @@ function handleEvent(event) {
|
|
|
29600
30233
|
case "tool_execution_start":
|
|
29601
30234
|
streamToolCallSeen = true;
|
|
29602
30235
|
if (voiceConversationActiveFor(event.tabId || activeTabId)) voiceConversation.setAssistantActivity({ toolRunning: true });
|
|
29603
|
-
|
|
29604
|
-
|
|
29605
|
-
|
|
30236
|
+
if (compactOutputActive()) {
|
|
30237
|
+
compactLiveScheduler.flushNow();
|
|
30238
|
+
renderCompactToolShell(event);
|
|
30239
|
+
} else {
|
|
30240
|
+
suppressStreamingAssistantTextBeforeToolCall();
|
|
30241
|
+
removeStreamingToolCallCard();
|
|
30242
|
+
handleToolExecutionStart(event);
|
|
30243
|
+
}
|
|
29606
30244
|
setRunIndicatorActivity(`Running tool: ${runIndicatorToolName(event.toolName)}…`);
|
|
29607
30245
|
addEvent(`tool ${event.toolName} started`, "info", { toolCallId: event.toolCallId });
|
|
29608
30246
|
break;
|
|
29609
30247
|
case "tool_execution_update":
|
|
29610
|
-
handleToolExecutionUpdate(event);
|
|
30248
|
+
if (!compactOutputActive()) handleToolExecutionUpdate(event);
|
|
29611
30249
|
setRunIndicatorActivity(`Running tool: ${runIndicatorToolName(event.toolName)}…`, { scroll: false });
|
|
29612
30250
|
break;
|
|
29613
30251
|
case "tool_execution_end": {
|
|
29614
30252
|
if (voiceConversationActiveFor(event.tabId || activeTabId)) voiceConversation.setAssistantActivity({ toolRunning: false });
|
|
29615
30253
|
const imagePayloadError = toolImagePayloadError(event);
|
|
29616
30254
|
if (imagePayloadError) surfaceRuntimeDiagnostic("Tool image payload error", imagePayloadError);
|
|
29617
|
-
|
|
30255
|
+
if (compactOutputActive()) {
|
|
30256
|
+
compactLiveScheduler.flushNow();
|
|
30257
|
+
renderCompactToolShell(event, { complete: true });
|
|
30258
|
+
finishCompactLiveOutput(tabContext);
|
|
30259
|
+
} else {
|
|
30260
|
+
handleToolExecutionEnd(event);
|
|
30261
|
+
}
|
|
29618
30262
|
setRunIndicatorActivity(`Tool ${runIndicatorToolName(event.toolName)} ${event.isError ? "failed" : "finished"}; waiting for the agent's next step…`);
|
|
29619
30263
|
addEvent(`tool ${event.toolName} ${event.isError ? "failed" : "finished"}`, event.isError ? "error" : "info", { toolCallId: event.toolCallId });
|
|
29620
|
-
//
|
|
29621
|
-
//
|
|
29622
|
-
// transcript. This avoids one fetch+render per tool call.
|
|
30264
|
+
// Compact tool shells deliberately defer rich body construction to the
|
|
30265
|
+
// final transcript reconciliation; normal mode retains its live card.
|
|
29623
30266
|
scheduleRefreshFooter();
|
|
29624
30267
|
break;
|
|
29625
30268
|
}
|
|
@@ -29631,6 +30274,7 @@ function handleEvent(event) {
|
|
|
29631
30274
|
renderStatus();
|
|
29632
30275
|
break;
|
|
29633
30276
|
case "compaction_end":
|
|
30277
|
+
if (compactOutputActive()) finishCompactLiveOutput(tabContext);
|
|
29634
30278
|
if (currentState) currentState = { ...currentState, isCompacting: false };
|
|
29635
30279
|
if (event.aborted) clearContextUsageUnknownAfterCompaction(event.tabId || activeTabId);
|
|
29636
30280
|
else markContextUsageUnknownAfterCompaction(event.tabId || activeTabId);
|
|
@@ -29643,6 +30287,9 @@ function handleEvent(event) {
|
|
|
29643
30287
|
scheduleRefreshMessages();
|
|
29644
30288
|
scheduleRefreshFooter();
|
|
29645
30289
|
break;
|
|
30290
|
+
case "agent_settled":
|
|
30291
|
+
if (compactOutputActive()) finishCompactLiveOutput(tabContext);
|
|
30292
|
+
break;
|
|
29646
30293
|
case "auto_retry_start": {
|
|
29647
30294
|
const seconds = Math.max(0, Math.ceil(Number(event.delayMs || 0) / 1000));
|
|
29648
30295
|
const retryText = `Retrying (${event.attempt || "?"}/${event.maxAttempts || "?"}) in ${seconds}s after: ${event.errorMessage || "model/provider error"}`;
|
|
@@ -29699,11 +30346,21 @@ function handleEvent(event) {
|
|
|
29699
30346
|
}
|
|
29700
30347
|
}
|
|
29701
30348
|
|
|
29702
|
-
function connectEvents(tabContext = activeTabContext()) {
|
|
30349
|
+
function connectEvents(tabContext = activeTabContext(), { requestedMode = "auto", fallbackAttempted = false } = {}) {
|
|
29703
30350
|
eventSource?.close();
|
|
29704
30351
|
eventSource = null;
|
|
30352
|
+
resetCompactLiveOutput();
|
|
30353
|
+
activeOutputMode = "normal";
|
|
30354
|
+
outputModeAcknowledged = false;
|
|
30355
|
+
eventSourceOutputModeRequest = requestedMode === "normal" ? "normal" : "auto";
|
|
30356
|
+
eventSourceOutputModeFallbackAttempted = !!fallbackAttempted;
|
|
29705
30357
|
if (!tabContext.tabId || !isCurrentTabContext(tabContext)) return;
|
|
29706
|
-
const
|
|
30358
|
+
const parameters = new URLSearchParams({
|
|
30359
|
+
tab: tabContext.tabId,
|
|
30360
|
+
outputMode: eventSourceOutputModeRequest,
|
|
30361
|
+
outputModeProtocol: "1",
|
|
30362
|
+
});
|
|
30363
|
+
const source = new EventSource(`/api/events?${parameters.toString()}`);
|
|
29707
30364
|
eventSource = source;
|
|
29708
30365
|
source.onmessage = (message) => {
|
|
29709
30366
|
if (eventSource !== source || !isCurrentTabContext(tabContext)) return;
|
|
@@ -29715,6 +30372,7 @@ function connectEvents(tabContext = activeTabContext()) {
|
|
|
29715
30372
|
};
|
|
29716
30373
|
source.onerror = () => {
|
|
29717
30374
|
if (eventSource !== source || !isCurrentTabContext(tabContext)) return;
|
|
30375
|
+
if (compactOutputActive()) compactLiveScheduler.flushNow();
|
|
29718
30376
|
addEvent("event stream disconnected; browser will retry", "warn");
|
|
29719
30377
|
fetch("/api/health", { cache: "no-store" }).catch((error) => setBackendOffline(true, error));
|
|
29720
30378
|
};
|
|
@@ -30534,6 +31192,11 @@ if (elements.thinkingVisibilityToggle) {
|
|
|
30534
31192
|
setThinkingOutputVisible(elements.thinkingVisibilityToggle.checked, { announce: true });
|
|
30535
31193
|
});
|
|
30536
31194
|
}
|
|
31195
|
+
elements.fastOutputModeSelect?.addEventListener("change", () => {
|
|
31196
|
+
sidebarOutputModeNotice = "";
|
|
31197
|
+
renderSidebarOutputModeControl({ syncSelection: false });
|
|
31198
|
+
});
|
|
31199
|
+
elements.setFastOutputModeButton?.addEventListener("click", () => applySidebarOutputMode().catch((error) => addEvent(error.message || String(error), "error")));
|
|
30537
31200
|
if (elements.terminalTabsLayoutSelect) {
|
|
30538
31201
|
elements.terminalTabsLayoutSelect.addEventListener("change", () => {
|
|
30539
31202
|
setTerminalTabsLayout(elements.terminalTabsLayoutSelect.value, { announce: true });
|
|
@@ -31213,4 +31876,5 @@ bindMobileViewChanges();
|
|
|
31213
31876
|
bindSidePanelOverlayViewChanges();
|
|
31214
31877
|
registerPwaServiceWorker();
|
|
31215
31878
|
renderServerOfflinePanel();
|
|
31879
|
+
refreshSidebarOutputMode().catch((error) => addEvent(error.message || String(error), "error"));
|
|
31216
31880
|
initializeTabs().catch((error) => addEvent(error.message, "error"));
|