fix(ai): enforce GPT-6.1 Sol native API contract

This commit is contained in:
nexxeln authored and opencode-agent[bot] committed 2026-09-30 08:37:35 +00:00
1 parent ffa4c4c730
commit 9cb42e9725
5 files changed
+155 -1

No files matched your search

+10
View File
@@ -808,6 +808,16 @@ export const fromRequest = Effect.fn("OpenAIChat.fromRequest")(function* (
) {
// `fromRequest` returns the provider body only. Endpoint, auth, framing,
// validation, and HTTP execution are composed by `Route.make`.
const nativeSol = OpenAIOptions.isNativeGpt61Sol(request, ADAPTER)
if (nativeSol && (request.tools.length > 0 || hasToolHistory(request.messages)))
return yield* ProviderShared.invalidRequest("GPT-6.1 Sol tool calling requires the OpenAI Responses API")
if (nativeSol) {
const effort = OpenAIOptions.resolve(request).reasoningEffort
if (effort === "none" || effort === "minimal")
return yield* ProviderShared.invalidRequest(
"GPT-6.1 Sol reasoning effort must be low, medium, high, xhigh, or max",
)
}
const reasoningField = request.model.compatibility?.reasoningField
if (reasoningField && RESERVED_REASONING_FIELDS.has(reasoningField))
return yield* ProviderShared.invalidRequest(
+12 -1
View File
@@ -6,9 +6,10 @@ import { Endpoint } from "../route/endpoint.js"
import { Protocol } from "../route/protocol.js"
import { HttpTransport } from "../route/transport/index.js"
import { LLMRequest, type ToolDefinition, type ToolEntry } from "../schema/index.js"
import { resolveEffortUpdates } from "../effort-updates.js"
import { effortUpdate, resolveEffortUpdates } from "../effort-updates.js"
import { OpenResponses } from "./open-responses.js"
import { OpenResponsesOptions } from "./utils/open-responses-options.js"
import { OpenAIOptions } from "./utils/openai-options.js"
import { JsonObject, optionalArray, optionalNull, ProviderShared } from "./shared.js"
import { ResponsesHostedTools } from "./utils/responses-hosted-tools.js"
import { OpenResponsesChannel } from "./open-responses-channel.js"
@@ -209,6 +210,16 @@ const fromRequest = Effect.fn("OpenAIResponses.fromRequest")(function* (request:
)(request.providerOptions?.contextManagement)
const options = OpenResponsesOptions.resolve(request)
const updates = resolveEffortUpdates(request, options.reasoningEffort)
if (
OpenAIOptions.isNativeGpt61Sol(request, ADAPTER) &&
(updates.effort === "none" ||
updates.effort === "minimal" ||
updates.request.messages.some((message) => {
const effort = effortUpdate(message)?.effort
return effort === "none" || effort === "minimal"
}))
)
return yield* ProviderShared.invalidRequest("GPT-6.1 Sol reasoning effort must be low, medium, high, xhigh, or max")
return yield* decodeBody({
...(yield* OpenResponses.lowerConversation(updates.request, adapter)),
...OpenResponses.lowerGeneration(request, { ...options, reasoningEffort: updates.effort }),
@@ -1,4 +1,5 @@
import { OpenResponsesOptions } from "./open-responses-options.js"
import type { LLMRequest } from "../../schema/index.js"
export const OpenAIReasoningEfforts = OpenResponsesOptions.ReasoningEfforts
export type OpenAIReasoningEffort = OpenResponsesOptions.ReasoningEffort
@@ -21,4 +22,7 @@ export const isReasoningEffort = (effort: unknown): effort is OpenAIReasoningEff
export const resolve = OpenResponsesOptions.resolve
export const isNativeGpt61Sol = (request: LLMRequest, route: "openai-chat" | "openai-responses") =>
request.model.provider === "openai" && request.model.route.id === route && request.model.id === "gpt-6.1-sol"
export * as OpenAIOptions from "./openai-options.js"
@@ -472,6 +472,87 @@ describe("OpenAI Chat route", () => {
}),
)
it.effect("rejects GPT-6.1 Sol tool calling on native OpenAI Chat", () =>
Effect.gen(function* () {
const error = yield* compileRequest(
LLM.request({
model: OpenAI.configure({ apiKey: "test" }).chat("gpt-6.1-sol"),
prompt: "What is the weather?",
tools: [ToolDefinition.make({ name: "lookup", description: "Look up weather", inputSchema: {} })],
}),
).pipe(Effect.flip)
expect(error.reason._tag).toBe("InvalidRequest")
expect(error.message).toContain("Responses API")
}),
)
it.effect("keeps tool-free GPT-6.1 Sol Chat requests with supported effort", () =>
Effect.gen(function* () {
const prepared = yield* compileRequest(
LLM.request({
model: OpenAI.configure({ apiKey: "test" }).chat("gpt-6.1-sol"),
prompt: "Hello",
providerOptions: { reasoningEffort: "low" },
}),
)
expect(prepared.body.model).toBe("gpt-6.1-sol")
expect(prepared.body.tools).toBeUndefined()
expect(prepared.body.reasoning_effort).toBe("low")
}),
)
it.effect("rejects GPT-6.1 Sol Chat tool history without active tools", () =>
Effect.gen(function* () {
const error = yield* compileRequest(
LLM.request({
model: OpenAI.configure({ apiKey: "test" }).chat("gpt-6.1-sol"),
messages: [
Message.assistant([ToolCallPart.make({ id: "call_1", name: "lookup", input: {} })]),
Message.tool({ id: "call_1", name: "lookup", result: "sunny" }),
],
}),
).pipe(Effect.flip)
expect(error.reason._tag).toBe("InvalidRequest")
expect(error.message).toContain("Responses API")
}),
)
it.effect("rejects unsupported GPT-6.1 Sol minimal effort on native OpenAI Chat", () =>
Effect.gen(function* () {
const error = yield* compileRequest(
LLM.request({
model: OpenAI.configure({ apiKey: "test" }).chat("gpt-6.1-sol"),
prompt: "Hello",
providerOptions: { reasoningEffort: "minimal" },
}),
).pipe(Effect.flip)
expect(error.reason._tag).toBe("InvalidRequest")
expect(error.message).toContain("low, medium, high, xhigh, or max")
}),
)
it.effect("leaves compatible gateways with the same model slug to their own contract", () =>
Effect.gen(function* () {
const prepared = yield* compileRequest(
LLM.request({
model: OpenAICompatible.configure({ baseURL: "https://gateway.test/v1", apiKey: "test" }).model(
"gpt-6.1-sol",
),
prompt: "What is the weather?",
tools: [ToolDefinition.make({ name: "lookup", description: "Look up weather", inputSchema: {} })],
providerOptions: { reasoningEffort: "none" },
}),
)
expect(prepared.body.tools).toHaveLength(1)
expect(prepared.body.reasoning_effort).toBe("none")
}),
)
it.effect("replays Gemini thought signatures as tool call extra content", () =>
Effect.gen(function* () {
const prepared = yield* compileRequest(
@@ -153,6 +153,54 @@ describe("OpenAI Responses route", () => {
}),
)
it.effect("rejects unsupported GPT-6.1 Sol none effort before sending Responses", () =>
Effect.gen(function* () {
const error = yield* compileRequest(
LLM.request({
model: OpenAI.configure({ apiKey: "test" }).responses("gpt-6.1-sol"),
prompt: "Hello",
providerOptions: { reasoningEffort: "none" },
}),
).pipe(Effect.flip)
expect(error.reason._tag).toBe("InvalidRequest")
expect(error.message).toContain("low, medium, high, xhigh, or max")
}),
)
it.effect("rejects unsupported GPT-6.1 Sol effort in a Responses configuration update", () =>
Effect.gen(function* () {
const error = yield* compileRequest(
LLM.request({
model: LanguageModel.update(OpenAI.configure({ apiKey: "test" }).responses("gpt-6.1-sol"), {
compatibility: { supportsEffortUpdates: true },
}),
messages: [Message.user("First"), Message.effort({ previous: "low", effort: "none" }), Message.user("Next")],
providerOptions: { reasoningEffort: "none" },
}),
).pipe(Effect.flip)
expect(error.reason._tag).toBe("InvalidRequest")
expect(error.message).toContain("low, medium, high, xhigh, or max")
}),
)
it.effect("keeps GPT-6.1 Sol Responses tool calling with supported effort", () =>
Effect.gen(function* () {
const prepared = yield* compileRequest(
LLM.request({
model: OpenAI.configure({ apiKey: "test" }).responses("gpt-6.1-sol"),
prompt: "What is the weather?",
tools: [ToolDefinition.make({ name: "lookup", description: "Look up weather", inputSchema: {} })],
providerOptions: { reasoningEffort: "low" },
}),
)
expect(prepared.body.tools).toMatchObject([{ type: "function", name: "lookup" }])
expect(prepared.body.reasoning?.effort).toBe("low")
}),
)
it.effect("lowers the hosted OpenAI image generation tool", () =>
Effect.gen(function* () {
const prepared = yield* compileRequest(