mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
Merge 86f9c3acce into 83397ebde2
This commit is contained in:
commit
45e663887c
4 changed files with 50 additions and 0 deletions
|
|
@ -3,6 +3,7 @@ import { unique } from "remeda"
|
|||
import type { JSONSchema } from "zod/v4/core"
|
||||
import type { Provider } from "./provider"
|
||||
import type { ModelsDev } from "./models"
|
||||
import type { MessageV2 } from "@/session/message-v2"
|
||||
|
||||
type Modality = NonNullable<ModelsDev.Model["modalities"]>["input"][number]
|
||||
|
||||
|
|
@ -241,6 +242,38 @@ export namespace ProviderTransform {
|
|||
return undefined
|
||||
}
|
||||
|
||||
export function thinking(model: Provider.Model, thinking: MessageV2.Thinking) {
|
||||
if (!model.capabilities.reasoning) return undefined
|
||||
|
||||
switch (model.api.npm) {
|
||||
case "@openrouter/ai-sdk-provider":
|
||||
return {
|
||||
reasoning: { effort: thinking.effort },
|
||||
}
|
||||
case "@ai-sdk/openai-compatible":
|
||||
const result: Record<string, any> = {
|
||||
reasoningEffort: thinking.effort,
|
||||
}
|
||||
|
||||
if (model.providerID === "baseten") {
|
||||
result["chat_template_args"] = { enable_thinking: true }
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
case "@ai-sdk/openai":
|
||||
return {
|
||||
reasoningEffort: thinking.effort,
|
||||
reasoningSummary: "auto",
|
||||
include: ["reasoning.encrypted_content"],
|
||||
}
|
||||
|
||||
case "@ai-sdk/anthropic":
|
||||
// TODO: map to thinking budgets
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
export function options(
|
||||
model: Provider.Model,
|
||||
sessionID: string,
|
||||
|
|
|
|||
|
|
@ -287,6 +287,9 @@ export namespace MessageV2 {
|
|||
sessionID: z.string(),
|
||||
})
|
||||
|
||||
export const Thinking = z.object({ effort: z.enum(["low", "medium", "high"]) })
|
||||
export type Thinking = z.infer<typeof Thinking>
|
||||
|
||||
export const User = Base.extend({
|
||||
role: z.literal("user"),
|
||||
time: z.object({
|
||||
|
|
@ -306,6 +309,7 @@ export namespace MessageV2 {
|
|||
}),
|
||||
system: z.string().optional(),
|
||||
tools: z.record(z.string(), z.boolean()).optional(),
|
||||
thinking: Thinking.optional(),
|
||||
}).meta({
|
||||
ref: "UserMessage",
|
||||
})
|
||||
|
|
|
|||
|
|
@ -90,6 +90,9 @@ export type UserMessage = {
|
|||
tools?: {
|
||||
[key: string]: boolean
|
||||
}
|
||||
thinking?: {
|
||||
effort: "low" | "medium" | "high"
|
||||
}
|
||||
}
|
||||
|
||||
export type ProviderAuthError = {
|
||||
|
|
|
|||
|
|
@ -5228,6 +5228,16 @@
|
|||
"additionalProperties": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"thinking": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"effort": {
|
||||
"type": "string",
|
||||
"enum": ["low", "medium", "high"]
|
||||
}
|
||||
},
|
||||
"required": ["effort"]
|
||||
}
|
||||
},
|
||||
"required": ["id", "sessionID", "role", "time", "agent", "model"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue