@kadi.build/core 0.0.1-alpha.3 → 0.0.1-alpha.4
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 +571 -594
- package/dist/KadiClient.d.ts +303 -0
- package/dist/KadiClient.d.ts.map +1 -0
- package/dist/KadiClient.js +1162 -0
- package/dist/KadiClient.js.map +1 -0
- package/dist/errors/error-codes.d.ts +215 -0
- package/dist/errors/error-codes.d.ts.map +1 -0
- package/dist/errors/error-codes.js +295 -0
- package/dist/errors/error-codes.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/loadAbility.d.ts +65 -0
- package/dist/loadAbility.d.ts.map +1 -0
- package/dist/loadAbility.js +335 -0
- package/dist/loadAbility.js.map +1 -0
- package/dist/messages/BrokerMessages.d.ts +84 -0
- package/dist/messages/BrokerMessages.d.ts.map +1 -0
- package/dist/messages/BrokerMessages.js +127 -0
- package/dist/messages/BrokerMessages.js.map +1 -0
- package/dist/messages/MessageBuilder.d.ts +83 -0
- package/dist/messages/MessageBuilder.d.ts.map +1 -0
- package/dist/messages/MessageBuilder.js +144 -0
- package/dist/messages/MessageBuilder.js.map +1 -0
- package/dist/schemas/events.schemas.d.ts +177 -0
- package/dist/schemas/events.schemas.d.ts.map +1 -0
- package/dist/schemas/events.schemas.js +265 -0
- package/dist/schemas/events.schemas.js.map +1 -0
- package/dist/schemas/index.d.ts +3 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +4 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/kadi.schemas.d.ts +70 -0
- package/dist/schemas/kadi.schemas.d.ts.map +1 -0
- package/dist/schemas/kadi.schemas.js +120 -0
- package/dist/schemas/kadi.schemas.js.map +1 -0
- package/dist/transports/BrokerTransport.d.ts +96 -0
- package/dist/transports/BrokerTransport.d.ts.map +1 -0
- package/dist/transports/BrokerTransport.js +145 -0
- package/dist/transports/BrokerTransport.js.map +1 -0
- package/dist/transports/NativeTransport.d.ts +92 -0
- package/dist/transports/NativeTransport.d.ts.map +1 -0
- package/dist/transports/NativeTransport.js +221 -0
- package/dist/transports/NativeTransport.js.map +1 -0
- package/dist/transports/StdioTransport.d.ts +112 -0
- package/dist/transports/StdioTransport.d.ts.map +1 -0
- package/dist/transports/StdioTransport.js +440 -0
- package/dist/transports/StdioTransport.js.map +1 -0
- package/dist/transports/Transport.d.ts +93 -0
- package/dist/transports/Transport.d.ts.map +1 -0
- package/dist/transports/Transport.js +13 -0
- package/dist/transports/Transport.js.map +1 -0
- package/dist/types/broker.d.ts +31 -0
- package/dist/types/broker.d.ts.map +1 -0
- package/dist/types/broker.js +6 -0
- package/dist/types/broker.js.map +1 -0
- package/dist/types/core.d.ts +138 -0
- package/dist/types/core.d.ts.map +1 -0
- package/dist/types/core.js +26 -0
- package/dist/types/core.js.map +1 -0
- package/dist/types/events.d.ts +186 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +16 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +13 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/protocol.d.ts +160 -0
- package/dist/types/protocol.d.ts.map +1 -0
- package/dist/types/protocol.js +5 -0
- package/dist/types/protocol.js.map +1 -0
- package/dist/utils/agentUtils.d.ts +102 -0
- package/dist/utils/agentUtils.d.ts.map +1 -0
- package/dist/utils/agentUtils.js +166 -0
- package/dist/utils/agentUtils.js.map +1 -0
- package/dist/utils/commandUtils.d.ts +45 -0
- package/dist/utils/commandUtils.d.ts.map +1 -0
- package/dist/utils/commandUtils.js +145 -0
- package/dist/utils/commandUtils.js.map +1 -0
- package/dist/utils/configUtils.d.ts +55 -0
- package/dist/utils/configUtils.d.ts.map +1 -0
- package/dist/utils/configUtils.js +100 -0
- package/dist/utils/configUtils.js.map +1 -0
- package/dist/utils/logger.d.ts +59 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +122 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/pathUtils.d.ts +48 -0
- package/dist/utils/pathUtils.d.ts.map +1 -0
- package/dist/utils/pathUtils.js +128 -0
- package/dist/utils/pathUtils.js.map +1 -0
- package/package.json +56 -5
- package/agent.json +0 -18
- package/examples/example-abilities/echo-js/README.md +0 -131
- package/examples/example-abilities/echo-js/agent.json +0 -63
- package/examples/example-abilities/echo-js/package.json +0 -24
- package/examples/example-abilities/echo-js/service.js +0 -43
- package/examples/example-abilities/hash-go/agent.json +0 -53
- package/examples/example-abilities/hash-go/cmd/hash_ability/main.go +0 -340
- package/examples/example-abilities/hash-go/go.mod +0 -3
- package/examples/example-agent/abilities/echo-js/0.0.1/README.md +0 -131
- package/examples/example-agent/abilities/echo-js/0.0.1/agent.json +0 -63
- package/examples/example-agent/abilities/echo-js/0.0.1/package-lock.json +0 -93
- package/examples/example-agent/abilities/echo-js/0.0.1/package.json +0 -24
- package/examples/example-agent/abilities/echo-js/0.0.1/service.js +0 -41
- package/examples/example-agent/abilities/hash-go/0.0.1/agent.json +0 -53
- package/examples/example-agent/abilities/hash-go/0.0.1/bin/hash_ability +0 -0
- package/examples/example-agent/abilities/hash-go/0.0.1/cmd/hash_ability/main.go +0 -340
- package/examples/example-agent/abilities/hash-go/0.0.1/go.mod +0 -3
- package/examples/example-agent/agent.json +0 -39
- package/examples/example-agent/index.js +0 -102
- package/examples/example-agent/package-lock.json +0 -93
- package/examples/example-agent/package.json +0 -17
- package/src/KadiAbility.js +0 -478
- package/src/index.js +0 -65
- package/src/loadAbility.js +0 -1086
- package/src/servers/BaseRpcServer.js +0 -404
- package/src/servers/BrokerRpcServer.js +0 -776
- package/src/servers/StdioRpcServer.js +0 -360
- package/src/transport/BrokerMessageBuilder.js +0 -377
- package/src/transport/IpcMessageBuilder.js +0 -1229
- package/src/utils/agentUtils.js +0 -137
- package/src/utils/commandUtils.js +0 -64
- package/src/utils/configUtils.js +0 -72
- package/src/utils/logger.js +0 -161
- package/src/utils/pathUtils.js +0 -86
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Load an ability using the specified protocol
|
|
3
|
+
*
|
|
4
|
+
* Simplified implementation that focuses on the native protocol for now.
|
|
5
|
+
* Stdio and broker support can be added back as needed.
|
|
6
|
+
*/
|
|
7
|
+
import { EventEmitter } from 'events';
|
|
8
|
+
export interface AbilityEvents extends EventEmitter {
|
|
9
|
+
on(event: string, listener: (...args: any[]) => void): this;
|
|
10
|
+
emit(event: string, ...args: any[]): boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface LoadedAbility extends EventEmitter {
|
|
13
|
+
events: AbilityEvents;
|
|
14
|
+
__call(method: string, params: any): Promise<any>;
|
|
15
|
+
__schema(method: string): {
|
|
16
|
+
inputSchema?: any;
|
|
17
|
+
outputSchema?: any;
|
|
18
|
+
} | undefined;
|
|
19
|
+
__disconnect(): Promise<void>;
|
|
20
|
+
__discover?(options: {
|
|
21
|
+
networks?: string[];
|
|
22
|
+
includeProviders?: boolean;
|
|
23
|
+
}): Promise<any[]>;
|
|
24
|
+
[methodName: string]: any;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Load an ability
|
|
28
|
+
*
|
|
29
|
+
* @param nameOrPath - Ability name, name@version, or direct path
|
|
30
|
+
* @param protocol - Protocol to use: 'native', 'stdio', or 'broker'
|
|
31
|
+
* @param options - Protocol-specific options
|
|
32
|
+
* @param options.brokerUrl - Broker WebSocket URL (broker protocol only)
|
|
33
|
+
* @param options.spawnAbility - Whether to spawn the ability process (broker/stdio protocols)
|
|
34
|
+
* @param options.networks - Networks to access (broker protocol only)
|
|
35
|
+
* @returns Ability proxy object with callable methods
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* Native protocol (in-process)
|
|
39
|
+
* const ability = await loadAbility('echo-js', 'native');
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* Stdio protocol (child process)
|
|
43
|
+
* const ability = await loadAbility('echo-js', 'stdio');
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* Broker protocol (assumes ability already running on broker)
|
|
47
|
+
* const ability = await loadAbility('math/multiply@1.0', 'broker', {
|
|
48
|
+
* brokerUrl: 'ws://localhost:8080',
|
|
49
|
+
* networks: ['global']
|
|
50
|
+
* });
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* Broker protocol with spawning (spawn ability + connect as client)
|
|
54
|
+
* const ability = await loadAbility('echo-js', 'broker', {
|
|
55
|
+
* brokerUrl: 'ws://localhost:8080',
|
|
56
|
+
* spawnAbility: true,
|
|
57
|
+
* networks: ['global', 'team-alpha']
|
|
58
|
+
* });
|
|
59
|
+
*/
|
|
60
|
+
export declare function loadAbility(nameOrPath: string, protocol?: 'native' | 'stdio' | 'broker', options?: {
|
|
61
|
+
brokerUrl?: string;
|
|
62
|
+
spawnAbility?: boolean;
|
|
63
|
+
networks?: string[];
|
|
64
|
+
}): Promise<LoadedAbility>;
|
|
65
|
+
//# sourceMappingURL=loadAbility.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadAbility.d.ts","sourceRoot":"","sources":["../src/loadAbility.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAiBtC,MAAM,WAAW,aAAc,SAAQ,YAAY;IACjD,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI,CAAC;IAC5D,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;CAC9C;AAED,MAAM,WAAW,aAAc,SAAQ,YAAY;IACjD,MAAM,EAAE,aAAa,CAAC;IACtB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAClD,QAAQ,CACN,MAAM,EAAE,MAAM,GACb;QAAE,WAAW,CAAC,EAAE,GAAG,CAAC;QAAC,YAAY,CAAC,EAAE,GAAG,CAAA;KAAE,GAAG,SAAS,CAAC;IACzD,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,UAAU,CAAC,CAAC,OAAO,EAAE;QACnB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;QACpB,gBAAgB,CAAC,EAAE,OAAO,CAAC;KAC5B,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACnB,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG,CAAC;CAC3B;AAqLD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAsB,WAAW,CAC/B,UAAU,EAAE,MAAM,EAClB,QAAQ,GAAE,QAAQ,GAAG,OAAO,GAAG,QAAmB,EAClD,OAAO,GAAE;IACP,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CAChB,GACL,OAAO,CAAC,aAAa,CAAC,CA0LxB"}
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Load an ability using the specified protocol
|
|
3
|
+
*
|
|
4
|
+
* Simplified implementation that focuses on the native protocol for now.
|
|
5
|
+
* Stdio and broker support can be added back as needed.
|
|
6
|
+
*/
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import fs from 'node:fs';
|
|
9
|
+
import { EventEmitter } from 'events';
|
|
10
|
+
import { NativeTransport } from './transports/NativeTransport.js';
|
|
11
|
+
import { StdioTransport } from './transports/StdioTransport.js';
|
|
12
|
+
import { BrokerTransport } from './transports/BrokerTransport.js';
|
|
13
|
+
import { createComponentLogger } from './utils/logger.js';
|
|
14
|
+
import { getAbilityJSON, getAbilitiesDir, getAbilityVersionFromArray, getProjectJSON } from './utils/agentUtils.js';
|
|
15
|
+
import { KadiError } from './errors/error-codes.js';
|
|
16
|
+
const logger = createComponentLogger('loadAbility');
|
|
17
|
+
/**
|
|
18
|
+
* Proxy object that provides method access to abilities
|
|
19
|
+
*/
|
|
20
|
+
class AbilityProxy extends EventEmitter {
|
|
21
|
+
name;
|
|
22
|
+
transport;
|
|
23
|
+
events;
|
|
24
|
+
constructor(name, transport) {
|
|
25
|
+
super();
|
|
26
|
+
this.name = name;
|
|
27
|
+
this.transport = transport;
|
|
28
|
+
// Create events emitter for compatibility with examples
|
|
29
|
+
this.events = new EventEmitter();
|
|
30
|
+
// Forward events from transport if it supports them
|
|
31
|
+
try {
|
|
32
|
+
if (transport && typeof transport.on === 'function') {
|
|
33
|
+
logger.trace('AbilityProxy', `Setting up transport event listener for ${name}`);
|
|
34
|
+
transport.on('event', (eventData) => {
|
|
35
|
+
logger.trace('AbilityProxy', `Received event from transport: ${JSON.stringify(eventData)}`);
|
|
36
|
+
this.emit('event', eventData);
|
|
37
|
+
this.events.emit('event', eventData);
|
|
38
|
+
if (eventData.name) {
|
|
39
|
+
logger.debug('AbilityProxy', `Emitting specific event: ${eventData.name}`);
|
|
40
|
+
this.emit(eventData.name, eventData.data);
|
|
41
|
+
this.events.emit(eventData.name, eventData.data);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
logger.debug('AbilityProxy', `Transport doesn't support .on() method for ${name}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
// Handler doesn't support events, that's ok
|
|
51
|
+
logger.debug('AbilityProxy', `Error setting up event listener for ${name}: ${e}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async __call(method, params) {
|
|
55
|
+
return this.transport.invoke(method, params);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get schema for a specific method (for TypeScript types)
|
|
59
|
+
*/
|
|
60
|
+
__schema(method) {
|
|
61
|
+
if ('getMethodSchema' in this.transport &&
|
|
62
|
+
typeof this.transport.getMethodSchema === 'function') {
|
|
63
|
+
const schema = this.transport.getMethodSchema(method);
|
|
64
|
+
if (schema) {
|
|
65
|
+
// Convert from handler's format to expected format
|
|
66
|
+
return {
|
|
67
|
+
inputSchema: schema.input || schema.inputSchema,
|
|
68
|
+
outputSchema: schema.output || schema.outputSchema
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
async __disconnect() {
|
|
75
|
+
await this.transport.disconnect();
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Discover available methods from the broker (broker protocol only)
|
|
79
|
+
*/
|
|
80
|
+
async __discover(options = {}) {
|
|
81
|
+
if ('discoverMethods' in this.transport &&
|
|
82
|
+
typeof this.transport.discoverMethods === 'function') {
|
|
83
|
+
return this.transport.discoverMethods(options);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
throw new Error(`Method discovery not supported for ${this.transport.constructor.name} protocol`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Resolve ability information from various sources
|
|
92
|
+
*/
|
|
93
|
+
function resolveAbilityInfo(nameOrPath) {
|
|
94
|
+
// Check if it's a direct path
|
|
95
|
+
if (fs.existsSync(nameOrPath)) {
|
|
96
|
+
const stats = fs.statSync(nameOrPath);
|
|
97
|
+
if (stats.isDirectory()) {
|
|
98
|
+
return {
|
|
99
|
+
name: path.basename(nameOrPath),
|
|
100
|
+
version: '1.0.0',
|
|
101
|
+
dir: nameOrPath,
|
|
102
|
+
manifest: null
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Parse name@version format
|
|
107
|
+
const match = nameOrPath.match(/^(.+?)(?:@(.+))?$/);
|
|
108
|
+
if (!match) {
|
|
109
|
+
throw new KadiError('ABILITY_PATH_INVALID', `Invalid ability name format: ${nameOrPath}`, {
|
|
110
|
+
abilityName: nameOrPath
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
const [, name, requestedVersion] = match;
|
|
114
|
+
// Look for the ability in standard locations
|
|
115
|
+
const abilitiesDir = getAbilitiesDir();
|
|
116
|
+
const projectJSON = getProjectJSON();
|
|
117
|
+
const abilities = projectJSON?.abilities;
|
|
118
|
+
if (abilities && abilities[name]) {
|
|
119
|
+
const versions = abilities[name];
|
|
120
|
+
// Handle both array and string formats for versions
|
|
121
|
+
const version = requestedVersion ||
|
|
122
|
+
(Array.isArray(versions)
|
|
123
|
+
? getAbilityVersionFromArray(versions, name)
|
|
124
|
+
: typeof versions === 'string'
|
|
125
|
+
? versions
|
|
126
|
+
: '1.0.0');
|
|
127
|
+
const dir = path.join(abilitiesDir, name, version);
|
|
128
|
+
return {
|
|
129
|
+
name,
|
|
130
|
+
version,
|
|
131
|
+
dir,
|
|
132
|
+
manifest: getAbilityJSON(name, version)
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
// Check if it exists as a directory in abilities folder
|
|
136
|
+
const abilityDir = path.join(abilitiesDir, name);
|
|
137
|
+
if (fs.existsSync(abilityDir)) {
|
|
138
|
+
return {
|
|
139
|
+
name,
|
|
140
|
+
version: requestedVersion || '1.0.0',
|
|
141
|
+
dir: abilityDir,
|
|
142
|
+
manifest: null
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
throw KadiError.abilityNotFound(name);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Load an ability
|
|
149
|
+
*
|
|
150
|
+
* @param nameOrPath - Ability name, name@version, or direct path
|
|
151
|
+
* @param protocol - Protocol to use: 'native', 'stdio', or 'broker'
|
|
152
|
+
* @param options - Protocol-specific options
|
|
153
|
+
* @param options.brokerUrl - Broker WebSocket URL (broker protocol only)
|
|
154
|
+
* @param options.spawnAbility - Whether to spawn the ability process (broker/stdio protocols)
|
|
155
|
+
* @param options.networks - Networks to access (broker protocol only)
|
|
156
|
+
* @returns Ability proxy object with callable methods
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* Native protocol (in-process)
|
|
160
|
+
* const ability = await loadAbility('echo-js', 'native');
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* Stdio protocol (child process)
|
|
164
|
+
* const ability = await loadAbility('echo-js', 'stdio');
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* Broker protocol (assumes ability already running on broker)
|
|
168
|
+
* const ability = await loadAbility('math/multiply@1.0', 'broker', {
|
|
169
|
+
* brokerUrl: 'ws://localhost:8080',
|
|
170
|
+
* networks: ['global']
|
|
171
|
+
* });
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* Broker protocol with spawning (spawn ability + connect as client)
|
|
175
|
+
* const ability = await loadAbility('echo-js', 'broker', {
|
|
176
|
+
* brokerUrl: 'ws://localhost:8080',
|
|
177
|
+
* spawnAbility: true,
|
|
178
|
+
* networks: ['global', 'team-alpha']
|
|
179
|
+
* });
|
|
180
|
+
*/
|
|
181
|
+
export async function loadAbility(nameOrPath, protocol = 'native', options = {}) {
|
|
182
|
+
logger.lifecycle('loadAbility', `Loading ability: ${nameOrPath}`);
|
|
183
|
+
if (protocol !== 'native' && protocol !== 'stdio' && protocol !== 'broker') {
|
|
184
|
+
throw new KadiError('PROTOCOL_UNSUPPORTED', `Protocol '${protocol}' not yet supported. Available: 'native', 'stdio', 'broker'`, {
|
|
185
|
+
protocol,
|
|
186
|
+
abilityName: nameOrPath
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
// For broker protocol without spawning, we don't need local ability files
|
|
190
|
+
// The name is just a label for which agent's tools we want to access
|
|
191
|
+
let name, version, abilityDir, manifest;
|
|
192
|
+
if (protocol === 'broker' && !options.spawnAbility) {
|
|
193
|
+
// Just connecting as a client - no local files needed
|
|
194
|
+
name = nameOrPath;
|
|
195
|
+
version = '1.0.0'; // Version doesn't matter for client-only
|
|
196
|
+
abilityDir = null;
|
|
197
|
+
manifest = null;
|
|
198
|
+
logger.info('Broker client mode', {
|
|
199
|
+
targetAgent: name,
|
|
200
|
+
protocol,
|
|
201
|
+
brokerUrl: options.brokerUrl
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
// Need local ability files for native, stdio, or broker with spawning
|
|
206
|
+
const resolved = resolveAbilityInfo(nameOrPath);
|
|
207
|
+
name = resolved.name;
|
|
208
|
+
version = resolved.version;
|
|
209
|
+
abilityDir = resolved.dir;
|
|
210
|
+
manifest = resolved.manifest;
|
|
211
|
+
logger.info('Resolved ability', {
|
|
212
|
+
name,
|
|
213
|
+
version,
|
|
214
|
+
dir: abilityDir,
|
|
215
|
+
protocol
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
// Create transport based on protocol
|
|
219
|
+
let transport;
|
|
220
|
+
if (protocol === 'native') {
|
|
221
|
+
if (!abilityDir) {
|
|
222
|
+
throw new KadiError('ABILITY_LOAD_FAILED', 'Native protocol requires local ability files', {
|
|
223
|
+
protocol: 'native',
|
|
224
|
+
abilityName: name
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
transport = new NativeTransport({
|
|
228
|
+
abilityName: name,
|
|
229
|
+
abilityVersion: version,
|
|
230
|
+
abilityDir,
|
|
231
|
+
manifest
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
else if (protocol === 'stdio') {
|
|
235
|
+
if (!abilityDir) {
|
|
236
|
+
throw new KadiError('ABILITY_LOAD_FAILED', 'Stdio protocol requires local ability files', {
|
|
237
|
+
protocol: 'stdio',
|
|
238
|
+
abilityName: name
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
// For stdio, get start command from agent.json
|
|
242
|
+
let startCmd = 'node service.js'; // fallback default
|
|
243
|
+
if (manifest && manifest.startCmd) {
|
|
244
|
+
startCmd = manifest.startCmd;
|
|
245
|
+
}
|
|
246
|
+
else if (manifest && manifest.interfaces?.stdio?.startCmd) {
|
|
247
|
+
startCmd = manifest.interfaces.stdio.startCmd;
|
|
248
|
+
}
|
|
249
|
+
transport = new StdioTransport({
|
|
250
|
+
abilityName: name,
|
|
251
|
+
abilityVersion: version,
|
|
252
|
+
abilityDir,
|
|
253
|
+
startCmd,
|
|
254
|
+
manifest
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
else if (protocol === 'broker') {
|
|
258
|
+
// For broker protocol, get broker URL and other settings
|
|
259
|
+
const brokerUrl = options.brokerUrl || 'ws://localhost:8080';
|
|
260
|
+
// Get start command for optional spawning
|
|
261
|
+
let startCmd = 'node service.js'; // fallback default
|
|
262
|
+
if (manifest && manifest.startCmd) {
|
|
263
|
+
startCmd = manifest.startCmd;
|
|
264
|
+
}
|
|
265
|
+
else if (manifest && manifest.interfaces?.broker?.startCmd) {
|
|
266
|
+
startCmd = manifest.interfaces.broker.startCmd;
|
|
267
|
+
}
|
|
268
|
+
// Get networks from manifest or options
|
|
269
|
+
const networks = options.networks ||
|
|
270
|
+
manifest?.interfaces?.broker?.networks || ['global'];
|
|
271
|
+
transport = new BrokerTransport({
|
|
272
|
+
targetAgent: name, // The remote agent we want to call
|
|
273
|
+
abilityName: name,
|
|
274
|
+
abilityVersion: version,
|
|
275
|
+
brokerUrl,
|
|
276
|
+
networks,
|
|
277
|
+
spawnAbility: options.spawnAbility || false
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
throw new KadiError('PROTOCOL_UNSUPPORTED', `Unsupported protocol: ${protocol}`, {
|
|
282
|
+
protocol,
|
|
283
|
+
abilityName: name
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
// Connect
|
|
287
|
+
try {
|
|
288
|
+
await transport.connect();
|
|
289
|
+
}
|
|
290
|
+
catch (error) {
|
|
291
|
+
if (error instanceof KadiError) {
|
|
292
|
+
throw error; // Re-throw KadiErrors as-is
|
|
293
|
+
}
|
|
294
|
+
// For broker protocol, connection errors should be treated as broker connection failures
|
|
295
|
+
if (protocol === 'broker') {
|
|
296
|
+
throw KadiError.brokerUnavailable(options.brokerUrl || 'ws://localhost:8080', error);
|
|
297
|
+
}
|
|
298
|
+
// For other protocols, wrap in generic ability load failure
|
|
299
|
+
throw KadiError.fromError(error, 'ABILITY_LOAD_FAILED', {
|
|
300
|
+
protocol,
|
|
301
|
+
abilityName: name,
|
|
302
|
+
abilityVersion: version
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
logger.info('Loaded ability', name);
|
|
306
|
+
// Create and return proxy
|
|
307
|
+
const proxy = new AbilityProxy(name, transport);
|
|
308
|
+
// Use a JavaScript Proxy to intercept any method calls and relay them
|
|
309
|
+
return new Proxy(proxy, {
|
|
310
|
+
get(target, prop, receiver) {
|
|
311
|
+
// If the property exists on the target, return it
|
|
312
|
+
if (prop in target) {
|
|
313
|
+
return Reflect.get(target, prop, receiver);
|
|
314
|
+
}
|
|
315
|
+
// Avoid being treated as a Promise/thenable
|
|
316
|
+
if (prop === 'then')
|
|
317
|
+
return undefined;
|
|
318
|
+
// If it's a string and looks like a method name, create a method proxy
|
|
319
|
+
if (typeof prop === 'string' && !prop.startsWith('_')) {
|
|
320
|
+
return async (params) => {
|
|
321
|
+
try {
|
|
322
|
+
return await target.__call(prop, params);
|
|
323
|
+
}
|
|
324
|
+
catch (error) {
|
|
325
|
+
throw new Error(`Failed to call method '${prop}' on ability '${name}'.\n` +
|
|
326
|
+
`Original error: ${error instanceof Error ? error.message : String(error)}\n` +
|
|
327
|
+
`Check if the method name is correct.`);
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
return undefined;
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
//# sourceMappingURL=loadAbility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version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OAAO,SAAS,CAAC;QACnB,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript implementation of Broker message builders
|
|
3
|
+
* Replaces the JavaScript BrokerMessageBuilder functionality
|
|
4
|
+
*/
|
|
5
|
+
import { KadiRegisterCapabilitiesParams, KadiCallAbilityParams, KadiHelloParams, KadiAuthenticateParams, KadiAbilityResultParams } from '../types/broker.js';
|
|
6
|
+
import { JsonRpcBuilder } from './MessageBuilder.js';
|
|
7
|
+
/**
|
|
8
|
+
* KADI Protocol message types (from kadi-broker)
|
|
9
|
+
*/
|
|
10
|
+
export declare const KadiMessages: {
|
|
11
|
+
readonly SESSION_HELLO: "kadi.session.hello";
|
|
12
|
+
readonly SESSION_AUTHENTICATE: "kadi.session.authenticate";
|
|
13
|
+
readonly SESSION_PING: "kadi.session.ping";
|
|
14
|
+
readonly SESSION_GOODBYE: "kadi.session.goodbye";
|
|
15
|
+
readonly AGENT_REGISTER: "kadi.agent.register";
|
|
16
|
+
readonly AGENT_UPDATE: "kadi.agent.update";
|
|
17
|
+
readonly AGENT_UNREGISTER: "kadi.agent.unregister";
|
|
18
|
+
readonly ABILITY_INVOKE: "kadi.ability.invoke";
|
|
19
|
+
readonly ABILITY_RESULT: "kadi.ability.result";
|
|
20
|
+
readonly ABILITY_QUEUED: "kadi.ability.queued";
|
|
21
|
+
readonly ABILITY_CANCEL: "kadi.ability.cancel";
|
|
22
|
+
readonly ABILITY_LIST: "kadi.ability.list";
|
|
23
|
+
readonly EVENT_SUBSCRIBE: "kadi.event.subscribe";
|
|
24
|
+
readonly EVENT_UNSUBSCRIBE: "kadi.event.unsubscribe";
|
|
25
|
+
readonly EVENT_PUBLISH: "kadi.event.publish";
|
|
26
|
+
readonly EVENT_DELIVERY: "kadi.event.delivery";
|
|
27
|
+
readonly EVENT_LIST: "kadi.event.list";
|
|
28
|
+
readonly OBSERVE_SUBSCRIBE: "kadi.observe.subscribe";
|
|
29
|
+
readonly OBSERVE_SNAPSHOT: "kadi.observe.snapshot";
|
|
30
|
+
readonly OBSERVE_EVENT: "kadi.observe.event";
|
|
31
|
+
readonly ERROR: "kadi.error";
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Broker message builder for KADI protocol messages
|
|
35
|
+
*/
|
|
36
|
+
export declare class BrokerMessageBuilder {
|
|
37
|
+
/**
|
|
38
|
+
* Create hello message
|
|
39
|
+
*/
|
|
40
|
+
static hello(params: KadiHelloParams): JsonRpcBuilder;
|
|
41
|
+
/**
|
|
42
|
+
* Create authenticate message
|
|
43
|
+
*/
|
|
44
|
+
static authenticate(params: KadiAuthenticateParams): JsonRpcBuilder;
|
|
45
|
+
/**
|
|
46
|
+
* Create registerCapabilities message (maps to AGENT_REGISTER)
|
|
47
|
+
*/
|
|
48
|
+
static registerCapabilities(params: KadiRegisterCapabilitiesParams): JsonRpcBuilder;
|
|
49
|
+
/**
|
|
50
|
+
* Create ping notification
|
|
51
|
+
*/
|
|
52
|
+
static ping(): JsonRpcBuilder;
|
|
53
|
+
/**
|
|
54
|
+
* Create listTools message (maps to ABILITY_LIST)
|
|
55
|
+
*/
|
|
56
|
+
static listTools(): JsonRpcBuilder;
|
|
57
|
+
/**
|
|
58
|
+
* Create callAbility message (maps to ABILITY_INVOKE)
|
|
59
|
+
*/
|
|
60
|
+
static callAbility(params: KadiCallAbilityParams): JsonRpcBuilder;
|
|
61
|
+
/**
|
|
62
|
+
* Create abilityResult message
|
|
63
|
+
*/
|
|
64
|
+
static abilityResult(params: KadiAbilityResultParams): JsonRpcBuilder;
|
|
65
|
+
/**
|
|
66
|
+
* Create agent register message (modern API)
|
|
67
|
+
*/
|
|
68
|
+
static agentRegister(params: KadiRegisterCapabilitiesParams): JsonRpcBuilder;
|
|
69
|
+
/**
|
|
70
|
+
* Create ability invoke message (modern API)
|
|
71
|
+
*/
|
|
72
|
+
static abilityInvoke(params: KadiCallAbilityParams): JsonRpcBuilder;
|
|
73
|
+
/**
|
|
74
|
+
* Create ability list message (modern API)
|
|
75
|
+
*/
|
|
76
|
+
static abilityList(): JsonRpcBuilder;
|
|
77
|
+
/**
|
|
78
|
+
* Create session goodbye message
|
|
79
|
+
*/
|
|
80
|
+
static goodbye(): JsonRpcBuilder;
|
|
81
|
+
}
|
|
82
|
+
export declare const Broker: typeof BrokerMessageBuilder;
|
|
83
|
+
export { IdFactory, JsonRpcBuilder } from './MessageBuilder.js';
|
|
84
|
+
//# sourceMappingURL=BrokerMessages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BrokerMessages.d.ts","sourceRoot":"","sources":["../../src/messages/BrokerMessages.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,8BAA8B,EAC9B,qBAAqB,EACrB,eAAe,EACf,sBAAsB,EACtB,uBAAuB,EACxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD;;GAEG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;CAoCf,CAAC;AAeX;;GAEG;AACH,qBAAa,oBAAoB;IAC/B;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,eAAe,GAAG,cAAc;IAIrD;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,sBAAsB,GAAG,cAAc;IAInE;;OAEG;IACH,MAAM,CAAC,oBAAoB,CACzB,MAAM,EAAE,8BAA8B,GACrC,cAAc;IAIjB;;OAEG;IACH,MAAM,CAAC,IAAI,IAAI,cAAc;IAI7B;;OAEG;IACH,MAAM,CAAC,SAAS,IAAI,cAAc;IAIlC;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,qBAAqB,GAAG,cAAc;IAIjE;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,uBAAuB,GAAG,cAAc;IAIrE;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,8BAA8B,GAAG,cAAc;IAI5E;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,qBAAqB,GAAG,cAAc;IAInE;;OAEG;IACH,MAAM,CAAC,WAAW,IAAI,cAAc;IAIpC;;OAEG;IACH,MAAM,CAAC,OAAO,IAAI,cAAc;CAGjC;AAGD,eAAO,MAAM,MAAM,6BAAuB,CAAC;AAG3C,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript implementation of Broker message builders
|
|
3
|
+
* Replaces the JavaScript BrokerMessageBuilder functionality
|
|
4
|
+
*/
|
|
5
|
+
import { JsonRpcBuilder } from './MessageBuilder.js';
|
|
6
|
+
/**
|
|
7
|
+
* KADI Protocol message types (from kadi-broker)
|
|
8
|
+
*/
|
|
9
|
+
export const KadiMessages = {
|
|
10
|
+
// Session Management
|
|
11
|
+
SESSION_HELLO: 'kadi.session.hello',
|
|
12
|
+
SESSION_AUTHENTICATE: 'kadi.session.authenticate',
|
|
13
|
+
SESSION_PING: 'kadi.session.ping',
|
|
14
|
+
SESSION_GOODBYE: 'kadi.session.goodbye',
|
|
15
|
+
// Agent Management
|
|
16
|
+
AGENT_REGISTER: 'kadi.agent.register',
|
|
17
|
+
AGENT_UPDATE: 'kadi.agent.update',
|
|
18
|
+
AGENT_UNREGISTER: 'kadi.agent.unregister',
|
|
19
|
+
// Ability Operations
|
|
20
|
+
ABILITY_INVOKE: 'kadi.ability.invoke',
|
|
21
|
+
ABILITY_RESULT: 'kadi.ability.result',
|
|
22
|
+
ABILITY_QUEUED: 'kadi.ability.queued', // Notification that request is queued
|
|
23
|
+
ABILITY_CANCEL: 'kadi.ability.cancel',
|
|
24
|
+
ABILITY_LIST: 'kadi.ability.list',
|
|
25
|
+
// Agent-side messages (from broker to agent/ability)
|
|
26
|
+
// AGENT_INVOKE removed - using ABILITY_INVOKE for all tool invocations
|
|
27
|
+
// Event System - Real-time publish-subscribe messaging
|
|
28
|
+
EVENT_SUBSCRIBE: 'kadi.event.subscribe', // Subscribe to event channels
|
|
29
|
+
EVENT_UNSUBSCRIBE: 'kadi.event.unsubscribe', // Unsubscribe from event channels
|
|
30
|
+
EVENT_PUBLISH: 'kadi.event.publish', // Publish an event to channels
|
|
31
|
+
EVENT_DELIVERY: 'kadi.event.delivery', // Notification of event delivery
|
|
32
|
+
EVENT_LIST: 'kadi.event.list', // List current subscriptions
|
|
33
|
+
// Observer Protocol
|
|
34
|
+
OBSERVE_SUBSCRIBE: 'kadi.observe.subscribe',
|
|
35
|
+
OBSERVE_SNAPSHOT: 'kadi.observe.snapshot',
|
|
36
|
+
OBSERVE_EVENT: 'kadi.observe.event',
|
|
37
|
+
// Errors
|
|
38
|
+
ERROR: 'kadi.error'
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Legacy compatibility mapping for older method names
|
|
42
|
+
*/
|
|
43
|
+
const _LegacyMethodMap = {
|
|
44
|
+
hello: KadiMessages.SESSION_HELLO,
|
|
45
|
+
authenticate: KadiMessages.SESSION_AUTHENTICATE,
|
|
46
|
+
registerCapabilities: KadiMessages.AGENT_REGISTER,
|
|
47
|
+
ping: KadiMessages.SESSION_PING,
|
|
48
|
+
listTools: KadiMessages.ABILITY_LIST,
|
|
49
|
+
callAbility: KadiMessages.ABILITY_INVOKE,
|
|
50
|
+
abilityResult: KadiMessages.ABILITY_RESULT
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Broker message builder for KADI protocol messages
|
|
54
|
+
*/
|
|
55
|
+
export class BrokerMessageBuilder {
|
|
56
|
+
/**
|
|
57
|
+
* Create hello message
|
|
58
|
+
*/
|
|
59
|
+
static hello(params) {
|
|
60
|
+
return new JsonRpcBuilder(KadiMessages.SESSION_HELLO, params);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Create authenticate message
|
|
64
|
+
*/
|
|
65
|
+
static authenticate(params) {
|
|
66
|
+
return new JsonRpcBuilder(KadiMessages.SESSION_AUTHENTICATE, params);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Create registerCapabilities message (maps to AGENT_REGISTER)
|
|
70
|
+
*/
|
|
71
|
+
static registerCapabilities(params) {
|
|
72
|
+
return new JsonRpcBuilder(KadiMessages.AGENT_REGISTER, params);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Create ping notification
|
|
76
|
+
*/
|
|
77
|
+
static ping() {
|
|
78
|
+
return new JsonRpcBuilder(KadiMessages.SESSION_PING, undefined, true);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Create listTools message (maps to ABILITY_LIST)
|
|
82
|
+
*/
|
|
83
|
+
static listTools() {
|
|
84
|
+
return new JsonRpcBuilder(KadiMessages.ABILITY_LIST);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Create callAbility message (maps to ABILITY_INVOKE)
|
|
88
|
+
*/
|
|
89
|
+
static callAbility(params) {
|
|
90
|
+
return new JsonRpcBuilder(KadiMessages.ABILITY_INVOKE, params);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Create abilityResult message
|
|
94
|
+
*/
|
|
95
|
+
static abilityResult(params) {
|
|
96
|
+
return new JsonRpcBuilder(KadiMessages.ABILITY_RESULT, params);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Create agent register message (modern API)
|
|
100
|
+
*/
|
|
101
|
+
static agentRegister(params) {
|
|
102
|
+
return new JsonRpcBuilder(KadiMessages.AGENT_REGISTER, params);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Create ability invoke message (modern API)
|
|
106
|
+
*/
|
|
107
|
+
static abilityInvoke(params) {
|
|
108
|
+
return new JsonRpcBuilder(KadiMessages.ABILITY_INVOKE, params);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Create ability list message (modern API)
|
|
112
|
+
*/
|
|
113
|
+
static abilityList() {
|
|
114
|
+
return new JsonRpcBuilder(KadiMessages.ABILITY_LIST);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Create session goodbye message
|
|
118
|
+
*/
|
|
119
|
+
static goodbye() {
|
|
120
|
+
return new JsonRpcBuilder(KadiMessages.SESSION_GOODBYE, undefined, true);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// Export as default for compatibility with existing code
|
|
124
|
+
export const Broker = BrokerMessageBuilder;
|
|
125
|
+
// Export IdFactory for compatibility
|
|
126
|
+
export { IdFactory, JsonRpcBuilder } from './MessageBuilder.js';
|
|
127
|
+
//# sourceMappingURL=BrokerMessages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BrokerMessages.js","sourceRoot":"","sources":["../../src/messages/BrokerMessages.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,qBAAqB;IACrB,aAAa,EAAE,oBAAoB;IACnC,oBAAoB,EAAE,2BAA2B;IACjD,YAAY,EAAE,mBAAmB;IACjC,eAAe,EAAE,sBAAsB;IAEvC,mBAAmB;IACnB,cAAc,EAAE,qBAAqB;IACrC,YAAY,EAAE,mBAAmB;IACjC,gBAAgB,EAAE,uBAAuB;IAEzC,qBAAqB;IACrB,cAAc,EAAE,qBAAqB;IACrC,cAAc,EAAE,qBAAqB;IACrC,cAAc,EAAE,qBAAqB,EAAE,sCAAsC;IAC7E,cAAc,EAAE,qBAAqB;IACrC,YAAY,EAAE,mBAAmB;IAEjC,qDAAqD;IACrD,uEAAuE;IAEvE,uDAAuD;IACvD,eAAe,EAAE,sBAAsB,EAAE,8BAA8B;IACvE,iBAAiB,EAAE,wBAAwB,EAAE,kCAAkC;IAC/E,aAAa,EAAE,oBAAoB,EA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