feat(ai): add UnsupportedOperation error for route capability mismatches - #46960
Open
rekram1-node wants to merge 1 commit into
Open
feat(ai): add UnsupportedOperation error for route capability mismatches#46960rekram1-node wants to merge 1 commit into
rekram1-node wants to merge 1 commit into
Conversation
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.
Calling an operation the selected route does not implement (e.g.
LLMClient.compacton Anthropic) failed with a genericInvalidRequest, forcing consumers to match on message text. This adds a typed distinction.Name options considered
InvalidRequest,NoRoute,UnknownProvider) and reads naturally next tooperation: "compact".Open to renaming before merge; the shape below stays the same either way.
Shape
AI.Error.UnsupportedOperation(packages/ai/src/schema/errors.ts) withoperation: stringplus optionalprovider/route.operationis an open string so future ops (video generation, etc.) reuse it without another union member.ProviderShared.unsupportedOperation({ operation, message, provider?, route? })is the shared constructor.Migrated (missing capability, never touches the network)
route/client.ts: explicitcompacton a route without a compact endpoint →operation: "compact"protocols/xai-responses.ts: automaticcontextManagementon xAI (explicit-only route) →operation: "in-band-compaction"core/src/aisdk.ts: AI SDK bridge hitting native compaction replay state →operation: "compaction-replay"Required follow-through:
to-session-error.tsmaps it toprovider.unsupported-operation(open wire string, no schema/regen needed),retry.tstreats it as non-retryable likeInvalidRequest/NoRoute.Deliberately left as InvalidRequest
The other ~20
invalidRequestsites are malformed caller input, not missing capabilities (bad media/base64, missing filename, conflicting options, missing credentials, cross-provider compaction replay, non-object overlays). Those stay; the rule is: capability missing →UnsupportedOperation, input invalid →InvalidRequest.Consumer guidance
Prefer the capability guard over try/catch:
LLMClient.canCompact(request)narrows toCompactionRequestat both type and runtime level. Catch-and-fallback now has a real branch:reason._tag === "UnsupportedOperation" && reason.operation === "compact".Verification
bun typecheckclean inpackages/ai(incl.tsconfig.types.jsoncapability assertions) andpackages/corepackages/ai: full suite 980 pass / 0 fail; updatedexplicit-compaction,schemareason-enumeration, and added an Anthropiccompactrejection testpackages/core:session-error(mapping + non-retryable) andaisdk(replay rejection) pass