@springbrand/agent-runtime 0.3.0-alpha.8 → 0.3.0-alpha.9

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 (87) hide show
  1. package/package.json +2 -2
  2. package/src/adapter/cloudflare/subagent/definition.ts +4 -4
  3. package/src/adapter/cloudflare/subagent/runner.ts +1 -1
  4. package/src/adapter/cloudflare/subagent/tools.ts +2 -2
  5. package/src/adapter/cloudflare/universal-agent/preparation.ts +3 -3
  6. package/src/adapter/cloudflare/universal-agent/tools.ts +4 -6
  7. package/src/adapter/cloudflare/workspace/version-control.ts +1 -1
  8. package/src/config/agent-context.ts +1 -1
  9. package/src/config/assembler.ts +17 -31
  10. package/src/config/assembly-snapshot.ts +1 -1
  11. package/src/config/definition.ts +1 -1
  12. package/src/config/model-guidance.ts +1 -1
  13. package/src/config/ports.ts +3 -3
  14. package/src/config/public-contracts.ts +2 -2
  15. package/src/context/extension/assembly.ts +2 -2
  16. package/src/context/memory/budget/gate.ts +1 -1
  17. package/src/conversation/state.ts +1 -1
  18. package/src/index.ts +7 -7
  19. package/src/lib/prompt.ts +3 -5
  20. package/src/models/index.ts +1 -0
  21. package/src/session/cloudflare/migration.ts +29 -8
  22. package/src/skills/springbrand-worker-website/index.ts +1 -1
  23. package/src/submission/delivery.ts +1 -1
  24. package/src/submission/finalization.ts +1 -1
  25. package/src/telemetry/coordinator.ts +1 -1
  26. package/src/telemetry/subagent-lifecycle.ts +1 -1
  27. package/src/telemetry/turn-events.ts +1 -1
  28. package/src/tools/README.md +44 -0
  29. package/src/tools/{ai-adapter.ts → adapters/ai-to-pi.ts} +6 -9
  30. package/src/tools/{declared.ts → adapters/declared.ts} +2 -2
  31. package/src/tools/{nested-tools.ts → adapters/pi-to-ai.ts} +2 -2
  32. package/src/tools/assistant/ask-user.ts +317 -0
  33. package/src/tools/assistant/candidate.ts +15 -0
  34. package/src/tools/assistant/followups.ts +34 -0
  35. package/src/tools/assistant/index.ts +19 -0
  36. package/src/tools/assistant/memory.ts +73 -0
  37. package/src/tools/assistant/plan.ts +98 -0
  38. package/src/tools/{time.ts → assistant/time.ts} +1 -1
  39. package/src/tools/{core-host.ts → codemode/adapter.ts} +50 -49
  40. package/src/tools/{core.ts → codemode/index.ts} +36 -92
  41. package/src/tools/codemode/workspace-connector.ts +198 -0
  42. package/src/tools/extension/index.ts +42 -0
  43. package/src/tools/index.ts +28 -26
  44. package/src/tools/{gateway.ts → mcp/gateway.ts} +19 -19
  45. package/src/tools/{mcp.ts → mcp/index.ts} +5 -5
  46. package/src/tools/{approval → runtime/approval}/repository.ts +3 -9
  47. package/src/tools/{compiler.ts → runtime/compiler.ts} +24 -157
  48. package/src/tools/runtime/contracts.ts +117 -0
  49. package/src/tools/{decision-gate.ts → runtime/decision-gate.ts} +6 -9
  50. package/src/tools/{human-decisions.ts → runtime/human-decisions.ts} +4 -4
  51. package/src/tools/{interaction → runtime/interaction}/repository.ts +1 -7
  52. package/src/tools/runtime/result.ts +22 -0
  53. package/src/tools/sandbox/index.ts +228 -0
  54. package/src/tools/{schedule.ts → schedule/index.ts} +50 -49
  55. package/src/tools/skill/contracts.ts +20 -0
  56. package/src/tools/skill/index.ts +99 -0
  57. package/src/tools/skill/resources.ts +322 -0
  58. package/src/tools/skill/scripts.ts +168 -0
  59. package/src/tools/{subagent-authority.ts → subagent/authority.ts} +31 -31
  60. package/src/tools/{subagent.ts → subagent/index.ts} +34 -37
  61. package/src/tools/{subagent-run-repository.ts → subagent/repository.ts} +1 -1
  62. package/src/tools/{subagent-runtime.ts → subagent/runtime.ts} +1 -1
  63. package/src/tools/{temporary-agent → subagent/temporary}/approvals.ts +4 -7
  64. package/src/tools/{temporary-agent → subagent/temporary}/core.ts +1 -1
  65. package/src/tools/{temporary-agent → subagent/temporary}/runner.ts +1 -1
  66. package/src/tools/{temporary-agent → subagent/temporary}/workspace.ts +1 -4
  67. package/src/tools/{web-fetch.ts → web/fetch.ts} +4 -13
  68. package/src/tools/web/index.ts +2 -0
  69. package/src/tools/web/search/api.ts +1320 -0
  70. package/src/tools/web/search/index.ts +2 -0
  71. package/src/tools/{web-search/web-search.ts → web/search/search.ts} +5 -7
  72. package/src/tools/{workspace-sandbox.ts → workspace/index.ts} +12 -272
  73. package/src/tools/{workspace-revision.ts → workspace/revision.ts} +3 -3
  74. package/src/tools/base.ts +0 -542
  75. package/src/tools/skill.ts +0 -565
  76. package/src/tools/web-search/api.ts +0 -1318
  77. package/src/tools/web-search/index.ts +0 -2
  78. package/src/tools/workspace-state-connector.ts +0 -146
  79. package/src/tools/{approval → runtime/approval}/index.ts +0 -0
  80. package/src/tools/{interaction → runtime/interaction}/index.ts +0 -0
  81. package/src/tools/{unattended-error.ts → runtime/unattended-error.ts} +0 -0
  82. package/src/tools/{temporary-agent → subagent/temporary}/coordinator.ts +0 -0
  83. package/src/tools/{subagent-types → subagent/types}/contract.ts +0 -0
  84. package/src/tools/{subagent-types → subagent/types}/extract/index.ts +0 -0
  85. package/src/tools/{subagent-types → subagent/types}/fanout/index.ts +0 -0
  86. package/src/tools/{subagent-types → subagent/types}/registry.ts +1 -1
  87. /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 当前可用的子代理类型查找表。