Skip to content
Open
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
1,051 changes: 0 additions & 1,051 deletions packages/opencode/src/provider/transform.ts

This file was deleted.

60 changes: 60 additions & 0 deletions packages/opencode/src/provider/transform/family/anthropic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import type { ModelMessage } from "ai"
import type { Transform } from "../types"
import { ADAPTIVE_EFFORTS, applyCaching, isAnthropicAdaptive, normalizeAnthropic, scrubClaude } from "../shared"

export const normalize: NonNullable<Transform["normalize"]> = (msgs, _model) => {
void _model
return scrubClaude(normalizeAnthropic(msgs))
}

export const cache: NonNullable<Transform["cache"]> = (msgs, model) => {
return applyCaching(msgs, model)
}

export const variants: Transform["variants"] = (model) => {
if (!model.capabilities.reasoning) return {}
if (isAnthropicAdaptive(model)) {
return Object.fromEntries(
ADAPTIVE_EFFORTS.map((effort) => [
effort,
{
thinking: {
type: "adaptive",
},
effort,
},
]),
)
}

return {
high: {
thinking: {
type: "enabled",
budgetTokens: Math.min(16_000, Math.floor(model.limit.output / 2 - 1)),
},
},
max: {
thinking: {
type: "enabled",
budgetTokens: Math.min(31_999, model.limit.output - 1),
},
},
}
}

export const options: Transform["options"] = (input) => {
const result: Record<string, any> = {}
const modelId = input.model.api.id.toLowerCase()
if (modelId.includes("k2p5") || modelId.includes("kimi-k2.5") || modelId.includes("kimi-k2p5")) {
result.thinking = {
type: "enabled",
budgetTokens: Math.min(16_000, Math.floor(input.model.limit.output / 2 - 1)),
}
}
return result
}

export const small: Transform["small"] = () => {
return {}
}
37 changes: 37 additions & 0 deletions packages/opencode/src/provider/transform/family/azure.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { Transform } from "../types"

export const options: Transform["options"] = (input) => {
const result: Record<string, any> = {}

if (input.model.api.id.includes("gpt-5") && !input.model.api.id.includes("gpt-5-chat")) {
if (!input.model.api.id.includes("gpt-5-pro")) {
result.reasoningEffort = "medium"
}
}

return result
}

export const variants: Transform["variants"] = (model) => {
if (!model.capabilities.reasoning) return {}
const id = model.id.toLowerCase()
if (id === "o1-mini") return {}
const efforts = ["low", "medium", "high"]
if (id.includes("gpt-5-") || id === "gpt-5") {
efforts.unshift("minimal")
}
return Object.fromEntries(
efforts.map((effort) => [
effort,
{
reasoningEffort: effort,
reasoningSummary: "auto",
include: ["reasoning.encrypted_content"],
},
]),
)
}

export const small: Transform["small"] = () => {
return {}
}
63 changes: 63 additions & 0 deletions packages/opencode/src/provider/transform/family/bedrock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import type { Transform } from "../types"
import { ADAPTIVE_EFFORTS, applyCaching, isAnthropicAdaptive, normalizeAnthropic } from "../shared"

export const normalize: NonNullable<Transform["normalize"]> = (msgs, _model) => {
void _model
return normalizeAnthropic(msgs)
}

export const cache: NonNullable<Transform["cache"]> = (msgs, model) => {
return applyCaching(msgs, model)
}

export const variants: Transform["variants"] = (model) => {
if (!model.capabilities.reasoning) return {}
if (isAnthropicAdaptive(model)) {
return Object.fromEntries(
ADAPTIVE_EFFORTS.map((effort) => [
effort,
{
reasoningConfig: {
type: "adaptive",
maxReasoningEffort: effort,
},
},
]),
)
}
if (model.api.id.includes("anthropic")) {
return {
high: {
reasoningConfig: {
type: "enabled",
budgetTokens: 16000,
},
},
max: {
reasoningConfig: {
type: "enabled",
budgetTokens: 31999,
},
},
}
}
return Object.fromEntries(
["low", "medium", "high"].map((effort) => [
effort,
{
reasoningConfig: {
type: "enabled",
maxReasoningEffort: effort,
},
},
]),
)
}

export const options: Transform["options"] = () => {
return {}
}

export const small: Transform["small"] = () => {
return {}
}
43 changes: 43 additions & 0 deletions packages/opencode/src/provider/transform/family/copilot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { iife } from "@/util/iife"
import { WIDELY_SUPPORTED_EFFORTS } from "../shared"
import type { Transform } from "../types"

export const options: Transform["options"] = () => {
return { store: false }
}

export const variants: Transform["variants"] = (model) => {
if (!model.capabilities.reasoning) return {}
const id = model.id.toLowerCase()
if (id.includes("gemini")) return {}
if (id.includes("claude")) {
return Object.fromEntries(WIDELY_SUPPORTED_EFFORTS.map((effort) => [effort, { reasoningEffort: effort }]))
}
const efforts = iife(() => {
if (id.includes("5.1-codex-max") || id.includes("5.2") || id.includes("5.3"))
return [...WIDELY_SUPPORTED_EFFORTS, "xhigh"]
const arr = [...WIDELY_SUPPORTED_EFFORTS]
if (id.includes("gpt-5") && model.release_date >= "2025-12-04") arr.push("xhigh")
return arr
})
return Object.fromEntries(
efforts.map((effort) => [
effort,
{
reasoningEffort: effort,
reasoningSummary: "auto",
include: ["reasoning.encrypted_content"],
},
]),
)
}

export const small: Transform["small"] = (model) => {
if (model.api.id.includes("gpt-5")) {
if (model.api.id.includes("5.")) {
return { store: false, reasoningEffort: "low" }
}
return { store: false, reasoningEffort: "minimal" }
}
return { store: false }
}
18 changes: 18 additions & 0 deletions packages/opencode/src/provider/transform/family/custom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { Transform } from "../types"

export const options: Transform["options"] = (input) => {
if (input.model.providerID === "baseten") {
return {
chat_template_args: { enable_thinking: true },
}
}
return {}
}

export const variants: Transform["variants"] = () => {
return {}
}

export const small: Transform["small"] = () => {
return {}
}
76 changes: 76 additions & 0 deletions packages/opencode/src/provider/transform/family/gateway.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { ADAPTIVE_EFFORTS, isAnthropicAdaptive, OPENAI_EFFORTS } from "../shared"
import type { Transform } from "../types"

export const options: Transform["options"] = () => {
return {
gateway: {
caching: "auto",
},
}
}

export const variants: Transform["variants"] = (model) => {
if (!model.capabilities.reasoning) return {}
const id = model.id.toLowerCase()
if (model.id.includes("anthropic")) {
if (isAnthropicAdaptive(model)) {
return Object.fromEntries(
ADAPTIVE_EFFORTS.map((effort) => [
effort,
{
thinking: {
type: "adaptive",
},
effort,
},
]),
)
}
return {
high: {
thinking: {
type: "enabled",
budgetTokens: 16000,
},
},
max: {
thinking: {
type: "enabled",
budgetTokens: 31999,
},
},
}
}
if (model.id.includes("google")) {
if (id.includes("2.5")) {
return {
high: {
thinkingConfig: {
includeThoughts: true,
thinkingBudget: 16000,
},
},
max: {
thinkingConfig: {
includeThoughts: true,
thinkingBudget: 24576,
},
},
}
}
return Object.fromEntries(
["low", "high"].map((effort) => [
effort,
{
includeThoughts: true,
thinkingLevel: effort,
},
]),
)
}
return Object.fromEntries(OPENAI_EFFORTS.map((effort) => [effort, { reasoningEffort: effort }]))
}

export const small: Transform["small"] = () => {
return {}
}
15 changes: 15 additions & 0 deletions packages/opencode/src/provider/transform/family/generic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { WIDELY_SUPPORTED_EFFORTS } from "../shared"
import type { Transform } from "../types"

export const options: Transform["options"] = () => {
return {}
}

export const variants: Transform["variants"] = (model) => {
if (!model.capabilities.reasoning) return {}
return Object.fromEntries(WIDELY_SUPPORTED_EFFORTS.map((effort) => [effort, { reasoningEffort: effort }]))
}

export const small: Transform["small"] = () => {
return {}
}
60 changes: 60 additions & 0 deletions packages/opencode/src/provider/transform/family/google.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import type { Transform } from "../types"

export const options: Transform["options"] = (input) => {
const result: Record<string, any> = {}
if (input.model.capabilities.reasoning) {
result.thinkingConfig = {
includeThoughts: true,
}
if (input.model.api.id.includes("gemini-3")) {
result.thinkingConfig.thinkingLevel = "high"
}
}
return result
}

export const variants: Transform["variants"] = (model) => {
if (!model.capabilities.reasoning) return {}
const id = model.id.toLowerCase()
if (id.includes("2.5")) {
return {
high: {
thinkingConfig: {
includeThoughts: true,
thinkingBudget: 16000,
},
},
max: {
thinkingConfig: {
includeThoughts: true,
thinkingBudget: 24576,
},
},
}
}
let levels = ["low", "high"]
if (id.includes("3.1")) {
levels = ["low", "medium", "high"]
}
return Object.fromEntries(
levels.map((effort) => [
effort,
{
thinkingConfig: {
includeThoughts: true,
thinkingLevel: effort,
},
},
]),
)
}

export const small: Transform["small"] = (model) => {
if (model.providerID === "google") {
if (model.api.id.includes("gemini-3")) {
return { thinkingConfig: { thinkingLevel: "minimal" } }
}
return { thinkingConfig: { thinkingBudget: 0 } }
}
return {}
}
17 changes: 17 additions & 0 deletions packages/opencode/src/provider/transform/family/groq.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { WIDELY_SUPPORTED_EFFORTS } from "../shared"
import type { Transform } from "../types"

export const options: Transform["options"] = () => {
return {}
}

export const variants: Transform["variants"] = (model) => {
if (!model.capabilities.reasoning) return {}
return Object.fromEntries(
["none", ...WIDELY_SUPPORTED_EFFORTS].map((effort) => [effort, { reasoningEffort: effort }]),
)
}

export const small: Transform["small"] = () => {
return {}
}
Loading
Loading