@springbrand/agent-runtime 0.2.0-alpha.72 → 0.3.0-alpha.10

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 (172) hide show
  1. package/package.json +7 -7
  2. package/src/{agent-tool-runtime.ts → adapter/cloudflare/agent-tool.ts} +1 -1
  3. package/src/adapter/cloudflare/agent.ts +1682 -0
  4. package/src/{db/index.ts → adapter/cloudflare/database.ts} +18 -55
  5. package/src/{runtime-agent.ts → adapter/cloudflare/define-agent.ts} +37 -42
  6. package/src/adapter/cloudflare/dynamic-worker-observability.ts +1 -1
  7. package/src/adapter/cloudflare/index.ts +18 -0
  8. package/src/adapter/cloudflare/resources/runtime-resources.ts +4 -4
  9. package/src/adapter/cloudflare/sandbox/adapter.ts +1 -1
  10. package/src/adapter/cloudflare/scheduling/schedule-rule.ts +322 -0
  11. package/src/adapter/cloudflare/scheduling/zoned-cron.ts +11 -6
  12. package/src/{db → adapter/cloudflare}/schema.ts +28 -80
  13. package/src/adapter/cloudflare/subagent/definition.ts +63 -33
  14. package/src/adapter/cloudflare/subagent/runner.ts +174 -120
  15. package/src/adapter/cloudflare/subagent/tools.ts +13 -14
  16. package/src/adapter/cloudflare/universal-agent/preparation.ts +7 -7
  17. package/src/adapter/cloudflare/universal-agent/tools.ts +10 -12
  18. package/src/adapter/cloudflare/workspace/git-fs.ts +1 -1
  19. package/src/adapter/cloudflare/workspace/scoped-workspace.ts +1 -1
  20. package/src/adapter/cloudflare/workspace/version-control.ts +2 -2
  21. package/src/config/activation.ts +140 -0
  22. package/src/{runtime-agent-context.ts → config/agent-context.ts} +3 -3
  23. package/src/{runtime-assembler.ts → config/assembler.ts} +45 -46
  24. package/src/{kernel/runtime-assembly.ts → config/assembly-projection.ts} +4 -4
  25. package/src/{pi/assembly/snapshot.ts → config/assembly-snapshot.ts} +6 -6
  26. package/src/{runtime-definition.ts → config/definition.ts} +13 -13
  27. package/src/config/harness-runtime.ts +190 -0
  28. package/src/config/index.ts +14 -0
  29. package/src/config/model-guidance.ts +21 -0
  30. package/src/{pi/runtime-adapter/assembly.ts → config/pinning.ts} +60 -19
  31. package/src/{kernel/bindings.ts → config/ports.ts} +32 -16
  32. package/src/{kernel → config}/profile.ts +7 -0
  33. package/src/{kernel → config}/public-contracts.ts +6 -6
  34. package/src/{kernel → config}/runtime-load.ts +1 -1
  35. package/src/{pi/assembly/context.ts → context/assembly.ts} +5 -207
  36. package/src/{pi/assembly/extensions.ts → context/extension/assembly.ts} +5 -5
  37. package/src/context/extension/index.ts +3 -0
  38. package/src/context/index.ts +6 -0
  39. package/src/{layers/context → context/memory}/budget/gate.ts +21 -5
  40. package/src/conversation/harness-resume.ts +288 -0
  41. package/src/conversation/harness-stream.ts +99 -0
  42. package/src/{pi/runtime-adapter/transcript.ts → conversation/history.ts} +206 -233
  43. package/src/conversation/index.ts +6 -0
  44. package/src/{pi → conversation}/message/contract.ts +3 -0
  45. package/src/{pi → conversation}/message/conversion.ts +75 -0
  46. package/src/{pi → conversation}/message/index.ts +1 -0
  47. package/src/{pi → conversation}/message/model-input.ts +1 -1
  48. package/src/{pi → conversation}/message/projection.ts +113 -30
  49. package/src/{db/message-ui.repo.ts → conversation/repository.ts} +4 -0
  50. package/src/conversation/state.ts +196 -0
  51. package/src/harness/index.ts +7 -0
  52. package/src/harness/session-harness.ts +562 -0
  53. package/src/harness/submission-operation.ts +49 -0
  54. package/src/index.ts +38 -43
  55. package/src/lib/artifacts.ts +18 -0
  56. package/src/lib/execution-level.ts +13 -0
  57. package/src/lib/mcp.ts +1 -1
  58. package/src/lib/prompt.ts +7 -6
  59. package/src/lib/token-estimate.ts +8 -0
  60. package/src/{pi/runtime-adapter/models.ts → models/index.ts} +64 -17
  61. package/src/{pi/turn/tool-recovery.ts → session/cloudflare/legacy-tool-recovery.ts} +33 -525
  62. package/src/{pi/session → session/cloudflare}/migration.ts +404 -14
  63. package/src/{pi/session → session/cloudflare}/storage.ts +8 -36
  64. package/src/session/index.ts +39 -0
  65. package/src/skills/springbrand-worker-website/index.ts +1 -1
  66. package/src/submission/admission.ts +286 -0
  67. package/src/{kernel/receipts.ts → submission/contracts.ts} +56 -2
  68. package/src/submission/delivery.ts +212 -0
  69. package/src/submission/finalization.ts +111 -0
  70. package/src/submission/index.ts +9 -0
  71. package/src/{kernel/submission-lifecycle.ts → submission/lifecycle.ts} +41 -28
  72. package/src/{db/submission.repo.ts → submission/repository.ts} +117 -114
  73. package/src/submission/steer-delivery.ts +167 -0
  74. package/src/{db/steer.repo.ts → submission/steer-repository.ts} +27 -5
  75. package/src/submission/unattended.ts +40 -0
  76. package/src/telemetry/contract.ts +12 -0
  77. package/src/telemetry/coordinator.ts +65 -0
  78. package/src/telemetry/delivery.ts +2 -2
  79. package/src/telemetry/index.ts +5 -0
  80. package/src/{model-usage.ts → telemetry/model-usage.ts} +1 -1
  81. package/src/telemetry/recorder.ts +1 -1
  82. package/src/telemetry/runtime-telemetry.ts +12 -0
  83. package/src/{kernel/durable-lifecycle.ts → telemetry/subagent-lifecycle.ts} +1 -1
  84. package/src/telemetry/turn-events.ts +279 -0
  85. package/src/tools/README.md +44 -0
  86. package/src/{pi/tool/ai-adapter.ts → tools/adapters/ai-to-pi.ts} +6 -9
  87. package/src/{pi/tool → tools/adapters}/declared.ts +6 -2
  88. package/src/{pi/tool/nested-tools.ts → tools/adapters/pi-to-ai.ts} +2 -2
  89. package/src/tools/assistant/ask-user.ts +317 -0
  90. package/src/tools/assistant/candidate.ts +15 -0
  91. package/src/tools/assistant/followups.ts +34 -0
  92. package/src/tools/assistant/index.ts +19 -0
  93. package/src/tools/assistant/memory.ts +73 -0
  94. package/src/tools/assistant/plan.ts +98 -0
  95. package/src/{pi/tool → tools/assistant}/time.ts +1 -1
  96. package/src/{pi/tool/core-host.ts → tools/codemode/adapter.ts} +50 -49
  97. package/src/{pi/tool/core.ts → tools/codemode/index.ts} +35 -91
  98. package/src/tools/codemode/workspace-connector.ts +198 -0
  99. package/src/tools/extension/index.ts +42 -0
  100. package/src/tools/index.ts +32 -0
  101. package/src/{pi/tool → tools/mcp}/gateway.ts +19 -19
  102. package/src/{pi/tool/mcp.ts → tools/mcp/index.ts} +5 -5
  103. package/src/tools/runtime/approval/index.ts +1 -0
  104. package/src/{db/approval.repo.ts → tools/runtime/approval/repository.ts} +22 -41
  105. package/src/tools/runtime/compiler.ts +264 -0
  106. package/src/tools/runtime/contracts.ts +117 -0
  107. package/src/tools/runtime/decision-gate.ts +337 -0
  108. package/src/tools/runtime/human-decisions.ts +127 -0
  109. package/src/tools/runtime/interaction/index.ts +1 -0
  110. package/src/{db/interaction.repo.ts → tools/runtime/interaction/repository.ts} +1 -7
  111. package/src/tools/runtime/result.ts +22 -0
  112. package/src/tools/runtime/unattended-error.ts +4 -0
  113. package/src/tools/sandbox/index.ts +228 -0
  114. package/src/tools/schedule/index.ts +301 -0
  115. package/src/tools/skill/contracts.ts +20 -0
  116. package/src/tools/skill/index.ts +99 -0
  117. package/src/tools/skill/resources.ts +322 -0
  118. package/src/tools/skill/scripts.ts +168 -0
  119. package/src/{kernel/submission-authority.ts → tools/subagent/authority.ts} +31 -31
  120. package/src/{pi/tool/subagent.ts → tools/subagent/index.ts} +33 -36
  121. package/src/{db/agent-tool.repo.ts → tools/subagent/repository.ts} +1 -1
  122. package/src/{kernel/subagent-runtime.ts → tools/subagent/runtime.ts} +1 -1
  123. package/src/tools/subagent/temporary/approvals.ts +123 -0
  124. package/src/{layers/orchestration/temporary-agent/core.ts → tools/subagent/temporary/coordinator.ts} +41 -49
  125. package/src/tools/subagent/temporary/core.ts +53 -0
  126. package/src/{layers/orchestration/temporary-agent → tools/subagent/temporary}/runner.ts +1 -1
  127. package/src/{layers/orchestration/temporary-agent → tools/subagent/temporary}/workspace.ts +1 -4
  128. package/src/{pi/tool/web-fetch.ts → tools/web/fetch.ts} +4 -13
  129. package/src/tools/web/index.ts +2 -0
  130. package/src/tools/web/search/api.ts +1320 -0
  131. package/src/tools/web/search/index.ts +2 -0
  132. package/src/{pi/tool/web-search/web-search.ts → tools/web/search/search.ts} +5 -7
  133. package/src/{pi/tool/workspace-sandbox.ts → tools/workspace/index.ts} +12 -272
  134. package/src/{pi/tool/workspace-revision.ts → tools/workspace/revision.ts} +2 -2
  135. package/src/db/milestone.repo.ts +0 -104
  136. package/src/db/settlement.repo.ts +0 -104
  137. package/src/kernel/approval-lifecycle.ts +0 -638
  138. package/src/kernel/interaction-lifecycle.ts +0 -433
  139. package/src/kernel/recoverable-chat-agent.ts +0 -1020
  140. package/src/kernel/state.ts +0 -91
  141. package/src/pi/assembly/index.ts +0 -19
  142. package/src/pi/runtime-adapter/execution.ts +0 -1163
  143. package/src/pi/runtime-adapter/index.ts +0 -293
  144. package/src/pi/runtime-adapter/recovery.ts +0 -982
  145. package/src/pi/session/index.ts +0 -24
  146. package/src/pi/tool/base.ts +0 -550
  147. package/src/pi/tool/compiler.ts +0 -483
  148. package/src/pi/tool/index.ts +0 -38
  149. package/src/pi/tool/schedule.ts +0 -261
  150. package/src/pi/tool/skill.ts +0 -565
  151. package/src/pi/tool/web-search/api.ts +0 -1318
  152. package/src/pi/tool/web-search/index.ts +0 -2
  153. package/src/pi/tool/workspace-state-connector.ts +0 -146
  154. package/src/pi/turn/approval.ts +0 -181
  155. package/src/pi/turn/index.ts +0 -82
  156. package/src/pi/turn/interaction.ts +0 -181
  157. package/src/runtime.ts +0 -4760
  158. package/src/{kernel/runtime-assembly-view.ts → config/assembly-view.ts} +0 -0
  159. package/src/{kernel → config}/degradation.ts +0 -0
  160. package/src/{kernel → config}/runtime-config.ts +0 -0
  161. package/src/{kernel/extensions.ts → context/extension/contracts.ts} +0 -0
  162. package/src/{db/ext-context.repo.ts → context/extension/repository.ts} +0 -0
  163. package/src/{pi/runtime-adapter/openrouter-messages.ts → models/openrouter/messages.ts} +0 -0
  164. package/src/{pi/runtime-adapter → models/openrouter}/test-fixtures/openrouter-tool-search.sse +0 -0
  165. package/src/{db/submission-admission.repo.ts → submission/admission-repository.ts} +0 -0
  166. package/src/{db/telemetry-outbox.repo.ts → telemetry/repository.ts} +0 -0
  167. package/src/{db/runtime-event-outbox.repo.ts → telemetry/runtime-event-repository.ts} +0 -0
  168. package/src/{layers/orchestration/subagents/agent-types → tools/subagent/types}/contract.ts +0 -0
  169. package/src/{layers/orchestration/subagents/agent-types → tools/subagent/types}/extract/index.ts +0 -0
  170. package/src/{layers/orchestration/subagents/agent-types → tools/subagent/types}/fanout/index.ts +0 -0
  171. package/src/{layers/orchestration/subagents/agent-types → tools/subagent/types}/registry.ts +1 -1
  172. /package/src/{workspace-versioning.ts → tools/workspace/versioning.ts} +0 -0
@@ -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,4 +1,4 @@
1
- import type { RuntimeSubagentUsageMetrics } from "./submission-authority";
1
+ import type { RuntimeSubagentUsageMetrics } from "./authority";
2
2
 
3
3
  export interface RuntimeSubagentRunMetadata {
4
4
  readonly submissionId: string;
@@ -0,0 +1,123 @@
1
+ import type { ApprovalDecision, ApprovalReceipt } from "../../../submission/contracts";
2
+ import type { RuntimeTelemetryCoordinator } from "../../../telemetry/coordinator";
3
+ import type { TemporaryAgentApprovalDecision, TemporaryAgentApprovalRequest } from "./core";
4
+
5
+ interface PendingApproval {
6
+ receipt: ApprovalReceipt;
7
+ submissionId?: string;
8
+ toolCallId: string;
9
+ resolve(decision: TemporaryAgentApprovalDecision): void;
10
+ }
11
+
12
+ /** Human decisions belong to the temporary execution and expire with it. */
13
+ export class TemporaryAgentApprovals {
14
+ private readonly pending = new Map<string, PendingApproval>();
15
+
16
+ constructor(private readonly options: {
17
+ capture: RuntimeTelemetryCoordinator["capture"];
18
+ onChanged(): Promise<void>;
19
+ }) { }
20
+
21
+ find(executionId: string): ApprovalReceipt | null {
22
+ return this.pending.get(executionId)?.receipt ?? null;
23
+ }
24
+
25
+ list(): ApprovalReceipt[] {
26
+ return [...this.pending.values()].map(({ receipt }) => receipt);
27
+ }
28
+
29
+ request(
30
+ request: TemporaryAgentApprovalRequest,
31
+ submissionId?: string,
32
+ ): Promise<TemporaryAgentApprovalDecision> {
33
+ if (this.pending.has(request.executionId)) {
34
+ return Promise.reject(new Error(
35
+ `temporary agent approval already pending: ${request.executionId}`,
36
+ ));
37
+ }
38
+ const summary = `${request.subagentName} requests ${request.toolName}`;
39
+ return new Promise((resolve, reject) => {
40
+ const pending: PendingApproval = {
41
+ receipt: {
42
+ executionId: request.executionId,
43
+ source: "temporary-agent",
44
+ action: request.toolName,
45
+ summary,
46
+ executionLevel: request.executionLevel,
47
+ requiredExecutionLevel: request.requiredExecutionLevel,
48
+ inputJson: JSON.stringify(request.input ?? null),
49
+ requestId: request.requestId,
50
+ },
51
+ submissionId,
52
+ toolCallId: request.toolCallId,
53
+ resolve,
54
+ };
55
+ this.pending.set(request.executionId, pending);
56
+ if (submissionId) {
57
+ this.options.capture("approvalRequested", {
58
+ submissionId,
59
+ toolCallId: request.toolCallId,
60
+ executionId: request.executionId,
61
+ toolName: request.toolName,
62
+ summary,
63
+ input: request.input,
64
+ });
65
+ }
66
+ void this.options.onChanged().catch((error) => {
67
+ if (this.pending.get(request.executionId) === pending) {
68
+ this.pending.delete(request.executionId);
69
+ }
70
+ reject(error);
71
+ });
72
+ });
73
+ }
74
+
75
+ async cancel(
76
+ executionId: string,
77
+ reason = "temporary agent was cancelled",
78
+ ): Promise<{ ok: boolean }> {
79
+ return this.settle(executionId, { approved: false, reason }, "cancelled");
80
+ }
81
+
82
+ /** Undefined leaves ordinary durable Tool approvals to their fact owner. */
83
+ async decide(
84
+ executionId: string,
85
+ decision: ApprovalDecision,
86
+ ): Promise<{ ok: boolean } | undefined> {
87
+ if (!this.pending.has(executionId)) return undefined;
88
+ if (decision.decision === "allow_level") {
89
+ throw new Error(
90
+ "allow_level must be applied by the User Agent Host before resuming the Tool",
91
+ );
92
+ }
93
+ return this.settle(
94
+ executionId,
95
+ decision.decision === "allow_once"
96
+ ? { approved: true }
97
+ : { approved: false, reason: decision.reason },
98
+ decision.decision === "allow_once" ? "approved" : "rejected",
99
+ );
100
+ }
101
+
102
+ private async settle(
103
+ executionId: string,
104
+ result: TemporaryAgentApprovalDecision,
105
+ decision: "approved" | "rejected" | "cancelled",
106
+ ): Promise<{ ok: boolean }> {
107
+ const pending = this.pending.get(executionId);
108
+ if (!pending) return { ok: false };
109
+ this.pending.delete(executionId);
110
+ pending.resolve(result);
111
+ if (pending.submissionId) {
112
+ this.options.capture("approvalDecided", {
113
+ submissionId: pending.submissionId,
114
+ toolCallId: pending.toolCallId,
115
+ executionId,
116
+ decision,
117
+ ...(result.reason ? { reason: result.reason } : {}),
118
+ });
119
+ }
120
+ await this.options.onChanged();
121
+ return { ok: true };
122
+ }
123
+ }
@@ -1,55 +1,26 @@
1
- import type { ExecutionLevel } from "../../../lib/execution-level";
1
+ import type { TemporaryAgentExecutor, TemporaryAgentRequest } from "./core";
2
2
 
3
- export const TEMPORARY_AGENT_LAUNCH_KEY =
4
- "universal-agent:temporary-agent-launch";
5
-
6
- export interface TemporaryAgentRequest {
7
- subagentName: string;
8
- instructions: string;
9
- task: string;
10
- }
11
-
12
- export interface TemporaryAgentLaunch<Config = unknown>
13
- extends TemporaryAgentRequest {
14
- runtimeKey: string;
15
- config: Config;
16
- executionLevel: ExecutionLevel;
17
- }
18
-
19
- export interface TemporaryAgentRunContext {
20
- signal: AbortSignal;
21
- requestId: string;
22
- toolCallId: string;
23
- }
24
-
25
- /**
26
- * 启动一个临时 Agent,并在它完整收尾后返回最终文本。
27
- *
28
- * @remarks
29
- * `TemporaryAgentCoordinator.run` 在获得并发槽位后调用;实现方应把子运行和外部资源清理收口到同一个 Promise。
30
- *
31
- * 协调器只依赖这个函数而不依赖 Durable Object、UI 或具体 Agent SDK,避免把基础设施生命周期写进并发规则。
32
- *
33
- * Agent 和 Runtime 的术语见 `src/index.ts`。
34
- */
35
- export type TemporaryAgentExecutor = (
36
- request: TemporaryAgentRequest,
37
- ) => Promise<string>;
3
+ export type TemporaryAgentLifecycleEvent = {
4
+ type: "started";
5
+ request: TemporaryAgentRequest;
6
+ occurredAt: number;
7
+ } | {
8
+ type: "finished";
9
+ outcome: "completed" | "failed" | "cancelled";
10
+ durationMs: number;
11
+ occurredAt: number;
12
+ output?: string;
13
+ error?: unknown;
14
+ };
38
15
 
39
- export interface TemporaryAgentApprovalRequest {
40
- executionId: string;
41
- subagentName: string;
42
- requestId: string;
43
- toolCallId: string;
44
- toolName: string;
45
- executionLevel: ExecutionLevel;
46
- requiredExecutionLevel: ExecutionLevel;
47
- input: unknown;
48
- }
16
+ type TemporaryAgentObserver = (event: TemporaryAgentLifecycleEvent) => void;
49
17
 
50
- export interface TemporaryAgentApprovalDecision {
51
- approved: boolean;
52
- reason?: string;
18
+ function observe(observer: TemporaryAgentObserver | undefined, event: TemporaryAgentLifecycleEvent): void {
19
+ try {
20
+ observer?.(event);
21
+ } catch {
22
+ // Observation must not fail a child or prevent releasing its execution slot.
23
+ }
53
24
  }
54
25
 
55
26
  // 作用:去掉临时 Agent 请求三个字段的首尾空白,并拒绝空值。
@@ -95,13 +66,34 @@ export class TemporaryAgentCoordinator {
95
66
  request: TemporaryAgentRequest,
96
67
  execute: TemporaryAgentExecutor,
97
68
  signal?: AbortSignal,
69
+ observer?: TemporaryAgentObserver,
98
70
  ): Promise<string> {
99
71
  const normalized = normalizeRequest(request);
100
72
  await this.acquire(signal);
73
+ const startedAt = Date.now();
74
+ observe(observer, { type: "started", request: normalized, occurredAt: startedAt });
101
75
  try {
102
76
  const text = (await execute(normalized)).trim();
103
77
  if (!text) throw new Error("temporary agent final text must not be blank");
78
+ const occurredAt = Date.now();
79
+ observe(observer, {
80
+ type: "finished",
81
+ outcome: "completed",
82
+ output: text,
83
+ durationMs: Math.max(0, occurredAt - startedAt),
84
+ occurredAt,
85
+ });
104
86
  return text;
87
+ } catch (error) {
88
+ const occurredAt = Date.now();
89
+ observe(observer, {
90
+ type: "finished",
91
+ outcome: signal?.aborted ? "cancelled" : "failed",
92
+ error,
93
+ durationMs: Math.max(0, occurredAt - startedAt),
94
+ occurredAt,
95
+ });
96
+ throw error;
105
97
  } finally {
106
98
  this.release();
107
99
  }
@@ -0,0 +1,53 @@
1
+ import type { ExecutionLevel } from "../../../lib/execution-level";
2
+
3
+ export const TEMPORARY_AGENT_LAUNCH_KEY =
4
+ "universal-agent:temporary-agent-launch";
5
+
6
+ export interface TemporaryAgentRequest {
7
+ subagentName: string;
8
+ instructions: string;
9
+ task: string;
10
+ }
11
+
12
+ export interface TemporaryAgentLaunch<Config = unknown>
13
+ extends TemporaryAgentRequest {
14
+ runtimeKey: string;
15
+ config: Config;
16
+ executionLevel: ExecutionLevel;
17
+ }
18
+
19
+ export interface TemporaryAgentRunContext {
20
+ signal: AbortSignal;
21
+ requestId: string;
22
+ toolCallId: string;
23
+ }
24
+
25
+ /**
26
+ * 启动一个临时 Agent,并在它完整收尾后返回最终文本。
27
+ *
28
+ * @remarks
29
+ * `TemporaryAgentCoordinator.run` 在获得并发槽位后调用;实现方应把子运行和外部资源清理收口到同一个 Promise。
30
+ *
31
+ * 协调器只依赖这个函数而不依赖 Durable Object、UI 或具体 Agent SDK,避免把基础设施生命周期写进并发规则。
32
+ *
33
+ * Agent 和 Runtime 的术语见 `src/index.ts`。
34
+ */
35
+ export type TemporaryAgentExecutor = (
36
+ request: TemporaryAgentRequest,
37
+ ) => Promise<string>;
38
+
39
+ export interface TemporaryAgentApprovalRequest {
40
+ executionId: string;
41
+ subagentName: string;
42
+ requestId: string;
43
+ toolCallId: string;
44
+ toolName: string;
45
+ executionLevel: ExecutionLevel;
46
+ requiredExecutionLevel: ExecutionLevel;
47
+ input: unknown;
48
+ }
49
+
50
+ export interface TemporaryAgentApprovalDecision {
51
+ approved: boolean;
52
+ reason?: string;
53
+ }
@@ -1,4 +1,4 @@
1
- import type { RuntimeExtensionConfig } from "../../../kernel/extensions";
1
+ import type { RuntimeExtensionConfig } from "../../../context/extension/contracts";
2
2
 
3
3
  const BLOCKED_TOOLS = new Set([
4
4
  "dispatch_background",
@@ -1,7 +1,4 @@
1
- import type {
2
- WorkspaceFileInfo,
3
- WorkspacePort,
4
- } from "../../../kernel/bindings";
1
+ import type { WorkspaceFileInfo, WorkspacePort } from "../../../config/ports";
5
2
 
6
3
  const MEMORY_ROOT = "/userspace/memories";
7
4
 
@@ -10,14 +10,13 @@
10
10
  * - 不依赖 Workers AI `toMarkdown()`——base runtime 不持有 AI binding,调用方若需要
11
11
  * Markdown 转换,应在宿主层叠加;此处返回原始 UTF-8 解码内容。
12
12
  *
13
- * 本文件未接入任何系统入口(index.ts / base.ts),可单独 import 使用。
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 "./compiler";
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
- `Use the HTTPS version of this URL.`,
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
- `indicating that it does not permit its content to be used as AI input.`,
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
@@ -0,0 +1,2 @@
1
+ export * from "./fetch";
2
+ export * from "./search";