mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-20 18:57:17 +03:00
66 lines
2.6 KiB
TypeScript
66 lines
2.6 KiB
TypeScript
import { expect } from "bun:test"
|
|
import { Effect } from "effect"
|
|
import { ai } from "../../src/effect.js"
|
|
import { AnthropicMessages } from "../../src/protocols/anthropic-messages.js"
|
|
import { compileRequest } from "../../src/route/client.js"
|
|
import { it } from "../lib/effect.js"
|
|
|
|
for (const [id, enabled] of [
|
|
["claude-fable-5-1", true],
|
|
["claude-mythos-5-1", true],
|
|
["claude-fable-5.1", true],
|
|
["anthropic/claude-fable-5.1", true],
|
|
["claude-fable-5-1@default", true],
|
|
["claude-fable-5-1@20260901", true],
|
|
["claude-sonnet-6", true],
|
|
["claude-opus-5-20260901", false],
|
|
["claude-opus-4-8", false],
|
|
["anthropic/claude-opus-4.8", false],
|
|
["claude-fable-5@default", false],
|
|
["kimi-k2.5", false],
|
|
] as const) {
|
|
it.effect(`thinking-binding defaults for ${id}`, () =>
|
|
Effect.gen(function* () {
|
|
const request = ai.request({
|
|
model: AnthropicMessages.route.model({ id }),
|
|
prompt: "Hello",
|
|
headers: { "anthropic-beta": "existing-beta" },
|
|
})
|
|
const compiled = yield* compileRequest(request)
|
|
const prepared = yield* AnthropicMessages.route.prepareTransport(compiled.body, request)
|
|
expect(compiled.body.thinking).toEqual(
|
|
enabled ? { type: "adaptive", block_binding: { prefix_mismatch_behavior: "drop_block" } } : undefined,
|
|
)
|
|
expect(prepared.request.headers["anthropic-beta"]).toBe(
|
|
enabled
|
|
? "existing-beta,interleaved-thinking-2025-05-14,thinking-binding-controls-2026-08-01"
|
|
: "existing-beta,interleaved-thinking-2025-05-14",
|
|
)
|
|
}),
|
|
)
|
|
}
|
|
|
|
it.effect("preserves explicit thinking settings and combines required beta headers", () =>
|
|
Effect.gen(function* () {
|
|
for (const thinking of [
|
|
{ type: "disabled" },
|
|
{ type: "between_tools" },
|
|
{ type: "adaptive", block_binding: { prefix_mismatch_behavior: "error" } },
|
|
] as const) {
|
|
const request = ai.request({
|
|
model: AnthropicMessages.route.model({ id: "claude-fable-5-1" }),
|
|
prompt: "Hello",
|
|
providerOptions: { thinking, contextManagement: { edits: [{ type: "compact_20260112" }] } },
|
|
})
|
|
const compiled = yield* compileRequest(request)
|
|
const prepared = yield* AnthropicMessages.route.prepareTransport(compiled.body, request)
|
|
expect(compiled.body.thinking).toEqual(thinking)
|
|
expect(prepared.request.headers["anthropic-beta"]).toBe(
|
|
thinking.type === "disabled" || thinking.type === "between_tools"
|
|
? "interleaved-thinking-2025-05-14,compact-2026-01-12"
|
|
: "interleaved-thinking-2025-05-14,compact-2026-01-12,thinking-binding-controls-2026-08-01",
|
|
)
|
|
}
|
|
}),
|
|
)
|