@keyou007/agent-bot 0.1.27-alpha.1 → 0.1.27-alpha.2
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 +24 -0
- package/README.md +54 -4
- package/README.zh.md +54 -4
- package/SECURITY.md +14 -0
- package/assets/workspace-sessions.js +648 -0
- package/assets/workspace.css +160 -0
- package/assets/workspace.js +1795 -0
- package/config.example.yaml +3 -2
- package/dist/codex/CodexEventMapper.js +35 -0
- package/dist/codex/CodexEventMapper.js.map +1 -1
- package/dist/codex/CodexRuntime.js +50 -4
- package/dist/codex/CodexRuntime.js.map +1 -1
- package/dist/codex/TraeTaskNotification.js +44 -0
- package/dist/codex/TraeTaskNotification.js.map +1 -0
- package/dist/config/SettingsStore.js +1 -1
- package/dist/config/SettingsStore.js.map +1 -1
- package/dist/config/loadConfig.js +3 -2
- package/dist/config/loadConfig.js.map +1 -1
- package/dist/config/paths.js +3 -0
- package/dist/config/paths.js.map +1 -1
- package/dist/feishu/CardRenderer.js +54 -10
- package/dist/feishu/CardRenderer.js.map +1 -1
- package/dist/feishu/FeishuMessageClient.js +2 -2
- package/dist/feishu/FeishuMessageClient.js.map +1 -1
- package/dist/feishu/FeishuTurnPresenter.js +103 -16
- package/dist/feishu/FeishuTurnPresenter.js.map +1 -1
- package/dist/index.js +61 -17
- package/dist/index.js.map +1 -1
- package/dist/local-files/DiagramPreview.js +1 -1
- package/dist/local-files/GitDiffPreview.js +11 -7
- package/dist/local-files/GitDiffPreview.js.map +1 -1
- package/dist/local-files/LocalFileViewerServer.js +273 -25
- package/dist/local-files/LocalFileViewerServer.js.map +1 -1
- package/dist/local-files/MarkdownFileLinks.js +5 -4
- package/dist/local-files/MarkdownFileLinks.js.map +1 -1
- package/dist/local-files/TurnPreviewPage.js +32 -10
- package/dist/local-files/TurnPreviewPage.js.map +1 -1
- package/dist/local-files/WebPageTitle.js +85 -0
- package/dist/local-files/WebPageTitle.js.map +1 -0
- package/dist/local-files/WorkspaceFiles.js +553 -0
- package/dist/local-files/WorkspaceFiles.js.map +1 -0
- package/dist/local-files/WorkspaceOrigin.js +38 -0
- package/dist/local-files/WorkspaceOrigin.js.map +1 -0
- package/dist/local-files/WorkspacePage.js +19 -0
- package/dist/local-files/WorkspacePage.js.map +1 -0
- package/dist/local-files/WorkspaceSessions.js +689 -0
- package/dist/local-files/WorkspaceSessions.js.map +1 -0
- package/dist/presentation/TurnStateReducer.js +74 -13
- package/dist/presentation/TurnStateReducer.js.map +1 -1
- package/dist/presentation/turnActivity.js +41 -0
- package/dist/presentation/turnActivity.js.map +1 -0
- package/dist/presentation/turnStatus.js +11 -0
- package/dist/presentation/turnStatus.js.map +1 -1
- package/dist/presentation/visibleTurnActivities.js +4 -2
- package/dist/presentation/visibleTurnActivities.js.map +1 -1
- package/dist/proxy/ProxySessionController.js +150 -14
- package/dist/proxy/ProxySessionController.js.map +1 -1
- package/dist/runtime/types.js +1 -1
- package/dist/runtime/types.js.map +1 -1
- package/dist/state/InboundMessageStore.js +54 -0
- package/dist/state/InboundMessageStore.js.map +1 -0
- package/dist/state/StateStore.js +71 -1
- package/dist/state/StateStore.js.map +1 -1
- package/dist/state/TurnPreviewJournal.js +4 -2
- package/dist/state/TurnPreviewJournal.js.map +1 -1
- package/dist/state/migrations.js +20 -0
- package/dist/state/migrations.js.map +1 -1
- package/dist/supervision/SafeRestartNotifier.js +1 -0
- package/dist/supervision/SafeRestartNotifier.js.map +1 -1
- package/dist/supervision/SafeRestartScheduler.js +33 -16
- package/dist/supervision/SafeRestartScheduler.js.map +1 -1
- package/dist/terminal/TerminalLinks.js +32 -0
- package/dist/terminal/TerminalLinks.js.map +1 -1
- package/dist/terminal/TerminalPage.js +44 -24
- package/dist/terminal/TerminalPage.js.map +1 -1
- package/dist/terminal/TerminalServer.js +103 -39
- package/dist/terminal/TerminalServer.js.map +1 -1
- package/docs/technical-reference.md +1 -1
- package/docs/technical-reference.zh.md +2 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/skills/agent-bot/SKILL.md +3 -1
- package/src/codex/CodexEventMapper.ts +39 -1
- package/src/codex/CodexRuntime.ts +54 -4
- package/src/codex/TraeTaskNotification.ts +49 -0
- package/src/config/SettingsStore.ts +1 -1
- package/src/config/loadConfig.ts +3 -2
- package/src/config/paths.ts +4 -0
- package/src/feishu/CardRenderer.ts +45 -11
- package/src/feishu/FeishuMessageClient.ts +2 -2
- package/src/feishu/FeishuTurnPresenter.ts +110 -20
- package/src/index.ts +62 -17
- package/src/local-files/DiagramPreview.ts +1 -1
- package/src/local-files/GitDiffPreview.ts +10 -7
- package/src/local-files/LocalFileViewerServer.ts +243 -25
- package/src/local-files/MarkdownFileLinks.ts +5 -3
- package/src/local-files/TurnPreviewPage.ts +35 -9
- package/src/local-files/WebPageTitle.ts +59 -0
- package/src/local-files/WorkspaceFiles.ts +468 -0
- package/src/local-files/WorkspaceOrigin.ts +31 -0
- package/src/local-files/WorkspacePage.ts +21 -0
- package/src/local-files/WorkspaceSessions.ts +587 -0
- package/src/presentation/TurnStateReducer.ts +76 -14
- package/src/presentation/turnActivity.ts +43 -0
- package/src/presentation/turnStatus.ts +14 -0
- package/src/presentation/turnViewTypes.ts +10 -1
- package/src/presentation/visibleTurnActivities.ts +4 -2
- package/src/proxy/ProxySessionController.ts +149 -13
- package/src/runtime/types.ts +17 -0
- package/src/state/InboundMessageStore.ts +72 -0
- package/src/state/StateStore.ts +80 -1
- package/src/state/TurnPreviewJournal.ts +4 -2
- package/src/state/migrations.ts +20 -0
- package/src/supervision/SafeRestartNotifier.ts +1 -0
- package/src/supervision/SafeRestartScheduler.ts +42 -18
- package/src/terminal/TerminalLinks.ts +26 -0
- package/src/terminal/TerminalPage.ts +44 -24
- package/src/terminal/TerminalServer.ts +98 -36
|
@@ -5,6 +5,7 @@ import { createRequire } from "node:module";
|
|
|
5
5
|
import http, { type IncomingMessage, type ServerResponse } from "node:http";
|
|
6
6
|
import type { Duplex } from "node:stream";
|
|
7
7
|
import path from "node:path";
|
|
8
|
+
import { z } from "zod";
|
|
8
9
|
import hljs from "highlight.js/lib/common";
|
|
9
10
|
import dos from "highlight.js/lib/languages/dos";
|
|
10
11
|
import dockerfile from "highlight.js/lib/languages/dockerfile";
|
|
@@ -12,6 +13,10 @@ import powershell from "highlight.js/lib/languages/powershell";
|
|
|
12
13
|
import MarkdownIt from "markdown-it";
|
|
13
14
|
import { CSV_PREVIEW_CSS, renderCsvPreview, csvSourcePreview } from "./CsvPreview.js";
|
|
14
15
|
import { GIT_DIFF_PREVIEW_CSS, readGitFileDiff, renderGitFileDiff } from "./GitDiffPreview.js";
|
|
16
|
+
import { renderWorkspacePage, WORKSPACE_SCRIPT } from "./WorkspacePage.js";
|
|
17
|
+
import { directWorkspaceOrigin } from "./WorkspaceOrigin.js";
|
|
18
|
+
import { readWebPageTitle } from "./WebPageTitle.js";
|
|
19
|
+
import { WorkspaceError, readWorkspaceAddress, readWorkspaceEntries, readWorkspaceGitStatus, readWorkspaceChanges, readWorkspaceFileVersions, createWorkspaceDiff, renderWorkspaceDiff, resolveWorkspacePath, type WorkspaceChange } from "./WorkspaceFiles.js";
|
|
15
20
|
import { enableDiagramFences, DIAGRAM_PREVIEW_CLIENT_SCRIPT, DIAGRAM_PREVIEW_CSS } from "./DiagramPreview.js";
|
|
16
21
|
import { isFileUrl, rewriteMarkdownFileLinks } from "./MarkdownFileLinks.js";
|
|
17
22
|
import {
|
|
@@ -39,6 +44,13 @@ const MAX_TEXT_PREVIEW_BYTES = 2 * 1024 * 1024;
|
|
|
39
44
|
const MAX_CONTENT_SAMPLE_BYTES = 64 * 1024;
|
|
40
45
|
const MAX_SYNTAX_HIGHLIGHT_BYTES = 512 * 1024;
|
|
41
46
|
const DIRECTORY_PAGE_SIZE = 100;
|
|
47
|
+
const WORKSPACE_QUERY = z.object({
|
|
48
|
+
api: z.string().optional(), entry: z.string().default(""),
|
|
49
|
+
page: z.coerce.number().int().min(0).max(Number.MAX_SAFE_INTEGER).default(0),
|
|
50
|
+
mode: z.enum(["all", "staged", "unstaged"]).default("all"), original: z.string().optional(),
|
|
51
|
+
prefetch: z.enum(["0", "1"]).optional(), query: z.string().trim().max(160).optional(),
|
|
52
|
+
instance: z.string().regex(/^[a-f0-9]{16}$/u).optional(),
|
|
53
|
+
});
|
|
42
54
|
const MARKDOWN_EXTENSIONS = new Set([".markdown", ".md", ".mdown", ".mkd", ".mkdn"]);
|
|
43
55
|
const HTML_EXTENSIONS = new Set([".html", ".htm"]);
|
|
44
56
|
hljs.registerLanguage("dos", dos);
|
|
@@ -51,8 +63,8 @@ const MARKDOWN_RENDERER = new MarkdownIt({
|
|
|
51
63
|
linkify: true,
|
|
52
64
|
typographer: false,
|
|
53
65
|
highlight(value, language) {
|
|
54
|
-
const highlighted = language && hljs.getLanguage(language)
|
|
55
|
-
?
|
|
66
|
+
const highlighted = language && hljs.getLanguage(language) && Buffer.byteLength(value, "utf8") <= MAX_SYNTAX_HIGHLIGHT_BYTES
|
|
67
|
+
? highlightLines(value, language).join("\n")
|
|
56
68
|
: escapeHtml(value);
|
|
57
69
|
const languageAttribute = language && hljs.getLanguage(language)
|
|
58
70
|
? ` class="language-${escapeAttribute(language)}"`
|
|
@@ -149,6 +161,12 @@ const VIEWER_CLIENT_SCRIPT = DIAGRAM_PREVIEW_CLIENT_SCRIPT + `(() => {
|
|
|
149
161
|
const positionHashTarget = () => {
|
|
150
162
|
highlightHashTarget()?.scrollIntoView({ block: "start" });
|
|
151
163
|
};
|
|
164
|
+
const positionInitialContent = () => {
|
|
165
|
+
const firstChange = content.querySelector(".git-diff .diff-addition, .git-diff .diff-deletion");
|
|
166
|
+
if (firstChange && ["reload", "back_forward"].includes(performance.getEntriesByType("navigation")[0]?.type)) { highlightHashTarget(); return; }
|
|
167
|
+
if (window.location.hash) return positionHashTarget();
|
|
168
|
+
firstChange?.scrollIntoView({ block: "center" });
|
|
169
|
+
};
|
|
152
170
|
if (/^#L\\d+$/u.test(window.location.hash)) document.body.dataset.viewMode = "code";
|
|
153
171
|
syncViewMode();
|
|
154
172
|
updateHeaderOffset();
|
|
@@ -159,7 +177,7 @@ const VIEWER_CLIENT_SCRIPT = DIAGRAM_PREVIEW_CLIENT_SCRIPT + `(() => {
|
|
|
159
177
|
if (/^#L\\d+$/u.test(window.location.hash)) setViewMode("code");
|
|
160
178
|
else requestAnimationFrame(positionHashTarget);
|
|
161
179
|
});
|
|
162
|
-
requestAnimationFrame(
|
|
180
|
+
requestAnimationFrame(positionInitialContent);
|
|
163
181
|
if (!eventsUrl || typeof EventSource !== "function") return;
|
|
164
182
|
|
|
165
183
|
const restoreScroll = (top, left, atBottom, codeScrollLeft, tablePositions) => {
|
|
@@ -275,6 +293,7 @@ export interface LocalFileViewerServerOptions {
|
|
|
275
293
|
getTurnSnapshot?: (turnId: string) => unknown;
|
|
276
294
|
loadTurnSnapshot?: (turnId: string) => Promise<unknown>;
|
|
277
295
|
turnPreviewPollIntervalMs?: number;
|
|
296
|
+
createWorkspaceTerminalUrl?: (root: string, instance: string, request: IncomingMessage) => string;
|
|
278
297
|
}
|
|
279
298
|
|
|
280
299
|
export interface LocalFileViewerAddress {
|
|
@@ -297,6 +316,13 @@ export class LocalFileViewerServer {
|
|
|
297
316
|
private address?: LocalFileViewerAddress;
|
|
298
317
|
private basePath = "";
|
|
299
318
|
private readonly services = new Map<string, LocalFileViewerService>();
|
|
319
|
+
private workspaceAppBase?: string;
|
|
320
|
+
|
|
321
|
+
enableWorkspaceApp(base: string): void { this.workspaceAppBase = base; }
|
|
322
|
+
|
|
323
|
+
serveWorkspaceAppPage(response: ServerResponse, url: URL, headOnly: boolean): void {
|
|
324
|
+
this.sendHtml(response, 200, renderWorkspacePage("", url.toString(), this.basePath + "/assets/workspace.js", this.workspaceAppBase), headOnly, true);
|
|
325
|
+
}
|
|
300
326
|
|
|
301
327
|
constructor(private readonly options: LocalFileViewerServerOptions) {}
|
|
302
328
|
|
|
@@ -424,6 +450,27 @@ export class LocalFileViewerServer {
|
|
|
424
450
|
return url.toString();
|
|
425
451
|
}
|
|
426
452
|
|
|
453
|
+
createWorkspaceUrl(directory: string, origin?: string): string | undefined {
|
|
454
|
+
if (!this.address || !this.secret) return undefined;
|
|
455
|
+
try {
|
|
456
|
+
const root = fs.realpathSync(directory);
|
|
457
|
+
if (!fs.statSync(root).isDirectory()) return undefined;
|
|
458
|
+
const url = new URL(origin ?? this.address.publicBaseUrl);
|
|
459
|
+
url.pathname = this.basePath + "/workspace/" + this.createShortToken("workspace:" + root);
|
|
460
|
+
url.searchParams.set("path", root);
|
|
461
|
+
return url.toString();
|
|
462
|
+
} catch { return undefined; }
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
serveWorkspaceChatImage(request: IncomingMessage, response: ServerResponse, root: string, entry: string): void {
|
|
466
|
+
const file = resolveWorkspacePath(root, entry);
|
|
467
|
+
const stat = fs.statSync(file);
|
|
468
|
+
if (!stat.isFile() || !contentTypeFor(path.extname(file).toLowerCase()).startsWith("image/")) {
|
|
469
|
+
throw new WorkspaceError("图片格式不可预览。", 404);
|
|
470
|
+
}
|
|
471
|
+
this.serveRawFile(request, response, file, stat, false);
|
|
472
|
+
}
|
|
473
|
+
|
|
427
474
|
createTurnPreviewUrl(turnId: string): string | undefined {
|
|
428
475
|
const normalizedTurnId = normalizeTurnId(turnId);
|
|
429
476
|
if (!this.address || !this.secret || !this.options.getTurnSnapshot || !normalizedTurnId) return undefined;
|
|
@@ -447,6 +494,26 @@ export class LocalFileViewerServer {
|
|
|
447
494
|
|
|
448
495
|
const requestUrl = new URL(request.url ?? "/", "http://127.0.0.1");
|
|
449
496
|
const route = routeWithinBasePath(requestUrl.pathname, this.basePath);
|
|
497
|
+
if (route === "/assets/workspace.js") {
|
|
498
|
+
this.sendJavascript(response, request.method === "HEAD", WORKSPACE_SCRIPT);
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
const workspaceMatch = new RegExp("^/workspace/([A-Za-z0-9_-]{" + SHORT_TOKEN_LENGTH + "})$", "u").exec(route);
|
|
502
|
+
if (workspaceMatch) {
|
|
503
|
+
const root = normalizeAbsolutePath(requestUrl.searchParams.get("path") ?? "");
|
|
504
|
+
const expected = root ? this.createShortToken("workspace:" + root) : "";
|
|
505
|
+
if (!root || !timingSafeEqual(Buffer.from(expected), Buffer.from(workspaceMatch[1]!))) {
|
|
506
|
+
this.sendWorkspaceJson(response, 403, { error: "工作台链接无效,项目签名校验失败。" }, request.method === "HEAD");
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
try { await this.handleWorkspace(request, response, requestUrl, root); }
|
|
510
|
+
catch (error) {
|
|
511
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
512
|
+
this.sendWorkspaceJson(response, error instanceof WorkspaceError ? error.status : code === "ENOENT" ? 404 : code === "EACCES" || code === "EPERM" ? 403 : 500,
|
|
513
|
+
{ error: error instanceof Error ? error.message : String(error) }, request.method === "HEAD");
|
|
514
|
+
}
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
450
517
|
if (!route.startsWith("/")) {
|
|
451
518
|
this.sendHtml(response, 404, errorPage("文件链接无效", "请从 Agent Bot 的回答中重新打开文件链接。"), request.method === "HEAD");
|
|
452
519
|
return;
|
|
@@ -532,8 +599,13 @@ export class LocalFileViewerServer {
|
|
|
532
599
|
eventsUrl.searchParams.set("events", "1");
|
|
533
600
|
if (snapshot.previewCursor !== undefined) eventsUrl.searchParams.set("after", String(snapshot.previewCursor));
|
|
534
601
|
const language = detectTurnPreviewLanguage(request.headers["accept-language"]);
|
|
602
|
+
const projectWorkspaceUrl = snapshot.projectCwd ? this.createWorkspaceUrl(snapshot.projectCwd) : undefined;
|
|
603
|
+
const workspaceUrl = projectWorkspaceUrl ? new URL(projectWorkspaceUrl) : undefined;
|
|
604
|
+
workspaceUrl?.searchParams.set("list", "changes");
|
|
605
|
+
if (this.workspaceAppBase && snapshot.sessionId) workspaceUrl?.searchParams.set("task", snapshot.sessionId);
|
|
535
606
|
const html = renderTurnPreviewPage({
|
|
536
607
|
state: snapshot,
|
|
608
|
+
workspaceUrl: workspaceUrl?.toString(),
|
|
537
609
|
eventsUrl: eventsUrl.toString(),
|
|
538
610
|
scriptPath: `${this.basePath}/assets/turn-preview.js`.replace(/\/{2,}/gu, "/"),
|
|
539
611
|
localFileUrl: (filePath, options) => this.createFileUrl(filePath, undefined, options),
|
|
@@ -574,7 +646,8 @@ export class LocalFileViewerServer {
|
|
|
574
646
|
actions.push({ href: original, label: "查看文件" }, { href: raw.toString(), label: "打开原始文件" }, { href: download.toString(), label: "下载" });
|
|
575
647
|
}
|
|
576
648
|
this.sendHtml(response, 200, renderViewerPage({ title: path.basename(filePath), filePath,
|
|
577
|
-
metadata: ["Git diff", "完整文件", "当前工作区"], actions, content
|
|
649
|
+
metadata: ["Git diff", "完整文件", "当前工作区"], actions, content,
|
|
650
|
+
scriptPath: `${this.basePath}/assets/viewer.js`.replace(/\/{2,}/gu, "/") }), request.method === "HEAD");
|
|
578
651
|
return;
|
|
579
652
|
}
|
|
580
653
|
}
|
|
@@ -706,10 +779,8 @@ export class LocalFileViewerServer {
|
|
|
706
779
|
content: snapshot.content,
|
|
707
780
|
viewMode: snapshot.viewMode,
|
|
708
781
|
diagramScriptPath: isMarkdownFile(filePath) ? `${this.basePath}/assets/mermaid.js`.replace(/\/{2,}/gu, "/") : undefined,
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
scriptPath: `${this.basePath}/assets/viewer.js`.replace(/\/{2,}/gu, "/"),
|
|
712
|
-
},
|
|
782
|
+
eventsUrl: eventsUrl.toString(),
|
|
783
|
+
scriptPath: `${this.basePath}/assets/viewer.js`.replace(/\/{2,}/gu, "/"),
|
|
713
784
|
});
|
|
714
785
|
}
|
|
715
786
|
|
|
@@ -961,6 +1032,128 @@ export class LocalFileViewerServer {
|
|
|
961
1032
|
response.once("close", cleanup);
|
|
962
1033
|
}
|
|
963
1034
|
|
|
1035
|
+
private sendWorkspaceJson(response: ServerResponse, status: number, value: unknown, headOnly: boolean): void {
|
|
1036
|
+
const body = Buffer.from(JSON.stringify(value), "utf8");
|
|
1037
|
+
setSecurityHeaders(response);
|
|
1038
|
+
response.writeHead(status, { "Content-Type": "application/json; charset=utf-8", "Cache-Control": "no-store", "Content-Length": body.length });
|
|
1039
|
+
response.end(headOnly ? undefined : body);
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
private async handleWorkspace(request: IncomingMessage, response: ServerResponse, url: URL, root: string): Promise<void> {
|
|
1043
|
+
resolveWorkspacePath(root);
|
|
1044
|
+
const headOnly = request.method === "HEAD";
|
|
1045
|
+
const published = new URL(this.address!.publicBaseUrl);
|
|
1046
|
+
const origin = request.headers.host === published.host ? published.origin : directWorkspaceOrigin(request);
|
|
1047
|
+
const workspaceUrl = this.createWorkspaceUrl(root, origin)!;
|
|
1048
|
+
if (!url.searchParams.has("api")) {
|
|
1049
|
+
this.sendHtml(response, 200, renderWorkspacePage(root, workspaceUrl, this.basePath + "/assets/workspace.js", this.workspaceAppBase), headOnly, true);
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
const parsed = WORKSPACE_QUERY.safeParse(Object.fromEntries(url.searchParams));
|
|
1053
|
+
if (!parsed.success) throw new WorkspaceError("工作台参数无效:" + parsed.error.issues.map((issue) => issue.message).join(";"));
|
|
1054
|
+
const { api, entry, page, mode, original, prefetch, query, instance } = parsed.data;
|
|
1055
|
+
if (!api) {
|
|
1056
|
+
this.sendHtml(response, 200, renderWorkspacePage(root, workspaceUrl, this.basePath + "/assets/workspace.js", this.workspaceAppBase), headOnly, true);
|
|
1057
|
+
return;
|
|
1058
|
+
}
|
|
1059
|
+
if (api === "tree") {
|
|
1060
|
+
this.sendWorkspaceJson(response, 200, await readWorkspaceEntries(root, entry, page, { prefetch: prefetch === "1", query }), headOnly);
|
|
1061
|
+
return;
|
|
1062
|
+
}
|
|
1063
|
+
if (api === "address") {
|
|
1064
|
+
this.sendWorkspaceJson(response, 200, await readWorkspaceAddress(root, entry, query), headOnly);
|
|
1065
|
+
return;
|
|
1066
|
+
}
|
|
1067
|
+
if (api === "web-title") {
|
|
1068
|
+
this.sendWorkspaceJson(response, 200, headOnly ? {} : await readWebPageTitle(entry), headOnly);
|
|
1069
|
+
return;
|
|
1070
|
+
}
|
|
1071
|
+
if (api === "changes") {
|
|
1072
|
+
this.sendWorkspaceJson(response, 200, await readWorkspaceChanges(root, entry, page, { prefetch: prefetch === "1", query }), headOnly);
|
|
1073
|
+
return;
|
|
1074
|
+
}
|
|
1075
|
+
if (api === "terminal") {
|
|
1076
|
+
if (!instance) throw new WorkspaceError("终端标签标识无效。");
|
|
1077
|
+
if (!this.options.createWorkspaceTerminalUrl) throw new WorkspaceError("网页终端服务未启用。", 503);
|
|
1078
|
+
if (!headOnly) this.sendWorkspaceJson(response, 200, { url: this.options.createWorkspaceTerminalUrl(root, instance, request) }, false);
|
|
1079
|
+
else this.sendWorkspaceJson(response, 200, {}, true);
|
|
1080
|
+
return;
|
|
1081
|
+
}
|
|
1082
|
+
if (api === "diff") {
|
|
1083
|
+
const versions = await readWorkspaceFileVersions(root, entry, mode, original);
|
|
1084
|
+
const file = resolveWorkspacePath(root, entry, true);
|
|
1085
|
+
const before = classifyContentSample(versions.before, true), after = classifyContentSample(versions.after, true);
|
|
1086
|
+
let html: string;
|
|
1087
|
+
if (before.kind === "binary" || after.kind === "binary") html = '<div class="workspace-notice">这个文件是二进制格式,无法显示文本 Diff;可以查看文件预览或下载。</div>';
|
|
1088
|
+
else {
|
|
1089
|
+
const previous = decodeText(versions.before, before.encoding, true), current = decodeText(versions.after, after.encoding, true);
|
|
1090
|
+
html = renderWorkspaceDiff(await createWorkspaceDiff(root, previous, current), current, (value) => highlightTextLines(value, file));
|
|
1091
|
+
}
|
|
1092
|
+
this.sendWorkspaceJson(response, 200, { html, canViewFile: versions.canViewFile }, headOnly);
|
|
1093
|
+
return;
|
|
1094
|
+
}
|
|
1095
|
+
if (api !== "file" && api !== "raw") throw new WorkspaceError("工作台接口不存在。", 404);
|
|
1096
|
+
const file = resolveWorkspacePath(root, entry);
|
|
1097
|
+
const stat = fs.statSync(file);
|
|
1098
|
+
if (!stat.isFile()) throw new WorkspaceError("这不是普通文件,未读取内容。");
|
|
1099
|
+
if (api === "raw") {
|
|
1100
|
+
this.serveRawFile(request, response, file, stat, url.searchParams.get("download") === "1");
|
|
1101
|
+
return;
|
|
1102
|
+
}
|
|
1103
|
+
const raw = new URL(workspaceUrl);
|
|
1104
|
+
raw.searchParams.set("api", "raw"); raw.searchParams.set("entry", entry);
|
|
1105
|
+
const classification = classifyFileContent(file, stat.size);
|
|
1106
|
+
const type = binaryContentTypeFor(path.extname(file).toLowerCase());
|
|
1107
|
+
let html: string;
|
|
1108
|
+
if (classification.kind === "text") {
|
|
1109
|
+
const preview = readTextPreview(file, stat.size, classification.encoding);
|
|
1110
|
+
const lines = preview.text.split(/\r\n?|\n/u);
|
|
1111
|
+
html = (preview.truncated || lines.length > 10_000 ? '<div class="workspace-notice">文件较大,仅显示前 2 MiB 或 10000 行;可下载完整文件。</div>' : "")
|
|
1112
|
+
+ (isMarkdownFile(file) ? this.renderWorkspaceMarkdown(root, file, lines.slice(0, 10_000).join("\n"), workspaceUrl) : renderText(lines.slice(0, 10_000).join("\n"), file));
|
|
1113
|
+
} else if (type.startsWith("image/")) {
|
|
1114
|
+
html = '<div class="workspace-media"><img src="' + escapeAttribute(raw.toString()) + '" alt="' + escapeAttribute(path.basename(file)) + '"></div>';
|
|
1115
|
+
} else if (type === "application/pdf") {
|
|
1116
|
+
html = '<object class="workspace-pdf" type="application/pdf" data="' + escapeAttribute(raw.toString()) + '">浏览器不支持 PDF 预览,请下载文件。</object>';
|
|
1117
|
+
} else {
|
|
1118
|
+
html = '<div class="workspace-notice">这个文件是二进制格式,无法显示文本内容;可下载到本地查看。</div>';
|
|
1119
|
+
}
|
|
1120
|
+
let change: WorkspaceChange | undefined, gitError: string | undefined;
|
|
1121
|
+
try {
|
|
1122
|
+
const relative = path.relative(root, file).split(path.sep).join("/");
|
|
1123
|
+
const normalize = (value: string) => process.platform === "win32" ? value.toLowerCase() : value;
|
|
1124
|
+
change = (await readWorkspaceGitStatus(root)).changes.find(item => normalize(item.path) === normalize(relative));
|
|
1125
|
+
} catch (error) { gitError = error instanceof Error ? error.message : String(error); }
|
|
1126
|
+
this.sendWorkspaceJson(response, 200, { html, rawUrl: raw.toString(), change, gitError }, headOnly);
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
private renderWorkspaceMarkdown(root: string, file: string, value: string, workspaceUrl: string): string {
|
|
1130
|
+
const environment = {}, tokens = MARKDOWN_RENDERER.parse(value, environment), targets = new Map<string, string>();
|
|
1131
|
+
rewriteMarkdownFileLinks(tokens, file, (target) => {
|
|
1132
|
+
const entry = path.relative(root, target).split(path.sep).join("/");
|
|
1133
|
+
try {
|
|
1134
|
+
const resolved = resolveWorkspacePath(root, entry);
|
|
1135
|
+
if (!fs.statSync(resolved).isFile()) return undefined;
|
|
1136
|
+
} catch { return undefined; }
|
|
1137
|
+
const url = new URL(workspaceUrl); url.searchParams.set("api", "raw"); url.searchParams.set("entry", entry);
|
|
1138
|
+
targets.set(url.toString(), entry); return url;
|
|
1139
|
+
});
|
|
1140
|
+
const rewriteLinks = (items: typeof tokens): void => {
|
|
1141
|
+
for (const token of items) {
|
|
1142
|
+
const href = token.type === "link_open" ? token.attrGet("href") : null;
|
|
1143
|
+
if (typeof href === "string" && href) {
|
|
1144
|
+
const entry = targets.get(href.split("#")[0]!);
|
|
1145
|
+
if (entry !== undefined) {
|
|
1146
|
+
const url = new URL(href); url.searchParams.delete("api");
|
|
1147
|
+
token.attrSet("href", url.toString()); token.attrSet("data-workspace-entry", entry);
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
if (token.children) rewriteLinks(token.children);
|
|
1151
|
+
}
|
|
1152
|
+
};
|
|
1153
|
+
rewriteLinks(tokens);
|
|
1154
|
+
return '<article class="markdown-body">' + MARKDOWN_RENDERER.renderer.render(tokens, MARKDOWN_RENDERER.options, environment) + '</article>';
|
|
1155
|
+
}
|
|
1156
|
+
|
|
964
1157
|
private renderDirectoryViewer(directory: string, stat: fs.Stats, requestedPage: number): string {
|
|
965
1158
|
const entries = fs.readdirSync(directory, { withFileTypes: true })
|
|
966
1159
|
.flatMap((entry): DirectoryViewerEntry[] => {
|
|
@@ -998,7 +1191,7 @@ export class LocalFileViewerServer {
|
|
|
998
1191
|
title,
|
|
999
1192
|
filePath: directory,
|
|
1000
1193
|
metadata: [`${entries.length} 项`, stat.mtime.toLocaleString()],
|
|
1001
|
-
actions: [],
|
|
1194
|
+
actions: [{ href: this.createWorkspaceUrl(directory)!, label: "打开项目工作台" }],
|
|
1002
1195
|
content: `<div class="directory-list">${rows}</div>${pagination}`,
|
|
1003
1196
|
});
|
|
1004
1197
|
}
|
|
@@ -1059,9 +1252,13 @@ export class LocalFileViewerServer {
|
|
|
1059
1252
|
stream.pipe(response);
|
|
1060
1253
|
}
|
|
1061
1254
|
|
|
1062
|
-
private sendHtml(response: ServerResponse, status: number, html: string, headOnly = false): void {
|
|
1255
|
+
private sendHtml(response: ServerResponse, status: number, html: string, headOnly = false, workspace = false): void {
|
|
1063
1256
|
const body = Buffer.from(html, "utf8");
|
|
1064
1257
|
setSecurityHeaders(response);
|
|
1258
|
+
// External frame redirects must not expose privileged viewer documents.
|
|
1259
|
+
response.setHeader("X-Frame-Options", "DENY");
|
|
1260
|
+
if (workspace) response.setHeader("Content-Security-Policy", "default-src 'none'; img-src 'self' data:; media-src 'self'; object-src 'self'; frame-src 'self' http: https:; script-src 'self'; connect-src 'self'; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'");
|
|
1261
|
+
else response.setHeader("Content-Security-Policy", String(response.getHeader("Content-Security-Policy")).replace("frame-ancestors 'self'", "frame-ancestors 'none'"));
|
|
1065
1262
|
response.statusCode = status;
|
|
1066
1263
|
response.setHeader("Cache-Control", "no-store");
|
|
1067
1264
|
response.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
@@ -1088,7 +1285,8 @@ function renderViewerPage(input: {
|
|
|
1088
1285
|
content: string;
|
|
1089
1286
|
viewMode?: RenderedFileSnapshot["viewMode"];
|
|
1090
1287
|
diagramScriptPath?: string;
|
|
1091
|
-
|
|
1288
|
+
eventsUrl?: string;
|
|
1289
|
+
scriptPath?: string;
|
|
1092
1290
|
}): string {
|
|
1093
1291
|
const metadata = renderMetadata(input.metadata);
|
|
1094
1292
|
const actions = input.actions.length > 0
|
|
@@ -1100,11 +1298,11 @@ function renderViewerPage(input: {
|
|
|
1100
1298
|
const toolbar = viewSwitch || actions
|
|
1101
1299
|
? `<div class="toolbar">${viewSwitch}${actions}</div>`
|
|
1102
1300
|
: "";
|
|
1103
|
-
const liveAttributes = input.
|
|
1104
|
-
? ` data-events-url="${escapeAttribute(input.
|
|
1301
|
+
const liveAttributes = input.eventsUrl
|
|
1302
|
+
? ` data-events-url="${escapeAttribute(input.eventsUrl)}"`
|
|
1105
1303
|
: "";
|
|
1106
|
-
const
|
|
1107
|
-
? `<script src="${escapeAttribute(input.
|
|
1304
|
+
const clientScript = input.scriptPath
|
|
1305
|
+
? `<script src="${escapeAttribute(input.scriptPath)}" defer></script>`
|
|
1108
1306
|
: "";
|
|
1109
1307
|
return `<!doctype html>
|
|
1110
1308
|
<html lang="zh-CN">
|
|
@@ -1230,7 +1428,7 @@ function renderViewerPage(input: {
|
|
|
1230
1428
|
<div class="meta"><span class="metadata-values" id="viewer-metadata">${metadata}</span>${toolbar}</div>
|
|
1231
1429
|
</header>
|
|
1232
1430
|
<main id="viewer-content">${input.content}</main>
|
|
1233
|
-
${
|
|
1431
|
+
${clientScript}
|
|
1234
1432
|
</body>
|
|
1235
1433
|
</html>`;
|
|
1236
1434
|
}
|
|
@@ -1385,11 +1583,26 @@ async function readGitDiffPreview(filePath: string): Promise<string | undefined>
|
|
|
1385
1583
|
text = preview.text;
|
|
1386
1584
|
}
|
|
1387
1585
|
const diff = await readGitFileDiff(filePath);
|
|
1388
|
-
|
|
1586
|
+
let content = diff ? renderGitFileDiff(diff, text, (value) => highlightTextLines(value, filePath)) : undefined;
|
|
1587
|
+
if (!content && !fs.lstatSync(filePath, { throwIfNoEntry: false })?.isSymbolicLink()) {
|
|
1588
|
+
let directory = path.dirname(filePath);
|
|
1589
|
+
while (!fs.existsSync(directory)) {
|
|
1590
|
+
const parent = path.dirname(directory); if (parent === directory) return undefined; directory = parent;
|
|
1591
|
+
}
|
|
1592
|
+
const root = fs.realpathSync(directory), entry = path.relative(directory, filePath).split(path.sep).join("/");
|
|
1593
|
+
const versions = await readWorkspaceFileVersions(root, entry, "all");
|
|
1594
|
+
if (!versions.beforeExists) return undefined;
|
|
1595
|
+
const previous = classifyContentSample(versions.before, true), current = classifyContentSample(versions.after, true);
|
|
1596
|
+
if (previous.kind !== "text" || current.kind !== "text") return undefined;
|
|
1597
|
+
const previousText = decodeText(versions.before, previous.encoding, true), currentText = decodeText(versions.after, current.encoding, true);
|
|
1598
|
+
const patch = await createWorkspaceDiff(root, previousText, currentText);
|
|
1599
|
+
if (!patch) return undefined;
|
|
1600
|
+
content = renderGitFileDiff(patch, currentText, (value) => highlightTextLines(value, filePath));
|
|
1601
|
+
}
|
|
1389
1602
|
const after = fs.statSync(filePath, { throwIfNoEntry: false });
|
|
1390
1603
|
if (before?.size !== after?.size || before?.mtimeMs !== after?.mtimeMs || before?.ctimeMs !== after?.ctimeMs
|
|
1391
1604
|
|| before?.ino !== after?.ino || before?.dev !== after?.dev) return undefined;
|
|
1392
|
-
return
|
|
1605
|
+
return content;
|
|
1393
1606
|
} catch {
|
|
1394
1607
|
return undefined;
|
|
1395
1608
|
}
|
|
@@ -1491,11 +1704,7 @@ function hasTextLikeCharacters(value: string): boolean {
|
|
|
1491
1704
|
}
|
|
1492
1705
|
|
|
1493
1706
|
function renderText(value: string, filePath: string): string {
|
|
1494
|
-
const
|
|
1495
|
-
const language = syntaxLanguageFor(filePath);
|
|
1496
|
-
const lines = language && Buffer.byteLength(normalized, "utf8") <= MAX_SYNTAX_HIGHLIGHT_BYTES
|
|
1497
|
-
? highlightLines(normalized, language)
|
|
1498
|
-
: normalized.split("\n").map(escapeHtml);
|
|
1707
|
+
const language = syntaxLanguageFor(filePath), lines = highlightTextLines(value, filePath);
|
|
1499
1708
|
const languageClass = language ? ` class="language-${escapeAttribute(language)}"` : "";
|
|
1500
1709
|
return `<pre class="code hljs"><code${languageClass}>${lines.map((line, index) => {
|
|
1501
1710
|
const lineNumber = index + 1;
|
|
@@ -1503,6 +1712,14 @@ function renderText(value: string, filePath: string): string {
|
|
|
1503
1712
|
}).join("")}</code></pre>`;
|
|
1504
1713
|
}
|
|
1505
1714
|
|
|
1715
|
+
function highlightTextLines(value: string, filePath: string): string[] {
|
|
1716
|
+
const normalized = value.replace(/\r\n?/gu, "\n");
|
|
1717
|
+
const language = syntaxLanguageFor(filePath);
|
|
1718
|
+
return language && Buffer.byteLength(normalized, "utf8") <= MAX_SYNTAX_HIGHLIGHT_BYTES
|
|
1719
|
+
? highlightLines(normalized, language)
|
|
1720
|
+
: normalized.split("\n").map(escapeHtml);
|
|
1721
|
+
}
|
|
1722
|
+
|
|
1506
1723
|
function renderMarkdownDocument(value: string, filePath: string, createPreviewUrl: (filePath: string) => URL): string {
|
|
1507
1724
|
const environment = {};
|
|
1508
1725
|
const tokens = MARKDOWN_RENDERER.parse(value, environment);
|
|
@@ -1516,9 +1733,10 @@ function isMarkdownFile(filePath: string): boolean {
|
|
|
1516
1733
|
}
|
|
1517
1734
|
|
|
1518
1735
|
function syntaxLanguageFor(filePath: string): string | undefined {
|
|
1736
|
+
if (isMarkdownFile(filePath)) return "markdown";
|
|
1519
1737
|
const fileName = path.basename(filePath).toLowerCase();
|
|
1520
|
-
return HIGHLIGHT_LANGUAGE_BY_FILENAME[fileName]
|
|
1521
|
-
|
|
1738
|
+
return Object.hasOwn(HIGHLIGHT_LANGUAGE_BY_FILENAME, fileName) ? HIGHLIGHT_LANGUAGE_BY_FILENAME[fileName]
|
|
1739
|
+
: HIGHLIGHT_LANGUAGE_BY_EXTENSION[path.extname(fileName)];
|
|
1522
1740
|
}
|
|
1523
1741
|
|
|
1524
1742
|
function highlightLines(value: string, language: string): string[] {
|
|
@@ -10,6 +10,7 @@ export function rewriteMarkdownFileLinks(
|
|
|
10
10
|
tokens: Token[],
|
|
11
11
|
markdownPath: string | undefined,
|
|
12
12
|
createPreviewUrl: (filePath: string) => URL | undefined,
|
|
13
|
+
createImageUrl?: (filePath: string) => URL | undefined,
|
|
13
14
|
): void {
|
|
14
15
|
for (const token of tokens) {
|
|
15
16
|
const attribute = token.type === "link_open" ? "href" : token.type === "image" ? "src" : undefined;
|
|
@@ -17,10 +18,11 @@ export function rewriteMarkdownFileLinks(
|
|
|
17
18
|
if (attribute && typeof target === "string" && target) {
|
|
18
19
|
const local = resolveLocalTarget(target, markdownPath);
|
|
19
20
|
if (local) {
|
|
20
|
-
const
|
|
21
|
+
const image = token.type === "image";
|
|
22
|
+
const url = image && createImageUrl ? createImageUrl(local.filePath) : createPreviewUrl(local.filePath);
|
|
21
23
|
if (url) {
|
|
22
24
|
url.hash = local.hash;
|
|
23
|
-
if (
|
|
25
|
+
if (image && !createImageUrl) url.searchParams.set("raw", "1");
|
|
24
26
|
token.attrSet(attribute, url.toString());
|
|
25
27
|
} else {
|
|
26
28
|
token.attrs = token.attrs?.filter(([name]) => name !== attribute) ?? null;
|
|
@@ -30,7 +32,7 @@ export function rewriteMarkdownFileLinks(
|
|
|
30
32
|
token.attrs = token.attrs?.filter(([name]) => name !== attribute) ?? null;
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
|
-
if (token.children) rewriteMarkdownFileLinks(token.children, markdownPath, createPreviewUrl);
|
|
35
|
+
if (token.children) rewriteMarkdownFileLinks(token.children, markdownPath, createPreviewUrl, createImageUrl);
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
38
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { approvalActivityId } from "../presentation/TurnStateReducer.js";
|
|
3
|
-
import { isSettledTurnStatus } from "../presentation/turnStatus.js";
|
|
3
|
+
import { isSettledTurnStatus, modelQueueLabel } from "../presentation/turnStatus.js";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { enableDiagramFences, DIAGRAM_PREVIEW_CLIENT_SCRIPT, DIAGRAM_PREVIEW_CSS } from "./DiagramPreview.js";
|
|
6
6
|
import MarkdownIt from "markdown-it";
|
|
@@ -10,6 +10,7 @@ import type { FileSummary, TurnActivity, TurnReasoningItem, TurnViewState, TurnV
|
|
|
10
10
|
import { displayFilePath, displayToolCommand, formatShellCommandForDisplay, toolStatusIcon } from "../feishu/CardRenderer.js";
|
|
11
11
|
import { turnReasoningItems } from "../presentation/turnReasoning.js";
|
|
12
12
|
import { visibleTurnActivities } from "../presentation/visibleTurnActivities.js";
|
|
13
|
+
import { formatModelQueueDuration, liveModelQueueActivity, systemActivityQuote, USER_ACTIVITY_ICON } from "../presentation/turnActivity.js";
|
|
13
14
|
import { displayRuntimeError } from "../runtime/responseErrors.js";
|
|
14
15
|
import { isFileUrl, rewriteMarkdownFileLinks } from "./MarkdownFileLinks.js";
|
|
15
16
|
|
|
@@ -272,6 +273,15 @@ export const TURN_PREVIEW_CLIENT_SCRIPT = DIAGRAM_PREVIEW_CLIENT_SCRIPT + `(() =
|
|
|
272
273
|
: remainder > 0 ? String(remainder) + "s" : "";
|
|
273
274
|
element.textContent = element.dataset.shortDuration === "1" ? shortDuration : labels.elapsed + duration;
|
|
274
275
|
});
|
|
276
|
+
document.querySelectorAll("[data-live-queue-duration]").forEach((element) => {
|
|
277
|
+
const startedAt = Number(element.dataset.startedAt);
|
|
278
|
+
if (!Number.isFinite(startedAt)) return;
|
|
279
|
+
const seconds = Math.max(0, Math.floor((Date.now() - startedAt) / 1000));
|
|
280
|
+
const hours = Math.floor(seconds / 3600);
|
|
281
|
+
const minutes = Math.floor((seconds % 3600) / 60);
|
|
282
|
+
const time = String(minutes).padStart(2, "0") + ":" + String(seconds % 60).padStart(2, "0");
|
|
283
|
+
element.textContent = hours > 0 ? String(hours).padStart(2, "0") + ":" + time : time;
|
|
284
|
+
});
|
|
275
285
|
};
|
|
276
286
|
updateElapsed();
|
|
277
287
|
let clock = terminalAtLoad ? undefined : setInterval(updateElapsed, 1000);
|
|
@@ -654,6 +664,7 @@ export function isTurnPreviewState(value: unknown): value is TurnViewState {
|
|
|
654
664
|
}
|
|
655
665
|
|
|
656
666
|
export function renderTurnPreviewPage(input: {
|
|
667
|
+
workspaceUrl?: string;
|
|
657
668
|
state: TurnViewState;
|
|
658
669
|
eventsUrl: string;
|
|
659
670
|
scriptPath: string;
|
|
@@ -678,6 +689,7 @@ export function renderTurnPreviewPage(input: {
|
|
|
678
689
|
<div class="header-top">
|
|
679
690
|
<h1 title="Turn ${escapeAttribute(input.state.turnId)}">Turn Preview</h1>
|
|
680
691
|
<span id="turn-status" class="status ${snapshot.status}" role="status">${escapeHtml(snapshot.statusLabel)}</span>
|
|
692
|
+
${input.workspaceUrl ? '<a class="workspace-link" href="' + escapeAttribute(input.workspaceUrl) + '">Workspace</a>' : ""}
|
|
681
693
|
<span id="turn-live" class="live ${snapshot.terminal ? "terminal" : "connected"}" role="status">${snapshot.terminal ? "" : escapeHtml(previewLabels(language).live)}</span>
|
|
682
694
|
</div>
|
|
683
695
|
<div id="turn-metadata" class="metadata">${snapshot.metadata}</div>
|
|
@@ -754,7 +766,7 @@ export function renderTurnPreviewSnapshot(
|
|
|
754
766
|
content: sections,
|
|
755
767
|
metadata: renderMetadata(state, language),
|
|
756
768
|
status: state.status,
|
|
757
|
-
statusLabel: statusLabel(state.status, language),
|
|
769
|
+
statusLabel: modelQueueLabel(state, language) ?? statusLabel(state.status, language),
|
|
758
770
|
terminal,
|
|
759
771
|
};
|
|
760
772
|
}
|
|
@@ -819,11 +831,13 @@ function renderTimeline(
|
|
|
819
831
|
}
|
|
820
832
|
const renderReasoning = (position: number): string => (reasoning.get(position) ?? [])
|
|
821
833
|
.map((item) => renderReasoningItem(item, state.projectCwd, localFileUrl, language, deferDetails)).join("");
|
|
834
|
+
const queue = liveModelQueueActivity(state);
|
|
822
835
|
return renderReasoning(-1) + activities.map((activity, index) => {
|
|
823
836
|
const visible = activity.kind === "reasoning"
|
|
824
837
|
? activity.id.startsWith("commentary:") ? { ...activity, kind: "assistant" as const } : undefined
|
|
825
838
|
: activity;
|
|
826
|
-
return (visible ? renderActivity(visible, renderText, localFileUrl, fullToolOutputs, fullToolErrors, language, projectCwd, deferDetails
|
|
839
|
+
return (visible ? renderActivity(visible, renderText, localFileUrl, fullToolOutputs, fullToolErrors, language, projectCwd, deferDetails,
|
|
840
|
+
visible.kind === "system" && visible.category === "model_queue" && visible.id === queue?.id ? queue : undefined) : "")
|
|
827
841
|
+ renderReasoning(index);
|
|
828
842
|
}).join("");
|
|
829
843
|
}
|
|
@@ -908,22 +922,31 @@ function renderActivity(
|
|
|
908
922
|
language: TurnPreviewLanguage = "zh",
|
|
909
923
|
projectCwd?: string,
|
|
910
924
|
deferDetails = false,
|
|
925
|
+
queue?: ReturnType<typeof liveModelQueueActivity>,
|
|
911
926
|
): string {
|
|
912
927
|
switch (activity.kind) {
|
|
928
|
+
case "system":
|
|
929
|
+
if (queue) {
|
|
930
|
+
const timer = `<span data-live-queue-duration data-started-at="${queue.startedAt}">${formatModelQueueDuration(Date.now() - queue.startedAt)}</span>`;
|
|
931
|
+
return `<article class="activity message system model_queue" data-activity="${escapeAttribute(activity.id)}"><div class="markdown"><blockquote><p>${escapeHtml(queue.label)} · ${language === "zh" ? "已等待" : "Waited"} ${timer}。</p></blockquote></div></article>`;
|
|
932
|
+
}
|
|
933
|
+
return renderMessageActivity(activity.id, systemActivityQuote(activity.text), `system ${activity.category}`, renderText);
|
|
913
934
|
case "assistant":
|
|
914
935
|
if (activity.id.startsWith("commentary:runtime-error:")) {
|
|
915
936
|
return `<article class="activity message runtime-error" data-activity="${escapeAttribute(activity.id)}"><pre>${escapeHtml(displayRuntimeError(activity.text))}</pre></article>`;
|
|
916
937
|
}
|
|
917
938
|
return renderMessageActivity(activity.id, activity.text, "commentary", renderText);
|
|
918
939
|
case "user":
|
|
919
|
-
return renderMessageActivity(activity.id, activity.text, "user", renderText,
|
|
940
|
+
return renderMessageActivity(activity.id, activity.text, "user", renderText,
|
|
941
|
+
renderMessageImages(activity.localImagePaths, localFileUrl, language), language === "zh" ? "用户补充" : "User message");
|
|
920
942
|
case "tool":
|
|
921
943
|
return renderToolActivity(activity.id, activity.tool, localFileUrl, fullToolOutputs, fullToolErrors, language, projectCwd, deferDetails);
|
|
922
944
|
}
|
|
923
945
|
}
|
|
924
946
|
|
|
925
|
-
function renderMessageActivity(id: string, text: string, kind: string, renderText: (value: string) => string, images = ""): string {
|
|
926
|
-
|
|
947
|
+
function renderMessageActivity(id: string, text: string, kind: string, renderText: (value: string) => string, images = "", userLabel?: string): string {
|
|
948
|
+
const icon = userLabel ? `<span class="message-icon" role="img" aria-label="${escapeAttribute(userLabel)}">${USER_ACTIVITY_ICON}</span>` : "";
|
|
949
|
+
return `<article class="activity message ${kind}${icon ? " with-icon" : ""}" data-activity="${escapeAttribute(id)}">${icon}<div class="markdown">${renderText(text)}${images}</div></article>`;
|
|
927
950
|
}
|
|
928
951
|
|
|
929
952
|
function renderMessageImages(paths: string[] | undefined, localFileUrl: PreviewFileUrl | undefined, language: TurnPreviewLanguage): string {
|
|
@@ -1376,12 +1399,13 @@ body { margin: 0; background: var(--page); color: var(--text); font-size: 13px;
|
|
|
1376
1399
|
.page-header { position: sticky; top: 0; z-index: 3; background: var(--page); border-bottom: 1px solid var(--line); }
|
|
1377
1400
|
.header-inner { display: flex; flex-wrap: wrap; align-items: center; gap: 3px 12px; max-width: 1320px; margin: auto; padding: 6px 20px; }
|
|
1378
1401
|
.header-top { display: flex; flex-wrap: wrap; align-items: center; min-width: 0; max-width: 100%; gap: 2px 8px; }
|
|
1402
|
+
.workspace-link { display: inline-flex; align-items: center; gap: 8px; color: var(--accent); white-space: nowrap; font-size: 12px; text-decoration: none; }
|
|
1379
1403
|
h1 { flex: none; margin: 0; font-size: 14px; line-height: 20px; font-weight: 650; }
|
|
1380
1404
|
h2 { margin: 0 0 8px; font-size: 13px; font-weight: 650; }
|
|
1381
1405
|
h2 span { margin-left: 6px; color: var(--muted); font-size: 12px; font-weight: 400; }
|
|
1382
1406
|
.status, .live { flex: none; font-size: 12px; white-space: nowrap; }
|
|
1383
1407
|
.status { display: inline-flex; align-items: center; gap: 8px; }
|
|
1384
|
-
.status::before { content: "·"; color: var(--muted); }
|
|
1408
|
+
.status::before, .workspace-link::before { content: "·"; color: var(--muted); }
|
|
1385
1409
|
.status.starting, .status.running, .status.tool_running, .tool-state.running { color: var(--accent); }
|
|
1386
1410
|
.status.waiting_for_approval, .status.unknown { color: #926a08; }
|
|
1387
1411
|
.status.completed, .tool-state.completed { color: var(--success); }
|
|
@@ -1410,6 +1434,8 @@ main { max-width: 1320px; margin: 0 auto; padding: 0 20px 40px; }
|
|
|
1410
1434
|
.timeline { padding-top: 2px; }
|
|
1411
1435
|
.activity { min-width: 0; }
|
|
1412
1436
|
.message { padding: 12px 0; }
|
|
1437
|
+
.message.with-icon { display: grid; grid-template-columns: 20px minmax(0, 1fr); column-gap: 6px; }
|
|
1438
|
+
.message-icon { font-size: 14px; line-height: 1.6; }
|
|
1413
1439
|
.prompt { border-bottom: 1px solid var(--line); }
|
|
1414
1440
|
.timeline .markdown hr { display: none; }
|
|
1415
1441
|
.markdown { min-width: 0; overflow-wrap: anywhere; }
|
|
@@ -1428,7 +1454,7 @@ main { max-width: 1320px; margin: 0 auto; padding: 0 20px 40px; }
|
|
|
1428
1454
|
.markdown a { color: var(--accent); text-underline-offset: 2px; }
|
|
1429
1455
|
.markdown table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; }
|
|
1430
1456
|
.markdown th, .markdown td { padding: 5px 8px; border: 1px solid var(--line); }
|
|
1431
|
-
.markdown img { max-width: 100%; height: auto; }
|
|
1457
|
+
.markdown img, .tool-image img { width: auto; max-width: 100%; height: auto; max-height: min(720px, 60svh); }
|
|
1432
1458
|
code { padding: 1px 3px; border-radius: 3px; background: var(--surface); font: 12px/1.55 "Cascadia Mono", "SFMono-Regular", Consolas, monospace; overflow-wrap: anywhere; }
|
|
1433
1459
|
pre { max-width: 100%; max-height: 480px; margin: 0; padding: 9px 12px; overflow: auto; background: var(--code); color: var(--text); font: 12px/1.55 "Cascadia Mono", "SFMono-Regular", Consolas, monospace; tab-size: 2; white-space: pre; }
|
|
1434
1460
|
.markdown pre code { padding: 0; background: transparent; color: inherit; }
|
|
@@ -1498,7 +1524,7 @@ summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px;
|
|
|
1498
1524
|
.detail-message { padding: 8px 12px; color: var(--muted); }
|
|
1499
1525
|
.detail-message:empty { display: none; }
|
|
1500
1526
|
.detail-message button { margin-left: 8px; cursor: pointer; }
|
|
1501
|
-
.tool-image img { display: block;
|
|
1527
|
+
.tool-image img { display: block; }
|
|
1502
1528
|
.final-result h2 { color: var(--success); }
|
|
1503
1529
|
.approval-reason { white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
1504
1530
|
.approval-reason:empty { display: none; }
|