@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,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Broker Transport
|
|
3
|
+
*
|
|
4
|
+
* Accesses abilities on remote agents via broker communication.
|
|
5
|
+
* Enables distributed system architecture with service discovery.
|
|
6
|
+
*
|
|
7
|
+
* @module transports/BrokerTransport
|
|
8
|
+
*/
|
|
9
|
+
import { EventEmitter } from 'events';
|
|
10
|
+
import type { AbilityTransport, BrokerTransportOptions, MethodSchema } from '../types/index.js';
|
|
11
|
+
import type { BrokerConnectionManager } from '../broker/BrokerConnectionManager.js';
|
|
12
|
+
import type { BrokerProtocol } from '../broker/BrokerProtocol.js';
|
|
13
|
+
/**
|
|
14
|
+
* Broker Client Interface
|
|
15
|
+
*
|
|
16
|
+
* Defines the minimal interface BrokerTransport needs from the client.
|
|
17
|
+
* This breaks the circular dependency between transport and client.
|
|
18
|
+
*/
|
|
19
|
+
export interface IBrokerClient {
|
|
20
|
+
/**
|
|
21
|
+
* Get the broker connection manager
|
|
22
|
+
*/
|
|
23
|
+
getBrokerManager(): BrokerConnectionManager;
|
|
24
|
+
/**
|
|
25
|
+
* Get broker protocol instance for a specific broker
|
|
26
|
+
*/
|
|
27
|
+
getBrokerProtocol(brokerName?: string): BrokerProtocol;
|
|
28
|
+
/**
|
|
29
|
+
* Networks this client is part of
|
|
30
|
+
*/
|
|
31
|
+
networks: string[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Broker Transport
|
|
35
|
+
*
|
|
36
|
+
* Communicates with remote abilities via broker infrastructure.
|
|
37
|
+
* Provides service discovery and load balancing across multiple brokers.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const transport = new BrokerTransport({
|
|
42
|
+
* abilityName: 'calculator',
|
|
43
|
+
* brokerUrl: 'ws://localhost:8080',
|
|
44
|
+
* networks: ['global']
|
|
45
|
+
* }, client);
|
|
46
|
+
*
|
|
47
|
+
* await transport.connect();
|
|
48
|
+
* const result = await transport.invoke('add', { a: 5, b: 3 });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare class BrokerTransport extends EventEmitter implements AbilityTransport {
|
|
52
|
+
/**
|
|
53
|
+
* Transport configuration
|
|
54
|
+
*/
|
|
55
|
+
private readonly options;
|
|
56
|
+
/**
|
|
57
|
+
* Broker client interface
|
|
58
|
+
*/
|
|
59
|
+
private readonly client;
|
|
60
|
+
/**
|
|
61
|
+
* Discovered methods
|
|
62
|
+
*/
|
|
63
|
+
private methods;
|
|
64
|
+
/**
|
|
65
|
+
* Method schemas
|
|
66
|
+
*/
|
|
67
|
+
private schemas;
|
|
68
|
+
/**
|
|
69
|
+
* Whether transport is connected
|
|
70
|
+
*/
|
|
71
|
+
private connected;
|
|
72
|
+
/**
|
|
73
|
+
* Target agent name (resolved during discovery)
|
|
74
|
+
*/
|
|
75
|
+
private targetAgent;
|
|
76
|
+
/**
|
|
77
|
+
* Create a new BrokerTransport
|
|
78
|
+
*
|
|
79
|
+
* @param options - Broker transport options
|
|
80
|
+
* @param client - Broker client interface
|
|
81
|
+
*/
|
|
82
|
+
constructor(options: BrokerTransportOptions, client: IBrokerClient);
|
|
83
|
+
/**
|
|
84
|
+
* Connect to the ability
|
|
85
|
+
*
|
|
86
|
+
* Discovers the ability on the broker network and queries its capabilities.
|
|
87
|
+
*
|
|
88
|
+
* @throws {KadiError} If ability cannot be found or discovery fails
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* await transport.connect();
|
|
93
|
+
* console.log('Connected to remote ability');
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
connect(): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Invoke a method on the remote ability
|
|
99
|
+
*
|
|
100
|
+
* @template TInput - Input parameter type
|
|
101
|
+
* @template TOutput - Return type
|
|
102
|
+
*
|
|
103
|
+
* @param method - Method name
|
|
104
|
+
* @param params - Method parameters
|
|
105
|
+
* @returns Promise resolving to method result
|
|
106
|
+
*
|
|
107
|
+
* @throws {KadiError} If method doesn't exist or invocation fails
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const result = await transport.invoke<{ a: number; b: number }, { result: number }>(
|
|
112
|
+
* 'add',
|
|
113
|
+
* { a: 5, b: 3 }
|
|
114
|
+
* );
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
invoke<TInput = unknown, TOutput = unknown>(method: string, params: TInput): Promise<TOutput>;
|
|
118
|
+
/**
|
|
119
|
+
* Get list of available methods
|
|
120
|
+
*
|
|
121
|
+
* @returns Array of method names
|
|
122
|
+
*/
|
|
123
|
+
getMethods(): string[];
|
|
124
|
+
/**
|
|
125
|
+
* Get schema for a specific method
|
|
126
|
+
*
|
|
127
|
+
* @param method - Method name
|
|
128
|
+
* @returns Method schema or undefined
|
|
129
|
+
*/
|
|
130
|
+
getMethodSchema(method: string): MethodSchema | undefined;
|
|
131
|
+
/**
|
|
132
|
+
* Disconnect from the ability
|
|
133
|
+
*
|
|
134
|
+
* Note: Does not disconnect the underlying broker connection,
|
|
135
|
+
* as it may be shared with other transports.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* await transport.disconnect();
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
disconnect(): Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* Publish an event from the ability
|
|
145
|
+
*
|
|
146
|
+
* @param eventName - Event name
|
|
147
|
+
* @param data - Event data
|
|
148
|
+
*/
|
|
149
|
+
publishEvent(eventName: string, data: unknown): void;
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=BrokerTransport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BrokerTransport.d.ts","sourceRoot":"","sources":["../../src/transports/BrokerTransport.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EACV,gBAAgB,EAChB,sBAAsB,EACtB,YAAY,EACb,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AACpF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAElE;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,gBAAgB,IAAI,uBAAuB,CAAC;IAE5C;;OAEG;IACH,iBAAiB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,cAAc,CAAC;IAEvD;;OAEG;IACH,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,eAAgB,SAAQ,YAAa,YAAW,gBAAgB;IAC3E;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmC;IAE3D;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IAEvC;;OAEG;IACH,OAAO,CAAC,OAAO,CAAgB;IAE/B;;OAEG;IACH,OAAO,CAAC,OAAO,CAAmC;IAElD;;OAEG;IACH,OAAO,CAAC,SAAS,CAAS;IAE1B;;OAEG;IACH,OAAO,CAAC,WAAW,CAAuB;IAE1C;;;;;OAKG;gBACS,OAAO,EAAE,sBAAsB,EAAE,MAAM,EAAE,aAAa;IAgBlE;;;;;;;;;;;;OAYG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA0E9B;;;;;;;;;;;;;;;;;;;OAmBG;IACG,MAAM,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,EAC9C,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,OAAO,CAAC;IAgEnB;;;;OAIG;IACH,UAAU,IAAI,MAAM,EAAE;IAItB;;;;;OAKG;IACH,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAIzD;;;;;;;;;;OAUG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAejC;;;;;OAKG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI;CA8BrD"}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Broker Transport
|
|
3
|
+
*
|
|
4
|
+
* Accesses abilities on remote agents via broker communication.
|
|
5
|
+
* Enables distributed system architecture with service discovery.
|
|
6
|
+
*
|
|
7
|
+
* @module transports/BrokerTransport
|
|
8
|
+
*/
|
|
9
|
+
import { EventEmitter } from 'events';
|
|
10
|
+
import { KadiError, ErrorCode } from '../types/index.js';
|
|
11
|
+
/**
|
|
12
|
+
* Broker Transport
|
|
13
|
+
*
|
|
14
|
+
* Communicates with remote abilities via broker infrastructure.
|
|
15
|
+
* Provides service discovery and load balancing across multiple brokers.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const transport = new BrokerTransport({
|
|
20
|
+
* abilityName: 'calculator',
|
|
21
|
+
* brokerUrl: 'ws://localhost:8080',
|
|
22
|
+
* networks: ['global']
|
|
23
|
+
* }, client);
|
|
24
|
+
*
|
|
25
|
+
* await transport.connect();
|
|
26
|
+
* const result = await transport.invoke('add', { a: 5, b: 3 });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export class BrokerTransport extends EventEmitter {
|
|
30
|
+
/**
|
|
31
|
+
* Transport configuration
|
|
32
|
+
*/
|
|
33
|
+
options;
|
|
34
|
+
/**
|
|
35
|
+
* Broker client interface
|
|
36
|
+
*/
|
|
37
|
+
client;
|
|
38
|
+
/**
|
|
39
|
+
* Discovered methods
|
|
40
|
+
*/
|
|
41
|
+
methods = [];
|
|
42
|
+
/**
|
|
43
|
+
* Method schemas
|
|
44
|
+
*/
|
|
45
|
+
schemas = new Map();
|
|
46
|
+
/**
|
|
47
|
+
* Whether transport is connected
|
|
48
|
+
*/
|
|
49
|
+
connected = false;
|
|
50
|
+
/**
|
|
51
|
+
* Target agent name (resolved during discovery)
|
|
52
|
+
*/
|
|
53
|
+
targetAgent = null;
|
|
54
|
+
/**
|
|
55
|
+
* Create a new BrokerTransport
|
|
56
|
+
*
|
|
57
|
+
* @param options - Broker transport options
|
|
58
|
+
* @param client - Broker client interface
|
|
59
|
+
*/
|
|
60
|
+
constructor(options, client) {
|
|
61
|
+
super();
|
|
62
|
+
this.options = {
|
|
63
|
+
timeout: options.timeout ?? 30000,
|
|
64
|
+
networks: options.networks ?? client.networks,
|
|
65
|
+
brokerUrl: options.brokerUrl,
|
|
66
|
+
brokerName: options.brokerName ?? 'default',
|
|
67
|
+
authToken: options.authToken ?? '',
|
|
68
|
+
abilityName: options.abilityName,
|
|
69
|
+
abilityVersion: options.abilityVersion ?? '0.0.1'
|
|
70
|
+
};
|
|
71
|
+
this.client = client;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Connect to the ability
|
|
75
|
+
*
|
|
76
|
+
* Discovers the ability on the broker network and queries its capabilities.
|
|
77
|
+
*
|
|
78
|
+
* @throws {KadiError} If ability cannot be found or discovery fails
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* await transport.connect();
|
|
83
|
+
* console.log('Connected to remote ability');
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
async connect() {
|
|
87
|
+
if (this.connected) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
// Get broker protocol
|
|
92
|
+
const protocol = this.client.getBrokerProtocol(this.options.brokerName);
|
|
93
|
+
// Discover agents on the network
|
|
94
|
+
const agents = await protocol.discoverAgents(this.options.networks);
|
|
95
|
+
// Find the target ability
|
|
96
|
+
const targetAgent = agents.find(agent => agent.name === this.options.abilityName ||
|
|
97
|
+
agent.capabilities.includes(this.options.abilityName));
|
|
98
|
+
if (!targetAgent) {
|
|
99
|
+
throw new KadiError(`Ability '${this.options.abilityName}' not found on networks: ${this.options.networks.join(', ')}`, ErrorCode.ABILITY_NOT_FOUND, 404, {
|
|
100
|
+
abilityName: this.options.abilityName,
|
|
101
|
+
networks: this.options.networks,
|
|
102
|
+
availableAgents: agents.map(a => a.name)
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
this.targetAgent = targetAgent.name;
|
|
106
|
+
// Query capabilities
|
|
107
|
+
const capabilities = await protocol.queryCapabilities(this.targetAgent, this.options.networks);
|
|
108
|
+
// Extract methods and schemas
|
|
109
|
+
this.methods = capabilities.map(cap => cap.name);
|
|
110
|
+
for (const cap of capabilities) {
|
|
111
|
+
if (cap.inputSchema || cap.outputSchema) {
|
|
112
|
+
this.schemas.set(cap.name, {
|
|
113
|
+
description: cap.description,
|
|
114
|
+
inputSchema: cap.inputSchema,
|
|
115
|
+
outputSchema: cap.outputSchema
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
this.connected = true;
|
|
120
|
+
this.emit('connected');
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
const kadiError = error instanceof KadiError
|
|
124
|
+
? error
|
|
125
|
+
: new KadiError(`Failed to connect to ability: ${error instanceof Error ? error.message : String(error)}`, ErrorCode.ABILITY_LOAD_FAILED, 500, {
|
|
126
|
+
abilityName: this.options.abilityName,
|
|
127
|
+
networks: this.options.networks,
|
|
128
|
+
originalError: error instanceof Error ? error.message : String(error)
|
|
129
|
+
});
|
|
130
|
+
this.emit('error', kadiError);
|
|
131
|
+
throw kadiError;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Invoke a method on the remote ability
|
|
136
|
+
*
|
|
137
|
+
* @template TInput - Input parameter type
|
|
138
|
+
* @template TOutput - Return type
|
|
139
|
+
*
|
|
140
|
+
* @param method - Method name
|
|
141
|
+
* @param params - Method parameters
|
|
142
|
+
* @returns Promise resolving to method result
|
|
143
|
+
*
|
|
144
|
+
* @throws {KadiError} If method doesn't exist or invocation fails
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* const result = await transport.invoke<{ a: number; b: number }, { result: number }>(
|
|
149
|
+
* 'add',
|
|
150
|
+
* { a: 5, b: 3 }
|
|
151
|
+
* );
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
async invoke(method, params) {
|
|
155
|
+
if (!this.connected || !this.targetAgent) {
|
|
156
|
+
throw new KadiError('Transport not connected', ErrorCode.TRANSPORT_NOT_CONNECTED, 503, { abilityName: this.options.abilityName });
|
|
157
|
+
}
|
|
158
|
+
// Check if method exists
|
|
159
|
+
if (!this.methods.includes(method)) {
|
|
160
|
+
throw new KadiError(`Method '${method}' not found on ability '${this.options.abilityName}'`, ErrorCode.ABILITY_METHOD_NOT_FOUND, 404, {
|
|
161
|
+
abilityName: this.options.abilityName,
|
|
162
|
+
method,
|
|
163
|
+
availableMethods: this.methods
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
try {
|
|
167
|
+
// Get broker protocol
|
|
168
|
+
const protocol = this.client.getBrokerProtocol(this.options.brokerName);
|
|
169
|
+
// Invoke tool via broker
|
|
170
|
+
const result = await protocol.invokeTool({
|
|
171
|
+
targetAgent: this.targetAgent,
|
|
172
|
+
toolName: method,
|
|
173
|
+
toolInput: params,
|
|
174
|
+
timeout: this.options.timeout
|
|
175
|
+
});
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
// Don't wrap KadiError
|
|
180
|
+
if (error instanceof KadiError) {
|
|
181
|
+
throw error;
|
|
182
|
+
}
|
|
183
|
+
// Enhance the original error
|
|
184
|
+
if (error instanceof Error) {
|
|
185
|
+
const enhancedError = error;
|
|
186
|
+
enhancedError.message = `${error.message} (in remote ${this.options.abilityName}.${method})`;
|
|
187
|
+
throw enhancedError;
|
|
188
|
+
}
|
|
189
|
+
throw new KadiError(`Remote method invocation failed: ${String(error)}`, ErrorCode.TOOL_INVOCATION_FAILED, 500, {
|
|
190
|
+
abilityName: this.options.abilityName,
|
|
191
|
+
targetAgent: this.targetAgent,
|
|
192
|
+
method
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Get list of available methods
|
|
198
|
+
*
|
|
199
|
+
* @returns Array of method names
|
|
200
|
+
*/
|
|
201
|
+
getMethods() {
|
|
202
|
+
return [...this.methods];
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Get schema for a specific method
|
|
206
|
+
*
|
|
207
|
+
* @param method - Method name
|
|
208
|
+
* @returns Method schema or undefined
|
|
209
|
+
*/
|
|
210
|
+
getMethodSchema(method) {
|
|
211
|
+
return this.schemas.get(method);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Disconnect from the ability
|
|
215
|
+
*
|
|
216
|
+
* Note: Does not disconnect the underlying broker connection,
|
|
217
|
+
* as it may be shared with other transports.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```typescript
|
|
221
|
+
* await transport.disconnect();
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
async disconnect() {
|
|
225
|
+
if (!this.connected) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
// Just mark as disconnected - don't close broker connection
|
|
229
|
+
// The broker connection is managed by BrokerConnectionManager
|
|
230
|
+
this.connected = false;
|
|
231
|
+
this.targetAgent = null;
|
|
232
|
+
this.methods = [];
|
|
233
|
+
this.schemas.clear();
|
|
234
|
+
this.emit('disconnected');
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Publish an event from the ability
|
|
238
|
+
*
|
|
239
|
+
* @param eventName - Event name
|
|
240
|
+
* @param data - Event data
|
|
241
|
+
*/
|
|
242
|
+
publishEvent(eventName, data) {
|
|
243
|
+
if (!this.connected) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
try {
|
|
247
|
+
const protocol = this.client.getBrokerProtocol(this.options.brokerName);
|
|
248
|
+
protocol.publishEvent({
|
|
249
|
+
channel: eventName,
|
|
250
|
+
data,
|
|
251
|
+
networkId: this.options.networks[0] // Use first network
|
|
252
|
+
}).catch(error => {
|
|
253
|
+
this.emit('error', new KadiError(`Failed to publish event: ${error instanceof Error ? error.message : String(error)}`, ErrorCode.EVENT_PUBLISH_FAILED, 500, { abilityName: this.options.abilityName, eventName }));
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
this.emit('error', new KadiError(`Failed to publish event: ${error instanceof Error ? error.message : String(error)}`, ErrorCode.EVENT_PUBLISH_FAILED, 500, { abilityName: this.options.abilityName, eventName }));
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
//# sourceMappingURL=BrokerTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BrokerTransport.js","sourceRoot":"","sources":["../../src/transports/BrokerTransport.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAMtC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AA2BzD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,eAAgB,SAAQ,YAAY;IAC/C;;OAEG;IACc,OAAO,CAAmC;IAE3D;;OAEG;IACc,MAAM,CAAgB;IAEvC;;OAEG;IACK,OAAO,GAAa,EAAE,CAAC;IAE/B;;OAEG;IACK,OAAO,GAAG,IAAI,GAAG,EAAwB,CAAC;IAElD;;OAEG;IACK,SAAS,GAAG,KAAK,CAAC;IAE1B;;OAEG;IACK,WAAW,GAAkB,IAAI,CAAC;IAE1C;;;;;OAKG;IACH,YAAY,OAA+B,EAAE,MAAqB;QAChE,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,OAAO,GAAG;YACb,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,KAAK;YACjC,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ;YAC7C,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,SAAS;YAC3C,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,EAAE;YAClC,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,OAAO;SAClD,CAAC;QAEF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,OAAO;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,CAAC,YAAY,CAAC;gBACpB,OAAO,EAAE,SAAS;gBAClB,IAAI;gBACJ,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,oBAAoB;aACzD,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;gBACf,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,SAAS,CAC9B,4BAA4B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EACpF,SAAS,CAAC,oBAAoB,EAC9B,GAAG,EACH,EAAE,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,SAAS,EAAE,CACrD,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QAEL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,SAAS,CAC9B,4BAA4B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EACpF,SAAS,CAAC,oBAAoB,EAC9B,GAAG,EACH,EAAE,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,SAAS,EAAE,CACrD,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Native Transport
|
|
3
|
+
*
|
|
4
|
+
* Loads abilities in-process for zero-overhead communication.
|
|
5
|
+
* Best for abilities written in JavaScript/TypeScript that can run in the same process.
|
|
6
|
+
*
|
|
7
|
+
* @module transports/NativeTransport
|
|
8
|
+
*/
|
|
9
|
+
import { EventEmitter } from 'events';
|
|
10
|
+
import type { AbilityTransport, NativeTransportOptions, MethodSchema } from '../types/index.js';
|
|
11
|
+
import type { AgentJson } from '../abilities/types.js';
|
|
12
|
+
/**
|
|
13
|
+
* Native Transport
|
|
14
|
+
*
|
|
15
|
+
* Loads Node.js modules directly into the current process.
|
|
16
|
+
* Provides zero-overhead method invocation since everything runs in-process.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const transport = new NativeTransport({
|
|
21
|
+
* abilityName: 'calculator',
|
|
22
|
+
* abilityPath: '/path/to/calculator',
|
|
23
|
+
* entryPoint: 'index.js'
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* await transport.connect();
|
|
27
|
+
* const result = await transport.invoke('add', { a: 5, b: 3 });
|
|
28
|
+
* console.log(result); // { result: 8 }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare class NativeTransport extends EventEmitter implements AbilityTransport {
|
|
32
|
+
/**
|
|
33
|
+
* Transport configuration
|
|
34
|
+
*/
|
|
35
|
+
private readonly options;
|
|
36
|
+
/**
|
|
37
|
+
* Loaded ability module
|
|
38
|
+
*/
|
|
39
|
+
private ability;
|
|
40
|
+
/**
|
|
41
|
+
* Whether loaded module is a KadiClient instance
|
|
42
|
+
*/
|
|
43
|
+
private isKadiClientInstance;
|
|
44
|
+
/**
|
|
45
|
+
* Discovered methods
|
|
46
|
+
*/
|
|
47
|
+
private methods;
|
|
48
|
+
/**
|
|
49
|
+
* Method schemas
|
|
50
|
+
*/
|
|
51
|
+
private schemas;
|
|
52
|
+
/**
|
|
53
|
+
* Whether transport is connected
|
|
54
|
+
*/
|
|
55
|
+
private connected;
|
|
56
|
+
/**
|
|
57
|
+
* Create a new NativeTransport
|
|
58
|
+
*
|
|
59
|
+
* @param options - Native transport options
|
|
60
|
+
*/
|
|
61
|
+
constructor(options: NativeTransportOptions);
|
|
62
|
+
/**
|
|
63
|
+
* Connect to the ability
|
|
64
|
+
*
|
|
65
|
+
* Loads the module from disk and performs discovery.
|
|
66
|
+
*
|
|
67
|
+
* @throws {KadiError} If module cannot be loaded
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* await transport.connect();
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
connect(): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Invoke a method on the ability
|
|
77
|
+
*
|
|
78
|
+
* @template TInput - Input parameter type
|
|
79
|
+
* @template TOutput - Return type
|
|
80
|
+
*
|
|
81
|
+
* @param method - Method name
|
|
82
|
+
* @param params - Method parameters
|
|
83
|
+
* @returns Promise resolving to method result
|
|
84
|
+
*
|
|
85
|
+
* @throws {KadiError} If method doesn't exist or invocation fails
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const result = await transport.invoke<{ a: number; b: number }, { result: number }>(
|
|
90
|
+
* 'add',
|
|
91
|
+
* { a: 5, b: 3 }
|
|
92
|
+
* );
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
invoke<TInput = unknown, TOutput = unknown>(method: string, params: TInput): Promise<TOutput>;
|
|
96
|
+
/**
|
|
97
|
+
* Get list of available methods
|
|
98
|
+
*
|
|
99
|
+
* @returns Array of method names
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* const methods = transport.getMethods();
|
|
104
|
+
* console.log('Available methods:', methods);
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
getMethods(): string[];
|
|
108
|
+
/**
|
|
109
|
+
* Get schema for a specific method
|
|
110
|
+
*
|
|
111
|
+
* @param method - Method name
|
|
112
|
+
* @returns Method schema or undefined
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* const schema = transport.getMethodSchema('add');
|
|
117
|
+
* if (schema) {
|
|
118
|
+
* console.log('Input schema:', schema.inputSchema);
|
|
119
|
+
* }
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
getMethodSchema(method: string): MethodSchema | undefined;
|
|
123
|
+
/**
|
|
124
|
+
* Read agent.json representation (only for KadiClient instances)
|
|
125
|
+
*
|
|
126
|
+
* Returns the agent.json representation from KadiClient.readAgentJson() if
|
|
127
|
+
* the loaded module is a KadiClient instance. Returns undefined for legacy modules.
|
|
128
|
+
*
|
|
129
|
+
* **What this returns:**
|
|
130
|
+
* - Runtime representation of the ability's agent.json file
|
|
131
|
+
* - Contains name, version, description, and tools (mapped from agent.json's 'exports')
|
|
132
|
+
* - Used for type generation during `kadi install`
|
|
133
|
+
*
|
|
134
|
+
* @returns agent.json representation or undefined
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* const agentJson = transport.readAgentJson();
|
|
139
|
+
* if (agentJson) {
|
|
140
|
+
* console.log('Ability:', agentJson.name, agentJson.version);
|
|
141
|
+
* console.log('Tools:', agentJson.tools.map(t => t.name));
|
|
142
|
+
* // This represents what's in the ability's agent.json file
|
|
143
|
+
* }
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
readAgentJson(): AgentJson | undefined;
|
|
147
|
+
/**
|
|
148
|
+
* Disconnect from the ability
|
|
149
|
+
*
|
|
150
|
+
* Cleans up resources and removes references.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* await transport.disconnect();
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
disconnect(): Promise<void>;
|
|
158
|
+
/**
|
|
159
|
+
* Publish an event from the ability
|
|
160
|
+
*
|
|
161
|
+
* @param eventName - Event name
|
|
162
|
+
* @param data - Event data
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* transport.publishEvent('calculation.completed', { result: 42 });
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
publishEvent(eventName: string, data: unknown): void;
|
|
170
|
+
/**
|
|
171
|
+
* Discover methods on the loaded ability
|
|
172
|
+
*
|
|
173
|
+
* Introspects the ability object to find callable methods.
|
|
174
|
+
* Excludes internal methods (starting with _) and special methods.
|
|
175
|
+
*/
|
|
176
|
+
private discoverMethods;
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=NativeTransport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeTransport.d.ts","sourceRoot":"","sources":["../../src/transports/NativeTransport.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,KAAK,EACV,gBAAgB,EAChB,sBAAsB,EACtB,YAAY,EACb,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAiDvD;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,eAAgB,SAAQ,YAAa,YAAW,gBAAgB;IAC3E;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmC;IAE3D;;OAEG;IACH,OAAO,CAAC,OAAO,CAAiB;IAEhC;;OAEG;IACH,OAAO,CAAC,oBAAoB,CAAS;IAErC;;OAEG;IACH,OAAO,CAAC,OAAO,CAAgB;IAE/B;;OAEG;IACH,OAAO,CAAC,OAAO,CAAmC;IAElD;;OAEG;IACH,OAAO,CAAC,SAAS,CAAS;IAE1B;;;;OAIG;gBACS,OAAO,EAAE,sBAAsB;IAW3C;;;;;;;;;;;OAWG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAqE9B;;;;;;;;;;;;;;;;;;;OAmBG;IACG,MAAM,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,EAC9C,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,OAAO,CAAC;IA+FnB;;;;;;;;;;OAUG;IACH,UAAU,IAAI,MAAM,EAAE;IAItB;;;;;;;;;;;;;OAaG;IACH,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG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