@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
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type { ToolStatus } from "../runtime/types.js";
|
|
2
|
+
import type { TurnViewState } from "../presentation/turnViewTypes.js";
|
|
3
|
+
import { toolTimestamp } from "../utils/toolTimestamp.js";
|
|
4
|
+
import { previewToolHeading, type PreviewToolHeading } from "./ToolCommandDisplay.js";
|
|
5
|
+
|
|
6
|
+
export type WorkspaceActivity = { id: string } & (
|
|
7
|
+
| { kind: "assistant" | "user" | "system" | "reasoning"; text: string | null; images: unknown; startedAt?: number | null }
|
|
8
|
+
| { kind: "tool"; heading: PreviewToolHeading; toolKind: string | null; status: ToolStatus; startedAt?: number | null; completedAt?: number | null }
|
|
9
|
+
);
|
|
10
|
+
export interface WorkspaceReasoning {
|
|
11
|
+
id: string;
|
|
12
|
+
after: string | null;
|
|
13
|
+
parts: Array<{ index: number; text: string }>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function recordedWorkspaceTimeline(state: TurnViewState) {
|
|
17
|
+
const activities = state.activities.map((activity): WorkspaceActivity => {
|
|
18
|
+
const { id, kind } = activity;
|
|
19
|
+
if (kind !== "tool") return { id, kind, text: activity.text,
|
|
20
|
+
images: kind === "user" ? activity.localImagePaths : undefined,
|
|
21
|
+
startedAt: kind === "user" ? activity.startedAt : undefined };
|
|
22
|
+
const { tool } = activity;
|
|
23
|
+
const heading = previewToolHeading(tool, "命令");
|
|
24
|
+
return { id, kind, heading: { ...heading, title: heading.title.slice(0, 240) }, toolKind: tool.kind ?? null,
|
|
25
|
+
status: tool.status, startedAt: tool.startedAt, completedAt: tool.completedAt };
|
|
26
|
+
});
|
|
27
|
+
const reasoning = (state.reasoningItems ?? []).map((item): WorkspaceReasoning => ({
|
|
28
|
+
id: item.itemId, after: item.afterActivityId ?? null,
|
|
29
|
+
parts: item.summary.flatMap((text, index) => text?.trim() ? [{ index, text: text.slice(0, 512) }] : []),
|
|
30
|
+
}));
|
|
31
|
+
return { activities, reasoning };
|
|
32
|
+
}
|
|
33
|
+
type WorkspaceTool = { id: string; title: string; kind: string; command?: true; status: ToolStatus; startedAt?: number; completedAt?: number };
|
|
34
|
+
interface ExecutionGroup {
|
|
35
|
+
kind: "execution";
|
|
36
|
+
id: string;
|
|
37
|
+
title: string;
|
|
38
|
+
tools: WorkspaceTool[];
|
|
39
|
+
}
|
|
40
|
+
type WorkspaceMessage = { id: string; kind: "assistant" | "user" | "system"; text: string | null; images: unknown; startedAt?: number | null };
|
|
41
|
+
type ThinkingSummary = { title?: string; detail?: string };
|
|
42
|
+
|
|
43
|
+
const reasoningPart = /^reasoning:(.+):(\d+)$/u;
|
|
44
|
+
const isNativeReasoning = (activity: WorkspaceActivity) => activity.kind === "reasoning" && !activity.id.startsWith("commentary:");
|
|
45
|
+
|
|
46
|
+
function reasoningSummary(excerpt: string): ThinkingSummary {
|
|
47
|
+
const [first, ...body] = excerpt.split(/\r?\n/u);
|
|
48
|
+
const line = first!.replace(/^#{1,6}\s+/u, "").trim();
|
|
49
|
+
const title = /^(?:\*\*(.+)\*\*|__(.+)__)$/u.exec(line);
|
|
50
|
+
const detail = body.join("\n").trim() || undefined;
|
|
51
|
+
if (!title && /^(?:\*\*|__|#{1,6}$)/u.test(line)) return { detail };
|
|
52
|
+
const text = title?.[1] ?? title?.[2] ?? line;
|
|
53
|
+
return text.length > 140 ? { title: `${text.slice(0, 139)}…`, detail: excerpt } : { title: text || undefined, detail };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function reasoningUpdates(activities: WorkspaceActivity[], saved: WorkspaceReasoning[]) {
|
|
57
|
+
const positions = new Map(activities.map((item, index) => [item.id, index]));
|
|
58
|
+
const markers = new Map<string, Map<number, { position: number; text: string | null }>>();
|
|
59
|
+
for (const [index, activity] of activities.entries()) {
|
|
60
|
+
if (activity.kind !== "reasoning" || !isNativeReasoning(activity)) continue;
|
|
61
|
+
const match = reasoningPart.exec(activity.id);
|
|
62
|
+
const id = match?.[1] ?? activity.id;
|
|
63
|
+
let parts = markers.get(id);
|
|
64
|
+
if (!parts) { parts = new Map(); markers.set(id, parts); }
|
|
65
|
+
const section = match ? Number(match[2]) : 0;
|
|
66
|
+
parts.set(section, { position: index, text: activity.text });
|
|
67
|
+
}
|
|
68
|
+
const result = new Map<number, ThinkingSummary>();
|
|
69
|
+
const add = (index: number, text: string | null) => {
|
|
70
|
+
const excerpt = text?.trim().slice(0, 512);
|
|
71
|
+
if (!excerpt || /^[*_#\s]+$/u.test(excerpt)) return;
|
|
72
|
+
const { title, detail } = reasoningSummary(excerpt);
|
|
73
|
+
result.set(index, { title: title ?? result.get(index)?.title, detail });
|
|
74
|
+
};
|
|
75
|
+
for (const item of saved) {
|
|
76
|
+
const parts = markers.get(item.id);
|
|
77
|
+
markers.delete(item.id);
|
|
78
|
+
const anchor = item.after === null ? -1 : positions.get(item.after);
|
|
79
|
+
let position = anchor === undefined ? parts?.values().next().value?.position : anchor + 1;
|
|
80
|
+
if (position === undefined) continue;
|
|
81
|
+
const projected = new Map(item.parts.map((part) => [part.index, part.text]));
|
|
82
|
+
const sections = [...new Set([...projected.keys(), ...(parts?.keys() ?? [])])].sort((a, b) => a - b);
|
|
83
|
+
for (const section of sections) {
|
|
84
|
+
const marker = parts?.get(section);
|
|
85
|
+
const summary = projected.get(section);
|
|
86
|
+
const sectionPosition = marker?.position ?? position;
|
|
87
|
+
add(sectionPosition, summary?.trim() ? summary : marker?.text ?? null);
|
|
88
|
+
position = Math.max(position, sectionPosition);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
for (const parts of markers.values()) for (const { position, text } of parts.values()) add(position, text);
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Visible messages split execution stretches; native summary sections update the title in arrival order. */
|
|
96
|
+
export function workspaceTimeline(
|
|
97
|
+
activities: WorkspaceActivity[], saved: WorkspaceReasoning[], answer?: string | null, showThinking = false,
|
|
98
|
+
) {
|
|
99
|
+
const reasoningAt = reasoningUpdates(activities, saved);
|
|
100
|
+
const rows: Array<ExecutionGroup | WorkspaceMessage | { kind: "reasoning"; id: string; title: string; detail?: string }> = [];
|
|
101
|
+
let group: ExecutionGroup | undefined, title: string | undefined, thinking: ThinkingSummary | undefined;
|
|
102
|
+
for (let index = 0; index <= activities.length; index++) {
|
|
103
|
+
const next = reasoningAt.get(index);
|
|
104
|
+
if (next) {
|
|
105
|
+
thinking = next;
|
|
106
|
+
if (next.title) { title = next.title; if (group) group.title = title; }
|
|
107
|
+
}
|
|
108
|
+
const activity = activities[index];
|
|
109
|
+
if (!activity) break;
|
|
110
|
+
if (isNativeReasoning(activity)) continue;
|
|
111
|
+
if (activity.kind === "tool") {
|
|
112
|
+
if (!group) {
|
|
113
|
+
group = { kind: "execution", id: `tools:${activity.id}`, title: title ?? "工具执行", tools: [] };
|
|
114
|
+
rows.push(group);
|
|
115
|
+
}
|
|
116
|
+
const { heading } = activity;
|
|
117
|
+
group.tools.push({ id: activity.id, title: heading.title, kind: heading.repl ? "repl" : activity.toolKind || "tool",
|
|
118
|
+
command: heading.command, status: activity.status,
|
|
119
|
+
startedAt: toolTimestamp(activity.startedAt), completedAt: toolTimestamp(activity.completedAt) });
|
|
120
|
+
} else {
|
|
121
|
+
const kind = activity.kind === "assistant" && /^(?:model-queue|context-compaction):/u.test(activity.id) ? "system"
|
|
122
|
+
: activity.kind === "reasoning" ? "assistant" : activity.kind;
|
|
123
|
+
if (kind === "assistant" && activity.text === answer && index === activities.length - 1) {
|
|
124
|
+
group = title = undefined; thinking = undefined; continue;
|
|
125
|
+
}
|
|
126
|
+
if (!activity.text?.trim() && !(kind === "user" && Array.isArray(activity.images) && activity.images.length)) continue;
|
|
127
|
+
rows.push({ ...activity, kind });
|
|
128
|
+
group = title = undefined; thinking = undefined;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (showThinking && !answer && thinking && !group && (title || thinking.detail)) {
|
|
132
|
+
rows.push({ kind: "reasoning", id: "workspace:thinking", title: title || "思考摘要", detail: thinking.detail });
|
|
133
|
+
}
|
|
134
|
+
return rows;
|
|
135
|
+
}
|
|
@@ -20,8 +20,9 @@ export interface TurnPresenter {
|
|
|
20
20
|
agentLabel?: string,
|
|
21
21
|
model?: string,
|
|
22
22
|
modelProvider?: string,
|
|
23
|
+
reasoningEffort?: string,
|
|
23
24
|
): void;
|
|
24
|
-
updateSessionModel(sessionId: string, model?: string, modelProvider?: string): void;
|
|
25
|
+
updateSessionModel(sessionId: string, model?: string, modelProvider?: string, reasoningEffort?: string): void;
|
|
25
26
|
updateSessionTitle(sessionId: string, taskTitle: string): void;
|
|
26
27
|
unregisterSession(sessionId: string): void;
|
|
27
28
|
startPendingTurn(
|
|
@@ -31,6 +32,8 @@ export interface TurnPresenter {
|
|
|
31
32
|
replyTarget?: MessageReplyTarget,
|
|
32
33
|
prompt?: string,
|
|
33
34
|
localImagePaths?: string[],
|
|
35
|
+
promptRequestId?: string,
|
|
36
|
+
localFirst?: boolean,
|
|
34
37
|
): Promise<string | undefined>;
|
|
35
38
|
failPendingTurn(
|
|
36
39
|
sessionId: string,
|
|
@@ -76,12 +79,13 @@ export class OutboundRouter {
|
|
|
76
79
|
agentLabel?: string,
|
|
77
80
|
model?: string,
|
|
78
81
|
modelProvider?: string,
|
|
82
|
+
reasoningEffort?: string,
|
|
79
83
|
): void {
|
|
80
84
|
const route = this.route(contextKey);
|
|
81
85
|
this.sessionRoutes.set(sessionId, route);
|
|
82
86
|
this.sessionContextKeys.set(sessionId, contextKey);
|
|
83
87
|
route.presenter.registerSession(sessionId, contextKey, taskTitle, projectCwd, agentLabel);
|
|
84
|
-
|
|
88
|
+
route.presenter.updateSessionModel(sessionId, model, modelProvider, reasoningEffort);
|
|
85
89
|
}
|
|
86
90
|
|
|
87
91
|
getSessionContextKey(sessionId: string): string | undefined {
|
|
@@ -100,8 +104,8 @@ export class OutboundRouter {
|
|
|
100
104
|
this.sessionRoutes.get(sessionId)?.presenter.updateSessionTitle(sessionId, taskTitle);
|
|
101
105
|
}
|
|
102
106
|
|
|
103
|
-
updateSessionModel(sessionId: string, model?: string, modelProvider?: string): void {
|
|
104
|
-
this.sessionRoutes.get(sessionId)?.presenter.updateSessionModel(sessionId, model, modelProvider);
|
|
107
|
+
updateSessionModel(sessionId: string, model?: string, modelProvider?: string, reasoningEffort?: string): void {
|
|
108
|
+
this.sessionRoutes.get(sessionId)?.presenter.updateSessionModel(sessionId, model, modelProvider, reasoningEffort);
|
|
105
109
|
}
|
|
106
110
|
|
|
107
111
|
unregisterSession(sessionId: string): void {
|
|
@@ -119,12 +123,16 @@ export class OutboundRouter {
|
|
|
119
123
|
replyTarget?: MessageReplyTarget,
|
|
120
124
|
prompt?: string,
|
|
121
125
|
localImagePaths?: string[],
|
|
126
|
+
promptRequestId?: string,
|
|
127
|
+
localFirst?: boolean,
|
|
122
128
|
): Promise<string | undefined> {
|
|
123
129
|
const route = this.route(contextKey);
|
|
124
130
|
this.sessionRoutes.set(sessionId, route);
|
|
125
131
|
this.sessionContextKeys.set(sessionId, contextKey);
|
|
126
132
|
if (replyTarget) this.sessionReplyTargets.set(sessionId, replyTarget);
|
|
127
133
|
else this.sessionReplyTargets.delete(sessionId);
|
|
134
|
+
if (localFirst) return route.presenter.startPendingTurn(sessionId, contextKey, taskTitle, replyTarget, prompt, localImagePaths, promptRequestId, true);
|
|
135
|
+
if (promptRequestId) return route.presenter.startPendingTurn(sessionId, contextKey, taskTitle, replyTarget, prompt, localImagePaths, promptRequestId);
|
|
128
136
|
return route.presenter.startPendingTurn(sessionId, contextKey, taskTitle, replyTarget, prompt, ...(localImagePaths ? [localImagePaths] : []));
|
|
129
137
|
}
|
|
130
138
|
|
|
@@ -273,6 +281,12 @@ export class OutboundRouter {
|
|
|
273
281
|
return outbound.sendFile(contextKey, filePath);
|
|
274
282
|
}
|
|
275
283
|
|
|
284
|
+
sendPromptImages(contextKey: string, text: string, files: string[], onPosting?: () => void): Promise<string | undefined> {
|
|
285
|
+
const outbound = this.route(contextKey).outbound;
|
|
286
|
+
if (!outbound.sendPromptImages) throw new Error("当前消息通道不支持发送图片附件。");
|
|
287
|
+
return outbound.sendPromptImages(contextKey, text, files, this.currentReplyTarget(contextKey), onPosting);
|
|
288
|
+
}
|
|
289
|
+
|
|
276
290
|
sendMarkdown(contextKey: string, markdown: string): Promise<string | undefined> {
|
|
277
291
|
const outbound = this.route(contextKey).outbound;
|
|
278
292
|
const target = this.currentReplyTarget(contextKey);
|
|
@@ -2,6 +2,7 @@ import { TASK_NOTIFICATION_ACTIVITY_PREFIX, type AgentEvent, type ApprovalDecisi
|
|
|
2
2
|
import { appendGeneratedImageMarkdown } from "../utils/generatedImageMarkdown.js";
|
|
3
3
|
import type { MessageReplyTarget } from "../feishu/types.js";
|
|
4
4
|
import { formatStorageSize } from "../utils/formatStorageSize.js";
|
|
5
|
+
import { toolTimestamp } from "../utils/toolTimestamp.js";
|
|
5
6
|
import type { FileSummary, TurnActivity, TurnReasoningItem, TurnViewState } from "./turnViewTypes.js";
|
|
6
7
|
import { turnReasoningItems } from "./turnReasoning.js";
|
|
7
8
|
import { canApplyTurnEvent, modelQueueLabel } from "./turnStatus.js";
|
|
@@ -24,6 +25,7 @@ export function createTurnViewState(
|
|
|
24
25
|
model?: string,
|
|
25
26
|
promptImagePaths?: string[],
|
|
26
27
|
modelProvider?: string,
|
|
28
|
+
reasoningEffort?: string,
|
|
27
29
|
): TurnViewState {
|
|
28
30
|
return {
|
|
29
31
|
sessionId,
|
|
@@ -31,6 +33,7 @@ export function createTurnViewState(
|
|
|
31
33
|
agentLabel,
|
|
32
34
|
model,
|
|
33
35
|
modelProvider,
|
|
36
|
+
reasoningEffort,
|
|
34
37
|
taskTitle,
|
|
35
38
|
prompt,
|
|
36
39
|
...(promptImagePaths?.length ? { promptImagePaths: [...new Set(promptImagePaths)] } : {}),
|
|
@@ -59,7 +62,7 @@ export function hydrateTurnViewState(summary: TurnViewState, details: RemoteTurn
|
|
|
59
62
|
...summary,
|
|
60
63
|
...createTurnViewState(summary.sessionId, summary.turnId, details.startedAt ?? summary.startedAt,
|
|
61
64
|
summary.taskTitle, summary.replyTarget, summary.projectCwd, summary.prompt,
|
|
62
|
-
summary.agentLabel, summary.model, summary.promptImagePaths, summary.modelProvider),
|
|
65
|
+
summary.agentLabel, summary.model, summary.promptImagePaths, summary.modelProvider, summary.reasoningEffort),
|
|
63
66
|
historyDetail: "full",
|
|
64
67
|
historyDetailError: undefined,
|
|
65
68
|
statusMessage: undefined,
|
|
@@ -82,7 +85,8 @@ export function hydrateTurnViewState(summary: TurnViewState, details: RemoteTurn
|
|
|
82
85
|
}
|
|
83
86
|
} else if (item.kind === "tool") {
|
|
84
87
|
state = reduceToolUpdate(state, item.tool, undefined, true);
|
|
85
|
-
state.activities = state.activities.map((a) => a.kind === "tool" && a.id === item.tool.id
|
|
88
|
+
state.activities = state.activities.map((a) => a.kind === "tool" && a.id === item.tool.id
|
|
89
|
+
? { ...a, tool: { ...item.tool, startedAt: a.tool.startedAt, completedAt: a.tool.completedAt } } : a);
|
|
86
90
|
} else if (item.kind === "reasoning") {
|
|
87
91
|
for (const [summaryIndex, text] of item.summary.entries()) {
|
|
88
92
|
state = reduceTurnEvent(state, { ...identity, type: "progress", text,
|
|
@@ -112,7 +116,7 @@ export function hydrateTurnViewState(summary: TurnViewState, details: RemoteTurn
|
|
|
112
116
|
};
|
|
113
117
|
}
|
|
114
118
|
|
|
115
|
-
export function reduceTurnEvent(state: TurnViewState, event: AgentEvent, complete = false): TurnViewState {
|
|
119
|
+
export function reduceTurnEvent(state: TurnViewState, event: AgentEvent, complete = false, historical = false): TurnViewState {
|
|
116
120
|
if (!canApplyTurnEvent(state, event)) return state;
|
|
117
121
|
const endingQueue = state.modelQueue && (event.type === "turn_completed" || event.type === "turn_cancelled"
|
|
118
122
|
|| event.type === "turn_failed" || event.type === "turn_status_unknown");
|
|
@@ -120,7 +124,7 @@ export function reduceTurnEvent(state: TurnViewState, event: AgentEvent, complet
|
|
|
120
124
|
type: "model_queue_updated", sessionId: state.sessionId, turnId: state.turnId, queue: { state: "ready" },
|
|
121
125
|
reason: event.type === "turn_status_unknown" ? "disconnected" : "turn_ended",
|
|
122
126
|
}) : state;
|
|
123
|
-
const next = reduceEvent(input, event);
|
|
127
|
+
const next = reduceEvent(input, event, historical);
|
|
124
128
|
if (!complete) return next;
|
|
125
129
|
if (event.type === "turn_completed") next.finalResponse = event.finalResponse;
|
|
126
130
|
if (event.type === "agent_text_delta") next.assistantText = state.assistantText + event.text;
|
|
@@ -140,15 +144,15 @@ export function reduceTurnEvent(state: TurnViewState, event: AgentEvent, complet
|
|
|
140
144
|
}
|
|
141
145
|
if (event.type === "tool_started" || event.type === "tool_updated") {
|
|
142
146
|
next.activities = next.activities.map((a) => a.kind === "tool" && a.id === event.tool.id
|
|
143
|
-
? { ...a, tool: { ...a.tool, ...event.tool } } : a);
|
|
147
|
+
? { ...a, tool: { ...a.tool, ...event.tool, startedAt: a.tool.startedAt, completedAt: a.tool.completedAt } } : a);
|
|
144
148
|
const files = new Map(state.fileSummary.map((f) => [f.path, f]));
|
|
145
|
-
for (const
|
|
149
|
+
for (const { path, additions, deletions } of event.tool.files ?? []) files.set(path, { path, additions, deletions });
|
|
146
150
|
next.fileSummary = [...files.values()];
|
|
147
151
|
}
|
|
148
152
|
return next;
|
|
149
153
|
}
|
|
150
154
|
|
|
151
|
-
function reduceEvent(state: TurnViewState, event: AgentEvent): TurnViewState {
|
|
155
|
+
function reduceEvent(state: TurnViewState, event: AgentEvent, historical: boolean): TurnViewState {
|
|
152
156
|
if (event.sessionId !== state.sessionId || event.turnId !== state.turnId) return state;
|
|
153
157
|
|
|
154
158
|
switch (event.type) {
|
|
@@ -330,7 +334,7 @@ function reduceEvent(state: TurnViewState, event: AgentEvent): TurnViewState {
|
|
|
330
334
|
case "plan_updated":
|
|
331
335
|
return { ...state, plan: event.steps.slice(0, 30).map((step) => ({ ...step, text: bound(step.text) })) };
|
|
332
336
|
case "tool_started": {
|
|
333
|
-
const tool = withToolTiming(state, event.tool);
|
|
337
|
+
const tool = withToolTiming(state, event.tool, historical);
|
|
334
338
|
const bounded = boundTool(tool);
|
|
335
339
|
const activityUpdate = upsertToolActivity(state.activities ?? [], bounded);
|
|
336
340
|
const tracking = trackToolStatus(state, tool);
|
|
@@ -345,9 +349,9 @@ function reduceEvent(state: TurnViewState, event: AgentEvent): TurnViewState {
|
|
|
345
349
|
};
|
|
346
350
|
}
|
|
347
351
|
case "tool_updated":
|
|
348
|
-
return reduceToolUpdate(state, event.tool);
|
|
352
|
+
return reduceToolUpdate(state, event.tool, undefined, historical);
|
|
349
353
|
case "tool_output_delta":
|
|
350
|
-
return reduceToolOutputDelta(state, event.toolId, event.delta);
|
|
354
|
+
return reduceToolOutputDelta(state, event.toolId, event.delta, historical);
|
|
351
355
|
case "approval_requested":
|
|
352
356
|
return { ...state, status: event.request.automatic ? state.activeTool ? "tool_running" : "running" : "waiting_for_approval", approval: event.request,
|
|
353
357
|
activities: [...state.activities.filter((a) => a.id !== approvalActivityId(event.turnId, event.request.id)), {
|
|
@@ -482,17 +486,19 @@ function approvalHistoryText(request: ApprovalRequest, decision?: ApprovalDecisi
|
|
|
482
486
|
].filter(Boolean).join("\n\n");
|
|
483
487
|
}
|
|
484
488
|
|
|
485
|
-
export function appendSteerMessage(state: TurnViewState, id: string, text: string, localImagePaths?: string[]): TurnViewState {
|
|
489
|
+
export function appendSteerMessage(state: TurnViewState, id: string, text: string, localImagePaths?: string[], startedAt?: number): TurnViewState {
|
|
486
490
|
const normalized = text.trim();
|
|
487
491
|
if (!normalized && !localImagePaths?.length) return state;
|
|
488
492
|
const activities = state.activities ?? [];
|
|
489
493
|
const index = activities.findIndex((activity) => activity.id === id);
|
|
490
494
|
const previous = activities[index];
|
|
491
495
|
const images = localImagePaths ?? (previous?.kind === "user" ? previous.localImagePaths : undefined);
|
|
496
|
+
const start = (previous?.kind === "user" ? previous.startedAt : undefined) ?? startedAt;
|
|
492
497
|
const activityUpdate = upsertActivity(activities, index, {
|
|
493
498
|
kind: "user",
|
|
494
499
|
id,
|
|
495
500
|
text: bound(normalized),
|
|
501
|
+
...(start === undefined ? {} : { startedAt: start }),
|
|
496
502
|
...(images?.length ? { localImagePaths: [...new Set(images)] } : {}),
|
|
497
503
|
});
|
|
498
504
|
return {
|
|
@@ -502,7 +508,7 @@ export function appendSteerMessage(state: TurnViewState, id: string, text: strin
|
|
|
502
508
|
};
|
|
503
509
|
}
|
|
504
510
|
|
|
505
|
-
function reduceToolOutputDelta(state: TurnViewState, toolId: string, delta: string): TurnViewState {
|
|
511
|
+
function reduceToolOutputDelta(state: TurnViewState, toolId: string, delta: string, historical: boolean): TurnViewState {
|
|
506
512
|
if (!delta) return state;
|
|
507
513
|
const tool = findTool(state, toolId);
|
|
508
514
|
if (!tool || tool.status !== "running" || tool.kind !== "command") return state;
|
|
@@ -510,7 +516,7 @@ function reduceToolOutputDelta(state: TurnViewState, toolId: string, delta: stri
|
|
|
510
516
|
return reduceToolUpdate(state, {
|
|
511
517
|
...tool,
|
|
512
518
|
output: appendBoundedOutput(tool.output, delta),
|
|
513
|
-
}, fullOutput);
|
|
519
|
+
}, fullOutput, historical);
|
|
514
520
|
}
|
|
515
521
|
|
|
516
522
|
function findTool(state: TurnViewState, toolId: string): ToolState | undefined {
|
|
@@ -522,14 +528,16 @@ function findTool(state: TurnViewState, toolId: string): ToolState | undefined {
|
|
|
522
528
|
?? state.completedTools.find((tool) => tool.id === toolId);
|
|
523
529
|
}
|
|
524
530
|
|
|
525
|
-
function withToolTiming(state: TurnViewState, tool: ToolState): ToolState {
|
|
531
|
+
function withToolTiming(state: TurnViewState, tool: ToolState, historical: boolean): ToolState {
|
|
526
532
|
const previous = findTool(state, tool.id);
|
|
527
|
-
const now = Date.now();
|
|
528
|
-
const
|
|
533
|
+
const now = historical ? undefined : Date.now();
|
|
534
|
+
const completedAt = toolTimestamp(tool.completedAt);
|
|
535
|
+
const startedAt = toolTimestamp(tool.startedAt) ?? toolTimestamp(previous?.startedAt)
|
|
536
|
+
?? (historical ? undefined : completedAt ?? now);
|
|
529
537
|
return {
|
|
530
538
|
...tool,
|
|
531
539
|
startedAt,
|
|
532
|
-
completedAt: tool.status === "running" ?
|
|
540
|
+
completedAt: tool.status === "running" ? completedAt : completedAt ?? toolTimestamp(previous?.completedAt) ?? now,
|
|
533
541
|
};
|
|
534
542
|
}
|
|
535
543
|
|
|
@@ -540,7 +548,7 @@ function appendBoundedOutput(previous: string | undefined, delta: string): strin
|
|
|
540
548
|
}
|
|
541
549
|
|
|
542
550
|
function reduceToolUpdate(state: TurnViewState, tool: ToolState, fullOutput?: string, historical = false): TurnViewState {
|
|
543
|
-
|
|
551
|
+
tool = withToolTiming(state, tool, historical);
|
|
544
552
|
const nextFullOutput = fullOutput ?? tool.output;
|
|
545
553
|
const fullToolOutputs = nextFullOutput === undefined
|
|
546
554
|
? state.fullToolOutputs
|
|
@@ -874,7 +882,10 @@ export function compactTurnView(state: TurnViewState): TurnViewState {
|
|
|
874
882
|
completedTools: state.completedTools.slice(-20).map(boundTool), failedTools: state.failedTools.slice(-5).map(boundTool),
|
|
875
883
|
fileSummary: state.fileSummary.slice(-30),
|
|
876
884
|
activitiesTruncated: state.activitiesTruncated || state.activities.length > 80,
|
|
877
|
-
|
|
885
|
+
// Keep only the reasoning anchors and summary headings in the hot snapshot; the body stays in the journal.
|
|
886
|
+
reasoningItems: state.reasoningItems?.slice(-32).map((item) => ({
|
|
887
|
+
...item, summary: item.summary.slice(0, 4).map((text) => text?.slice(0, 512) ?? ""), content: [],
|
|
888
|
+
})) ?? [], fullToolOutputs: {}, fullToolErrors: {},
|
|
878
889
|
toolStatuses: Object.fromEntries(Object.entries(state.toolStatuses ?? {}).filter(([id]) => ids.has(id))),
|
|
879
890
|
};
|
|
880
891
|
}
|
|
@@ -22,7 +22,7 @@ export type SystemActivityCategory = "context_compaction" | "model_queue";
|
|
|
22
22
|
export type TurnActivity =
|
|
23
23
|
| { kind: "assistant"; id: string; text: string }
|
|
24
24
|
| { kind: "system"; category: SystemActivityCategory; id: string; text: string }
|
|
25
|
-
| { kind: "user"; id: string; text: string; localImagePaths?: string[] }
|
|
25
|
+
| { kind: "user"; id: string; text: string; localImagePaths?: string[]; startedAt?: number }
|
|
26
26
|
| { kind: "reasoning"; id: string; text: string }
|
|
27
27
|
| { kind: "tool"; id: string; tool: ToolState };
|
|
28
28
|
|
|
@@ -50,9 +50,11 @@ export interface TurnViewState {
|
|
|
50
50
|
agentLabel?: string;
|
|
51
51
|
model?: string;
|
|
52
52
|
modelProvider?: string;
|
|
53
|
+
reasoningEffort?: string;
|
|
53
54
|
taskTitle?: string;
|
|
54
55
|
prompt?: string;
|
|
55
56
|
promptImagePaths?: string[];
|
|
57
|
+
promptRequestId?: string;
|
|
56
58
|
projectCwd?: string;
|
|
57
59
|
replyTarget?: MessageReplyTarget;
|
|
58
60
|
status: TurnViewStatus;
|