@kadi.build/core 0.0.1-alpha.1 → 0.0.1-alpha.10
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 +1387 -214
- 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 +177 -0
- package/dist/abilities/AbilityLoader.d.ts.map +1 -0
- package/dist/abilities/AbilityLoader.js +277 -0
- package/dist/abilities/AbilityLoader.js.map +1 -0
- package/dist/abilities/AbilityProxy.d.ts +463 -0
- package/dist/abilities/AbilityProxy.d.ts.map +1 -0
- package/dist/abilities/AbilityProxy.js +511 -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 +156 -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 +270 -0
- package/dist/client/KadiClient.d.ts.map +1 -0
- package/dist/client/KadiClient.js +492 -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 +49 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +63 -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 +19 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +25 -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/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 +149 -0
- package/dist/transports/NativeTransport.d.ts.map +1 -0
- package/dist/transports/NativeTransport.js +302 -0
- package/dist/transports/NativeTransport.js.map +1 -0
- package/dist/transports/StdioTransport.d.ts +172 -0
- package/dist/transports/StdioTransport.d.ts.map +1 -0
- package/dist/transports/StdioTransport.js +410 -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 +301 -0
- package/dist/types/broker.d.ts.map +1 -0
- package/dist/types/broker.js +46 -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 +32 -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/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 +69 -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 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Errors Module
|
|
3
|
+
*
|
|
4
|
+
* Re-exports error types and utilities from types/errors.ts
|
|
5
|
+
* This module provides a convenient import point for error handling.
|
|
6
|
+
*/
|
|
7
|
+
export { KadiError, ErrorCode, isKadiError, isError, success, failure } from '../types/errors.js';
|
|
8
|
+
export type { ErrorContext, ErrorJSON, Result } from '../types/errors.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,SAAS,EACT,SAAS,EACT,WAAW,EACX,OAAO,EACP,OAAO,EACP,OAAO,EACR,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EACV,YAAY,EACZ,SAAS,EACT,MAAM,EACP,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Errors Module
|
|
3
|
+
*
|
|
4
|
+
* Re-exports error types and utilities from types/errors.ts
|
|
5
|
+
* This module provides a convenient import point for error handling.
|
|
6
|
+
*/
|
|
7
|
+
export { KadiError, ErrorCode, isKadiError, isError, success, failure } from '../types/errors.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,SAAS,EACT,SAAS,EACT,WAAW,EACX,OAAO,EACP,OAAO,EACP,OAAO,EACR,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event Hub
|
|
3
|
+
*
|
|
4
|
+
* Unified pub/sub event system that works consistently across all transports.
|
|
5
|
+
* Supports wildcard pattern matching for flexible event subscriptions.
|
|
6
|
+
*
|
|
7
|
+
* @module events/EventHub
|
|
8
|
+
*/
|
|
9
|
+
import type { EventPattern, EventName, EventCallback, UnsubscribeFunction, PublishOptions, EventSubscription, SubscriptionOptions } from '../types/index.js';
|
|
10
|
+
/**
|
|
11
|
+
* Event Hub class
|
|
12
|
+
*
|
|
13
|
+
* Single responsibility: Manage event subscriptions and publication.
|
|
14
|
+
* Works uniformly across all transport types (native, stdio, broker).
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const hub = new EventHub('my-agent');
|
|
19
|
+
*
|
|
20
|
+
* // Subscribe to events
|
|
21
|
+
* const unsubscribe = hub.subscribe('user.*', (data) => {
|
|
22
|
+
* console.log('User event:', data);
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* // Publish an event
|
|
26
|
+
* hub.publish('user.login', { userId: '123', timestamp: Date.now() });
|
|
27
|
+
*
|
|
28
|
+
* // Unsubscribe
|
|
29
|
+
* unsubscribe();
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare class EventHub {
|
|
33
|
+
/**
|
|
34
|
+
* Source identifier (agent/ability name)
|
|
35
|
+
*/
|
|
36
|
+
private source;
|
|
37
|
+
/**
|
|
38
|
+
* Event subscriptions map (pattern -> Set of callbacks)
|
|
39
|
+
* Uses unknown for data type since different subscriptions may have different data types
|
|
40
|
+
*/
|
|
41
|
+
private readonly subscriptions;
|
|
42
|
+
/**
|
|
43
|
+
* Subscription ID counter
|
|
44
|
+
*/
|
|
45
|
+
private subscriptionIdCounter;
|
|
46
|
+
/**
|
|
47
|
+
* Create a new EventHub
|
|
48
|
+
*
|
|
49
|
+
* @param source - Identifier for this event source (agent/ability name)
|
|
50
|
+
*/
|
|
51
|
+
constructor(source: string);
|
|
52
|
+
/**
|
|
53
|
+
* Update the source identifier
|
|
54
|
+
*
|
|
55
|
+
* This is useful when the agent/ability name is determined after construction.
|
|
56
|
+
*
|
|
57
|
+
* @param newSource - New source identifier
|
|
58
|
+
*/
|
|
59
|
+
setSource(newSource: string): void;
|
|
60
|
+
/**
|
|
61
|
+
* Subscribe to events matching a pattern
|
|
62
|
+
*
|
|
63
|
+
* Patterns support wildcards:
|
|
64
|
+
* - `user.login` - exact match
|
|
65
|
+
* - `user.*` - all events starting with "user."
|
|
66
|
+
* - `*.error` - all error events
|
|
67
|
+
* - `*` - all events
|
|
68
|
+
*
|
|
69
|
+
* @template TData - Expected event data type
|
|
70
|
+
*
|
|
71
|
+
* @param pattern - Event pattern to match
|
|
72
|
+
* @param callback - Function to call when matching events occur
|
|
73
|
+
* @param options - Optional subscription options
|
|
74
|
+
* @returns Function to unsubscribe
|
|
75
|
+
*
|
|
76
|
+
* @throws {KadiError} If pattern or callback is invalid
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const unsubscribe = hub.subscribe('user.login', (data) => {
|
|
81
|
+
* console.log('User logged in:', data);
|
|
82
|
+
* });
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
subscribe<TData = unknown>(pattern: EventPattern, callback: EventCallback<TData>, options?: SubscriptionOptions): UnsubscribeFunction;
|
|
86
|
+
/**
|
|
87
|
+
* Publish an event to all matching subscribers
|
|
88
|
+
*
|
|
89
|
+
* @template TData - Event data type
|
|
90
|
+
*
|
|
91
|
+
* @param eventName - Event name/channel
|
|
92
|
+
* @param data - Event data payload
|
|
93
|
+
* @param options - Optional publishing options
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* hub.publish('user.logout', {
|
|
98
|
+
* userId: '123',
|
|
99
|
+
* timestamp: Date.now()
|
|
100
|
+
* });
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
publish<TData = unknown>(eventName: EventName, data: TData, options?: PublishOptions): void;
|
|
104
|
+
/**
|
|
105
|
+
* Unsubscribe from a pattern
|
|
106
|
+
*
|
|
107
|
+
* @param pattern - Pattern to unsubscribe from
|
|
108
|
+
* @param callback - Optional specific callback to remove (removes all if not specified)
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* hub.unsubscribe('user.*');
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
unsubscribe(pattern: EventPattern, callback?: EventCallback): void;
|
|
116
|
+
/**
|
|
117
|
+
* Get all active subscriptions
|
|
118
|
+
*
|
|
119
|
+
* @returns Array of all active subscriptions
|
|
120
|
+
*/
|
|
121
|
+
getSubscriptions(): EventSubscription[];
|
|
122
|
+
/**
|
|
123
|
+
* Get subscription count
|
|
124
|
+
*
|
|
125
|
+
* @returns Number of active subscriptions
|
|
126
|
+
*/
|
|
127
|
+
get subscriptionCount(): number;
|
|
128
|
+
/**
|
|
129
|
+
* Clear all subscriptions
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* hub.clear();
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
clear(): void;
|
|
137
|
+
/**
|
|
138
|
+
* Find subscriptions matching an event name
|
|
139
|
+
*
|
|
140
|
+
* @param eventName - Event name to match
|
|
141
|
+
* @returns Set of matching subscriptions
|
|
142
|
+
*/
|
|
143
|
+
private findMatchingSubscriptions;
|
|
144
|
+
/**
|
|
145
|
+
* Check if an event name matches a pattern
|
|
146
|
+
*
|
|
147
|
+
* Supports wildcard matching:
|
|
148
|
+
* - Exact match: 'user.login' matches 'user.login'
|
|
149
|
+
* - Prefix wildcard: 'user.*' matches 'user.login', 'user.logout', etc.
|
|
150
|
+
* - Suffix wildcard: '*.error' matches 'user.error', 'system.error', etc.
|
|
151
|
+
* - Full wildcard: '*' matches any event
|
|
152
|
+
*
|
|
153
|
+
* @param eventName - Event name to test
|
|
154
|
+
* @param pattern - Pattern to match against
|
|
155
|
+
* @returns true if event matches pattern
|
|
156
|
+
*/
|
|
157
|
+
private matchesPattern;
|
|
158
|
+
/**
|
|
159
|
+
* Deliver an event to a subscription
|
|
160
|
+
*
|
|
161
|
+
* @param subscription - Subscription to deliver to
|
|
162
|
+
* @param payload - Event payload
|
|
163
|
+
*/
|
|
164
|
+
private deliverEvent;
|
|
165
|
+
/**
|
|
166
|
+
* Unsubscribe by subscription ID
|
|
167
|
+
*
|
|
168
|
+
* @param id - Subscription ID to remove
|
|
169
|
+
*/
|
|
170
|
+
private unsubscribeById;
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=EventHub.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventHub.d.ts","sourceRoot":"","sources":["../../src/events/EventHub.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,SAAS,EACT,aAAa,EAEb,mBAAmB,EACnB,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACpB,MAAM,mBAAmB,CAAC;AAG3B;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,QAAQ;IACnB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAS;IAEvB;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA4D;IAE1F;;OAEG;IACH,OAAO,CAAC,qBAAqB,CAAK;IAElC;;;;OAIG;gBACS,MAAM,EAAE,MAAM;IAI1B;;;;;;OAMG;IACH,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAIlC;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,SAAS,CAAC,KAAK,GAAG,OAAO,EACvB,OAAO,EAAE,YAAY,EACrB,QAAQ,EAAE,aAAa,CAAC,KAAK,CAAC,EAC9B,OAAO,CAAC,EAAE,mBAAmB,GAC5B,mBAAmB;IA2DtB;;;;;;;;;;;;;;;;OAgBG;IACH,OAAO,CAAC,KAAK,GAAG,OAAO,EACrB,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,KAAK,EACX,OAAO,CAAC,EAAE,cAAc,GACvB,IAAI;IAsBP;;;;;;;;;;OAUG;IACH,WAAW,CAAC,OAAO,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE,aAAa,GAAG,IAAI;IAwBlE;;;;OAIG;IACH,gBAAgB,IAAI,iBAAiB,EAAE;IAQvC;;;;OAIG;IACH,IAAI,iBAAiB,IAAI,MAAM,CAM9B;IAED;;;;;;;OAOG;IACH,KAAK,IAAI,IAAI;IAIb;;;;;OAKG;IACH,OAAO,CAAC,yBAAyB;IAcjC;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,cAAc;IAoBtB;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IA+BpB;;;;OAIG;IACH,OAAO,CAAC,eAAe;CAaxB"}
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event Hub
|
|
3
|
+
*
|
|
4
|
+
* Unified pub/sub event system that works consistently across all transports.
|
|
5
|
+
* Supports wildcard pattern matching for flexible event subscriptions.
|
|
6
|
+
*
|
|
7
|
+
* @module events/EventHub
|
|
8
|
+
*/
|
|
9
|
+
import { KadiError, ErrorCode } from '../types/index.js';
|
|
10
|
+
/**
|
|
11
|
+
* Event Hub class
|
|
12
|
+
*
|
|
13
|
+
* Single responsibility: Manage event subscriptions and publication.
|
|
14
|
+
* Works uniformly across all transport types (native, stdio, broker).
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const hub = new EventHub('my-agent');
|
|
19
|
+
*
|
|
20
|
+
* // Subscribe to events
|
|
21
|
+
* const unsubscribe = hub.subscribe('user.*', (data) => {
|
|
22
|
+
* console.log('User event:', data);
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* // Publish an event
|
|
26
|
+
* hub.publish('user.login', { userId: '123', timestamp: Date.now() });
|
|
27
|
+
*
|
|
28
|
+
* // Unsubscribe
|
|
29
|
+
* unsubscribe();
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export class EventHub {
|
|
33
|
+
/**
|
|
34
|
+
* Source identifier (agent/ability name)
|
|
35
|
+
*/
|
|
36
|
+
source;
|
|
37
|
+
/**
|
|
38
|
+
* Event subscriptions map (pattern -> Set of callbacks)
|
|
39
|
+
* Uses unknown for data type since different subscriptions may have different data types
|
|
40
|
+
*/
|
|
41
|
+
subscriptions = new Map();
|
|
42
|
+
/**
|
|
43
|
+
* Subscription ID counter
|
|
44
|
+
*/
|
|
45
|
+
subscriptionIdCounter = 0;
|
|
46
|
+
/**
|
|
47
|
+
* Create a new EventHub
|
|
48
|
+
*
|
|
49
|
+
* @param source - Identifier for this event source (agent/ability name)
|
|
50
|
+
*/
|
|
51
|
+
constructor(source) {
|
|
52
|
+
this.source = source;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Update the source identifier
|
|
56
|
+
*
|
|
57
|
+
* This is useful when the agent/ability name is determined after construction.
|
|
58
|
+
*
|
|
59
|
+
* @param newSource - New source identifier
|
|
60
|
+
*/
|
|
61
|
+
setSource(newSource) {
|
|
62
|
+
this.source = newSource;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Subscribe to events matching a pattern
|
|
66
|
+
*
|
|
67
|
+
* Patterns support wildcards:
|
|
68
|
+
* - `user.login` - exact match
|
|
69
|
+
* - `user.*` - all events starting with "user."
|
|
70
|
+
* - `*.error` - all error events
|
|
71
|
+
* - `*` - all events
|
|
72
|
+
*
|
|
73
|
+
* @template TData - Expected event data type
|
|
74
|
+
*
|
|
75
|
+
* @param pattern - Event pattern to match
|
|
76
|
+
* @param callback - Function to call when matching events occur
|
|
77
|
+
* @param options - Optional subscription options
|
|
78
|
+
* @returns Function to unsubscribe
|
|
79
|
+
*
|
|
80
|
+
* @throws {KadiError} If pattern or callback is invalid
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* const unsubscribe = hub.subscribe('user.login', (data) => {
|
|
85
|
+
* console.log('User logged in:', data);
|
|
86
|
+
* });
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
subscribe(pattern, callback, options) {
|
|
90
|
+
// Validate pattern
|
|
91
|
+
if (!pattern || typeof pattern !== 'string') {
|
|
92
|
+
throw new KadiError('Event pattern must be a non-empty string', ErrorCode.EVENT_PATTERN_INVALID, 400, { pattern });
|
|
93
|
+
}
|
|
94
|
+
// Validate callback
|
|
95
|
+
if (typeof callback !== 'function') {
|
|
96
|
+
throw new KadiError('Event callback must be a function', ErrorCode.INVALID_INPUT, 400, { pattern });
|
|
97
|
+
}
|
|
98
|
+
// Create subscription
|
|
99
|
+
const subscription = {
|
|
100
|
+
id: `sub_${++this.subscriptionIdCounter}`,
|
|
101
|
+
pattern,
|
|
102
|
+
callback: callback,
|
|
103
|
+
createdAt: Date.now(),
|
|
104
|
+
options
|
|
105
|
+
};
|
|
106
|
+
// Add to subscriptions map
|
|
107
|
+
if (!this.subscriptions.has(pattern)) {
|
|
108
|
+
this.subscriptions.set(pattern, new Set());
|
|
109
|
+
}
|
|
110
|
+
const patternSubscriptions = this.subscriptions.get(pattern);
|
|
111
|
+
if (patternSubscriptions) {
|
|
112
|
+
// Safe cast: EventSubscription<TData> is compatible with EventSubscription<unknown>
|
|
113
|
+
// since unknown is the least restrictive type
|
|
114
|
+
patternSubscriptions.add(subscription);
|
|
115
|
+
}
|
|
116
|
+
// Set up timeout if specified
|
|
117
|
+
let timeoutId;
|
|
118
|
+
if (options?.timeout) {
|
|
119
|
+
timeoutId = setTimeout(() => {
|
|
120
|
+
this.unsubscribeById(subscription.id);
|
|
121
|
+
}, options.timeout);
|
|
122
|
+
}
|
|
123
|
+
// Return unsubscribe function
|
|
124
|
+
return () => {
|
|
125
|
+
if (timeoutId) {
|
|
126
|
+
clearTimeout(timeoutId);
|
|
127
|
+
}
|
|
128
|
+
this.unsubscribeById(subscription.id);
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Publish an event to all matching subscribers
|
|
133
|
+
*
|
|
134
|
+
* @template TData - Event data type
|
|
135
|
+
*
|
|
136
|
+
* @param eventName - Event name/channel
|
|
137
|
+
* @param data - Event data payload
|
|
138
|
+
* @param options - Optional publishing options
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* hub.publish('user.logout', {
|
|
143
|
+
* userId: '123',
|
|
144
|
+
* timestamp: Date.now()
|
|
145
|
+
* });
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
publish(eventName, data, options) {
|
|
149
|
+
// Create event payload
|
|
150
|
+
const payload = {
|
|
151
|
+
eventName,
|
|
152
|
+
data,
|
|
153
|
+
timestamp: Date.now(),
|
|
154
|
+
source: this.source,
|
|
155
|
+
metadata: {
|
|
156
|
+
...options,
|
|
157
|
+
correlationId: options?.correlationId
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
// Find all matching subscriptions
|
|
161
|
+
const matchingSubscriptions = this.findMatchingSubscriptions(eventName);
|
|
162
|
+
// Deliver to each subscriber
|
|
163
|
+
for (const subscription of matchingSubscriptions) {
|
|
164
|
+
this.deliverEvent(subscription, payload);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Unsubscribe from a pattern
|
|
169
|
+
*
|
|
170
|
+
* @param pattern - Pattern to unsubscribe from
|
|
171
|
+
* @param callback - Optional specific callback to remove (removes all if not specified)
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```typescript
|
|
175
|
+
* hub.unsubscribe('user.*');
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
unsubscribe(pattern, callback) {
|
|
179
|
+
const patternSubscriptions = this.subscriptions.get(pattern);
|
|
180
|
+
if (!patternSubscriptions) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (callback) {
|
|
184
|
+
// Remove specific callback
|
|
185
|
+
for (const sub of patternSubscriptions) {
|
|
186
|
+
if (sub.callback === callback) {
|
|
187
|
+
patternSubscriptions.delete(sub);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
// Remove all subscriptions for this pattern
|
|
193
|
+
patternSubscriptions.clear();
|
|
194
|
+
}
|
|
195
|
+
// Clean up empty pattern entries
|
|
196
|
+
if (patternSubscriptions.size === 0) {
|
|
197
|
+
this.subscriptions.delete(pattern);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Get all active subscriptions
|
|
202
|
+
*
|
|
203
|
+
* @returns Array of all active subscriptions
|
|
204
|
+
*/
|
|
205
|
+
getSubscriptions() {
|
|
206
|
+
const allSubscriptions = [];
|
|
207
|
+
for (const subs of this.subscriptions.values()) {
|
|
208
|
+
allSubscriptions.push(...Array.from(subs));
|
|
209
|
+
}
|
|
210
|
+
return allSubscriptions;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Get subscription count
|
|
214
|
+
*
|
|
215
|
+
* @returns Number of active subscriptions
|
|
216
|
+
*/
|
|
217
|
+
get subscriptionCount() {
|
|
218
|
+
let count = 0;
|
|
219
|
+
for (const subs of this.subscriptions.values()) {
|
|
220
|
+
count += subs.size;
|
|
221
|
+
}
|
|
222
|
+
return count;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Clear all subscriptions
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* ```typescript
|
|
229
|
+
* hub.clear();
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
clear() {
|
|
233
|
+
this.subscriptions.clear();
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Find subscriptions matching an event name
|
|
237
|
+
*
|
|
238
|
+
* @param eventName - Event name to match
|
|
239
|
+
* @returns Set of matching subscriptions
|
|
240
|
+
*/
|
|
241
|
+
findMatchingSubscriptions(eventName) {
|
|
242
|
+
const matching = new Set();
|
|
243
|
+
for (const [pattern, subs] of this.subscriptions.entries()) {
|
|
244
|
+
if (this.matchesPattern(eventName, pattern)) {
|
|
245
|
+
for (const sub of subs) {
|
|
246
|
+
matching.add(sub);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return matching;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Check if an event name matches a pattern
|
|
254
|
+
*
|
|
255
|
+
* Supports wildcard matching:
|
|
256
|
+
* - Exact match: 'user.login' matches 'user.login'
|
|
257
|
+
* - Prefix wildcard: 'user.*' matches 'user.login', 'user.logout', etc.
|
|
258
|
+
* - Suffix wildcard: '*.error' matches 'user.error', 'system.error', etc.
|
|
259
|
+
* - Full wildcard: '*' matches any event
|
|
260
|
+
*
|
|
261
|
+
* @param eventName - Event name to test
|
|
262
|
+
* @param pattern - Pattern to match against
|
|
263
|
+
* @returns true if event matches pattern
|
|
264
|
+
*/
|
|
265
|
+
matchesPattern(eventName, pattern) {
|
|
266
|
+
// Exact match
|
|
267
|
+
if (eventName === pattern) {
|
|
268
|
+
return true;
|
|
269
|
+
}
|
|
270
|
+
// No wildcards, no match
|
|
271
|
+
if (!pattern.includes('*')) {
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
// Convert pattern to regex
|
|
275
|
+
const regexPattern = pattern
|
|
276
|
+
.replace(/\./g, '\\.') // Escape dots
|
|
277
|
+
.replace(/\*/g, '.*'); // Replace * with .*
|
|
278
|
+
const regex = new RegExp(`^${regexPattern}$`);
|
|
279
|
+
return regex.test(eventName);
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Deliver an event to a subscription
|
|
283
|
+
*
|
|
284
|
+
* @param subscription - Subscription to deliver to
|
|
285
|
+
* @param payload - Event payload
|
|
286
|
+
*/
|
|
287
|
+
deliverEvent(subscription, payload) {
|
|
288
|
+
try {
|
|
289
|
+
// Apply filter if provided
|
|
290
|
+
if (subscription.options?.filter && !subscription.options.filter(payload)) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
// Call the callback
|
|
294
|
+
const result = subscription.callback(payload);
|
|
295
|
+
// Handle promise if callback is async
|
|
296
|
+
if (result instanceof Promise) {
|
|
297
|
+
result.catch(error => {
|
|
298
|
+
console.error('Error in event callback:', error);
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
// Handle maxEvents option
|
|
302
|
+
if (subscription.options?.maxEvents) {
|
|
303
|
+
const currentCount = subscription._eventCount ?? 0;
|
|
304
|
+
subscription._eventCount = currentCount + 1;
|
|
305
|
+
if (subscription._eventCount >= subscription.options.maxEvents) {
|
|
306
|
+
this.unsubscribeById(subscription.id);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
catch (error) {
|
|
311
|
+
console.error('Error delivering event:', error);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Unsubscribe by subscription ID
|
|
316
|
+
*
|
|
317
|
+
* @param id - Subscription ID to remove
|
|
318
|
+
*/
|
|
319
|
+
unsubscribeById(id) {
|
|
320
|
+
for (const [pattern, subs] of this.subscriptions.entries()) {
|
|
321
|
+
for (const sub of subs) {
|
|
322
|
+
if (sub.id === id) {
|
|
323
|
+
subs.delete(sub);
|
|
324
|
+
if (subs.size === 0) {
|
|
325
|
+
this.subscriptions.delete(pattern);
|
|
326
|
+
}
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
//# sourceMappingURL=EventHub.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventHub.js","sourceRoot":"","sources":["../../src/events/EventHub.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAYH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,QAAQ;IACnB;;OAEG;IACK,MAAM,CAAS;IAEvB;;;OAGG;IACc,aAAa,GAAG,IAAI,GAAG,EAAiD,CAAC;IAE1F;;OAEG;IACK,qBAAqB,GAAG,CAAC,CAAC;IAElC;;;;OAIG;IACH,YAAY,MAAc;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;;;;;OAMG;IACH,SAAS,CAAC,SAAiB;QACzB,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;IAC1B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,SAAS,CACP,OAAqB,EACrB,QAA8B,EAC9B,OAA6B;QAE7B,mBAAmB;QACnB,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAC5C,MAAM,IAAI,SAAS,CACjB,0CAA0C,EAC1C,SAAS,CAAC,qBAAqB,EAC/B,GAAG,EACH,EAAE,OAAO,EAAE,CACZ,CAAC;QACJ,CAAC;QAED,oBAAoB;QACpB,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;YACnC,MAAM,IAAI,SAAS,CACjB,mCAAmC,EACnC,SAAS,CAAC,aAAa,EACvB,GAAG,EACH,EAAE,OAAO,EAAE,CACZ,CAAC;QACJ,CAAC;QAED,sBAAsB;QACtB,MAAM,YAAY,GAA6B;YAC7C,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,qBAAqB,EAAE;YACzC,OAAO;YACP,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AAG,IAAI,IAAI,EAAE,CAAC;gBACvB,IAAI,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;oBAClB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;oBACjB,IAAI,IAAI,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;wBACpB,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;oBACrC,CAAC;oBACD,OAAO;gBACT,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KADI Core V2
|
|
3
|
+
*
|
|
4
|
+
* Main entry point for the KADI framework.
|
|
5
|
+
* Provides a clean, typed, and intuitive API for building distributed systems.
|
|
6
|
+
*
|
|
7
|
+
* **Breaking Changes (v2.0.0)**:
|
|
8
|
+
* - Replaced Zod schemas with MCP (Model Context Protocol) JSON Schemas
|
|
9
|
+
* - Full MCP compliance with KADI extensions
|
|
10
|
+
* - See migration guide for upgrading from v1.x
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
*/
|
|
14
|
+
export { KadiClient } from './client/index.js';
|
|
15
|
+
export * as Kadi from './api/index.js';
|
|
16
|
+
export type { KadiClientConfig, KadiConfig, ServiceConfig, LoadAbilityOptions, TransportKind, AgentRole, ToolHandler, KadiTool, ToolDefinition, RegisteredTool, ToolTag, NetworkId, ToolDiscoveryQuery, ToolDiscoveryResult, McpTool, ToolAnnotations, EventCallback, EventPattern, EventPayload, UnsubscribeFunction, PublishOptions, BrokerConfig, BrokerConnection, HandshakeParams, HandshakeResult, ErrorContext } from './types/index.js';
|
|
17
|
+
export { KadiError, isKadiError, isError, ErrorCode } from './errors/index.js';
|
|
18
|
+
export { AbilityLoader, AbilityProxy } from './abilities/index.js';
|
|
19
|
+
export type { LoadedAbility } from './abilities/index.js';
|
|
20
|
+
export type { ValidationResult } from './validation/index.js';
|
|
21
|
+
export { SchemaValidator } from './validation/index.js';
|
|
22
|
+
/**
|
|
23
|
+
* Broker-specific error code subset
|
|
24
|
+
*/
|
|
25
|
+
export declare const BrokerErrorCodes: {
|
|
26
|
+
readonly SCHEMA_VALIDATION_FAILED: "SCHEMA_VALIDATION_FAILED";
|
|
27
|
+
readonly TOOL_VALIDATION_FAILED: "TOOL_VALIDATION_FAILED";
|
|
28
|
+
readonly BROKER_RESPONSE_ERROR: "BROKER_RESPONSE_ERROR";
|
|
29
|
+
readonly BROKER_TIMEOUT: "BROKER_TIMEOUT";
|
|
30
|
+
readonly BROKER_SCHEMA_COMPILATION_ERROR: "BROKER_SCHEMA_COMPILATION_ERROR";
|
|
31
|
+
readonly TOOL_NOT_FOUND: "TOOL_NOT_FOUND";
|
|
32
|
+
readonly TOOL_INVOCATION_FAILED: "TOOL_INVOCATION_FAILED";
|
|
33
|
+
readonly INVALID_INPUT: "INVALID_INPUT";
|
|
34
|
+
readonly INTERNAL_ERROR: "INTERNAL_ERROR";
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Validate tool schemas for MCP compliance
|
|
38
|
+
*
|
|
39
|
+
* @param inputSchema - Input schema
|
|
40
|
+
* @param outputSchema - Output schema (optional)
|
|
41
|
+
* @param toolName - Tool name for error messages
|
|
42
|
+
* @returns Validation result
|
|
43
|
+
*/
|
|
44
|
+
export declare function validateToolSchemas(inputSchema: Record<string, unknown>, outputSchema: Record<string, unknown> | undefined, toolName: string): {
|
|
45
|
+
valid: boolean;
|
|
46
|
+
errors: string[];
|
|
47
|
+
};
|
|
48
|
+
export { MCP_SCHEMA_VERSION, MCP_SPEC_URL, getMcpVersionInfo, buildTool, stringProp, numberProp, integerProp, booleanProp, arrayProp, objectProp, enumProp, optional } from './schemas/index.js';
|
|
49
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAG/C,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AAGvC,YAAY,EAEV,gBAAgB,EAChB,UAAU,EACV,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,SAAS,EAGT,WAAW,EACX,QAAQ,EACR,cAAc,EACd,cAAc,EACd,OAAO,EACP,SAAS,EACT,kBAAkB,EAClB,mBAAmB,EACnB,OAAO,EACP,eAAe,EAGf,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,mBAAmB,EACnB,cAAc,EAGd,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,eAAe,EAGf,YAAY,EACb,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAG/E,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACnE,YAAY,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAG1D,YAAY,EAEV,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD;;GAEG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;CAUnB,CAAC;AAEX;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,W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