@springbrand/agent-runtime 0.3.0-alpha.7 → 0.3.0-alpha.9
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 +2 -2
- package/src/adapter/cloudflare/agent.ts +4 -7
- package/src/adapter/cloudflare/define-agent.ts +2 -0
- package/src/adapter/cloudflare/schema.ts +3 -0
- package/src/adapter/cloudflare/subagent/definition.ts +4 -4
- package/src/adapter/cloudflare/subagent/runner.ts +1 -1
- package/src/adapter/cloudflare/subagent/tools.ts +2 -2
- package/src/adapter/cloudflare/universal-agent/preparation.ts +3 -3
- package/src/adapter/cloudflare/universal-agent/tools.ts +4 -6
- package/src/adapter/cloudflare/workspace/version-control.ts +1 -1
- package/src/config/agent-context.ts +1 -1
- package/src/config/assembler.ts +17 -31
- package/src/config/assembly-snapshot.ts +1 -1
- package/src/config/definition.ts +1 -1
- package/src/config/model-guidance.ts +1 -1
- package/src/config/ports.ts +5 -15
- package/src/config/public-contracts.ts +2 -2
- package/src/context/extension/assembly.ts +2 -2
- package/src/context/memory/budget/gate.ts +1 -1
- package/src/conversation/state.ts +1 -1
- package/src/index.ts +7 -7
- package/src/lib/execution-level.ts +13 -0
- package/src/lib/prompt.ts +3 -5
- package/src/models/index.ts +1 -0
- package/src/session/cloudflare/migration.ts +29 -8
- package/src/skills/springbrand-worker-website/index.ts +1 -1
- package/src/submission/admission.ts +4 -0
- package/src/submission/delivery.ts +1 -1
- package/src/submission/finalization.ts +1 -1
- package/src/submission/repository.ts +8 -1
- package/src/telemetry/coordinator.ts +1 -1
- package/src/telemetry/subagent-lifecycle.ts +1 -1
- package/src/telemetry/turn-events.ts +1 -1
- package/src/tools/README.md +44 -0
- package/src/tools/{ai-adapter.ts → adapters/ai-to-pi.ts} +6 -9
- package/src/tools/{declared.ts → adapters/declared.ts} +2 -2
- package/src/tools/{nested-tools.ts → adapters/pi-to-ai.ts} +2 -2
- package/src/tools/assistant/ask-user.ts +317 -0
- package/src/tools/assistant/candidate.ts +15 -0
- package/src/tools/assistant/followups.ts +34 -0
- package/src/tools/assistant/index.ts +19 -0
- package/src/tools/assistant/memory.ts +73 -0
- package/src/tools/assistant/plan.ts +98 -0
- package/src/tools/{time.ts → assistant/time.ts} +1 -1
- package/src/tools/{core-host.ts → codemode/adapter.ts} +50 -49
- package/src/tools/{core.ts → codemode/index.ts} +36 -92
- package/src/tools/codemode/workspace-connector.ts +198 -0
- package/src/tools/extension/index.ts +42 -0
- package/src/tools/index.ts +28 -26
- package/src/tools/{gateway.ts → mcp/gateway.ts} +19 -19
- package/src/tools/{mcp.ts → mcp/index.ts} +5 -5
- package/src/tools/{approval → runtime/approval}/repository.ts +3 -9
- package/src/tools/{compiler.ts → runtime/compiler.ts} +24 -155
- package/src/tools/runtime/contracts.ts +117 -0
- package/src/tools/{decision-gate.ts → runtime/decision-gate.ts} +36 -61
- package/src/tools/{human-decisions.ts → runtime/human-decisions.ts} +4 -4
- package/src/tools/{interaction → runtime/interaction}/repository.ts +1 -7
- package/src/tools/runtime/result.ts +22 -0
- package/src/tools/sandbox/index.ts +228 -0
- package/src/tools/{schedule.ts → schedule/index.ts} +50 -49
- package/src/tools/skill/contracts.ts +20 -0
- package/src/tools/skill/index.ts +99 -0
- package/src/tools/skill/resources.ts +322 -0
- package/src/tools/skill/scripts.ts +168 -0
- package/src/tools/{subagent-authority.ts → subagent/authority.ts} +31 -31
- package/src/tools/{subagent.ts → subagent/index.ts} +34 -37
- package/src/tools/{subagent-run-repository.ts → subagent/repository.ts} +1 -1
- package/src/tools/{subagent-runtime.ts → subagent/runtime.ts} +1 -1
- package/src/tools/{temporary-agent → subagent/temporary}/approvals.ts +4 -7
- package/src/tools/{temporary-agent → subagent/temporary}/core.ts +1 -1
- package/src/tools/{temporary-agent → subagent/temporary}/runner.ts +1 -1
- package/src/tools/{temporary-agent → subagent/temporary}/workspace.ts +1 -4
- package/src/tools/{web-fetch.ts → web/fetch.ts} +4 -13
- package/src/tools/web/index.ts +2 -0
- package/src/tools/web/search/api.ts +1320 -0
- package/src/tools/web/search/index.ts +2 -0
- package/src/tools/{web-search/web-search.ts → web/search/search.ts} +5 -7
- package/src/tools/{workspace-sandbox.ts → workspace/index.ts} +12 -272
- package/src/tools/{workspace-revision.ts → workspace/revision.ts} +3 -3
- package/src/tools/base.ts +0 -542
- package/src/tools/skill.ts +0 -565
- package/src/tools/web-search/api.ts +0 -1318
- package/src/tools/web-search/index.ts +0 -2
- package/src/tools/workspace-state-connector.ts +0 -146
- package/src/tools/{approval → runtime/approval}/index.ts +0 -0
- package/src/tools/{interaction → runtime/interaction}/index.ts +0 -0
- package/src/tools/{unattended-error.ts → runtime/unattended-error.ts} +0 -0
- package/src/tools/{temporary-agent → subagent/temporary}/coordinator.ts +0 -0
- package/src/tools/{subagent-types → subagent/types}/contract.ts +0 -0
- package/src/tools/{subagent-types → subagent/types}/extract/index.ts +0 -0
- package/src/tools/{subagent-types → subagent/types}/fanout/index.ts +0 -0
- package/src/tools/{subagent-types → subagent/types}/registry.ts +1 -1
- /package/src/tools/{workspace-versioning.ts → workspace/versioning.ts} +0 -0
|
@@ -5,14 +5,11 @@ import type {
|
|
|
5
5
|
RuntimeSubagentPort,
|
|
6
6
|
RuntimeSubagentRunResult,
|
|
7
7
|
RuntimeSubagentUsageEvent,
|
|
8
|
-
} from "
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
subagentTerminalStatus,
|
|
14
|
-
} from "./subagent-runtime";
|
|
15
|
-
import type { PiToolCandidate } from "./compiler";
|
|
8
|
+
} from "../../config/ports";
|
|
9
|
+
import { serializeOutput } from "../../lib/artifacts";
|
|
10
|
+
import type { PiToolCandidate } from "../runtime/contracts";
|
|
11
|
+
import { isZeroSubagentUsage, subagentTerminalStatus } from "./runtime";
|
|
12
|
+
import { AGENT_TYPES } from "./types/registry";
|
|
16
13
|
|
|
17
14
|
const BACKGROUND_MAX_BUDGET_MS = 10 * 60 * 1_000;
|
|
18
15
|
|
|
@@ -105,7 +102,7 @@ async function recordSubagentResult(
|
|
|
105
102
|
* 会等待子任务结果,“后台派发”只返回 runId,并由 Host 通过通知把最终结果送回
|
|
106
103
|
* 当前会话。注册表同时生成工具 Schema 和再次校验后台 input,不能改成两份定义。
|
|
107
104
|
*
|
|
108
|
-
* `Host`、`Pi`、`Port`、`Runtime Snapshot` 与“候选工具”见
|
|
105
|
+
* `Host`、`Pi`、`Port`、`Runtime Snapshot` 与“候选工具”见 `src/index.ts`。
|
|
109
106
|
*/
|
|
110
107
|
export function subagentPiToolCandidates(
|
|
111
108
|
subagents: RuntimeSubagentPort | undefined,
|
|
@@ -143,25 +140,25 @@ export function subagentPiToolCandidates(
|
|
|
143
140
|
}
|
|
144
141
|
const reserved = lifecycle
|
|
145
142
|
? await subagents.reserve!(type.name, childInput, {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
143
|
+
parentRunId: lifecycle.parentRunId,
|
|
144
|
+
submissionId: lifecycle.submissionId,
|
|
145
|
+
toolCallId: _toolCallId,
|
|
146
|
+
})
|
|
150
147
|
: undefined;
|
|
151
148
|
if (reserved && lifecycle) await lifecycle.onRegistered(reserved.runId);
|
|
152
149
|
const runOptions = lifecycle
|
|
153
150
|
? {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
151
|
+
parentRunId: lifecycle.parentRunId,
|
|
152
|
+
submissionId: lifecycle.submissionId,
|
|
153
|
+
...(reserved ? { subagentRunId: reserved.runId } : {}),
|
|
154
|
+
}
|
|
158
155
|
: undefined;
|
|
159
156
|
const run = lifecycle && reserved
|
|
160
157
|
? await runRegisteredSubagent(
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
158
|
+
lifecycle,
|
|
159
|
+
reserved.runId,
|
|
160
|
+
() => subagents.run(type.name, childInput, runOptions),
|
|
161
|
+
)
|
|
165
162
|
: await subagents.run(type.name, childInput);
|
|
166
163
|
if (lifecycle && !run.childStillRunning) {
|
|
167
164
|
await recordSubagentResult(lifecycle, run);
|
|
@@ -213,14 +210,14 @@ export function subagentPiToolCandidates(
|
|
|
213
210
|
}
|
|
214
211
|
const reserved = lifecycle
|
|
215
212
|
? await subagents.reserve!(
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
213
|
+
input.agentType,
|
|
214
|
+
parsed.data as Record<string, unknown>,
|
|
215
|
+
{
|
|
216
|
+
parentRunId: lifecycle.parentRunId,
|
|
217
|
+
submissionId: lifecycle.submissionId,
|
|
218
|
+
toolCallId,
|
|
219
|
+
},
|
|
220
|
+
)
|
|
224
221
|
: undefined;
|
|
225
222
|
if (reserved && lifecycle) await lifecycle.onRegistered(reserved.runId);
|
|
226
223
|
const runInput = parsed.data as Record<string, unknown>;
|
|
@@ -230,18 +227,18 @@ export function subagentPiToolCandidates(
|
|
|
230
227
|
notifySource: "dispatch-background",
|
|
231
228
|
...(lifecycle
|
|
232
229
|
? {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
230
|
+
parentRunId: lifecycle.parentRunId,
|
|
231
|
+
submissionId: lifecycle.submissionId,
|
|
232
|
+
...(reserved ? { subagentRunId: reserved.runId } : {}),
|
|
233
|
+
}
|
|
237
234
|
: {}),
|
|
238
235
|
};
|
|
239
236
|
const run = lifecycle && reserved
|
|
240
237
|
? await runRegisteredSubagent(
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
238
|
+
lifecycle,
|
|
239
|
+
reserved.runId,
|
|
240
|
+
() => subagents.run(input.agentType, runInput, runOptions),
|
|
241
|
+
)
|
|
245
242
|
: await subagents.run(input.agentType, runInput, runOptions);
|
|
246
243
|
if (lifecycle && !run.childStillRunning && run.status !== "running") {
|
|
247
244
|
await recordSubagentResult(lifecycle, run);
|
|
@@ -5,7 +5,7 @@ export class AgentToolRepository {
|
|
|
5
5
|
// 保存当前 Agent SQLite 的查询入口。
|
|
6
6
|
// RuntimeDatabase 构造时调用,活动投影随后通过这个 Repository 读取子运行。
|
|
7
7
|
// 把存储绑定留在构造阶段,避免每次读取都传入可能属于其他 Agent 的 sql。
|
|
8
|
-
constructor(private readonly sql: SqlTaggedTemplate) {}
|
|
8
|
+
constructor(private readonly sql: SqlTaggedTemplate) { }
|
|
9
9
|
|
|
10
10
|
// 是否仍有 Agent Tool 子运行在执行。
|
|
11
11
|
// 活动投影在重算 activity 时调用,判定只在这里做一次。
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import type { ApprovalDecision, ApprovalReceipt } from "
|
|
2
|
-
import type { RuntimeTelemetryCoordinator } from "
|
|
3
|
-
import type {
|
|
4
|
-
TemporaryAgentApprovalDecision,
|
|
5
|
-
TemporaryAgentApprovalRequest,
|
|
6
|
-
} from "./core";
|
|
1
|
+
import type { ApprovalDecision, ApprovalReceipt } from "../../../submission/contracts";
|
|
2
|
+
import type { RuntimeTelemetryCoordinator } from "../../../telemetry/coordinator";
|
|
3
|
+
import type { TemporaryAgentApprovalDecision, TemporaryAgentApprovalRequest } from "./core";
|
|
7
4
|
|
|
8
5
|
interface PendingApproval {
|
|
9
6
|
receipt: ApprovalReceipt;
|
|
@@ -19,7 +16,7 @@ export class TemporaryAgentApprovals {
|
|
|
19
16
|
constructor(private readonly options: {
|
|
20
17
|
capture: RuntimeTelemetryCoordinator["capture"];
|
|
21
18
|
onChanged(): Promise<void>;
|
|
22
|
-
}) {}
|
|
19
|
+
}) { }
|
|
23
20
|
|
|
24
21
|
find(executionId: string): ApprovalReceipt | null {
|
|
25
22
|
return this.pending.get(executionId)?.receipt ?? null;
|
|
@@ -10,14 +10,13 @@
|
|
|
10
10
|
* - 不依赖 Workers AI `toMarkdown()`——base runtime 不持有 AI binding,调用方若需要
|
|
11
11
|
* Markdown 转换,应在宿主层叠加;此处返回原始 UTF-8 解码内容。
|
|
12
12
|
*
|
|
13
|
-
*
|
|
13
|
+
* 本文件未注册到默认 Tool Surface,可单独 import 使用。
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
17
17
|
import { Type } from "@earendil-works/pi-ai";
|
|
18
|
-
import type { PiToolCandidate } from "
|
|
18
|
+
import type { PiToolCandidate } from "../runtime/contracts";
|
|
19
19
|
|
|
20
|
-
// #region 常量
|
|
21
20
|
|
|
22
21
|
/** 服务端强制截断上限(字节)。调用方 maxBytes 在此之上再被夹断。 */
|
|
23
22
|
const HARD_MAX_BYTES = 5 * 1024 * 1024; // 5 MiB
|
|
@@ -28,9 +27,7 @@ const FETCH_TIMEOUT_MS = 30_000;
|
|
|
28
27
|
/** 发出请求时使用的 User-Agent 字符串。 */
|
|
29
28
|
const USER_AGENT = "UniversalAgent/1.0";
|
|
30
29
|
|
|
31
|
-
// #endregion
|
|
32
30
|
|
|
33
|
-
// #region 公开类型
|
|
34
31
|
|
|
35
32
|
export const webFetchParameters = Type.Object({
|
|
36
33
|
url: Type.String({
|
|
@@ -62,9 +59,7 @@ export interface WebFetchDetails {
|
|
|
62
59
|
bodyLength: number;
|
|
63
60
|
}
|
|
64
61
|
|
|
65
|
-
// #endregion
|
|
66
62
|
|
|
67
|
-
// #region 内部工具函数
|
|
68
63
|
|
|
69
64
|
/**
|
|
70
65
|
* 校验 URL 字符串是否符合 webFetch 的安全约束。
|
|
@@ -83,7 +78,7 @@ export function validateWebFetchUrl(input: string): URL {
|
|
|
83
78
|
if (parsed.protocol !== "https:") {
|
|
84
79
|
throw new Error(
|
|
85
80
|
`Only https:// URLs are allowed; got ${parsed.protocol}//. ` +
|
|
86
|
-
|
|
81
|
+
`Use the HTTPS version of this URL.`,
|
|
87
82
|
);
|
|
88
83
|
}
|
|
89
84
|
if (parsed.username || parsed.password) {
|
|
@@ -170,9 +165,7 @@ export function formatWebFetchResult(
|
|
|
170
165
|
].join("\n");
|
|
171
166
|
}
|
|
172
167
|
|
|
173
|
-
// #endregion
|
|
174
168
|
|
|
175
|
-
// #region Pi 工具候选项工厂
|
|
176
169
|
|
|
177
170
|
/**
|
|
178
171
|
* 创建独立的 `web_fetch` Pi 工具候选项。
|
|
@@ -247,7 +240,7 @@ export function webFetchPiToolCandidate(): PiToolCandidate {
|
|
|
247
240
|
try { await response.body?.cancel(); } catch { /* ignore */ }
|
|
248
241
|
throw new Error(
|
|
249
242
|
`The site at ${finalUrl} sets Content-Signal: ai-input=no, ` +
|
|
250
|
-
|
|
243
|
+
`indicating that it does not permit its content to be used as AI input.`,
|
|
251
244
|
);
|
|
252
245
|
}
|
|
253
246
|
|
|
@@ -277,5 +270,3 @@ export function webFetchPiToolCandidate(): PiToolCandidate {
|
|
|
277
270
|
tool,
|
|
278
271
|
};
|
|
279
272
|
}
|
|
280
|
-
|
|
281
|
-
// #endregion
|