@launchdarkly/server-sdk-ai 0.20.0 → 1.0.1

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,62 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.0.1](https://github.com/launchdarkly/js-core/compare/server-sdk-ai-v1.0.0...server-sdk-ai-v1.0.1) (2026-05-21)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * Remove pre-release caution note from server-ai README ([#1387](https://github.com/launchdarkly/js-core/issues/1387)) ([0bafcbf](https://github.com/launchdarkly/js-core/commit/0bafcbfc22d5c39c3664d38bdb47183824a068e5))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * devDependencies
15
+ * @launchdarkly/js-server-sdk-common bumped from 2.18.7 to 2.19.0
16
+ * peerDependencies
17
+ * @launchdarkly/js-server-sdk-common bumped from 2.18.7 to 2.19.0
18
+
19
+ ## [1.0.0](https://github.com/launchdarkly/js-core/compare/server-sdk-ai-v0.20.0...server-sdk-ai-v1.0.0) (2026-05-19)
20
+
21
+
22
+ ### ⚠ BREAKING CHANGES
23
+
24
+ * Remove bedrock-specific tracker method ([#1385](https://github.com/launchdarkly/js-core/issues/1385))
25
+ * Remove `LDAIClient.agent` — use `LDAIClient.agentConfig` instead
26
+ * Remove `LDAIClient.agents` — use `LDAIClient.agentConfigs` instead
27
+ * Remove `LDAIClient.createChat` — use `LDAIClient.createModel` instead
28
+ * Remove `LDAIClient.initChat` — use `LDAIClient.createModel` instead
29
+ * Remove `ChatResponse` type and the `api/chat` module — use `RunnerResult` from `api/model` instead
30
+ * Change `Judge.evaluateMessages` parameter type from `ChatResponse` to `RunnerResult` (method retained per AI SDK spec Requirement 1.1.3)
31
+ * Remove `evaluationMetricKeys` (plural) field from `LDAIJudgeConfig` and `LDAIJudgeConfigDefault` — use `evaluationMetricKey` (singular) instead
32
+ * Remove `LDAIConfigTracker.trackOpenAIMetrics` — use `tracker.trackMetricsOf(getAIMetricsFromResponse, fn)` from `@launchdarkly/server-sdk-ai-openai` instead
33
+ * Remove `LDAIConfigTracker.trackVercelAISDKGenerateTextMetrics` — use `tracker.trackMetricsOf(getAIMetricsFromResponse, fn)` from `@launchdarkly/server-sdk-ai-vercel` instead
34
+ * Remove `createOpenAiUsage` helper — use `getAIMetricsFromResponse` from `@launchdarkly/server-sdk-ai-openai` instead
35
+ * Remove `createVercelAISDKTokenUsage` helper — use `getAIMetricsFromResponse` from `@launchdarkly/server-sdk-ai-vercel` instead
36
+ * Remove `LDAIClient.config` — use `LDAIClient.completionConfig` instead
37
+
38
+ ### Features
39
+
40
+ * Change `Judge.evaluateMessages` parameter type from `ChatResponse` to `RunnerResult` (method retained per AI SDK spec Requirement 1.1.3) ([86951b0](https://github.com/launchdarkly/js-core/commit/86951b0f66eed3f374d06c40e858dca04a837fda))
41
+ * Remove `ChatResponse` type and the `api/chat` module — use `RunnerResult` from `api/model` instead ([86951b0](https://github.com/launchdarkly/js-core/commit/86951b0f66eed3f374d06c40e858dca04a837fda))
42
+ * Remove `createOpenAiUsage` helper — use `getAIMetricsFromResponse` from `@launchdarkly/server-sdk-ai-openai` instead ([86951b0](https://github.com/launchdarkly/js-core/commit/86951b0f66eed3f374d06c40e858dca04a837fda))
43
+ * Remove `createVercelAISDKTokenUsage` helper — use `getAIMetricsFromResponse` from `@launchdarkly/server-sdk-ai-vercel` instead ([86951b0](https://github.com/launchdarkly/js-core/commit/86951b0f66eed3f374d06c40e858dca04a837fda))
44
+ * Remove `evaluationMetricKeys` (plural) field from `LDAIJudgeConfig` and `LDAIJudgeConfigDefault` — use `evaluationMetricKey` (singular) instead ([86951b0](https://github.com/launchdarkly/js-core/commit/86951b0f66eed3f374d06c40e858dca04a837fda))
45
+ * Remove `LDAIClient.agent` — use `LDAIClient.agentConfig` instead ([86951b0](https://github.com/launchdarkly/js-core/commit/86951b0f66eed3f374d06c40e858dca04a837fda))
46
+ * Remove `LDAIClient.agents` — use `LDAIClient.agentConfigs` instead ([86951b0](https://github.com/launchdarkly/js-core/commit/86951b0f66eed3f374d06c40e858dca04a837fda))
47
+ * Remove `LDAIClient.config` — use `LDAIClient.completionConfig` instead ([86951b0](https://github.com/launchdarkly/js-core/commit/86951b0f66eed3f374d06c40e858dca04a837fda))
48
+ * Remove `LDAIClient.createChat` — use `LDAIClient.createModel` instead ([86951b0](https://github.com/launchdarkly/js-core/commit/86951b0f66eed3f374d06c40e858dca04a837fda))
49
+ * Remove `LDAIClient.initChat` — use `LDAIClient.createModel` instead ([86951b0](https://github.com/launchdarkly/js-core/commit/86951b0f66eed3f374d06c40e858dca04a837fda))
50
+ * Remove `LDAIConfigTracker.trackOpenAIMetrics` — use `tracker.trackMetricsOf(getAIMetricsFromResponse, fn)` from `@launchdarkly/server-sdk-ai-openai` instead ([86951b0](https://github.com/launchdarkly/js-core/commit/86951b0f66eed3f374d06c40e858dca04a837fda))
51
+ * Remove `LDAIConfigTracker.trackVercelAISDKGenerateTextMetrics` — use `tracker.trackMetricsOf(getAIMetricsFromResponse, fn)` from `@launchdarkly/server-sdk-ai-vercel` instead ([86951b0](https://github.com/launchdarkly/js-core/commit/86951b0f66eed3f374d06c40e858dca04a837fda))
52
+ * Remove bedrock-specific tracker method ([#1385](https://github.com/launchdarkly/js-core/issues/1385)) ([f7dbee8](https://github.com/launchdarkly/js-core/commit/f7dbee806a15e8b9d5a6b7b49a461e16e5e757fe))
53
+
54
+
55
+ ### Bug Fixes
56
+
57
+ * Make judge runners non-multi-turn ([#1383](https://github.com/launchdarkly/js-core/issues/1383)) ([3d8f488](https://github.com/launchdarkly/js-core/commit/3d8f488354a5ed590859c7fe96429a2ab9f79c01))
58
+ * Move ManagedAgentGraph alongside other managed types ([#1384](https://github.com/launchdarkly/js-core/issues/1384)) ([22dd76d](https://github.com/launchdarkly/js-core/commit/22dd76d61a830d7ad37ae0136b59d1971973b424))
59
+
3
60
  ## [0.20.0](https://github.com/launchdarkly/js-core/compare/server-sdk-ai-v0.19.1...server-sdk-ai-v0.20.0) (2026-05-07)
4
61
 
5
62
 
package/README.md CHANGED
@@ -6,12 +6,6 @@
6
6
  [![NPM][server-ai-sdk-dm-badge]][server-ai-sdk-npm-link]
7
7
  [![NPM][server-ai-sdk-dt-badge]][server-ai-sdk-npm-link]
8
8
 
9
- > [!CAUTION]
10
- > This SDK is in pre-release and not subject to backwards compatibility
11
- > guarantees. The API may change based on feedback.
12
- >
13
- > Pin to a specific minor version and review the [changelog](CHANGELOG.md) before upgrading.
14
-
15
9
  ## LaunchDarkly overview
16
10
 
17
11
  [LaunchDarkly](https://www.launchdarkly.com) is a feature management platform that serves over 100 billion feature flags daily to help teams build better software, faster. [Get started](https://docs.launchdarkly.com/home/getting-started) using LaunchDarkly today!
package/dist/index.cjs CHANGED
@@ -41,9 +41,6 @@ __export(src_exports, {
41
41
  ManagedModel: () => ManagedModel,
42
42
  RunnerFactory: () => RunnerFactory,
43
43
  SUPPORTED_AI_PROVIDERS: () => SUPPORTED_AI_PROVIDERS,
44
- createBedrockTokenUsage: () => createBedrockTokenUsage,
45
- createOpenAiUsage: () => createOpenAiUsage,
46
- createVercelAISDKTokenUsage: () => createVercelAISDKTokenUsage,
47
44
  initAi: () => initAi
48
45
  });
49
46
  module.exports = __toCommonJS(src_exports);
@@ -189,9 +186,6 @@ var LDAIConfigUtils = class {
189
186
  if ("evaluationMetricKey" in config && config.evaluationMetricKey !== void 0) {
190
187
  flagValue.evaluationMetricKey = config.evaluationMetricKey;
191
188
  }
192
- if ("evaluationMetricKeys" in config && config.evaluationMetricKeys !== void 0) {
193
- flagValue.evaluationMetricKeys = config.evaluationMetricKeys;
194
- }
195
189
  if ("judgeConfiguration" in config && config.judgeConfiguration !== void 0) {
196
190
  flagValue.judgeConfiguration = config.judgeConfiguration;
197
191
  }
@@ -205,7 +199,7 @@ var LDAIConfigUtils = class {
205
199
  *
206
200
  * @param key The configuration key
207
201
  * @param flagValue The flag value from LaunchDarkly
208
- * @param trackerFactory A factory function that creates a new tracker for each execution
202
+ * @param trackerFactory A factory function that creates a new tracker for each AI run
209
203
  * @param evaluator The evaluator to attach to completion and agent configs
210
204
  * @returns The appropriate AI configuration type
211
205
  */
@@ -226,7 +220,7 @@ var LDAIConfigUtils = class {
226
220
  *
227
221
  * @param key The configuration key
228
222
  * @param mode The mode for the disabled config
229
- * @param createTracker A factory function that creates a new tracker for each execution
223
+ * @param createTracker A factory function that creates a new tracker for each AI run
230
224
  * @param evaluator The evaluator to attach to completion and agent configs
231
225
  * @returns A disabled config of the appropriate type
232
226
  */
@@ -292,7 +286,7 @@ var LDAIConfigUtils = class {
292
286
  *
293
287
  * @param key The configuration key
294
288
  * @param flagValue The flag value from LaunchDarkly
295
- * @param trackerFactory A factory function that creates a new tracker for each execution
289
+ * @param trackerFactory A factory function that creates a new tracker for each AI run
296
290
  * @param evaluator The evaluator for this completion config
297
291
  * @returns A completion configuration
298
292
  */
@@ -311,7 +305,7 @@ var LDAIConfigUtils = class {
311
305
  *
312
306
  * @param key The configuration key
313
307
  * @param flagValue The flag value from LaunchDarkly
314
- * @param trackerFactory A factory function that creates a new tracker for each execution
308
+ * @param trackerFactory A factory function that creates a new tracker for each AI run
315
309
  * @param evaluator The evaluator for this agent config
316
310
  * @returns An agent configuration
317
311
  */
@@ -330,7 +324,7 @@ var LDAIConfigUtils = class {
330
324
  *
331
325
  * @param key The configuration key
332
326
  * @param flagValue The flag value from LaunchDarkly
333
- * @param trackerFactory A factory function that creates a new tracker for each execution
327
+ * @param trackerFactory A factory function that creates a new tracker for each AI run
334
328
  * @returns A judge configuration
335
329
  */
336
330
  static toJudgeConfig(key, flagValue, trackerFactory) {
@@ -463,10 +457,10 @@ var AgentGraphDefinition = class _AgentGraphDefinition {
463
457
  return this._agentGraph;
464
458
  }
465
459
  /**
466
- * Returns a new {@link LDGraphTracker} for this graph invocation.
460
+ * Returns a new {@link LDGraphTracker} for a fresh graph run.
467
461
  *
468
- * Call this once per invocation. Each call produces a tracker with a fresh `runId`
469
- * that groups all events for that invocation.
462
+ * Call this once per graph run. Each call produces a tracker with a fresh `runId`
463
+ * that groups all events for that run.
470
464
  */
471
465
  createTracker() {
472
466
  return this._createTracker();
@@ -584,81 +578,6 @@ var AgentGraphDefinition = class _AgentGraphDefinition {
584
578
  }
585
579
  };
586
580
 
587
- // src/api/graph/ManagedAgentGraph.ts
588
- var ManagedAgentGraph = class {
589
- constructor(_graphDefinition, _logger) {
590
- this._graphDefinition = _graphDefinition;
591
- this._logger = _logger;
592
- }
593
- /**
594
- * Runs the agent graph using the provided runner function and returns a ManagedGraphResult.
595
- *
596
- * The runner function receives the graph tracker and AgentGraphDefinition,
597
- * executes the graph, and returns an AgentGraphRunnerResult.
598
- *
599
- * run() returns before ManagedGraphResult.evaluations resolves.
600
- *
601
- * @param runner Async function that executes the graph and returns AgentGraphRunnerResult.
602
- * @returns ManagedGraphResult with LDAIGraphMetricSummary and evaluations promise.
603
- */
604
- async run(runner) {
605
- const graphTracker = this._graphDefinition.createTracker();
606
- const runnerResult = await runner(this._graphDefinition, graphTracker);
607
- const metrics = {
608
- success: runnerResult.metrics.success,
609
- path: runnerResult.metrics.path,
610
- durationMs: runnerResult.metrics.durationMs,
611
- tokens: runnerResult.metrics.tokens,
612
- nodeMetrics: this._trackNodeMetrics(runnerResult.metrics.nodeMetrics),
613
- resumptionToken: graphTracker.resumptionToken
614
- };
615
- const evaluations = Promise.resolve([]);
616
- return {
617
- content: runnerResult.content,
618
- metrics,
619
- raw: runnerResult.raw,
620
- evaluations
621
- };
622
- }
623
- /**
624
- * Converts per-node LDAIMetrics from the runner into LDAIMetricSummary by
625
- * creating a per-node tracker, firing tracking events, and calling getSummary().
626
- */
627
- _trackNodeMetrics(nodeMetrics) {
628
- const summaries = {};
629
- for (const [nodeKey, metrics] of Object.entries(nodeMetrics)) {
630
- const node = this._graphDefinition.getNode(nodeKey);
631
- if (!node) {
632
- this._logger?.warn(`ManagedAgentGraph: no node found for key "${nodeKey}", skipping metrics`);
633
- continue;
634
- }
635
- const tracker = node.getConfig().createTracker();
636
- if (metrics.tokens) {
637
- tracker.trackTokens(metrics.tokens);
638
- }
639
- if (metrics.durationMs !== void 0) {
640
- tracker.trackDuration(metrics.durationMs);
641
- }
642
- if (metrics.toolCalls?.length) {
643
- tracker.trackToolCalls(metrics.toolCalls);
644
- }
645
- if (metrics.success) {
646
- tracker.trackSuccess();
647
- } else {
648
- tracker.trackError();
649
- }
650
- summaries[nodeKey] = tracker.getSummary();
651
- }
652
- return summaries;
653
- }
654
- /**
655
- * Returns the underlying AgentGraphDefinition.
656
- */
657
- getGraphDefinition() {
658
- return this._graphDefinition;
659
- }
660
- };
661
-
662
581
  // src/api/judge/Evaluator.ts
663
582
  var Evaluator = class _Evaluator {
664
583
  constructor(_judges) {
@@ -713,8 +632,7 @@ var Judge = class {
713
632
  return this._sampleRate;
714
633
  }
715
634
  /**
716
- * Gets the evaluation metric key, prioritizing evaluationMetricKey over evaluationMetricKeys.
717
- * Falls back to the first valid (non-empty, non-whitespace) value in evaluationMetricKeys if evaluationMetricKey is not provided.
635
+ * Gets the evaluation metric key from the judge AI config.
718
636
  * Treats empty strings and whitespace-only strings as invalid.
719
637
  * @returns The evaluation metric key, or undefined if not available
720
638
  */
@@ -722,12 +640,6 @@ var Judge = class {
722
640
  if (this._aiConfig.evaluationMetricKey && this._aiConfig.evaluationMetricKey.trim().length > 0) {
723
641
  return this._aiConfig.evaluationMetricKey.trim();
724
642
  }
725
- if (this._aiConfig.evaluationMetricKeys && this._aiConfig.evaluationMetricKeys.length > 0) {
726
- const validKey = this._aiConfig.evaluationMetricKeys.find(
727
- (key) => key && key.trim().length > 0
728
- );
729
- return validKey ? validKey.trim() : void 0;
730
- }
731
643
  return void 0;
732
644
  }
733
645
  /**
@@ -792,17 +704,21 @@ var Judge = class {
792
704
  }
793
705
  }
794
706
  /**
795
- * Evaluates an AI response from chat messages and response.
707
+ * Evaluates an AI response from chat messages and a runner result.
708
+ *
709
+ * Each message is rendered as `<role>: <content>` so the judge model can
710
+ * distinguish speakers in the message history. Messages are joined with a
711
+ * single newline.
796
712
  *
797
713
  * @param messages Array of messages representing the conversation history
798
- * @param response The AI response to be evaluated
714
+ * @param response The runner result containing the AI-generated content to evaluate
799
715
  * @param samplingRatio Sampling ratio (0-1). When omitted, the Judge's
800
716
  * constructor-default rate is used.
801
717
  * @returns Promise that resolves to evaluation results
802
718
  */
803
719
  async evaluateMessages(messages, response, samplingRatio) {
804
- const input = messages.length === 0 ? "" : messages.map((msg) => msg.content).join("\r\n");
805
- const output = response.message.content;
720
+ const input = messages.length === 0 ? "" : messages.map((msg) => `${msg.role}: ${msg.content}`).join("\n");
721
+ const output = response.content;
806
722
  return this.evaluate(input, output, samplingRatio);
807
723
  }
808
724
  /**
@@ -863,10 +779,14 @@ var AIProvider = class {
863
779
  * Default implementation returns `undefined`.
864
780
  *
865
781
  * @param config The completion or judge AI configuration.
782
+ * @param multiTurn Whether the runner should accumulate conversation history
783
+ * across successive `run()` calls. Defaults to `true` (chat semantics).
784
+ * Pass `false` for stateless runners such as judges where each call must
785
+ * start from the initial config messages.
866
786
  * @returns Promise resolving to a {@link Runner}, or `undefined` if this
867
787
  * provider does not support model creation.
868
788
  */
869
- async createModel(_config) {
789
+ async createModel(_config, _multiTurn = true) {
870
790
  return void 0;
871
791
  }
872
792
  /**
@@ -1002,15 +922,19 @@ var RunnerFactory = class _RunnerFactory {
1002
922
  * ('openai', 'langchain', 'vercel', …). When set, only that provider is
1003
923
  * tried. When omitted, providers are tried in priority order based on the
1004
924
  * provider name in the config.
925
+ * @param multiTurn Whether the runner should accumulate conversation history
926
+ * across successive `run()` calls. Defaults to `true` (chat semantics).
927
+ * Judges pass `false` so each evaluation starts from the initial config
928
+ * messages.
1005
929
  * @returns A configured {@link Runner} ready to invoke the model, or
1006
930
  * `undefined` if no suitable provider could be loaded.
1007
931
  */
1008
- static async createModel(config, logger, defaultAiProvider) {
932
+ static async createModel(config, logger, defaultAiProvider, multiTurn = true) {
1009
933
  const providerName = config.provider?.name?.toLowerCase();
1010
934
  const providers = _RunnerFactory._getProvidersToTry(defaultAiProvider, providerName);
1011
935
  const runner = await _RunnerFactory._withFallback(
1012
936
  providers,
1013
- (factory) => factory.createModel(config),
937
+ (factory) => factory.createModel(config, multiTurn),
1014
938
  logger
1015
939
  );
1016
940
  if (!runner) {
@@ -1073,24 +997,6 @@ var RunnerFactory = class _RunnerFactory {
1073
997
  }
1074
998
  };
1075
999
 
1076
- // src/api/metrics/BedrockTokenUsage.ts
1077
- function createBedrockTokenUsage(data) {
1078
- return {
1079
- total: data.totalTokens || 0,
1080
- input: data.inputTokens || 0,
1081
- output: data.outputTokens || 0
1082
- };
1083
- }
1084
-
1085
- // src/api/metrics/OpenAiUsage.ts
1086
- function createOpenAiUsage(data) {
1087
- return {
1088
- total: data.total_tokens ?? 0,
1089
- input: data.prompt_tokens ?? 0,
1090
- output: data.completion_tokens ?? 0
1091
- };
1092
- }
1093
-
1094
1000
  // src/api/metrics/LDFeedbackKind.ts
1095
1001
  var LDFeedbackKind = /* @__PURE__ */ ((LDFeedbackKind2) => {
1096
1002
  LDFeedbackKind2["Positive"] = "positive";
@@ -1098,15 +1004,6 @@ var LDFeedbackKind = /* @__PURE__ */ ((LDFeedbackKind2) => {
1098
1004
  return LDFeedbackKind2;
1099
1005
  })(LDFeedbackKind || {});
1100
1006
 
1101
- // src/api/metrics/VercelAISDKTokenUsage.ts
1102
- function createVercelAISDKTokenUsage(data) {
1103
- return {
1104
- total: data.totalTokens ?? 0,
1105
- input: data.inputTokens ?? data.promptTokens ?? 0,
1106
- output: data.outputTokens ?? data.completionTokens ?? 0
1107
- };
1108
- }
1109
-
1110
1007
  // src/LDAIConfigTrackerImpl.ts
1111
1008
  var LDAIConfigTrackerImpl = class _LDAIConfigTrackerImpl {
1112
1009
  constructor(_ldClient, _runId, _configKey, _variationKey, _version, _modelName, _providerName, _context, _graphKey) {
@@ -1161,7 +1058,7 @@ var LDAIConfigTrackerImpl = class _LDAIConfigTrackerImpl {
1161
1058
  trackDuration(duration) {
1162
1059
  if (this._trackedMetrics.durationMs !== void 0) {
1163
1060
  this._ldClient.logger?.warn(
1164
- "Duration has already been tracked for this execution. Use createTracker() for a new execution."
1061
+ "Skipping trackDuration: duration already recorded on this tracker. Call createTracker on the AI Config for a new run."
1165
1062
  );
1166
1063
  return;
1167
1064
  }
@@ -1182,7 +1079,7 @@ var LDAIConfigTrackerImpl = class _LDAIConfigTrackerImpl {
1182
1079
  trackTimeToFirstToken(timeToFirstTokenMs) {
1183
1080
  if (this._trackedMetrics.timeToFirstTokenMs !== void 0) {
1184
1081
  this._ldClient.logger?.warn(
1185
- "Time to first token has already been tracked for this execution. Use createTracker() for a new execution."
1082
+ "Skipping trackTimeToFirstToken: time-to-first-token already recorded on this tracker. Call createTracker on the AI Config for a new run."
1186
1083
  );
1187
1084
  return;
1188
1085
  }
@@ -1218,7 +1115,7 @@ var LDAIConfigTrackerImpl = class _LDAIConfigTrackerImpl {
1218
1115
  trackFeedback(feedback) {
1219
1116
  if (this._trackedMetrics.feedback !== void 0) {
1220
1117
  this._ldClient.logger?.warn(
1221
- "Feedback has already been tracked for this execution. Use createTracker() for a new execution."
1118
+ "Skipping trackFeedback: feedback already recorded on this tracker. Call createTracker on the AI Config for a new run."
1222
1119
  );
1223
1120
  return;
1224
1121
  }
@@ -1232,7 +1129,7 @@ var LDAIConfigTrackerImpl = class _LDAIConfigTrackerImpl {
1232
1129
  trackSuccess() {
1233
1130
  if (this._trackedMetrics.success !== void 0) {
1234
1131
  this._ldClient.logger?.warn(
1235
- "Generation result has already been tracked for this execution. Use createTracker() for a new execution."
1132
+ "Skipping trackSuccess: success/error already recorded on this tracker. Call createTracker on the AI Config for a new run."
1236
1133
  );
1237
1134
  return;
1238
1135
  }
@@ -1242,7 +1139,7 @@ var LDAIConfigTrackerImpl = class _LDAIConfigTrackerImpl {
1242
1139
  trackError() {
1243
1140
  if (this._trackedMetrics.success !== void 0) {
1244
1141
  this._ldClient.logger?.warn(
1245
- "Generation result has already been tracked for this execution. Use createTracker() for a new execution."
1142
+ "Skipping trackError: success/error already recorded on this tracker. Call createTracker on the AI Config for a new run."
1246
1143
  );
1247
1144
  return;
1248
1145
  }
@@ -1303,50 +1200,10 @@ var LDAIConfigTrackerImpl = class _LDAIConfigTrackerImpl {
1303
1200
  this.trackDuration(Date.now() - startTime);
1304
1201
  }
1305
1202
  }
1306
- async trackOpenAIMetrics(func) {
1307
- try {
1308
- const result = await this.trackDurationOf(func);
1309
- this.trackSuccess();
1310
- if (result.usage) {
1311
- this.trackTokens(createOpenAiUsage(result.usage));
1312
- }
1313
- return result;
1314
- } catch (err) {
1315
- this.trackError();
1316
- throw err;
1317
- }
1318
- }
1319
- trackBedrockConverseMetrics(res) {
1320
- if (res.$metadata?.httpStatusCode === 200) {
1321
- this.trackSuccess();
1322
- } else if (res.$metadata?.httpStatusCode && res.$metadata.httpStatusCode >= 400) {
1323
- this.trackError();
1324
- }
1325
- if (res.metrics && res.metrics.latencyMs) {
1326
- this.trackDuration(res.metrics.latencyMs);
1327
- }
1328
- if (res.usage) {
1329
- this.trackTokens(createBedrockTokenUsage(res.usage));
1330
- }
1331
- return res;
1332
- }
1333
- async trackVercelAISDKGenerateTextMetrics(func) {
1334
- try {
1335
- const result = await this.trackDurationOf(func);
1336
- this.trackSuccess();
1337
- if (result.usage) {
1338
- this.trackTokens(createVercelAISDKTokenUsage(result.usage));
1339
- }
1340
- return result;
1341
- } catch (err) {
1342
- this.trackError();
1343
- throw err;
1344
- }
1345
- }
1346
1203
  trackTokens(tokens) {
1347
1204
  if (this._trackedMetrics.tokens !== void 0) {
1348
1205
  this._ldClient.logger?.warn(
1349
- "Token usage has already been tracked for this execution. Use createTracker() for a new execution."
1206
+ "Skipping trackTokens: token usage already recorded on this tracker. Call createTracker on the AI Config for a new run."
1350
1207
  );
1351
1208
  return;
1352
1209
  }
@@ -1431,7 +1288,7 @@ var LDGraphTrackerImpl = class _LDGraphTrackerImpl {
1431
1288
  trackInvocationSuccess() {
1432
1289
  if (this._summary.success !== void 0) {
1433
1290
  this._ldClient.logger?.warn(
1434
- "LDGraphTracker: invocation success/failure already recorded for this run \u2014 dropping duplicate call."
1291
+ "Skipping trackInvocationSuccess: invocation result already recorded on this graph tracker. Call createTracker on the agent graph for a new run."
1435
1292
  );
1436
1293
  return;
1437
1294
  }
@@ -1441,7 +1298,7 @@ var LDGraphTrackerImpl = class _LDGraphTrackerImpl {
1441
1298
  trackInvocationFailure() {
1442
1299
  if (this._summary.success !== void 0) {
1443
1300
  this._ldClient.logger?.warn(
1444
- "LDGraphTracker: invocation success/failure already recorded for this run \u2014 dropping duplicate call."
1301
+ "Skipping trackInvocationFailure: invocation result already recorded on this graph tracker. Call createTracker on the agent graph for a new run."
1445
1302
  );
1446
1303
  return;
1447
1304
  }
@@ -1451,7 +1308,7 @@ var LDGraphTrackerImpl = class _LDGraphTrackerImpl {
1451
1308
  trackDuration(durationMs) {
1452
1309
  if (this._summary.durationMs !== void 0) {
1453
1310
  this._ldClient.logger?.warn(
1454
- "LDGraphTracker: trackDuration already called for this run \u2014 dropping duplicate call."
1311
+ "Skipping trackDuration: duration already recorded on this graph tracker. Call createTracker on the agent graph for a new run."
1455
1312
  );
1456
1313
  return;
1457
1314
  }
@@ -1466,7 +1323,7 @@ var LDGraphTrackerImpl = class _LDGraphTrackerImpl {
1466
1323
  trackTotalTokens(tokens) {
1467
1324
  if (this._summary.tokens !== void 0) {
1468
1325
  this._ldClient.logger?.warn(
1469
- "LDGraphTracker: trackTotalTokens already called for this run \u2014 dropping duplicate call."
1326
+ "Skipping trackTotalTokens: tokens already recorded on this graph tracker. Call createTracker on the agent graph for a new run."
1470
1327
  );
1471
1328
  return;
1472
1329
  }
@@ -1481,7 +1338,7 @@ var LDGraphTrackerImpl = class _LDGraphTrackerImpl {
1481
1338
  trackPath(path) {
1482
1339
  if (this._summary.path !== void 0) {
1483
1340
  this._ldClient.logger?.warn(
1484
- "LDGraphTracker: trackPath already called for this run \u2014 dropping duplicate call."
1341
+ "Skipping trackPath: path already recorded on this graph tracker. Call createTracker on the agent graph for a new run."
1485
1342
  );
1486
1343
  return;
1487
1344
  }
@@ -1516,7 +1373,7 @@ var LDGraphTrackerImpl = class _LDGraphTrackerImpl {
1516
1373
 
1517
1374
  // src/sdkInfo.ts
1518
1375
  var aiSdkName = "@launchdarkly/server-sdk-ai";
1519
- var aiSdkVersion = "0.20.0";
1376
+ var aiSdkVersion = "1.0.1";
1520
1377
  var aiSdkLanguage = "javascript";
1521
1378
 
1522
1379
  // src/LDAIClientImpl.ts
@@ -1646,12 +1503,6 @@ var LDAIClientImpl = class {
1646
1503
  defaultAiProvider
1647
1504
  );
1648
1505
  }
1649
- /**
1650
- * @deprecated Use `completionConfig` instead. This method will be removed in a future version.
1651
- */
1652
- async config(key, context, defaultValue, variables) {
1653
- return this.completionConfig(key, context, defaultValue, variables);
1654
- }
1655
1506
  async _judgeConfig(key, context, defaultValue, variables) {
1656
1507
  if (variables?.message_history !== void 0) {
1657
1508
  this._logger?.warn(
@@ -1706,12 +1557,6 @@ var LDAIClientImpl = class {
1706
1557
  defaultAiProvider
1707
1558
  );
1708
1559
  }
1709
- /**
1710
- * @deprecated Use `agentConfig` instead. This method will be removed in a future version.
1711
- */
1712
- async agent(key, context, defaultValue, variables) {
1713
- return this.agentConfig(key, context, defaultValue, variables);
1714
- }
1715
1560
  async agentConfigs(agentConfigs, context) {
1716
1561
  this._ldClient.track(
1717
1562
  TRACK_USAGE_AGENT_CONFIGS,
@@ -1733,12 +1578,6 @@ var LDAIClientImpl = class {
1733
1578
  );
1734
1579
  return agents;
1735
1580
  }
1736
- /**
1737
- * @deprecated Use `agentConfigs` instead. This method will be removed in a future version.
1738
- */
1739
- async agents(agentConfigs, context) {
1740
- return this.agentConfigs(agentConfigs, context);
1741
- }
1742
1581
  async createJudge(key, context, defaultValue, variables, defaultAiProvider, sampleRate = 1) {
1743
1582
  this._ldClient.track(TRACK_USAGE_CREATE_JUDGE, context, key, 1);
1744
1583
  return this._createJudgeInstance(
@@ -1762,7 +1601,12 @@ var LDAIClientImpl = class {
1762
1601
  this._logger?.info(`Judge configuration is disabled: ${key}`);
1763
1602
  return void 0;
1764
1603
  }
1765
- const runner = await RunnerFactory.createModel(judgeConfig, this._logger, defaultAiProvider);
1604
+ const runner = await RunnerFactory.createModel(
1605
+ judgeConfig,
1606
+ this._logger,
1607
+ defaultAiProvider,
1608
+ false
1609
+ );
1766
1610
  if (!runner) {
1767
1611
  return void 0;
1768
1612
  }
@@ -1811,18 +1655,6 @@ var LDAIClientImpl = class {
1811
1655
  }
1812
1656
  return new ManagedAgent(config, runner, this._logger);
1813
1657
  }
1814
- /**
1815
- * @deprecated Use `createModel` instead. This method will be removed in a future version.
1816
- */
1817
- async createChat(key, context, defaultValue, variables, defaultAiProvider) {
1818
- return this.createModel(key, context, defaultValue, variables, defaultAiProvider);
1819
- }
1820
- /**
1821
- * @deprecated Use `createModel` instead. This method will be removed in a future version.
1822
- */
1823
- async initChat(key, context, defaultValue, variables, defaultAiProvider) {
1824
- return this.createModel(key, context, defaultValue, variables, defaultAiProvider);
1825
- }
1826
1658
  createTracker(token, context) {
1827
1659
  return LDAIConfigTrackerImpl.fromResumptionToken(token, this._ldClient, context);
1828
1660
  }
@@ -1900,6 +1732,81 @@ var LDAIClientImpl = class {
1900
1732
  }
1901
1733
  };
1902
1734
 
1735
+ // src/api/ManagedAgentGraph.ts
1736
+ var ManagedAgentGraph = class {
1737
+ constructor(_graphDefinition, _logger) {
1738
+ this._graphDefinition = _graphDefinition;
1739
+ this._logger = _logger;
1740
+ }
1741
+ /**
1742
+ * Runs the agent graph using the provided runner function and returns a ManagedGraphResult.
1743
+ *
1744
+ * The runner function receives the graph tracker and AgentGraphDefinition,
1745
+ * executes the graph, and returns an AgentGraphRunnerResult.
1746
+ *
1747
+ * run() returns before ManagedGraphResult.evaluations resolves.
1748
+ *
1749
+ * @param runner Async function that executes the graph and returns AgentGraphRunnerResult.
1750
+ * @returns ManagedGraphResult with LDAIGraphMetricSummary and evaluations promise.
1751
+ */
1752
+ async run(runner) {
1753
+ const graphTracker = this._graphDefinition.createTracker();
1754
+ const runnerResult = await runner(this._graphDefinition, graphTracker);
1755
+ const metrics = {
1756
+ success: runnerResult.metrics.success,
1757
+ path: runnerResult.metrics.path,
1758
+ durationMs: runnerResult.metrics.durationMs,
1759
+ tokens: runnerResult.metrics.tokens,
1760
+ nodeMetrics: this._trackNodeMetrics(runnerResult.metrics.nodeMetrics),
1761
+ resumptionToken: graphTracker.resumptionToken
1762
+ };
1763
+ const evaluations = Promise.resolve([]);
1764
+ return {
1765
+ content: runnerResult.content,
1766
+ metrics,
1767
+ raw: runnerResult.raw,
1768
+ evaluations
1769
+ };
1770
+ }
1771
+ /**
1772
+ * Converts per-node LDAIMetrics from the runner into LDAIMetricSummary by
1773
+ * creating a per-node tracker, firing tracking events, and calling getSummary().
1774
+ */
1775
+ _trackNodeMetrics(nodeMetrics) {
1776
+ const summaries = {};
1777
+ for (const [nodeKey, metrics] of Object.entries(nodeMetrics)) {
1778
+ const node = this._graphDefinition.getNode(nodeKey);
1779
+ if (!node) {
1780
+ this._logger?.warn(`ManagedAgentGraph: no node found for key "${nodeKey}", skipping metrics`);
1781
+ continue;
1782
+ }
1783
+ const tracker = node.getConfig().createTracker();
1784
+ if (metrics.tokens) {
1785
+ tracker.trackTokens(metrics.tokens);
1786
+ }
1787
+ if (metrics.durationMs !== void 0) {
1788
+ tracker.trackDuration(metrics.durationMs);
1789
+ }
1790
+ if (metrics.toolCalls?.length) {
1791
+ tracker.trackToolCalls(metrics.toolCalls);
1792
+ }
1793
+ if (metrics.success) {
1794
+ tracker.trackSuccess();
1795
+ } else {
1796
+ tracker.trackError();
1797
+ }
1798
+ summaries[nodeKey] = tracker.getSummary();
1799
+ }
1800
+ return summaries;
1801
+ }
1802
+ /**
1803
+ * Returns the underlying AgentGraphDefinition.
1804
+ */
1805
+ getGraphDefinition() {
1806
+ return this._graphDefinition;
1807
+ }
1808
+ };
1809
+
1903
1810
  // src/index.ts
1904
1811
  function initAi(ldClient) {
1905
1812
  return new LDAIClientImpl(ldClient);
@@ -1917,9 +1824,6 @@ function initAi(ldClient) {
1917
1824
  ManagedModel,
1918
1825
  RunnerFactory,
1919
1826
  SUPPORTED_AI_PROVIDERS,
1920
- createBedrockTokenUsage,
1921
- createOpenAiUsage,
1922
- createVercelAISDKTokenUsage,
1923
1827
  initAi
1924
1828
  });
1925
1829
  //# sourceMappingURL=index.cjs.map