pi-web-ui 0.114.0 → 0.114.1
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/CHANGELOG.md +28 -0
- package/README.md +187 -187
- package/README.zh-CN.md +227 -227
- package/README.zh-TW.md +227 -227
- package/bin/device-hub-cli.mjs +577 -577
- package/bin/frp-manager.mjs +1573 -1573
- package/bin/pi-device-hub.mjs +9 -9
- package/bin/pi-web-ui.mjs +4081 -4073
- package/deploy/nginx-subpath.conf +100 -100
- package/deploy/pi-web-ui.service +36 -36
- package/dist/server/agent-service.js +131 -55
- package/dist/server/attachments.js +51 -5
- package/dist/server/canvas/canvas-agent-tool.js +3 -3
- package/dist/server/canvas/canvas-cards.js +1 -1
- package/dist/server/canvas/canvas-orchestrator.js +3 -3
- package/dist/server/canvas/canvas-scheduled-task.js +45 -0
- package/dist/server/canvas/canvas-validation.js +1 -1
- package/dist/server/client-state.js +6 -2
- package/dist/server/compaction-instructions.js +8 -8
- package/dist/server/device-center/connector.js +33 -14
- package/dist/server/device-center/desktop-page.js +228 -228
- package/dist/server/device-center/hub-page.js +64 -64
- package/dist/server/device-center/hub.js +2 -1
- package/dist/server/device-center/local-hub.js +92 -0
- package/dist/server/device-center/local.js +60 -7
- package/dist/server/device-center/native-desktop/macos.js +190 -190
- package/dist/server/device-center/native-desktop/windows.js +116 -116
- package/dist/server/device-center/path-portal.js +1 -1
- package/dist/server/device-center/relay.js +45 -8
- package/dist/server/dispatch-domain-handlers.js +1 -0
- package/dist/server/dsh/dsh-agent-service.js +5 -1
- package/dist/server/dsh/runtime/cordis.yml +1 -1
- package/dist/server/dsh/runtime/custom-prompt.mjs +33 -33
- package/dist/server/dsh/runtime/goal-rpc.mjs +1309 -1309
- package/dist/server/dsh/runtime/launcher.mjs +235 -235
- package/dist/server/dsh/runtime/override.patch.yml +89 -89
- package/dist/server/dsh/runtime/runtime-root.mjs +405 -405
- package/dist/server/engine-probe.js +36 -6
- package/dist/server/eval-tool.js +135 -135
- package/dist/server/global-loader.js +40 -2
- package/dist/server/index.js +56 -32
- package/dist/server/patch-bash-process.js +125 -0
- package/dist/server/patch-tool.js +9 -9
- package/dist/server/patch-turn-end-boundary.js +3 -3
- package/dist/server/persona-chain.js +8 -8
- package/dist/server/plugins.js +26 -2
- package/dist/server/preset-fields.js +7 -0
- package/dist/server/preset-share.js +1 -0
- package/dist/server/prompt-templates.js +106 -0
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/remote-ssh-service.js +39 -39
- package/dist/server/resolve-global-sdk.js +2 -0
- package/dist/server/schedule-agent-tool.js +39 -21
- package/dist/server/scheduler-tasks.js +45 -9
- package/dist/server/scm-commitmsg.js +10 -10
- package/dist/server/settings-service.js +6 -0
- package/dist/server/setup-page.js +620 -620
- package/dist/server/text-quote.js +9 -0
- package/dist/server/tool-manager.js +2 -1
- package/dist/server/universal/drivers/claude-code.js +5 -0
- package/dist/server/universal/drivers/codex.js +336 -0
- package/dist/server/universal/index.js +1 -0
- package/dist/server/universal/universal-attachments.js +24 -1
- package/dist/server/universal/universal-session.js +23 -0
- package/dist/server/vision-bridge.js +18 -18
- package/docs/device-center.md +148 -142
- package/docs/device-desktop.md +48 -48
- package/docs/dsh-engine.md +493 -493
- package/extensions/webui.ts +335 -335
- package/package.json +2 -2
- package/plugin-sdk/README.md +174 -174
- package/plugin-sdk/client-utils.mjs +279 -279
- package/plugin-sdk/import-check.mjs +210 -210
- package/plugin-sdk/index.d.ts +698 -698
- package/plugin-sdk/index.mjs +696 -696
- package/plugin-sdk/package.json +13 -13
- package/plugin-sdk/ssh-host-trust.mjs +225 -225
- package/plugins/catalog.json +10 -0
- package/themes/aetheris.css +501 -501
- package/themes/ayu-light.css +116 -116
- package/themes/bases/flow-base.css +1357 -1357
- package/themes/bases/obsidian-base.css +895 -895
- package/themes/bases/statusbar-flat-base.css +112 -112
- package/themes/bases/zhujian-base.css +688 -688
- package/themes/bases/zhupi-base.css +660 -660
- package/themes/catppuccin-latte.css +119 -119
- package/themes/catppuccin.css +116 -116
- package/themes/claude-code-dark.css +147 -147
- package/themes/codex.css +114 -114
- package/themes/cyberpunk.css +50 -50
- package/themes/dark-teal.css +264 -264
- package/themes/dazzle.css +38 -38
- package/themes/everforest-light.css +115 -115
- package/themes/flow-light.css +164 -164
- package/themes/flow.css +161 -161
- package/themes/geist.css +114 -114
- package/themes/gruvbox-light.css +115 -115
- package/themes/kanagawa-lotus.css +115 -115
- package/themes/md-preview.css +24 -24
- package/themes/mist.css +166 -166
- package/themes/nord.css +107 -107
- package/themes/one-dark.css +106 -106
- package/themes/paper.css +174 -174
- package/themes/rose-pine-dawn.css +114 -114
- package/themes/sakura.css +166 -166
- package/themes/solarized-light.css +114 -114
- package/themes/tokyo-night.css +115 -115
- package/themes/translucent.css +85 -85
- package/themes/transparent.css +116 -116
- package/themes/vs-code-dark.css +147 -147
- package/themes/wallpaper-flow.css +382 -382
- package/themes/wallpaper-obsidian.css +74 -74
- package/themes/white.css +164 -164
- package/themes/zhujian-dark.css +115 -115
- package/themes/zhujian.css +114 -114
- package/themes/zhupi-dark.css +115 -115
- package/themes/zhupi.css +114 -114
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/BgTasksModal-BcXJ20RO.js +1 -0
- package/web/dist/assets/BgTasksModal-DjQmiKnE.js +1 -0
- package/web/dist/assets/{CanvasStudio-BEJZE5BI.js → CanvasStudio-PI9pid0Y.js} +3 -3
- package/web/dist/assets/{CanvasStudio-CgUNHqos.js → CanvasStudio-nf5-HxLM.js} +3 -3
- package/web/dist/assets/DeviceCenter-CYttJw2a.js +3 -0
- package/web/dist/assets/DeviceCenter-DPe4sz74.js +3 -0
- package/web/dist/assets/DeviceGroups-D2rogxEN.js +1 -0
- package/web/dist/assets/Dropdown-ZLS04O8p.js +1 -0
- package/web/dist/assets/FilePreview-C9Ut4Lq6.js +2 -0
- package/web/dist/assets/FilePreview-CvK3ZzX5.js +2 -0
- package/web/dist/assets/GlobalSearchModal-C5e-OCw2.js +1 -0
- package/web/dist/assets/GlobalSearchModal-H7pFK2UC.js +1 -0
- package/web/dist/assets/GroupConversation-C2wNM0dQ.js +1 -0
- package/web/dist/assets/GroupConversation-ChN3TWQK.js +1 -0
- package/web/dist/assets/ModelConfigModal-DDZccDYt.js +2 -0
- package/web/dist/assets/PiSetupModal-DHbqfx8T.js +1 -0
- package/web/dist/assets/ProviderOAuthControls-C-MK36Dk.js +1 -0
- package/web/dist/assets/SCMPanel-buTGziDB.js +2 -0
- package/web/dist/assets/SCMPanel-kx-SCL2s.js +2 -0
- package/web/dist/assets/SettingsModal-BsUF8jqr.js +20 -0
- package/web/dist/assets/SettingsModal-D357Ky7P.js +20 -0
- package/web/dist/assets/{TerminalPanel-DL20uKgU.js → TerminalPanel-BBuM_Sez.js} +2 -2
- package/web/dist/assets/{TerminalPanel-D6cPRFei.js → TerminalPanel-D6x6xz8Q.js} +2 -2
- package/web/dist/assets/TuiOverlayModal-CdbGV3Za.js +1 -0
- package/web/dist/assets/TuiOverlayModal-d6x9u25n.js +1 -0
- package/web/dist/assets/app-globals-DcyO0UPi.js +1 -0
- package/web/dist/assets/{desktop-DPyTy4M3.js → desktop-YguLbrX1.js} +1 -1
- package/web/dist/assets/fi-DaSO0Q-m.js +325 -0
- package/web/dist/assets/index-BPvpea8t.js +85 -0
- package/web/dist/assets/index-D6u8xH0o.js +85 -0
- package/web/dist/assets/index-DDZMv6LO.css +1 -0
- package/web/dist/assets/{plugin-host-CqA4yW6w.js → plugin-host-BRBg6zmQ.js} +1 -1
- package/web/dist/assets/theme-DDl-Oy1b.js +1 -0
- package/web/dist/index.html +37 -36
- package/web/dist/sw.js +179 -179
- package/web/public/sw.js +179 -179
- package/dist/gh-comment-781.md +0 -5
- package/dist/server/device-center/local-page.js +0 -17
- package/dist/server/device-center/smoke-preview.js +0 -3
- package/dist/server/durable/durable-capabilities.js +0 -11
- package/dist/server/markers/builtins/services.js +0 -123
- package/dist/server/markers/builtins/todo.js +0 -189
- package/dist/server/markers-list-tool.js +0 -34
- package/dist/server/orchestrator.js +0 -109
- package/dist/server/system-prompt-soul.js +0 -41
- package/dist/server/univer-service.js +0 -448
- package/dist/server/universal/drivers/dsh-driver.js +0 -379
- package/dist/test-artifact.md +0 -9
- package/dist/test-preview-modal.md +0 -11
- package/dist/test-report.html +0 -20
- package/web/dist/assets/BgTasksModal-CS7UNzcw.js +0 -1
- package/web/dist/assets/BgTasksModal-Dk-tp78W.js +0 -1
- package/web/dist/assets/DeviceCenter-C8_CbxQ3.js +0 -3
- package/web/dist/assets/DeviceCenter-CVblvhNX.js +0 -3
- package/web/dist/assets/Dropdown-Oug0DDte.js +0 -1
- package/web/dist/assets/FilePreview-CvdX6nr6.js +0 -2
- package/web/dist/assets/FilePreview-kCZhfBAF.js +0 -2
- package/web/dist/assets/GlobalSearchModal-BLH63yYP.js +0 -1
- package/web/dist/assets/GlobalSearchModal-DAkvlvp6.js +0 -1
- package/web/dist/assets/GroupConversation-Cgo4xbpa.js +0 -1
- package/web/dist/assets/GroupConversation-DZ71jEi8.js +0 -1
- package/web/dist/assets/ModelConfigModal-BpWdFdQC.js +0 -2
- package/web/dist/assets/PiSetupModal-mkWPSxMj.js +0 -1
- package/web/dist/assets/ProviderOAuthControls-VK_jqXYS.js +0 -1
- package/web/dist/assets/SCMPanel-BP1TUT-V.js +0 -2
- package/web/dist/assets/SCMPanel-BscPm9kf.js +0 -2
- package/web/dist/assets/SettingsModal-C8UgMjVM.js +0 -20
- package/web/dist/assets/SettingsModal-VynB7jNb.js +0 -20
- package/web/dist/assets/TuiOverlayModal-Dst3BmT8.js +0 -1
- package/web/dist/assets/TuiOverlayModal-NCkpNtTp.js +0 -1
- package/web/dist/assets/UniversalPathPicker-CfQFc_c3.js +0 -1
- package/web/dist/assets/UniversalPathPicker-DwxwNcFw.js +0 -1
- package/web/dist/assets/app-globals-CnO6KlEM.js +0 -325
- package/web/dist/assets/index-CPgAH5q7.js +0 -83
- package/web/dist/assets/index-Cje8iugL.js +0 -83
- package/web/dist/assets/index-DnKeiDbj.css +0 -1
- package/web/dist/assets/theme-BqdAjEjF.js +0 -1
|
@@ -159,6 +159,15 @@ export function splitQuotedPrompt(value) {
|
|
|
159
159
|
attachments.push({ type: "conversation", name: title });
|
|
160
160
|
return "";
|
|
161
161
|
});
|
|
162
|
+
text = text.replace(/(?:^|\n\n)?<canvas-ref id="([^"]*)" title="([^"]*)">[\s\S]*?<\/canvas-ref>/g, (_, id, title) => {
|
|
163
|
+
const decode = (s) => s
|
|
164
|
+
.replace(/"/g, '"')
|
|
165
|
+
.replace(/</g, "<")
|
|
166
|
+
.replace(/>/g, ">")
|
|
167
|
+
.replace(/&/g, "&");
|
|
168
|
+
attachments.push({ type: "canvas", path: decode(id), name: decode(title) || decode(id) });
|
|
169
|
+
return "";
|
|
170
|
+
});
|
|
162
171
|
text = text.replace(/(?:^|\n\n)?<vision-bridge>[\s\S]*?<\/vision-bridge>/g, () => {
|
|
163
172
|
attachments.push({ type: "vision-bridge", name: "视觉转写" });
|
|
164
173
|
return "";
|
|
@@ -124,7 +124,8 @@ export const AGENT_TOOL_CATALOG = [
|
|
|
124
124
|
group: "subagent",
|
|
125
125
|
defaultOn: true,
|
|
126
126
|
dshVisible: false,
|
|
127
|
-
descKey: "
|
|
127
|
+
descKey: "communicateEnabledDesc",
|
|
128
|
+
offHintKey: "communicateOffHint",
|
|
128
129
|
},
|
|
129
130
|
{
|
|
130
131
|
name: EDIT_SOFT_TOOL_NAME,
|
|
@@ -19,6 +19,7 @@ import { delimiter, isAbsolute, join } from "node:path";
|
|
|
19
19
|
import { BaseAgentDriver } from "../driver-base.js";
|
|
20
20
|
import { resolveProviderCredential, listCustomModelsFromConfig, isModelProtocolSupportedByEngine, } from "../../model-resolver.js";
|
|
21
21
|
import { discoverDiskSkills } from "../../skill-discovery.js";
|
|
22
|
+
import { formatUnavailableCanvasReference } from "../universal-attachments.js";
|
|
22
23
|
/**
|
|
23
24
|
* 探测可执行文件路径:若传入了绝对路径或在系统 PATH 中找到则直接使用;
|
|
24
25
|
* 若未找到(尤其在 macOS launchd/GUI 等精简 PATH 环境),则自动扫描系统及版本管理器的常见安装目录。
|
|
@@ -197,6 +198,10 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
|
|
|
197
198
|
if (attachments && attachments.length > 0) {
|
|
198
199
|
const notes = [];
|
|
199
200
|
for (const att of attachments) {
|
|
201
|
+
if (att.mode === "canvas") {
|
|
202
|
+
notes.push(formatUnavailableCanvasReference(att));
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
200
205
|
if (att.path) {
|
|
201
206
|
const lineRange = att.lines ? ` (行 ${att.lines.start}-${att.lines.end})` : "";
|
|
202
207
|
notes.push(`[文件引用: ${att.path}${lineRange}]`);
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { execFile, spawn } from "node:child_process";
|
|
2
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { homedir, tmpdir } from "node:os";
|
|
4
|
+
import { delimiter, join } from "node:path";
|
|
5
|
+
import { StringDecoder } from "node:string_decoder";
|
|
6
|
+
import { BaseAgentDriver } from "../driver-base.js";
|
|
7
|
+
import { probeGlobalPackage } from "../../global-loader.js";
|
|
8
|
+
import { killPidTree } from "../../process-utils.js";
|
|
9
|
+
import { formatUnavailableCanvasReference } from "../universal-attachments.js";
|
|
10
|
+
/** Resolve the npm launcher before PATH so Windows does not require a command shell. */
|
|
11
|
+
function codexCommand(executablePath) {
|
|
12
|
+
if (executablePath)
|
|
13
|
+
return { command: executablePath, args: [] };
|
|
14
|
+
const pkg = probeGlobalPackage("@openai/codex");
|
|
15
|
+
if (pkg.packagePath) {
|
|
16
|
+
const launcher = join(pkg.packagePath, "bin", "codex.js");
|
|
17
|
+
if (existsSync(launcher))
|
|
18
|
+
return { command: process.execPath, args: [launcher] };
|
|
19
|
+
}
|
|
20
|
+
for (const dir of (process.env.PATH ?? "").split(delimiter)) {
|
|
21
|
+
const exe = join(dir, process.platform === "win32" ? "codex.exe" : "codex");
|
|
22
|
+
if (existsSync(exe))
|
|
23
|
+
return { command: exe, args: [] };
|
|
24
|
+
}
|
|
25
|
+
return { command: "codex", args: [] };
|
|
26
|
+
}
|
|
27
|
+
export async function probeCodex(executablePath) {
|
|
28
|
+
const cmd = codexCommand(executablePath);
|
|
29
|
+
return new Promise((resolve) => {
|
|
30
|
+
execFile(cmd.command, [...cmd.args, "--version"], { timeout: 4000, windowsHide: true, maxBuffer: 8192 }, (err, stdout) => {
|
|
31
|
+
resolve(err
|
|
32
|
+
? { available: false, error: err.message }
|
|
33
|
+
: { available: true, version: stdout.trim().replace(/^codex(?:-cli)?\s+/i, "") });
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export class CodexDriver extends BaseAgentDriver {
|
|
38
|
+
options;
|
|
39
|
+
id = "codex";
|
|
40
|
+
name = "Codex";
|
|
41
|
+
capabilities = {
|
|
42
|
+
supportsTreeFork: false,
|
|
43
|
+
supportsHistoryEdit: false,
|
|
44
|
+
supportsToolPromptOverride: false,
|
|
45
|
+
supportsModelSwitch: true,
|
|
46
|
+
supportsThinkingLevels: true,
|
|
47
|
+
supportsAskUser: false,
|
|
48
|
+
supportsSubagents: true,
|
|
49
|
+
};
|
|
50
|
+
sessionId = "";
|
|
51
|
+
model = "default";
|
|
52
|
+
effort = "medium";
|
|
53
|
+
active;
|
|
54
|
+
disposed = false;
|
|
55
|
+
constructor(cwd, options = {}) {
|
|
56
|
+
super(cwd);
|
|
57
|
+
this.options = options;
|
|
58
|
+
}
|
|
59
|
+
async createSession() {
|
|
60
|
+
this.sessionId = "";
|
|
61
|
+
return "";
|
|
62
|
+
}
|
|
63
|
+
async resumeSession(sessionId) {
|
|
64
|
+
this.sessionId = sessionId;
|
|
65
|
+
}
|
|
66
|
+
getActiveSessionId() {
|
|
67
|
+
return this.sessionId;
|
|
68
|
+
}
|
|
69
|
+
async setModel(modelId) {
|
|
70
|
+
this.model = modelId.replace(/^codex\//, "");
|
|
71
|
+
}
|
|
72
|
+
setThinkingLevel(level) {
|
|
73
|
+
this.effort = this.getSupportedThinkingLevels().includes(level) ? level : "medium";
|
|
74
|
+
}
|
|
75
|
+
getSupportedThinkingLevels() {
|
|
76
|
+
return ["minimal", "low", "medium", "high", "xhigh"];
|
|
77
|
+
}
|
|
78
|
+
async listModels() {
|
|
79
|
+
const rows = [{ id: "default", name: "Codex config default" }];
|
|
80
|
+
try {
|
|
81
|
+
const cache = JSON.parse(readFileSync(join(process.env.CODEX_HOME || join(homedir(), ".codex"), "models_cache.json"), "utf8"));
|
|
82
|
+
for (const model of cache.models ?? []) {
|
|
83
|
+
if (typeof model.slug === "string" && !rows.some((row) => row.id === model.slug))
|
|
84
|
+
rows.push({ id: model.slug, name: model.display_name || model.slug });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
/* CLI populates the catalog after login. */
|
|
89
|
+
}
|
|
90
|
+
return rows;
|
|
91
|
+
}
|
|
92
|
+
async sendPrompt(prompt, attachments, sink) {
|
|
93
|
+
if (this.disposed)
|
|
94
|
+
throw new Error("Codex driver disposed");
|
|
95
|
+
if (this.active)
|
|
96
|
+
throw new Error("Codex is already running");
|
|
97
|
+
const cwd = this.cwd;
|
|
98
|
+
let imageDir;
|
|
99
|
+
const imageArgs = [];
|
|
100
|
+
let input = prompt;
|
|
101
|
+
try {
|
|
102
|
+
for (const att of attachments ?? []) {
|
|
103
|
+
if (att.mode === "canvas") {
|
|
104
|
+
input += `\n${formatUnavailableCanvasReference(att)}`;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (att.mode === "page" || att.mode === "conversation") {
|
|
108
|
+
input += `\nReferenced ${att.mode}: ${JSON.stringify(att.path)} (host access unavailable in Codex).`;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (att.imageData) {
|
|
112
|
+
const match = /^data:(image\/(?:png|jpeg|webp|gif));base64,([\s\S]+)$/.exec(att.imageData);
|
|
113
|
+
const mime = match?.[1] ?? att.mimeType;
|
|
114
|
+
if (!mime || !["image/png", "image/jpeg", "image/webp", "image/gif"].includes(mime))
|
|
115
|
+
throw new Error("Unsupported Codex image format");
|
|
116
|
+
const encoded = match?.[2] ?? att.imageData;
|
|
117
|
+
if (encoded.length > 28 * 1024 * 1024)
|
|
118
|
+
throw new Error("Codex image exceeds size limit");
|
|
119
|
+
imageDir ??= mkdtempSync(join(tmpdir(), "pi-codex-images-"));
|
|
120
|
+
const path = join(imageDir, `${imageArgs.length}.${mime.split("/")[1]}`);
|
|
121
|
+
writeFileSync(path, Buffer.from(encoded, "base64"), { mode: 0o600 });
|
|
122
|
+
imageArgs.push("--image", path);
|
|
123
|
+
}
|
|
124
|
+
else if (att.mode === "quote" && att.quote)
|
|
125
|
+
input += `\n<quote>\n${att.quote.text}\n</quote>`;
|
|
126
|
+
else
|
|
127
|
+
input += `\nFile reference: ${JSON.stringify(att.path)}${att.mode === "lines" ? ` (lines ${att.lines?.start ?? ""}-${att.lines?.end ?? ""})` : ""}`;
|
|
128
|
+
}
|
|
129
|
+
const cmd = codexCommand(this.options.executablePath);
|
|
130
|
+
const args = [
|
|
131
|
+
...cmd.args,
|
|
132
|
+
"--ask-for-approval",
|
|
133
|
+
"never",
|
|
134
|
+
"exec",
|
|
135
|
+
"--json",
|
|
136
|
+
"--skip-git-repo-check",
|
|
137
|
+
"--sandbox",
|
|
138
|
+
"workspace-write",
|
|
139
|
+
"--color",
|
|
140
|
+
"never",
|
|
141
|
+
"-c",
|
|
142
|
+
`model_reasoning_effort=${JSON.stringify(this.effort)}`,
|
|
143
|
+
];
|
|
144
|
+
if (this.model !== "default")
|
|
145
|
+
args.push("--model", this.model);
|
|
146
|
+
if (this.sessionId)
|
|
147
|
+
args.push("resume", this.sessionId);
|
|
148
|
+
args.push(...imageArgs, "-");
|
|
149
|
+
const child = spawn(cmd.command, args, {
|
|
150
|
+
cwd,
|
|
151
|
+
windowsHide: true,
|
|
152
|
+
detached: process.platform !== "win32",
|
|
153
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
154
|
+
env: { ...process.env, NO_COLOR: "1" },
|
|
155
|
+
});
|
|
156
|
+
let finish;
|
|
157
|
+
const run = {
|
|
158
|
+
child,
|
|
159
|
+
cancelled: false,
|
|
160
|
+
done: new Promise((resolve) => {
|
|
161
|
+
finish = resolve;
|
|
162
|
+
}),
|
|
163
|
+
};
|
|
164
|
+
this.active = run;
|
|
165
|
+
const decoder = new StringDecoder("utf8");
|
|
166
|
+
let pending = "", stderr = "", error, completed = false, settled = false;
|
|
167
|
+
let usage;
|
|
168
|
+
const texts = new Map();
|
|
169
|
+
const tools = new Set();
|
|
170
|
+
const parse = (line) => {
|
|
171
|
+
if (!line.trim() || run.cancelled)
|
|
172
|
+
return;
|
|
173
|
+
let event;
|
|
174
|
+
try {
|
|
175
|
+
event = JSON.parse(line);
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
throw new Error("Invalid Codex JSON event");
|
|
179
|
+
}
|
|
180
|
+
if (event.type === "thread.started" && typeof event.thread_id === "string") {
|
|
181
|
+
this.sessionId = event.thread_id;
|
|
182
|
+
sink.onSessionStarted?.(event.thread_id);
|
|
183
|
+
}
|
|
184
|
+
else if (event.type === "turn.completed") {
|
|
185
|
+
completed = true;
|
|
186
|
+
const u = event.usage ?? {};
|
|
187
|
+
const cached = u.cached_input_tokens ?? 0;
|
|
188
|
+
usage = {
|
|
189
|
+
inputTokens: Math.max(0, (u.input_tokens ?? 0) - cached),
|
|
190
|
+
cacheReadTokens: cached,
|
|
191
|
+
outputTokens: u.output_tokens ?? 0,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
else if (event.type === "turn.failed")
|
|
195
|
+
error = new Error(event.error?.message || "Codex turn failed");
|
|
196
|
+
else if (event.type === "error")
|
|
197
|
+
error = new Error(event.message || "Codex error");
|
|
198
|
+
else if (event.type?.startsWith("item.") && event.item) {
|
|
199
|
+
const item = event.item, id = String(item.id);
|
|
200
|
+
if (item.type === "agent_message" || item.type === "reasoning") {
|
|
201
|
+
const text = typeof item.text === "string" ? item.text : "";
|
|
202
|
+
const previous = texts.get(id) ?? "";
|
|
203
|
+
const delta = text.startsWith(previous) ? text.slice(previous.length) : text;
|
|
204
|
+
texts.set(id, text);
|
|
205
|
+
if (delta) {
|
|
206
|
+
if (item.type === "reasoning")
|
|
207
|
+
sink.onThinkingDelta(delta);
|
|
208
|
+
else
|
|
209
|
+
sink.onTextDelta(delta);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
else if (["command_execution", "file_change", "mcp_tool_call", "web_search", "todo_list"].includes(item.type)) {
|
|
213
|
+
if (!tools.has(id)) {
|
|
214
|
+
tools.add(id);
|
|
215
|
+
sink.onToolStart(id, item.type, item.type === "command_execution" ? { command: item.command } : { ...item });
|
|
216
|
+
}
|
|
217
|
+
if (event.type === "item.completed")
|
|
218
|
+
sink.onToolEnd(id, {
|
|
219
|
+
output: item.aggregated_output ?? JSON.stringify(item),
|
|
220
|
+
...(item.status === "failed" || (typeof item.exit_code === "number" && item.exit_code !== 0)
|
|
221
|
+
? { error: item.error?.message || `Codex ${item.type} failed (${item.exit_code ?? item.status})` }
|
|
222
|
+
: {}),
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
const fail = (err) => {
|
|
228
|
+
error = err instanceof Error ? err : new Error(String(err));
|
|
229
|
+
void this.stopRun(run);
|
|
230
|
+
};
|
|
231
|
+
child.stdout?.on("data", (chunk) => {
|
|
232
|
+
try {
|
|
233
|
+
pending += decoder.write(chunk);
|
|
234
|
+
if (pending.length > 8 * 1024 * 1024)
|
|
235
|
+
throw new Error("Codex output event exceeds limit");
|
|
236
|
+
let newline;
|
|
237
|
+
while ((newline = pending.indexOf("\n")) >= 0) {
|
|
238
|
+
const line = pending.slice(0, newline);
|
|
239
|
+
pending = pending.slice(newline + 1);
|
|
240
|
+
parse(line);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
catch (err) {
|
|
244
|
+
fail(err);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
child.stderr?.on("data", (chunk) => {
|
|
248
|
+
stderr = (stderr + chunk.toString()).slice(-8000);
|
|
249
|
+
});
|
|
250
|
+
child.stdin?.on("error", (err) => {
|
|
251
|
+
if (!run.cancelled)
|
|
252
|
+
error = err;
|
|
253
|
+
});
|
|
254
|
+
const settle = (code) => {
|
|
255
|
+
if (settled)
|
|
256
|
+
return;
|
|
257
|
+
settled = true;
|
|
258
|
+
try {
|
|
259
|
+
pending += decoder.end();
|
|
260
|
+
if (pending.trim() && !run.cancelled)
|
|
261
|
+
parse(pending);
|
|
262
|
+
if (this.active === run)
|
|
263
|
+
this.active = undefined;
|
|
264
|
+
if (run.cancelled) {
|
|
265
|
+
if (error)
|
|
266
|
+
sink.onError(error);
|
|
267
|
+
}
|
|
268
|
+
else if (error || code !== 0 || !completed)
|
|
269
|
+
sink.onError(error ?? new Error(stderr.trim() || `Codex exited before completion (${code})`));
|
|
270
|
+
else
|
|
271
|
+
sink.onTurnComplete({ usage });
|
|
272
|
+
}
|
|
273
|
+
catch (err) {
|
|
274
|
+
sink.onError(err instanceof Error ? err : String(err));
|
|
275
|
+
}
|
|
276
|
+
finally {
|
|
277
|
+
if (this.active === run)
|
|
278
|
+
this.active = undefined;
|
|
279
|
+
finish();
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
child.on("error", (err) => {
|
|
283
|
+
error = err;
|
|
284
|
+
settle(null);
|
|
285
|
+
});
|
|
286
|
+
child.on("close", settle);
|
|
287
|
+
child.stdin?.end(input);
|
|
288
|
+
await run.done;
|
|
289
|
+
}
|
|
290
|
+
finally {
|
|
291
|
+
if (imageDir)
|
|
292
|
+
rmSync(imageDir, { recursive: true, force: true });
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
stopRun(run) {
|
|
296
|
+
if (run.stop)
|
|
297
|
+
return run.stop;
|
|
298
|
+
run.cancelled = true;
|
|
299
|
+
run.stop = (async () => {
|
|
300
|
+
if (run.child.pid) {
|
|
301
|
+
let timer;
|
|
302
|
+
try {
|
|
303
|
+
await Promise.race([
|
|
304
|
+
killPidTree(run.child.pid),
|
|
305
|
+
new Promise((resolve) => {
|
|
306
|
+
timer = setTimeout(resolve, 3000);
|
|
307
|
+
}),
|
|
308
|
+
]);
|
|
309
|
+
}
|
|
310
|
+
finally {
|
|
311
|
+
if (timer)
|
|
312
|
+
clearTimeout(timer);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
else
|
|
316
|
+
run.child.kill();
|
|
317
|
+
await Promise.race([
|
|
318
|
+
run.done,
|
|
319
|
+
new Promise((resolve) => {
|
|
320
|
+
const timer = setTimeout(resolve, 3000);
|
|
321
|
+
timer.unref();
|
|
322
|
+
run.done.then(() => clearTimeout(timer));
|
|
323
|
+
}),
|
|
324
|
+
]);
|
|
325
|
+
})();
|
|
326
|
+
return run.stop;
|
|
327
|
+
}
|
|
328
|
+
async abort() {
|
|
329
|
+
if (this.active)
|
|
330
|
+
await this.stopRun(this.active);
|
|
331
|
+
}
|
|
332
|
+
async dispose() {
|
|
333
|
+
this.disposed = true;
|
|
334
|
+
await this.abort();
|
|
335
|
+
}
|
|
336
|
+
}
|
|
@@ -5,5 +5,6 @@ export { BaseAgentDriver } from "./driver-base.js";
|
|
|
5
5
|
export { UniversalSessionStore } from "./session-store.js";
|
|
6
6
|
export { UniversalSession } from "./universal-session.js";
|
|
7
7
|
export { UniversalAgentService } from "./universal-service.js";
|
|
8
|
+
export { CodexDriver, probeCodex } from "./drivers/codex.js";
|
|
8
9
|
export { MockAgentDriver } from "./drivers/mock-driver.js";
|
|
9
10
|
export { ClaudeCodeDriver, probeClaudeCode } from "./drivers/claude-code.js";
|
|
@@ -12,6 +12,11 @@ import { existsSync, statSync } from "node:fs";
|
|
|
12
12
|
import { basename, isAbsolute, relative, resolve } from "node:path";
|
|
13
13
|
import { readSkillInstruction } from "../skill-discovery.js";
|
|
14
14
|
import { isRemoteWorkspaceUri } from "../remote-ssh-service.js";
|
|
15
|
+
/** Canvas ids are not workspace paths; unsupported engines must say so. */
|
|
16
|
+
export function formatUnavailableCanvasReference(att) {
|
|
17
|
+
const escape = (s) => s.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
18
|
+
return `<canvas-ref id="${escape(att.path)}" title="${escape(att.name || att.path)}">Canvas tooling is unavailable in this engine. This is a graph identifier, not a file path; do not read it as a file or start a run.</canvas-ref>`;
|
|
19
|
+
}
|
|
15
20
|
/**
|
|
16
21
|
* 扫描用户提问文本中的 `@` 词元:
|
|
17
22
|
* - `@skill:foo` 或匹配已知技能名的 `@foo`
|
|
@@ -42,7 +47,14 @@ export function scanAtMentions(text, cwd, availableSkills = [], existingAttachme
|
|
|
42
47
|
const pathRegex = /(?:^|\s)@([^\s@:"'<>|?*]+)/g;
|
|
43
48
|
let pm;
|
|
44
49
|
const root = resolve(cwd);
|
|
45
|
-
|
|
50
|
+
let pathText = text;
|
|
51
|
+
for (const att of existingAttachments) {
|
|
52
|
+
if (att.mode !== "canvas" || !att.name)
|
|
53
|
+
continue;
|
|
54
|
+
const escaped = att.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
55
|
+
pathText = pathText.replace(new RegExp(`(^|\\s)@${escaped}(?=$|\\s)`, "g"), "$1");
|
|
56
|
+
}
|
|
57
|
+
while ((pm = pathRegex.exec(pathText)) !== null) {
|
|
46
58
|
const rawCandidate = pm[1].trim();
|
|
47
59
|
if (!rawCandidate || rawCandidate.startsWith("skill:"))
|
|
48
60
|
continue;
|
|
@@ -125,6 +137,17 @@ export function createAttachmentUiMessages(attachments, timestamp = Date.now())
|
|
|
125
137
|
});
|
|
126
138
|
continue;
|
|
127
139
|
}
|
|
140
|
+
if (att.mode === "canvas") {
|
|
141
|
+
out.push({
|
|
142
|
+
id: cardId,
|
|
143
|
+
role: "custom",
|
|
144
|
+
customType: "file",
|
|
145
|
+
timestamp,
|
|
146
|
+
content: [{ type: "text", text: formatUnavailableCanvasReference(att) }],
|
|
147
|
+
details: { mode: "canvas", path: att.path, name: att.name || att.path, title: att.name || att.path },
|
|
148
|
+
});
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
128
151
|
// 4. 工作区文件/目录/行范围
|
|
129
152
|
if (att.path) {
|
|
130
153
|
const isLines = att.mode === "lines" && att.lines;
|
|
@@ -20,6 +20,7 @@ import { BgServerTracker } from "../bg-servers.js";
|
|
|
20
20
|
import { ModelAdminService } from "../model-admin.js";
|
|
21
21
|
import { WebUIContext } from "../webui-context.js";
|
|
22
22
|
import { ClaudeCodeDriver, probeClaudeCode } from "./drivers/claude-code.js";
|
|
23
|
+
import { CodexDriver, probeCodex } from "./drivers/codex.js";
|
|
23
24
|
import { normalizeUiLayout, settingsPresetToUi } from "../client-state.js";
|
|
24
25
|
import { messageTextWithQuotes } from "../text-quote.js";
|
|
25
26
|
import { readModelsJson, getModelThinkingLevelFromSettings, saveModelThinkingLevelToSettings, } from "../model-resolver.js";
|
|
@@ -279,6 +280,10 @@ export class UniversalSession {
|
|
|
279
280
|
this.currentModel = "claude-3-7-sonnet-20250219";
|
|
280
281
|
this.seedDefaultClaudeModels();
|
|
281
282
|
}
|
|
283
|
+
else if (opts.driver.id === "codex") {
|
|
284
|
+
this.currentModel = "default";
|
|
285
|
+
this.thinkingLevel = "medium";
|
|
286
|
+
}
|
|
282
287
|
else if (opts.driver.id === "dsh") {
|
|
283
288
|
this.currentModel = "deepseek/deepseek-v4-flash";
|
|
284
289
|
this.thinkingLevel = "high";
|
|
@@ -348,6 +353,14 @@ export class UniversalSession {
|
|
|
348
353
|
if (typeof this.stateStore?.remember === "function" && this.cwd) {
|
|
349
354
|
this.stateStore.remember(this.clientId, this.cwd);
|
|
350
355
|
}
|
|
356
|
+
if (this.driver instanceof CodexDriver) {
|
|
357
|
+
void probeCodex()
|
|
358
|
+
.then((probe) => {
|
|
359
|
+
if (!probe.available && !this.disposed)
|
|
360
|
+
this.emitNotice("warning", "Codex CLI 未安装,请运行 npm i -g @openai/codex 并完成 codex login。", "Codex CLI not found; run npm i -g @openai/codex and codex login.");
|
|
361
|
+
})
|
|
362
|
+
.catch(() => { });
|
|
363
|
+
}
|
|
351
364
|
// 若驱动为 Claude Code,异步探测环境并下发安装指引
|
|
352
365
|
if (this.driver instanceof ClaudeCodeDriver) {
|
|
353
366
|
void probeClaudeCode().then((probe) => {
|
|
@@ -722,6 +735,11 @@ export class UniversalSession {
|
|
|
722
735
|
this.flushSnapshot();
|
|
723
736
|
// 4. 构建 AgentEventSink(时序保真:思考 -> 前置正文 -> 工具调用 -> 总结正文)
|
|
724
737
|
const sink = {
|
|
738
|
+
onSessionStarted: (sessionId) => {
|
|
739
|
+
conv.driverSessionId = sessionId;
|
|
740
|
+
if (!conv.isEphemeral)
|
|
741
|
+
this.store.saveConversation(turn.cwd, conv);
|
|
742
|
+
},
|
|
725
743
|
onThinkingDelta: (delta) => {
|
|
726
744
|
this.streamingThinking += delta;
|
|
727
745
|
if (!this.streamingMessage)
|
|
@@ -2547,6 +2565,11 @@ export class UniversalSession {
|
|
|
2547
2565
|
};
|
|
2548
2566
|
conv.messages.push(assistantMsg);
|
|
2549
2567
|
const sink = {
|
|
2568
|
+
onSessionStarted: (sessionId) => {
|
|
2569
|
+
conv.driverSessionId = sessionId;
|
|
2570
|
+
if (!conv.isEphemeral)
|
|
2571
|
+
this.store.saveConversation(cwd, conv);
|
|
2572
|
+
},
|
|
2550
2573
|
onThinkingDelta: (delta) => {
|
|
2551
2574
|
thinkingText += delta;
|
|
2552
2575
|
let thinkBlock = assistantMsg.content.find((b) => b.type === "thinking");
|
|
@@ -36,29 +36,29 @@ export function findVisionModels(runtime) {
|
|
|
36
36
|
* Exported so the settings panel can offer a custom prompt (append to this
|
|
37
37
|
* default or replace it entirely).
|
|
38
38
|
*/
|
|
39
|
-
export const SYSTEM_PROMPT = `You are a vision bridge for a text-only language model. You receive one or more images and must transcribe them into precise, structured text evidence so another model that cannot see images can answer questions about them accurately.
|
|
40
|
-
|
|
41
|
-
Follow these rules:
|
|
42
|
-
1. Transcribe ALL visible text verbatim, preserving wording, spelling, punctuation and line breaks. This is the most important part — the reader relies on your transcription, not on the image.
|
|
43
|
-
2. Describe the layout in reading order: headers, paragraphs, lists, tables, buttons, panels — say what appears where.
|
|
44
|
-
3. For tables/charts/diagrams: read axes, scales (note log scale), legend entries, series names, highlighted points and their coordinates, and any data values you can discern.
|
|
45
|
-
4. Name entities: people, products, companies, colors, style, objects, actions.
|
|
46
|
-
5. If part of the image is too blurry/low-resolution to read, say "(读不清)" or "unclear" for that part — NEVER invent or guess content you cannot see.
|
|
47
|
-
6. If there are multiple images, address them in order (图 1 / Image 1, 图 2 / Image 2, ...).
|
|
39
|
+
export const SYSTEM_PROMPT = `You are a vision bridge for a text-only language model. You receive one or more images and must transcribe them into precise, structured text evidence so another model that cannot see images can answer questions about them accurately.
|
|
40
|
+
|
|
41
|
+
Follow these rules:
|
|
42
|
+
1. Transcribe ALL visible text verbatim, preserving wording, spelling, punctuation and line breaks. This is the most important part — the reader relies on your transcription, not on the image.
|
|
43
|
+
2. Describe the layout in reading order: headers, paragraphs, lists, tables, buttons, panels — say what appears where.
|
|
44
|
+
3. For tables/charts/diagrams: read axes, scales (note log scale), legend entries, series names, highlighted points and their coordinates, and any data values you can discern.
|
|
45
|
+
4. Name entities: people, products, companies, colors, style, objects, actions.
|
|
46
|
+
5. If part of the image is too blurry/low-resolution to read, say "(读不清)" or "unclear" for that part — NEVER invent or guess content you cannot see.
|
|
47
|
+
6. If there are multiple images, address them in order (图 1 / Image 1, 图 2 / Image 2, ...).
|
|
48
48
|
7. Output only the transcript. No preamble, no commentary about the image itself.`;
|
|
49
49
|
/**
|
|
50
50
|
* 中文版内置转写提示词(调用方按 lang 选用,默认英文)。与 SYSTEM_PROMPT 同义,
|
|
51
51
|
* 仅语言不同——英文版是默认行为,保持原有转写质量不变。
|
|
52
52
|
*/
|
|
53
|
-
export const SYSTEM_PROMPT_ZH = `你是文本模型的视觉桥。你会收到一张或多张图片,必须把它们转写成精确的结构化文字证据,让看不到图片的模型也能准确回答相关问题。
|
|
54
|
-
|
|
55
|
-
规则:
|
|
56
|
-
1. 逐字转写所有可见文本,保留措辞、拼写、标点与换行。这是最重要的部分——阅读者依赖你的转写,而非图片本身。
|
|
57
|
-
2. 按阅读顺序描述版式:标题、段落、列表、表格、按钮、面板——说明它们出现的位置。
|
|
58
|
-
3. 表格/图表/示意图:读出坐标轴、刻度(注意对数轴)、图例项、系列名、高亮点及其坐标,以及能辨认的数据值。
|
|
59
|
-
4. 点名实体:人物、产品、公司、颜色、风格、物体、动作。
|
|
60
|
-
5. 图片局部太模糊/分辨率太低读不清时,对该部分写“(读不清)”或 "unclear”——绝不编造或猜测看不见的内容。
|
|
61
|
-
6. 多张图片时按顺序逐张处理(图 1 / Image 1,图 2 / Image 2,……)。
|
|
53
|
+
export const SYSTEM_PROMPT_ZH = `你是文本模型的视觉桥。你会收到一张或多张图片,必须把它们转写成精确的结构化文字证据,让看不到图片的模型也能准确回答相关问题。
|
|
54
|
+
|
|
55
|
+
规则:
|
|
56
|
+
1. 逐字转写所有可见文本,保留措辞、拼写、标点与换行。这是最重要的部分——阅读者依赖你的转写,而非图片本身。
|
|
57
|
+
2. 按阅读顺序描述版式:标题、段落、列表、表格、按钮、面板——说明它们出现的位置。
|
|
58
|
+
3. 表格/图表/示意图:读出坐标轴、刻度(注意对数轴)、图例项、系列名、高亮点及其坐标,以及能辨认的数据值。
|
|
59
|
+
4. 点名实体:人物、产品、公司、颜色、风格、物体、动作。
|
|
60
|
+
5. 图片局部太模糊/分辨率太低读不清时,对该部分写“(读不清)”或 "unclear”——绝不编造或猜测看不见的内容。
|
|
61
|
+
6. 多张图片时按顺序逐张处理(图 1 / Image 1,图 2 / Image 2,……)。
|
|
62
62
|
7. 只输出转写结果,不加开场白,不评论图片本身。`;
|
|
63
63
|
/** 按服务端语言选用内置转写提示词(默认英文)。 */
|
|
64
64
|
export function getVisionSystemPrompt(lang = "en") {
|