@launchdarkly/server-sdk-ai 0.11.3 → 0.12.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.
- package/CHANGELOG.md +17 -0
- package/__tests__/LDAIConfigTrackerImpl.test.ts +155 -0
- package/__tests__/TrackedChat.test.ts +231 -0
- package/dist/LDAIClientImpl.d.ts +4 -0
- package/dist/LDAIClientImpl.d.ts.map +1 -1
- package/dist/LDAIClientImpl.js +21 -0
- package/dist/LDAIClientImpl.js.map +1 -1
- package/dist/LDAIConfigMapper.d.ts.map +1 -1
- package/dist/LDAIConfigMapper.js +1 -0
- package/dist/LDAIConfigMapper.js.map +1 -1
- package/dist/LDAIConfigTrackerImpl.d.ts +6 -1
- package/dist/LDAIConfigTrackerImpl.d.ts.map +1 -1
- package/dist/LDAIConfigTrackerImpl.js +24 -0
- package/dist/LDAIConfigTrackerImpl.js.map +1 -1
- package/dist/LDClientMin.d.ts +2 -1
- package/dist/LDClientMin.d.ts.map +1 -1
- package/dist/api/LDAIClient.d.ts +39 -0
- package/dist/api/LDAIClient.d.ts.map +1 -1
- package/dist/api/chat/TrackedChat.d.ts +54 -0
- package/dist/api/chat/TrackedChat.d.ts.map +1 -0
- package/dist/api/chat/TrackedChat.js +84 -0
- package/dist/api/chat/TrackedChat.js.map +1 -0
- package/dist/api/chat/index.d.ts +3 -0
- package/dist/api/chat/index.d.ts.map +1 -0
- package/dist/api/chat/index.js +19 -0
- package/dist/api/chat/index.js.map +1 -0
- package/dist/api/chat/types.d.ts +16 -0
- package/dist/api/chat/types.d.ts.map +1 -0
- package/dist/api/chat/types.js +3 -0
- package/dist/api/chat/types.js.map +1 -0
- package/dist/api/config/LDAIConfigTracker.d.ts +20 -1
- package/dist/api/config/LDAIConfigTracker.d.ts.map +1 -1
- package/dist/api/config/VercelAISDK.d.ts +1 -0
- package/dist/api/config/VercelAISDK.d.ts.map +1 -1
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +2 -0
- package/dist/api/index.js.map +1 -1
- package/dist/api/metrics/LDAIMetrics.d.ts +17 -0
- package/dist/api/metrics/LDAIMetrics.d.ts.map +1 -0
- package/dist/api/metrics/LDAIMetrics.js +3 -0
- package/dist/api/metrics/LDAIMetrics.js.map +1 -0
- package/dist/api/metrics/VercelAISDKTokenUsage.d.ts +2 -0
- package/dist/api/metrics/VercelAISDKTokenUsage.d.ts.map +1 -1
- package/dist/api/metrics/VercelAISDKTokenUsage.js +3 -3
- package/dist/api/metrics/VercelAISDKTokenUsage.js.map +1 -1
- package/dist/api/metrics/index.d.ts +1 -0
- package/dist/api/metrics/index.d.ts.map +1 -1
- package/dist/api/metrics/index.js +1 -0
- package/dist/api/metrics/index.js.map +1 -1
- package/dist/api/providers/AIProvider.d.ts +35 -0
- package/dist/api/providers/AIProvider.d.ts.map +1 -0
- package/dist/api/providers/AIProvider.js +31 -0
- package/dist/api/providers/AIProvider.js.map +1 -0
- package/dist/api/providers/AIProviderFactory.d.ts +39 -0
- package/dist/api/providers/AIProviderFactory.d.ts.map +1 -0
- package/dist/api/providers/AIProviderFactory.js +102 -0
- package/dist/api/providers/AIProviderFactory.js.map +1 -0
- package/dist/api/providers/index.d.ts +3 -0
- package/dist/api/providers/index.d.ts.map +1 -0
- package/dist/api/providers/index.js +19 -0
- package/dist/api/providers/index.js.map +1 -0
- package/docs/assets/search.js +1 -1
- package/docs/classes/AIProvider.html +174 -0
- package/docs/classes/AIProviderFactory.html +197 -0
- package/docs/classes/TrackedChat.html +253 -0
- package/docs/enums/LDFeedbackKind.html +14 -7
- package/docs/functions/createBedrockTokenUsage.html +12 -5
- package/docs/functions/createOpenAiUsage.html +12 -5
- package/docs/functions/createVercelAISDKTokenUsage.html +17 -6
- package/docs/functions/initAi.html +12 -5
- package/docs/index.html +25 -5
- package/docs/interfaces/ChatResponse.html +108 -0
- package/docs/interfaces/LDAIAgent.html +17 -10
- package/docs/interfaces/LDAIAgentConfig.html +15 -8
- package/docs/interfaces/LDAIClient.html +55 -9
- package/docs/interfaces/LDAIConfig.html +18 -11
- package/docs/interfaces/LDAIConfigTracker.html +78 -19
- package/docs/interfaces/LDAIMetrics.html +110 -0
- package/docs/interfaces/LDMessage.html +14 -7
- package/docs/interfaces/LDModelConfig.html +15 -8
- package/docs/interfaces/LDProviderConfig.html +13 -6
- package/docs/interfaces/LDTokenUsage.html +15 -8
- package/docs/interfaces/VercelAISDKConfig.html +29 -15
- package/docs/interfaces/VercelAISDKMapOptions.html +13 -6
- package/docs/types/LDAIAgentDefaults.html +12 -5
- package/docs/types/LDAIDefaults.html +12 -5
- package/docs/types/SupportedAIProvider.html +70 -0
- package/docs/types/VercelAISDKProvider.html +12 -5
- package/docs/variables/SUPPORTED_AI_PROVIDERS.html +70 -0
- package/package.json +1 -1
- package/src/LDAIClientImpl.ts +36 -2
- package/src/LDAIConfigMapper.ts +1 -0
- package/src/LDAIConfigTrackerImpl.ts +36 -0
- package/src/LDClientMin.ts +3 -1
- package/src/api/LDAIClient.ts +46 -0
- package/src/api/chat/TrackedChat.ts +100 -0
- package/src/api/chat/index.ts +2 -0
- package/src/api/chat/types.ts +17 -0
- package/src/api/config/LDAIConfigTracker.ts +24 -1
- package/src/api/config/VercelAISDK.ts +1 -0
- package/src/api/index.ts +2 -0
- package/src/api/metrics/LDAIMetrics.ts +18 -0
- package/src/api/metrics/VercelAISDKTokenUsage.ts +4 -2
- package/src/api/metrics/index.ts +1 -0
- package/src/api/providers/AIProvider.ts +43 -0
- package/src/api/providers/AIProviderFactory.ts +152 -0
- package/src/api/providers/index.ts +2 -0
- package/tsconfig.eslint.json +2 -2
package/dist/api/LDAIClient.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { LDContext } from '@launchdarkly/js-server-sdk-common';
|
|
2
2
|
import { LDAIAgent, LDAIAgentConfig, LDAIAgentDefaults } from './agents';
|
|
3
|
+
import { TrackedChat } from './chat';
|
|
3
4
|
import { LDAIConfig, LDAIDefaults } from './config/LDAIConfig';
|
|
5
|
+
import { SupportedAIProvider } from './providers';
|
|
4
6
|
/**
|
|
5
7
|
* Interface for performing AI operations using LaunchDarkly.
|
|
6
8
|
*/
|
|
@@ -126,5 +128,42 @@ export interface LDAIClient {
|
|
|
126
128
|
* ```
|
|
127
129
|
*/
|
|
128
130
|
agents<const T extends readonly LDAIAgentConfig[]>(agentConfigs: T, context: LDContext): Promise<Record<T[number]['key'], LDAIAgent>>;
|
|
131
|
+
/**
|
|
132
|
+
* Initializes and returns a new TrackedChat instance for chat interactions.
|
|
133
|
+
* This method serves as the primary entry point for creating TrackedChat instances from configuration.
|
|
134
|
+
*
|
|
135
|
+
* @param key The key identifying the AI chat configuration to use.
|
|
136
|
+
* @param context The standard LDContext used when evaluating flags.
|
|
137
|
+
* @param defaultValue A default value representing a standard AI chat config result.
|
|
138
|
+
* @param variables Dictionary of values for instruction interpolation.
|
|
139
|
+
* @returns A promise that resolves to the TrackedChat instance, or null if the configuration is disabled.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```
|
|
143
|
+
* const key = "customer_support_chat";
|
|
144
|
+
* const context = {...};
|
|
145
|
+
* const defaultValue = {
|
|
146
|
+
* config: {
|
|
147
|
+
* enabled: false,
|
|
148
|
+
* model: { name: "gpt-4" },
|
|
149
|
+
* messages: [
|
|
150
|
+
* { role: "system", content: "You are a helpful customer support agent." }
|
|
151
|
+
* ]
|
|
152
|
+
* }
|
|
153
|
+
* };
|
|
154
|
+
* const variables = { customerName: 'John' };
|
|
155
|
+
*
|
|
156
|
+
* const chat = await client.initChat(key, context, defaultValue, variables);
|
|
157
|
+
* if (chat) {
|
|
158
|
+
* const response = await chat.invoke("I need help with my order");
|
|
159
|
+
* console.log(response.message.content);
|
|
160
|
+
*
|
|
161
|
+
* // Access configuration and tracker if needed
|
|
162
|
+
* console.log('Model:', chat.getConfig().model?.name);
|
|
163
|
+
* chat.getTracker().trackSuccess();
|
|
164
|
+
* }
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
initChat(key: string, context: LDContext, defaultValue: LDAIDefaults, variables?: Record<string, unknown>, defaultAiProvider?: SupportedAIProvider): Promise<TrackedChat | undefined>;
|
|
129
168
|
}
|
|
130
169
|
//# sourceMappingURL=LDAIClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LDAIClient.d.ts","sourceRoot":"","sources":["../../src/api/LDAIClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AAE/D,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"LDAIClient.d.ts","sourceRoot":"","sources":["../../src/api/LDAIClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AAE/D,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkDG;IACH,MAAM,CACJ,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,CAAC;IAEvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,KAAK,CACH,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,CAAC;IAEtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;IACH,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,SAAS,eAAe,EAAE,EAC/C,YAAY,EAAE,CAAC,EACf,OAAO,EAAE,SAAS,GACjB,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;IAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;IACH,QAAQ,CACN,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,SAAS,EAClB,YAAY,EAAE,YAAY,EAC1B,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,iBAAiB,CAAC,EAAE,mBAAmB,GACtC,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC;CACrC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { LDAIConfig, LDMessage } from '../config/LDAIConfig';
|
|
2
|
+
import { LDAIConfigTracker } from '../config/LDAIConfigTracker';
|
|
3
|
+
import { AIProvider } from '../providers/AIProvider';
|
|
4
|
+
import { ChatResponse } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Concrete implementation of TrackedChat that provides chat functionality
|
|
7
|
+
* by delegating to an AIProvider implementation.
|
|
8
|
+
* This class handles conversation management and tracking, while delegating
|
|
9
|
+
* the actual model invocation to the provider.
|
|
10
|
+
*/
|
|
11
|
+
export declare class TrackedChat {
|
|
12
|
+
protected readonly aiConfig: LDAIConfig;
|
|
13
|
+
protected readonly tracker: LDAIConfigTracker;
|
|
14
|
+
protected readonly provider: AIProvider;
|
|
15
|
+
protected messages: LDMessage[];
|
|
16
|
+
constructor(aiConfig: LDAIConfig, tracker: LDAIConfigTracker, provider: AIProvider);
|
|
17
|
+
/**
|
|
18
|
+
* Invoke the chat model with a prompt string.
|
|
19
|
+
* This method handles conversation management and tracking, delegating to the provider's invokeModel method.
|
|
20
|
+
*/
|
|
21
|
+
invoke(prompt: string): Promise<ChatResponse>;
|
|
22
|
+
/**
|
|
23
|
+
* Get the underlying AI configuration used to initialize this TrackedChat.
|
|
24
|
+
*/
|
|
25
|
+
getConfig(): LDAIConfig;
|
|
26
|
+
/**
|
|
27
|
+
* Get the underlying AI configuration tracker used to initialize this TrackedChat.
|
|
28
|
+
*/
|
|
29
|
+
getTracker(): LDAIConfigTracker;
|
|
30
|
+
/**
|
|
31
|
+
* Get the underlying AI provider instance.
|
|
32
|
+
* This provides direct access to the provider for advanced use cases.
|
|
33
|
+
*/
|
|
34
|
+
getProvider(): AIProvider;
|
|
35
|
+
/**
|
|
36
|
+
* Append messages to the conversation history.
|
|
37
|
+
* Adds messages to the conversation history without invoking the model,
|
|
38
|
+
* which is useful for managing multi-turn conversations or injecting context.
|
|
39
|
+
*
|
|
40
|
+
* @param messages Array of messages to append to the conversation history
|
|
41
|
+
*/
|
|
42
|
+
appendMessages(messages: LDMessage[]): void;
|
|
43
|
+
/**
|
|
44
|
+
* Get all messages in the conversation history.
|
|
45
|
+
*
|
|
46
|
+
* @param includeConfigMessages Whether to include the config messages from the AIConfig.
|
|
47
|
+
* Defaults to false.
|
|
48
|
+
* @returns Array of messages. When includeConfigMessages is true, returns both config
|
|
49
|
+
* messages and conversation history with config messages prepended. When false,
|
|
50
|
+
* returns only the conversation history messages.
|
|
51
|
+
*/
|
|
52
|
+
getMessages(includeConfigMessages?: boolean): LDMessage[];
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=TrackedChat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TrackedChat.d.ts","sourceRoot":"","sources":["../../../src/api/chat/TrackedChat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC;;;;;GAKG;AACH,qBAAa,WAAW;IAIpB,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,UAAU;IACvC,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,iBAAiB;IAC7C,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,UAAU;IALzC,SAAS,CAAC,QAAQ,EAAE,SAAS,EAAE,CAAC;gBAGX,QAAQ,EAAE,UAAU,EACpB,OAAO,EAAE,iBAAiB,EAC1B,QAAQ,EAAE,UAAU;IAKzC;;;OAGG;IACG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAwBnD;;OAEG;IACH,SAAS,IAAI,UAAU;IAIvB;;OAEG;IACH,UAAU,IAAI,iBAAiB;IAI/B;;;OAGG;IACH,WAAW,IAAI,UAAU;IAIzB;;;;;;OAMG;IACH,cAAc,CAAC,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI;IAI3C;;;;;;;;OAQG;IACH,WAAW,CAAC,qBAAqB,GAAE,OAAe,GAAG,SAAS,EAAE;CAOjE"}
|
|
@@ -0,0 +1,84 @@
|
|
|
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) {
|
|
12
|
+
this.aiConfig = aiConfig;
|
|
13
|
+
this.tracker = tracker;
|
|
14
|
+
this.provider = provider;
|
|
15
|
+
this.messages = [];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Invoke the chat model with a prompt string.
|
|
19
|
+
* This method handles conversation management and tracking, delegating to the provider's invokeModel method.
|
|
20
|
+
*/
|
|
21
|
+
async invoke(prompt) {
|
|
22
|
+
// Convert prompt string to LDMessage with role 'user' and add to conversation history
|
|
23
|
+
const userMessage = {
|
|
24
|
+
role: 'user',
|
|
25
|
+
content: prompt,
|
|
26
|
+
};
|
|
27
|
+
this.messages.push(userMessage);
|
|
28
|
+
// Prepend config messages to conversation history for model invocation
|
|
29
|
+
const configMessages = this.aiConfig.messages || [];
|
|
30
|
+
const allMessages = [...configMessages, ...this.messages];
|
|
31
|
+
// Delegate to provider-specific implementation with tracking
|
|
32
|
+
const response = await this.tracker.trackMetricsOf((result) => result.metrics, () => this.provider.invokeModel(allMessages));
|
|
33
|
+
// Add the assistant response to the conversation history
|
|
34
|
+
this.messages.push(response.message);
|
|
35
|
+
return response;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get the underlying AI configuration used to initialize this TrackedChat.
|
|
39
|
+
*/
|
|
40
|
+
getConfig() {
|
|
41
|
+
return this.aiConfig;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get the underlying AI configuration tracker used to initialize this TrackedChat.
|
|
45
|
+
*/
|
|
46
|
+
getTracker() {
|
|
47
|
+
return this.tracker;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get the underlying AI provider instance.
|
|
51
|
+
* This provides direct access to the provider for advanced use cases.
|
|
52
|
+
*/
|
|
53
|
+
getProvider() {
|
|
54
|
+
return this.provider;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Append messages to the conversation history.
|
|
58
|
+
* Adds messages to the conversation history without invoking the model,
|
|
59
|
+
* which is useful for managing multi-turn conversations or injecting context.
|
|
60
|
+
*
|
|
61
|
+
* @param messages Array of messages to append to the conversation history
|
|
62
|
+
*/
|
|
63
|
+
appendMessages(messages) {
|
|
64
|
+
this.messages.push(...messages);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get all messages in the conversation history.
|
|
68
|
+
*
|
|
69
|
+
* @param includeConfigMessages Whether to include the config messages from the AIConfig.
|
|
70
|
+
* Defaults to false.
|
|
71
|
+
* @returns Array of messages. When includeConfigMessages is true, returns both config
|
|
72
|
+
* messages and conversation history with config messages prepended. When false,
|
|
73
|
+
* returns only the conversation history messages.
|
|
74
|
+
*/
|
|
75
|
+
getMessages(includeConfigMessages = false) {
|
|
76
|
+
if (includeConfigMessages) {
|
|
77
|
+
const configMessages = this.aiConfig.messages || [];
|
|
78
|
+
return [...configMessages, ...this.messages];
|
|
79
|
+
}
|
|
80
|
+
return [...this.messages];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.TrackedChat = TrackedChat;
|
|
84
|
+
//# sourceMappingURL=TrackedChat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TrackedChat.js","sourceRoot":"","sources":["../../../src/api/chat/TrackedChat.ts"],"names":[],"mappings":";;;AAKA;;;;;GAKG;AACH,MAAa,WAAW;IAGtB,YACqB,QAAoB,EACpB,OAA0B,EAC1B,QAAoB;QAFpB,aAAQ,GAAR,QAAQ,CAAY;QACpB,YAAO,GAAP,OAAO,CAAmB;QAC1B,aAAQ,GAAR,QAAQ,CAAY;QAEvC,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,MAAM,CAAC,MAAc;QACzB,sFAAsF;QACtF,MAAM,WAAW,GAAc;YAC7B,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,MAAM;SAChB,CAAC;QACF,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CA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"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/chat/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/chat/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,gDAA8B"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { LDMessage } from '../config/LDAIConfig';
|
|
2
|
+
import { LDAIMetrics } from '../metrics/LDAIMetrics';
|
|
3
|
+
/**
|
|
4
|
+
* Chat response structure.
|
|
5
|
+
*/
|
|
6
|
+
export interface ChatResponse {
|
|
7
|
+
/**
|
|
8
|
+
* The response message from the AI.
|
|
9
|
+
*/
|
|
10
|
+
message: LDMessage;
|
|
11
|
+
/**
|
|
12
|
+
* Metrics information including success status and token usage.
|
|
13
|
+
*/
|
|
14
|
+
metrics: LDAIMetrics;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/api/chat/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,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;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/api/chat/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LDFeedbackKind, LDTokenUsage } from '../metrics';
|
|
1
|
+
import { LDAIMetrics, LDFeedbackKind, LDTokenUsage } from '../metrics';
|
|
2
2
|
/**
|
|
3
3
|
* Metrics which have been tracked.
|
|
4
4
|
*/
|
|
@@ -78,6 +78,21 @@ export interface LDAIConfigTracker {
|
|
|
78
78
|
* @returns The result of the function.
|
|
79
79
|
*/
|
|
80
80
|
trackDurationOf(func: () => Promise<any>): Promise<any>;
|
|
81
|
+
/**
|
|
82
|
+
* Track metrics for a generic AI operation.
|
|
83
|
+
*
|
|
84
|
+
* This function will track the duration of the operation, extract metrics using the provided
|
|
85
|
+
* metrics extractor function, and track success or error status accordingly.
|
|
86
|
+
*
|
|
87
|
+
* If the provided function throws, then this method will also throw.
|
|
88
|
+
* In the case the provided function throws, this function will record the duration and an error.
|
|
89
|
+
* A failed operation will not have any token usage data.
|
|
90
|
+
*
|
|
91
|
+
* @param metricsExtractor Function that extracts LDAIMetrics from the operation result
|
|
92
|
+
* @param func Function which executes the operation
|
|
93
|
+
* @returns The result of the operation
|
|
94
|
+
*/
|
|
95
|
+
trackMetricsOf<TRes>(metricsExtractor: (result: TRes) => LDAIMetrics, func: () => Promise<TRes>): Promise<TRes>;
|
|
81
96
|
/**
|
|
82
97
|
* Track an OpenAI operation.
|
|
83
98
|
*
|
|
@@ -133,7 +148,9 @@ export interface LDAIConfigTracker {
|
|
|
133
148
|
trackVercelAISDKGenerateTextMetrics<TRes extends {
|
|
134
149
|
usage?: {
|
|
135
150
|
totalTokens?: number;
|
|
151
|
+
inputTokens?: number;
|
|
136
152
|
promptTokens?: number;
|
|
153
|
+
outputTokens?: number;
|
|
137
154
|
completionTokens?: number;
|
|
138
155
|
};
|
|
139
156
|
}>(func: () => Promise<TRes>): Promise<TRes>;
|
|
@@ -153,7 +170,9 @@ export interface LDAIConfigTracker {
|
|
|
153
170
|
finishReason?: Promise<string>;
|
|
154
171
|
usage?: Promise<{
|
|
155
172
|
totalTokens?: number;
|
|
173
|
+
inputTokens?: number;
|
|
156
174
|
promptTokens?: number;
|
|
175
|
+
outputTokens?: number;
|
|
157
176
|
completionTokens?: number;
|
|
158
177
|
}>;
|
|
159
178
|
}>(func: () => TRes): TRes;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LDAIConfigTracker.d.ts","sourceRoot":"","sources":["../../../src/api/config/LDAIConfigTracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"LDAIConfigTracker.d.ts","sourceRoot":"","sources":["../../../src/api/config/LDAIConfigTracker.ts"],"names":[],"mappings":"AAAA,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;IAC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@@ export interface VercelAISDKConfig<TMod> {
|
|
|
7
7
|
model: TMod;
|
|
8
8
|
messages?: LDMessage[] | undefined;
|
|
9
9
|
maxTokens?: number | undefined;
|
|
10
|
+
maxOutputTokens?: number | undefined;
|
|
10
11
|
temperature?: number | undefined;
|
|
11
12
|
topP?: number | undefined;
|
|
12
13
|
topK?: number | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VercelAISDK.d.ts","sourceRoot":"","sources":["../../../src/api/config/VercelAISDK.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,MAAM,mBAAmB,CAAC,IAAI,IAAI,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;AAEpE,MAAM,WAAW,qBAAqB;IACpC,uBAAuB,CAAC,EAAE,SAAS,EAAE,GAAG,SAAS,CAAC;CACnD;AAED,MAAM,WAAW,iBAAiB,CAAC,IAAI;IACrC,KAAK,EAAE,IAAI,CAAC;IACZ,QAAQ,CAAC,EAAE,SAAS,EAAE,GAAG,SAAS,CAAC;IACnC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,aAAa,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IACrC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3B"}
|
|
1
|
+
{"version":3,"file":"VercelAISDK.d.ts","sourceRoot":"","sources":["../../../src/api/config/VercelAISDK.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,MAAM,mBAAmB,CAAC,IAAI,IAAI,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;AAEpE,MAAM,WAAW,qBAAqB;IACpC,uBAAuB,CAAC,EAAE,SAAS,EAAE,GAAG,SAAS,CAAC;CACnD;AAED,MAAM,WAAW,iBAAiB,CAAC,IAAI;IACrC,KAAK,EAAE,IAAI,CAAC;IACZ,QAAQ,CAAC,EAAE,SAAS,EAAE,GAAG,SAAS,CAAC;IACnC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,aAAa,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IACrC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3B"}
|
package/dist/api/index.d.ts
CHANGED
package/dist/api/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
|
package/dist/api/index.js
CHANGED
|
@@ -16,6 +16,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./config"), exports);
|
|
18
18
|
__exportStar(require("./agents"), exports);
|
|
19
|
+
__exportStar(require("./chat"), exports);
|
|
19
20
|
__exportStar(require("./metrics"), exports);
|
|
20
21
|
__exportStar(require("./LDAIClient"), exports);
|
|
22
|
+
__exportStar(require("./providers"), exports);
|
|
21
23
|
//# sourceMappingURL=index.js.map
|
package/dist/api/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,2CAAyB;AACzB,4CAA0B;AAC1B,+CAA6B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,2CAAyB;AACzB,yCAAuB;AACvB,4CAA0B;AAC1B,+CAA6B;AAC7B,8CAA4B"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { LDTokenUsage } from './LDTokenUsage';
|
|
2
|
+
/**
|
|
3
|
+
* Metrics information for AI operations that includes success status and token usage.
|
|
4
|
+
* This class combines success/failure tracking with token usage metrics.
|
|
5
|
+
*/
|
|
6
|
+
export interface LDAIMetrics {
|
|
7
|
+
/**
|
|
8
|
+
* Whether the AI operation was successful.
|
|
9
|
+
*/
|
|
10
|
+
success: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Token usage information for the operation.
|
|
13
|
+
* This will be undefined if no token usage data is available.
|
|
14
|
+
*/
|
|
15
|
+
usage?: LDTokenUsage;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=LDAIMetrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LDAIMetrics.d.ts","sourceRoot":"","sources":["../../../src/api/metrics/LDAIMetrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;;OAGG;IACH,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LDAIMetrics.js","sourceRoot":"","sources":["../../../src/api/metrics/LDAIMetrics.ts"],"names":[],"mappings":""}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { LDTokenUsage } from './LDTokenUsage';
|
|
2
2
|
export declare function createVercelAISDKTokenUsage(data: {
|
|
3
3
|
totalTokens?: number;
|
|
4
|
+
inputTokens?: number;
|
|
4
5
|
promptTokens?: number;
|
|
6
|
+
outputTokens?: number;
|
|
5
7
|
completionTokens?: number;
|
|
6
8
|
}): LDTokenUsage;
|
|
7
9
|
//# sourceMappingURL=VercelAISDKTokenUsage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VercelAISDKTokenUsage.d.ts","sourceRoot":"","sources":["../../../src/api/metrics/VercelAISDKTokenUsage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,wBAAgB,2BAA2B,CAAC,IAAI,EAAE;IAChD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,GAAG,YAAY,CAMf"}
|
|
1
|
+
{"version":3,"file":"VercelAISDKTokenUsage.d.ts","sourceRoot":"","sources":["../../../src/api/metrics/VercelAISDKTokenUsage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,wBAAgB,2BAA2B,CAAC,IAAI,EAAE;IAChD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,GAAG,YAAY,CAMf"}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createVercelAISDKTokenUsage = void 0;
|
|
4
4
|
function createVercelAISDKTokenUsage(data) {
|
|
5
|
-
var _a, _b, _c;
|
|
5
|
+
var _a, _b, _c, _d, _e;
|
|
6
6
|
return {
|
|
7
7
|
total: (_a = data.totalTokens) !== null && _a !== void 0 ? _a : 0,
|
|
8
|
-
input: (_b = data.
|
|
9
|
-
output: (
|
|
8
|
+
input: (_c = (_b = data.inputTokens) !== null && _b !== void 0 ? _b : data.promptTokens) !== null && _c !== void 0 ? _c : 0,
|
|
9
|
+
output: (_e = (_d = data.outputTokens) !== null && _d !== void 0 ? _d : data.completionTokens) !== null && _e !== void 0 ? _e : 0,
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
12
|
exports.createVercelAISDKTokenUsage = createVercelAISDKTokenUsage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VercelAISDKTokenUsage.js","sourceRoot":"","sources":["../../../src/api/metrics/VercelAISDKTokenUsage.ts"],"names":[],"mappings":";;;AAEA,SAAgB,2BAA2B,CAAC,
|
|
1
|
+
{"version":3,"file":"VercelAISDKTokenUsage.js","sourceRoot":"","sources":["../../../src/api/metrics/VercelAISDKTokenUsage.ts"],"names":[],"mappings":";;;AAEA,SAAgB,2BAA2B,CAAC,IAM3C;;IACC,OAAO;QACL,KAAK,EAAE,MAAA,IAAI,CAAC,WAAW,mCAAI,CAAC;QAC5B,KAAK,EAAE,MAAA,MAAA,IAAI,CAAC,WAAW,mCAAI,IAAI,CAAC,YAAY,mCAAI,CAAC;QACjD,MAAM,EAAE,MAAA,MAAA,IAAI,CAAC,YAAY,mCAAI,IAAI,CAAC,gBAAgB,mCAAI,CAAC;KACxD,CAAC;AACJ,CAAC;AAZD,kEAYC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/metrics/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/metrics/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC"}
|
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./BedrockTokenUsage"), exports);
|
|
18
18
|
__exportStar(require("./OpenAiUsage"), exports);
|
|
19
19
|
__exportStar(require("./LDFeedbackKind"), exports);
|
|
20
|
+
__exportStar(require("./LDAIMetrics"), exports);
|
|
20
21
|
__exportStar(require("./LDTokenUsage"), exports);
|
|
21
22
|
__exportStar(require("./VercelAISDKTokenUsage"), exports);
|
|
22
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/metrics/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,gDAA8B;AAC9B,mDAAiC;AACjC,iDAA+B;AAC/B,0DAAwC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/metrics/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,gDAA8B;AAC9B,mDAAiC;AACjC,gDAA8B;AAC9B,iDAA+B;AAC/B,0DAAwC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { LDLogger } from '@launchdarkly/js-server-sdk-common';
|
|
2
|
+
import { ChatResponse } from '../chat/types';
|
|
3
|
+
import { LDAIConfig, LDMessage } from '../config/LDAIConfig';
|
|
4
|
+
/**
|
|
5
|
+
* Abstract base class for AI providers that implement chat model functionality.
|
|
6
|
+
* This class provides the contract that all provider implementations must follow
|
|
7
|
+
* to integrate with LaunchDarkly's tracking and configuration capabilities.
|
|
8
|
+
*
|
|
9
|
+
* Following the AICHAT spec recommendation to use base classes with non-abstract methods
|
|
10
|
+
* for better extensibility and backwards compatibility.
|
|
11
|
+
*/
|
|
12
|
+
export declare abstract class AIProvider {
|
|
13
|
+
protected readonly logger?: LDLogger;
|
|
14
|
+
constructor(logger?: LDLogger);
|
|
15
|
+
/**
|
|
16
|
+
* Invoke the chat model with an array of messages.
|
|
17
|
+
* This method should convert messages to provider format, invoke the model,
|
|
18
|
+
* and return a ChatResponse with the result and metrics.
|
|
19
|
+
*
|
|
20
|
+
* @param messages Array of LDMessage objects representing the conversation
|
|
21
|
+
* @returns Promise that resolves to a ChatResponse containing the model's response
|
|
22
|
+
*/
|
|
23
|
+
abstract invokeModel(messages: LDMessage[]): Promise<ChatResponse>;
|
|
24
|
+
/**
|
|
25
|
+
* Static method that constructs an instance of the provider.
|
|
26
|
+
* Each provider implementation must provide their own static create method
|
|
27
|
+
* that accepts an AIConfig and returns a configured instance.
|
|
28
|
+
*
|
|
29
|
+
* @param aiConfig The LaunchDarkly AI configuration
|
|
30
|
+
* @param logger Optional logger for the provider
|
|
31
|
+
* @returns Promise that resolves to a configured provider instance
|
|
32
|
+
*/
|
|
33
|
+
static create(aiConfig: LDAIConfig, logger?: LDLogger): Promise<AIProvider>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=AIProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AIProvider.d.ts","sourceRoot":"","sources":["../../../src/api/providers/AIProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAE9D,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAE7D;;;;;;;GAOG;AACH,8BAAsB,UAAU;IAC9B,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC;gBAEzB,MAAM,CAAC,EAAE,QAAQ;IAG7B;;;;;;;OAOG;IACH,QAAQ,CAAC,WAAW,CAAC,QAAQ,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,YAAY,CAAC;IAElE;;;;;;;;OAQG;WAEU,MAAM,CAAC,QAAQ,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;CAGlF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AIProvider = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Abstract base class for AI providers that implement chat model functionality.
|
|
6
|
+
* This class provides the contract that all provider implementations must follow
|
|
7
|
+
* to integrate with LaunchDarkly's tracking and configuration capabilities.
|
|
8
|
+
*
|
|
9
|
+
* Following the AICHAT spec recommendation to use base classes with non-abstract methods
|
|
10
|
+
* for better extensibility and backwards compatibility.
|
|
11
|
+
*/
|
|
12
|
+
class AIProvider {
|
|
13
|
+
constructor(logger) {
|
|
14
|
+
this.logger = logger;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Static method that constructs an instance of the provider.
|
|
18
|
+
* Each provider implementation must provide their own static create method
|
|
19
|
+
* that accepts an AIConfig and returns a configured instance.
|
|
20
|
+
*
|
|
21
|
+
* @param aiConfig The LaunchDarkly AI configuration
|
|
22
|
+
* @param logger Optional logger for the provider
|
|
23
|
+
* @returns Promise that resolves to a configured provider instance
|
|
24
|
+
*/
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
26
|
+
static async create(aiConfig, logger) {
|
|
27
|
+
throw new Error('Provider implementations must override the static create method');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.AIProvider = AIProvider;
|
|
31
|
+
//# sourceMappingURL=AIProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AIProvider.js","sourceRoot":"","sources":["../../../src/api/providers/AIProvider.ts"],"names":[],"mappings":";;;AAKA;;;;;;;GAOG;AACH,MAAsB,UAAU;IAG9B,YAAY,MAAiB;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAWD;;;;;;;;OAQG;IACH,6DAA6D;IAC7D,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,QAAoB,EAAE,MAAiB;QACzD,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;IACrF,CAAC;CACF;AA7BD,gCA6BC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { LDLogger } from '@launchdarkly/js-server-sdk-common';
|
|
2
|
+
import { LDAIConfig } from '../config/LDAIConfig';
|
|
3
|
+
import { AIProvider } from './AIProvider';
|
|
4
|
+
/**
|
|
5
|
+
* List of supported AI providers.
|
|
6
|
+
*/
|
|
7
|
+
export declare const SUPPORTED_AI_PROVIDERS: readonly ["openai", "langchain", "vercel"];
|
|
8
|
+
/**
|
|
9
|
+
* Type representing the supported AI providers.
|
|
10
|
+
*/
|
|
11
|
+
export type SupportedAIProvider = (typeof SUPPORTED_AI_PROVIDERS)[number];
|
|
12
|
+
/**
|
|
13
|
+
* Factory for creating AIProvider instances based on the provider configuration.
|
|
14
|
+
*/
|
|
15
|
+
export declare class AIProviderFactory {
|
|
16
|
+
/**
|
|
17
|
+
* Create an AIProvider instance based on the AI configuration.
|
|
18
|
+
* This method attempts to load provider-specific implementations dynamically.
|
|
19
|
+
* Returns undefined if the provider is not supported.
|
|
20
|
+
*
|
|
21
|
+
* @param aiConfig The AI configuration
|
|
22
|
+
* @param logger Optional logger for logging provider initialization
|
|
23
|
+
* @param defaultAiProvider Optional default AI provider to use
|
|
24
|
+
*/
|
|
25
|
+
static create(aiConfig: LDAIConfig, logger?: LDLogger, defaultAiProvider?: SupportedAIProvider): Promise<AIProvider | undefined>;
|
|
26
|
+
/**
|
|
27
|
+
* Determine which providers to try based on defaultAiProvider and providerName.
|
|
28
|
+
*/
|
|
29
|
+
private static _getProvidersToTry;
|
|
30
|
+
/**
|
|
31
|
+
* Try to create a provider of the specified type.
|
|
32
|
+
*/
|
|
33
|
+
private static _tryCreateProvider;
|
|
34
|
+
/**
|
|
35
|
+
* Create a provider instance dynamically.
|
|
36
|
+
*/
|
|
37
|
+
private static _createProvider;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=AIProviderFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AIProviderFactory.d.ts","sourceRoot":"","sources":["../../../src/api/providers/AIProviderFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAE9D,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C;;GAEG;AACH,eAAO,MAAM,sBAAsB,4CAKzB,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE1E;;GAEG;AACH,qBAAa,iBAAiB;IAC5B;;;;;;;;OAQG;WACU,MAAM,CACjB,QAAQ,EAAE,UAAU,EACpB,MAAM,CAAC,EAAE,QAAQ,EACjB,iBAAiB,CAAC,EAAE,mBAAmB,GACtC,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAsBlC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB;IA0BjC;;OAEG;mBACkB,kBAAkB;IAgCvC;;OAEG;mBACkB,eAAe;CAyBrC"}
|