stitchkit 0.67.0 → 0.68.1

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 (226) hide show
  1. package/dist/agent-runtime/admission-lanes.d.ts +1 -1
  2. package/dist/agent-runtime/compaction.d.ts +2 -2
  3. package/dist/agent-runtime/events.d.ts +1 -1
  4. package/dist/agent-runtime/history.d.ts +1 -1
  5. package/dist/agent-runtime/history.d.ts.map +1 -1
  6. package/dist/agent-runtime/injection.d.ts +1 -1
  7. package/dist/agent-runtime/managed-tools.d.ts +3 -3
  8. package/dist/agent-runtime/models.d.ts +1 -1
  9. package/dist/agent-runtime/observability.d.ts +1 -1
  10. package/dist/agent-runtime/prompt.d.ts +1 -1
  11. package/dist/agent-runtime/prompt.d.ts.map +1 -1
  12. package/dist/agent-runtime/protocol.d.ts +19 -1
  13. package/dist/agent-runtime/protocol.d.ts.map +1 -1
  14. package/dist/agent-runtime/run-execution.d.ts +5 -5
  15. package/dist/agent-runtime/run-execution.d.ts.map +1 -1
  16. package/dist/agent-runtime/runtime-internals.d.ts +1 -1
  17. package/dist/agent-runtime/runtime-result.d.ts +1 -1
  18. package/dist/agent-runtime/runtime.d.ts +14 -12
  19. package/dist/agent-runtime/runtime.d.ts.map +1 -1
  20. package/dist/agent-runtime/store-driver.d.ts +2 -2
  21. package/dist/agent-runtime/store.d.ts +2 -2
  22. package/dist/agent-runtime/terminal-commit.d.ts +2 -2
  23. package/dist/agent-runtime/terminal-status.d.ts +1 -1
  24. package/dist/agent-runtime-openrouter.d.ts +1 -1
  25. package/dist/agent-runtime.d.ts +15 -15
  26. package/dist/agent-runtime.d.ts.map +1 -1
  27. package/dist/agent-runtime.js +90 -30
  28. package/dist/application/admission.d.ts +131 -0
  29. package/dist/application/admission.d.ts.map +1 -0
  30. package/dist/application/channel.d.ts +106 -0
  31. package/dist/application/channel.d.ts.map +1 -0
  32. package/dist/application/events.d.ts +2 -2
  33. package/dist/application/grammy.d.ts +2 -2
  34. package/dist/application/graph.d.ts +1 -1
  35. package/dist/application/health.d.ts +1 -1
  36. package/dist/application/kernel.d.ts +3 -3
  37. package/dist/application/latest-sink.d.ts.map +1 -1
  38. package/dist/application/opentelemetry.d.ts +3 -3
  39. package/dist/application/resource.d.ts +1 -1
  40. package/dist/application/schedule.d.ts +1 -1
  41. package/dist/application/server-resource.d.ts +7 -9
  42. package/dist/application/server-resource.d.ts.map +1 -1
  43. package/dist/application-grammy.d.ts +1 -1
  44. package/dist/application-grammy.js +1 -1
  45. package/dist/application-opentelemetry.d.ts +1 -1
  46. package/dist/application-opentelemetry.js +1 -1
  47. package/dist/application.d.ts +11 -9
  48. package/dist/application.d.ts.map +1 -1
  49. package/dist/application.js +393 -24
  50. package/dist/browser/client-multipart.d.ts +1 -1
  51. package/dist/browser/client-url.d.ts +2 -2
  52. package/dist/browser/client.d.ts +4 -5
  53. package/dist/browser/client.d.ts.map +1 -1
  54. package/dist/browser/contract-stream.d.ts +5 -0
  55. package/dist/browser/contract-stream.d.ts.map +1 -0
  56. package/dist/browser/http.d.ts +9 -6
  57. package/dist/browser/http.d.ts.map +1 -1
  58. package/dist/browser/socket-io.d.ts +12 -31
  59. package/dist/browser/socket-io.d.ts.map +1 -1
  60. package/dist/browser/stream.d.ts +5 -2
  61. package/dist/browser/stream.d.ts.map +1 -1
  62. package/dist/browser/transport.d.ts +3 -0
  63. package/dist/browser/transport.d.ts.map +1 -0
  64. package/dist/cli.d.ts +6 -6
  65. package/dist/cli.js +7 -7
  66. package/dist/contract/define.d.ts +34 -2
  67. package/dist/contract/define.d.ts.map +1 -1
  68. package/dist/contract/errors-factory.d.ts +1 -1
  69. package/dist/contract/errors.d.ts +4 -0
  70. package/dist/contract/errors.d.ts.map +1 -1
  71. package/dist/contract/factory.d.ts +1 -1
  72. package/dist/contract/index.d.ts +7 -6
  73. package/dist/contract/index.d.ts.map +1 -1
  74. package/dist/contract/index.js +5 -1
  75. package/dist/contract/stream.d.ts +19 -0
  76. package/dist/contract/stream.d.ts.map +1 -0
  77. package/dist/files/boundary.d.ts +1 -1
  78. package/dist/files.d.ts +2 -2
  79. package/dist/{index-xxye8j3k.js → index-0w9abg87.js} +4 -0
  80. package/dist/{index-svqhcrrj.js → index-2ve29dzn.js} +159 -13
  81. package/dist/index-69m2278y.js +115 -0
  82. package/dist/{index-physbf4z.js → index-6wzr93cg.js} +1 -1
  83. package/dist/index-7etq650s.js +75 -0
  84. package/dist/index-9ky9hhg3.js +484 -0
  85. package/dist/{index-413xk7ga.js → index-cq9q73nf.js} +50 -1
  86. package/dist/{index-1pgeyyee.js → index-cszjsxy5.js} +25 -88
  87. package/dist/{index-wrhf06ak.js → index-cz32amcb.js} +8 -8
  88. package/dist/{index-6taryy00.js → index-dafax5md.js} +1 -1
  89. package/dist/index-g2j2m6vv.js +63 -0
  90. package/dist/{index-8mxadm34.js → index-nck3yx3y.js} +1102 -22
  91. package/dist/{index-y91zd0ch.js → index-pr0qsmjy.js} +3 -2
  92. package/dist/index-v5bayx1z.js +138 -0
  93. package/dist/{index-mfw1pec7.js → index-wqyrvhzz.js} +3 -3
  94. package/dist/{index-x8v8b7rc.js → index-zpyj7hsv.js} +330 -58
  95. package/dist/index.d.ts +10 -10
  96. package/dist/index.js +274 -109
  97. package/dist/internal/bounded-lines.d.ts +4 -0
  98. package/dist/internal/bounded-lines.d.ts.map +1 -0
  99. package/dist/internal/errors.d.ts +1 -1
  100. package/dist/internal/observability-sink.d.ts +1 -1
  101. package/dist/node.d.ts +11 -10
  102. package/dist/node.d.ts.map +1 -1
  103. package/dist/node.js +11 -8
  104. package/dist/observability/audit.d.ts +5 -5
  105. package/dist/observability/context.d.ts +2 -2
  106. package/dist/observability/event.d.ts +2 -2
  107. package/dist/observability/index.d.ts +6 -6
  108. package/dist/observability/index.js +6 -7
  109. package/dist/react/entity-cache.d.ts +26 -1
  110. package/dist/react/entity-cache.d.ts.map +1 -1
  111. package/dist/react.d.ts +3 -3
  112. package/dist/react.d.ts.map +1 -1
  113. package/dist/react.js +136 -38
  114. package/dist/realtime/contract.d.ts +1 -1
  115. package/dist/realtime/index.d.ts +4 -4
  116. package/dist/realtime/rejection.d.ts +1 -1
  117. package/dist/realtime/request.d.ts +1 -1
  118. package/dist/realtime/socket.d.ts +2 -2
  119. package/dist/remote.d.ts +1 -1
  120. package/dist/remote.js +5 -6
  121. package/dist/server/bun.d.ts +3 -3
  122. package/dist/server/context-contribution.d.ts +1 -1
  123. package/dist/server/context.d.ts +4 -4
  124. package/dist/server/contract-stream.d.ts +5 -0
  125. package/dist/server/contract-stream.d.ts.map +1 -0
  126. package/dist/server/create.d.ts +1 -1
  127. package/dist/server/create.d.ts.map +1 -1
  128. package/dist/server/error-hook.d.ts +3 -3
  129. package/dist/server/file.d.ts +1 -1
  130. package/dist/server/implement.d.ts +2 -2
  131. package/dist/server/implement.d.ts.map +1 -1
  132. package/dist/server/index.d.ts +31 -30
  133. package/dist/server/index.d.ts.map +1 -1
  134. package/dist/server/index.js +44 -286
  135. package/dist/server/lifecycle.d.ts +1 -1
  136. package/dist/server/logging.d.ts +1 -1
  137. package/dist/server/middleware/auth.d.ts +2 -2
  138. package/dist/server/multipart.d.ts +2 -2
  139. package/dist/server/node.d.ts +2 -2
  140. package/dist/server/openapi.d.ts +1 -1
  141. package/dist/server/openapi.d.ts.map +1 -1
  142. package/dist/server/process-signal-common.d.ts +1 -1
  143. package/dist/server/process-signals.d.ts +1 -1
  144. package/dist/server/realtime.d.ts +4 -4
  145. package/dist/server/response-metadata.d.ts +1 -1
  146. package/dist/server/router.d.ts +1 -1
  147. package/dist/server/shutdown.d.ts +1 -1
  148. package/dist/server/socket-io-node.d.ts +3 -3
  149. package/dist/server/socket-io.d.ts +6 -6
  150. package/dist/server/stream.d.ts +3 -1
  151. package/dist/server/stream.d.ts.map +1 -1
  152. package/dist/server/streaming-route.d.ts +4 -2
  153. package/dist/server/streaming-route.d.ts.map +1 -1
  154. package/dist/server/types.d.ts +18 -8
  155. package/dist/server/types.d.ts.map +1 -1
  156. package/dist/server/unix-client-body.d.ts +4 -0
  157. package/dist/server/unix-client-body.d.ts.map +1 -0
  158. package/dist/server/unix-client-bun.d.ts +13 -0
  159. package/dist/server/unix-client-bun.d.ts.map +1 -0
  160. package/dist/server/unix-client-error.d.ts +9 -0
  161. package/dist/server/unix-client-error.d.ts.map +1 -0
  162. package/dist/server/unix-client.d.ts +25 -0
  163. package/dist/server/unix-client.d.ts.map +1 -0
  164. package/dist/testing/agent-store-conformance.d.ts +1 -1
  165. package/dist/testing/managed-resource-conformance-contract.d.ts +1 -1
  166. package/dist/testing/managed-resource-conformance-driver.d.ts +2 -2
  167. package/dist/testing/managed-resource-conformance-scenarios.d.ts +2 -2
  168. package/dist/testing/managed-resource-conformance.d.ts +2 -2
  169. package/dist/testing/surface-conformance.d.ts +3 -3
  170. package/dist/testing/surface-manifest.d.ts +5 -5
  171. package/dist/testing.d.ts +8 -8
  172. package/dist/testing.js +6 -5
  173. package/dist/tool-invoker.d.ts +9 -0
  174. package/dist/tool-invoker.d.ts.map +1 -0
  175. package/dist/tool-invoker.js +16 -0
  176. package/dist/tools/agent.d.ts +4 -4
  177. package/dist/tools/async-operation.d.ts +3 -3
  178. package/dist/tools/cli-command.d.ts +3 -3
  179. package/dist/tools/cli-format.d.ts +1 -1
  180. package/dist/tools/cli-policy.d.ts +1 -1
  181. package/dist/tools/cli-wait.d.ts +1 -1
  182. package/dist/tools/cli.d.ts +7 -7
  183. package/dist/tools/define-download-tool.d.ts +4 -4
  184. package/dist/tools/define-upload-tool.d.ts +3 -3
  185. package/dist/tools/define-view-file-tool.d.ts +3 -3
  186. package/dist/tools/define-wait-tool.d.ts +2 -2
  187. package/dist/tools/download-core.d.ts +2 -2
  188. package/dist/tools/execute.d.ts +2 -2
  189. package/dist/tools/flatten-join.d.ts +1 -1
  190. package/dist/tools/internal/surface-projector.d.ts +3 -3
  191. package/dist/tools/invoker.d.ts +4 -4
  192. package/dist/tools/lifecycle.d.ts +1 -1
  193. package/dist/tools/list-names.d.ts +2 -2
  194. package/dist/tools/managed-file-error.d.ts +1 -1
  195. package/dist/tools/manifest.d.ts +3 -3
  196. package/dist/tools/mcp-handler.d.ts +4 -4
  197. package/dist/tools/mcp-prepare.d.ts +8 -8
  198. package/dist/tools/mcp-round-policy.d.ts +1 -1
  199. package/dist/tools/mcp-round.d.ts +3 -3
  200. package/dist/tools/mcp-stdio-signals.d.ts +2 -2
  201. package/dist/tools/mcp-stdio.d.ts +3 -3
  202. package/dist/tools/mcp.d.ts +7 -7
  203. package/dist/tools/mount-download.d.ts +1 -1
  204. package/dist/tools/mount-upload.d.ts +1 -1
  205. package/dist/tools/mount.d.ts +5 -5
  206. package/dist/tools/native-definition.d.ts +2 -2
  207. package/dist/tools/native-mcp.d.ts +3 -3
  208. package/dist/tools/oauth-metadata.d.ts +1 -1
  209. package/dist/tools/oauth-provider.d.ts +1 -1
  210. package/dist/tools/presentation.d.ts +1 -1
  211. package/dist/tools/remote.d.ts +3 -3
  212. package/dist/tools/runtime-tool.d.ts +2 -2
  213. package/dist/tools/surface.d.ts +5 -5
  214. package/dist/tools/tool-logger.d.ts +1 -1
  215. package/dist/tools/toolkit.d.ts +7 -7
  216. package/dist/tools/transports.d.ts +2 -2
  217. package/dist/tools/upload-core.d.ts +1 -1
  218. package/dist/tools/view-file.d.ts +1 -1
  219. package/dist/tools.d.ts +42 -42
  220. package/dist/tools.js +27 -72
  221. package/llms-full.txt +506 -35
  222. package/package.json +8 -4
  223. package/dist/index-48ffdxgk.js +0 -6
  224. package/dist/index-pzyt11ch.js +0 -127
  225. package/dist/index-tvwcrx2d.js +0 -224
  226. package/dist/index-wd8g8z6e.js +0 -206
@@ -1,100 +1,37 @@
1
+ import {
2
+ contractToolMountable,
3
+ createToolRunner,
4
+ formatToolError
5
+ } from "./index-7etq650s.js";
1
6
  import {
2
7
  coerceJsonArgs,
3
- executeToolMethod,
4
8
  toolResultFromError
5
- } from "./index-wrhf06ak.js";
9
+ } from "./index-cz32amcb.js";
6
10
  import {
7
11
  isWithinDir
8
12
  } from "./index-sbdmyz75.js";
9
13
  import {
10
- assertToolExtensionCompatible,
11
14
  assertUniqueToolName,
12
15
  buildToolPresentationSchema,
13
16
  projectRuntimeTool,
14
17
  projectToolSurface
15
18
  } from "./index-vkk06pv1.js";
16
19
  import {
17
- mergeSchemas,
18
- objectShapeKeys,
19
- rebuildObject
20
+ objectShapeKeys
20
21
  } from "./index-6djpbnda.js";
21
22
  import {
22
23
  jsonSchemaFields
23
24
  } from "./index-cby4ar3v.js";
24
25
  import {
25
26
  formatZodError,
26
- validateDeclaredOutput
27
- } from "./index-tvwcrx2d.js";
28
- import {
29
27
  isUnsafeKey,
30
- safeJsonParse
31
- } from "./index-wd8g8z6e.js";
28
+ safeJsonParse,
29
+ validateDeclaredOutput
30
+ } from "./index-9ky9hhg3.js";
32
31
  import {
33
32
  isRecord
34
33
  } from "./index-smpbdg6k.js";
35
34
 
36
- // src/tools/mount.ts
37
- import { z } from "zod";
38
- function applyExtend(base, extra) {
39
- if (base instanceof z.ZodObject) {
40
- assertToolExtensionCompatible(base, extra);
41
- return rebuildObject(base, { ...extra, ...base.shape });
42
- }
43
- return z.intersection(z.object(extra), base);
44
- }
45
- function contractToolMountable(projected, extend) {
46
- const method = projected.source;
47
- const baseArgumentSchema = mergeSchemas(method.paramsSchema, method.inputSchema);
48
- const argumentSchema = projected.shouldExtend && extend ? applyExtend(baseArgumentSchema, extend.schema) : baseArgumentSchema;
49
- return {
50
- method,
51
- name: projected.name,
52
- argumentSchema,
53
- presentationSchema: projected.presentationSchema,
54
- shouldExtend: projected.shouldExtend
55
- };
56
- }
57
- function collectTools(service, transport, config = {}) {
58
- const { extend, flattenUnionInput = false, assertNames = true } = config;
59
- const tools = [];
60
- for (const projected of projectToolSurface({ services: [service] }, transport === "HTTP" ? "AGENT" : transport, {
61
- extend,
62
- flattenUnionInput,
63
- assertNames,
64
- assertUniqueNames: false
65
- })) {
66
- if (projected.kind !== "contract")
67
- continue;
68
- tools.push(contractToolMountable(projected, extend));
69
- }
70
- return tools;
71
- }
72
- function createToolRunner(config) {
73
- const extension = config.extend ? {
74
- schema: z.object(config.extend.schema),
75
- resolve: config.extend.resolve
76
- } : undefined;
77
- return async function runOneToolCall(tool, rawArgs, context) {
78
- return executeToolMethod(tool.method, tool.name, rawArgs, { ...config.context, ...context, source: config.source }, config.hooks, config.lifecycle, config.coerceJsonArgs ?? true, config.onOutputStrip ? (paths) => config.onOutputStrip?.(tool.name, paths) : undefined, tool.shouldExtend ? extension : undefined);
79
- };
80
- }
81
- function formatToolError(result, toolName, errorHint) {
82
- const err = { error: result.code };
83
- if (result.details)
84
- err.details = result.details;
85
- const hints = [];
86
- if (result.hint)
87
- hints.push(result.hint);
88
- if (errorHint && toolName) {
89
- const global = errorHint(toolName, result.code);
90
- if (global)
91
- hints.push(global);
92
- }
93
- if (hints.length > 0)
94
- err._hint = hints.join(" ");
95
- return err;
96
- }
97
-
98
35
  // src/tools/runtime-tool.ts
99
36
  function defineRuntimeTool(definition) {
100
37
  if (definition.transports?.length === 0) {
@@ -177,7 +114,7 @@ function runtimeToolMountable(definition, assertName = true) {
177
114
  }
178
115
 
179
116
  // src/tools/cli-args.ts
180
- import { z as z2 } from "zod";
117
+ import { z } from "zod";
181
118
  var NUMERIC_VALUE = /^-(\d+\.?\d*|\.\d+)$/;
182
119
  var BOOL_OPTIONS = new Set(["json", "wait", "quiet", "dry-run", "help"]);
183
120
  var VALUE_OPTIONS = new Set(["wait-timeout", "output-dir"]);
@@ -286,27 +223,27 @@ class CliArgumentError extends Error {
286
223
  name = "CliArgumentError";
287
224
  }
288
225
  function unwrap(field) {
289
- if (field instanceof z2.ZodOptional || field instanceof z2.ZodNullable || field instanceof z2.ZodDefault) {
226
+ if (field instanceof z.ZodOptional || field instanceof z.ZodNullable || field instanceof z.ZodDefault) {
290
227
  return unwrap(field.unwrap());
291
228
  }
292
229
  return field;
293
230
  }
294
231
  function classify(field) {
295
- if (field instanceof z2.ZodBoolean)
232
+ if (field instanceof z.ZodBoolean)
296
233
  return "boolean";
297
- if (field instanceof z2.ZodNumber)
234
+ if (field instanceof z.ZodNumber)
298
235
  return "number";
299
- if (field instanceof z2.ZodBigInt)
236
+ if (field instanceof z.ZodBigInt)
300
237
  return "bigint";
301
- if (field instanceof z2.ZodDate)
238
+ if (field instanceof z.ZodDate)
302
239
  return "date";
303
- if (field instanceof z2.ZodEnum)
240
+ if (field instanceof z.ZodEnum)
304
241
  return "enum";
305
- if (field instanceof z2.ZodArray)
242
+ if (field instanceof z.ZodArray)
306
243
  return "array";
307
- if (field instanceof z2.ZodObject)
244
+ if (field instanceof z.ZodObject)
308
245
  return "object";
309
- if (field instanceof z2.ZodString || field instanceof z2.ZodLiteral)
246
+ if (field instanceof z.ZodString || field instanceof z.ZodLiteral)
310
247
  return "string";
311
248
  return "other";
312
249
  }
@@ -326,11 +263,11 @@ function mergeField(fields, name, info) {
326
263
  }
327
264
  function collectSchemaFields(schema, fields) {
328
265
  const base = unwrap(schema);
329
- if (base instanceof z2.ZodObject) {
266
+ if (base instanceof z.ZodObject) {
330
267
  for (const [name, raw] of Object.entries(base.shape)) {
331
268
  const fieldBase = unwrap(raw);
332
269
  const kind = classify(fieldBase);
333
- if (kind === "array" && fieldBase instanceof z2.ZodArray) {
270
+ if (kind === "array" && fieldBase instanceof z.ZodArray) {
334
271
  mergeField(fields, name, { kind, elementKind: classify(unwrap(fieldBase.element)) });
335
272
  } else {
336
273
  mergeField(fields, name, { kind });
@@ -338,12 +275,12 @@ function collectSchemaFields(schema, fields) {
338
275
  }
339
276
  return;
340
277
  }
341
- if (base instanceof z2.ZodUnion) {
278
+ if (base instanceof z.ZodUnion) {
342
279
  for (const option of base.def.options)
343
280
  collectSchemaFields(option, fields);
344
281
  return;
345
282
  }
346
- if (base instanceof z2.ZodIntersection) {
283
+ if (base instanceof z.ZodIntersection) {
347
284
  collectSchemaFields(base.def.left, fields);
348
285
  collectSchemaFields(base.def.right, fields);
349
286
  return;
@@ -1737,4 +1674,4 @@ async function createCli(config) {
1737
1674
  return exit(downloadsOk ? exitCode : 1);
1738
1675
  }
1739
1676
 
1740
- export { collectTools, createToolRunner, formatToolError, defineRuntimeTool, createRuntimeToolFactory, collectToolSurface, WaitTimeoutError, runWaitOperation, fetchGuarded, fetchPinnedDocument, readCapped, parseCliArgs, defineCliCommand, DEFAULT_EXIT_CODES, emitResult, pollUntilDone, createCli };
1677
+ export { defineRuntimeTool, createRuntimeToolFactory, collectToolSurface, WaitTimeoutError, runWaitOperation, fetchGuarded, fetchPinnedDocument, readCapped, parseCliArgs, defineCliCommand, DEFAULT_EXIT_CODES, emitResult, pollUntilDone, createCli };
@@ -1,17 +1,17 @@
1
+ import {
2
+ getRequestContext,
3
+ runWithRequestContext
4
+ } from "./index-69m2278y.js";
1
5
  import {
2
6
  objectShapeKeys
3
7
  } from "./index-6djpbnda.js";
4
8
  import {
5
9
  formatZodError,
6
- getRequestContext,
10
+ isUnsafeKey,
7
11
  normalizeError,
8
- runWithRequestContext,
12
+ safeJsonParse,
9
13
  validateDeclaredOutput
10
- } from "./index-tvwcrx2d.js";
11
- import {
12
- isUnsafeKey,
13
- safeJsonParse
14
- } from "./index-wd8g8z6e.js";
14
+ } from "./index-9ky9hhg3.js";
15
15
  import {
16
16
  isRecord
17
17
  } from "./index-smpbdg6k.js";
@@ -19,7 +19,7 @@ import {
19
19
  AppError,
20
20
  STITCH_ERROR_STATUS,
21
21
  isStitchErrorCode
22
- } from "./index-xxye8j3k.js";
22
+ } from "./index-0w9abg87.js";
23
23
 
24
24
  // src/tools/coerce.ts
25
25
  import { z } from "zod";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  isUnsafeKey
3
- } from "./index-wd8g8z6e.js";
3
+ } from "./index-9ky9hhg3.js";
4
4
  import {
5
5
  isRecord
6
6
  } from "./index-smpbdg6k.js";
@@ -0,0 +1,63 @@
1
+ import {
2
+ collectTools,
3
+ createToolRunner
4
+ } from "./index-7etq650s.js";
5
+ import {
6
+ toolErrorFromResult
7
+ } from "./index-cz32amcb.js";
8
+ import {
9
+ assertUniqueToolName
10
+ } from "./index-vkk06pv1.js";
11
+ import {
12
+ AppError
13
+ } from "./index-0w9abg87.js";
14
+
15
+ // src/tools/invoker.ts
16
+ function createToolInvoker(services, config) {
17
+ const serviceList = Array.isArray(services) ? services : [services];
18
+ const tools = new Map;
19
+ for (const service of serviceList) {
20
+ for (const tool of collectTools(service, config.transport, {
21
+ extend: config.extend,
22
+ flattenUnionInput: config.flattenUnionInput
23
+ })) {
24
+ assertUniqueToolName(tool.name, tools.has(tool.name), "in-process tool name");
25
+ tools.set(tool.name, tool);
26
+ }
27
+ }
28
+ const names = Object.freeze([...tools.keys()].sort());
29
+ const operation = (name) => {
30
+ const tool = tools.get(name);
31
+ if (tool)
32
+ return tool;
33
+ throw new AppError("NOT_FOUND", `Unknown tool: ${name}`, 404, {
34
+ available: names
35
+ });
36
+ };
37
+ const run = (name, args, options = {}) => {
38
+ const runTool = createToolRunner({
39
+ source: options.source ?? "internal",
40
+ context: options.context,
41
+ hooks: options.hooks,
42
+ lifecycle: options.lifecycle,
43
+ extend: config.extend,
44
+ coerceJsonArgs: config.coerceJsonArgs,
45
+ onOutputStrip: options.onOutputStrip
46
+ });
47
+ return runTool(operation(name), args);
48
+ };
49
+ return Object.freeze({
50
+ names,
51
+ invoke(name, args, options) {
52
+ return run(name, args, options);
53
+ },
54
+ async invokeOrThrow(name, args, options) {
55
+ const result = await run(name, args, options);
56
+ if (!result.ok)
57
+ throw toolErrorFromResult(result);
58
+ return result.data;
59
+ }
60
+ });
61
+ }
62
+
63
+ export { createToolInvoker };