@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,496 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ability Proxy
|
|
3
|
+
*
|
|
4
|
+
* Creates a proxy object that makes calling ability methods feel natural.
|
|
5
|
+
* Enables syntax like: `ability.methodName(params)` instead of
|
|
6
|
+
* `transport.invoke('methodName', params)`.
|
|
7
|
+
*
|
|
8
|
+
* @module abilities/AbilityProxy
|
|
9
|
+
*/
|
|
10
|
+
import { EventEmitter } from 'events';
|
|
11
|
+
import type { AbilityTransport, MethodSchema } from '../types/index.js';
|
|
12
|
+
/**
|
|
13
|
+
* Transport type for ability loading
|
|
14
|
+
*/
|
|
15
|
+
export type TransportType = 'native' | 'stdio' | 'broker';
|
|
16
|
+
/**
|
|
17
|
+
* Framework methods that ALL abilities have.
|
|
18
|
+
*
|
|
19
|
+
* These are introspection and control methods provided by the KADI framework,
|
|
20
|
+
* prefixed with __ to avoid conflicts with ability-specific methods.
|
|
21
|
+
*
|
|
22
|
+
* Every loaded ability will have these methods available regardless of what
|
|
23
|
+
* the underlying ability provides.
|
|
24
|
+
*/
|
|
25
|
+
export interface AbilityFramework extends EventEmitter {
|
|
26
|
+
/**
|
|
27
|
+
* Ability name (readonly)
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* console.log(ability.__name); // "calculator"
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
readonly __name: string;
|
|
35
|
+
/**
|
|
36
|
+
* Transport type used to load this ability (readonly)
|
|
37
|
+
* - 'native': In-process module (loaded directly into memory)
|
|
38
|
+
* - 'stdio': Child process (communicated via stdin/stdout)
|
|
39
|
+
* - 'broker': Remote service (communicated via WebSocket broker)
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* console.log(ability.__transport); // "broker"
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
readonly __transport: TransportType;
|
|
47
|
+
/**
|
|
48
|
+
* Get list of available method names
|
|
49
|
+
*
|
|
50
|
+
* Returns all methods that this ability exposes. You can call any of
|
|
51
|
+
* these methods on the ability object.
|
|
52
|
+
*
|
|
53
|
+
* @returns Array of method names
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const methods = ability.__getMethods();
|
|
58
|
+
* console.log(methods); // ['add', 'subtract', 'multiply']
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
__getMethods(): string[];
|
|
62
|
+
/**
|
|
63
|
+
* Get MCP schema for a specific method
|
|
64
|
+
*
|
|
65
|
+
* Returns the JSON Schema describing the method's input and output types.
|
|
66
|
+
* Useful for validation, documentation, and runtime type checking.
|
|
67
|
+
*
|
|
68
|
+
* @param method - Method name
|
|
69
|
+
* @returns Method schema or undefined if not available
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const schema = ability.__getSchema('add');
|
|
74
|
+
* console.log(schema.inputSchema); // { type: 'object', properties: { a: ..., b: ... } }
|
|
75
|
+
* console.log(schema.outputSchema); // { type: 'object', properties: { result: ... } }
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
__getSchema(method: string): MethodSchema | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Get all schemas for all methods
|
|
81
|
+
*
|
|
82
|
+
* Returns a map of method name to schema for every method this ability provides.
|
|
83
|
+
*
|
|
84
|
+
* @returns Record mapping method names to their schemas
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const schemas = ability.__getAllSchemas();
|
|
89
|
+
* for (const [method, schema] of Object.entries(schemas)) {
|
|
90
|
+
* console.log(`${method}:`, schema.description);
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
__getAllSchemas(): Record<string, MethodSchema>;
|
|
95
|
+
/**
|
|
96
|
+
* Get human-readable usage documentation for a method
|
|
97
|
+
*
|
|
98
|
+
* Returns formatted documentation showing how to use a method, including
|
|
99
|
+
* description, parameters, return type, and example usage.
|
|
100
|
+
*
|
|
101
|
+
* @param method - Method name
|
|
102
|
+
* @returns Formatted usage string or undefined if method not found
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* console.log(ability.__getUsage('add'));
|
|
107
|
+
* // Output:
|
|
108
|
+
* // add(params)
|
|
109
|
+
* // Description: Add two numbers
|
|
110
|
+
* // Parameters: { a: number, b: number }
|
|
111
|
+
* // Returns: { result: number }
|
|
112
|
+
* // Example: ability.add({ a: 5, b: 3 })
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
__getUsage(method: string): string | undefined;
|
|
116
|
+
/**
|
|
117
|
+
* Get complete API documentation for all methods
|
|
118
|
+
*
|
|
119
|
+
* Returns formatted documentation for the entire ability API.
|
|
120
|
+
* Includes all methods, their descriptions, parameters, and examples.
|
|
121
|
+
*
|
|
122
|
+
* @returns Complete API documentation string
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* console.log(ability.__getAPI());
|
|
127
|
+
* // Shows formatted documentation for all methods
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
__getAPI(): string;
|
|
131
|
+
/**
|
|
132
|
+
* Call a method directly by name (alternative to proxy syntax)
|
|
133
|
+
*
|
|
134
|
+
* This is an escape hatch for when you need to call methods dynamically
|
|
135
|
+
* or when the method name is in a variable.
|
|
136
|
+
*
|
|
137
|
+
* @template TInput - Input parameter type
|
|
138
|
+
* @template TOutput - Output return type
|
|
139
|
+
* @param method - Method name to invoke
|
|
140
|
+
* @param params - Method parameters
|
|
141
|
+
* @returns Promise resolving to method result
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* // These are equivalent:
|
|
146
|
+
* const result1 = await ability.add({ a: 5, b: 3 });
|
|
147
|
+
* const result2 = await ability.__call('add', { a: 5, b: 3 });
|
|
148
|
+
*
|
|
149
|
+
* // Dynamic method name:
|
|
150
|
+
* const methodName = 'add';
|
|
151
|
+
* const result3 = await ability.__call(methodName, { a: 5, b: 3 });
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
__call<TInput = unknown, TOutput = unknown>(method: string, params: TInput): Promise<TOutput>;
|
|
155
|
+
/**
|
|
156
|
+
* Disconnect from the ability
|
|
157
|
+
*
|
|
158
|
+
* Closes the connection and cleans up resources. After calling disconnect,
|
|
159
|
+
* any subsequent method calls will fail.
|
|
160
|
+
*
|
|
161
|
+
* @returns Promise that resolves when disconnection is complete
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* await ability.__disconnect();
|
|
166
|
+
* console.log(ability.__isConnected()); // false
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
__disconnect(): Promise<void>;
|
|
170
|
+
/**
|
|
171
|
+
* Check if currently connected to the ability
|
|
172
|
+
*
|
|
173
|
+
* @returns true if connected and ready for method calls, false otherwise
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* if (ability.__isConnected()) {
|
|
178
|
+
* await ability.someMethod({ ... });
|
|
179
|
+
* }
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
__isConnected(): boolean;
|
|
183
|
+
/**
|
|
184
|
+
* Subscribe to events from the ability
|
|
185
|
+
*
|
|
186
|
+
* Abilities can emit events during long-running operations or to notify
|
|
187
|
+
* about state changes. Use this to listen for those events.
|
|
188
|
+
*
|
|
189
|
+
* @param event - Event name
|
|
190
|
+
* @param callback - Event callback function
|
|
191
|
+
* @returns this for chaining
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```typescript
|
|
195
|
+
* ability.__on('progress', (data) => {
|
|
196
|
+
* console.log(`Progress: ${data.percent}%`);
|
|
197
|
+
* });
|
|
198
|
+
*
|
|
199
|
+
* ability.__on('error', (error) => {
|
|
200
|
+
* console.error('Ability error:', error);
|
|
201
|
+
* });
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
__on(event: string, callback: (...args: unknown[]) => void): this;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Default type for dynamic method calls.
|
|
208
|
+
*
|
|
209
|
+
* When you don't provide a type parameter to LoadedAbility, this is what you get:
|
|
210
|
+
* - Any string property can be called as a function
|
|
211
|
+
* - Parameters are flexible (any[])
|
|
212
|
+
* - Return type is Promise<any>
|
|
213
|
+
*
|
|
214
|
+
* This allows rapid prototyping without needing to define types upfront.
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```typescript
|
|
218
|
+
* const ability = await client.load('my-ability', 'broker');
|
|
219
|
+
* // ability has type: LoadedAbility<DynamicMethods>
|
|
220
|
+
*
|
|
221
|
+
* // Any method name works:
|
|
222
|
+
* await ability.anyMethod({ foo: 'bar' });
|
|
223
|
+
* await ability.something();
|
|
224
|
+
* await ability.whatever({ a: 1, b: 2 });
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
export type DynamicMethods = Record<string, (...args: any[]) => Promise<any>>;
|
|
228
|
+
/**
|
|
229
|
+
* Loaded Ability type.
|
|
230
|
+
*
|
|
231
|
+
* **TYPE ARCHITECTURE:**
|
|
232
|
+
* This is an intersection type that combines:
|
|
233
|
+
* 1. DynamicMethods - allows calling any method name dynamically
|
|
234
|
+
* 2. AbilityFramework - framework methods (introspection, control)
|
|
235
|
+
*
|
|
236
|
+
* **HOW IT WORKS:**
|
|
237
|
+
* At runtime, AbilityProxy creates a JavaScript Proxy that intercepts ALL
|
|
238
|
+
* property access. When you call `ability.someMethod(params)`:
|
|
239
|
+
* 1. Proxy intercepts the 'someMethod' property access
|
|
240
|
+
* 2. Returns a function that calls `transport.invoke('someMethod', params)`
|
|
241
|
+
* 3. Framework methods (__name, etc.) are handled directly
|
|
242
|
+
*
|
|
243
|
+
* This type definition makes TypeScript understand that runtime behavior.
|
|
244
|
+
*
|
|
245
|
+
* **RUNTIME VALIDATION:**
|
|
246
|
+
* Use the `validate: true` option when loading abilities to get runtime
|
|
247
|
+
* method checking and helpful error messages.
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```typescript
|
|
251
|
+
* // Basic usage:
|
|
252
|
+
* const calc = await client.load('calculator', 'broker');
|
|
253
|
+
* const result = await calc.add({ a: 5, b: 3 });
|
|
254
|
+
*
|
|
255
|
+
* // With runtime validation:
|
|
256
|
+
* const validated = await client.load('calculator', 'broker', {
|
|
257
|
+
* validate: true // Checks ability has expected methods
|
|
258
|
+
* });
|
|
259
|
+
*
|
|
260
|
+
* // Access framework methods:
|
|
261
|
+
* console.log(calc.__name); // "calculator"
|
|
262
|
+
* console.log(calc.__getMethods()); // ["add", "subtract", ...]
|
|
263
|
+
* console.log(calc.__getSchema('add')); // { inputSchema: {...}, outputSchema: {...} }
|
|
264
|
+
* ```
|
|
265
|
+
*/
|
|
266
|
+
export type LoadedAbility = DynamicMethods & AbilityFramework;
|
|
267
|
+
/**
|
|
268
|
+
* Ability Proxy (internal implementation)
|
|
269
|
+
*
|
|
270
|
+
* Creates a proxy object that intercepts property access and converts it
|
|
271
|
+
* to method invocations on the underlying transport.
|
|
272
|
+
*
|
|
273
|
+
* This class implements AbilityFramework, providing all the framework methods.
|
|
274
|
+
* The runtime Proxy wrapper adds dynamic method access on top.
|
|
275
|
+
*
|
|
276
|
+
* **Internal Architecture:**
|
|
277
|
+
* - This class extends EventEmitter and implements AbilityFramework
|
|
278
|
+
* - createProxy() wraps an instance in a Proxy for dynamic method access
|
|
279
|
+
* - The Proxy intercepts property access and routes to __call()
|
|
280
|
+
* - Framework methods (__name, __getMethods, etc.) are handled directly
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* ```typescript
|
|
284
|
+
* const proxy = AbilityProxy.create('calculator', transport, 'broker');
|
|
285
|
+
*
|
|
286
|
+
* // These all work:
|
|
287
|
+
* const result1 = await proxy.add({ a: 5, b: 3 });
|
|
288
|
+
* const result2 = await proxy.__call('add', { a: 5, b: 3 });
|
|
289
|
+
*
|
|
290
|
+
* // Get methods
|
|
291
|
+
* const methods = proxy.__getMethods();
|
|
292
|
+
*
|
|
293
|
+
* // Get schema
|
|
294
|
+
* const schema = proxy.__getSchema('add');
|
|
295
|
+
*
|
|
296
|
+
* // Events
|
|
297
|
+
* proxy.__on('calculation.done', (data) => {
|
|
298
|
+
* console.log('Done:', data);
|
|
299
|
+
* });
|
|
300
|
+
* ```
|
|
301
|
+
*/
|
|
302
|
+
export declare class AbilityProxy extends EventEmitter implements AbilityFramework {
|
|
303
|
+
/**
|
|
304
|
+
* Ability name
|
|
305
|
+
*/
|
|
306
|
+
readonly __name: string;
|
|
307
|
+
/**
|
|
308
|
+
* Transport type
|
|
309
|
+
*/
|
|
310
|
+
readonly __transport: TransportType;
|
|
311
|
+
/**
|
|
312
|
+
* Underlying transport
|
|
313
|
+
*/
|
|
314
|
+
private readonly transport;
|
|
315
|
+
/**
|
|
316
|
+
* Schema validator for runtime validation
|
|
317
|
+
*/
|
|
318
|
+
private readonly validator;
|
|
319
|
+
/**
|
|
320
|
+
* Create a new AbilityProxy (private constructor)
|
|
321
|
+
*
|
|
322
|
+
* Use AbilityProxy.create() to get a proxied ability object.
|
|
323
|
+
*
|
|
324
|
+
* @param name - Ability name
|
|
325
|
+
* @param transport - Ability transport
|
|
326
|
+
* @param transportType - Transport type identifier
|
|
327
|
+
*/
|
|
328
|
+
private constructor();
|
|
329
|
+
/**
|
|
330
|
+
* Create a new proxied ability
|
|
331
|
+
*
|
|
332
|
+
* Factory method that creates an AbilityProxy and wraps it in a Proxy
|
|
333
|
+
* to enable dynamic method access.
|
|
334
|
+
*
|
|
335
|
+
* @param name - Ability name
|
|
336
|
+
* @param transport - Ability transport
|
|
337
|
+
* @param transportType - Transport type identifier
|
|
338
|
+
* @returns Proxied ability object with dynamic method access and framework methods
|
|
339
|
+
*
|
|
340
|
+
* @example
|
|
341
|
+
* ```typescript
|
|
342
|
+
* // Create ability proxy:
|
|
343
|
+
* const calc = AbilityProxy.create('calculator', transport, 'broker');
|
|
344
|
+
*
|
|
345
|
+
* // Call methods dynamically:
|
|
346
|
+
* await calc.add({ a: 5, b: 3 });
|
|
347
|
+
* await calc.subtract({ a: 10, b: 4 });
|
|
348
|
+
*
|
|
349
|
+
* // Access framework methods:
|
|
350
|
+
* console.log(calc.__name); // "calculator"
|
|
351
|
+
* console.log(calc.__getMethods()); // ["add", "subtract", ...]
|
|
352
|
+
* ```
|
|
353
|
+
*/
|
|
354
|
+
static create(name: string, transport: AbilityTransport, transportType: TransportType): LoadedAbility;
|
|
355
|
+
/**
|
|
356
|
+
* Register schemas for all methods with the validator
|
|
357
|
+
*
|
|
358
|
+
* Iterates over all methods and registers their schemas for validation.
|
|
359
|
+
* Methods without schemas will not have validation.
|
|
360
|
+
*/
|
|
361
|
+
private registerMethodSchemas;
|
|
362
|
+
/**
|
|
363
|
+
* Get available methods
|
|
364
|
+
*
|
|
365
|
+
* @returns Array of method names
|
|
366
|
+
*/
|
|
367
|
+
__getMethods(): string[];
|
|
368
|
+
/**
|
|
369
|
+
* Get schema for a method
|
|
370
|
+
*
|
|
371
|
+
* @param method - Method name
|
|
372
|
+
* @returns Method schema or undefined
|
|
373
|
+
*/
|
|
374
|
+
__getSchema(method: string): MethodSchema | undefined;
|
|
375
|
+
/**
|
|
376
|
+
* Get all schemas for all methods
|
|
377
|
+
*
|
|
378
|
+
* @returns Map of method names to their schemas
|
|
379
|
+
*/
|
|
380
|
+
__getAllSchemas(): Record<string, MethodSchema>;
|
|
381
|
+
/**
|
|
382
|
+
* Read agent.json representation (native transport with KadiClient only)
|
|
383
|
+
*
|
|
384
|
+
* Returns the agent.json representation from the loaded ability if it's a KadiClient
|
|
385
|
+
* instance loaded via native transport. Returns undefined for other transports
|
|
386
|
+
* or legacy modules.
|
|
387
|
+
*
|
|
388
|
+
* **What this returns:**
|
|
389
|
+
* - Runtime representation of the ability's agent.json file
|
|
390
|
+
* - Contains name, version, description, and tools
|
|
391
|
+
* - Tools field is mapped from agent.json's 'exports' field
|
|
392
|
+
*
|
|
393
|
+
* **Use Case:** Type generation during `kadi install`
|
|
394
|
+
* The CLI can call this method to get the agent.json representation including schemas,
|
|
395
|
+
* then generate TypeScript .d.ts files for autocomplete.
|
|
396
|
+
*
|
|
397
|
+
* @returns agent.json representation or undefined
|
|
398
|
+
*
|
|
399
|
+
* @example
|
|
400
|
+
* ```typescript
|
|
401
|
+
* const calc = await client.load('calculator', 'native', { path: './abilities/calc' });
|
|
402
|
+
* const agentJson = calc.__readAgentJson();
|
|
403
|
+
*
|
|
404
|
+
* if (agentJson) {
|
|
405
|
+
* console.log('Ability:', agentJson.name, agentJson.version);
|
|
406
|
+
* console.log('Tools:', agentJson.tools.map(t => t.name));
|
|
407
|
+
*
|
|
408
|
+
* // CLI would use this for type generation:
|
|
409
|
+
* // await TypeGenerator.generate(agentJson, './types/calculator.d.ts');
|
|
410
|
+
* }
|
|
411
|
+
* ```
|
|
412
|
+
*/
|
|
413
|
+
__readAgentJson(): import('../abilities/types.js').AgentJson | undefined;
|
|
414
|
+
/**
|
|
415
|
+
* Get usage information for a method
|
|
416
|
+
*
|
|
417
|
+
* Formats schema into human-readable usage documentation.
|
|
418
|
+
*
|
|
419
|
+
* @param method - Method name
|
|
420
|
+
* @returns Formatted usage string
|
|
421
|
+
*/
|
|
422
|
+
__getUsage(method: string): string | undefined;
|
|
423
|
+
/**
|
|
424
|
+
* Get complete API documentation
|
|
425
|
+
*
|
|
426
|
+
* Returns formatted documentation for all methods.
|
|
427
|
+
*
|
|
428
|
+
* @returns API documentation string
|
|
429
|
+
*/
|
|
430
|
+
__getAPI(): string;
|
|
431
|
+
/**
|
|
432
|
+
* Call a method directly
|
|
433
|
+
*
|
|
434
|
+
* @template TInput - Input type
|
|
435
|
+
* @template TOutput - Output type
|
|
436
|
+
* @param method - Method name
|
|
437
|
+
* @param params - Method parameters
|
|
438
|
+
* @returns Promise resolving to method result
|
|
439
|
+
*/
|
|
440
|
+
__call<TInput = unknown, TOutput = unknown>(method: string, params: TInput): Promise<TOutput>;
|
|
441
|
+
/**
|
|
442
|
+
* Disconnect the ability
|
|
443
|
+
*/
|
|
444
|
+
__disconnect(): Promise<void>;
|
|
445
|
+
/**
|
|
446
|
+
* Check if connected
|
|
447
|
+
*/
|
|
448
|
+
__isConnected(): boolean;
|
|
449
|
+
/**
|
|
450
|
+
* Subscribe to events
|
|
451
|
+
*
|
|
452
|
+
* @param event - Event name
|
|
453
|
+
* @param callback - Event callback
|
|
454
|
+
* @returns this for chaining
|
|
455
|
+
*/
|
|
456
|
+
__on(event: string, callback: (...args: unknown[]) => void): this;
|
|
457
|
+
/**
|
|
458
|
+
* Generate example data from JSON Schema
|
|
459
|
+
*
|
|
460
|
+
* Creates sample values based on schema types and constraints.
|
|
461
|
+
* Useful for showing users what valid input looks like.
|
|
462
|
+
*
|
|
463
|
+
* @param schema - JSON Schema (MCP inputSchema)
|
|
464
|
+
* @returns Example data matching schema
|
|
465
|
+
*
|
|
466
|
+
* @example
|
|
467
|
+
* ```typescript
|
|
468
|
+
* const schema = {
|
|
469
|
+
* type: 'object',
|
|
470
|
+
* properties: {
|
|
471
|
+
* name: { type: 'string' },
|
|
472
|
+
* age: { type: 'number' }
|
|
473
|
+
* },
|
|
474
|
+
* required: ['name']
|
|
475
|
+
* };
|
|
476
|
+
* const example = generateExampleFromSchema(schema);
|
|
477
|
+
* // Returns: { name: "example", age: 0 }
|
|
478
|
+
* ```
|
|
479
|
+
*/
|
|
480
|
+
private generateExampleFromSchema;
|
|
481
|
+
/**
|
|
482
|
+
* Create the proxy object
|
|
483
|
+
*
|
|
484
|
+
* Wraps this AbilityProxy instance in a JavaScript Proxy to intercept
|
|
485
|
+
* property access and convert it to method calls.
|
|
486
|
+
*
|
|
487
|
+
* **How this satisfies LoadedAbility type:**
|
|
488
|
+
* - Target (this) implements AbilityFramework (all __ methods)
|
|
489
|
+
* - Proxy handler provides dynamic method access (DynamicMethods)
|
|
490
|
+
* - Result is AbilityFramework & DynamicMethods = LoadedAbility
|
|
491
|
+
*
|
|
492
|
+
* @returns Proxied ability (satisfies LoadedAbility<DynamicMethods>)
|
|
493
|
+
*/
|
|
494
|
+
private createProxy;
|
|
495
|
+
}
|
|
496
|
+
//# sourceMappingURL=AbilityProxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbilityProxy.d.ts","sourceRoot":"","sources":["../../src/abilities/AbilityProxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,O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