@contractspec/lib.ai-agent 1.57.0 → 1.59.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 -71
- 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 +48 -52
- 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 -4
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +2102 -4
- package/dist/agent/json-runner.d.ts +15 -19
- package/dist/agent/json-runner.d.ts.map +1 -1
- package/dist/agent/json-runner.js +672 -57
- 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 -109
- package/dist/agent/unified-agent.d.ts.map +1 -1
- package/dist/agent/unified-agent.js +2011 -293
- 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 -48
- 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 -45
- 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 -169
- package/dist/exporters/types.d.ts.map +1 -1
- package/dist/exporters/types.js +1 -0
- package/dist/index.d.ts +15 -39
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3337 -32
- 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 -53
- 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 -53
- 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 -171
- 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 -20
- 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 -70
- 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 -52
- 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 -40
- 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 -60
- 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 -48
- 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 -57
- 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 -42
- 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 -11
- package/dist/providers/registry.d.ts.map +1 -1
- package/dist/providers/registry.js +86 -49
- package/dist/providers/types.d.ts +169 -166
- 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 -26
- 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 -32
- 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 -55
- 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 -36
- package/dist/spec/registry.d.ts.map +1 -1
- package/dist/spec/registry.js +51 -60
- package/dist/spec/spec.d.ts +80 -84
- package/dist/spec/spec.d.ts.map +1 -1
- package/dist/spec/spec.js +40 -26
- package/dist/telemetry/adapter.d.ts +33 -37
- 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 -8
- 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 -21
- 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 -18
- 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 -11
- 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 -111
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/package.json +448 -90
- 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/json-runner.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
|
@@ -1,287 +1,307 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* includeMetadata: true,
|
|
12
|
-
* });
|
|
13
|
-
*
|
|
14
|
-
* // Get markdown representation
|
|
15
|
-
* const markdown = consumer.getSpecMarkdown('my-agent.v1.0.0');
|
|
16
|
-
*
|
|
17
|
-
* // Get prompt for LLM
|
|
18
|
-
* const prompt = consumer.getSpecPrompt('my-agent.v1.0.0', {
|
|
19
|
-
* includeTools: true,
|
|
20
|
-
* });
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
var ContractSpecConsumer = class {
|
|
24
|
-
specs;
|
|
25
|
-
includeMetadata;
|
|
26
|
-
baseUrl;
|
|
27
|
-
constructor(config) {
|
|
28
|
-
this.specs = /* @__PURE__ */ new Map();
|
|
29
|
-
this.includeMetadata = config.includeMetadata ?? true;
|
|
30
|
-
this.baseUrl = config.baseUrl;
|
|
31
|
-
for (const spec of config.specs) {
|
|
32
|
-
const key = agentKey(spec.meta);
|
|
33
|
-
this.specs.set(key, spec);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Get a spec as markdown.
|
|
38
|
-
*/
|
|
39
|
-
getSpecMarkdown(specKey, options) {
|
|
40
|
-
const spec = this.specs.get(specKey);
|
|
41
|
-
if (!spec) throw new Error(`Spec not found: ${specKey}`);
|
|
42
|
-
const sections = [];
|
|
43
|
-
const opts = {
|
|
44
|
-
includeToc: options?.includeToc ?? true,
|
|
45
|
-
includeTools: options?.includeTools ?? true,
|
|
46
|
-
...options
|
|
47
|
-
};
|
|
48
|
-
if (opts.customHeader) {
|
|
49
|
-
sections.push(opts.customHeader);
|
|
50
|
-
sections.push("");
|
|
51
|
-
}
|
|
52
|
-
const specName = spec.meta.key;
|
|
53
|
-
sections.push(`# ${specName}`);
|
|
54
|
-
sections.push("");
|
|
55
|
-
if (spec.description) {
|
|
56
|
-
sections.push(spec.description);
|
|
57
|
-
sections.push("");
|
|
58
|
-
}
|
|
59
|
-
if (opts.includeToc) {
|
|
60
|
-
sections.push("## Table of Contents");
|
|
61
|
-
sections.push("");
|
|
62
|
-
sections.push("- [Overview](#overview)");
|
|
63
|
-
sections.push("- [Instructions](#instructions)");
|
|
64
|
-
if (opts.includeTools && spec.tools && spec.tools.length > 0) sections.push("- [Tools](#tools)");
|
|
65
|
-
if (spec.knowledge && spec.knowledge.length > 0) sections.push("- [Knowledge](#knowledge)");
|
|
66
|
-
sections.push("");
|
|
67
|
-
}
|
|
68
|
-
sections.push("## Overview");
|
|
69
|
-
sections.push("");
|
|
70
|
-
if (this.includeMetadata) {
|
|
71
|
-
sections.push(`- **Key**: \`${spec.meta.key}\``);
|
|
72
|
-
sections.push(`- **Version**: ${spec.meta.version}`);
|
|
73
|
-
if (spec.meta.stability) sections.push(`- **Stability**: ${spec.meta.stability}`);
|
|
74
|
-
if (spec.meta.owners && spec.meta.owners.length > 0) sections.push(`- **Owners**: ${spec.meta.owners.join(", ")}`);
|
|
75
|
-
if (spec.tags && spec.tags.length > 0) sections.push(`- **Tags**: ${spec.tags.join(", ")}`);
|
|
76
|
-
}
|
|
77
|
-
sections.push("");
|
|
78
|
-
sections.push("## Instructions");
|
|
79
|
-
sections.push("");
|
|
80
|
-
sections.push(spec.instructions);
|
|
81
|
-
sections.push("");
|
|
82
|
-
if (opts.includeTools && spec.tools && spec.tools.length > 0) {
|
|
83
|
-
sections.push("## Tools");
|
|
84
|
-
sections.push("");
|
|
85
|
-
for (const tool of spec.tools) {
|
|
86
|
-
sections.push(`### ${tool.name}`);
|
|
87
|
-
sections.push("");
|
|
88
|
-
if (tool.description) {
|
|
89
|
-
sections.push(tool.description);
|
|
90
|
-
sections.push("");
|
|
91
|
-
}
|
|
92
|
-
if (tool.schema) {
|
|
93
|
-
sections.push("**Schema:**");
|
|
94
|
-
sections.push("");
|
|
95
|
-
sections.push("```json");
|
|
96
|
-
sections.push(JSON.stringify(tool.schema, null, 2));
|
|
97
|
-
sections.push("```");
|
|
98
|
-
sections.push("");
|
|
99
|
-
}
|
|
100
|
-
if (tool.automationSafe !== void 0) {
|
|
101
|
-
sections.push(`**Automation Safe**: ${tool.automationSafe ? "Yes" : "No"}`);
|
|
102
|
-
sections.push("");
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
if (spec.knowledge && spec.knowledge.length > 0) {
|
|
107
|
-
sections.push("## Knowledge");
|
|
108
|
-
sections.push("");
|
|
109
|
-
for (const k of spec.knowledge) {
|
|
110
|
-
sections.push(`- **${k.key}**${k.required ? " (required)" : ""}`);
|
|
111
|
-
if (k.instructions) sections.push(` - ${k.instructions}`);
|
|
112
|
-
}
|
|
113
|
-
sections.push("");
|
|
114
|
-
}
|
|
115
|
-
if (spec.policy) {
|
|
116
|
-
sections.push("## Policy");
|
|
117
|
-
sections.push("");
|
|
118
|
-
if (spec.policy.confidence) sections.push(`- **Minimum Confidence**: ${spec.policy.confidence.min ?? .7}`);
|
|
119
|
-
if (spec.policy.escalation) {
|
|
120
|
-
const esc = spec.policy.escalation;
|
|
121
|
-
if (esc.confidenceThreshold) sections.push(`- **Escalation Threshold**: ${esc.confidenceThreshold}`);
|
|
122
|
-
if (esc.onToolFailure) sections.push("- **Escalate on Tool Failure**: Yes");
|
|
123
|
-
if (esc.onTimeout) sections.push("- **Escalate on Timeout**: Yes");
|
|
124
|
-
}
|
|
125
|
-
sections.push("");
|
|
126
|
-
}
|
|
127
|
-
return sections.join("\n");
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Get a spec as an LLM prompt.
|
|
131
|
-
*/
|
|
132
|
-
getSpecPrompt(specKey, options) {
|
|
133
|
-
const spec = this.specs.get(specKey);
|
|
134
|
-
if (!spec) throw new Error(`Spec not found: ${specKey}`);
|
|
135
|
-
const sections = [];
|
|
136
|
-
const opts = {
|
|
137
|
-
includeTools: options?.includeTools ?? true,
|
|
138
|
-
format: options?.format ?? "structured",
|
|
139
|
-
...options
|
|
140
|
-
};
|
|
141
|
-
sections.push("# Agent Identity");
|
|
142
|
-
sections.push("");
|
|
143
|
-
sections.push(`You are ${spec.meta.key} (v${spec.meta.version}).`);
|
|
144
|
-
sections.push("");
|
|
145
|
-
if (spec.description) {
|
|
146
|
-
sections.push("## Description");
|
|
147
|
-
sections.push("");
|
|
148
|
-
sections.push(spec.description);
|
|
149
|
-
sections.push("");
|
|
150
|
-
}
|
|
151
|
-
sections.push("## Instructions");
|
|
152
|
-
sections.push("");
|
|
153
|
-
sections.push(spec.instructions);
|
|
154
|
-
sections.push("");
|
|
155
|
-
if (opts.includeTools && spec.tools && spec.tools.length > 0) {
|
|
156
|
-
sections.push("## Available Tools");
|
|
157
|
-
sections.push("");
|
|
158
|
-
sections.push("You have access to the following tools:");
|
|
159
|
-
sections.push("");
|
|
160
|
-
for (const tool of spec.tools) {
|
|
161
|
-
sections.push(`### ${tool.name}`);
|
|
162
|
-
sections.push("");
|
|
163
|
-
if (tool.description) {
|
|
164
|
-
sections.push(tool.description);
|
|
165
|
-
sections.push("");
|
|
166
|
-
}
|
|
167
|
-
if (tool.schema && opts.format === "structured") {
|
|
168
|
-
sections.push("Parameters:");
|
|
169
|
-
sections.push("```json");
|
|
170
|
-
sections.push(JSON.stringify(tool.schema, null, 2));
|
|
171
|
-
sections.push("```");
|
|
172
|
-
sections.push("");
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
if (spec.knowledge && spec.knowledge.length > 0) {
|
|
177
|
-
const requiredKnowledge = spec.knowledge.filter((k) => k.required);
|
|
178
|
-
if (requiredKnowledge.length > 0) {
|
|
179
|
-
sections.push("## Knowledge Context");
|
|
180
|
-
sections.push("");
|
|
181
|
-
for (const k of requiredKnowledge) if (k.instructions) {
|
|
182
|
-
sections.push(k.instructions);
|
|
183
|
-
sections.push("");
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
if (options?.customContext) {
|
|
188
|
-
sections.push("## Additional Context");
|
|
189
|
-
sections.push("");
|
|
190
|
-
sections.push(options.customContext);
|
|
191
|
-
sections.push("");
|
|
192
|
-
}
|
|
193
|
-
return sections.join("\n");
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* List available specs.
|
|
197
|
-
*/
|
|
198
|
-
listSpecs(options) {
|
|
199
|
-
const results = [];
|
|
200
|
-
for (const [key, spec] of this.specs) {
|
|
201
|
-
if (options?.stability && spec.meta.stability !== options.stability) continue;
|
|
202
|
-
if (options?.tags && options.tags.length > 0) {
|
|
203
|
-
const specTags = spec.tags ?? [];
|
|
204
|
-
if (!options.tags.some((tag) => specTags.includes(tag))) continue;
|
|
205
|
-
}
|
|
206
|
-
results.push({
|
|
207
|
-
key,
|
|
208
|
-
name: spec.meta.key,
|
|
209
|
-
version: spec.meta.version,
|
|
210
|
-
description: spec.description,
|
|
211
|
-
stability: spec.meta.stability,
|
|
212
|
-
tags: spec.tags,
|
|
213
|
-
toolCount: spec.tools?.length ?? 0
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
return results;
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Query a spec by key.
|
|
220
|
-
*/
|
|
221
|
-
querySpec(specKey) {
|
|
222
|
-
const spec = this.specs.get(specKey);
|
|
223
|
-
if (!spec) return;
|
|
224
|
-
return {
|
|
225
|
-
key: specKey,
|
|
226
|
-
spec,
|
|
227
|
-
markdown: this.getSpecMarkdown(specKey),
|
|
228
|
-
prompt: this.getSpecPrompt(specKey)
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Check if a spec exists.
|
|
233
|
-
*/
|
|
234
|
-
hasSpec(specKey) {
|
|
235
|
-
return this.specs.has(specKey);
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Get a spec by key.
|
|
239
|
-
*/
|
|
240
|
-
getSpec(specKey) {
|
|
241
|
-
return this.specs.get(specKey);
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Get all specs.
|
|
245
|
-
*/
|
|
246
|
-
getAllSpecs() {
|
|
247
|
-
return Array.from(this.specs.values());
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Get spec count.
|
|
251
|
-
*/
|
|
252
|
-
getSpecCount() {
|
|
253
|
-
return this.specs.size;
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Add a spec to the consumer.
|
|
257
|
-
*/
|
|
258
|
-
addSpec(spec) {
|
|
259
|
-
const key = agentKey(spec.meta);
|
|
260
|
-
this.specs.set(key, spec);
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Remove a spec from the consumer.
|
|
264
|
-
*/
|
|
265
|
-
removeSpec(specKey) {
|
|
266
|
-
return this.specs.delete(specKey);
|
|
267
|
-
}
|
|
1
|
+
// @bun
|
|
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
|
+
});
|
|
268
11
|
};
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
12
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
13
|
+
var __require = import.meta.require;
|
|
14
|
+
|
|
15
|
+
// src/spec/spec.ts
|
|
16
|
+
function defineAgent(spec) {
|
|
17
|
+
if (!spec.meta?.key) {
|
|
18
|
+
throw new Error("Agent key is required");
|
|
19
|
+
}
|
|
20
|
+
if (typeof spec.meta.version !== "string") {
|
|
21
|
+
throw new Error(`Agent ${spec.meta.key} is missing a string version`);
|
|
22
|
+
}
|
|
23
|
+
if (!spec.instructions?.trim()) {
|
|
24
|
+
throw new Error(`Agent ${spec.meta.key} requires instructions`);
|
|
25
|
+
}
|
|
26
|
+
if (!spec.tools?.length) {
|
|
27
|
+
throw new Error(`Agent ${spec.meta.key} must expose at least one tool`);
|
|
28
|
+
}
|
|
29
|
+
const toolNames = new Set;
|
|
30
|
+
for (const tool of spec.tools) {
|
|
31
|
+
if (toolNames.has(tool.name)) {
|
|
32
|
+
throw new Error(`Agent ${spec.meta.key} has duplicate tool name: ${tool.name}`);
|
|
33
|
+
}
|
|
34
|
+
toolNames.add(tool.name);
|
|
35
|
+
}
|
|
36
|
+
return Object.freeze(spec);
|
|
37
|
+
}
|
|
38
|
+
function agentKey(meta) {
|
|
39
|
+
return `${meta.key}.v${meta.version}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// src/interop/spec-consumer.ts
|
|
43
|
+
class ContractSpecConsumer {
|
|
44
|
+
specs;
|
|
45
|
+
includeMetadata;
|
|
46
|
+
baseUrl;
|
|
47
|
+
constructor(config) {
|
|
48
|
+
this.specs = new Map;
|
|
49
|
+
this.includeMetadata = config.includeMetadata ?? true;
|
|
50
|
+
this.baseUrl = config.baseUrl;
|
|
51
|
+
for (const spec of config.specs) {
|
|
52
|
+
const key = agentKey(spec.meta);
|
|
53
|
+
this.specs.set(key, spec);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
getSpecMarkdown(specKey, options) {
|
|
57
|
+
const spec = this.specs.get(specKey);
|
|
58
|
+
if (!spec) {
|
|
59
|
+
throw new Error(`Spec not found: ${specKey}`);
|
|
60
|
+
}
|
|
61
|
+
const sections = [];
|
|
62
|
+
const opts = {
|
|
63
|
+
includeToc: options?.includeToc ?? true,
|
|
64
|
+
includeTools: options?.includeTools ?? true,
|
|
65
|
+
...options
|
|
66
|
+
};
|
|
67
|
+
if (opts.customHeader) {
|
|
68
|
+
sections.push(opts.customHeader);
|
|
69
|
+
sections.push("");
|
|
70
|
+
}
|
|
71
|
+
const specName = spec.meta.key;
|
|
72
|
+
sections.push(`# ${specName}`);
|
|
73
|
+
sections.push("");
|
|
74
|
+
if (spec.description) {
|
|
75
|
+
sections.push(spec.description);
|
|
76
|
+
sections.push("");
|
|
77
|
+
}
|
|
78
|
+
if (opts.includeToc) {
|
|
79
|
+
sections.push("## Table of Contents");
|
|
80
|
+
sections.push("");
|
|
81
|
+
sections.push("- [Overview](#overview)");
|
|
82
|
+
sections.push("- [Instructions](#instructions)");
|
|
83
|
+
if (opts.includeTools && spec.tools && spec.tools.length > 0) {
|
|
84
|
+
sections.push("- [Tools](#tools)");
|
|
85
|
+
}
|
|
86
|
+
if (spec.knowledge && spec.knowledge.length > 0) {
|
|
87
|
+
sections.push("- [Knowledge](#knowledge)");
|
|
88
|
+
}
|
|
89
|
+
sections.push("");
|
|
90
|
+
}
|
|
91
|
+
sections.push("## Overview");
|
|
92
|
+
sections.push("");
|
|
93
|
+
if (this.includeMetadata) {
|
|
94
|
+
sections.push(`- **Key**: \`${spec.meta.key}\``);
|
|
95
|
+
sections.push(`- **Version**: ${spec.meta.version}`);
|
|
96
|
+
if (spec.meta.stability) {
|
|
97
|
+
sections.push(`- **Stability**: ${spec.meta.stability}`);
|
|
98
|
+
}
|
|
99
|
+
if (spec.meta.owners && spec.meta.owners.length > 0) {
|
|
100
|
+
sections.push(`- **Owners**: ${spec.meta.owners.join(", ")}`);
|
|
101
|
+
}
|
|
102
|
+
if (spec.tags && spec.tags.length > 0) {
|
|
103
|
+
sections.push(`- **Tags**: ${spec.tags.join(", ")}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
sections.push("");
|
|
107
|
+
sections.push("## Instructions");
|
|
108
|
+
sections.push("");
|
|
109
|
+
sections.push(spec.instructions);
|
|
110
|
+
sections.push("");
|
|
111
|
+
if (opts.includeTools && spec.tools && spec.tools.length > 0) {
|
|
112
|
+
sections.push("## Tools");
|
|
113
|
+
sections.push("");
|
|
114
|
+
for (const tool of spec.tools) {
|
|
115
|
+
sections.push(`### ${tool.name}`);
|
|
116
|
+
sections.push("");
|
|
117
|
+
if (tool.description) {
|
|
118
|
+
sections.push(tool.description);
|
|
119
|
+
sections.push("");
|
|
120
|
+
}
|
|
121
|
+
if (tool.schema) {
|
|
122
|
+
sections.push("**Schema:**");
|
|
123
|
+
sections.push("");
|
|
124
|
+
sections.push("```json");
|
|
125
|
+
sections.push(JSON.stringify(tool.schema, null, 2));
|
|
126
|
+
sections.push("```");
|
|
127
|
+
sections.push("");
|
|
128
|
+
}
|
|
129
|
+
if (tool.automationSafe !== undefined) {
|
|
130
|
+
sections.push(`**Automation Safe**: ${tool.automationSafe ? "Yes" : "No"}`);
|
|
131
|
+
sections.push("");
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (spec.knowledge && spec.knowledge.length > 0) {
|
|
136
|
+
sections.push("## Knowledge");
|
|
137
|
+
sections.push("");
|
|
138
|
+
for (const k of spec.knowledge) {
|
|
139
|
+
sections.push(`- **${k.key}**${k.required ? " (required)" : ""}`);
|
|
140
|
+
if (k.instructions) {
|
|
141
|
+
sections.push(` - ${k.instructions}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
sections.push("");
|
|
145
|
+
}
|
|
146
|
+
if (spec.policy) {
|
|
147
|
+
sections.push("## Policy");
|
|
148
|
+
sections.push("");
|
|
149
|
+
if (spec.policy.confidence) {
|
|
150
|
+
sections.push(`- **Minimum Confidence**: ${spec.policy.confidence.min ?? 0.7}`);
|
|
151
|
+
}
|
|
152
|
+
if (spec.policy.escalation) {
|
|
153
|
+
const esc = spec.policy.escalation;
|
|
154
|
+
if (esc.confidenceThreshold) {
|
|
155
|
+
sections.push(`- **Escalation Threshold**: ${esc.confidenceThreshold}`);
|
|
156
|
+
}
|
|
157
|
+
if (esc.onToolFailure) {
|
|
158
|
+
sections.push("- **Escalate on Tool Failure**: Yes");
|
|
159
|
+
}
|
|
160
|
+
if (esc.onTimeout) {
|
|
161
|
+
sections.push("- **Escalate on Timeout**: Yes");
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
sections.push("");
|
|
165
|
+
}
|
|
166
|
+
return sections.join(`
|
|
167
|
+
`);
|
|
168
|
+
}
|
|
169
|
+
getSpecPrompt(specKey, options) {
|
|
170
|
+
const spec = this.specs.get(specKey);
|
|
171
|
+
if (!spec) {
|
|
172
|
+
throw new Error(`Spec not found: ${specKey}`);
|
|
173
|
+
}
|
|
174
|
+
const sections = [];
|
|
175
|
+
const opts = {
|
|
176
|
+
includeTools: options?.includeTools ?? true,
|
|
177
|
+
format: options?.format ?? "structured",
|
|
178
|
+
...options
|
|
179
|
+
};
|
|
180
|
+
sections.push("# Agent Identity");
|
|
181
|
+
sections.push("");
|
|
182
|
+
sections.push(`You are ${spec.meta.key} (v${spec.meta.version}).`);
|
|
183
|
+
sections.push("");
|
|
184
|
+
if (spec.description) {
|
|
185
|
+
sections.push("## Description");
|
|
186
|
+
sections.push("");
|
|
187
|
+
sections.push(spec.description);
|
|
188
|
+
sections.push("");
|
|
189
|
+
}
|
|
190
|
+
sections.push("## Instructions");
|
|
191
|
+
sections.push("");
|
|
192
|
+
sections.push(spec.instructions);
|
|
193
|
+
sections.push("");
|
|
194
|
+
if (opts.includeTools && spec.tools && spec.tools.length > 0) {
|
|
195
|
+
sections.push("## Available Tools");
|
|
196
|
+
sections.push("");
|
|
197
|
+
sections.push("You have access to the following tools:");
|
|
198
|
+
sections.push("");
|
|
199
|
+
for (const tool of spec.tools) {
|
|
200
|
+
sections.push(`### ${tool.name}`);
|
|
201
|
+
sections.push("");
|
|
202
|
+
if (tool.description) {
|
|
203
|
+
sections.push(tool.description);
|
|
204
|
+
sections.push("");
|
|
205
|
+
}
|
|
206
|
+
if (tool.schema && opts.format === "structured") {
|
|
207
|
+
sections.push("Parameters:");
|
|
208
|
+
sections.push("```json");
|
|
209
|
+
sections.push(JSON.stringify(tool.schema, null, 2));
|
|
210
|
+
sections.push("```");
|
|
211
|
+
sections.push("");
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (spec.knowledge && spec.knowledge.length > 0) {
|
|
216
|
+
const requiredKnowledge = spec.knowledge.filter((k) => k.required);
|
|
217
|
+
if (requiredKnowledge.length > 0) {
|
|
218
|
+
sections.push("## Knowledge Context");
|
|
219
|
+
sections.push("");
|
|
220
|
+
for (const k of requiredKnowledge) {
|
|
221
|
+
if (k.instructions) {
|
|
222
|
+
sections.push(k.instructions);
|
|
223
|
+
sections.push("");
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (options?.customContext) {
|
|
229
|
+
sections.push("## Additional Context");
|
|
230
|
+
sections.push("");
|
|
231
|
+
sections.push(options.customContext);
|
|
232
|
+
sections.push("");
|
|
233
|
+
}
|
|
234
|
+
return sections.join(`
|
|
235
|
+
`);
|
|
236
|
+
}
|
|
237
|
+
listSpecs(options) {
|
|
238
|
+
const results = [];
|
|
239
|
+
for (const [key, spec] of this.specs) {
|
|
240
|
+
if (options?.stability && spec.meta.stability !== options.stability) {
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
if (options?.tags && options.tags.length > 0) {
|
|
244
|
+
const specTags = spec.tags ?? [];
|
|
245
|
+
const hasMatchingTag = options.tags.some((tag) => specTags.includes(tag));
|
|
246
|
+
if (!hasMatchingTag) {
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
results.push({
|
|
251
|
+
key,
|
|
252
|
+
name: spec.meta.key,
|
|
253
|
+
version: spec.meta.version,
|
|
254
|
+
description: spec.description,
|
|
255
|
+
stability: spec.meta.stability,
|
|
256
|
+
tags: spec.tags,
|
|
257
|
+
toolCount: spec.tools?.length ?? 0
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
return results;
|
|
261
|
+
}
|
|
262
|
+
querySpec(specKey) {
|
|
263
|
+
const spec = this.specs.get(specKey);
|
|
264
|
+
if (!spec) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
key: specKey,
|
|
269
|
+
spec,
|
|
270
|
+
markdown: this.getSpecMarkdown(specKey),
|
|
271
|
+
prompt: this.getSpecPrompt(specKey)
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
hasSpec(specKey) {
|
|
275
|
+
return this.specs.has(specKey);
|
|
276
|
+
}
|
|
277
|
+
getSpec(specKey) {
|
|
278
|
+
return this.specs.get(specKey);
|
|
279
|
+
}
|
|
280
|
+
getAllSpecs() {
|
|
281
|
+
return Array.from(this.specs.values());
|
|
282
|
+
}
|
|
283
|
+
getSpecCount() {
|
|
284
|
+
return this.specs.size;
|
|
285
|
+
}
|
|
286
|
+
addSpec(spec) {
|
|
287
|
+
const key = agentKey(spec.meta);
|
|
288
|
+
this.specs.set(key, spec);
|
|
289
|
+
}
|
|
290
|
+
removeSpec(specKey) {
|
|
291
|
+
return this.specs.delete(specKey);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
272
294
|
function createSpecConsumer(config) {
|
|
273
|
-
|
|
295
|
+
return new ContractSpecConsumer(config);
|
|
274
296
|
}
|
|
275
|
-
/**
|
|
276
|
-
* Create a spec consumer from a single spec.
|
|
277
|
-
*/
|
|
278
297
|
function createSingleSpecConsumer(spec, options) {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
298
|
+
return new ContractSpecConsumer({
|
|
299
|
+
specs: [spec],
|
|
300
|
+
...options
|
|
301
|
+
});
|
|
283
302
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
303
|
+
export {
|
|
304
|
+
createSpecConsumer,
|
|
305
|
+
createSingleSpecConsumer,
|
|
306
|
+
ContractSpecConsumer
|
|
307
|
+
};
|