@launchdarkly/server-sdk-ai 0.12.1 → 0.12.3
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 +14 -0
- package/__tests__/LDAIClientImpl.test.ts +20 -6
- package/dist/LDAIClientImpl.d.ts +1 -0
- package/dist/LDAIClientImpl.d.ts.map +1 -1
- package/dist/LDAIClientImpl.js +17 -4
- package/dist/LDAIClientImpl.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/AIProvider.html +12 -11
- package/docs/classes/AIProviderFactory.html +12 -11
- package/docs/classes/TrackedChat.html +16 -15
- package/docs/enums/LDFeedbackKind.html +7 -6
- package/docs/functions/createBedrockTokenUsage.html +5 -4
- package/docs/functions/createOpenAiUsage.html +5 -4
- package/docs/functions/createVercelAISDKTokenUsage.html +5 -4
- package/docs/functions/initAi.html +5 -4
- package/docs/index.html +6 -4
- package/docs/interfaces/ChatResponse.html +7 -6
- package/docs/interfaces/LDAIAgent.html +10 -9
- package/docs/interfaces/LDAIAgentConfig.html +8 -7
- package/docs/interfaces/LDAIClient.html +9 -8
- package/docs/interfaces/LDAIConfig.html +11 -10
- package/docs/interfaces/LDAIConfigTracker.html +18 -17
- package/docs/interfaces/LDAIMetrics.html +7 -6
- package/docs/interfaces/LDLogger.html +179 -0
- package/docs/interfaces/LDMessage.html +7 -6
- package/docs/interfaces/LDModelConfig.html +8 -7
- package/docs/interfaces/LDProviderConfig.html +6 -5
- package/docs/interfaces/LDTokenUsage.html +8 -7
- package/docs/interfaces/VercelAISDKConfig.html +16 -15
- package/docs/interfaces/VercelAISDKMapOptions.html +6 -5
- package/docs/types/LDAIAgentDefaults.html +5 -4
- package/docs/types/LDAIDefaults.html +5 -4
- package/docs/types/SupportedAIProvider.html +5 -4
- package/docs/types/VercelAISDKProvider.html +5 -4
- package/docs/variables/SUPPORTED_AI_PROVIDERS.html +5 -4
- package/package.json +1 -1
- package/src/LDAIClientImpl.ts +30 -8
- package/src/index.ts +2 -0
package/src/LDAIClientImpl.ts
CHANGED
|
@@ -69,12 +69,32 @@ export class LDAIClientImpl implements LDAIClient {
|
|
|
69
69
|
return Mustache.render(template, variables, undefined, { escape: (item: any) => item });
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
private static _toLDFlagValue(defaultValue: LDAIDefaults | LDAIAgentDefaults): {
|
|
73
|
+
_ldMeta: { enabled: boolean };
|
|
74
|
+
model?: LDModelConfig;
|
|
75
|
+
messages?: LDMessage[];
|
|
76
|
+
provider?: LDProviderConfig;
|
|
77
|
+
instructions?: string;
|
|
78
|
+
} {
|
|
79
|
+
return {
|
|
80
|
+
_ldMeta: { enabled: defaultValue.enabled ?? false },
|
|
81
|
+
model: defaultValue.model,
|
|
82
|
+
messages: 'messages' in defaultValue ? defaultValue.messages : undefined,
|
|
83
|
+
provider: defaultValue.provider,
|
|
84
|
+
instructions: 'instructions' in defaultValue ? defaultValue.instructions : undefined,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
72
88
|
private async _evaluate(
|
|
73
89
|
key: string,
|
|
74
90
|
context: LDContext,
|
|
75
91
|
defaultValue: LDAIDefaults,
|
|
76
92
|
): Promise<EvaluationResult> {
|
|
77
|
-
|
|
93
|
+
// Convert default value to LDFlagValue format
|
|
94
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
95
|
+
const ldFlagValue = LDAIClientImpl._toLDFlagValue(defaultValue);
|
|
96
|
+
|
|
97
|
+
const value: VariationContent = await this._ldClient.variation(key, context, ldFlagValue);
|
|
78
98
|
|
|
79
99
|
const tracker = new LDAIConfigTrackerImpl(
|
|
80
100
|
this._ldClient,
|
|
@@ -109,11 +129,13 @@ export class LDAIClientImpl implements LDAIClient {
|
|
|
109
129
|
defaultValue: LDAIAgentDefaults,
|
|
110
130
|
variables?: Record<string, unknown>,
|
|
111
131
|
): Promise<LDAIAgent> {
|
|
112
|
-
const {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
132
|
+
const {
|
|
133
|
+
tracker,
|
|
134
|
+
enabled,
|
|
135
|
+
model,
|
|
136
|
+
provider: configProvider,
|
|
137
|
+
instructions,
|
|
138
|
+
} = await this._evaluate(key, context, defaultValue);
|
|
117
139
|
|
|
118
140
|
const agent: LDAIAgent = {
|
|
119
141
|
tracker,
|
|
@@ -126,8 +148,8 @@ export class LDAIClientImpl implements LDAIClient {
|
|
|
126
148
|
agent.model = { ...model };
|
|
127
149
|
}
|
|
128
150
|
|
|
129
|
-
if (
|
|
130
|
-
agent.provider = { ...
|
|
151
|
+
if (configProvider) {
|
|
152
|
+
agent.provider = { ...configProvider };
|
|
131
153
|
}
|
|
132
154
|
|
|
133
155
|
const allVariables = { ...variables, ldctx: context };
|