@lssm/lib.ai-agent 0.0.0-canary-20251217063201 → 0.0.0-canary-20251217073102
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.js +102 -1
- package/dist/agent/contract-spec-agent.js +147 -1
- package/dist/agent/index.js +4 -1
- package/dist/approval/index.js +3 -1
- package/dist/approval/workflow.js +159 -1
- package/dist/index.js +21 -1
- package/dist/knowledge/index.js +3 -1
- package/dist/knowledge/injector.js +49 -5
- package/dist/memory/in-memory.js +47 -2
- package/dist/memory/index.js +4 -1
- package/dist/memory/manager.js +79 -1
- package/dist/schema/index.js +4 -1
- package/dist/schema/json-schema-to-zod.js +123 -1
- package/dist/schema/schema-output.js +64 -1
- package/dist/session/index.js +3 -1
- package/dist/session/store.js +78 -1
- package/dist/spec/index.js +4 -1
- package/dist/spec/registry.js +116 -1
- package/dist/spec/spec.js +29 -1
- package/dist/telemetry/adapter.js +102 -1
- package/dist/telemetry/index.js +3 -1
- package/dist/tools/index.js +6 -1
- package/dist/tools/knowledge-tool.js +50 -6
- package/dist/tools/mcp-client.js +57 -1
- package/dist/tools/mcp-server.js +68 -1
- package/dist/tools/tool-adapter.js +79 -1
- package/package.json +7 -6
package/dist/tools/mcp-server.js
CHANGED
|
@@ -1 +1,68 @@
|
|
|
1
|
-
import{jsonSchemaToZodSafe
|
|
1
|
+
import { jsonSchemaToZodSafe } from "../schema/json-schema-to-zod.js";
|
|
2
|
+
import * as z$1 from "zod";
|
|
3
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
4
|
+
|
|
5
|
+
//#region src/tools/mcp-server.ts
|
|
6
|
+
/**
|
|
7
|
+
* Generate an MCP server that exposes a ContractSpec agent as a tool.
|
|
8
|
+
*
|
|
9
|
+
* This allows other AI agents (e.g., Claude Desktop, Cursor) to use
|
|
10
|
+
* your ContractSpec agents as tools, enabling agent-to-agent composition.
|
|
11
|
+
*
|
|
12
|
+
* @param agent - The ContractSpec agent to expose
|
|
13
|
+
* @param spec - The agent specification
|
|
14
|
+
* @returns MCP Server instance
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const server = agentToMcpServer(myAgent, myAgentSpec);
|
|
19
|
+
*
|
|
20
|
+
* // Run via stdio transport
|
|
21
|
+
* const transport = new StdioServerTransport();
|
|
22
|
+
* await server.connect(transport);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
function agentToMcpServer(agent, spec) {
|
|
26
|
+
const server = new McpServer({
|
|
27
|
+
name: spec.meta.name,
|
|
28
|
+
version: `${spec.meta.version}`
|
|
29
|
+
});
|
|
30
|
+
server.registerTool(spec.meta.name, {
|
|
31
|
+
description: spec.description ?? `Interact with ${spec.meta.name} agent`,
|
|
32
|
+
inputSchema: z$1.object({
|
|
33
|
+
message: z$1.string().describe("The message or query to send to the agent"),
|
|
34
|
+
sessionId: z$1.string().optional().describe("Optional session ID to continue a conversation")
|
|
35
|
+
})
|
|
36
|
+
}, async (args) => {
|
|
37
|
+
const { message, sessionId } = args;
|
|
38
|
+
return { content: [{
|
|
39
|
+
type: "text",
|
|
40
|
+
text: (await agent.generate({
|
|
41
|
+
prompt: message,
|
|
42
|
+
options: { sessionId }
|
|
43
|
+
})).text
|
|
44
|
+
}] };
|
|
45
|
+
});
|
|
46
|
+
for (const toolConfig of spec.tools) {
|
|
47
|
+
const inputSchema = toolConfig.schema ? jsonSchemaToZodSafe(toolConfig.schema) : z$1.object({});
|
|
48
|
+
server.registerTool(`${spec.meta.name}.${toolConfig.name}`, {
|
|
49
|
+
description: toolConfig.description ?? `Execute ${toolConfig.name} tool`,
|
|
50
|
+
inputSchema
|
|
51
|
+
}, async (args) => {
|
|
52
|
+
return { content: [{
|
|
53
|
+
type: "text",
|
|
54
|
+
text: (await agent.generate({ prompt: `Execute the ${toolConfig.name} tool with the following arguments: ${JSON.stringify(args)}` })).text
|
|
55
|
+
}] };
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return server;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Create an MCP server from configuration.
|
|
62
|
+
*/
|
|
63
|
+
function createAgentMcpServer(config) {
|
|
64
|
+
return agentToMcpServer(config.agent, config.spec);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
export { agentToMcpServer, createAgentMcpServer };
|
|
@@ -1 +1,79 @@
|
|
|
1
|
-
import{jsonSchemaToZodSafe
|
|
1
|
+
import { jsonSchemaToZodSafe } from "../schema/json-schema-to-zod.js";
|
|
2
|
+
import { tool } from "ai";
|
|
3
|
+
|
|
4
|
+
//#region src/tools/tool-adapter.ts
|
|
5
|
+
/**
|
|
6
|
+
* Convert ContractSpec AgentToolConfig to AI SDK CoreTool.
|
|
7
|
+
*
|
|
8
|
+
* @param specTool - The tool configuration from AgentSpec
|
|
9
|
+
* @param handler - The handler function for the tool
|
|
10
|
+
* @param context - Partial context to inject into handler calls
|
|
11
|
+
* @returns AI SDK CoreTool
|
|
12
|
+
*/
|
|
13
|
+
function specToolToAISDKTool(specTool, handler, context = {}) {
|
|
14
|
+
return tool({
|
|
15
|
+
description: specTool.description ?? specTool.name,
|
|
16
|
+
inputSchema: jsonSchemaToZodSafe(specTool.schema),
|
|
17
|
+
needsApproval: specTool.requiresApproval ?? !specTool.automationSafe,
|
|
18
|
+
execute: async (input) => {
|
|
19
|
+
const result = await handler(input, {
|
|
20
|
+
agentId: context.agentId ?? "unknown",
|
|
21
|
+
sessionId: context.sessionId ?? "unknown",
|
|
22
|
+
tenantId: context.tenantId,
|
|
23
|
+
actorId: context.actorId,
|
|
24
|
+
metadata: context.metadata,
|
|
25
|
+
signal: context.signal
|
|
26
|
+
});
|
|
27
|
+
return typeof result === "string" ? result : JSON.stringify(result);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Convert multiple ContractSpec tool configs to AI SDK tools.
|
|
33
|
+
*
|
|
34
|
+
* @param specTools - Array of tool configurations
|
|
35
|
+
* @param handlers - Map of tool name to handler function
|
|
36
|
+
* @param context - Partial context to inject into handler calls
|
|
37
|
+
* @returns Record of AI SDK tools keyed by name
|
|
38
|
+
*/
|
|
39
|
+
function specToolsToAISDKTools(specTools, handlers, context = {}) {
|
|
40
|
+
const tools = {};
|
|
41
|
+
for (const specTool of specTools) {
|
|
42
|
+
const handler = handlers.get(specTool.name);
|
|
43
|
+
if (!handler) throw new Error(`Missing handler for tool: ${specTool.name}`);
|
|
44
|
+
tools[specTool.name] = specToolToAISDKTool(specTool, handler, context);
|
|
45
|
+
}
|
|
46
|
+
return tools;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Type-safe tool handler builder.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const handler = createToolHandler<{ query: string }>((input, ctx) => {
|
|
54
|
+
* return `Searched for: ${input.query}`;
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
function createToolHandler(handler) {
|
|
59
|
+
return async (input, context) => {
|
|
60
|
+
return handler(input, context);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Build a tool handlers map from an object.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const handlers = buildToolHandlers({
|
|
69
|
+
* search: async (input: { query: string }) => `Found: ${input.query}`,
|
|
70
|
+
* calculate: async (input: { a: number, b: number }) => `${input.a + input.b}`,
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
function buildToolHandlers(handlersObj) {
|
|
75
|
+
return new Map(Object.entries(handlersObj));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
//#endregion
|
|
79
|
+
export { buildToolHandlers, createToolHandler, specToolToAISDKTool, specToolsToAISDKTools };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lssm/lib.ai-agent",
|
|
3
|
-
"version": "0.0.0-canary-
|
|
3
|
+
"version": "0.0.0-canary-20251217073102",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -25,17 +25,18 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"ai": "beta",
|
|
27
27
|
"@ai-sdk/mcp": "beta",
|
|
28
|
+
"@ai-sdk/anthropic": "beta",
|
|
29
|
+
"@ai-sdk/google": "beta",
|
|
28
30
|
"@ai-sdk/mistral": "beta",
|
|
29
31
|
"@ai-sdk/openai": "beta",
|
|
30
|
-
"@ai-sdk/anthropic": "beta",
|
|
31
32
|
"@modelcontextprotocol/sdk": "^1.24.3",
|
|
32
|
-
"@lssm/lib.contracts": "0.0.0-canary-
|
|
33
|
-
"@lssm/lib.knowledge": "0.0.0-canary-
|
|
33
|
+
"@lssm/lib.contracts": "0.0.0-canary-20251217073102",
|
|
34
|
+
"@lssm/lib.knowledge": "0.0.0-canary-20251217073102",
|
|
34
35
|
"zod": "^4.1.13"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
|
-
"@lssm/tool.tsdown": "0.0.0-canary-
|
|
38
|
-
"@lssm/tool.typescript": "0.0.0-canary-
|
|
38
|
+
"@lssm/tool.tsdown": "0.0.0-canary-20251217073102",
|
|
39
|
+
"@lssm/tool.typescript": "0.0.0-canary-20251217073102",
|
|
39
40
|
"tsdown": "^0.17.4",
|
|
40
41
|
"typescript": "^5.9.3"
|
|
41
42
|
},
|