@launchdarkly/server-sdk-ai 0.14.1 → 0.15.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 (197) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/index.cjs +1117 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.cts +1022 -0
  5. package/dist/index.d.ts +1022 -0
  6. package/dist/index.js +1071 -0
  7. package/dist/index.js.map +1 -0
  8. package/package.json +22 -5
  9. package/__tests__/Judge.test.ts +0 -521
  10. package/__tests__/LDAIClientImpl.test.ts +0 -594
  11. package/__tests__/LDAIConfigTrackerImpl.test.ts +0 -815
  12. package/__tests__/TokenUsage.test.ts +0 -119
  13. package/__tests__/TrackedChat.test.ts +0 -231
  14. package/dist/package.json +0 -53
  15. package/dist/src/LDAIClientImpl.d.ts +0 -39
  16. package/dist/src/LDAIClientImpl.d.ts.map +0 -1
  17. package/dist/src/LDAIClientImpl.js +0 -164
  18. package/dist/src/LDAIClientImpl.js.map +0 -1
  19. package/dist/src/LDAIConfigTrackerImpl.d.ts +0 -74
  20. package/dist/src/LDAIConfigTrackerImpl.d.ts.map +0 -1
  21. package/dist/src/LDAIConfigTrackerImpl.js +0 -207
  22. package/dist/src/LDAIConfigTrackerImpl.js.map +0 -1
  23. package/dist/src/LDClientMin.d.ts +0 -11
  24. package/dist/src/LDClientMin.d.ts.map +0 -1
  25. package/dist/src/LDClientMin.js +0 -3
  26. package/dist/src/LDClientMin.js.map +0 -1
  27. package/dist/src/api/LDAIClient.d.ts +0 -258
  28. package/dist/src/api/LDAIClient.d.ts.map +0 -1
  29. package/dist/src/api/LDAIClient.js +0 -3
  30. package/dist/src/api/LDAIClient.js.map +0 -1
  31. package/dist/src/api/chat/TrackedChat.d.ts +0 -72
  32. package/dist/src/api/chat/TrackedChat.d.ts.map +0 -1
  33. package/dist/src/api/chat/TrackedChat.js +0 -125
  34. package/dist/src/api/chat/TrackedChat.js.map +0 -1
  35. package/dist/src/api/chat/index.d.ts +0 -3
  36. package/dist/src/api/chat/index.d.ts.map +0 -1
  37. package/dist/src/api/chat/index.js +0 -19
  38. package/dist/src/api/chat/index.js.map +0 -1
  39. package/dist/src/api/chat/types.d.ts +0 -22
  40. package/dist/src/api/chat/types.d.ts.map +0 -1
  41. package/dist/src/api/chat/types.js +0 -3
  42. package/dist/src/api/chat/types.js.map +0 -1
  43. package/dist/src/api/config/LDAIConfigTracker.d.ts +0 -209
  44. package/dist/src/api/config/LDAIConfigTracker.d.ts.map +0 -1
  45. package/dist/src/api/config/LDAIConfigTracker.js +0 -3
  46. package/dist/src/api/config/LDAIConfigTracker.js.map +0 -1
  47. package/dist/src/api/config/LDAIConfigUtils.d.ts +0 -2
  48. package/dist/src/api/config/LDAIConfigUtils.d.ts.map +0 -1
  49. package/dist/src/api/config/LDAIConfigUtils.js +0 -145
  50. package/dist/src/api/config/LDAIConfigUtils.js.map +0 -1
  51. package/dist/src/api/config/index.d.ts +0 -3
  52. package/dist/src/api/config/index.d.ts.map +0 -1
  53. package/dist/src/api/config/index.js +0 -18
  54. package/dist/src/api/config/index.js.map +0 -1
  55. package/dist/src/api/config/types.d.ts +0 -206
  56. package/dist/src/api/config/types.d.ts.map +0 -1
  57. package/dist/src/api/config/types.js +0 -3
  58. package/dist/src/api/config/types.js.map +0 -1
  59. package/dist/src/api/index.d.ts +0 -7
  60. package/dist/src/api/index.d.ts.map +0 -1
  61. package/dist/src/api/index.js +0 -23
  62. package/dist/src/api/index.js.map +0 -1
  63. package/dist/src/api/judge/EvaluationSchemaBuilder.d.ts +0 -11
  64. package/dist/src/api/judge/EvaluationSchemaBuilder.d.ts.map +0 -1
  65. package/dist/src/api/judge/EvaluationSchemaBuilder.js +0 -52
  66. package/dist/src/api/judge/EvaluationSchemaBuilder.js.map +0 -1
  67. package/dist/src/api/judge/Judge.d.ts +0 -63
  68. package/dist/src/api/judge/Judge.d.ts.map +0 -1
  69. package/dist/src/api/judge/Judge.js +0 -151
  70. package/dist/src/api/judge/Judge.js.map +0 -1
  71. package/dist/src/api/judge/index.d.ts +0 -3
  72. package/dist/src/api/judge/index.d.ts.map +0 -1
  73. package/dist/src/api/judge/index.js +0 -6
  74. package/dist/src/api/judge/index.js.map +0 -1
  75. package/dist/src/api/judge/types.d.ts +0 -37
  76. package/dist/src/api/judge/types.d.ts.map +0 -1
  77. package/dist/src/api/judge/types.js +0 -3
  78. package/dist/src/api/judge/types.js.map +0 -1
  79. package/dist/src/api/metrics/BedrockTokenUsage.d.ts +0 -7
  80. package/dist/src/api/metrics/BedrockTokenUsage.d.ts.map +0 -1
  81. package/dist/src/api/metrics/BedrockTokenUsage.js +0 -12
  82. package/dist/src/api/metrics/BedrockTokenUsage.js.map +0 -1
  83. package/dist/src/api/metrics/LDAIMetrics.d.ts +0 -17
  84. package/dist/src/api/metrics/LDAIMetrics.d.ts.map +0 -1
  85. package/dist/src/api/metrics/LDAIMetrics.js +0 -3
  86. package/dist/src/api/metrics/LDAIMetrics.js.map +0 -1
  87. package/dist/src/api/metrics/LDFeedbackKind.d.ts +0 -14
  88. package/dist/src/api/metrics/LDFeedbackKind.d.ts.map +0 -1
  89. package/dist/src/api/metrics/LDFeedbackKind.js +0 -18
  90. package/dist/src/api/metrics/LDFeedbackKind.js.map +0 -1
  91. package/dist/src/api/metrics/LDTokenUsage.d.ts +0 -18
  92. package/dist/src/api/metrics/LDTokenUsage.d.ts.map +0 -1
  93. package/dist/src/api/metrics/LDTokenUsage.js +0 -3
  94. package/dist/src/api/metrics/LDTokenUsage.js.map +0 -1
  95. package/dist/src/api/metrics/OpenAiUsage.d.ts +0 -7
  96. package/dist/src/api/metrics/OpenAiUsage.d.ts.map +0 -1
  97. package/dist/src/api/metrics/OpenAiUsage.js +0 -13
  98. package/dist/src/api/metrics/OpenAiUsage.js.map +0 -1
  99. package/dist/src/api/metrics/VercelAISDKTokenUsage.d.ts +0 -9
  100. package/dist/src/api/metrics/VercelAISDKTokenUsage.d.ts.map +0 -1
  101. package/dist/src/api/metrics/VercelAISDKTokenUsage.js +0 -13
  102. package/dist/src/api/metrics/VercelAISDKTokenUsage.js.map +0 -1
  103. package/dist/src/api/metrics/index.d.ts +0 -7
  104. package/dist/src/api/metrics/index.d.ts.map +0 -1
  105. package/dist/src/api/metrics/index.js +0 -23
  106. package/dist/src/api/metrics/index.js.map +0 -1
  107. package/dist/src/api/providers/AIProvider.d.ts +0 -52
  108. package/dist/src/api/providers/AIProvider.d.ts.map +0 -1
  109. package/dist/src/api/providers/AIProvider.js +0 -88
  110. package/dist/src/api/providers/AIProvider.js.map +0 -1
  111. package/dist/src/api/providers/AIProviderFactory.d.ts +0 -39
  112. package/dist/src/api/providers/AIProviderFactory.d.ts.map +0 -1
  113. package/dist/src/api/providers/AIProviderFactory.js +0 -102
  114. package/dist/src/api/providers/AIProviderFactory.js.map +0 -1
  115. package/dist/src/api/providers/index.d.ts +0 -3
  116. package/dist/src/api/providers/index.d.ts.map +0 -1
  117. package/dist/src/api/providers/index.js +0 -19
  118. package/dist/src/api/providers/index.js.map +0 -1
  119. package/dist/src/index.d.ts +0 -19
  120. package/dist/src/index.d.ts.map +0 -1
  121. package/dist/src/index.js +0 -29
  122. package/dist/src/index.js.map +0 -1
  123. package/docs/.nojekyll +0 -1
  124. package/docs/assets/highlight.css +0 -92
  125. package/docs/assets/main.js +0 -58
  126. package/docs/assets/search.js +0 -1
  127. package/docs/assets/style.css +0 -1379
  128. package/docs/classes/AIProvider.html +0 -210
  129. package/docs/classes/AIProviderFactory.html +0 -208
  130. package/docs/classes/Judge.html +0 -322
  131. package/docs/classes/TrackedChat.html +0 -322
  132. package/docs/enums/LDFeedbackKind.html +0 -115
  133. package/docs/functions/createBedrockTokenUsage.html +0 -94
  134. package/docs/functions/createOpenAiUsage.html +0 -94
  135. package/docs/functions/createVercelAISDKTokenUsage.html +0 -98
  136. package/docs/functions/initAi.html +0 -93
  137. package/docs/index.html +0 -136
  138. package/docs/interfaces/ChatResponse.html +0 -130
  139. package/docs/interfaces/EvalScore.html +0 -119
  140. package/docs/interfaces/JudgeResponse.html +0 -139
  141. package/docs/interfaces/LDAIAgentConfig.html +0 -178
  142. package/docs/interfaces/LDAIAgentConfigDefault.html +0 -155
  143. package/docs/interfaces/LDAIAgentRequestConfig.html +0 -129
  144. package/docs/interfaces/LDAIClient.html +0 -449
  145. package/docs/interfaces/LDAICompletionConfig.html +0 -178
  146. package/docs/interfaces/LDAICompletionConfigDefault.html +0 -155
  147. package/docs/interfaces/LDAIConfig.html +0 -158
  148. package/docs/interfaces/LDAIConfigDefault.html +0 -133
  149. package/docs/interfaces/LDAIConfigTracker.html +0 -530
  150. package/docs/interfaces/LDAIJudgeConfig.html +0 -178
  151. package/docs/interfaces/LDAIJudgeConfigDefault.html +0 -155
  152. package/docs/interfaces/LDAIMetrics.html +0 -121
  153. package/docs/interfaces/LDJudge.html +0 -119
  154. package/docs/interfaces/LDJudgeConfiguration.html +0 -109
  155. package/docs/interfaces/LDLogger.html +0 -189
  156. package/docs/interfaces/LDMessage.html +0 -119
  157. package/docs/interfaces/LDModelConfig.html +0 -139
  158. package/docs/interfaces/LDProviderConfig.html +0 -105
  159. package/docs/interfaces/LDTokenUsage.html +0 -129
  160. package/docs/interfaces/StructuredResponse.html +0 -129
  161. package/docs/types/LDAIConfigDefaultKind.html +0 -81
  162. package/docs/types/LDAIConfigKind.html +0 -81
  163. package/docs/types/LDAIConfigMode.html +0 -81
  164. package/docs/types/SupportedAIProvider.html +0 -81
  165. package/docs/variables/SUPPORTED_AI_PROVIDERS.html +0 -81
  166. package/jest.config.js +0 -7
  167. package/src/LDAIClientImpl.ts +0 -327
  168. package/src/LDAIConfigTrackerImpl.ts +0 -288
  169. package/src/LDClientMin.ts +0 -18
  170. package/src/api/LDAIClient.ts +0 -325
  171. package/src/api/chat/TrackedChat.ts +0 -163
  172. package/src/api/chat/index.ts +0 -2
  173. package/src/api/chat/types.ts +0 -24
  174. package/src/api/config/LDAIConfigTracker.ts +0 -238
  175. package/src/api/config/LDAIConfigUtils.ts +0 -212
  176. package/src/api/config/index.ts +0 -3
  177. package/src/api/config/types.ts +0 -260
  178. package/src/api/index.ts +0 -6
  179. package/src/api/judge/EvaluationSchemaBuilder.ts +0 -54
  180. package/src/api/judge/Judge.ts +0 -218
  181. package/src/api/judge/index.ts +0 -2
  182. package/src/api/judge/types.ts +0 -41
  183. package/src/api/metrics/BedrockTokenUsage.ts +0 -13
  184. package/src/api/metrics/LDAIMetrics.ts +0 -18
  185. package/src/api/metrics/LDFeedbackKind.ts +0 -13
  186. package/src/api/metrics/LDTokenUsage.ts +0 -19
  187. package/src/api/metrics/OpenAiUsage.ts +0 -13
  188. package/src/api/metrics/VercelAISDKTokenUsage.ts +0 -15
  189. package/src/api/metrics/index.ts +0 -6
  190. package/src/api/providers/AIProvider.ts +0 -94
  191. package/src/api/providers/AIProviderFactory.ts +0 -152
  192. package/src/api/providers/index.ts +0 -2
  193. package/src/index.ts +0 -24
  194. package/tsconfig.eslint.json +0 -5
  195. package/tsconfig.json +0 -21
  196. package/tsconfig.ref.json +0 -7
  197. package/typedoc.json +0 -5
@@ -1,72 +0,0 @@
1
- import { LDLogger } from '@launchdarkly/js-server-sdk-common';
2
- import { LDAIConfigTracker } from '../config/LDAIConfigTracker';
3
- import { LDAICompletionConfig, LDMessage } from '../config/types';
4
- import { Judge } from '../judge/Judge';
5
- import { AIProvider } from '../providers/AIProvider';
6
- import { ChatResponse } from './types';
7
- /**
8
- * Concrete implementation of TrackedChat that provides chat functionality
9
- * by delegating to an AIProvider implementation.
10
- * This class handles conversation management and tracking, while delegating
11
- * the actual model invocation to the provider.
12
- */
13
- export declare class TrackedChat {
14
- protected readonly aiConfig: LDAICompletionConfig;
15
- protected readonly tracker: LDAIConfigTracker;
16
- protected readonly provider: AIProvider;
17
- protected readonly judges: Record<string, Judge>;
18
- private readonly _logger?;
19
- protected messages: LDMessage[];
20
- constructor(aiConfig: LDAICompletionConfig, tracker: LDAIConfigTracker, provider: AIProvider, judges?: Record<string, Judge>, _logger?: LDLogger | undefined);
21
- /**
22
- * Invoke the chat model with a prompt string.
23
- * This method handles conversation management and tracking, delegating to the provider's invokeModel method.
24
- */
25
- invoke(prompt: string): Promise<ChatResponse>;
26
- /**
27
- * Evaluates the response with all configured judges.
28
- * Returns a promise that resolves to an array of evaluation results.
29
- *
30
- * @param messages Array of messages representing the conversation history
31
- * @param response The AI response to be evaluated
32
- * @returns Promise resolving to array of judge evaluation results
33
- */
34
- private _evaluateWithJudges;
35
- /**
36
- * Get the underlying AI configuration used to initialize this TrackedChat.
37
- */
38
- getConfig(): LDAICompletionConfig;
39
- /**
40
- * Get the underlying AI configuration tracker used to initialize this TrackedChat.
41
- */
42
- getTracker(): LDAIConfigTracker;
43
- /**
44
- * Get the underlying AI provider instance.
45
- * This provides direct access to the provider for advanced use cases.
46
- */
47
- getProvider(): AIProvider;
48
- /**
49
- * Get the judges associated with this TrackedChat.
50
- * Returns a record of judge instances keyed by their configuration keys.
51
- */
52
- getJudges(): Record<string, Judge>;
53
- /**
54
- * Append messages to the conversation history.
55
- * Adds messages to the conversation history without invoking the model,
56
- * which is useful for managing multi-turn conversations or injecting context.
57
- *
58
- * @param messages Array of messages to append to the conversation history
59
- */
60
- appendMessages(messages: LDMessage[]): void;
61
- /**
62
- * Get all messages in the conversation history.
63
- *
64
- * @param includeConfigMessages Whether to include the config messages from the AIConfig.
65
- * Defaults to false.
66
- * @returns Array of messages. When includeConfigMessages is true, returns both config
67
- * messages and conversation history with config messages prepended. When false,
68
- * returns only the conversation history messages.
69
- */
70
- getMessages(includeConfigMessages?: boolean): LDMessage[];
71
- }
72
- //# sourceMappingURL=TrackedChat.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TrackedChat.d.ts","sourceRoot":"","sources":["../../../../src/api/chat/TrackedChat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAE9D,OAAO,EAAE,iBAAiB,EAAE,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-1,125 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TrackedChat = void 0;
4
- /**
5
- * Concrete implementation of TrackedChat that provides chat functionality
6
- * by delegating to an AIProvider implementation.
7
- * This class handles conversation management and tracking, while delegating
8
- * the actual model invocation to the provider.
9
- */
10
- class TrackedChat {
11
- constructor(aiConfig, tracker, provider, judges = {}, _logger) {
12
- this.aiConfig = aiConfig;
13
- this.tracker = tracker;
14
- this.provider = provider;
15
- this.judges = judges;
16
- this._logger = _logger;
17
- this.messages = [];
18
- }
19
- /**
20
- * Invoke the chat model with a prompt string.
21
- * This method handles conversation management and tracking, delegating to the provider's invokeModel method.
22
- */
23
- async invoke(prompt) {
24
- var _a;
25
- // Convert prompt string to LDMessage with role 'user' and add to conversation history
26
- const userMessage = {
27
- role: 'user',
28
- content: prompt,
29
- };
30
- this.messages.push(userMessage);
31
- // Prepend config messages to conversation history for model invocation
32
- const configMessages = this.aiConfig.messages || [];
33
- const allMessages = [...configMessages, ...this.messages];
34
- // Delegate to provider-specific implementation with tracking
35
- const response = await this.tracker.trackMetricsOf((result) => result.metrics, () => this.provider.invokeModel(allMessages));
36
- if (((_a = this.aiConfig.judgeConfiguration) === null || _a === void 0 ? void 0 : _a.judges) &&
37
- this.aiConfig.judgeConfiguration.judges.length > 0) {
38
- response.evaluations = this._evaluateWithJudges(this.messages, response);
39
- }
40
- this.messages.push(response.message);
41
- return response;
42
- }
43
- /**
44
- * Evaluates the response with all configured judges.
45
- * Returns a promise that resolves to an array of evaluation results.
46
- *
47
- * @param messages Array of messages representing the conversation history
48
- * @param response The AI response to be evaluated
49
- * @returns Promise resolving to array of judge evaluation results
50
- */
51
- async _evaluateWithJudges(messages, response) {
52
- const judgeConfigs = this.aiConfig.judgeConfiguration.judges;
53
- // Start all judge evaluations in parallel
54
- const evaluationPromises = judgeConfigs.map(async (judgeConfig) => {
55
- var _a;
56
- const judge = this.judges[judgeConfig.key];
57
- if (!judge) {
58
- (_a = this._logger) === null || _a === void 0 ? void 0 : _a.warn(`Judge configuration is not enabled: ${judgeConfig.key}`, this.tracker.getTrackData());
59
- return undefined;
60
- }
61
- const judgeResponse = await judge.evaluateMessages(messages, response, judgeConfig.samplingRate);
62
- if (judgeResponse && judgeResponse.success) {
63
- this.tracker.trackJudgeResponse(judgeResponse);
64
- }
65
- return judgeResponse;
66
- });
67
- // ensure all evaluations complete even if some fail
68
- const results = await Promise.allSettled(evaluationPromises);
69
- return results.map((result) => (result.status === 'fulfilled' ? result.value : undefined));
70
- }
71
- /**
72
- * Get the underlying AI configuration used to initialize this TrackedChat.
73
- */
74
- getConfig() {
75
- return this.aiConfig;
76
- }
77
- /**
78
- * Get the underlying AI configuration tracker used to initialize this TrackedChat.
79
- */
80
- getTracker() {
81
- return this.tracker;
82
- }
83
- /**
84
- * Get the underlying AI provider instance.
85
- * This provides direct access to the provider for advanced use cases.
86
- */
87
- getProvider() {
88
- return this.provider;
89
- }
90
- /**
91
- * Get the judges associated with this TrackedChat.
92
- * Returns a record of judge instances keyed by their configuration keys.
93
- */
94
- getJudges() {
95
- return this.judges;
96
- }
97
- /**
98
- * Append messages to the conversation history.
99
- * Adds messages to the conversation history without invoking the model,
100
- * which is useful for managing multi-turn conversations or injecting context.
101
- *
102
- * @param messages Array of messages to append to the conversation history
103
- */
104
- appendMessages(messages) {
105
- this.messages.push(...messages);
106
- }
107
- /**
108
- * Get all messages in the conversation history.
109
- *
110
- * @param includeConfigMessages Whether to include the config messages from the AIConfig.
111
- * Defaults to false.
112
- * @returns Array of messages. When includeConfigMessages is true, returns both config
113
- * messages and conversation history with config messages prepended. When false,
114
- * returns only the conversation history messages.
115
- */
116
- getMessages(includeConfigMessages = false) {
117
- if (includeConfigMessages) {
118
- const configMessages = this.aiConfig.messages || [];
119
- return [...configMessages, ...this.messages];
120
- }
121
- return [...this.messages];
122
- }
123
- }
124
- exports.TrackedChat = TrackedChat;
125
- //# sourceMappingURL=TrackedChat.js.map
@@ -1 +0,0 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C;IAC7F,CAAC;IAED;;OAEG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,WAAW;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;;OAGG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;;;;OAMG;IACH,cAAc,CAAC,QAAqB;QAClC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC;IAClC,CAAC;IAED;;;;;;;;OAQG;IACH,WAAW,CAAC,wBAAiC,KAAK;QAChD,IAAI,qBAAqB,EAAE;YACzB,MAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,IAAI,EAAE,CAAC;YACpD,OAAO,CAAC,GAAG,cAAc,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;SAC9C;QACD,OAAO,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5B,CAAC;CACF;AAnJD,kCAmJC"}
@@ -1,3 +0,0 @@
1
- export * from './types';
2
- export * from './TrackedChat';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/api/chat/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC"}
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./types"), exports);
18
- __exportStar(require("./TrackedChat"), exports);
19
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/api/chat/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,gDAA8B"}
@@ -1,22 +0,0 @@
1
- import { LDMessage } from '../config/types';
2
- import { JudgeResponse } from '../judge/types';
3
- import { LDAIMetrics } from '../metrics/LDAIMetrics';
4
- /**
5
- * Chat response structure.
6
- */
7
- export interface ChatResponse {
8
- /**
9
- * The response message from the AI.
10
- */
11
- message: LDMessage;
12
- /**
13
- * Metrics information including success status and token usage.
14
- */
15
- metrics: LDAIMetrics;
16
- /**
17
- * Promise that resolves to judge evaluation results.
18
- * Only present when judges are configured for evaluation.
19
- */
20
- evaluations?: Promise<Array<JudgeResponse | undefined>>;
21
- }
22
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/api/chat/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,OAAO,EAAE,SAAS,CAAC;IAEnB;;OAEG;IACH,OAAO,EAAE,WAAW,CAAC;IAErB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,aAAa,GAAG,SAAS,CAAC,CAAC,CAAC;CACzD"}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/api/chat/types.ts"],"names":[],"mappings":""}
@@ -1,209 +0,0 @@
1
- import { EvalScore, JudgeResponse } from '../judge/types';
2
- import { LDAIMetrics, LDFeedbackKind, LDTokenUsage } from '../metrics';
3
- /**
4
- * Metrics which have been tracked.
5
- */
6
- export interface LDAIMetricSummary {
7
- /**
8
- * The duration of generation.
9
- */
10
- durationMs?: number;
11
- /**
12
- * Information about token usage.
13
- */
14
- tokens?: LDTokenUsage;
15
- /**
16
- * Was generation successful.
17
- */
18
- success?: boolean;
19
- /**
20
- * Any sentiment about the generation.
21
- */
22
- feedback?: {
23
- kind: LDFeedbackKind;
24
- };
25
- /**
26
- * Time to first token for this generation.
27
- */
28
- timeToFirstTokenMs?: number;
29
- }
30
- /**
31
- * The LDAIConfigTracker is used to track various details about AI operations.
32
- */
33
- export interface LDAIConfigTracker {
34
- /**
35
- * Get the data for tracking.
36
- */
37
- getTrackData(): {
38
- variationKey: string;
39
- configKey: string;
40
- version: number;
41
- modelName: string;
42
- providerName: string;
43
- aiSdkName: string;
44
- aiSdkVersion: string;
45
- };
46
- /**
47
- * Track the duration of generation.
48
- *
49
- * Ideally this would not include overhead time such as network communication.
50
- *
51
- * @param durationMs The duration in milliseconds.
52
- */
53
- trackDuration(durationMs: number): void;
54
- /**
55
- * Track information about token usage.
56
- *
57
- * @param tokens Token usage information.
58
- */
59
- trackTokens(tokens: LDTokenUsage): void;
60
- /**
61
- * Generation was successful.
62
- */
63
- trackSuccess(): void;
64
- /**
65
- * An error was encountered during generation.
66
- */
67
- trackError(): void;
68
- /**
69
- * Track sentiment about the generation.
70
- *
71
- * @param feedback Feedback about the generation.
72
- */
73
- trackFeedback(feedback: {
74
- kind: LDFeedbackKind;
75
- }): void;
76
- /**
77
- * Track the time to first token for this generation.
78
- *
79
- * @param timeToFirstTokenMs The duration in milliseconds.
80
- */
81
- trackTimeToFirstToken(timeToFirstTokenMs: number): void;
82
- /**
83
- * Track evaluation scores for multiple metrics.
84
- *
85
- * @param scores Record mapping metric keys to their evaluation scores
86
- */
87
- trackEvalScores(scores: Record<string, EvalScore>): void;
88
- /**
89
- * Track a judge response containing evaluation scores and judge configuration key.
90
- *
91
- * @param response Judge response containing evaluation scores and judge configuration key
92
- */
93
- trackJudgeResponse(response: JudgeResponse): void;
94
- /**
95
- * Track the duration of execution of the provided function.
96
- *
97
- * If the provided function throws, then this method will also throw.
98
- * In the case the provided function throws, this function will still record the duration.
99
- *
100
- * This function does not automatically record an error when the function throws.
101
- *
102
- * @param func The function to track the duration of.
103
- * @returns The result of the function.
104
- */
105
- trackDurationOf(func: () => Promise<any>): Promise<any>;
106
- /**
107
- * Track metrics for a generic AI operation.
108
- *
109
- * This function will track the duration of the operation, extract metrics using the provided
110
- * metrics extractor function, and track success or error status accordingly.
111
- *
112
- * If the provided function throws, then this method will also throw.
113
- * In the case the provided function throws, this function will record the duration and an error.
114
- * A failed operation will not have any token usage data.
115
- *
116
- * @param metricsExtractor Function that extracts LDAIMetrics from the operation result
117
- * @param func Function which executes the operation
118
- * @returns The result of the operation
119
- */
120
- trackMetricsOf<TRes>(metricsExtractor: (result: TRes) => LDAIMetrics, func: () => Promise<TRes>): Promise<TRes>;
121
- /**
122
- * Track metrics for a streaming AI operation.
123
- *
124
- * This function will track the duration of the operation, extract metrics using the provided
125
- * metrics extractor function, and track success or error status accordingly.
126
- *
127
- * Unlike trackMetricsOf, this method is designed for streaming operations where:
128
- * - The stream is created and returned immediately (synchronously)
129
- * - Metrics are extracted asynchronously in the background once the stream completes
130
- * - Duration is tracked from stream creation to metrics extraction completion
131
- *
132
- * The stream is returned immediately so the caller can begin consuming it without waiting.
133
- * Metrics extraction happens in the background and does not block stream consumption.
134
- *
135
- * If the stream creator throws, then this method will also throw and record an error.
136
- * If metrics extraction fails, the error is logged but does not affect stream consumption.
137
- *
138
- * @param streamCreator Function that creates and returns the stream (synchronous)
139
- * @param metricsExtractor Function that asynchronously extracts metrics from the stream
140
- * @returns The stream result (returned immediately, not a Promise)
141
- */
142
- trackStreamMetricsOf<TStream>(streamCreator: () => TStream, metricsExtractor: (stream: TStream) => Promise<LDAIMetrics>): TStream;
143
- /**
144
- * Track an OpenAI operation.
145
- *
146
- * This function will track the duration of the operation, the token usage, and the success or error status.
147
- *
148
- * If the provided function throws, then this method will also throw.
149
- * In the case the provided function throws, this function will record the duration and an error.
150
- * A failed operation will not have any token usage data.
151
- *
152
- * @param func Function which executes the operation.
153
- * @returns The result of the operation.
154
- */
155
- trackOpenAIMetrics<TRes extends {
156
- usage?: {
157
- total_tokens?: number;
158
- prompt_tokens?: number;
159
- completion_tokens?: number;
160
- };
161
- }>(func: () => Promise<TRes>): Promise<TRes>;
162
- /**
163
- * Track an operation which uses Bedrock.
164
- *
165
- * This function will track the duration of the operation, the token usage, and the success or error status.
166
- *
167
- * @param res The result of the Bedrock operation.
168
- * @returns The input operation.
169
- */
170
- trackBedrockConverseMetrics<TRes extends {
171
- $metadata: {
172
- httpStatusCode?: number;
173
- };
174
- metrics?: {
175
- latencyMs?: number;
176
- };
177
- usage?: {
178
- inputTokens?: number;
179
- outputTokens?: number;
180
- totalTokens?: number;
181
- };
182
- }>(res: TRes): TRes;
183
- /**
184
- * Track a Vercel AI SDK generateText operation.
185
- *
186
- * This function will track the duration of the operation, the token usage, and the success or error status.
187
- *
188
- * If the provided function throws, then this method will also throw.
189
- * In the case the provided function throws, this function will record the duration and an error.
190
- * A failed operation will not have any token usage data.
191
- *
192
- * @param func Function which executes the operation.
193
- * @returns The result of the operation.
194
- */
195
- trackVercelAISDKGenerateTextMetrics<TRes extends {
196
- usage?: {
197
- totalTokens?: number;
198
- inputTokens?: number;
199
- promptTokens?: number;
200
- outputTokens?: number;
201
- completionTokens?: number;
202
- };
203
- }>(func: () => Promise<TRes>): Promise<TRes>;
204
- /**
205
- * Get a summary of the tracked metrics.
206
- */
207
- getSummary(): LDAIMetricSummary;
208
- }
209
- //# sourceMappingURL=LDAIConfigTracker.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LDAIConfigTracker.d.ts","sourceRoot":"","sources":["../../../../src/api/config/LDAIConfigTracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEvE;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,MAAM,CAAC,EAAE,YAAY,CAAC;IAEtB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,QAAQ,CAAC,EAAE;QAAE,IAAI,EAAE,cAAc,CAAA;KAAE,CAAC;IAEpC;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,YAAY,IAAI;QACd,YAAY,EAAE,MAAM,CAAC;QACrB,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,YAAY,EAAE,MAAM,CAAC;QACrB,SAAS,EAAE,MAAM,CAAC;QAClB,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;IACF;;;;;;OAMG;IACH,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAExC;;;;OAIG;IACH,WAAW,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAExC;;OAEG;IACH,YAAY,IAAI,IAAI,CAAC;IAErB;;OAEG;IACH,UAAU,IAAI,IAAI,CAAC;IA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AA;SAAE,CAAC;QACvC,OAAO,CAAC,EAAE;YAAE,SAAS,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QACjC,KAAK,CAAC,EAAE;YACN,WAAW,CAAC,EAAE,MAAM,CAAC;YACrB,YAAY,CAAC,EAAE,MAAM,CAAC;YACtB,WAAW,CAAC,EAAE,MAAM,CAAC;SACtB,CAAC;KACH,EAED,GAAG,EAAE,IAAI,GACR,IAAI,CAAC;IAER;;;;;;;;;;;OAWG;IACH,mCAAmC,CACjC,IAAI,SAAS;QACX,KAAK,CAAC,EAAE;YACN,WAAW,CAAC,EAAE,MAAM,CAAC;YACrB,WAAW,CAAC,EAAE,MAAM,CAAC;YACrB,YAAY,CAAC,EAAE,MAAM,CAAC;YACtB,YAAY,CAAC,EAAE,MAAM,CAAC;YACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;SAC3B,CAAC;KACH,EAED,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GACxB,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjB;;OAEG;IACH,UAAU,IAAI,iBAAiB,CAAC;CACjC"}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=LDAIConfigTracker.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LDAIConfigTracker.js","sourceRoot":"","sources":["../../../../src/api/config/LDAIConfigTracker.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=LDAIConfigUtils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LDAIConfigUtils.d.ts","sourceRoot":"","sources":["../../../../src/api/config/LDAIConfigUtils.ts"],"names":[],"mappings":""}
@@ -1,145 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LDAIConfigUtils = void 0;
4
- /**
5
- * Utility class for converting between AI configuration types and LaunchDarkly flag values.
6
- *
7
- * @internal - This class and its types are internal implementation details and should not be used by SDK consumers.
8
- */
9
- class LDAIConfigUtils {
10
- /**
11
- * Converts a default AI configuration to a LaunchDarkly flag value format.
12
- *
13
- * @param config The default AI configuration to convert
14
- * @param mode The mode for the configuration
15
- * @returns The flag value structure for LaunchDarkly
16
- */
17
- static toFlagValue(config, mode) {
18
- var _a;
19
- const flagValue = {
20
- _ldMeta: {
21
- variationKey: '',
22
- enabled: (_a = config.enabled) !== null && _a !== void 0 ? _a : false,
23
- mode,
24
- },
25
- model: config.model,
26
- };
27
- if ('messages' in config && config.messages !== undefined) {
28
- flagValue.messages = config.messages;
29
- }
30
- if (config.provider !== undefined) {
31
- flagValue.provider = config.provider;
32
- }
33
- if ('instructions' in config && config.instructions !== undefined) {
34
- flagValue.instructions = config.instructions;
35
- }
36
- if ('evaluationMetricKeys' in config && config.evaluationMetricKeys !== undefined) {
37
- flagValue.evaluationMetricKeys = config.evaluationMetricKeys;
38
- }
39
- if ('judgeConfiguration' in config && config.judgeConfiguration !== undefined) {
40
- flagValue.judgeConfiguration = config.judgeConfiguration;
41
- }
42
- return flagValue;
43
- }
44
- /**
45
- * Converts a LaunchDarkly flag value to the appropriate AI configuration type.
46
- *
47
- * @param flagValue The flag value from LaunchDarkly
48
- * @param tracker The tracker to add to the config
49
- * @returns The appropriate AI configuration type
50
- */
51
- static fromFlagValue(key, flagValue, tracker) {
52
- var _a;
53
- // Determine the actual mode from flag value
54
- // eslint-disable-next-line no-underscore-dangle
55
- const flagValueMode = (_a = flagValue._ldMeta) === null || _a === void 0 ? void 0 : _a.mode;
56
- switch (flagValueMode) {
57
- case 'agent':
58
- return this.toAgentConfig(key, flagValue, tracker);
59
- case 'judge':
60
- return this.toJudgeConfig(key, flagValue, tracker);
61
- case 'completion':
62
- default:
63
- return this.toCompletionConfig(key, flagValue, tracker);
64
- }
65
- }
66
- /**
67
- * Creates a disabled configuration of the specified mode.
68
- *
69
- * @param mode The mode for the disabled config
70
- * @returns A disabled config of the appropriate type
71
- */
72
- static createDisabledConfig(key, mode) {
73
- switch (mode) {
74
- case 'agent':
75
- return {
76
- key,
77
- enabled: false,
78
- tracker: undefined,
79
- };
80
- case 'judge':
81
- return {
82
- key,
83
- enabled: false,
84
- tracker: undefined,
85
- evaluationMetricKeys: [],
86
- };
87
- case 'completion':
88
- default:
89
- // Default to completion config for completion mode or any unexpected mode
90
- return {
91
- key,
92
- enabled: false,
93
- tracker: undefined,
94
- };
95
- }
96
- }
97
- /**
98
- * Creates the base configuration that all config types share.
99
- *
100
- * @param flagValue The flag value from LaunchDarkly
101
- * @returns Base configuration object
102
- */
103
- static _toBaseConfig(key, flagValue) {
104
- var _a, _b;
105
- return {
106
- key,
107
- // eslint-disable-next-line no-underscore-dangle
108
- enabled: (_b = (_a = flagValue._ldMeta) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : false,
109
- model: flagValue.model,
110
- provider: flagValue.provider,
111
- };
112
- }
113
- /**
114
- * Creates a completion config from flag value data.
115
- *
116
- * @param flagValue The flag value from LaunchDarkly
117
- * @param tracker The tracker to add to the config
118
- * @returns A completion configuration
119
- */
120
- static toCompletionConfig(key, flagValue, tracker) {
121
- return Object.assign(Object.assign({}, this._toBaseConfig(key, flagValue)), { tracker, messages: flagValue.messages, judgeConfiguration: flagValue.judgeConfiguration });
122
- }
123
- /**
124
- * Creates an agent config from flag value data.
125
- *
126
- * @param flagValue The flag value from LaunchDarkly
127
- * @param tracker The tracker to add to the config
128
- * @returns An agent configuration
129
- */
130
- static toAgentConfig(key, flagValue, tracker) {
131
- return Object.assign(Object.assign({}, this._toBaseConfig(key, flagValue)), { tracker, instructions: flagValue.instructions, judgeConfiguration: flagValue.judgeConfiguration });
132
- }
133
- /**
134
- * Creates a judge config from flag value data.
135
- *
136
- * @param flagValue The flag value from LaunchDarkly
137
- * @param tracker The tracker to add to the config
138
- * @returns A judge configuration
139
- */
140
- static toJudgeConfig(key, flagValue, tracker) {
141
- return Object.assign(Object.assign({}, this._toBaseConfig(key, flagValue)), { tracker, messages: flagValue.messages, evaluationMetricKeys: flagValue.evaluationMetricKeys || [] });
142
- }
143
- }
144
- exports.LDAIConfigUtils = LDAIConfigUtils;
145
- //# sourceMappingURL=LDAIConfigUtils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LDAIConfigUtils.js","sourceRoot":"","sources":["../../../../src/api/config/LDAIConfigUtils.ts"],"names":[],"mappings":";;;AAmCA;;;;GAIG;AACH,MAAa,eAAe;IAC1B;;;;;;OAMG;IACH,MAAM,CAAC,WAAW,CAAC,MAA6B,EAAE,IAAoB;;QACpE,MAAM,SAAS,GAAwB;YACrC,OAAO,EAAE;gBACP,YAAY,EAAE,EAAE;gBAChB,OAAO,EAAE,MAAA,MAAM,CAAC,OAAO,mCAAI,KAAK;gBAChC,IAAI;aACL;YACD,KAAK,EAAE,MAAM,CAAC,KAAK;SACpB,CAAC;QAEF,IAAI,UAAU,IAAI,MAAM,IAAI,MAAM,CAAC,QAAQ,KAAK,SAAS,EAAE;YACzD,SAAS,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;SACtC;QACD,IAAI,MAAM,CAAC,QAAQ,KAAK,SAAS,EAAE;YACjC,SAAS,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;SACtC;QACD,IAAI,cAAc,IAAI,MAAM,IAAI,MAAM,CAAC,YAAY,KAAK,SAAS,EAAE;YACjE,SAAS,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;SAC9C;QACD,IAAI,sBAAsB,IAAI,MAAM,IAAI,MAAM,CAAC,oBAAoB,KAAK,SAAS,EAAE;YACjF,SAAS,CAAC,oBAAoB,GAAG,MAAM,CAAC,oBAAoB,CAAC;SAC9D;QACD,IAAI,oBAAoB,IAAI,MAAM,IAAI,MAAM,CAAC,kBAAkB,KAAK,SAAS,EAAE;YAC7E,SAAS,CAAC,kBAAkB,GAAG,MAAM,CAAC,kBAAkB,CAAC;SAC1D;QAED,OAAO,SAAS,CA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