@springbrand/agent-runtime 0.3.0-alpha.2 → 0.3.0-alpha.21

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 (131) hide show
  1. package/package.json +11 -9
  2. package/src/adapter/cloudflare/agent.ts +233 -179
  3. package/src/adapter/cloudflare/define-agent.ts +252 -104
  4. package/src/adapter/cloudflare/index.ts +18 -0
  5. package/src/adapter/cloudflare/scheduling/schedule-rule.ts +322 -0
  6. package/src/adapter/cloudflare/scheduling/zoned-cron.ts +11 -6
  7. package/src/adapter/cloudflare/schema.ts +21 -2
  8. package/src/adapter/cloudflare/subagent/definition.ts +25 -13
  9. package/src/adapter/cloudflare/subagent/runner.ts +43 -50
  10. package/src/adapter/cloudflare/subagent/tools.ts +4 -4
  11. package/src/adapter/cloudflare/universal-agent/preparation.ts +3 -3
  12. package/src/adapter/cloudflare/universal-agent/tools.ts +4 -6
  13. package/src/adapter/cloudflare/workspace/version-control.ts +1 -1
  14. package/src/config/activation.ts +13 -15
  15. package/src/config/agent-context.ts +1 -1
  16. package/src/config/assembler.ts +48 -31
  17. package/src/config/assembly-snapshot.ts +1 -1
  18. package/src/config/definition.ts +1 -1
  19. package/src/config/harness-runtime.ts +77 -49
  20. package/src/config/index.ts +1 -1
  21. package/src/config/model-guidance.ts +20 -0
  22. package/src/config/ports.ts +57 -7
  23. package/src/config/{pinning.ts → prepared-runtime.ts} +59 -123
  24. package/src/config/public-contracts.ts +2 -2
  25. package/src/config/runtime-config.ts +2 -1
  26. package/src/context/assembly.ts +1 -1
  27. package/src/context/extension/assembly.ts +2 -2
  28. package/src/context/memory/budget/gate.ts +19 -3
  29. package/src/conversation/harness-resume.ts +89 -238
  30. package/src/conversation/harness-stream.ts +87 -71
  31. package/src/conversation/history.ts +154 -152
  32. package/src/conversation/message/contract.ts +28 -4
  33. package/src/conversation/message/conversion.ts +46 -5
  34. package/src/conversation/message/projection.ts +61 -21
  35. package/src/conversation/session-entry.ts +29 -0
  36. package/src/conversation/state.ts +23 -2
  37. package/src/harness/governance.ts +206 -0
  38. package/src/harness/index.ts +3 -0
  39. package/src/harness/session-harness.ts +269 -445
  40. package/src/harness/submission-operation.ts +15 -40
  41. package/src/index.ts +18 -8
  42. package/src/lib/artifacts.ts +18 -0
  43. package/src/lib/execution-level.ts +13 -0
  44. package/src/lib/prompt.ts +9 -10
  45. package/src/lib/token-estimate.ts +8 -0
  46. package/src/model-protocol/openrouter.ts +41 -0
  47. package/src/models/index.ts +200 -35
  48. package/src/models/openrouter/messages.ts +13 -8
  49. package/src/models/openrouter/openai.ts +200 -0
  50. package/src/models/openrouter/protocol-response.ts +85 -0
  51. package/src/models/provider-streams.ts +45 -0
  52. package/src/session/cloudflare/migration.ts +382 -864
  53. package/src/session/cloudflare/storage.ts +13 -536
  54. package/src/session/index.ts +22 -35
  55. package/src/skills/springbrand-worker-website/index.ts +1 -1
  56. package/src/submission/admission.ts +20 -30
  57. package/src/submission/contracts.ts +42 -2
  58. package/src/submission/delivery.ts +1 -1
  59. package/src/submission/finalization.ts +36 -15
  60. package/src/submission/lifecycle.ts +28 -15
  61. package/src/submission/repository.ts +97 -49
  62. package/src/submission/steer-delivery.ts +32 -76
  63. package/src/submission/unattended.ts +40 -0
  64. package/src/telemetry/contract.ts +0 -1
  65. package/src/telemetry/coordinator.ts +1 -1
  66. package/src/telemetry/runtime-telemetry.ts +0 -4
  67. package/src/telemetry/subagent-lifecycle.ts +1 -1
  68. package/src/telemetry/turn-events.ts +35 -25
  69. package/src/tools/README.md +44 -0
  70. package/src/tools/{ai-adapter.ts → adapters/ai-to-pi.ts} +6 -9
  71. package/src/tools/{declared.ts → adapters/declared.ts} +6 -2
  72. package/src/tools/{nested-tools.ts → adapters/pi-to-ai.ts} +4 -4
  73. package/src/tools/assistant/ask-user.ts +319 -0
  74. package/src/tools/assistant/candidate.ts +15 -0
  75. package/src/tools/assistant/followups.ts +34 -0
  76. package/src/tools/assistant/index.ts +19 -0
  77. package/src/tools/assistant/memory.ts +73 -0
  78. package/src/tools/assistant/plan.ts +98 -0
  79. package/src/tools/{time.ts → assistant/time.ts} +1 -1
  80. package/src/tools/{core-host.ts → codemode/adapter.ts} +50 -53
  81. package/src/tools/{core.ts → codemode/index.ts} +36 -92
  82. package/src/tools/codemode/workspace-connector.ts +198 -0
  83. package/src/tools/extension/index.ts +42 -0
  84. package/src/tools/index.ts +29 -26
  85. package/src/tools/{gateway.ts → mcp/gateway.ts} +19 -19
  86. package/src/tools/{mcp.ts → mcp/index.ts} +5 -5
  87. package/src/tools/runtime/activation.ts +40 -0
  88. package/src/tools/{approval → runtime/approval}/repository.ts +13 -12
  89. package/src/tools/runtime/compiler.ts +246 -0
  90. package/src/tools/runtime/contracts.ts +140 -0
  91. package/src/tools/{decision-gate.ts → runtime/decision-gate.ts} +149 -39
  92. package/src/tools/{human-decisions.ts → runtime/human-decisions.ts} +4 -4
  93. package/src/tools/{interaction → runtime/interaction}/repository.ts +1 -7
  94. package/src/tools/runtime/result.ts +22 -0
  95. package/src/tools/runtime/unattended-error.ts +4 -0
  96. package/src/tools/sandbox/index.ts +228 -0
  97. package/src/tools/schedule/index.ts +301 -0
  98. package/src/tools/skill/contracts.ts +20 -0
  99. package/src/tools/skill/index.ts +99 -0
  100. package/src/tools/skill/resources.ts +322 -0
  101. package/src/tools/skill/scripts.ts +168 -0
  102. package/src/tools/{subagent-authority.ts → subagent/authority.ts} +31 -31
  103. package/src/tools/{subagent.ts → subagent/index.ts} +34 -37
  104. package/src/tools/{subagent-run-repository.ts → subagent/repository.ts} +1 -1
  105. package/src/tools/{subagent-runtime.ts → subagent/runtime.ts} +1 -1
  106. package/src/tools/{temporary-agent → subagent/temporary}/approvals.ts +4 -7
  107. package/src/tools/{temporary-agent → subagent/temporary}/core.ts +2 -3
  108. package/src/tools/{temporary-agent → subagent/temporary}/runner.ts +1 -1
  109. package/src/tools/{temporary-agent → subagent/temporary}/workspace.ts +1 -4
  110. package/src/tools/{web-fetch.ts → web/fetch.ts} +4 -13
  111. package/src/tools/web/index.ts +2 -0
  112. package/src/tools/web/search/api.ts +1322 -0
  113. package/src/tools/web/search/index.ts +2 -0
  114. package/src/tools/{web-search/web-search.ts → web/search/search.ts} +5 -7
  115. package/src/tools/{workspace-sandbox.ts → workspace/index.ts} +12 -272
  116. package/src/tools/{workspace-revision.ts → workspace/revision.ts} +3 -3
  117. package/src/tools/base.ts +0 -534
  118. package/src/tools/compiler.ts +0 -327
  119. package/src/tools/schedule.ts +0 -261
  120. package/src/tools/skill.ts +0 -565
  121. package/src/tools/web-search/api.ts +0 -1318
  122. package/src/tools/web-search/index.ts +0 -2
  123. package/src/tools/workspace-state-connector.ts +0 -146
  124. package/src/tools/{approval → runtime/approval}/index.ts +0 -0
  125. package/src/tools/{interaction → runtime/interaction}/index.ts +0 -0
  126. package/src/tools/{temporary-agent → subagent/temporary}/coordinator.ts +0 -0
  127. package/src/tools/{subagent-types → subagent/types}/contract.ts +0 -0
  128. package/src/tools/{subagent-types → subagent/types}/extract/index.ts +0 -0
  129. package/src/tools/{subagent-types → subagent/types}/fanout/index.ts +0 -0
  130. package/src/tools/{subagent-types → subagent/types}/registry.ts +1 -1
  131. /package/src/tools/{workspace-versioning.ts → workspace/versioning.ts} +0 -0
@@ -1,2 +0,0 @@
1
- export * from "./api";
2
- export * from "./web-search";
@@ -1,146 +0,0 @@
1
- import { STATE_TYPES } from "@cloudflare/shell";
2
- import type { StateBackend } from "@cloudflare/shell/workers";
3
- import { StateConnector } from "@cloudflare/shell/workers";
4
- import type { ConnectorTools } from "@cloudflare/codemode";
5
- import type { WorkspacePort } from "../config/ports";
6
-
7
- export const WORKSPACE_DIRECT_TEXT_READ_MAX_BYTES = 1024 * 1024;
8
-
9
- const READ_FILE_PAGE_TYPES = `
10
- type WorkspaceFilePage =
11
- | { kind: "text"; size: number; nextOffset: number | null; content: string }
12
- | { kind: "csv"; size: number; nextOffset: number | null; columns: string[] | null; rows: string[][] };
13
- `;
14
-
15
- export const WORKSPACE_STATE_TYPES = `${READ_FILE_PAGE_TYPES}\n${STATE_TYPES.replace(
16
- /\n\};$/u,
17
- '\n /** CSV pages have columns and rows; never data. Omit offset first, then pass nextOffset until null. */\n readFilePage(args: { path: string; offset?: number }): Promise<WorkspaceFilePage | null>;\n};',
18
- )}`;
19
-
20
- export const WORKSPACE_PAGING_INSTRUCTIONS = `For CSV files, do not make a separate probe read or return page contents. Inspect columns and aggregate rows in the same execution with this loop shape:
21
-
22
- let page = await state.readFilePage({ path });
23
- if (!page || page.kind !== "csv") throw new Error("CSV not found");
24
- const columns = page.columns;
25
- for (;;) {
26
- // Aggregate page.rows here. Do not return raw rows.
27
- if (page.nextOffset === null) break;
28
- page = await state.readFilePage({ path, offset: page.nextOffset });
29
- }
30
- return summary;
31
-
32
- CSV pages use page.columns and page.rows; never page.data or page.content. Only the first page has columns. Do not use console.log to inspect a page; explicitly return the final summary.`;
33
-
34
- type PagedWorkspacePort = WorkspacePort & {
35
- readFilePage: NonNullable<WorkspacePort["readFilePage"]>;
36
- };
37
-
38
- export class WorkspaceStateConnector extends StateConnector {
39
- constructor(
40
- ctx: DurableObjectState | ExecutionContext,
41
- backend: StateBackend,
42
- private readonly workspace: PagedWorkspacePort,
43
- ) {
44
- super(ctx, backend);
45
- }
46
-
47
- protected override instructions(): string {
48
- const base = super.instructions();
49
- return `${base}
50
-
51
- ${WORKSPACE_PAGING_INSTRUCTIONS}`;
52
- }
53
-
54
- protected override tools(): ConnectorTools {
55
- const tools = super.tools();
56
- const readFile = tools.readFile!;
57
- return {
58
- ...tools,
59
- readFile: {
60
- ...readFile,
61
- description:
62
- `${readFile.description} CSV and files over ${WORKSPACE_DIRECT_TEXT_READ_MAX_BYTES} bytes must use readFilePage.`,
63
- execute: async (args, context) => {
64
- const path = requiredPath(args, "readFile");
65
- const file = await this.workspace.stat(path);
66
- if (file?.type === "file" && (
67
- file.mimeType === "text/csv" ||
68
- file.size > WORKSPACE_DIRECT_TEXT_READ_MAX_BYTES
69
- )) {
70
- throw new Error(
71
- `${path} requires state.readFilePage({ path: ${JSON.stringify(path)} }); continue with nextOffset until it is null`,
72
- );
73
- }
74
- return readFile.execute(args, context);
75
- },
76
- },
77
- readFilePage: {
78
- description:
79
- "Read up to 512 KiB or 2,000 CSV rows from a Workspace file. " +
80
- "A CSV page returns columns and rows and has no data field; rows are string arrays aligned to columns. " +
81
- "A text page returns content. Omit offset on the first call, then pass page.nextOffset until it is null. " +
82
- "Prefer this over readFile for CSV and large files.",
83
- inputSchema: {
84
- type: "object",
85
- properties: {
86
- path: { type: "string", minLength: 1, description: "Absolute Workspace file path." },
87
- offset: {
88
- type: "integer",
89
- minimum: 0,
90
- description: "Previous page.nextOffset. Omit on the first call.",
91
- },
92
- },
93
- required: ["path"],
94
- additionalProperties: false,
95
- },
96
- replay: "reexecute",
97
- execute: (args) => {
98
- const input = readFilePageInput(args);
99
- return this.workspace.readFilePage(input.path, input.offset);
100
- },
101
- },
102
- };
103
- }
104
-
105
- override async getTypeScriptTypes(): Promise<string> {
106
- return WORKSPACE_STATE_TYPES;
107
- }
108
- }
109
-
110
- function requiredPath(value: unknown, method: string): string {
111
- if (!value || typeof value !== "object" || Array.isArray(value) ||
112
- typeof (value as { path?: unknown }).path !== "string" ||
113
- !(value as { path: string }).path) {
114
- throw new Error(
115
- `state.${method} takes one object argument: state.${method}({ path: "/path/to/file" })`,
116
- );
117
- }
118
- return (value as { path: string }).path;
119
- }
120
-
121
- function readFilePageInput(value: unknown): {
122
- path: string;
123
- offset?: number;
124
- } {
125
- if (!value || typeof value !== "object" || Array.isArray(value)) {
126
- throw new Error("state.readFilePage requires an object argument");
127
- }
128
- const input = value as Record<string, unknown>;
129
- const keys = Object.keys(input);
130
- if (keys.some((key) => !["path", "offset"].includes(key))) {
131
- throw new Error("state.readFilePage accepts only path and offset");
132
- }
133
- if (typeof input.path !== "string" || input.path.length === 0) {
134
- throw new Error("state.readFilePage requires path");
135
- }
136
- const offset = input.offset;
137
- if (offset !== undefined && (!Number.isInteger(offset) || (offset as number) < 0)) {
138
- throw new Error(
139
- "state.readFilePage offset must be a previous page.nextOffset; omit it on the first call",
140
- );
141
- }
142
- return {
143
- path: input.path,
144
- ...(offset === undefined ? {} : { offset: offset as number }),
145
- };
146
- }
@@ -1,6 +1,6 @@
1
1
  import { foldAgentTypes } from "./contract";
2
- import { fanout } from "./fanout";
3
2
  import { extract } from "./extract";
3
+ import { fanout } from "./fanout";
4
4
 
5
5
  /**
6
6
  * 提供 Runtime 当前可用的子代理类型查找表。