@springbrand/agent-runtime 0.2.0-alpha.34 → 0.2.0-alpha.38
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 -1
- package/src/adapter/cloudflare/dynamic-worker-observability.ts +84 -0
- package/src/adapter/cloudflare/index.ts +11 -2
- package/src/adapter/cloudflare/scheduling/zoned-cron.ts +114 -0
- package/src/adapter/cloudflare/universal-agent/tools.ts +17 -30
- package/src/index.ts +7 -35
- package/src/kernel/bindings.ts +6 -6
- package/src/pi/assembly/extensions.ts +23 -38
- package/src/pi/assembly/snapshot.ts +7 -1
- package/src/pi/runtime-adapter/assembly.ts +19 -14
- package/src/pi/runtime-adapter/execution.ts +7 -10
- package/src/pi/runtime-adapter/recovery.ts +15 -34
- package/src/pi/runtime-adapter/transcript.ts +5 -12
- package/src/pi/tool/base.ts +0 -15
- package/src/pi/tool/compiler.ts +0 -2
- package/src/pi/tool/core-host.ts +125 -49
- package/src/pi/tool/core.ts +8 -3
- package/src/pi/tool/index.ts +1 -0
- package/src/pi/tool/nested-tools.ts +42 -0
- package/src/pi/tool/schedule.ts +0 -9
- package/src/pi/tool/skill.ts +10 -21
- package/src/pi/tool/subagent.ts +0 -13
- package/src/pi/tool/time.ts +31 -0
- package/src/pi/tool/workspace-revision.ts +0 -12
- package/src/pi/tool/workspace-sandbox.ts +0 -10
- package/src/runtime-agent.ts +35 -45
- package/src/runtime-assembler.ts +68 -192
- package/src/runtime-definition.ts +35 -109
- package/src/runtime.ts +75 -47
- package/src/adapter/cloudflare/universal-agent/hooks.ts +0 -57
- package/src/kernel/tool-surface.ts +0 -42
- package/src/tool-registry.ts +0 -142
package/src/tool-registry.ts
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
RuntimeCodeExecutionFactory,
|
|
3
|
-
RuntimeMemoryPort,
|
|
4
|
-
RuntimeSubagentPort,
|
|
5
|
-
WorkspacePort,
|
|
6
|
-
} from "./kernel/bindings";
|
|
7
|
-
import type { RuntimeExtensionConfig } from "./kernel/extensions";
|
|
8
|
-
import type { RuntimeDegradation } from "./kernel/degradation";
|
|
9
|
-
import type {
|
|
10
|
-
ToolContext,
|
|
11
|
-
ToolRegistry,
|
|
12
|
-
ToolSpec,
|
|
13
|
-
} from "./kernel/tool-surface";
|
|
14
|
-
import type { PiToolCandidate } from "./pi/tool/compiler";
|
|
15
|
-
import { validateToolArguments } from "@earendil-works/pi-ai";
|
|
16
|
-
|
|
17
|
-
// Tool Surface 的形状类型住在 `kernel/tool-surface.ts`:bindings 也要用它们,放在这里
|
|
18
|
-
// 会让 `bindings → tool-registry → bindings` 成环。这里继续导出是为了保持调用方不变。
|
|
19
|
-
export type {
|
|
20
|
-
RuntimeCodeExecutionFactory,
|
|
21
|
-
ToolContext,
|
|
22
|
-
ToolRegistry,
|
|
23
|
-
ToolSpec,
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/** Tool Surface 筛选策略(不含 Manifest deny 列表)。 */
|
|
27
|
-
export interface ToolSurfaceSelectionPolicy {
|
|
28
|
-
readonly allowsTool?: (name: string) => boolean;
|
|
29
|
-
readonly allowsExtension?: (extension: RuntimeExtensionConfig) => boolean;
|
|
30
|
-
readonly defersTool?: (name: string) => boolean;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function emptyToolRegistry(): ToolRegistry {
|
|
34
|
-
return {};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function mergeToolRegistries(...registries: ToolRegistry[]): ToolRegistry {
|
|
38
|
-
const merged: ToolRegistry = {};
|
|
39
|
-
for (const registry of registries) {
|
|
40
|
-
for (const [name, spec] of Object.entries(registry)) {
|
|
41
|
-
if (name in merged) {
|
|
42
|
-
throw new Error(`Duplicate Runtime Tool: ${name}`);
|
|
43
|
-
}
|
|
44
|
-
merged[name] = spec;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return merged;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function toolRegistryFromPiCandidates(
|
|
51
|
-
candidates:
|
|
52
|
-
| readonly PiToolCandidate[]
|
|
53
|
-
| Record<string, PiToolCandidate>,
|
|
54
|
-
): ToolRegistry {
|
|
55
|
-
const list = Array.isArray(candidates)
|
|
56
|
-
? candidates
|
|
57
|
-
: Object.values(candidates);
|
|
58
|
-
const registry: ToolRegistry = {};
|
|
59
|
-
for (const candidate of list) {
|
|
60
|
-
const name = candidate.tool.name;
|
|
61
|
-
if (!name.trim()) {
|
|
62
|
-
throw new Error("SpringBrand Tool name must not be empty");
|
|
63
|
-
}
|
|
64
|
-
registry[name] = piCandidateToToolSpec(candidate);
|
|
65
|
-
}
|
|
66
|
-
return registry;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function piCandidateToToolSpec(candidate: PiToolCandidate): ToolSpec {
|
|
70
|
-
const { tool, ...metadata } = candidate;
|
|
71
|
-
const name = tool.name;
|
|
72
|
-
return {
|
|
73
|
-
...metadata,
|
|
74
|
-
label: tool.label ?? name,
|
|
75
|
-
description: tool.description,
|
|
76
|
-
parameters: tool.parameters,
|
|
77
|
-
execute: async (input, ctx) => {
|
|
78
|
-
const execute = tool.execute;
|
|
79
|
-
if (typeof execute !== "function") {
|
|
80
|
-
throw new Error(`Tool "${name}" is not executable`);
|
|
81
|
-
}
|
|
82
|
-
const validated = validateToolArguments(tool, {
|
|
83
|
-
type: "toolCall",
|
|
84
|
-
id: ctx.toolCallId,
|
|
85
|
-
name,
|
|
86
|
-
arguments: input as Record<string, unknown>,
|
|
87
|
-
});
|
|
88
|
-
return execute(
|
|
89
|
-
ctx.toolCallId,
|
|
90
|
-
validated,
|
|
91
|
-
ctx.signal,
|
|
92
|
-
undefined,
|
|
93
|
-
);
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/** Kernel 绑定仍需要的执行后端;不出现在 Definition 公开类型里。 */
|
|
99
|
-
export interface RuntimeToolBindings {
|
|
100
|
-
readonly workspace?: WorkspacePort;
|
|
101
|
-
readonly codeExecution?: RuntimeCodeExecutionFactory;
|
|
102
|
-
readonly memory?: RuntimeMemoryPort;
|
|
103
|
-
readonly subagents?: RuntimeSubagentPort;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Worker `tools()` 可返回纯注册表,或附带 Kernel 绑定与降级信息。
|
|
108
|
-
*/
|
|
109
|
-
export interface ToolAssemblyResult {
|
|
110
|
-
readonly tools: ToolRegistry;
|
|
111
|
-
readonly bindings?: RuntimeToolBindings;
|
|
112
|
-
readonly memoryProfile?: import("./kernel/profile").RuntimeMemoryProfile;
|
|
113
|
-
readonly enabledSubagents?: readonly string[];
|
|
114
|
-
readonly degradations?: readonly RuntimeDegradation[];
|
|
115
|
-
readonly surfacePolicy?: ToolSurfaceSelectionPolicy;
|
|
116
|
-
readonly commitGuard?: () => Promise<void>;
|
|
117
|
-
/** 释放本次装配创建的外部资源;临时 Agent 终止后由 Runtime 调用。 */
|
|
118
|
-
readonly dispose?: () => Promise<void>;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export function normalizeToolAssembly(
|
|
122
|
-
input: ToolRegistry | ToolAssemblyResult,
|
|
123
|
-
): ToolAssemblyResult {
|
|
124
|
-
if ("tools" in input && typeof input.tools === "object" && input.tools !== null) {
|
|
125
|
-
return input as ToolAssemblyResult;
|
|
126
|
-
}
|
|
127
|
-
return { tools: input as ToolRegistry };
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/** @deprecated 使用 `ToolSpec`。 */
|
|
131
|
-
export type PlatformToolSpec = ToolSpec;
|
|
132
|
-
|
|
133
|
-
/** @deprecated 使用 `ToolContext`。 */
|
|
134
|
-
export type PlatformToolContext = ToolContext;
|
|
135
|
-
|
|
136
|
-
/** @deprecated 使用 `ToolRegistry`。 */
|
|
137
|
-
export type PlatformToolRegistry = ToolRegistry;
|
|
138
|
-
|
|
139
|
-
/** @deprecated 使用 `emptyToolRegistry`。 */
|
|
140
|
-
export function emptyPlatformToolRegistry(): ToolRegistry {
|
|
141
|
-
return emptyToolRegistry();
|
|
142
|
-
}
|