Skip to content

Commit f71a457

Browse files
fix(ai-sdk): Remove Vercel mapping method from LD (#911)
**Requirements** - [ ] I have added test coverage for new or changed functionality -- removed functionality - [x] I have followed the repository's [pull request submission guidelines](../blob/main/CONTRIBUTING.md#submitting-pull-requests) - [x] I have validated my changes against all supported platform versions **Related issues** Private JIRA issue **Describe the solution you've provided** Removes the implementation of the `toVercelAISDK` from the `LDAIAgent` implementation as the return type does not conform to the agents data model. **Describe alternatives you've considered** This method will need to be updated to work specifically with agents. Specifically, the `instructions` and `tools` fields will need to be mapped to [Vercel's agent contract](https://vercel.com/docs/agents) **Additional context** When built locally, the `toVercelAISDK` method is no longer required to be implemented in the default values: <img width="564" height="317" alt="Screenshot 2025-08-26 at 9 08 13 AM" src="https://github.com/user-attachments/assets/5a1f93d0-0bf0-4417-8e61-8e470ce616a9" />
1 parent 83f42b8 commit f71a457

File tree

3 files changed

+5
-113
lines changed

3 files changed

+5
-113
lines changed

packages/sdk/server-ai/__tests__/LDAIClientImpl.test.ts

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

33
import { LDAIAgentDefaults } from '../src/api/agents';
4-
import {
5-
LDAIDefaults,
6-
VercelAISDKConfig,
7-
VercelAISDKMapOptions,
8-
VercelAISDKProvider,
9-
} from '../src/api/config';
4+
import { LDAIDefaults } from '../src/api/config';
105
import { LDAIClientImpl } from '../src/LDAIClientImpl';
116
import { LDClientMin } from '../src/LDClientMin';
127

@@ -17,7 +12,7 @@ const mockLdClient: jest.Mocked<LDClientMin> = {
1712

1813
const testContext: LDContext = { kind: 'user', key: 'test-user' };
1914

20-
it('returns config with interpolated messagess', async () => {
15+
it('returns config with interpolated messages', async () => {
2116
const client = new LDAIClientImpl(mockLdClient);
2217
const key = 'test-flag';
2318
const defaultValue: LDAIDefaults = {
@@ -156,21 +151,6 @@ it('returns single agent config with interpolated instructions', async () => {
156151
model: { name: 'test', parameters: { name: 'test-model' } },
157152
instructions: 'You are a helpful assistant.',
158153
enabled: true,
159-
toVercelAISDK: <TMod>(
160-
provider: VercelAISDKProvider<TMod> | Record<string, VercelAISDKProvider<TMod>>,
161-
options?: VercelAISDKMapOptions,
162-
): VercelAISDKConfig<TMod> => {
163-
const modelProvider = typeof provider === 'function' ? provider : provider.test;
164-
return {
165-
model: modelProvider('test-model'),
166-
messages: [],
167-
...(options?.nonInterpolatedMessages
168-
? {
169-
messages: options.nonInterpolatedMessages,
170-
}
171-
: {}),
172-
};
173-
},
174154
};
175155

176156
const mockVariation = {
@@ -205,7 +185,6 @@ it('returns single agent config with interpolated instructions', async () => {
205185
instructions: 'You are a helpful assistant. Your name is John and your score is 42',
206186
tracker: expect.any(Object),
207187
enabled: true,
208-
toVercelAISDK: expect.any(Function),
209188
});
210189

211190
// Verify tracking was called
@@ -224,21 +203,6 @@ it('includes context in variables for agent instructions interpolation', async (
224203
model: { name: 'test', parameters: { name: 'test-model' } },
225204
instructions: 'You are a helpful assistant.',
226205
enabled: true,
227-
toVercelAISDK: <TMod>(
228-
provider: VercelAISDKProvider<TMod> | Record<string, VercelAISDKProvider<TMod>>,
229-
options?: VercelAISDKMapOptions,
230-
): VercelAISDKConfig<TMod> => {
231-
const modelProvider = typeof provider === 'function' ? provider : provider.test;
232-
return {
233-
model: modelProvider('test-model'),
234-
messages: [],
235-
...(options?.nonInterpolatedMessages
236-
? {
237-
messages: options.nonInterpolatedMessages,
238-
}
239-
: {}),
240-
};
241-
},
242206
};
243207

244208
const mockVariation = {
@@ -260,21 +224,6 @@ it('handles missing metadata in agent variation', async () => {
260224
model: { name: 'test', parameters: { name: 'test-model' } },
261225
instructions: 'You are a helpful assistant.',
262226
enabled: true,
263-
toVercelAISDK: <TMod>(
264-
provider: VercelAISDKProvider<TMod> | Record<string, VercelAISDKProvider<TMod>>,
265-
options?: VercelAISDKMapOptions,
266-
): VercelAISDKConfig<TMod> => {
267-
const modelProvider = typeof provider === 'function' ? provider : provider.test;
268-
return {
269-
model: modelProvider('test-model'),
270-
messages: [],
271-
...(options?.nonInterpolatedMessages
272-
? {
273-
messages: options.nonInterpolatedMessages,
274-
}
275-
: {}),
276-
};
277-
},
278227
};
279228

280229
const mockVariation = {
@@ -291,7 +240,6 @@ it('handles missing metadata in agent variation', async () => {
291240
instructions: 'Hello.',
292241
tracker: expect.any(Object),
293242
enabled: false,
294-
toVercelAISDK: expect.any(Function),
295243
});
296244
});
297245

@@ -303,22 +251,6 @@ it('passes the default value to the underlying client for single agent', async (
303251
provider: { name: 'default-provider' },
304252
instructions: 'Default instructions',
305253
enabled: true,
306-
toVercelAISDK: <TMod>(
307-
provider: VercelAISDKProvider<TMod> | Record<string, VercelAISDKProvider<TMod>>,
308-
options?: VercelAISDKMapOptions,
309-
): VercelAISDKConfig<TMod> => {
310-
const modelProvider =
311-
typeof provider === 'function' ? provider : provider['default-provider'];
312-
return {
313-
model: modelProvider('default-model'),
314-
messages: [],
315-
...(options?.nonInterpolatedMessages
316-
? {
317-
messages: options.nonInterpolatedMessages,
318-
}
319-
: {}),
320-
};
321-
},
322254
};
323255

324256
mockLdClient.variation.mockResolvedValue(defaultValue);
@@ -331,7 +263,6 @@ it('passes the default value to the underlying client for single agent', async (
331263
provider: defaultValue.provider,
332264
tracker: expect.any(Object),
333265
enabled: false,
334-
toVercelAISDK: expect.any(Function),
335266
});
336267

337268
expect(mockLdClient.variation).toHaveBeenCalledWith(key, testContext, defaultValue);
@@ -347,21 +278,6 @@ it('returns multiple agents config with interpolated instructions', async () =>
347278
model: { name: 'test', parameters: { name: 'test-model' } },
348279
instructions: 'You are a research assistant.',
349280
enabled: true,
350-
toVercelAISDK: <TMod>(
351-
provider: VercelAISDKProvider<TMod> | Record<string, VercelAISDKProvider<TMod>>,
352-
options?: VercelAISDKMapOptions,
353-
): VercelAISDKConfig<TMod> => {
354-
const modelProvider = typeof provider === 'function' ? provider : provider.test;
355-
return {
356-
model: modelProvider('test-model'),
357-
messages: [],
358-
...(options?.nonInterpolatedMessages
359-
? {
360-
messages: options.nonInterpolatedMessages,
361-
}
362-
: {}),
363-
};
364-
},
365281
},
366282
variables: { topic: 'climate change' },
367283
},
@@ -371,21 +287,6 @@ it('returns multiple agents config with interpolated instructions', async () =>
371287
model: { name: 'test', parameters: { name: 'test-model' } },
372288
instructions: 'You are a writing assistant.',
373289
enabled: true,
374-
toVercelAISDK: <TMod>(
375-
provider: VercelAISDKProvider<TMod> | Record<string, VercelAISDKProvider<TMod>>,
376-
options?: VercelAISDKMapOptions,
377-
): VercelAISDKConfig<TMod> => {
378-
const modelProvider = typeof provider === 'function' ? provider : provider.test;
379-
return {
380-
model: modelProvider('test-model'),
381-
messages: [],
382-
...(options?.nonInterpolatedMessages
383-
? {
384-
messages: options.nonInterpolatedMessages,
385-
}
386-
: {}),
387-
};
388-
},
389290
},
390291
variables: { style: 'academic' },
391292
},
@@ -428,7 +329,6 @@ it('returns multiple agents config with interpolated instructions', async () =>
428329
instructions: 'You are a research assistant specializing in climate change.',
429330
tracker: expect.any(Object),
430331
enabled: true,
431-
toVercelAISDK: expect.any(Function),
432332
},
433333
'writing-agent': {
434334
model: {
@@ -439,7 +339,6 @@ it('returns multiple agents config with interpolated instructions', async () =>
439339
instructions: 'You are a writing assistant with academic style.',
440340
tracker: expect.any(Object),
441341
enabled: true,
442-
toVercelAISDK: expect.any(Function),
443342
},
444343
});
445344

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ export class LDAIClientImpl implements LDAIClient {
109109
defaultValue,
110110
);
111111

112-
const mapper = new LDAIConfigMapper(model, provider, undefined);
113-
const agent: Omit<LDAIAgent, 'toVercelAISDK'> = {
112+
const agent: LDAIAgent = {
114113
tracker,
115114
enabled,
116115
};
@@ -131,13 +130,7 @@ export class LDAIClientImpl implements LDAIClient {
131130
agent.instructions = this._interpolateTemplate(instructions, allVariables);
132131
}
133132

134-
return {
135-
...agent,
136-
toVercelAISDK: <TMod>(
137-
sdkProvider: VercelAISDKProvider<TMod> | Record<string, VercelAISDKProvider<TMod>>,
138-
options?: VercelAISDKMapOptions | undefined,
139-
): VercelAISDKConfig<TMod> => mapper.toVercelAISDK(sdkProvider, options),
140-
};
133+
return agent;
141134
}
142135

143136
async config(

packages/sdk/server-ai/src/api/agents/LDAIAgent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { LDAIConfig } from '../config';
33
/**
44
* AI Config agent and tracker.
55
*/
6-
export interface LDAIAgent extends Omit<LDAIConfig, 'messages'> {
6+
export interface LDAIAgent extends Omit<LDAIConfig, 'messages' | 'toVercelAISDK'> {
77
/**
88
* Instructions for the agent.
99
*/

0 commit comments

Comments
 (0)