This commit is contained in:
Aiden Cline 2025-12-23 15:42:23 +08:00 committed by GitHub
commit 45e663887c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 50 additions and 0 deletions

View file

@ -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,

View file

@ -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",
})

View file

@ -90,6 +90,9 @@ export type UserMessage = {
tools?: {
[key: string]: boolean
}
thinking?: {
effort: "low" | "medium" | "high"
}
}
export type ProviderAuthError = {

View file

@ -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"]