-
Notifications
You must be signed in to change notification settings - Fork 31
feat: Adding Vercel AI SDK mapper #895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Adding Vercel AI SDK mapper #895
Conversation
|
@launchdarkly/browser size report |
|
@launchdarkly/js-sdk-common size report |
|
@launchdarkly/js-client-sdk-common size report |
|
@launchdarkly/js-client-sdk size report |
tracisiebel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v minor comments on function
|
Do you have an example of how someone using the Vercel AI SDK would use this wrapper? If not - no worries - we can come up with something. |
const aiConfig = await aiClient.config('vercel-ai-config', context, {});
const result = await aiConfig.tracker.trackVercelAISDKGenerateTextMetrics(() =>
generateText(aiConfig.toVercelAISDK(openai)),
);
console.log(result.text); |
5b6ef04 to
a9a3c6d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Metrics Tracking Fails When Finish Reason Undefined
In the trackVercelAISDKStreamTextMetrics method, if result.finishReason is undefined (which is allowed by its optional type), the optional chaining ?.then() prevents any metrics from being tracked. This includes duration, success/error status, and token usage, leading to incomplete analytics and inconsistent behavior compared to other tracking methods.
packages/sdk/server-ai/src/LDAIConfigTrackerImpl.ts#L150-L193
js-core/packages/sdk/server-ai/src/LDAIConfigTrackerImpl.ts
Lines 150 to 193 in 8ce7288
| trackVercelAISDKStreamTextMetrics< | |
| TRes extends { | |
| finishReason?: Promise<string>; | |
| usage?: Promise<{ | |
| totalTokens?: number; | |
| promptTokens?: number; | |
| completionTokens?: number; | |
| }>; | |
| }, | |
| >(func: () => TRes): TRes { | |
| const startTime = Date.now(); | |
| try { | |
| const result = func(); | |
| result.finishReason | |
| ?.then(async (finishReason) => { | |
| const endTime = Date.now(); | |
| this.trackDuration(endTime - startTime); | |
| if (finishReason === 'error') { | |
| this.trackError(); | |
| } else { | |
| this.trackSuccess(); | |
| if (result.usage) { | |
| try { | |
| this.trackTokens(createVercelAISDKTokenUsage(await result.usage)); | |
| } catch { | |
| // Intentionally squashing this error | |
| } | |
| } | |
| } | |
| }) | |
| .catch(() => { | |
| const endTime = Date.now(); | |
| this.trackDuration(endTime - startTime); | |
| this.trackError(); | |
| }); | |
| return result; | |
| } catch (err) { | |
| const endTime = Date.now(); | |
| this.trackDuration(endTime - startTime); | |
| this.trackError(); | |
| throw err; | |
| } | |
| } |
Was this report helpful? Give feedback by reacting with 👍 or 👎
🤖 I have created a release *beep* *boop* --- <details><summary>server-sdk-ai: 0.10.0</summary> ## [0.10.0](server-sdk-ai-v0.9.9...server-sdk-ai-v0.10.0) (2025-07-16) ### Features * Adding Vercel AI SDK mapper ([#895](#895)) ([0befee0](0befee0)) </details> --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
No description provided.