@keyou007/agent-bot 0.1.27-alpha.3 → 0.1.27-alpha.5
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 +32 -0
- package/README.md +102 -18
- package/README.zh.md +102 -18
- 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 +2676 -243
- package/assets/workspace.css +553 -44
- package/assets/workspace.js +3429 -327
- 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 +51 -22
- 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 +106 -14
- 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 +141 -122
- 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 +53 -276
- 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 +43 -0
- package/dist/local-files/WorkspaceImages.js.map +1 -0
- package/dist/local-files/WorkspacePage.js +24 -6
- package/dist/local-files/WorkspacePage.js.map +1 -1
- package/dist/local-files/WorkspaceSessions.js +1153 -104
- package/dist/local-files/WorkspaceSessions.js.map +1 -1
- package/dist/local-files/WorkspaceTimeline.js +129 -0
- package/dist/local-files/WorkspaceTimeline.js.map +1 -0
- package/dist/presentation/OutboundRouter.js +15 -6
- package/dist/presentation/OutboundRouter.js.map +1 -1
- package/dist/presentation/TurnStateReducer.js +31 -22
- package/dist/presentation/TurnStateReducer.js.map +1 -1
- package/dist/proxy/ProxySessionController.js +335 -113
- 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 +53 -12
- package/dist/scheduling/ScheduledTaskStore.js.map +1 -1
- package/dist/scheduling/types.js +19 -4
- package/dist/scheduling/types.js.map +1 -1
- package/dist/state/StateStore.js +213 -23
- package/dist/state/StateStore.js.map +1 -1
- package/dist/state/TurnPreviewJournal.js +157 -39
- 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 +22 -0
- package/dist/utils/promptAttachments.js.map +1 -0
- package/dist/utils/promptQuotes.js +47 -0
- package/dist/utils/promptQuotes.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 +49 -16
- 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 +107 -15
- package/src/local-files/LiveMarkup.ts +103 -0
- package/src/local-files/LocalFileViewerServer.ts +128 -125
- 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 +58 -261
- package/src/local-files/WorkspaceFileEvents.ts +186 -0
- package/src/local-files/WorkspaceFiles.ts +72 -5
- package/src/local-files/WorkspaceImages.ts +35 -0
- package/src/local-files/WorkspacePage.ts +24 -6
- package/src/local-files/WorkspaceSessions.ts +1057 -111
- package/src/local-files/WorkspaceTimeline.ts +135 -0
- package/src/presentation/OutboundRouter.ts +18 -4
- package/src/presentation/TurnStateReducer.ts +30 -19
- package/src/presentation/turnViewTypes.ts +3 -1
- package/src/proxy/ProxySessionController.ts +336 -96
- 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 +56 -9
- package/src/scheduling/types.ts +27 -4
- package/src/state/StateStore.ts +227 -24
- package/src/state/TurnPreviewJournal.ts +155 -38
- 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 +27 -0
- package/src/utils/promptQuotes.ts +48 -0
- package/src/utils/toolTimestamp.ts +5 -0
|
@@ -2,6 +2,7 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import type { Logger } from "pino";
|
|
3
3
|
import { truncateText } from "../utils/markdown.js";
|
|
4
4
|
import { compareSemver } from "../cli/SelfUpdater.js";
|
|
5
|
+
import { sanitizeUpdateDiagnostic } from "../cli/SelfUpdateRunner.js";
|
|
5
6
|
import { CardRenderer, type TaskListCardAction } from "../feishu/CardRenderer.js";
|
|
6
7
|
import type { CardAction, MessageReplyTarget } from "../feishu/types.js";
|
|
7
8
|
import type { OutboundRouter } from "../presentation/OutboundRouter.js";
|
|
@@ -17,7 +18,7 @@ interface ManualUpdateOptions {
|
|
|
17
18
|
readReleases(): Promise<PublishedRelease[]>;
|
|
18
19
|
checkSupport(): Promise<void>;
|
|
19
20
|
hasPendingUpdate(): boolean;
|
|
20
|
-
applyUpdate(version: string, contextKey: string, replyTarget?: MessageReplyTarget): Promise<void>;
|
|
21
|
+
applyUpdate(version: string, contextKey: string, replyTarget?: MessageReplyTarget, progress?: { messageId: string; update(message: string): Promise<void> }): Promise<void>;
|
|
21
22
|
now?(): number;
|
|
22
23
|
}
|
|
23
24
|
|
|
@@ -95,10 +96,14 @@ export class ManualUpdateController {
|
|
|
95
96
|
try {
|
|
96
97
|
this.options.store.retainCardActionBindings(action.messageId!, []);
|
|
97
98
|
await this.options.outbound.sendText(action.contextKey, `正在下载并校验 Agent Bot ${version},请稍后;完成后将安排安全更新。`);
|
|
98
|
-
await this.
|
|
99
|
+
await this.showResult(action, version, "正在准备更新……");
|
|
100
|
+
await this.options.applyUpdate(version, action.contextKey, replyTarget, {
|
|
101
|
+
messageId: action.messageId!, update: (message) => this.showResult(action, version, message),
|
|
102
|
+
});
|
|
99
103
|
await this.showResult(action, version, "更新已就绪,等待任务与结果投递完成后自动安装并重启。");
|
|
100
104
|
} catch (error) {
|
|
101
|
-
|
|
105
|
+
const reason = truncateText(sanitizeUpdateDiagnostic(error instanceof Error ? error.message : String(error)), 3000);
|
|
106
|
+
await this.showResult(action, version, "更新未完成,当前服务继续运行。请重新发送 /update 后重试。\n失败原因:" + reason);
|
|
102
107
|
throw error;
|
|
103
108
|
} finally {
|
|
104
109
|
this.selecting = false;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { appendPromptQuotes, type PromptQuote } from "./promptQuotes.js";
|
|
2
|
+
|
|
3
|
+
const downloadedFilesHeading = "\n\n参考文件(已下载到本地):\n";
|
|
4
|
+
|
|
5
|
+
export function appendDownloadedFiles(
|
|
6
|
+
prompt: string,
|
|
7
|
+
files: ReadonlyArray<{ fileName: string; filePath: string }>,
|
|
8
|
+
): string {
|
|
9
|
+
return `${prompt}${downloadedFilesHeading}${files.map((file, index) =>
|
|
10
|
+
`[文件 ${index + 1}:${file.fileName}] ${file.filePath}`).join("\n")}`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function queuedPromptContent({ text, displayPrompt }: { text: string; displayPrompt?: string }, quotes?: readonly PromptQuote[]) {
|
|
14
|
+
const heading = text.indexOf(downloadedFilesHeading);
|
|
15
|
+
const fileCount = heading < 0 ? 0 : [...text.slice(heading + downloadedFilesHeading.length).matchAll(/^\[文件 \d+:[^\n]+\] .+/gmu)].length;
|
|
16
|
+
const quoteOffset = quotes?.length ? text.lastIndexOf(appendPromptQuotes("", quotes)) : -1;
|
|
17
|
+
// Display text can be followed by downloaded files or conversation context attached at submission.
|
|
18
|
+
const end = displayPrompt !== undefined && text.startsWith(`${displayPrompt}\n\n`)
|
|
19
|
+
? displayPrompt.length : quoteOffset >= 0 ? quoteOffset : fileCount ? heading : text.length;
|
|
20
|
+
return { text: text.slice(0, end), suffix: text.slice(end), fileCount };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function defaultResourcePromptFromCounts(imageCount: number, fileCount: number): string {
|
|
24
|
+
if (imageCount > 0 && fileCount > 0) return "请查看附带的图片和文件";
|
|
25
|
+
if (fileCount > 0) return fileCount === 1 ? "请查看这个文件" : "请查看这些文件";
|
|
26
|
+
return imageCount === 1 ? "请查看这张图片" : "请查看这些图片";
|
|
27
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
const lineNumber = z.string().regex(/^\d{1,10}(?:–\d{1,10})?$/u);
|
|
4
|
+
const quoteSource = z.union([
|
|
5
|
+
z.object({ path: z.string().min(1).max(4096), directory: z.literal(true).optional(), wholeLines: z.literal(true).optional(), line: lineNumber.optional(),
|
|
6
|
+
originalLine: lineNumber.optional(), originalPath: z.string().min(1).max(4096).optional() }).strict(),
|
|
7
|
+
z.object({ label: z.string().trim().min(1).max(160), turn: z.string().max(400).optional() }).strict(),
|
|
8
|
+
z.object({ label: z.string().trim().min(1).max(160), url: z.url({ protocol: /^https?$/u }).max(4096) }).strict(),
|
|
9
|
+
]);
|
|
10
|
+
const excerpt = z.string().max(100_000).refine(text => Boolean(text.trim()));
|
|
11
|
+
const sessionSource = z.object({
|
|
12
|
+
sessionId: z.string().min(1).max(200).regex(/^[^\x00-\x1f\x7f]+$/u),
|
|
13
|
+
title: z.string().trim().min(1).max(200),
|
|
14
|
+
}).strict();
|
|
15
|
+
export const promptQuotesSchema = z.array(z.discriminatedUnion("kind", [
|
|
16
|
+
z.object({ kind: z.literal("reference"), source: z.union([quoteSource, sessionSource]), quote: excerpt.optional() }).strict(),
|
|
17
|
+
z.object({ kind: z.literal("annotation"), source: quoteSource, quote: excerpt, note: z.string().trim().min(1).max(8_000) }).strict(),
|
|
18
|
+
])).max(4);
|
|
19
|
+
export type PromptQuote = z.output<typeof promptQuotesSchema>[number];
|
|
20
|
+
|
|
21
|
+
function indented(text: string): string {
|
|
22
|
+
return text.split(/\r?\n/u).map(line => ` ${line}`).join("\n");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function quoteSourceText(source: PromptQuote["source"]): string {
|
|
26
|
+
if ("sessionId" in source) return `会话标题:${source.title}\n会话 ID:${source.sessionId}`;
|
|
27
|
+
if ("path" in source) return [source.directory ? `目录路径:${source.path}` : source.path,
|
|
28
|
+
source.line && `第 ${source.line} 行`, source.originalLine && `变更前第 ${source.originalLine} 行`,
|
|
29
|
+
source.originalPath && `变更前的文件:${source.originalPath}`].filter(Boolean).join(" · ");
|
|
30
|
+
if ("url" in source) return `${source.label}\n${source.url}`;
|
|
31
|
+
return source.turn ? `${source.label}\n轮次:${source.turn}` : source.label;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function promptQuoteInstruction(quotes: readonly PromptQuote[] = []): string {
|
|
35
|
+
if (quotes.some(item => item.kind === "annotation")) return "请阅读所附批注,并处理其中提出的要求。";
|
|
36
|
+
return quotes.length ? "请查看所附引用。" : "";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function appendPromptQuotes(prompt: string, quotes: readonly PromptQuote[] = []): string {
|
|
40
|
+
return [prompt, ...quotes.map(item => {
|
|
41
|
+
const { source } = item;
|
|
42
|
+
const locationOnly = "path" in source && (source.directory || source.wholeLines && Boolean(source.line || source.originalLine));
|
|
43
|
+
return [item.kind === "annotation" ? "批注来源:" : "引用来源:", indented(quoteSourceText(source)),
|
|
44
|
+
...(item.quote && !locationOnly ? ["原文:", indented(item.quote)] : []),
|
|
45
|
+
...(item.kind === "annotation" ? ["用户批注:", indented(item.note)] : []),
|
|
46
|
+
].join("\n");
|
|
47
|
+
})].join("\n\n");
|
|
48
|
+
}
|