@firstpick/pi-package-webui 0.9.1 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -9
- package/bin/pi-webui-launcher.mjs +23 -12
- package/bin/pi-webui.mjs +729 -93
- package/index.ts +266 -1
- package/lib/agent-run-adapters.mjs +500 -0
- package/lib/agent-run-protocol.mjs +262 -0
- package/lib/agent-run-registry.mjs +339 -0
- package/lib/git-workflow-preferences.mjs +18 -28
- package/lib/intercom-conversations.mjs +491 -0
- package/lib/intercom-transcript-filter.mjs +99 -0
- package/lib/resource-selection.mjs +140 -0
- package/lib/trust-boundaries.mjs +2 -0
- package/lib/ui-layout-settings.mjs +172 -28
- package/lib/update/package-layout.mjs +50 -0
- package/lib/update/plan.mjs +11 -0
- package/package.json +2 -2
- package/public/app.js +2276 -419
- package/public/index.html +142 -72
- package/public/service-worker.js +2 -1
- package/public/stream-output-controller.mjs +15 -0
- package/public/styles.css +764 -92
- package/public/syntax-highlight.mjs +622 -0
- package/tests/agent-run-adapters.test.mjs +217 -0
- package/tests/agent-run-launcher.test.mjs +41 -0
- package/tests/agent-run-protocol.test.mjs +82 -0
- package/tests/agent-run-registry.test.mjs +102 -0
- package/tests/boot-failure-diagnostics.test.mjs +3 -3
- package/tests/browser/control-deck-side-panels.spec.mjs +354 -0
- package/tests/browser/controls-layout.spec.mjs +122 -0
- package/tests/browser/file-tree-git-ignored.spec.mjs +113 -0
- package/tests/browser/interaction-continuity.spec.mjs +161 -0
- package/tests/browser/intercom-conversation-viewer.spec.mjs +355 -0
- package/tests/browser/mobile-foundation.spec.mjs +26 -0
- package/tests/browser/model-search-focus.spec.mjs +96 -0
- package/tests/browser/optimistic-prompt.spec.mjs +22 -0
- package/tests/browser/persistent-ui-layout.spec.mjs +285 -66
- package/tests/browser/resource-profiles.spec.mjs +200 -0
- package/tests/browser/subagent-observability.spec.mjs +116 -0
- package/tests/codex-fast-mode-static.test.mjs +7 -6
- package/tests/common-options-submenus-interaction-static.test.mjs +2 -0
- package/tests/common-options-submenus-markup-static.test.mjs +1 -0
- package/tests/component-update-api-static.test.mjs +2 -1
- package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
- package/tests/composer-skill-tag-layout.test.mjs +32 -2
- package/tests/control-deck-component-updates-static.test.mjs +6 -0
- package/tests/control-deck-side-panels-static.test.mjs +68 -0
- package/tests/controls-layout-static.test.mjs +22 -0
- package/tests/fast-mode-client-static.test.mjs +2 -2
- package/tests/feature-decision-output-popup-static.test.mjs +2 -2
- package/tests/feature-system-prompt-optional-feature-static.test.mjs +5 -5
- package/tests/file-tree-git-ignored-static.test.mjs +152 -0
- package/tests/file-tree-search-layout-static.test.mjs +2 -1
- package/tests/file-viewer-image-static.test.mjs +69 -0
- package/tests/fixtures/fake-pi.mjs +147 -12
- package/tests/foreground-transcript-catch-up-static.test.mjs +1 -1
- package/tests/git-panel-file-preview-static.test.mjs +5 -5
- package/tests/git-panel-live-updates-static.test.mjs +3 -3
- package/tests/git-workflow-preferences.test.mjs +55 -6
- package/tests/http-endpoints-harness.test.mjs +295 -14
- package/tests/intercom-conversation-viewer-static.test.mjs +105 -0
- package/tests/intercom-conversations-http.test.mjs +252 -0
- package/tests/intercom-conversations.test.mjs +374 -0
- package/tests/intercom-main-transcript-suppression-static.test.mjs +52 -0
- package/tests/intercom-tag-layout-static.test.mjs +46 -0
- package/tests/intercom-transcript-filter.test.mjs +98 -0
- package/tests/main-output-loading-static.test.mjs +59 -0
- package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
- package/tests/mobile-compact-layout.test.mjs +2 -3
- package/tests/mobile-continuity-tablet-static.test.mjs +6 -6
- package/tests/mobile-foundation-static.test.mjs +3 -3
- package/tests/mobile-phone-experience-static.test.mjs +1 -1
- package/tests/mobile-static.test.mjs +76 -42
- package/tests/native-parity.test.mjs +8 -7
- package/tests/open-issue-wizard-static.test.mjs +2 -2
- package/tests/optional-feature-migration-frontend.test.mjs +5 -5
- package/tests/optional-feature-resource-setup-static.test.mjs +29 -0
- package/tests/persistent-ui-layout-static.test.mjs +13 -13
- package/tests/questionnaire-dialog.test.mjs +3 -3
- package/tests/remote-auth-settings-harness.test.mjs +1 -1
- package/tests/resource-defaults-helper.test.mjs +60 -6
- package/tests/resource-selection.test.mjs +114 -0
- package/tests/resource-tui-extension.test.mjs +23 -0
- package/tests/session-sampling-ui-static.test.mjs +3 -3
- package/tests/side-panel-context-menu-static.test.mjs +1 -1
- package/tests/side-panel-resize-static.test.mjs +26 -16
- package/tests/side-panel-section-height-removal-static.test.mjs +4 -4
- package/tests/side-panel-section-reorder-static.test.mjs +16 -70
- package/tests/stream-output-controller.test.mjs +8 -0
- package/tests/stream-output-isolation-static.test.mjs +2 -2
- package/tests/streaming-ui-coupling.test.mjs +5 -0
- package/tests/subagent-gate-visibility.test.mjs +2 -1
- package/tests/subagent-launch-slots.test.mjs +1 -1
- package/tests/subagent-observability-static.test.mjs +32 -0
- package/tests/subagent-reliability-integration.test.mjs +183 -0
- package/tests/subagent-workflow-section-static.test.mjs +67 -0
- package/tests/subagents-helper.test.mjs +548 -5
- package/tests/syntax-highlight.test.mjs +235 -0
- package/tests/syntax-highlighting-static.test.mjs +84 -0
- package/tests/terminal-tabs-resize-static.test.mjs +35 -0
- package/tests/theme-customizer-static.test.mjs +5 -5
- package/tests/thinking-format-parser.test.mjs +64 -0
- package/tests/ui-layout-settings.test.mjs +104 -32
- package/tests/update-api-harness.test.mjs +24 -10
- package/tests/update-package-layout.test.mjs +38 -0
- package/tests/update-plan.test.mjs +11 -1
- package/tests/webui-settings-locking.test.mjs +33 -3
- package/webui-rpc-helper.mjs +700 -89
package/bin/pi-webui.mjs
CHANGED
|
@@ -22,7 +22,11 @@ import {
|
|
|
22
22
|
} from "../public/theme-contract.mjs";
|
|
23
23
|
import { authProvidersPayload, createAuthContext, logoutStoredProvider } from "../lib/auth-actions.mjs";
|
|
24
24
|
import { resolveCodexUsageAuth } from "../lib/codex-usage-auth.mjs";
|
|
25
|
+
import { AgentRunIndex, canonicalAgentRunId, normalizeAgentInstance } from "../lib/agent-run-protocol.mjs";
|
|
26
|
+
import { AgentRunRegistry } from "../lib/agent-run-registry.mjs";
|
|
25
27
|
import { resolveScopedModelsFromPatterns } from "../lib/scoped-models.mjs";
|
|
28
|
+
import { projectIntercomConversations } from "../lib/intercom-conversations.mjs";
|
|
29
|
+
import { filterIntercomTranscriptMessages } from "../lib/intercom-transcript-filter.mjs";
|
|
26
30
|
import {
|
|
27
31
|
readSessionSummaryPreferences,
|
|
28
32
|
supportedSessionSummaryThinkingLevels,
|
|
@@ -56,7 +60,8 @@ import {
|
|
|
56
60
|
} from "../lib/git-command-errors.mjs";
|
|
57
61
|
import { ComponentUpdateState, sanitizeComponentUpdateError, validateComponentUpdateRequest, validateUpdateApplyRequest, validateUpdatePlanRequest } from "../lib/component-update-state.mjs";
|
|
58
62
|
import { resolveCanonicalPiRuntime, resolveWebuiRuntimeIdentity } from "../lib/update/resolver.mjs";
|
|
59
|
-
import {
|
|
63
|
+
import { bundledPackageOwnership, packageOwnerRoot } from "../lib/update/package-layout.mjs";
|
|
64
|
+
import { createUpdatePlan, assertActionableUpdatePlan, assertPlanIdentity, assertUpdatePlanDigest } from "../lib/update/plan.mjs";
|
|
60
65
|
import { executeCommand, executePlanTargets } from "../lib/update/executor.mjs";
|
|
61
66
|
import { verifyTargetResult } from "../lib/update/verify.mjs";
|
|
62
67
|
import { acquireInstallLock, createUpdateJournal, readUpdateJournal, reconcileInterruptedUpdates, releaseInstallLock, transferInstallLock, transitionUpdateJournal } from "../lib/update/journal.mjs";
|
|
@@ -87,6 +92,12 @@ import {
|
|
|
87
92
|
writeGitWorkflowPreferences,
|
|
88
93
|
writeWebuiSettings,
|
|
89
94
|
} from "../lib/git-workflow-preferences.mjs";
|
|
95
|
+
import {
|
|
96
|
+
exactModelProfile,
|
|
97
|
+
preserveUnavailableResourceNames,
|
|
98
|
+
resolveResourceSelection,
|
|
99
|
+
setExactModelProfile,
|
|
100
|
+
} from "../lib/resource-selection.mjs";
|
|
90
101
|
import {
|
|
91
102
|
UI_LAYOUT_REQUEST_MAX_BYTES,
|
|
92
103
|
mergeUiLayout,
|
|
@@ -185,6 +196,10 @@ const WEBUI_HELPER_RESPONSE_PREFIX = "__PI_WEBUI_HELPER_RESPONSE__:";
|
|
|
185
196
|
const SAMPLING_PARAMS_HTTP_MAX_BYTES = 20 * 1024;
|
|
186
197
|
const WEBUI_SUBAGENTS_STATUS_KEY = "webui-subagents";
|
|
187
198
|
const WEBUI_SUBAGENTS_PAYLOAD_PREFIX = "PI_WEBUI_SUBAGENTS_V1 ";
|
|
199
|
+
const WEBUI_SUBAGENTS_V2_STATUS_KEY = "webui-subagents-v2";
|
|
200
|
+
const WEBUI_SUBAGENTS_V2_PAYLOAD_PREFIX = "PI_WEBUI_SUBAGENTS_V2 ";
|
|
201
|
+
const WEBUI_AGENT_RUN_LIMIT = 512;
|
|
202
|
+
const WEBUI_AGENT_RUN_DIAGNOSTIC_LIMIT = 128;
|
|
188
203
|
const WEBUI_SUBAGENT_RUN_LIMIT = 128;
|
|
189
204
|
const WEBUI_SUBAGENT_AGENT_LIMIT = 256;
|
|
190
205
|
const WEBUI_SUBAGENT_GATE_LIMIT = 32;
|
|
@@ -234,6 +249,14 @@ const RECOVERY_TITLE = "Anthropic compatibility recovery";
|
|
|
234
249
|
const SKILL_FILE_BODY_LIMIT_BYTES = 2 * 1024 * 1024;
|
|
235
250
|
const FILE_VIEWER_MAX_BYTES = 2 * 1024 * 1024;
|
|
236
251
|
const FILE_VIEWER_BODY_LIMIT_BYTES = FILE_VIEWER_MAX_BYTES + 64 * 1024;
|
|
252
|
+
const FILE_VIEWER_IMAGE_MIME_TYPES_BY_EXTENSION = Object.freeze({
|
|
253
|
+
".png": "image/png",
|
|
254
|
+
".jpg": "image/jpeg",
|
|
255
|
+
".jpeg": "image/jpeg",
|
|
256
|
+
".gif": "image/gif",
|
|
257
|
+
".webp": "image/webp",
|
|
258
|
+
".avif": "image/avif",
|
|
259
|
+
});
|
|
237
260
|
const FILE_TREE_MAX_ENTRIES = 1200;
|
|
238
261
|
const FILE_TREE_ENTRY_STAT_CONCURRENCY = 32;
|
|
239
262
|
const FILE_SEARCH_MAX_RESULTS = 200;
|
|
@@ -1842,16 +1865,17 @@ function latestEvents(limit = 40) {
|
|
|
1842
1865
|
return eventHistory.slice(-Math.max(0, Math.min(EVENT_HISTORY_LIMIT, limit)));
|
|
1843
1866
|
}
|
|
1844
1867
|
|
|
1845
|
-
function runCommand(command, args, { cwd, timeoutMs = 2000, maxOutputLength = 20000, env = {} } = {}) {
|
|
1868
|
+
function runCommand(command, args, { cwd, timeoutMs = 2000, maxOutputLength = 20000, env = {}, input, utf8Output = false } = {}) {
|
|
1846
1869
|
return new Promise((resolve) => {
|
|
1847
1870
|
const child = spawn(command, args, {
|
|
1848
1871
|
cwd,
|
|
1849
1872
|
// LC_ALL=C keeps tool output in English so error classification works
|
|
1850
1873
|
// regardless of locale.
|
|
1851
1874
|
env: { ...process.env, ...env, LC_ALL: "C" },
|
|
1852
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
1875
|
+
stdio: [input === undefined ? "ignore" : "pipe", "pipe", "pipe"],
|
|
1853
1876
|
windowsHide: true,
|
|
1854
1877
|
});
|
|
1878
|
+
if (utf8Output) child.stdout.setEncoding("utf8");
|
|
1855
1879
|
let stdout = "";
|
|
1856
1880
|
let stderr = "";
|
|
1857
1881
|
let stdoutTruncated = false;
|
|
@@ -1877,6 +1901,10 @@ function runCommand(command, args, { cwd, timeoutMs = 2000, maxOutputLength = 20
|
|
|
1877
1901
|
stderr += String(chunk);
|
|
1878
1902
|
if (stderr.length > maxOutputLength) stderr = stderr.slice(-maxOutputLength);
|
|
1879
1903
|
});
|
|
1904
|
+
if (child.stdin) {
|
|
1905
|
+
child.stdin.on("error", () => {});
|
|
1906
|
+
child.stdin.end(input);
|
|
1907
|
+
}
|
|
1880
1908
|
child.on("error", (error) => {
|
|
1881
1909
|
const message = formatCommandSpawnError(command, error);
|
|
1882
1910
|
finish({ exitCode: undefined, stdout, stderr: message, error: message, errorCode: error?.code });
|
|
@@ -1889,13 +1917,7 @@ function runCommand(command, args, { cwd, timeoutMs = 2000, maxOutputLength = 20
|
|
|
1889
1917
|
}
|
|
1890
1918
|
|
|
1891
1919
|
function nodeModulesParentForPackageRoot(root = packageRoot) {
|
|
1892
|
-
|
|
1893
|
-
const nodeModulesIndex = parts.lastIndexOf("node_modules");
|
|
1894
|
-
if (nodeModulesIndex >= 0) {
|
|
1895
|
-
const parent = parts.slice(0, nodeModulesIndex).join(path.sep);
|
|
1896
|
-
return parent || path.parse(root).root;
|
|
1897
|
-
}
|
|
1898
|
-
return root;
|
|
1920
|
+
return packageOwnerRoot(root);
|
|
1899
1921
|
}
|
|
1900
1922
|
|
|
1901
1923
|
function packageNodeModulesPath(nodeModulesRoot, packageName) {
|
|
@@ -6073,6 +6095,46 @@ function withFileTreeGitStatus(entries = [], workspaceRoot, gitStatus) {
|
|
|
6073
6095
|
});
|
|
6074
6096
|
}
|
|
6075
6097
|
|
|
6098
|
+
async function readWorkspaceGitIgnoredPaths(workspaceRoot, entries = [], gitRoot = "") {
|
|
6099
|
+
try {
|
|
6100
|
+
const root = path.resolve(gitRoot || await getGitRoot(workspaceRoot));
|
|
6101
|
+
const candidates = new Set();
|
|
6102
|
+
for (const entry of entries) {
|
|
6103
|
+
if (!entry?.path) continue;
|
|
6104
|
+
const absolute = path.resolve(workspaceRoot, entry.path);
|
|
6105
|
+
if (absolute !== root && !pathInside(root, absolute)) continue;
|
|
6106
|
+
const relative = path.relative(root, absolute);
|
|
6107
|
+
if (!relative || path.isAbsolute(relative) || relative.startsWith(`..${path.sep}`)) continue;
|
|
6108
|
+
candidates.add(relative.split(path.sep).join("/"));
|
|
6109
|
+
}
|
|
6110
|
+
if (!candidates.size) return null;
|
|
6111
|
+
const input = `${[...candidates].join("\0")}\0`;
|
|
6112
|
+
const result = await runCommand("git", ["check-ignore", "-z", "--stdin"], {
|
|
6113
|
+
cwd: root,
|
|
6114
|
+
timeoutMs: GIT_CHANGES_COMMAND_TIMEOUT_MS,
|
|
6115
|
+
maxOutputLength: Math.max(20_000, input.length + 1),
|
|
6116
|
+
env: { GIT_OPTIONAL_LOCKS: "0" },
|
|
6117
|
+
input,
|
|
6118
|
+
utf8Output: true,
|
|
6119
|
+
});
|
|
6120
|
+
if (![0, 1].includes(result.exitCode) || result.timedOut || result.error || result.stdoutTruncated) return null;
|
|
6121
|
+
return { root, paths: new Set(result.stdout.split("\0").filter(Boolean)) };
|
|
6122
|
+
} catch {
|
|
6123
|
+
return null;
|
|
6124
|
+
}
|
|
6125
|
+
}
|
|
6126
|
+
|
|
6127
|
+
function withFileTreeGitIgnored(entries = [], workspaceRoot, gitIgnored) {
|
|
6128
|
+
if (!gitIgnored?.root || !gitIgnored.paths?.size) return entries;
|
|
6129
|
+
return entries.map((entry) => {
|
|
6130
|
+
if (!entry?.path) return entry;
|
|
6131
|
+
const absolute = path.resolve(workspaceRoot, entry.path);
|
|
6132
|
+
if (absolute !== gitIgnored.root && !pathInside(gitIgnored.root, absolute)) return entry;
|
|
6133
|
+
const relative = path.relative(gitIgnored.root, absolute).split(path.sep).join("/");
|
|
6134
|
+
return gitIgnored.paths.has(relative) ? { ...entry, gitIgnored: true } : entry;
|
|
6135
|
+
});
|
|
6136
|
+
}
|
|
6137
|
+
|
|
6076
6138
|
function fileTreeGitStatusPayload(workspaceRoot, gitStatus) {
|
|
6077
6139
|
if (!gitStatus?.root || !gitStatus.entries?.size) return null;
|
|
6078
6140
|
const root = path.resolve(workspaceRoot);
|
|
@@ -9126,6 +9188,51 @@ try {
|
|
|
9126
9188
|
|
|
9127
9189
|
process.env.PI_WEBUI_HOST = options.host;
|
|
9128
9190
|
process.env.PI_WEBUI_PORT = String(options.port);
|
|
9191
|
+
const agentRunRegistry = new AgentRunRegistry({ agentDir, port: options.port });
|
|
9192
|
+
const AGENT_RUN_PRUNE_INTERVAL_MS = 5 * 60_000;
|
|
9193
|
+
const AGENT_RUN_PROJECTION_DISMISSAL_RETENTION_MS = 24 * 60 * 60_000;
|
|
9194
|
+
const AGENT_RUN_PROJECTION_DISMISSAL_LIMIT = 2_048;
|
|
9195
|
+
const AGENT_RUN_TERMINAL_STATUSES = new Set(["done", "failed", "cancelled"]);
|
|
9196
|
+
const dismissedAgentRunProjectionKeys = new Map();
|
|
9197
|
+
let lastAgentRunPruneAt = 0;
|
|
9198
|
+
|
|
9199
|
+
function agentRunProjectionKey(instance) {
|
|
9200
|
+
return `${instance?.parentSessionId || "external"}\0${instance?.instanceId || ""}`;
|
|
9201
|
+
}
|
|
9202
|
+
|
|
9203
|
+
function agentRunProjectionCanBeDismissed(instance) {
|
|
9204
|
+
return AGENT_RUN_TERMINAL_STATUSES.has(instance?.status)
|
|
9205
|
+
|| (instance?.origin === "explicit-attach" && ["stale", "lost"].includes(instance?.status));
|
|
9206
|
+
}
|
|
9207
|
+
|
|
9208
|
+
function pruneDismissedAgentRunProjections(now = Date.now()) {
|
|
9209
|
+
for (const [key, dismissedAt] of dismissedAgentRunProjectionKeys) {
|
|
9210
|
+
if (!Number.isSafeInteger(dismissedAt) || now - dismissedAt > AGENT_RUN_PROJECTION_DISMISSAL_RETENTION_MS) dismissedAgentRunProjectionKeys.delete(key);
|
|
9211
|
+
}
|
|
9212
|
+
while (dismissedAgentRunProjectionKeys.size > AGENT_RUN_PROJECTION_DISMISSAL_LIMIT) {
|
|
9213
|
+
const oldest = dismissedAgentRunProjectionKeys.keys().next().value;
|
|
9214
|
+
if (oldest === undefined) break;
|
|
9215
|
+
dismissedAgentRunProjectionKeys.delete(oldest);
|
|
9216
|
+
}
|
|
9217
|
+
}
|
|
9218
|
+
|
|
9219
|
+
function dismissAgentRunProjection(instance, now = Date.now()) {
|
|
9220
|
+
const key = agentRunProjectionKey(instance);
|
|
9221
|
+
dismissedAgentRunProjectionKeys.delete(key);
|
|
9222
|
+
dismissedAgentRunProjectionKeys.set(key, now);
|
|
9223
|
+
pruneDismissedAgentRunProjections(now);
|
|
9224
|
+
}
|
|
9225
|
+
|
|
9226
|
+
const startupSuppressedAgentRunProjectionKeys = new Set();
|
|
9227
|
+
try {
|
|
9228
|
+
const startupRegistrySnapshot = await agentRunRegistry.readRecords();
|
|
9229
|
+
for (const record of startupRegistrySnapshot.records) {
|
|
9230
|
+
if (!agentRunIsActive(record.instance)) startupSuppressedAgentRunProjectionKeys.add(agentRunProjectionKey(record.instance));
|
|
9231
|
+
}
|
|
9232
|
+
} catch {
|
|
9233
|
+
// Registry startup is best-effort; normal reconciliation reports later availability errors.
|
|
9234
|
+
}
|
|
9235
|
+
|
|
9129
9236
|
const recoveryEndpointToken = String(process.env.PI_WEBUI_RECOVERY_TOKEN || "").trim() || `${randomUUID()}${randomUUID()}`;
|
|
9130
9237
|
const recoveryEndpointTokens = new Set([recoveryEndpointToken]);
|
|
9131
9238
|
|
|
@@ -9918,7 +10025,9 @@ function filterSessionSummaryTranscriptMessages(messages) {
|
|
|
9918
10025
|
}
|
|
9919
10026
|
|
|
9920
10027
|
function clearWebuiSubagents(tab) {
|
|
9921
|
-
if (tab)
|
|
10028
|
+
if (!tab) return;
|
|
10029
|
+
tab.webuiSubagents = null;
|
|
10030
|
+
tab.webuiAgentRuns = null;
|
|
9922
10031
|
}
|
|
9923
10032
|
|
|
9924
10033
|
function normalizeWebuiSubagentText(value, maxLength = 240) {
|
|
@@ -9927,7 +10036,19 @@ function normalizeWebuiSubagentText(value, maxLength = 240) {
|
|
|
9927
10036
|
}
|
|
9928
10037
|
|
|
9929
10038
|
function normalizeWebuiSubagentSource(value) {
|
|
9930
|
-
return
|
|
10039
|
+
return ["foreground", "workflow", "recovered"].includes(value) ? value : "async";
|
|
10040
|
+
}
|
|
10041
|
+
|
|
10042
|
+
function normalizeWebuiSubagentFleet(value) {
|
|
10043
|
+
if (!value || typeof value !== "object" || value.version !== 1) return null;
|
|
10044
|
+
const totalActive = Number.isSafeInteger(value.totalActive) && value.totalActive >= 0 ? value.totalActive : -1;
|
|
10045
|
+
const omitted = Number.isSafeInteger(value.omitted) && value.omitted >= 0 ? value.omitted : -1;
|
|
10046
|
+
if (totalActive < 0 || omitted < 0 || omitted > totalActive) return null;
|
|
10047
|
+
return { version: 1, totalActive, omitted };
|
|
10048
|
+
}
|
|
10049
|
+
|
|
10050
|
+
function agentRunIsActive(value) {
|
|
10051
|
+
return ["queued", "running"].includes(value?.status);
|
|
9931
10052
|
}
|
|
9932
10053
|
|
|
9933
10054
|
function normalizeWebuiSubagentPayload(value) {
|
|
@@ -9958,9 +10079,14 @@ function normalizeWebuiSubagentPayload(value) {
|
|
|
9958
10079
|
});
|
|
9959
10080
|
}
|
|
9960
10081
|
if (status === "running" && !agents.length) continue;
|
|
10082
|
+
const source = normalizeWebuiSubagentSource(rawRun.source);
|
|
10083
|
+
const provisional = source === "recovered" || rawRun.provisional === true;
|
|
10084
|
+
const controllable = source !== "recovered" && !provisional && rawRun.controllable !== false;
|
|
9961
10085
|
runs.push({
|
|
9962
10086
|
id,
|
|
9963
|
-
source
|
|
10087
|
+
source,
|
|
10088
|
+
...(provisional ? { provisional: true } : {}),
|
|
10089
|
+
...(!controllable ? { controllable: false } : {}),
|
|
9964
10090
|
mode: ["single", "parallel", "chain"].includes(rawRun.mode) ? rawRun.mode : "single",
|
|
9965
10091
|
status,
|
|
9966
10092
|
startedAt: Number.isFinite(rawRun.startedAt) ? rawRun.startedAt : Date.now(),
|
|
@@ -10019,24 +10145,82 @@ function normalizeWebuiSubagentPayload(value) {
|
|
|
10019
10145
|
available: value.available === true,
|
|
10020
10146
|
updatedAt: Number.isFinite(value.updatedAt) ? value.updatedAt : Date.now(),
|
|
10021
10147
|
receivedAt: Date.now(),
|
|
10148
|
+
fleet: normalizeWebuiSubagentFleet(value.fleet),
|
|
10022
10149
|
runs: runs.sort((a, b) => a.startedAt - b.startedAt || a.id.localeCompare(b.id)),
|
|
10023
10150
|
gates: gates.sort((a, b) => a.startedAt - b.startedAt || a.id.localeCompare(b.id)),
|
|
10024
10151
|
};
|
|
10025
10152
|
}
|
|
10026
10153
|
|
|
10154
|
+
function normalizeWebuiAgentRunPayload(value) {
|
|
10155
|
+
if (!value || typeof value !== "object" || value.version !== 2) return null;
|
|
10156
|
+
const instances = [];
|
|
10157
|
+
const diagnostics = [];
|
|
10158
|
+
for (const raw of Array.isArray(value.instances) ? value.instances.slice(0, WEBUI_AGENT_RUN_LIMIT) : []) {
|
|
10159
|
+
try { instances.push(normalizeAgentInstance(raw)); }
|
|
10160
|
+
catch { diagnostics.push({ code: "invalid-helper-instance" }); }
|
|
10161
|
+
}
|
|
10162
|
+
for (const raw of Array.isArray(value.diagnostics) ? value.diagnostics.slice(-WEBUI_AGENT_RUN_DIAGNOSTIC_LIMIT) : []) {
|
|
10163
|
+
const code = normalizeWebuiSubagentText(raw?.code, 80);
|
|
10164
|
+
const producerId = normalizeWebuiSubagentText(raw?.producerId, 80);
|
|
10165
|
+
if (code) diagnostics.push({ code, ...(producerId ? { producerId } : {}) });
|
|
10166
|
+
}
|
|
10167
|
+
return {
|
|
10168
|
+
version: 2,
|
|
10169
|
+
available: value.available === true,
|
|
10170
|
+
updatedAt: Number.isFinite(value.updatedAt) ? value.updatedAt : Date.now(),
|
|
10171
|
+
receivedAt: Date.now(),
|
|
10172
|
+
instances,
|
|
10173
|
+
gateReferences: (Array.isArray(value.gateReferences) ? value.gateReferences : []).slice(0, 128).map((reference) => ({
|
|
10174
|
+
gateId: normalizeWebuiSubagentText(reference?.gateId, 160),
|
|
10175
|
+
attemptId: normalizeWebuiSubagentText(reference?.attemptId, 240),
|
|
10176
|
+
runId: normalizeWebuiSubagentText(reference?.runId, 160),
|
|
10177
|
+
instanceIds: (Array.isArray(reference?.instanceIds) ? reference.instanceIds : []).slice(0, 32).map((id) => normalizeWebuiSubagentText(id, 160)).filter(Boolean),
|
|
10178
|
+
resolved: reference?.resolved === true,
|
|
10179
|
+
})).filter((reference) => reference.gateId && reference.attemptId && reference.runId),
|
|
10180
|
+
diagnostics: diagnostics.slice(-WEBUI_AGENT_RUN_DIAGNOSTIC_LIMIT),
|
|
10181
|
+
};
|
|
10182
|
+
}
|
|
10183
|
+
|
|
10184
|
+
function filterStartupInactiveRows(tab, payload, { rowsKey, stateKey }) {
|
|
10185
|
+
if (!payload) return payload;
|
|
10186
|
+
const rows = Array.isArray(payload[rowsKey]) ? payload[rowsKey] : [];
|
|
10187
|
+
const seenKey = `${stateKey}Seen`;
|
|
10188
|
+
const suppressedKey = `${stateKey}Suppressed`;
|
|
10189
|
+
const suppressed = tab[suppressedKey] instanceof Set ? tab[suppressedKey] : new Set();
|
|
10190
|
+
if (tab[seenKey] !== true) {
|
|
10191
|
+
for (const row of rows) if (!agentRunIsActive(row)) suppressed.add(row.instanceId || row.id);
|
|
10192
|
+
tab[seenKey] = true;
|
|
10193
|
+
tab[suppressedKey] = suppressed;
|
|
10194
|
+
}
|
|
10195
|
+
const visibleRows = rows.filter((row) => {
|
|
10196
|
+
const id = row.instanceId || row.id;
|
|
10197
|
+
if (!suppressed.has(id)) return true;
|
|
10198
|
+
if (!agentRunIsActive(row)) return false;
|
|
10199
|
+
suppressed.delete(id);
|
|
10200
|
+
return true;
|
|
10201
|
+
});
|
|
10202
|
+
return { ...payload, [rowsKey]: visibleRows };
|
|
10203
|
+
}
|
|
10204
|
+
|
|
10027
10205
|
function rememberWebuiSubagentsStatusEvent(tab, event) {
|
|
10028
|
-
if (event?.type !== "extension_ui_request" || event.method !== "setStatus"
|
|
10206
|
+
if (event?.type !== "extension_ui_request" || event.method !== "setStatus") return false;
|
|
10029
10207
|
const statusText = String(event.statusText || "");
|
|
10030
|
-
if (
|
|
10031
|
-
|
|
10208
|
+
if (event.statusKey === WEBUI_SUBAGENTS_V2_STATUS_KEY) {
|
|
10209
|
+
if (!statusText) { tab.webuiAgentRuns = null; return true; }
|
|
10210
|
+
if (!statusText.startsWith(WEBUI_SUBAGENTS_V2_PAYLOAD_PREFIX)) return true;
|
|
10211
|
+
try {
|
|
10212
|
+
const payload = normalizeWebuiAgentRunPayload(JSON.parse(statusText.slice(WEBUI_SUBAGENTS_V2_PAYLOAD_PREFIX.length)));
|
|
10213
|
+
tab.webuiAgentRuns = filterStartupInactiveRows(tab, payload, { rowsKey: "instances", stateKey: "webuiAgentRunStartup" });
|
|
10214
|
+
} catch { tab.webuiAgentRuns = null; }
|
|
10032
10215
|
return true;
|
|
10033
10216
|
}
|
|
10217
|
+
if (event.statusKey !== WEBUI_SUBAGENTS_STATUS_KEY) return false;
|
|
10218
|
+
if (!statusText) { tab.webuiSubagents = null; return true; }
|
|
10034
10219
|
if (!statusText.startsWith(WEBUI_SUBAGENTS_PAYLOAD_PREFIX)) return true;
|
|
10035
10220
|
try {
|
|
10036
|
-
|
|
10037
|
-
|
|
10038
|
-
|
|
10039
|
-
}
|
|
10221
|
+
const payload = normalizeWebuiSubagentPayload(JSON.parse(statusText.slice(WEBUI_SUBAGENTS_PAYLOAD_PREFIX.length)));
|
|
10222
|
+
tab.webuiSubagents = filterStartupInactiveRows(tab, payload, { rowsKey: "runs", stateKey: "webuiSubagentStartup" });
|
|
10223
|
+
} catch { tab.webuiSubagents = null; }
|
|
10040
10224
|
return true;
|
|
10041
10225
|
}
|
|
10042
10226
|
|
|
@@ -10836,6 +11020,7 @@ function createTabRecord({ id, index, title, titleSource, conversationStarted, c
|
|
|
10836
11020
|
extensionWidgets: new Map(),
|
|
10837
11021
|
sessionSummary: null,
|
|
10838
11022
|
webuiSubagents: null,
|
|
11023
|
+
webuiAgentRuns: null,
|
|
10839
11024
|
subagentDisplayTitle: undefined,
|
|
10840
11025
|
subagentDisplayTitlePromise: undefined,
|
|
10841
11026
|
webuiHelperRequests: new Map(),
|
|
@@ -11021,43 +11206,197 @@ async function resolveSubagentDisplayTitle(tab) {
|
|
|
11021
11206
|
return tab.subagentDisplayTitlePromise;
|
|
11022
11207
|
}
|
|
11023
11208
|
|
|
11024
|
-
|
|
11209
|
+
function tabParentSessionId(tab) {
|
|
11210
|
+
const raw = tab?.lastState?.sessionId;
|
|
11211
|
+
return raw ? canonicalAgentRunId(raw, "session") : null;
|
|
11212
|
+
}
|
|
11213
|
+
|
|
11214
|
+
function legacyRunInstances(tab, run) {
|
|
11215
|
+
const parentSessionId = tabParentSessionId(tab) || `legacy-tab:${tab.id}`;
|
|
11216
|
+
const startedAt = Number.isSafeInteger(run.startedAt) ? run.startedAt : Date.now();
|
|
11217
|
+
return run.agents.map((agent) => {
|
|
11218
|
+
const status = ["running", "done", "failed", "cancelled"].includes(agent.status) ? agent.status : run.status;
|
|
11219
|
+
const endedAt = status === "running" ? null : Math.max(startedAt, Number.isSafeInteger(run.endedAt) ? run.endedAt : Date.now());
|
|
11220
|
+
return normalizeAgentInstance({
|
|
11221
|
+
version: 1,
|
|
11222
|
+
instanceId: canonicalAgentRunId(agent.id, "agent"),
|
|
11223
|
+
runId: canonicalAgentRunId(run.id, "run"),
|
|
11224
|
+
parentSessionId,
|
|
11225
|
+
launcher: run.source === "workflow" ? "workflow" : "pi-subagents",
|
|
11226
|
+
provider: run.source === "workflow" ? "workflow-run" : "webui-helper",
|
|
11227
|
+
origin: run.source,
|
|
11228
|
+
name: agent.name,
|
|
11229
|
+
status,
|
|
11230
|
+
startedAt,
|
|
11231
|
+
updatedAt: endedAt ?? Date.now(),
|
|
11232
|
+
endedAt,
|
|
11233
|
+
model: agent.model,
|
|
11234
|
+
thinking: agent.thinking,
|
|
11235
|
+
activityState: agent.activityState,
|
|
11236
|
+
currentTool: agent.currentTool,
|
|
11237
|
+
capabilities: {
|
|
11238
|
+
open: webuiSubagentRunSupportsInteraction(run),
|
|
11239
|
+
refresh: webuiSubagentRunSupportsInteraction(run),
|
|
11240
|
+
cancel: status === "running" && webuiSubagentRunSupportsInteraction(run),
|
|
11241
|
+
steer: false,
|
|
11242
|
+
},
|
|
11243
|
+
outputRef: { kind: "none" },
|
|
11244
|
+
});
|
|
11245
|
+
});
|
|
11246
|
+
}
|
|
11247
|
+
|
|
11248
|
+
function groupedCanonicalRuns(instances) {
|
|
11249
|
+
const byRun = new Map();
|
|
11250
|
+
for (const instance of instances) {
|
|
11251
|
+
const current = byRun.get(instance.runId) || [];
|
|
11252
|
+
current.push(instance);
|
|
11253
|
+
byRun.set(instance.runId, current);
|
|
11254
|
+
}
|
|
11255
|
+
return [...byRun.entries()].map(([runId, agents]) => {
|
|
11256
|
+
agents.sort((a, b) => a.startedAt - b.startedAt || a.instanceId.localeCompare(b.instanceId));
|
|
11257
|
+
const status = agents.some((agent) => agent.status === "running") ? "running"
|
|
11258
|
+
: agents.some((agent) => agent.status === "stale") ? "stale"
|
|
11259
|
+
: agents.some((agent) => agent.status === "lost") ? "lost"
|
|
11260
|
+
: agents.some((agent) => agent.status === "failed") ? "failed"
|
|
11261
|
+
: agents.some((agent) => agent.status === "cancelled") ? "cancelled" : "done";
|
|
11262
|
+
return {
|
|
11263
|
+
id: runId,
|
|
11264
|
+
source: agents[0].origin || agents[0].launcher,
|
|
11265
|
+
launcher: agents[0].launcher,
|
|
11266
|
+
provider: agents[0].provider,
|
|
11267
|
+
status,
|
|
11268
|
+
startedAt: Math.min(...agents.map((agent) => agent.startedAt)),
|
|
11269
|
+
endedAt: agents.every((agent) => Number.isSafeInteger(agent.endedAt)) ? Math.max(...agents.map((agent) => agent.endedAt)) : undefined,
|
|
11270
|
+
capabilities: {
|
|
11271
|
+
open: agents.some((agent) => agent.capabilities.open),
|
|
11272
|
+
refresh: agents.some((agent) => agent.capabilities.refresh),
|
|
11273
|
+
cancel: agents.some((agent) => agent.capabilities.cancel),
|
|
11274
|
+
steer: agents.some((agent) => agent.capabilities.steer),
|
|
11275
|
+
},
|
|
11276
|
+
agents: agents.map((agent) => ({
|
|
11277
|
+
id: agent.instanceId,
|
|
11278
|
+
instanceId: agent.instanceId,
|
|
11279
|
+
name: agent.name || "Agent",
|
|
11280
|
+
status: agent.status,
|
|
11281
|
+
launcher: agent.launcher,
|
|
11282
|
+
provider: agent.provider,
|
|
11283
|
+
origin: agent.origin,
|
|
11284
|
+
model: agent.model,
|
|
11285
|
+
thinking: agent.thinking,
|
|
11286
|
+
activityState: agent.activityState,
|
|
11287
|
+
currentTool: agent.currentTool,
|
|
11288
|
+
capabilities: agent.capabilities,
|
|
11289
|
+
outputRef: agent.outputRef,
|
|
11290
|
+
})),
|
|
11291
|
+
};
|
|
11292
|
+
}).sort((a, b) => a.startedAt - b.startedAt || a.id.localeCompare(b.id));
|
|
11293
|
+
}
|
|
11294
|
+
|
|
11295
|
+
async function webuiSubagentsData({ includeSelections = false } = {}) {
|
|
11025
11296
|
const sortedTabs = [...tabs.values()].sort((a, b) => a.index - b.index || a.title.localeCompare(b.title));
|
|
11026
11297
|
const tabSummaries = await Promise.all(sortedTabs.map(async (tab) => {
|
|
11027
11298
|
const status = tab.webuiSubagents || { version: 1, available: false, updatedAt: null, receivedAt: null, runs: [], gates: [] };
|
|
11028
11299
|
const runs = Array.isArray(status.runs) ? status.runs : [];
|
|
11029
11300
|
const gates = Array.isArray(status.gates) ? status.gates : [];
|
|
11030
|
-
const tabTitle = runs.length || gates.length ? await resolveSubagentDisplayTitle(tab) : tab.title;
|
|
11301
|
+
const tabTitle = runs.length || gates.length || tab.webuiAgentRuns?.instances?.length ? await resolveSubagentDisplayTitle(tab) : tab.title;
|
|
11031
11302
|
return {
|
|
11032
|
-
tabId: tab.id,
|
|
11033
|
-
tabIndex: tab.index,
|
|
11034
|
-
tabTitle,
|
|
11035
|
-
cwd: tab.cwd,
|
|
11303
|
+
tabId: tab.id, tabIndex: tab.index, tabTitle, cwd: tab.cwd,
|
|
11036
11304
|
sessionName: normalizeWebuiSubagentText(tab.lastState?.sessionName || tab.title, 160),
|
|
11037
11305
|
sessionFile: tabRestorableSessionFile(tab) || null,
|
|
11038
|
-
running: tab.rpc.isRunning(),
|
|
11039
|
-
|
|
11040
|
-
|
|
11041
|
-
|
|
11042
|
-
runs,
|
|
11043
|
-
gates,
|
|
11306
|
+
running: tab.rpc.isRunning(), available: status.available === true || tab.webuiAgentRuns?.available === true,
|
|
11307
|
+
updatedAt: status.updatedAt || tab.webuiAgentRuns?.updatedAt || null,
|
|
11308
|
+
receivedAt: status.receivedAt || tab.webuiAgentRuns?.receivedAt || null,
|
|
11309
|
+
fleet: status.fleet || null, runs, gates,
|
|
11044
11310
|
agentCount: runs.reduce((count, run) => count + run.agents.length, 0),
|
|
11045
11311
|
runningRuns: runs.filter((run) => run.status === "running").length,
|
|
11046
11312
|
runningAgents: runs.reduce((count, run) => count + run.agents.filter((agent) => agent.status === "running").length, 0),
|
|
11047
11313
|
gateCount: gates.length,
|
|
11048
11314
|
};
|
|
11049
11315
|
}));
|
|
11050
|
-
|
|
11051
|
-
|
|
11052
|
-
|
|
11053
|
-
|
|
11054
|
-
|
|
11055
|
-
|
|
11056
|
-
|
|
11057
|
-
|
|
11058
|
-
|
|
11059
|
-
|
|
11316
|
+
const index = new AgentRunIndex();
|
|
11317
|
+
const selections = new Map();
|
|
11318
|
+
const diagnostics = [];
|
|
11319
|
+
for (const tab of sortedTabs) {
|
|
11320
|
+
const canonical = tab.webuiAgentRuns?.instances;
|
|
11321
|
+
if (Array.isArray(canonical)) {
|
|
11322
|
+
for (const instance of canonical) {
|
|
11323
|
+
index.upsert(instance, { producerId: instance.provider, lifecycleOwner: true, capabilityOwner: true });
|
|
11324
|
+
selections.set(`${instance.parentSessionId || "external"}\0${instance.instanceId}`, { kind: "helper", tab, instance });
|
|
11325
|
+
}
|
|
11326
|
+
diagnostics.push(...(tab.webuiAgentRuns.diagnostics || []));
|
|
11327
|
+
} else {
|
|
11328
|
+
for (const run of tab.webuiSubagents?.runs || []) for (const instance of legacyRunInstances(tab, run)) {
|
|
11329
|
+
index.upsert(instance, { producerId: instance.provider, lifecycleOwner: true, capabilityOwner: true });
|
|
11330
|
+
selections.set(`${instance.parentSessionId}\0${instance.instanceId}`, { kind: "legacy-helper", tab, instance, run, agent: run.agents.find((candidate) => canonicalAgentRunId(candidate.id, "agent") === instance.instanceId) });
|
|
11331
|
+
}
|
|
11332
|
+
}
|
|
11333
|
+
}
|
|
11334
|
+
let registrySnapshot = { records: [], diagnostics: [], omitted: 0, artifacts: new Map() };
|
|
11335
|
+
const reconcileNow = Date.now();
|
|
11336
|
+
pruneDismissedAgentRunProjections(reconcileNow);
|
|
11337
|
+
try {
|
|
11338
|
+
if (reconcileNow - lastAgentRunPruneAt >= AGENT_RUN_PRUNE_INTERVAL_MS) {
|
|
11339
|
+
lastAgentRunPruneAt = reconcileNow;
|
|
11340
|
+
try { await agentRunRegistry.prune({ now: reconcileNow }); }
|
|
11341
|
+
catch { diagnostics.push({ code: "registry-prune-unavailable" }); }
|
|
11342
|
+
}
|
|
11343
|
+
registrySnapshot = await agentRunRegistry.readRecords({ now: reconcileNow });
|
|
11344
|
+
} catch { diagnostics.push({ code: "registry-unavailable" }); }
|
|
11345
|
+
const visibleRegistryRecords = [];
|
|
11346
|
+
for (const record of registrySnapshot.records) {
|
|
11347
|
+
const key = agentRunProjectionKey(record.instance);
|
|
11348
|
+
if (startupSuppressedAgentRunProjectionKeys.has(key)) {
|
|
11349
|
+
if (!agentRunIsActive(record.instance)) continue;
|
|
11350
|
+
startupSuppressedAgentRunProjectionKeys.delete(key);
|
|
11351
|
+
}
|
|
11352
|
+
if (dismissedAgentRunProjectionKeys.has(key)) {
|
|
11353
|
+
if (agentRunProjectionCanBeDismissed(record.instance)) continue;
|
|
11354
|
+
dismissedAgentRunProjectionKeys.delete(key);
|
|
11355
|
+
}
|
|
11356
|
+
visibleRegistryRecords.push(record);
|
|
11357
|
+
index.upsert(record.instance, { producerId: record.producerId });
|
|
11358
|
+
if (!selections.has(key) || record.instance.outputRef.kind === "session-jsonl") selections.set(key, { kind: "registry", instance: record.instance, record });
|
|
11359
|
+
}
|
|
11360
|
+
diagnostics.push(...registrySnapshot.diagnostics, ...(registrySnapshot.omitted ? [{ code: "registry-records-omitted", count: registrySnapshot.omitted }] : []));
|
|
11361
|
+
|
|
11362
|
+
const byParent = new Map();
|
|
11363
|
+
for (const instance of index.values()) {
|
|
11364
|
+
const key = instance.parentSessionId || "external";
|
|
11365
|
+
const rows = byParent.get(key) || [];
|
|
11366
|
+
rows.push(instance);
|
|
11367
|
+
byParent.set(key, rows);
|
|
11368
|
+
}
|
|
11369
|
+
const groups = [];
|
|
11370
|
+
const claimedParents = new Set();
|
|
11371
|
+
for (const tabSummary of tabSummaries) {
|
|
11372
|
+
const tab = tabs.get(tabSummary.tabId);
|
|
11373
|
+
const parentId = tabParentSessionId(tab) || `legacy-tab:${tabSummary.tabId}`;
|
|
11374
|
+
claimedParents.add(parentId);
|
|
11375
|
+
groups.push({
|
|
11376
|
+
id: `tab:${tabSummary.tabId}`, kind: "tab", tabId: tabSummary.tabId, tabIndex: tabSummary.tabIndex,
|
|
11377
|
+
title: tabSummary.tabTitle, cwdLabel: path.basename(tabSummary.cwd) || tabSummary.cwd,
|
|
11378
|
+
runs: groupedCanonicalRuns(byParent.get(parentId) || []), gates: tabSummary.gates,
|
|
11379
|
+
});
|
|
11380
|
+
}
|
|
11381
|
+
const externalInstances = [...byParent.entries()].filter(([parent]) => !claimedParents.has(parent)).flatMap(([, rows]) => rows);
|
|
11382
|
+
if (externalInstances.length) groups.push({ id: "external", kind: "external", title: "External agents", runs: groupedCanonicalRuns(externalInstances), gates: [] });
|
|
11383
|
+
const instances = index.values();
|
|
11384
|
+
const counts = {
|
|
11385
|
+
totalRuns: groups.reduce((count, group) => count + group.runs.length, 0),
|
|
11386
|
+
totalAgents: instances.length,
|
|
11387
|
+
runningAgents: instances.filter((instance) => instance.status === "running").length,
|
|
11388
|
+
staleAgents: instances.filter((instance) => instance.status === "stale").length,
|
|
11389
|
+
byLauncher: Object.fromEntries([...new Set(instances.map((instance) => instance.launcher))].sort().map((launcher) => [launcher, instances.filter((instance) => instance.launcher === launcher).length])),
|
|
11060
11390
|
};
|
|
11391
|
+
const fleet = tabSummaries.reduce((summary, tab) => ({ version: 1, totalActive: Math.min(Number.MAX_SAFE_INTEGER, summary.totalActive + Number(tab.fleet?.totalActive || 0)), omitted: Math.min(Number.MAX_SAFE_INTEGER, summary.omitted + Number(tab.fleet?.omitted || 0)) }), { version: 1, totalActive: 0, omitted: 0 });
|
|
11392
|
+
const overview = {
|
|
11393
|
+
version: 2, updatedAt: Date.now(), available: tabSummaries.some((tab) => tab.available) || visibleRegistryRecords.length > 0,
|
|
11394
|
+
groups, counts, diagnostics: diagnostics.slice(-WEBUI_AGENT_RUN_DIAGNOSTIC_LIMIT), fleet,
|
|
11395
|
+
totalRuns: counts.totalRuns, totalAgents: counts.totalAgents,
|
|
11396
|
+
runningRuns: groups.reduce((count, group) => count + group.runs.filter((run) => run.status === "running").length, 0),
|
|
11397
|
+
runningAgents: counts.runningAgents, totalGates: tabSummaries.reduce((count, tab) => count + tab.gateCount, 0), tabs: tabSummaries,
|
|
11398
|
+
};
|
|
11399
|
+
return includeSelections ? { overview, selections, registrySnapshot } : overview;
|
|
11061
11400
|
}
|
|
11062
11401
|
|
|
11063
11402
|
function normalizeWebuiSubagentTranscriptValue(value, maxLength = WEBUI_SUBAGENT_OUTPUT_LINE_LENGTH) {
|
|
@@ -11197,21 +11536,153 @@ function normalizeWebuiSubagentOutput(value, selection) {
|
|
|
11197
11536
|
recentTools,
|
|
11198
11537
|
recentOutput,
|
|
11199
11538
|
transcript,
|
|
11539
|
+
unavailable: rawAgent.unavailable === true || undefined,
|
|
11540
|
+
unavailableReason: rawAgent.unavailable === true ? normalizeWebuiSubagentText(rawAgent.unavailableReason, 1000) || "Live output is unavailable for this agent." : undefined,
|
|
11200
11541
|
error: normalizeWebuiSubagentText(rawAgent.error, 1000) || undefined,
|
|
11201
11542
|
},
|
|
11202
11543
|
};
|
|
11203
11544
|
}
|
|
11204
11545
|
|
|
11205
|
-
|
|
11546
|
+
function webuiSubagentRunSupportsInteraction(run) {
|
|
11547
|
+
return run?.source !== "recovered" && run?.provisional !== true && run?.controllable !== false;
|
|
11548
|
+
}
|
|
11549
|
+
|
|
11550
|
+
function requireInteractiveWebuiSubagentRun(tab, runId) {
|
|
11551
|
+
const normalizedRunId = normalizeWebuiSubagentText(runId, 160);
|
|
11206
11552
|
const runs = Array.isArray(tab.webuiSubagents?.runs) ? tab.webuiSubagents.runs : [];
|
|
11207
|
-
const run = runs.find((candidate) => candidate.id ===
|
|
11208
|
-
if (!run) throw makeHttpError(404, `Subagent run not found: ${
|
|
11553
|
+
const run = runs.find((candidate) => candidate.id === normalizedRunId);
|
|
11554
|
+
if (!run) throw makeHttpError(404, `Subagent run not found: ${normalizedRunId}`);
|
|
11555
|
+
if (!webuiSubagentRunSupportsInteraction(run)) throw makeHttpError(409, "Recovered provisional subagents are status-only");
|
|
11556
|
+
return run;
|
|
11557
|
+
}
|
|
11558
|
+
|
|
11559
|
+
function rejectUnsupportedWebuiSubagentRun(tab, runId) {
|
|
11560
|
+
const normalizedRunId = normalizeWebuiSubagentText(runId, 160);
|
|
11561
|
+
const runs = Array.isArray(tab.webuiSubagents?.runs) ? tab.webuiSubagents.runs : [];
|
|
11562
|
+
const run = runs.find((candidate) => candidate.id === normalizedRunId);
|
|
11563
|
+
if (run && !webuiSubagentRunSupportsInteraction(run)) throw makeHttpError(409, "Recovered provisional subagents are status-only");
|
|
11564
|
+
return normalizedRunId;
|
|
11565
|
+
}
|
|
11566
|
+
|
|
11567
|
+
async function webuiSubagentOutputData(tab, runId, agentId) {
|
|
11568
|
+
const run = requireInteractiveWebuiSubagentRun(tab, runId);
|
|
11209
11569
|
const agent = (Array.isArray(run.agents) ? run.agents : []).find((candidate) => candidate.id === agentId);
|
|
11210
11570
|
if (!agent) throw makeHttpError(404, `Subagent not found: ${agentId}`);
|
|
11211
11571
|
const data = await sendWebuiHelperCommand(tab, "subagent-output", { runId, agentId });
|
|
11212
11572
|
return normalizeWebuiSubagentOutput(data, { run, agent });
|
|
11213
11573
|
}
|
|
11214
11574
|
|
|
11575
|
+
function canonicalOutputSelection(groupId, runId, instanceId, state) {
|
|
11576
|
+
const group = state.overview.groups.find((candidate) => candidate.id === groupId);
|
|
11577
|
+
const run = group?.runs.find((candidate) => candidate.id === runId);
|
|
11578
|
+
const agent = run?.agents.find((candidate) => candidate.instanceId === instanceId);
|
|
11579
|
+
if (!group || !run || !agent) throw makeHttpError(404, "Agent run output is no longer tracked");
|
|
11580
|
+
for (const selection of state.selections.values()) {
|
|
11581
|
+
if (selection.instance.runId !== runId || selection.instance.instanceId !== instanceId) continue;
|
|
11582
|
+
if (group.kind === "tab") {
|
|
11583
|
+
const tab = tabs.get(group.tabId);
|
|
11584
|
+
if (selection.tab?.id === group.tabId || selection.instance.parentSessionId === tabParentSessionId(tab)) return { group, run, agent, selection };
|
|
11585
|
+
} else if (!selection.instance.parentSessionId || ![...tabs.values()].some((tab) => tabParentSessionId(tab) === selection.instance.parentSessionId)) {
|
|
11586
|
+
return { group, run, agent, selection };
|
|
11587
|
+
}
|
|
11588
|
+
}
|
|
11589
|
+
throw makeHttpError(404, "Agent run output is no longer tracked");
|
|
11590
|
+
}
|
|
11591
|
+
|
|
11592
|
+
async function boundedSessionMessages(sessionFile, maximum = 256 * 1024) {
|
|
11593
|
+
const handle = await open(sessionFile, "r");
|
|
11594
|
+
try {
|
|
11595
|
+
const info = await handle.stat();
|
|
11596
|
+
const length = Math.min(info.size, maximum);
|
|
11597
|
+
const buffer = Buffer.alloc(length);
|
|
11598
|
+
await handle.read(buffer, 0, length, Math.max(0, info.size - length));
|
|
11599
|
+
const text = buffer.toString("utf8");
|
|
11600
|
+
const lines = text.split("\n");
|
|
11601
|
+
if (info.size > length) lines.shift();
|
|
11602
|
+
const messages = [];
|
|
11603
|
+
for (const line of lines) {
|
|
11604
|
+
if (!line || Buffer.byteLength(line) > 64 * 1024) continue;
|
|
11605
|
+
try {
|
|
11606
|
+
const entry = JSON.parse(line);
|
|
11607
|
+
if (entry?.type === "message" && entry.message) messages.push(entry.message);
|
|
11608
|
+
else if (["assistant", "toolResult"].includes(entry?.role)) messages.push(entry);
|
|
11609
|
+
} catch {}
|
|
11610
|
+
}
|
|
11611
|
+
return messages;
|
|
11612
|
+
} finally { await handle.close(); }
|
|
11613
|
+
}
|
|
11614
|
+
|
|
11615
|
+
function registryOutputData(instance, events = [], transcript = []) {
|
|
11616
|
+
const outputLines = events.filter((event) => typeof event?.message === "string").slice(-WEBUI_SUBAGENT_OUTPUT_LINE_LIMIT).map((event) => event.message.slice(0, WEBUI_SUBAGENT_OUTPUT_LINE_LENGTH));
|
|
11617
|
+
const recentTools = events.filter((event) => typeof event?.tool === "string").slice(-20).map((event) => ({ tool: event.tool.slice(0, 120), args: "", endMs: Number.isFinite(event.at) ? event.at : undefined }));
|
|
11618
|
+
return {
|
|
11619
|
+
version: 1, runId: instance.runId, source: instance.launcher, mode: "single", startedAt: instance.startedAt, updatedAt: instance.updatedAt,
|
|
11620
|
+
agent: {
|
|
11621
|
+
id: instance.instanceId, name: instance.name || "Agent", index: 0, nested: false, status: instance.status,
|
|
11622
|
+
activityState: instance.activityState, currentTool: instance.currentTool, model: instance.model, thinking: instance.thinking,
|
|
11623
|
+
telemetry: normalizeWebuiSubagentTelemetry(null, { model: instance.model, effort: instance.thinking }),
|
|
11624
|
+
recentTools, recentOutput: outputLines, transcript: normalizeWebuiSubagentTranscript(transcript),
|
|
11625
|
+
...(!outputLines.length && !transcript.length ? { unavailable: true, unavailableReason: "No bounded output has been registered for this agent." } : {}),
|
|
11626
|
+
},
|
|
11627
|
+
};
|
|
11628
|
+
}
|
|
11629
|
+
|
|
11630
|
+
async function canonicalWebuiSubagentOutputData(groupId, runId, instanceId) {
|
|
11631
|
+
const state = await webuiSubagentsData({ includeSelections: true });
|
|
11632
|
+
const { selection } = canonicalOutputSelection(groupId, runId, instanceId, state);
|
|
11633
|
+
const instance = selection.instance;
|
|
11634
|
+
if (!instance.capabilities.open) throw makeHttpError(409, "This agent provider does not support opening output");
|
|
11635
|
+
if (selection.kind === "legacy-helper") return webuiSubagentOutputData(selection.tab, selection.run.id, selection.agent.id);
|
|
11636
|
+
if (selection.kind === "helper") {
|
|
11637
|
+
if (instance.outputRef.kind !== "helper") return registryOutputData(instance);
|
|
11638
|
+
const data = await sendWebuiHelperCommand(selection.tab, "subagent-output", { outputId: instance.outputRef.id });
|
|
11639
|
+
const run = { id: instance.runId, source: instance.origin || "async", mode: "single", startedAt: instance.startedAt };
|
|
11640
|
+
const agent = { id: instance.instanceId, name: instance.name || "Agent", index: 0, model: instance.model, thinking: instance.thinking };
|
|
11641
|
+
return normalizeWebuiSubagentOutput(data, { run, agent });
|
|
11642
|
+
}
|
|
11643
|
+
if (instance.outputRef.kind === "session-jsonl") {
|
|
11644
|
+
const locator = await agentRunRegistry.resolveSessionLocator(instance.outputRef.id, { allowedRoots: allowedSessionDirs() });
|
|
11645
|
+
if (!locator) throw makeHttpError(404, "Registered session output is unavailable");
|
|
11646
|
+
return registryOutputData(instance, [], await boundedSessionMessages(locator.sessionFile));
|
|
11647
|
+
}
|
|
11648
|
+
if (["rpc-events", "json-events", "plain-log", "registry-artifact"].includes(instance.outputRef.kind)) {
|
|
11649
|
+
const artifact = await agentRunRegistry.readArtifact(instance.outputRef.id);
|
|
11650
|
+
return registryOutputData(instance, artifact?.events || []);
|
|
11651
|
+
}
|
|
11652
|
+
return registryOutputData(instance);
|
|
11653
|
+
}
|
|
11654
|
+
|
|
11655
|
+
async function canonicalWebuiSubagentAction(action, body) {
|
|
11656
|
+
const groupId = normalizeWebuiSubagentText(body.group, 240);
|
|
11657
|
+
const runId = normalizeWebuiSubagentText(body.runId || body.run, 160);
|
|
11658
|
+
const requestedAgentId = normalizeWebuiSubagentText(body.agentId || body.agent, 160);
|
|
11659
|
+
if (!groupId || !runId) throw makeHttpError(400, "group and runId are required");
|
|
11660
|
+
const state = await webuiSubagentsData({ includeSelections: true });
|
|
11661
|
+
const group = state.overview.groups.find((candidate) => candidate.id === groupId);
|
|
11662
|
+
const run = group?.runs.find((candidate) => candidate.id === runId);
|
|
11663
|
+
const agent = requestedAgentId ? run?.agents.find((candidate) => candidate.instanceId === requestedAgentId) : run?.agents[0];
|
|
11664
|
+
if (!group || !run || !agent) throw makeHttpError(404, "Agent run is no longer tracked");
|
|
11665
|
+
const { selection } = canonicalOutputSelection(groupId, runId, agent.instanceId, state);
|
|
11666
|
+
if (action === "cancel") {
|
|
11667
|
+
if (selection.kind !== "helper" && selection.kind !== "legacy-helper") throw makeHttpError(409, "This agent provider does not support cancellation");
|
|
11668
|
+
if (!agent.capabilities?.cancel) throw makeHttpError(409, "This agent provider does not support cancellation");
|
|
11669
|
+
return sendWebuiHelperCommand(selection.tab, "subagent-cancel", { runId: selection.kind === "legacy-helper" ? selection.run.id : selection.instance.runId, reason: body.reason, note: body.note });
|
|
11670
|
+
}
|
|
11671
|
+
if (!agentRunProjectionCanBeDismissed(selection.instance)) {
|
|
11672
|
+
throw makeHttpError(409, "Only terminal retained runs or stale attached-session projections can be dismissed");
|
|
11673
|
+
}
|
|
11674
|
+
if (selection.kind === "registry") {
|
|
11675
|
+
const registrySelections = run.agents.map((candidate) => canonicalOutputSelection(groupId, runId, candidate.instanceId, state).selection);
|
|
11676
|
+
if (registrySelections.some((candidate) => candidate.kind !== "registry" || !agentRunProjectionCanBeDismissed(candidate.instance))) {
|
|
11677
|
+
throw makeHttpError(409, "Only terminal registry-owned runs or stale attached-session projections can be dismissed as one projection");
|
|
11678
|
+
}
|
|
11679
|
+
for (const candidate of registrySelections) dismissAgentRunProjection(candidate.instance);
|
|
11680
|
+
return { runId: selection.instance.runId, dismissed: true };
|
|
11681
|
+
}
|
|
11682
|
+
if (selection.kind !== "helper" && selection.kind !== "legacy-helper") throw makeHttpError(409, `This agent provider does not support ${action}`);
|
|
11683
|
+
return sendWebuiHelperCommand(selection.tab, "subagent-dismiss", { runId: selection.kind === "legacy-helper" ? selection.run.id : selection.instance.runId });
|
|
11684
|
+
}
|
|
11685
|
+
|
|
11215
11686
|
function restorableTabDescriptor(tab, state = null) {
|
|
11216
11687
|
return normalizeRestoreTabDescriptor({
|
|
11217
11688
|
id: tab.id,
|
|
@@ -11442,10 +11913,9 @@ function updateOwnerForTarget(target, identities) {
|
|
|
11442
11913
|
}
|
|
11443
11914
|
const active = identities.pi.active;
|
|
11444
11915
|
const piRoot = active?.packageRoot || "";
|
|
11445
|
-
const
|
|
11446
|
-
const bundled = piRoot && exactUpdatePathInside(path.join(packageRoot, "node_modules"), piRoot);
|
|
11916
|
+
const bundled = bundledPackageOwnership({ hostPackageRoot: packageRoot, packageRoot: piRoot, source: active?.source });
|
|
11447
11917
|
if (bundled && webuiDevServer) return { manager: "unknown", packageRoot: piRoot, ownerRoot: packageRoot, sourceCheckout: true };
|
|
11448
|
-
if (bundled) return { manager: "npm", packageRoot: piRoot, ownerRoot:
|
|
11918
|
+
if (bundled) return { manager: "npm", packageRoot: piRoot, ownerRoot: bundled.ownerRoot, topLevel: true };
|
|
11449
11919
|
if ((active?.source === "explicit" || active?.source === "path") && piRoot) {
|
|
11450
11920
|
return { manager: "pi", packageRoot: piRoot, ownerRoot: piRoot, topLevel: true };
|
|
11451
11921
|
}
|
|
@@ -11462,7 +11932,7 @@ async function createServerOwnedUpdatePlan(targets) {
|
|
|
11462
11932
|
if (!status[target]?.checked || !status[target]?.latestVersion) throw makeHttpError(409, `${target} exact target metadata is unavailable.`);
|
|
11463
11933
|
}
|
|
11464
11934
|
const piRoot = identities.pi.active?.packageRoot || "";
|
|
11465
|
-
const bundledPi = Boolean(
|
|
11935
|
+
const bundledPi = Boolean(bundledPackageOwnership({ hostPackageRoot: packageRoot, packageRoot: piRoot, source: identities.pi.active?.source }));
|
|
11466
11936
|
const requested = new Set(targets);
|
|
11467
11937
|
const desiredPiVersion = requested.has("pi") ? status.pi.latestVersion : identities.pi.active?.version;
|
|
11468
11938
|
const desiredWebuiVersion = requested.has("webui") ? status.webui.latestVersion : identities.webui.version;
|
|
@@ -11564,6 +12034,7 @@ async function createServerOwnedUpdatePlan(targets) {
|
|
|
11564
12034
|
return { version: targetVersion, registry, metadata };
|
|
11565
12035
|
},
|
|
11566
12036
|
});
|
|
12037
|
+
assertActionableUpdatePlan(plan);
|
|
11567
12038
|
await createUpdateJournal(agentDir, plan);
|
|
11568
12039
|
return plan;
|
|
11569
12040
|
}
|
|
@@ -11621,6 +12092,7 @@ async function applyServerOwnedUpdate(transactionId, planDigest) {
|
|
|
11621
12092
|
const journal = await readUpdateJournal(agentDir, transactionId);
|
|
11622
12093
|
if (!journal) throw makeHttpError(404, "Update transaction was not found.");
|
|
11623
12094
|
assertUpdatePlanDigest(journal.plan, planDigest);
|
|
12095
|
+
assertActionableUpdatePlan(journal.plan);
|
|
11624
12096
|
if (journal.state !== "planned") throw makeHttpError(409, `Update transaction is already ${journal.state}.`);
|
|
11625
12097
|
piUpdateInProgress = true;
|
|
11626
12098
|
let lock = null;
|
|
@@ -12124,7 +12596,7 @@ async function safeRpcResponse(tab, command, timeoutMs = REQUEST_TIMEOUT_MS) {
|
|
|
12124
12596
|
if (command?.type === "get_messages" && Array.isArray(response?.data?.messages)) {
|
|
12125
12597
|
response.data = {
|
|
12126
12598
|
...response.data,
|
|
12127
|
-
messages: filterSessionSummaryTranscriptMessages(tab.thinkingStreamRecovery.applyToMessages(response.data.messages)),
|
|
12599
|
+
messages: filterSessionSummaryTranscriptMessages(filterIntercomTranscriptMessages(tab.thinkingStreamRecovery.applyToMessages(response.data.messages))),
|
|
12128
12600
|
};
|
|
12129
12601
|
}
|
|
12130
12602
|
return response;
|
|
@@ -12204,10 +12676,20 @@ async function sendWebuiHelperCommand(tab, action, payload = {}, timeoutMs = WEB
|
|
|
12204
12676
|
|
|
12205
12677
|
function requireResourceScope(value) {
|
|
12206
12678
|
const scope = String(value || "session").trim().toLowerCase();
|
|
12207
|
-
if (scope !== "session" && scope !== "global") throw makeHttpError(400, "Resource scope must be session or
|
|
12679
|
+
if (scope !== "session" && scope !== "global" && scope !== "model") throw makeHttpError(400, "Resource scope must be session, global, or model");
|
|
12208
12680
|
return scope;
|
|
12209
12681
|
}
|
|
12210
12682
|
|
|
12683
|
+
function requireResourceModelIdentity(source, models) {
|
|
12684
|
+
const provider = String(source?.provider || "").trim();
|
|
12685
|
+
const modelId = String(source?.modelId || "").trim();
|
|
12686
|
+
if (!provider || !modelId) throw makeHttpError(400, "Model resource scope requires an exact provider and modelId");
|
|
12687
|
+
if (!(models || []).some((model) => model?.provider === provider && model?.id === modelId)) {
|
|
12688
|
+
throw makeHttpError(400, `Unknown authenticated model for resource profile: ${provider}/${modelId}`);
|
|
12689
|
+
}
|
|
12690
|
+
return { provider, modelId };
|
|
12691
|
+
}
|
|
12692
|
+
|
|
12211
12693
|
function selectedResourceNames(body, enabledKey, disabledKey, resources, label) {
|
|
12212
12694
|
const allNames = new Set((resources || []).map((resource) => String(resource.name || "").trim()).filter(Boolean));
|
|
12213
12695
|
if (Array.isArray(body?.[enabledKey])) {
|
|
@@ -12220,12 +12702,6 @@ function selectedResourceNames(body, enabledKey, disabledKey, resources, label)
|
|
|
12220
12702
|
throw makeHttpError(400, `${label} update requires ${enabledKey} or ${disabledKey}`);
|
|
12221
12703
|
}
|
|
12222
12704
|
|
|
12223
|
-
function preserveUnavailableGlobalNames(selectedNames, resources, previousNames) {
|
|
12224
|
-
if (!Array.isArray(previousNames)) return selectedNames;
|
|
12225
|
-
const available = new Set((resources || []).map((resource) => resource.name));
|
|
12226
|
-
return [...new Set([...selectedNames, ...previousNames.filter((name) => !available.has(name))])];
|
|
12227
|
-
}
|
|
12228
|
-
|
|
12229
12705
|
function globalResourcePayload(key, resources, configuredNames) {
|
|
12230
12706
|
const configured = Array.isArray(configuredNames);
|
|
12231
12707
|
const enabled = new Set(configured ? configuredNames : resources.filter((resource) => resource.enabled !== false).map((resource) => resource.name));
|
|
@@ -12236,10 +12712,73 @@ function globalResourcePayload(key, resources, configuredNames) {
|
|
|
12236
12712
|
};
|
|
12237
12713
|
}
|
|
12238
12714
|
|
|
12239
|
-
async function
|
|
12715
|
+
async function modelResourcePayload(tab, key, resources, identity, models) {
|
|
12716
|
+
const selectionKey = key === "tools" ? "enabledTools" : "enabledSkills";
|
|
12717
|
+
const defaults = (await readWebuiSettings()).resourceDefaults;
|
|
12718
|
+
const profile = exactModelProfile(defaults, identity.provider, identity.modelId);
|
|
12719
|
+
const configuredNames = profile?.[key]?.[selectionKey];
|
|
12720
|
+
const configured = Array.isArray(configuredNames);
|
|
12721
|
+
const resolved = resolveResourceSelection(defaults, key, identity.provider, identity.modelId, null);
|
|
12722
|
+
const enabledNames = configured
|
|
12723
|
+
? configuredNames
|
|
12724
|
+
: resolved.names !== null
|
|
12725
|
+
? resolved.names
|
|
12726
|
+
: resources.filter((resource) => resource.enabled !== false).map((resource) => resource.name);
|
|
12727
|
+
const enabled = new Set(enabledNames);
|
|
12728
|
+
return {
|
|
12729
|
+
scope: "model",
|
|
12730
|
+
provider: identity.provider,
|
|
12731
|
+
modelId: identity.modelId,
|
|
12732
|
+
configured,
|
|
12733
|
+
source: configured ? "model" : resolved.source,
|
|
12734
|
+
models: (models || []).map((model) => ({ provider: model.provider, id: model.id, name: model.name || model.id })),
|
|
12735
|
+
[key]: resources.map((resource) => ({ ...resource, enabled: enabled.has(resource.name) })),
|
|
12736
|
+
};
|
|
12737
|
+
}
|
|
12738
|
+
|
|
12739
|
+
async function recomputeResourceRuntime(tab) {
|
|
12740
|
+
return sendWebuiHelperCommand(tab, "resources-recompute");
|
|
12741
|
+
}
|
|
12742
|
+
|
|
12743
|
+
async function setModelResourceProfile(tab, key, resources, body) {
|
|
12744
|
+
const selectionKey = key === "tools" ? "enabledTools" : "enabledSkills";
|
|
12745
|
+
const label = key === "tools" ? "Tool" : "Skill";
|
|
12746
|
+
const enabledKey = `enabled${label}s`;
|
|
12747
|
+
const disabledKey = `disabled${label}s`;
|
|
12748
|
+
const models = await availableGitWorkflowModels(tab);
|
|
12749
|
+
const identity = requireResourceModelIdentity(body, models);
|
|
12750
|
+
if (body?.inherit === true) {
|
|
12751
|
+
await updateWebuiSettings((current) => ({
|
|
12752
|
+
resourceDefaults: {
|
|
12753
|
+
modelProfiles: setExactModelProfile(current.resourceDefaults, identity.provider, identity.modelId, key, null),
|
|
12754
|
+
},
|
|
12755
|
+
}));
|
|
12756
|
+
const refreshed = await recomputeResourceRuntime(tab);
|
|
12757
|
+
return modelResourcePayload(tab, key, refreshed?.[key]?.[key] || resources, identity, models);
|
|
12758
|
+
}
|
|
12759
|
+
const selectedNames = selectedResourceNames(body, enabledKey, disabledKey, resources, label);
|
|
12760
|
+
await updateWebuiSettings((current) => {
|
|
12761
|
+
const previousNames = exactModelProfile(current.resourceDefaults, identity.provider, identity.modelId)?.[key]?.[selectionKey];
|
|
12762
|
+
const enabledNames = preserveUnavailableResourceNames(previousNames, resources.map((resource) => resource.name), selectedNames);
|
|
12763
|
+
return {
|
|
12764
|
+
resourceDefaults: {
|
|
12765
|
+
modelProfiles: setExactModelProfile(current.resourceDefaults, identity.provider, identity.modelId, key, enabledNames),
|
|
12766
|
+
},
|
|
12767
|
+
};
|
|
12768
|
+
});
|
|
12769
|
+
const refreshed = await recomputeResourceRuntime(tab);
|
|
12770
|
+
return modelResourcePayload(tab, key, refreshed?.[key]?.[key] || resources, identity, models);
|
|
12771
|
+
}
|
|
12772
|
+
|
|
12773
|
+
async function getToolConfigData(tab, requestedScope = "session", searchParams) {
|
|
12240
12774
|
const scope = requireResourceScope(requestedScope);
|
|
12241
12775
|
const runtime = await sendWebuiHelperCommand(tab, "tools-state");
|
|
12242
12776
|
if (scope === "session") return { ...runtime, scope };
|
|
12777
|
+
if (scope === "model") {
|
|
12778
|
+
const models = await availableGitWorkflowModels(tab);
|
|
12779
|
+
const identity = requireResourceModelIdentity({ provider: searchParams?.get("provider"), modelId: searchParams?.get("modelId") }, models);
|
|
12780
|
+
return modelResourcePayload(tab, "tools", runtime.tools || [], identity, models);
|
|
12781
|
+
}
|
|
12243
12782
|
const defaults = (await readWebuiSettings()).resourceDefaults.tools.enabledTools;
|
|
12244
12783
|
return globalResourcePayload("tools", runtime.tools || [], defaults);
|
|
12245
12784
|
}
|
|
@@ -12438,26 +12977,44 @@ async function setToolConfigData(tab, body) {
|
|
|
12438
12977
|
const scope = requireResourceScope(body?.scope);
|
|
12439
12978
|
if (scope === "session") {
|
|
12440
12979
|
return {
|
|
12441
|
-
...(await sendWebuiHelperCommand(tab, "tools-set",
|
|
12442
|
-
|
|
12443
|
-
|
|
12444
|
-
|
|
12980
|
+
...(await sendWebuiHelperCommand(tab, "tools-set", body?.inherit === true
|
|
12981
|
+
? { mode: "inherit" }
|
|
12982
|
+
: {
|
|
12983
|
+
enabledTools: Array.isArray(body.enabledTools) ? body.enabledTools : undefined,
|
|
12984
|
+
disabledTools: Array.isArray(body.disabledTools) ? body.disabledTools : undefined,
|
|
12985
|
+
})),
|
|
12445
12986
|
scope,
|
|
12446
12987
|
};
|
|
12447
12988
|
}
|
|
12448
12989
|
|
|
12449
12990
|
const runtime = await sendWebuiHelperCommand(tab, "tools-state");
|
|
12450
|
-
|
|
12991
|
+
if (scope === "model") return setModelResourceProfile(tab, "tools", runtime.tools || [], body);
|
|
12992
|
+
if (body?.inherit === true) {
|
|
12993
|
+
await updateWebuiSettings(() => ({ resourceDefaults: { tools: { enabledTools: null } } }));
|
|
12994
|
+
const refreshed = await recomputeResourceRuntime(tab);
|
|
12995
|
+
return globalResourcePayload("tools", refreshed?.tools?.tools || runtime.tools || [], null);
|
|
12996
|
+
}
|
|
12451
12997
|
const selectedTools = selectedResourceNames(body, "enabledTools", "disabledTools", runtime.tools, "Tool");
|
|
12452
|
-
const
|
|
12453
|
-
|
|
12454
|
-
|
|
12998
|
+
const settings = await updateWebuiSettings((current) => ({
|
|
12999
|
+
resourceDefaults: {
|
|
13000
|
+
tools: {
|
|
13001
|
+
enabledTools: preserveUnavailableResourceNames(current.resourceDefaults?.tools?.enabledTools, (runtime.tools || []).map((tool) => tool.name), selectedTools),
|
|
13002
|
+
},
|
|
13003
|
+
},
|
|
13004
|
+
}));
|
|
13005
|
+
const refreshed = await recomputeResourceRuntime(tab);
|
|
13006
|
+
return globalResourcePayload("tools", refreshed?.tools?.tools || runtime.tools || [], settings.resourceDefaults.tools.enabledTools);
|
|
12455
13007
|
}
|
|
12456
13008
|
|
|
12457
|
-
async function getSkillConfigData(tab, requestedScope = "session") {
|
|
13009
|
+
async function getSkillConfigData(tab, requestedScope = "session", searchParams) {
|
|
12458
13010
|
const scope = requireResourceScope(requestedScope);
|
|
12459
13011
|
const runtime = await getSkillConfigDataFromRuntime(tab);
|
|
12460
13012
|
if (scope === "session") return { ...runtime, scope };
|
|
13013
|
+
if (scope === "model") {
|
|
13014
|
+
const models = await availableGitWorkflowModels(tab);
|
|
13015
|
+
const identity = requireResourceModelIdentity({ provider: searchParams?.get("provider"), modelId: searchParams?.get("modelId") }, models);
|
|
13016
|
+
return modelResourcePayload(tab, "skills", runtime.skills || [], identity, models);
|
|
13017
|
+
}
|
|
12461
13018
|
const defaults = (await readWebuiSettings()).resourceDefaults.skills.enabledSkills;
|
|
12462
13019
|
return globalResourcePayload("skills", runtime.skills || [], defaults);
|
|
12463
13020
|
}
|
|
@@ -12470,20 +13027,33 @@ async function setSkillConfigData(tab, body) {
|
|
|
12470
13027
|
const scope = requireResourceScope(body?.scope);
|
|
12471
13028
|
if (scope === "session") {
|
|
12472
13029
|
return {
|
|
12473
|
-
...(await sendWebuiHelperCommand(tab, "skills-set",
|
|
12474
|
-
|
|
12475
|
-
|
|
12476
|
-
|
|
13030
|
+
...(await sendWebuiHelperCommand(tab, "skills-set", body?.inherit === true
|
|
13031
|
+
? { mode: "inherit" }
|
|
13032
|
+
: {
|
|
13033
|
+
enabledSkills: Array.isArray(body.enabledSkills) ? body.enabledSkills : undefined,
|
|
13034
|
+
disabledSkills: Array.isArray(body.disabledSkills) ? body.disabledSkills : undefined,
|
|
13035
|
+
})),
|
|
12477
13036
|
scope,
|
|
12478
13037
|
};
|
|
12479
13038
|
}
|
|
12480
13039
|
|
|
12481
13040
|
const runtime = await getSkillConfigDataFromRuntime(tab);
|
|
12482
|
-
|
|
13041
|
+
if (scope === "model") return setModelResourceProfile(tab, "skills", runtime.skills || [], body);
|
|
13042
|
+
if (body?.inherit === true) {
|
|
13043
|
+
await updateWebuiSettings(() => ({ resourceDefaults: { skills: { enabledSkills: null } } }));
|
|
13044
|
+
const refreshed = await recomputeResourceRuntime(tab);
|
|
13045
|
+
return globalResourcePayload("skills", refreshed?.skills?.skills || runtime.skills || [], null);
|
|
13046
|
+
}
|
|
12483
13047
|
const selectedSkills = selectedResourceNames(body, "enabledSkills", "disabledSkills", runtime.skills, "Skill");
|
|
12484
|
-
const
|
|
12485
|
-
|
|
12486
|
-
|
|
13048
|
+
const settings = await updateWebuiSettings((current) => ({
|
|
13049
|
+
resourceDefaults: {
|
|
13050
|
+
skills: {
|
|
13051
|
+
enabledSkills: preserveUnavailableResourceNames(current.resourceDefaults?.skills?.enabledSkills, (runtime.skills || []).map((skill) => skill.name), selectedSkills),
|
|
13052
|
+
},
|
|
13053
|
+
},
|
|
13054
|
+
}));
|
|
13055
|
+
const refreshed = await recomputeResourceRuntime(tab);
|
|
13056
|
+
return globalResourcePayload("skills", refreshed?.skills?.skills || runtime.skills || [], settings.resourceDefaults.skills.enabledSkills);
|
|
12487
13057
|
}
|
|
12488
13058
|
|
|
12489
13059
|
function settingsManagerForTab(tab) {
|
|
@@ -13216,6 +13786,10 @@ function fileViewerLanguage(filePath) {
|
|
|
13216
13786
|
return "text";
|
|
13217
13787
|
}
|
|
13218
13788
|
|
|
13789
|
+
function fileViewerImageMimeType(filePath) {
|
|
13790
|
+
return FILE_VIEWER_IMAGE_MIME_TYPES_BY_EXTENSION[path.extname(String(filePath || "")).toLowerCase()] || "";
|
|
13791
|
+
}
|
|
13792
|
+
|
|
13219
13793
|
function fileTreeEntryType(dirent, info) {
|
|
13220
13794
|
if (info?.isDirectory?.() || dirent?.isDirectory?.()) return "directory";
|
|
13221
13795
|
if (info?.isFile?.() || dirent?.isFile?.()) return "file";
|
|
@@ -13276,12 +13850,13 @@ async function getFileTreeData(tab, requestedPath = "") {
|
|
|
13276
13850
|
statFileTreeEntries(resolved.targetPath, dirents, resolved.root, resolved.realRoot),
|
|
13277
13851
|
readWorkspaceGitStatusIndex(resolved.root),
|
|
13278
13852
|
]);
|
|
13853
|
+
const gitIgnored = await readWorkspaceGitIgnoredPaths(resolved.root, listed.entries, gitStatus?.root);
|
|
13279
13854
|
return {
|
|
13280
13855
|
root: resolved.root,
|
|
13281
13856
|
displayRoot: displayPath(resolved.root),
|
|
13282
13857
|
path: resolved.relative,
|
|
13283
13858
|
displayPath: displayPath(resolved.targetPath),
|
|
13284
|
-
entries: withFileTreeGitStatus(listed.entries, resolved.root, gitStatus),
|
|
13859
|
+
entries: withFileTreeGitIgnored(withFileTreeGitStatus(listed.entries, resolved.root, gitStatus), resolved.root, gitIgnored),
|
|
13285
13860
|
gitStatus: fileTreeGitStatusPayload(resolved.root, gitStatus),
|
|
13286
13861
|
truncated: listed.truncated,
|
|
13287
13862
|
total: listed.total,
|
|
@@ -13367,11 +13942,12 @@ async function getFileSearchData(tab, rawQuery = "") {
|
|
|
13367
13942
|
}
|
|
13368
13943
|
}
|
|
13369
13944
|
truncated = queue.length > 0 || scanned >= FILE_SEARCH_MAX_SCANNED || entries.length >= FILE_SEARCH_MAX_RESULTS;
|
|
13945
|
+
const gitIgnored = await readWorkspaceGitIgnoredPaths(resolved.root, entries, gitStatus?.root);
|
|
13370
13946
|
return {
|
|
13371
13947
|
root: resolved.root,
|
|
13372
13948
|
displayRoot: displayPath(resolved.root),
|
|
13373
13949
|
query,
|
|
13374
|
-
entries: withFileTreeGitStatus(entries, resolved.root, gitStatus),
|
|
13950
|
+
entries: withFileTreeGitIgnored(withFileTreeGitStatus(entries, resolved.root, gitStatus), resolved.root, gitIgnored),
|
|
13375
13951
|
gitStatus: fileTreeGitStatusPayload(resolved.root, gitStatus),
|
|
13376
13952
|
truncated,
|
|
13377
13953
|
total: entries.length,
|
|
@@ -13382,7 +13958,7 @@ async function getFileSearchData(tab, rawQuery = "") {
|
|
|
13382
13958
|
}
|
|
13383
13959
|
|
|
13384
13960
|
function assertTextFileBuffer(buffer) {
|
|
13385
|
-
if (isLikelyBinaryBuffer(buffer)) throw makeHttpError(415, "File appears to be binary; only text files can be opened in WebUI");
|
|
13961
|
+
if (isLikelyBinaryBuffer(buffer)) throw makeHttpError(415, "File appears to be binary; only text files and supported raster images can be opened in WebUI");
|
|
13386
13962
|
}
|
|
13387
13963
|
|
|
13388
13964
|
async function getFileContentData(tab, requestedPath = "") {
|
|
@@ -13390,17 +13966,21 @@ async function getFileContentData(tab, requestedPath = "") {
|
|
|
13390
13966
|
if (!resolved.info?.isFile()) throw makeHttpError(400, "Path is not a regular file");
|
|
13391
13967
|
if (resolved.info.size > FILE_VIEWER_MAX_BYTES) throw makeHttpError(413, `File is too large to open in WebUI (limit ${formatBytes(FILE_VIEWER_MAX_BYTES)})`);
|
|
13392
13968
|
const buffer = await readFile(resolved.targetPath);
|
|
13393
|
-
|
|
13394
|
-
|
|
13969
|
+
const extension = path.extname(resolved.targetPath).toLowerCase();
|
|
13970
|
+
const imageMimeType = fileViewerImageMimeType(resolved.targetPath);
|
|
13971
|
+
const shared = {
|
|
13395
13972
|
root: resolved.root,
|
|
13396
13973
|
path: resolved.relative,
|
|
13397
13974
|
name: path.basename(resolved.targetPath),
|
|
13398
|
-
content: buffer.toString("utf8"),
|
|
13399
13975
|
size: resolved.info.size,
|
|
13400
13976
|
mtimeMs: resolved.info.mtimeMs,
|
|
13401
|
-
extension
|
|
13402
|
-
language: fileViewerLanguage(resolved.targetPath),
|
|
13977
|
+
extension,
|
|
13403
13978
|
};
|
|
13979
|
+
if (imageMimeType) {
|
|
13980
|
+
return { ...shared, kind: "image", mimeType: imageMimeType, data: buffer.toString("base64") };
|
|
13981
|
+
}
|
|
13982
|
+
assertTextFileBuffer(buffer);
|
|
13983
|
+
return { ...shared, kind: "text", content: buffer.toString("utf8"), language: fileViewerLanguage(resolved.targetPath) };
|
|
13404
13984
|
}
|
|
13405
13985
|
|
|
13406
13986
|
function aurReviewReportPathSegments(value = "") {
|
|
@@ -13731,6 +14311,45 @@ async function getSessionSelectorData(tab, scope = "current") {
|
|
|
13731
14311
|
};
|
|
13732
14312
|
}
|
|
13733
14313
|
|
|
14314
|
+
function requestedIntercomConversationId(url) {
|
|
14315
|
+
const value = String(url.searchParams.get("conversation") || "").trim();
|
|
14316
|
+
if (!value) return "";
|
|
14317
|
+
if (!/^conv_[A-Za-z0-9_-]{24}$/.test(value)) throw makeHttpError(400, "conversation must be an opaque Intercom conversation ID");
|
|
14318
|
+
return value;
|
|
14319
|
+
}
|
|
14320
|
+
|
|
14321
|
+
async function getIntercomConversationsData(tab, conversationId = "") {
|
|
14322
|
+
const state = await currentSessionState(tab).catch(() => tab.lastState || {});
|
|
14323
|
+
const sessionFile = sessionFileFromState(state) || tabRestorableSessionFile(tab);
|
|
14324
|
+
const projectionOptions = {
|
|
14325
|
+
conversationId,
|
|
14326
|
+
localSessionId: normalizedRestoreString(state.sessionId, 240) || "local",
|
|
14327
|
+
localName: normalizedRestoreString(state.sessionName, 160) || tab.title || "Local agent",
|
|
14328
|
+
};
|
|
14329
|
+
if (options.noSession || !sessionFile) {
|
|
14330
|
+
const empty = projectIntercomConversations([], projectionOptions);
|
|
14331
|
+
if (conversationId) throw makeHttpError(404, "Intercom conversation not found");
|
|
14332
|
+
return empty;
|
|
14333
|
+
}
|
|
14334
|
+
|
|
14335
|
+
requireAllowedSessionPath(sessionFile);
|
|
14336
|
+
const sessionInfo = await stat(sessionFile).catch(() => null);
|
|
14337
|
+
if (!sessionInfo?.isFile()) throw makeHttpError(404, "Persisted session is unavailable");
|
|
14338
|
+
|
|
14339
|
+
let manager;
|
|
14340
|
+
try {
|
|
14341
|
+
manager = SessionManager.open(sessionFile, configuredSessionDir(), tab.cwd);
|
|
14342
|
+
} catch {
|
|
14343
|
+
throw makeHttpError(400, "Persisted session could not be read");
|
|
14344
|
+
}
|
|
14345
|
+
const data = projectIntercomConversations(manager.getBranch(), {
|
|
14346
|
+
...projectionOptions,
|
|
14347
|
+
localSessionId: normalizedRestoreString(manager.getSessionId(), 240) || projectionOptions.localSessionId,
|
|
14348
|
+
});
|
|
14349
|
+
if (conversationId && !data.conversation) throw makeHttpError(404, "Intercom conversation not found");
|
|
14350
|
+
return data;
|
|
14351
|
+
}
|
|
14352
|
+
|
|
13734
14353
|
function extractSessionTextContent(content) {
|
|
13735
14354
|
if (typeof content === "string") return content;
|
|
13736
14355
|
if (!Array.isArray(content)) return "";
|
|
@@ -13859,6 +14478,7 @@ function sessionTreeEntryLabel(entry) {
|
|
|
13859
14478
|
function sessionTreeEntryText(entry) {
|
|
13860
14479
|
if (!entry || typeof entry !== "object") return "";
|
|
13861
14480
|
if (entry.type === "message") return extractSessionTextContent(entry.message?.content);
|
|
14481
|
+
if (entry.type === "custom_message" && entry.customType === "intercom_message") return "Intercom message";
|
|
13862
14482
|
if (entry.type === "custom_message") return extractSessionTextContent(entry.content);
|
|
13863
14483
|
if (entry.type === "branch_summary") return entry.summary || "branch summary";
|
|
13864
14484
|
if (entry.type === "compaction") return entry.summary || "compaction summary";
|
|
@@ -15305,11 +15925,14 @@ const server = createServer(async (req, res) => {
|
|
|
15305
15925
|
}
|
|
15306
15926
|
|
|
15307
15927
|
if (url.pathname === "/api/subagents/output" && req.method === "GET") {
|
|
15308
|
-
const tab = getRequestedTab(req, url);
|
|
15309
15928
|
const runId = normalizeWebuiSubagentText(url.searchParams.get("run"), 160);
|
|
15310
15929
|
const agentId = normalizeWebuiSubagentText(url.searchParams.get("agent"), 240);
|
|
15311
15930
|
if (!runId || !agentId) throw makeHttpError(400, "run and agent query parameters are required");
|
|
15312
|
-
|
|
15931
|
+
const groupId = normalizeWebuiSubagentText(url.searchParams.get("group"), 240);
|
|
15932
|
+
const data = groupId
|
|
15933
|
+
? await canonicalWebuiSubagentOutputData(groupId, runId, agentId)
|
|
15934
|
+
: await webuiSubagentOutputData(getRequestedTab(req, url), runId, agentId);
|
|
15935
|
+
sendJson(res, 200, { ok: true, data });
|
|
15313
15936
|
return;
|
|
15314
15937
|
}
|
|
15315
15938
|
|
|
@@ -15330,20 +15953,26 @@ const server = createServer(async (req, res) => {
|
|
|
15330
15953
|
if (url.pathname === "/api/subagents/cancel" && req.method === "POST") {
|
|
15331
15954
|
requireLocalhostRoute(req, url.pathname);
|
|
15332
15955
|
const body = await readJsonBody(req);
|
|
15956
|
+
if (body.group) {
|
|
15957
|
+
sendJson(res, 200, { ok: true, data: await canonicalWebuiSubagentAction("cancel", body) });
|
|
15958
|
+
return;
|
|
15959
|
+
}
|
|
15333
15960
|
const tab = getRequestedTab(req, url, body);
|
|
15334
|
-
|
|
15335
|
-
|
|
15336
|
-
reason: body.reason,
|
|
15337
|
-
note: body.note,
|
|
15338
|
-
}) });
|
|
15961
|
+
const runId = rejectUnsupportedWebuiSubagentRun(tab, body.runId);
|
|
15962
|
+
sendJson(res, 200, { ok: true, data: await sendWebuiHelperCommand(tab, "subagent-cancel", { runId, reason: body.reason, note: body.note }) });
|
|
15339
15963
|
return;
|
|
15340
15964
|
}
|
|
15341
15965
|
|
|
15342
15966
|
if (url.pathname === "/api/subagents/dismiss" && req.method === "POST") {
|
|
15343
15967
|
requireLocalhostRoute(req, url.pathname);
|
|
15344
15968
|
const body = await readJsonBody(req);
|
|
15969
|
+
if (body.group) {
|
|
15970
|
+
sendJson(res, 200, { ok: true, data: await canonicalWebuiSubagentAction("dismiss", body) });
|
|
15971
|
+
return;
|
|
15972
|
+
}
|
|
15345
15973
|
const tab = getRequestedTab(req, url, body);
|
|
15346
|
-
|
|
15974
|
+
const runId = rejectUnsupportedWebuiSubagentRun(tab, body.runId);
|
|
15975
|
+
sendJson(res, 200, { ok: true, data: await sendWebuiHelperCommand(tab, "subagent-dismiss", { runId }) });
|
|
15347
15976
|
return;
|
|
15348
15977
|
}
|
|
15349
15978
|
|
|
@@ -15917,6 +16546,13 @@ const server = createServer(async (req, res) => {
|
|
|
15917
16546
|
return;
|
|
15918
16547
|
}
|
|
15919
16548
|
|
|
16549
|
+
if (url.pathname === "/api/intercom/conversations" && req.method === "GET") {
|
|
16550
|
+
if (!requestedTabId(req, url)) throw makeHttpError(400, "tab is required");
|
|
16551
|
+
const tab = getRequestedTab(req, url);
|
|
16552
|
+
sendJson(res, 200, { ok: true, data: await getIntercomConversationsData(tab, requestedIntercomConversationId(url)) }, { "cache-control": "private, no-store" });
|
|
16553
|
+
return;
|
|
16554
|
+
}
|
|
16555
|
+
|
|
15920
16556
|
if (url.pathname === "/api/sessions" && req.method === "GET") {
|
|
15921
16557
|
const tab = getRequestedTab(req, url);
|
|
15922
16558
|
sendJson(res, 200, { ok: true, data: await getSessionSelectorData(tab, url.searchParams.get("scope") || "current") });
|
|
@@ -16121,7 +16757,7 @@ const server = createServer(async (req, res) => {
|
|
|
16121
16757
|
|
|
16122
16758
|
if (url.pathname === "/api/tools" && req.method === "GET") {
|
|
16123
16759
|
const tab = getRequestedTab(req, url);
|
|
16124
|
-
sendJson(res, 200, { ok: true, data: await getToolConfigData(tab, url.searchParams.get("scope")) });
|
|
16760
|
+
sendJson(res, 200, { ok: true, data: await getToolConfigData(tab, url.searchParams.get("scope"), url.searchParams) });
|
|
16125
16761
|
return;
|
|
16126
16762
|
}
|
|
16127
16763
|
|
|
@@ -16135,7 +16771,7 @@ const server = createServer(async (req, res) => {
|
|
|
16135
16771
|
|
|
16136
16772
|
if (url.pathname === "/api/skills" && req.method === "GET") {
|
|
16137
16773
|
const tab = getRequestedTab(req, url);
|
|
16138
|
-
sendJson(res, 200, { ok: true, data: await getSkillConfigData(tab, url.searchParams.get("scope")) });
|
|
16774
|
+
sendJson(res, 200, { ok: true, data: await getSkillConfigData(tab, url.searchParams.get("scope"), url.searchParams) });
|
|
16139
16775
|
return;
|
|
16140
16776
|
}
|
|
16141
16777
|
|