Skip to content

Commit fbf7411

Browse files
jsonbaileyclaude
andcommitted
feat!: remove deprecated AIProvider methods and create*/init* aliases (AIC-2388)
Now that all provider packages (#1337 OpenAI, #1338 LangChain, #1339 Vercel) have migrated to the Runner protocol, the deprecated compatibility surface on the umbrella `feat/next-ai-release` branch can be removed. BREAKING CHANGE: Removes the following deprecated APIs: AIProvider abstract base class: - `invokeModel()` and `invokeStructuredModel()` instance methods - `static create()` factory method - `protected logger` field on the constructor (provider subclasses now declare their own private `_logger` field) LDAIClient deprecated method aliases: - `config()` (use `completionConfig`) - `agent()` (use `agentConfig`) - `agents()` (use `agentConfigs`) - `createChat()` and `initChat()` (use `createModel`) Public types: - `StructuredResponse` (only consumed by the removed `invokeStructuredModel` method) Type narrowing on `AIProvider` and `RunnerFactory`: - `createModel(config: LDAICompletionConfig | LDAIJudgeConfig)` - `createAgent(config: LDAIAgentConfig)` - `createAgentGraph(graphDef: AgentGraphDefinition)` Previously these accepted the wider `LDAIConfigKind` union; the new signatures mirror what the provider subclasses already declared and surface mode mismatches at the type level. Also updates README examples to use `createModel`/`run()` and removes the stale `_LegacyProviderAdapter` references in `RunnerFactory` doc comments. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 288ac65 commit fbf7411

21 files changed

Lines changed: 138 additions & 348 deletions

File tree

packages/ai-providers/server-ai-langchain/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
## Quick Setup
2222

23-
This package provides LangChain integration for the LaunchDarkly AI SDK. The simplest way to use it is with the LaunchDarkly AI SDK's `initChat` method:
23+
This package provides LangChain integration for the LaunchDarkly AI SDK. The simplest way to use it is with the LaunchDarkly AI SDK's `createModel` method:
2424

2525
1. Install the required packages:
2626

@@ -30,7 +30,7 @@ npm install @launchdarkly/server-sdk-ai @launchdarkly/server-sdk-ai-langchain --
3030
yarn add @launchdarkly/server-sdk-ai @launchdarkly/server-sdk-ai-langchain
3131
```
3232

33-
2. Create a chat session and use it:
33+
2. Create a managed model and run it:
3434

3535
```typescript
3636
import { init } from '@launchdarkly/node-server-sdk';
@@ -40,17 +40,17 @@ import { initAi } from '@launchdarkly/server-sdk-ai';
4040
const ldClient = init(sdkKey);
4141
const aiClient = initAi(ldClient);
4242

43-
// Create a chat session
44-
const defaultConfig = {
45-
enabled: true,
43+
// Create a managed model
44+
const defaultConfig = {
45+
enabled: true,
4646
model: { name: 'gpt-4' },
4747
provider: { name: 'openai' }
4848
};
49-
const chat = await aiClient.initChat('my-chat-config', context, defaultConfig);
49+
const model = await aiClient.createModel('my-chat-config', context, defaultConfig);
5050

51-
if (chat) {
52-
const response = await chat.invoke('What is the capital of France?');
53-
console.log(response.message.content);
51+
if (model) {
52+
const result = await model.run('What is the capital of France?');
53+
console.log(result.content);
5454
}
5555
```
5656

packages/ai-providers/server-ai-langchain/__tests__/LangChainHelper.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('createLangChainModel', () => {
3333
enabled: true,
3434
provider: { name: 'openai' },
3535
model: { name: 'gpt-4o', parameters: { temperature: 0.5 } },
36-
});
36+
} as any);
3737

3838
expect(mockInitChatModel).toHaveBeenCalledWith('gpt-4o', {
3939
temperature: 0.5,
@@ -47,7 +47,7 @@ describe('createLangChainModel', () => {
4747
enabled: true,
4848
provider: { name: 'gemini' },
4949
model: { name: 'gemini-2.0' },
50-
});
50+
} as any);
5151

5252
expect(mockInitChatModel).toHaveBeenCalledWith('gemini-2.0', {
5353
modelProvider: 'google-genai',

packages/ai-providers/server-ai-langchain/__tests__/LangChainModelRunner.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ const mockLogger = {
1111
debug: jest.fn(),
1212
};
1313

14-
const baseConfig: LDAICompletionConfig = {
14+
const baseConfig = {
1515
key: 'completion',
1616
enabled: true,
1717
model: { name: 'fake' },
18-
};
18+
} as unknown as LDAICompletionConfig;
1919

2020
describe('LangChainModelRunner', () => {
2121
let mockLLM: any;

packages/ai-providers/server-ai-langchain/__tests__/LangChainRunnerFactory.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ describe('LangChainRunnerFactory', () => {
3232
});
3333

3434
it('builds a LangChainModelRunner with model and parameters from the config', async () => {
35-
const config: LDAICompletionConfig = {
35+
const config = {
3636
key: 'completion',
3737
enabled: true,
3838
provider: { name: 'openai' },
3939
model: { name: 'gpt-4o', parameters: { temperature: 0.5 } },
40-
};
40+
} as unknown as LDAICompletionConfig;
4141

4242
const runner = await factory.createModel(config);
4343

@@ -54,7 +54,7 @@ describe('LangChainRunnerFactory', () => {
5454
enabled: true,
5555
provider: { name: 'gemini' },
5656
model: { name: 'gemini-2.0' },
57-
});
57+
} as unknown as LDAICompletionConfig);
5858

5959
expect(mockInitChatModel).toHaveBeenCalledWith('gemini-2.0', {
6060
modelProvider: 'google-genai',
@@ -63,13 +63,13 @@ describe('LangChainRunnerFactory', () => {
6363

6464
it('strips tools from parameters and passes them to createAgent', async () => {
6565
const tools = [{ name: 'lookup', description: 'looks up a value' }];
66-
const config: LDAIAgentConfig = {
66+
const config = {
6767
key: 'agent',
6868
enabled: true,
6969
provider: { name: 'openai' },
7070
model: { name: 'gpt-4o', parameters: { temperature: 0.7, tools } },
7171
instructions: 'be helpful',
72-
};
72+
} as unknown as LDAIAgentConfig;
7373

7474
const runner = await factory.createAgent(config, { lookup: () => 'ok' });
7575

@@ -88,13 +88,13 @@ describe('LangChainRunnerFactory', () => {
8888
});
8989

9090
it('passes undefined tools to createAgent when no tool definitions exist', async () => {
91-
const config: LDAIAgentConfig = {
91+
const config = {
9292
key: 'agent',
9393
enabled: true,
9494
provider: { name: 'openai' },
9595
model: { name: 'gpt-4o' },
9696
instructions: '',
97-
};
97+
} as unknown as LDAIAgentConfig;
9898

9999
await factory.createAgent(config);
100100

packages/ai-providers/server-ai-langchain/src/LangChainRunnerFactory.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ let instrumentPromise: Promise<void> | undefined;
1818
* Factory for creating LangChain runners (chat completion and agent).
1919
*/
2020
export class LangChainRunnerFactory extends AIProvider {
21+
private _logger?: LDLogger;
22+
2123
constructor(logger?: LDLogger) {
22-
super(logger);
24+
super();
25+
this._logger = logger;
2326
LangChainRunnerFactory._ensureInstrumented(logger).catch(() => {});
2427
}
2528

@@ -28,7 +31,7 @@ export class LangChainRunnerFactory extends AIProvider {
2831
*/
2932
async createModel(config: LDAICompletionConfig): Promise<LangChainModelRunner> {
3033
const llm = await createLangChainModel(config);
31-
return new LangChainModelRunner(llm, config, this.logger);
34+
return new LangChainModelRunner(llm, config, this._logger);
3235
}
3336

3437
/**
@@ -50,7 +53,7 @@ export class LangChainRunnerFactory extends AIProvider {
5053
};
5154
const llm = await createLangChainModel(configForModel);
5255

53-
const lcTools = buildStructuredTools(toolDefinitions, tools ?? {}, this.logger);
56+
const lcTools = buildStructuredTools(toolDefinitions, tools ?? {}, this._logger);
5457
const instructions = config.instructions ?? '';
5558

5659
const agent = createAgent({
@@ -59,7 +62,7 @@ export class LangChainRunnerFactory extends AIProvider {
5962
systemPrompt: instructions || undefined,
6063
});
6164

62-
return new LangChainAgentRunner(agent as any, this.logger);
65+
return new LangChainAgentRunner(agent as any, this._logger);
6366
}
6467

6568
/**

packages/ai-providers/server-ai-openai/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323

2424
## Quick Setup
2525

26-
This package provides OpenAI integration for the LaunchDarkly AI SDK. The simplest way to use it is with the LaunchDarkly AI SDK's `initChat` method:
26+
This package provides OpenAI integration for the LaunchDarkly AI SDK. The simplest way to use it is with the LaunchDarkly AI SDK's `createModel` method:
2727

2828
1. Install the required packages:
2929

3030
```shell
3131
npm install @launchdarkly/server-sdk-ai @launchdarkly/server-sdk-ai-openai --save
3232
```
3333

34-
2. Create a chat session and use it:
34+
2. Create a managed model and run it:
3535

3636
```typescript
3737
import { init } from '@launchdarkly/node-server-sdk';
@@ -41,17 +41,17 @@ import { initAi } from '@launchdarkly/server-sdk-ai';
4141
const ldClient = init(sdkKey);
4242
const aiClient = initAi(ldClient);
4343

44-
// Create a chat session
45-
const defaultConfig = {
46-
enabled: true,
44+
// Create a managed model
45+
const defaultConfig = {
46+
enabled: true,
4747
model: { name: 'gpt-4' },
4848
provider: { name: 'openai' }
4949
};
50-
const chat = await aiClient.initChat('my-chat-config', context, defaultConfig);
50+
const model = await aiClient.createModel('my-chat-config', context, defaultConfig);
5151

52-
if (chat) {
53-
const response = await chat.invoke("What is the capital of France?");
54-
console.log(response.message.content);
52+
if (model) {
53+
const result = await model.run('What is the capital of France?');
54+
console.log(result.content);
5555
}
5656
```
5757

packages/ai-providers/server-ai-openai/src/OpenAIRunnerFactory.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ let instrumentPromise: Promise<void> | undefined;
1717
*/
1818
export class OpenAIRunnerFactory extends AIProvider {
1919
private _client: OpenAI;
20+
private _logger?: LDLogger;
2021

2122
constructor(logger?: LDLogger) {
22-
super(logger);
23+
super();
24+
this._logger = logger;
2325
this._client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
2426
// Fire-and-forget: OTel instrumentation is optional and must not block construction.
2527
OpenAIRunnerFactory._ensureInstrumented(logger).catch(() => {});
@@ -29,7 +31,7 @@ export class OpenAIRunnerFactory extends AIProvider {
2931
* Create a model runner from a completion AI configuration.
3032
*/
3133
async createModel(config: LDAICompletionConfig): Promise<OpenAIModelRunner> {
32-
return new OpenAIModelRunner(this._client, config, this.logger);
34+
return new OpenAIModelRunner(this._client, config, this._logger);
3335
}
3436

3537
/**
@@ -66,7 +68,12 @@ export class OpenAIRunnerFactory extends AIProvider {
6668
const parameters = _mapParameterKeys({ ...(config.model?.parameters ?? {}) });
6769
delete parameters.tools;
6870

69-
const { agentTools, toolNameMap } = buildAgentTools(toolHelper, configTools, registry, this.logger);
71+
const { agentTools, toolNameMap } = buildAgentTools(
72+
toolHelper,
73+
configTools,
74+
registry,
75+
this._logger,
76+
);
7077
const agent = new Agent({
7178
name: 'ldai-agent',
7279
instructions: config.instructions || undefined,
@@ -75,7 +82,7 @@ export class OpenAIRunnerFactory extends AIProvider {
7582
modelSettings: parameters,
7683
});
7784

78-
return new OpenAIAgentRunner(agent, agentRun, toolNameMap, this.logger);
85+
return new OpenAIAgentRunner(agent, agentRun, toolNameMap, this._logger);
7986
}
8087

8188
/**

packages/ai-providers/server-ai-vercel/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
## Quick Setup
2222

23-
This package provides Vercel AI SDK integration for the LaunchDarkly AI SDK. The simplest way to use it is with the LaunchDarkly AI SDK's `initChat` method:
23+
This package provides Vercel AI SDK integration for the LaunchDarkly AI SDK. The simplest way to use it is with the LaunchDarkly AI SDK's `createModel` method:
2424

2525
1. Install the required packages:
2626

@@ -30,7 +30,7 @@ npm install @launchdarkly/server-sdk-ai @launchdarkly/server-sdk-ai-vercel --sav
3030
yarn add @launchdarkly/server-sdk-ai @launchdarkly/server-sdk-ai-vercel
3131
```
3232

33-
2. Create a chat session and use it:
33+
2. Create a managed model and run it:
3434

3535
```typescript
3636
import { init } from '@launchdarkly/node-server-sdk';
@@ -40,17 +40,17 @@ import { initAi } from '@launchdarkly/server-sdk-ai';
4040
const ldClient = init(sdkKey);
4141
const aiClient = initAi(ldClient);
4242

43-
// Create a chat session
44-
const defaultConfig = {
45-
enabled: true,
43+
// Create a managed model
44+
const defaultConfig = {
45+
enabled: true,
4646
model: { name: 'gpt-4' },
4747
provider: { name: 'openai' }
4848
};
49-
const chat = await aiClient.initChat('my-chat-config', context, defaultConfig);
49+
const model = await aiClient.createModel('my-chat-config', context, defaultConfig);
5050

51-
if (chat) {
52-
const response = await chat.invoke('What is the capital of France?');
53-
console.log(response.message.content);
51+
if (model) {
52+
const result = await model.run('What is the capital of France?');
53+
console.log(result.content);
5454
}
5555
```
5656

packages/ai-providers/server-ai-vercel/__tests__/VercelModelRunner.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ const mockLogger = {
1717
debug: jest.fn(),
1818
};
1919

20-
const baseConfig: LDAICompletionConfig = {
20+
const baseConfig = {
2121
key: 'completion',
2222
enabled: true,
2323
model: { name: 'mock' },
24-
};
24+
} as unknown as LDAICompletionConfig;
2525

2626
describe('VercelModelRunner', () => {
2727
const fakeModel = { name: 'mock' };

packages/ai-providers/server-ai-vercel/__tests__/VercelRunnerFactory.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { LDAICompletionConfig, LDAIConfig } from '@launchdarkly/server-sdk-ai';
2+
13
import { VercelModelRunner } from '../src/VercelModelRunner';
24
import { VercelRunnerFactory } from '../src/VercelRunnerFactory';
35

@@ -15,7 +17,7 @@ describe('VercelRunnerFactory', () => {
1517
enabled: true,
1618
provider: { name: 'openai' },
1719
model: { name: 'gpt-4o', parameters: { max_tokens: 100, temperature: 0.7 } },
18-
});
20+
} as unknown as LDAICompletionConfig);
1921

2022
expect(runner).toBeInstanceOf(VercelModelRunner);
2123
expect(runner.getModel()).toBe(fakeModel);
@@ -62,7 +64,7 @@ describe('VercelRunnerFactory', () => {
6264
enabled: true,
6365
provider: { name: 'unsupported' },
6466
model: { name: 'm' },
65-
}),
67+
} as unknown as LDAIConfig),
6668
).rejects.toThrow('Unsupported Vercel AI provider: unsupported');
6769
});
6870
});

0 commit comments

Comments
 (0)