@kadi.build/core 0.0.1-alpha.1 → 0.0.1-alpha.11
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 +361 -230
- package/dist/abilities/AbilityCache.d.ts +242 -0
- package/dist/abilities/AbilityCache.d.ts.map +1 -0
- package/dist/abilities/AbilityCache.js +285 -0
- package/dist/abilities/AbilityCache.js.map +1 -0
- package/dist/abilities/AbilityContext.d.ts +215 -0
- package/dist/abilities/AbilityContext.d.ts.map +1 -0
- package/dist/abilities/AbilityContext.js +36 -0
- package/dist/abilities/AbilityContext.js.map +1 -0
- package/dist/abilities/AbilityLoader.d.ts +203 -0
- package/dist/abilities/AbilityLoader.d.ts.map +1 -0
- package/dist/abilities/AbilityLoader.js +343 -0
- package/dist/abilities/AbilityLoader.js.map +1 -0
- package/dist/abilities/AbilityProxy.d.ts +496 -0
- package/dist/abilities/AbilityProxy.d.ts.map +1 -0
- package/dist/abilities/AbilityProxy.js +551 -0
- package/dist/abilities/AbilityProxy.js.map +1 -0
- package/dist/abilities/AbilityValidator.d.ts +172 -0
- package/dist/abilities/AbilityValidator.d.ts.map +1 -0
- package/dist/abilities/AbilityValidator.js +253 -0
- package/dist/abilities/AbilityValidator.js.map +1 -0
- package/dist/abilities/index.d.ts +26 -0
- package/dist/abilities/index.d.ts.map +1 -0
- package/dist/abilities/index.js +23 -0
- package/dist/abilities/index.js.map +1 -0
- package/dist/abilities/types.d.ts +223 -0
- package/dist/abilities/types.d.ts.map +1 -0
- package/dist/abilities/types.js +10 -0
- package/dist/abilities/types.js.map +1 -0
- package/dist/api/index.d.ts +92 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +124 -0
- package/dist/api/index.js.map +1 -0
- package/dist/broker/BrokerConnection.d.ts +253 -0
- package/dist/broker/BrokerConnection.d.ts.map +1 -0
- package/dist/broker/BrokerConnection.js +434 -0
- package/dist/broker/BrokerConnection.js.map +1 -0
- package/dist/broker/BrokerConnectionManager.d.ts +216 -0
- package/dist/broker/BrokerConnectionManager.d.ts.map +1 -0
- package/dist/broker/BrokerConnectionManager.js +305 -0
- package/dist/broker/BrokerConnectionManager.js.map +1 -0
- package/dist/broker/BrokerProtocol.d.ts +280 -0
- package/dist/broker/BrokerProtocol.d.ts.map +1 -0
- package/dist/broker/BrokerProtocol.js +466 -0
- package/dist/broker/BrokerProtocol.js.map +1 -0
- package/dist/broker/index.d.ts +9 -0
- package/dist/broker/index.d.ts.map +1 -0
- package/dist/broker/index.js +9 -0
- package/dist/broker/index.js.map +1 -0
- package/dist/client/KadiClient.d.ts +459 -0
- package/dist/client/KadiClient.d.ts.map +1 -0
- package/dist/client/KadiClient.js +902 -0
- package/dist/client/KadiClient.js.map +1 -0
- package/dist/client/index.d.ts +7 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +7 -0
- package/dist/client/index.js.map +1 -0
- package/dist/config/ConfigLoader.d.ts +138 -0
- package/dist/config/ConfigLoader.d.ts.map +1 -0
- package/dist/config/ConfigLoader.js +226 -0
- package/dist/config/ConfigLoader.js.map +1 -0
- package/dist/config/ConfigResolver.d.ts +135 -0
- package/dist/config/ConfigResolver.d.ts.map +1 -0
- package/dist/config/ConfigResolver.js +282 -0
- package/dist/config/ConfigResolver.js.map +1 -0
- package/dist/config/index.d.ts +8 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +8 -0
- package/dist/config/index.js.map +1 -0
- package/dist/errors/index.d.ts +9 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +8 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/events/EventHub.d.ts +172 -0
- package/dist/events/EventHub.d.ts.map +1 -0
- package/dist/events/EventHub.js +333 -0
- package/dist/events/EventHub.js.map +1 -0
- package/dist/events/index.d.ts +7 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +7 -0
- package/dist/events/index.js.map +1 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +67 -0
- package/dist/index.js.map +1 -0
- package/dist/messages/index.d.ts +33 -0
- package/dist/messages/index.d.ts.map +1 -0
- package/dist/messages/index.js +33 -0
- package/dist/messages/index.js.map +1 -0
- package/dist/schemas/index.d.ts +22 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +27 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/kadi-extensions.d.ts +231 -0
- package/dist/schemas/kadi-extensions.d.ts.map +1 -0
- package/dist/schemas/kadi-extensions.js +14 -0
- package/dist/schemas/kadi-extensions.js.map +1 -0
- package/dist/schemas/mcp/schema.d.ts +1399 -0
- package/dist/schemas/mcp/schema.d.ts.map +1 -0
- package/dist/schemas/mcp/schema.js +53 -0
- package/dist/schemas/mcp/schema.js.map +1 -0
- package/dist/schemas/mcp/version.d.ts +37 -0
- package/dist/schemas/mcp/version.d.ts.map +1 -0
- package/dist/schemas/mcp/version.js +39 -0
- package/dist/schemas/mcp/version.js.map +1 -0
- package/dist/schemas/schema-builders.d.ts +178 -0
- package/dist/schemas/schema-builders.d.ts.map +1 -0
- package/dist/schemas/schema-builders.js +258 -0
- package/dist/schemas/schema-builders.js.map +1 -0
- package/dist/schemas/zod-helpers.d.ts +129 -0
- package/dist/schemas/zod-helpers.d.ts.map +1 -0
- package/dist/schemas/zod-helpers.js +225 -0
- package/dist/schemas/zod-helpers.js.map +1 -0
- package/dist/schemas/zod-to-json-schema.d.ts +159 -0
- package/dist/schemas/zod-to-json-schema.d.ts.map +1 -0
- package/dist/schemas/zod-to-json-schema.js +154 -0
- package/dist/schemas/zod-to-json-schema.js.map +1 -0
- package/dist/tools/ToolRegistry.d.ts +256 -0
- package/dist/tools/ToolRegistry.d.ts.map +1 -0
- package/dist/tools/ToolRegistry.js +340 -0
- package/dist/tools/ToolRegistry.js.map +1 -0
- package/dist/tools/index.d.ts +7 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +7 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/transports/BrokerTransport.d.ts +151 -0
- package/dist/transports/BrokerTransport.d.ts.map +1 -0
- package/dist/transports/BrokerTransport.js +261 -0
- package/dist/transports/BrokerTransport.js.map +1 -0
- package/dist/transports/NativeTransport.d.ts +178 -0
- package/dist/transports/NativeTransport.d.ts.map +1 -0
- package/dist/transports/NativeTransport.js +397 -0
- package/dist/transports/NativeTransport.js.map +1 -0
- package/dist/transports/StdioTransport.d.ts +250 -0
- package/dist/transports/StdioTransport.d.ts.map +1 -0
- package/dist/transports/StdioTransport.js +487 -0
- package/dist/transports/StdioTransport.js.map +1 -0
- package/dist/transports/index.d.ts +10 -0
- package/dist/transports/index.d.ts.map +1 -0
- package/dist/transports/index.js +9 -0
- package/dist/transports/index.js.map +1 -0
- package/dist/types/broker.d.ts +279 -0
- package/dist/types/broker.d.ts.map +1 -0
- package/dist/types/broker.js +19 -0
- package/dist/types/broker.js.map +1 -0
- package/dist/types/config.d.ts +325 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +17 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/errors.d.ts +178 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/errors.js +165 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/events.d.ts +210 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +8 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/index.d.ts +34 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +21 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/protocol.d.ts +48 -0
- package/dist/types/protocol.d.ts.map +1 -0
- package/dist/types/protocol.js +11 -0
- package/dist/types/protocol.js.map +1 -0
- package/dist/types/tools.d.ts +67 -0
- package/dist/types/tools.d.ts.map +1 -0
- package/dist/types/tools.js +16 -0
- package/dist/types/tools.js.map +1 -0
- package/dist/types/transport.d.ts +250 -0
- package/dist/types/transport.d.ts.map +1 -0
- package/dist/types/transport.js +18 -0
- package/dist/types/transport.js.map +1 -0
- package/dist/types/zod-tools.d.ts +198 -0
- package/dist/types/zod-tools.d.ts.map +1 -0
- package/dist/types/zod-tools.js +14 -0
- package/dist/types/zod-tools.js.map +1 -0
- package/dist/utils/StdioMessageReader.d.ts +122 -0
- package/dist/utils/StdioMessageReader.d.ts.map +1 -0
- package/dist/utils/StdioMessageReader.js +209 -0
- package/dist/utils/StdioMessageReader.js.map +1 -0
- package/dist/utils/StdioMessageWriter.d.ts +104 -0
- package/dist/utils/StdioMessageWriter.d.ts.map +1 -0
- package/dist/utils/StdioMessageWriter.js +162 -0
- package/dist/utils/StdioMessageWriter.js.map +1 -0
- package/dist/validation/SchemaValidator.d.ts +208 -0
- package/dist/validation/SchemaValidator.d.ts.map +1 -0
- package/dist/validation/SchemaValidator.js +411 -0
- package/dist/validation/SchemaValidator.js.map +1 -0
- package/dist/validation/index.d.ts +11 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +10 -0
- package/dist/validation/index.js.map +1 -0
- package/package.json +70 -5
- package/agent.json +0 -18
- package/broker.js +0 -214
- package/index.js +0 -370
- package/ipc.js +0 -220
- package/ipcInterfaces/pythonAbilityIPC.py +0 -177
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Protocol Types Module
|
|
3
|
+
* ======================
|
|
4
|
+
*
|
|
5
|
+
* Re-exports protocol-related types for kadi-broker and other consumers.
|
|
6
|
+
* This provides a clean import path: @kadi.build/core/types/protocol
|
|
7
|
+
*
|
|
8
|
+
* @module types/protocol
|
|
9
|
+
*/
|
|
10
|
+
import type { NetworkId, ToolTag, KadiTool } from '../schemas/kadi-extensions.js';
|
|
11
|
+
import type { AgentRole } from './config.js';
|
|
12
|
+
export type { JsonRpcRequest, JsonRpcResponse, JsonRpcNotification, JsonRpcError, PendingRequest } from './broker.js';
|
|
13
|
+
export type { NetworkId, ToolTag };
|
|
14
|
+
export interface Provider {
|
|
15
|
+
agentId: string;
|
|
16
|
+
agentName?: string;
|
|
17
|
+
networks: NetworkId[];
|
|
18
|
+
tags?: ToolTag[];
|
|
19
|
+
displayName?: string;
|
|
20
|
+
lastSeen?: number;
|
|
21
|
+
registeredAt?: number;
|
|
22
|
+
}
|
|
23
|
+
export interface SystemSnapshot {
|
|
24
|
+
agents: Array<{
|
|
25
|
+
id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
type: 'agent';
|
|
28
|
+
tools: string[];
|
|
29
|
+
networks: string[];
|
|
30
|
+
status: 'active' | 'disconnected';
|
|
31
|
+
}>;
|
|
32
|
+
networks: Array<{
|
|
33
|
+
id: string;
|
|
34
|
+
name: string;
|
|
35
|
+
type: 'network';
|
|
36
|
+
status: 'active';
|
|
37
|
+
}>;
|
|
38
|
+
connections: Array<{
|
|
39
|
+
from: string;
|
|
40
|
+
to: string;
|
|
41
|
+
status: 'connected' | 'disconnected';
|
|
42
|
+
}>;
|
|
43
|
+
timestamp: string;
|
|
44
|
+
}
|
|
45
|
+
export type { KadiTool as Tool };
|
|
46
|
+
export type { AgentRole as SessionRole };
|
|
47
|
+
export type QueueKind = 'direct' | 'fanout' | 'topic' | 'agent';
|
|
48
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/types/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAClF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAG7C,YAAY,EACV,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,cAAc,EACf,MAAM,aAAa,CAAC;AAGrB,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;AAGnC,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,SAAS,EAAE,CAAC;IACtB,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAGD,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,KAAK,CAAC;QACZ,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,OAAO,CAAC;QACd,KAAK,EAAE,MAAM,EAAE,CAAC;QAChB,QAAQ,EAAE,MAAM,EAAE,CAAC;QACnB,MAAM,EAAE,QAAQ,GAAG,cAAc,CAAC;KACnC,CAAC,CAAC;IACH,QAAQ,EAAE,KAAK,CAAC;QACd,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,SAAS,CAAC;QAChB,MAAM,EAAE,QAAQ,CAAC;KAClB,CAAC,CAAC;IACH,WAAW,EAAE,KAAK,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,EAAE,EAAE,MAAM,CAAC;QACX,MAAM,EAAE,WAAW,GAAG,cAAc,CAAC;KACtC,CAAC,CAAC;IACH,SAAS,EAAE,MAAM,CAAC;CACnB;AAGD,YAAY,EAAE,QAAQ,IAAI,IAAI,EAAE,CAAC;AAGjC,YAAY,EAAE,SAAS,IAAI,WAAW,EAAE,CAAC;AAGzC,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Protocol Types Module
|
|
3
|
+
* ======================
|
|
4
|
+
*
|
|
5
|
+
* Re-exports protocol-related types for kadi-broker and other consumers.
|
|
6
|
+
* This provides a clean import path: @kadi.build/core/types/protocol
|
|
7
|
+
*
|
|
8
|
+
* @module types/protocol
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/types/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Types (MCP-Based)
|
|
3
|
+
* ========================
|
|
4
|
+
*
|
|
5
|
+
* Type definitions for tool registration, handlers, and schemas using the
|
|
6
|
+
* Model Context Protocol (MCP) standard.
|
|
7
|
+
*
|
|
8
|
+
* **Breaking Change (v2.0.0)**:
|
|
9
|
+
* - Replaced Zod schemas with MCP JSON Schemas
|
|
10
|
+
* - Full MCP compliance with KADI extensions
|
|
11
|
+
* - See migration guide for upgrading from v1.x
|
|
12
|
+
*
|
|
13
|
+
* @module types/tools
|
|
14
|
+
*/
|
|
15
|
+
export type { KadiTool, KadiToolResult, ToolDefinition, ToolHandler, RegisteredTool, ToolTag, NetworkId, ToolDiscoveryQuery, ToolDiscoveryResult } from '../schemas/index.js';
|
|
16
|
+
export type { McpTool, McpCallToolResult, ToolAnnotations, ListToolsRequest, ListToolsResult, CallToolRequest, ToolListChangedNotification } from '../schemas/index.js';
|
|
17
|
+
/**
|
|
18
|
+
* Tool invocation result
|
|
19
|
+
*
|
|
20
|
+
* Extended version of MCP CallToolResult with KADI-specific metadata.
|
|
21
|
+
*
|
|
22
|
+
* @template T - Result data type
|
|
23
|
+
*/
|
|
24
|
+
export interface ToolInvocationResult<T = unknown> {
|
|
25
|
+
/**
|
|
26
|
+
* Whether the invocation succeeded
|
|
27
|
+
*/
|
|
28
|
+
success: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* The result data if successful
|
|
31
|
+
*/
|
|
32
|
+
data?: T;
|
|
33
|
+
/**
|
|
34
|
+
* Error information if failed
|
|
35
|
+
*/
|
|
36
|
+
error?: {
|
|
37
|
+
code: string;
|
|
38
|
+
message: string;
|
|
39
|
+
details?: unknown;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Execution metadata
|
|
43
|
+
*/
|
|
44
|
+
metadata?: {
|
|
45
|
+
/**
|
|
46
|
+
* Execution time in milliseconds
|
|
47
|
+
*/
|
|
48
|
+
executionTime?: number;
|
|
49
|
+
/**
|
|
50
|
+
* Timestamp when execution started
|
|
51
|
+
*/
|
|
52
|
+
timestamp?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Agent that executed the tool
|
|
55
|
+
*/
|
|
56
|
+
agentId?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Network the tool was executed on
|
|
59
|
+
*/
|
|
60
|
+
networkId?: string;
|
|
61
|
+
/**
|
|
62
|
+
* Whether result was cached
|
|
63
|
+
*/
|
|
64
|
+
cacheHit?: boolean;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/types/tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,YAAY,EACV,QAAQ,EACR,cAAc,EACd,cAAc,EACd,WAAW,EACX,cAAc,EACd,OAAO,EACP,SAAS,EACT,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,qBAAqB,CAAC;AAG7B,YAAY,EACV,OAAO,EACP,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,2BAA2B,EAC5B,MAAM,qBAAqB,CAAC;AAE7B;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB,CAAC,CAAC,GAAG,OAAO;IAC/C;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,IAAI,CAAC,EAAE,CAAC,CAAC;IAET;;OAEG;IACH,KAAK,CAAC,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,CAAC;IAEF;;OAEG;IACH,QAAQ,CAAC,EAAE;QACT;;WAEG;QACH,aAAa,CAAC,EAAE,MAAM,CAAC;QAEvB;;WAEG;QACH,SAAS,CAAC,EAAE,MAAM,CAAC;QAEnB;;WAEG;QACH,OAAO,CAAC,EAAE,MAAM,CAAC;QAEjB;;WAEG;QACH,SAAS,CAAC,EAAE,MAAM,CAAC;QAEnB;;WAEG;QACH,QAAQ,CAAC,EAAE,OAAO,CAAC;KACpB,CAAC;CACH"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Types (MCP-Based)
|
|
3
|
+
* ========================
|
|
4
|
+
*
|
|
5
|
+
* Type definitions for tool registration, handlers, and schemas using the
|
|
6
|
+
* Model Context Protocol (MCP) standard.
|
|
7
|
+
*
|
|
8
|
+
* **Breaking Change (v2.0.0)**:
|
|
9
|
+
* - Replaced Zod schemas with MCP JSON Schemas
|
|
10
|
+
* - Full MCP compliance with KADI extensions
|
|
11
|
+
* - See migration guide for upgrading from v1.x
|
|
12
|
+
*
|
|
13
|
+
* @module types/tools
|
|
14
|
+
*/
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/types/tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG"}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transport Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for ability transports.
|
|
5
|
+
* Transports enable loading and communicating with abilities across different protocols.
|
|
6
|
+
*/
|
|
7
|
+
import type { EventEmitter } from 'events';
|
|
8
|
+
/**
|
|
9
|
+
* Ability Transport Interface
|
|
10
|
+
*
|
|
11
|
+
* All transports (Native, Stdio, Broker) must implement this interface.
|
|
12
|
+
* This provides a uniform way to load and communicate with abilities
|
|
13
|
+
* regardless of their deployment location or protocol.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* class MyTransport implements AbilityTransport {
|
|
18
|
+
* async connect() { / * ... * / }
|
|
19
|
+
* async invoke(method, params) { / * ... * / }
|
|
20
|
+
* getMethods() { / * ... * / }
|
|
21
|
+
* async disconnect() { / * ... * / }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export interface AbilityTransport extends EventEmitter {
|
|
26
|
+
/**
|
|
27
|
+
* Establish connection to the ability
|
|
28
|
+
*
|
|
29
|
+
* - Native: Load the module from disk
|
|
30
|
+
* - Stdio: Spawn the child process
|
|
31
|
+
* - Broker: Connect to WebSocket and authenticate
|
|
32
|
+
*
|
|
33
|
+
* @throws {Error} If connection fails
|
|
34
|
+
*/
|
|
35
|
+
connect(): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Invoke a method on the connected ability
|
|
38
|
+
*
|
|
39
|
+
* @template TInput - Input parameter type
|
|
40
|
+
* @template TOutput - Return value type
|
|
41
|
+
*
|
|
42
|
+
* @param method - Method name to invoke
|
|
43
|
+
* @param params - Parameters to pass
|
|
44
|
+
* @returns Promise resolving to the method result
|
|
45
|
+
*
|
|
46
|
+
* @throws {Error} If method doesn't exist or invocation fails
|
|
47
|
+
*/
|
|
48
|
+
invoke<TInput = unknown, TOutput = unknown>(method: string, params: TInput): Promise<TOutput>;
|
|
49
|
+
/**
|
|
50
|
+
* Get list of available methods on this ability
|
|
51
|
+
*
|
|
52
|
+
* @returns Array of method names
|
|
53
|
+
*/
|
|
54
|
+
getMethods(): string[];
|
|
55
|
+
/**
|
|
56
|
+
* Disconnect and cleanup resources
|
|
57
|
+
*
|
|
58
|
+
* - Native: Cleanup module references
|
|
59
|
+
* - Stdio: Terminate child process
|
|
60
|
+
* - Broker: Close WebSocket connection
|
|
61
|
+
*/
|
|
62
|
+
disconnect(): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Get schema for a specific method (optional)
|
|
65
|
+
*
|
|
66
|
+
* @param method - Method name
|
|
67
|
+
* @returns Method schema if available
|
|
68
|
+
*/
|
|
69
|
+
getMethodSchema?(method: string): MethodSchema | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Publish an event from the ability (optional)
|
|
72
|
+
*
|
|
73
|
+
* @param eventName - Event name
|
|
74
|
+
* @param data - Event data
|
|
75
|
+
*/
|
|
76
|
+
publishEvent?(eventName: string, data: unknown): void;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Method schema definition
|
|
80
|
+
*/
|
|
81
|
+
export interface MethodSchema {
|
|
82
|
+
/**
|
|
83
|
+
* Description of what the method does
|
|
84
|
+
*/
|
|
85
|
+
description?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Input schema (JSON Schema)
|
|
88
|
+
*/
|
|
89
|
+
inputSchema?: Record<string, unknown>;
|
|
90
|
+
/**
|
|
91
|
+
* Output schema (JSON Schema)
|
|
92
|
+
*/
|
|
93
|
+
outputSchema?: Record<string, unknown>;
|
|
94
|
+
/**
|
|
95
|
+
* Example usage
|
|
96
|
+
*/
|
|
97
|
+
examples?: Array<{
|
|
98
|
+
input: unknown;
|
|
99
|
+
output: unknown;
|
|
100
|
+
}>;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Base transport configuration options
|
|
104
|
+
*/
|
|
105
|
+
export interface TransportOptions {
|
|
106
|
+
/**
|
|
107
|
+
* Ability name
|
|
108
|
+
*/
|
|
109
|
+
abilityName: string;
|
|
110
|
+
/**
|
|
111
|
+
* Ability version (optional)
|
|
112
|
+
*/
|
|
113
|
+
abilityVersion?: string;
|
|
114
|
+
/**
|
|
115
|
+
* Timeout for method invocations in milliseconds
|
|
116
|
+
* @default 30000
|
|
117
|
+
*/
|
|
118
|
+
timeout?: number;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Native transport options (in-process loading)
|
|
122
|
+
*/
|
|
123
|
+
export interface NativeTransportOptions extends TransportOptions {
|
|
124
|
+
/**
|
|
125
|
+
* Path to ability directory
|
|
126
|
+
*/
|
|
127
|
+
abilityPath: string;
|
|
128
|
+
/**
|
|
129
|
+
* Entry point file (relative to abilityPath)
|
|
130
|
+
* @default 'index.js'
|
|
131
|
+
*/
|
|
132
|
+
entryPoint?: string;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Stdio transport options (child process)
|
|
136
|
+
*/
|
|
137
|
+
export interface StdioTransportOptions extends TransportOptions {
|
|
138
|
+
/**
|
|
139
|
+
* Path to ability directory
|
|
140
|
+
*/
|
|
141
|
+
abilityPath: string;
|
|
142
|
+
/**
|
|
143
|
+
* Command to execute
|
|
144
|
+
* @default 'node'
|
|
145
|
+
*/
|
|
146
|
+
command?: string;
|
|
147
|
+
/**
|
|
148
|
+
* Command arguments
|
|
149
|
+
* @default ['index.js']
|
|
150
|
+
*/
|
|
151
|
+
args?: string[];
|
|
152
|
+
/**
|
|
153
|
+
* Environment variables to pass
|
|
154
|
+
*/
|
|
155
|
+
env?: Record<string, string>;
|
|
156
|
+
/**
|
|
157
|
+
* Working directory
|
|
158
|
+
*/
|
|
159
|
+
cwd?: string;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Broker transport options (remote ability)
|
|
163
|
+
*/
|
|
164
|
+
export interface BrokerTransportOptions extends TransportOptions {
|
|
165
|
+
/**
|
|
166
|
+
* Broker URL
|
|
167
|
+
*/
|
|
168
|
+
brokerUrl: string;
|
|
169
|
+
/**
|
|
170
|
+
* Broker name identifier
|
|
171
|
+
*/
|
|
172
|
+
brokerName?: string;
|
|
173
|
+
/**
|
|
174
|
+
* Networks to search for the ability
|
|
175
|
+
*/
|
|
176
|
+
networks?: string[];
|
|
177
|
+
/**
|
|
178
|
+
* Authentication token
|
|
179
|
+
*/
|
|
180
|
+
authToken?: string;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Message transport interface (low-level)
|
|
184
|
+
*
|
|
185
|
+
* This is for the underlying message-passing layer (WebSocket, stdio streams, etc.)
|
|
186
|
+
* Distinct from AbilityTransport which is higher-level.
|
|
187
|
+
*/
|
|
188
|
+
export interface MessageTransport extends EventEmitter {
|
|
189
|
+
/**
|
|
190
|
+
* Connect to the message transport
|
|
191
|
+
*/
|
|
192
|
+
connect(): Promise<void>;
|
|
193
|
+
/**
|
|
194
|
+
* Disconnect from the message transport
|
|
195
|
+
*/
|
|
196
|
+
disconnect(): Promise<void>;
|
|
197
|
+
/**
|
|
198
|
+
* Send raw data
|
|
199
|
+
*/
|
|
200
|
+
send(data: Buffer | string): Promise<void>;
|
|
201
|
+
/**
|
|
202
|
+
* Check if connected
|
|
203
|
+
*/
|
|
204
|
+
isConnected(): boolean;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Transport discovery result
|
|
208
|
+
*/
|
|
209
|
+
export interface TransportDiscoveryResult {
|
|
210
|
+
/**
|
|
211
|
+
* Available methods
|
|
212
|
+
*/
|
|
213
|
+
methods: string[];
|
|
214
|
+
/**
|
|
215
|
+
* Method schemas
|
|
216
|
+
*/
|
|
217
|
+
schemas?: Map<string, MethodSchema>;
|
|
218
|
+
/**
|
|
219
|
+
* Ability metadata
|
|
220
|
+
*/
|
|
221
|
+
metadata?: {
|
|
222
|
+
name: string;
|
|
223
|
+
version?: string;
|
|
224
|
+
description?: string;
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Stdio message framing
|
|
229
|
+
*/
|
|
230
|
+
export interface StdioFrame {
|
|
231
|
+
/**
|
|
232
|
+
* Message length
|
|
233
|
+
*/
|
|
234
|
+
length: number;
|
|
235
|
+
/**
|
|
236
|
+
* Message content (JSON)
|
|
237
|
+
*/
|
|
238
|
+
content: unknown;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Stdio protocol message types
|
|
242
|
+
*/
|
|
243
|
+
export declare enum StdioMessageType {
|
|
244
|
+
DISCOVER = "__kadi_discover",
|
|
245
|
+
INVOKE = "__kadi_invoke",
|
|
246
|
+
RESULT = "__kadi_result",
|
|
247
|
+
ERROR = "__kadi_error",
|
|
248
|
+
EVENT = "__kadi_event"
|
|
249
|
+
}
|
|
250
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/types/transport.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transport Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for ability transports.
|
|
5
|
+
* Transports enable loading and communicating with abilities across different protocols.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Stdio protocol message types
|
|
9
|
+
*/
|
|
10
|
+
export var StdioMessageType;
|
|
11
|
+
(function (StdioMessageType) {
|
|
12
|
+
StdioMessageType["DISCOVER"] = "__kadi_discover";
|
|
13
|
+
StdioMessageType["INVOKE"] = "__kadi_invoke";
|
|
14
|
+
StdioMessageType["RESULT"] = "__kadi_result";
|
|
15
|
+
StdioMessageType["ERROR"] = "__kadi_error";
|
|
16
|
+
StdioMessageType["EVENT"] = "__kadi_event";
|
|
17
|
+
})(StdioMessageType || (StdioMessageType = {}));
|
|
18
|
+
//# sourceMappingURL=transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../src/types/transport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgRH;;GAEG;AACH,MAAM,CAAN,IAAY,gBAMX;AAND,WAAY,gBAAgB;IAC1B,gDAA4B,CAAA;IAC5B,4CAAwB,CAAA;IACxB,4CAAwB,CAAA;IACxB,0CAAsB,CAAA;IACtB,0CAAsB,CAAA;AACxB,CAAC,EANW,gBAAgB,KAAhB,gBAAgB,QAM3B"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for Zod-based tool registration
|
|
3
|
+
*
|
|
4
|
+
* This module provides TypeScript types for registering tools using Zod schemas
|
|
5
|
+
* instead of manual JSON Schema definitions. This approach provides:
|
|
6
|
+
* - Single source of truth (Zod schema)
|
|
7
|
+
* - Automatic TypeScript type inference
|
|
8
|
+
* - Runtime validation with excellent error messages
|
|
9
|
+
* - Significantly less boilerplate code
|
|
10
|
+
*
|
|
11
|
+
* @module types/zod-tools
|
|
12
|
+
*/
|
|
13
|
+
import type { z } from 'zod';
|
|
14
|
+
import type { KadiTool, ToolHandler } from './tools.js';
|
|
15
|
+
/**
|
|
16
|
+
* Tool configuration using Zod schemas
|
|
17
|
+
*
|
|
18
|
+
* This interface allows developers to define tools using Zod schemas
|
|
19
|
+
* for input and output validation. The schemas are automatically converted
|
|
20
|
+
* to MCP-compliant JSON Schema at registration time.
|
|
21
|
+
*
|
|
22
|
+
* @typeParam TInput - Zod schema type for tool input
|
|
23
|
+
* @typeParam TOutput - Zod schema type for tool output
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* import { z } from 'zod';
|
|
28
|
+
*
|
|
29
|
+
* const config: ZodToolConfig = {
|
|
30
|
+
* name: 'add',
|
|
31
|
+
* description: 'Add two numbers',
|
|
32
|
+
* version: '1.0.0',
|
|
33
|
+
* input: z.object({
|
|
34
|
+
* a: z.number().describe('First number'),
|
|
35
|
+
* b: z.number().describe('Second number')
|
|
36
|
+
* }),
|
|
37
|
+
* output: z.object({
|
|
38
|
+
* result: z.number().describe('Sum of a and b')
|
|
39
|
+
* }),
|
|
40
|
+
* handler: async ({ a, b }) => ({ result: a + b })
|
|
41
|
+
* };
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export interface ZodToolConfig<TInput extends z.ZodTypeAny = z.ZodTypeAny, TOutput extends z.ZodTypeAny = z.ZodTypeAny> {
|
|
45
|
+
/**
|
|
46
|
+
* Tool name
|
|
47
|
+
*
|
|
48
|
+
* Must be unique within the client. Used for tool discovery and invocation.
|
|
49
|
+
* Recommended format: lowercase, hyphen-separated (e.g., 'deploy-to-akash')
|
|
50
|
+
*/
|
|
51
|
+
name: string;
|
|
52
|
+
/**
|
|
53
|
+
* Human-readable description
|
|
54
|
+
*
|
|
55
|
+
* Displayed in tool lists and helps LLMs understand when to use this tool.
|
|
56
|
+
* Should be clear and concise (1-2 sentences).
|
|
57
|
+
*/
|
|
58
|
+
description?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Display title for the tool
|
|
61
|
+
*
|
|
62
|
+
* Optional short title shown in UIs. If not provided, uses `name`.
|
|
63
|
+
*/
|
|
64
|
+
title?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Semantic version
|
|
67
|
+
*
|
|
68
|
+
* Format: MAJOR.MINOR.PATCH (e.g., "1.0.0", "2.3.1")
|
|
69
|
+
* Follows semver specification: https://semver.org/
|
|
70
|
+
*/
|
|
71
|
+
version?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Routing tags
|
|
74
|
+
*
|
|
75
|
+
* Tags provide hints for intelligent tool selection and routing.
|
|
76
|
+
* Examples:
|
|
77
|
+
* - Performance: 'cpu-intensive', 'memory-heavy', 'gpu-required'
|
|
78
|
+
* - Execution: 'batch', 'real-time', 'async'
|
|
79
|
+
* - Domain: 'math', 'crypto', 'file-ops', 'network'
|
|
80
|
+
*/
|
|
81
|
+
tags?: string[];
|
|
82
|
+
/**
|
|
83
|
+
* Network availability
|
|
84
|
+
*
|
|
85
|
+
* Networks this tool is available on. Tools can be scoped to specific
|
|
86
|
+
* networks for isolation and organization.
|
|
87
|
+
* If not specified, defaults to ['global'].
|
|
88
|
+
*/
|
|
89
|
+
networks?: string[];
|
|
90
|
+
/**
|
|
91
|
+
* Input schema (Zod)
|
|
92
|
+
*
|
|
93
|
+
* Zod schema defining the structure and validation rules for tool input.
|
|
94
|
+
* Will be automatically converted to MCP-compliant JSON Schema.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* input: z.object({
|
|
99
|
+
* name: z.string().min(1).describe('User name'),
|
|
100
|
+
* age: z.number().int().positive().optional()
|
|
101
|
+
* })
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
input: TInput;
|
|
105
|
+
/**
|
|
106
|
+
* Output schema (Zod)
|
|
107
|
+
*
|
|
108
|
+
* Zod schema defining the structure and validation rules for tool output.
|
|
109
|
+
* Will be automatically converted to MCP-compliant JSON Schema.
|
|
110
|
+
* Output validation is optional but recommended for debugging.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* output: z.object({
|
|
115
|
+
* success: z.boolean(),
|
|
116
|
+
* message: z.string()
|
|
117
|
+
* })
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
output: TOutput;
|
|
121
|
+
/**
|
|
122
|
+
* Tool handler function
|
|
123
|
+
*
|
|
124
|
+
* Implements the tool's logic. Receives validated input (typed automatically
|
|
125
|
+
* from `input` schema) and must return output matching `output` schema.
|
|
126
|
+
*
|
|
127
|
+
* Input validation happens automatically before handler is called.
|
|
128
|
+
* Output validation happens automatically after handler returns (if output schema provided).
|
|
129
|
+
*
|
|
130
|
+
* @param params - Validated input matching `input` schema type
|
|
131
|
+
* @returns Result matching `output` schema type
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* handler: async (params) => {
|
|
136
|
+
* // params is fully typed based on input schema!
|
|
137
|
+
* const result = await someOperation(params.name);
|
|
138
|
+
* return { success: true, message: result };
|
|
139
|
+
* }
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
handler: (params: z.infer<TInput>) => Promise<z.infer<TOutput>> | z.infer<TOutput>;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Result of createTool() - ready to register with KadiClient
|
|
146
|
+
*
|
|
147
|
+
* This interface represents a tool that has been created from Zod schemas
|
|
148
|
+
* and converted to the standard KadiTool format. It includes both:
|
|
149
|
+
* - The tool definition (with JSON Schema)
|
|
150
|
+
* - The wrapped handler (with auto-validation)
|
|
151
|
+
*
|
|
152
|
+
* @typeParam TInput - Inferred TypeScript type from input Zod schema
|
|
153
|
+
* @typeParam TOutput - Inferred TypeScript type from output Zod schema
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* const tool = createTool(config);
|
|
158
|
+
* client.registerTool(tool.definition, tool.handler);
|
|
159
|
+
*
|
|
160
|
+
* // Or with destructuring:
|
|
161
|
+
* const { definition, handler } = createTool(config);
|
|
162
|
+
* client.registerTool(definition, handler);
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
export interface ZodToolResult<TInput = unknown, TOutput = unknown> {
|
|
166
|
+
/**
|
|
167
|
+
* Tool definition with JSON Schema
|
|
168
|
+
*
|
|
169
|
+
* Contains the tool metadata with input/output schemas converted to
|
|
170
|
+
* MCP-compliant JSON Schema. Ready to pass to `client.registerTool()`.
|
|
171
|
+
*/
|
|
172
|
+
definition: KadiTool;
|
|
173
|
+
/**
|
|
174
|
+
* Tool handler with automatic validation
|
|
175
|
+
*
|
|
176
|
+
* Wrapper around the original handler that:
|
|
177
|
+
* 1. Validates input using Zod (throws ZodError if invalid)
|
|
178
|
+
* 2. Calls original handler
|
|
179
|
+
* 3. Validates output using Zod (throws ZodError if invalid)
|
|
180
|
+
*
|
|
181
|
+
* The handler is ready to pass to `client.registerTool()`.
|
|
182
|
+
*/
|
|
183
|
+
handler: ToolHandler<TInput, TOutput>;
|
|
184
|
+
/**
|
|
185
|
+
* Original Zod input schema
|
|
186
|
+
*
|
|
187
|
+
* Preserved for reference and advanced use cases (e.g., custom validation,
|
|
188
|
+
* schema introspection, documentation generation).
|
|
189
|
+
*/
|
|
190
|
+
inputSchema: z.ZodTypeAny;
|
|
191
|
+
/**
|
|
192
|
+
* Original Zod output schema
|
|
193
|
+
*
|
|
194
|
+
* Preserved for reference and advanced use cases.
|
|
195
|
+
*/
|
|
196
|
+
outputSchema: z.ZodTypeAny;
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=zod-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod-tools.d.ts","sourceRoot":"","sources":["../../src/types/zod-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,WAAW,aAAa,CAC5B,MAAM,SAAS,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,EAC1C,OAAO,SAAS,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU;IAE3C;;;;;OAKG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;;;;OAQG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAEhB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAEpB;;;;;;;;;;;;;OAaG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;;;;;;;;;;OAcG;IACH,MAAM,EAAE,OAAO,CAAC;IAEhB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,OAAO,EAAE,CACP,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KACpB,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;CACnD;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,aAAa,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO;IAChE;;;;;OAKG;IACH,UAAU,EAAE,QAAQ,CAAC;IAErB;;;;;;;;;OASG;IACH,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEtC;;;;;OAKG;IACH,WAAW,EAAE,CAAC,CAAC,UAAU,CAAC;IAE1B;;;;OAIG;IACH,YAAY,EAAE,CAAC,CAAC,UAAU,CAAC;CAC5B"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for Zod-based tool registration
|
|
3
|
+
*
|
|
4
|
+
* This module provides TypeScript types for registering tools using Zod schemas
|
|
5
|
+
* instead of manual JSON Schema definitions. This approach provides:
|
|
6
|
+
* - Single source of truth (Zod schema)
|
|
7
|
+
* - Automatic TypeScript type inference
|
|
8
|
+
* - Runtime validation with excellent error messages
|
|
9
|
+
* - Significantly less boilerplate code
|
|
10
|
+
*
|
|
11
|
+
* @module types/zod-tools
|
|
12
|
+
*/
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=zod-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod-tools.js","sourceRoot":"","sources":["../../src/types/zod-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG"}
|