@keyou007/agent-bot 0.1.27-alpha.3 → 0.1.27-alpha.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/CHANGELOG.md +18 -0
- package/README.md +77 -12
- package/README.zh.md +77 -12
- package/assets/agent-bot.ico +0 -0
- package/assets/roboto-mono-OFL.txt +93 -0
- package/assets/roboto-mono-latin.woff2 +0 -0
- package/assets/workspace-drafts.js +88 -0
- package/assets/workspace-sessions.js +1935 -232
- package/assets/workspace.css +360 -35
- package/assets/workspace.js +2115 -249
- package/dist/cli/SelfUpdateObserver.js +124 -0
- package/dist/cli/SelfUpdateObserver.js.map +1 -0
- package/dist/cli/SelfUpdateRunner.js +267 -70
- package/dist/cli/SelfUpdateRunner.js.map +1 -1
- package/dist/cli/SelfUpdater.js +54 -15
- package/dist/cli/SelfUpdater.js.map +1 -1
- package/dist/cli/controlProtocol.js.map +1 -1
- package/dist/cli/help.js +6 -0
- package/dist/cli/help.js.map +1 -1
- package/dist/cli.js +85 -6
- package/dist/cli.js.map +1 -1
- package/dist/codex/CodexEventMapper.js +29 -5
- package/dist/codex/CodexEventMapper.js.map +1 -1
- package/dist/codex/CodexRuntime.js +3 -0
- package/dist/codex/CodexRuntime.js.map +1 -1
- package/dist/feishu/CardRenderer.js +45 -13
- package/dist/feishu/CardRenderer.js.map +1 -1
- package/dist/feishu/ConsoleFeishuClient.js +4 -0
- package/dist/feishu/ConsoleFeishuClient.js.map +1 -1
- package/dist/feishu/FeishuMarkdown.js +2 -14
- package/dist/feishu/FeishuMarkdown.js.map +1 -1
- package/dist/feishu/FeishuMessageClient.js +9 -0
- package/dist/feishu/FeishuMessageClient.js.map +1 -1
- package/dist/feishu/FeishuTurnPresenter.js +26 -14
- package/dist/feishu/FeishuTurnPresenter.js.map +1 -1
- package/dist/index.js +47 -12
- package/dist/index.js.map +1 -1
- package/dist/local-files/DiagramPreview.js +11 -6
- package/dist/local-files/DiagramPreview.js.map +1 -1
- package/dist/local-files/GitDiffPreview.js +40 -10
- package/dist/local-files/GitDiffPreview.js.map +1 -1
- package/dist/local-files/LiveMarkup.js +104 -0
- package/dist/local-files/LiveMarkup.js.map +1 -0
- package/dist/local-files/LocalFileViewerServer.js +133 -117
- package/dist/local-files/LocalFileViewerServer.js.map +1 -1
- package/dist/local-files/MarkdownExport.js +54 -0
- package/dist/local-files/MarkdownExport.js.map +1 -0
- package/dist/local-files/PreviewCodeFont.js +11 -0
- package/dist/local-files/PreviewCodeFont.js.map +1 -0
- package/dist/local-files/PreviewSyntaxHighlight.js +73 -0
- package/dist/local-files/PreviewSyntaxHighlight.js.map +1 -1
- package/dist/local-files/ToolCommandDisplay.js +111 -0
- package/dist/local-files/ToolCommandDisplay.js.map +1 -0
- package/dist/local-files/TurnPreviewPage.js +23 -269
- package/dist/local-files/TurnPreviewPage.js.map +1 -1
- package/dist/local-files/WorkspaceFileEvents.js +206 -0
- package/dist/local-files/WorkspaceFileEvents.js.map +1 -0
- package/dist/local-files/WorkspaceFiles.js +79 -3
- package/dist/local-files/WorkspaceFiles.js.map +1 -1
- package/dist/local-files/WorkspaceImages.js +15 -0
- package/dist/local-files/WorkspaceImages.js.map +1 -0
- package/dist/local-files/WorkspacePage.js +20 -5
- package/dist/local-files/WorkspacePage.js.map +1 -1
- package/dist/local-files/WorkspaceSessions.js +881 -79
- package/dist/local-files/WorkspaceSessions.js.map +1 -1
- package/dist/local-files/WorkspaceTimeline.js +105 -0
- package/dist/local-files/WorkspaceTimeline.js.map +1 -0
- package/dist/presentation/OutboundRouter.js +13 -6
- package/dist/presentation/OutboundRouter.js.map +1 -1
- package/dist/presentation/TurnStateReducer.js +28 -21
- package/dist/presentation/TurnStateReducer.js.map +1 -1
- package/dist/proxy/ProxySessionController.js +229 -92
- package/dist/proxy/ProxySessionController.js.map +1 -1
- package/dist/proxy/TaskMetadata.js +86 -0
- package/dist/proxy/TaskMetadata.js.map +1 -0
- package/dist/scheduling/ScheduleCards.js +10 -4
- package/dist/scheduling/ScheduleCards.js.map +1 -1
- package/dist/scheduling/ScheduleCommand.js +4 -0
- package/dist/scheduling/ScheduleCommand.js.map +1 -1
- package/dist/scheduling/ScheduledTaskStore.js +51 -12
- package/dist/scheduling/ScheduledTaskStore.js.map +1 -1
- package/dist/scheduling/types.js +18 -4
- package/dist/scheduling/types.js.map +1 -1
- package/dist/state/StateStore.js +145 -19
- package/dist/state/StateStore.js.map +1 -1
- package/dist/state/TurnPreviewJournal.js +143 -36
- package/dist/state/TurnPreviewJournal.js.map +1 -1
- package/dist/state/TurnToolText.js +172 -0
- package/dist/state/TurnToolText.js.map +1 -0
- package/dist/state/migrations.js +4 -0
- package/dist/state/migrations.js.map +1 -1
- package/dist/supervision/SafeRestartNotifier.js +9 -6
- package/dist/supervision/SafeRestartNotifier.js.map +1 -1
- package/dist/terminal/TerminalPage.js +5 -0
- package/dist/terminal/TerminalPage.js.map +1 -1
- package/dist/updates/AutomaticUpdatePreparer.js +63 -12
- package/dist/updates/AutomaticUpdatePreparer.js.map +1 -1
- package/dist/updates/ManualUpdateController.js +7 -2
- package/dist/updates/ManualUpdateController.js.map +1 -1
- package/dist/utils/promptAttachments.js +20 -0
- package/dist/utils/promptAttachments.js.map +1 -0
- package/dist/utils/toolTimestamp.js +6 -0
- package/dist/utils/toolTimestamp.js.map +1 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/skills/agent-bot/SKILL.md +23 -2
- package/src/cli/SelfUpdateObserver.ts +111 -0
- package/src/cli/SelfUpdateRunner.ts +271 -85
- package/src/cli/SelfUpdater.ts +53 -16
- package/src/cli/controlProtocol.ts +1 -0
- package/src/cli/help.ts +6 -0
- package/src/cli.ts +71 -5
- package/src/codex/CodexEventMapper.ts +25 -5
- package/src/codex/CodexRuntime.ts +4 -0
- package/src/feishu/CardRenderer.ts +48 -13
- package/src/feishu/ConsoleFeishuClient.ts +6 -1
- package/src/feishu/FeishuMarkdown.ts +2 -14
- package/src/feishu/FeishuMessageClient.ts +10 -0
- package/src/feishu/FeishuTurnPresenter.ts +22 -8
- package/src/feishu/types.ts +1 -0
- package/src/index.ts +47 -12
- package/src/local-files/DiagramPreview.ts +11 -6
- package/src/local-files/GitDiffPreview.ts +38 -10
- package/src/local-files/LiveMarkup.ts +103 -0
- package/src/local-files/LocalFileViewerServer.ts +120 -120
- package/src/local-files/MarkdownExport.ts +54 -0
- package/src/local-files/PreviewCodeFont.ts +12 -0
- package/src/local-files/PreviewSyntaxHighlight.ts +75 -0
- package/src/local-files/ToolCommandDisplay.ts +104 -0
- package/src/local-files/TurnPreviewPage.ts +23 -254
- package/src/local-files/WorkspaceFileEvents.ts +186 -0
- package/src/local-files/WorkspaceFiles.ts +72 -5
- package/src/local-files/WorkspaceImages.ts +10 -0
- package/src/local-files/WorkspacePage.ts +20 -5
- package/src/local-files/WorkspaceSessions.ts +811 -82
- package/src/local-files/WorkspaceTimeline.ts +109 -0
- package/src/presentation/OutboundRouter.ts +15 -4
- package/src/presentation/TurnStateReducer.ts +27 -18
- package/src/presentation/turnViewTypes.ts +2 -0
- package/src/proxy/ProxySessionController.ts +226 -77
- package/src/proxy/TaskMetadata.ts +81 -0
- package/src/runtime/types.ts +2 -1
- package/src/scheduling/ScheduleCards.ts +10 -4
- package/src/scheduling/ScheduleCommand.ts +4 -0
- package/src/scheduling/ScheduledTaskStore.ts +54 -9
- package/src/scheduling/types.ts +24 -4
- package/src/state/StateStore.ts +157 -20
- package/src/state/TurnPreviewJournal.ts +138 -34
- package/src/state/TurnToolText.ts +156 -0
- package/src/state/migrations.ts +4 -0
- package/src/supervision/SafeRestartNotifier.ts +9 -6
- package/src/terminal/TerminalPage.ts +5 -0
- package/src/updates/AutomaticUpdatePreparer.ts +52 -11
- package/src/updates/ManualUpdateController.ts +8 -3
- package/src/utils/promptAttachments.ts +24 -0
- package/src/utils/toolTimestamp.ts +5 -0
|
@@ -75,7 +75,7 @@ export interface SafeRestartStatusView {
|
|
|
75
75
|
remainingMs?: number;
|
|
76
76
|
pendingFinalDeliveries: number;
|
|
77
77
|
waitingTasks: Array<{
|
|
78
|
-
|
|
78
|
+
prompt?: string;
|
|
79
79
|
localSessionId: string;
|
|
80
80
|
isRunning: boolean;
|
|
81
81
|
title?: string;
|
|
@@ -89,6 +89,7 @@ export interface PromptQueueCardView {
|
|
|
89
89
|
prompts: Array<{
|
|
90
90
|
id: string;
|
|
91
91
|
text: string;
|
|
92
|
+
hasImages?: boolean;
|
|
92
93
|
}>;
|
|
93
94
|
}
|
|
94
95
|
|
|
@@ -316,6 +317,8 @@ export interface AppServerReleaseCardView {
|
|
|
316
317
|
}
|
|
317
318
|
|
|
318
319
|
export class CardRenderer {
|
|
320
|
+
constructor(private readonly fileChangeUrl?: (filePath: string) => string | undefined) {}
|
|
321
|
+
|
|
319
322
|
renderThreadWriterConflict(view: ThreadWriterConflictCardView): Record<string, unknown> {
|
|
320
323
|
if (view.status === "released") {
|
|
321
324
|
return sectionCard("任务占用已解除", [markdown([
|
|
@@ -941,7 +944,7 @@ export class CardRenderer {
|
|
|
941
944
|
vertical_align: "center",
|
|
942
945
|
elements: [markdown(
|
|
943
946
|
escapeCardHtml(
|
|
944
|
-
`${index + 1}. ${truncateText(prompt.text.replace(/\s+/g, " ").trim(), 180)}`,
|
|
947
|
+
`${index + 1}. ${truncateText(prompt.text.replace(/\s+/g, " ").trim(), 180)}${prompt.hasImages ? " [图片]" : ""}`,
|
|
945
948
|
),
|
|
946
949
|
)],
|
|
947
950
|
},
|
|
@@ -1096,7 +1099,8 @@ export class CardRenderer {
|
|
|
1096
1099
|
const visible = view.waitingTasks.slice(0, 10);
|
|
1097
1100
|
elements.push({ tag: "hr" }, markdown(`**当前等待的任务(${view.waitingTasks.length})**`));
|
|
1098
1101
|
for (const [index, task] of visible.entries()) {
|
|
1099
|
-
const
|
|
1102
|
+
const prompt = task.prompt?.replace(/\s+/gu, " ").trim() || (task.isRunning ? "Prompt 暂不可用" : "等待执行");
|
|
1103
|
+
const label = `${index + 1}. ${task.title ? `**${escapeCardMarkdownText(truncateText(task.title, 80))}** · ` : ""}${escapeCardMarkdownText(truncateText(prompt, 40))}`;
|
|
1100
1104
|
elements.push({
|
|
1101
1105
|
tag: "column_set",
|
|
1102
1106
|
flex_mode: "none",
|
|
@@ -1281,7 +1285,7 @@ export class CardRenderer {
|
|
|
1281
1285
|
}
|
|
1282
1286
|
|
|
1283
1287
|
renderTurn(state: TurnViewState, previewUrl?: string): Record<string, unknown> {
|
|
1284
|
-
const elements = renderGroupedTurnElements(state, "hidden");
|
|
1288
|
+
const elements = renderGroupedTurnElements(state, "hidden", this.fileChangeUrl);
|
|
1285
1289
|
const footerActions: TaskListCardAction[] = [];
|
|
1286
1290
|
if (isTurnStoppable(state.status)) {
|
|
1287
1291
|
footerActions.push({
|
|
@@ -1382,7 +1386,7 @@ export class CardRenderer {
|
|
|
1382
1386
|
} else if (state.historyDetail === "summary") {
|
|
1383
1387
|
elements.push(markdown("当前仅保存轮次摘要,尚未加载历史执行详情。"));
|
|
1384
1388
|
}
|
|
1385
|
-
elements.push(...renderGroupedTurnElements(state, "always"));
|
|
1389
|
+
elements.push(...renderGroupedTurnElements(state, "always", this.fileChangeUrl));
|
|
1386
1390
|
if (previewUrl) elements.push(taskActionRow([turnPreviewAction(previewUrl)]));
|
|
1387
1391
|
return turnCard(title, "blue", elements, renderTurnSubtitle(state));
|
|
1388
1392
|
}
|
|
@@ -1777,6 +1781,7 @@ function isTurnStoppable(status: TurnViewStatus): boolean {
|
|
|
1777
1781
|
function renderGroupedTurnElements(
|
|
1778
1782
|
state: TurnViewState,
|
|
1779
1783
|
assistantTextMode: "hidden" | "always",
|
|
1784
|
+
fileChangeUrl?: (filePath: string) => string | undefined,
|
|
1780
1785
|
): Record<string, unknown>[] {
|
|
1781
1786
|
const elements: Record<string, unknown>[] = [];
|
|
1782
1787
|
const allActivities = turnActivities(state);
|
|
@@ -1800,7 +1805,7 @@ function renderGroupedTurnElements(
|
|
|
1800
1805
|
? [{ kind: "gap", id: "gap:truncated" }, ...visible.groups]
|
|
1801
1806
|
: visible.groups;
|
|
1802
1807
|
elements.push(...renderGroupedActivityGroups(visibleGroups, state.projectCwd));
|
|
1803
|
-
if (state.fileSummary.length > 0) elements.push(fileSummaryPanel(state));
|
|
1808
|
+
if (state.fileSummary.length > 0) elements.push(fileSummaryPanel(state, fileChangeUrl));
|
|
1804
1809
|
|
|
1805
1810
|
if (state.approval) elements.push(...renderApprovalElements(state, state.approval));
|
|
1806
1811
|
if (state.statusMessage) elements.push(markdown(codeBlock(state.statusMessage, 2_000)));
|
|
@@ -1811,7 +1816,17 @@ function renderGroupedTurnElements(
|
|
|
1811
1816
|
const heading = state.status === "completed" ? "回答" : "回答生成中";
|
|
1812
1817
|
elements.push(markdown(`**${heading}**\n${truncateText(state.assistantText, 3_000)}`));
|
|
1813
1818
|
}
|
|
1814
|
-
if (elements.length === 0)
|
|
1819
|
+
if (elements.length === 0) {
|
|
1820
|
+
if (state.status === "starting" || state.status === "running" || state.status === "tool_running") {
|
|
1821
|
+
const value = (text: string | undefined, fallback: string): string =>
|
|
1822
|
+
escapeCardMarkdownText(text?.trim().replace(/[\r\n]+/g, " ") || fallback);
|
|
1823
|
+
elements.push({
|
|
1824
|
+
...markdown(`Model: ${value(state.model, "默认")} · ${value(state.reasoningEffort, "自动")}`),
|
|
1825
|
+
text_size: "notation",
|
|
1826
|
+
});
|
|
1827
|
+
}
|
|
1828
|
+
elements.push(markdown(emptyTurnText(state.status, state.agentLabel)));
|
|
1829
|
+
}
|
|
1815
1830
|
return elements;
|
|
1816
1831
|
}
|
|
1817
1832
|
|
|
@@ -1823,8 +1838,8 @@ function renderApprovalElements(state: TurnViewState, request: ApprovalRequest):
|
|
|
1823
1838
|
const reason = request.reason?.trim()
|
|
1824
1839
|
|| (request.title.trim() !== command ? request.title.trim() : "");
|
|
1825
1840
|
if (reason && reason !== command) {
|
|
1826
|
-
const preview = approvalTextPreview(reason, 1_000,
|
|
1827
|
-
elements.push(markdown(
|
|
1841
|
+
const preview = approvalTextPreview(reason, 1_000, escapeCardMarkdownText);
|
|
1842
|
+
elements.push(markdown(escapeCardMarkdownText(preview)));
|
|
1828
1843
|
if (preview !== reason) elements.push(markdown("<font color='grey'>说明较长,请在 Preview 中查看完整内容。</font>"));
|
|
1829
1844
|
}
|
|
1830
1845
|
const display = displayToolCommand(command) ?? command;
|
|
@@ -1888,7 +1903,7 @@ function approvalTextPreview(value: string, maxBytes: number, encode = (text: st
|
|
|
1888
1903
|
return `${result}...`;
|
|
1889
1904
|
}
|
|
1890
1905
|
|
|
1891
|
-
function
|
|
1906
|
+
function escapeCardMarkdownText(value: string): string {
|
|
1892
1907
|
return escapeCardHtml(value).replace(/[\\`*_[\]#]/gu, (character) => `&#${character.codePointAt(0)};`);
|
|
1893
1908
|
}
|
|
1894
1909
|
|
|
@@ -1909,16 +1924,36 @@ function planPanel(plan: TurnViewState["plan"]): Record<string, unknown> {
|
|
|
1909
1924
|
});
|
|
1910
1925
|
}
|
|
1911
1926
|
|
|
1912
|
-
function fileSummaryPanel(state: TurnViewState): Record<string, unknown> {
|
|
1927
|
+
function fileSummaryPanel(state: TurnViewState, fileChangeUrl?: (filePath: string) => string | undefined): Record<string, unknown> {
|
|
1913
1928
|
return collapsiblePanel(
|
|
1914
1929
|
`文件变更 · ${state.fileSummary.length}`,
|
|
1915
1930
|
state.fileSummary
|
|
1916
|
-
.map((file) =>
|
|
1931
|
+
.map((file) => {
|
|
1932
|
+
const displayPath = displayFilePath(file.path, state.projectCwd);
|
|
1933
|
+
let label = escapeMarkdownFilePath(displayPath);
|
|
1934
|
+
const pathApi = usesWindowsPaths(file.path, state.projectCwd ?? "") ? path.win32 : path;
|
|
1935
|
+
const absolutePath = pathApi.isAbsolute(file.path) ? pathApi.normalize(file.path)
|
|
1936
|
+
: state.projectCwd ? pathApi.resolve(state.projectCwd, file.path) : undefined;
|
|
1937
|
+
const target = absolutePath && fileChangeUrl?.(absolutePath);
|
|
1938
|
+
if (target) {
|
|
1939
|
+
const url = new URL(target);
|
|
1940
|
+
if (url.protocol === "http:" || url.protocol === "https:") {
|
|
1941
|
+
label = `[${escapeCardMarkdownText(pathApi.normalize(displayPath))}](${url.toString()})`;
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
return `- ${label}${fileChangeSuffix(file)}`;
|
|
1945
|
+
})
|
|
1917
1946
|
.join("\n"),
|
|
1918
1947
|
{ elementId: "turn_files" },
|
|
1919
1948
|
);
|
|
1920
1949
|
}
|
|
1921
1950
|
|
|
1951
|
+
function fileChangeSuffix(file: { additions?: number; deletions?: number }): string {
|
|
1952
|
+
const changes = [file.additions ? `+${file.additions}` : "", file.deletions ? `-${file.deletions}` : ""]
|
|
1953
|
+
.filter(Boolean).join(" ");
|
|
1954
|
+
return changes ? ` ${changes}` : "";
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1922
1957
|
function renderPlanStep(step: TurnViewState["plan"][number]): string {
|
|
1923
1958
|
const marker = step.status === "completed" ? "✅" : step.status === "in_progress" ? "🔄" : "○";
|
|
1924
1959
|
return `${marker} ${step.text}`;
|
|
@@ -2416,7 +2451,7 @@ function renderToolDetails(tool: ToolState, projectCwd?: string): string {
|
|
|
2416
2451
|
const command = tool.command ?? tool.title;
|
|
2417
2452
|
const fileSummary = tool.files?.length
|
|
2418
2453
|
? tool.files
|
|
2419
|
-
.map((file) => `${displayFilePath(file.path, projectCwd)}
|
|
2454
|
+
.map((file) => `${displayFilePath(file.path, projectCwd)}${fileChangeSuffix(file)}`)
|
|
2420
2455
|
.join("\n")
|
|
2421
2456
|
: undefined;
|
|
2422
2457
|
const result = tool.error ?? tool.output ?? fileSummary;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FeishuOutbound } from "./types.js";
|
|
1
|
+
import type { FeishuOutbound, MessageReplyTarget } from "./types.js";
|
|
2
2
|
|
|
3
3
|
export class ConsoleFeishuClient implements FeishuOutbound {
|
|
4
4
|
async sendText(contextKey: string, text: string): Promise<string> {
|
|
@@ -6,6 +6,11 @@ export class ConsoleFeishuClient implements FeishuOutbound {
|
|
|
6
6
|
return `console-text-${Date.now()}`;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
sendPromptImages(contextKey: string, text: string, files: string[], _target?: MessageReplyTarget, onPosting?: () => void): Promise<string> {
|
|
10
|
+
onPosting?.();
|
|
11
|
+
return this.sendText(contextKey, [text, `${files.length} 张图片附件`].filter(Boolean).join("\n"));
|
|
12
|
+
}
|
|
13
|
+
|
|
9
14
|
async sendMarkdown(contextKey: string, markdown: string): Promise<string> {
|
|
10
15
|
console.log(`\n[${contextKey}] ${markdown}\n`);
|
|
11
16
|
return `console-markdown-${Date.now()}`;
|
|
@@ -8,9 +8,8 @@ interface FenceState {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
const FENCE_OPENER = /^([ \t]*)((?:`{3,})|(?:~{3,}))(.*)$/;
|
|
11
|
-
const MARKDOWN_LINK = /(!?)\[([^\]\r\n]*)\]\((<[^>\r\n]+>|[^)\r\n]+)\)/g;
|
|
11
|
+
const MARKDOWN_LINK = /(!?)\[([^\[\]\r\n]*)\]\((<[^>\r\n]+>|[^)\r\n]+)\)/g;
|
|
12
12
|
const LOCAL_FILE_LINE_REFERENCE = /(:\d+(?::\d+)?)$/;
|
|
13
|
-
const LOCAL_IMAGE_EXTENSIONS = new Set([".png", ".jpg", ".jpeg", ".gif", ".webp", ".tiff", ".bmp", ".ico"]);
|
|
14
13
|
|
|
15
14
|
export type LocalFileUrlResolver = (filePath: string, reference?: string) => string | undefined;
|
|
16
15
|
|
|
@@ -61,7 +60,7 @@ function includeLocalFileLineReferences(
|
|
|
61
60
|
const target = unwrapMarkdownTarget(rawTarget.trim());
|
|
62
61
|
if (!isLocalFileTarget(target)) {
|
|
63
62
|
const relative = resolveRelativeFileTarget(target, projectCwd);
|
|
64
|
-
if (!relative
|
|
63
|
+
if (!relative) return link;
|
|
65
64
|
const viewerUrl = localFileUrl?.(relative.filePath, relative.reference);
|
|
66
65
|
if (!viewerUrl) {
|
|
67
66
|
const displayPath = displayAbsolutePath(relative.filePath) + (relative.reference ?? "");
|
|
@@ -73,8 +72,6 @@ function includeLocalFileLineReferences(
|
|
|
73
72
|
? `${label}${relative.reference}` : label;
|
|
74
73
|
return `[${normalizedLabel}](${url.toString()})`;
|
|
75
74
|
}
|
|
76
|
-
if (isLocalImageTarget(target)) return link;
|
|
77
|
-
|
|
78
75
|
const reference = LOCAL_FILE_LINE_REFERENCE.exec(target)?.[1];
|
|
79
76
|
const targetWithoutReference = reference ? target.slice(0, -reference.length) : target;
|
|
80
77
|
const filePath = localFilePath(targetWithoutReference);
|
|
@@ -208,15 +205,6 @@ function usesWindowsPaths(...values: string[]): boolean {
|
|
|
208
205
|
return values.some((value) => /^\/?[a-z]:[\\/]/i.test(value) || /^\\\\/.test(value));
|
|
209
206
|
}
|
|
210
207
|
|
|
211
|
-
function isLocalImageTarget(target: string): boolean {
|
|
212
|
-
const reference = LOCAL_FILE_LINE_REFERENCE.exec(target)?.[1];
|
|
213
|
-
const targetWithoutReference = reference ? target.slice(0, -reference.length) : target;
|
|
214
|
-
const filePath = localFilePath(targetWithoutReference);
|
|
215
|
-
if (!filePath) return false;
|
|
216
|
-
const pathApi = usesWindowsPaths(filePath) ? path.win32 : path.posix;
|
|
217
|
-
return LOCAL_IMAGE_EXTENSIONS.has(pathApi.extname(filePath).toLowerCase());
|
|
218
|
-
}
|
|
219
|
-
|
|
220
208
|
function unwrapMarkdownTarget(target: string): string {
|
|
221
209
|
return target.startsWith("<") && target.endsWith(">") ? target.slice(1, -1) : target;
|
|
222
210
|
}
|
|
@@ -335,6 +335,16 @@ export class FeishuMessageClient implements FeishuOutbound {
|
|
|
335
335
|
return this.sendMessage(contextKey, "file", { file_key: fileKey });
|
|
336
336
|
}
|
|
337
337
|
|
|
338
|
+
async sendPromptImages(contextKey: string, text: string, files: string[], target?: MessageReplyTarget, onPosting?: () => void): Promise<string | undefined> {
|
|
339
|
+
const keys = await Promise.all(files.map((file) => this.uploadImageCached(file)));
|
|
340
|
+
const content = { zh_cn: { content: [
|
|
341
|
+
...(text ? [[{ tag: "text", text }]] : []),
|
|
342
|
+
...keys.map((image_key) => [{ tag: "img", image_key }]),
|
|
343
|
+
] } };
|
|
344
|
+
onPosting?.();
|
|
345
|
+
return target ? this.replyMessage(contextKey, target, "post", content) : this.sendMessage(contextKey, "post", content);
|
|
346
|
+
}
|
|
347
|
+
|
|
338
348
|
async sendMarkdown(contextKey: string, markdown: string, idempotencyKey?: string): Promise<string | undefined> {
|
|
339
349
|
const normalizedMarkdown = normalizeFeishuMarkdown(markdown);
|
|
340
350
|
const elements = this.renderFinalAnswerElements(normalizedMarkdown);
|
|
@@ -90,6 +90,7 @@ export class FeishuTurnPresenter {
|
|
|
90
90
|
private readonly sessionAgentLabels = new Map<string, string>();
|
|
91
91
|
private readonly sessionModels = new Map<string, string>();
|
|
92
92
|
private readonly sessionModelProviders = new Map<string, string>();
|
|
93
|
+
private readonly sessionReasoningEfforts = new Map<string, string>();
|
|
93
94
|
private readonly entries = new Map<string, TurnEntry>();
|
|
94
95
|
private readonly pendingEntries = new Map<string, TurnEntry>();
|
|
95
96
|
private readonly renderer: CardRenderer;
|
|
@@ -114,24 +115,27 @@ export class FeishuTurnPresenter {
|
|
|
114
115
|
agentLabel?: string,
|
|
115
116
|
model?: string,
|
|
116
117
|
modelProvider?: string,
|
|
118
|
+
reasoningEffort?: string,
|
|
117
119
|
): void {
|
|
118
120
|
this.sessionContexts.set(sessionId, contextKey);
|
|
119
121
|
if (taskTitle) this.sessionTitles.set(sessionId, taskTitle);
|
|
120
122
|
if (projectCwd) this.sessionCwds.set(sessionId, projectCwd);
|
|
121
123
|
if (agentLabel) this.sessionAgentLabels.set(sessionId, agentLabel);
|
|
122
|
-
|
|
123
|
-
this.updateSessionModel(sessionId, model, modelProvider);
|
|
124
|
-
}
|
|
124
|
+
this.updateSessionModel(sessionId, model, modelProvider, reasoningEffort);
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
updateSessionModel(sessionId: string, model?: string, modelProvider?: string): void {
|
|
127
|
+
updateSessionModel(sessionId: string, model?: string, modelProvider?: string, reasoningEffort?: string): void {
|
|
128
128
|
if (model) this.sessionModels.set(sessionId, model);
|
|
129
129
|
if (modelProvider) this.sessionModelProviders.set(sessionId, modelProvider);
|
|
130
|
+
if (reasoningEffort) this.sessionReasoningEfforts.set(sessionId, reasoningEffort);
|
|
131
|
+
else this.sessionReasoningEfforts.delete(sessionId);
|
|
130
132
|
const pending = this.pendingEntries.get(sessionId);
|
|
131
133
|
const nextModel = this.sessionModels.get(sessionId);
|
|
132
134
|
const nextProvider = this.sessionModelProviders.get(sessionId);
|
|
133
|
-
|
|
134
|
-
pending
|
|
135
|
+
const nextEffort = this.sessionReasoningEfforts.get(sessionId);
|
|
136
|
+
if (!pending || (pending.state.model === nextModel && pending.state.modelProvider === nextProvider
|
|
137
|
+
&& pending.state.reasoningEffort === nextEffort)) return;
|
|
138
|
+
pending.state = { ...pending.state, model: nextModel, modelProvider: nextProvider, reasoningEffort: nextEffort };
|
|
135
139
|
this.persist(pending.state.turnId, sessionId, pending.state, pending.contextKey);
|
|
136
140
|
if (!pending.historySnapshot) pending.scheduler?.update(pending.state, "critical");
|
|
137
141
|
}
|
|
@@ -153,6 +157,7 @@ export class FeishuTurnPresenter {
|
|
|
153
157
|
this.sessionAgentLabels.delete(sessionId);
|
|
154
158
|
this.sessionModels.delete(sessionId);
|
|
155
159
|
this.sessionModelProviders.delete(sessionId);
|
|
160
|
+
this.sessionReasoningEfforts.delete(sessionId);
|
|
156
161
|
}
|
|
157
162
|
|
|
158
163
|
async startPendingTurn(
|
|
@@ -162,6 +167,7 @@ export class FeishuTurnPresenter {
|
|
|
162
167
|
replyTarget?: MessageReplyTarget,
|
|
163
168
|
prompt?: string,
|
|
164
169
|
localImagePaths?: string[],
|
|
170
|
+
promptRequestId?: string,
|
|
165
171
|
): Promise<string | undefined> {
|
|
166
172
|
const existing = this.pendingEntries.get(sessionId);
|
|
167
173
|
if (existing) {
|
|
@@ -174,8 +180,10 @@ export class FeishuTurnPresenter {
|
|
|
174
180
|
return existing.state.turnId;
|
|
175
181
|
}
|
|
176
182
|
const images = localImagePaths === undefined ? existing.state.promptImagePaths : [...new Set(localImagePaths)];
|
|
177
|
-
if ((prompt && existing.state.prompt !== prompt) || JSON.stringify(images) !== JSON.stringify(existing.state.promptImagePaths)
|
|
178
|
-
|
|
183
|
+
if ((prompt && existing.state.prompt !== prompt) || JSON.stringify(images) !== JSON.stringify(existing.state.promptImagePaths)
|
|
184
|
+
|| promptRequestId !== undefined && promptRequestId !== existing.state.promptRequestId) {
|
|
185
|
+
existing.state = { ...existing.state, ...(prompt ? { prompt } : {}), ...(images ? { promptImagePaths: images } : {}),
|
|
186
|
+
...(promptRequestId ? { promptRequestId } : {}) };
|
|
179
187
|
this.persist(existing.state.turnId, sessionId, existing.state, existing.contextKey);
|
|
180
188
|
if (!existing.historySnapshot) existing.scheduler?.update(existing.state, "critical");
|
|
181
189
|
}
|
|
@@ -195,7 +203,9 @@ export class FeishuTurnPresenter {
|
|
|
195
203
|
this.sessionModels.get(sessionId),
|
|
196
204
|
localImagePaths,
|
|
197
205
|
this.sessionModelProviders.get(sessionId),
|
|
206
|
+
this.sessionReasoningEfforts.get(sessionId),
|
|
198
207
|
);
|
|
208
|
+
if (promptRequestId) state.promptRequestId = promptRequestId;
|
|
199
209
|
const entry = { contextKey, state, initializing: Promise.resolve() } as TurnEntry;
|
|
200
210
|
this.entries.set(state.turnId, entry);
|
|
201
211
|
this.pendingEntries.set(sessionId, entry);
|
|
@@ -310,6 +320,7 @@ export class FeishuTurnPresenter {
|
|
|
310
320
|
this.sessionModels.get(sessionId),
|
|
311
321
|
undefined,
|
|
312
322
|
this.sessionModelProviders.get(sessionId),
|
|
323
|
+
this.sessionReasoningEfforts.get(sessionId),
|
|
313
324
|
),
|
|
314
325
|
status: "running" as const,
|
|
315
326
|
};
|
|
@@ -394,9 +405,11 @@ export class FeishuTurnPresenter {
|
|
|
394
405
|
pending.state.model,
|
|
395
406
|
pending.state.promptImagePaths,
|
|
396
407
|
pending.state.modelProvider,
|
|
408
|
+
pending.state.reasoningEffort,
|
|
397
409
|
),
|
|
398
410
|
event,
|
|
399
411
|
);
|
|
412
|
+
if (pending.state.promptRequestId) state.promptRequestId = pending.state.promptRequestId;
|
|
400
413
|
this.flushPersistence();
|
|
401
414
|
this.store.previews?.seed(state);
|
|
402
415
|
this.store.previews?.event(event);
|
|
@@ -593,6 +606,7 @@ export class FeishuTurnPresenter {
|
|
|
593
606
|
this.sessionModels.get(event.sessionId),
|
|
594
607
|
undefined,
|
|
595
608
|
this.sessionModelProviders.get(event.sessionId),
|
|
609
|
+
this.sessionReasoningEfforts.get(event.sessionId),
|
|
596
610
|
);
|
|
597
611
|
this.store.previews?.seed(initial);
|
|
598
612
|
event = presentationEvent(event, initial);
|
package/src/feishu/types.ts
CHANGED
|
@@ -80,6 +80,7 @@ export interface FeishuOutbound {
|
|
|
80
80
|
readReferencedMessage?(messageId: string): Promise<ReferencedMessageContent>;
|
|
81
81
|
sendText(contextKey: string, text: string): Promise<string | undefined>;
|
|
82
82
|
sendFile?(contextKey: string, filePath: string): Promise<string | undefined>;
|
|
83
|
+
sendPromptImages?(contextKey: string, text: string, files: string[], target?: MessageReplyTarget, onPosting?: () => void): Promise<string | undefined>;
|
|
83
84
|
sendMarkdown(contextKey: string, markdown: string, idempotencyKey?: string): Promise<string | undefined>;
|
|
84
85
|
sendInteractiveCard(contextKey: string, card: Record<string, unknown>, idempotencyKey?: string): Promise<string | undefined>;
|
|
85
86
|
replyText?(
|
package/src/index.ts
CHANGED
|
@@ -31,6 +31,7 @@ import { requireServerFeishuTransport } from "./feishu/transport.js";
|
|
|
31
31
|
import { createLogger } from "./logging/logger.js";
|
|
32
32
|
import { OutboundRouter, type OutboundRoute } from "./presentation/OutboundRouter.js";
|
|
33
33
|
import { ProxySessionController } from "./proxy/ProxySessionController.js";
|
|
34
|
+
import { recordTaskMetadata } from "./proxy/TaskMetadata.js";
|
|
34
35
|
import type { AgentEnvironmentContext } from "./runtime/agentEnvironment.js";
|
|
35
36
|
import { createAgentRuntimeRegistry } from "./runtime/createAgentRuntimeRegistry.js";
|
|
36
37
|
import { StateStore } from "./state/StateStore.js";
|
|
@@ -43,6 +44,7 @@ import { StartupNotifier } from "./startup/StartupNotifier.js";
|
|
|
43
44
|
import { SessionMetadataHydrator } from "./startup/SessionMetadataHydrator.js";
|
|
44
45
|
import { startFeishu } from "./startup/startFeishu.js";
|
|
45
46
|
import { STOP_EXIT_CODE } from "./supervision/restartPolicy.js";
|
|
47
|
+
import { readSelfUpdateRecoveryAttemptIds, SELF_UPDATE_RECOVERY_ATTEMPTS_ENV } from "./cli/SelfUpdateRunner.js";
|
|
46
48
|
import {
|
|
47
49
|
RESTART_GROUP_CONTEXTS_ENV,
|
|
48
50
|
RESTART_NOTIFICATION_TARGETS_ENV,
|
|
@@ -69,10 +71,13 @@ import {
|
|
|
69
71
|
launchSelfUpdateRunner,
|
|
70
72
|
readPendingSelfUpdate,
|
|
71
73
|
releaseSelfUpdatePlan,
|
|
74
|
+
SelfUpdatePreparationError,
|
|
72
75
|
} from "./cli/SelfUpdater.js";
|
|
73
76
|
|
|
74
77
|
const processStartedAt = new Date();
|
|
75
78
|
const agentBotVersion = readPackageVersion();
|
|
79
|
+
const updateRecoveryAttemptIds = readSelfUpdateRecoveryAttemptIds(process.env[SELF_UPDATE_RECOVERY_ATTEMPTS_ENV]);
|
|
80
|
+
delete process.env[SELF_UPDATE_RECOVERY_ATTEMPTS_ENV];
|
|
76
81
|
const supervised = process.env.AGENT_BOT_SUPERVISED === "1";
|
|
77
82
|
const startupReason = process.env.AGENT_BOT_RESTART_REASON?.trim()
|
|
78
83
|
|| (supervised ? "Supervisor 启动" : "直接启动");
|
|
@@ -136,7 +141,7 @@ let serverReady = false;
|
|
|
136
141
|
|
|
137
142
|
const feishuOutbound = transport === "sdk" ? new FeishuMessageClient(config, logger) : undefined;
|
|
138
143
|
if (feishuOutbound) {
|
|
139
|
-
const renderer = new CardRenderer();
|
|
144
|
+
const renderer = new CardRenderer((filePath) => localFileViewer?.createFileUrl(filePath, undefined, { diff: true }));
|
|
140
145
|
const presenter = new FeishuTurnPresenter(feishuOutbound, store, renderer, {
|
|
141
146
|
normalIntervalMs: 2_000,
|
|
142
147
|
criticalGapMs: 500,
|
|
@@ -209,20 +214,20 @@ const manualUpdates = new ManualUpdateController({
|
|
|
209
214
|
readReleases: readPublishedReleases,
|
|
210
215
|
checkSupport: () => checkAutomaticUpdateSupport({ home: agentBotHome(), configPath: activeConfigPath }),
|
|
211
216
|
hasPendingUpdate: () => preparingSelfUpdate || shuttingDown || restartRequested || !!pendingSelfUpdatePlanPath || safeRestart.scheduled,
|
|
212
|
-
applyUpdate: (version, contextKey, replyTarget) => prepareAndScheduleUpdate(version, {
|
|
217
|
+
applyUpdate: (version, contextKey, replyTarget, progress) => prepareAndScheduleUpdate(version, {
|
|
213
218
|
contextKey,
|
|
214
219
|
...(replyTarget ? { replyMessageId: replyTarget.messageId } : {}),
|
|
215
|
-
}, true),
|
|
220
|
+
}, true, progress),
|
|
216
221
|
});
|
|
217
222
|
|
|
218
|
-
async function prepareAndScheduleUpdate(version: string, target: RestartNotificationTarget, manual = false): Promise<void> {
|
|
223
|
+
async function prepareAndScheduleUpdate(version: string, target: RestartNotificationTarget, manual = false, progress?: { messageId: string; update(message: string): Promise<void> }): Promise<void> {
|
|
219
224
|
if (preparingSelfUpdate || shuttingDown || restartRequested || pendingSelfUpdatePlanPath || safeRestart.scheduled) {
|
|
220
225
|
throw new Error("已有更新或重启正在进行,请稍后重试。");
|
|
221
226
|
}
|
|
222
227
|
preparingSelfUpdate = true;
|
|
223
228
|
try {
|
|
224
229
|
const prepare = manual ? prepareSelectedUpdate : prepareAutomaticUpdate;
|
|
225
|
-
const prepared = await prepare(version, { home: agentBotHome(), configPath: activeConfigPath });
|
|
230
|
+
const prepared = await prepare(version, { home: agentBotHome(), configPath: activeConfigPath }, undefined, progress?.update);
|
|
226
231
|
try {
|
|
227
232
|
if (shuttingDown || restartRequested || pendingSelfUpdatePlanPath || safeRestart.scheduled) {
|
|
228
233
|
throw new Error("服务正在停止或已有更新/重启等待执行,本次更新已停止。");
|
|
@@ -234,6 +239,7 @@ async function prepareAndScheduleUpdate(version: string, target: RestartNotifica
|
|
|
234
239
|
databasePath: config.storage.sqlitePath,
|
|
235
240
|
restartService: true,
|
|
236
241
|
notificationTarget: target,
|
|
242
|
+
notificationMessageId: progress?.messageId ?? (!manual ? store.getUpdateNotice(version)?.messageId : undefined),
|
|
237
243
|
});
|
|
238
244
|
pendingSelfUpdatePlanPath = prepared.planPath;
|
|
239
245
|
}
|
|
@@ -245,6 +251,12 @@ async function prepareAndScheduleUpdate(version: string, target: RestartNotifica
|
|
|
245
251
|
}
|
|
246
252
|
throw error;
|
|
247
253
|
}
|
|
254
|
+
} catch (error) {
|
|
255
|
+
if (error instanceof SelfUpdatePreparationError && !shuttingDown && !restartRequested && !pendingSelfUpdatePlanPath && !safeRestart.scheduled) {
|
|
256
|
+
safeRestart.schedule("更新准备失败,重启当前版本", target);
|
|
257
|
+
throw new Error(`更新准备失败,已安排安全重启。\n${error.message}`, { cause: error });
|
|
258
|
+
}
|
|
259
|
+
throw error;
|
|
248
260
|
} finally {
|
|
249
261
|
preparingSelfUpdate = false;
|
|
250
262
|
}
|
|
@@ -278,7 +290,9 @@ function serverActivity() {
|
|
|
278
290
|
const activity = store.getServerActivityState();
|
|
279
291
|
const terminalBlockers = terminalServer?.listActiveTerminals() ?? [];
|
|
280
292
|
const pendingInboundMessages = (controller?.pendingInboundMessages ?? 0) + (workspaceSessions?.preparingActions ?? 0);
|
|
281
|
-
|
|
293
|
+
const workspaceInboundAt = workspaceSessions?.latestInboundAt;
|
|
294
|
+
const latestInboundAt = workspaceInboundAt && workspaceInboundAt > (activity.latestInboundAt ?? "") ? workspaceInboundAt : activity.latestInboundAt;
|
|
295
|
+
return { ...activity, latestInboundAt, pendingInboundMessages, activeTerminals: terminalBlockers.length, terminalBlockers };
|
|
282
296
|
}
|
|
283
297
|
|
|
284
298
|
controller = new ProxySessionController(config, store, runtimes, outbound, logger, {
|
|
@@ -331,11 +345,13 @@ loadTurnDetails = (turnId) => controller.loadTurnDetails(turnId);
|
|
|
331
345
|
if (localFileViewer && feishuOutbound) {
|
|
332
346
|
workspaceSessions = new WorkspaceSessions(localFileViewer, {
|
|
333
347
|
store, controller, logger,
|
|
348
|
+
loadTurnDetails: (turnId) => controller.loadTurnDetails(turnId),
|
|
334
349
|
inboundImageDirectory: inboundImageDirectory(config.storage.sqlitePath),
|
|
335
350
|
owner: () => config.feishu.userOpenId,
|
|
336
351
|
password: browserPassword,
|
|
337
352
|
isAppServer: (name) => config.agents[name]?.kind === "app-server",
|
|
338
|
-
|
|
353
|
+
sessionStorageBytes: (task) => runtimes.forAgent(task.agentName).getSessionStorageBytes?.(task.localSessionId),
|
|
354
|
+
canSubmit: () => serverReady && !shuttingDown && controller.acceptingInboundMessages,
|
|
339
355
|
});
|
|
340
356
|
localFileViewer.enableWorkspaceApp(workspaceSessions.start());
|
|
341
357
|
}
|
|
@@ -386,7 +402,7 @@ taskScheduler = new TaskScheduler({
|
|
|
386
402
|
drain: (sessionId) => controller.drainScheduledPrompts(sessionId),
|
|
387
403
|
notify: (job, text) => controller.notifySchedule(job, text),
|
|
388
404
|
});
|
|
389
|
-
await controller.recoverInterruptedTasks().catch((error: unknown) => {
|
|
405
|
+
await controller.recoverInterruptedTasks(updateRecoveryAttemptIds).catch((error: unknown) => {
|
|
390
406
|
logger.error({ error }, "Startup task recovery failed; the server will remain available.");
|
|
391
407
|
});
|
|
392
408
|
consoleConnector?.start();
|
|
@@ -510,13 +526,29 @@ async function initiateSelfUpdate(
|
|
|
510
526
|
if (!commitRestart(force, activity.latestInboundAt)) return false;
|
|
511
527
|
try {
|
|
512
528
|
assertSelfUpdatePlanPath(planPath, agentBotHome());
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
529
|
+
const recoveryAttemptIds = store.listIncompleteTurnAttempts().filter((attempt) => {
|
|
530
|
+
const session = store.getSession(attempt.localSessionId);
|
|
531
|
+
return session && (session.status === "starting" || session.status === "running")
|
|
532
|
+
&& attempt.executionGeneration === store.executionGeneration(attempt.localSessionId)
|
|
533
|
+
&& store.isLatestTurnAttempt(attempt.attemptId) && !store.hasCancellationRequestedForSession(attempt.localSessionId);
|
|
534
|
+
}).map((attempt) => attempt.attemptId);
|
|
535
|
+
finalizeSelfUpdatePlan(planPath, {
|
|
536
|
+
controlEndpoint: controlEndpoint(config.storage.sqlitePath), databasePath: config.storage.sqlitePath,
|
|
537
|
+
restartService: true, recoveryAttemptIds,
|
|
538
|
+
});
|
|
539
|
+
await launchSelfUpdateRunner(planPath, {
|
|
540
|
+
waitPids: [
|
|
541
|
+
...(supervised ? [process.ppid] : []), process.pid,
|
|
542
|
+
...runtimes.entries().flatMap(([, runtime]) => {
|
|
543
|
+
const pid = runtime.getProcessInfo?.().pid;
|
|
544
|
+
return pid ? [pid] : [];
|
|
545
|
+
}),
|
|
546
|
+
],
|
|
547
|
+
environment: { ...replacementSupervisorEnvironment(
|
|
516
548
|
reason,
|
|
517
549
|
environmentRefresh.environment,
|
|
518
550
|
allNotificationTargets,
|
|
519
|
-
),
|
|
551
|
+
), AGENT_BOT_UPDATE_APP_ID: config.feishu.appId, AGENT_BOT_UPDATE_APP_SECRET: config.feishu.appSecret },
|
|
520
552
|
});
|
|
521
553
|
} catch (error) {
|
|
522
554
|
restartRequested = false;
|
|
@@ -556,6 +588,7 @@ async function handleControlRequest(request: ControlRequest): Promise<ControlRes
|
|
|
556
588
|
pid: process.pid,
|
|
557
589
|
startedAt: processStartedAt.toISOString(),
|
|
558
590
|
supervised,
|
|
591
|
+
supervisorPid: supervised ? process.ppid : null,
|
|
559
592
|
feishuAppId: config.feishu.appId ?? null,
|
|
560
593
|
agents: runtimes.entries().map(([name, runtime]) => {
|
|
561
594
|
const processInfo = runtime.getProcessInfo?.() ?? {};
|
|
@@ -678,6 +711,8 @@ async function handleControlRequest(request: ControlRequest): Promise<ControlRes
|
|
|
678
711
|
return { ok: true, data: controller.controlTaskMute(request.localSessionId, request.enabled) };
|
|
679
712
|
case "task_shell":
|
|
680
713
|
return { ok: true, data: await controller.controlRunTaskShell(request.localSessionId, request.command) };
|
|
714
|
+
case "task_metadata":
|
|
715
|
+
return { ok: true, data: recordTaskMetadata(store, request.localSessionId, request.command) };
|
|
681
716
|
case "task_directory":
|
|
682
717
|
return {
|
|
683
718
|
ok: true,
|
|
@@ -48,6 +48,8 @@ export const DIAGRAM_PREVIEW_CLIENT_SCRIPT = String.raw`(() => {
|
|
|
48
48
|
const states = new WeakMap();
|
|
49
49
|
let library;
|
|
50
50
|
let sequence = 0;
|
|
51
|
+
const workspaceTheme = () => document.documentElement.dataset.workspaceTheme;
|
|
52
|
+
const isRendered = (state) => state.rendered === state.source && state.renderedTheme === workspaceTheme();
|
|
51
53
|
const loadLibrary = () => {
|
|
52
54
|
if (!library) library = new Promise((resolve, reject) => {
|
|
53
55
|
const url = document.body.dataset.diagramScript;
|
|
@@ -84,20 +86,21 @@ export const DIAGRAM_PREVIEW_CLIENT_SCRIPT = String.raw`(() => {
|
|
|
84
86
|
block.querySelector(".diagram-source").hidden = mode !== "source";
|
|
85
87
|
block.dataset.diagramSize = state.size;
|
|
86
88
|
const sizeButton = block.querySelector("[data-diagram-size-toggle]");
|
|
87
|
-
|
|
89
|
+
const ready = isRendered(state);
|
|
90
|
+
sizeButton.hidden = mode !== "preview" || !ready;
|
|
88
91
|
sizeButton.textContent = state.size === "actual" ? (zh ? "适应" : "Fit") : (zh ? "原大" : "Actual size");
|
|
89
92
|
sizeButton.setAttribute("aria-label", state.size === "actual"
|
|
90
93
|
? (zh ? "适应容器宽度" : "Fit diagram to width")
|
|
91
94
|
: (zh ? "按原始尺寸查看图表" : "View diagram at actual size"));
|
|
92
95
|
const notice = block.querySelector(".diagram-notice");
|
|
93
|
-
notice.hidden = !state.error && (
|
|
96
|
+
notice.hidden = !state.error && (ready || mode === "source");
|
|
94
97
|
notice.textContent = state.error ? failed : loading;
|
|
95
98
|
block.querySelectorAll("[data-diagram-mode]").forEach((button) => {
|
|
96
99
|
button.setAttribute("aria-pressed", String(button.dataset.diagramMode === mode));
|
|
97
100
|
});
|
|
98
101
|
};
|
|
99
102
|
const render = async (block, state, revision) => {
|
|
100
|
-
const source = state.source;
|
|
103
|
+
const source = state.source, theme = workspaceTheme();
|
|
101
104
|
let container;
|
|
102
105
|
try {
|
|
103
106
|
// Keep model-authored Mermaid config from weakening the renderer's safety policy.
|
|
@@ -109,7 +112,8 @@ export const DIAGRAM_PREVIEW_CLIENT_SCRIPT = String.raw`(() => {
|
|
|
109
112
|
container = document.createElement("div");
|
|
110
113
|
container.style.cssText = "position:absolute;left:-100000px;top:0;width:1000px;visibility:hidden;pointer-events:none";
|
|
111
114
|
document.body.appendChild(container);
|
|
112
|
-
const
|
|
115
|
+
const themedSource = theme ? "---\nconfig:\n theme: " + (theme === "dark" ? "dark" : "default") + "\n---\n" + source : source;
|
|
116
|
+
const result = await mermaid.render("agentbot-diagram-" + (++sequence), themedSource, container);
|
|
113
117
|
if (!block.isConnected || state.revision !== revision) return;
|
|
114
118
|
const template = document.createElement("template");
|
|
115
119
|
template.innerHTML = result.svg;
|
|
@@ -128,6 +132,7 @@ export const DIAGRAM_PREVIEW_CLIENT_SCRIPT = String.raw`(() => {
|
|
|
128
132
|
}
|
|
129
133
|
block.querySelector(".diagram-preview").replaceChildren(template.content);
|
|
130
134
|
state.rendered = source;
|
|
135
|
+
state.renderedTheme = theme;
|
|
131
136
|
state.error = false;
|
|
132
137
|
show(block, state);
|
|
133
138
|
} catch {
|
|
@@ -137,7 +142,7 @@ export const DIAGRAM_PREVIEW_CLIENT_SCRIPT = String.raw`(() => {
|
|
|
137
142
|
const schedule = (block, state) => {
|
|
138
143
|
clearTimeout(state.timer);
|
|
139
144
|
state.revision += 1;
|
|
140
|
-
if (state.mode !== "preview" || state
|
|
145
|
+
if (state.mode !== "preview" || isRendered(state)) return;
|
|
141
146
|
const revision = state.revision;
|
|
142
147
|
state.timer = setTimeout(() => void render(block, state, revision), 180);
|
|
143
148
|
};
|
|
@@ -162,7 +167,7 @@ export const DIAGRAM_PREVIEW_CLIENT_SCRIPT = String.raw`(() => {
|
|
|
162
167
|
schedule(block, state);
|
|
163
168
|
});
|
|
164
169
|
});
|
|
165
|
-
} else if (state.source === source && (state.mode !== "preview" || state
|
|
170
|
+
} else if (state.source === source && (state.mode !== "preview" || isRendered(state) || state.error)) { return; }
|
|
166
171
|
else { state.source = source; state.error = false; }
|
|
167
172
|
show(block, state);
|
|
168
173
|
schedule(block, state);
|