@springbrand/agent-runtime 0.2.0-alpha.72 → 0.3.0-alpha.2
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/package.json +3 -3
- package/src/{agent-tool-runtime.ts → adapter/cloudflare/agent-tool.ts} +1 -1
- package/src/adapter/cloudflare/agent.ts +1592 -0
- package/src/{db/index.ts → adapter/cloudflare/database.ts} +18 -55
- package/src/{runtime-agent.ts → adapter/cloudflare/define-agent.ts} +25 -35
- package/src/adapter/cloudflare/dynamic-worker-observability.ts +1 -1
- package/src/adapter/cloudflare/resources/runtime-resources.ts +4 -4
- package/src/adapter/cloudflare/sandbox/adapter.ts +1 -1
- package/src/{db → adapter/cloudflare}/schema.ts +16 -83
- package/src/adapter/cloudflare/subagent/definition.ts +63 -33
- package/src/adapter/cloudflare/subagent/runner.ts +174 -120
- package/src/adapter/cloudflare/subagent/tools.ts +13 -14
- package/src/adapter/cloudflare/universal-agent/preparation.ts +7 -7
- package/src/adapter/cloudflare/universal-agent/tools.ts +10 -10
- package/src/adapter/cloudflare/workspace/git-fs.ts +1 -1
- package/src/adapter/cloudflare/workspace/scoped-workspace.ts +1 -1
- package/src/adapter/cloudflare/workspace/version-control.ts +2 -2
- package/src/config/activation.ts +140 -0
- package/src/{runtime-agent-context.ts → config/agent-context.ts} +3 -3
- package/src/{runtime-assembler.ts → config/assembler.ts} +20 -19
- package/src/{kernel/runtime-assembly.ts → config/assembly-projection.ts} +4 -4
- package/src/{pi/assembly/snapshot.ts → config/assembly-snapshot.ts} +6 -6
- package/src/{runtime-definition.ts → config/definition.ts} +13 -13
- package/src/config/harness-runtime.ts +182 -0
- package/src/config/index.ts +14 -0
- package/src/{pi/runtime-adapter/assembly.ts → config/pinning.ts} +38 -16
- package/src/{kernel/bindings.ts → config/ports.ts} +9 -13
- package/src/{kernel → config}/profile.ts +7 -0
- package/src/{kernel → config}/public-contracts.ts +6 -6
- package/src/{kernel → config}/runtime-load.ts +1 -1
- package/src/{pi/assembly/context.ts → context/assembly.ts} +4 -206
- package/src/{pi/assembly/extensions.ts → context/extension/assembly.ts} +5 -5
- package/src/context/extension/index.ts +3 -0
- package/src/context/index.ts +6 -0
- package/src/{layers/context → context/memory}/budget/gate.ts +2 -2
- package/src/conversation/harness-resume.ts +288 -0
- package/src/conversation/harness-stream.ts +98 -0
- package/src/{pi/runtime-adapter/transcript.ts → conversation/history.ts} +206 -233
- package/src/conversation/index.ts +6 -0
- package/src/{pi → conversation}/message/contract.ts +3 -0
- package/src/{pi → conversation}/message/conversion.ts +75 -0
- package/src/{pi → conversation}/message/index.ts +1 -0
- package/src/{pi → conversation}/message/model-input.ts +1 -1
- package/src/{pi → conversation}/message/projection.ts +76 -10
- package/src/{db/message-ui.repo.ts → conversation/repository.ts} +4 -0
- package/src/conversation/state.ts +175 -0
- package/src/harness/index.ts +7 -0
- package/src/harness/session-harness.ts +481 -0
- package/src/harness/submission-operation.ts +49 -0
- package/src/index.ts +38 -43
- package/src/lib/mcp.ts +1 -1
- package/src/{pi/runtime-adapter/models.ts → models/index.ts} +64 -18
- package/src/{pi/turn/tool-recovery.ts → session/cloudflare/legacy-tool-recovery.ts} +33 -525
- package/src/{pi/session → session/cloudflare}/migration.ts +334 -8
- package/src/{pi/session → session/cloudflare}/storage.ts +8 -36
- package/src/session/index.ts +39 -0
- package/src/submission/admission.ts +275 -0
- package/src/{kernel/receipts.ts → submission/contracts.ts} +14 -0
- package/src/submission/delivery.ts +212 -0
- package/src/submission/finalization.ts +111 -0
- package/src/submission/index.ts +9 -0
- package/src/{kernel/submission-lifecycle.ts → submission/lifecycle.ts} +41 -28
- package/src/{db/submission.repo.ts → submission/repository.ts} +62 -119
- package/src/submission/steer-delivery.ts +167 -0
- package/src/{db/steer.repo.ts → submission/steer-repository.ts} +27 -5
- package/src/telemetry/contract.ts +12 -0
- package/src/telemetry/coordinator.ts +65 -0
- package/src/telemetry/delivery.ts +2 -2
- package/src/telemetry/index.ts +5 -0
- package/src/{model-usage.ts → telemetry/model-usage.ts} +1 -1
- package/src/telemetry/recorder.ts +1 -1
- package/src/telemetry/runtime-telemetry.ts +12 -0
- package/src/{kernel/durable-lifecycle.ts → telemetry/subagent-lifecycle.ts} +1 -1
- package/src/telemetry/turn-events.ts +279 -0
- package/src/{pi/tool → tools}/ai-adapter.ts +2 -2
- package/src/tools/approval/index.ts +1 -0
- package/src/{db/approval.repo.ts → tools/approval/repository.ts} +10 -30
- package/src/{pi/tool → tools}/base.ts +14 -30
- package/src/tools/compiler.ts +327 -0
- package/src/{pi/tool → tools}/core-host.ts +3 -3
- package/src/{pi/tool → tools}/core.ts +3 -3
- package/src/tools/decision-gate.ts +227 -0
- package/src/{pi/tool → tools}/gateway.ts +1 -1
- package/src/tools/human-decisions.ts +127 -0
- package/src/tools/index.ts +30 -0
- package/src/tools/interaction/index.ts +1 -0
- package/src/{pi/tool → tools}/mcp.ts +1 -1
- package/src/{pi/tool → tools}/schedule.ts +3 -3
- package/src/{pi/tool → tools}/skill.ts +4 -4
- package/src/{kernel → tools}/subagent-runtime.ts +1 -1
- package/src/{pi/tool → tools}/subagent.ts +4 -4
- package/src/tools/temporary-agent/approvals.ts +126 -0
- package/src/{layers/orchestration/temporary-agent/core.ts → tools/temporary-agent/coordinator.ts} +41 -49
- package/src/tools/temporary-agent/core.ts +53 -0
- package/src/{layers/orchestration → tools}/temporary-agent/runner.ts +1 -1
- package/src/{layers/orchestration → tools}/temporary-agent/workspace.ts +1 -1
- package/src/{pi/tool → tools}/web-search/api.ts +1 -1
- package/src/{pi/tool → tools}/workspace-revision.ts +2 -2
- package/src/{pi/tool → tools}/workspace-sandbox.ts +2 -2
- package/src/{pi/tool → tools}/workspace-state-connector.ts +1 -1
- package/src/db/milestone.repo.ts +0 -104
- package/src/db/settlement.repo.ts +0 -104
- package/src/kernel/approval-lifecycle.ts +0 -638
- package/src/kernel/interaction-lifecycle.ts +0 -433
- package/src/kernel/recoverable-chat-agent.ts +0 -1020
- package/src/kernel/state.ts +0 -91
- package/src/pi/assembly/index.ts +0 -19
- package/src/pi/runtime-adapter/execution.ts +0 -1163
- package/src/pi/runtime-adapter/index.ts +0 -293
- package/src/pi/runtime-adapter/recovery.ts +0 -982
- package/src/pi/session/index.ts +0 -24
- package/src/pi/tool/compiler.ts +0 -483
- package/src/pi/tool/index.ts +0 -38
- package/src/pi/turn/approval.ts +0 -181
- package/src/pi/turn/index.ts +0 -82
- package/src/pi/turn/interaction.ts +0 -181
- package/src/runtime.ts +0 -4760
- /package/src/{kernel/runtime-assembly-view.ts → config/assembly-view.ts} +0 -0
- /package/src/{kernel → config}/degradation.ts +0 -0
- /package/src/{kernel → config}/runtime-config.ts +0 -0
- /package/src/{kernel/extensions.ts → context/extension/contracts.ts} +0 -0
- /package/src/{db/ext-context.repo.ts → context/extension/repository.ts} +0 -0
- /package/src/{pi/runtime-adapter/openrouter-messages.ts → models/openrouter/messages.ts} +0 -0
- /package/src/{pi/runtime-adapter → models/openrouter}/test-fixtures/openrouter-tool-search.sse +0 -0
- /package/src/{db/submission-admission.repo.ts → submission/admission-repository.ts} +0 -0
- /package/src/{db/telemetry-outbox.repo.ts → telemetry/repository.ts} +0 -0
- /package/src/{db/runtime-event-outbox.repo.ts → telemetry/runtime-event-repository.ts} +0 -0
- /package/src/{pi/tool → tools}/declared.ts +0 -0
- /package/src/{db/interaction.repo.ts → tools/interaction/repository.ts} +0 -0
- /package/src/{pi/tool → tools}/nested-tools.ts +0 -0
- /package/src/{kernel/submission-authority.ts → tools/subagent-authority.ts} +0 -0
- /package/src/{db/agent-tool.repo.ts → tools/subagent-run-repository.ts} +0 -0
- /package/src/{layers/orchestration/subagents/agent-types → tools/subagent-types}/contract.ts +0 -0
- /package/src/{layers/orchestration/subagents/agent-types → tools/subagent-types}/extract/index.ts +0 -0
- /package/src/{layers/orchestration/subagents/agent-types → tools/subagent-types}/fanout/index.ts +0 -0
- /package/src/{layers/orchestration/subagents/agent-types → tools/subagent-types}/registry.ts +0 -0
- /package/src/{pi/tool → tools}/time.ts +0 -0
- /package/src/{pi/tool → tools}/web-fetch.ts +0 -0
- /package/src/{pi/tool → tools}/web-search/index.ts +0 -0
- /package/src/{pi/tool → tools}/web-search/web-search.ts +0 -0
- /package/src/{workspace-versioning.ts → tools/workspace-versioning.ts} +0 -0
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PreparedPiTurnAdapter,
|
|
3
|
-
type CreatePreparedPiTurnOptions,
|
|
4
|
-
} from "./execution";
|
|
5
|
-
export {
|
|
6
|
-
ContextOverflowError,
|
|
7
|
-
RetryableModelError,
|
|
8
|
-
RetryableModelSessionError,
|
|
9
|
-
} from "./execution";
|
|
10
|
-
import {
|
|
11
|
-
uiUserMessageToPi,
|
|
12
|
-
} from "../message";
|
|
13
|
-
import type { UIMessage } from "ai";
|
|
14
|
-
import { createModels, type MutableModels } from "@earendil-works/pi-ai";
|
|
15
|
-
import { configurePiModels, createPiModels } from "./models";
|
|
16
|
-
export {
|
|
17
|
-
MODEL_STREAM_STALL_TIMEOUT_MS,
|
|
18
|
-
modelRequestUrl,
|
|
19
|
-
readModelStreamStallDetails,
|
|
20
|
-
withProviderRetry,
|
|
21
|
-
} from "./models";
|
|
22
|
-
import {
|
|
23
|
-
pinPiRuntime,
|
|
24
|
-
preparePiRuntime,
|
|
25
|
-
readPreparedPiRuntime,
|
|
26
|
-
type PinPiRuntimeOptions,
|
|
27
|
-
type PinnedPiRuntime,
|
|
28
|
-
type PreparePiRuntimeOptions,
|
|
29
|
-
type PreparedPiRuntime,
|
|
30
|
-
} from "./assembly";
|
|
31
|
-
import {
|
|
32
|
-
decidePiRecovery,
|
|
33
|
-
recordPiToolMilestone,
|
|
34
|
-
type PiToolMilestoneInput,
|
|
35
|
-
PiRuntimeRecoveryAdapter,
|
|
36
|
-
type PiRecoveryHost,
|
|
37
|
-
type PiRecoveryInput,
|
|
38
|
-
} from "./recovery";
|
|
39
|
-
import {
|
|
40
|
-
PiRuntimeTranscript,
|
|
41
|
-
type PiTranscriptDurability,
|
|
42
|
-
} from "./transcript";
|
|
43
|
-
import { subagentPiToolCandidates } from "../tool/subagent";
|
|
44
|
-
import type {
|
|
45
|
-
RuntimeSubagentLifecyclePort,
|
|
46
|
-
RuntimeSubagentPort,
|
|
47
|
-
} from "../../kernel/bindings";
|
|
48
|
-
import type { SqlTaggedTemplate } from "agents/chat";
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Runtime 只通过这个入口使用 Pi 的装配、执行、消息和恢复能力。
|
|
52
|
-
*
|
|
53
|
-
* @remarks
|
|
54
|
-
* Runtime、Pi、Turn、Tool Candidate 和 canonical transcript 等核心术语见包入口 `../../index.ts`。
|
|
55
|
-
* 本适配器只补充以下局部术语。
|
|
56
|
-
*
|
|
57
|
-
* - Prepared Runtime 是配置加载期产生的不透明句柄。
|
|
58
|
-
* 它包含已加载 Extension、Tool candidate 和快照,但 Runtime 只能读取 revision descriptor 与 degradation。
|
|
59
|
-
* - revision descriptor 是影响执行行为的已排序 JSON 描述。
|
|
60
|
-
* Runtime 会对它取哈希,用来识别当前 Prepared Runtime 的基础版本。
|
|
61
|
-
* - Pinned Runtime 是 Submission 准入时固定的描述符。
|
|
62
|
-
* 它在 Prepared Runtime 基础上加入动态 system context、approval mode 和 base revision。
|
|
63
|
-
* - recovery milestone 是可重放的持久化恢复记录。
|
|
64
|
-
* recovery effect 是重放后交给 Runtime 执行的唯一下一步动作。
|
|
65
|
-
*
|
|
66
|
-
* 调用方:`AgentRuntimeKernel` 在配置加载、请求准入、Turn 执行和中断恢复时调用这些粗粒度能力。
|
|
67
|
-
*
|
|
68
|
-
* 实现理由:较早的入口曾直接公开 assembly、message、session、tool 和 recovery 命名空间。
|
|
69
|
-
* 当前边界刻意隐藏这些细节,避免 Runtime 同时维护第二套 Pi 状态或绕过统一校验。
|
|
70
|
-
* 不要为了调用某个内部 helper 重新导出子模块;应先判断它是否属于 Runtime 真正需要的边界能力。
|
|
71
|
-
*/
|
|
72
|
-
export class PiRuntimeAdapter {
|
|
73
|
-
private readonly owner = {};
|
|
74
|
-
private readonly models: MutableModels;
|
|
75
|
-
private readonly managesModels: boolean;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* 创建一个持有独立 Pi 模型目录的 Runtime 适配器。
|
|
79
|
-
*
|
|
80
|
-
* @remarks
|
|
81
|
-
* 调用方:生产 Runtime 使用零参数构造,测试或专用宿主可以注入已经配置好的模型目录。
|
|
82
|
-
*
|
|
83
|
-
* 实现理由:适配器只管理自己创建的目录;注入目录的生命周期和配置权仍属于注入方。
|
|
84
|
-
* 不要让 `activate()` 重配注入目录,否则会覆盖调用方准备的 provider 和模型替身。
|
|
85
|
-
*/
|
|
86
|
-
constructor(options: { models?: MutableModels } = {}) {
|
|
87
|
-
this.models = options.models ?? createModels();
|
|
88
|
-
this.managesModels = !options.models;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* 创建负责 canonical transcript、浏览器投影和上下文压缩的对象。
|
|
93
|
-
*
|
|
94
|
-
* @remarks
|
|
95
|
-
* 调用方:Runtime 构造函数为当前实例创建一次,并提供 SQLite、事务和 Submission 投影回调。
|
|
96
|
-
*
|
|
97
|
-
* 实现理由:transcript 与 Turn 共用同一个模型目录,让上下文压缩和实际执行看到相同的 provider 配置。
|
|
98
|
-
* 不要把 RuntimeDatabase 直接传进 Pi 层;持久化职责应继续通过这里的窄回调提供。
|
|
99
|
-
*/
|
|
100
|
-
createTranscript(options: {
|
|
101
|
-
readonly storage: DurableObjectStorage;
|
|
102
|
-
readonly durability: PiTranscriptDurability;
|
|
103
|
-
readonly hasActiveTurn: () => boolean;
|
|
104
|
-
}): PiRuntimeTranscript {
|
|
105
|
-
return new PiRuntimeTranscript(
|
|
106
|
-
options.storage,
|
|
107
|
-
options.durability,
|
|
108
|
-
this.models,
|
|
109
|
-
options.hasActiveTurn,
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* 把已校验的浏览器用户消息转换成 Pi 可以写入 transcript 的用户消息。
|
|
115
|
-
*
|
|
116
|
-
* @remarks
|
|
117
|
-
* 调用方:Runtime 收到 submit 或 regenerate 请求并完成结构校验后,在持久化 Submission 前调用。
|
|
118
|
-
*
|
|
119
|
-
* 实现理由:转换只生成 Pi UserMessage 的 content 和 timestamp,原始浏览器视图由 transcript sidecar 另行保存。
|
|
120
|
-
* 不要把 UI id、metadata 或原始 part 结构并入 canonical message。
|
|
121
|
-
*/
|
|
122
|
-
normalizeUserInput(
|
|
123
|
-
input: UIMessage & { role: "user" },
|
|
124
|
-
privateContext?: string,
|
|
125
|
-
) {
|
|
126
|
-
return uiUserMessageToPi(input, privateContext);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* 加载并预检一份可供后续准入使用的 Prepared Runtime。
|
|
131
|
-
*
|
|
132
|
-
* @remarks
|
|
133
|
-
* 调用方:Runtime 的 `initConfig()` 在取得新快照后调用,再用返回的 revision descriptor 判断是否可以切换配置。
|
|
134
|
-
*
|
|
135
|
-
* 实现理由:Extension 加载、Tool candidate 汇总和 Tool 编译预检在配置切换前一次完成。
|
|
136
|
-
* 返回值绑定当前 Adapter 的 owner,不能交给另一个 Adapter 创建 Turn。
|
|
137
|
-
*/
|
|
138
|
-
prepare(
|
|
139
|
-
options: PreparePiRuntimeOptions,
|
|
140
|
-
): Promise<PreparedPiRuntime> {
|
|
141
|
-
if (this.managesModels) {
|
|
142
|
-
createPiModels(options.snapshot.bindings.provider);
|
|
143
|
-
}
|
|
144
|
-
return preparePiRuntime(options, this.owner);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
hasTool(prepared: PreparedPiRuntime, name: string): boolean {
|
|
148
|
-
return readPreparedPiRuntime(prepared, this.owner).candidates.some(
|
|
149
|
-
(candidate) => candidate.tool.name === name,
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* 用已经通过加载检查的快照启用当前部署声明的模型目录。
|
|
155
|
-
*
|
|
156
|
-
* @remarks
|
|
157
|
-
* 调用方:Runtime 的 `initConfig()` 在 Prepared Runtime 和 revision 检查成功后、发布新快照前调用。
|
|
158
|
-
*
|
|
159
|
-
* 实现理由:`prepare()` 已校验所有 endpoint 模型,这里只把同一份部署目录切换到长期 Models 实例。
|
|
160
|
-
* 注入模型目录时跳过此步骤,以保留调用方对目录的配置权。
|
|
161
|
-
*/
|
|
162
|
-
activate(snapshot: PreparePiRuntimeOptions["snapshot"]): void {
|
|
163
|
-
if (this.managesModels) {
|
|
164
|
-
configurePiModels(this.models, snapshot.bindings.provider);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* 在接受 Submission 前固定本次执行使用的动态上下文和审批模式。
|
|
170
|
-
*
|
|
171
|
-
* @remarks
|
|
172
|
-
* 调用方:Runtime 的准入流程为每个新 Submission 调用,并把 descriptor 与其哈希一起持久化。
|
|
173
|
-
*
|
|
174
|
-
* 实现理由:memory、workspace 和 Extension context 可能随时间变化,所以把准入时的 Turn 字段保存在 descriptor 中。
|
|
175
|
-
* 不要把 pin 推迟到 Turn 启动后,否则已持久化的 Submission 将失去可验证的执行基线。
|
|
176
|
-
*/
|
|
177
|
-
pin(options: PinPiRuntimeOptions): Promise<PinnedPiRuntime> {
|
|
178
|
-
return pinPiRuntime(options, this.owner);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* 根据持久化 milestone 和一个命令算出恢复时要写什么、下一步做什么。
|
|
183
|
-
*
|
|
184
|
-
* @remarks
|
|
185
|
-
* 调用方:Runtime 和 approval 生命周期在检查恢复状态、处理审批或提交终态时调用。
|
|
186
|
-
*
|
|
187
|
-
* 实现理由:该方法只返回 durable mutations 和一个 effect,实际写库与调度仍由 Runtime 完成。
|
|
188
|
-
* 恢复规划保留在此入口;正常 Tool 写入复用同一命令 reducer,但不重复规划整个 Turn。
|
|
189
|
-
*/
|
|
190
|
-
decideRecovery(options: PiRecoveryInput) {
|
|
191
|
-
return decidePiRecovery(options);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/** Active execution records only the indexed Tool fact; cold recovery still replays the full log. */
|
|
195
|
-
recordToolMilestone(options: PiToolMilestoneInput) {
|
|
196
|
-
return recordPiToolMilestone(options);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* 把 Runtime 提供的持久化和重试回调包装成通用聊天恢复端口。
|
|
201
|
-
*
|
|
202
|
-
* @remarks
|
|
203
|
-
* 调用方:`AgentRuntimeKernel.createRecoveryPort()` 在恢复引擎需要分类、重试、终结或读取部分输出时创建并复用它。
|
|
204
|
-
*
|
|
205
|
-
* 实现理由:Durable Object 被驱逐或休眠后内存状态不会保留,因此恢复判断必须从宿主持久化状态和 stream chunk 重建。
|
|
206
|
-
* Pi 负责解释 milestone,Runtime 仍负责数据库写入、Submission 重试和终态提交;不要合并这两个所有权边界。
|
|
207
|
-
*/
|
|
208
|
-
createRecovery(host: PiRecoveryHost) {
|
|
209
|
-
return new PiRuntimeRecoveryAdapter(host);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* 为一个已准入的 Submission 创建一次可执行的 Pi Turn。
|
|
214
|
-
*
|
|
215
|
-
* @remarks
|
|
216
|
-
* 调用方:Runtime 在首次执行和恢复继续时各创建一个新 Turn,并提供 canonical messages、durable Tool 回调和流事件回调。
|
|
217
|
-
*
|
|
218
|
-
* 实现理由:构造时会校验 Prepared Runtime 的 owner 和 pinned descriptor 格式,再建立本 Turn 独享的 Tool governance 与执行状态。
|
|
219
|
-
* 不要跨 Turn 复用返回对象;abort、steer、assistant ordinal 和 Tool governance 都是单次执行状态。
|
|
220
|
-
*/
|
|
221
|
-
/**
|
|
222
|
-
* 为一个已准入的 Submission 生成绑定 durable lifecycle 的 SubAgent Tool 执行器。
|
|
223
|
-
*
|
|
224
|
-
* @remarks
|
|
225
|
-
* 调用方:Runtime 在创建 Turn 前调用一次,并把结果作为 `createTurn` 的 `toolExecutors` 传入。
|
|
226
|
-
*
|
|
227
|
-
* 实现理由:SubAgent Tool 的名称、Schema 和执行语义属于 Pi Tool 层,而父子执行身份属于 Submission。两者在这里汇合:Pi 提供工具,
|
|
228
|
-
* Runtime 提供本次 Submission 的 lifecycle 端口,因此 Runtime 不需要认识 Tool 模块本身。
|
|
229
|
-
* 没有可用 SubAgent 类型时返回 `undefined`,让 Turn 继续使用装配期的无 lifecycle 执行器。
|
|
230
|
-
*/
|
|
231
|
-
subagentToolExecutors(
|
|
232
|
-
subagents: RuntimeSubagentPort,
|
|
233
|
-
enabledSubagents: readonly string[],
|
|
234
|
-
lifecycle: RuntimeSubagentLifecyclePort,
|
|
235
|
-
): CreatePreparedPiTurnOptions["toolExecutors"] {
|
|
236
|
-
const entries = subagentPiToolCandidates(
|
|
237
|
-
subagents,
|
|
238
|
-
enabledSubagents,
|
|
239
|
-
lifecycle,
|
|
240
|
-
).flatMap((candidate) =>
|
|
241
|
-
candidate.tool.execute
|
|
242
|
-
? [[candidate.tool.name, candidate.tool.execute] as const]
|
|
243
|
-
: []
|
|
244
|
-
);
|
|
245
|
-
return entries.length > 0 ? Object.fromEntries(entries) : undefined;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
createTurn(
|
|
249
|
-
options: CreatePreparedPiTurnOptions,
|
|
250
|
-
): PreparedPiTurnAdapter {
|
|
251
|
-
return new PreparedPiTurnAdapter(options, {
|
|
252
|
-
owner: this.owner,
|
|
253
|
-
models: this.models,
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
export type {
|
|
259
|
-
RequestedCapability,
|
|
260
|
-
UIChatRequestBody,
|
|
261
|
-
} from "../message";
|
|
262
|
-
export type { PiToolApproval } from "../turn";
|
|
263
|
-
export type {
|
|
264
|
-
PiToolInteraction,
|
|
265
|
-
PiToolInteractionCancelReason,
|
|
266
|
-
} from "../turn";
|
|
267
|
-
export type {
|
|
268
|
-
CreatePreparedPiTurnOptions,
|
|
269
|
-
PiCanonicalUserInput,
|
|
270
|
-
PiStoredToolSettlement,
|
|
271
|
-
PiToolSettlement,
|
|
272
|
-
PiToolInputRecord,
|
|
273
|
-
PiTurnRunResult,
|
|
274
|
-
PreparedPiTurnAdapter,
|
|
275
|
-
} from "./execution";
|
|
276
|
-
export type {
|
|
277
|
-
PinPiRuntimeOptions,
|
|
278
|
-
PinnedPiRuntime,
|
|
279
|
-
PreparePiRuntimeOptions,
|
|
280
|
-
PreparedPiRuntime,
|
|
281
|
-
} from "./assembly";
|
|
282
|
-
export type {
|
|
283
|
-
PiChatRecoveryData,
|
|
284
|
-
PiDurableMutation,
|
|
285
|
-
PiDurableRecoveryState,
|
|
286
|
-
PiRecoveryCommand,
|
|
287
|
-
PiRecoveryDecision,
|
|
288
|
-
PiRecoveryHost,
|
|
289
|
-
} from "./recovery";
|
|
290
|
-
export type {
|
|
291
|
-
PiRuntimeTranscript,
|
|
292
|
-
PiCanonicalTranscriptSnapshot,
|
|
293
|
-
} from "./transcript";
|