@contractspec/lib.ai-agent 7.0.7 → 8.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.
Files changed (81) hide show
  1. package/README.md +45 -4
  2. package/dist/agent/agent-factory.d.ts +14 -3
  3. package/dist/agent/agent-factory.js +676 -111
  4. package/dist/agent/contract-spec-agent.d.ts +16 -2
  5. package/dist/agent/contract-spec-agent.js +672 -110
  6. package/dist/agent/index.js +685 -118
  7. package/dist/agent/json-runner.d.ts +1 -1
  8. package/dist/agent/json-runner.js +672 -110
  9. package/dist/agent/unified-agent.d.ts +2 -2
  10. package/dist/agent/unified-agent.js +685 -118
  11. package/dist/approval/index.js +6 -1
  12. package/dist/approval/workflow.js +5 -1
  13. package/dist/exporters/claude-agent-exporter.d.ts +1 -1
  14. package/dist/exporters/claude-agent-exporter.js +3 -51
  15. package/dist/exporters/index.js +8 -54
  16. package/dist/exporters/opencode-exporter.d.ts +1 -1
  17. package/dist/exporters/opencode-exporter.js +3 -51
  18. package/dist/exporters/types.d.ts +1 -1
  19. package/dist/index.d.ts +2 -1
  20. package/dist/index.js +3805 -71
  21. package/dist/interop/index.js +3 -51
  22. package/dist/interop/spec-consumer.d.ts +1 -1
  23. package/dist/interop/spec-consumer.js +3 -51
  24. package/dist/interop/tool-consumer.d.ts +1 -1
  25. package/dist/interop/types.d.ts +1 -1
  26. package/dist/knowledge/injector.d.ts +1 -1
  27. package/dist/node/agent/agent-factory.js +676 -111
  28. package/dist/node/agent/contract-spec-agent.js +672 -110
  29. package/dist/node/agent/index.js +685 -118
  30. package/dist/node/agent/json-runner.js +672 -110
  31. package/dist/node/agent/unified-agent.js +685 -118
  32. package/dist/node/approval/index.js +6 -1
  33. package/dist/node/approval/workflow.js +5 -1
  34. package/dist/node/exporters/claude-agent-exporter.js +3 -51
  35. package/dist/node/exporters/index.js +8 -54
  36. package/dist/node/exporters/opencode-exporter.js +3 -51
  37. package/dist/node/index.js +3805 -71
  38. package/dist/node/interop/index.js +3 -51
  39. package/dist/node/interop/spec-consumer.js +3 -51
  40. package/dist/node/providers/claude-agent-sdk/adapter.js +3 -51
  41. package/dist/node/providers/claude-agent-sdk/index.js +3 -51
  42. package/dist/node/providers/index.js +8 -53
  43. package/dist/node/providers/opencode-sdk/adapter.js +4 -51
  44. package/dist/node/providers/opencode-sdk/index.js +4 -51
  45. package/dist/node/session/index.js +26 -1
  46. package/dist/node/session/store.js +26 -1
  47. package/dist/node/telemetry/adapter.js +2 -0
  48. package/dist/node/telemetry/index.js +2 -0
  49. package/dist/providers/claude-agent-sdk/adapter.d.ts +1 -1
  50. package/dist/providers/claude-agent-sdk/adapter.js +3 -51
  51. package/dist/providers/claude-agent-sdk/index.js +3 -51
  52. package/dist/providers/claude-agent-sdk/tool-bridge.d.ts +1 -8
  53. package/dist/providers/index.js +8 -53
  54. package/dist/providers/opencode-sdk/adapter.d.ts +1 -13
  55. package/dist/providers/opencode-sdk/adapter.js +4 -51
  56. package/dist/providers/opencode-sdk/agent-bridge.d.ts +1 -10
  57. package/dist/providers/opencode-sdk/index.js +4 -51
  58. package/dist/providers/opencode-sdk/tool-bridge.d.ts +1 -4
  59. package/dist/providers/types.d.ts +1 -8
  60. package/dist/session/index.js +26 -1
  61. package/dist/session/store.d.ts +2 -2
  62. package/dist/session/store.js +26 -1
  63. package/dist/telemetry/adapter.d.ts +1 -0
  64. package/dist/telemetry/adapter.js +2 -0
  65. package/dist/telemetry/index.js +2 -0
  66. package/dist/tools/knowledge-tool.d.ts +1 -1
  67. package/dist/tools/mcp-server.d.ts +1 -1
  68. package/dist/tools/operation-tool-handler.d.ts +1 -1
  69. package/dist/tools/tool-adapter.d.ts +1 -1
  70. package/dist/types.d.ts +13 -0
  71. package/package.json +8 -44
  72. package/dist/node/spec/index.js +0 -2233
  73. package/dist/node/spec/registry.js +0 -2178
  74. package/dist/node/spec/spec.js +0 -2188
  75. package/dist/spec/index.d.ts +0 -2
  76. package/dist/spec/index.js +0 -2233
  77. package/dist/spec/registry.d.ts +0 -41
  78. package/dist/spec/registry.js +0 -2178
  79. package/dist/spec/spec.d.ts +0 -218
  80. package/dist/spec/spec.js +0 -2188
  81. /package/dist/{spec/spec.test.d.ts → session/store.test.d.ts} +0 -0
@@ -2131,56 +2131,6 @@ var init_i18n = __esm(() => {
2131
2131
  init_messages();
2132
2132
  });
2133
2133
 
2134
- // src/spec/spec.ts
2135
- function defineAgent(spec) {
2136
- const i18n = createAgentI18n(spec.locale);
2137
- if (!spec.meta?.key) {
2138
- throw new Error(i18n.t("error.agentKeyRequired"));
2139
- }
2140
- if (typeof spec.meta.version !== "string") {
2141
- throw new Error(i18n.t("error.agentMissingVersion", { key: spec.meta.key }));
2142
- }
2143
- if (!spec.instructions?.trim()) {
2144
- throw new Error(i18n.t("error.agentRequiresInstructions", { key: spec.meta.key }));
2145
- }
2146
- if (!spec.tools?.length) {
2147
- throw new Error(i18n.t("error.agentRequiresTool", { key: spec.meta.key }));
2148
- }
2149
- for (const [portName, portRef] of Object.entries(spec.runtime?.ports ?? {})) {
2150
- if (portRef !== undefined && portRef.trim().length === 0) {
2151
- throw new Error(`Agent ${spec.meta.key} has invalid runtime config: port "${portName}" must not be empty`);
2152
- }
2153
- }
2154
- const toolNames = new Set;
2155
- for (const tool of spec.tools) {
2156
- if (toolNames.has(tool.name)) {
2157
- throw new Error(i18n.t("error.agentDuplicateTool", {
2158
- key: spec.meta.key,
2159
- name: tool.name
2160
- }));
2161
- }
2162
- toolNames.add(tool.name);
2163
- if (tool.subagentRef && tool.operationRef) {
2164
- throw new Error(`Agent ${spec.meta.key} tool "${tool.name}" cannot have both subagentRef and operationRef. Use one.`);
2165
- }
2166
- const outputRefCount = [
2167
- tool.outputPresentation,
2168
- tool.outputForm,
2169
- tool.outputDataView
2170
- ].filter(Boolean).length;
2171
- if (outputRefCount > 1) {
2172
- throw new Error(`Agent ${spec.meta.key} tool "${tool.name}" has multiple output refs (outputPresentation, outputForm, outputDataView). Use at most one.`);
2173
- }
2174
- }
2175
- return Object.freeze(spec);
2176
- }
2177
- function agentKey(meta) {
2178
- return `${meta.key}.v${meta.version}`;
2179
- }
2180
- var init_spec = __esm(() => {
2181
- init_i18n();
2182
- });
2183
-
2184
2134
  // src/providers/claude-agent-sdk/tool-bridge.ts
2185
2135
  function specToolToClaudeAgentTool(tool, handler, context) {
2186
2136
  return {
@@ -2408,7 +2358,9 @@ var init_tool_bridge2 = __esm(() => {
2408
2358
  });
2409
2359
  // src/interop/spec-consumer.ts
2410
2360
  init_i18n();
2411
- init_spec();
2361
+ import {
2362
+ agentKey
2363
+ } from "@contractspec/lib.contracts-spec/agent";
2412
2364
 
2413
2365
  class ContractSpecConsumer {
2414
2366
  specs;
@@ -6,7 +6,7 @@
6
6
  * - List available specs
7
7
  * - Query spec metadata
8
8
  */
9
- import type { AgentSpec } from '../spec/spec';
9
+ import { type AgentSpec } from '@contractspec/lib.contracts-spec/agent';
10
10
  import type { SpecConsumer, SpecConsumerConfig, SpecListOptions, SpecListResult, SpecMarkdownOptions, SpecPromptOptions, SpecQueryResult } from './types';
11
11
  /**
12
12
  * ContractSpec consumer for external agents.
@@ -2131,59 +2131,11 @@ var init_i18n = __esm(() => {
2131
2131
  init_messages();
2132
2132
  });
2133
2133
 
2134
- // src/spec/spec.ts
2135
- function defineAgent(spec) {
2136
- const i18n = createAgentI18n(spec.locale);
2137
- if (!spec.meta?.key) {
2138
- throw new Error(i18n.t("error.agentKeyRequired"));
2139
- }
2140
- if (typeof spec.meta.version !== "string") {
2141
- throw new Error(i18n.t("error.agentMissingVersion", { key: spec.meta.key }));
2142
- }
2143
- if (!spec.instructions?.trim()) {
2144
- throw new Error(i18n.t("error.agentRequiresInstructions", { key: spec.meta.key }));
2145
- }
2146
- if (!spec.tools?.length) {
2147
- throw new Error(i18n.t("error.agentRequiresTool", { key: spec.meta.key }));
2148
- }
2149
- for (const [portName, portRef] of Object.entries(spec.runtime?.ports ?? {})) {
2150
- if (portRef !== undefined && portRef.trim().length === 0) {
2151
- throw new Error(`Agent ${spec.meta.key} has invalid runtime config: port "${portName}" must not be empty`);
2152
- }
2153
- }
2154
- const toolNames = new Set;
2155
- for (const tool of spec.tools) {
2156
- if (toolNames.has(tool.name)) {
2157
- throw new Error(i18n.t("error.agentDuplicateTool", {
2158
- key: spec.meta.key,
2159
- name: tool.name
2160
- }));
2161
- }
2162
- toolNames.add(tool.name);
2163
- if (tool.subagentRef && tool.operationRef) {
2164
- throw new Error(`Agent ${spec.meta.key} tool "${tool.name}" cannot have both subagentRef and operationRef. Use one.`);
2165
- }
2166
- const outputRefCount = [
2167
- tool.outputPresentation,
2168
- tool.outputForm,
2169
- tool.outputDataView
2170
- ].filter(Boolean).length;
2171
- if (outputRefCount > 1) {
2172
- throw new Error(`Agent ${spec.meta.key} tool "${tool.name}" has multiple output refs (outputPresentation, outputForm, outputDataView). Use at most one.`);
2173
- }
2174
- }
2175
- return Object.freeze(spec);
2176
- }
2177
- function agentKey(meta) {
2178
- return `${meta.key}.v${meta.version}`;
2179
- }
2180
- var init_spec = __esm(() => {
2181
- init_i18n();
2182
- });
2183
-
2184
2134
  // src/interop/spec-consumer.ts
2185
2135
  init_i18n();
2186
- init_spec();
2136
+ import {
2137
+ agentKey
2138
+ } from "@contractspec/lib.contracts-spec/agent";
2187
2139
 
2188
2140
  class ContractSpecConsumer {
2189
2141
  specs;
@@ -1,3 +1,4 @@
1
+ import type { AgentToolConfig } from '@contractspec/lib.contracts-spec/agent';
1
2
  /**
2
3
  * Tool consumer for external agents.
3
4
  *
@@ -6,7 +7,6 @@
6
7
  * - Export tools for specific SDK formats
7
8
  * - Bridge tool execution
8
9
  */
9
- import type { AgentToolConfig } from '../spec/spec';
10
10
  import type { ToolExecutionContext, ToolHandler } from '../types';
11
11
  import type { ToolConsumer, ToolConsumerConfig, ToolExportFormat, ToolServer, ToolServerConfig } from './types';
12
12
  /**
@@ -1,10 +1,10 @@
1
+ import type { AgentSpec, AgentToolConfig } from '@contractspec/lib.contracts-spec/agent';
1
2
  /**
2
3
  * Types for the interop layer.
3
4
  *
4
5
  * The interop layer enables bidirectional integration between
5
6
  * ContractSpec and external agent SDKs.
6
7
  */
7
- import type { AgentSpec, AgentToolConfig } from '../spec/spec';
8
8
  import type { ToolHandler } from '../types';
9
9
  /**
10
10
  * Configuration for a spec consumer.
@@ -1,5 +1,5 @@
1
+ import type { AgentKnowledgeRef } from '@contractspec/lib.contracts-spec/agent';
1
2
  import type { KnowledgeRetriever } from '@contractspec/lib.knowledge/retriever';
2
- import type { AgentKnowledgeRef } from '../spec/spec';
3
3
  /**
4
4
  * Inject static knowledge into agent instructions.
5
5
  *