tweak: adjust logic for store=false for codex plans
This commit is contained in:
parent
87438fb38e
commit
2522ae6e41
4 changed files with 439 additions and 27 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 { Auth } from "@/auth"
|
||||
import { iife } from "@/util/iife"
|
||||
|
||||
type Modality = NonNullable<ModelsDev.Model["modalities"]>["input"][number]
|
||||
|
|
@ -453,64 +454,70 @@ export namespace ProviderTransform {
|
|||
return {}
|
||||
}
|
||||
|
||||
export function options(
|
||||
model: Provider.Model,
|
||||
sessionID: string,
|
||||
providerOptions?: Record<string, any>,
|
||||
): Record<string, any> {
|
||||
export function options(input: {
|
||||
model: Provider.Model
|
||||
sessionID: string
|
||||
providerOptions?: Record<string, any>
|
||||
auth: Auth.Info | undefined
|
||||
}): Record<string, any> {
|
||||
const result: Record<string, any> = {}
|
||||
|
||||
if (model.api.npm === "@openrouter/ai-sdk-provider") {
|
||||
// all codex plans MUST use store = false
|
||||
if (input.model.providerID === "openai" && input.auth?.type === "oauth") {
|
||||
result["store"] = false
|
||||
}
|
||||
|
||||
if (input.model.api.npm === "@openrouter/ai-sdk-provider") {
|
||||
result["usage"] = {
|
||||
include: true,
|
||||
}
|
||||
if (model.api.id.includes("gemini-3")) {
|
||||
if (input.model.api.id.includes("gemini-3")) {
|
||||
result["reasoning"] = { effort: "high" }
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
model.providerID === "baseten" ||
|
||||
(model.providerID === "opencode" && ["kimi-k2-thinking", "glm-4.6"].includes(model.api.id))
|
||||
input.model.providerID === "baseten" ||
|
||||
(input.model.providerID === "opencode" && ["kimi-k2-thinking", "glm-4.6"].includes(input.model.api.id))
|
||||
) {
|
||||
result["chat_template_args"] = { enable_thinking: true }
|
||||
}
|
||||
|
||||
if (["zai", "zhipuai"].includes(model.providerID) && model.api.npm === "@ai-sdk/openai-compatible") {
|
||||
if (["zai", "zhipuai"].includes(input.model.providerID) && input.model.api.npm === "@ai-sdk/openai-compatible") {
|
||||
result["thinking"] = {
|
||||
type: "enabled",
|
||||
clear_thinking: false,
|
||||
}
|
||||
}
|
||||
|
||||
if (model.providerID === "openai" || providerOptions?.setCacheKey) {
|
||||
result["promptCacheKey"] = sessionID
|
||||
if (input.model.providerID === "openai" || input.providerOptions?.setCacheKey) {
|
||||
result["promptCacheKey"] = input.sessionID
|
||||
}
|
||||
|
||||
if (model.api.npm === "@ai-sdk/google" || model.api.npm === "@ai-sdk/google-vertex") {
|
||||
if (input.model.api.npm === "@ai-sdk/google" || input.model.api.npm === "@ai-sdk/google-vertex") {
|
||||
result["thinkingConfig"] = {
|
||||
includeThoughts: true,
|
||||
}
|
||||
if (model.api.id.includes("gemini-3")) {
|
||||
if (input.model.api.id.includes("gemini-3")) {
|
||||
result["thinkingConfig"]["thinkingLevel"] = "high"
|
||||
}
|
||||
}
|
||||
|
||||
if (model.api.id.includes("gpt-5") && !model.api.id.includes("gpt-5-chat")) {
|
||||
if (model.providerID.includes("codex")) {
|
||||
if (input.model.api.id.includes("gpt-5") && !input.model.api.id.includes("gpt-5-chat")) {
|
||||
if (input.model.providerID.includes("codex")) {
|
||||
result["store"] = false
|
||||
}
|
||||
|
||||
if (!model.api.id.includes("codex") && !model.api.id.includes("gpt-5-pro")) {
|
||||
if (!input.model.api.id.includes("codex") && !input.model.api.id.includes("gpt-5-pro")) {
|
||||
result["reasoningEffort"] = "medium"
|
||||
}
|
||||
|
||||
if (model.api.id.endsWith("gpt-5.") && model.providerID !== "azure") {
|
||||
if (input.model.api.id.endsWith("gpt-5.") && input.model.providerID !== "azure") {
|
||||
result["textVerbosity"] = "low"
|
||||
}
|
||||
|
||||
if (model.providerID.startsWith("opencode")) {
|
||||
result["promptCacheKey"] = sessionID
|
||||
if (input.model.providerID.startsWith("opencode")) {
|
||||
result["promptCacheKey"] = input.sessionID
|
||||
result["include"] = ["reasoning.encrypted_content"]
|
||||
result["reasoningSummary"] = "auto"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,7 +95,12 @@ export namespace LLM {
|
|||
!input.small && input.model.variants && input.user.variant ? input.model.variants[input.user.variant] : {}
|
||||
const base = input.small
|
||||
? ProviderTransform.smallOptions(input.model)
|
||||
: ProviderTransform.options(input.model, input.sessionID, provider.options)
|
||||
: ProviderTransform.options({
|
||||
model: input.model,
|
||||
sessionID: input.sessionID,
|
||||
providerOptions: provider.options,
|
||||
auth,
|
||||
})
|
||||
const options: Record<string, any> = pipe(
|
||||
base,
|
||||
mergeDeep(input.model.options),
|
||||
|
|
@ -104,7 +109,6 @@ export namespace LLM {
|
|||
)
|
||||
if (isCodex) {
|
||||
options.instructions = SystemPrompt.instructions()
|
||||
options.store = false
|
||||
}
|
||||
|
||||
const params = await Plugin.trigger(
|
||||
|
|
|
|||
|
|
@ -39,22 +39,37 @@ describe("ProviderTransform.options - setCacheKey", () => {
|
|||
} as any
|
||||
|
||||
test("should set promptCacheKey when providerOptions.setCacheKey is true", () => {
|
||||
const result = ProviderTransform.options(mockModel, sessionID, { setCacheKey: true })
|
||||
const result = ProviderTransform.options({
|
||||
model: mockModel,
|
||||
sessionID,
|
||||
providerOptions: { setCacheKey: true },
|
||||
auth: undefined,
|
||||
})
|
||||
expect(result.promptCacheKey).toBe(sessionID)
|
||||
})
|
||||
|
||||
test("should not set promptCacheKey when providerOptions.setCacheKey is false", () => {
|
||||
const result = ProviderTransform.options(mockModel, sessionID, { setCacheKey: false })
|
||||
const result = ProviderTransform.options({
|
||||
model: mockModel,
|
||||
sessionID,
|
||||
providerOptions: { setCacheKey: false },
|
||||
auth: undefined,
|
||||
})
|
||||
expect(result.promptCacheKey).toBeUndefined()
|
||||
})
|
||||
|
||||
test("should not set promptCacheKey when providerOptions is undefined", () => {
|
||||
const result = ProviderTransform.options(mockModel, sessionID, undefined)
|
||||
const result = ProviderTransform.options({
|
||||
model: mockModel,
|
||||
sessionID,
|
||||
providerOptions: undefined,
|
||||
auth: undefined,
|
||||
})
|
||||
expect(result.promptCacheKey).toBeUndefined()
|
||||
})
|
||||
|
||||
test("should not set promptCacheKey when providerOptions does not have setCacheKey", () => {
|
||||
const result = ProviderTransform.options(mockModel, sessionID, {})
|
||||
const result = ProviderTransform.options({ model: mockModel, sessionID, providerOptions: {}, auth: undefined })
|
||||
expect(result.promptCacheKey).toBeUndefined()
|
||||
})
|
||||
|
||||
|
|
@ -68,9 +83,47 @@ describe("ProviderTransform.options - setCacheKey", () => {
|
|||
npm: "@ai-sdk/openai",
|
||||
},
|
||||
}
|
||||
const result = ProviderTransform.options(openaiModel, sessionID, {})
|
||||
const result = ProviderTransform.options({ model: openaiModel, sessionID, providerOptions: {}, auth: undefined })
|
||||
expect(result.promptCacheKey).toBe(sessionID)
|
||||
})
|
||||
|
||||
test("should set store=false for openai provider with oauth auth", () => {
|
||||
const openaiModel = {
|
||||
...mockModel,
|
||||
providerID: "openai",
|
||||
api: {
|
||||
id: "gpt-4",
|
||||
url: "https://api.openai.com",
|
||||
npm: "@ai-sdk/openai",
|
||||
},
|
||||
}
|
||||
const result = ProviderTransform.options({
|
||||
model: openaiModel,
|
||||
sessionID,
|
||||
providerOptions: {},
|
||||
auth: { type: "oauth", refresh: "r", access: "a", expires: 0 },
|
||||
})
|
||||
expect(result.store).toBe(false)
|
||||
})
|
||||
|
||||
test("should not set store=false for openai provider with api auth", () => {
|
||||
const openaiModel = {
|
||||
...mockModel,
|
||||
providerID: "openai",
|
||||
api: {
|
||||
id: "gpt-4",
|
||||
url: "https://api.openai.com",
|
||||
npm: "@ai-sdk/openai",
|
||||
},
|
||||
}
|
||||
const result = ProviderTransform.options({
|
||||
model: openaiModel,
|
||||
sessionID,
|
||||
providerOptions: {},
|
||||
auth: { type: "api", key: "sk-xxx" },
|
||||
})
|
||||
expect(result.store).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe("ProviderTransform.maxOutputTokens", () => {
|
||||
|
|
|
|||
348
session.json
Normal file
348
session.json
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue