Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 96 additions & 84 deletions bun.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@tailwindcss/vite": "4.1.11",
"diff": "8.0.2",
"dompurify": "3.3.1",
"ai": "5.0.124",
"ai": "6.0.81",
"hono": "4.10.7",
"hono-openapi": "1.1.2",
"fuzzysort": "3.1.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/console/function/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"@typescript/native-preview": "catalog:"
},
"dependencies": {
"@ai-sdk/anthropic": "2.0.0",
"@ai-sdk/openai": "2.0.2",
"@ai-sdk/openai-compatible": "1.0.1",
"@ai-sdk/anthropic": "3.0.42",
"@ai-sdk/openai": "3.0.27",
"@ai-sdk/openai-compatible": "2.0.29",
"@hono/zod-validator": "catalog:",
"@opencode-ai/console-core": "workspace:*",
"@opencode-ai/console-resource": "workspace:*",
Expand Down
38 changes: 19 additions & 19 deletions packages/opencode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,25 @@
"@actions/core": "1.11.1",
"@actions/github": "6.0.1",
"@agentclientprotocol/sdk": "0.14.1",
"@ai-sdk/amazon-bedrock": "3.0.74",
"@ai-sdk/anthropic": "2.0.58",
"@ai-sdk/azure": "2.0.91",
"@ai-sdk/cerebras": "1.0.36",
"@ai-sdk/cohere": "2.0.22",
"@ai-sdk/deepinfra": "1.0.33",
"@ai-sdk/gateway": "2.0.30",
"@ai-sdk/google": "2.0.52",
"@ai-sdk/google-vertex": "3.0.98",
"@ai-sdk/groq": "2.0.34",
"@ai-sdk/mistral": "2.0.27",
"@ai-sdk/openai": "2.0.89",
"@ai-sdk/openai-compatible": "1.0.32",
"@ai-sdk/perplexity": "2.0.23",
"@ai-sdk/provider": "2.0.1",
"@ai-sdk/provider-utils": "3.0.20",
"@ai-sdk/togetherai": "1.0.34",
"@ai-sdk/vercel": "1.0.33",
"@ai-sdk/xai": "2.0.51",
"@ai-sdk/amazon-bedrock": "4.0.56",
"@ai-sdk/anthropic": "3.0.42",
"@ai-sdk/azure": "3.0.28",
"@ai-sdk/cerebras": "2.0.32",
"@ai-sdk/cohere": "3.0.20",
"@ai-sdk/deepinfra": "2.0.33",
"@ai-sdk/gateway": "3.0.41",
"@ai-sdk/google": "3.0.26",
"@ai-sdk/google-vertex": "4.0.54",
"@ai-sdk/groq": "3.0.23",
"@ai-sdk/mistral": "3.0.19",
"@ai-sdk/openai": "3.0.27",
"@ai-sdk/openai-compatible": "2.0.29",
"@ai-sdk/perplexity": "3.0.18",
"@ai-sdk/provider": "3.0.8",
"@ai-sdk/provider-utils": "4.0.14",
"@ai-sdk/togetherai": "2.0.32",
"@ai-sdk/vercel": "2.0.31",
"@ai-sdk/xai": "3.0.54",
"@clack/prompts": "1.0.0-alpha.1",
"@gitlab/gitlab-ai-provider": "3.5.0",
"@gitlab/opencode-gitlab-auth": "1.3.2",
Expand Down
11 changes: 6 additions & 5 deletions packages/opencode/src/provider/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import { createVertex } from "@ai-sdk/google-vertex"
import { createVertexAnthropic } from "@ai-sdk/google-vertex/anthropic"
import { createOpenAI } from "@ai-sdk/openai"
import { createOpenAICompatible } from "@ai-sdk/openai-compatible"
import { createOpenRouter, type LanguageModelV2 } from "@openrouter/ai-sdk-provider"
import { createOpenRouter } from "@openrouter/ai-sdk-provider"
import type { LanguageModel } from "ai"
import { createOpenaiCompatible as createGitHubCopilotOpenAICompatible } from "./sdk/copilot"
import { createXai } from "@ai-sdk/xai"
import { createMistral } from "@ai-sdk/mistral"
Expand Down Expand Up @@ -55,7 +56,7 @@ export namespace Provider {
return isGpt5OrLater(modelID) && !modelID.startsWith("gpt-5-mini")
}

const BUNDLED_PROVIDERS: Record<string, (options: any) => SDK> = {
const BUNDLED_PROVIDERS: Record<string, (options: any) => any> = {
"@ai-sdk/amazon-bedrock": createAmazonBedrock,
"@ai-sdk/anthropic": createAnthropic,
"@ai-sdk/azure": createAzure,
Expand Down Expand Up @@ -518,7 +519,7 @@ export namespace Provider {
autoload: true,
async getModel(_sdk: any, modelID: string, _options?: Record<string, any>) {
// Model IDs use Unified API format: provider/model (e.g., "anthropic/claude-sonnet-4-5")
return aigateway(unified(modelID))
return aigateway(unified(modelID) as any)
},
options: {},
}
Expand Down Expand Up @@ -715,7 +716,7 @@ export namespace Provider {
}

const providers: { [providerID: string]: Info } = {}
const languages = new Map<string, LanguageModelV2>()
const languages = new Map<string, LanguageModel>()
const modelLoaders: {
[providerID: string]: CustomModelLoader
} = {}
Expand Down Expand Up @@ -1107,7 +1108,7 @@ export namespace Provider {
return info
}

export async function getLanguage(model: Model): Promise<LanguageModelV2> {
export async function getLanguage(model: Model): Promise<LanguageModel> {
const s = await state()
const key = `${model.providerID}/${model.id}`
if (s.models.has(key)) return s.models.get(key)!
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createProviderDefinedToolFactoryWithOutputSchema } from "@ai-sdk/provider-utils"
import { createProviderToolFactoryWithOutputSchema } from "@ai-sdk/provider-utils"
import { z } from "zod/v4"

export const codeInterpreterInputSchema = z.object({
Expand Down Expand Up @@ -37,7 +37,7 @@ type CodeInterpreterArgs = {
container?: string | { fileIds?: string[] }
}

export const codeInterpreterToolFactory = createProviderDefinedToolFactoryWithOutputSchema<
export const codeInterpreterToolFactory = createProviderToolFactoryWithOutputSchema<
{
/**
* The code to run, or null if not available.
Expand Down Expand Up @@ -76,7 +76,6 @@ export const codeInterpreterToolFactory = createProviderDefinedToolFactoryWithOu
CodeInterpreterArgs
>({
id: "openai.code_interpreter",
name: "code_interpreter",
inputSchema: codeInterpreterInputSchema,
outputSchema: codeInterpreterOutputSchema,
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createProviderDefinedToolFactoryWithOutputSchema } from "@ai-sdk/provider-utils"
import { createProviderToolFactoryWithOutputSchema } from "@ai-sdk/provider-utils"
import type {
OpenAIResponsesFileSearchToolComparisonFilter,
OpenAIResponsesFileSearchToolCompoundFilter,
Expand Down Expand Up @@ -43,7 +43,7 @@ export const fileSearchOutputSchema = z.object({
.nullable(),
})

export const fileSearch = createProviderDefinedToolFactoryWithOutputSchema<
export const fileSearch = createProviderToolFactoryWithOutputSchema<
{},
{
/**
Expand Down Expand Up @@ -122,7 +122,6 @@ export const fileSearch = createProviderDefinedToolFactoryWithOutputSchema<
}
>({
id: "openai.file_search",
name: "file_search",
inputSchema: z.object({}),
outputSchema: fileSearchOutputSchema,
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createProviderDefinedToolFactoryWithOutputSchema } from "@ai-sdk/provider-utils"
import { createProviderToolFactoryWithOutputSchema } from "@ai-sdk/provider-utils"
import { z } from "zod/v4"

export const imageGenerationArgsSchema = z
Expand Down Expand Up @@ -92,7 +92,7 @@ type ImageGenerationArgs = {
size?: "auto" | "1024x1024" | "1024x1536" | "1536x1024"
}

const imageGenerationToolFactory = createProviderDefinedToolFactoryWithOutputSchema<
const imageGenerationToolFactory = createProviderToolFactoryWithOutputSchema<
{},
{
/**
Expand All @@ -103,7 +103,6 @@ const imageGenerationToolFactory = createProviderDefinedToolFactoryWithOutputSch
ImageGenerationArgs
>({
id: "openai.image_generation",
name: "image_generation",
inputSchema: z.object({}),
outputSchema: imageGenerationOutputSchema,
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createProviderDefinedToolFactoryWithOutputSchema } from "@ai-sdk/provider-utils"
import { createProviderToolFactoryWithOutputSchema } from "@ai-sdk/provider-utils"
import { z } from "zod/v4"

export const localShellInputSchema = z.object({
Expand All @@ -16,7 +16,7 @@ export const localShellOutputSchema = z.object({
output: z.string(),
})

export const localShell = createProviderDefinedToolFactoryWithOutputSchema<
export const localShell = createProviderToolFactoryWithOutputSchema<
{
/**
* Execute a shell command on the server.
Expand Down Expand Up @@ -59,7 +59,6 @@ export const localShell = createProviderDefinedToolFactoryWithOutputSchema<
{}
>({
id: "openai.local_shell",
name: "local_shell",
inputSchema: localShellInputSchema,
outputSchema: localShellOutputSchema,
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createProviderDefinedToolFactory } from "@ai-sdk/provider-utils"
import { createProviderToolFactory } from "@ai-sdk/provider-utils"
import { z } from "zod/v4"

// Args validation schema
Expand Down Expand Up @@ -40,7 +40,7 @@ export const webSearchPreviewArgsSchema = z.object({
.optional(),
})

export const webSearchPreview = createProviderDefinedToolFactory<
export const webSearchPreview = createProviderToolFactory<
{
// Web search doesn't take input parameters - it's controlled by the prompt
},
Expand Down Expand Up @@ -81,7 +81,6 @@ export const webSearchPreview = createProviderDefinedToolFactory<
}
>({
id: "openai.web_search_preview",
name: "web_search_preview",
inputSchema: z.object({
action: z
.discriminatedUnion("type", [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createProviderDefinedToolFactory } from "@ai-sdk/provider-utils"
import { createProviderToolFactory } from "@ai-sdk/provider-utils"
import { z } from "zod/v4"

export const webSearchArgsSchema = z.object({
Expand All @@ -21,7 +21,7 @@ export const webSearchArgsSchema = z.object({
.optional(),
})

export const webSearchToolFactory = createProviderDefinedToolFactory<
export const webSearchToolFactory = createProviderToolFactory<
{
// Web search doesn't take input parameters - it's controlled by the prompt
},
Expand Down Expand Up @@ -74,7 +74,6 @@ export const webSearchToolFactory = createProviderDefinedToolFactory<
}
>({
id: "openai.web_search",
name: "web_search",
inputSchema: z.object({
action: z
.discriminatedUnion("type", [
Expand Down
30 changes: 25 additions & 5 deletions packages/opencode/src/provider/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export namespace ProviderTransform {
}
}
return part
})
}) as typeof msg.content
}
return msg
})
Expand Down Expand Up @@ -112,7 +112,7 @@ export namespace ProviderTransform {
}
}
return part
})
}) as typeof msg.content
}

result.push(msg)
Expand Down Expand Up @@ -199,8 +199,8 @@ export namespace ProviderTransform {

if (shouldUseContentOptions) {
const lastContent = msg.content[msg.content.length - 1]
if (lastContent && typeof lastContent === "object") {
lastContent.providerOptions = mergeDeep(lastContent.providerOptions ?? {}, providerOptions)
if (lastContent && typeof lastContent === "object" && "providerOptions" in lastContent) {
;(lastContent as any).providerOptions = mergeDeep((lastContent as any).providerOptions ?? {}, providerOptions)
continue
}
}
Expand Down Expand Up @@ -280,7 +280,7 @@ export namespace ProviderTransform {
return {
...msg,
providerOptions: remap(msg.providerOptions),
content: msg.content.map((part) => ({ ...part, providerOptions: remap(part.providerOptions) })),
content: msg.content.map((part) => ({ ...part, providerOptions: remap((part as any).providerOptions) })),
} as typeof msg
})
}
Expand Down Expand Up @@ -456,6 +456,26 @@ export namespace ProviderTransform {
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/anthropic
case "@ai-sdk/google-vertex/anthropic":
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/google-vertex#anthropic-provider

// Opus 4.6+ supports adaptive thinking, effort levels, and fast mode
if (id.includes("opus-4-6") || id.includes("opus-4.6")) {
return {
high: {
thinking: { type: "adaptive" },
effort: "high",
},
max: {
thinking: { type: "adaptive" },
effort: "max",
},
fast: {
thinking: { type: "adaptive" },
effort: "high",
speed: "fast",
},
}
}

return {
high: {
thinking: {
Expand Down
2 changes: 1 addition & 1 deletion packages/opencode/src/session/compaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ When constructing the summary, try to stick to this template:
tools: {},
system: [],
messages: [
...MessageV2.toModelMessages(input.messages, model),
...(await MessageV2.toModelMessages(input.messages, model)),
{
role: "user",
content: [
Expand Down
5 changes: 3 additions & 2 deletions packages/opencode/src/session/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export namespace LLM {
retries?: number
}

export type StreamOutput = StreamTextResult<ToolSet, unknown>
export type StreamOutput = StreamTextResult<ToolSet, any>

export async function stream(input: StreamInput) {
const l = log
Expand Down Expand Up @@ -234,9 +234,10 @@ export namespace LLM {
...input.messages,
],
model: wrapLanguageModel({
model: language,
model: language as any,
middleware: [
{
specificationVersion: "v3" as const,
async transformParams(args) {
if (args.type === "stream") {
// @ts-expect-error
Expand Down
2 changes: 1 addition & 1 deletion packages/opencode/src/session/message-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ export namespace MessageV2 {
})
export type WithParts = z.infer<typeof WithParts>

export function toModelMessages(input: WithParts[], model: Provider.Model): ModelMessage[] {
export async function toModelMessages(input: WithParts[], model: Provider.Model): Promise<ModelMessage[]> {
const result: UIMessage[] = []
const toolNames = new Set<string>()
// Track media from tool results that need to be injected as user messages
Expand Down
12 changes: 6 additions & 6 deletions packages/opencode/src/session/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ export namespace SessionPrompt {
sessionID,
system: [...(await SystemPrompt.environment(model)), ...(await InstructionPrompt.system())],
messages: [
...MessageV2.toModelMessages(sessionMessages, model),
...(await MessageV2.toModelMessages(sessionMessages, model)),
...(isLastStep
? [
{
Expand Down Expand Up @@ -757,7 +757,7 @@ export namespace SessionPrompt {
const execute = item.execute
if (!execute) continue

const transformed = ProviderTransform.schema(input.model, asSchema(item.inputSchema).jsonSchema)
const transformed = ProviderTransform.schema(input.model, await Promise.resolve(asSchema(item.inputSchema).jsonSchema))
item.inputSchema = jsonSchema(transformed)
// Wrap execute to add plugin hooks and format output
item.execute = async (args, opts) => {
Expand Down Expand Up @@ -1849,19 +1849,19 @@ NOTE: At any point in time through this workflow you should feel free to ask the
},
...(hasOnlySubtaskParts
? [{ role: "user" as const, content: subtaskParts.map((p) => p.prompt).join("\n") }]
: MessageV2.toModelMessages(contextMessages, model)),
: await MessageV2.toModelMessages(contextMessages, model)),
],
})
const text = await result.text.catch((err) => log.error("failed to generate title", { error: err }))
const text = await Promise.resolve(result.text).catch((err: unknown) => log.error("failed to generate title", { error: err }))
if (text)
return Session.update(
input.session.id,
(draft) => {
const cleaned = text
.replace(/<think>[\s\S]*?<\/think>\s*/g, "")
.split("\n")
.map((line) => line.trim())
.find((line) => line.length > 0)
.map((line: string) => line.trim())
.find((line: string) => line.length > 0)
if (!cleaned) return

const title = cleaned.length > 100 ? cleaned.substring(0, 97) + "..." : cleaned
Expand Down
Loading
Loading