Skip to content

feat(ai): add Vercel AI SDK package - #14

Merged
vijaysingh2219 merged 1 commit into
mainfrom
feat/ai-package
Nov 23, 2026
Merged

vijaysingh2219 merged 1 commit into
mainfrom
feat/ai-package

Conversation

@vijaysingh2219

Copy link
Copy Markdown
Member

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:

  • Provider & Model Resolution (src/providers.ts): getLanguageModel resolves OpenAI (@ai-sdk/openai) and Anthropic (@ai-sdk/anthropic) models with per-key provider instance caching, and getDefaultModelSpecs builds the default fallback chain from AI_DEFAULT_PROVIDER.
  • Automatic Fallbacks (src/fallback.ts): withFallback, generateTextWithFallback, and streamTextWithFallback execute model calls across an ordered fallback chain, retrying on retryable provider errors (error.isRetryable, 408, 429, 5xx) and returning { result, modelIndex, failedAttempts }.
  • Typed Tool Calling (src/tools.ts): defineTool wraps tool handlers with runtime Zod inputSchema validation and produces tools compatible with generateText and streamText.
  • Environment & Workspace Config (src/keys.ts, .env.example, turbo.json): Validates AI_DEFAULT_PROVIDER, OPENAI_API_KEY, OPENAI_MODEL (gpt-6-luna), ANTHROPIC_API_KEY, and ANTHROPIC_MODEL (claude-sonnet-5-5) via @t3-oss/env-nextjs and Zod, declares lint env keys in package turbo.json, and registers ai, @ai-sdk/openai, and @ai-sdk/anthropic in templates/base/pnpm-workspace.yaml.

Scope

Closes #13

Second module in the stackbase add expansion (@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/ai using:

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

- 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
@vercel

vercel Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
stackbase-docs Ready Ready Preview Nov 23, 2026 5:33pm UTC

@vijaysingh2219 vijaysingh2219 self-assigned this Nov 23, 2026
@vijaysingh2219 vijaysingh2219 added the area:templates Starter templates (templates/base, templates/web, templates/api) label Nov 23, 2026
@vijaysingh2219
vijaysingh2219 merged commit 8b5899b into main Nov 23, 2026
10 checks passed

This branch was successfully deployed

1 active deployment
Preview — fe46a68d Deployed Nov 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:templates Starter templates (templates/base, templates/web, templates/api)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(ai): add Vercel AI SDK package

1 participant