@contractspec/lib.ai-agent 7.0.5 → 7.0.7
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 +71 -130
- package/dist/agent/agent-factory.d.ts +8 -8
- package/dist/agent/agent-factory.js +1360 -1358
- package/dist/agent/contract-spec-agent.d.ts +8 -8
- package/dist/agent/contract-spec-agent.js +1360 -1358
- package/dist/agent/index.js +1621 -1619
- package/dist/agent/json-runner.d.ts +2 -2
- package/dist/agent/json-runner.js +1360 -1358
- package/dist/agent/unified-agent.d.ts +3 -3
- package/dist/agent/unified-agent.js +1621 -1619
- package/dist/approval/index.d.ts +1 -1
- package/dist/approval/index.js +618 -618
- package/dist/approval/workflow.js +618 -618
- package/dist/exporters/claude-agent-exporter.d.ts +1 -1
- package/dist/exporters/claude-agent-exporter.js +619 -619
- package/dist/exporters/index.d.ts +2 -2
- package/dist/exporters/index.js +626 -625
- package/dist/exporters/opencode-exporter.js +625 -625
- package/dist/exporters/types.d.ts +1 -1
- package/dist/i18n/catalogs/index.d.ts +1 -1
- package/dist/i18n/catalogs/index.js +587 -587
- package/dist/i18n/index.d.ts +7 -7
- package/dist/i18n/index.js +618 -618
- package/dist/i18n/locale.d.ts +1 -1
- package/dist/i18n/locale.js +2 -2
- package/dist/i18n/messages.js +587 -587
- package/dist/index.js +619 -619
- package/dist/interop/index.d.ts +2 -2
- package/dist/interop/index.js +619 -619
- package/dist/interop/spec-consumer.d.ts +1 -1
- package/dist/interop/spec-consumer.js +619 -619
- package/dist/interop/tool-consumer.d.ts +2 -2
- package/dist/interop/tool-consumer.js +619 -619
- package/dist/knowledge/index.js +618 -618
- package/dist/knowledge/injector.js +618 -618
- package/dist/memory/in-memory.d.ts +1 -1
- package/dist/memory/index.d.ts +1 -1
- package/dist/node/agent/agent-factory.js +1360 -1358
- package/dist/node/agent/contract-spec-agent.js +1360 -1358
- package/dist/node/agent/index.js +1621 -1619
- package/dist/node/agent/json-runner.js +1360 -1358
- package/dist/node/agent/unified-agent.js +1621 -1619
- package/dist/node/approval/index.js +618 -618
- package/dist/node/approval/workflow.js +618 -618
- package/dist/node/exporters/claude-agent-exporter.js +619 -619
- package/dist/node/exporters/index.js +626 -625
- package/dist/node/exporters/opencode-exporter.js +625 -625
- package/dist/node/i18n/catalogs/index.js +587 -587
- package/dist/node/i18n/index.js +618 -618
- package/dist/node/i18n/locale.js +2 -2
- package/dist/node/i18n/messages.js +587 -587
- package/dist/node/index.js +619 -619
- package/dist/node/interop/index.js +619 -619
- package/dist/node/interop/spec-consumer.js +619 -619
- package/dist/node/interop/tool-consumer.js +619 -619
- package/dist/node/knowledge/index.js +618 -618
- package/dist/node/knowledge/injector.js +618 -618
- package/dist/node/providers/claude-agent-sdk/adapter.js +799 -799
- package/dist/node/providers/claude-agent-sdk/index.js +799 -799
- package/dist/node/providers/claude-agent-sdk/tool-bridge.js +618 -618
- package/dist/node/providers/index.js +795 -795
- package/dist/node/providers/opencode-sdk/adapter.js +671 -671
- package/dist/node/providers/opencode-sdk/agent-bridge.js +619 -619
- package/dist/node/providers/opencode-sdk/index.js +673 -673
- package/dist/node/providers/opencode-sdk/tool-bridge.js +618 -618
- package/dist/node/providers/registry.js +619 -619
- package/dist/node/providers/types.js +618 -618
- package/dist/node/spec/index.js +619 -619
- package/dist/node/spec/registry.js +619 -619
- package/dist/node/spec/spec.js +618 -618
- package/dist/node/telemetry/index.js +622 -620
- package/dist/node/telemetry/posthog.js +622 -620
- package/dist/node/tools/index.js +902 -902
- package/dist/node/tools/knowledge-tool.js +618 -618
- package/dist/node/tools/mcp-server.js +619 -619
- package/dist/node/tools/tool-adapter.js +619 -619
- package/dist/providers/claude-agent-sdk/adapter.d.ts +1 -1
- package/dist/providers/claude-agent-sdk/adapter.js +799 -799
- package/dist/providers/claude-agent-sdk/index.d.ts +1 -1
- package/dist/providers/claude-agent-sdk/index.js +799 -799
- package/dist/providers/claude-agent-sdk/session-bridge.d.ts +1 -2
- package/dist/providers/claude-agent-sdk/tool-bridge.d.ts +1 -1
- package/dist/providers/claude-agent-sdk/tool-bridge.js +618 -618
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.js +795 -795
- package/dist/providers/opencode-sdk/adapter.d.ts +1 -1
- package/dist/providers/opencode-sdk/adapter.js +671 -671
- package/dist/providers/opencode-sdk/agent-bridge.js +619 -619
- package/dist/providers/opencode-sdk/index.d.ts +1 -1
- package/dist/providers/opencode-sdk/index.js +673 -673
- package/dist/providers/opencode-sdk/tool-bridge.d.ts +1 -1
- package/dist/providers/opencode-sdk/tool-bridge.js +618 -618
- package/dist/providers/registry.js +619 -619
- package/dist/providers/types.d.ts +1 -1
- package/dist/providers/types.js +618 -618
- package/dist/spec/index.d.ts +1 -1
- package/dist/spec/index.js +619 -619
- package/dist/spec/registry.d.ts +1 -1
- package/dist/spec/registry.js +619 -619
- package/dist/spec/spec.d.ts +1 -1
- package/dist/spec/spec.js +618 -618
- package/dist/telemetry/index.d.ts +1 -1
- package/dist/telemetry/index.js +622 -620
- package/dist/telemetry/posthog.d.ts +1 -1
- package/dist/telemetry/posthog.js +622 -620
- package/dist/tools/index.d.ts +5 -5
- package/dist/tools/index.js +902 -902
- package/dist/tools/knowledge-tool.d.ts +1 -1
- package/dist/tools/knowledge-tool.js +618 -618
- package/dist/tools/mcp-server.d.ts +1 -1
- package/dist/tools/mcp-server.js +619 -619
- package/dist/tools/tool-adapter.d.ts +2 -2
- package/dist/tools/tool-adapter.js +619 -619
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -1,137 +1,78 @@
|
|
|
1
1
|
# @contractspec/lib.ai-agent
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[](https://www.npmjs.com/package/@contractspec/lib.ai-agent)
|
|
5
|
-
[](https://deepwiki.com/lssm-tech/contractspec)
|
|
3
|
+
Website: https://contractspec.io
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
**Core AI agent runtime for ContractSpec with tool orchestration, MCP integration, session state, memory, and telemetry.**
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
## What It Provides
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
- Provides the central agent runtime used by chat, automation, and higher-level orchestration packages.
|
|
10
|
+
- Supports tools, sessions, memory, approvals, providers, telemetry, and MCP-aware workflows.
|
|
11
|
+
- Acts as the stable public API for agent execution across multiple runtimes and delivery surfaces.
|
|
12
|
+
- `src/providers/` contains provider integrations and provider-facing adapters.
|
|
12
13
|
|
|
13
|
-
##
|
|
14
|
+
## Installation
|
|
14
15
|
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
## Quickstart
|
|
80
|
-
|
|
81
|
-
```ts
|
|
82
|
-
import { AgentRegistry, AgentRunner, defineAgent } from '@contractspec/lib.ai-agent';
|
|
83
|
-
import { ToolExecutor } from '@contractspec/lib.ai-agent/tools';
|
|
84
|
-
import { InMemoryAgentMemory } from '@contractspec/lib.ai-agent/memory';
|
|
85
|
-
|
|
86
|
-
const SupportAgent = defineAgent({
|
|
87
|
-
meta: { name: 'support.bot', version: '1.0.0', owners: ['team-support'], domain: 'operations' },
|
|
88
|
-
instructions: 'Resolve support tickets. Escalate whenever confidence < 0.75.',
|
|
89
|
-
tools: [{ name: 'search_knowledge', description: 'Query support corpus', schema: { type: 'object', properties: { question: { type: 'string' } }, required: ['question'] } }],
|
|
90
|
-
policy: { confidence: { min: 0.75 }, escalation: { auto: true } },
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
const registry = new AgentRegistry().register(SupportAgent);
|
|
94
|
-
const runner = new AgentRunner({
|
|
95
|
-
registry,
|
|
96
|
-
llm: mistralProvider,
|
|
97
|
-
toolExecutor: new ToolExecutor({ tools: [searchKnowledgeTool] }),
|
|
98
|
-
memoryManager: new InMemoryAgentMemory(),
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
const result = await runner.run({ agent: 'support.bot', input: 'My payout failed.', tenantId: 'acme' });
|
|
102
|
-
if (result.requiresEscalation) notifyHuman(result);
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
See `examples/ai-support-bot` for a full workflow including ticket ingestion and approval queues.
|
|
106
|
-
|
|
107
|
-
## MCP Client Tooling
|
|
108
|
-
|
|
109
|
-
```ts
|
|
110
|
-
import { createAgentFactory } from '@contractspec/lib.ai-agent/agent/agent-factory';
|
|
111
|
-
|
|
112
|
-
const factory = createAgentFactory({
|
|
113
|
-
defaultModel,
|
|
114
|
-
registry,
|
|
115
|
-
toolHandlers,
|
|
116
|
-
mcpServers: [
|
|
117
|
-
{
|
|
118
|
-
name: 'filesystem',
|
|
119
|
-
command: 'npx',
|
|
120
|
-
args: ['-y', '@modelcontextprotocol/server-filesystem', '/workspace'],
|
|
121
|
-
toolPrefix: 'fs',
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
name: 'posthog',
|
|
125
|
-
transport: 'http',
|
|
126
|
-
url: process.env.POSTHOG_MCP_URL!,
|
|
127
|
-
accessTokenEnvVar: 'POSTHOG_MCP_TOKEN',
|
|
128
|
-
toolPrefix: 'ph',
|
|
129
|
-
},
|
|
130
|
-
],
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
const agent = await factory.create('support.bot');
|
|
134
|
-
const result = await agent.generate({ prompt: 'Summarize today\'s incidents.' });
|
|
135
|
-
|
|
136
|
-
await agent.cleanup();
|
|
137
|
-
```
|
|
16
|
+
`npm install @contractspec/lib.ai-agent`
|
|
17
|
+
|
|
18
|
+
or
|
|
19
|
+
|
|
20
|
+
`bun add @contractspec/lib.ai-agent`
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
Import the root entrypoint from `@contractspec/lib.ai-agent`, or choose a documented subpath when you only need one part of the package surface.
|
|
25
|
+
|
|
26
|
+
## Architecture
|
|
27
|
+
|
|
28
|
+
- `src/agent/`, `src/session/`, and `src/memory/` contain the runtime core for execution state and persistence hooks.
|
|
29
|
+
- `src/tools/`, `src.providers/`, and `src.interop/` connect providers, tools, and MCP-aware runtime surfaces.
|
|
30
|
+
- `src.telemetry/`, `src.approval/`, `src.knowledge/`, `src.schema/`, and `src.spec/` round out agent policy and observability surfaces.
|
|
31
|
+
- `src/index.ts` is the root public barrel and package entrypoint.
|
|
32
|
+
- `src/types.ts` is shared public type definitions.
|
|
33
|
+
|
|
34
|
+
## Public Entry Points
|
|
35
|
+
|
|
36
|
+
- Large multi-subpath library exporting agent runtime, approval, memory, knowledge, providers, schema, telemetry, tools, and types.
|
|
37
|
+
- Export `.` resolves through `./src/index.ts`.
|
|
38
|
+
- Export `./agent` resolves through `./src/agent/index.ts`.
|
|
39
|
+
- Export `./agent/agent-factory` resolves through `./src/agent/agent-factory.ts`.
|
|
40
|
+
- Export `./agent/contract-spec-agent` resolves through `./src/agent/contract-spec-agent.ts`.
|
|
41
|
+
- Export `./agent/json-runner` resolves through `./src/agent/json-runner.ts`.
|
|
42
|
+
- Export `./agent/unified-agent` resolves through `./src/agent/unified-agent.ts`.
|
|
43
|
+
- Export `./approval` resolves through `./src/approval/index.ts`.
|
|
44
|
+
- Export `./approval/workflow` resolves through `./src/approval/workflow.ts`.
|
|
45
|
+
- Export `./exporters` resolves through `./src/exporters/index.ts`.
|
|
46
|
+
- Export `./exporters/claude-agent-exporter` resolves through `./src/exporters/claude-agent-exporter.ts`.
|
|
47
|
+
- The package publishes 66 total export subpaths; keep docs aligned with `package.json`.
|
|
48
|
+
|
|
49
|
+
## Local Commands
|
|
50
|
+
|
|
51
|
+
- `bun run dev` — contractspec-bun-build dev
|
|
52
|
+
- `bun run build` — bun run prebuild && bun run build:bundle && bun run build:types
|
|
53
|
+
- `bun run test` — bun test
|
|
54
|
+
- `bun run lint` — bun lint:fix
|
|
55
|
+
- `bun run lint:check` — biome check .
|
|
56
|
+
- `bun run lint:fix` — biome check --write --unsafe --only=nursery/useSortedClasses . && biome check --write .
|
|
57
|
+
- `bun run typecheck` — tsc --noEmit
|
|
58
|
+
- `bun run publish:pkg` — bun publish --tolerate-republish --ignore-scripts --verbose
|
|
59
|
+
- `bun run publish:pkg:canary` — bun publish:pkg --tag canary
|
|
60
|
+
- `bun run clean` — rimraf dist .turbo
|
|
61
|
+
- `bun run build:bundle` — contractspec-bun-build transpile
|
|
62
|
+
- `bun run build:types` — contractspec-bun-build types
|
|
63
|
+
- `bun run prebuild` — contractspec-bun-build prebuild
|
|
64
|
+
|
|
65
|
+
## Recent Updates
|
|
66
|
+
|
|
67
|
+
- Missing dependencies (thanks to knip).
|
|
68
|
+
- Replace eslint+prettier by biomejs to optimize speed.
|
|
69
|
+
- Agentic workflows — subagents, memory tools, and next steps.
|
|
70
|
+
- Vnext ai-native.
|
|
71
|
+
- Backend operations + frontend rendering support.
|
|
72
|
+
- Add latest models and align defaults.
|
|
73
|
+
|
|
74
|
+
## Notes
|
|
75
|
+
|
|
76
|
+
- High blast radius — used by multiple bundles and libs.
|
|
77
|
+
- `AgentSpec` interface is a public contract; do not change its shape without a migration plan.
|
|
78
|
+
- MCP transport adapters must stay runtime-agnostic (no Node/browser-specific globals).
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import type { LanguageModel, Tool } from 'ai';
|
|
2
|
-
import type { KnowledgeRetriever } from '@contractspec/lib.knowledge/retriever';
|
|
3
1
|
import type { ModelSelector } from '@contractspec/lib.ai-providers/selector-types';
|
|
4
2
|
import type { OperationSpecRegistry } from '@contractspec/lib.contracts-spec/operations/registry';
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type { ToolHandler } from '../types';
|
|
8
|
-
import type { McpClientConfig } from '../tools/mcp-client';
|
|
9
|
-
import type { SubagentRegistry } from '../tools/tool-adapter';
|
|
10
|
-
import type { AgentMemoryStore } from '../tools/agent-memory-store';
|
|
3
|
+
import type { KnowledgeRetriever } from '@contractspec/lib.knowledge/retriever';
|
|
4
|
+
import type { LanguageModel, Tool } from 'ai';
|
|
11
5
|
import type { AgentSessionStore } from '../session/store';
|
|
6
|
+
import type { AgentRegistry } from '../spec/registry';
|
|
7
|
+
import type { AgentSpec } from '../spec/spec';
|
|
12
8
|
import type { TelemetryCollector } from '../telemetry/adapter';
|
|
13
9
|
import type { PostHogLLMConfig, PostHogTracingOptions } from '../telemetry/posthog-types';
|
|
10
|
+
import type { AgentMemoryStore } from '../tools/agent-memory-store';
|
|
11
|
+
import type { McpClientConfig } from '../tools/mcp-client';
|
|
12
|
+
import type { SubagentRegistry } from '../tools/tool-adapter';
|
|
13
|
+
import type { ToolHandler } from '../types';
|
|
14
14
|
import { ContractSpecAgent } from './contract-spec-agent';
|
|
15
15
|
/**
|
|
16
16
|
* Factory configuration for creating agents.
|