@kognitivedev/vercel-ai-provider 0.2.8 → 0.2.13

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,55 @@
1
1
  # @kognitivedev/vercel-ai-provider
2
2
 
3
+ ## 0.2.13
4
+
5
+ ### Patch Changes
6
+
7
+ - release
8
+
9
+ - Updated dependencies []:
10
+ - @kognitivedev/prompthub@0.1.11
11
+ - @kognitivedev/shared@0.2.13
12
+
13
+ ## 0.2.12
14
+
15
+ ### Patch Changes
16
+
17
+ - release
18
+
19
+ - Updated dependencies []:
20
+ - @kognitivedev/prompthub@0.1.10
21
+ - @kognitivedev/shared@0.2.12
22
+
23
+ ## 0.2.11
24
+
25
+ ### Patch Changes
26
+
27
+ - release
28
+
29
+ - Updated dependencies []:
30
+ - @kognitivedev/prompthub@0.1.9
31
+ - @kognitivedev/shared@0.2.11
32
+
33
+ ## 0.2.10
34
+
35
+ ### Patch Changes
36
+
37
+ - release
38
+
39
+ - Updated dependencies []:
40
+ - @kognitivedev/prompthub@0.1.8
41
+ - @kognitivedev/shared@0.2.10
42
+
43
+ ## 0.2.9
44
+
45
+ ### Patch Changes
46
+
47
+ - release
48
+
49
+ - Updated dependencies []:
50
+ - @kognitivedev/prompthub@0.1.7
51
+ - @kognitivedev/shared@0.2.9
52
+
3
53
  ## 0.2.8
4
54
 
5
55
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -48,7 +48,7 @@ export type CLGenerateTextOptions = Omit<Parameters<typeof aiGenerateText>[0], '
48
48
  };
49
49
  export interface LogConversationPayload {
50
50
  userId: string;
51
- projectId: string;
51
+ projectId?: string;
52
52
  sessionId: string;
53
53
  messages: any[];
54
54
  memorySystemPrompt?: string;
@@ -96,7 +96,7 @@ export type CognitiveLayer = CLModelWrapper & {
96
96
  tag?: string;
97
97
  }) => Promise<CachedPrompt>;
98
98
  logConversation: (payload: LogConversationPayload) => Promise<void>;
99
- triggerProcessing: (userId: string, projectId: string, sessionId: string) => void;
99
+ triggerProcessing: (userId: string, sessionId: string) => void;
100
100
  clearSessionCache: (sessionKey?: string) => void;
101
101
  };
102
102
  export interface CachedPrompt {
package/dist/index.js CHANGED
@@ -73,8 +73,11 @@ function createLogger(logLevel) {
73
73
  };
74
74
  }
75
75
  function getContentText(content) {
76
- if (typeof content === "string")
76
+ if (typeof content === "string") {
77
+ if (content.includes("data:image/") && content.includes("base64,"))
78
+ return "[Image]";
77
79
  return content;
80
+ }
78
81
  if (!Array.isArray(content))
79
82
  return "";
80
83
  return content.map((part) => {
@@ -86,6 +89,10 @@ function getContentText(content) {
86
89
  return `Called ${part.toolName}`;
87
90
  if (part.type === "tool-result")
88
91
  return "Received tool result";
92
+ if (part.type === "image" || part.type === "image_url")
93
+ return "[Image]";
94
+ if (part.type === "file")
95
+ return "[File]";
89
96
  return "";
90
97
  }).filter(Boolean).join(" ");
91
98
  }
@@ -175,6 +182,9 @@ function extractToolDefinitions(params) {
175
182
  }
176
183
  // Session-scoped snapshot cache: sessionKey → formatted memory block
177
184
  const sessionSnapshots = new Map();
185
+ function getSessionKey(userId, sessionId) {
186
+ return `${userId}:${sessionId || "default"}`;
187
+ }
178
188
  // Regex to detect if memory has already been injected
179
189
  const MEMORY_TAG_REGEX = /<MemoryContext>/i;
180
190
  // Symbol-keyed property to track session settings on model objects
@@ -263,7 +273,7 @@ function createCognitiveLayer(config) {
263
273
  logger.error("Log failed", e);
264
274
  }
265
275
  };
266
- const triggerProcessing = (userId, projectId, sessionId) => {
276
+ const triggerProcessing = (userId, sessionId) => {
267
277
  const run = () => {
268
278
  fetch(`${baseUrl}/api/cognitive/process`, {
269
279
  method: "POST",
@@ -308,7 +318,7 @@ function createCognitiveLayer(config) {
308
318
  return params;
309
319
  }
310
320
  // 2) Check session cache
311
- const sessionKey = `${userId}:${projectId}:${sessionId || "default"}`;
321
+ const sessionKey = getSessionKey(userId, sessionId);
312
322
  let systemPromptToAdd = sessionSnapshots.get(sessionKey);
313
323
  // 3) Fetch snapshot only if not cached
314
324
  if (systemPromptToAdd === undefined) {
@@ -316,7 +326,6 @@ function createCognitiveLayer(config) {
316
326
  const url = `${baseUrl}/api/cognitive/snapshot?userId=${userId}`;
317
327
  logger.debug("Fetching snapshot from backend", {
318
328
  userId,
319
- projectId,
320
329
  sessionId,
321
330
  url,
322
331
  baseUrl,
@@ -327,7 +336,6 @@ function createCognitiveLayer(config) {
327
336
  });
328
337
  logger.debug("Snapshot response received", {
329
338
  userId,
330
- projectId,
331
339
  sessionId,
332
340
  status: res.status,
333
341
  ok: res.ok,
@@ -351,7 +359,6 @@ ${userContextBlock || "None"}
351
359
  sessionSnapshots.set(sessionKey, systemPromptToAdd);
352
360
  logger.info("Snapshot fetched and cached", {
353
361
  userId,
354
- projectId,
355
362
  sessionId,
356
363
  sessionKey,
357
364
  systemLen: systemBlock.length,
@@ -412,7 +419,7 @@ ${userContextBlock || "None"}
412
419
  }
413
420
  if (isValidId(userId) && isValidId(sessionId)) {
414
421
  const endedAt = new Date();
415
- const sessionKey = `${userId}:${projectId}:${sessionId}`;
422
+ const sessionKey = getSessionKey(userId, sessionId);
416
423
  const promptMeta = sessionPromptMetadata.get(sessionKey);
417
424
  const agentRunId = (_c = (_b = params === null || params === void 0 ? void 0 : params.providerMetadata) === null || _b === void 0 ? void 0 : _b.kognitive) === null || _c === void 0 ? void 0 : _c.agentRunId;
418
425
  const messagesInput = params.prompt || params.messages || [];
@@ -448,7 +455,6 @@ ${userContextBlock || "None"}
448
455
  const spans = buildTraceSpansFromMessages(finalMessages);
449
456
  const toolDefs = extractToolDefinitions(params);
450
457
  logConversation(Object.assign(Object.assign(Object.assign(Object.assign({ userId,
451
- projectId,
452
458
  sessionId, messages: finalMessages, modelId, usage: result.usage }, (promptMeta && {
453
459
  promptSlug: promptMeta.promptSlug,
454
460
  promptVersion: promptMeta.promptVersion,
@@ -457,7 +463,7 @@ ${userContextBlock || "None"}
457
463
  abTestId: promptMeta.abTestId,
458
464
  variant: promptMeta.variant,
459
465
  })), (toolDefs && { tools: toolDefs })), (agentRunId && { agentRunId })), { traceId: (0, crypto_1.randomUUID)(), requestPreview,
460
- responsePreview, state: "completed", startedAt: startedAt.toISOString(), endedAt: endedAt.toISOString(), durationMs: endedAt.getTime() - startedAt.getTime(), metadata: Object.assign(Object.assign(Object.assign({ appId: clConfig.appId }, ((promptMeta === null || promptMeta === void 0 ? void 0 : promptMeta.tag) && { promptTag: promptMeta.tag })), ((promptMeta === null || promptMeta === void 0 ? void 0 : promptMeta.abTestId) && { abTestId: promptMeta.abTestId })), ((promptMeta === null || promptMeta === void 0 ? void 0 : promptMeta.variant) && { variant: promptMeta.variant })), spans })).then(() => triggerProcessing(userId, projectId, sessionId));
466
+ responsePreview, state: "completed", startedAt: startedAt.toISOString(), endedAt: endedAt.toISOString(), durationMs: endedAt.getTime() - startedAt.getTime(), metadata: Object.assign(Object.assign(Object.assign({ appId: clConfig.appId }, ((promptMeta === null || promptMeta === void 0 ? void 0 : promptMeta.tag) && { promptTag: promptMeta.tag })), ((promptMeta === null || promptMeta === void 0 ? void 0 : promptMeta.abTestId) && { abTestId: promptMeta.abTestId })), ((promptMeta === null || promptMeta === void 0 ? void 0 : promptMeta.variant) && { variant: promptMeta.variant })), spans })).then(() => triggerProcessing(userId, sessionId));
461
467
  }
462
468
  return result;
463
469
  },
@@ -477,7 +483,7 @@ ${userContextBlock || "None"}
477
483
  throw err;
478
484
  }
479
485
  if (isValidId(userId) && isValidId(sessionId)) {
480
- const sessionKey = `${userId}:${projectId}:${sessionId}`;
486
+ const sessionKey = getSessionKey(userId, sessionId);
481
487
  const promptMeta = sessionPromptMetadata.get(sessionKey);
482
488
  const agentRunId = (_b = (_a = params === null || params === void 0 ? void 0 : params.providerMetadata) === null || _a === void 0 ? void 0 : _a.kognitive) === null || _b === void 0 ? void 0 : _b.agentRunId;
483
489
  const messagesInput = params.prompt || params.messages || [];
@@ -557,7 +563,6 @@ ${userContextBlock || "None"}
557
563
  // Fire-and-forget: do not await so the stream closes immediately,
558
564
  // allowing the AI SDK's multi-step continuation logic to proceed.
559
565
  logConversation(Object.assign(Object.assign(Object.assign(Object.assign({ userId,
560
- projectId,
561
566
  sessionId, messages: allMessages, modelId, usage: streamUsage }, (promptMeta && {
562
567
  promptSlug: promptMeta.promptSlug,
563
568
  promptVersion: promptMeta.promptVersion,
@@ -567,7 +572,7 @@ ${userContextBlock || "None"}
567
572
  variant: promptMeta.variant,
568
573
  })), (toolDefs && { tools: toolDefs })), (agentRunId && { agentRunId })), { traceId,
569
574
  requestPreview,
570
- responsePreview, state: "completed", startedAt: startedAt.toISOString(), endedAt: endedAt.toISOString(), durationMs: endedAt.getTime() - startedAt.getTime(), metadata: Object.assign(Object.assign(Object.assign({ appId: clConfig.appId }, ((promptMeta === null || promptMeta === void 0 ? void 0 : promptMeta.tag) && { promptTag: promptMeta.tag })), ((promptMeta === null || promptMeta === void 0 ? void 0 : promptMeta.abTestId) && { abTestId: promptMeta.abTestId })), ((promptMeta === null || promptMeta === void 0 ? void 0 : promptMeta.variant) && { variant: promptMeta.variant })), spans })).then(() => triggerProcessing(userId, projectId, sessionId))
575
+ responsePreview, state: "completed", startedAt: startedAt.toISOString(), endedAt: endedAt.toISOString(), durationMs: endedAt.getTime() - startedAt.getTime(), metadata: Object.assign(Object.assign(Object.assign({ appId: clConfig.appId }, ((promptMeta === null || promptMeta === void 0 ? void 0 : promptMeta.tag) && { promptTag: promptMeta.tag })), ((promptMeta === null || promptMeta === void 0 ? void 0 : promptMeta.abTestId) && { abTestId: promptMeta.abTestId })), ((promptMeta === null || promptMeta === void 0 ? void 0 : promptMeta.variant) && { variant: promptMeta.variant })), spans })).then(() => triggerProcessing(userId, sessionId))
571
576
  .catch((e) => logger.error("Stream log failed", e));
572
577
  }
573
578
  });
@@ -608,7 +613,7 @@ ${userContextBlock || "None"}
608
613
  ? provider(modelId, providerOptions)
609
614
  : provider(modelId));
610
615
  const userId = settings === null || settings === void 0 ? void 0 : settings.userId;
611
- const projectId = (settings === null || settings === void 0 ? void 0 : settings.projectId) || clConfig.projectId || "default";
616
+ const projectId = isValidId(settings === null || settings === void 0 ? void 0 : settings.projectId) ? settings === null || settings === void 0 ? void 0 : settings.projectId : isValidId(clConfig.projectId) ? clConfig.projectId : undefined;
612
617
  const sessionId = settings === null || settings === void 0 ? void 0 : settings.sessionId;
613
618
  const sessionMissing = isValidId(userId) && !isValidId(sessionId);
614
619
  if (sessionMissing) {
@@ -647,7 +652,7 @@ ${userContextBlock || "None"}
647
652
  : resolved.content;
648
653
  // Store prompt metadata for the session (read by middleware during logging)
649
654
  if (session === null || session === void 0 ? void 0 : session.sessionId) {
650
- const sessionKey = `${session.userId}:${session.projectId}:${session.sessionId}`;
655
+ const sessionKey = getSessionKey(session.userId, session.sessionId);
651
656
  sessionPromptMetadata.set(sessionKey, {
652
657
  promptSlug: resolved.slug,
653
658
  promptVersion: resolved.version,
@@ -692,7 +697,7 @@ ${userContextBlock || "None"}
692
697
  : resolved.content;
693
698
  // Store prompt metadata for the session (read by middleware during logging)
694
699
  if (session === null || session === void 0 ? void 0 : session.sessionId) {
695
- const sessionKey = `${session.userId}:${session.projectId}:${session.sessionId}`;
700
+ const sessionKey = getSessionKey(session.userId, session.sessionId);
696
701
  sessionPromptMetadata.set(sessionKey, {
697
702
  promptSlug: resolved.slug,
698
703
  promptVersion: resolved.version,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kognitivedev/vercel-ai-provider",
3
- "version": "0.2.8",
3
+ "version": "0.2.13",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "publishConfig": {
@@ -13,8 +13,8 @@
13
13
  "prepublishOnly": "npm run build"
14
14
  },
15
15
  "dependencies": {
16
- "@kognitivedev/prompthub": "^0.1.6",
17
- "@kognitivedev/shared": "^0.2.8"
16
+ "@kognitivedev/prompthub": "^0.1.11",
17
+ "@kognitivedev/shared": "^0.2.13"
18
18
  },
19
19
  "peerDependencies": {
20
20
  "ai": "^5.0.0 || ^6.0.0"
package/src/index.ts CHANGED
@@ -118,7 +118,7 @@ export type CLGenerateTextOptions = Omit<Parameters<typeof aiGenerateText>[0], '
118
118
 
119
119
  export interface LogConversationPayload {
120
120
  userId: string;
121
- projectId: string;
121
+ projectId?: string;
122
122
  sessionId: string;
123
123
  messages: any[];
124
124
  memorySystemPrompt?: string;
@@ -163,7 +163,7 @@ export type CognitiveLayer = CLModelWrapper & {
163
163
  userId?: string | { userId?: string; tag?: string }
164
164
  ) => Promise<CachedPrompt>;
165
165
  logConversation: (payload: LogConversationPayload) => Promise<void>;
166
- triggerProcessing: (userId: string, projectId: string, sessionId: string) => void;
166
+ triggerProcessing: (userId: string, sessionId: string) => void;
167
167
  clearSessionCache: (sessionKey?: string) => void;
168
168
  };
169
169
 
@@ -182,7 +182,10 @@ export interface CachedPrompt {
182
182
  }
183
183
 
184
184
  function getContentText(content: any): string {
185
- if (typeof content === "string") return content;
185
+ if (typeof content === "string") {
186
+ if (content.includes("data:image/") && content.includes("base64,")) return "[Image]";
187
+ return content;
188
+ }
186
189
  if (!Array.isArray(content)) return "";
187
190
 
188
191
  return content.map((part) => {
@@ -190,6 +193,8 @@ function getContentText(content: any): string {
190
193
  if (typeof part.text === "string") return part.text;
191
194
  if (part.type === "tool-call" && typeof part.toolName === "string") return `Called ${part.toolName}`;
192
195
  if (part.type === "tool-result") return "Received tool result";
196
+ if (part.type === "image" || part.type === "image_url") return "[Image]";
197
+ if (part.type === "file") return "[File]";
193
198
  return "";
194
199
  }).filter(Boolean).join(" ");
195
200
  }
@@ -310,6 +315,9 @@ function extractToolDefinitions(params: any): Array<{ name: string; description?
310
315
 
311
316
  // Session-scoped snapshot cache: sessionKey → formatted memory block
312
317
  const sessionSnapshots = new Map<string, string>();
318
+ function getSessionKey(userId: string, sessionId: string | undefined): string {
319
+ return `${userId}:${sessionId || "default"}`;
320
+ }
313
321
 
314
322
  // Regex to detect if memory has already been injected
315
323
  const MEMORY_TAG_REGEX = /<MemoryContext>/i;
@@ -415,7 +423,7 @@ export function createCognitiveLayer(config: {
415
423
  }
416
424
  };
417
425
 
418
- const triggerProcessing = (userId: string, projectId: string, sessionId: string) => {
426
+ const triggerProcessing = (userId: string, sessionId: string) => {
419
427
  const run = () => {
420
428
  fetch(`${baseUrl}/api/cognitive/process`, {
421
429
  method: "POST",
@@ -454,7 +462,7 @@ export function createCognitiveLayer(config: {
454
462
  return { nextParams, messages: updated, mode: "prepend-system" };
455
463
  };
456
464
 
457
- const buildMiddleware = (userId: string | undefined, projectId: string, sessionId: string | undefined, modelId: string) => ({
465
+ const buildMiddleware = (userId: string | undefined, projectId: string | undefined, sessionId: string | undefined, modelId: string) => ({
458
466
  specificationVersion: 'v3' as const,
459
467
  async transformParams({ params }: { params: any }) {
460
468
  if (!isValidId(userId)) return params;
@@ -470,7 +478,7 @@ export function createCognitiveLayer(config: {
470
478
  }
471
479
 
472
480
  // 2) Check session cache
473
- const sessionKey = `${userId}:${projectId}:${sessionId || "default"}`;
481
+ const sessionKey = getSessionKey(userId, sessionId);
474
482
  let systemPromptToAdd = sessionSnapshots.get(sessionKey);
475
483
 
476
484
  // 3) Fetch snapshot only if not cached
@@ -479,7 +487,6 @@ export function createCognitiveLayer(config: {
479
487
  const url = `${baseUrl}/api/cognitive/snapshot?userId=${userId}`;
480
488
  logger.debug("Fetching snapshot from backend", {
481
489
  userId,
482
- projectId,
483
490
  sessionId,
484
491
  url,
485
492
  baseUrl,
@@ -490,7 +497,6 @@ export function createCognitiveLayer(config: {
490
497
  });
491
498
  logger.debug("Snapshot response received", {
492
499
  userId,
493
- projectId,
494
500
  sessionId,
495
501
  status: res.status,
496
502
  ok: res.ok,
@@ -515,8 +521,7 @@ ${userContextBlock || "None"}
515
521
  sessionSnapshots.set(sessionKey, systemPromptToAdd);
516
522
 
517
523
  logger.info("Snapshot fetched and cached", {
518
- userId,
519
- projectId,
524
+ userId,
520
525
  sessionId,
521
526
  sessionKey,
522
527
  systemLen: systemBlock.length,
@@ -582,7 +587,7 @@ ${userContextBlock || "None"}
582
587
 
583
588
  if (isValidId(userId) && isValidId(sessionId)) {
584
589
  const endedAt = new Date();
585
- const sessionKey = `${userId}:${projectId}:${sessionId}`;
590
+ const sessionKey = getSessionKey(userId, sessionId);
586
591
  const promptMeta = sessionPromptMetadata.get(sessionKey);
587
592
  const agentRunId = (params as any)?.providerMetadata?.kognitive?.agentRunId as string | undefined;
588
593
 
@@ -620,7 +625,6 @@ ${userContextBlock || "None"}
620
625
 
621
626
  logConversation({
622
627
  userId,
623
- projectId,
624
628
  sessionId,
625
629
  messages: finalMessages,
626
630
  modelId,
@@ -649,7 +653,7 @@ ${userContextBlock || "None"}
649
653
  ...(promptMeta?.variant && { variant: promptMeta.variant }),
650
654
  },
651
655
  spans,
652
- }).then(() => triggerProcessing(userId, projectId, sessionId));
656
+ }).then(() => triggerProcessing(userId, sessionId));
653
657
  }
654
658
 
655
659
  return result;
@@ -670,7 +674,7 @@ ${userContextBlock || "None"}
670
674
  }
671
675
 
672
676
  if (isValidId(userId) && isValidId(sessionId)) {
673
- const sessionKey = `${userId}:${projectId}:${sessionId}`;
677
+ const sessionKey = getSessionKey(userId, sessionId);
674
678
  const promptMeta = sessionPromptMetadata.get(sessionKey);
675
679
  const agentRunId = (params as any)?.providerMetadata?.kognitive?.agentRunId as string | undefined;
676
680
 
@@ -756,8 +760,7 @@ ${userContextBlock || "None"}
756
760
  // Fire-and-forget: do not await so the stream closes immediately,
757
761
  // allowing the AI SDK's multi-step continuation logic to proceed.
758
762
  logConversation({
759
- userId,
760
- projectId,
763
+ userId,
761
764
  sessionId,
762
765
  messages: allMessages,
763
766
  modelId,
@@ -786,7 +789,7 @@ ${userContextBlock || "None"}
786
789
  ...(promptMeta?.variant && { variant: promptMeta.variant }),
787
790
  },
788
791
  spans,
789
- }).then(() => triggerProcessing(userId, projectId, sessionId))
792
+ }).then(() => triggerProcessing(userId, sessionId))
790
793
  .catch((e) => logger.error("Stream log failed", e));
791
794
  }
792
795
  });
@@ -838,7 +841,7 @@ ${userContextBlock || "None"}
838
841
  : provider(modelId)
839
842
  ) as LanguageModel;
840
843
  const userId = settings?.userId;
841
- const projectId = settings?.projectId || clConfig.projectId || "default";
844
+ const projectId = isValidId(settings?.projectId) ? settings?.projectId : isValidId(clConfig.projectId) ? clConfig.projectId : undefined;
842
845
  const sessionId = settings?.sessionId;
843
846
  const sessionMissing = isValidId(userId) && !isValidId(sessionId);
844
847
 
@@ -848,7 +851,7 @@ ${userContextBlock || "None"}
848
851
 
849
852
  const wrappedModel = wrapLanguageModel({
850
853
  model: model as any,
851
- middleware: buildMiddleware(userId, projectId, sessionId, modelId) as any,
854
+ middleware: buildMiddleware(userId, projectId, sessionId, modelId) as any,
852
855
  }) as LanguageModel;
853
856
 
854
857
  // Track session settings on the model for use in cl.streamText/cl.generateText
@@ -864,7 +867,7 @@ ${userContextBlock || "None"}
864
867
  const clStreamText = async (options: CLStreamTextOptions) => {
865
868
  const { prompt: promptConfig, ...rest } = options;
866
869
 
867
- const session = (options.model as any)[SESSION_KEY] as { userId: string; projectId: string; sessionId?: string } | undefined;
870
+ const session = (options.model as any)[SESSION_KEY] as { userId: string; projectId?: string; sessionId?: string } | undefined;
868
871
 
869
872
  // Resolve and interpolate prompt (graceful fallback on failure)
870
873
  let resolved: CachedPrompt | null = null;
@@ -885,7 +888,7 @@ ${userContextBlock || "None"}
885
888
 
886
889
  // Store prompt metadata for the session (read by middleware during logging)
887
890
  if (session?.sessionId) {
888
- const sessionKey = `${session.userId}:${session.projectId}:${session.sessionId}`;
891
+ const sessionKey = getSessionKey(session.userId, session.sessionId);
889
892
  sessionPromptMetadata.set(sessionKey, {
890
893
  promptSlug: resolved.slug,
891
894
  promptVersion: resolved.version,
@@ -914,7 +917,7 @@ ${userContextBlock || "None"}
914
917
  const clGenerateText = async (options: CLGenerateTextOptions) => {
915
918
  const { prompt: promptConfig, ...rest } = options;
916
919
 
917
- const session = (options.model as any)[SESSION_KEY] as { userId: string; projectId: string; sessionId?: string } | undefined;
920
+ const session = (options.model as any)[SESSION_KEY] as { userId: string; projectId?: string; sessionId?: string } | undefined;
918
921
 
919
922
  // Resolve and interpolate prompt (graceful fallback on failure)
920
923
  let resolved: CachedPrompt | null = null;
@@ -935,7 +938,7 @@ ${userContextBlock || "None"}
935
938
 
936
939
  // Store prompt metadata for the session (read by middleware during logging)
937
940
  if (session?.sessionId) {
938
- const sessionKey = `${session.userId}:${session.projectId}:${session.sessionId}`;
941
+ const sessionKey = getSessionKey(session.userId, session.sessionId);
939
942
  sessionPromptMetadata.set(sessionKey, {
940
943
  promptSlug: resolved.slug,
941
944
  promptVersion: resolved.version,