@x12i/ai-gateway 7.9.2 → 9.0.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 (66) hide show
  1. package/README.md +107 -94
  2. package/dist/activity-manager.d.ts +3 -1
  3. package/dist/activity-manager.js +48 -17
  4. package/dist/content-normalizer/content-normalizer.d.ts +2 -1
  5. package/dist/content-normalizer/content-normalizer.js +5 -5
  6. package/dist/flex-md-loader.d.ts +2 -1
  7. package/dist/flex-md-loader.js +18 -15
  8. package/dist/gateway-config.d.ts +4 -4
  9. package/dist/gateway-config.js +21 -25
  10. package/dist/gateway-conversion.js +2 -2
  11. package/dist/gateway-log-meta.d.ts +15 -0
  12. package/dist/gateway-log-meta.js +36 -0
  13. package/dist/gateway-memory.js +6 -6
  14. package/dist/gateway-messages.js +4 -4
  15. package/dist/gateway-meta.d.ts +3 -1
  16. package/dist/gateway-meta.js +9 -2
  17. package/dist/gateway-utils.js +9 -9
  18. package/dist/gateway-validation.js +9 -0
  19. package/dist/gateway.js +32 -33
  20. package/dist/index.d.ts +3 -2
  21. package/dist/index.js +2 -1
  22. package/dist/instruction-optimizer.d.ts +6 -1
  23. package/dist/instruction-optimizer.js +10 -3
  24. package/dist/instructions-parser.d.ts +2 -1
  25. package/dist/instructions-parser.js +2 -2
  26. package/dist/logger-factory.js +12 -1
  27. package/dist/message-builder.js +19 -19
  28. package/dist/request-report-generator.js +1 -1
  29. package/dist/template-parser.d.ts +3 -1
  30. package/dist/template-parser.js +3 -2
  31. package/dist/troubleshooting-helper.d.ts +1 -1
  32. package/dist/troubleshooting-helper.js +2 -2
  33. package/dist/types.d.ts +16 -10
  34. package/dist-cjs/activity-manager.cjs +48 -17
  35. package/dist-cjs/activity-manager.d.ts +3 -1
  36. package/dist-cjs/content-normalizer/content-normalizer.cjs +5 -5
  37. package/dist-cjs/content-normalizer/content-normalizer.d.ts +2 -1
  38. package/dist-cjs/flex-md-loader.cjs +18 -15
  39. package/dist-cjs/flex-md-loader.d.ts +2 -1
  40. package/dist-cjs/gateway-config.cjs +21 -25
  41. package/dist-cjs/gateway-config.d.ts +4 -4
  42. package/dist-cjs/gateway-conversion.cjs +2 -2
  43. package/dist-cjs/gateway-log-meta.cjs +41 -0
  44. package/dist-cjs/gateway-log-meta.d.ts +15 -0
  45. package/dist-cjs/gateway-memory.cjs +6 -6
  46. package/dist-cjs/gateway-messages.cjs +4 -4
  47. package/dist-cjs/gateway-meta.cjs +9 -2
  48. package/dist-cjs/gateway-meta.d.ts +3 -1
  49. package/dist-cjs/gateway-utils.cjs +9 -9
  50. package/dist-cjs/gateway-validation.cjs +9 -0
  51. package/dist-cjs/gateway.cjs +31 -32
  52. package/dist-cjs/index.cjs +6 -1
  53. package/dist-cjs/index.d.ts +3 -2
  54. package/dist-cjs/instruction-optimizer.cjs +10 -3
  55. package/dist-cjs/instruction-optimizer.d.ts +6 -1
  56. package/dist-cjs/instructions-parser.cjs +2 -2
  57. package/dist-cjs/instructions-parser.d.ts +2 -1
  58. package/dist-cjs/logger-factory.cjs +12 -1
  59. package/dist-cjs/message-builder.cjs +19 -19
  60. package/dist-cjs/request-report-generator.cjs +1 -1
  61. package/dist-cjs/template-parser.cjs +3 -2
  62. package/dist-cjs/template-parser.d.ts +3 -1
  63. package/dist-cjs/troubleshooting-helper.cjs +2 -2
  64. package/dist-cjs/troubleshooting-helper.d.ts +1 -1
  65. package/dist-cjs/types.d.ts +16 -10
  66. package/package.json +3 -3
@@ -600,12 +600,12 @@ function formatDiagnostic(diagnostic) {
600
600
  /**
601
601
  * Quick validation helper - throws if invalid
602
602
  */
603
- function assertValidAIRequest(request) {
603
+ function assertValidAIRequest(request, logger) {
604
604
  const validation = validateAIRequest(request);
605
605
  if (!validation.valid) {
606
606
  throw new Error(`AIRequest validation failed:\n${validation.errors.join('\n')}`);
607
607
  }
608
608
  if (validation.warnings.length > 0) {
609
- console.warn('AIRequest validation warnings:', validation.warnings);
609
+ logger?.warn('AIRequest validation warnings', { warnings: validation.warnings });
610
610
  }
611
611
  }
@@ -120,4 +120,4 @@ export declare function formatDiagnostic(diagnostic: DiagnosticInfo): string;
120
120
  /**
121
121
  * Quick validation helper - throws if invalid
122
122
  */
123
- export declare function assertValidAIRequest(request: Partial<AIRequest>): void;
123
+ export declare function assertValidAIRequest(request: Partial<AIRequest>, logger?: import('@x12i/logxer').Logxer): void;
@@ -32,11 +32,18 @@ export type ActivityIdentity = {
32
32
  };
33
33
  /** Gateway-level request correlation ID. */
34
34
  aiRequestId: string;
35
- /** @deprecated Use aiRequestId. Kept only for backward compatibility. */
36
- jobId?: string;
35
+ /**
36
+ * Upstream job identifier — must be supplied on `request.identity` only.
37
+ * The gateway copies this value as-is; it never generates or mutates it.
38
+ */
39
+ jobId: string;
37
40
  jobTypeId?: string;
38
41
  agentId: string;
39
- taskId?: string;
42
+ /**
43
+ * Upstream task identifier — must be supplied on `request.identity` only.
44
+ * The gateway copies this value as-is; it never generates or mutates it.
45
+ */
46
+ taskId: string;
40
47
  taskTypeId?: string;
41
48
  /** Graph/node linkage (optional, used by activity identity grouping). */
42
49
  graphId?: string;
@@ -413,7 +420,7 @@ export interface GatewayConfig extends Omit<RouterConfig, 'defaultEngine' | 'log
413
420
  * Extends LLMRequest but omits 'messages' and 'input' to allow custom message handling
414
421
  * and make input optional (router may require it, but gateway allows it to be optional)
415
422
  */
416
- interface BaseLLMRequest extends Omit<LLMRequest, 'messages' | 'input'> {
423
+ interface BaseLLMRequest extends Omit<LLMRequest, 'messages' | 'input' | 'request' | 'mode'> {
417
424
  /**
418
425
  * AI request ID - Required for all invocations and activity tracking
419
426
  */
@@ -422,15 +429,14 @@ interface BaseLLMRequest extends Omit<LLMRequest, 'messages' | 'input'> {
422
429
  jobId?: string;
423
430
  /**
424
431
  * Optional top-level run/session id for Activix. Prefer `identity.sessionId`; if both are set they must match.
425
- * When omitted, `ActivityManager` resolves session from `identity.sessionId`, then `jobId`, then `aiRequestId`.
432
+ * When omitted, `ActivityManager` resolves session from `identity.sessionId`, then `identity.jobId`, then `aiRequestId`.
426
433
  */
427
434
  sessionId?: string;
428
435
  /**
429
- * Optional identity object used for upstream linkage (forwarded through the request).
430
- * May be partial; may include product-specific keys beyond `ActivityIdentity`. When omitted,
431
- * the gateway normalizes and attaches a full envelope (`ensureGatewayRequestIdentity` / activity tracking).
436
+ * Mandatory runtime identity from the upstream client (job/task correlation, Activix `runContext`).
437
+ * Must include at least `jobId` and `taskId` as non-empty strings; the gateway never invents these.
432
438
  */
433
- identity?: ActivityIdentity & Record<string, unknown>;
439
+ identity: ActivityIdentity & Record<string, unknown>;
434
440
  /**
435
441
  * Job type ID (optional) - Short ID or hash to identify recurring job types
436
442
  * Best practice: Use MD5 hash of the job type string for consistent job identification
@@ -459,7 +465,7 @@ interface BaseLLMRequest extends Omit<LLMRequest, 'messages' | 'input'> {
459
465
  */
460
466
  instructions: string;
461
467
  /**
462
- * Task ID (optional)
468
+ * @deprecated Prefer `identity.taskId`. The gateway does not copy this into `identity`.
463
469
  */
464
470
  taskId?: string;
465
471
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@x12i/ai-gateway",
3
- "version": "7.9.2",
3
+ "version": "9.0.0",
4
4
  "description": "AI Gateway - Unified interface for LLM provider routing and management",
5
5
  "type": "module",
6
6
  "exports": {
@@ -64,8 +64,8 @@
64
64
  "@x12i/rendrix": "^4.2.0",
65
65
  "@aws-sdk/s3-request-presigner": "^3.953.0",
66
66
  "@x12i/env": "^4.0.1",
67
- "@x12i/logxer": "^4.0.2",
68
- "@x12i/activix": "^6.5.0",
67
+ "@x12i/logxer": "^4.2.1",
68
+ "@x12i/activix": "^6.5.1",
69
69
  "@x12i/flex-md": "^4.8.0"
70
70
  },
71
71
  "devDependencies": {