fix: guard against undefined warnings in embed/embedMany (#14425)#14426
Open
xyaz1313 wants to merge 1 commit intovercel:mainfrom
Open
fix: guard against undefined warnings in embed/embedMany (#14425)#14426xyaz1313 wants to merge 1 commit intovercel:mainfrom
xyaz1313 wants to merge 1 commit intovercel:mainfrom
Conversation
EmbeddingModelV2 providers (e.g. @ai-sdk/google-vertex@3.x) do not return a `warnings` property from doEmbed. This caused: - TypeError in logWarnings: Cannot read properties of undefined (reading 'length') - TypeError in embedMany: result.warnings is not iterable Fix: add null checks in log-warnings.ts and embed-many.ts.
AI Code Trust — ship readinessScore: 100 · Verdict: SAFE · Model: deterministic-v1 No blocking issues detected by automated checks. Top issues:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes #14425 —
embed()andembedMany()crash at runtime when used withEmbeddingModelV2providers (e.g.@ai-sdk/google-vertex@3.x) that don't return awarningsproperty fromdoEmbed.Root cause
logWarningsinlog-warnings.ts:97accessesoptions.warnings.lengthwithout a null check —TypeError: Cannot read properties of undefined (reading 'length')embedManyinembed-many.ts:312spreadsresult.warnings—TypeError: result.warnings is not iterableThe
EmbeddingModelV2protocol does not includewarningsin itsdoEmbedreturn type, so v2 providers returnundefinedfor this field.Fix
packages/ai/src/logger/log-warnings.ts:97: Guard with!options.warnings ||before accessing.lengthpackages/ai/src/embed/embed-many.ts:312: Guard withif (result.warnings)before spreadingTesting
The existing test suite should continue to pass since these guards are no-ops when
warningsis present (the common case). The fix handles the edge case wherewarningsisundefined.