@springbrand/agent-runtime 0.1.3-alpha.4 → 0.1.3-alpha.5

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.
Files changed (34) hide show
  1. package/package.json +3 -1
  2. package/src/adapter/cloudflare/index.ts +60 -0
  3. package/src/adapter/cloudflare/resources/runtime-resources.ts +86 -0
  4. package/src/adapter/cloudflare/sandbox/adapter.ts +1509 -0
  5. package/src/adapter/cloudflare/sandbox/id.ts +23 -0
  6. package/src/adapter/cloudflare/sandbox/policy.ts +15 -0
  7. package/src/adapter/cloudflare/subagent/definition.ts +574 -0
  8. package/src/adapter/cloudflare/subagent/runner.ts +175 -0
  9. package/src/adapter/cloudflare/subagent/tools.ts +256 -0
  10. package/src/adapter/cloudflare/universal-agent/definition.ts +71 -0
  11. package/src/adapter/cloudflare/universal-agent/hooks.ts +35 -0
  12. package/src/adapter/cloudflare/universal-agent/preparation.ts +273 -0
  13. package/src/adapter/cloudflare/universal-agent/tools.ts +74 -0
  14. package/src/adapter/cloudflare/workspace/publisher.ts +31 -0
  15. package/src/adapter/cloudflare/workspace/scoped-workspace.ts +376 -0
  16. package/src/agent-tool-runtime.ts +152 -0
  17. package/src/index.ts +49 -7
  18. package/src/layers/orchestration/temporary-agent/core.ts +12 -1
  19. package/src/layers/orchestration/temporary-agent/runner.ts +1 -2
  20. package/src/pi/message/contract.ts +7 -0
  21. package/src/pi/message/conversion.ts +9 -1
  22. package/src/pi/runtime-adapter/assembly.ts +4 -2
  23. package/src/pi/runtime-adapter/index.ts +6 -2
  24. package/src/pi/tool/base.ts +17 -0
  25. package/src/pi/tool/core.ts +13 -0
  26. package/src/pi/tool/schedule.ts +11 -0
  27. package/src/pi/tool/subagent.ts +14 -0
  28. package/src/pi/tool/workspace-sandbox.ts +15 -0
  29. package/src/runtime-agent-context.ts +112 -0
  30. package/src/runtime-agent.ts +429 -315
  31. package/src/runtime-assembler.ts +249 -99
  32. package/src/runtime-definition.ts +173 -0
  33. package/src/runtime.ts +139 -12
  34. package/src/tool-registry.ts +143 -0
@@ -33,75 +33,40 @@ import {
33
33
  type PiToolSurface,
34
34
  type PiRuntimeAssembly,
35
35
  } from "./pi/assembly/snapshot";
36
+ import type { AgentTool } from "@earendil-works/pi-agent-core";
36
37
  import type { PiToolCandidate } from "./pi/tool/compiler";
38
+ import type {
39
+ AssembleRuntimeSnapshotInput,
40
+ RuntimeAgentHooks,
41
+ RuntimeSettings,
42
+ RuntimeExtensionContribution,
43
+ RuntimeProfileContribution,
44
+ RuntimeSkillContribution,
45
+ RuntimeToolSurfacePolicy,
46
+ } from "./runtime-definition";
47
+ import type { ToolRegistry } from "./tool-registry";
37
48
  import {
38
49
  basePiToolCandidates,
39
50
  memoryPiToolCandidate,
40
51
  } from "./pi/tool/base";
41
52
  import {
42
53
  browserQuickActionPiToolCandidates,
43
- codeExecutionPiToolCandidate,
44
54
  } from "./pi/tool/core";
45
- import {
46
- sandboxPiToolCandidates,
47
- workspacePiToolCandidates,
48
- } from "./pi/tool/workspace-sandbox";
49
- import { schedulePiToolCandidates } from "./pi/tool/schedule";
50
55
  import { skillPiToolCandidates } from "./pi/tool/skill";
51
- import { subagentPiToolCandidates } from "./pi/tool/subagent";
52
56
  import { createWebSearch } from "./pi/tool/web-search";
53
57
  import { resolvePiModel } from "./pi/runtime-adapter/models";
54
58
 
55
59
  /** Runtime Assembler:校验一份扁平输入并生成可原子提交的 Snapshot。 */
56
60
 
57
61
  export type { RuntimeDegradation } from "./kernel/degradation";
58
-
59
- /**
60
- * 提供 Runtime 核心运行参数。
61
- *
62
- * @remarks
63
- * Host Planner 在装配输入中提供它。
64
- *
65
- * 这里只放业务可配置字段,冻结和最终结构由 Runtime 负责。
66
- */
67
- export interface RuntimeProfileContribution {
68
- readonly model: string;
69
- readonly thinking: ThinkingEffort;
70
- readonly systemPrompt?: string;
71
- readonly executionLevel: ExecutionLevel;
72
- }
73
-
74
- /**
75
- * 描述一个已准备 Skill。
76
- */
77
- export interface RuntimeSkillContribution {
78
- readonly name: string;
79
- readonly description: string;
80
- readonly source: SkillSource;
81
- readonly script?: Partial<RuntimeSkillScriptPolicy>;
82
- }
83
-
84
- /**
85
- * 描述一个已准备 Extension。
86
- */
87
- export interface RuntimeExtensionContribution {
88
- readonly name: string;
89
- readonly extension: RuntimeExtensionConfig;
90
- }
91
-
92
- /**
93
- * 描述 Agent 对最终 Tool Surface 的可见性约束。
94
- *
95
- * Host 只提供策略;Runtime 在唯一 Tool Surface seam 中对所有
96
- * Port 和 Resource 生成的候选项统一应用。
97
- */
98
- export interface RuntimeToolSurfacePolicy {
99
- readonly denyPolicy?: RuntimeDenyPolicy;
100
- readonly allowsTool?: (name: string) => boolean;
101
- readonly allowsExtension?: (extension: RuntimeExtensionConfig) => boolean;
102
- }
103
-
104
- /** Host Planner 与 Runtime Assembler 之间唯一的一次性 seam。 */
62
+ export type {
63
+ RuntimeExtensionContribution,
64
+ RuntimeProfileContribution,
65
+ RuntimeSkillContribution,
66
+ RuntimeToolSurfacePolicy,
67
+ } from "./runtime-definition";
68
+
69
+ /** Host Planner Runtime Assembler 之间的一次性内部 seam。 */
105
70
  export interface RuntimeAssemblyInput {
106
71
  readonly profile: RuntimeProfileContribution;
107
72
  readonly memoryProfile: RuntimeMemoryProfile;
@@ -147,6 +112,8 @@ export interface RuntimeSnapshot {
147
112
  export interface RuntimeCandidate {
148
113
  readonly snapshot: RuntimeSnapshot;
149
114
  readonly commitGuards: readonly (() => Promise<void>)[];
115
+ readonly hooks?: RuntimeAgentHooks<Cloudflare.Env, unknown, never, never>;
116
+ readonly turnEvents?: RuntimeTurnEventsPort;
150
117
  }
151
118
 
152
119
  const DISABLED_MEMORY: RuntimeMemoryProfile = Object.freeze({
@@ -187,12 +154,8 @@ interface ToolSurfaceInput {
187
154
  readonly port: RuntimeMemoryPort;
188
155
  readonly profile: RuntimeMemoryProfile;
189
156
  };
190
- readonly codeExecution?: RuntimeCodeExecutionPort;
191
- readonly sandbox?: RuntimeSandboxPort;
192
157
  readonly hostTools: readonly PiToolCandidate[];
193
158
  readonly skills: readonly RuntimeSkillSourceBinding[];
194
- readonly schedule?: RuntimeSchedulePort;
195
- readonly subagents?: RuntimeSubagentPort;
196
159
  readonly enabledSubagents: readonly string[];
197
160
  readonly webSearch: Parameters<typeof basePiToolCandidates>[0];
198
161
  readonly extensions: readonly RuntimeExtensionConfig[];
@@ -220,50 +183,24 @@ async function createToolSurface(
220
183
  const browserCandidates = input.platform.browser
221
184
  ? browserQuickActionPiToolCandidates(input.platform.browser)
222
185
  : [];
223
- const workspaceCandidates = input.workspace
224
- ? workspacePiToolCandidates(input.workspace)
225
- : [];
226
- const executionCandidates = input.workspace && input.codeExecution
227
- ? [codeExecutionPiToolCandidate(input.codeExecution)]
228
- : [];
229
- const sandboxCandidates = input.sandbox
230
- ? sandboxPiToolCandidates(input.sandbox)
231
- : [];
232
- const subagentCandidates = subagentPiToolCandidates(
233
- input.subagents,
234
- input.enabledSubagents,
235
- );
236
- const scheduleCandidates = input.schedule
237
- ? schedulePiToolCandidates(input.schedule)
238
- : [];
239
186
  const baseCandidates = basePiToolCandidates(input.webSearch);
240
187
  const memoryCandidates = input.memory
241
188
  ? [memoryPiToolCandidate(input.memory.port, input.memory.profile)]
242
189
  : [];
243
190
  const scriptCandidates = [
244
191
  ...browserCandidates,
245
- ...workspaceCandidates,
246
- ...executionCandidates,
247
- ...sandboxCandidates,
248
192
  ...input.hostTools,
249
- ...scheduleCandidates,
250
- ...subagentCandidates,
251
193
  ...baseCandidates,
252
194
  ...memoryCandidates,
253
195
  ].filter(visible);
254
196
  const staticCandidates = [
255
197
  ...browserCandidates,
256
- ...workspaceCandidates,
257
- ...executionCandidates,
258
- ...sandboxCandidates,
259
198
  ...input.hostTools,
260
199
  ...(await skillPiToolCandidates(input.skills, {
261
200
  loader: input.platform.loader,
262
201
  ...(input.workspace ? { workspace: input.workspace } : {}),
263
202
  tools: scriptCandidates,
264
203
  })),
265
- ...scheduleCandidates,
266
- ...subagentCandidates,
267
204
  ...baseCandidates,
268
205
  ...memoryCandidates,
269
206
  ];
@@ -487,17 +424,7 @@ class RuntimeBuilder {
487
424
  assertMemoryProfile(this.memoryProfile);
488
425
  if (this.memoryProfile.enabled && (!this.workspace || !this.memory)) {
489
426
  throw new Error(
490
- "Enabled Runtime memory requires Workspace and Memory ports",
491
- );
492
- }
493
- if (this.sandbox && !this.workspace) {
494
- throw new Error(
495
- "Runtime Sandbox requires a persistent Workspace port",
496
- );
497
- }
498
- if (this.enabledSubagents.size > 0 && !this.subagents) {
499
- throw new Error(
500
- "Enabled Runtime Subagents require a Subagent port",
427
+ "Enabled Runtime memory requires Workspace and Memory bindings",
501
428
  );
502
429
  }
503
430
  const profile = freezeRuntimeProfile({
@@ -547,12 +474,8 @@ class RuntimeBuilder {
547
474
  ...(this.memoryProfile.enabled && this.memory
548
475
  ? { memory: { port: this.memory, profile: this.memoryProfile } }
549
476
  : {}),
550
- ...(this.codeExecution ? { codeExecution: this.codeExecution } : {}),
551
- ...(this.sandbox ? { sandbox: this.sandbox } : {}),
552
477
  hostTools: this.hostTools,
553
478
  skills: skillSources,
554
- ...(this.schedule ? { schedule: this.schedule } : {}),
555
- ...(this.subagents ? { subagents: this.subagents } : {}),
556
479
  enabledSubagents: [...this.enabledSubagents],
557
480
  webSearch,
558
481
  extensions: [...this.extensions.values()],
@@ -640,4 +563,231 @@ export async function assembleRuntime(
640
563
  commit(candidate.snapshot);
641
564
  }
642
565
 
566
+ export function toolRegistryPiToolCandidates(
567
+ registry: ToolRegistry,
568
+ settings?: Pick<RuntimeSettings, "toolPolicy">,
569
+ ): PiToolCandidate[] {
570
+ const deny = new Set(settings?.toolPolicy?.denyPolicy?.deny ?? []);
571
+ const allowsTool = settings?.toolPolicy?.allowsTool;
572
+ const candidates: PiToolCandidate[] = [];
573
+ for (const [name, spec] of Object.entries(registry)) {
574
+ if (deny.has(name)) continue;
575
+ if (allowsTool?.(name) === false) continue;
576
+ const normalized = requiredName(name, "Platform Tool");
577
+ candidates.push(Object.freeze({
578
+ owner: "platform",
579
+ authorized: true,
580
+ requiredExecutionLevel: spec.requiredExecutionLevel,
581
+ ...(spec.alwaysRequiresApproval
582
+ ? { alwaysRequiresApproval: true }
583
+ : {}),
584
+ tool: Object.freeze({
585
+ name: normalized,
586
+ label: spec.label,
587
+ description: spec.description,
588
+ parameters: spec.parameters,
589
+ async execute(
590
+ toolCallId: string,
591
+ input: unknown,
592
+ signal?: AbortSignal,
593
+ ) {
594
+ const result = await spec.execute(input, {
595
+ toolCallId,
596
+ signal: signal ?? new AbortController().signal,
597
+ });
598
+ if (
599
+ result != null &&
600
+ typeof result === "object" &&
601
+ "content" in result &&
602
+ Array.isArray((result as { content?: unknown }).content)
603
+ ) {
604
+ return result as import("@earendil-works/pi-agent-core").AgentToolResult<unknown>;
605
+ }
606
+ let text: string;
607
+ try {
608
+ text = JSON.stringify(result) ?? String(result);
609
+ } catch {
610
+ text = String(result);
611
+ }
612
+ return {
613
+ content: [{ type: "text" as const, text }],
614
+ details: result,
615
+ };
616
+ },
617
+ } as AgentTool<any, any>),
618
+ }));
619
+ }
620
+ return candidates;
621
+ }
622
+
623
+ function hooksToTurnEventsPort<
624
+ Env extends Cloudflare.Env,
625
+ Config,
626
+ Command,
627
+ Change,
628
+ >(
629
+ ctx: AssembleRuntimeSnapshotInput<Env, Config, Command, Change>["ctx"],
630
+ hooks?: RuntimeAgentHooks<Env, Config, Command, Change>,
631
+ ): RuntimeTurnEventsPort | undefined {
632
+ if (!hooks) return undefined;
633
+ if (
634
+ !hooks.onTurnEnd &&
635
+ !hooks.onModelUsage &&
636
+ !hooks.onToolSettled &&
637
+ !hooks.onApproval &&
638
+ !hooks.onActivityChanged &&
639
+ !hooks.onSubmissionTerminal
640
+ ) {
641
+ return undefined;
642
+ }
643
+ return {
644
+ onResponse: hooks.onTurnEnd
645
+ ? (messages) => hooks.onTurnEnd!(ctx, messages)
646
+ : async () => undefined,
647
+ ...(hooks.onModelUsage ? { onModelUsage: hooks.onModelUsage } : {}),
648
+ ...(hooks.onToolSettled ? { onToolSettled: hooks.onToolSettled } : {}),
649
+ ...(hooks.onApproval ? { onApproval: hooks.onApproval } : {}),
650
+ ...(hooks.onActivityChanged
651
+ ? { onActivityChanged: hooks.onActivityChanged }
652
+ : {}),
653
+ ...(hooks.onSubmissionTerminal
654
+ ? { onSubmissionTerminal: hooks.onSubmissionTerminal }
655
+ : {}),
656
+ };
657
+ }
658
+
659
+ /**
660
+ * 从 Config、Tool 和已加载 Resource 装配 Runtime 候选 Snapshot。
661
+ *
662
+ * @internal
663
+ */
664
+ export async function assembleRuntimeSnapshot<
665
+ Env extends Cloudflare.Env,
666
+ Config,
667
+ Command = never,
668
+ Change = never,
669
+ >(
670
+ input: AssembleRuntimeSnapshotInput<Env, Config, Command, Change>,
671
+ ): Promise<RuntimeCandidate> {
672
+ const resources = input.resources;
673
+ const toolAssembly = input.tools;
674
+ const settings = resources.settings;
675
+ const provider = resources.provider;
676
+ let profile = settings.profile;
677
+ if (input.hooks?.profileOverrides) {
678
+ const overrides = await input.hooks.profileOverrides(
679
+ input.ctx,
680
+ input.config,
681
+ );
682
+ if (overrides.systemPrompt !== undefined) {
683
+ profile = { ...profile, systemPrompt: overrides.systemPrompt };
684
+ }
685
+ if (overrides.executionLevel !== undefined) {
686
+ profile = { ...profile, executionLevel: overrides.executionLevel };
687
+ }
688
+ }
689
+
690
+ const hostTools = toolRegistryPiToolCandidates(
691
+ toolAssembly.tools,
692
+ settings,
693
+ );
694
+
695
+ const commitGuards: Array<() => Promise<void>> = [];
696
+ if (toolAssembly.commitGuard) commitGuards.push(toolAssembly.commitGuard);
697
+ if (input.hooks?.beforeCommit) {
698
+ for (const guard of input.hooks.beforeCommit) {
699
+ commitGuards.push(() => guard(input.ctx, input.config));
700
+ }
701
+ }
702
+
703
+ const platform: RuntimePlatformPort = input.hooks?.gateTool
704
+ ? Object.freeze({
705
+ ...resources.platform,
706
+ gateTool: (request: {
707
+ toolCallId: string;
708
+ toolName: string;
709
+ input: unknown;
710
+ requiredExecutionLevel: import("./lib/execution-level").ExecutionLevel;
711
+ signal: AbortSignal;
712
+ }) => input.hooks!.gateTool!(request),
713
+ })
714
+ : resources.platform;
715
+
716
+ const memoryProfile =
717
+ toolAssembly.memoryProfile ?? settings.memoryProfile;
718
+ const enabledSubagents =
719
+ toolAssembly.enabledSubagents ?? settings.enabledSubagents;
720
+ const turnEvents = hooksToTurnEventsPort(input.ctx, input.hooks);
721
+
722
+ const toolPolicy: RuntimeToolSurfacePolicy | undefined =
723
+ settings.toolPolicy || toolAssembly.surfacePolicy
724
+ ? {
725
+ ...(settings.toolPolicy?.denyPolicy
726
+ ? { denyPolicy: settings.toolPolicy.denyPolicy }
727
+ : {}),
728
+ ...(settings.toolPolicy?.allowsTool
729
+ ? { allowsTool: settings.toolPolicy.allowsTool }
730
+ : {}),
731
+ ...(settings.toolPolicy?.allowsExtension
732
+ ? { allowsExtension: settings.toolPolicy.allowsExtension }
733
+ : {}),
734
+ ...(toolAssembly.surfacePolicy?.allowsTool
735
+ ? { allowsTool: toolAssembly.surfacePolicy.allowsTool }
736
+ : {}),
737
+ ...(toolAssembly.surfacePolicy?.allowsExtension
738
+ ? { allowsExtension: toolAssembly.surfacePolicy.allowsExtension }
739
+ : {}),
740
+ }
741
+ : undefined;
742
+
743
+ const assemblyInput: RuntimeAssemblyInput = {
744
+ profile,
745
+ memoryProfile,
746
+ ...(toolPolicy ? { toolPolicy } : {}),
747
+ enabledSubagents: [...enabledSubagents],
748
+ provider,
749
+ platform,
750
+ ...(toolAssembly.bindings?.workspace
751
+ ? { workspace: toolAssembly.bindings.workspace }
752
+ : {}),
753
+ ...(memoryProfile.enabled && toolAssembly.bindings?.memory
754
+ ? { memory: toolAssembly.bindings.memory }
755
+ : {}),
756
+ hostTools,
757
+ skills: resources.skills,
758
+ connectors: resources.connectors.servers,
759
+ ...(resources.connectors.gateway
760
+ ? { gateway: resources.connectors.gateway }
761
+ : {}),
762
+ extensions: resources.extensions,
763
+ ...(turnEvents ? { turnEvents } : {}),
764
+ commitGuards: [],
765
+ degradations: [
766
+ ...(toolAssembly.degradations ?? []),
767
+ ...(resources.degradations ?? []),
768
+ ...resources.connectors.degradations,
769
+ ],
770
+ };
771
+
772
+ const candidate = await prepareRuntimeCandidate(assemblyInput);
773
+ return Object.freeze({
774
+ snapshot: candidate.snapshot,
775
+ commitGuards: Object.freeze([
776
+ ...candidate.commitGuards,
777
+ ...commitGuards,
778
+ ]),
779
+ ...(input.hooks
780
+ ? {
781
+ hooks: input.hooks as unknown as RuntimeAgentHooks<
782
+ Cloudflare.Env,
783
+ unknown,
784
+ never,
785
+ never
786
+ >,
787
+ }
788
+ : {}),
789
+ ...(turnEvents ? { turnEvents } : {}),
790
+ });
791
+ }
792
+
643
793
  // #endregion
@@ -0,0 +1,173 @@
1
+ import type { SkillSource } from "agents/skills";
2
+ import type { ExecutionLevel } from "./lib/execution-level";
3
+ import type {
4
+ RuntimeGatewayPort,
5
+ RuntimeModelUsageEvent,
6
+ RuntimePlatformPort,
7
+ RuntimeProviderPort,
8
+ RuntimeSkillScriptPolicy,
9
+ RuntimeTurnMessage,
10
+ } from "./kernel/bindings";
11
+ import type {
12
+ RuntimeDenyPolicy,
13
+ RuntimeMcpServer,
14
+ RuntimeMemoryProfile,
15
+ ThinkingEffort,
16
+ } from "./kernel/profile";
17
+ import type { RuntimeExtensionConfig } from "./kernel/extensions";
18
+ import type { RuntimeActivityProjection } from "./kernel/state";
19
+ import type { RuntimeDegradation } from "./kernel/degradation";
20
+ import type {
21
+ RuntimeAgentContext,
22
+ RuntimeAssemblyContext,
23
+ RuntimeAgentPlanningContext,
24
+ } from "./runtime-agent-context";
25
+
26
+ export interface RuntimeProfileContribution {
27
+ readonly model: string;
28
+ readonly thinking: ThinkingEffort;
29
+ readonly systemPrompt?: string;
30
+ readonly executionLevel: ExecutionLevel;
31
+ }
32
+
33
+ export interface RuntimeSkillContribution {
34
+ readonly name: string;
35
+ readonly description: string;
36
+ readonly source: SkillSource;
37
+ readonly script?: Partial<RuntimeSkillScriptPolicy>;
38
+ }
39
+
40
+ export interface RuntimeExtensionContribution {
41
+ readonly name: string;
42
+ readonly extension: RuntimeExtensionConfig;
43
+ }
44
+
45
+ export interface RuntimeToolSurfacePolicy {
46
+ readonly denyPolicy?: RuntimeDenyPolicy;
47
+ readonly allowsTool?: (name: string) => boolean;
48
+ readonly allowsExtension?: (extension: RuntimeExtensionConfig) => boolean;
49
+ }
50
+
51
+ export type { RuntimeAgentContext, RuntimeAssemblyContext } from "./runtime-agent-context";
52
+
53
+ export interface GateToolRequest {
54
+ readonly toolCallId: string;
55
+ readonly toolName: string;
56
+ readonly input: unknown;
57
+ readonly requiredExecutionLevel: ExecutionLevel;
58
+ readonly signal: AbortSignal;
59
+ }
60
+
61
+ export type {
62
+ PlatformToolContext,
63
+ PlatformToolRegistry,
64
+ PlatformToolSpec,
65
+ RuntimeToolBindings,
66
+ ToolAssemblyResult,
67
+ ToolContext,
68
+ ToolRegistry,
69
+ ToolSpec,
70
+ } from "./tool-registry";
71
+ export {
72
+ emptyPlatformToolRegistry,
73
+ emptyToolRegistry,
74
+ mergeToolRegistries,
75
+ normalizeToolAssembly,
76
+ toolRegistryFromPiCandidates,
77
+ } from "./tool-registry";
78
+
79
+ export interface ResolvedConnectors {
80
+ readonly servers: readonly RuntimeMcpServer[];
81
+ readonly gateway?: RuntimeGatewayPort;
82
+ readonly degradations: readonly RuntimeDegradation[];
83
+ }
84
+
85
+ export interface ResolvedResources {
86
+ readonly settings: RuntimeSettings;
87
+ readonly provider: RuntimeProviderPort;
88
+ readonly platform: RuntimePlatformPort;
89
+ readonly skills: readonly RuntimeSkillContribution[];
90
+ readonly extensions: readonly RuntimeExtensionContribution[];
91
+ readonly connectors: ResolvedConnectors;
92
+ readonly degradations?: readonly RuntimeDegradation[];
93
+ }
94
+
95
+ export interface ProfileOverrides {
96
+ readonly systemPrompt?: string;
97
+ readonly executionLevel?: ExecutionLevel;
98
+ }
99
+
100
+ export interface ApprovalHookInput {
101
+ readonly submissionId: string;
102
+ readonly approvalExecutionId: string;
103
+ }
104
+
105
+ export interface SubmissionTerminalHookInput {
106
+ readonly submissionId: string;
107
+ readonly status: "completed" | "aborted" | "skipped" | "error";
108
+ readonly error?: string;
109
+ readonly resultMessageId?: string;
110
+ }
111
+
112
+ export interface RuntimeToolSettlementEvent {
113
+ readonly eventId: string;
114
+ readonly submissionId: string;
115
+ readonly toolCallId: string;
116
+ readonly toolName: string;
117
+ readonly status: "success" | "error";
118
+ }
119
+
120
+ export interface RuntimeAgentHooks<
121
+ Env extends Cloudflare.Env = Cloudflare.Env,
122
+ Config = unknown,
123
+ Command = never,
124
+ Change = never,
125
+ > {
126
+ readonly beforeCommit?: ReadonlyArray<
127
+ (
128
+ ctx: RuntimeAssemblyContext<Env, Command, Change>,
129
+ config: Config,
130
+ ) => Promise<void>
131
+ >;
132
+
133
+ readonly onTurnEnd?: (
134
+ ctx: RuntimeAssemblyContext<Env, Command, Change>,
135
+ messages: readonly RuntimeTurnMessage[],
136
+ ) => Promise<void>;
137
+ readonly onModelUsage?: (event: RuntimeModelUsageEvent) => Promise<void>;
138
+ readonly onToolSettled?: (event: RuntimeToolSettlementEvent) => Promise<void>;
139
+ readonly onApproval?: (input: ApprovalHookInput) => Promise<void>;
140
+ readonly onActivityChanged?: (
141
+ projection: RuntimeActivityProjection,
142
+ ) => Promise<void>;
143
+ readonly onSubmissionTerminal?: (
144
+ input: SubmissionTerminalHookInput,
145
+ ) => Promise<void>;
146
+
147
+ readonly gateTool?: (request: GateToolRequest) => Promise<void>;
148
+
149
+ readonly profileOverrides?: (
150
+ ctx: RuntimeAssemblyContext<Env, Command, Change>,
151
+ config: Config,
152
+ ) => ProfileOverrides | Promise<ProfileOverrides>;
153
+ }
154
+
155
+ export interface RuntimeSettings {
156
+ readonly profile: RuntimeProfileContribution;
157
+ readonly memoryProfile: RuntimeMemoryProfile;
158
+ readonly toolPolicy?: RuntimeToolSurfacePolicy;
159
+ readonly enabledSubagents: readonly string[];
160
+ }
161
+
162
+ export interface AssembleRuntimeSnapshotInput<
163
+ Env extends Cloudflare.Env,
164
+ Config,
165
+ Command = never,
166
+ Change = never,
167
+ > {
168
+ readonly ctx: RuntimeAgentPlanningContext<Env, Command, Change>;
169
+ readonly config: Config;
170
+ readonly tools: import("./tool-registry").ToolAssemblyResult;
171
+ readonly resources: ResolvedResources;
172
+ readonly hooks?: RuntimeAgentHooks<Env, Config, Command, Change>;
173
+ }