@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,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ability Context
|
|
3
|
+
* ================
|
|
4
|
+
*
|
|
5
|
+
* Context provided to abilities when running in stdio or native mode.
|
|
6
|
+
* Enables abilities to load other abilities with inherited configuration.
|
|
7
|
+
*
|
|
8
|
+
* **Context Flow:**
|
|
9
|
+
* - Native/Stdio: Context flows from parent to child
|
|
10
|
+
* - Broker: Services are independent (no context inheritance)
|
|
11
|
+
*
|
|
12
|
+
* @module abilities/AbilityContext
|
|
13
|
+
*/
|
|
14
|
+
import type { LoadedAbility } from './AbilityProxy.js';
|
|
15
|
+
/**
|
|
16
|
+
* Load options for ability loading
|
|
17
|
+
*/
|
|
18
|
+
export interface LoadOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Force specific transport (optional - auto-detect if omitted)
|
|
21
|
+
* - 'native': In-process module
|
|
22
|
+
* - 'stdio': Child process communication
|
|
23
|
+
* - 'broker': Remote service via broker
|
|
24
|
+
*/
|
|
25
|
+
transport?: 'native' | 'stdio' | 'broker';
|
|
26
|
+
/**
|
|
27
|
+
* Version constraint (semver format)
|
|
28
|
+
* @example '^2.0.0', '>=1.5.0 <2.0.0'
|
|
29
|
+
*/
|
|
30
|
+
version?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Connection timeout in milliseconds
|
|
33
|
+
* @default 30000 (30 seconds)
|
|
34
|
+
*/
|
|
35
|
+
timeout?: number;
|
|
36
|
+
/**
|
|
37
|
+
* Use cached instance if available
|
|
38
|
+
* @default true
|
|
39
|
+
*/
|
|
40
|
+
cached?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Enable debug logging for this ability
|
|
43
|
+
* @default false
|
|
44
|
+
*/
|
|
45
|
+
debug?: boolean;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Authentication configuration
|
|
49
|
+
*/
|
|
50
|
+
export interface AuthConfig {
|
|
51
|
+
/**
|
|
52
|
+
* Authentication token
|
|
53
|
+
*/
|
|
54
|
+
token?: string;
|
|
55
|
+
/**
|
|
56
|
+
* API key
|
|
57
|
+
*/
|
|
58
|
+
apiKey?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Additional authentication data
|
|
61
|
+
*/
|
|
62
|
+
[key: string]: unknown;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Context provided to abilities running as stdio/native children.
|
|
66
|
+
*
|
|
67
|
+
* Abilities receive this context from their parent and can use it to:
|
|
68
|
+
* - Load other abilities with inherited configuration
|
|
69
|
+
* - Emit events to parent
|
|
70
|
+
* - Access parent's broker/auth/networks
|
|
71
|
+
*
|
|
72
|
+
* **Important:** Context only flows through stdio/native transport.
|
|
73
|
+
* Broker services are independent and have their own context.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* // Inside an ability
|
|
78
|
+
* export class DataAnalyzer extends Ability {
|
|
79
|
+
* async initialize() {
|
|
80
|
+
* // Load child abilities using inherited context
|
|
81
|
+
* this.mlModel = await this.context.load('ml-model');
|
|
82
|
+
* this.database = await this.context.load('database');
|
|
83
|
+
* }
|
|
84
|
+
*
|
|
85
|
+
* async analyze(data: any) {
|
|
86
|
+
* // Use loaded abilities
|
|
87
|
+
* const predictions = await this.mlModel.predict(data);
|
|
88
|
+
* await this.database.save(predictions);
|
|
89
|
+
* return predictions;
|
|
90
|
+
* }
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export interface AbilityContext {
|
|
95
|
+
/**
|
|
96
|
+
* Ability name
|
|
97
|
+
*/
|
|
98
|
+
readonly name: string;
|
|
99
|
+
/**
|
|
100
|
+
* Broker URL (inherited from parent)
|
|
101
|
+
*
|
|
102
|
+
* If the parent is connected to a broker, the child inherits this connection.
|
|
103
|
+
* The child can use this to load abilities via the broker.
|
|
104
|
+
*
|
|
105
|
+
* @example 'ws://broker.example.com'
|
|
106
|
+
*/
|
|
107
|
+
readonly broker?: string;
|
|
108
|
+
/**
|
|
109
|
+
* Authentication configuration (inherited from parent)
|
|
110
|
+
*
|
|
111
|
+
* Child abilities inherit parent's authentication credentials.
|
|
112
|
+
* This enables seamless ability chaining without re-authentication.
|
|
113
|
+
*/
|
|
114
|
+
readonly auth?: AuthConfig;
|
|
115
|
+
/**
|
|
116
|
+
* Network memberships (inherited from parent)
|
|
117
|
+
*
|
|
118
|
+
* Networks define visibility boundaries for abilities in the broker.
|
|
119
|
+
* Child abilities inherit parent's network memberships.
|
|
120
|
+
*
|
|
121
|
+
* @example ['global', 'team-alpha', 'production']
|
|
122
|
+
*/
|
|
123
|
+
readonly networks?: readonly string[];
|
|
124
|
+
/**
|
|
125
|
+
* Parent ability name (for chain tracking)
|
|
126
|
+
*
|
|
127
|
+
* Identifies the immediate parent that loaded this ability.
|
|
128
|
+
* Useful for debugging and cycle detection.
|
|
129
|
+
*
|
|
130
|
+
* @example If Agent → Python Analyzer, parent is 'Agent'
|
|
131
|
+
*/
|
|
132
|
+
readonly parent?: string;
|
|
133
|
+
/**
|
|
134
|
+
* Full chain from root to this ability
|
|
135
|
+
*
|
|
136
|
+
* Tracks the complete loading chain for debugging and cycle detection.
|
|
137
|
+
* Each ability in the chain adds itself to this array.
|
|
138
|
+
*
|
|
139
|
+
* @example ['js-agent', 'data-processor', 'ml-model']
|
|
140
|
+
*/
|
|
141
|
+
readonly chain: readonly string[];
|
|
142
|
+
/**
|
|
143
|
+
* Load another ability with inherited context.
|
|
144
|
+
*
|
|
145
|
+
* **Context Inheritance (Stdio/Native only):**
|
|
146
|
+
* - broker, auth, networks are inherited from this context
|
|
147
|
+
* - Chain is extended with the new ability
|
|
148
|
+
* - Cycle detection prevents infinite loops
|
|
149
|
+
*
|
|
150
|
+
* **Broker Services (Independent):**
|
|
151
|
+
* - When loading via broker, service has its own context
|
|
152
|
+
* - No configuration inheritance
|
|
153
|
+
* - Services are autonomous
|
|
154
|
+
*
|
|
155
|
+
* @param name - Ability name to load
|
|
156
|
+
* @param options - Loading options (transport, version, etc.)
|
|
157
|
+
* @returns Promise resolving to loaded ability proxy
|
|
158
|
+
*
|
|
159
|
+
* @throws {AbilityNotFoundError} If ability not found
|
|
160
|
+
* @throws {CircularDependencyError} If loading would create a cycle
|
|
161
|
+
* @throws {ConnectionError} If connection fails
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* // Load with auto-detection
|
|
166
|
+
* const helper = await context.load('helper-service');
|
|
167
|
+
*
|
|
168
|
+
* // Force specific transport
|
|
169
|
+
* const localScript = await context.load('script', { transport: 'stdio' });
|
|
170
|
+
*
|
|
171
|
+
* // With version constraint
|
|
172
|
+
* const mlModel = await context.load('ml-model', { version: '^2.0.0' });
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
load(name: string, options?: LoadOptions): Promise<LoadedAbility>;
|
|
176
|
+
/**
|
|
177
|
+
* Emit events to parent.
|
|
178
|
+
*
|
|
179
|
+
* Allows child abilities to communicate with their parent via events.
|
|
180
|
+
* Useful for progress updates, notifications, and status changes.
|
|
181
|
+
*
|
|
182
|
+
* @param event - Event name
|
|
183
|
+
* @param data - Event data
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* // Inside an ability
|
|
188
|
+
* context.emit('progress', { percent: 50 });
|
|
189
|
+
* context.emit('warning', { message: 'Low memory' });
|
|
190
|
+
* context.emit('completed', { result: data });
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
emit(event: string, data: unknown): void;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Create an AbilityContext from parent information.
|
|
197
|
+
*
|
|
198
|
+
* Used internally when spawning stdio child processes or loading native abilities.
|
|
199
|
+
*
|
|
200
|
+
* @param config - Context configuration
|
|
201
|
+
* @returns AbilityContext instance
|
|
202
|
+
*
|
|
203
|
+
* @internal
|
|
204
|
+
*/
|
|
205
|
+
export declare function createAbilityContext(config: {
|
|
206
|
+
name: string;
|
|
207
|
+
broker?: string;
|
|
208
|
+
auth?: AuthConfig;
|
|
209
|
+
networks?: string[];
|
|
210
|
+
parent?: string;
|
|
211
|
+
chain?: string[];
|
|
212
|
+
loadFn: (name: string, options?: LoadOptions) => Promise<LoadedAbility>;
|
|
213
|
+
emitFn: (event: string, data: unknown) => void;
|
|
214
|
+
}): AbilityContext;
|
|
215
|
+
//# sourceMappingURL=AbilityContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbilityContext.d.ts","sourceRoot":"","sources":["../../src/abilities/AbilityContext.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB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,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;CAC1C;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;IACxE,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;CAChD,GAAG,cAAc,CAWjB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ability Context
|
|
3
|
+
* ================
|
|
4
|
+
*
|
|
5
|
+
* Context provided to abilities when running in stdio or native mode.
|
|
6
|
+
* Enables abilities to load other abilities with inherited configuration.
|
|
7
|
+
*
|
|
8
|
+
* **Context Flow:**
|
|
9
|
+
* - Native/Stdio: Context flows from parent to child
|
|
10
|
+
* - Broker: Services are independent (no context inheritance)
|
|
11
|
+
*
|
|
12
|
+
* @module abilities/AbilityContext
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Create an AbilityContext from parent information.
|
|
16
|
+
*
|
|
17
|
+
* Used internally when spawning stdio child processes or loading native abilities.
|
|
18
|
+
*
|
|
19
|
+
* @param config - Context configuration
|
|
20
|
+
* @returns AbilityContext instance
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export function createAbilityContext(config) {
|
|
25
|
+
return {
|
|
26
|
+
name: config.name,
|
|
27
|
+
broker: config.broker,
|
|
28
|
+
auth: config.auth,
|
|
29
|
+
networks: config.networks ? [...config.networks] : undefined,
|
|
30
|
+
parent: config.parent,
|
|
31
|
+
chain: config.chain ? [...config.chain, config.name] : [config.name],
|
|
32
|
+
load: config.loadFn,
|
|
33
|
+
emit: config.emitFn
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=AbilityContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbilityContext.js","sourceRoot":"","sources":["../../src/abilities/AbilityContext.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAwMH;;;;;;;;;GASG;AACH,MAAM,UAAU,oBAAoB,CAAC,MASpC;IACC,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS;QAC5D,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;QACpE,IAAI,EAAE,MAAM,CAAC,MAAM;QACnB,IAAI,EAAE,MAAM,CAAC,MAAM;KACpB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ability Loader
|
|
3
|
+
*
|
|
4
|
+
* Orchestrates ability loading with excellent developer experience:
|
|
5
|
+
* - Smart transport inference (auto-detect or explicit)
|
|
6
|
+
* - Intelligent caching (composite keys)
|
|
7
|
+
* - Runtime validation (catch issues early)
|
|
8
|
+
* - Helpful error messages (actionable suggestions)
|
|
9
|
+
*
|
|
10
|
+
* @module abilities/AbilityLoader
|
|
11
|
+
*/
|
|
12
|
+
import type { LoadOptions, TransportType } from './types.js';
|
|
13
|
+
import { type IBrokerClient } from '../transports/BrokerTransport.js';
|
|
14
|
+
import { type LoadedAbility } from './AbilityProxy.js';
|
|
15
|
+
/**
|
|
16
|
+
* Ability Loader
|
|
17
|
+
*
|
|
18
|
+
* Orchestrates the complete ability loading process:
|
|
19
|
+
* - Transport inference (smart auto-detection)
|
|
20
|
+
* - Caching (avoid duplicate loads)
|
|
21
|
+
* - Transport creation (factory pattern)
|
|
22
|
+
* - Validation (runtime checks)
|
|
23
|
+
* - Error handling (helpful messages)
|
|
24
|
+
*
|
|
25
|
+
* Single responsibility: Load abilities, nothing else.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const loader = new AbilityLoader();
|
|
30
|
+
*
|
|
31
|
+
* // Auto-detect (recommended)
|
|
32
|
+
* const calc = await loader.load('calculator', {}, brokerClient);
|
|
33
|
+
*
|
|
34
|
+
* // Explicit transport
|
|
35
|
+
* const remote = await loader.load('service', {
|
|
36
|
+
* transport: 'broker',
|
|
37
|
+
* networks: ['global']
|
|
38
|
+
* }, brokerClient);
|
|
39
|
+
*
|
|
40
|
+
* // With validation
|
|
41
|
+
* const typed = await loader.load<CalcAPI>('calc', {
|
|
42
|
+
* validate: true
|
|
43
|
+
* }, brokerClient);
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare class AbilityLoader {
|
|
47
|
+
/**
|
|
48
|
+
* Ability cache with composite key strategy
|
|
49
|
+
*
|
|
50
|
+
* Handles complex scenarios:
|
|
51
|
+
* - Same name, different transports
|
|
52
|
+
* - Same name, different versions
|
|
53
|
+
* - Same name, different brokers
|
|
54
|
+
*/
|
|
55
|
+
private cache;
|
|
56
|
+
/**
|
|
57
|
+
* Load an ability with explicit transport
|
|
58
|
+
*
|
|
59
|
+
* **Features:**
|
|
60
|
+
* - Explicit transport (no magic)
|
|
61
|
+
* - Smart caching (composite keys)
|
|
62
|
+
* - Runtime validation (optional)
|
|
63
|
+
* - Dynamic method access
|
|
64
|
+
*
|
|
65
|
+
* @param name - Ability name
|
|
66
|
+
* @param transport - Transport type (native, stdio, or broker)
|
|
67
|
+
* @param options - Load options (transport-specific)
|
|
68
|
+
* @param brokerClient - Broker client interface
|
|
69
|
+
* @returns Loaded ability with dynamic method access
|
|
70
|
+
*
|
|
71
|
+
* @throws {KadiError} If loading fails
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* // Broker transport
|
|
76
|
+
* const remote = await loader.load('service', 'broker', {
|
|
77
|
+
* networks: ['global']
|
|
78
|
+
* }, brokerClient);
|
|
79
|
+
*
|
|
80
|
+
* // With runtime validation
|
|
81
|
+
* const calc = await loader.load('calc', 'broker', {
|
|
82
|
+
* validate: true
|
|
83
|
+
* }, brokerClient);
|
|
84
|
+
*
|
|
85
|
+
* // Native transport
|
|
86
|
+
* const local = await loader.load('local-lib', 'native', {
|
|
87
|
+
* path: './abilities/local-lib'
|
|
88
|
+
* });
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
load(name: string, transport: TransportType, options?: LoadOptions, brokerClient?: IBrokerClient): Promise<LoadedAbility>;
|
|
92
|
+
/**
|
|
93
|
+
* Unload all abilities
|
|
94
|
+
*
|
|
95
|
+
* Disconnects all transports and clears cache.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* await loader.unloadAll();
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
unloadAll(): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Get all loaded abilities
|
|
105
|
+
*
|
|
106
|
+
* @returns Array of loaded abilities
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const abilities = loader.getAll();
|
|
111
|
+
* console.log(`Loaded ${abilities.length} abilities`);
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
getAll(): LoadedAbility[];
|
|
115
|
+
/**
|
|
116
|
+
* Get cache statistics
|
|
117
|
+
*
|
|
118
|
+
* Useful for debugging and monitoring.
|
|
119
|
+
*
|
|
120
|
+
* @returns Cache statistics
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* const stats = loader.getStats();
|
|
125
|
+
* console.log(`Cached: ${stats.totalCached}, Connected: ${stats.connected}`);
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
getStats(): {
|
|
129
|
+
totalCached: number;
|
|
130
|
+
connected: number;
|
|
131
|
+
disconnected: number;
|
|
132
|
+
byTransport: Record<TransportType, number>;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Cleanup disconnected abilities
|
|
136
|
+
*
|
|
137
|
+
* Removes stale cache entries.
|
|
138
|
+
*
|
|
139
|
+
* @returns Number of stale entries removed
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* const removed = loader.cleanup();
|
|
144
|
+
* console.log(`Cleaned up ${removed} disconnected abilities`);
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
cleanup(): number;
|
|
148
|
+
/**
|
|
149
|
+
* Create appropriate transport instance
|
|
150
|
+
*
|
|
151
|
+
* Clean factory pattern - delegates to specialized creation methods.
|
|
152
|
+
* Each transport type has its own dedicated method with proper validation.
|
|
153
|
+
*
|
|
154
|
+
* @param name - Ability name
|
|
155
|
+
* @param transport - Transport type (from inference)
|
|
156
|
+
* @param options - Load options
|
|
157
|
+
* @param brokerClient - Broker client (for broker transport)
|
|
158
|
+
* @returns Transport instance ready to connect
|
|
159
|
+
*
|
|
160
|
+
* @throws {KadiError} If transport creation fails
|
|
161
|
+
*/
|
|
162
|
+
private createTransport;
|
|
163
|
+
/**
|
|
164
|
+
* Create broker transport with excellent error handling
|
|
165
|
+
*
|
|
166
|
+
* Validates broker connection and creates transport with proper configuration.
|
|
167
|
+
*
|
|
168
|
+
* @param name - Ability name
|
|
169
|
+
* @param options - Load options (broker-specific)
|
|
170
|
+
* @param brokerClient - Broker client interface
|
|
171
|
+
* @returns Broker transport instance
|
|
172
|
+
*
|
|
173
|
+
* @throws {KadiError} If broker client missing or invalid config
|
|
174
|
+
*/
|
|
175
|
+
private createBrokerTransport;
|
|
176
|
+
/**
|
|
177
|
+
* Create native transport with path validation
|
|
178
|
+
*
|
|
179
|
+
* Validates the ability path and creates a NativeTransport instance
|
|
180
|
+
* for in-process ability loading.
|
|
181
|
+
*
|
|
182
|
+
* @param name - Ability name
|
|
183
|
+
* @param options - Load options (native-specific)
|
|
184
|
+
* @returns Native transport instance
|
|
185
|
+
*
|
|
186
|
+
* @throws {KadiError} If path is missing or invalid
|
|
187
|
+
*/
|
|
188
|
+
private createNativeTransport;
|
|
189
|
+
/**
|
|
190
|
+
* Create stdio transport with command validation
|
|
191
|
+
*
|
|
192
|
+
* Validates the command and creates a StdioTransport instance
|
|
193
|
+
* for spawning the ability as a child process.
|
|
194
|
+
*
|
|
195
|
+
* @param name - Ability name
|
|
196
|
+
* @param options - Load options (stdio-specific)
|
|
197
|
+
* @returns Stdio transport instance
|
|
198
|
+
*
|
|
199
|
+
* @throws {KadiError} If command is missing
|
|
200
|
+
*/
|
|
201
|
+
private createStdioTransport;
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=AbilityLoader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbilityLoader.d.ts","sourceRoot":"","sources":["../../src/abilities/AbilityLoader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAuC,MAAM,YAAY,CAAC;AAGlG,OAAO,EAAmB,KAAK,aAAa,EAAE,MAAM,kCAAkC,CAAC;AAGvF,OAAO,EAAgB,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIrE;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