@firstpick/pi-package-webui 0.7.2 → 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 +38 -25
- package/bin/pi-webui.mjs +469 -106
- package/index.ts +10 -1
- package/lib/git-live-watcher.mjs +135 -0
- package/lib/git-message-artifacts.mjs +103 -0
- package/lib/git-workflow-preferences.mjs +10 -3
- package/lib/process-tree.mjs +3 -1
- package/lib/webui-output-mode.mjs +97 -0
- package/package.json +7 -6
- package/public/app.js +1170 -97
- package/public/fast-output-live.mjs +179 -0
- package/public/index.html +31 -5
- package/public/service-worker.js +2 -1
- package/public/styles.css +474 -12
- package/tests/app-runner-windows-conpty-harness.test.mjs +140 -0
- package/tests/danger-button-contrast-static.test.mjs +32 -0
- 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 +59 -0
- package/tests/fixtures/fast-mode-output-events.mjs +50 -0
- package/tests/footer-middle-truncation.test.mjs +118 -0
- package/tests/git-live-watcher.test.mjs +93 -0
- package/tests/git-message-artifacts.test.mjs +59 -0
- package/tests/git-panel-live-updates-static.test.mjs +54 -0
- package/tests/git-panel-render-stability-static.test.mjs +1 -1
- package/tests/git-workflow-preferences.test.mjs +8 -2
- package/tests/guided-git-message-reliability-static.test.mjs +38 -0
- package/tests/http-endpoints-harness.test.mjs +61 -5
- package/tests/image-payload-hardening-harness.test.mjs +115 -0
- package/tests/mobile-static.test.mjs +79 -20
- package/tests/pi-footer-calibration-static.test.mjs +55 -0
- package/tests/remote-auth-settings-harness.test.mjs +1 -1
- package/tests/runtime-error-visibility.test.mjs +63 -0
- package/tests/side-panel-context-menu-static.test.mjs +74 -0
- package/tests/webui-output-mode.test.mjs +73 -0
package/index.ts
CHANGED
|
@@ -33,6 +33,7 @@ type StartWebuiOptions = WebuiAddress & {
|
|
|
33
33
|
open: boolean;
|
|
34
34
|
noSession: boolean;
|
|
35
35
|
remoteAuth: boolean;
|
|
36
|
+
outputMode?: "normal" | "compact-v1";
|
|
36
37
|
name?: string;
|
|
37
38
|
piArgs: string[];
|
|
38
39
|
};
|
|
@@ -87,6 +88,13 @@ function parseStartWebuiArgs(args: string): StartWebuiOptions {
|
|
|
87
88
|
options.noSession = true;
|
|
88
89
|
continue;
|
|
89
90
|
}
|
|
91
|
+
if (token === "--output-mode") {
|
|
92
|
+
const outputMode = takeValue(tokens, i, token);
|
|
93
|
+
if (outputMode !== "normal" && outputMode !== "compact-v1") throw new Error("--output-mode must be normal or compact-v1");
|
|
94
|
+
options.outputMode = outputMode;
|
|
95
|
+
i++;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
90
98
|
if (token === "--remote-auth") {
|
|
91
99
|
options.remoteAuth = true;
|
|
92
100
|
continue;
|
|
@@ -450,6 +458,7 @@ async function startWebui(options: StartWebuiOptions, ctx: ExtensionCommandConte
|
|
|
450
458
|
const args = [webuiBin, "--host", options.host, "--port", String(options.port), "--cwd", ctx.cwd];
|
|
451
459
|
if (options.noSession) args.push("--no-session");
|
|
452
460
|
if (options.remoteAuth) args.push("--remote-auth");
|
|
461
|
+
if (options.outputMode) args.push("--output-mode", options.outputMode);
|
|
453
462
|
if (options.name) args.push("--name", options.name);
|
|
454
463
|
if (options.piArgs.length > 0) args.push("--", ...options.piArgs);
|
|
455
464
|
|
|
@@ -696,7 +705,7 @@ function formatWebuiStatus(result: WebuiStatusFetchResult, requestedDetailed: bo
|
|
|
696
705
|
|
|
697
706
|
function usage(): string {
|
|
698
707
|
return [
|
|
699
|
-
"Usage: /webui-start [port] [--port N] [--no-open] [--no-session] [--remote-auth] [--name NAME] [-- --model provider/model]",
|
|
708
|
+
"Usage: /webui-start [port] [--port N] [--no-open] [--no-session] [--remote-auth] [--output-mode normal|compact-v1] [--name NAME] [-- --model provider/model]",
|
|
700
709
|
"Starts the Pi Web UI companion server for the current cwd, prints the localhost URL, and opens it in your default browser.",
|
|
701
710
|
].join("\n");
|
|
702
711
|
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { watch as watchDirectory } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
export const GIT_LIVE_WATCH_DEBOUNCE_MS = 250;
|
|
5
|
+
export const GIT_LIVE_WATCH_MAX_WAIT_MS = 2_000;
|
|
6
|
+
|
|
7
|
+
function cleanTabId(value) {
|
|
8
|
+
return String(value || "").trim();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function canonicalRoot(value) {
|
|
12
|
+
const root = String(value || "").trim();
|
|
13
|
+
return root ? path.resolve(root) : "";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function createGitLiveWatcher({
|
|
17
|
+
watch = watchDirectory,
|
|
18
|
+
debounceMs = GIT_LIVE_WATCH_DEBOUNCE_MS,
|
|
19
|
+
maxWaitMs = GIT_LIVE_WATCH_MAX_WAIT_MS,
|
|
20
|
+
onChange = () => {},
|
|
21
|
+
onError = () => {},
|
|
22
|
+
} = {}) {
|
|
23
|
+
const roots = new Map();
|
|
24
|
+
const tabRoots = new Map();
|
|
25
|
+
const delayMs = Math.max(0, Number(debounceMs) || 0);
|
|
26
|
+
const maximumWaitMs = Math.max(0, Number(maxWaitMs) || GIT_LIVE_WATCH_MAX_WAIT_MS);
|
|
27
|
+
|
|
28
|
+
function reportError(root, error) {
|
|
29
|
+
try {
|
|
30
|
+
onError({ root, error });
|
|
31
|
+
} catch {
|
|
32
|
+
// Watcher diagnostics must never crash the Web UI server.
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function closeRoot(root, { clearTabs = true } = {}) {
|
|
37
|
+
const record = roots.get(root);
|
|
38
|
+
if (!record) return false;
|
|
39
|
+
roots.delete(root);
|
|
40
|
+
if (record.timer) clearTimeout(record.timer);
|
|
41
|
+
try {
|
|
42
|
+
record.watcher?.close();
|
|
43
|
+
} catch {
|
|
44
|
+
// The watcher may already be closed after an error.
|
|
45
|
+
}
|
|
46
|
+
if (clearTabs) {
|
|
47
|
+
for (const tabId of record.tabs) {
|
|
48
|
+
if (tabRoots.get(tabId) === root) tabRoots.delete(tabId);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function failRoot(root, error) {
|
|
55
|
+
if (!roots.has(root)) return;
|
|
56
|
+
closeRoot(root);
|
|
57
|
+
reportError(root, error);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function scheduleChange(root) {
|
|
61
|
+
const record = roots.get(root);
|
|
62
|
+
if (!record) return;
|
|
63
|
+
if (record.timer) clearTimeout(record.timer);
|
|
64
|
+
const now = Date.now();
|
|
65
|
+
if (!record.burstStartedAt) record.burstStartedAt = now;
|
|
66
|
+
const remainingMs = Math.max(0, maximumWaitMs - (now - record.burstStartedAt));
|
|
67
|
+
record.timer = setTimeout(() => {
|
|
68
|
+
const current = roots.get(root);
|
|
69
|
+
if (!current || current !== record) return;
|
|
70
|
+
current.timer = null;
|
|
71
|
+
current.burstStartedAt = 0;
|
|
72
|
+
try {
|
|
73
|
+
onChange({ root, changedAt: new Date().toISOString() });
|
|
74
|
+
} catch (error) {
|
|
75
|
+
reportError(root, error);
|
|
76
|
+
}
|
|
77
|
+
}, Math.min(delayMs, remainingMs));
|
|
78
|
+
record.timer.unref?.();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function ensureRoot(root) {
|
|
82
|
+
const existing = roots.get(root);
|
|
83
|
+
if (existing) return existing;
|
|
84
|
+
const record = { root, tabs: new Set(), watcher: null, timer: null, burstStartedAt: 0 };
|
|
85
|
+
roots.set(root, record);
|
|
86
|
+
try {
|
|
87
|
+
record.watcher = watch(root, { recursive: true, persistent: false }, () => scheduleChange(root));
|
|
88
|
+
record.watcher.on?.("error", (error) => failRoot(root, error));
|
|
89
|
+
return record;
|
|
90
|
+
} catch (error) {
|
|
91
|
+
roots.delete(root);
|
|
92
|
+
reportError(root, error);
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function unsubscribe(tabIdValue) {
|
|
98
|
+
const tabId = cleanTabId(tabIdValue);
|
|
99
|
+
const root = tabRoots.get(tabId);
|
|
100
|
+
if (!root) return false;
|
|
101
|
+
tabRoots.delete(tabId);
|
|
102
|
+
const record = roots.get(root);
|
|
103
|
+
if (!record) return true;
|
|
104
|
+
record.tabs.delete(tabId);
|
|
105
|
+
if (!record.tabs.size) closeRoot(root, { clearTabs: false });
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function subscribe(tabIdValue, rootValue) {
|
|
110
|
+
const tabId = cleanTabId(tabIdValue);
|
|
111
|
+
const root = canonicalRoot(rootValue);
|
|
112
|
+
if (!tabId || !root) return false;
|
|
113
|
+
const previousRoot = tabRoots.get(tabId);
|
|
114
|
+
if (previousRoot === root && roots.has(root)) return true;
|
|
115
|
+
if (previousRoot) unsubscribe(tabId);
|
|
116
|
+
const record = ensureRoot(root);
|
|
117
|
+
if (!record) return false;
|
|
118
|
+
record.tabs.add(tabId);
|
|
119
|
+
tabRoots.set(tabId, root);
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function closeAll() {
|
|
124
|
+
for (const root of [...roots.keys()]) closeRoot(root);
|
|
125
|
+
tabRoots.clear();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
subscribe,
|
|
130
|
+
unsubscribe,
|
|
131
|
+
closeAll,
|
|
132
|
+
watchedRootCount: () => roots.size,
|
|
133
|
+
subscribedRootForTab: (tabId) => tabRoots.get(cleanTabId(tabId)) || "",
|
|
134
|
+
};
|
|
135
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { readFile, stat } from "node:fs/promises";
|
|
3
|
+
|
|
4
|
+
const DEFAULT_STABLE_READ_ATTEMPTS = 3;
|
|
5
|
+
const DEFAULT_STABLE_READ_DELAY_MS = 20;
|
|
6
|
+
|
|
7
|
+
function delay(ms) {
|
|
8
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function artifactIdentity(stats, bytes) {
|
|
12
|
+
return {
|
|
13
|
+
size: Number(stats.size),
|
|
14
|
+
mtimeNs: String(stats.mtimeNs),
|
|
15
|
+
ctimeNs: String(stats.ctimeNs),
|
|
16
|
+
ino: String(stats.ino),
|
|
17
|
+
sha256: createHash("sha256").update(bytes).digest("hex"),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function sameStatIdentity(left, right) {
|
|
22
|
+
return left.size === right.size
|
|
23
|
+
&& left.mtimeNs === right.mtimeNs
|
|
24
|
+
&& left.ctimeNs === right.ctimeNs
|
|
25
|
+
&& left.ino === right.ino;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function sameGitMessageArtifactVersion(left, right) {
|
|
29
|
+
if (!left?.exists || !right?.exists) return left?.exists === right?.exists;
|
|
30
|
+
return left.size === right.size
|
|
31
|
+
&& left.mtimeNs === right.mtimeNs
|
|
32
|
+
&& left.ctimeNs === right.ctimeNs
|
|
33
|
+
&& left.ino === right.ino
|
|
34
|
+
&& left.sha256 === right.sha256;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function readStableGitMessageArtifact(filePath, {
|
|
38
|
+
attempts = DEFAULT_STABLE_READ_ATTEMPTS,
|
|
39
|
+
retryDelayMs = DEFAULT_STABLE_READ_DELAY_MS,
|
|
40
|
+
} = {}) {
|
|
41
|
+
let lastError;
|
|
42
|
+
for (let attempt = 0; attempt < Math.max(1, attempts); attempt += 1) {
|
|
43
|
+
try {
|
|
44
|
+
const before = await stat(filePath, { bigint: true });
|
|
45
|
+
if (!before.isFile()) return { exists: false, path: filePath, reason: "not-file" };
|
|
46
|
+
const bytes = await readFile(filePath);
|
|
47
|
+
const after = await stat(filePath, { bigint: true });
|
|
48
|
+
const beforeIdentity = artifactIdentity(before, bytes);
|
|
49
|
+
const afterIdentity = artifactIdentity(after, bytes);
|
|
50
|
+
if (sameStatIdentity(beforeIdentity, afterIdentity)) {
|
|
51
|
+
return {
|
|
52
|
+
exists: true,
|
|
53
|
+
path: filePath,
|
|
54
|
+
text: bytes.toString("utf8"),
|
|
55
|
+
...afterIdentity,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
lastError = new Error(`Git message artifact changed while it was being read: ${filePath}`);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (error?.code === "ENOENT" || error?.code === "ENOTDIR") {
|
|
61
|
+
return { exists: false, path: filePath, reason: "missing" };
|
|
62
|
+
}
|
|
63
|
+
lastError = error;
|
|
64
|
+
}
|
|
65
|
+
if (attempt + 1 < attempts && retryDelayMs > 0) await delay(retryDelayMs);
|
|
66
|
+
}
|
|
67
|
+
throw lastError || new Error(`Could not read a stable Git message artifact: ${filePath}`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function readStableGitMessageArtifactPair({ shortPath, longPath }, options) {
|
|
71
|
+
const [short, long] = await Promise.all([
|
|
72
|
+
readStableGitMessageArtifact(shortPath, options),
|
|
73
|
+
readStableGitMessageArtifact(longPath, options),
|
|
74
|
+
]);
|
|
75
|
+
return { short, long };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function sameGitMessageArtifactPair(left, right) {
|
|
79
|
+
return sameGitMessageArtifactVersion(left?.short, right?.short)
|
|
80
|
+
&& sameGitMessageArtifactVersion(left?.long, right?.long);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function gitMessageArtifactPairReadiness(baseline, current) {
|
|
84
|
+
const missing = [];
|
|
85
|
+
const unchanged = [];
|
|
86
|
+
const empty = [];
|
|
87
|
+
for (const key of ["short", "long"]) {
|
|
88
|
+
const before = baseline?.[key] || { exists: false };
|
|
89
|
+
const after = current?.[key] || { exists: false };
|
|
90
|
+
if (!after.exists) {
|
|
91
|
+
missing.push(key);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (sameGitMessageArtifactVersion(before, after)) unchanged.push(key);
|
|
95
|
+
if (!String(after.text || "").trim()) empty.push(key);
|
|
96
|
+
}
|
|
97
|
+
const ready = missing.length === 0 && unchanged.length === 0 && empty.length === 0;
|
|
98
|
+
let reason = "Generated commit message files are ready.";
|
|
99
|
+
if (missing.length) reason = `Waiting for generated ${missing.join(" and ")} message file${missing.length === 1 ? "" : "s"}.`;
|
|
100
|
+
else if (unchanged.length) reason = `Waiting for ${unchanged.join(" and ")} message file${unchanged.length === 1 ? "" : "s"} to be refreshed for this generation.`;
|
|
101
|
+
else if (empty.length) reason = `Waiting for generated ${empty.join(" and ")} message file${empty.length === 1 ? "" : "s"} to contain a message.`;
|
|
102
|
+
return { ready, reason, missing, unchanged, empty };
|
|
103
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
import { normalizeOutputMode, OUTPUT_MODE_NORMAL } from "./webui-output-mode.mjs";
|
|
4
5
|
|
|
5
6
|
export const GIT_WORKFLOW_SETUP_VERSION = 1;
|
|
6
7
|
export const GIT_WORKFLOW_THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
@@ -22,7 +23,7 @@ export function supportedGitWorkflowThinkingLevels(model) {
|
|
|
22
23
|
});
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
const WEBUI_SETTINGS_VERSION =
|
|
26
|
+
const WEBUI_SETTINGS_VERSION = 4;
|
|
26
27
|
const WEBUI_SETTINGS_FILE_ENV = "PI_WEBUI_SETTINGS_FILE";
|
|
27
28
|
|
|
28
29
|
function cleanBoundedString(value, maxLength = 512) {
|
|
@@ -139,14 +140,20 @@ export function normalizeWebuiSettings(value) {
|
|
|
139
140
|
return {
|
|
140
141
|
version: WEBUI_SETTINGS_VERSION,
|
|
141
142
|
remoteAuthEnabled: value?.remoteAuthEnabled === true,
|
|
143
|
+
outputModeDefault: normalizeOutputMode(value?.outputModeDefault, OUTPUT_MODE_NORMAL),
|
|
142
144
|
gitWorkflow: normalizeGitWorkflowPreferences(value?.gitWorkflow),
|
|
143
145
|
resourceDefaults: normalizeResourceDefaults(value?.resourceDefaults),
|
|
144
146
|
};
|
|
145
147
|
}
|
|
146
148
|
|
|
147
|
-
export async function readWebuiSettings(storageFile = webuiSettingsFile()) {
|
|
149
|
+
export async function readWebuiSettings(storageFile = webuiSettingsFile(), { reportInvalidOutputMode = false } = {}) {
|
|
148
150
|
try {
|
|
149
|
-
|
|
151
|
+
const raw = JSON.parse(await readFile(storageFile, "utf8"));
|
|
152
|
+
const normalized = normalizeWebuiSettings(raw);
|
|
153
|
+
if (reportInvalidOutputMode && raw?.outputModeDefault !== undefined && normalized.outputModeDefault !== raw.outputModeDefault) {
|
|
154
|
+
console.warn(`Invalid persisted Web UI output mode ${JSON.stringify(raw.outputModeDefault)} in ${storageFile}; using ${OUTPUT_MODE_NORMAL}.`);
|
|
155
|
+
}
|
|
156
|
+
return normalized;
|
|
150
157
|
} catch (error) {
|
|
151
158
|
if (error?.code === "ENOENT") return normalizeWebuiSettings({});
|
|
152
159
|
throw new Error(`Cannot read Pi Web UI settings at ${storageFile}: ${error instanceof Error ? error.message : String(error)}`);
|
package/lib/process-tree.mjs
CHANGED
|
@@ -24,7 +24,9 @@ function windowsTaskkillCommand() {
|
|
|
24
24
|
* used instead of child.kill(), which only terminates the direct child.
|
|
25
25
|
*/
|
|
26
26
|
export function terminateProcessTree(target, signal = "SIGTERM") {
|
|
27
|
-
|
|
27
|
+
const hasExited = (target?.exitCode !== undefined && target.exitCode !== null)
|
|
28
|
+
|| (target?.signalCode !== undefined && target.signalCode !== null);
|
|
29
|
+
if (!target || hasExited) return false;
|
|
28
30
|
const pid = Number(target.pid);
|
|
29
31
|
|
|
30
32
|
if (process.platform === "win32" && Number.isInteger(pid) && pid > 0) {
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export const OUTPUT_MODE_NORMAL = "normal";
|
|
2
|
+
export const OUTPUT_MODE_COMPACT_V1 = "compact-v1";
|
|
3
|
+
export const OUTPUT_MODE_PROTOCOL_VERSION = 1;
|
|
4
|
+
|
|
5
|
+
const OUTPUT_MODES = new Set([OUTPUT_MODE_NORMAL, OUTPUT_MODE_COMPACT_V1]);
|
|
6
|
+
const COMPACT_MESSAGE_UPDATE_TYPES = new Set(["text_delta", "thinking_delta", "toolcall_delta"]);
|
|
7
|
+
const COMPACT_SELF_CONTAINED_END_TYPES = new Set(["text_end", "thinking_end", "toolcall_end", "tool_call_end"]);
|
|
8
|
+
const SEMANTIC_BARRIER_TYPES = new Set([
|
|
9
|
+
"message_end",
|
|
10
|
+
"tool_execution_end",
|
|
11
|
+
"agent_end",
|
|
12
|
+
"agent_settled",
|
|
13
|
+
"compaction_end",
|
|
14
|
+
"pi_process_exit",
|
|
15
|
+
"pi_process_error",
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
function cleanOutputMode(value) {
|
|
19
|
+
return typeof value === "string" ? value.trim() : "";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function hasProtocolVersionOne(value) {
|
|
23
|
+
return value === OUTPUT_MODE_PROTOCOL_VERSION || value === String(OUTPUT_MODE_PROTOCOL_VERSION);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function directSelfContainedEnd(update) {
|
|
27
|
+
if (!COMPACT_SELF_CONTAINED_END_TYPES.has(update?.type)) return false;
|
|
28
|
+
return Object.prototype.hasOwnProperty.call(update, "content")
|
|
29
|
+
|| Object.prototype.hasOwnProperty.call(update, "toolCall")
|
|
30
|
+
|| Object.prototype.hasOwnProperty.call(update, "error")
|
|
31
|
+
|| Object.prototype.hasOwnProperty.call(update, "isError");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function compactAssistantMessageUpdate(event) {
|
|
35
|
+
if (!event || typeof event !== "object" || event.type !== "message_update") return null;
|
|
36
|
+
const update = event.assistantMessageEvent;
|
|
37
|
+
if (!update || typeof update !== "object" || Array.isArray(update)) return null;
|
|
38
|
+
|
|
39
|
+
const hasDirectDelta = COMPACT_MESSAGE_UPDATE_TYPES.has(update.type) && typeof update.delta === "string";
|
|
40
|
+
if (!hasDirectDelta && !directSelfContainedEnd(update)) return null;
|
|
41
|
+
|
|
42
|
+
const compactUpdate = { ...update };
|
|
43
|
+
delete compactUpdate.partial;
|
|
44
|
+
const compactEvent = { ...event, assistantMessageEvent: compactUpdate };
|
|
45
|
+
delete compactEvent.message;
|
|
46
|
+
return compactEvent;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function normalizeOutputMode(value, fallback = OUTPUT_MODE_NORMAL) {
|
|
50
|
+
const normalizedFallback = OUTPUT_MODES.has(cleanOutputMode(fallback)) ? cleanOutputMode(fallback) : OUTPUT_MODE_NORMAL;
|
|
51
|
+
const normalizedValue = cleanOutputMode(value);
|
|
52
|
+
return OUTPUT_MODES.has(normalizedValue) ? normalizedValue : normalizedFallback;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function resolveOutputModeDefault({ cliMode, envMode, persistedMode } = {}) {
|
|
56
|
+
const cli = cleanOutputMode(cliMode);
|
|
57
|
+
if (OUTPUT_MODES.has(cli)) return { mode: cli, source: "cli" };
|
|
58
|
+
const env = cleanOutputMode(envMode);
|
|
59
|
+
if (OUTPUT_MODES.has(env)) return { mode: env, source: "env" };
|
|
60
|
+
const persisted = cleanOutputMode(persistedMode);
|
|
61
|
+
if (OUTPUT_MODES.has(persisted)) return { mode: persisted, source: "persisted" };
|
|
62
|
+
return { mode: OUTPUT_MODE_NORMAL, source: "normal" };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function negotiateOutputMode({ requestedMode, protocolVersion, serverDefault } = {}) {
|
|
66
|
+
const protocolAccepted = hasProtocolVersionOne(protocolVersion);
|
|
67
|
+
const requested = cleanOutputMode(requestedMode);
|
|
68
|
+
const validRequest = protocolAccepted && ["auto", OUTPUT_MODE_NORMAL, OUTPUT_MODE_COMPACT_V1].includes(requested);
|
|
69
|
+
if (!validRequest) {
|
|
70
|
+
return {
|
|
71
|
+
requestedMode: OUTPUT_MODE_NORMAL,
|
|
72
|
+
protocolVersion: 0,
|
|
73
|
+
activeMode: OUTPUT_MODE_NORMAL,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
requestedMode: requested,
|
|
79
|
+
protocolVersion: OUTPUT_MODE_PROTOCOL_VERSION,
|
|
80
|
+
activeMode: requested === "auto" ? normalizeOutputMode(serverDefault) : requested,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function browserOutputEvent(event, { outputMode = OUTPUT_MODE_NORMAL } = {}) {
|
|
85
|
+
if (normalizeOutputMode(outputMode) !== OUTPUT_MODE_COMPACT_V1) return event;
|
|
86
|
+
if (event?.type === "tool_execution_update") return undefined;
|
|
87
|
+
return compactAssistantMessageUpdate(event) || event;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function encodeBrowserSseEvent(event, { outputMode = OUTPUT_MODE_NORMAL } = {}) {
|
|
91
|
+
const browserEvent = browserOutputEvent(event, { outputMode });
|
|
92
|
+
return browserEvent === undefined ? undefined : JSON.stringify(browserEvent);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function isOutputModeSemanticBarrier(event) {
|
|
96
|
+
return SEMANTIC_BARRIER_TYPES.has(event?.type);
|
|
97
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firstpick/pi-package-webui",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.4",
|
|
4
4
|
"description": "Pi Web UI companion package with a local browser UI CLI plus /webui-start and /webui-status commands.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"homepage": "https://github.com/Firstp1ck/
|
|
6
|
+
"homepage": "https://github.com/Firstp1ck/pi-coding-agent-forge/tree/main/pi-package-webui#readme",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/Firstp1ck/
|
|
9
|
+
"url": "git+https://github.com/Firstp1ck/pi-coding-agent-forge.git",
|
|
10
10
|
"directory": "pi-package-webui"
|
|
11
11
|
},
|
|
12
12
|
"type": "module",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"extension"
|
|
21
21
|
],
|
|
22
22
|
"pi": {
|
|
23
|
-
"image": "https://raw.githubusercontent.com/Firstp1ck/
|
|
23
|
+
"image": "https://raw.githubusercontent.com/Firstp1ck/pi-coding-agent-forge/main/pi-package-webui/images/Webui_MainWindow_v0.4.8.png",
|
|
24
24
|
"extensions": [
|
|
25
25
|
"./index.ts",
|
|
26
26
|
"node_modules/@firstpick/pi-extension-bang-command-autocomplete/index.ts",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"pi-webui": "./bin/pi-webui.mjs"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
|
-
"check": "node --check public/app.js && node --check public/voice-conversation.mjs && node --check public/aur-review-payload.mjs && node --check public/guided-git-command-state.mjs && node --check public/guided-git-review-state.mjs && node --check bin/pi-webui.mjs && node --check webui-rpc-helper.mjs && node --check lib/trust-boundaries.mjs && node --check lib/native-command-adapter.mjs && node --check lib/session-actions.mjs && node --check lib/auth-actions.mjs && node --check lib/temp-artifacts.mjs && node tests/run-all.mjs",
|
|
54
|
+
"check": "node --check public/app.js && node --check public/fast-output-live.mjs && node --check public/voice-conversation.mjs && node --check public/aur-review-payload.mjs && node --check public/guided-git-command-state.mjs && node --check public/guided-git-review-state.mjs && node --check bin/pi-webui.mjs && node --check webui-rpc-helper.mjs && node --check lib/git-live-watcher.mjs && node --check lib/git-message-artifacts.mjs && node --check lib/trust-boundaries.mjs && node --check lib/native-command-adapter.mjs && node --check lib/session-actions.mjs && node --check lib/auth-actions.mjs && node --check lib/temp-artifacts.mjs && node tests/run-all.mjs",
|
|
55
55
|
"test": "node tests/run-all.mjs"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
@@ -75,7 +75,8 @@
|
|
|
75
75
|
"@firstpick/pi-extension-workflows": "^0.1.4",
|
|
76
76
|
"@firstpick/pi-package-remote-webui": "^0.1.6",
|
|
77
77
|
"@firstpick/pi-prompts-git-pr": "^0.1.4",
|
|
78
|
-
"@firstpick/pi-themes-bundle": "^0.1.4"
|
|
78
|
+
"@firstpick/pi-themes-bundle": "^0.1.4",
|
|
79
|
+
"node-pty": "^1.1.0"
|
|
79
80
|
},
|
|
80
81
|
"files": [
|
|
81
82
|
"index.ts",
|