@springbrand/agent-runtime 0.2.0-alpha.15 → 0.2.0-alpha.17
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 +1 -1
- package/src/adapter/cloudflare/sandbox/adapter.ts +61 -36
- package/src/adapter/cloudflare/universal-agent/preparation.ts +0 -2
- package/src/adapter/cloudflare/workspace/scoped-workspace.ts +23 -18
- package/src/db/index.ts +5 -0
- package/src/db/schema.ts +15 -0
- package/src/db/telemetry-outbox.repo.ts +151 -0
- package/src/index.ts +1 -0
- package/src/kernel/approval-lifecycle.ts +35 -3
- package/src/kernel/bindings.ts +2 -1
- package/src/kernel/interaction-lifecycle.ts +35 -6
- package/src/layers/orchestration/temporary-agent/workspace.ts +4 -4
- package/src/lib/prompt.ts +22 -15
- package/src/pi/assembly/context.ts +2 -2
- package/src/pi/message/conversion.ts +13 -1
- package/src/pi/runtime-adapter/assembly.ts +1 -0
- package/src/pi/runtime-adapter/execution.ts +63 -27
- package/src/pi/runtime-adapter/models.ts +144 -44
- package/src/pi/tool/ai-adapter.ts +2 -2
- package/src/pi/tool/base.ts +31 -25
- package/src/pi/tool/compiler.ts +6 -102
- package/src/pi/turn/tool-recovery.ts +11 -1
- package/src/runtime-agent.ts +24 -0
- package/src/runtime-assembler.ts +38 -19
- package/src/runtime-definition.ts +2 -0
- package/src/runtime.ts +362 -20
- package/src/telemetry/contract.ts +389 -0
- package/src/telemetry/coordinator.ts +143 -0
- package/src/telemetry/delivery.ts +138 -0
- package/src/telemetry/ids.ts +60 -0
- package/src/telemetry/index.ts +7 -0
- package/src/telemetry/recorder.ts +61 -0
- package/src/telemetry/runtime-telemetry.ts +484 -0
- package/src/telemetry/sanitize.ts +97 -0
- package/src/tool-registry.ts +18 -11
- package/src/lib/telemetry-dev.ts +0 -47
package/src/tool-registry.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type {
|
|
|
8
8
|
import type { RuntimeExtensionConfig } from "./kernel/extensions";
|
|
9
9
|
import type { RuntimeDegradation } from "./kernel/degradation";
|
|
10
10
|
import type { PiToolCandidate } from "./pi/tool/compiler";
|
|
11
|
+
import { validateToolArguments } from "@earendil-works/pi-ai";
|
|
11
12
|
|
|
12
13
|
/** Tool Surface 筛选策略(不含 Manifest deny 列表)。 */
|
|
13
14
|
export interface ToolSurfaceSelectionPolicy {
|
|
@@ -22,7 +23,9 @@ export interface ToolContext {
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
/** Definition 作者声明的一个 Tool。 */
|
|
25
|
-
export interface ToolSpec
|
|
26
|
+
export interface ToolSpec extends Partial<
|
|
27
|
+
Omit<PiToolCandidate, "tool" | "requiredExecutionLevel">
|
|
28
|
+
> {
|
|
26
29
|
readonly label: string;
|
|
27
30
|
readonly description: string;
|
|
28
31
|
readonly parameters: unknown;
|
|
@@ -80,23 +83,27 @@ export function toolRegistryFromPiCandidates(
|
|
|
80
83
|
}
|
|
81
84
|
|
|
82
85
|
export function piCandidateToToolSpec(candidate: PiToolCandidate): ToolSpec {
|
|
83
|
-
const
|
|
86
|
+
const { tool, ...metadata } = candidate;
|
|
87
|
+
const name = tool.name;
|
|
84
88
|
return {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
...(candidate.alwaysRequiresApproval
|
|
90
|
-
? { alwaysRequiresApproval: true }
|
|
91
|
-
: {}),
|
|
89
|
+
...metadata,
|
|
90
|
+
label: tool.label ?? name,
|
|
91
|
+
description: tool.description,
|
|
92
|
+
parameters: tool.parameters,
|
|
92
93
|
execute: async (input, ctx) => {
|
|
93
|
-
const execute =
|
|
94
|
+
const execute = tool.execute;
|
|
94
95
|
if (typeof execute !== "function") {
|
|
95
96
|
throw new Error(`Tool "${name}" is not executable`);
|
|
96
97
|
}
|
|
98
|
+
const validated = validateToolArguments(tool, {
|
|
99
|
+
type: "toolCall",
|
|
100
|
+
id: ctx.toolCallId,
|
|
101
|
+
name,
|
|
102
|
+
arguments: input as Record<string, unknown>,
|
|
103
|
+
});
|
|
97
104
|
const result = await execute(
|
|
98
105
|
ctx.toolCallId,
|
|
99
|
-
|
|
106
|
+
validated,
|
|
100
107
|
ctx.signal,
|
|
101
108
|
undefined,
|
|
102
109
|
);
|
package/src/lib/telemetry-dev.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 观测降级:把 observability 事件打到 console,让 `wrangler dev` / `wrangler tail` 里能实时看到埋点,
|
|
3
|
-
* 并且(生产上开了 `observability.logs` 时)进 Workers Logs 供事后查询。
|
|
4
|
-
* 不装它,事件就 publish 到零订阅 channel = 静默 no-op。
|
|
5
|
-
*
|
|
6
|
-
* 由 onStart 在 env `TELEMETRY_CONSOLE==="1"` 时装载 —— `.dev.vars` 和 `wrangler.jsonc` 的 vars 里都开着。
|
|
7
|
-
* 注意:上游注释宣称"生产上所有 channel 事件自动转发 Tail Worker",那条路径需要 `tail_consumers`,
|
|
8
|
-
* 本仓没有配,所以生产**不能**指望它;这个 console sink 就是生产的唯一消费面(2026-08-06 实测:
|
|
9
|
-
* 未开启前 Observability API 查 universal-agent 24h 事件 count=0)。
|
|
10
|
-
*
|
|
11
|
-
* 用 `agents/observability` 的类型化 `subscribe`(按 channel key 订阅),避免引 `node:diagnostics_channel`
|
|
12
|
-
* 与 `@types/node`(tsconfig 只带 workers-types)。
|
|
13
|
-
*/
|
|
14
|
-
import { subscribe } from "agents/observability";
|
|
15
|
-
|
|
16
|
-
// Covers chat events, Runtime lifecycle events and tool messages.
|
|
17
|
-
const CHANNEL_KEYS = ["chat", "lifecycle", "message", "schedule", "mcp"] as const;
|
|
18
|
-
|
|
19
|
-
// Module state is isolate-wide, so multiple DO instances share one subscription.
|
|
20
|
-
let installed = false;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* 在当前 Worker isolate 中安装一次把观测事件打到 console 的订阅。
|
|
24
|
-
*
|
|
25
|
-
* @remarks
|
|
26
|
-
* Runtime `onStart` 只在 `telemetryConsole` 开启时调用,用于 `wrangler dev` 和日志调试。
|
|
27
|
-
*
|
|
28
|
-
* `installed` 是 isolate 级模块状态,因此多个 Durable Object 实例共享一组订阅;不做幂等检查会让每个事件重复输出。
|
|
29
|
-
*
|
|
30
|
-
* 使用 `agents/observability` 的 channel 订阅而不是 Node.js `diagnostics_channel`,保持当前 Workers TypeScript 环境不需要 Node 类型。
|
|
31
|
-
*
|
|
32
|
-
* Runtime 的术语见 `src/index.ts`。
|
|
33
|
-
*/
|
|
34
|
-
export function installConsoleSink(): void {
|
|
35
|
-
if (installed) return;
|
|
36
|
-
installed = true;
|
|
37
|
-
for (const key of CHANNEL_KEYS) {
|
|
38
|
-
subscribe(key, (event) => {
|
|
39
|
-
const e = event as { type?: string; payload?: unknown };
|
|
40
|
-
try {
|
|
41
|
-
console.log(`[obs] ${e.type}`, JSON.stringify(e.payload ?? {}));
|
|
42
|
-
} catch {
|
|
43
|
-
console.log(`[obs] ${e?.type} (payload 不可序列化)`);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|