@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.
- package/dist/agent/agent-factory.d.ts +67 -72
- package/dist/agent/agent-factory.d.ts.map +1 -1
- package/dist/agent/agent-factory.js +658 -100
- package/dist/agent/agent.test.d.ts +2 -0
- package/dist/agent/agent.test.d.ts.map +1 -0
- package/dist/agent/contract-spec-agent.d.ts +49 -55
- package/dist/agent/contract-spec-agent.d.ts.map +1 -1
- package/dist/agent/contract-spec-agent.js +605 -146
- package/dist/agent/index.d.ts +4 -3
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +2102 -3
- package/dist/agent/json-runner.d.ts +18 -0
- package/dist/agent/json-runner.d.ts.map +1 -0
- package/dist/agent/json-runner.js +684 -0
- package/dist/agent/json-runner.test.d.ts +2 -0
- package/dist/agent/json-runner.test.d.ts.map +1 -0
- package/dist/agent/unified-agent.d.ts +132 -99
- package/dist/agent/unified-agent.d.ts.map +1 -1
- package/dist/agent/unified-agent.js +2012 -260
- package/dist/approval/index.d.ts +3 -2
- package/dist/approval/index.d.ts.map +1 -0
- package/dist/approval/index.js +128 -2
- package/dist/approval/workflow.d.ts +106 -110
- package/dist/approval/workflow.d.ts.map +1 -1
- package/dist/approval/workflow.js +126 -157
- package/dist/exporters/claude-agent-exporter.d.ts +50 -49
- package/dist/exporters/claude-agent-exporter.d.ts.map +1 -1
- package/dist/exporters/claude-agent-exporter.js +258 -203
- package/dist/exporters/index.d.ts +28 -4
- package/dist/exporters/index.d.ts.map +1 -0
- package/dist/exporters/index.js +737 -3
- package/dist/exporters/opencode-exporter.d.ts +47 -46
- package/dist/exporters/opencode-exporter.d.ts.map +1 -1
- package/dist/exporters/opencode-exporter.js +507 -191
- package/dist/exporters/types.d.ts +171 -170
- package/dist/exporters/types.d.ts.map +1 -1
- package/dist/exporters/types.js +1 -0
- package/dist/index.d.ts +15 -37
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3337 -31
- package/dist/interop/index.d.ts +48 -4
- package/dist/interop/index.d.ts.map +1 -0
- package/dist/interop/index.js +709 -3
- package/dist/interop/spec-consumer.d.ts +57 -54
- package/dist/interop/spec-consumer.d.ts.map +1 -1
- package/dist/interop/spec-consumer.js +302 -282
- package/dist/interop/tool-consumer.d.ts +57 -54
- package/dist/interop/tool-consumer.d.ts.map +1 -1
- package/dist/interop/tool-consumer.js +412 -213
- package/dist/interop/types.d.ts +173 -172
- package/dist/interop/types.d.ts.map +1 -1
- package/dist/interop/types.js +1 -0
- package/dist/knowledge/index.d.ts +2 -2
- package/dist/knowledge/index.d.ts.map +1 -0
- package/dist/knowledge/index.js +66 -2
- package/dist/knowledge/injector.d.ts +16 -21
- package/dist/knowledge/injector.d.ts.map +1 -1
- package/dist/knowledge/injector.js +56 -47
- package/dist/memory/in-memory.d.ts +15 -19
- package/dist/memory/in-memory.d.ts.map +1 -1
- package/dist/memory/in-memory.js +152 -46
- package/dist/memory/index.d.ts +3 -3
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +155 -3
- package/dist/memory/manager.d.ts +32 -36
- package/dist/memory/manager.d.ts.map +1 -1
- package/dist/memory/manager.js +96 -71
- package/dist/memory/memory.test.d.ts +2 -0
- package/dist/memory/memory.test.d.ts.map +1 -0
- package/dist/node/agent/agent-factory.js +661 -0
- package/dist/node/agent/contract-spec-agent.js +607 -0
- package/dist/node/agent/index.js +2103 -0
- package/dist/node/agent/json-runner.js +684 -0
- package/dist/node/agent/unified-agent.js +2019 -0
- package/dist/node/approval/index.js +129 -0
- package/dist/node/approval/workflow.js +129 -0
- package/dist/node/exporters/claude-agent-exporter.js +265 -0
- package/dist/node/exporters/index.js +738 -0
- package/dist/node/exporters/opencode-exporter.js +516 -0
- package/dist/node/exporters/types.js +0 -0
- package/dist/node/index.js +3337 -0
- package/dist/node/interop/index.js +710 -0
- package/dist/node/interop/spec-consumer.js +307 -0
- package/dist/node/interop/tool-consumer.js +419 -0
- package/dist/node/interop/types.js +0 -0
- package/dist/node/knowledge/index.js +67 -0
- package/dist/node/knowledge/injector.js +67 -0
- package/dist/node/memory/in-memory.js +154 -0
- package/dist/node/memory/index.js +156 -0
- package/dist/node/memory/manager.js +105 -0
- package/dist/node/providers/claude-agent-sdk/adapter.js +624 -0
- package/dist/node/providers/claude-agent-sdk/index.js +673 -0
- package/dist/node/providers/claude-agent-sdk/session-bridge.js +149 -0
- package/dist/node/providers/claude-agent-sdk/tool-bridge.js +118 -0
- package/dist/node/providers/index.js +1261 -0
- package/dist/node/providers/opencode-sdk/adapter.js +669 -0
- package/dist/node/providers/opencode-sdk/agent-bridge.js +299 -0
- package/dist/node/providers/opencode-sdk/index.js +703 -0
- package/dist/node/providers/opencode-sdk/tool-bridge.js +141 -0
- package/dist/node/providers/registry.js +89 -0
- package/dist/node/providers/types.js +56 -0
- package/dist/node/schema/index.js +195 -0
- package/dist/node/schema/json-schema-to-zod.js +152 -0
- package/dist/node/schema/schema-output.js +190 -0
- package/dist/node/session/index.js +90 -0
- package/dist/node/session/store.js +90 -0
- package/dist/node/spec/index.js +85 -0
- package/dist/node/spec/registry.js +56 -0
- package/dist/node/spec/spec.js +44 -0
- package/dist/node/telemetry/adapter.js +85 -0
- package/dist/node/telemetry/index.js +86 -0
- package/dist/node/tools/index.js +345 -0
- package/dist/node/tools/knowledge-tool.js +74 -0
- package/dist/node/tools/mcp-client.js +47 -0
- package/dist/node/tools/mcp-server.js +205 -0
- package/dist/node/tools/tool-adapter.js +197 -0
- package/dist/node/types.js +0 -0
- package/dist/providers/claude-agent-sdk/adapter.d.ts +60 -53
- package/dist/providers/claude-agent-sdk/adapter.d.ts.map +1 -1
- package/dist/providers/claude-agent-sdk/adapter.js +622 -304
- package/dist/providers/claude-agent-sdk/index.d.ts +22 -4
- package/dist/providers/claude-agent-sdk/index.d.ts.map +1 -0
- package/dist/providers/claude-agent-sdk/index.js +672 -4
- package/dist/providers/claude-agent-sdk/session-bridge.d.ts +43 -41
- package/dist/providers/claude-agent-sdk/session-bridge.d.ts.map +1 -1
- package/dist/providers/claude-agent-sdk/session-bridge.js +121 -130
- package/dist/providers/claude-agent-sdk/tool-bridge.d.ts +63 -61
- package/dist/providers/claude-agent-sdk/tool-bridge.d.ts.map +1 -1
- package/dist/providers/claude-agent-sdk/tool-bridge.js +104 -108
- package/dist/providers/index.d.ts +28 -7
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +1261 -8
- package/dist/providers/opencode-sdk/adapter.d.ts +56 -49
- package/dist/providers/opencode-sdk/adapter.d.ts.map +1 -1
- package/dist/providers/opencode-sdk/adapter.js +667 -274
- package/dist/providers/opencode-sdk/agent-bridge.d.ts +62 -58
- package/dist/providers/opencode-sdk/agent-bridge.d.ts.map +1 -1
- package/dist/providers/opencode-sdk/agent-bridge.js +289 -155
- package/dist/providers/opencode-sdk/index.d.ts +22 -4
- package/dist/providers/opencode-sdk/index.d.ts.map +1 -0
- package/dist/providers/opencode-sdk/index.js +702 -4
- package/dist/providers/opencode-sdk/tool-bridge.d.ts +41 -43
- package/dist/providers/opencode-sdk/tool-bridge.d.ts.map +1 -1
- package/dist/providers/opencode-sdk/tool-bridge.js +121 -107
- package/dist/providers/registry.d.ts +10 -12
- package/dist/providers/registry.d.ts.map +1 -1
- package/dist/providers/registry.js +86 -49
- package/dist/providers/types.d.ts +169 -167
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/providers/types.js +54 -42
- package/dist/schema/index.d.ts +3 -3
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +194 -3
- package/dist/schema/json-schema-to-zod.d.ts +23 -27
- package/dist/schema/json-schema-to-zod.d.ts.map +1 -1
- package/dist/schema/json-schema-to-zod.js +138 -110
- package/dist/schema/schema-output.d.ts +29 -33
- package/dist/schema/schema-output.d.ts.map +1 -1
- package/dist/schema/schema-output.js +178 -53
- package/dist/session/index.d.ts +2 -2
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +89 -2
- package/dist/session/store.d.ts +51 -56
- package/dist/session/store.d.ts.map +1 -1
- package/dist/session/store.js +85 -74
- package/dist/spec/index.d.ts +3 -3
- package/dist/spec/index.d.ts.map +1 -0
- package/dist/spec/index.js +84 -3
- package/dist/spec/registry.d.ts +32 -37
- package/dist/spec/registry.d.ts.map +1 -1
- package/dist/spec/registry.js +51 -60
- package/dist/spec/spec.d.ts +80 -85
- package/dist/spec/spec.d.ts.map +1 -1
- package/dist/spec/spec.js +40 -26
- package/dist/telemetry/adapter.d.ts +33 -38
- package/dist/telemetry/adapter.d.ts.map +1 -1
- package/dist/telemetry/adapter.js +78 -96
- package/dist/telemetry/index.d.ts +2 -2
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +85 -2
- package/dist/tools/index.d.ts +5 -5
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +344 -5
- package/dist/tools/knowledge-tool.d.ts +4 -9
- package/dist/tools/knowledge-tool.d.ts.map +1 -1
- package/dist/tools/knowledge-tool.js +68 -48
- package/dist/tools/mcp-client.d.ts +17 -22
- package/dist/tools/mcp-client.d.ts.map +1 -1
- package/dist/tools/mcp-client.js +42 -53
- package/dist/tools/mcp-server.d.ts +14 -19
- package/dist/tools/mcp-server.d.ts.map +1 -1
- package/dist/tools/mcp-server.js +200 -64
- package/dist/tools/tool-adapter.d.ts +7 -12
- package/dist/tools/tool-adapter.d.ts.map +1 -1
- package/dist/tools/tool-adapter.js +187 -70
- package/dist/tools/tools.test.d.ts +2 -0
- package/dist/tools/tools.test.d.ts.map +1 -0
- package/dist/types.d.ts +108 -112
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/package.json +452 -92
- package/dist/_virtual/rolldown_runtime.js +0 -8
- package/dist/agent/agent-factory.js.map +0 -1
- package/dist/agent/contract-spec-agent.js.map +0 -1
- package/dist/agent/unified-agent.js.map +0 -1
- package/dist/approval/workflow.js.map +0 -1
- package/dist/exporters/claude-agent-exporter.js.map +0 -1
- package/dist/exporters/opencode-exporter.js.map +0 -1
- package/dist/interop/spec-consumer.js.map +0 -1
- package/dist/interop/tool-consumer.js.map +0 -1
- package/dist/knowledge/injector.js.map +0 -1
- package/dist/memory/in-memory.js.map +0 -1
- package/dist/memory/manager.js.map +0 -1
- package/dist/providers/claude-agent-sdk/adapter.js.map +0 -1
- package/dist/providers/claude-agent-sdk/session-bridge.js.map +0 -1
- package/dist/providers/claude-agent-sdk/tool-bridge.js.map +0 -1
- package/dist/providers/opencode-sdk/adapter.js.map +0 -1
- package/dist/providers/opencode-sdk/agent-bridge.js.map +0 -1
- package/dist/providers/opencode-sdk/tool-bridge.js.map +0 -1
- package/dist/providers/registry.js.map +0 -1
- package/dist/providers/types.js.map +0 -1
- package/dist/schema/json-schema-to-zod.js.map +0 -1
- package/dist/schema/schema-output.js.map +0 -1
- package/dist/session/store.js.map +0 -1
- package/dist/spec/registry.js.map +0 -1
- package/dist/spec/spec.js.map +0 -1
- package/dist/telemetry/adapter.js.map +0 -1
- package/dist/tools/knowledge-tool.js.map +0 -1
- package/dist/tools/mcp-client.js.map +0 -1
- package/dist/tools/mcp-server.js.map +0 -1
- 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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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","
|
|
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"}
|