Skip to content

Migrate AI harness to Vercel AI SDK - #3

Merged
arvarik merged 1 commit into
mainfrom
feature/vercel-ai-sdk-harness
Aug 17, 2026
Merged

Migrate AI harness to Vercel AI SDK#3
arvarik merged 1 commit into
mainfrom
feature/vercel-ai-sdk-harness

Conversation

@arvarik

@arvarik arvarik commented Aug 17, 2026

Copy link
Copy Markdown
Owner

Summary

Replaces the hand-written provider abstraction (5 provider classes, ~2,300 lines) with a single engine built on the Vercel AI SDK v7. Every model call now goes through three functions in server/ai/engine.js: runText, runStructured, and chatStream. Net deletion of ~1,300 lines.

Fixes

  • Claude Opus 4.8 was broken: every request sent temperature, which newer Claude models reject with a 400. No call sends sampling parameters now.
  • Context stuffing removed: the chat no longer injects the entire flashcard + guide database into the system prompt. The model retrieves notes just-in-time through search_flashcards / search_guide tools (a test chat turn dropped to ~900 input tokens).
  • Dead SDK removed: @google/generative-ai reached end-of-life Nov 2025. Also removes the per-request Gemini explicit-cache creation that paid a cache-write on every call and never read it back.
  • Reliability: retries with backoff (SDK default 2), per-call timeouts, client-disconnect abort propagation, tool loops capped at 8 steps, SSE heartbeats every 15s.
  • Structured output: Zod schemas validated against each provider's native JSON mode; truncation raises a clear error instead of a JSON-parse failure; commit-to-guide gets a 16K output budget.
  • Clear errors: unknown model IDs fail with "Unknown model X" instead of silently routing to Gemini.
  • Observability: one log line per call with model, tokens in/out, finish reason, and duration.

Wire compatibility

The SSE format (data: {text} / {tool} / [DONE]) and all route contracts are unchanged — no client changes needed.

Testing

  • npm test: 167 passing (12 files), including 11 new tests for model routing and the custom-endpoint namespace
  • npm run lint: clean
  • Verified live: Gemini, Claude Haiku, Claude Opus 4.8 (the previously broken path), streaming with a real tool call, structured output, starters, post-chat memory extraction
  • Not verified live: the OpenAI path (the account tied to the stored key is deactivated upstream); it shares the code path with custom endpoints, which are covered by tests

🤖 Generated with Claude Code

…t fixes

Replace the five hand-written provider classes with one engine
(server/ai/engine.js) built on the Vercel AI SDK v7. All model calls
now go through runText, runStructured, and chatStream.

Fixes:
- Remove sampling parameters everywhere (temperature broke Claude Opus 4.8)
- Stop injecting the full flashcard/guide database into the system prompt;
  the model now retrieves notes just-in-time via search tools
- Drop the end-of-life @google/generative-ai SDK and the per-request
  Gemini explicit-cache creation (implicit caching covers it)
- Add retries with backoff, per-call timeouts, and client-disconnect
  abort propagation on every model call
- Cap tool-calling loops at 8 steps
- Stream all providers through one path with SSE heartbeats
- Validate structured output with Zod against provider-native JSON modes;
  raise a clear error on truncation instead of a JSON-parse failure
- Fail clearly on unknown model IDs instead of silently routing to Gemini
- Log model, token usage, finish reason, and duration for every call
- Send real message arrays in non-streaming chat instead of flattened text

Net deletion of ~1,300 lines. Adds engine routing tests; suite is 167 passing.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@cursor

cursor Bot commented Aug 17, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@arvarik
arvarik merged commit 69f88a0 into main Aug 17, 2026
1 check passed
@arvarik
arvarik deleted the feature/vercel-ai-sdk-harness branch August 17, 2026 04:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant