@contractspec/lib.ai-agent 1.56.1 → 1.58.0

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 (231) hide show
  1. package/dist/agent/agent-factory.d.ts +67 -72
  2. package/dist/agent/agent-factory.d.ts.map +1 -1
  3. package/dist/agent/agent-factory.js +658 -100
  4. package/dist/agent/agent.test.d.ts +2 -0
  5. package/dist/agent/agent.test.d.ts.map +1 -0
  6. package/dist/agent/contract-spec-agent.d.ts +49 -55
  7. package/dist/agent/contract-spec-agent.d.ts.map +1 -1
  8. package/dist/agent/contract-spec-agent.js +605 -146
  9. package/dist/agent/index.d.ts +4 -3
  10. package/dist/agent/index.d.ts.map +1 -0
  11. package/dist/agent/index.js +2102 -3
  12. package/dist/agent/json-runner.d.ts +18 -0
  13. package/dist/agent/json-runner.d.ts.map +1 -0
  14. package/dist/agent/json-runner.js +684 -0
  15. package/dist/agent/json-runner.test.d.ts +2 -0
  16. package/dist/agent/json-runner.test.d.ts.map +1 -0
  17. package/dist/agent/unified-agent.d.ts +132 -99
  18. package/dist/agent/unified-agent.d.ts.map +1 -1
  19. package/dist/agent/unified-agent.js +2012 -260
  20. package/dist/approval/index.d.ts +3 -2
  21. package/dist/approval/index.d.ts.map +1 -0
  22. package/dist/approval/index.js +128 -2
  23. package/dist/approval/workflow.d.ts +106 -110
  24. package/dist/approval/workflow.d.ts.map +1 -1
  25. package/dist/approval/workflow.js +126 -157
  26. package/dist/exporters/claude-agent-exporter.d.ts +50 -49
  27. package/dist/exporters/claude-agent-exporter.d.ts.map +1 -1
  28. package/dist/exporters/claude-agent-exporter.js +258 -203
  29. package/dist/exporters/index.d.ts +28 -4
  30. package/dist/exporters/index.d.ts.map +1 -0
  31. package/dist/exporters/index.js +737 -3
  32. package/dist/exporters/opencode-exporter.d.ts +47 -46
  33. package/dist/exporters/opencode-exporter.d.ts.map +1 -1
  34. package/dist/exporters/opencode-exporter.js +507 -191
  35. package/dist/exporters/types.d.ts +171 -170
  36. package/dist/exporters/types.d.ts.map +1 -1
  37. package/dist/exporters/types.js +1 -0
  38. package/dist/index.d.ts +15 -37
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.js +3337 -31
  41. package/dist/interop/index.d.ts +48 -4
  42. package/dist/interop/index.d.ts.map +1 -0
  43. package/dist/interop/index.js +709 -3
  44. package/dist/interop/spec-consumer.d.ts +57 -54
  45. package/dist/interop/spec-consumer.d.ts.map +1 -1
  46. package/dist/interop/spec-consumer.js +302 -282
  47. package/dist/interop/tool-consumer.d.ts +57 -54
  48. package/dist/interop/tool-consumer.d.ts.map +1 -1
  49. package/dist/interop/tool-consumer.js +412 -213
  50. package/dist/interop/types.d.ts +173 -172
  51. package/dist/interop/types.d.ts.map +1 -1
  52. package/dist/interop/types.js +1 -0
  53. package/dist/knowledge/index.d.ts +2 -2
  54. package/dist/knowledge/index.d.ts.map +1 -0
  55. package/dist/knowledge/index.js +66 -2
  56. package/dist/knowledge/injector.d.ts +16 -21
  57. package/dist/knowledge/injector.d.ts.map +1 -1
  58. package/dist/knowledge/injector.js +56 -47
  59. package/dist/memory/in-memory.d.ts +15 -19
  60. package/dist/memory/in-memory.d.ts.map +1 -1
  61. package/dist/memory/in-memory.js +152 -46
  62. package/dist/memory/index.d.ts +3 -3
  63. package/dist/memory/index.d.ts.map +1 -0
  64. package/dist/memory/index.js +155 -3
  65. package/dist/memory/manager.d.ts +32 -36
  66. package/dist/memory/manager.d.ts.map +1 -1
  67. package/dist/memory/manager.js +96 -71
  68. package/dist/memory/memory.test.d.ts +2 -0
  69. package/dist/memory/memory.test.d.ts.map +1 -0
  70. package/dist/node/agent/agent-factory.js +661 -0
  71. package/dist/node/agent/contract-spec-agent.js +607 -0
  72. package/dist/node/agent/index.js +2103 -0
  73. package/dist/node/agent/json-runner.js +684 -0
  74. package/dist/node/agent/unified-agent.js +2019 -0
  75. package/dist/node/approval/index.js +129 -0
  76. package/dist/node/approval/workflow.js +129 -0
  77. package/dist/node/exporters/claude-agent-exporter.js +265 -0
  78. package/dist/node/exporters/index.js +738 -0
  79. package/dist/node/exporters/opencode-exporter.js +516 -0
  80. package/dist/node/exporters/types.js +0 -0
  81. package/dist/node/index.js +3337 -0
  82. package/dist/node/interop/index.js +710 -0
  83. package/dist/node/interop/spec-consumer.js +307 -0
  84. package/dist/node/interop/tool-consumer.js +419 -0
  85. package/dist/node/interop/types.js +0 -0
  86. package/dist/node/knowledge/index.js +67 -0
  87. package/dist/node/knowledge/injector.js +67 -0
  88. package/dist/node/memory/in-memory.js +154 -0
  89. package/dist/node/memory/index.js +156 -0
  90. package/dist/node/memory/manager.js +105 -0
  91. package/dist/node/providers/claude-agent-sdk/adapter.js +624 -0
  92. package/dist/node/providers/claude-agent-sdk/index.js +673 -0
  93. package/dist/node/providers/claude-agent-sdk/session-bridge.js +149 -0
  94. package/dist/node/providers/claude-agent-sdk/tool-bridge.js +118 -0
  95. package/dist/node/providers/index.js +1261 -0
  96. package/dist/node/providers/opencode-sdk/adapter.js +669 -0
  97. package/dist/node/providers/opencode-sdk/agent-bridge.js +299 -0
  98. package/dist/node/providers/opencode-sdk/index.js +703 -0
  99. package/dist/node/providers/opencode-sdk/tool-bridge.js +141 -0
  100. package/dist/node/providers/registry.js +89 -0
  101. package/dist/node/providers/types.js +56 -0
  102. package/dist/node/schema/index.js +195 -0
  103. package/dist/node/schema/json-schema-to-zod.js +152 -0
  104. package/dist/node/schema/schema-output.js +190 -0
  105. package/dist/node/session/index.js +90 -0
  106. package/dist/node/session/store.js +90 -0
  107. package/dist/node/spec/index.js +85 -0
  108. package/dist/node/spec/registry.js +56 -0
  109. package/dist/node/spec/spec.js +44 -0
  110. package/dist/node/telemetry/adapter.js +85 -0
  111. package/dist/node/telemetry/index.js +86 -0
  112. package/dist/node/tools/index.js +345 -0
  113. package/dist/node/tools/knowledge-tool.js +74 -0
  114. package/dist/node/tools/mcp-client.js +47 -0
  115. package/dist/node/tools/mcp-server.js +205 -0
  116. package/dist/node/tools/tool-adapter.js +197 -0
  117. package/dist/node/types.js +0 -0
  118. package/dist/providers/claude-agent-sdk/adapter.d.ts +60 -53
  119. package/dist/providers/claude-agent-sdk/adapter.d.ts.map +1 -1
  120. package/dist/providers/claude-agent-sdk/adapter.js +622 -304
  121. package/dist/providers/claude-agent-sdk/index.d.ts +22 -4
  122. package/dist/providers/claude-agent-sdk/index.d.ts.map +1 -0
  123. package/dist/providers/claude-agent-sdk/index.js +672 -4
  124. package/dist/providers/claude-agent-sdk/session-bridge.d.ts +43 -41
  125. package/dist/providers/claude-agent-sdk/session-bridge.d.ts.map +1 -1
  126. package/dist/providers/claude-agent-sdk/session-bridge.js +121 -130
  127. package/dist/providers/claude-agent-sdk/tool-bridge.d.ts +63 -61
  128. package/dist/providers/claude-agent-sdk/tool-bridge.d.ts.map +1 -1
  129. package/dist/providers/claude-agent-sdk/tool-bridge.js +104 -108
  130. package/dist/providers/index.d.ts +28 -7
  131. package/dist/providers/index.d.ts.map +1 -0
  132. package/dist/providers/index.js +1261 -8
  133. package/dist/providers/opencode-sdk/adapter.d.ts +56 -49
  134. package/dist/providers/opencode-sdk/adapter.d.ts.map +1 -1
  135. package/dist/providers/opencode-sdk/adapter.js +667 -274
  136. package/dist/providers/opencode-sdk/agent-bridge.d.ts +62 -58
  137. package/dist/providers/opencode-sdk/agent-bridge.d.ts.map +1 -1
  138. package/dist/providers/opencode-sdk/agent-bridge.js +289 -155
  139. package/dist/providers/opencode-sdk/index.d.ts +22 -4
  140. package/dist/providers/opencode-sdk/index.d.ts.map +1 -0
  141. package/dist/providers/opencode-sdk/index.js +702 -4
  142. package/dist/providers/opencode-sdk/tool-bridge.d.ts +41 -43
  143. package/dist/providers/opencode-sdk/tool-bridge.d.ts.map +1 -1
  144. package/dist/providers/opencode-sdk/tool-bridge.js +121 -107
  145. package/dist/providers/registry.d.ts +10 -12
  146. package/dist/providers/registry.d.ts.map +1 -1
  147. package/dist/providers/registry.js +86 -49
  148. package/dist/providers/types.d.ts +169 -167
  149. package/dist/providers/types.d.ts.map +1 -1
  150. package/dist/providers/types.js +54 -42
  151. package/dist/schema/index.d.ts +3 -3
  152. package/dist/schema/index.d.ts.map +1 -0
  153. package/dist/schema/index.js +194 -3
  154. package/dist/schema/json-schema-to-zod.d.ts +23 -27
  155. package/dist/schema/json-schema-to-zod.d.ts.map +1 -1
  156. package/dist/schema/json-schema-to-zod.js +138 -110
  157. package/dist/schema/schema-output.d.ts +29 -33
  158. package/dist/schema/schema-output.d.ts.map +1 -1
  159. package/dist/schema/schema-output.js +178 -53
  160. package/dist/session/index.d.ts +2 -2
  161. package/dist/session/index.d.ts.map +1 -0
  162. package/dist/session/index.js +89 -2
  163. package/dist/session/store.d.ts +51 -56
  164. package/dist/session/store.d.ts.map +1 -1
  165. package/dist/session/store.js +85 -74
  166. package/dist/spec/index.d.ts +3 -3
  167. package/dist/spec/index.d.ts.map +1 -0
  168. package/dist/spec/index.js +84 -3
  169. package/dist/spec/registry.d.ts +32 -37
  170. package/dist/spec/registry.d.ts.map +1 -1
  171. package/dist/spec/registry.js +51 -60
  172. package/dist/spec/spec.d.ts +80 -85
  173. package/dist/spec/spec.d.ts.map +1 -1
  174. package/dist/spec/spec.js +40 -26
  175. package/dist/telemetry/adapter.d.ts +33 -38
  176. package/dist/telemetry/adapter.d.ts.map +1 -1
  177. package/dist/telemetry/adapter.js +78 -96
  178. package/dist/telemetry/index.d.ts +2 -2
  179. package/dist/telemetry/index.d.ts.map +1 -0
  180. package/dist/telemetry/index.js +85 -2
  181. package/dist/tools/index.d.ts +5 -5
  182. package/dist/tools/index.d.ts.map +1 -0
  183. package/dist/tools/index.js +344 -5
  184. package/dist/tools/knowledge-tool.d.ts +4 -9
  185. package/dist/tools/knowledge-tool.d.ts.map +1 -1
  186. package/dist/tools/knowledge-tool.js +68 -48
  187. package/dist/tools/mcp-client.d.ts +17 -22
  188. package/dist/tools/mcp-client.d.ts.map +1 -1
  189. package/dist/tools/mcp-client.js +42 -53
  190. package/dist/tools/mcp-server.d.ts +14 -19
  191. package/dist/tools/mcp-server.d.ts.map +1 -1
  192. package/dist/tools/mcp-server.js +200 -64
  193. package/dist/tools/tool-adapter.d.ts +7 -12
  194. package/dist/tools/tool-adapter.d.ts.map +1 -1
  195. package/dist/tools/tool-adapter.js +187 -70
  196. package/dist/tools/tools.test.d.ts +2 -0
  197. package/dist/tools/tools.test.d.ts.map +1 -0
  198. package/dist/types.d.ts +108 -112
  199. package/dist/types.d.ts.map +1 -1
  200. package/dist/types.js +1 -0
  201. package/package.json +452 -92
  202. package/dist/_virtual/rolldown_runtime.js +0 -8
  203. package/dist/agent/agent-factory.js.map +0 -1
  204. package/dist/agent/contract-spec-agent.js.map +0 -1
  205. package/dist/agent/unified-agent.js.map +0 -1
  206. package/dist/approval/workflow.js.map +0 -1
  207. package/dist/exporters/claude-agent-exporter.js.map +0 -1
  208. package/dist/exporters/opencode-exporter.js.map +0 -1
  209. package/dist/interop/spec-consumer.js.map +0 -1
  210. package/dist/interop/tool-consumer.js.map +0 -1
  211. package/dist/knowledge/injector.js.map +0 -1
  212. package/dist/memory/in-memory.js.map +0 -1
  213. package/dist/memory/manager.js.map +0 -1
  214. package/dist/providers/claude-agent-sdk/adapter.js.map +0 -1
  215. package/dist/providers/claude-agent-sdk/session-bridge.js.map +0 -1
  216. package/dist/providers/claude-agent-sdk/tool-bridge.js.map +0 -1
  217. package/dist/providers/opencode-sdk/adapter.js.map +0 -1
  218. package/dist/providers/opencode-sdk/agent-bridge.js.map +0 -1
  219. package/dist/providers/opencode-sdk/tool-bridge.js.map +0 -1
  220. package/dist/providers/registry.js.map +0 -1
  221. package/dist/providers/types.js.map +0 -1
  222. package/dist/schema/json-schema-to-zod.js.map +0 -1
  223. package/dist/schema/schema-output.js.map +0 -1
  224. package/dist/session/store.js.map +0 -1
  225. package/dist/spec/registry.js.map +0 -1
  226. package/dist/spec/spec.js.map +0 -1
  227. package/dist/telemetry/adapter.js.map +0 -1
  228. package/dist/tools/knowledge-tool.js.map +0 -1
  229. package/dist/tools/mcp-client.js.map +0 -1
  230. package/dist/tools/mcp-server.js.map +0 -1
  231. package/dist/tools/tool-adapter.js.map +0 -1
@@ -0,0 +1,205 @@
1
+ import { createRequire } from "node:module";
2
+ var __defProp = Object.defineProperty;
3
+ var __export = (target, all) => {
4
+ for (var name in all)
5
+ __defProp(target, name, {
6
+ get: all[name],
7
+ enumerable: true,
8
+ configurable: true,
9
+ set: (newValue) => all[name] = () => newValue
10
+ });
11
+ };
12
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
13
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
14
+
15
+ // src/schema/json-schema-to-zod.ts
16
+ import { z } from "zod";
17
+ function jsonSchemaToZod(schema) {
18
+ const s = schema;
19
+ const makeNullable = (zodSchema) => {
20
+ return s.nullable ? z.union([zodSchema, z.null()]) : zodSchema;
21
+ };
22
+ if (s.const !== undefined) {
23
+ return z.literal(s.const);
24
+ }
25
+ if (s.enum) {
26
+ const values = s.enum;
27
+ return makeNullable(z.enum(values.map(String)));
28
+ }
29
+ if (s.anyOf && s.anyOf.length > 0) {
30
+ const schemas = s.anyOf.map((sub) => jsonSchemaToZod(sub));
31
+ if (schemas.length === 1)
32
+ return schemas[0] ?? z.unknown();
33
+ return z.union([
34
+ schemas[0] ?? z.unknown(),
35
+ schemas[1] ?? z.unknown(),
36
+ ...schemas.slice(2)
37
+ ]);
38
+ }
39
+ if (s.oneOf && s.oneOf.length > 0) {
40
+ const schemas = s.oneOf.map((sub) => jsonSchemaToZod(sub));
41
+ if (schemas.length === 1)
42
+ return schemas[0] ?? z.unknown();
43
+ return z.union([
44
+ schemas[0] ?? z.unknown(),
45
+ schemas[1] ?? z.unknown(),
46
+ ...schemas.slice(2)
47
+ ]);
48
+ }
49
+ if (s.allOf && s.allOf.length > 0) {
50
+ const schemas = s.allOf.map((sub) => jsonSchemaToZod(sub));
51
+ return schemas.reduce((acc, curr) => z.intersection(acc, curr));
52
+ }
53
+ switch (s.type) {
54
+ case "string":
55
+ return makeNullable(buildStringSchema(s));
56
+ case "number":
57
+ case "integer":
58
+ return makeNullable(buildNumberSchema(s));
59
+ case "boolean":
60
+ return makeNullable(z.boolean());
61
+ case "null":
62
+ return z.null();
63
+ case "array":
64
+ return makeNullable(buildArraySchema(s));
65
+ case "object":
66
+ return makeNullable(buildObjectSchema(s));
67
+ default:
68
+ return z.unknown();
69
+ }
70
+ }
71
+ function buildStringSchema(schema) {
72
+ let zodSchema = z.string();
73
+ if (schema.description) {
74
+ zodSchema = zodSchema.describe(schema.description);
75
+ }
76
+ switch (schema.format) {
77
+ case "email":
78
+ zodSchema = zodSchema.email();
79
+ break;
80
+ case "uri":
81
+ case "url":
82
+ zodSchema = zodSchema.url();
83
+ break;
84
+ case "uuid":
85
+ zodSchema = zodSchema.uuid();
86
+ break;
87
+ case "date-time":
88
+ zodSchema = zodSchema.datetime();
89
+ break;
90
+ case "date":
91
+ zodSchema = zodSchema.date();
92
+ break;
93
+ }
94
+ if (schema.minLength !== undefined) {
95
+ zodSchema = zodSchema.min(schema.minLength);
96
+ }
97
+ if (schema.maxLength !== undefined) {
98
+ zodSchema = zodSchema.max(schema.maxLength);
99
+ }
100
+ if (schema.pattern) {
101
+ zodSchema = zodSchema.regex(new RegExp(schema.pattern));
102
+ }
103
+ return zodSchema;
104
+ }
105
+ function buildNumberSchema(schema) {
106
+ let zodSchema = schema.type === "integer" ? z.number().int() : z.number();
107
+ if (schema.description) {
108
+ zodSchema = zodSchema.describe(schema.description);
109
+ }
110
+ if (schema.minimum !== undefined) {
111
+ zodSchema = zodSchema.min(schema.minimum);
112
+ }
113
+ if (schema.maximum !== undefined) {
114
+ zodSchema = zodSchema.max(schema.maximum);
115
+ }
116
+ return zodSchema;
117
+ }
118
+ function buildArraySchema(schema) {
119
+ const itemsSchema = schema.items ? jsonSchemaToZod(schema.items) : z.unknown();
120
+ let zodSchema = z.array(itemsSchema);
121
+ if (schema.description) {
122
+ zodSchema = zodSchema.describe(schema.description);
123
+ }
124
+ return zodSchema;
125
+ }
126
+ function buildObjectSchema(schema) {
127
+ const properties = schema.properties ?? {};
128
+ const required = new Set(schema.required ?? []);
129
+ const shape = {};
130
+ for (const [key, propSchema] of Object.entries(properties)) {
131
+ const zodProp = jsonSchemaToZod(propSchema);
132
+ shape[key] = required.has(key) ? zodProp : zodProp.optional();
133
+ }
134
+ let zodSchema = z.object(shape);
135
+ if (schema.description) {
136
+ zodSchema = zodSchema.describe(schema.description);
137
+ }
138
+ return zodSchema;
139
+ }
140
+ function jsonSchemaToZodSafe(schema) {
141
+ if (!schema || Object.keys(schema).length === 0) {
142
+ return z.object({});
143
+ }
144
+ return jsonSchemaToZod(schema);
145
+ }
146
+ var init_json_schema_to_zod = () => {};
147
+
148
+ // src/tools/mcp-server.ts
149
+ init_json_schema_to_zod();
150
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
151
+ import * as z2 from "zod";
152
+ function agentToMcpServer(agent, spec) {
153
+ const server = new McpServer({
154
+ name: spec.meta.key,
155
+ version: `${spec.meta.version}`
156
+ });
157
+ server.registerTool(spec.meta.key, {
158
+ description: spec.description ?? `Interact with ${spec.meta.key} agent`,
159
+ inputSchema: z2.object({
160
+ message: z2.string().describe("The message or query to send to the agent"),
161
+ sessionId: z2.string().optional().describe("Optional session ID to continue a conversation")
162
+ })
163
+ }, async (args) => {
164
+ const { message, sessionId } = args;
165
+ const result = await agent.generate({
166
+ prompt: message,
167
+ options: { sessionId }
168
+ });
169
+ return {
170
+ content: [
171
+ {
172
+ type: "text",
173
+ text: result.text
174
+ }
175
+ ]
176
+ };
177
+ });
178
+ for (const toolConfig of spec.tools) {
179
+ const inputSchema = toolConfig.schema ? jsonSchemaToZodSafe(toolConfig.schema) : z2.object({});
180
+ server.registerTool(`${spec.meta.key}.${toolConfig.name}`, {
181
+ description: toolConfig.description ?? `Execute ${toolConfig.name} tool`,
182
+ inputSchema
183
+ }, async (args) => {
184
+ const result = await agent.generate({
185
+ prompt: `Execute the ${toolConfig.name} tool with the following arguments: ${JSON.stringify(args)}`
186
+ });
187
+ return {
188
+ content: [
189
+ {
190
+ type: "text",
191
+ text: result.text
192
+ }
193
+ ]
194
+ };
195
+ });
196
+ }
197
+ return server;
198
+ }
199
+ function createAgentMcpServer(config) {
200
+ return agentToMcpServer(config.agent, config.spec);
201
+ }
202
+ export {
203
+ createAgentMcpServer,
204
+ agentToMcpServer
205
+ };
@@ -0,0 +1,197 @@
1
+ import { createRequire } from "node:module";
2
+ var __defProp = Object.defineProperty;
3
+ var __export = (target, all) => {
4
+ for (var name in all)
5
+ __defProp(target, name, {
6
+ get: all[name],
7
+ enumerable: true,
8
+ configurable: true,
9
+ set: (newValue) => all[name] = () => newValue
10
+ });
11
+ };
12
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
13
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
14
+
15
+ // src/schema/json-schema-to-zod.ts
16
+ import { z } from "zod";
17
+ function jsonSchemaToZod(schema) {
18
+ const s = schema;
19
+ const makeNullable = (zodSchema) => {
20
+ return s.nullable ? z.union([zodSchema, z.null()]) : zodSchema;
21
+ };
22
+ if (s.const !== undefined) {
23
+ return z.literal(s.const);
24
+ }
25
+ if (s.enum) {
26
+ const values = s.enum;
27
+ return makeNullable(z.enum(values.map(String)));
28
+ }
29
+ if (s.anyOf && s.anyOf.length > 0) {
30
+ const schemas = s.anyOf.map((sub) => jsonSchemaToZod(sub));
31
+ if (schemas.length === 1)
32
+ return schemas[0] ?? z.unknown();
33
+ return z.union([
34
+ schemas[0] ?? z.unknown(),
35
+ schemas[1] ?? z.unknown(),
36
+ ...schemas.slice(2)
37
+ ]);
38
+ }
39
+ if (s.oneOf && s.oneOf.length > 0) {
40
+ const schemas = s.oneOf.map((sub) => jsonSchemaToZod(sub));
41
+ if (schemas.length === 1)
42
+ return schemas[0] ?? z.unknown();
43
+ return z.union([
44
+ schemas[0] ?? z.unknown(),
45
+ schemas[1] ?? z.unknown(),
46
+ ...schemas.slice(2)
47
+ ]);
48
+ }
49
+ if (s.allOf && s.allOf.length > 0) {
50
+ const schemas = s.allOf.map((sub) => jsonSchemaToZod(sub));
51
+ return schemas.reduce((acc, curr) => z.intersection(acc, curr));
52
+ }
53
+ switch (s.type) {
54
+ case "string":
55
+ return makeNullable(buildStringSchema(s));
56
+ case "number":
57
+ case "integer":
58
+ return makeNullable(buildNumberSchema(s));
59
+ case "boolean":
60
+ return makeNullable(z.boolean());
61
+ case "null":
62
+ return z.null();
63
+ case "array":
64
+ return makeNullable(buildArraySchema(s));
65
+ case "object":
66
+ return makeNullable(buildObjectSchema(s));
67
+ default:
68
+ return z.unknown();
69
+ }
70
+ }
71
+ function buildStringSchema(schema) {
72
+ let zodSchema = z.string();
73
+ if (schema.description) {
74
+ zodSchema = zodSchema.describe(schema.description);
75
+ }
76
+ switch (schema.format) {
77
+ case "email":
78
+ zodSchema = zodSchema.email();
79
+ break;
80
+ case "uri":
81
+ case "url":
82
+ zodSchema = zodSchema.url();
83
+ break;
84
+ case "uuid":
85
+ zodSchema = zodSchema.uuid();
86
+ break;
87
+ case "date-time":
88
+ zodSchema = zodSchema.datetime();
89
+ break;
90
+ case "date":
91
+ zodSchema = zodSchema.date();
92
+ break;
93
+ }
94
+ if (schema.minLength !== undefined) {
95
+ zodSchema = zodSchema.min(schema.minLength);
96
+ }
97
+ if (schema.maxLength !== undefined) {
98
+ zodSchema = zodSchema.max(schema.maxLength);
99
+ }
100
+ if (schema.pattern) {
101
+ zodSchema = zodSchema.regex(new RegExp(schema.pattern));
102
+ }
103
+ return zodSchema;
104
+ }
105
+ function buildNumberSchema(schema) {
106
+ let zodSchema = schema.type === "integer" ? z.number().int() : z.number();
107
+ if (schema.description) {
108
+ zodSchema = zodSchema.describe(schema.description);
109
+ }
110
+ if (schema.minimum !== undefined) {
111
+ zodSchema = zodSchema.min(schema.minimum);
112
+ }
113
+ if (schema.maximum !== undefined) {
114
+ zodSchema = zodSchema.max(schema.maximum);
115
+ }
116
+ return zodSchema;
117
+ }
118
+ function buildArraySchema(schema) {
119
+ const itemsSchema = schema.items ? jsonSchemaToZod(schema.items) : z.unknown();
120
+ let zodSchema = z.array(itemsSchema);
121
+ if (schema.description) {
122
+ zodSchema = zodSchema.describe(schema.description);
123
+ }
124
+ return zodSchema;
125
+ }
126
+ function buildObjectSchema(schema) {
127
+ const properties = schema.properties ?? {};
128
+ const required = new Set(schema.required ?? []);
129
+ const shape = {};
130
+ for (const [key, propSchema] of Object.entries(properties)) {
131
+ const zodProp = jsonSchemaToZod(propSchema);
132
+ shape[key] = required.has(key) ? zodProp : zodProp.optional();
133
+ }
134
+ let zodSchema = z.object(shape);
135
+ if (schema.description) {
136
+ zodSchema = zodSchema.describe(schema.description);
137
+ }
138
+ return zodSchema;
139
+ }
140
+ function jsonSchemaToZodSafe(schema) {
141
+ if (!schema || Object.keys(schema).length === 0) {
142
+ return z.object({});
143
+ }
144
+ return jsonSchemaToZod(schema);
145
+ }
146
+ var init_json_schema_to_zod = () => {};
147
+
148
+ // src/tools/tool-adapter.ts
149
+ import { tool } from "ai";
150
+ function specToolToAISDKTool(specTool, handler, context = {}) {
151
+ return tool({
152
+ description: specTool.description ?? specTool.name,
153
+ inputSchema: jsonSchemaToZodSafe(specTool.schema),
154
+ needsApproval: specTool.requiresApproval ?? !specTool.automationSafe,
155
+ execute: async (input) => {
156
+ const result = await handler(input, {
157
+ agentId: context.agentId ?? "unknown",
158
+ sessionId: context.sessionId ?? "unknown",
159
+ tenantId: context.tenantId,
160
+ actorId: context.actorId,
161
+ metadata: context.metadata,
162
+ signal: context.signal
163
+ });
164
+ return typeof result === "string" ? result : JSON.stringify(result);
165
+ }
166
+ });
167
+ }
168
+ function specToolsToAISDKTools(specTools, handlers, context = {}) {
169
+ const tools = {};
170
+ for (const specTool of specTools) {
171
+ const handler = handlers.get(specTool.name);
172
+ if (!handler) {
173
+ throw new Error(`Missing handler for tool: ${specTool.name}`);
174
+ }
175
+ tools[specTool.name] = specToolToAISDKTool(specTool, handler, context);
176
+ }
177
+ return tools;
178
+ }
179
+ function createToolHandler(handler) {
180
+ return async (input, context) => {
181
+ return handler(input, context);
182
+ };
183
+ }
184
+ function buildToolHandlers(handlersObj) {
185
+ return new Map(Object.entries(handlersObj));
186
+ }
187
+ var init_tool_adapter = __esm(() => {
188
+ init_json_schema_to_zod();
189
+ });
190
+ init_tool_adapter();
191
+
192
+ export {
193
+ specToolsToAISDKTools,
194
+ specToolToAISDKTool,
195
+ createToolHandler,
196
+ buildToolHandlers
197
+ };
File without changes
@@ -1,58 +1,65 @@
1
- import { AgentSpec } from "../../spec/spec.js";
2
- import { ClaudeAgentSDKConfig, ExternalAgentContext, ExternalAgentProvider, ExternalExecuteParams, ExternalExecuteResult, ExternalStreamChunk } from "../types.js";
3
-
4
- //#region src/providers/claude-agent-sdk/adapter.d.ts
5
-
1
+ /**
2
+ * Claude Agent SDK Provider
3
+ *
4
+ * Enables ContractSpec agents to leverage Claude's agentic capabilities:
5
+ * - Computer use (file editing, bash execution)
6
+ * - Extended thinking for complex reasoning
7
+ * - Agentic search and subagents
8
+ * - MCP server integration
9
+ *
10
+ * This adapter wraps @anthropic-ai/claude-agent-sdk to work as a backend
11
+ * for ContractSpec agents.
12
+ */
13
+ import type { AgentSpec } from '../../spec/spec';
14
+ import type { ExternalAgentProvider, ExternalAgentContext, ExternalExecuteParams, ExternalExecuteResult, ExternalStreamChunk, ClaudeAgentSDKConfig } from '../types';
6
15
  /**
7
16
  * Claude Agent SDK Provider implementation.
8
17
  */
9
- declare class ClaudeAgentSDKProvider implements ExternalAgentProvider {
10
- readonly name = "claude-agent-sdk";
11
- readonly version = "1.0.0";
12
- private config;
13
- private sdkAvailable;
14
- constructor(config?: ClaudeAgentSDKConfig);
15
- /**
16
- * Check if Claude Agent SDK is available.
17
- */
18
- isAvailable(): boolean;
19
- /**
20
- * Create an execution context from an AgentSpec.
21
- */
22
- createContext(spec: AgentSpec): Promise<ExternalAgentContext>;
23
- /**
24
- * Execute a prompt using Claude Agent SDK.
25
- */
26
- execute(context: ExternalAgentContext, params: ExternalExecuteParams): Promise<ExternalExecuteResult>;
27
- /**
28
- * Stream execution with real-time updates.
29
- */
30
- stream(context: ExternalAgentContext, params: ExternalExecuteParams): AsyncIterable<ExternalStreamChunk>;
31
- /**
32
- * Load the Claude Agent SDK dynamically.
33
- */
34
- private loadSDK;
35
- /**
36
- * Prepare tools for Claude Agent SDK format.
37
- */
38
- private prepareToolsForSDK;
39
- /**
40
- * Execute a single tool.
41
- */
42
- private executeTool;
43
- /**
44
- * Execute multiple tools.
45
- */
46
- private executeTools;
47
- /**
48
- * Extract text content from response.
49
- */
50
- private extractTextContent;
51
- /**
52
- * Map Claude Agent SDK stop reason to ContractSpec finish reason.
53
- */
54
- private mapStopReason;
18
+ export declare class ClaudeAgentSDKProvider implements ExternalAgentProvider {
19
+ readonly name = "claude-agent-sdk";
20
+ readonly version = "1.0.0";
21
+ private config;
22
+ private sdkAvailable;
23
+ constructor(config?: ClaudeAgentSDKConfig);
24
+ /**
25
+ * Check if Claude Agent SDK is available.
26
+ */
27
+ isAvailable(): boolean;
28
+ /**
29
+ * Create an execution context from an AgentSpec.
30
+ */
31
+ createContext(spec: AgentSpec): Promise<ExternalAgentContext>;
32
+ /**
33
+ * Execute a prompt using Claude Agent SDK.
34
+ */
35
+ execute(context: ExternalAgentContext, params: ExternalExecuteParams): Promise<ExternalExecuteResult>;
36
+ /**
37
+ * Stream execution with real-time updates.
38
+ */
39
+ stream(context: ExternalAgentContext, params: ExternalExecuteParams): AsyncIterable<ExternalStreamChunk>;
40
+ /**
41
+ * Load the Claude Agent SDK dynamically.
42
+ */
43
+ private loadSDK;
44
+ /**
45
+ * Prepare tools for Claude Agent SDK format.
46
+ */
47
+ private prepareToolsForSDK;
48
+ /**
49
+ * Execute a single tool.
50
+ */
51
+ private executeTool;
52
+ /**
53
+ * Execute multiple tools.
54
+ */
55
+ private executeTools;
56
+ /**
57
+ * Extract text content from response.
58
+ */
59
+ private extractTextContent;
60
+ /**
61
+ * Map Claude Agent SDK stop reason to ContractSpec finish reason.
62
+ */
63
+ private mapStopReason;
55
64
  }
56
- //#endregion
57
- export { ClaudeAgentSDKProvider };
58
65
  //# sourceMappingURL=adapter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","names":[],"sources":["../../../src/providers/claude-agent-sdk/adapter.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAqD+C,cAAlC,sBAAA,YAAkC,qBAAA,CAAA;EAAqB,SAAA,IAAA,GAAA,kBAAA;;;;uBAO9C;;;;;;;;sBAoCM,YAAY,QAAQ;;;;mBAwDnC,8BACD,wBACP,QAAQ;;;;kBAuGA,8BACD,wBACP,cAAc"}
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/providers/claude-agent-sdk/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGjD,OAAO,KAAK,EACV,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,mBAAmB,EAEnB,oBAAoB,EAErB,MAAM,UAAU,CAAC;AAyBlB;;GAEG;AACH,qBAAa,sBAAuB,YAAW,qBAAqB;IAClE,QAAQ,CAAC,IAAI,sBAAsB;IACnC,QAAQ,CAAC,OAAO,WAAW;IAE3B,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,YAAY,CAAwB;gBAEhC,MAAM,GAAE,oBAAyB;IAW7C;;OAEG;IACH,WAAW,IAAI,OAAO;IAmBtB;;OAEG;IACG,aAAa,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAoDnE;;OAEG;IACG,OAAO,CACX,OAAO,EAAE,oBAAoB,EAC7B,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,qBAAqB,CAAC;IAmGjC;;OAEG;IACI,MAAM,CACX,OAAO,EAAE,oBAAoB,EAC7B,MAAM,EAAE,qBAAqB,GAC5B,aAAa,CAAC,mBAAmB,CAAC;IAkHrC;;OAEG;YACW,OAAO;IAarB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IA6B1B;;OAEG;YACW,WAAW;IA8BzB;;OAEG;YACW,YAAY;IAU1B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAgB1B;;OAEG;IACH,OAAO,CAAC,aAAa;CAetB"}