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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/README.md +1387 -214
  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 +177 -0
  11. package/dist/abilities/AbilityLoader.d.ts.map +1 -0
  12. package/dist/abilities/AbilityLoader.js +277 -0
  13. package/dist/abilities/AbilityLoader.js.map +1 -0
  14. package/dist/abilities/AbilityProxy.d.ts +463 -0
  15. package/dist/abilities/AbilityProxy.d.ts.map +1 -0
  16. package/dist/abilities/AbilityProxy.js +511 -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 +156 -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 +270 -0
  51. package/dist/client/KadiClient.d.ts.map +1 -0
  52. package/dist/client/KadiClient.js +492 -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 +49 -0
  83. package/dist/index.d.ts.map +1 -0
  84. package/dist/index.js +63 -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 +19 -0
  91. package/dist/schemas/index.d.ts.map +1 -0
  92. package/dist/schemas/index.js +25 -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/tools/ToolRegistry.d.ts +256 -0
  111. package/dist/tools/ToolRegistry.d.ts.map +1 -0
  112. package/dist/tools/ToolRegistry.js +340 -0
  113. package/dist/tools/ToolRegistry.js.map +1 -0
  114. package/dist/tools/index.d.ts +7 -0
  115. package/dist/tools/index.d.ts.map +1 -0
  116. package/dist/tools/index.js +7 -0
  117. package/dist/tools/index.js.map +1 -0
  118. package/dist/transports/BrokerTransport.d.ts +151 -0
  119. package/dist/transports/BrokerTransport.d.ts.map +1 -0
  120. package/dist/transports/BrokerTransport.js +261 -0
  121. package/dist/transports/BrokerTransport.js.map +1 -0
  122. package/dist/transports/NativeTransport.d.ts +149 -0
  123. package/dist/transports/NativeTransport.d.ts.map +1 -0
  124. package/dist/transports/NativeTransport.js +302 -0
  125. package/dist/transports/NativeTransport.js.map +1 -0
  126. package/dist/transports/StdioTransport.d.ts +172 -0
  127. package/dist/transports/StdioTransport.d.ts.map +1 -0
  128. package/dist/transports/StdioTransport.js +410 -0
  129. package/dist/transports/StdioTransport.js.map +1 -0
  130. package/dist/transports/index.d.ts +10 -0
  131. package/dist/transports/index.d.ts.map +1 -0
  132. package/dist/transports/index.js +9 -0
  133. package/dist/transports/index.js.map +1 -0
  134. package/dist/types/broker.d.ts +301 -0
  135. package/dist/types/broker.d.ts.map +1 -0
  136. package/dist/types/broker.js +46 -0
  137. package/dist/types/broker.js.map +1 -0
  138. package/dist/types/config.d.ts +325 -0
  139. package/dist/types/config.d.ts.map +1 -0
  140. package/dist/types/config.js +17 -0
  141. package/dist/types/config.js.map +1 -0
  142. package/dist/types/errors.d.ts +178 -0
  143. package/dist/types/errors.d.ts.map +1 -0
  144. package/dist/types/errors.js +165 -0
  145. package/dist/types/errors.js.map +1 -0
  146. package/dist/types/events.d.ts +210 -0
  147. package/dist/types/events.d.ts.map +1 -0
  148. package/dist/types/events.js +8 -0
  149. package/dist/types/events.js.map +1 -0
  150. package/dist/types/index.d.ts +32 -0
  151. package/dist/types/index.d.ts.map +1 -0
  152. package/dist/types/index.js +21 -0
  153. package/dist/types/index.js.map +1 -0
  154. package/dist/types/protocol.d.ts +48 -0
  155. package/dist/types/protocol.d.ts.map +1 -0
  156. package/dist/types/protocol.js +11 -0
  157. package/dist/types/protocol.js.map +1 -0
  158. package/dist/types/tools.d.ts +67 -0
  159. package/dist/types/tools.d.ts.map +1 -0
  160. package/dist/types/tools.js +16 -0
  161. package/dist/types/tools.js.map +1 -0
  162. package/dist/types/transport.d.ts +250 -0
  163. package/dist/types/transport.d.ts.map +1 -0
  164. package/dist/types/transport.js +18 -0
  165. package/dist/types/transport.js.map +1 -0
  166. package/dist/validation/SchemaValidator.d.ts +208 -0
  167. package/dist/validation/SchemaValidator.d.ts.map +1 -0
  168. package/dist/validation/SchemaValidator.js +411 -0
  169. package/dist/validation/SchemaValidator.js.map +1 -0
  170. package/dist/validation/index.d.ts +11 -0
  171. package/dist/validation/index.d.ts.map +1 -0
  172. package/dist/validation/index.js +10 -0
  173. package/dist/validation/index.js.map +1 -0
  174. package/package.json +69 -5
  175. package/agent.json +0 -18
  176. package/broker.js +0 -214
  177. package/index.js +0 -370
  178. package/ipc.js +0 -220
  179. package/ipcInterfaces/pythonAbilityIPC.py +0 -177
@@ -0,0 +1,411 @@
1
+ /**
2
+ * Schema Validator
3
+ * =================
4
+ *
5
+ * Validates tool input/output against MCP JSON Schemas using AJV.
6
+ * Implements global caching for performance at scale.
7
+ *
8
+ * **Performance Optimization**:
9
+ * - Global cache prevents redundant schema compilations
10
+ * - At scale (1000+ tools), this provides 1000x performance improvement
11
+ * - Memory efficient: ~5KB per compiled schema vs 5MB for duplicates
12
+ *
13
+ * @module validation/SchemaValidator
14
+ */
15
+ import AjvDefault from 'ajv';
16
+ import addFormatsDefault from 'ajv-formats';
17
+ import { KadiError, ErrorCode } from '../types/index.js';
18
+ /**
19
+ * ESM/CommonJS Interop for AJV
20
+ *
21
+ * TypeScript's NodeNext module resolution has issues with AJV's dual CJS/ESM exports.
22
+ * These casts ensure we get the correct constructor and function types regardless
23
+ * of how the modules are loaded at runtime.
24
+ *
25
+ * Without these, we get:
26
+ * - "This expression is not constructable" for `new Ajv()`
27
+ * - "This expression is not callable" for `addFormats()`
28
+ *
29
+ * This is a known TypeScript/Node.js ESM limitation, not a code smell.
30
+ */
31
+ const AjvConstructor = AjvDefault;
32
+ const addFormats = addFormatsDefault;
33
+ /**
34
+ * Global Schema Compilation Cache
35
+ * =================================
36
+ *
37
+ * **Why Global?**
38
+ * At scale (1000+ agents, 10 tools each), the same schemas are compiled repeatedly.
39
+ * Without caching: 10,000 compilations of the same ~10 unique schemas.
40
+ * With caching: 10 compilations (1000x improvement).
41
+ *
42
+ * **Performance**:
43
+ * - Memory: 50KB (cached) vs 50MB (duplicates)
44
+ * - CPU: O(1) cache lookup vs O(n) compilation
45
+ *
46
+ * **Thread Safety**:
47
+ * Node.js is single-threaded, no locking needed.
48
+ *
49
+ * **Singleton Pattern**:
50
+ * Ensures one cache instance across entire application.
51
+ */
52
+ class GlobalSchemaCache {
53
+ static instance;
54
+ cache = new Map();
55
+ ajv;
56
+ constructor() {
57
+ // Shared AJV instance for all schema compilations
58
+ this.ajv = new AjvConstructor({
59
+ allErrors: true, // Collect all errors, not just first
60
+ verbose: true, // Include validated data in errors
61
+ strict: false, // Allow unknown JSON Schema keywords
62
+ validateFormats: true // Validate format constraints
63
+ });
64
+ // Add format validators (email, uri, date, etc.)
65
+ addFormats(this.ajv);
66
+ }
67
+ /**
68
+ * Get the singleton cache instance
69
+ *
70
+ * @returns Global schema cache
71
+ */
72
+ static getInstance() {
73
+ if (!GlobalSchemaCache.instance) {
74
+ GlobalSchemaCache.instance = new GlobalSchemaCache();
75
+ }
76
+ return GlobalSchemaCache.instance;
77
+ }
78
+ /**
79
+ * Get or compile a schema validator
80
+ *
81
+ * **Cache Strategy**:
82
+ * - Cache key: JSON.stringify(schema)
83
+ * - Hit: Return cached validator (O(1))
84
+ * - Miss: Compile and cache for future use (O(n))
85
+ *
86
+ * @param schema - JSON Schema to compile
87
+ * @returns Compiled validator function
88
+ * @throws {Error} If schema compilation fails
89
+ */
90
+ getValidator(schema) {
91
+ // Generate cache key from schema content
92
+ const cacheKey = JSON.stringify(schema);
93
+ // Check cache first
94
+ let validator = this.cache.get(cacheKey);
95
+ if (!validator) {
96
+ // Cache miss - compile and store
97
+ validator = this.ajv.compile(schema);
98
+ this.cache.set(cacheKey, validator);
99
+ }
100
+ return validator;
101
+ }
102
+ /**
103
+ * Get cache statistics
104
+ *
105
+ * Useful for monitoring and debugging.
106
+ *
107
+ * @returns Cache statistics
108
+ */
109
+ getStats() {
110
+ return {
111
+ cachedSchemas: this.cache.size
112
+ };
113
+ }
114
+ /**
115
+ * Clear the global cache
116
+ *
117
+ * Primarily for testing. In production, cache should persist
118
+ * for lifetime of application.
119
+ */
120
+ clear() {
121
+ this.cache.clear();
122
+ }
123
+ }
124
+ /**
125
+ * Schema Validator
126
+ * =================
127
+ *
128
+ * Validates tool inputs and outputs against JSON Schemas.
129
+ * Each instance manages schemas for a set of tools, but shares
130
+ * the global compilation cache for efficiency.
131
+ *
132
+ * **Usage**:
133
+ * ```typescript
134
+ * const validator = new SchemaValidator();
135
+ *
136
+ * // Register tool schemas
137
+ * validator.registerTool('add', inputSchema, outputSchema);
138
+ *
139
+ * // Validate input
140
+ * const result = validator.validateInput('add', { a: 5, b: 3 });
141
+ * if (!result.valid) {
142
+ * console.error('Validation failed:', result.errors);
143
+ * }
144
+ * ```
145
+ */
146
+ export class SchemaValidator {
147
+ /**
148
+ * Tool schemas (per validator instance)
149
+ */
150
+ toolSchemas = new Map();
151
+ /**
152
+ * Compiled validators (per validator instance, but reuses global cache)
153
+ */
154
+ validators = new Map();
155
+ /**
156
+ * Reference to global cache (shared across all instances)
157
+ */
158
+ globalCache;
159
+ constructor() {
160
+ // Get singleton cache instance (shared with all SchemaValidator instances)
161
+ this.globalCache = GlobalSchemaCache.getInstance();
162
+ }
163
+ /**
164
+ * Register a tool with its input and output schemas
165
+ *
166
+ * Compiles schemas using global cache to avoid redundant work.
167
+ * If these schemas were compiled before (by any validator instance),
168
+ * the cached validators are reused.
169
+ *
170
+ * @param toolName - Tool name
171
+ * @param inputSchema - Input JSON Schema (MCP format)
172
+ * @param outputSchema - Optional output JSON Schema (MCP format)
173
+ * @throws {KadiError} If schema compilation fails
174
+ *
175
+ * @example
176
+ * ```typescript
177
+ * validator.registerTool('add', {
178
+ * type: 'object',
179
+ * properties: {
180
+ * a: { type: 'number' },
181
+ * b: { type: 'number' }
182
+ * },
183
+ * required: ['a', 'b']
184
+ * }, {
185
+ * type: 'object',
186
+ * properties: {
187
+ * result: { type: 'number' }
188
+ * }
189
+ * });
190
+ * ```
191
+ */
192
+ registerTool(toolName, inputSchema, outputSchema) {
193
+ try {
194
+ // Get or compile validators using global cache
195
+ const inputValidator = this.globalCache.getValidator(inputSchema);
196
+ const outputValidator = outputSchema
197
+ ? this.globalCache.getValidator(outputSchema)
198
+ : undefined;
199
+ // Store schemas and validators for this tool
200
+ this.toolSchemas.set(toolName, { input: inputSchema, output: outputSchema });
201
+ this.validators.set(toolName, { input: inputValidator, output: outputValidator });
202
+ }
203
+ catch (error) {
204
+ throw new KadiError(`Failed to compile schemas for tool '${toolName}': ${error instanceof Error ? error.message : String(error)}`, ErrorCode.SCHEMA_VALIDATION_FAILED, 400, { toolName, error });
205
+ }
206
+ }
207
+ /**
208
+ * Validate input data against a tool's input schema
209
+ *
210
+ * @param toolName - Tool name
211
+ * @param input - Input data to validate
212
+ * @returns Validation result
213
+ *
214
+ * @example
215
+ * ```typescript
216
+ * const result = validator.validateInput('add', { a: 5, b: 3 });
217
+ * if (!result.valid) {
218
+ * console.error('Invalid input:', result.errors);
219
+ * }
220
+ * ```
221
+ */
222
+ validateInput(toolName, input) {
223
+ const validators = this.validators.get(toolName);
224
+ if (!validators) {
225
+ return {
226
+ valid: false,
227
+ errors: [`No schema registered for tool '${toolName}'`]
228
+ };
229
+ }
230
+ const valid = validators.input(input);
231
+ if (valid) {
232
+ return { valid: true, errors: [] };
233
+ }
234
+ const errors = this.formatValidationErrors(validators.input.errors || []);
235
+ return {
236
+ valid: false,
237
+ errors,
238
+ errorDetails: validators.input.errors || []
239
+ };
240
+ }
241
+ /**
242
+ * Validate output data against a tool's output schema
243
+ *
244
+ * @param toolName - Tool name
245
+ * @param output - Output data to validate
246
+ * @returns Validation result
247
+ *
248
+ * @example
249
+ * ```typescript
250
+ * const result = validator.validateOutput('add', { result: 8 });
251
+ * if (!result.valid) {
252
+ * console.error('Invalid output:', result.errors);
253
+ * }
254
+ * ```
255
+ */
256
+ validateOutput(toolName, output) {
257
+ const validators = this.validators.get(toolName);
258
+ if (!validators) {
259
+ return {
260
+ valid: false,
261
+ errors: [`No schema registered for tool '${toolName}'`]
262
+ };
263
+ }
264
+ // Output schema is optional in MCP
265
+ if (!validators.output) {
266
+ return { valid: true, errors: [] };
267
+ }
268
+ const valid = validators.output(output);
269
+ if (valid) {
270
+ return { valid: true, errors: [] };
271
+ }
272
+ const errors = this.formatValidationErrors(validators.output.errors || []);
273
+ return {
274
+ valid: false,
275
+ errors,
276
+ errorDetails: validators.output.errors || []
277
+ };
278
+ }
279
+ /**
280
+ * Get the schemas for a tool
281
+ *
282
+ * @param toolName - Tool name
283
+ * @returns Tool schemas or undefined if not registered
284
+ */
285
+ getToolSchemas(toolName) {
286
+ return this.toolSchemas.get(toolName);
287
+ }
288
+ /**
289
+ * Check if a tool has registered schemas
290
+ *
291
+ * @param toolName - Tool name
292
+ * @returns Whether tool is registered
293
+ */
294
+ hasToolSchemas(toolName) {
295
+ return this.toolSchemas.has(toolName);
296
+ }
297
+ /**
298
+ * Remove schemas for a tool
299
+ *
300
+ * @param toolName - Tool name
301
+ */
302
+ unregisterTool(toolName) {
303
+ this.toolSchemas.delete(toolName);
304
+ this.validators.delete(toolName);
305
+ }
306
+ /**
307
+ * Get all registered tool names
308
+ *
309
+ * @returns Array of tool names
310
+ */
311
+ getRegisteredTools() {
312
+ return Array.from(this.toolSchemas.keys());
313
+ }
314
+ /**
315
+ * Validate a schema definition itself (meta-validation)
316
+ *
317
+ * Checks if a schema is valid JSON Schema and can be compiled.
318
+ * Uses global cache to avoid redundant compilations.
319
+ *
320
+ * @param schema - JSON Schema to validate
321
+ * @returns Validation result
322
+ *
323
+ * @example
324
+ * ```typescript
325
+ * const result = validator.validateSchemaDefinition({
326
+ * type: 'object',
327
+ * properties: {
328
+ * name: { type: 'string' }
329
+ * }
330
+ * });
331
+ * if (!result.valid) {
332
+ * console.error('Invalid schema:', result.errors);
333
+ * }
334
+ * ```
335
+ */
336
+ validateSchemaDefinition(schema) {
337
+ try {
338
+ // Attempt to compile using global cache
339
+ // This validates the schema and potentially caches it for future use
340
+ this.globalCache.getValidator(schema);
341
+ return { valid: true, errors: [] };
342
+ }
343
+ catch (error) {
344
+ return {
345
+ valid: false,
346
+ errors: [error instanceof Error ? error.message : String(error)]
347
+ };
348
+ }
349
+ }
350
+ /**
351
+ * Format validation errors for human readability
352
+ *
353
+ * Converts AJV error objects into clear, actionable error messages.
354
+ *
355
+ * @param errors - AJV error objects
356
+ * @returns Human-readable error messages
357
+ */
358
+ formatValidationErrors(errors) {
359
+ return errors.map((error) => {
360
+ const path = error.instancePath || '/';
361
+ const message = error.message || 'Validation failed';
362
+ // Specific formatting for common error types
363
+ if (error.keyword === 'required') {
364
+ return `Missing required field at ${path}: ${error.params.missingProperty}`;
365
+ }
366
+ if (error.keyword === 'type') {
367
+ const expected = error.params.type;
368
+ const actual = typeof error.data;
369
+ return `Invalid type at ${path}: expected ${expected}, got ${actual}`;
370
+ }
371
+ if (error.keyword === 'additionalProperties') {
372
+ return `Unexpected property at ${path}: ${error.params.additionalProperty}`;
373
+ }
374
+ if (error.keyword === 'enum') {
375
+ return `Invalid value at ${path}: must be one of ${error.params.allowedValues?.join(', ')}`;
376
+ }
377
+ if (error.keyword === 'minimum' || error.keyword === 'maximum') {
378
+ return `Value at ${path} ${message} (limit: ${error.params.limit})`;
379
+ }
380
+ if (error.keyword === 'minLength' || error.keyword === 'maxLength') {
381
+ return `String at ${path} ${message} (limit: ${error.params.limit})`;
382
+ }
383
+ if (error.keyword === 'pattern') {
384
+ return `String at ${path} does not match pattern: ${error.params.pattern}`;
385
+ }
386
+ if (error.keyword === 'format') {
387
+ return `Invalid ${error.params.format} format at ${path}`;
388
+ }
389
+ // Default formatting
390
+ return `${path}: ${message}`;
391
+ });
392
+ }
393
+ /**
394
+ * Get global cache statistics
395
+ *
396
+ * @returns Cache statistics
397
+ */
398
+ static getCacheStats() {
399
+ return GlobalSchemaCache.getInstance().getStats();
400
+ }
401
+ /**
402
+ * Clear global cache
403
+ *
404
+ * **Warning**: This affects all SchemaValidator instances.
405
+ * Primarily for testing.
406
+ */
407
+ static clearGlobalCache() {
408
+ GlobalSchemaCache.getInstance().clear();
409
+ }
410
+ }
411
+ //# sourceMappingURL=SchemaValidator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaValidator.js","sourceRoot":"","sources":["../../src/validation/SchemaValidator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,UAAuD,MAAM,KAAK,CAAC;AAC1E,OAAO,iBAAiB,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEzD;;;;;;;;;;;;GAYG;AACH,MAAM,cAAc,GAAG,UAAmC,CAAC;AAC3D,MAAM,UAAU,GAAG,iBAAkD,CAAC;AAsBtE;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,iBAAiB;IACb,MAAM,CAAC,QAAQ,CAAoB;IAC1B,KAAK,GAAG,IAAI,GAAG,EAA4B,CAAC;IAC5C,GAAG,CAAM;IAE1B;QACE,kDAAkD;QAClD,IAAI,CAAC,GAAG,GAAG,IAAI,cAAc,CAAC;YAC5B,SAAS,EAAE,IAAI,EAAE,qCAAqC;YACtD,OAAO,EAAE,IAAI,EAAE,mCAAmC;YAClD,MAAM,EAAE,KAAK,EAAE,qCAAqC;YACpD,eAAe,EAAE,IAAI,CAAC,8BAA8B;SACrD,CAAC,CAAC;QAEH,iDAAiD;QACjD,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,WA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,OAAO,WAAW,KAAK,CAAC,MAAM,CAAC,MAAM,cAAc,IAAI,EAAE,CAAC;YAC5D,CAAC;YAED,qBAAqB;YACrB,OAAO,GAAG,IAAI,KAAK,OAAO,EAAE,CAAC;QAC/B,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,aAAa;QAClB,OAAO,iBAAiB,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE,CAAC;IACpD,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,gBAAgB;QACrB,iBAAiB,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,CAAC;IAC1C,CAAC;CACF"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Validation Module
3
+ * ==================
4
+ *
5
+ * Schema validation using AJV for MCP JSON Schemas.
6
+ *
7
+ * @module validation
8
+ */
9
+ export { SchemaValidator } from './SchemaValidator.js';
10
+ export type { ValidationResult } from './SchemaValidator.js';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validation/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,YAAY,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Validation Module
3
+ * ==================
4
+ *
5
+ * Schema validation using AJV for MCP JSON Schemas.
6
+ *
7
+ * @module validation
8
+ */
9
+ export { SchemaValidator } from './SchemaValidator.js';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validation/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
package/package.json CHANGED
@@ -1,12 +1,59 @@
1
1
  {
2
2
  "name": "@kadi.build/core",
3
- "version": "0.0.1-alpha.1",
3
+ "version": "0.0.1-alpha.10",
4
4
  "description": "A module that is a comprehensive toolkit for developers integrating with the KADI infrastructure.",
5
- "main": "index.js",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
6
7
  "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ },
13
+ "./types": {
14
+ "import": "./dist/types/index.js",
15
+ "types": "./dist/types/index.d.ts"
16
+ },
17
+ "./types/protocol": {
18
+ "import": "./dist/types/protocol.js",
19
+ "types": "./dist/types/protocol.d.ts"
20
+ },
21
+ "./messages": {
22
+ "import": "./dist/messages/index.js",
23
+ "types": "./dist/messages/index.d.ts"
24
+ },
25
+ "./schemas": {
26
+ "import": "./dist/schemas/index.js",
27
+ "types": "./dist/schemas/index.d.ts"
28
+ },
29
+ "./schemas/mcp": {
30
+ "import": "./dist/schemas/mcp/schema.js",
31
+ "types": "./dist/schemas/mcp/schema.d.ts"
32
+ },
33
+ "./validation": {
34
+ "import": "./dist/validation/index.js",
35
+ "types": "./dist/validation/index.d.ts"
36
+ }
37
+ },
38
+ "files": [
39
+ "dist",
40
+ "README.md",
41
+ "LICENSE"
42
+ ],
7
43
  "scripts": {
44
+ "clean": "rm -rf dist",
45
+ "build": "npm run clean && tsc",
46
+ "build:watch": "tsc --watch",
47
+ "typecheck": "tsc --noEmit",
48
+ "test": "vitest run",
49
+ "test:watch": "vitest",
50
+ "test:ui": "vitest --ui",
51
+ "test:coverage": "vitest run --coverage",
52
+ "lint": "eslint 'src/**/*.{js,ts}'",
53
+ "lint:fix": "eslint 'src/**/*.{js,ts}' --fix",
8
54
  "format": "prettier --write .",
9
- "test": "echo \"Error: no test specified\" && exit 1"
55
+ "format:check": "prettier --check .",
56
+ "prepublishOnly": "npm run build"
10
57
  },
11
58
  "author": "Corey Clark",
12
59
  "contributors": [
@@ -17,10 +64,27 @@
17
64
  ],
18
65
  "license": "MIT",
19
66
  "dependencies": {
67
+ "ajv": "^8.17.1",
68
+ "ajv-formats": "^3.0.1",
69
+ "chalk": "^5.5.0",
70
+ "debug": "^4.4.1",
20
71
  "events": "^3.3.0",
21
- "ws": "^8.16.0"
72
+ "ws": "^8.16.0",
73
+ "zod": "^4.1.5"
22
74
  },
23
75
  "devDependencies": {
24
- "prettier": "^3.6.2"
76
+ "@types/debug": "^4.1.12",
77
+ "@types/node": "^20.19.11",
78
+ "@types/ws": "^8.18.1",
79
+ "@typescript-eslint/eslint-plugin": "^7.18.0",
80
+ "@typescript-eslint/parser": "^7.18.0",
81
+ "@vitest/coverage-v8": "^3.2.4",
82
+ "@vitest/ui": "^3.2.4",
83
+ "eslint": "^8.57.1",
84
+ "eslint-config-prettier": "^9.1.2",
85
+ "eslint-plugin-prettier": "^5.5.4",
86
+ "prettier": "^3.6.2",
87
+ "typescript": "^5.9.2",
88
+ "vitest": "^3.2.4"
25
89
  }
26
90
  }
package/agent.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "name": "kadi-core",
3
- "version": "0.0.1",
4
- "license": "MIT",
5
- "description": "base install ability for kadi",
6
- "repo": "https://gitlab.com/humin-game-lab/agent-abilities/kadi-core.git",
7
- "lib": "https://gitlab.com/humin-game-lab/agent-abilities/kadi-core/-/archive/v0.0.1/kadi-core-v0.0.1.zip",
8
- "abilities": {},
9
-
10
- "scripts": {
11
- "preflight": "echo 'kadi-core v0.0.1 is starting...'",
12
- "setup": "echo 'kadi-core v0.0.1 is ready...'",
13
- "start": "npm install",
14
- "stop": "echo 'kadi-core v0.0.1 is ready...'",
15
- "python": "python3 ./node_modules/kadi-core/ipcInterfaces/pythonAbilityIPC.py",
16
- "rust": "cargo run --bin path/to/rustAbilityIPC"
17
- }
18
- }