@x12i/ai-gateway 9.0.9 → 9.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 (38) hide show
  1. package/README.md +897 -998
  2. package/dist/activity-manager.js +46 -6
  3. package/dist/config/activity-tracking-config.d.ts +2 -1
  4. package/dist/config/activity-tracking-config.js +3 -2
  5. package/dist/gateway-memory.d.ts +1 -2
  6. package/dist/gateway-memory.js +1 -15
  7. package/dist/gateway-meta.js +3 -0
  8. package/dist/gateway-utils.d.ts +9 -1
  9. package/dist/gateway-utils.js +79 -18
  10. package/dist/gateway-validation.d.ts +3 -3
  11. package/dist/gateway-validation.js +10 -1
  12. package/dist/gateway.d.ts +2 -2
  13. package/dist/gateway.js +20 -3
  14. package/dist/index.d.ts +2 -2
  15. package/dist/instruction-optimizer.js +3 -0
  16. package/dist/runtime-objects.d.ts +2 -13
  17. package/dist/troubleshooting-helper.d.ts +0 -3
  18. package/dist/troubleshooting-helper.js +99 -20
  19. package/dist/types.d.ts +39 -89
  20. package/dist-cjs/activity-manager.cjs +45 -5
  21. package/dist-cjs/config/activity-tracking-config.cjs +3 -2
  22. package/dist-cjs/config/activity-tracking-config.d.ts +2 -1
  23. package/dist-cjs/gateway-memory.cjs +1 -15
  24. package/dist-cjs/gateway-memory.d.ts +1 -2
  25. package/dist-cjs/gateway-meta.cjs +3 -0
  26. package/dist-cjs/gateway-utils.cjs +81 -18
  27. package/dist-cjs/gateway-utils.d.ts +9 -1
  28. package/dist-cjs/gateway-validation.cjs +10 -1
  29. package/dist-cjs/gateway-validation.d.ts +3 -3
  30. package/dist-cjs/gateway.cjs +19 -2
  31. package/dist-cjs/gateway.d.ts +2 -2
  32. package/dist-cjs/index.d.ts +2 -2
  33. package/dist-cjs/instruction-optimizer.cjs +3 -0
  34. package/dist-cjs/runtime-objects.d.ts +2 -13
  35. package/dist-cjs/troubleshooting-helper.cjs +99 -20
  36. package/dist-cjs/troubleshooting-helper.d.ts +0 -3
  37. package/dist-cjs/types.d.ts +39 -89
  38. package/package.json +2 -2
@@ -172,18 +172,27 @@ function validateSingleObjectType(objType, context, index) {
172
172
  /**
173
173
  * Validates AIRequest structure
174
174
  */
175
+ const GATEWAY_ACTION_TYPES_DIAG = ['skill', 'preSkill', 'postSkill'];
175
176
  export function validateAIRequest(request) {
176
177
  const errors = [];
177
178
  const warnings = [];
178
- // Validate base fields
179
- if (!request.jobId) {
180
- errors.push('jobId is required');
179
+ const identityJobId = request.identity && typeof request.identity === 'object' ? request.identity.jobId : undefined;
180
+ if (!identityJobId && !request.jobId) {
181
+ errors.push('identity.jobId is required (legacy top-level jobId is deprecated)');
181
182
  }
182
183
  if (!request.agentId) {
183
184
  errors.push('agentId is required');
184
185
  }
186
+ if (!request.actionType ||
187
+ !GATEWAY_ACTION_TYPES_DIAG.includes(request.actionType)) {
188
+ errors.push('actionType is required and must be skill, preSkill, or postSkill');
189
+ }
190
+ const actionRefTrim = typeof request.actionRef === 'string' ? request.actionRef.trim() : '';
191
+ if (!actionRefTrim) {
192
+ errors.push('actionRef is required (non-empty string, e.g. skill id)');
193
+ }
185
194
  if (!request.instructions) {
186
- warnings.push('instructions is optional (system-context will be used as fallback)');
195
+ errors.push('instructions is required');
187
196
  }
188
197
  if (!request.prompt) {
189
198
  errors.push('Prompt is required (input field has been removed - use workingMemory.input instead)');
@@ -434,11 +443,23 @@ export function supportsJSONMode(provider, model) {
434
443
  * Creates a test AIRequest with minimal valid structure
435
444
  */
436
445
  export function createTestAIRequest(overrides) {
437
- return {
438
- jobId: 'test-job-' + Date.now(),
446
+ const aiRequestId = 'test-ai-req-' + Date.now();
447
+ const base = {
448
+ aiRequestId,
439
449
  agentId: 'test-agent',
450
+ actionType: 'skill',
451
+ actionRef: 'tests/createTestAIRequest',
440
452
  instructions: 'Test instructions',
441
- input: 'Test input',
453
+ prompt: '{{input}}',
454
+ workingMemory: { input: 'Test input' },
455
+ identity: {
456
+ sessionId: `session-${aiRequestId}`,
457
+ instance: { instanceId: 'test-agent', type: 'test' },
458
+ aiRequestId,
459
+ jobId: `job-${aiRequestId}`,
460
+ agentId: 'test-agent',
461
+ taskId: `task-${aiRequestId}`
462
+ },
442
463
  config: {
443
464
  model: 'gpt-4o',
444
465
  provider: 'openai'
@@ -455,20 +476,33 @@ export function createTestAIRequest(overrides) {
455
476
  },
456
477
  ...overrides
457
478
  };
479
+ return base;
458
480
  }
459
481
  /**
460
482
  * Creates test cases for validation
461
483
  */
462
484
  export function createValidationTestCases() {
485
+ const sampleIdentity = (jobId, agentId) => ({
486
+ sessionId: `session-${jobId}`,
487
+ instance: { instanceId: agentId, type: 'test' },
488
+ aiRequestId: `ai-${jobId}`,
489
+ jobId,
490
+ agentId,
491
+ taskId: `task-${jobId}`
492
+ });
463
493
  return [
464
494
  {
465
495
  name: 'Valid minimal request',
466
496
  request: {
467
- jobId: 'test',
497
+ aiRequestId: 'ai-valid-min',
468
498
  agentId: 'agent-1',
499
+ actionType: 'skill',
500
+ actionRef: 'validation/minimal',
501
+ identity: sampleIdentity('test', 'agent-1'),
469
502
  instructions: 'Test',
470
503
  prompt: 'test.prompt',
471
- workingMemory: { input: 'Test' }
504
+ workingMemory: { input: 'Test' },
505
+ config: { model: 'gpt-4o', provider: 'openai' }
472
506
  },
473
507
  shouldFail: false,
474
508
  expectedErrors: []
@@ -476,8 +510,11 @@ export function createValidationTestCases() {
476
510
  {
477
511
  name: 'Valid request with config',
478
512
  request: {
479
- jobId: 'test',
513
+ aiRequestId: 'ai-valid-cfg',
480
514
  agentId: 'agent-1',
515
+ actionType: 'skill',
516
+ actionRef: 'validation/config',
517
+ identity: sampleIdentity('test', 'agent-1'),
481
518
  instructions: 'Test',
482
519
  prompt: 'test.prompt',
483
520
  workingMemory: { input: 'Test' },
@@ -490,23 +527,40 @@ export function createValidationTestCases() {
490
527
  expectedErrors: []
491
528
  },
492
529
  {
493
- name: 'Missing jobId',
530
+ name: 'Missing identity.jobId',
494
531
  request: {
532
+ aiRequestId: 'ai-no-job',
495
533
  agentId: 'agent-1',
534
+ actionType: 'skill',
535
+ actionRef: 'validation/x',
536
+ identity: {
537
+ sessionId: 's',
538
+ instance: { instanceId: 'agent-1', type: 'test' },
539
+ aiRequestId: 'ai-no-job',
540
+ jobId: '',
541
+ agentId: 'agent-1',
542
+ taskId: 't'
543
+ },
496
544
  instructions: 'Test',
497
545
  prompt: 'test.prompt',
498
- workingMemory: { input: 'Test' }
546
+ workingMemory: { input: 'Test' },
547
+ config: { model: 'gpt-4o', provider: 'openai' }
499
548
  },
500
549
  shouldFail: true,
501
- expectedErrors: ['jobId is required']
550
+ expectedErrors: ['identity.jobId is required (legacy top-level jobId is deprecated)']
502
551
  },
503
552
  {
504
553
  name: 'Missing agentId',
505
554
  request: {
506
- jobId: 'test',
555
+ aiRequestId: 'ai-no-agent',
556
+ actionType: 'skill',
557
+ actionRef: 'validation/x',
558
+ identity: sampleIdentity('test', 'agent-1'),
507
559
  instructions: 'Test',
508
560
  prompt: 'test.prompt',
509
- workingMemory: { input: 'Test' }
561
+ workingMemory: { input: 'Test' },
562
+ config: { model: 'gpt-4o', provider: 'openai' }
563
+ // intentional: no top-level agentId
510
564
  },
511
565
  shouldFail: true,
512
566
  expectedErrors: ['agentId is required']
@@ -514,10 +568,14 @@ export function createValidationTestCases() {
514
568
  {
515
569
  name: 'Missing instructions',
516
570
  request: {
517
- jobId: 'test',
571
+ aiRequestId: 'ai-no-inst',
518
572
  agentId: 'agent-1',
573
+ actionType: 'skill',
574
+ actionRef: 'validation/x',
575
+ identity: sampleIdentity('test', 'agent-1'),
519
576
  prompt: 'test.prompt',
520
- workingMemory: { input: 'Test' }
577
+ workingMemory: { input: 'Test' },
578
+ config: { model: 'gpt-4o', provider: 'openai' }
521
579
  },
522
580
  shouldFail: true,
523
581
  expectedErrors: ['instructions is required']
@@ -525,12 +583,33 @@ export function createValidationTestCases() {
525
583
  {
526
584
  name: 'Missing prompt',
527
585
  request: {
528
- jobId: 'test',
586
+ aiRequestId: 'ai-no-prompt',
529
587
  agentId: 'agent-1',
530
- instructions: 'Test'
588
+ actionType: 'skill',
589
+ actionRef: 'validation/x',
590
+ identity: sampleIdentity('test', 'agent-1'),
591
+ instructions: 'Test',
592
+ workingMemory: { input: 'Test' },
593
+ config: { model: 'gpt-4o', provider: 'openai' }
594
+ },
595
+ shouldFail: true,
596
+ expectedErrors: ['Prompt is required (input field has been removed - use workingMemory.input instead)']
597
+ },
598
+ {
599
+ name: 'Missing actionRef',
600
+ request: {
601
+ aiRequestId: 'ai-no-ref',
602
+ agentId: 'agent-1',
603
+ actionType: 'skill',
604
+ actionRef: ' ',
605
+ identity: sampleIdentity('test', 'agent-1'),
606
+ instructions: 'Test',
607
+ prompt: 'p',
608
+ workingMemory: { input: 'Test' },
609
+ config: { model: 'gpt-4o', provider: 'openai' }
531
610
  },
532
611
  shouldFail: true,
533
- expectedErrors: ['input is required']
612
+ expectedErrors: ['actionRef is required (non-empty string, e.g. skill id)']
534
613
  }
535
614
  ];
536
615
  }
package/dist/types.d.ts CHANGED
@@ -22,7 +22,22 @@ export interface DiagnosticsOptions {
22
22
  * Implementations must size-cap any raw payload included.
23
23
  */
24
24
  includeRawProviderPayload?: boolean;
25
+ /**
26
+ * When false, Activix activity completion omits `response.content.fullResponse` (large provider blob).
27
+ * When true or omitted, the full payload is stored (subject to `activityFullResponseMaxChars`).
28
+ */
29
+ includeFullProviderResponseInActivity?: boolean;
30
+ /**
31
+ * Max serialized length for `fullResponse` on activity records when included (JSON string length).
32
+ * Default applied in gateway when omitted.
33
+ */
34
+ activityFullResponseMaxChars?: number;
25
35
  }
36
+ /**
37
+ * Classifies the gateway invocation for tracing and Activix (`runContext`).
38
+ * Mandatory on {@link AIInvokeRequest} (`AIGateway.invoke`).
39
+ */
40
+ export type GatewayActionType = 'skill' | 'preSkill' | 'postSkill';
26
41
  export type GatewayTraceRequestIds = {
27
42
  /** Stable alias of gateway aiRequestId (always set when trace enabled). */
28
43
  gatewayAiRequestId: string;
@@ -111,6 +126,14 @@ export type ActivityIdentity = {
111
126
  coreSkillId?: string;
112
127
  masterSkillId?: string;
113
128
  masterSkillActivityId?: string;
129
+ /**
130
+ * From {@link AIInvokeRequest.actionType} when present (gateway.invoke); copied into runContext for Activix.
131
+ */
132
+ actionType?: GatewayActionType;
133
+ /**
134
+ * From {@link AIInvokeRequest.actionRef} when present; copied into runContext for Activix.
135
+ */
136
+ actionRef?: string;
114
137
  };
115
138
  /** Re-export parser template options for gateway consumers (MUST/optional protocol, subPathSearch, etc.). */
116
139
  export type { TemplateRenderOptions } from '@x12i/rendrix';
@@ -566,14 +589,6 @@ interface BaseLLMRequest extends Omit<LLMRequest, 'messages' | 'input' | 'reques
566
589
  * Added as system message between instructions and prompt
567
590
  */
568
591
  context?: string;
569
- /**
570
- * Task configuration (optional) - Control template behavior and conditional rendering
571
- * @deprecated taskConfig is no longer used by Rendrix 3.0.0+
572
- * Kept for backward compatibility only - will be ignored
573
- */
574
- taskConfig?: {
575
- includeThoughts?: boolean;
576
- };
577
592
  /**
578
593
  * Working memory (optional) - Affects all template parsing
579
594
  * Passed to Rendrix (v4+) for template variable substitution.
@@ -587,16 +602,6 @@ interface BaseLLMRequest extends Omit<LLMRequest, 'messages' | 'input' | 'reques
587
602
  * the full list or only set `enabled` and inherit `roots` from the gateway default merge.
588
603
  */
589
604
  templateRenderOptions?: TemplateRenderOptions;
590
- /**
591
- * Template tokens (optional) - Tier 1 (highest priority) token values
592
- * These tokens are passed directly as arguments and override all other memory sources
593
- * Common tokens: taskDescription, input (from workingMemory.input), role
594
- * Example: { taskDescription: "Extract emails", input: "user@example.com", role: "user" }
595
- * Note: The `input` field has been removed. Use workingMemory.input instead.
596
- */
597
- templateTokens?: {
598
- [key: string]: string | number | boolean | object | object[];
599
- };
600
605
  /**
601
606
  * Messages array - Optional, can be used instead of instructions/prompt
602
607
  * If provided, will be appended as-is after built messages; instructions template text is still parsed for the system message when present
@@ -643,28 +648,6 @@ interface BaseLLMRequest extends Omit<LLMRequest, 'messages' | 'input' | 'reques
643
648
  * Can be a single type (string) or multiple types (array)
644
649
  */
645
650
  inferenceType?: string | string[];
646
- /**
647
- * Enable output schema validation (optional)
648
- * When true, validates parsed output against schema from instruction metadata or outputs library
649
- * @default false
650
- */
651
- validateOutputSchema?: boolean;
652
- /**
653
- * Enable strict validation mode (optional)
654
- * When true, validation errors will throw exceptions instead of warnings
655
- * @default false
656
- */
657
- strictValidation?: boolean;
658
- /**
659
- * Response transformation hooks (optional)
660
- * Allows transforming responses at different stages of processing
661
- */
662
- transformations?: ResponseTransformationConfig;
663
- /**
664
- * Parse options for outputs library (optional)
665
- * Used when inferenceType is provided for parsing inference outputs
666
- */
667
- parseOptions?: Record<string, unknown>;
668
651
  /**
669
652
  * Optional diagnostics controls. When omitted or mode != 'trace', the gateway must not
670
653
  * attach heavy diagnostic objects or raw provider payloads.
@@ -682,7 +665,7 @@ interface BaseLLMRequest extends Omit<LLMRequest, 'messages' | 'input' | 'reques
682
665
  * Minimum: instructions + prompt (prompt is required for user message)
683
666
  *
684
667
  * Note: objectTypes is NOT supported in ChatRequest.
685
- * Use AIRequest with invoke() method for structured output requests.
668
+ * Use {@link AIInvokeRequest} with invoke() for structured output requests.
686
669
  */
687
670
  export interface ChatRequest extends BaseLLMRequest {
688
671
  /**
@@ -714,18 +697,19 @@ export interface StructuredTextSpec {
714
697
  formatHint?: string;
715
698
  }
716
699
  /**
717
- * AI request for structured output requests
718
- * Used exclusively with invoke() method for requests requiring structured output
700
+ * Payload for {@link AIGateway.invoke}: structured / skill flows with mandatory action classification.
719
701
  *
720
- * Mandatory:
721
- * - aiRequestId: Required for activity tracking
722
- * - agentId: Required to identify the agent
723
- * - instructions: Required (template text)
724
- * - primaryObjectType OR flexMdFormat: Required for structured output
725
- * * primaryObjectType: Standard/custom object type (requires outputs library)
726
- * * flexMdFormat: Direct flex-md format specification (no outputs library needed)
702
+ * Recorded on {@link ActivityIdentity} (`runContext`) and activity roots for Activix.
727
703
  */
728
- export interface AIRequest extends BaseLLMRequest {
704
+ export interface AIInvokeRequest extends BaseLLMRequest {
705
+ /**
706
+ * Invocation kind: main skill vs pre/post hooks around skill execution.
707
+ */
708
+ actionType: GatewayActionType;
709
+ /**
710
+ * Stable reference for the action (e.g. `skills/my-skill`).
711
+ */
712
+ actionRef: string;
729
713
  /**
730
714
  * Encrypted reasoning items for conversation continuity
731
715
  * Only include reasoning.encrypted items from previous responses
@@ -739,10 +723,6 @@ export interface AIRequest extends BaseLLMRequest {
739
723
  data?: string;
740
724
  summary?: any[];
741
725
  }>;
742
- /**
743
- * Skill execution tracking fields
744
- * Used when executing skills (instruction keys starting with 'skills/')
745
- */
746
726
  /**
747
727
  * Master skill activity ID - The parent skill activity's ID (when a skill calls another skill)
748
728
  * When a skill executes and calls another skill, the parent skill's activityId becomes
@@ -761,6 +741,10 @@ export interface AIRequest extends BaseLLMRequest {
761
741
  */
762
742
  masterSkillId?: string;
763
743
  }
744
+ /**
745
+ * @deprecated Prefer {@link AIInvokeRequest}; alias kept for existing imports.
746
+ */
747
+ export type AIRequest = AIInvokeRequest;
764
748
  /**
765
749
  * Enhanced response with comprehensive metadata and generic type support
766
750
  *
@@ -1241,38 +1225,4 @@ export interface ValidationRule {
1241
1225
  */
1242
1226
  message?: string;
1243
1227
  }
1244
- /**
1245
- * Response transformation hooks configuration
1246
- * Allows transforming responses at different stages of processing
1247
- */
1248
- export interface ResponseTransformationConfig {
1249
- /**
1250
- * Transform raw text before parsing
1251
- * @param rawText - Raw text from LLM response
1252
- * @param metadata - Request metadata (jobId, agentId, etc.)
1253
- * @returns Transformed raw text
1254
- */
1255
- preParse?: (rawText: string, metadata: any) => string;
1256
- /**
1257
- * Transform parsed content after parsing
1258
- * @param parsed - Parsed content (object/array)
1259
- * @param metadata - Request metadata
1260
- * @returns Transformed parsed content
1261
- */
1262
- postParse?: (parsed: any, metadata: any) => any;
1263
- /**
1264
- * Transform parsed content before validation
1265
- * @param parsed - Parsed content
1266
- * @param schema - JSON schema (if available)
1267
- * @returns Transformed parsed content
1268
- */
1269
- preValidate?: (parsed: any, schema: any) => any;
1270
- /**
1271
- * Transform validated content after validation
1272
- * @param validated - Validated content
1273
- * @param metadata - Request metadata
1274
- * @returns Transformed validated content
1275
- */
1276
- postValidate?: (validated: any, metadata: any) => any;
1277
- }
1278
1228
  export type { LLMRequest, LLMResponse };
@@ -165,6 +165,17 @@ function mergeGatewayActivityIdentity(request, aiRequestId, extras) {
165
165
  merged.aiRequestId = aiRequestId;
166
166
  merged.jobId = upstreamJobId;
167
167
  merged.taskId = upstreamTaskId;
168
+ // gateway.invoke (AIInvokeRequest): request root is canonical for Activix runContext.
169
+ if ('actionType' in request && 'actionRef' in request) {
170
+ const inv = request;
171
+ if (inv.actionType) {
172
+ merged.actionType = inv.actionType;
173
+ }
174
+ const ref = typeof inv.actionRef === 'string' ? inv.actionRef.trim() : '';
175
+ if (ref) {
176
+ merged.actionRef = ref;
177
+ }
178
+ }
168
179
  return merged;
169
180
  }
170
181
  /**
@@ -263,12 +274,37 @@ class ActivityManager {
263
274
  }
264
275
  }
265
276
  });
266
- this.initPromise = this.activix.init().catch((error) => {
267
- // MongoDB config not available - log warning but don't throw.
268
- // This allows tests and development to work without MongoDB.
269
- this.logger.warn('Activity tracking enabled but MongoDB configuration not available. Activity records will not be persisted.', {
277
+ this.initPromise = this.activix
278
+ .init()
279
+ .then(() => {
280
+ const ax = this.activix;
281
+ if (!ax) {
282
+ return;
283
+ }
284
+ const backend = ax.storageBackend;
285
+ const mongoDb = backend === 'database' ? (0, activix_1.resolveActivixLogsDatabaseName)() : undefined;
286
+ const mongoUriConfigured = Boolean((0, activix_1.resolveActivixMongoUriFromEnv)());
287
+ this.logger.info('Activity tracking persistence backend ready', {
288
+ storageBackend: backend,
289
+ mongoDatabase: mongoDb,
290
+ mongoUriConfigured,
291
+ mainCollection: collectionName,
292
+ badRequestsCollection: badRequestsCollectionName,
293
+ skillExecutionsCollection: this.skillExecutionsCollectionName,
294
+ ...(backend === 'local'
295
+ ? {
296
+ note: 'Activix is using local playground storage, not MongoDB. The ai-actions collection will not appear in Mongo until URI is set (MONGO_URI or MONGO_LOGS_URI), Activix can ping the database, and at least one activity is written.'
297
+ }
298
+ : {
299
+ note: 'MongoDB stores one document per activity; the ai-actions collection is created on first insert (empty collections may be hidden in some tools until then).'
300
+ })
301
+ });
302
+ })
303
+ .catch((error) => {
304
+ // Init threw — disable tracker so requests are not blocked.
305
+ this.logger.warn('Activity tracking enabled but Activix init failed. Activity records will not be persisted.', {
270
306
  error: error instanceof Error ? error.message : String(error),
271
- hint: 'Set MONGO_URI and MONGO_LOGS_DB (or MONGO_DB) environment variables to enable activity tracking persistence'
307
+ hint: 'Set MONGO_URI or MONGO_LOGS_URI and a database name (MONGO_LOGS_DB, MONGO_DB, MONGO_AI_LOGS_DB, or ACTIVIX_DB_NAME). See README: Activity tracking / persistence troubleshooting.'
272
308
  });
273
309
  this.activix = undefined;
274
310
  });
@@ -347,6 +383,8 @@ class ActivityManager {
347
383
  startTime,
348
384
  status: 'started',
349
385
  activityType: 'gateway-invocation',
386
+ ...(identity.actionType !== undefined && { actionType: identity.actionType }),
387
+ ...(identity.actionRef !== undefined && identity.actionRef !== '' && { actionRef: identity.actionRef }),
350
388
  // Activix v5+: correlation BSON field is `runContext` (same object as `request.identity`)
351
389
  runContext: identity
352
390
  // Removed root-level fields per v2.3.2:
@@ -561,6 +599,8 @@ class ActivityManager {
561
599
  taskTypeId: request.taskTypeId,
562
600
  startTime,
563
601
  status: 'started',
602
+ ...(identity.actionType !== undefined && { actionType: identity.actionType }),
603
+ ...(identity.actionRef !== undefined && identity.actionRef !== '' && { actionRef: identity.actionRef }),
564
604
  runContext: identity,
565
605
  ...(instructionMetadata.key && { instructionKey: instructionMetadata.key }),
566
606
  ...(instructionMetadata.version && { instructionVersion: instructionMetadata.version }),
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  /**
3
3
  * Centralized activity tracking configuration.
4
- * Single source of truth for package-level collection names.
4
+ * Package-level Mongo collection names are fixed literals here (no env override).
5
+ * Main gateway rows: `ai-actions`; bad requests: `bad-requests` (see constants below).
5
6
  */
6
7
  Object.defineProperty(exports, "__esModule", { value: true });
7
8
  exports.resolveActivityTrackingConfig = resolveActivityTrackingConfig;
8
- const ACTIVITY_COLLECTION_NAME = 'ai-activities';
9
+ const ACTIVITY_COLLECTION_NAME = 'ai-actions';
9
10
  const BAD_REQUESTS_COLLECTION_NAME = 'bad-requests';
10
11
  function resolveActivityTrackingConfig() {
11
12
  // Collection names are intentionally hardcoded at package level.
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Centralized activity tracking configuration.
3
- * Single source of truth for package-level collection names.
3
+ * Package-level Mongo collection names are fixed literals here (no env override).
4
+ * Main gateway rows: `ai-actions`; bad requests: `bad-requests` (see constants below).
4
5
  */
5
6
  export interface ActivityTrackingConfig {
6
7
  mongoUri: string;
@@ -18,7 +18,6 @@ function isAIRequest(request) {
18
18
  * Merges existing workingMemory (from request or memory component) with request metadata
19
19
  *
20
20
  * Implements tiered token resolution:
21
- * - Tier 1 (highest): templateTokens (handled in resolveTemplateParams, merged into shortTermMemory)
22
21
  * - Tier 2: workingMemory (this method) - checks existing workingMemory first
23
22
  * - Tier 3: derived from request fields or other memories (fallback)
24
23
  */
@@ -38,7 +37,6 @@ function buildWorkingMemory(request, existingWorkingMemory, otherMemories) {
38
37
  }
39
38
  /**
40
39
  * Token Resolution with Tiered Fallback
41
- * Tier 1: templateTokens (handled in resolveTemplateParams, merged into shortTermMemory)
42
40
  * Tier 2: workingMemory (check existing workingMemory first)
43
41
  * Tier 3: derive from request fields or other memories
44
42
  */
@@ -142,7 +140,7 @@ function buildWorkingMemory(request, existingWorkingMemory, otherMemories) {
142
140
  }
143
141
  /**
144
142
  * Resolves template parameters with smart fallback logic
145
- * Priority: Request args (tier 1) -> Memory component (tier 2) -> Gateway config (tier 3) -> defaults
143
+ * Priority: request.workingMemory -> memoryManager resolution -> buildWorkingMemory merge
146
144
  */
147
145
  async function resolveTemplateParams(request, config, logger) {
148
146
  // Tier 1: Request args (highest priority)
@@ -193,19 +191,7 @@ async function resolveTemplateParams(request, config, logger) {
193
191
  // Build proper workingMemory structure (merge with request fields if needed)
194
192
  // This implements tiered token resolution: tier 2 (workingMemory) and tier 3 (derive from request fields)
195
193
  const finalWorkingMemory = buildWorkingMemory(request, workingMemory);
196
- // Merge templateTokens (tier 1 - highest priority) into shortTermMemory AFTER memory resolution
197
- // This ensures templateTokens override everything (workingMemory and other memories)
198
- // Rendrix priority: shortTermMemory > workingMemory > experienceMemory > knowledgeMemory
199
- if (request.templateTokens && Object.keys(request.templateTokens).length > 0) {
200
- logger?.debug('Merged templateTokens into shortTermMemory (tier 1 - highest priority)', {
201
- jobId: request.identity.jobId,
202
- tokenKeys: Object.keys(request.templateTokens)
203
- });
204
- }
205
- // Note: taskConfig removed - Rendrix 3.0.0+ no longer accepts it
206
- // taskConfig is deprecated and no longer used
207
194
  return {
208
195
  workingMemory: finalWorkingMemory
209
- // taskConfig removed - Rendrix 3.0.0+ no longer uses it
210
196
  };
211
197
  }
@@ -10,7 +10,6 @@ type Request = ChatRequest | AIRequest;
10
10
  * Merges existing workingMemory (from request or memory component) with request metadata
11
11
  *
12
12
  * Implements tiered token resolution:
13
- * - Tier 1 (highest): templateTokens (handled in resolveTemplateParams, merged into shortTermMemory)
14
13
  * - Tier 2: workingMemory (this method) - checks existing workingMemory first
15
14
  * - Tier 3: derived from request fields or other memories (fallback)
16
15
  */
@@ -27,7 +26,7 @@ export declare function buildWorkingMemory(request: Request, existingWorkingMemo
27
26
  }): unknown;
28
27
  /**
29
28
  * Resolves template parameters with smart fallback logic
30
- * Priority: Request args (tier 1) -> Memory component (tier 2) -> Gateway config (tier 3) -> defaults
29
+ * Priority: request.workingMemory -> memoryManager resolution -> buildWorkingMemory merge
31
30
  */
32
31
  export declare function resolveTemplateParams(request: Request, config: GatewayConfig, logger: Logxer): Promise<{
33
32
  workingMemory: unknown;
@@ -30,8 +30,11 @@ async function testInstructions(instructions, testInput, expectedSchema, options
30
30
  const testRequest = {
31
31
  aiRequestId,
32
32
  agentId,
33
+ actionType: 'skill',
34
+ actionRef: 'gateway-meta/test-instructions',
33
35
  instructions,
34
36
  identity: runtimeIdentity,
37
+ prompt: '{{input}}',
35
38
  workingMemory: { input: testInput },
36
39
  config: {
37
40
  model,