Repository navigation
feat(ai): add Vercel AI SDK package - #14
Merged
Merged
Conversation
- Add @workspace/ai package powered by Vercel AI SDK to base template - Implement OpenAI and Anthropic model resolution with provider instance caching - Provide withFallback, generateTextWithFallback, and streamTextWithFallback helpers - Add defineTool utility with runtime Zod inputSchema validation - Validate AI environment variables with @t3-oss/env-nextjs and Zod - Add unit test suite for fallbacks, retryable errors, and tool execution
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This was referenced Nov 24, 2026
This branch was successfully deployed
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.
Problem
Applications built on Stackbase that integrate LLMs need a shared workspace package for provider initialization, tool calling, and resilience against rate limits (
429) or upstream outages (5xx). Currently developers have to wire Vercel AI SDK providers, fallback retry chains, and environment validation manually inside individual apps.Change
Adds
@workspace/ai(templates/base/packages/ai) as a reusable Vercel AI SDK package for the monorepo:src/providers.ts):getLanguageModelresolves OpenAI (@ai-sdk/openai) and Anthropic (@ai-sdk/anthropic) models with per-key provider instance caching, andgetDefaultModelSpecsbuilds the default fallback chain fromAI_DEFAULT_PROVIDER.src/fallback.ts):withFallback,generateTextWithFallback, andstreamTextWithFallbackexecute model calls across an ordered fallback chain, retrying on retryable provider errors (error.isRetryable,408,429,5xx) and returning{ result, modelIndex, failedAttempts }.src/tools.ts):defineToolwraps tool handlers with runtime ZodinputSchemavalidation and produces tools compatible withgenerateTextandstreamText.src/keys.ts,.env.example,turbo.json): ValidatesAI_DEFAULT_PROVIDER,OPENAI_API_KEY,OPENAI_MODEL(gpt-6-luna),ANTHROPIC_API_KEY, andANTHROPIC_MODEL(claude-sonnet-5-5) via@t3-oss/env-nextjsand Zod, declares lint env keys in packageturbo.json, and registersai,@ai-sdk/openai, and@ai-sdk/anthropicintemplates/base/pnpm-workspace.yaml.Scope
Closes #13
Second module in the
stackbase addexpansion (@workspace/payments,@workspace/ai,@workspace/analytics).Verification
Verified environment schema defaults, retryable error detection, multi-provider fallback execution, non-retryable error propagation, and Zod-validated tool execution in
templates/base/packages/aiusing:pnpm --dir templates/base --filter @workspace/ai check-types pnpm --dir templates/base --filter @workspace/ai lint pnpm --dir templates/base --filter @workspace/ai test pnpm --dir templates/base --filter @workspace/ai build