agents-library 0.1.0

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 (89) hide show
  1. package/dist/base-agent.d.ts +172 -0
  2. package/dist/base-agent.d.ts.map +1 -0
  3. package/dist/base-agent.js +255 -0
  4. package/dist/base-agent.js.map +1 -0
  5. package/dist/base-bot.d.ts +282 -0
  6. package/dist/base-bot.d.ts.map +1 -0
  7. package/dist/base-bot.js +375 -0
  8. package/dist/base-bot.js.map +1 -0
  9. package/dist/common/result.d.ts +51 -0
  10. package/dist/common/result.d.ts.map +1 -0
  11. package/dist/common/result.js +45 -0
  12. package/dist/common/result.js.map +1 -0
  13. package/dist/common/types.d.ts +57 -0
  14. package/dist/common/types.d.ts.map +1 -0
  15. package/dist/common/types.js +42 -0
  16. package/dist/common/types.js.map +1 -0
  17. package/dist/index.d.ts +94 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +108 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/kadi-event-publisher.d.ts +163 -0
  22. package/dist/kadi-event-publisher.d.ts.map +1 -0
  23. package/dist/kadi-event-publisher.js +286 -0
  24. package/dist/kadi-event-publisher.js.map +1 -0
  25. package/dist/memory/arcadedb-adapter.d.ts +159 -0
  26. package/dist/memory/arcadedb-adapter.d.ts.map +1 -0
  27. package/dist/memory/arcadedb-adapter.js +314 -0
  28. package/dist/memory/arcadedb-adapter.js.map +1 -0
  29. package/dist/memory/file-storage-adapter.d.ts +122 -0
  30. package/dist/memory/file-storage-adapter.d.ts.map +1 -0
  31. package/dist/memory/file-storage-adapter.js +352 -0
  32. package/dist/memory/file-storage-adapter.js.map +1 -0
  33. package/dist/memory/memory-service.d.ts +208 -0
  34. package/dist/memory/memory-service.d.ts.map +1 -0
  35. package/dist/memory/memory-service.js +410 -0
  36. package/dist/memory/memory-service.js.map +1 -0
  37. package/dist/memory/types.d.ts +126 -0
  38. package/dist/memory/types.d.ts.map +1 -0
  39. package/dist/memory/types.js +41 -0
  40. package/dist/memory/types.js.map +1 -0
  41. package/dist/producer-tool-utils.d.ts +474 -0
  42. package/dist/producer-tool-utils.d.ts.map +1 -0
  43. package/dist/producer-tool-utils.js +664 -0
  44. package/dist/producer-tool-utils.js.map +1 -0
  45. package/dist/providers/anthropic-provider.d.ts +160 -0
  46. package/dist/providers/anthropic-provider.d.ts.map +1 -0
  47. package/dist/providers/anthropic-provider.js +527 -0
  48. package/dist/providers/anthropic-provider.js.map +1 -0
  49. package/dist/providers/model-manager-provider.d.ts +91 -0
  50. package/dist/providers/model-manager-provider.d.ts.map +1 -0
  51. package/dist/providers/model-manager-provider.js +355 -0
  52. package/dist/providers/model-manager-provider.js.map +1 -0
  53. package/dist/providers/provider-manager.d.ts +111 -0
  54. package/dist/providers/provider-manager.d.ts.map +1 -0
  55. package/dist/providers/provider-manager.js +337 -0
  56. package/dist/providers/provider-manager.js.map +1 -0
  57. package/dist/providers/types.d.ts +145 -0
  58. package/dist/providers/types.d.ts.map +1 -0
  59. package/dist/providers/types.js +23 -0
  60. package/dist/providers/types.js.map +1 -0
  61. package/dist/shadow-agent-factory.d.ts +623 -0
  62. package/dist/shadow-agent-factory.d.ts.map +1 -0
  63. package/dist/shadow-agent-factory.js +1117 -0
  64. package/dist/shadow-agent-factory.js.map +1 -0
  65. package/dist/types/agent-config.d.ts +307 -0
  66. package/dist/types/agent-config.d.ts.map +1 -0
  67. package/dist/types/agent-config.js +15 -0
  68. package/dist/types/agent-config.js.map +1 -0
  69. package/dist/types/event-schemas.d.ts +358 -0
  70. package/dist/types/event-schemas.d.ts.map +1 -0
  71. package/dist/types/event-schemas.js +188 -0
  72. package/dist/types/event-schemas.js.map +1 -0
  73. package/dist/types/tool-schemas.d.ts +498 -0
  74. package/dist/types/tool-schemas.d.ts.map +1 -0
  75. package/dist/types/tool-schemas.js +457 -0
  76. package/dist/types/tool-schemas.js.map +1 -0
  77. package/dist/utils/logger.d.ts +135 -0
  78. package/dist/utils/logger.d.ts.map +1 -0
  79. package/dist/utils/logger.js +205 -0
  80. package/dist/utils/logger.js.map +1 -0
  81. package/dist/utils/timer.d.ts +186 -0
  82. package/dist/utils/timer.d.ts.map +1 -0
  83. package/dist/utils/timer.js +211 -0
  84. package/dist/utils/timer.js.map +1 -0
  85. package/dist/worker-agent-factory.d.ts +688 -0
  86. package/dist/worker-agent-factory.d.ts.map +1 -0
  87. package/dist/worker-agent-factory.js +1517 -0
  88. package/dist/worker-agent-factory.js.map +1 -0
  89. package/package.json +38 -0
@@ -0,0 +1,457 @@
1
+ /**
2
+ * Tool Schema Type Definitions
3
+ * ==============================
4
+ *
5
+ * Type definitions for KĀDI tool invocation, validation, and error handling.
6
+ * Provides standardized interfaces for tool schemas, invocation results, and error classification.
7
+ *
8
+ * Design Principles:
9
+ * - Discriminated unions for type-safe result handling
10
+ * - Clear error classification for retry logic
11
+ * - Compatible with @kadi.build/core tool registration
12
+ * - Runtime validation via Zod schemas
13
+ *
14
+ * @module tool-schemas
15
+ */
16
+ import { z } from '@kadi.build/core';
17
+ // ============================================================================
18
+ // Error Classification
19
+ // ============================================================================
20
+ /**
21
+ * Error type classification for retry logic
22
+ *
23
+ * Discriminates between transient errors (retry allowed) and permanent errors (fail-fast).
24
+ * Used by circuit breaker and exponential backoff retry logic in BaseBot.
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * function classifyError(error: Error): ErrorType {
29
+ * const message = error.message.toLowerCase();
30
+ *
31
+ * // Transient errors - retry allowed
32
+ * if (message.includes('timeout')) return ErrorType.Transient;
33
+ * if (message.includes('econnrefused')) return ErrorType.Transient;
34
+ * if (message.includes('enotfound')) return ErrorType.Transient;
35
+ * if (message.includes('rate limit')) return ErrorType.Transient;
36
+ *
37
+ * // Permanent errors - fail-fast
38
+ * if (message.includes('unauthorized')) return ErrorType.Permanent;
39
+ * if (message.includes('not found')) return ErrorType.Permanent;
40
+ * if (message.includes('invalid')) return ErrorType.Permanent;
41
+ * if (message.includes('validation')) return ErrorType.Permanent;
42
+ *
43
+ * // Default to permanent to avoid infinite retry loops
44
+ * return ErrorType.Permanent;
45
+ * }
46
+ * ```
47
+ */
48
+ export var ErrorType;
49
+ (function (ErrorType) {
50
+ /**
51
+ * Transient error - may succeed on retry
52
+ *
53
+ * Includes:
54
+ * - Network errors (ECONNREFUSED, ENOTFOUND)
55
+ * - Timeout errors
56
+ * - Rate limit errors (429)
57
+ * - Temporary service unavailable (503)
58
+ */
59
+ ErrorType["Transient"] = "transient";
60
+ /**
61
+ * Permanent error - will not succeed on retry
62
+ *
63
+ * Includes:
64
+ * - Validation errors (400)
65
+ * - Authentication errors (401, 403)
66
+ * - Not found errors (404)
67
+ * - Invalid input errors
68
+ * - Business logic errors
69
+ */
70
+ ErrorType["Permanent"] = "permanent";
71
+ })(ErrorType || (ErrorType = {}));
72
+ // ============================================================================
73
+ // Zod Schemas for Runtime Validation
74
+ // ============================================================================
75
+ /**
76
+ * Zod schema for ToolInvocationSuccess
77
+ */
78
+ export const ToolInvocationSuccessSchema = z.object({
79
+ success: z.literal(true),
80
+ result: z.any()
81
+ });
82
+ /**
83
+ * Zod schema for ToolInvocationFailure
84
+ */
85
+ export const ToolInvocationFailureSchema = z.object({
86
+ success: z.literal(false),
87
+ error: z.instanceof(Error),
88
+ errorType: z.nativeEnum(ErrorType).optional()
89
+ });
90
+ /**
91
+ * Zod schema for ToolInvocationResult
92
+ */
93
+ export const ToolInvocationResultSchema = z.discriminatedUnion('success', [
94
+ ToolInvocationSuccessSchema,
95
+ ToolInvocationFailureSchema
96
+ ]);
97
+ /**
98
+ * Zod schema for ToolInvocationParams
99
+ */
100
+ export const ToolInvocationParamsSchema = z.object({
101
+ targetAgent: z.string().min(1, 'Target agent ID is required'),
102
+ toolName: z.string().min(1, 'Tool name is required'),
103
+ toolInput: z.any(),
104
+ timeout: z.number().positive().optional()
105
+ });
106
+ // ============================================================================
107
+ // Type Guards
108
+ // ============================================================================
109
+ /**
110
+ * Type guard to check if result is a success
111
+ *
112
+ * @param result - Tool invocation result
113
+ * @returns True if result is ToolInvocationSuccess
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * if (isToolInvocationSuccess(result)) {
118
+ * console.log('Success:', result.result);
119
+ * }
120
+ * ```
121
+ */
122
+ export function isToolInvocationSuccess(result) {
123
+ return result.success === true;
124
+ }
125
+ /**
126
+ * Type guard to check if result is a failure
127
+ *
128
+ * @param result - Tool invocation result
129
+ * @returns True if result is ToolInvocationFailure
130
+ *
131
+ * @example
132
+ * ```typescript
133
+ * if (isToolInvocationFailure(result)) {
134
+ * console.error('Failure:', result.error.message);
135
+ * }
136
+ * ```
137
+ */
138
+ export function isToolInvocationFailure(result) {
139
+ return result.success === false;
140
+ }
141
+ /**
142
+ * Classify error as transient or permanent with detailed categorization
143
+ *
144
+ * Analyzes errors from multiple sources (Claude API, KĀDI broker, Node.js) and returns
145
+ * detailed classification for intelligent retry logic. Handles HTTP status codes,
146
+ * Node.js error codes, and error message patterns.
147
+ *
148
+ * **Classification Rules:**
149
+ *
150
+ * **Transient Errors (retry allowed):**
151
+ * - Network errors: ECONNREFUSED, ENOTFOUND, ECONNRESET, ETIMEDOUT
152
+ * - Timeout errors: timeout, ETIMEDOUT
153
+ * - Rate limiting: 429 status code, "rate limit" message (use exponential backoff)
154
+ * - Server errors: 5xx status codes, "service unavailable"
155
+ * - Connection errors: "socket hang up", "connection reset"
156
+ *
157
+ * **Permanent Errors (fail-fast):**
158
+ * - Validation errors: 400 Bad Request, "validation", "invalid"
159
+ * - Authentication: 401 Unauthorized, "unauthorized"
160
+ * - Authorization: 403 Forbidden, "forbidden"
161
+ * - Not found: 404 Not Found, "not found"
162
+ * - Other 4xx client errors (except 429)
163
+ *
164
+ * **Special Cases:**
165
+ * - 429 (Rate Limit): Classified as transient with category 'rate_limit' - use exponential backoff
166
+ * - Unknown errors: Default to permanent to avoid infinite retry loops
167
+ *
168
+ * **Error Source Handling:**
169
+ * - **Claude API errors**: Anthropic SDK error objects with status codes
170
+ * - **KĀDI protocol errors**: Protocol response errors with status/statusCode fields
171
+ * - **Node.js errors**: Error objects with code property (ECONNREFUSED, etc.)
172
+ * - **Generic errors**: Error message pattern matching
173
+ *
174
+ * @param error - Error to classify (Error object, unknown type, or any)
175
+ * @returns Detailed error classification with type, category, message, retryable flag
176
+ *
177
+ * @example
178
+ * ```typescript
179
+ * // Network error (transient)
180
+ * try {
181
+ * await fetch('http://unavailable-service.com');
182
+ * } catch (error) {
183
+ * const classification = classifyToolError(error);
184
+ * // { type: 'transient', category: 'network', message: 'ECONNREFUSED', retryable: true, errorCode: 'ECONNREFUSED' }
185
+ * }
186
+ * ```
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * // Rate limit error (transient with exponential backoff)
191
+ * try {
192
+ * await anthropic.messages.create({ ... });
193
+ * } catch (error) {
194
+ * const classification = classifyToolError(error);
195
+ * // { type: 'transient', category: 'rate_limit', message: 'Rate limit exceeded', retryable: true, statusCode: 429 }
196
+ *
197
+ * if (classification.category === 'rate_limit') {
198
+ * // Use exponential backoff specifically for rate limits
199
+ * await retryWithExponentialBackoff(() => operation(), { baseDelay: 1000, maxDelay: 60000 });
200
+ * }
201
+ * }
202
+ * ```
203
+ *
204
+ * @example
205
+ * ```typescript
206
+ * // Validation error (permanent)
207
+ * try {
208
+ * await invokeTool({ toolName: 'invalid', toolInput: null });
209
+ * } catch (error) {
210
+ * const classification = classifyToolError(error);
211
+ * // { type: 'permanent', category: 'validation', message: 'Invalid tool input', retryable: false, statusCode: 400 }
212
+ *
213
+ * // Don't retry - fail immediately
214
+ * console.error('Validation failed:', classification.message);
215
+ * throw error;
216
+ * }
217
+ * ```
218
+ *
219
+ * @example
220
+ * ```typescript
221
+ * // Generic error handling with classification
222
+ * async function executeWithRetry(operation: () => Promise<any>, maxRetries: number = 3) {
223
+ * let attempt = 0;
224
+ *
225
+ * while (attempt < maxRetries) {
226
+ * try {
227
+ * return await operation();
228
+ * } catch (error) {
229
+ * const classification = classifyToolError(error);
230
+ *
231
+ * console.error(`Attempt ${attempt + 1} failed:`, classification.message);
232
+ *
233
+ * if (!classification.retryable) {
234
+ * // Permanent error - fail immediately
235
+ * throw new Error(`Permanent error (${classification.category}): ${classification.message}`);
236
+ * }
237
+ *
238
+ * // Calculate delay based on error category
239
+ * const delay = classification.category === 'rate_limit'
240
+ * ? Math.pow(2, attempt) * 1000 // Exponential backoff for rate limits
241
+ * : 1000; // Fixed delay for other transient errors
242
+ *
243
+ * console.log(`Retrying in ${delay}ms...`);
244
+ * await new Promise(resolve => setTimeout(resolve, delay));
245
+ *
246
+ * attempt++;
247
+ * }
248
+ * }
249
+ *
250
+ * throw new Error(`Operation failed after ${maxRetries} attempts`);
251
+ * }
252
+ * ```
253
+ */
254
+ export function classifyToolError(error) {
255
+ // Extract error message for pattern matching
256
+ const errorMessage = error instanceof Error ? error.message : String(error);
257
+ const messageLower = errorMessage.toLowerCase();
258
+ // Extract Node.js error code if available
259
+ const errorCode = error?.code;
260
+ // Extract HTTP status code from various sources
261
+ let statusCode;
262
+ // Try to extract from error object (Anthropic SDK, KĀDI protocol)
263
+ if (typeof error?.status === 'number') {
264
+ statusCode = error.status;
265
+ }
266
+ else if (typeof error?.statusCode === 'number') {
267
+ statusCode = error.statusCode;
268
+ }
269
+ else if (typeof error?.response?.status === 'number') {
270
+ statusCode = error.response.status;
271
+ }
272
+ // Try to extract from error message (e.g., "400 Bad Request", "429 Too Many Requests")
273
+ if (!statusCode) {
274
+ const statusMatch = errorMessage.match(/\b([45]\d{2})\b/);
275
+ if (statusMatch) {
276
+ statusCode = parseInt(statusMatch[1], 10);
277
+ }
278
+ }
279
+ // ============================================================================
280
+ // Transient Error Classification (retry allowed)
281
+ // ============================================================================
282
+ // Rate Limit (429) - Special case: use exponential backoff
283
+ if (statusCode === 429 || messageLower.includes('rate limit') || messageLower.includes('too many requests')) {
284
+ return {
285
+ type: 'transient',
286
+ category: 'rate_limit',
287
+ message: 'Rate limit exceeded - use exponential backoff',
288
+ retryable: true,
289
+ statusCode: statusCode || 429,
290
+ errorCode
291
+ };
292
+ }
293
+ // Network Errors (Node.js error codes)
294
+ if (errorCode === 'ECONNREFUSED') {
295
+ return {
296
+ type: 'transient',
297
+ category: 'network',
298
+ message: 'Connection refused - service may be unavailable',
299
+ retryable: true,
300
+ errorCode
301
+ };
302
+ }
303
+ if (errorCode === 'ENOTFOUND') {
304
+ return {
305
+ type: 'transient',
306
+ category: 'network',
307
+ message: 'DNS lookup failed - hostname not found',
308
+ retryable: true,
309
+ errorCode
310
+ };
311
+ }
312
+ if (errorCode === 'ECONNRESET') {
313
+ return {
314
+ type: 'transient',
315
+ category: 'network',
316
+ message: 'Connection reset by peer',
317
+ retryable: true,
318
+ errorCode
319
+ };
320
+ }
321
+ if (errorCode === 'ETIMEDOUT') {
322
+ return {
323
+ type: 'transient',
324
+ category: 'timeout',
325
+ message: 'Connection timed out',
326
+ retryable: true,
327
+ errorCode
328
+ };
329
+ }
330
+ // Timeout Errors (message patterns)
331
+ if (messageLower.includes('timeout') || messageLower.includes('timed out')) {
332
+ return {
333
+ type: 'transient',
334
+ category: 'timeout',
335
+ message: 'Operation timed out',
336
+ retryable: true,
337
+ statusCode,
338
+ errorCode
339
+ };
340
+ }
341
+ // Server Errors (5xx status codes)
342
+ if (statusCode && statusCode >= 500 && statusCode < 600) {
343
+ return {
344
+ type: 'transient',
345
+ category: 'server_error',
346
+ message: `Server error (${statusCode})`,
347
+ retryable: true,
348
+ statusCode,
349
+ errorCode
350
+ };
351
+ }
352
+ // Service Unavailable (503 or message patterns)
353
+ if (messageLower.includes('service unavailable') || messageLower.includes('unavailable')) {
354
+ return {
355
+ type: 'transient',
356
+ category: 'service_unavailable',
357
+ message: 'Service temporarily unavailable',
358
+ retryable: true,
359
+ statusCode: statusCode || 503,
360
+ errorCode
361
+ };
362
+ }
363
+ // Connection Errors (message patterns)
364
+ if (messageLower.includes('socket hang up') || messageLower.includes('connection reset')) {
365
+ return {
366
+ type: 'transient',
367
+ category: 'network',
368
+ message: 'Connection interrupted',
369
+ retryable: true,
370
+ statusCode,
371
+ errorCode
372
+ };
373
+ }
374
+ // ============================================================================
375
+ // Permanent Error Classification (fail-fast)
376
+ // ============================================================================
377
+ // Bad Request (400)
378
+ if (statusCode === 400 || messageLower.includes('bad request')) {
379
+ return {
380
+ type: 'permanent',
381
+ category: 'bad_request',
382
+ message: 'Bad request - check input parameters',
383
+ retryable: false,
384
+ statusCode: statusCode || 400,
385
+ errorCode
386
+ };
387
+ }
388
+ // Validation Errors
389
+ if (messageLower.includes('validation') || messageLower.includes('invalid')) {
390
+ return {
391
+ type: 'permanent',
392
+ category: 'validation',
393
+ message: 'Validation failed - check input data',
394
+ retryable: false,
395
+ statusCode,
396
+ errorCode
397
+ };
398
+ }
399
+ // Authentication (401)
400
+ if (statusCode === 401 || messageLower.includes('unauthorized') || messageLower.includes('authentication')) {
401
+ return {
402
+ type: 'permanent',
403
+ category: 'authentication',
404
+ message: 'Authentication failed - check API key or credentials',
405
+ retryable: false,
406
+ statusCode: statusCode || 401,
407
+ errorCode
408
+ };
409
+ }
410
+ // Authorization (403)
411
+ if (statusCode === 403 || messageLower.includes('forbidden') || messageLower.includes('permission denied')) {
412
+ return {
413
+ type: 'permanent',
414
+ category: 'authorization',
415
+ message: 'Access forbidden - insufficient permissions',
416
+ retryable: false,
417
+ statusCode: statusCode || 403,
418
+ errorCode
419
+ };
420
+ }
421
+ // Not Found (404)
422
+ if (statusCode === 404 || messageLower.includes('not found')) {
423
+ return {
424
+ type: 'permanent',
425
+ category: 'not_found',
426
+ message: 'Resource not found',
427
+ retryable: false,
428
+ statusCode: statusCode || 404,
429
+ errorCode
430
+ };
431
+ }
432
+ // Other 4xx Client Errors (except 429 which is handled above)
433
+ if (statusCode && statusCode >= 400 && statusCode < 500 && statusCode !== 429) {
434
+ return {
435
+ type: 'permanent',
436
+ category: 'bad_request',
437
+ message: `Client error (${statusCode})`,
438
+ retryable: false,
439
+ statusCode,
440
+ errorCode
441
+ };
442
+ }
443
+ // ============================================================================
444
+ // Default Classification (unknown errors)
445
+ // ============================================================================
446
+ // Default to permanent to avoid infinite retry loops
447
+ // Better to fail-fast on unknown errors than retry indefinitely
448
+ return {
449
+ type: 'permanent',
450
+ category: 'unknown',
451
+ message: errorMessage || 'Unknown error',
452
+ retryable: false,
453
+ statusCode,
454
+ errorCode
455
+ };
456
+ }
457
+ //# sourceMappingURL=tool-schemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-schemas.js","sourceRoot":"","sources":["../../src/types/tool-schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,kBAAkB,CAAC;AAErC,+EAA+E;AAC/E,uBAAuB;AACvB,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAN,IAAY,SAuBX;AAvBD,WAAY,SAAS;IACnB;;;;;;;;OAQG;IACH,oCAAuB,CAAA;IAEvB;;;;;;;;;OASG;IACH,oCAAuB,CAAA;AACzB,CAAC,EAvBW,SAAS,KAAT,SAAS,QAuBpB;AAsND,+EAA+E;AAC/E,qCAAqC;AACrC,+EAA+E;AAE/E;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC,MAAM,CAAC;IAClD,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;IACxB,MAAM,EAAE,CAAC,CAAC,GAAG,EAAE;CAChB,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC,MAAM,CAAC;IAClD,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;IACzB,KAAK,EAAE,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC;IAC1B,SAAS,EAAE,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE;CAC9C,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,CAAC,MAA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B,OAAO,EAAE,YAAY,IAAI,eAAe;QACxC,SAAS,EAAE,KAAK;QAChB,UAAU;QACV,SAAS;KACV,CAAC;AACJ,CAAC"}
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Unreal Engine-Style Logger Utility
3
+ * ==================================
4
+ *
5
+ * Provides structured logging with Unreal Engine format:
6
+ * [MODULE_NAME] [HH:MM:SS.mmm] LogLevel: Message
7
+ *
8
+ * This logger is shared across all KĀDI agents (template-agent-typescript,
9
+ * agent-producer, agent-artist, etc.) for consistent log formatting.
10
+ *
11
+ * Usage:
12
+ * ```typescript
13
+ * import { logger, MODULE_AGENT } from 'agents-library';
14
+ *
15
+ * logger.info(MODULE_AGENT, 'Application started');
16
+ * logger.warn(MODULE_SLACK_BOT, 'Circuit breaker open', { timeout: 5000 });
17
+ * logger.error(MODULE_AGENT, 'Connection failed', error);
18
+ * logger.debug(MODULE_TOOLS, 'Tool invocation', { toolName: 'echo' });
19
+ * ```
20
+ *
21
+ * @module logger
22
+ */
23
+ /**
24
+ * Module name constants for structured logging
25
+ * All use kebab-case for consistency with KĀDI naming conventions
26
+ */
27
+ export declare const MODULE_AGENT: "template-agent";
28
+ export declare const MODULE_SLACK_BOT: "slack-bot";
29
+ export declare const MODULE_DISCORD_BOT: "discord-bot";
30
+ export declare const MODULE_TASK_HANDLER: "task-handler";
31
+ export declare const MODULE_TOOLS: "tools";
32
+ /**
33
+ * UnrealLogger class for Unreal Engine-style structured logging
34
+ *
35
+ * Formats all log output as: [MODULE_NAME] [HH:MM:SS.mmm] LogLevel: Message
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const logger = new UnrealLogger();
40
+ * logger.info('my-module', 'Initialization complete');
41
+ * // Output: [my-module] [14:32:45.123] Info: Initialization complete
42
+ * ```
43
+ */
44
+ declare class Logger {
45
+ /**
46
+ * Get current timestamp in HH:MM:SS.mmm format
47
+ *
48
+ * @returns Formatted timestamp string with millisecond precision
49
+ */
50
+ private getTimestamp;
51
+ /**
52
+ * Determine if colors should be used in log output
53
+ *
54
+ * Colors are enabled only when:
55
+ * 1. stdout is a TTY (interactive terminal)
56
+ * 2. NO_COLOR environment variable is not set
57
+ *
58
+ * This respects the NO_COLOR standard (https://no-color.org/)
59
+ * which provides a universal way to disable colorized output.
60
+ *
61
+ * @returns true if colors should be applied, false for plain text
62
+ */
63
+ private shouldUseColors;
64
+ /**
65
+ * Format log message with module name and timestamp
66
+ *
67
+ * @param module - Module name (e.g., 'template-agent', 'slack-bot')
68
+ * @param level - Log level (Info, Warning, Error, Debug)
69
+ * @param message - Log message
70
+ * @param elapsedTime - Elapsed time suffix (e.g., '+5s', '+3m') - always included
71
+ * @param color - Optional ANSI color code to apply to module bracket, level indicator, and elapsed time
72
+ * @returns Formatted log string with selective coloring: <color>[module]<reset> [timestamp] <color>level<reset>: <white>message<reset> <color>elapsedTime<reset>
73
+ */
74
+ private formatMessage;
75
+ /**
76
+ * Log informational message
77
+ *
78
+ * Used for normal operational events (startup, connections, completions)
79
+ *
80
+ * @param module - Module name
81
+ * @param message - Log message
82
+ * @param elapsedTime - Elapsed time suffix (e.g., '+5s', '+3m')
83
+ * @param data - Optional data to log (will be logged on separate line)
84
+ */
85
+ info(module: string, message: string, elapsedTime: string, data?: any): void;
86
+ /**
87
+ * Log warning message
88
+ *
89
+ * Used for potentially problematic situations (circuit breaker open, retries, timeouts)
90
+ *
91
+ * @param module - Module name
92
+ * @param message - Log message
93
+ * @param elapsedTime - Elapsed time suffix (e.g., '+5s', '+3m')
94
+ * @param data - Optional data to log
95
+ */
96
+ warn(module: string, message: string, elapsedTime: string, data?: any): void;
97
+ /**
98
+ * Log error message
99
+ *
100
+ * Used for error conditions and exceptions
101
+ *
102
+ * @param module - Module name
103
+ * @param message - Log message
104
+ * @param elapsedTime - Elapsed time suffix (e.g., '+5s', '+3m')
105
+ * @param error - Optional error object or error message string
106
+ * @param data - Optional additional data to log
107
+ */
108
+ error(module: string, message: string, elapsedTime: string, error?: Error | string, data?: any): void;
109
+ /**
110
+ * Log debug message
111
+ *
112
+ * Used for detailed diagnostic information during development
113
+ *
114
+ * @param module - Module name
115
+ * @param message - Log message
116
+ * @param elapsedTime - Elapsed time suffix (e.g., '+5s', '+3m')
117
+ * @param data - Optional data to log
118
+ */
119
+ debug(module: string, message: string, elapsedTime: string, data?: any): void;
120
+ }
121
+ /**
122
+ * Singleton logger instance
123
+ *
124
+ * Export as singleton to ensure consistent timestamp generation and
125
+ * single source of truth for logging configuration across all agents.
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * import { logger, MODULE_AGENT } from 'agents-library';
130
+ * logger.info(MODULE_AGENT, 'Application started');
131
+ * ```
132
+ */
133
+ export declare const logger: Logger;
134
+ export {};
135
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAG,gBAAyB,CAAC;AACtD,eAAO,MAAM,gBAAgB,EAAG,WAAoB,CAAC;AACrD,eAAO,MAAM,kBAAkB,EAAG,aAAsB,CAAC;AACzD,eAAO,MAAM,mBAAmB,EAAG,cAAuB,CAAC;AAC3D,eAAO,MAAM,YAAY,EAAG,OAAgB,CAAC;AAoB7C;;;;;;;;;;;GAWG;AACH,cAAM,MAAM;IACR;;;;OAIG;IACH,OAAO,CAAC,YAAY;IAUpB;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,eAAe;IAIvB;;;;;;;;;OASG;IACH,OAAO,CAAC,aAAa;IAkBrB;;;;;;;;;OASG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;IAO5E;;;;;;;;;OASG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MA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