@launchdarkly/server-sdk-ai 0.11.4 → 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 +10 -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/LDAIConfigTrackerImpl.d.ts +2 -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 +16 -1
- package/dist/api/config/LDAIConfigTracker.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/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 +12 -5
- 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 +76 -17
- 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 +23 -16
- 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/LDAIConfigTrackerImpl.ts +32 -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 +20 -1
- package/src/api/index.ts +2 -0
- package/src/api/metrics/LDAIMetrics.ts +18 -0
- 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
|
@@ -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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
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,Q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AC,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;AAxFD,kCAwFC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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
|
*
|
|
@@ -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;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;IAE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AAE,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;;;;;;;;;;;OAWG;IACH,iCAAiC,CAC/B,IAAI,SAAS;QACX,YAAY,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QAC/B,KAAK,CAAC,EAAE,OAAO,CAAC;YACd,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,CAAC;KACJ,EAED,IAAI,EAAE,MAAM,IAAI,GACf,IAAI,CAAC;IAER;;OAEG;IACH,UAAU,IAAI,iBAAiB,CAAC;CACjC"}
|
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 +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"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AIProviderFactory = exports.SUPPORTED_AI_PROVIDERS = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* List of supported AI providers.
|
|
6
|
+
*/
|
|
7
|
+
exports.SUPPORTED_AI_PROVIDERS = [
|
|
8
|
+
'openai',
|
|
9
|
+
// Multi-provider packages should be last in the list
|
|
10
|
+
'langchain',
|
|
11
|
+
'vercel',
|
|
12
|
+
];
|
|
13
|
+
/**
|
|
14
|
+
* Factory for creating AIProvider instances based on the provider configuration.
|
|
15
|
+
*/
|
|
16
|
+
class AIProviderFactory {
|
|
17
|
+
/**
|
|
18
|
+
* Create an AIProvider instance based on the AI configuration.
|
|
19
|
+
* This method attempts to load provider-specific implementations dynamically.
|
|
20
|
+
* Returns undefined if the provider is not supported.
|
|
21
|
+
*
|
|
22
|
+
* @param aiConfig The AI configuration
|
|
23
|
+
* @param logger Optional logger for logging provider initialization
|
|
24
|
+
* @param defaultAiProvider Optional default AI provider to use
|
|
25
|
+
*/
|
|
26
|
+
static async create(aiConfig, logger, defaultAiProvider) {
|
|
27
|
+
var _a, _b, _c, _d;
|
|
28
|
+
const providerName = (_b = (_a = aiConfig.provider) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.toLowerCase();
|
|
29
|
+
// Determine which providers to try based on defaultAiProvider
|
|
30
|
+
const providersToTry = this._getProvidersToTry(defaultAiProvider, providerName);
|
|
31
|
+
// Try each provider in order
|
|
32
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
33
|
+
for (const providerType of providersToTry) {
|
|
34
|
+
// eslint-disable-next-line no-await-in-loop
|
|
35
|
+
const provider = await this._tryCreateProvider(providerType, aiConfig, logger);
|
|
36
|
+
if (provider) {
|
|
37
|
+
return provider;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// If no provider was successfully created, log a warning
|
|
41
|
+
logger === null || logger === void 0 ? void 0 : logger.warn(`Provider is not supported or failed to initialize: ${(_d = (_c = aiConfig.provider) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : 'unknown'}`);
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Determine which providers to try based on defaultAiProvider and providerName.
|
|
46
|
+
*/
|
|
47
|
+
static _getProvidersToTry(defaultAiProvider, providerName) {
|
|
48
|
+
// If defaultAiProvider is set, only try that specific provider
|
|
49
|
+
if (defaultAiProvider) {
|
|
50
|
+
return [defaultAiProvider];
|
|
51
|
+
}
|
|
52
|
+
// If no defaultAiProvider is set, try all providers in order
|
|
53
|
+
const providerSet = new Set();
|
|
54
|
+
// First try the specific provider if it's supported
|
|
55
|
+
if (providerName && exports.SUPPORTED_AI_PROVIDERS.includes(providerName)) {
|
|
56
|
+
providerSet.add(providerName);
|
|
57
|
+
}
|
|
58
|
+
// Then try multi-provider packages, but avoid duplicates
|
|
59
|
+
const multiProviderPackages = ['langchain', 'vercel'];
|
|
60
|
+
multiProviderPackages.forEach((provider) => {
|
|
61
|
+
providerSet.add(provider);
|
|
62
|
+
});
|
|
63
|
+
return Array.from(providerSet);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Try to create a provider of the specified type.
|
|
67
|
+
*/
|
|
68
|
+
static async _tryCreateProvider(providerType, aiConfig, logger) {
|
|
69
|
+
switch (providerType) {
|
|
70
|
+
case 'openai':
|
|
71
|
+
return this._createProvider('@launchdarkly/server-sdk-ai-openai', 'OpenAIProvider', aiConfig, logger);
|
|
72
|
+
case 'langchain':
|
|
73
|
+
return this._createProvider('@launchdarkly/server-sdk-ai-langchain', 'LangChainProvider', aiConfig, logger);
|
|
74
|
+
case 'vercel':
|
|
75
|
+
return this._createProvider('@launchdarkly/server-sdk-ai-vercel', 'VercelProvider', aiConfig, logger);
|
|
76
|
+
default:
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Create a provider instance dynamically.
|
|
82
|
+
*/
|
|
83
|
+
static async _createProvider(packageName, providerClassName, aiConfig, logger) {
|
|
84
|
+
var _a, _b;
|
|
85
|
+
try {
|
|
86
|
+
// Try to dynamically import the provider
|
|
87
|
+
// This will work if the package is installed
|
|
88
|
+
// eslint-disable-next-line import/no-extraneous-dependencies, global-require, import/no-dynamic-require
|
|
89
|
+
const { [providerClassName]: ProviderClass } = require(packageName);
|
|
90
|
+
const provider = await ProviderClass.create(aiConfig, logger);
|
|
91
|
+
logger === null || logger === void 0 ? void 0 : logger.debug(`Successfully created AIProvider for: ${(_a = aiConfig.provider) === null || _a === void 0 ? void 0 : _a.name} with package ${packageName}`);
|
|
92
|
+
return provider;
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
// If the provider is not available or creation fails, return undefined
|
|
96
|
+
logger === null || logger === void 0 ? void 0 : logger.warn(`Error creating AIProvider for: ${(_b = aiConfig.provider) === null || _b === void 0 ? void 0 : _b.name} with package ${packageName}: ${error}`);
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.AIProviderFactory = AIProviderFactory;
|
|
102
|
+
//# sourceMappingURL=AIProviderFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AIProviderFactory.js","sourceRoot":"","sources":["../../../src/api/providers/AIProviderFactory.ts"],"names":[],"mappings":";;;AAKA;;GAEG;AACU,QAAA,sBAAsB,GAAG;IACpC,QAAQ;IACR,qDAAqD;IACrD,WAAW;IACX,QAAQ;CACA,CAAC;AAOX;;GAEG;AACH,MAAa,iBAAiB;IAC5B;;;;;;;;OAQG;IACH,MAAM,CAAC,KAAK,CAAC,MAAM,CACjB,QAAoB,EACpB,MAAiB,EACjB,iBAAuC;;QAEvC,MAAM,YAAY,GAAG,MAAA,MAAA,QAAQ,CAAC,QAAQ,0CAAE,IAAI,0CAAE,WAAW,EAAE,CAAC;QAC5D,8DAA8D;QAC9D,MAAM,cAAc,GAAG,IAAI,CAAC,kBAAkB,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAC;QAEhF,6BAA6B;QAC7B,gDAAgD;QAChD,KAAK,MAAM,YAAY,IAAI,cAAc,EAAE;YACzC,4CAA4C;YAC5C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,YAAY,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;YAC/E,IAAI,QAAQ,EAAE;gBACZ,OAAO,QAAQ,CAAC;aACjB;SACF;QAED,yDAAyD;QACzD,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,CACV,sDAAsD,MAAA,MAAA,QAAQ,CAA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;;OAEG;IACK,MAAM,CAAC,KAAK,CAAC,eAAe,CAClC,WAAmB,EACnB,iBAAyB,EACzB,QAAoB,EACpB,MAAiB;;QAEjB,IAAI;YACF,yCAAyC;YACzC,6CAA6C;YAC7C,wGAAwG;YACxG,MAAM,EAAE,CAAC,iBAAiB,CAAC,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;YAEpE,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YAC9D,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,CACX,wCAAwC,MAAA,QAAQ,CAAC,QAAQ,0CAAE,IAAI,iBAAiB,WAAW,EAAE,CAC9F,CAAC;YACF,OAAO,QAAQ,CAAC;SACjB;QAAC,OAAO,KAAK,EAAE;YACd,uEAAuE;YACvE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,CACV,kCAAkC,MAAA,QAAQ,CAAC,QAAQ,0CAAE,IAAI,iBAAiB,WAAW,KAAK,KAAK,EAAE,CAClG,CAAC;YACF,OAAO,SAAS,CAAC;SAClB;IACH,CAAC;CACF;AAhID,8CAgIC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/providers/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,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("./AIProvider"), exports);
|
|
18
|
+
__exportStar(require("./AIProviderFactory"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/providers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,sDAAoC"}
|