@launchdarkly/server-sdk-ai 0.10.1 → 0.11.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 (54) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/__tests__/LDAIClientImpl.test.ts +328 -1
  3. package/__tests__/LDAIConfigTrackerImpl.test.ts +94 -136
  4. package/dist/LDAIClientImpl.d.ts +7 -0
  5. package/dist/LDAIClientImpl.d.ts.map +1 -1
  6. package/dist/LDAIClientImpl.js +60 -11
  7. package/dist/LDAIClientImpl.js.map +1 -1
  8. package/dist/LDAIConfigTrackerImpl.d.ts +3 -1
  9. package/dist/LDAIConfigTrackerImpl.d.ts.map +1 -1
  10. package/dist/LDAIConfigTrackerImpl.js +5 -3
  11. package/dist/LDAIConfigTrackerImpl.js.map +1 -1
  12. package/dist/api/LDAIClient.d.ts +70 -0
  13. package/dist/api/LDAIClient.d.ts.map +1 -1
  14. package/dist/api/agents/LDAIAgent.d.ts +32 -0
  15. package/dist/api/agents/LDAIAgent.d.ts.map +1 -0
  16. package/dist/api/agents/LDAIAgent.js +3 -0
  17. package/dist/api/agents/LDAIAgent.js.map +1 -0
  18. package/dist/api/agents/index.d.ts +2 -0
  19. package/dist/api/agents/index.d.ts.map +1 -0
  20. package/dist/api/agents/index.js +18 -0
  21. package/dist/api/agents/index.js.map +1 -0
  22. package/dist/api/index.d.ts +1 -0
  23. package/dist/api/index.d.ts.map +1 -1
  24. package/dist/api/index.js +1 -0
  25. package/dist/api/index.js.map +1 -1
  26. package/docs/assets/highlight.css +15 -8
  27. package/docs/assets/search.js +1 -1
  28. package/docs/enums/LDFeedbackKind.html +11 -8
  29. package/docs/functions/createBedrockTokenUsage.html +9 -6
  30. package/docs/functions/createOpenAiUsage.html +9 -6
  31. package/docs/functions/createVercelAISDKTokenUsage.html +9 -6
  32. package/docs/functions/initAi.html +9 -6
  33. package/docs/index.html +12 -6
  34. package/docs/interfaces/LDAIAgent.html +177 -0
  35. package/docs/interfaces/LDAIAgentConfig.html +111 -0
  36. package/docs/interfaces/LDAIClient.html +96 -10
  37. package/docs/interfaces/LDAIConfig.html +15 -12
  38. package/docs/interfaces/LDAIConfigTracker.html +21 -18
  39. package/docs/interfaces/LDMessage.html +11 -8
  40. package/docs/interfaces/LDModelConfig.html +12 -9
  41. package/docs/interfaces/LDProviderConfig.html +10 -7
  42. package/docs/interfaces/LDTokenUsage.html +12 -9
  43. package/docs/interfaces/VercelAISDKConfig.html +19 -16
  44. package/docs/interfaces/VercelAISDKMapOptions.html +10 -7
  45. package/docs/types/LDAIAgentDefaults.html +63 -0
  46. package/docs/types/LDAIDefaults.html +9 -6
  47. package/docs/types/VercelAISDKProvider.html +9 -6
  48. package/package.json +1 -1
  49. package/src/LDAIClientImpl.ts +146 -12
  50. package/src/LDAIConfigTrackerImpl.ts +11 -3
  51. package/src/api/LDAIClient.ts +80 -0
  52. package/src/api/agents/LDAIAgent.ts +36 -0
  53. package/src/api/agents/index.ts +1 -0
  54. package/src/api/index.ts +1 -0
@@ -15,6 +15,8 @@ const testContext: LDContext = { kind: 'user', key: 'test-user' };
15
15
  const configKey = 'test-config';
16
16
  const variationKey = 'v1';
17
17
  const version = 1;
18
+ const modelName = 'test-model';
19
+ const providerName = 'test-provider';
18
20
 
19
21
  beforeEach(() => {
20
22
  jest.clearAllMocks();
@@ -26,6 +28,8 @@ it('tracks duration', () => {
26
28
  configKey,
27
29
  variationKey,
28
30
  version,
31
+ modelName,
32
+ providerName,
29
33
  testContext,
30
34
  );
31
35
  tracker.trackDuration(1000);
@@ -33,7 +37,7 @@ it('tracks duration', () => {
33
37
  expect(mockTrack).toHaveBeenCalledWith(
34
38
  '$ld:ai:duration:total',
35
39
  testContext,
36
- { configKey, variationKey, version },
40
+ { configKey, variationKey, version, modelName, providerName },
37
41
  1000,
38
42
  );
39
43
  });
@@ -44,6 +48,8 @@ it('tracks duration of async function', async () => {
44
48
  configKey,
45
49
  variationKey,
46
50
  version,
51
+ modelName,
52
+ providerName,
47
53
  testContext,
48
54
  );
49
55
  jest.spyOn(global.Date, 'now').mockReturnValueOnce(1000).mockReturnValueOnce(2000);
@@ -54,7 +60,7 @@ it('tracks duration of async function', async () => {
54
60
  expect(mockTrack).toHaveBeenCalledWith(
55
61
  '$ld:ai:duration:total',
56
62
  testContext,
57
- { configKey, variationKey, version },
63
+ { configKey, variationKey, version, modelName, providerName },
58
64
  1000,
59
65
  );
60
66
  });
@@ -65,6 +71,8 @@ it('tracks time to first token', () => {
65
71
  configKey,
66
72
  variationKey,
67
73
  version,
74
+ modelName,
75
+ providerName,
68
76
  testContext,
69
77
  );
70
78
  tracker.trackTimeToFirstToken(1000);
@@ -72,7 +80,7 @@ it('tracks time to first token', () => {
72
80
  expect(mockTrack).toHaveBeenCalledWith(
73
81
  '$ld:ai:tokens:ttf',
74
82
  testContext,
75
- { configKey, variationKey, version },
83
+ { configKey, variationKey, version, modelName, providerName },
76
84
  1000,
77
85
  );
78
86
  });
@@ -83,6 +91,8 @@ it('tracks positive feedback', () => {
83
91
  configKey,
84
92
  variationKey,
85
93
  version,
94
+ modelName,
95
+ providerName,
86
96
  testContext,
87
97
  );
88
98
  tracker.trackFeedback({ kind: LDFeedbackKind.Positive });
@@ -90,7 +100,7 @@ it('tracks positive feedback', () => {
90
100
  expect(mockTrack).toHaveBeenCalledWith(
91
101
  '$ld:ai:feedback:user:positive',
92
102
  testContext,
93
- { configKey, variationKey, version },
103
+ { configKey, variationKey, version, modelName, providerName },
94
104
  1,
95
105
  );
96
106
  });
@@ -101,6 +111,8 @@ it('tracks negative feedback', () => {
101
111
  configKey,
102
112
  variationKey,
103
113
  version,
114
+ modelName,
115
+ providerName,
104
116
  testContext,
105
117
  );
106
118
  tracker.trackFeedback({ kind: LDFeedbackKind.Negative });
@@ -108,7 +120,7 @@ it('tracks negative feedback', () => {
108
120
  expect(mockTrack).toHaveBeenCalledWith(
109
121
  '$ld:ai:feedback:user:negative',
110
122
  testContext,
111
- { configKey, variationKey, version },
123
+ { configKey, variationKey, version, modelName, providerName },
112
124
  1,
113
125
  );
114
126
  });
@@ -119,21 +131,16 @@ it('tracks success', () => {
119
131
  configKey,
120
132
  variationKey,
121
133
  version,
134
+ modelName,
135
+ providerName,
122
136
  testContext,
123
137
  );
124
138
  tracker.trackSuccess();
125
139
 
126
- expect(mockTrack).toHaveBeenCalledWith(
127
- '$ld:ai:generation',
128
- testContext,
129
- { configKey, variationKey, version },
130
- 1,
131
- );
132
-
133
140
  expect(mockTrack).toHaveBeenCalledWith(
134
141
  '$ld:ai:generation:success',
135
142
  testContext,
136
- { configKey, variationKey, version },
143
+ { configKey, variationKey, version, modelName, providerName },
137
144
  1,
138
145
  );
139
146
  });
@@ -144,6 +151,8 @@ it('tracks OpenAI usage', async () => {
144
151
  configKey,
145
152
  variationKey,
146
153
  version,
154
+ modelName,
155
+ providerName,
147
156
  testContext,
148
157
  );
149
158
  jest.spyOn(global.Date, 'now').mockReturnValueOnce(1000).mockReturnValueOnce(2000);
@@ -163,21 +172,14 @@ it('tracks OpenAI usage', async () => {
163
172
  expect(mockTrack).toHaveBeenCalledWith(
164
173
  '$ld:ai:duration:total',
165
174
  testContext,
166
- { configKey, variationKey, version },
175
+ { configKey, variationKey, version, modelName, providerName },
167
176
  1000,
168
177
  );
169
178
 
170
- expect(mockTrack).toHaveBeenCalledWith(
171
- '$ld:ai:generation',
172
- testContext,
173
- { configKey, variationKey, version },
174
- 1,
175
- );
176
-
177
179
  expect(mockTrack).toHaveBeenCalledWith(
178
180
  '$ld:ai:generation:success',
179
181
  testContext,
180
- { configKey, variationKey, version },
182
+ { configKey, variationKey, version, modelName, providerName },
181
183
  1,
182
184
  );
183
185
 
@@ -191,21 +193,21 @@ it('tracks OpenAI usage', async () => {
191
193
  expect(mockTrack).toHaveBeenCalledWith(
192
194
  '$ld:ai:tokens:total',
193
195
  testContext,
194
- { configKey, variationKey, version },
196
+ { configKey, variationKey, version, modelName, providerName },
195
197
  TOTAL_TOKENS,
196
198
  );
197
199
 
198
200
  expect(mockTrack).toHaveBeenCalledWith(
199
201
  '$ld:ai:tokens:input',
200
202
  testContext,
201
- { configKey, variationKey, version },
203
+ { configKey, variationKey, version, modelName, providerName },
202
204
  PROMPT_TOKENS,
203
205
  );
204
206
 
205
207
  expect(mockTrack).toHaveBeenCalledWith(
206
208
  '$ld:ai:tokens:output',
207
209
  testContext,
208
- { configKey, variationKey, version },
210
+ { configKey, variationKey, version, modelName, providerName },
209
211
  COMPLETION_TOKENS,
210
212
  );
211
213
  });
@@ -216,6 +218,8 @@ it('tracks error when OpenAI metrics function throws', async () => {
216
218
  configKey,
217
219
  variationKey,
218
220
  version,
221
+ modelName,
222
+ providerName,
219
223
  testContext,
220
224
  );
221
225
  jest.spyOn(global.Date, 'now').mockReturnValueOnce(1000).mockReturnValueOnce(2000);
@@ -230,21 +234,14 @@ it('tracks error when OpenAI metrics function throws', async () => {
230
234
  expect(mockTrack).toHaveBeenCalledWith(
231
235
  '$ld:ai:duration:total',
232
236
  testContext,
233
- { configKey, variationKey, version },
237
+ { configKey, variationKey, version, modelName, providerName },
234
238
  1000,
235
239
  );
236
240
 
237
- expect(mockTrack).toHaveBeenCalledWith(
238
- '$ld:ai:generation',
239
- testContext,
240
- { configKey, variationKey, version },
241
- 1,
242
- );
243
-
244
241
  expect(mockTrack).toHaveBeenCalledWith(
245
242
  '$ld:ai:generation:error',
246
243
  testContext,
247
- { configKey, variationKey, version },
244
+ { configKey, variationKey, version, modelName, providerName },
248
245
  1,
249
246
  );
250
247
 
@@ -262,6 +259,8 @@ it('tracks Bedrock conversation with successful response', () => {
262
259
  configKey,
263
260
  variationKey,
264
261
  version,
262
+ modelName,
263
+ providerName,
265
264
  testContext,
266
265
  );
267
266
 
@@ -281,17 +280,10 @@ it('tracks Bedrock conversation with successful response', () => {
281
280
 
282
281
  tracker.trackBedrockConverseMetrics(response);
283
282
 
284
- expect(mockTrack).toHaveBeenCalledWith(
285
- '$ld:ai:generation',
286
- testContext,
287
- { configKey, variationKey, version },
288
- 1,
289
- );
290
-
291
283
  expect(mockTrack).toHaveBeenCalledWith(
292
284
  '$ld:ai:generation:success',
293
285
  testContext,
294
- { configKey, variationKey, version },
286
+ { configKey, variationKey, version, modelName, providerName },
295
287
  1,
296
288
  );
297
289
 
@@ -305,28 +297,28 @@ it('tracks Bedrock conversation with successful response', () => {
305
297
  expect(mockTrack).toHaveBeenCalledWith(
306
298
  '$ld:ai:duration:total',
307
299
  testContext,
308
- { configKey, variationKey, version },
300
+ { configKey, variationKey, version, modelName, providerName },
309
301
  500,
310
302
  );
311
303
 
312
304
  expect(mockTrack).toHaveBeenCalledWith(
313
305
  '$ld:ai:tokens:total',
314
306
  testContext,
315
- { configKey, variationKey, version },
307
+ { configKey, variationKey, version, modelName, providerName },
316
308
  TOTAL_TOKENS,
317
309
  );
318
310
 
319
311
  expect(mockTrack).toHaveBeenCalledWith(
320
312
  '$ld:ai:tokens:input',
321
313
  testContext,
322
- { configKey, variationKey, version },
314
+ { configKey, variationKey, version, modelName, providerName },
323
315
  PROMPT_TOKENS,
324
316
  );
325
317
 
326
318
  expect(mockTrack).toHaveBeenCalledWith(
327
319
  '$ld:ai:tokens:output',
328
320
  testContext,
329
- { configKey, variationKey, version },
321
+ { configKey, variationKey, version, modelName, providerName },
330
322
  COMPLETION_TOKENS,
331
323
  );
332
324
  });
@@ -337,6 +329,8 @@ it('tracks Bedrock conversation with error response', () => {
337
329
  configKey,
338
330
  variationKey,
339
331
  version,
332
+ modelName,
333
+ providerName,
340
334
  testContext,
341
335
  );
342
336
 
@@ -346,18 +340,12 @@ it('tracks Bedrock conversation with error response', () => {
346
340
 
347
341
  tracker.trackBedrockConverseMetrics(response);
348
342
 
349
- expect(mockTrack).toHaveBeenCalledTimes(2);
350
- expect(mockTrack).toHaveBeenCalledWith(
351
- '$ld:ai:generation',
352
- testContext,
353
- { configKey, variationKey, version },
354
- 1,
355
- );
343
+ expect(mockTrack).toHaveBeenCalledTimes(1);
356
344
 
357
345
  expect(mockTrack).toHaveBeenCalledWith(
358
346
  '$ld:ai:generation:error',
359
347
  testContext,
360
- { configKey, variationKey, version },
348
+ { configKey, variationKey, version, modelName, providerName },
361
349
  1,
362
350
  );
363
351
 
@@ -376,6 +364,8 @@ describe('Vercel AI SDK generateText', () => {
376
364
  configKey,
377
365
  variationKey,
378
366
  version,
367
+ modelName,
368
+ providerName,
379
369
  testContext,
380
370
  );
381
371
  jest.spyOn(global.Date, 'now').mockReturnValueOnce(1000).mockReturnValueOnce(2000);
@@ -395,21 +385,14 @@ describe('Vercel AI SDK generateText', () => {
395
385
  expect(mockTrack).toHaveBeenCalledWith(
396
386
  '$ld:ai:duration:total',
397
387
  testContext,
398
- { configKey, variationKey, version },
388
+ { configKey, variationKey, version, modelName, providerName },
399
389
  1000,
400
390
  );
401
391
 
402
- expect(mockTrack).toHaveBeenCalledWith(
403
- '$ld:ai:generation',
404
- testContext,
405
- { configKey, variationKey, version },
406
- 1,
407
- );
408
-
409
392
  expect(mockTrack).toHaveBeenCalledWith(
410
393
  '$ld:ai:generation:success',
411
394
  testContext,
412
- { configKey, variationKey, version },
395
+ { configKey, variationKey, version, modelName, providerName },
413
396
  1,
414
397
  );
415
398
 
@@ -423,21 +406,21 @@ describe('Vercel AI SDK generateText', () => {
423
406
  expect(mockTrack).toHaveBeenCalledWith(
424
407
  '$ld:ai:tokens:total',
425
408
  testContext,
426
- { configKey, variationKey, version },
409
+ { configKey, variationKey, version, modelName, providerName },
427
410
  TOTAL_TOKENS,
428
411
  );
429
412
 
430
413
  expect(mockTrack).toHaveBeenCalledWith(
431
414
  '$ld:ai:tokens:input',
432
415
  testContext,
433
- { configKey, variationKey, version },
416
+ { configKey, variationKey, version, modelName, providerName },
434
417
  PROMPT_TOKENS,
435
418
  );
436
419
 
437
420
  expect(mockTrack).toHaveBeenCalledWith(
438
421
  '$ld:ai:tokens:output',
439
422
  testContext,
440
- { configKey, variationKey, version },
423
+ { configKey, variationKey, version, modelName, providerName },
441
424
  COMPLETION_TOKENS,
442
425
  );
443
426
  });
@@ -448,6 +431,8 @@ describe('Vercel AI SDK generateText', () => {
448
431
  configKey,
449
432
  variationKey,
450
433
  version,
434
+ modelName,
435
+ providerName,
451
436
  testContext,
452
437
  );
453
438
  jest.spyOn(global.Date, 'now').mockReturnValueOnce(1000).mockReturnValueOnce(2000);
@@ -462,21 +447,14 @@ describe('Vercel AI SDK generateText', () => {
462
447
  expect(mockTrack).toHaveBeenCalledWith(
463
448
  '$ld:ai:duration:total',
464
449
  testContext,
465
- { configKey, variationKey, version },
450
+ { configKey, variationKey, version, modelName, providerName },
466
451
  1000,
467
452
  );
468
453
 
469
- expect(mockTrack).toHaveBeenCalledWith(
470
- '$ld:ai:generation',
471
- testContext,
472
- { configKey, variationKey, version },
473
- 1,
474
- );
475
-
476
454
  expect(mockTrack).toHaveBeenCalledWith(
477
455
  '$ld:ai:generation:error',
478
456
  testContext,
479
- { configKey, variationKey, version },
457
+ { configKey, variationKey, version, modelName, providerName },
480
458
  1,
481
459
  );
482
460
 
@@ -496,6 +474,8 @@ describe('Vercel AI SDK streamText', () => {
496
474
  configKey,
497
475
  variationKey,
498
476
  version,
477
+ modelName,
478
+ providerName,
499
479
  testContext,
500
480
  );
501
481
  jest.spyOn(global.Date, 'now').mockReturnValueOnce(1000).mockReturnValueOnce(2000);
@@ -528,21 +508,14 @@ describe('Vercel AI SDK streamText', () => {
528
508
  expect(mockTrack).toHaveBeenCalledWith(
529
509
  '$ld:ai:duration:total',
530
510
  testContext,
531
- { configKey, variationKey, version },
511
+ { configKey, variationKey, version, modelName, providerName },
532
512
  1000,
533
513
  );
534
514
 
535
- expect(mockTrack).toHaveBeenCalledWith(
536
- '$ld:ai:generation',
537
- testContext,
538
- { configKey, variationKey, version },
539
- 1,
540
- );
541
-
542
515
  expect(mockTrack).toHaveBeenCalledWith(
543
516
  '$ld:ai:generation:success',
544
517
  testContext,
545
- { configKey, variationKey, version },
518
+ { configKey, variationKey, version, modelName, providerName },
546
519
  1,
547
520
  );
548
521
 
@@ -556,21 +529,21 @@ describe('Vercel AI SDK streamText', () => {
556
529
  expect(mockTrack).toHaveBeenCalledWith(
557
530
  '$ld:ai:tokens:total',
558
531
  testContext,
559
- { configKey, variationKey, version },
532
+ { configKey, variationKey, version, modelName, providerName },
560
533
  TOTAL_TOKENS,
561
534
  );
562
535
 
563
536
  expect(mockTrack).toHaveBeenCalledWith(
564
537
  '$ld:ai:tokens:input',
565
538
  testContext,
566
- { configKey, variationKey, version },
539
+ { configKey, variationKey, version, modelName, providerName },
567
540
  PROMPT_TOKENS,
568
541
  );
569
542
 
570
543
  expect(mockTrack).toHaveBeenCalledWith(
571
544
  '$ld:ai:tokens:output',
572
545
  testContext,
573
- { configKey, variationKey, version },
546
+ { configKey, variationKey, version, modelName, providerName },
574
547
  COMPLETION_TOKENS,
575
548
  );
576
549
  });
@@ -581,6 +554,8 @@ describe('Vercel AI SDK streamText', () => {
581
554
  configKey,
582
555
  variationKey,
583
556
  version,
557
+ modelName,
558
+ providerName,
584
559
  testContext,
585
560
  );
586
561
  jest.spyOn(global.Date, 'now').mockReturnValueOnce(1000).mockReturnValueOnce(2000);
@@ -595,21 +570,14 @@ describe('Vercel AI SDK streamText', () => {
595
570
  expect(mockTrack).toHaveBeenCalledWith(
596
571
  '$ld:ai:duration:total',
597
572
  testContext,
598
- { configKey, variationKey, version },
573
+ { configKey, variationKey, version, modelName, providerName },
599
574
  1000,
600
575
  );
601
576
 
602
- expect(mockTrack).toHaveBeenCalledWith(
603
- '$ld:ai:generation',
604
- testContext,
605
- { configKey, variationKey, version },
606
- 1,
607
- );
608
-
609
577
  expect(mockTrack).toHaveBeenCalledWith(
610
578
  '$ld:ai:generation:error',
611
579
  testContext,
612
- { configKey, variationKey, version },
580
+ { configKey, variationKey, version, modelName, providerName },
613
581
  1,
614
582
  );
615
583
 
@@ -627,6 +595,8 @@ describe('Vercel AI SDK streamText', () => {
627
595
  configKey,
628
596
  variationKey,
629
597
  version,
598
+ modelName,
599
+ providerName,
630
600
  testContext,
631
601
  );
632
602
  jest.spyOn(global.Date, 'now').mockReturnValueOnce(1000).mockReturnValueOnce(2000);
@@ -640,21 +610,14 @@ describe('Vercel AI SDK streamText', () => {
640
610
  expect(mockTrack).toHaveBeenCalledWith(
641
611
  '$ld:ai:duration:total',
642
612
  testContext,
643
- { configKey, variationKey, version },
613
+ { configKey, variationKey, version, modelName, providerName },
644
614
  1000,
645
615
  );
646
616
 
647
- expect(mockTrack).toHaveBeenCalledWith(
648
- '$ld:ai:generation',
649
- testContext,
650
- { configKey, variationKey, version },
651
- 1,
652
- );
653
-
654
617
  expect(mockTrack).toHaveBeenCalledWith(
655
618
  '$ld:ai:generation:error',
656
619
  testContext,
657
- { configKey, variationKey, version },
620
+ { configKey, variationKey, version, modelName, providerName },
658
621
  1,
659
622
  );
660
623
 
@@ -672,6 +635,8 @@ describe('Vercel AI SDK streamText', () => {
672
635
  configKey,
673
636
  variationKey,
674
637
  version,
638
+ modelName,
639
+ providerName,
675
640
  testContext,
676
641
  );
677
642
  jest.spyOn(global.Date, 'now').mockReturnValueOnce(1000).mockReturnValueOnce(2000);
@@ -685,21 +650,14 @@ describe('Vercel AI SDK streamText', () => {
685
650
  expect(mockTrack).toHaveBeenCalledWith(
686
651
  '$ld:ai:duration:total',
687
652
  testContext,
688
- { configKey, variationKey, version },
653
+ { configKey, variationKey, version, modelName, providerName },
689
654
  1000,
690
655
  );
691
656
 
692
- expect(mockTrack).toHaveBeenCalledWith(
693
- '$ld:ai:generation',
694
- testContext,
695
- { configKey, variationKey, version },
696
- 1,
697
- );
698
-
699
657
  expect(mockTrack).toHaveBeenCalledWith(
700
658
  '$ld:ai:generation:error',
701
659
  testContext,
702
- { configKey, variationKey, version },
660
+ { configKey, variationKey, version, modelName, providerName },
703
661
  1,
704
662
  );
705
663
 
@@ -717,6 +675,8 @@ describe('Vercel AI SDK streamText', () => {
717
675
  configKey,
718
676
  variationKey,
719
677
  version,
678
+ modelName,
679
+ providerName,
720
680
  testContext,
721
681
  );
722
682
  jest.spyOn(global.Date, 'now').mockReturnValueOnce(1000).mockReturnValueOnce(2000);
@@ -731,21 +691,14 @@ describe('Vercel AI SDK streamText', () => {
731
691
  expect(mockTrack).toHaveBeenCalledWith(
732
692
  '$ld:ai:duration:total',
733
693
  testContext,
734
- { configKey, variationKey, version },
694
+ { configKey, variationKey, version, modelName, providerName },
735
695
  1000,
736
696
  );
737
697
 
738
- expect(mockTrack).toHaveBeenCalledWith(
739
- '$ld:ai:generation',
740
- testContext,
741
- { configKey, variationKey, version },
742
- 1,
743
- );
744
-
745
698
  expect(mockTrack).toHaveBeenCalledWith(
746
699
  '$ld:ai:generation:success',
747
700
  testContext,
748
- { configKey, variationKey, version },
701
+ { configKey, variationKey, version, modelName, providerName },
749
702
  1,
750
703
  );
751
704
 
@@ -771,6 +724,8 @@ it('tracks tokens', () => {
771
724
  configKey,
772
725
  variationKey,
773
726
  version,
727
+ modelName,
728
+ providerName,
774
729
  testContext,
775
730
  );
776
731
 
@@ -787,21 +742,21 @@ it('tracks tokens', () => {
787
742
  expect(mockTrack).toHaveBeenCalledWith(
788
743
  '$ld:ai:tokens:total',
789
744
  testContext,
790
- { configKey, variationKey, version },
745
+ { configKey, variationKey, version, modelName, providerName },
791
746
  TOTAL_TOKENS,
792
747
  );
793
748
 
794
749
  expect(mockTrack).toHaveBeenCalledWith(
795
750
  '$ld:ai:tokens:input',
796
751
  testContext,
797
- { configKey, variationKey, version },
752
+ { configKey, variationKey, version, modelName, providerName },
798
753
  PROMPT_TOKENS,
799
754
  );
800
755
 
801
756
  expect(mockTrack).toHaveBeenCalledWith(
802
757
  '$ld:ai:tokens:output',
803
758
  testContext,
804
- { configKey, variationKey, version },
759
+ { configKey, variationKey, version, modelName, providerName },
805
760
  COMPLETION_TOKENS,
806
761
  );
807
762
  });
@@ -812,6 +767,8 @@ it('only tracks non-zero token counts', () => {
812
767
  configKey,
813
768
  variationKey,
814
769
  version,
770
+ modelName,
771
+ providerName,
815
772
  testContext,
816
773
  );
817
774
 
@@ -831,7 +788,7 @@ it('only tracks non-zero token counts', () => {
831
788
  expect(mockTrack).toHaveBeenCalledWith(
832
789
  '$ld:ai:tokens:input',
833
790
  testContext,
834
- { configKey, variationKey, version },
791
+ { configKey, variationKey, version, modelName, providerName },
835
792
  50,
836
793
  );
837
794
 
@@ -849,6 +806,8 @@ it('returns empty summary when no metrics tracked', () => {
849
806
  configKey,
850
807
  variationKey,
851
808
  version,
809
+ modelName,
810
+ providerName,
852
811
  testContext,
853
812
  );
854
813
 
@@ -863,6 +822,8 @@ it('summarizes tracked metrics', () => {
863
822
  configKey,
864
823
  variationKey,
865
824
  version,
825
+ modelName,
826
+ providerName,
866
827
  testContext,
867
828
  );
868
829
 
@@ -897,6 +858,8 @@ it('tracks duration when async function throws', async () => {
897
858
  configKey,
898
859
  variationKey,
899
860
  version,
861
+ modelName,
862
+ providerName,
900
863
  testContext,
901
864
  );
902
865
  jest.spyOn(global.Date, 'now').mockReturnValueOnce(1000).mockReturnValueOnce(2000);
@@ -911,7 +874,7 @@ it('tracks duration when async function throws', async () => {
911
874
  expect(mockTrack).toHaveBeenCalledWith(
912
875
  '$ld:ai:duration:total',
913
876
  testContext,
914
- { configKey, variationKey, version },
877
+ { configKey, variationKey, version, modelName, providerName },
915
878
  1000,
916
879
  );
917
880
  });
@@ -922,21 +885,16 @@ it('tracks error', () => {
922
885
  configKey,
923
886
  variationKey,
924
887
  version,
888
+ modelName,
889
+ providerName,
925
890
  testContext,
926
891
  );
927
892
  tracker.trackError();
928
893
 
929
- expect(mockTrack).toHaveBeenCalledWith(
930
- '$ld:ai:generation',
931
- testContext,
932
- { configKey, variationKey, version },
933
- 1,
934
- );
935
-
936
894
  expect(mockTrack).toHaveBeenCalledWith(
937
895
  '$ld:ai:generation:error',
938
896
  testContext,
939
- { configKey, variationKey, version },
897
+ { configKey, variationKey, version, modelName, providerName },
940
898
  1,
941
899
  );
942
900
  });
@@ -1,4 +1,5 @@
1
1
  import { LDContext } from '@launchdarkly/js-server-sdk-common';
2
+ import { LDAIAgent, LDAIAgentConfig, LDAIAgentDefaults } from './api/agents';
2
3
  import { LDAIConfig, LDAIDefaults } from './api/config';
3
4
  import { LDAIClient } from './api/LDAIClient';
4
5
  import { LDClientMin } from './LDClientMin';
@@ -6,6 +7,12 @@ export declare class LDAIClientImpl implements LDAIClient {
6
7
  private _ldClient;
7
8
  constructor(_ldClient: LDClientMin);
8
9
  private _interpolateTemplate;
10
+ private _evaluate;
11
+ private _evaluateAgent;
9
12
  config(key: string, context: LDContext, defaultValue: LDAIDefaults, variables?: Record<string, unknown>): Promise<LDAIConfig>;
13
+ agent(key: string, context: LDContext, defaultValue: LDAIAgentDefaults, variables?: Record<string, unknown>): Promise<LDAIAgent>;
14
+ agents<const T extends readonly (LDAIAgentConfig & {
15
+ defaultValue: LDAIAgentDefaults;
16
+ })[]>(agentConfigs: T, context: LDContext): Promise<Record<T[number]['key'], LDAIAgent>>;
10
17
  }
11
18
  //# sourceMappingURL=LDAIClientImpl.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"LDAIClientImpl.d.ts","sourceRoot":"","sources":["../src/LDAIClientImpl.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AAE/D,OAAO,EACL,UAAU,EACV,YAAY,EAOb,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAsB5C,qBAAa,cAAe,YAAW,UAAU;IACnC,OAAO,CAAC,SAAS;gBAAT,SAAS,EAAE,WAAW;IAE1C,OAAO,CAAC,oBAAoB;IAItB,MAAM,CACV,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,SAAS,EAClB,YAAY,EAAE,YAAY,EAC1B,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAClC,OAAO,CAAC,UAAU,CAAC;CA4CvB"}
1
+ {"version":3,"file":"LDAIClientImpl.d.ts","sourceRoot":"","sources":["../src/LDAIClientImpl.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AAE/D,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC7E,OAAO,EACL,UAAU,EAEV,YAAY,EAOb,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAuC5C,qBAAa,cAAe,YAAW,UAAU;IACnC,OAAO,CAAC,SAAS;gBAAT,SAAS,EAAE,WAAW;IAE1C,OAAO,CAAC,oBAAoB;YAId,SAAS;YAkCT,cAAc;IA2CtB,MAAM,CACV,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,SAAS,EAClB,YAAY,EAAE,YAAY,EAC1B,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAClC,OAAO,CAAC,UAAU,CAAC;IA0ChB,KAAK,CACT,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,SAAS,EAClB,YAAY,EAAE,iBAAiB,EAC/B,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAClC,OAAO,CAAC,SAAS,CAAC;IAOf,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,SAAS,CAAC,eAAe,GAAG;QAAE,YAAY,EAAE,iBAAiB,CAAA;KAAE,CAAC,EAAE,EAC7F,YAAY,EAAE,CAAC,EACf,OAAO,EAAE,SAAS,GACjB,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,CAAC;CAyBhD"}