Skip to content

Commit 37b54e7

Browse files
committed
set defaults for ai provider and adjust some type names for ai sdk
1 parent af43b47 commit 37b54e7

File tree

4 files changed

+59
-22
lines changed

4 files changed

+59
-22
lines changed

packages/sdk/server-ai/src/LDAIClientImpl.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
LDAIAgentConfig,
88
LDAIAgentConfigDefault,
99
LDAIAgentRequestConfig,
10-
LDAIConfigKindDefault,
10+
LDAIConfigDefaultKind,
11+
LDAIConfigKind,
1112
LDAIConversationConfig,
1213
LDAIConversationConfigDefault,
1314
LDAIJudgeConfig,
@@ -39,10 +40,10 @@ export class LDAIClientImpl implements LDAIClient {
3940
private async _evaluate(
4041
key: string,
4142
context: LDContext,
42-
defaultValue: LDAIConfigKindDefault,
43+
defaultValue: LDAIConfigDefaultKind,
4344
mode: 'completion' | 'agent' | 'judge',
4445
variables?: Record<string, unknown>,
45-
): Promise<LDAIConversationConfig | LDAIAgentConfig | LDAIJudgeConfig> {
46+
): Promise<LDAIConfigKind> {
4647
// Convert default value to LDFlagValue format
4748
const ldFlagValue = LDAIConfigUtils.toFlagValue(defaultValue, mode);
4849

packages/sdk/server-ai/src/api/config/LDAIConfigUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { LDAIConfigTracker } from './LDAIConfigTracker';
22
import {
33
LDAIAgentConfig,
4-
LDAIConfigKindDefault,
4+
LDAIConfigDefaultKind,
55
LDAIConversationConfig,
66
LDAIJudgeConfig,
77
LDJudgeConfiguration,
@@ -45,7 +45,7 @@ export class LDAIConfigUtils {
4545
* @returns The flag value structure for LaunchDarkly
4646
*/
4747
static toFlagValue(
48-
config: LDAIConfigKindDefault,
48+
config: LDAIConfigDefaultKind,
4949
mode: 'completion' | 'agent' | 'judge',
5050
): LDAIConfigFlagValue {
5151
return {

packages/sdk/server-ai/src/api/config/types.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export interface LDJudgeConfiguration {
4949
/**
5050
* Base AI Config interface without mode-specific fields.
5151
*/
52-
export interface LDAIConfigBase extends Omit<LDAIConfigBaseDefault, 'enabled'> {
52+
export interface LDAIConfig extends Omit<LDAIConfigDefault, 'enabled'> {
5353
/**
5454
* Whether the configuration is enabled.
5555
*/
@@ -81,7 +81,7 @@ export interface LDAIConfigBase extends Omit<LDAIConfigBaseDefault, 'enabled'> {
8181
/**
8282
* Base AI Config interface for default implementations with optional enabled property.
8383
*/
84-
export interface LDAIConfigBaseDefault {
84+
export interface LDAIConfigDefault {
8585
/**
8686
* Optional model configuration.
8787
*/
@@ -105,7 +105,7 @@ export interface LDAIConfigBaseDefault {
105105
/**
106106
* Default Judge-specific AI Config with required evaluation metric key.
107107
*/
108-
export interface LDAIJudgeConfigDefault extends LDAIConfigBaseDefault {
108+
export interface LDAIJudgeConfigDefault extends LDAIConfigDefault {
109109
/**
110110
* Optional prompt data for judge configurations.
111111
*/
@@ -120,7 +120,7 @@ export interface LDAIJudgeConfigDefault extends LDAIConfigBaseDefault {
120120
/**
121121
* Default Agent-specific AI Config with instructions.
122122
*/
123-
export interface LDAIAgentConfigDefault extends LDAIConfigBaseDefault {
123+
export interface LDAIAgentConfigDefault extends LDAIConfigDefault {
124124
/**
125125
* Instructions for the agent.
126126
*/
@@ -135,7 +135,7 @@ export interface LDAIAgentConfigDefault extends LDAIConfigBaseDefault {
135135
/**
136136
* Default Completion AI Config (default mode).
137137
*/
138-
export interface LDAIConversationConfigDefault extends LDAIConfigBaseDefault {
138+
export interface LDAIConversationConfigDefault extends LDAIConfigDefault {
139139
/**
140140
* Optional prompt data for completion configurations.
141141
*/
@@ -154,7 +154,7 @@ export interface LDAIConversationConfigDefault extends LDAIConfigBaseDefault {
154154
/**
155155
* Judge-specific AI Config with required evaluation metric key.
156156
*/
157-
export interface LDAIJudgeConfig extends LDAIConfigBase {
157+
export interface LDAIJudgeConfig extends LDAIConfig {
158158
/**
159159
* Optional prompt data for judge configurations.
160160
*/
@@ -169,7 +169,7 @@ export interface LDAIJudgeConfig extends LDAIConfigBase {
169169
/**
170170
* Agent-specific AI Config with instructions.
171171
*/
172-
export interface LDAIAgentConfig extends LDAIConfigBase {
172+
export interface LDAIAgentConfig extends LDAIConfig {
173173
/**
174174
* Instructions for the agent.
175175
*/
@@ -184,7 +184,7 @@ export interface LDAIAgentConfig extends LDAIConfigBase {
184184
/**
185185
* Completion AI Config (default mode).
186186
*/
187-
export interface LDAIConversationConfig extends LDAIConfigBase {
187+
export interface LDAIConversationConfig extends LDAIConfig {
188188
/**
189189
* Optional prompt data for completion configurations.
190190
*/
@@ -218,7 +218,7 @@ export type LDAIConfigKind = LDAIConversationConfig | LDAIAgentConfig | LDAIJudg
218218
/**
219219
* Union type for all default AI Config variants.
220220
*/
221-
export type LDAIConfigKindDefault =
221+
export type LDAIConfigDefaultKind =
222222
| LDAIConversationConfigDefault
223223
| LDAIAgentConfigDefault
224224
| LDAIJudgeConfigDefault;

packages/sdk/server-ai/src/api/providers/AIProvider.ts

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { LDLogger } from '@launchdarkly/js-server-sdk-common';
22

33
import { ChatResponse } from '../chat/types';
4-
import { LDAIConfigKind, LDMessage } from '../config/types';
4+
import { LDAIConfig, LDMessage } from '../config/types';
55
import { StructuredResponse } from '../judge/types';
66

77
/**
@@ -23,24 +23,60 @@ export abstract class AIProvider {
2323
* This method should convert messages to provider format, invoke the model,
2424
* and return a ChatResponse with the result and metrics.
2525
*
26+
* Default implementation takes no action and returns a placeholder response.
27+
* Provider implementations should override this method.
28+
*
2629
* @param messages Array of LDMessage objects representing the conversation
2730
* @returns Promise that resolves to a ChatResponse containing the model's response
2831
*/
29-
abstract invokeModel(messages: LDMessage[]): Promise<ChatResponse>;
32+
async invokeModel(_messages: LDMessage[]): Promise<ChatResponse> {
33+
this.logger?.warn('invokeModel not implemented by this provider');
34+
return {
35+
message: {
36+
role: 'assistant',
37+
content: '',
38+
},
39+
metrics: {
40+
success: false,
41+
usage: {
42+
total: 0,
43+
input: 0,
44+
output: 0,
45+
},
46+
},
47+
};
48+
}
3049

3150
/**
3251
* Invoke the chat model with structured output support.
3352
* This method should convert messages to provider format, invoke the model with
3453
* structured output configuration, and return a structured response.
3554
*
55+
* Default implementation takes no action and returns a placeholder response.
56+
* Provider implementations should override this method.
57+
*
3658
* @param messages Array of LDMessage objects representing the conversation
37-
* @param outputs Dictionary of output configurations keyed by output name
59+
* @param responseStructure Dictionary of output configurations keyed by output name
3860
* @returns Promise that resolves to a structured response
3961
*/
40-
abstract invokeStructuredModel(
41-
messages: LDMessage[],
42-
responseStructure: Record<string, unknown>,
43-
): Promise<StructuredResponse>;
62+
async invokeStructuredModel(
63+
_messages: LDMessage[],
64+
_responseStructure: Record<string, unknown>,
65+
): Promise<StructuredResponse> {
66+
this.logger?.warn('invokeStructuredModel not implemented by this provider');
67+
return {
68+
data: {},
69+
rawResponse: '',
70+
metrics: {
71+
success: false,
72+
usage: {
73+
total: 0,
74+
input: 0,
75+
output: 0,
76+
},
77+
},
78+
};
79+
}
4480

4581
/**
4682
* Static method that constructs an instance of the provider.
@@ -52,7 +88,7 @@ export abstract class AIProvider {
5288
* @returns Promise that resolves to a configured provider instance
5389
*/
5490
// eslint-disable-next-line @typescript-eslint/no-unused-vars
55-
static async create(aiConfig: LDAIConfigKind, logger?: LDLogger): Promise<AIProvider> {
91+
static async create(aiConfig: LDAIConfig, logger?: LDLogger): Promise<AIProvider> {
5692
throw new Error('Provider implementations must override the static create method');
5793
}
5894
}

0 commit comments

Comments
 (0)