@ai-zen/agents-sdk 1.2.0-alpha.2 → 2.0.0-alpha.1
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 +77 -0
- package/README.md +397 -113
- package/README.zh.md +314 -112
- package/dist/agent-plugins/AssetTransportPlugin.d.ts +51 -0
- package/dist/agent-plugins/AssetTransportPlugin.js +145 -0
- package/dist/agent-plugins/AutoMigratePlugin.d.ts +56 -6
- package/dist/agent-plugins/AutoMigratePlugin.js +64 -15
- package/dist/agent-plugins/AutoRefreshToolsPlugin.d.ts +12 -9
- package/dist/agent-plugins/AutoRefreshToolsPlugin.js +6 -7
- package/dist/agent-plugins/ContextGuardPlugin.d.ts +32 -24
- package/dist/agent-plugins/ContextGuardPlugin.js +37 -22
- package/dist/agent-plugins/SubAgentGuardInstallerPlugin.d.ts +38 -46
- package/dist/agent-plugins/SubAgentGuardInstallerPlugin.js +37 -50
- package/dist/agent-plugins/UnknownToolHintPlugin.d.ts +15 -1
- package/dist/agent-plugins/UnknownToolHintPlugin.js +15 -1
- package/dist/config/ConfigManager.d.ts +13 -5
- package/dist/config/ConfigManager.js +58 -39
- package/dist/config/constants.d.ts +1 -1
- package/dist/config/constants.js +2 -2
- package/dist/config/factory-skills.js +2 -2
- package/dist/config/normalize.d.ts +93 -0
- package/dist/config/normalize.js +158 -0
- package/dist/crud/AgentRepository.d.ts +3 -1
- package/dist/crud/AgentRepository.js +4 -2
- package/dist/index.d.ts +22 -9
- package/dist/index.js +16 -6
- package/dist/runtime/AgentRuntime.d.ts +293 -0
- package/dist/runtime/AgentRuntime.js +457 -0
- package/dist/runtime/HandoffGuardPlugin.d.ts +85 -16
- package/dist/runtime/HandoffGuardPlugin.js +140 -19
- package/dist/runtime/HandoffService.d.ts +255 -91
- package/dist/runtime/HandoffService.js +392 -177
- package/dist/runtime/RuntimePeerSessions.d.ts +34 -0
- package/dist/runtime/RuntimePeerSessions.js +50 -0
- package/dist/runtime/Scopes.d.ts +123 -0
- package/dist/runtime/Scopes.js +169 -0
- package/dist/runtime/SdkAgent.d.ts +21 -11
- package/dist/runtime/SdkAgent.js +24 -8
- package/dist/runtime/completeOnce.d.ts +3 -3
- package/dist/runtime/completeOnce.js +3 -3
- package/dist/runtime/createAgent.d.ts +29 -7
- package/dist/runtime/createAgent.js +57 -12
- package/dist/runtime/createModel.d.ts +4 -4
- package/dist/runtime/createModel.js +6 -6
- package/dist/runtime/lastPromptTokens.d.ts +18 -0
- package/dist/runtime/lastPromptTokens.js +26 -0
- package/dist/runtime/resolveModel.d.ts +9 -9
- package/dist/runtime/resolveModel.js +8 -8
- package/dist/scope/Scope.d.ts +42 -14
- package/dist/scope/Scope.js +55 -16
- package/dist/scope/ScopePlugin.d.ts +2 -8
- package/dist/scope/disclosure.d.ts +1 -1
- package/dist/scope/disclosure.js +1 -1
- package/dist/scope/plugins/allInOne.d.ts +13 -1
- package/dist/scope/plugins/allInOne.js +9 -5
- package/dist/scope/plugins/builtin/AsyncExecTool.d.ts +12 -0
- package/dist/scope/plugins/builtin/AsyncExecTool.js +103 -0
- package/dist/scope/plugins/builtin/AsyncTimeoutTool.d.ts +10 -0
- package/dist/scope/plugins/builtin/AsyncTimeoutTool.js +90 -0
- package/dist/scope/plugins/builtin/BuiltinToolsScopePlugin.d.ts +1 -1
- package/dist/scope/plugins/builtin/BuiltinToolsScopePlugin.js +1 -1
- package/dist/scope/plugins/builtin/DownloadFileTool.js +1 -1
- package/dist/scope/plugins/builtin/ExecTool.js +10 -199
- package/dist/scope/plugins/builtin/FindTextTool.d.ts +1 -1
- package/dist/scope/plugins/builtin/FindTextTool.js +1 -1
- package/dist/scope/plugins/builtin/GenerateImageTool.d.ts +1 -4
- package/dist/scope/plugins/builtin/GenerateImageTool.js +2 -8
- package/dist/scope/plugins/builtin/InspectFileTool.js +1 -1
- package/dist/scope/plugins/builtin/SdkCallbackTool.d.ts +4 -4
- package/dist/scope/plugins/builtin/SdkCallbackTool.js +3 -3
- package/dist/scope/plugins/builtin/SleepTool.js +2 -3
- package/dist/scope/plugins/builtin/ViewImageTool.d.ts +2 -4
- package/dist/scope/plugins/builtin/ViewImageTool.js +4 -6
- package/dist/scope/plugins/builtin/WriteTool.d.ts +7 -0
- package/dist/scope/plugins/builtin/WriteTool.js +8 -1
- package/dist/scope/plugins/builtin/asyncTasks.d.ts +41 -0
- package/dist/scope/plugins/builtin/asyncTasks.js +97 -0
- package/dist/scope/plugins/builtin/commandOutput.d.ts +22 -0
- package/dist/scope/plugins/builtin/commandOutput.js +55 -0
- package/dist/scope/plugins/builtin/commandRun.d.ts +48 -0
- package/dist/scope/plugins/builtin/commandRun.js +169 -0
- package/dist/scope/plugins/builtin/discover.d.ts +1 -3
- package/dist/scope/plugins/builtin/discover.js +1 -3
- package/dist/scope/plugins/builtin/index.d.ts +5 -7
- package/dist/scope/plugins/builtin/index.js +7 -7
- package/dist/scope/plugins/builtin/outputGuard.d.ts +1 -5
- package/dist/scope/plugins/builtin/outputGuard.js +1 -5
- package/dist/scope/plugins/mcp/McpConnectionManager.d.ts +61 -9
- package/dist/scope/plugins/mcp/McpConnectionManager.js +174 -72
- package/dist/scope/plugins/mcp/McpScopePlugin.d.ts +37 -4
- package/dist/scope/plugins/mcp/McpScopePlugin.js +100 -9
- package/dist/scope/plugins/mcp/discover.d.ts +9 -2
- package/dist/scope/plugins/mcp/discover.js +12 -14
- package/dist/scope/plugins/mcp/mcpTaskNotice.d.ts +52 -0
- package/dist/scope/plugins/mcp/mcpTaskNotice.js +8 -0
- package/dist/scope/plugins/mcp/mcpTools.d.ts +20 -2
- package/dist/scope/plugins/mcp/mcpTools.js +220 -39
- package/dist/scope/plugins/peers/PeerSessionsScopePlugin.d.ts +25 -0
- package/dist/scope/plugins/peers/PeerSessionsScopePlugin.js +32 -0
- package/dist/scope/plugins/peers/peerSessionTools.d.ts +173 -0
- package/dist/scope/plugins/peers/peerSessionTools.js +292 -0
- package/dist/scope/plugins/skills/SkillsScopePlugin.d.ts +4 -0
- package/dist/scope/plugins/skills/SkillsScopePlugin.js +10 -4
- package/dist/scope/plugins/skills/discover.d.ts +15 -8
- package/dist/scope/plugins/skills/discover.js +15 -26
- package/dist/scope/plugins/skills/skillTools.d.ts +9 -8
- package/dist/scope/plugins/skills/skillTools.js +21 -13
- package/dist/scope/plugins/subagents/SubAgentsScopePlugin.d.ts +4 -0
- package/dist/scope/plugins/subagents/SubAgentsScopePlugin.js +4 -1
- package/dist/scope/plugins/subagents/discover.d.ts +7 -1
- package/dist/scope/plugins/subagents/discover.js +7 -3
- package/dist/scope/plugins/subagents/subAgentTools.d.ts +0 -1
- package/dist/scope/plugins/subagents/subAgentTools.js +14 -1
- package/dist/scope/plugins/usertools/UserToolsScopePlugin.d.ts +4 -0
- package/dist/scope/plugins/usertools/UserToolsScopePlugin.js +4 -1
- package/dist/scope/plugins/usertools/discover.d.ts +7 -8
- package/dist/scope/plugins/usertools/discover.js +17 -27
- package/dist/shared/EntityRepository.d.ts +22 -5
- package/dist/shared/EntityRepository.js +45 -29
- package/dist/shared/content-blocks.d.ts +9 -3
- package/dist/shared/content-blocks.js +12 -19
- package/dist/shared/errors.d.ts +8 -3
- package/dist/shared/errors.js +9 -4
- package/dist/shared/logger.d.ts +21 -10
- package/dist/shared/logger.js +9 -15
- package/dist/types/index.d.ts +38 -13
- package/package.json +2 -2
- package/dist/config/migrate.d.ts +0 -115
- package/dist/config/migrate.js +0 -200
- package/dist/scope/plugins/builtin/test-helpers.d.ts +0 -3
- package/dist/scope/plugins/builtin/test-helpers.js +0 -4
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { AgentNS, type Agent, type AgentEvents, type AgentPlugin } from "@ai-zen/agents-core";
|
|
2
|
+
import type { Scope } from "../scope/Scope.js";
|
|
3
|
+
import type { PeerSessionCreated, PeerSessionPort, PeerSessionSent, PeerSessionStatus } from "../scope/plugins/peers/peerSessionTools.js";
|
|
4
|
+
import { type LogSink } from "../shared/logger.js";
|
|
5
|
+
import type { ModelParams } from "../types/index.js";
|
|
6
|
+
import { Scopes } from "./Scopes.js";
|
|
7
|
+
import type { ScopeCapabilities } from "./Scopes.js";
|
|
8
|
+
import type { SdkAgent } from "./SdkAgent.js";
|
|
9
|
+
/**
|
|
10
|
+
* 装出一个执行体需要的全部事实 —— 从上往下给(`TRD` 的「材料从上往下给」)。
|
|
11
|
+
*
|
|
12
|
+
* 这里没有一样是运行时自己去取的:历史与没取走的条目在库里的那一份只有宿主认得,模型解析的
|
|
13
|
+
* 三级链只有 `createAgent` 一处实现,运行时只负责把它们拼成一个活着的对象。
|
|
14
|
+
*/
|
|
15
|
+
export interface WakeMaterials {
|
|
16
|
+
/** 在哪一个目录上干活:能力容器按它取(同一个目录上的几段会话共用一个) */
|
|
17
|
+
cwd: string;
|
|
18
|
+
/** 用哪个助手定义装 */
|
|
19
|
+
agentId: string;
|
|
20
|
+
/** 这一段会话的模型覆盖(三级解析的第一级) */
|
|
21
|
+
modelId?: string;
|
|
22
|
+
/** 与 `modelId` 同一级的模型参数覆盖(档位补丁就叠在这一份上) */
|
|
23
|
+
modelParams?: ModelParams;
|
|
24
|
+
/**
|
|
25
|
+
* 谁开的这一段:`null` = 人建的,否则是开出它的那一段会话的身份。
|
|
26
|
+
*
|
|
27
|
+
* 运行时只拿它判一件事:这一段自己能不能再开一段(`PRD.md` 4.3 的「防俄罗斯套娃」)。
|
|
28
|
+
* 血缘本身是会话行上的事实,展示归宿主。
|
|
29
|
+
*/
|
|
30
|
+
lineage: string | null;
|
|
31
|
+
/** 已经落库的历史,按原顺序。**不含**助手定义里的模板消息 —— 那些由 `createAgent` 装 */
|
|
32
|
+
history: AgentNS.Message[];
|
|
33
|
+
/** 还没被取走的条目(上次没来得及处理的那几句),按入队顺序 */
|
|
34
|
+
waiting: AgentNS.InboxEntryWithContent[];
|
|
35
|
+
/**
|
|
36
|
+
* 这一段上要装的插件(比如越线自动交接)。
|
|
37
|
+
*
|
|
38
|
+
* 插件是**这一段会话的政策**:阈值与开关长在会话行上、配置在宿主的配置里,只有宿主说得清。
|
|
39
|
+
* 而「装」这一步是运行时的事 —— 材料从上往下给,装配由做装配的那一层做。
|
|
40
|
+
*/
|
|
41
|
+
plugins?: AgentPlugin[];
|
|
42
|
+
}
|
|
43
|
+
/** 开一段新会话要的事实:运行时发身份,行由宿主写 */
|
|
44
|
+
export interface NewPeerSession {
|
|
45
|
+
/** 哪一段会话开的 */
|
|
46
|
+
lineage: string;
|
|
47
|
+
/** 交给新会话的第一句话(它从空上下文开始,只能用这一句话知道要干什么) */
|
|
48
|
+
prompt: string;
|
|
49
|
+
/** 用哪个助手定义装 */
|
|
50
|
+
agentId: string;
|
|
51
|
+
/** 模型覆盖(不给就按该定义走三级解析) */
|
|
52
|
+
modelId?: string;
|
|
53
|
+
/** 模型给的可读名字;不给则由宿主按 `prompt` 起一个 */
|
|
54
|
+
label?: string;
|
|
55
|
+
}
|
|
56
|
+
/** `open` 的答案:开成了就把材料交回来,开不成给原因(运行时不替宿主编理由) */
|
|
57
|
+
export type OpenPeerSession = {
|
|
58
|
+
ok: true;
|
|
59
|
+
sessionId: string;
|
|
60
|
+
materials: WakeMaterials;
|
|
61
|
+
} | {
|
|
62
|
+
ok: false;
|
|
63
|
+
reason: "model_unresolved";
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* 运行时向宿主借的四件事。
|
|
67
|
+
*
|
|
68
|
+
* 它们全是「读写文件、写库」那一类:运行时自己不做这些,但必须有地方做。
|
|
69
|
+
*/
|
|
70
|
+
export interface RuntimePorts {
|
|
71
|
+
/** 造一个能力容器(怎么发现能力、装哪些插件归宿主) */
|
|
72
|
+
openScope(cwd: string, peers: PeerSessionPort): Promise<Scope>;
|
|
73
|
+
/** 开一段会话:写行、定身份、把装它的材料交回来 */
|
|
74
|
+
open(input: NewPeerSession): Promise<OpenPeerSession>;
|
|
75
|
+
/** 一段会话此刻叫什么(宿主从会话行现读);`undefined` = 库里没有这一段 */
|
|
76
|
+
nameOf(sessionId: string): Promise<string | undefined>;
|
|
77
|
+
/** 日志口(可选):不注入就什么都不记 */
|
|
78
|
+
log?: LogSink;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* 运行时交出去的事实。
|
|
82
|
+
*
|
|
83
|
+
* 三种来源,按 `type` 判别:
|
|
84
|
+
* - 运行时自己知道的两格:一段会话出现了(`resident:appeared`)、没了(`resident:gone`)。
|
|
85
|
+
* 这两件事只有运行时知道 —— 执行体自己说不出「我在这张登记表里」;
|
|
86
|
+
* - 能力容器的三格(`scope:` 前缀,与上面那一对并列):这个目录的容器造起来了(`scope:appeared`)、
|
|
87
|
+
* 按新配置刷新完了(`scope:refreshed`)、拆掉了(`scope:gone`)。前两格带一份能力快照(四个
|
|
88
|
+
* 维度的候选名),于是第三方不必再摸容器就能说「现在能用什么能力」;
|
|
89
|
+
* - 每个执行体的内核事件:名字与载荷**原样**转出(`started`、`messageAdded`、`state:idle` 等),
|
|
90
|
+
* 只额外带上它属于哪一段会话。
|
|
91
|
+
*
|
|
92
|
+
* 内核那一支为什么用映射类型拼、而不是手抄一份成员:手抄的那一份与内核的事件表迟早漂开,而漂开
|
|
93
|
+
* 的后果是订阅者按 `fact.type === "messageAdded"` 收窄不出载荷的形状。映射之后,每一个成员都是
|
|
94
|
+
* 「事件名 + 同一个名字的载荷 + 会话身份」的交叉,订阅者按名字判别就取得到那一格。
|
|
95
|
+
*
|
|
96
|
+
* 载荷里带出去的是活对象本身(内核原样),不是拷贝:收到事实的人手里攥着的就是那条消息。
|
|
97
|
+
*/
|
|
98
|
+
export type RuntimeFact = {
|
|
99
|
+
type: "resident:appeared";
|
|
100
|
+
sessionId: string;
|
|
101
|
+
cwd: string;
|
|
102
|
+
lineage: string | null;
|
|
103
|
+
agent: SdkAgent;
|
|
104
|
+
} | {
|
|
105
|
+
type: "resident:gone";
|
|
106
|
+
sessionId: string;
|
|
107
|
+
} | {
|
|
108
|
+
type: "scope:appeared";
|
|
109
|
+
cwd: string;
|
|
110
|
+
capabilities: ScopeCapabilities;
|
|
111
|
+
} | {
|
|
112
|
+
type: "scope:refreshed";
|
|
113
|
+
cwd: string;
|
|
114
|
+
capabilities: ScopeCapabilities;
|
|
115
|
+
} | {
|
|
116
|
+
type: "scope:gone";
|
|
117
|
+
cwd: string;
|
|
118
|
+
} | {
|
|
119
|
+
[K in keyof AgentEvents]: {
|
|
120
|
+
type: K;
|
|
121
|
+
sessionId: string;
|
|
122
|
+
} & AgentEvents[K];
|
|
123
|
+
}[keyof AgentEvents];
|
|
124
|
+
/** `send` 的答案与工具那一侧同一个形状(`ok` / 两条拒绝原因) */
|
|
125
|
+
export type PostResult = PeerSessionSent;
|
|
126
|
+
/**
|
|
127
|
+
* 运行时 —— 让执行体活着,并让它们互相说话。
|
|
128
|
+
*
|
|
129
|
+
* 三件事,共用同一份登记:
|
|
130
|
+
* - **常驻**:`wake` 装起来、登记、开跑;`kill` 收掉。一段会话最多一个执行体。
|
|
131
|
+
* - **事件驱动**:没有人 `await` 也照样跑 —— 一条投递把它从闲推到忙,跑完自己回到闲。
|
|
132
|
+
* 运行时不给「等它跑完」这种口,常驻会话也没有「跑完了」这个对象。
|
|
133
|
+
* - **发话**:`post` 把一句话寄给另一段会话(模型那一侧对应的工具是 `post_message`)。
|
|
134
|
+
*
|
|
135
|
+
* 它还管能力容器的生死(见 `Scopes`):容器按目录存活,「这个目录上还有几段会话活着」由登记表
|
|
136
|
+
* 自己答得出,不必问谁。
|
|
137
|
+
*
|
|
138
|
+
* 它自己**没有**库、连接、凭证、语言与用户可见文案,也不认识会话行:身份是不透明的字符串,
|
|
139
|
+
* 名字要问 `ports.nameOf`。
|
|
140
|
+
*/
|
|
141
|
+
export declare class AgentRuntime {
|
|
142
|
+
private readonly ports;
|
|
143
|
+
/**
|
|
144
|
+
* 活着的那些。**只有活着的**:杀死与删会话都把登记项去掉,于是「这一段在我这儿还在不在」
|
|
145
|
+
* 与「它有没有执行体」是同一个问题。
|
|
146
|
+
*/
|
|
147
|
+
private readonly residents;
|
|
148
|
+
/**
|
|
149
|
+
* 正在装的那几次。记的是那次调用的 Promise:记「正在装」的布尔标志会在两次并发唤醒里一起
|
|
150
|
+
* 看到 false,于是装出两个执行体,而登记表只留得下一个。
|
|
151
|
+
*/
|
|
152
|
+
private readonly waking;
|
|
153
|
+
/** 订了这份事实的那些人。**旁路**:只收,不参与任何判断 */
|
|
154
|
+
private readonly listeners;
|
|
155
|
+
/**
|
|
156
|
+
* 每个活着的执行体那一组转发订阅,按会话收好。
|
|
157
|
+
*
|
|
158
|
+
* 与登记表分开的理由:登记表答的是「谁活着」,这张表答的是「谁的转发还没解」。杀一段会话只解
|
|
159
|
+
* 它自己那一组,别的执行体一个字都不动。
|
|
160
|
+
*/
|
|
161
|
+
private readonly forwarders;
|
|
162
|
+
/**
|
|
163
|
+
* 记日志的地方。缺省 {@link SILENT_LOG}(不注入就什么都不写)。
|
|
164
|
+
*
|
|
165
|
+
* 收成字段而不是在每个方法里现算 `ports.log ?? SILENT_LOG`:缺省值只在一处定,「不注入日志
|
|
166
|
+
* 时会发生什么」才答得上来。
|
|
167
|
+
*/
|
|
168
|
+
private readonly log;
|
|
169
|
+
/** 能力容器:按目录一份,什么时候造、什么时候拆归它 */
|
|
170
|
+
readonly scopes: Scopes;
|
|
171
|
+
/** 平级会话的三方法端口:插件拿它造那三个工具,宿主这里一个字节都不必知道 */
|
|
172
|
+
readonly peerSessions: PeerSessionPort;
|
|
173
|
+
constructor(ports: RuntimePorts);
|
|
174
|
+
/**
|
|
175
|
+
* 订阅运行时交出去的事实;返回退订函数(幂等:连着调两次不会炸)。
|
|
176
|
+
*
|
|
177
|
+
* 这是**旁路**:订阅者不改任何决定,也不参与任何判断。晚到的订阅者拿不到过去的事实 ——
|
|
178
|
+
* 事实只报变化,快照那一侧由 `get` / `aliveOn` 对齐,两者合起来才说得清「此刻」与「怎么走到
|
|
179
|
+
* 这一刻」。
|
|
180
|
+
*/
|
|
181
|
+
observe(listener: (fact: RuntimeFact) => void): () => void;
|
|
182
|
+
/** 这一段此刻活着的执行体;没有就是 `undefined` */
|
|
183
|
+
get(sessionId: string): SdkAgent | undefined;
|
|
184
|
+
/** 这个执行体属于哪一段会话;查不到 = 它不属于任何一段(被派出去的那个) */
|
|
185
|
+
sessionOf(agent: Agent): string | undefined;
|
|
186
|
+
/** 这个目录上还活着哪几段会话(拆容器之前问的就是它) */
|
|
187
|
+
aliveOn(cwd: string): readonly string[];
|
|
188
|
+
/**
|
|
189
|
+
* 唤醒:装起来、登记、开跑。
|
|
190
|
+
*
|
|
191
|
+
* **幂等**:已经活着就把它交回去;正在装的话,等的是同一次装。两个触发方同时叫醒同一段
|
|
192
|
+
* (客户端连点两下发送)不该装出两个执行体 —— 那条会话的记忆只有一个,两个执行体会同时写它。
|
|
193
|
+
*
|
|
194
|
+
* 装不出来就抛(模型解析不出来、定义文件读不出来、历史形状不对),并且**不留登记项**:
|
|
195
|
+
* 一个装了一半的会话在登记表里,等于告诉外面「它活着」,而它连件都收不了。
|
|
196
|
+
*/
|
|
197
|
+
wake(sessionId: string, materials: WakeMaterials): Promise<SdkAgent>;
|
|
198
|
+
/**
|
|
199
|
+
* 发话:把一句话寄给另一段会话。
|
|
200
|
+
*
|
|
201
|
+
* **投递不创建、也不复活会话**(`PRD.md` 4.1):目标没有执行体就是没投出去,由发起方自己
|
|
202
|
+
* 决定怎么跟用户说。两条拒绝原因要分得开 —— `gone` 是这段会话不在了(行都没了),`dead`
|
|
203
|
+
* 是行还在、只是没人取件。判据只有宿主答得出,所以问 `nameOf`。
|
|
204
|
+
*
|
|
205
|
+
* 优先级是 `low`:寄来的话不该插进对方手上那一批的工具调用之间。对方这一批跑完再取它,
|
|
206
|
+
* 顺序是它自己队列的顺序。**投递不承诺任何未来** —— 收下了就是收下了。
|
|
207
|
+
*/
|
|
208
|
+
post(input: {
|
|
209
|
+
from: string;
|
|
210
|
+
to: string;
|
|
211
|
+
content: AgentNS.MessageContent;
|
|
212
|
+
}): Promise<PostResult>;
|
|
213
|
+
/**
|
|
214
|
+
* 一段会话此刻什么样:忙不忙、名字、最近说了什么。
|
|
215
|
+
*
|
|
216
|
+
* **不给全量消息、不给历史**:这个答案唯一的读者是另一段会话的模型,给了原文它就会把对方的
|
|
217
|
+
* 记忆当上下文搬运(`PRD.md` 4.3)。
|
|
218
|
+
*
|
|
219
|
+
* `found: false` 说的是「我这儿没有它的执行体」:会话行被删了,或者进程重启之后还没人叫醒
|
|
220
|
+
* 它,都落在这一格。
|
|
221
|
+
*/
|
|
222
|
+
status(sessionId: string): Promise<PeerSessionStatus>;
|
|
223
|
+
/**
|
|
224
|
+
* 开一段平级会话:写行、装起来、把 `prompt` 递进去,建完即回。
|
|
225
|
+
*
|
|
226
|
+
* **只许开一层**(`PRD.md` 4.3):一段会话本身是别人开出来的话,它开不出第二层;被派出去的
|
|
227
|
+
* 那个执行体(subagent)不属于任何一段会话,同样开不出来。判据是登记表里的血缘 —— 这一格
|
|
228
|
+
* 只有运行时知道,所以这条规矩落在这里,而不是落在一道谁也查不动的校验里。
|
|
229
|
+
*
|
|
230
|
+
* 不等那边的答复:它收下这句话之后怎么干、什么时候干,都不是这一句能定下的。
|
|
231
|
+
*/
|
|
232
|
+
openPeer(input: {
|
|
233
|
+
from: string;
|
|
234
|
+
prompt: string;
|
|
235
|
+
agentId?: string;
|
|
236
|
+
modelId?: string;
|
|
237
|
+
label?: string;
|
|
238
|
+
}): Promise<PeerSessionCreated>;
|
|
239
|
+
/**
|
|
240
|
+
* 杀死:执行体销毁,登记项去掉。会话行与历史留着(`PRD.md` 4.1)。
|
|
241
|
+
*
|
|
242
|
+
* 四步次序(`live-objects.md` 判据四):
|
|
243
|
+
* - 先去掉登记项再杀:杀死会发最后几条事件,那时这一段不该还能被别人查到活着的执行体,
|
|
244
|
+
* 也不该有人趁这一刻往里投话;
|
|
245
|
+
* - 杀完再报「没了」:它最后那几条事实要排在这一条之前转出去;
|
|
246
|
+
* - 报完再解这一组转发订阅:先解再报的话,订阅者永远不知道自己漏了什么。
|
|
247
|
+
*/
|
|
248
|
+
kill(sessionId: string): void;
|
|
249
|
+
/** 收工:杀光、拆光。进程退出前那一步;此后再叫醒就要重新给材料 */
|
|
250
|
+
close(): Promise<void>;
|
|
251
|
+
/**
|
|
252
|
+
* 装配:取容器、造执行体、装材料里带的插件、把历史接在模板后面、把没取走的条目放回队列。
|
|
253
|
+
*
|
|
254
|
+
* 两处次序不是随手定的:
|
|
255
|
+
* - 历史一条一条 `append`,**不给 `agent.messages` 整体赋值**:那个数组是记忆的唯一真相,
|
|
256
|
+
* 换掉它会让已经拿到引用的地方继续指着旧的那一份;
|
|
257
|
+
* - 放回队列排在装历史之后:一条条目落过地没有,判据是它那条消息在不在已经装好的历史里。
|
|
258
|
+
* 反过来排,这个判据就得另找一份账。
|
|
259
|
+
*
|
|
260
|
+
* 插件与「报出现」都排在 `start()` 之前,理由各自写在那两处。
|
|
261
|
+
*/
|
|
262
|
+
private assemble;
|
|
263
|
+
/**
|
|
264
|
+
* 给一个执行体挂上转发:它的每一条内核事件都变成一条运行时事实(名字与载荷原样,只多一个
|
|
265
|
+
* 会话身份)。交回来的是这一组退订函数,由调用方按会话收好。
|
|
266
|
+
*/
|
|
267
|
+
private forward;
|
|
268
|
+
/**
|
|
269
|
+
* 把一条事实交给每一个订阅者。
|
|
270
|
+
*
|
|
271
|
+
* **这是「把事实交给每个订阅者」的唯一循环**:运行时的每一格事实(`resident:` 那两格、
|
|
272
|
+
* `scope:` 那三格、每个执行体转发上来的内核事件)都从这里出去,没有第二条路。所以隔离只需要
|
|
273
|
+
* 兜在这一处 —— 漏不出第二个循环去。
|
|
274
|
+
*
|
|
275
|
+
* 一个订阅者抛错:记一句日志,接着交给下一个。抛错既不该连累别的订阅者,也不该打断被观察的
|
|
276
|
+
* 执行体(更没有打断这一趟叫醒的道理)。
|
|
277
|
+
*
|
|
278
|
+
* **与内核那条 `observerFailed` 的分工**:内核报的是「某个执行体的订阅者炸了」,它有一个
|
|
279
|
+
* 执行体可以挂在上面(那条事实的 `agent` 一格)。这里没有「被观察的活物」可挂 ——
|
|
280
|
+
* `broadcast` 交出去的正是事实本身,来源可能只是一个目录。替它另造一种事实,就得回答
|
|
281
|
+
* 「这条事实的订阅者又炸了怎么办」,而那是一个死循环。
|
|
282
|
+
*
|
|
283
|
+
* **为什么必须兜**:`broadcast` 就在 `assemble()` 里(报「这一段出现了」那一下)。订阅者一
|
|
284
|
+
* 抛,`wake` 会以一个旁路者的错误失败 —— 而那时登记项已经写进 `residents`、`start()` 还没
|
|
285
|
+
* 调用,等于留下一段「登记着却永远不跑」的会话:`get` / `aliveOn` 都说它活着,它却一件事都
|
|
286
|
+
* 不会做。
|
|
287
|
+
*/
|
|
288
|
+
private broadcast;
|
|
289
|
+
/** 解掉一段会话的转发订阅(整组解,只解这一段会话) */
|
|
290
|
+
private detach;
|
|
291
|
+
/** 这一段此刻叫什么;库里已经没有这一段时退回身份本身(说得出是哪一段,不编一个名字) */
|
|
292
|
+
private labelOf;
|
|
293
|
+
}
|