@keyou007/agent-bot 0.1.14-alpha.1 → 0.1.14-alpha.3
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 +19 -1
- package/README.md +48 -15
- package/README.zh.md +48 -15
- package/config.example.yaml +1 -1
- package/dist/cli/AutostartManager.js +431 -0
- package/dist/cli/AutostartManager.js.map +1 -0
- package/dist/cli/FeishuAppConfiguration.js +21 -13
- package/dist/cli/FeishuAppConfiguration.js.map +1 -1
- package/dist/cli/Initializer.js +35 -0
- package/dist/cli/Initializer.js.map +1 -1
- package/dist/cli/SelfUpdateRunner.js +552 -0
- package/dist/cli/SelfUpdateRunner.js.map +1 -0
- package/dist/cli/SelfUpdater.js +431 -0
- package/dist/cli/SelfUpdater.js.map +1 -0
- package/dist/cli/autostartOutput.js +63 -0
- package/dist/cli/autostartOutput.js.map +1 -0
- package/dist/cli/controlProtocol.js.map +1 -1
- package/dist/cli/help.js +94 -18
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/taskGroupOptions.js +14 -11
- package/dist/cli/taskGroupOptions.js.map +1 -1
- package/dist/cli/taskListOutput.js +3 -0
- package/dist/cli/taskListOutput.js.map +1 -1
- package/dist/cli/taskTarget.js +99 -0
- package/dist/cli/taskTarget.js.map +1 -0
- package/dist/cli.js +661 -58
- package/dist/cli.js.map +1 -1
- package/dist/codex/CodexRuntime.js +8 -2
- package/dist/codex/CodexRuntime.js.map +1 -1
- package/dist/commands/CommandRouter.js +16 -1
- package/dist/commands/CommandRouter.js.map +1 -1
- package/dist/feishu/CardRenderer.js +266 -38
- package/dist/feishu/CardRenderer.js.map +1 -1
- package/dist/feishu/FeishuMarkdown.js +25 -1
- package/dist/feishu/FeishuMarkdown.js.map +1 -1
- package/dist/feishu/FeishuMessageClient.js +16 -0
- package/dist/feishu/FeishuMessageClient.js.map +1 -1
- package/dist/feishu/FeishuTurnPresenter.js +42 -6
- package/dist/feishu/FeishuTurnPresenter.js.map +1 -1
- package/dist/index.js +136 -2
- package/dist/index.js.map +1 -1
- package/dist/presentation/OutboundRouter.js +7 -0
- package/dist/presentation/OutboundRouter.js.map +1 -1
- package/dist/presentation/TurnStateReducer.js +21 -7
- package/dist/presentation/TurnStateReducer.js.map +1 -1
- package/dist/proxy/ProxySessionController.js +537 -13
- package/dist/proxy/ProxySessionController.js.map +1 -1
- package/dist/state/StateStore.js +53 -0
- package/dist/state/StateStore.js.map +1 -1
- package/docs/technical-reference.md +17 -7
- package/docs/technical-reference.zh.md +17 -7
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -2
- package/skills/agent-bot/SKILL.md +109 -188
- package/src/cli/AutostartManager.ts +579 -0
- package/src/cli/FeishuAppConfiguration.ts +26 -7
- package/src/cli/Initializer.ts +57 -0
- package/src/cli/SelfUpdateRunner.ts +817 -0
- package/src/cli/SelfUpdater.ts +688 -0
- package/src/cli/autostartOutput.ts +75 -0
- package/src/cli/controlProtocol.ts +119 -1
- package/src/cli/help.ts +94 -18
- package/src/cli/taskGroupOptions.ts +27 -17
- package/src/cli/taskListOutput.ts +10 -0
- package/src/cli/taskTarget.ts +168 -0
- package/src/cli.ts +809 -65
- package/src/codex/CodexRuntime.ts +8 -2
- package/src/commands/CommandRouter.ts +14 -1
- package/src/commands/commandTypes.ts +2 -0
- package/src/feishu/CardRenderer.ts +313 -35
- package/src/feishu/FeishuMarkdown.ts +27 -1
- package/src/feishu/FeishuMessageClient.ts +33 -0
- package/src/feishu/FeishuTurnPresenter.ts +43 -6
- package/src/feishu/types.ts +1 -0
- package/src/index.ts +174 -2
- package/src/presentation/OutboundRouter.ts +7 -0
- package/src/presentation/TurnStateReducer.ts +21 -7
- package/src/proxy/ProxySessionController.ts +661 -16
- package/src/runtime/types.ts +1 -0
- package/src/state/StateStore.ts +56 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import type { SessionRecord } from "../state/StateStore.js";
|
|
2
|
+
import { cliLanguage, cliText, type CliLanguage } from "./i18n.js";
|
|
3
|
+
import {
|
|
4
|
+
currentAppServerThreadIds,
|
|
5
|
+
resolveCurrentTask,
|
|
6
|
+
taskCurrentExternalInvocationMessage,
|
|
7
|
+
} from "./taskListOutput.js";
|
|
8
|
+
|
|
9
|
+
export interface TaskCommandTarget {
|
|
10
|
+
session: SessionRecord;
|
|
11
|
+
args: string[];
|
|
12
|
+
source: "current" | "explicit";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function resolveTaskCommandTarget(
|
|
16
|
+
sessions: SessionRecord[],
|
|
17
|
+
args: string[],
|
|
18
|
+
action: string,
|
|
19
|
+
options: {
|
|
20
|
+
env?: NodeJS.ProcessEnv;
|
|
21
|
+
language?: CliLanguage;
|
|
22
|
+
preferCurrent?: boolean;
|
|
23
|
+
} = {},
|
|
24
|
+
): TaskCommandTarget {
|
|
25
|
+
const env = options.env ?? process.env;
|
|
26
|
+
const language = options.language ?? cliLanguage;
|
|
27
|
+
const extracted = extractTaskOption(args, action, language);
|
|
28
|
+
if (extracted.reference) {
|
|
29
|
+
return {
|
|
30
|
+
session: resolveTask(sessions, extracted.reference, language),
|
|
31
|
+
args: extracted.args,
|
|
32
|
+
source: "explicit",
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const first = extracted.args[0];
|
|
37
|
+
if (env.AGENT_BOT === "1") {
|
|
38
|
+
if (!options.preferCurrent && first && !first.startsWith("--")) {
|
|
39
|
+
const explicit = tryResolveTask(sessions, first, language);
|
|
40
|
+
if (explicit) {
|
|
41
|
+
return { session: explicit, args: extracted.args.slice(1), source: "explicit" };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
session: resolveCurrentTaskFromEnvironment(sessions, env, language),
|
|
46
|
+
args: extracted.args,
|
|
47
|
+
source: "current",
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
requireTaskCommandReference(action, first, language);
|
|
52
|
+
return {
|
|
53
|
+
session: resolveTask(sessions, first, language),
|
|
54
|
+
args: extracted.args.slice(1),
|
|
55
|
+
source: "explicit",
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function resolveCurrentTaskFromEnvironment(
|
|
60
|
+
sessions: SessionRecord[],
|
|
61
|
+
env: NodeJS.ProcessEnv = process.env,
|
|
62
|
+
language: CliLanguage = cliLanguage,
|
|
63
|
+
): SessionRecord {
|
|
64
|
+
if (env.AGENT_BOT !== "1") throw new Error(taskCurrentExternalInvocationMessage(language));
|
|
65
|
+
const resolution = resolveCurrentTask(sessions, currentAppServerThreadIds(env));
|
|
66
|
+
if (resolution.status === "found") return resolution.session;
|
|
67
|
+
if (resolution.status === "missing-thread-id") throw new Error(cliText(
|
|
68
|
+
"Agent Bot detected an Agent process, but no current task ID is available. Use agentbot task list and pass --task <task>.",
|
|
69
|
+
"已检测到 Agent Bot 中的 Agent 进程,但当前任务 ID 不可用。请使用 agentbot task list,并传入 --task <任务>。",
|
|
70
|
+
language,
|
|
71
|
+
));
|
|
72
|
+
if (resolution.status === "not-found") throw new Error(cliText(
|
|
73
|
+
`No AgentBot task matches the current App Server Thread ID (${resolution.threadIds.join(", ")}). Check that the correct Profile is selected.`,
|
|
74
|
+
`没有 AgentBot 任务匹配当前 App Server Thread ID(${resolution.threadIds.join(",")})。请检查是否选择了正确的 Profile。`,
|
|
75
|
+
language,
|
|
76
|
+
));
|
|
77
|
+
throw new Error(cliText(
|
|
78
|
+
"The current task is ambiguous because multiple injected Thread IDs match AgentBot tasks. Pass --task <task> with an explicit AgentBot task ID.",
|
|
79
|
+
"当前任务存在歧义:多个注入的 Thread ID 匹配到了 AgentBot 任务。请通过 --task <任务> 传入明确的 AgentBot 任务 ID。",
|
|
80
|
+
language,
|
|
81
|
+
));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function resolveTask(
|
|
85
|
+
sessions: SessionRecord[],
|
|
86
|
+
reference: string,
|
|
87
|
+
language: CliLanguage = cliLanguage,
|
|
88
|
+
): SessionRecord {
|
|
89
|
+
if (/^\d+$/.test(reference)) {
|
|
90
|
+
const index = Number(reference) - 1;
|
|
91
|
+
const session = sessions[index];
|
|
92
|
+
if (!session) throw new Error(cliText(
|
|
93
|
+
`Task number is out of range: ${reference}`,
|
|
94
|
+
`任务序号超出范围:${reference}`,
|
|
95
|
+
language,
|
|
96
|
+
));
|
|
97
|
+
return session;
|
|
98
|
+
}
|
|
99
|
+
const exact = sessions.find((session) =>
|
|
100
|
+
session.localSessionId === reference || session.remoteSessionId === reference || session.acpSessionId === reference);
|
|
101
|
+
if (exact) return exact;
|
|
102
|
+
const matches = sessions.filter((session) =>
|
|
103
|
+
session.localSessionId.startsWith(reference)
|
|
104
|
+
|| session.remoteSessionId?.startsWith(reference)
|
|
105
|
+
|| session.acpSessionId?.startsWith(reference));
|
|
106
|
+
if (matches.length === 1) return matches[0]!;
|
|
107
|
+
if (matches.length > 1) throw new Error(cliText(
|
|
108
|
+
`Task ID prefix is ambiguous: ${reference}`,
|
|
109
|
+
`任务 ID 前缀不唯一:${reference}`,
|
|
110
|
+
language,
|
|
111
|
+
));
|
|
112
|
+
throw new Error(cliText(`Task not found: ${reference}`, `未找到任务:${reference}`, language));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function extractTaskOption(
|
|
116
|
+
args: string[],
|
|
117
|
+
action: string,
|
|
118
|
+
language: CliLanguage,
|
|
119
|
+
): { reference?: string; args: string[] } {
|
|
120
|
+
const remaining: string[] = [];
|
|
121
|
+
let reference: string | undefined;
|
|
122
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
123
|
+
const value = args[index]!;
|
|
124
|
+
if (value !== "--task") {
|
|
125
|
+
remaining.push(value);
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (reference) throw new Error(cliText(
|
|
129
|
+
`task ${action} accepts --task only once.`,
|
|
130
|
+
`task ${action} 只能指定一次 --task。`,
|
|
131
|
+
language,
|
|
132
|
+
));
|
|
133
|
+
const candidate = args[index + 1]?.trim();
|
|
134
|
+
if (!candidate || candidate.startsWith("--")) throw new Error(cliText(
|
|
135
|
+
`task ${action} requires a task number or task ID after --task.`,
|
|
136
|
+
`task ${action} 需要在 --task 后指定任务序号或任务 ID。`,
|
|
137
|
+
language,
|
|
138
|
+
));
|
|
139
|
+
reference = candidate;
|
|
140
|
+
index += 1;
|
|
141
|
+
}
|
|
142
|
+
return { ...(reference ? { reference } : {}), args: remaining };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function tryResolveTask(
|
|
146
|
+
sessions: SessionRecord[],
|
|
147
|
+
reference: string,
|
|
148
|
+
language: CliLanguage,
|
|
149
|
+
): SessionRecord | undefined {
|
|
150
|
+
try {
|
|
151
|
+
return resolveTask(sessions, reference, language);
|
|
152
|
+
} catch {
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function requireTaskCommandReference(
|
|
158
|
+
action: string,
|
|
159
|
+
reference: string | undefined,
|
|
160
|
+
language: CliLanguage,
|
|
161
|
+
): asserts reference is string {
|
|
162
|
+
if (reference && !reference.startsWith("--")) return;
|
|
163
|
+
throw new Error(cliText(
|
|
164
|
+
`task ${action} requires a task number or task ID outside Agent Bot, or --task <task>.`,
|
|
165
|
+
`在 Agent Bot 外执行 task ${action} 时,需要任务序号或任务 ID,或传入 --task <任务>。`,
|
|
166
|
+
language,
|
|
167
|
+
));
|
|
168
|
+
}
|