@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/runtime-assembler.ts
CHANGED
|
@@ -61,6 +61,10 @@ import { skillPiToolCandidates } from "./pi/tool/skill";
|
|
|
61
61
|
import { createWebSearch } from "./pi/tool/web-search";
|
|
62
62
|
import { subagentPiToolCandidates } from "./pi/tool/subagent";
|
|
63
63
|
import { resolvePiModel } from "./pi/runtime-adapter/models";
|
|
64
|
+
import {
|
|
65
|
+
normalizeAgentTelemetryBinding,
|
|
66
|
+
type AgentTelemetryBinding,
|
|
67
|
+
} from "./telemetry/contract";
|
|
64
68
|
|
|
65
69
|
/** Runtime Assembler:校验一份扁平输入并生成可原子提交的 Snapshot。 */
|
|
66
70
|
|
|
@@ -92,6 +96,7 @@ export interface RuntimeAssemblyInput {
|
|
|
92
96
|
readonly subagents?: RuntimeSubagentPort;
|
|
93
97
|
readonly schedule?: RuntimeSchedulePort;
|
|
94
98
|
readonly turnEvents?: RuntimeTurnEventsPort;
|
|
99
|
+
readonly telemetry?: AgentTelemetryBinding;
|
|
95
100
|
readonly commitGuards: readonly (() => Promise<void>)[];
|
|
96
101
|
readonly degradations: readonly RuntimeDegradation[];
|
|
97
102
|
}
|
|
@@ -120,6 +125,7 @@ export interface RuntimeCandidate {
|
|
|
120
125
|
readonly commitGuards: readonly (() => Promise<void>)[];
|
|
121
126
|
readonly hooks?: RuntimeAgentHooks<Cloudflare.Env, unknown, never, never>;
|
|
122
127
|
readonly turnEvents?: RuntimeTurnEventsPort;
|
|
128
|
+
readonly telemetry?: AgentTelemetryBinding;
|
|
123
129
|
}
|
|
124
130
|
|
|
125
131
|
const DISABLED_MEMORY: RuntimeMemoryProfile = Object.freeze({
|
|
@@ -244,21 +250,21 @@ async function createToolSurface(
|
|
|
244
250
|
}
|
|
245
251
|
const mergeable = finalized.filter(
|
|
246
252
|
(candidate) =>
|
|
253
|
+
!candidate.direct &&
|
|
247
254
|
!candidate.interaction &&
|
|
248
255
|
typeof candidate.tool.execute === "function",
|
|
249
256
|
);
|
|
250
|
-
const
|
|
251
|
-
(candidate) =>
|
|
252
|
-
candidate.interaction ||
|
|
253
|
-
typeof candidate.tool.execute !== "function",
|
|
254
|
-
);
|
|
257
|
+
const codeExecutionTools = Object.freeze([...mergeable]);
|
|
255
258
|
return Object.freeze([
|
|
256
|
-
Object.freeze(
|
|
257
|
-
|
|
258
|
-
|
|
259
|
+
Object.freeze({
|
|
260
|
+
...codeExecutionPiToolCandidate(
|
|
261
|
+
input.codeExecution.create(
|
|
262
|
+
toolRegistryFromPiCandidates(codeExecutionTools),
|
|
263
|
+
),
|
|
259
264
|
),
|
|
260
|
-
|
|
261
|
-
|
|
265
|
+
codeExecutionTools,
|
|
266
|
+
}),
|
|
267
|
+
...finalized,
|
|
262
268
|
]);
|
|
263
269
|
},
|
|
264
270
|
}),
|
|
@@ -300,6 +306,7 @@ class RuntimeBuilder {
|
|
|
300
306
|
private readonly enabledSubagents = new Set<string>();
|
|
301
307
|
private subagents?: RuntimeSubagentPort;
|
|
302
308
|
private turnEvents?: RuntimeTurnEventsPort;
|
|
309
|
+
private telemetry?: AgentTelemetryBinding;
|
|
303
310
|
private readonly commitGuards: Array<() => Promise<void>> = [];
|
|
304
311
|
private readonly degradations: RuntimeDegradation[] = [];
|
|
305
312
|
|
|
@@ -332,6 +339,9 @@ class RuntimeBuilder {
|
|
|
332
339
|
}
|
|
333
340
|
this.subagents = input.subagents;
|
|
334
341
|
this.turnEvents = input.turnEvents;
|
|
342
|
+
this.telemetry = input.telemetry
|
|
343
|
+
? normalizeAgentTelemetryBinding(input.telemetry)
|
|
344
|
+
: undefined;
|
|
335
345
|
this.commitGuards.push(...input.commitGuards);
|
|
336
346
|
}
|
|
337
347
|
|
|
@@ -528,6 +538,7 @@ class RuntimeBuilder {
|
|
|
528
538
|
const bindings: RuntimeBindings = Object.freeze({
|
|
529
539
|
provider,
|
|
530
540
|
platform: Object.freeze({ ...this.platform }),
|
|
541
|
+
...(this.codeExecution ? { codeExecution: this.codeExecution } : {}),
|
|
531
542
|
...(this.gateway ? { gateway: this.gateway } : {}),
|
|
532
543
|
...(this.workspace ? { workspace: this.workspace } : {}),
|
|
533
544
|
...(this.memoryProfile.enabled && this.memory
|
|
@@ -559,6 +570,7 @@ class RuntimeBuilder {
|
|
|
559
570
|
commitGuards: Object.freeze([
|
|
560
571
|
...this.commitGuards,
|
|
561
572
|
]),
|
|
573
|
+
...(this.telemetry ? { telemetry: this.telemetry } : {}),
|
|
562
574
|
});
|
|
563
575
|
}
|
|
564
576
|
|
|
@@ -616,23 +628,28 @@ export function toolRegistryPiToolCandidates(
|
|
|
616
628
|
if (deny.has(name)) continue;
|
|
617
629
|
if (allowsTool?.(name) === false) continue;
|
|
618
630
|
const normalized = requiredName(name, "Platform Tool");
|
|
631
|
+
const {
|
|
632
|
+
label,
|
|
633
|
+
description,
|
|
634
|
+
parameters,
|
|
635
|
+
execute,
|
|
636
|
+
owner = "platform",
|
|
637
|
+
...metadata
|
|
638
|
+
} = spec;
|
|
619
639
|
candidates.push(Object.freeze({
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
...(spec.alwaysRequiresApproval
|
|
623
|
-
? { alwaysRequiresApproval: true }
|
|
624
|
-
: {}),
|
|
640
|
+
...metadata,
|
|
641
|
+
owner,
|
|
625
642
|
tool: Object.freeze({
|
|
626
643
|
name: normalized,
|
|
627
|
-
label
|
|
628
|
-
description
|
|
629
|
-
parameters
|
|
644
|
+
label,
|
|
645
|
+
description,
|
|
646
|
+
parameters,
|
|
630
647
|
async execute(
|
|
631
648
|
toolCallId: string,
|
|
632
649
|
input: unknown,
|
|
633
650
|
signal?: AbortSignal,
|
|
634
651
|
) {
|
|
635
|
-
const result = await
|
|
652
|
+
const result = await execute(input, {
|
|
636
653
|
toolCallId,
|
|
637
654
|
signal: signal ?? new AbortController().signal,
|
|
638
655
|
});
|
|
@@ -817,6 +834,7 @@ export async function assembleRuntimeSnapshot<
|
|
|
817
834
|
: {}),
|
|
818
835
|
extensions: resources.extensions,
|
|
819
836
|
...(turnEvents ? { turnEvents } : {}),
|
|
837
|
+
...(input.telemetry ? { telemetry: input.telemetry } : {}),
|
|
820
838
|
commitGuards: [],
|
|
821
839
|
degradations: [
|
|
822
840
|
...(toolAssembly.degradations ?? []),
|
|
@@ -843,6 +861,7 @@ export async function assembleRuntimeSnapshot<
|
|
|
843
861
|
}
|
|
844
862
|
: {}),
|
|
845
863
|
...(turnEvents ? { turnEvents } : {}),
|
|
864
|
+
...(candidate.telemetry ? { telemetry: candidate.telemetry } : {}),
|
|
846
865
|
});
|
|
847
866
|
}
|
|
848
867
|
|
|
@@ -27,6 +27,7 @@ import type {
|
|
|
27
27
|
RuntimeAssemblyContext,
|
|
28
28
|
RuntimeAgentPlanningContext,
|
|
29
29
|
} from "./runtime-agent-context";
|
|
30
|
+
import type { AgentTelemetryBinding } from "./telemetry/contract";
|
|
30
31
|
|
|
31
32
|
export interface RuntimeProfileContribution {
|
|
32
33
|
readonly model: string;
|
|
@@ -184,4 +185,5 @@ export interface AssembleRuntimeSnapshotInput<
|
|
|
184
185
|
readonly tools: import("./tool-registry").ToolAssemblyResult;
|
|
185
186
|
readonly resources: ResolvedResources;
|
|
186
187
|
readonly hooks?: RuntimeAgentHooks<Env, Config, Command, Change>;
|
|
188
|
+
readonly telemetry?: AgentTelemetryBinding;
|
|
187
189
|
}
|