Skip to content

feat: upgrade AI SDK from v5 to v6#309

Open
marius-kilocode wants to merge 2 commits intodevfrom
feat/ai-sdk-v6-upgrade
Open

feat: upgrade AI SDK from v5 to v6#309
marius-kilocode wants to merge 2 commits intodevfrom
feat/ai-sdk-v6-upgrade

Conversation

@marius-kilocode
Copy link
Collaborator

Summary

Upgrades the Vercel AI SDK from 5.0.124 to 6.0.85 along with all 19 @ai-sdk/* provider packages and third-party providers (@openrouter/ai-sdk-provider, ai-gateway-provider).

Package Version Changes

Package Old New
ai 5.0.124 6.0.85
@ai-sdk/provider 2.0.1 3.0.8
@ai-sdk/provider-utils 3.0.20 4.0.15
@ai-sdk/anthropic 2.0.58 3.0.43
@ai-sdk/openai 2.0.89 3.0.28
@ai-sdk/google 2.0.52 3.0.29
@openrouter/ai-sdk-provider 1.5.4 2.2.3
All other @ai-sdk/* v1-3.x Latest major

Key Changes

  • generateObject/streamObjectgenerateText/streamText + Output.object() — deprecated APIs replaced in agent/agent.ts
  • convertToModelMessages is now async — updated message-v2.ts and all call sites (prompt.ts, compaction.ts)
  • ToolCallOptionsToolExecutionOptions — renamed in prompt.ts
  • LanguageModelUsage type updated — now has inputTokenDetails/outputTokenDetails sub-objects
  • Middleware requires specificationVersion: "v3" — added in llm.ts
  • Provider tool factory renamescreateProviderDefinedToolFactorycreateProviderToolFactory in copilot SDK
  • Finish reason "unknown""other" — updated in copilot SDK finish reason mappers
  • Anthropic top_p/temperature mutual exclusivity — SDK now drops top_p when temperature is set (Anthropic API requirement)
  • toModelOutput parameter wrapping — now receives { output } instead of raw output
  • asSchema().jsonSchema is now async — added await
  • result.text is PromiseLike — wrapped with Promise.resolve() for .catch()

Copilot SDK Strategy

The custom copilot SDK (provider/sdk/copilot/) continues to implement LanguageModelV2 — the AI SDK v6 automatically adapts V2 models via its built-in compatibility layer. This avoids a risky migration of the V2→V3 provider internals while maintaining full functionality.

Validation

  • Typecheck: 10/10 packages pass
  • Tests: Zero regressions — all remaining failures (Bedrock credential-providers, tool.registry timeouts) are pre-existing and identical on the dev branch

Upgrade Vercel AI SDK from 5.0.124 to 6.0.85 along with all 19
@ai-sdk/* provider packages and third-party providers.

Key changes:
- Migrate generateObject/streamObject to generateText/streamText + Output.object()
- Make convertToModelMessages async (now returns Promise)
- Rename ToolCallOptions to ToolExecutionOptions
- Update LanguageModelUsage type (inputTokenDetails/outputTokenDetails)
- Add specificationVersion: 'v3' to middleware
- Rename provider tool factories (createProviderDefinedToolFactory -> createProviderToolFactory)
- Handle finish reason 'unknown' -> 'other' in copilot SDK
- Update Anthropic top_p/temperature mutual exclusivity behavior
- Fix PromiseLike -> Promise.resolve() for result.text
- Fix asSchema().jsonSchema now being async
- Re-enable Claude reasoning variants via Kilo Gateway (effort-based)
})()

const toModelOutput = (output: unknown) => {
const toModelOutput = ({ output }: { output: unknown }) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Potential runtime error when output is null

typeof null === "object", so the later if (typeof output === "object") branch will treat null as an object and then access outputObject.text/attachments, which would throw. Consider guarding with output && typeof output === "object" (or output !== null) before the object branch.

}

const BUNDLED_PROVIDERS: Record<string, (options: any) => SDK> = {
const BUNDLED_PROVIDERS: Record<string, (options: any) => any> = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Avoid widening BUNDLED_PROVIDERS return type to any

Changing Record<string, (options: any) => SDK> to any weakens type safety and can hide provider factory incompatibilities introduced by the AI SDK v6 upgrade. If possible, keep a concrete return type (e.g. SDK or the specific provider factory return types) and add narrow casts at the few incompatibility points instead of globally opting out.

@kiloconnect
Copy link
Contributor

kiloconnect bot commented Feb 16, 2026

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 1
Issue Details (click to expand)

WARNING

File Line Issue
packages/opencode/src/session/message-v2.ts 469 Potential runtime error when output is null (treated as object)

SUGGESTION

File Line Issue
packages/opencode/src/provider/provider.ts 61 BUNDLED_PROVIDERS widened to any, weakening type safety
Other Observations (not in diff)

Issues found in unchanged code that cannot receive inline comments:

File Line Issue
Files Reviewed (7 files)
  • packages/opencode/src/agent/agent.ts - 0 issues
  • packages/opencode/src/provider/provider.ts - 1 issue
  • packages/opencode/src/provider/transform.ts - 0 issues
  • packages/opencode/src/session/llm.ts - 0 issues
  • packages/opencode/src/session/message-v2.ts - 1 issue
  • packages/opencode/src/session/prompt.ts - 0 issues
  • packages/opencode/src/session/compaction.ts - 0 issues

Fix these issues in Kilo Cloud

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.

2 participants