@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.
Files changed (41) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/__tests__/LDAIClientImpl.test.ts +20 -6
  3. package/dist/LDAIClientImpl.d.ts +1 -0
  4. package/dist/LDAIClientImpl.d.ts.map +1 -1
  5. package/dist/LDAIClientImpl.js +17 -4
  6. package/dist/LDAIClientImpl.js.map +1 -1
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js.map +1 -1
  10. package/docs/assets/search.js +1 -1
  11. package/docs/classes/AIProvider.html +12 -11
  12. package/docs/classes/AIProviderFactory.html +12 -11
  13. package/docs/classes/TrackedChat.html +16 -15
  14. package/docs/enums/LDFeedbackKind.html +7 -6
  15. package/docs/functions/createBedrockTokenUsage.html +5 -4
  16. package/docs/functions/createOpenAiUsage.html +5 -4
  17. package/docs/functions/createVercelAISDKTokenUsage.html +5 -4
  18. package/docs/functions/initAi.html +5 -4
  19. package/docs/index.html +6 -4
  20. package/docs/interfaces/ChatResponse.html +7 -6
  21. package/docs/interfaces/LDAIAgent.html +10 -9
  22. package/docs/interfaces/LDAIAgentConfig.html +8 -7
  23. package/docs/interfaces/LDAIClient.html +9 -8
  24. package/docs/interfaces/LDAIConfig.html +11 -10
  25. package/docs/interfaces/LDAIConfigTracker.html +18 -17
  26. package/docs/interfaces/LDAIMetrics.html +7 -6
  27. package/docs/interfaces/LDLogger.html +179 -0
  28. package/docs/interfaces/LDMessage.html +7 -6
  29. package/docs/interfaces/LDModelConfig.html +8 -7
  30. package/docs/interfaces/LDProviderConfig.html +6 -5
  31. package/docs/interfaces/LDTokenUsage.html +8 -7
  32. package/docs/interfaces/VercelAISDKConfig.html +16 -15
  33. package/docs/interfaces/VercelAISDKMapOptions.html +6 -5
  34. package/docs/types/LDAIAgentDefaults.html +5 -4
  35. package/docs/types/LDAIDefaults.html +5 -4
  36. package/docs/types/SupportedAIProvider.html +5 -4
  37. package/docs/types/VercelAISDKProvider.html +5 -4
  38. package/docs/variables/SUPPORTED_AI_PROVIDERS.html +5 -4
  39. package/package.json +1 -1
  40. package/src/LDAIClientImpl.ts +30 -8
  41. package/src/index.ts +2 -0
@@ -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
- const value: VariationContent = await this._ldClient.variation(key, context, defaultValue);
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 { tracker, enabled, model, provider, instructions } = await this._evaluate(
113
- key,
114
- context,
115
- defaultValue,
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 (provider) {
130
- agent.provider = { ...provider };
151
+ if (configProvider) {
152
+ agent.provider = { ...configProvider };
131
153
  }
132
154
 
133
155
  const allVariables = { ...variables, ldctx: context };
package/src/index.ts CHANGED
@@ -19,4 +19,6 @@ export function initAi(ldClient: LDClientMin): LDAIClient {
19
19
  return new LDAIClientImpl(ldClient);
20
20
  }
21
21
 
22
+ export { LDLogger } from '@launchdarkly/js-server-sdk-common';
23
+
22
24
  export * from './api';