@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.
- package/README.md +45 -4
- package/dist/agent/agent-factory.d.ts +14 -3
- package/dist/agent/agent-factory.js +676 -111
- package/dist/agent/contract-spec-agent.d.ts +16 -2
- package/dist/agent/contract-spec-agent.js +672 -110
- package/dist/agent/index.js +685 -118
- package/dist/agent/json-runner.d.ts +1 -1
- package/dist/agent/json-runner.js +672 -110
- package/dist/agent/unified-agent.d.ts +2 -2
- package/dist/agent/unified-agent.js +685 -118
- package/dist/approval/index.js +6 -1
- package/dist/approval/workflow.js +5 -1
- package/dist/exporters/claude-agent-exporter.d.ts +1 -1
- package/dist/exporters/claude-agent-exporter.js +3 -51
- package/dist/exporters/index.js +8 -54
- package/dist/exporters/opencode-exporter.d.ts +1 -1
- package/dist/exporters/opencode-exporter.js +3 -51
- package/dist/exporters/types.d.ts +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3805 -71
- package/dist/interop/index.js +3 -51
- package/dist/interop/spec-consumer.d.ts +1 -1
- package/dist/interop/spec-consumer.js +3 -51
- package/dist/interop/tool-consumer.d.ts +1 -1
- package/dist/interop/types.d.ts +1 -1
- package/dist/knowledge/injector.d.ts +1 -1
- package/dist/node/agent/agent-factory.js +676 -111
- package/dist/node/agent/contract-spec-agent.js +672 -110
- package/dist/node/agent/index.js +685 -118
- package/dist/node/agent/json-runner.js +672 -110
- package/dist/node/agent/unified-agent.js +685 -118
- package/dist/node/approval/index.js +6 -1
- package/dist/node/approval/workflow.js +5 -1
- package/dist/node/exporters/claude-agent-exporter.js +3 -51
- package/dist/node/exporters/index.js +8 -54
- package/dist/node/exporters/opencode-exporter.js +3 -51
- package/dist/node/index.js +3805 -71
- package/dist/node/interop/index.js +3 -51
- package/dist/node/interop/spec-consumer.js +3 -51
- package/dist/node/providers/claude-agent-sdk/adapter.js +3 -51
- package/dist/node/providers/claude-agent-sdk/index.js +3 -51
- package/dist/node/providers/index.js +8 -53
- package/dist/node/providers/opencode-sdk/adapter.js +4 -51
- package/dist/node/providers/opencode-sdk/index.js +4 -51
- package/dist/node/session/index.js +26 -1
- package/dist/node/session/store.js +26 -1
- package/dist/node/telemetry/adapter.js +2 -0
- package/dist/node/telemetry/index.js +2 -0
- package/dist/providers/claude-agent-sdk/adapter.d.ts +1 -1
- package/dist/providers/claude-agent-sdk/adapter.js +3 -51
- package/dist/providers/claude-agent-sdk/index.js +3 -51
- package/dist/providers/claude-agent-sdk/tool-bridge.d.ts +1 -8
- package/dist/providers/index.js +8 -53
- package/dist/providers/opencode-sdk/adapter.d.ts +1 -13
- package/dist/providers/opencode-sdk/adapter.js +4 -51
- package/dist/providers/opencode-sdk/agent-bridge.d.ts +1 -10
- package/dist/providers/opencode-sdk/index.js +4 -51
- package/dist/providers/opencode-sdk/tool-bridge.d.ts +1 -4
- package/dist/providers/types.d.ts +1 -8
- package/dist/session/index.js +26 -1
- package/dist/session/store.d.ts +2 -2
- package/dist/session/store.js +26 -1
- package/dist/telemetry/adapter.d.ts +1 -0
- package/dist/telemetry/adapter.js +2 -0
- package/dist/telemetry/index.js +2 -0
- package/dist/tools/knowledge-tool.d.ts +1 -1
- package/dist/tools/mcp-server.d.ts +1 -1
- package/dist/tools/operation-tool-handler.d.ts +1 -1
- package/dist/tools/tool-adapter.d.ts +1 -1
- package/dist/types.d.ts +13 -0
- package/package.json +8 -44
- package/dist/node/spec/index.js +0 -2233
- package/dist/node/spec/registry.js +0 -2178
- package/dist/node/spec/spec.js +0 -2188
- package/dist/spec/index.d.ts +0 -2
- package/dist/spec/index.js +0 -2233
- package/dist/spec/registry.d.ts +0 -41
- package/dist/spec/registry.js +0 -2178
- package/dist/spec/spec.d.ts +0 -218
- package/dist/spec/spec.js +0 -2188
- /package/dist/{spec/spec.test.d.ts → session/store.test.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -9,6 +9,7 @@ Website: https://contractspec.io
|
|
|
9
9
|
- Provides the central agent runtime used by chat, automation, and higher-level orchestration packages.
|
|
10
10
|
- Supports tools, sessions, memory, approvals, providers, telemetry, and MCP-aware workflows.
|
|
11
11
|
- Acts as the stable public API for agent execution across multiple runtimes and delivery surfaces.
|
|
12
|
+
- Consumes agent definitions from `@contractspec/lib.contracts-spec/agent`.
|
|
12
13
|
- `src/providers/` contains provider integrations and provider-facing adapters.
|
|
13
14
|
|
|
14
15
|
## Installation
|
|
@@ -21,13 +22,42 @@ or
|
|
|
21
22
|
|
|
22
23
|
## Usage
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
Define agents in `@contractspec/lib.contracts-spec/agent`, then run or export them with `@contractspec/lib.ai-agent`.
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { defineAgent } from "@contractspec/lib.contracts-spec/agent";
|
|
29
|
+
import { createUnifiedAgent } from "@contractspec/lib.ai-agent/agent/unified-agent";
|
|
30
|
+
|
|
31
|
+
const SupportBot = defineAgent({
|
|
32
|
+
meta: {
|
|
33
|
+
key: "support.bot",
|
|
34
|
+
version: "1.0.0",
|
|
35
|
+
description: "Customer support assistant",
|
|
36
|
+
owners: ["support"],
|
|
37
|
+
tags: ["support"],
|
|
38
|
+
stability: "experimental",
|
|
39
|
+
},
|
|
40
|
+
instructions: "Resolve tickets and escalate low-confidence cases.",
|
|
41
|
+
tools: [{ name: "support.resolve" }],
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const agent = createUnifiedAgent(SupportBot, {
|
|
45
|
+
backend: "ai-sdk",
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Runtime portability stays adapter-first:
|
|
50
|
+
|
|
51
|
+
- `AgentSpec.runtime` can declare checkpointing, suspend/resume, and approval-gateway capabilities.
|
|
52
|
+
- `AgentFactory` and `ContractSpecAgent` accept optional runtime adapter bundles for LangGraph/LangChain-style integrations.
|
|
53
|
+
- Session state now persists workflow, thread, trace, checkpoint, and approval metadata for replay-safe resumes.
|
|
54
|
+
- Escalation policies can raise approval requests on timeout, tool failure, or confidence thresholds without coupling core contracts to a vendor runtime.
|
|
25
55
|
|
|
26
56
|
## Architecture
|
|
27
57
|
|
|
28
58
|
- `src/agent/`, `src/session/`, and `src/memory/` contain the runtime core for execution state and persistence hooks.
|
|
29
59
|
- `src/tools/`, `src.providers/`, and `src.interop/` connect providers, tools, and MCP-aware runtime surfaces.
|
|
30
|
-
- `src.telemetry/`, `src.approval/`, `src.knowledge/`,
|
|
60
|
+
- `src.telemetry/`, `src.approval/`, `src.knowledge/`, and `src.schema/` round out runtime policy and observability surfaces.
|
|
31
61
|
- `src/index.ts` is the root public barrel and package entrypoint.
|
|
32
62
|
- `src/types.ts` is shared public type definitions.
|
|
33
63
|
|
|
@@ -44,7 +74,17 @@ Import the root entrypoint from `@contractspec/lib.ai-agent`, or choose a docume
|
|
|
44
74
|
- Export `./approval/workflow` resolves through `./src/approval/workflow.ts`.
|
|
45
75
|
- Export `./exporters` resolves through `./src/exporters/index.ts`.
|
|
46
76
|
- Export `./exporters/claude-agent-exporter` resolves through `./src/exporters/claude-agent-exporter.ts`.
|
|
47
|
-
-
|
|
77
|
+
- Additional runtime subpaths are published through `package.json`; keep docs aligned with the manifest.
|
|
78
|
+
|
|
79
|
+
## Migration Note
|
|
80
|
+
|
|
81
|
+
`@contractspec/lib.ai-agent` no longer owns the agent-definition contract layer.
|
|
82
|
+
|
|
83
|
+
- Removed: `@contractspec/lib.ai-agent/spec`
|
|
84
|
+
- Removed: `@contractspec/lib.ai-agent/spec/spec`
|
|
85
|
+
- Removed: `@contractspec/lib.ai-agent/spec/registry`
|
|
86
|
+
- Use `@contractspec/lib.contracts-spec/agent` for `AgentSpec`, `AgentToolConfig`,
|
|
87
|
+
`AgentRegistry`, `createAgentRegistry`, and `defineAgent`
|
|
48
88
|
|
|
49
89
|
## Local Commands
|
|
50
90
|
|
|
@@ -74,5 +114,6 @@ Import the root entrypoint from `@contractspec/lib.ai-agent`, or choose a docume
|
|
|
74
114
|
## Notes
|
|
75
115
|
|
|
76
116
|
- High blast radius — used by multiple bundles and libs.
|
|
77
|
-
-
|
|
117
|
+
- Agent definitions are owned by `@contractspec/lib.contracts-spec/agent`.
|
|
118
|
+
- This package is runtime-focused: execution, exporters, MCP/tool bridges, sessions, memory, approvals, providers, and telemetry.
|
|
78
119
|
- MCP transport adapters must stay runtime-agnostic (no Node/browser-specific globals).
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import type { ModelSelector } from '@contractspec/lib.ai-providers/selector-types';
|
|
2
|
+
import type { AgentRegistry, AgentSpec } from '@contractspec/lib.contracts-spec/agent';
|
|
2
3
|
import type { OperationSpecRegistry } from '@contractspec/lib.contracts-spec/operations/registry';
|
|
3
4
|
import type { KnowledgeRetriever } from '@contractspec/lib.knowledge/retriever';
|
|
4
5
|
import type { LanguageModel, Tool } from 'ai';
|
|
6
|
+
import type { ApprovalWorkflow } from '../approval/workflow';
|
|
7
|
+
import type { AgentRuntimeAdapterBundle } from '../interop/runtime-adapters';
|
|
5
8
|
import type { AgentSessionStore } from '../session/store';
|
|
6
|
-
import type { AgentRegistry } from '../spec/registry';
|
|
7
|
-
import type { AgentSpec } from '../spec/spec';
|
|
8
9
|
import type { TelemetryCollector } from '../telemetry/adapter';
|
|
9
10
|
import type { PostHogLLMConfig, PostHogTracingOptions } from '../telemetry/posthog-types';
|
|
10
11
|
import type { AgentMemoryStore } from '../tools/agent-memory-store';
|
|
11
12
|
import type { McpClientConfig } from '../tools/mcp-client';
|
|
12
13
|
import type { SubagentRegistry } from '../tools/tool-adapter';
|
|
13
|
-
import type { ToolHandler } from '../types';
|
|
14
|
+
import type { AgentEventEmitter, AgentSessionState, ToolHandler } from '../types';
|
|
14
15
|
import { ContractSpecAgent } from './contract-spec-agent';
|
|
15
16
|
/**
|
|
16
17
|
* Factory configuration for creating agents.
|
|
@@ -44,6 +45,12 @@ export interface AgentFactoryConfig {
|
|
|
44
45
|
mcpServers?: McpClientConfig[];
|
|
45
46
|
/** Ranking-driven model selector for dynamic per-call routing */
|
|
46
47
|
modelSelector?: ModelSelector;
|
|
48
|
+
/** Optional external adapter bundles keyed by runtime id. */
|
|
49
|
+
runtimeAdapters?: Partial<Record<string, AgentRuntimeAdapterBundle<AgentSessionState>>>;
|
|
50
|
+
/** Approval workflow used for escalation and tool approvals. */
|
|
51
|
+
approvalWorkflow?: ApprovalWorkflow;
|
|
52
|
+
/** Event emitter for lifecycle/audit events. */
|
|
53
|
+
eventEmitter?: AgentEventEmitter;
|
|
47
54
|
}
|
|
48
55
|
/**
|
|
49
56
|
* Options for creating an agent instance.
|
|
@@ -61,6 +68,10 @@ export interface CreateAgentOptions {
|
|
|
61
68
|
operationRegistry?: OperationSpecRegistry;
|
|
62
69
|
/** Override SubagentRegistry for subagent-backed tools */
|
|
63
70
|
subagentRegistry?: SubagentRegistry;
|
|
71
|
+
/** Override runtime adapters for this instance. */
|
|
72
|
+
runtimeAdapters?: Partial<Record<string, AgentRuntimeAdapterBundle<AgentSessionState>>>;
|
|
73
|
+
/** Override approval workflow for this instance. */
|
|
74
|
+
approvalWorkflow?: ApprovalWorkflow;
|
|
64
75
|
}
|
|
65
76
|
/**
|
|
66
77
|
* Factory for creating ContractSpec agents from specs.
|