@contractspec/lib.ai-agent 5.0.5 → 7.0.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/README.md +41 -0
- package/dist/agent/agent-factory.d.ts +13 -0
- package/dist/agent/agent-factory.js +290 -63
- package/dist/agent/contract-spec-agent.d.ts +9 -0
- package/dist/agent/contract-spec-agent.js +287 -63
- package/dist/agent/index.js +353 -129
- package/dist/agent/json-runner.js +290 -66
- package/dist/agent/unified-agent.js +350 -126
- package/dist/exporters/claude-agent-exporter.js +11 -0
- package/dist/exporters/index.js +11 -0
- package/dist/exporters/opencode-exporter.js +11 -0
- package/dist/index.js +11 -0
- package/dist/interop/index.js +24 -2
- package/dist/interop/spec-consumer.js +11 -0
- package/dist/interop/tool-consumer.js +13 -2
- package/dist/node/agent/agent-factory.js +290 -63
- package/dist/node/agent/contract-spec-agent.js +287 -63
- package/dist/node/agent/index.js +353 -129
- package/dist/node/agent/json-runner.js +290 -66
- package/dist/node/agent/unified-agent.js +350 -126
- package/dist/node/exporters/claude-agent-exporter.js +11 -0
- package/dist/node/exporters/index.js +11 -0
- package/dist/node/exporters/opencode-exporter.js +11 -0
- package/dist/node/index.js +11 -0
- package/dist/node/interop/index.js +24 -2
- package/dist/node/interop/spec-consumer.js +11 -0
- package/dist/node/interop/tool-consumer.js +13 -2
- package/dist/node/providers/claude-agent-sdk/adapter.js +11 -0
- package/dist/node/providers/claude-agent-sdk/index.js +11 -0
- package/dist/node/providers/index.js +11 -0
- package/dist/node/providers/opencode-sdk/adapter.js +11 -0
- package/dist/node/providers/opencode-sdk/index.js +11 -0
- package/dist/node/spec/index.js +11 -0
- package/dist/node/spec/spec.js +11 -0
- package/dist/node/tools/agent-memory-store.js +24 -0
- package/dist/node/tools/in-memory-agent-memory-store.js +236 -0
- package/dist/node/tools/index.js +463 -42
- package/dist/node/tools/memory-tools.js +45 -0
- package/dist/node/tools/operation-tool-handler.js +35 -0
- package/dist/node/tools/subagent-tool.js +95 -0
- package/dist/node/tools/tool-adapter.js +192 -25
- package/dist/providers/claude-agent-sdk/adapter.js +11 -0
- package/dist/providers/claude-agent-sdk/index.js +11 -0
- package/dist/providers/index.js +11 -0
- package/dist/providers/opencode-sdk/adapter.js +11 -0
- package/dist/providers/opencode-sdk/index.js +11 -0
- package/dist/spec/index.js +11 -0
- package/dist/spec/spec.d.ts +69 -1
- package/dist/spec/spec.js +11 -0
- package/dist/tools/agent-memory-store.d.ts +26 -0
- package/dist/tools/agent-memory-store.js +24 -0
- package/dist/tools/agent-memory-store.test.d.ts +1 -0
- package/dist/tools/in-memory-agent-memory-store.d.ts +18 -0
- package/dist/tools/in-memory-agent-memory-store.js +236 -0
- package/dist/tools/index.d.ts +5 -0
- package/dist/tools/index.js +463 -42
- package/dist/tools/mcp-client.browser.d.ts +6 -6
- package/dist/tools/memory-tools.d.ts +29 -0
- package/dist/tools/memory-tools.js +45 -0
- package/dist/tools/operation-tool-handler.d.ts +24 -0
- package/dist/tools/operation-tool-handler.js +35 -0
- package/dist/tools/subagent-tool.d.ts +66 -0
- package/dist/tools/subagent-tool.js +95 -0
- package/dist/tools/tool-adapter.d.ts +26 -10
- package/dist/tools/tool-adapter.js +192 -25
- package/dist/types.d.ts +9 -3
- package/package.json +67 -7
|
@@ -2156,6 +2156,17 @@ function defineAgent(spec) {
|
|
|
2156
2156
|
}));
|
|
2157
2157
|
}
|
|
2158
2158
|
toolNames.add(tool.name);
|
|
2159
|
+
if (tool.subagentRef && tool.operationRef) {
|
|
2160
|
+
throw new Error(`Agent ${spec.meta.key} tool "${tool.name}" cannot have both subagentRef and operationRef. Use one.`);
|
|
2161
|
+
}
|
|
2162
|
+
const outputRefCount = [
|
|
2163
|
+
tool.outputPresentation,
|
|
2164
|
+
tool.outputForm,
|
|
2165
|
+
tool.outputDataView
|
|
2166
|
+
].filter(Boolean).length;
|
|
2167
|
+
if (outputRefCount > 1) {
|
|
2168
|
+
throw new Error(`Agent ${spec.meta.key} tool "${tool.name}" has multiple output refs (outputPresentation, outputForm, outputDataView). Use at most one.`);
|
|
2169
|
+
}
|
|
2159
2170
|
}
|
|
2160
2171
|
return Object.freeze(spec);
|
|
2161
2172
|
}
|
package/dist/exporters/index.js
CHANGED
|
@@ -2156,6 +2156,17 @@ function defineAgent(spec) {
|
|
|
2156
2156
|
}));
|
|
2157
2157
|
}
|
|
2158
2158
|
toolNames.add(tool.name);
|
|
2159
|
+
if (tool.subagentRef && tool.operationRef) {
|
|
2160
|
+
throw new Error(`Agent ${spec.meta.key} tool "${tool.name}" cannot have both subagentRef and operationRef. Use one.`);
|
|
2161
|
+
}
|
|
2162
|
+
const outputRefCount = [
|
|
2163
|
+
tool.outputPresentation,
|
|
2164
|
+
tool.outputForm,
|
|
2165
|
+
tool.outputDataView
|
|
2166
|
+
].filter(Boolean).length;
|
|
2167
|
+
if (outputRefCount > 1) {
|
|
2168
|
+
throw new Error(`Agent ${spec.meta.key} tool "${tool.name}" has multiple output refs (outputPresentation, outputForm, outputDataView). Use at most one.`);
|
|
2169
|
+
}
|
|
2159
2170
|
}
|
|
2160
2171
|
return Object.freeze(spec);
|
|
2161
2172
|
}
|
|
@@ -2156,6 +2156,17 @@ function defineAgent(spec) {
|
|
|
2156
2156
|
}));
|
|
2157
2157
|
}
|
|
2158
2158
|
toolNames.add(tool.name);
|
|
2159
|
+
if (tool.subagentRef && tool.operationRef) {
|
|
2160
|
+
throw new Error(`Agent ${spec.meta.key} tool "${tool.name}" cannot have both subagentRef and operationRef. Use one.`);
|
|
2161
|
+
}
|
|
2162
|
+
const outputRefCount = [
|
|
2163
|
+
tool.outputPresentation,
|
|
2164
|
+
tool.outputForm,
|
|
2165
|
+
tool.outputDataView
|
|
2166
|
+
].filter(Boolean).length;
|
|
2167
|
+
if (outputRefCount > 1) {
|
|
2168
|
+
throw new Error(`Agent ${spec.meta.key} tool "${tool.name}" has multiple output refs (outputPresentation, outputForm, outputDataView). Use at most one.`);
|
|
2169
|
+
}
|
|
2159
2170
|
}
|
|
2160
2171
|
return Object.freeze(spec);
|
|
2161
2172
|
}
|
package/dist/index.js
CHANGED
|
@@ -2156,6 +2156,17 @@ function defineAgent(spec) {
|
|
|
2156
2156
|
}));
|
|
2157
2157
|
}
|
|
2158
2158
|
toolNames.add(tool.name);
|
|
2159
|
+
if (tool.subagentRef && tool.operationRef) {
|
|
2160
|
+
throw new Error(`Agent ${spec.meta.key} tool "${tool.name}" cannot have both subagentRef and operationRef. Use one.`);
|
|
2161
|
+
}
|
|
2162
|
+
const outputRefCount = [
|
|
2163
|
+
tool.outputPresentation,
|
|
2164
|
+
tool.outputForm,
|
|
2165
|
+
tool.outputDataView
|
|
2166
|
+
].filter(Boolean).length;
|
|
2167
|
+
if (outputRefCount > 1) {
|
|
2168
|
+
throw new Error(`Agent ${spec.meta.key} tool "${tool.name}" has multiple output refs (outputPresentation, outputForm, outputDataView). Use at most one.`);
|
|
2169
|
+
}
|
|
2159
2170
|
}
|
|
2160
2171
|
return Object.freeze(spec);
|
|
2161
2172
|
}
|
package/dist/interop/index.js
CHANGED
|
@@ -2156,6 +2156,17 @@ function defineAgent(spec) {
|
|
|
2156
2156
|
}));
|
|
2157
2157
|
}
|
|
2158
2158
|
toolNames.add(tool.name);
|
|
2159
|
+
if (tool.subagentRef && tool.operationRef) {
|
|
2160
|
+
throw new Error(`Agent ${spec.meta.key} tool "${tool.name}" cannot have both subagentRef and operationRef. Use one.`);
|
|
2161
|
+
}
|
|
2162
|
+
const outputRefCount = [
|
|
2163
|
+
tool.outputPresentation,
|
|
2164
|
+
tool.outputForm,
|
|
2165
|
+
tool.outputDataView
|
|
2166
|
+
].filter(Boolean).length;
|
|
2167
|
+
if (outputRefCount > 1) {
|
|
2168
|
+
throw new Error(`Agent ${spec.meta.key} tool "${tool.name}" has multiple output refs (outputPresentation, outputForm, outputDataView). Use at most one.`);
|
|
2169
|
+
}
|
|
2159
2170
|
}
|
|
2160
2171
|
return Object.freeze(spec);
|
|
2161
2172
|
}
|
|
@@ -2678,6 +2689,17 @@ function createSingleSpecConsumer(spec, options) {
|
|
|
2678
2689
|
init_tool_bridge();
|
|
2679
2690
|
init_tool_bridge2();
|
|
2680
2691
|
init_i18n();
|
|
2692
|
+
async function resolveToolResult(result) {
|
|
2693
|
+
const resolved = await result;
|
|
2694
|
+
if (typeof resolved === "object" && resolved !== null && typeof resolved.next === "function" && typeof resolved[Symbol.asyncIterator] === "function") {
|
|
2695
|
+
let last;
|
|
2696
|
+
for await (const value of resolved) {
|
|
2697
|
+
last = value;
|
|
2698
|
+
}
|
|
2699
|
+
return typeof last === "string" ? last : JSON.stringify(last ?? "");
|
|
2700
|
+
}
|
|
2701
|
+
return typeof resolved === "string" ? resolved : JSON.stringify(resolved ?? "");
|
|
2702
|
+
}
|
|
2681
2703
|
|
|
2682
2704
|
class MCPToolServer {
|
|
2683
2705
|
tools;
|
|
@@ -2738,7 +2760,7 @@ class MCPToolServer {
|
|
|
2738
2760
|
metadata: context?.metadata,
|
|
2739
2761
|
signal: context?.signal
|
|
2740
2762
|
};
|
|
2741
|
-
return
|
|
2763
|
+
return resolveToolResult(tool.handler(args, fullContext));
|
|
2742
2764
|
}
|
|
2743
2765
|
getMCPToolDefinitions() {
|
|
2744
2766
|
const definitions = [];
|
|
@@ -2853,7 +2875,7 @@ class ContractSpecToolConsumer {
|
|
|
2853
2875
|
metadata: context?.metadata,
|
|
2854
2876
|
signal: context?.signal
|
|
2855
2877
|
};
|
|
2856
|
-
return
|
|
2878
|
+
return resolveToolResult(tool.handler(args, fullContext));
|
|
2857
2879
|
}
|
|
2858
2880
|
addTool(config, handler) {
|
|
2859
2881
|
this.tools.set(config.name, { config, handler });
|
|
@@ -2156,6 +2156,17 @@ function defineAgent(spec) {
|
|
|
2156
2156
|
}));
|
|
2157
2157
|
}
|
|
2158
2158
|
toolNames.add(tool.name);
|
|
2159
|
+
if (tool.subagentRef && tool.operationRef) {
|
|
2160
|
+
throw new Error(`Agent ${spec.meta.key} tool "${tool.name}" cannot have both subagentRef and operationRef. Use one.`);
|
|
2161
|
+
}
|
|
2162
|
+
const outputRefCount = [
|
|
2163
|
+
tool.outputPresentation,
|
|
2164
|
+
tool.outputForm,
|
|
2165
|
+
tool.outputDataView
|
|
2166
|
+
].filter(Boolean).length;
|
|
2167
|
+
if (outputRefCount > 1) {
|
|
2168
|
+
throw new Error(`Agent ${spec.meta.key} tool "${tool.name}" has multiple output refs (outputPresentation, outputForm, outputDataView). Use at most one.`);
|
|
2169
|
+
}
|
|
2159
2170
|
}
|
|
2160
2171
|
return Object.freeze(spec);
|
|
2161
2172
|
}
|
|
@@ -2357,6 +2357,17 @@ var init_tool_bridge2 = __esm(() => {
|
|
|
2357
2357
|
init_tool_bridge();
|
|
2358
2358
|
init_tool_bridge2();
|
|
2359
2359
|
init_i18n();
|
|
2360
|
+
async function resolveToolResult(result) {
|
|
2361
|
+
const resolved = await result;
|
|
2362
|
+
if (typeof resolved === "object" && resolved !== null && typeof resolved.next === "function" && typeof resolved[Symbol.asyncIterator] === "function") {
|
|
2363
|
+
let last;
|
|
2364
|
+
for await (const value of resolved) {
|
|
2365
|
+
last = value;
|
|
2366
|
+
}
|
|
2367
|
+
return typeof last === "string" ? last : JSON.stringify(last ?? "");
|
|
2368
|
+
}
|
|
2369
|
+
return typeof resolved === "string" ? resolved : JSON.stringify(resolved ?? "");
|
|
2370
|
+
}
|
|
2360
2371
|
|
|
2361
2372
|
class MCPToolServer {
|
|
2362
2373
|
tools;
|
|
@@ -2417,7 +2428,7 @@ class MCPToolServer {
|
|
|
2417
2428
|
metadata: context?.metadata,
|
|
2418
2429
|
signal: context?.signal
|
|
2419
2430
|
};
|
|
2420
|
-
return
|
|
2431
|
+
return resolveToolResult(tool.handler(args, fullContext));
|
|
2421
2432
|
}
|
|
2422
2433
|
getMCPToolDefinitions() {
|
|
2423
2434
|
const definitions = [];
|
|
@@ -2532,7 +2543,7 @@ class ContractSpecToolConsumer {
|
|
|
2532
2543
|
metadata: context?.metadata,
|
|
2533
2544
|
signal: context?.signal
|
|
2534
2545
|
};
|
|
2535
|
-
return
|
|
2546
|
+
return resolveToolResult(tool.handler(args, fullContext));
|
|
2536
2547
|
}
|
|
2537
2548
|
addTool(config, handler) {
|
|
2538
2549
|
this.tools.set(config.name, { config, handler });
|