@kadi.build/core 0.0.1-alpha.3 → 0.0.1-alpha.5

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.
Files changed (128) hide show
  1. package/README.md +754 -606
  2. package/dist/KadiClient.d.ts +440 -0
  3. package/dist/KadiClient.d.ts.map +1 -0
  4. package/dist/KadiClient.js +1518 -0
  5. package/dist/KadiClient.js.map +1 -0
  6. package/dist/errors/error-codes.d.ts +215 -0
  7. package/dist/errors/error-codes.d.ts.map +1 -0
  8. package/dist/errors/error-codes.js +295 -0
  9. package/dist/errors/error-codes.js.map +1 -0
  10. package/dist/index.d.ts +15 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +24 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/loadAbility.d.ts +106 -0
  15. package/dist/loadAbility.d.ts.map +1 -0
  16. package/dist/loadAbility.js +376 -0
  17. package/dist/loadAbility.js.map +1 -0
  18. package/dist/messages/BrokerMessages.d.ts +84 -0
  19. package/dist/messages/BrokerMessages.d.ts.map +1 -0
  20. package/dist/messages/BrokerMessages.js +125 -0
  21. package/dist/messages/BrokerMessages.js.map +1 -0
  22. package/dist/messages/MessageBuilder.d.ts +83 -0
  23. package/dist/messages/MessageBuilder.d.ts.map +1 -0
  24. package/dist/messages/MessageBuilder.js +144 -0
  25. package/dist/messages/MessageBuilder.js.map +1 -0
  26. package/dist/schemas/events.schemas.d.ts +177 -0
  27. package/dist/schemas/events.schemas.d.ts.map +1 -0
  28. package/dist/schemas/events.schemas.js +265 -0
  29. package/dist/schemas/events.schemas.js.map +1 -0
  30. package/dist/schemas/index.d.ts +3 -0
  31. package/dist/schemas/index.d.ts.map +1 -0
  32. package/dist/schemas/index.js +4 -0
  33. package/dist/schemas/index.js.map +1 -0
  34. package/dist/schemas/kadi.schemas.d.ts +70 -0
  35. package/dist/schemas/kadi.schemas.d.ts.map +1 -0
  36. package/dist/schemas/kadi.schemas.js +120 -0
  37. package/dist/schemas/kadi.schemas.js.map +1 -0
  38. package/dist/transports/BrokerTransport.d.ts +106 -0
  39. package/dist/transports/BrokerTransport.d.ts.map +1 -0
  40. package/dist/transports/BrokerTransport.js +177 -0
  41. package/dist/transports/BrokerTransport.js.map +1 -0
  42. package/dist/transports/NativeTransport.d.ts +82 -0
  43. package/dist/transports/NativeTransport.d.ts.map +1 -0
  44. package/dist/transports/NativeTransport.js +263 -0
  45. package/dist/transports/NativeTransport.js.map +1 -0
  46. package/dist/transports/StdioTransport.d.ts +112 -0
  47. package/dist/transports/StdioTransport.d.ts.map +1 -0
  48. package/dist/transports/StdioTransport.js +445 -0
  49. package/dist/transports/StdioTransport.js.map +1 -0
  50. package/dist/transports/Transport.d.ts +93 -0
  51. package/dist/transports/Transport.d.ts.map +1 -0
  52. package/dist/transports/Transport.js +13 -0
  53. package/dist/transports/Transport.js.map +1 -0
  54. package/dist/types/broker.d.ts +31 -0
  55. package/dist/types/broker.d.ts.map +1 -0
  56. package/dist/types/broker.js +6 -0
  57. package/dist/types/broker.js.map +1 -0
  58. package/dist/types/core.d.ts +139 -0
  59. package/dist/types/core.d.ts.map +1 -0
  60. package/dist/types/core.js +26 -0
  61. package/dist/types/core.js.map +1 -0
  62. package/dist/types/events.d.ts +186 -0
  63. package/dist/types/events.d.ts.map +1 -0
  64. package/dist/types/events.js +16 -0
  65. package/dist/types/events.js.map +1 -0
  66. package/dist/types/index.d.ts +9 -0
  67. package/dist/types/index.d.ts.map +1 -0
  68. package/dist/types/index.js +13 -0
  69. package/dist/types/index.js.map +1 -0
  70. package/dist/types/protocol.d.ts +160 -0
  71. package/dist/types/protocol.d.ts.map +1 -0
  72. package/dist/types/protocol.js +5 -0
  73. package/dist/types/protocol.js.map +1 -0
  74. package/dist/utils/agentUtils.d.ts +187 -0
  75. package/dist/utils/agentUtils.d.ts.map +1 -0
  76. package/dist/utils/agentUtils.js +185 -0
  77. package/dist/utils/agentUtils.js.map +1 -0
  78. package/dist/utils/commandUtils.d.ts +45 -0
  79. package/dist/utils/commandUtils.d.ts.map +1 -0
  80. package/dist/utils/commandUtils.js +145 -0
  81. package/dist/utils/commandUtils.js.map +1 -0
  82. package/dist/utils/configUtils.d.ts +55 -0
  83. package/dist/utils/configUtils.d.ts.map +1 -0
  84. package/dist/utils/configUtils.js +100 -0
  85. package/dist/utils/configUtils.js.map +1 -0
  86. package/dist/utils/logger.d.ts +59 -0
  87. package/dist/utils/logger.d.ts.map +1 -0
  88. package/dist/utils/logger.js +122 -0
  89. package/dist/utils/logger.js.map +1 -0
  90. package/dist/utils/pathUtils.d.ts +48 -0
  91. package/dist/utils/pathUtils.d.ts.map +1 -0
  92. package/dist/utils/pathUtils.js +128 -0
  93. package/dist/utils/pathUtils.js.map +1 -0
  94. package/package.json +56 -5
  95. package/agent.json +0 -18
  96. package/examples/example-abilities/echo-js/README.md +0 -131
  97. package/examples/example-abilities/echo-js/agent.json +0 -63
  98. package/examples/example-abilities/echo-js/package.json +0 -24
  99. package/examples/example-abilities/echo-js/service.js +0 -43
  100. package/examples/example-abilities/hash-go/agent.json +0 -53
  101. package/examples/example-abilities/hash-go/cmd/hash_ability/main.go +0 -340
  102. package/examples/example-abilities/hash-go/go.mod +0 -3
  103. package/examples/example-agent/abilities/echo-js/0.0.1/README.md +0 -131
  104. package/examples/example-agent/abilities/echo-js/0.0.1/agent.json +0 -63
  105. package/examples/example-agent/abilities/echo-js/0.0.1/package-lock.json +0 -93
  106. package/examples/example-agent/abilities/echo-js/0.0.1/package.json +0 -24
  107. package/examples/example-agent/abilities/echo-js/0.0.1/service.js +0 -41
  108. package/examples/example-agent/abilities/hash-go/0.0.1/agent.json +0 -53
  109. package/examples/example-agent/abilities/hash-go/0.0.1/bin/hash_ability +0 -0
  110. package/examples/example-agent/abilities/hash-go/0.0.1/cmd/hash_ability/main.go +0 -340
  111. package/examples/example-agent/abilities/hash-go/0.0.1/go.mod +0 -3
  112. package/examples/example-agent/agent.json +0 -39
  113. package/examples/example-agent/index.js +0 -102
  114. package/examples/example-agent/package-lock.json +0 -93
  115. package/examples/example-agent/package.json +0 -17
  116. package/src/KadiAbility.js +0 -478
  117. package/src/index.js +0 -65
  118. package/src/loadAbility.js +0 -1086
  119. package/src/servers/BaseRpcServer.js +0 -404
  120. package/src/servers/BrokerRpcServer.js +0 -776
  121. package/src/servers/StdioRpcServer.js +0 -360
  122. package/src/transport/BrokerMessageBuilder.js +0 -377
  123. package/src/transport/IpcMessageBuilder.js +0 -1229
  124. package/src/utils/agentUtils.js +0 -137
  125. package/src/utils/commandUtils.js +0 -64
  126. package/src/utils/configUtils.js +0 -72
  127. package/src/utils/logger.js +0 -161
  128. package/src/utils/pathUtils.js +0 -86
package/dist/index.js ADDED
@@ -0,0 +1,24 @@
1
+ // Main client export
2
+ export { KadiClient } from './KadiClient.js';
3
+ // Export logging facilities
4
+ export { createLogger, loggers, isDebugEnabled } from './utils/logger.js';
5
+ export { NativeTransport } from './transports/NativeTransport.js';
6
+ export { StdioTransport } from './transports/StdioTransport.js';
7
+ export { BrokerTransport } from './transports/BrokerTransport.js';
8
+ // Export message utilities
9
+ export { Broker, IdFactory, JsonRpcBuilder } from './messages/BrokerMessages.js';
10
+ // Export loadAbility from its own file
11
+ export { loadAbility } from './loadAbility.js';
12
+ // Export error handling system
13
+ export { KadiError, ErrorCodes, isKadiError } from './errors/error-codes.js';
14
+ // Your existing utility functions from utils files
15
+ export { getAbilityJSON, getAbilityJSONPath, getAbilitiesDir, getProjectJSON, getProjectJSONPath, getKadiCoreJSON, getKadiCoreJSONPath, getKadiJSON, getKadiJSONPath, getKadiExecPath, getKadiInstallPath, getAbilityVersionFromArray, KADI_API_URL, SEARCH_API_URL, GET_API_URL } from './utils/agentUtils.js';
16
+ export { runExecCommand, runSpawnCommand } from './utils/commandUtils.js';
17
+ export { KADI_BROKERS, KADI_BROKER_URL, getBrokerUrl, getBrokerNames, getDefaultBrokerName, setActiveBroker, getActiveBrokerName, getActiveBrokerUrl, findAbilityVersionByName } from './utils/configUtils.js';
18
+ // Note: pathUtils.js exports are internal and not typically needed by external users
19
+ // but you can add them if needed
20
+ // Export schemas for validation
21
+ export * from './schemas/index.js';
22
+ // Export all types - single source of truth for KADI protocol
23
+ export * from './types/index.js';
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAAA,qBAAqB;AACrB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,4BAA4B;AAC5B,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAI1E,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAElE,2BAA2B;AAC3B,OAAO,EACL,MAAM,EACN,SAAS,EACT,cAAc,EACf,MAAM,8BAA8B,CAAC;AAEtC,uCAAuC;AACvC,OAAO,EAAE,WAAW,EAAiB,MAAM,kBAAkB,CAAC;AAE9D,+BAA+B;AAC/B,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE7E,mDAAmD;AACnD,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,mBAAmB,EACnB,WAAW,EACX,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,0BAA0B,EAC1B,YAAY,EACZ,cAAc,EACd,WAAW,EACZ,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1E,OAAO,EACL,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,cAAc,EACd,oBAAoB,EACpB,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,wBAAwB,EACzB,MAAM,wBAAwB,CAAC;AAEhC,qFAAqF;AACrF,iCAAiC;AAEjC,gCAAgC;AAChC,cAAc,oBAAoB,CAAC;AAEnC,8DAA8D;AAC9D,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,106 @@
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 (standalone function)
28
+ *
29
+ * This is the core ability loading function that does the actual work. It's designed
30
+ * as a standalone function for maximum flexibility - you can use it directly without
31
+ * needing a KadiClient instance.
32
+ *
33
+ * Why standalone? This design allows:
34
+ * - Simple ability loading without full KadiClient setup
35
+ * - Use in lightweight scripts or utilities
36
+ * - Direct control over all options without client configuration interference
37
+ * - Testing and debugging individual ability loading scenarios
38
+ *
39
+ * The KadiClient.loadAbility() method is a convenient wrapper that calls this
40
+ * function after resolving broker names from the client's configuration.
41
+ *
42
+ * @param nameOrPath - Which ability to load. Can be:
43
+ * - "ability-name" - loads from your installed abilities folder
44
+ * - "/absolute/path/to/ability" - loads from a specific directory path
45
+ *
46
+ * @param protocol - How to connect to the ability:
47
+ * - 'native': Load directly into this process (fastest, JavaScript/TypeScript only)
48
+ * - 'stdio': Spawn as child process, communicate via stdin/stdout (any language)
49
+ * - 'broker': Connect via broker WebSocket (ability runs anywhere, most flexible)
50
+ *
51
+ * @param options - Protocol-specific configuration:
52
+ *
53
+ * existingClient: KadiClient instance to reuse (broker protocol only).
54
+ * Used internally when called from KadiClient.loadAbility() to reuse connections.
55
+ *
56
+ * brokerUrl: Direct WebSocket URL (broker protocol only).
57
+ * Example: 'ws://localhost:8080', 'wss://broker.company.com'
58
+ * Must be provided when using broker protocol without existingClient.
59
+ *
60
+ * brokerName: Human-readable name for the broker (broker protocol only).
61
+ * Used for logging and identification purposes.
62
+ *
63
+ * spawnAbility: Whether to start the ability process first (broker protocol only).
64
+ * - true: Start the ability locally AND connect to it via broker
65
+ * - false (default): Just connect to an already-running ability
66
+ * Typically false in production where abilities run as separate processes.
67
+ *
68
+ * networks: Which KADI networks to search for the ability (broker protocol only).
69
+ * Example: ['global', 'team-alpha', 'production']
70
+ * Networks are like public/private rooms in the broker where clients register
71
+ * and discover each other.
72
+ * Defaults to ['global'] if not specified.
73
+ *
74
+ * @returns A proxy object that lets you call the ability's methods directly.
75
+ * The proxy automatically handles protocol communication (native imports, stdio JSON-RPC,
76
+ * or broker WebSocket messages) and presents a clean JavaScript API.
77
+ *
78
+ * @example
79
+ * // Direct ability loading without KadiClient
80
+ * import { loadAbility } from '@kadi.build/core';
81
+ *
82
+ * // Load local JavaScript ability
83
+ * const mathLib = await loadAbility('math-utils', 'native');
84
+ * const result = await mathLib.add({a: 5, b: 3});
85
+ *
86
+ * @example
87
+ * // Load cross-language ability via stdio
88
+ * const hashAbility = await loadAbility('hash-go', 'stdio');
89
+ * const digest = await hashAbility.digest({text: "hello", algo: "sha256"});
90
+ *
91
+ * @example
92
+ * // Load remote ability via direct broker connection
93
+ * const aiAbility = await loadAbility('gpt-analyzer', 'broker', {
94
+ * brokerUrl: 'wss://production-broker.company.com',
95
+ * networks: ['ai-abilities', 'production']
96
+ * });
97
+ * const analysis = await aiAbility.analyze({text: "Hello world"});
98
+ */
99
+ export declare function loadAbility(nameOrPath: string, protocol?: 'native' | 'stdio' | 'broker', options?: {
100
+ brokerUrl?: string;
101
+ brokerName?: string;
102
+ spawnAbility?: boolean;
103
+ networks?: string[];
104
+ existingClient?: any;
105
+ }): Promise<LoadedAbility>;
106
+ //# 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;AA4LD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwEG;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,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,cAAc,CAAC,EAAE,GAAG,CAAC;CACjB,GACL,OAAO,CAAC,aAAa,CAAC,CAwLxB"}
@@ -0,0 +1,376 @@
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
+ * Get list of available tools/methods
79
+ */
80
+ getTools() {
81
+ return this.transport.getMethods();
82
+ }
83
+ /**
84
+ * Discover available methods from the broker (broker protocol only)
85
+ */
86
+ async __discover(options = {}) {
87
+ if ('discoverMethods' in this.transport &&
88
+ typeof this.transport.discoverMethods === 'function') {
89
+ return this.transport.discoverMethods(options);
90
+ }
91
+ else {
92
+ throw new Error(`Method discovery not supported for ${this.transport.constructor.name} protocol`);
93
+ }
94
+ }
95
+ }
96
+ /**
97
+ * Resolve ability information from various sources
98
+ */
99
+ function resolveAbilityInfo(nameOrPath) {
100
+ // Check if it's a direct path
101
+ if (fs.existsSync(nameOrPath)) {
102
+ const stats = fs.statSync(nameOrPath);
103
+ if (stats.isDirectory()) {
104
+ return {
105
+ name: path.basename(nameOrPath),
106
+ version: '1.0.0',
107
+ dir: nameOrPath,
108
+ manifest: null
109
+ };
110
+ }
111
+ }
112
+ // Parse name@version format
113
+ const match = nameOrPath.match(/^(.+?)(?:@(.+))?$/);
114
+ if (!match) {
115
+ throw new KadiError('ABILITY_PATH_INVALID', `Invalid ability name format: ${nameOrPath}`, {
116
+ abilityName: nameOrPath
117
+ });
118
+ }
119
+ const [, name, requestedVersion] = match;
120
+ // Look for the ability in standard locations
121
+ const abilitiesDir = getAbilitiesDir();
122
+ const projectJSON = getProjectJSON();
123
+ const abilities = projectJSON?.abilities;
124
+ if (abilities && abilities[name]) {
125
+ const versions = abilities[name];
126
+ // Handle both array and string formats for versions
127
+ const version = requestedVersion ||
128
+ (Array.isArray(versions)
129
+ ? getAbilityVersionFromArray(versions, name)
130
+ : typeof versions === 'string'
131
+ ? versions
132
+ : '1.0.0');
133
+ const dir = path.join(abilitiesDir, name, version);
134
+ return {
135
+ name,
136
+ version,
137
+ dir,
138
+ manifest: getAbilityJSON(name, version)
139
+ };
140
+ }
141
+ // Check if it exists as a directory in abilities folder
142
+ const abilityDir = path.join(abilitiesDir, name);
143
+ if (fs.existsSync(abilityDir)) {
144
+ return {
145
+ name,
146
+ version: requestedVersion || '1.0.0',
147
+ dir: abilityDir,
148
+ manifest: null
149
+ };
150
+ }
151
+ throw KadiError.abilityNotFound(name);
152
+ }
153
+ /**
154
+ * Load an ability (standalone function)
155
+ *
156
+ * This is the core ability loading function that does the actual work. It's designed
157
+ * as a standalone function for maximum flexibility - you can use it directly without
158
+ * needing a KadiClient instance.
159
+ *
160
+ * Why standalone? This design allows:
161
+ * - Simple ability loading without full KadiClient setup
162
+ * - Use in lightweight scripts or utilities
163
+ * - Direct control over all options without client configuration interference
164
+ * - Testing and debugging individual ability loading scenarios
165
+ *
166
+ * The KadiClient.loadAbility() method is a convenient wrapper that calls this
167
+ * function after resolving broker names from the client's configuration.
168
+ *
169
+ * @param nameOrPath - Which ability to load. Can be:
170
+ * - "ability-name" - loads from your installed abilities folder
171
+ * - "/absolute/path/to/ability" - loads from a specific directory path
172
+ *
173
+ * @param protocol - How to connect to the ability:
174
+ * - 'native': Load directly into this process (fastest, JavaScript/TypeScript only)
175
+ * - 'stdio': Spawn as child process, communicate via stdin/stdout (any language)
176
+ * - 'broker': Connect via broker WebSocket (ability runs anywhere, most flexible)
177
+ *
178
+ * @param options - Protocol-specific configuration:
179
+ *
180
+ * existingClient: KadiClient instance to reuse (broker protocol only).
181
+ * Used internally when called from KadiClient.loadAbility() to reuse connections.
182
+ *
183
+ * brokerUrl: Direct WebSocket URL (broker protocol only).
184
+ * Example: 'ws://localhost:8080', 'wss://broker.company.com'
185
+ * Must be provided when using broker protocol without existingClient.
186
+ *
187
+ * brokerName: Human-readable name for the broker (broker protocol only).
188
+ * Used for logging and identification purposes.
189
+ *
190
+ * spawnAbility: Whether to start the ability process first (broker protocol only).
191
+ * - true: Start the ability locally AND connect to it via broker
192
+ * - false (default): Just connect to an already-running ability
193
+ * Typically false in production where abilities run as separate processes.
194
+ *
195
+ * networks: Which KADI networks to search for the ability (broker protocol only).
196
+ * Example: ['global', 'team-alpha', 'production']
197
+ * Networks are like public/private rooms in the broker where clients register
198
+ * and discover each other.
199
+ * Defaults to ['global'] if not specified.
200
+ *
201
+ * @returns A proxy object that lets you call the ability's methods directly.
202
+ * The proxy automatically handles protocol communication (native imports, stdio JSON-RPC,
203
+ * or broker WebSocket messages) and presents a clean JavaScript API.
204
+ *
205
+ * @example
206
+ * // Direct ability loading without KadiClient
207
+ * import { loadAbility } from '@kadi.build/core';
208
+ *
209
+ * // Load local JavaScript ability
210
+ * const mathLib = await loadAbility('math-utils', 'native');
211
+ * const result = await mathLib.add({a: 5, b: 3});
212
+ *
213
+ * @example
214
+ * // Load cross-language ability via stdio
215
+ * const hashAbility = await loadAbility('hash-go', 'stdio');
216
+ * const digest = await hashAbility.digest({text: "hello", algo: "sha256"});
217
+ *
218
+ * @example
219
+ * // Load remote ability via direct broker connection
220
+ * const aiAbility = await loadAbility('gpt-analyzer', 'broker', {
221
+ * brokerUrl: 'wss://production-broker.company.com',
222
+ * networks: ['ai-abilities', 'production']
223
+ * });
224
+ * const analysis = await aiAbility.analyze({text: "Hello world"});
225
+ */
226
+ export async function loadAbility(nameOrPath, protocol = 'native', options = {}) {
227
+ logger.lifecycle('loadAbility', `Loading ability: ${nameOrPath}`);
228
+ if (protocol !== 'native' && protocol !== 'stdio' && protocol !== 'broker') {
229
+ throw new KadiError('PROTOCOL_UNSUPPORTED', `Protocol '${protocol}' not yet supported. Available: 'native', 'stdio', 'broker'`, {
230
+ protocol,
231
+ abilityName: nameOrPath
232
+ });
233
+ }
234
+ // For broker protocol without spawning, we don't need local ability files
235
+ // The name is just a label for which agent's tools we want to access
236
+ let name, version, abilityDir, manifest;
237
+ if (protocol === 'broker' && !options.spawnAbility) {
238
+ // Just connecting as a client - no local files needed
239
+ name = nameOrPath;
240
+ version = '1.0.0'; // Version doesn't matter for client-only
241
+ abilityDir = null;
242
+ manifest = null; // The agent.json. TODO: Rename this variable later
243
+ logger.info('Broker client mode', {
244
+ targetAgent: name,
245
+ protocol,
246
+ brokerUrl: options.brokerUrl
247
+ });
248
+ }
249
+ else {
250
+ // Need local ability files for native, stdio, or broker with spawning
251
+ const resolved = resolveAbilityInfo(nameOrPath);
252
+ name = resolved.name;
253
+ version = resolved.version;
254
+ abilityDir = resolved.dir;
255
+ manifest = resolved.manifest;
256
+ logger.info('Resolved ability', {
257
+ name,
258
+ version,
259
+ dir: abilityDir,
260
+ protocol
261
+ });
262
+ }
263
+ // Create transport based on protocol
264
+ let transport;
265
+ if (protocol === 'native') {
266
+ if (!abilityDir) {
267
+ throw new KadiError('ABILITY_LOAD_FAILED', 'Native protocol requires local ability files', {
268
+ protocol: 'native',
269
+ abilityName: name
270
+ });
271
+ }
272
+ transport = new NativeTransport({
273
+ abilityName: name,
274
+ abilityVersion: version,
275
+ abilityDir,
276
+ manifest
277
+ });
278
+ }
279
+ else if (protocol === 'stdio') {
280
+ if (!abilityDir) {
281
+ throw new KadiError('ABILITY_LOAD_FAILED', 'Stdio protocol requires local ability files', {
282
+ protocol: 'stdio',
283
+ abilityName: name
284
+ });
285
+ }
286
+ // For stdio, get start command from agent.json
287
+ let startCmd = 'node ability.js'; // fallback default
288
+ if (manifest && manifest.scripts?.start) {
289
+ startCmd = manifest.scripts.start;
290
+ }
291
+ transport = new StdioTransport({
292
+ abilityName: name,
293
+ abilityVersion: version,
294
+ abilityDir,
295
+ startCmd,
296
+ manifest
297
+ });
298
+ }
299
+ else if (protocol === 'broker') {
300
+ // For broker protocol, get broker URL and other settings
301
+ const brokerUrl = options.brokerUrl || 'ws://localhost:8080';
302
+ // Get start command for optional spawning
303
+ let startCmd = 'node ability.js'; // fallback default
304
+ if (manifest && manifest.scripts?.start) {
305
+ startCmd = manifest.scripts.start;
306
+ }
307
+ // Get networks from options or default
308
+ const networks = options.networks || ['global'];
309
+ transport = new BrokerTransport({
310
+ targetAgent: name, // The remote agent we want to call
311
+ abilityName: name,
312
+ abilityVersion: version,
313
+ existingClient: options.existingClient, // Reuse existing client if provided
314
+ brokerUrl,
315
+ brokerName: options.brokerName,
316
+ networks,
317
+ spawnAbility: options.spawnAbility || false
318
+ });
319
+ }
320
+ else {
321
+ throw new KadiError('PROTOCOL_UNSUPPORTED', `Unsupported protocol: ${protocol}`, {
322
+ protocol,
323
+ abilityName: name
324
+ });
325
+ }
326
+ // Connect
327
+ try {
328
+ await transport.connect();
329
+ }
330
+ catch (error) {
331
+ if (error instanceof KadiError) {
332
+ throw error; // Re-throw KadiErrors as-is
333
+ }
334
+ // For broker protocol, connection errors should be treated
335
+ // as broker connection failures
336
+ if (protocol === 'broker') {
337
+ throw KadiError.brokerUnavailable(options.brokerUrl || 'ws://localhost:8080', error);
338
+ }
339
+ // For other protocols, wrap in generic ability load failure
340
+ throw KadiError.fromError(error, 'ABILITY_LOAD_FAILED', {
341
+ protocol,
342
+ abilityName: name,
343
+ abilityVersion: version
344
+ });
345
+ }
346
+ logger.info('Loaded ability', name);
347
+ // Create and return proxy
348
+ const proxy = new AbilityProxy(name, transport);
349
+ // Use a JavaScript Proxy to intercept any method calls and relay them
350
+ return new Proxy(proxy, {
351
+ get(target, prop, receiver) {
352
+ // If the property exists on the target, return it
353
+ if (prop in target) {
354
+ return Reflect.get(target, prop, receiver);
355
+ }
356
+ // Avoid being treated as a Promise/thenable
357
+ if (prop === 'then')
358
+ return undefined;
359
+ // If it's a string and looks like a method name, create a method proxy
360
+ if (typeof prop === 'string' && !prop.startsWith('_')) {
361
+ return async (params) => {
362
+ try {
363
+ return await target.__call(prop, params);
364
+ }
365
+ catch (error) {
366
+ throw new Error(`Failed to call method '${prop}' on ability '${name}'.\n` +
367
+ `Original error: ${error instanceof Error ? error.message : String(error)}\n` +
368
+ `Check if the method name is correct.`);
369
+ }
370
+ };
371
+ }
372
+ return undefined;
373
+ }
374
+ });
375
+ }
376
+ //# sourceMappingURL=loadAbility.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadAbility.js","sourceRoot":"","sources":["../src/loadAbility.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAElE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EACL,cAAc,EACd,eAAe,EACf,0BAA0B,EAC1B,cAAc,EACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,MAAM,MAAM,GAAG,qBAAqB,CAAC,aAAa,CAAC,CAAC;AAsBpD;;GAEG;AACH,MAAM,YAAa,SAAQ,YAAY;IAK3B;IACA;IAJH,MAAM,CAAgB;IAE7B,YACU,IAAY,EAC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AAE,CAAC;gBACtD,OAAO,KAAK,EAAE,MAAW,EAAE,EAAE;oBAC3B,IAAI,CAAC;wBACH,OAAO,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;oBAC3C,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBACf,MAAM,IAAI,KAAK,CACb,0BAA0B,IAAI,iBAAiB,IAAI,MAAM;4BACvD,mBAAmB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI;4BAC7E,sCAAsC,CACzC,CAAC;oBACJ,CAAC;gBACH,CAAC,CAAC;YACJ,CAAC;YAED,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;;;;;;;;;;;;;;;;;;;;;;CAiCf,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;I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