@botbotgo/agent-harness 0.0.309 → 0.0.310

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 (195) hide show
  1. package/README.md +14 -0
  2. package/README.zh.md +14 -0
  3. package/dist/acp.d.ts +1 -116
  4. package/dist/acp.js +1 -310
  5. package/dist/api.d.ts +1 -1
  6. package/dist/api.js +1 -1
  7. package/dist/cli/chat-interactive.d.ts +24 -0
  8. package/dist/cli/chat-interactive.js +244 -0
  9. package/dist/cli/chat-rendering.d.ts +9 -0
  10. package/dist/cli/chat-rendering.js +102 -0
  11. package/dist/cli/chat-stream.d.ts +23 -0
  12. package/dist/cli/chat-stream.js +330 -0
  13. package/dist/cli/chat-ui.d.ts +20 -0
  14. package/dist/cli/chat-ui.js +198 -0
  15. package/dist/cli/chat-workspace.d.ts +15 -0
  16. package/dist/cli/chat-workspace.js +205 -0
  17. package/dist/cli/main.d.ts +52 -0
  18. package/dist/cli/main.js +323 -0
  19. package/dist/cli/managed-service-commands.d.ts +23 -0
  20. package/dist/cli/managed-service-commands.js +63 -0
  21. package/dist/cli/managed-service.d.ts +27 -0
  22. package/dist/cli/managed-service.js +61 -0
  23. package/dist/cli/options-init-chat.d.ts +16 -0
  24. package/dist/cli/options-init-chat.js +108 -0
  25. package/dist/cli/options-runtime.d.ts +27 -0
  26. package/dist/cli/options-runtime.js +158 -0
  27. package/dist/cli/options-serve.d.ts +24 -0
  28. package/dist/cli/options-serve.js +166 -0
  29. package/dist/cli/options.d.ts +5 -0
  30. package/dist/cli/options.js +47 -0
  31. package/dist/cli/process-guards.d.ts +14 -0
  32. package/dist/cli/process-guards.js +139 -0
  33. package/dist/cli/request-tree.d.ts +12 -0
  34. package/dist/cli/request-tree.js +296 -0
  35. package/dist/cli/runtime-commands.d.ts +15 -0
  36. package/dist/cli/runtime-commands.js +247 -0
  37. package/dist/cli/runtime-output.d.ts +5 -0
  38. package/dist/cli/runtime-output.js +124 -0
  39. package/dist/cli/server-commands.d.ts +36 -0
  40. package/dist/cli/server-commands.js +250 -0
  41. package/dist/cli/workspace.d.ts +6 -0
  42. package/dist/cli/workspace.js +71 -0
  43. package/dist/cli.d.ts +1 -78
  44. package/dist/cli.js +2 -3024
  45. package/dist/client/acp.d.ts +1 -50
  46. package/dist/client/acp.js +1 -219
  47. package/dist/client/in-process.d.ts +5 -5
  48. package/dist/client/index.d.ts +2 -2
  49. package/dist/client/index.js +1 -1
  50. package/dist/contracts/runtime-evaluation.d.ts +103 -0
  51. package/dist/contracts/runtime-evaluation.js +1 -0
  52. package/dist/contracts/runtime-memory.d.ts +162 -0
  53. package/dist/contracts/runtime-memory.js +1 -0
  54. package/dist/contracts/runtime-observability.d.ts +248 -0
  55. package/dist/contracts/runtime-observability.js +1 -0
  56. package/dist/contracts/runtime-requests.d.ts +342 -0
  57. package/dist/contracts/runtime-requests.js +1 -0
  58. package/dist/contracts/runtime-scheduling.d.ts +146 -0
  59. package/dist/contracts/runtime-scheduling.js +1 -0
  60. package/dist/contracts/runtime.d.ts +5 -1042
  61. package/dist/contracts/runtime.js +27 -1
  62. package/dist/flow/build-flow-graph.js +4 -875
  63. package/dist/flow/flow-graph-normalization.d.ts +56 -0
  64. package/dist/flow/flow-graph-normalization.js +214 -0
  65. package/dist/flow/flow-graph-runtime.d.ts +8 -0
  66. package/dist/flow/flow-graph-runtime.js +107 -0
  67. package/dist/flow/flow-graph-upstream.d.ts +18 -0
  68. package/dist/flow/flow-graph-upstream.js +498 -0
  69. package/dist/flow/types.d.ts +1 -1
  70. package/dist/index.d.ts +3 -3
  71. package/dist/index.js +1 -1
  72. package/dist/init-project.d.ts +1 -12
  73. package/dist/init-project.js +1 -651
  74. package/dist/{procedural → knowledge/procedural}/manager.d.ts +3 -3
  75. package/dist/{procedural → knowledge/procedural}/manager.js +6 -6
  76. package/dist/mcp.d.ts +2 -76
  77. package/dist/mcp.js +2 -428
  78. package/dist/package-version.d.ts +1 -1
  79. package/dist/package-version.js +1 -1
  80. package/dist/persistence/file-store.js +1 -1
  81. package/dist/persistence/sqlite-runtime.d.ts +19 -0
  82. package/dist/persistence/sqlite-runtime.js +86 -0
  83. package/dist/persistence/sqlite-store.js +11 -99
  84. package/dist/{request-events.d.ts → projections/request-events.d.ts} +1 -1
  85. package/dist/{upstream-events.js → projections/upstream-events.js} +1 -1
  86. package/dist/protocol/a2a/http-discovery.d.ts +39 -0
  87. package/dist/protocol/a2a/http-discovery.js +178 -0
  88. package/dist/protocol/a2a/http-rpc.d.ts +28 -0
  89. package/dist/protocol/a2a/http-rpc.js +623 -0
  90. package/dist/protocol/a2a/http.d.ts +72 -1
  91. package/dist/protocol/a2a/http.js +14 -1124
  92. package/dist/protocol/a2a/task-state.d.ts +29 -0
  93. package/dist/protocol/a2a/task-state.js +317 -0
  94. package/dist/protocol/acp/client.js +1 -1
  95. package/dist/protocol/acp/harness-client.d.ts +50 -0
  96. package/dist/protocol/acp/harness-client.js +219 -0
  97. package/dist/protocol/acp/server.d.ts +116 -0
  98. package/dist/protocol/acp/server.js +310 -0
  99. package/dist/protocol/ag-ui/http.js +1 -1
  100. package/dist/protocol/mcp/server.d.ts +76 -0
  101. package/dist/protocol/mcp/server.js +428 -0
  102. package/dist/resource/backend/workspace-scoped-backend.d.ts +40 -0
  103. package/dist/resource/backend/workspace-scoped-backend.js +296 -0
  104. package/dist/resource/mcp/tool-support.d.ts +35 -0
  105. package/dist/resource/mcp/tool-support.js +296 -0
  106. package/dist/resource/mcp-tool-support.d.ts +2 -35
  107. package/dist/resource/mcp-tool-support.js +2 -296
  108. package/dist/resource/providers/resource-provider.d.ts +22 -0
  109. package/dist/resource/providers/resource-provider.js +215 -0
  110. package/dist/resource/resource-impl.d.ts +3 -33
  111. package/dist/resource/resource-impl.js +2 -808
  112. package/dist/resource/resource-types.d.ts +33 -0
  113. package/dist/resource/resource-types.js +1 -0
  114. package/dist/resource/tools/function-tool-resolver.d.ts +2 -0
  115. package/dist/resource/tools/function-tool-resolver.js +306 -0
  116. package/dist/runtime/adapter/middleware-assembly.js +1 -1
  117. package/dist/runtime/adapter/model/invocation-request.js +2 -2
  118. package/dist/runtime/adapter/model/message-assembly.js +1 -1
  119. package/dist/runtime/agent-runtime-adapter.d.ts +3 -63
  120. package/dist/runtime/agent-runtime-adapter.js +5 -233
  121. package/dist/runtime/agent-runtime-assembly.d.ts +67 -0
  122. package/dist/runtime/agent-runtime-assembly.js +211 -0
  123. package/dist/runtime/harness/background-runtime.d.ts +1 -1
  124. package/dist/runtime/harness/events/event-sink.js +1 -1
  125. package/dist/runtime/harness/events/runtime-event-operations.d.ts +1 -1
  126. package/dist/runtime/harness/events/streaming.js +1 -1
  127. package/dist/runtime/harness/public-shapes.d.ts +43 -0
  128. package/dist/runtime/harness/public-shapes.js +186 -0
  129. package/dist/runtime/harness/run/inspection.js +2 -2
  130. package/dist/runtime/harness/run/resources.js +1 -1
  131. package/dist/runtime/harness/run/surface-semantics.js +1 -1
  132. package/dist/runtime/harness/system/inventory.d.ts +1 -1
  133. package/dist/runtime/harness/system/inventory.js +2 -2
  134. package/dist/runtime/harness/system/policy-engine.js +1 -1
  135. package/dist/runtime/harness/system/runtime-memory-manager.js +1 -1
  136. package/dist/runtime/harness/system/skill-requirements.d.ts +1 -1
  137. package/dist/runtime/harness/system/skill-requirements.js +1 -1
  138. package/dist/runtime/harness.d.ts +2 -2
  139. package/dist/runtime/harness.js +7 -191
  140. package/dist/runtime/maintenance/checkpoint-maintenance.js +1 -1
  141. package/dist/runtime/maintenance/runtime-record-maintenance.js +1 -1
  142. package/dist/runtime/parsing/output-content.d.ts +11 -0
  143. package/dist/runtime/parsing/output-content.js +442 -0
  144. package/dist/runtime/parsing/output-parsing.d.ts +3 -29
  145. package/dist/runtime/parsing/output-parsing.js +3 -806
  146. package/dist/runtime/parsing/output-recovery.d.ts +14 -0
  147. package/dist/runtime/parsing/output-recovery.js +288 -0
  148. package/dist/runtime/parsing/output-tool-args.d.ts +4 -0
  149. package/dist/runtime/parsing/output-tool-args.js +120 -0
  150. package/dist/runtime/support/runtime-factories.js +1 -1
  151. package/dist/scaffold/init-project.d.ts +12 -0
  152. package/dist/scaffold/init-project.js +651 -0
  153. package/dist/{extensions.d.ts → tooling/extensions.d.ts} +1 -1
  154. package/dist/{extensions.js → tooling/extensions.js} +3 -3
  155. package/dist/{tool-modules.d.ts → tooling/module-loader.d.ts} +1 -1
  156. package/dist/{tool-modules.js → tooling/module-loader.js} +2 -2
  157. package/dist/workspace/agent-binding-compiler.js +2 -2
  158. package/dist/workspace/compile.js +2 -2
  159. package/dist/workspace/object-loader-paths.d.ts +11 -0
  160. package/dist/workspace/object-loader-paths.js +75 -0
  161. package/dist/workspace/object-loader-readers.d.ts +21 -0
  162. package/dist/workspace/object-loader-readers.js +187 -0
  163. package/dist/workspace/object-loader.d.ts +0 -1
  164. package/dist/workspace/object-loader.js +6 -260
  165. package/dist/workspace/resource-compilers.js +1 -1
  166. package/dist/workspace/support/discovery.js +1 -1
  167. package/package.json +1 -1
  168. package/dist/runtime/adapter/index.d.ts +0 -13
  169. package/dist/runtime/adapter/index.js +0 -13
  170. package/dist/runtime/harness/index.d.ts +0 -19
  171. package/dist/runtime/harness/index.js +0 -19
  172. package/dist/runtime/maintenance/index.d.ts +0 -4
  173. package/dist/runtime/maintenance/index.js +0 -4
  174. package/dist/runtime/parsing/index.d.ts +0 -2
  175. package/dist/runtime/parsing/index.js +0 -2
  176. package/dist/runtime/support/index.d.ts +0 -4
  177. package/dist/runtime/support/index.js +0 -4
  178. package/dist/workspace/support/index.d.ts +0 -2
  179. package/dist/workspace/support/index.js +0 -2
  180. /package/dist/{procedural → knowledge/procedural}/config.d.ts +0 -0
  181. /package/dist/{procedural → knowledge/procedural}/config.js +0 -0
  182. /package/dist/{procedural → knowledge/procedural}/index.d.ts +0 -0
  183. /package/dist/{procedural → knowledge/procedural}/index.js +0 -0
  184. /package/dist/{presentation.d.ts → projections/presentation.d.ts} +0 -0
  185. /package/dist/{presentation.js → projections/presentation.js} +0 -0
  186. /package/dist/{request-events.js → projections/request-events.js} +0 -0
  187. /package/dist/{upstream-events.d.ts → projections/upstream-events.d.ts} +0 -0
  188. /package/dist/runtime/{support → env}/runtime-env.d.ts +0 -0
  189. /package/dist/runtime/{support → env}/runtime-env.js +0 -0
  190. /package/dist/runtime/{support → layout}/runtime-layout.d.ts +0 -0
  191. /package/dist/runtime/{support → layout}/runtime-layout.js +0 -0
  192. /package/dist/runtime/{support → prompts}/runtime-prompts.d.ts +0 -0
  193. /package/dist/runtime/{support → prompts}/runtime-prompts.js +0 -0
  194. /package/dist/runtime/{support → skills}/skill-metadata.d.ts +0 -0
  195. /package/dist/runtime/{support → skills}/skill-metadata.js +0 -0
@@ -0,0 +1,33 @@
1
+ import type { RuntimeAdapterOptions, WorkspaceBundle } from "../contracts/types.js";
2
+ export type ResourceToolInfo = {
3
+ toolPath: string;
4
+ backendOperation: string;
5
+ name: string;
6
+ description: string;
7
+ retryable?: boolean;
8
+ hitl?: {
9
+ enabled: boolean;
10
+ allow: Array<"approve" | "edit" | "reject">;
11
+ };
12
+ };
13
+ export type ResourceProvider = {
14
+ listResourceTools?: () => ResourceToolInfo[];
15
+ listBuiltinTools?: () => ResourceToolInfo[];
16
+ createResourceToolResolver?: (workspace: WorkspaceBundle, options?: {
17
+ getStore?: (_binding?: WorkspaceBundle["bindings"] extends Map<any, infer T> ? T : never) => unknown;
18
+ getEmbeddingModel?: (embeddingModelRef?: string, _binding?: WorkspaceBundle["bindings"] extends Map<any, infer T> ? T : never) => Promise<unknown>;
19
+ getVectorStore?: (vectorStoreRef?: string, _binding?: WorkspaceBundle["bindings"] extends Map<any, infer T> ? T : never) => Promise<unknown>;
20
+ }) => NonNullable<RuntimeAdapterOptions["toolResolver"]>;
21
+ createBuiltinToolResolver?: (workspace: WorkspaceBundle, options?: {
22
+ getStore?: (_binding?: WorkspaceBundle["bindings"] extends Map<any, infer T> ? T : never) => unknown;
23
+ getEmbeddingModel?: (embeddingModelRef?: string, _binding?: WorkspaceBundle["bindings"] extends Map<any, infer T> ? T : never) => Promise<unknown>;
24
+ getVectorStore?: (vectorStoreRef?: string, _binding?: WorkspaceBundle["bindings"] extends Map<any, infer T> ? T : never) => Promise<unknown>;
25
+ }) => NonNullable<RuntimeAdapterOptions["toolResolver"]>;
26
+ createResourceBackendResolver?: (workspace: WorkspaceBundle) => NonNullable<RuntimeAdapterOptions["backendResolver"]>;
27
+ createBuiltinBackendResolver?: (workspace: WorkspaceBundle) => NonNullable<RuntimeAdapterOptions["backendResolver"]>;
28
+ defaultResourceSkillsRoot?: () => string;
29
+ builtinSkillsRoot?: () => string;
30
+ defaultResourceConfigRoot?: () => string;
31
+ builtinConfigRoot?: () => string;
32
+ builtinDefaultsRoot?: () => string;
33
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { RuntimeAdapterOptions, WorkspaceBundle } from "../../contracts/types.js";
2
+ export declare function createFunctionToolResolver(workspace: WorkspaceBundle): NonNullable<RuntimeAdapterOptions["toolResolver"]>;
@@ -0,0 +1,306 @@
1
+ import { spawn } from "node:child_process";
2
+ import path from "node:path";
3
+ import { stat } from "node:fs/promises";
4
+ import { pathToFileURL } from "node:url";
5
+ import { UPSTREAM_REQUEST_CONFIG_KEY, UPSTREAM_SESSION_CONFIG_KEY } from "../../runtime/adapter/upstream-configurable-keys.js";
6
+ import { getBindingExecutionView, getBindingPrimaryModel } from "../../runtime/support/compiled-binding.js";
7
+ import { resolveCompiledEmbeddingModelRef } from "../../runtime/support/embedding-models.js";
8
+ import { createRuntimeEnv } from "../../runtime/env/runtime-env.js";
9
+ import { isSupportedToolModulePath, loadToolModuleDefinition } from "../../tooling/module-loader.js";
10
+ import { resolveIsolatedResourceModulePath } from "../isolation.js";
11
+ import { resolveResourcePackageRoot } from "../sources.js";
12
+ function findEnclosingResourcePackageRoot(startPath) {
13
+ let current = path.dirname(startPath);
14
+ for (;;) {
15
+ const resourcePackageRoot = resolveResourcePackageRoot(current);
16
+ if (resourcePackageRoot && isPathWithinRoot(startPath, resourcePackageRoot)) {
17
+ return resourcePackageRoot;
18
+ }
19
+ const parent = path.dirname(current);
20
+ if (parent === current) {
21
+ return null;
22
+ }
23
+ current = parent;
24
+ }
25
+ }
26
+ function isPathWithinRoot(targetPath, rootPath) {
27
+ const relative = path.relative(rootPath, targetPath);
28
+ return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
29
+ }
30
+ async function findPackageRoot(startPath) {
31
+ const resourcePackageRoot = findEnclosingResourcePackageRoot(startPath);
32
+ if (resourcePackageRoot) {
33
+ return resourcePackageRoot;
34
+ }
35
+ let current = path.dirname(startPath);
36
+ for (;;) {
37
+ try {
38
+ await stat(path.join(current, "package.json"));
39
+ return current;
40
+ }
41
+ catch { }
42
+ const parent = path.dirname(current);
43
+ if (parent === current) {
44
+ return path.dirname(startPath);
45
+ }
46
+ current = parent;
47
+ }
48
+ }
49
+ function asObject(value) {
50
+ return typeof value === "object" && value !== null ? value : undefined;
51
+ }
52
+ function asStringRecord(value) {
53
+ const record = asObject(value);
54
+ if (!record) {
55
+ return undefined;
56
+ }
57
+ return Object.fromEntries(Object.entries(record).filter((entry) => typeof entry[1] === "string"));
58
+ }
59
+ function asStringArray(value) {
60
+ return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
61
+ }
62
+ const FUNCTION_TOOL_SUBPROCESS_RUNNER_SOURCE = `
63
+ import { pathToFileURL } from "node:url";
64
+
65
+ const TOOL_DEFINITION_MARKER = "__agent_harness_tool_definition__";
66
+
67
+ function isToolDefinitionObject(value) {
68
+ return typeof value === "object" && value !== null && value[TOOL_DEFINITION_MARKER] === true;
69
+ }
70
+
71
+ function loadToolDefinition(imported, implementationName) {
72
+ for (const [exportName, value] of Object.entries(imported)) {
73
+ if (exportName === "default" || !isToolDefinitionObject(value)) {
74
+ continue;
75
+ }
76
+ const resolvedName = typeof value.name === "string" && value.name.trim() ? value.name.trim() : exportName;
77
+ if (resolvedName === implementationName) {
78
+ return value;
79
+ }
80
+ }
81
+ throw new Error(\`Tool module must export a tool({...}) definition named \${implementationName}.\`);
82
+ }
83
+
84
+ const [modulePath, implementationName] = process.argv.slice(1);
85
+ const imported = await import(pathToFileURL(modulePath).href);
86
+ const tool = loadToolDefinition(imported, implementationName);
87
+ let stdin = "";
88
+ for await (const chunk of process.stdin) {
89
+ stdin += String(chunk);
90
+ }
91
+ const payload = stdin.trim() ? JSON.parse(stdin) : {};
92
+ const input = tool.schema && typeof tool.schema.parse === "function"
93
+ ? tool.schema.parse(payload.input ?? {})
94
+ : (payload.input ?? {});
95
+ const result = await tool.invoke(input, payload.context ?? {});
96
+ process.stdout.write(typeof result === "string" ? result : JSON.stringify(result));
97
+ `;
98
+ function resolveFunctionToolSubprocessConfig(tool, workspaceRoot, isolatedSourcePath) {
99
+ const execution = asObject(tool.config?.execution);
100
+ if (tool.subprocess !== true) {
101
+ return null;
102
+ }
103
+ const resolvedExecution = execution ?? {};
104
+ const entry = typeof resolvedExecution.entry === "string" && resolvedExecution.entry.trim()
105
+ ? path.resolve(workspaceRoot, resolvedExecution.entry)
106
+ : undefined;
107
+ const command = typeof resolvedExecution.command === "string" && resolvedExecution.command.trim()
108
+ ? resolvedExecution.command
109
+ : entry
110
+ ? process.execPath
111
+ : process.execPath;
112
+ if (!command) {
113
+ throw new Error(`Tool ${tool.id} subprocess execution requires config.execution.command or config.execution.entry`);
114
+ }
115
+ const args = [
116
+ ...(entry ? [entry] : ["--input-type=module", "--eval", FUNCTION_TOOL_SUBPROCESS_RUNNER_SOURCE, isolatedSourcePath, tool.implementationName ?? tool.id]),
117
+ ...asStringArray(resolvedExecution.args),
118
+ ];
119
+ const cwd = typeof resolvedExecution.cwd === "string" && resolvedExecution.cwd.trim()
120
+ ? path.resolve(workspaceRoot, resolvedExecution.cwd)
121
+ : workspaceRoot;
122
+ const timeoutMs = Number.isFinite(resolvedExecution.timeoutMs) ? Number(resolvedExecution.timeoutMs) : undefined;
123
+ return {
124
+ command,
125
+ args,
126
+ cwd,
127
+ env: asStringRecord(resolvedExecution.env),
128
+ timeoutMs,
129
+ };
130
+ }
131
+ async function runFunctionToolInSubprocess(config, input, context) {
132
+ return await new Promise((resolve, reject) => {
133
+ const child = spawn(config.command, config.args, {
134
+ cwd: config.cwd,
135
+ env: createRuntimeEnv(config.env, process.env),
136
+ stdio: ["pipe", "pipe", "pipe"],
137
+ });
138
+ let stdout = "";
139
+ let stderr = "";
140
+ let settled = false;
141
+ let timeout;
142
+ const finish = (fn) => {
143
+ if (settled) {
144
+ return;
145
+ }
146
+ settled = true;
147
+ if (timeout) {
148
+ clearTimeout(timeout);
149
+ }
150
+ fn();
151
+ };
152
+ if (config.timeoutMs && config.timeoutMs > 0) {
153
+ timeout = setTimeout(() => {
154
+ child.kill("SIGTERM");
155
+ finish(() => reject(new Error(`Subprocess tool timed out after ${config.timeoutMs}ms`)));
156
+ }, config.timeoutMs);
157
+ }
158
+ child.stdout.setEncoding("utf8");
159
+ child.stderr.setEncoding("utf8");
160
+ child.stdout.on("data", (chunk) => {
161
+ stdout += chunk;
162
+ });
163
+ child.stderr.on("data", (chunk) => {
164
+ stderr += chunk;
165
+ });
166
+ child.on("error", (error) => {
167
+ finish(() => reject(error));
168
+ });
169
+ child.on("close", (code, signal) => {
170
+ finish(() => {
171
+ if (code === 0) {
172
+ resolve(stdout.trim());
173
+ return;
174
+ }
175
+ const message = stderr.trim() || stdout.trim() || `Subprocess tool exited with code ${code ?? "unknown"}${signal ? ` (${signal})` : ""}`;
176
+ reject(new Error(message));
177
+ });
178
+ });
179
+ child.stdin.end(JSON.stringify({ input, context }));
180
+ });
181
+ }
182
+ const functionToolModuleCache = new Map();
183
+ async function loadFunctionToolModule(tool) {
184
+ const cacheKey = `${tool.sourcePath}:${tool.implementationName ?? tool.id}`;
185
+ const cached = functionToolModuleCache.get(cacheKey);
186
+ if (cached) {
187
+ return cached;
188
+ }
189
+ const loading = (async () => {
190
+ const packageRoot = await findPackageRoot(tool.sourcePath);
191
+ const isolatedSourcePath = await resolveIsolatedResourceModulePath(packageRoot, tool.sourcePath);
192
+ const imported = await import(pathToFileURL(isolatedSourcePath).href);
193
+ const implementationName = tool.implementationName ?? tool.id;
194
+ const loaded = loadToolModuleDefinition(imported, implementationName);
195
+ return {
196
+ invoke: loaded.invoke,
197
+ schema: loaded.schema,
198
+ modelSchema: loaded.modelSchema,
199
+ description: loaded.description,
200
+ isolatedSourcePath,
201
+ implementationName,
202
+ };
203
+ })();
204
+ functionToolModuleCache.set(cacheKey, loading);
205
+ return loading;
206
+ }
207
+ export function createFunctionToolResolver(workspace) {
208
+ const functionTools = new Map(Array.from(workspace.tools.values())
209
+ .filter((tool) => tool.type === "function" && isSupportedToolModulePath(tool.sourcePath))
210
+ .map((tool) => [tool.id, tool]));
211
+ return (toolIds, binding) => toolIds.flatMap((toolId) => {
212
+ const tool = functionTools.get(toolId);
213
+ if (!tool) {
214
+ return [];
215
+ }
216
+ return [
217
+ {
218
+ name: tool.name,
219
+ description: tool.description,
220
+ schema: tool.modelSchema,
221
+ modelSchema: tool.modelSchema,
222
+ async invoke(input, config) {
223
+ const loaded = await loadFunctionToolModule(tool);
224
+ const parsedInput = loaded.schema.parse(input ?? {});
225
+ const toolPackageRoot = await findPackageRoot(tool.sourcePath);
226
+ const bindingTool = binding
227
+ ? getBindingExecutionView(binding).primaryTools.find((candidate) => candidate.id === tool.id || candidate.name === tool.name)
228
+ : undefined;
229
+ const effectiveEmbeddingModelRef = bindingTool?.embeddingModelRef ?? tool.embeddingModelRef;
230
+ const effectiveSubprocess = bindingTool?.subprocess ?? tool.subprocess;
231
+ const effectiveConfig = bindingTool?.config ?? tool.config;
232
+ const effectiveHitl = bindingTool?.hitl ?? tool.hitl;
233
+ const effectiveRetryable = bindingTool?.retryable ?? tool.retryable;
234
+ const embeddingModel = effectiveEmbeddingModelRef
235
+ ? resolveCompiledEmbeddingModelRef(workspace, effectiveEmbeddingModelRef)
236
+ : undefined;
237
+ const model = binding ? getBindingPrimaryModel(binding) : undefined;
238
+ const configurable = typeof config?.configurable === "object" && config.configurable !== null
239
+ ? config.configurable
240
+ : {};
241
+ const dynamicToolRuntimeContext = typeof config?.toolRuntimeContext === "object" && config.toolRuntimeContext !== null
242
+ ? config.toolRuntimeContext
243
+ : {};
244
+ const baseToolContext = {
245
+ appRoot: workspace.workspaceRoot,
246
+ toolId: tool.id,
247
+ toolPath: tool.sourcePath,
248
+ toolPackageRoot,
249
+ embeddingModel,
250
+ model,
251
+ runtime: {
252
+ workspaceRoot: workspace.workspaceRoot,
253
+ runtimeRoot: binding?.harnessRuntime.runtimeRoot,
254
+ ...(typeof configurable[UPSTREAM_SESSION_CONFIG_KEY] === "string"
255
+ ? { sessionId: configurable[UPSTREAM_SESSION_CONFIG_KEY] }
256
+ : {}),
257
+ ...(typeof configurable[UPSTREAM_REQUEST_CONFIG_KEY] === "string"
258
+ ? { requestId: configurable[UPSTREAM_REQUEST_CONFIG_KEY] }
259
+ : {}),
260
+ },
261
+ agent: binding
262
+ ? {
263
+ id: binding.agent.id,
264
+ executionMode: binding.agent.executionMode,
265
+ description: binding.agent.description,
266
+ sourcePath: binding.agent.sourcePath,
267
+ }
268
+ : undefined,
269
+ tool: {
270
+ id: tool.id,
271
+ name: tool.name,
272
+ type: tool.type,
273
+ description: tool.description,
274
+ sourcePath: tool.sourcePath,
275
+ packageRoot: toolPackageRoot,
276
+ config: effectiveConfig,
277
+ embeddingModelRef: effectiveEmbeddingModelRef,
278
+ inputSchemaRef: tool.inputSchemaRef,
279
+ retryable: effectiveRetryable,
280
+ hitl: effectiveHitl,
281
+ },
282
+ };
283
+ const subprocessConfig = resolveFunctionToolSubprocessConfig({
284
+ ...tool,
285
+ config: effectiveConfig,
286
+ embeddingModelRef: effectiveEmbeddingModelRef,
287
+ hitl: effectiveHitl,
288
+ retryable: effectiveRetryable,
289
+ subprocess: effectiveSubprocess,
290
+ }, workspace.workspaceRoot, loaded.isolatedSourcePath);
291
+ if (subprocessConfig) {
292
+ return runFunctionToolInSubprocess(subprocessConfig, parsedInput, baseToolContext);
293
+ }
294
+ return loaded.invoke(parsedInput, {
295
+ ...baseToolContext,
296
+ ...dynamicToolRuntimeContext,
297
+ runtime: {
298
+ ...(typeof baseToolContext.runtime === "object" && baseToolContext.runtime ? baseToolContext.runtime : {}),
299
+ ...(typeof dynamicToolRuntimeContext.runtime === "object" && dynamicToolRuntimeContext.runtime ? dynamicToolRuntimeContext.runtime : {}),
300
+ },
301
+ });
302
+ },
303
+ },
304
+ ];
305
+ });
306
+ }
@@ -9,7 +9,7 @@ import { resolveDeclaredMiddleware } from "./tool/declared-middleware.js";
9
9
  import { UPSTREAM_SESSION_CONFIG_KEY } from "./upstream-configurable-keys.js";
10
10
  import { bindingHasLangChainSubagentSupport, bindingHasMiddlewareKind, getBindingExecutionKind, getBindingGeneralPurposeAgent, getBindingInterruptCompatibilityRules, getBindingMiddlewareConfigs, getBindingMemorySources, getBindingPrimaryModel, getBindingPrimaryTools, getBindingSkills, getBindingSubagents, getBindingTaskDescription, isDeepAgentBinding, isLangChainBinding, } from "../support/compiled-binding.js";
11
11
  import { applyDeepAgentDelegationPromptCompatibility, materializeDeepAgentSkillSourcePaths } from "./compat/deepagent-compat.js";
12
- import { DEFAULT_SUBAGENT_PROMPT } from "../support/runtime-prompts.js";
12
+ import { DEFAULT_SUBAGENT_PROMPT } from "../prompts/runtime-prompts.js";
13
13
  export function buildBuiltinTaskSubagentMiddleware(input) {
14
14
  const { selectedSubagent, builtinBackend, summarizationModel } = input;
15
15
  const defaultSubagentMiddleware = [
@@ -1,8 +1,8 @@
1
1
  import { getBindingSkills } from "../../support/compiled-binding.js";
2
2
  import { extractMessageText, normalizeMessageContent } from "../../../utils/message-content.js";
3
- import { readSkillMetadata } from "../../support/skill-metadata.js";
3
+ import { readSkillMetadata } from "../../skills/skill-metadata.js";
4
4
  import { summarizeAssistantText } from "../direct-builtin-utility.js";
5
- import { renderDurableMemoryContextPrompt, renderSlashCommandSkillInstruction } from "../../support/runtime-prompts.js";
5
+ import { renderDurableMemoryContextPrompt, renderSlashCommandSkillInstruction } from "../../prompts/runtime-prompts.js";
6
6
  import { hasExplicitResourceReference, } from "../../harness/system/runtime-memory-policy.js";
7
7
  const MAX_HISTORY_ASSISTANT_CHARS = 1600;
8
8
  const MAX_HISTORY_ASSISTANT_LINES = 40;
@@ -1,5 +1,5 @@
1
1
  import { buildAgentMessages, buildSlashCommandSkillInstruction } from "./invocation-request.js";
2
- import { renderDurableMemoryContextPrompt } from "../../support/runtime-prompts.js";
2
+ import { renderDurableMemoryContextPrompt } from "../../prompts/runtime-prompts.js";
3
3
  export function buildStateSnapshot(result) {
4
4
  const snapshot = { ...result };
5
5
  delete snapshot.messages;
@@ -1,8 +1,7 @@
1
- import type { CompiledAgentBinding, CompiledAsyncSubAgent, MessageContent, RequestResult, RuntimeAdapterOptions, TranscriptMessage } from "../contracts/types.js";
1
+ import type { CompiledAgentBinding, MessageContent, RequestResult, RuntimeAdapterOptions, TranscriptMessage } from "../contracts/types.js";
2
2
  import { type RuntimeStreamChunk } from "./parsing/stream-event-parsing.js";
3
- import type { ExecutableTool } from "./adapter/flow/invoke-runtime.js";
3
+ import { AGENT_INTERRUPT_SENTINEL_PREFIX, buildDeepAgentCreateParams, buildLangChainCreateParams, buildMinimalDeepAgentCreateParams, materializeModelExposedBuiltinMiddlewareTools, resolveLangChainInvocationConfig, resolveRunnableCheckpointer, resolveRunnableInterruptOn, shouldUseMinimalDeepAgentAssembly } from "./agent-runtime-assembly.js";
4
4
  import { RuntimeOperationTimeoutError } from "./adapter/runtime-shell.js";
5
- import { type UpstreamSubagentConfig } from "./adapter/middleware-assembly.js";
6
5
  export { applyDeepAgentDelegationPromptCompatibility, materializeDeepAgentSkillSourcePaths, resolveDeepAgentSkillSourcePaths, relativizeDeepAgentSkillSourcePaths, shouldRelaxDeepAgentDelegationPrompt, } from "./adapter/compat/deepagent-compat.js";
7
6
  export { buildAuthOmittingFetch, normalizeOpenAICompatibleInit } from "./adapter/compat/openai-compatible.js";
8
7
  export { buildToolNameMapping, createModelFacingToolNameCandidates, createModelFacingToolNameLookupCandidates, resolveModelFacingToolName, sanitizeToolNameForModel, } from "./adapter/tool/tool-name-mapping.js";
@@ -12,65 +11,6 @@ type RunnableLike = {
12
11
  stream?: (input: unknown, config?: Record<string, unknown>) => Promise<AsyncIterable<unknown>>;
13
12
  streamEvents?: (input: unknown, config?: Record<string, unknown>) => Promise<AsyncIterable<unknown>>;
14
13
  };
15
- declare const AGENT_INTERRUPT_SENTINEL_PREFIX = "__agent_harness_interrupt__:";
16
- export declare function materializeModelExposedBuiltinMiddlewareTools(input: {
17
- builtinTools: Map<string, ExecutableTool>;
18
- explicitToolNames?: string[];
19
- }): unknown[];
20
- export declare function resolveRunnableCheckpointer(options: RuntimeAdapterOptions, binding: CompiledAgentBinding): unknown;
21
- export declare function resolveRunnableInterruptOn(binding: CompiledAgentBinding): Record<string, {
22
- allowedDecisions: import("./adapter/tool/interrupt-policy.js").InterruptDecision[];
23
- }> | undefined;
24
- export declare function buildLangChainCreateParams(input: {
25
- binding: CompiledAgentBinding;
26
- resolvedModel: unknown;
27
- resolvedTools: unknown[];
28
- resolvedMiddleware: unknown[];
29
- resolvedCheckpointer: unknown;
30
- resolvedStore: unknown;
31
- passthroughOverride?: Record<string, unknown>;
32
- systemPromptOverride?: string;
33
- }): Record<string, unknown>;
34
- export declare function resolveLangChainInvocationConfig(binding: CompiledAgentBinding, options: {
35
- sessionId: string;
36
- requestId: string;
37
- legacySessionId?: string;
38
- legacyRequestId?: string;
39
- context?: Record<string, unknown>;
40
- toolRuntimeContext?: Record<string, unknown>;
41
- }): Record<string, unknown>;
42
- export declare function buildDeepAgentCreateParams(input: {
43
- binding: CompiledAgentBinding;
44
- resolvedModel: unknown;
45
- resolvedTools: unknown[];
46
- resolvedMiddleware: unknown[];
47
- resolvedSubagents: Array<UpstreamSubagentConfig | CompiledAsyncSubAgent>;
48
- resolvedCheckpointer?: unknown;
49
- resolvedStore?: unknown;
50
- resolvedBackend?: unknown;
51
- resolvedInterruptOn?: Record<string, {
52
- allowedDecisions: Array<"approve" | "edit" | "reject">;
53
- }>;
54
- resolvedSkills: string[];
55
- }): Record<string, unknown>;
56
- export declare function shouldUseMinimalDeepAgentAssembly(input: {
57
- binding: CompiledAgentBinding;
58
- resolvedMiddleware: unknown[];
59
- resolvedSubagents: Array<UpstreamSubagentConfig | CompiledAsyncSubAgent>;
60
- resolvedInterruptOn?: Record<string, {
61
- allowedDecisions: Array<"approve" | "edit" | "reject">;
62
- }>;
63
- resolvedSkills: string[];
64
- resolvedBackend?: unknown;
65
- }): boolean;
66
- export declare function buildMinimalDeepAgentCreateParams(input: {
67
- binding: CompiledAgentBinding;
68
- resolvedModel: unknown;
69
- resolvedTools: unknown[];
70
- resolvedCheckpointer?: unknown;
71
- resolvedStore?: unknown;
72
- resolvedBackend: unknown;
73
- }): Record<string, unknown>;
74
14
  export declare class AgentRuntimeAdapter {
75
15
  private readonly options;
76
16
  private readonly modelCache;
@@ -125,4 +65,4 @@ export declare class AgentRuntimeAdapter {
125
65
  toolRuntimeContext?: Record<string, unknown>;
126
66
  }): AsyncGenerator<RuntimeStreamChunk | string>;
127
67
  }
128
- export { AgentRuntimeAdapter as RuntimeAdapter, AGENT_INTERRUPT_SENTINEL_PREFIX, AGENT_INTERRUPT_SENTINEL_PREFIX as INTERRUPT_SENTINEL_PREFIX, RuntimeOperationTimeoutError, };
68
+ export { AgentRuntimeAdapter as RuntimeAdapter, AGENT_INTERRUPT_SENTINEL_PREFIX, AGENT_INTERRUPT_SENTINEL_PREFIX as INTERRUPT_SENTINEL_PREFIX, buildDeepAgentCreateParams, buildLangChainCreateParams, buildMinimalDeepAgentCreateParams, materializeModelExposedBuiltinMiddlewareTools, resolveLangChainInvocationConfig, resolveRunnableCheckpointer, resolveRunnableInterruptOn, shouldUseMinimalDeepAgentAssembly, RuntimeOperationTimeoutError, };