@kadi.build/core 0.0.1-alpha.1 → 0.0.1-alpha.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/README.md +361 -230
  2. package/dist/abilities/AbilityCache.d.ts +242 -0
  3. package/dist/abilities/AbilityCache.d.ts.map +1 -0
  4. package/dist/abilities/AbilityCache.js +285 -0
  5. package/dist/abilities/AbilityCache.js.map +1 -0
  6. package/dist/abilities/AbilityContext.d.ts +215 -0
  7. package/dist/abilities/AbilityContext.d.ts.map +1 -0
  8. package/dist/abilities/AbilityContext.js +36 -0
  9. package/dist/abilities/AbilityContext.js.map +1 -0
  10. package/dist/abilities/AbilityLoader.d.ts +203 -0
  11. package/dist/abilities/AbilityLoader.d.ts.map +1 -0
  12. package/dist/abilities/AbilityLoader.js +343 -0
  13. package/dist/abilities/AbilityLoader.js.map +1 -0
  14. package/dist/abilities/AbilityProxy.d.ts +496 -0
  15. package/dist/abilities/AbilityProxy.d.ts.map +1 -0
  16. package/dist/abilities/AbilityProxy.js +551 -0
  17. package/dist/abilities/AbilityProxy.js.map +1 -0
  18. package/dist/abilities/AbilityValidator.d.ts +172 -0
  19. package/dist/abilities/AbilityValidator.d.ts.map +1 -0
  20. package/dist/abilities/AbilityValidator.js +253 -0
  21. package/dist/abilities/AbilityValidator.js.map +1 -0
  22. package/dist/abilities/index.d.ts +26 -0
  23. package/dist/abilities/index.d.ts.map +1 -0
  24. package/dist/abilities/index.js +23 -0
  25. package/dist/abilities/index.js.map +1 -0
  26. package/dist/abilities/types.d.ts +223 -0
  27. package/dist/abilities/types.d.ts.map +1 -0
  28. package/dist/abilities/types.js +10 -0
  29. package/dist/abilities/types.js.map +1 -0
  30. package/dist/api/index.d.ts +92 -0
  31. package/dist/api/index.d.ts.map +1 -0
  32. package/dist/api/index.js +124 -0
  33. package/dist/api/index.js.map +1 -0
  34. package/dist/broker/BrokerConnection.d.ts +253 -0
  35. package/dist/broker/BrokerConnection.d.ts.map +1 -0
  36. package/dist/broker/BrokerConnection.js +434 -0
  37. package/dist/broker/BrokerConnection.js.map +1 -0
  38. package/dist/broker/BrokerConnectionManager.d.ts +216 -0
  39. package/dist/broker/BrokerConnectionManager.d.ts.map +1 -0
  40. package/dist/broker/BrokerConnectionManager.js +305 -0
  41. package/dist/broker/BrokerConnectionManager.js.map +1 -0
  42. package/dist/broker/BrokerProtocol.d.ts +280 -0
  43. package/dist/broker/BrokerProtocol.d.ts.map +1 -0
  44. package/dist/broker/BrokerProtocol.js +466 -0
  45. package/dist/broker/BrokerProtocol.js.map +1 -0
  46. package/dist/broker/index.d.ts +9 -0
  47. package/dist/broker/index.d.ts.map +1 -0
  48. package/dist/broker/index.js +9 -0
  49. package/dist/broker/index.js.map +1 -0
  50. package/dist/client/KadiClient.d.ts +459 -0
  51. package/dist/client/KadiClient.d.ts.map +1 -0
  52. package/dist/client/KadiClient.js +902 -0
  53. package/dist/client/KadiClient.js.map +1 -0
  54. package/dist/client/index.d.ts +7 -0
  55. package/dist/client/index.d.ts.map +1 -0
  56. package/dist/client/index.js +7 -0
  57. package/dist/client/index.js.map +1 -0
  58. package/dist/config/ConfigLoader.d.ts +138 -0
  59. package/dist/config/ConfigLoader.d.ts.map +1 -0
  60. package/dist/config/ConfigLoader.js +226 -0
  61. package/dist/config/ConfigLoader.js.map +1 -0
  62. package/dist/config/ConfigResolver.d.ts +135 -0
  63. package/dist/config/ConfigResolver.d.ts.map +1 -0
  64. package/dist/config/ConfigResolver.js +282 -0
  65. package/dist/config/ConfigResolver.js.map +1 -0
  66. package/dist/config/index.d.ts +8 -0
  67. package/dist/config/index.d.ts.map +1 -0
  68. package/dist/config/index.js +8 -0
  69. package/dist/config/index.js.map +1 -0
  70. package/dist/errors/index.d.ts +9 -0
  71. package/dist/errors/index.d.ts.map +1 -0
  72. package/dist/errors/index.js +8 -0
  73. package/dist/errors/index.js.map +1 -0
  74. package/dist/events/EventHub.d.ts +172 -0
  75. package/dist/events/EventHub.d.ts.map +1 -0
  76. package/dist/events/EventHub.js +333 -0
  77. package/dist/events/EventHub.js.map +1 -0
  78. package/dist/events/index.d.ts +7 -0
  79. package/dist/events/index.d.ts.map +1 -0
  80. package/dist/events/index.js +7 -0
  81. package/dist/events/index.js.map +1 -0
  82. package/dist/index.d.ts +50 -0
  83. package/dist/index.d.ts.map +1 -0
  84. package/dist/index.js +67 -0
  85. package/dist/index.js.map +1 -0
  86. package/dist/messages/index.d.ts +33 -0
  87. package/dist/messages/index.d.ts.map +1 -0
  88. package/dist/messages/index.js +33 -0
  89. package/dist/messages/index.js.map +1 -0
  90. package/dist/schemas/index.d.ts +22 -0
  91. package/dist/schemas/index.d.ts.map +1 -0
  92. package/dist/schemas/index.js +27 -0
  93. package/dist/schemas/index.js.map +1 -0
  94. package/dist/schemas/kadi-extensions.d.ts +231 -0
  95. package/dist/schemas/kadi-extensions.d.ts.map +1 -0
  96. package/dist/schemas/kadi-extensions.js +14 -0
  97. package/dist/schemas/kadi-extensions.js.map +1 -0
  98. package/dist/schemas/mcp/schema.d.ts +1399 -0
  99. package/dist/schemas/mcp/schema.d.ts.map +1 -0
  100. package/dist/schemas/mcp/schema.js +53 -0
  101. package/dist/schemas/mcp/schema.js.map +1 -0
  102. package/dist/schemas/mcp/version.d.ts +37 -0
  103. package/dist/schemas/mcp/version.d.ts.map +1 -0
  104. package/dist/schemas/mcp/version.js +39 -0
  105. package/dist/schemas/mcp/version.js.map +1 -0
  106. package/dist/schemas/schema-builders.d.ts +178 -0
  107. package/dist/schemas/schema-builders.d.ts.map +1 -0
  108. package/dist/schemas/schema-builders.js +258 -0
  109. package/dist/schemas/schema-builders.js.map +1 -0
  110. package/dist/schemas/zod-helpers.d.ts +129 -0
  111. package/dist/schemas/zod-helpers.d.ts.map +1 -0
  112. package/dist/schemas/zod-helpers.js +225 -0
  113. package/dist/schemas/zod-helpers.js.map +1 -0
  114. package/dist/schemas/zod-to-json-schema.d.ts +159 -0
  115. package/dist/schemas/zod-to-json-schema.d.ts.map +1 -0
  116. package/dist/schemas/zod-to-json-schema.js +154 -0
  117. package/dist/schemas/zod-to-json-schema.js.map +1 -0
  118. package/dist/tools/ToolRegistry.d.ts +256 -0
  119. package/dist/tools/ToolRegistry.d.ts.map +1 -0
  120. package/dist/tools/ToolRegistry.js +340 -0
  121. package/dist/tools/ToolRegistry.js.map +1 -0
  122. package/dist/tools/index.d.ts +7 -0
  123. package/dist/tools/index.d.ts.map +1 -0
  124. package/dist/tools/index.js +7 -0
  125. package/dist/tools/index.js.map +1 -0
  126. package/dist/transports/BrokerTransport.d.ts +151 -0
  127. package/dist/transports/BrokerTransport.d.ts.map +1 -0
  128. package/dist/transports/BrokerTransport.js +261 -0
  129. package/dist/transports/BrokerTransport.js.map +1 -0
  130. package/dist/transports/NativeTransport.d.ts +178 -0
  131. package/dist/transports/NativeTransport.d.ts.map +1 -0
  132. package/dist/transports/NativeTransport.js +397 -0
  133. package/dist/transports/NativeTransport.js.map +1 -0
  134. package/dist/transports/StdioTransport.d.ts +250 -0
  135. package/dist/transports/StdioTransport.d.ts.map +1 -0
  136. package/dist/transports/StdioTransport.js +487 -0
  137. package/dist/transports/StdioTransport.js.map +1 -0
  138. package/dist/transports/index.d.ts +10 -0
  139. package/dist/transports/index.d.ts.map +1 -0
  140. package/dist/transports/index.js +9 -0
  141. package/dist/transports/index.js.map +1 -0
  142. package/dist/types/broker.d.ts +279 -0
  143. package/dist/types/broker.d.ts.map +1 -0
  144. package/dist/types/broker.js +19 -0
  145. package/dist/types/broker.js.map +1 -0
  146. package/dist/types/config.d.ts +325 -0
  147. package/dist/types/config.d.ts.map +1 -0
  148. package/dist/types/config.js +17 -0
  149. package/dist/types/config.js.map +1 -0
  150. package/dist/types/errors.d.ts +178 -0
  151. package/dist/types/errors.d.ts.map +1 -0
  152. package/dist/types/errors.js +165 -0
  153. package/dist/types/errors.js.map +1 -0
  154. package/dist/types/events.d.ts +210 -0
  155. package/dist/types/events.d.ts.map +1 -0
  156. package/dist/types/events.js +8 -0
  157. package/dist/types/events.js.map +1 -0
  158. package/dist/types/index.d.ts +34 -0
  159. package/dist/types/index.d.ts.map +1 -0
  160. package/dist/types/index.js +21 -0
  161. package/dist/types/index.js.map +1 -0
  162. package/dist/types/protocol.d.ts +48 -0
  163. package/dist/types/protocol.d.ts.map +1 -0
  164. package/dist/types/protocol.js +11 -0
  165. package/dist/types/protocol.js.map +1 -0
  166. package/dist/types/tools.d.ts +67 -0
  167. package/dist/types/tools.d.ts.map +1 -0
  168. package/dist/types/tools.js +16 -0
  169. package/dist/types/tools.js.map +1 -0
  170. package/dist/types/transport.d.ts +250 -0
  171. package/dist/types/transport.d.ts.map +1 -0
  172. package/dist/types/transport.js +18 -0
  173. package/dist/types/transport.js.map +1 -0
  174. package/dist/types/zod-tools.d.ts +198 -0
  175. package/dist/types/zod-tools.d.ts.map +1 -0
  176. package/dist/types/zod-tools.js +14 -0
  177. package/dist/types/zod-tools.js.map +1 -0
  178. package/dist/utils/StdioMessageReader.d.ts +122 -0
  179. package/dist/utils/StdioMessageReader.d.ts.map +1 -0
  180. package/dist/utils/StdioMessageReader.js +209 -0
  181. package/dist/utils/StdioMessageReader.js.map +1 -0
  182. package/dist/utils/StdioMessageWriter.d.ts +104 -0
  183. package/dist/utils/StdioMessageWriter.d.ts.map +1 -0
  184. package/dist/utils/StdioMessageWriter.js +162 -0
  185. package/dist/utils/StdioMessageWriter.js.map +1 -0
  186. package/dist/validation/SchemaValidator.d.ts +208 -0
  187. package/dist/validation/SchemaValidator.d.ts.map +1 -0
  188. package/dist/validation/SchemaValidator.js +411 -0
  189. package/dist/validation/SchemaValidator.js.map +1 -0
  190. package/dist/validation/index.d.ts +11 -0
  191. package/dist/validation/index.d.ts.map +1 -0
  192. package/dist/validation/index.js +10 -0
  193. package/dist/validation/index.js.map +1 -0
  194. package/package.json +70 -5
  195. package/agent.json +0 -18
  196. package/broker.js +0 -214
  197. package/index.js +0 -370
  198. package/ipc.js +0 -220
  199. package/ipcInterfaces/pythonAbilityIPC.py +0 -177
@@ -0,0 +1,223 @@
1
+ /**
2
+ * Ability Loading Types
3
+ *
4
+ * Clean, type-safe options for loading abilities using discriminated unions.
5
+ * TypeScript enforces that only relevant fields are used per transport type.
6
+ *
7
+ * @module abilities/types
8
+ */
9
+ import type { KadiTool } from '../types/index.js';
10
+ /**
11
+ * AgentJson - Runtime representation of agent.json file
12
+ *
13
+ * Both KADI agents and abilities have an `agent.json` file in their root directory.
14
+ * This interface represents the runtime structure returned by `readAgentJson()`.
15
+ *
16
+ * **Field Mapping:**
17
+ * - agent.json uses `exports` field (array of tool definitions)
18
+ * - Runtime uses `tools` field (clearer, more intuitive naming)
19
+ *
20
+ * **Purpose:**
21
+ * - Ability discovery: What tools does this provide?
22
+ * - Type generation: Generate TypeScript .d.ts files from agent.json
23
+ * - Validation: Check schemas before invocation
24
+ *
25
+ * **Source:** Extracted from agent.json at runtime via `KadiClient.readAgentJson()`
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * // agent.json file:
30
+ * {
31
+ * "name": "calculator",
32
+ * "version": "1.0.0",
33
+ * "description": "Basic math operations",
34
+ * "exports": [
35
+ * { "name": "add", "description": "Add two numbers", ... }
36
+ * ]
37
+ * }
38
+ *
39
+ * // Runtime representation:
40
+ * const agentJson = client.readAgentJson();
41
+ * // {
42
+ * // name: 'calculator',
43
+ * // version: '1.0.0',
44
+ * // description: 'Basic math operations',
45
+ * // tools: [{ name: 'add', ... }] // ← mapped from 'exports'
46
+ * // }
47
+ * ```
48
+ */
49
+ export interface AgentJson {
50
+ /**
51
+ * Agent/ability name from agent.json
52
+ *
53
+ * @example 'calculator', 'text-processor', 'my-agent'
54
+ */
55
+ name: string;
56
+ /**
57
+ * Semantic version from agent.json
58
+ *
59
+ * @example '1.0.0', '2.1.3'
60
+ */
61
+ version: string;
62
+ /**
63
+ * Human-readable description from agent.json
64
+ *
65
+ * @example 'Basic math operations'
66
+ */
67
+ description?: string;
68
+ /**
69
+ * List of tools provided by this agent/ability
70
+ *
71
+ * Mapped from agent.json's 'exports' field at runtime.
72
+ * We use 'tools' instead of 'exports' for clarity.
73
+ */
74
+ tools: KadiTool[];
75
+ }
76
+ /**
77
+ * Base options shared across all transports
78
+ *
79
+ * These options apply regardless of how the ability is loaded.
80
+ */
81
+ interface BaseLoadOptions {
82
+ /**
83
+ * Version constraint (semver format)
84
+ *
85
+ * @example '^2.0.0', '>=1.5.0 <2.0.0'
86
+ */
87
+ version?: string;
88
+ /**
89
+ * Connection timeout in milliseconds
90
+ *
91
+ * @default 30000 (30 seconds)
92
+ */
93
+ timeout?: number;
94
+ /**
95
+ * Validate loaded ability has expected methods
96
+ *
97
+ * When true, checks that ability exposes methods before returning.
98
+ * Catches mismatches early with helpful error messages.
99
+ *
100
+ * @default false
101
+ */
102
+ validate?: boolean;
103
+ }
104
+ /**
105
+ * Broker transport options
106
+ *
107
+ * Load ability from remote broker service.
108
+ * Service is already running independently with its own context.
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * const remote = await client.load('gpu-service', 'broker', {
113
+ * networks: ['global', 'gpu-cluster']
114
+ * });
115
+ * ```
116
+ */
117
+ export interface BrokerLoadOptions extends BaseLoadOptions {
118
+ /**
119
+ * Networks to search for the ability
120
+ *
121
+ * @default client's configured networks
122
+ */
123
+ networks?: string[];
124
+ /**
125
+ * Specific broker to use
126
+ *
127
+ * @default client's default broker
128
+ */
129
+ broker?: string;
130
+ }
131
+ /**
132
+ * Native transport options
133
+ *
134
+ * Load ability in same process (fastest, full type safety).
135
+ * Ability runs in same Node.js process as caller.
136
+ *
137
+ * @example
138
+ * ```typescript
139
+ * const local = await client.load('math-lib', 'native', {
140
+ * path: './abilities/math'
141
+ * });
142
+ * ```
143
+ */
144
+ export interface NativeLoadOptions extends BaseLoadOptions {
145
+ /**
146
+ * Path to ability module
147
+ *
148
+ * Can be:
149
+ * - Relative path: './abilities/math'
150
+ * - Absolute path: '/usr/local/lib/abilities/math'
151
+ * - Package name: '@kadi/math-ability'
152
+ */
153
+ path: string;
154
+ }
155
+ /**
156
+ * Stdio transport options
157
+ *
158
+ * Load ability as child process (any language).
159
+ * Context flows from parent to child (broker, auth, networks).
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * const analyzer = await client.load('python-analyzer', 'stdio', {
164
+ * command: 'python3',
165
+ * args: ['analyzer.py'],
166
+ * env: { PYTHONPATH: './lib' }
167
+ * });
168
+ * ```
169
+ */
170
+ export interface StdioLoadOptions extends BaseLoadOptions {
171
+ /**
172
+ * Command to execute
173
+ *
174
+ * @example 'python3', 'node', './my-script.sh'
175
+ */
176
+ command: string;
177
+ /**
178
+ * Command arguments
179
+ *
180
+ * @example ['main.py', '--verbose']
181
+ */
182
+ args?: string[];
183
+ /**
184
+ * Environment variables for child process
185
+ *
186
+ * @example { PYTHONPATH: './lib', DEBUG: 'true' }
187
+ */
188
+ env?: Record<string, string>;
189
+ /**
190
+ * Working directory for child process
191
+ *
192
+ * @default process.cwd()
193
+ */
194
+ cwd?: string;
195
+ }
196
+ /**
197
+ * Load options based on transport type
198
+ *
199
+ * Options are now transport-specific since transport is a separate parameter.
200
+ * TypeScript will enforce correct options based on the transport you specify.
201
+ *
202
+ * @example
203
+ * ```typescript
204
+ * // Broker transport with options
205
+ * await client.load('ability', 'broker', { networks: ['global'] });
206
+ *
207
+ * // Native transport with path (required)
208
+ * await client.load('ability', 'native', { path: './local' });
209
+ *
210
+ * // Stdio transport with command (required)
211
+ * await client.load('ability', 'stdio', { command: 'python3', args: ['main.py'] });
212
+ *
213
+ * // Minimal broker - just base options
214
+ * await client.load('calculator', 'broker', { validate: true });
215
+ * ```
216
+ */
217
+ export type LoadOptions<T extends TransportType = TransportType> = T extends 'broker' ? BrokerLoadOptions : T extends 'native' ? NativeLoadOptions : T extends 'stdio' ? StdioLoadOptions : BaseLoadOptions;
218
+ /**
219
+ * Transport type for ability loading
220
+ */
221
+ export type TransportType = 'native' | 'stdio' | 'broker';
222
+ export {};
223
+ //# sourceMappingURL=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E,MAAM,CAAC;CACd;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,aAAa,GAAG,aAAa,IAC7D,CAAC,SAAS,QAAQ,GAAG,iBAAiB,GACtC,CAAC,SAAS,QAAQ,GAAG,iBAAiB,GACtC,CAAC,SAAS,OAAO,GAAG,gBAAgB,GACpC,eAAe,CAAC;AAElB;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Ability Loading Types
3
+ *
4
+ * Clean, type-safe options for loading abilities using discriminated unions.
5
+ * TypeScript enforces that only relevant fields are used per transport type.
6
+ *
7
+ * @module abilities/types
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/abilities/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Simplified KADI API
3
+ *
4
+ * User-friendly API wrapper that makes KADI incredibly simple to use.
5
+ * This is what developers actually interact with.
6
+ *
7
+ * @module api
8
+ */
9
+ import { KadiClient } from '../client/KadiClient.js';
10
+ import type { KadiConfig, ServiceConfig } from '../types/index.js';
11
+ /**
12
+ * Connect to a KADI broker and create a client
13
+ *
14
+ * Simplified connection API that handles common cases beautifully.
15
+ *
16
+ * @param config - Broker URL string or full configuration object
17
+ * @returns Connected KADI client
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * // Simple broker URL
22
+ * const client = await Kadi.connect('ws://localhost:8080');
23
+ *
24
+ * // Full configuration
25
+ * const client = await Kadi.connect({
26
+ * name: 'my-app',
27
+ * brokers: { local: 'ws://localhost:8080' },
28
+ * networks: ['global']
29
+ * });
30
+ * ```
31
+ */
32
+ export declare function connect(config: string | KadiConfig): Promise<KadiClient>;
33
+ /**
34
+ * Create a service that provides tools
35
+ *
36
+ * Simplified service creation for agents that expose capabilities.
37
+ *
38
+ * @param config - Service configuration
39
+ * @returns Service client ready for tool registration
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * const service = await Kadi.service({
44
+ * name: 'calculator',
45
+ * broker: 'ws://localhost:8080'
46
+ * });
47
+ *
48
+ * // Register tools using MCP schema format
49
+ * service.registerTool({
50
+ * name: 'add',
51
+ * description: 'Add two numbers',
52
+ * inputSchema: {
53
+ * type: 'object',
54
+ * properties: {
55
+ * a: { type: 'number' },
56
+ * b: { type: 'number' }
57
+ * },
58
+ * required: ['a', 'b']
59
+ * },
60
+ * outputSchema: {
61
+ * type: 'object',
62
+ * properties: {
63
+ * result: { type: 'number' }
64
+ * }
65
+ * }
66
+ * }, async ({ a, b }) => {
67
+ * return { result: a + b };
68
+ * });
69
+ * ```
70
+ */
71
+ export declare function service(config: ServiceConfig): Promise<KadiClient>;
72
+ /**
73
+ * Create a client without connecting to brokers
74
+ *
75
+ * Useful for local-only operations (native/stdio transports).
76
+ *
77
+ * @param name - Client name
78
+ * @returns Local client (not connected to brokers)
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * const client = Kadi.local('my-app');
83
+ *
84
+ * // Load abilities locally
85
+ * const calc = await client.loadAbility('calculator', {
86
+ * transport: 'native',
87
+ * path: './calculator'
88
+ * });
89
+ * ```
90
+ */
91
+ export declare function local(name: string): KadiClient;
92
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAoB,MAAM,mBAAmB,CAAC;AAErF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAa9E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAsB,OAAO,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,CAAC,CAqBxE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAK9C"}
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Simplified KADI API
3
+ *
4
+ * User-friendly API wrapper that makes KADI incredibly simple to use.
5
+ * This is what developers actually interact with.
6
+ *
7
+ * @module api
8
+ */
9
+ import { KadiClient } from '../client/KadiClient.js';
10
+ /**
11
+ * Connect to a KADI broker and create a client
12
+ *
13
+ * Simplified connection API that handles common cases beautifully.
14
+ *
15
+ * @param config - Broker URL string or full configuration object
16
+ * @returns Connected KADI client
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * // Simple broker URL
21
+ * const client = await Kadi.connect('ws://localhost:8080');
22
+ *
23
+ * // Full configuration
24
+ * const client = await Kadi.connect({
25
+ * name: 'my-app',
26
+ * brokers: { local: 'ws://localhost:8080' },
27
+ * networks: ['global']
28
+ * });
29
+ * ```
30
+ */
31
+ export async function connect(config) {
32
+ // Normalize config
33
+ const normalizedConfig = typeof config === 'string'
34
+ ? { name: 'kadi-client', brokers: { default: config } }
35
+ : config;
36
+ // Create client
37
+ const client = new KadiClient(normalizedConfig);
38
+ // Auto-connect
39
+ await client.connect();
40
+ return client;
41
+ }
42
+ /**
43
+ * Create a service that provides tools
44
+ *
45
+ * Simplified service creation for agents that expose capabilities.
46
+ *
47
+ * @param config - Service configuration
48
+ * @returns Service client ready for tool registration
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * const service = await Kadi.service({
53
+ * name: 'calculator',
54
+ * broker: 'ws://localhost:8080'
55
+ * });
56
+ *
57
+ * // Register tools using MCP schema format
58
+ * service.registerTool({
59
+ * name: 'add',
60
+ * description: 'Add two numbers',
61
+ * inputSchema: {
62
+ * type: 'object',
63
+ * properties: {
64
+ * a: { type: 'number' },
65
+ * b: { type: 'number' }
66
+ * },
67
+ * required: ['a', 'b']
68
+ * },
69
+ * outputSchema: {
70
+ * type: 'object',
71
+ * properties: {
72
+ * result: { type: 'number' }
73
+ * }
74
+ * }
75
+ * }, async ({ a, b }) => {
76
+ * return { result: a + b };
77
+ * });
78
+ * ```
79
+ */
80
+ export async function service(config) {
81
+ // Convert ServiceConfig to KadiConfig
82
+ const clientConfig = {
83
+ name: config.name,
84
+ version: config.version,
85
+ description: config.description,
86
+ role: 'ability',
87
+ networks: config.networks ?? ['global']
88
+ };
89
+ // Add broker configuration
90
+ if (config.broker) {
91
+ clientConfig.brokers = { default: config.broker };
92
+ clientConfig.defaultBroker = 'default';
93
+ }
94
+ // Create and return client
95
+ const client = new KadiClient(clientConfig);
96
+ await client.connect();
97
+ return client;
98
+ }
99
+ /**
100
+ * Create a client without connecting to brokers
101
+ *
102
+ * Useful for local-only operations (native/stdio transports).
103
+ *
104
+ * @param name - Client name
105
+ * @returns Local client (not connected to brokers)
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * const client = Kadi.local('my-app');
110
+ *
111
+ * // Load abilities locally
112
+ * const calc = await client.loadAbility('calculator', {
113
+ * transport: 'native',
114
+ * path: './calculator'
115
+ * });
116
+ * ```
117
+ */
118
+ export function local(name) {
119
+ return new KadiClient({
120
+ name,
121
+ networks: ['local']
122
+ });
123
+ }
124
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGrD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,MAA2B;IACvD,mBAAmB;IACnB,MAAM,gBAAgB,GAAe,OAAO,MAAM,KAAK,QAAQ;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