mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-19 17:01:37 +03:00
refactor(ai): require prompt or messages, not both (#60964)
This commit is contained in:
committed by
GitHub
Unverified
parent
977f5c695c
commit
66ee1c3ffc
@@ -47,7 +47,8 @@ await Effect.runPromise(program.pipe(Effect.provide(AIClient.layer)))
|
||||
```
|
||||
|
||||
Run `ai.stream(...)` instead of `generate` when you want incremental `LLMEvent`s. Both accept input or a prebuilt
|
||||
`ai.request(...)`. The event stream is provider-neutral — same shape across OpenAI Chat, OpenAI Responses,
|
||||
`ai.request(...)`. Input takes either `prompt`, a single user message, or `messages`, the whole conversation, never
|
||||
both; `system` goes with either. The event stream is provider-neutral — same shape across OpenAI Chat, OpenAI Responses,
|
||||
Anthropic Messages, Gemini, Bedrock Converse, and any OpenAI-compatible deployment.
|
||||
|
||||
### Tool loop
|
||||
|
||||
+22
-10
@@ -5,6 +5,7 @@ import {
|
||||
GenerationOptions,
|
||||
HttpOptions,
|
||||
InvalidProviderOutputError,
|
||||
InvalidRequestError,
|
||||
AIError,
|
||||
LLMEvent,
|
||||
LLMRequest,
|
||||
@@ -24,14 +25,20 @@ import { tool, type ExecutableTool, type Tool, type ToolSchema } from "./tool.js
|
||||
import { ToolRuntime } from "./tool-runtime.js"
|
||||
|
||||
/** Input accepted by `LLM.request`, normalized into the canonical `LLMRequest` class. */
|
||||
export type RequestInput<SelectedLanguageModel extends LanguageModel = LanguageModel> = Omit<
|
||||
export type RequestInput<SelectedLanguageModel extends LanguageModel = LanguageModel> =
|
||||
RequestFields<SelectedLanguageModel> & PromptOrMessages
|
||||
|
||||
/** Exactly one of `prompt`, a single user message, or `messages`, the full conversation. */
|
||||
export type PromptOrMessages =
|
||||
| { readonly prompt: string | ContentPart | ReadonlyArray<ContentPart>; readonly messages?: never }
|
||||
| { readonly messages: ReadonlyArray<Message | Message.Input>; readonly prompt?: never }
|
||||
|
||||
type RequestFields<SelectedLanguageModel extends LanguageModel> = Omit<
|
||||
ConstructorParameters<typeof LLMRequest>[0],
|
||||
"model" | "system" | "messages" | "tools" | "toolChoice" | "generation" | "http" | "providerOptions"
|
||||
> & {
|
||||
readonly model: SelectedLanguageModel
|
||||
readonly system?: string | SystemPart | ReadonlyArray<SystemPart>
|
||||
readonly prompt?: string | ContentPart | ReadonlyArray<ContentPart>
|
||||
readonly messages?: ReadonlyArray<Message | Message.Input>
|
||||
/** Sent in array order. Pass `tool(...)` values or wire entries such as hosted provider tools. */
|
||||
readonly tools?: ReadonlyArray<Tool | ToolEntryInput>
|
||||
readonly toolChoice?: ToolChoice.Input
|
||||
@@ -111,13 +118,14 @@ export function stream(input: Input, options?: StreamOptions) {
|
||||
}
|
||||
|
||||
export type LoopInput<SelectedLanguageModel extends LanguageModel = LanguageModel> = Omit<
|
||||
RequestInput<SelectedLanguageModel>,
|
||||
RequestFields<SelectedLanguageModel>,
|
||||
"tools"
|
||||
> & {
|
||||
readonly tools: ReadonlyArray<ExecutableTool>
|
||||
/** Called after each step that has tool calls; returning `true` ends the loop without running them. */
|
||||
readonly until?: (state: { readonly steps: ReadonlyArray<LLMResponse> }) => boolean
|
||||
}
|
||||
> &
|
||||
PromptOrMessages & {
|
||||
readonly tools: ReadonlyArray<ExecutableTool>
|
||||
/** Called after each step that has tool calls; returning `true` ends the loop without running them. */
|
||||
readonly until?: (state: { readonly steps: ReadonlyArray<LLMResponse> }) => boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Stream model calls, running the model's tool calls between them, until a step has no client-executed tool calls,
|
||||
@@ -264,10 +272,14 @@ export const request = <const SelectedLanguageModel extends LanguageModel>(
|
||||
http: requestHttp,
|
||||
...rest
|
||||
} = input
|
||||
if ((prompt === undefined) === (messages === undefined))
|
||||
throw new AIError({
|
||||
reason: new InvalidRequestError({ message: "Pass exactly one of `prompt` or `messages`, not both or neither" }),
|
||||
})
|
||||
return new LLMRequest({
|
||||
...rest,
|
||||
system: SystemPart.content(requestSystem),
|
||||
messages: [...(messages?.map(Message.make) ?? []), ...(prompt === undefined ? [] : [Message.user(prompt)])],
|
||||
messages: prompt === undefined ? (messages ?? []).map(Message.make) : [Message.user(prompt)],
|
||||
tools: tools?.map((item) => ("_definition" in item ? item._definition : ToolEntry.make(item))) ?? [],
|
||||
toolChoice: requestToolChoice ? ToolChoice.make(requestToolChoice) : undefined,
|
||||
generation: requestGeneration === undefined ? undefined : GenerationOptions.make(requestGeneration),
|
||||
|
||||
@@ -105,10 +105,12 @@ export const tryRequest = <A>(make: () => A): Effect.Effect<A, AIError> =>
|
||||
Effect.try({
|
||||
try: make,
|
||||
catch: (error) =>
|
||||
new AIError({
|
||||
reason: new InvalidRequestError({
|
||||
message: error instanceof Error ? error.message : String(error),
|
||||
cause: error,
|
||||
}),
|
||||
}),
|
||||
error instanceof AIError
|
||||
? error
|
||||
: new AIError({
|
||||
reason: new InvalidRequestError({
|
||||
message: error instanceof Error ? error.message : String(error),
|
||||
cause: error,
|
||||
}),
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -366,6 +366,7 @@ describe("applyCachePolicy", () => {
|
||||
const prepared = yield* compileRequest(
|
||||
ai.request({
|
||||
model: anthropicModel,
|
||||
prompt: "Hello",
|
||||
tools: [
|
||||
duplicate("first"),
|
||||
duplicate("second"),
|
||||
@@ -452,6 +453,7 @@ describe("applyCachePolicy", () => {
|
||||
test("marks the final leaf inside a tool namespace", () => {
|
||||
const request = ai.request({
|
||||
model: anthropicModel,
|
||||
prompt: "Hello",
|
||||
tools: [
|
||||
{
|
||||
type: "namespace",
|
||||
@@ -481,7 +483,9 @@ describe("applyCachePolicy", () => {
|
||||
|
||||
expect(prepared.body).toMatchObject({
|
||||
system: [{ type: "text", text: "Sys", cache_control: { type: "ephemeral", ttl: "1h" } }],
|
||||
messages: [{ role: "user", content: [{ type: "text", text: "hi", cache_control: { type: "ephemeral", ttl: "1h" } }] }],
|
||||
messages: [
|
||||
{ role: "user", content: [{ type: "text", text: "hi", cache_control: { type: "ephemeral", ttl: "1h" } }] },
|
||||
],
|
||||
})
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -13,10 +13,14 @@ test("runtime capability checks follow model and route updates", () => {
|
||||
expect(ai.canCompact(request)).toBe(true)
|
||||
expect(ai.canCompact(LLMRequest.update(request, { messages: [] }))).toBe(true)
|
||||
expect(ai.canCompact(LLMRequest.update(request, { model: unsupported }))).toBe(false)
|
||||
expect(ai.canCompact(ai.request({ model: LanguageModel.update(supported, { route: unsupported.route }) }))).toBe(
|
||||
false,
|
||||
)
|
||||
expect(ai.canCompact(ai.request({ model: LanguageModel.update(supported, { route: undefined }) }))).toBe(true)
|
||||
expect(
|
||||
ai.canCompact(
|
||||
ai.request({ model: LanguageModel.update(supported, { route: unsupported.route }), prompt: "Hello" }),
|
||||
),
|
||||
).toBe(false)
|
||||
expect(
|
||||
ai.canCompact(ai.request({ model: LanguageModel.update(supported, { route: undefined }), prompt: "Hello" })),
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
test("explicit compaction serializes a replacement window without a messages alias", () => {
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import { Effect, Ref, Schema } from "effect"
|
||||
import { HttpClientRequest, HttpClientResponse } from "effect/http"
|
||||
import {
|
||||
ai,
|
||||
LLMRequest,
|
||||
Message,
|
||||
ToolCallPart,
|
||||
ToolDefinition,
|
||||
ToolNamespace,
|
||||
} from "../src/effect.js"
|
||||
import { ai, LLMRequest, Message, ToolCallPart, ToolDefinition, ToolNamespace } from "../src/effect.js"
|
||||
import { AnthropicMessages, OpenAIChat, OpenAIResponses } from "../src/protocols.js"
|
||||
import { Auth, LLMClient } from "../src/route.js"
|
||||
import { compileRequest } from "../src/route/client.js"
|
||||
@@ -119,6 +112,7 @@ describe("request option precedence", () => {
|
||||
const prepared = yield* compileRequest(
|
||||
ai.request({
|
||||
model: OpenAIResponses.route.model({ id: "gpt-5.4" }),
|
||||
prompt: "Hello",
|
||||
tools: [
|
||||
ToolDefinition.make({ name: "crm", description: "Top-level CRM tool", inputSchema: {} }),
|
||||
ToolNamespace.make({
|
||||
|
||||
@@ -115,3 +115,25 @@ void AI.ai.stream(AI.ai.request({ model, prompt: "Hello" }))
|
||||
void AI.ai.generate({ model, prompt: "Hello", providerOptions: { mode: "slow" } })
|
||||
// @ts-expect-error Promise stream input keeps the selected model's provider option types.
|
||||
void AI.ai.stream({ model, prompt: "Hello", providerOptions: { mode: "slow" } })
|
||||
|
||||
ai.request({ model, system: "Be brief.", prompt: "Hello" })
|
||||
ai.request({ model, system: "Be brief.", messages: [] })
|
||||
// @ts-expect-error A request needs `prompt` or `messages`.
|
||||
ai.request({ model })
|
||||
// @ts-expect-error A request takes `prompt` or `messages`, not both.
|
||||
ai.request({ model, prompt: "Hello", messages: [] })
|
||||
// @ts-expect-error Effect generate needs `prompt` or `messages`.
|
||||
ai.generate({ model, system: "Be brief." })
|
||||
// @ts-expect-error Effect stream takes `prompt` or `messages`, not both.
|
||||
ai.stream({ model, prompt: "Hello", messages: [] })
|
||||
// @ts-expect-error Effect loop needs `prompt` or `messages`.
|
||||
ai.loop({ model, tools: [] })
|
||||
// @ts-expect-error Effect structured output takes `prompt` or `messages`, not both.
|
||||
ai.generate({ model, prompt: "Hello", messages: [], schema: Schema.String })
|
||||
// @ts-expect-error Promise generate needs `prompt` or `messages`.
|
||||
void AI.ai.generate({ model })
|
||||
// @ts-expect-error Promise stream takes `prompt` or `messages`, not both.
|
||||
AI.ai.stream({ model, prompt: "Hello", messages: [] })
|
||||
// @ts-expect-error Promise loop takes `prompt` or `messages`, not both.
|
||||
AI.ai.loop({ model, prompt: "Hello", messages: [], tools: [] })
|
||||
AI.ai.loop({ model, messages: [], tools: [] })
|
||||
|
||||
@@ -24,6 +24,7 @@ describe("llm constructors", () => {
|
||||
test("normalizes recursive tool namespaces", () => {
|
||||
const request = ai.request({
|
||||
model: LanguageModel.make({ id: "fake-model", provider: "fake", route: responsesRoute }),
|
||||
prompt: "Hello",
|
||||
tools: [
|
||||
{
|
||||
type: "namespace",
|
||||
|
||||
@@ -175,4 +175,21 @@ describe("ai.loop", () => {
|
||||
expect(yield* client.requests()).toHaveLength(0)
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("fails untyped input that has neither or both of prompt and messages", () =>
|
||||
Effect.gen(function* () {
|
||||
const client = yield* TestLLM.Test
|
||||
const untyped = (input: object) => input as LLM.RequestInput
|
||||
const message = "Pass exactly one of `prompt` or `messages`, not both or neither"
|
||||
const neither = yield* ai.generate(untyped({ model })).pipe(Effect.flip)
|
||||
const both = yield* ai
|
||||
.loop({ ...untyped({ model, prompt: "Hi.", messages: [] }), tools: [read_file] })
|
||||
.pipe(Stream.runDrain, Effect.flip)
|
||||
|
||||
expect(neither.reason).toMatchObject({ _tag: "InvalidRequest", message })
|
||||
expect(both.reason).toMatchObject({ _tag: "InvalidRequest", message })
|
||||
expect(() => ai.request(untyped({ model, system: "Be brief." }))).toThrow(message)
|
||||
expect(yield* client.requests()).toHaveLength(0)
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
@@ -6,34 +6,41 @@ Alibaba.configure({ baseURL: "https://gateway.example/v1" })
|
||||
Alibaba.configure({ region: "eu-central-1", workspaceID: "llm-workspace" })
|
||||
ai.request({
|
||||
model: provider.chat("qwen3.8-max"),
|
||||
prompt: "Hello",
|
||||
providerOptions: { reasoningEffort: "future", enableThinking: true, preserveThinking: false, toolStream: true },
|
||||
})
|
||||
ai.request({
|
||||
model: provider.messages("qwen3.8-max"),
|
||||
prompt: "Hello",
|
||||
providerOptions: { effort: "xhigh", thinking: { type: "enabled" } },
|
||||
})
|
||||
ai.request({
|
||||
model: provider.messages("qwen3.7-plus"),
|
||||
prompt: "Hello",
|
||||
providerOptions: { thinking: { type: "enabled", budgetTokens: 512 } },
|
||||
})
|
||||
ai.request({
|
||||
model: provider.responses("qwen3.8-max"),
|
||||
prompt: "Hello",
|
||||
providerOptions: { reasoningEffort: "low", enableThinking: true, store: true, previousResponseId: "resp_previous" },
|
||||
})
|
||||
// @ts-expect-error Region or complete base URL is required.
|
||||
Alibaba.configure({ apiKey: "fixture" })
|
||||
ai.request({
|
||||
model: provider.chat("qwen3.8-max"),
|
||||
prompt: "Hello",
|
||||
// @ts-expect-error Thinking toggle is a boolean.
|
||||
providerOptions: { enableThinking: "true" },
|
||||
})
|
||||
ai.request({
|
||||
model: provider.messages("qwen3.8-max"),
|
||||
prompt: "Hello",
|
||||
// @ts-expect-error Messages uses effort.
|
||||
providerOptions: { reasoningEffort: "high" },
|
||||
})
|
||||
ai.request({
|
||||
model: provider.responses("qwen3.8-max"),
|
||||
prompt: "Hello",
|
||||
// @ts-expect-error Responses does not use Chat thinking budgets.
|
||||
providerOptions: { thinkingBudget: 512 },
|
||||
})
|
||||
|
||||
@@ -49,7 +49,7 @@ for (const selected of [
|
||||
LanguageModel.make(LanguageModel.input(model)),
|
||||
LanguageModel.update(model, { defaults: { generation: { maxTokens: 100 } } }),
|
||||
]) {
|
||||
ai.compact(ai.request({ model: selected }), { mechanism: "trigger" })
|
||||
ai.compact(ai.request({ model: selected, prompt: "Hello" }), { mechanism: "trigger" })
|
||||
}
|
||||
ai.compact(new LLMRequest(LLMRequest.input(request)), { mechanism: "trigger" })
|
||||
ai.compact(LLMRequest.update(request, { messages: [] }), { mechanism: "trigger" })
|
||||
@@ -57,25 +57,26 @@ ai.compact(LLMRequest.update(request, { messages: [] }), { mechanism: "trigger"
|
||||
const azure = Azure.configure({ resourceName: "fixture" }).responses("fixture")
|
||||
const xai = XAI.configure().responses("fixture")
|
||||
// @ts-expect-error Azure must not inherit OpenAI's trigger operation.
|
||||
ai.compact(ai.request({ model: azure }), { mechanism: "trigger" })
|
||||
ai.compact(ai.request({ model: Azure.responsesModel("fixture", { resourceName: "fixture" }) }), {
|
||||
ai.compact(ai.request({ model: azure, prompt: "Hello" }), { mechanism: "trigger" })
|
||||
ai.compact(ai.request({ model: Azure.responsesModel("fixture", { resourceName: "fixture" }), prompt: "Hello" }), {
|
||||
// @ts-expect-error Azure's package entrypoint must preserve its narrower capability.
|
||||
mechanism: "trigger",
|
||||
})
|
||||
// @ts-expect-error xAI endpoint support does not imply trigger support.
|
||||
ai.compact(ai.request({ model: xai }), { mechanism: "trigger" })
|
||||
ai.compact(ai.request({ model: xai, prompt: "Hello" }), { mechanism: "trigger" })
|
||||
// @ts-expect-error xAI's package entrypoint must preserve its narrower capability.
|
||||
ai.compact(ai.request({ model: XAI.model("fixture", {}) }), { mechanism: "trigger" })
|
||||
ai.compact(ai.request({ model: XAI.model("fixture", {}), prompt: "Hello" }), { mechanism: "trigger" })
|
||||
|
||||
const unsupported = {
|
||||
bedrock: ai.request({ model: AmazonBedrock.configure().model("fixture") }),
|
||||
mantle: ai.request({ model: AmazonBedrockMantle.configure().responses("fixture") }),
|
||||
anthropic: ai.request({ model: Anthropic.configure().model("fixture") }),
|
||||
openai: ai.request({ model: OpenAI.configure().chat("fixture") }),
|
||||
azure: ai.request({ model: Azure.configure({ resourceName: "fixture" }).chat("fixture") }),
|
||||
xai: ai.request({ model: XAI.configure().chat("fixture") }),
|
||||
bedrock: ai.request({ model: AmazonBedrock.configure().model("fixture"), prompt: "Hello" }),
|
||||
mantle: ai.request({ model: AmazonBedrockMantle.configure().responses("fixture"), prompt: "Hello" }),
|
||||
anthropic: ai.request({ model: Anthropic.configure().model("fixture"), prompt: "Hello" }),
|
||||
openai: ai.request({ model: OpenAI.configure().chat("fixture"), prompt: "Hello" }),
|
||||
azure: ai.request({ model: Azure.configure({ resourceName: "fixture" }).chat("fixture"), prompt: "Hello" }),
|
||||
xai: ai.request({ model: XAI.configure().chat("fixture"), prompt: "Hello" }),
|
||||
compatible: ai.request({
|
||||
model: OpenAICompatibleResponses.configure({ baseURL: "https://example.com" }).model("fixture"),
|
||||
prompt: "Hello",
|
||||
}),
|
||||
}
|
||||
// @ts-expect-error Bedrock does not expose trigger compaction.
|
||||
@@ -94,13 +95,14 @@ ai.compact(unsupported.xai, { mechanism: "trigger" })
|
||||
ai.compact(unsupported.compatible, { mechanism: "trigger" })
|
||||
// @ts-expect-error Changing the model replaces its capability.
|
||||
ai.compact(LLMRequest.update(request, { model: azure }), { mechanism: "trigger" })
|
||||
ai.compact(ai.request({ model: LanguageModel.update(model, { route: azure.route }) }), {
|
||||
ai.compact(ai.request({ model: LanguageModel.update(model, { route: azure.route }), prompt: "Hello" }), {
|
||||
// @ts-expect-error Changing the route replaces its capability.
|
||||
mechanism: "trigger",
|
||||
})
|
||||
ai.compact(
|
||||
ai.request({
|
||||
model: model.route.with({ compact: { endpoint: model.route.compact.endpoint } }).model({ id: "fixture" }),
|
||||
prompt: "Hello",
|
||||
}),
|
||||
// @ts-expect-error Replacing route operations does not retain the old trigger capability.
|
||||
{ mechanism: "trigger" },
|
||||
@@ -110,11 +112,11 @@ declare const dynamic: LLMRequest
|
||||
declare const patch: Partial<LLMRequest.Input>
|
||||
declare const routePatch: RoutePatch<OpenAIResponsesBody, Prepared>
|
||||
// @ts-expect-error A dynamic operation override cannot preserve trigger support.
|
||||
ai.compact(ai.request({ model: model.route.with(routePatch).model({ id: "fixture" }) }), {
|
||||
ai.compact(ai.request({ model: model.route.with(routePatch).model({ id: "fixture" }), prompt: "Hello" }), {
|
||||
mechanism: "trigger",
|
||||
})
|
||||
// @ts-expect-error Explicitly removing operations removes trigger support.
|
||||
ai.compact(ai.request({ model: model.route.with({ compact: undefined }).model({ id: "fixture" }) }), {
|
||||
ai.compact(ai.request({ model: model.route.with({ compact: undefined }).model({ id: "fixture" }), prompt: "Hello" }), {
|
||||
mechanism: "trigger",
|
||||
})
|
||||
// @ts-expect-error Dynamic models must be narrowed.
|
||||
@@ -140,7 +142,7 @@ void AI.ai.compact(request, { mechanism: "trigger", webSocket, signal: AbortSign
|
||||
// @ts-expect-error Endpoint compaction does not accept a WebSocket executor.
|
||||
void AI.ai.compact(request, { webSocket })
|
||||
// @ts-expect-error Azure must not inherit OpenAI's trigger operation.
|
||||
void AI.ai.compact(ai.request({ model: azure }), { mechanism: "trigger" })
|
||||
void AI.ai.compact(ai.request({ model: azure, prompt: "Hello" }), { mechanism: "trigger" })
|
||||
// @ts-expect-error OpenAI Chat does not expose explicit compaction.
|
||||
void AI.ai.compact(unsupported.openai)
|
||||
// @ts-expect-error Dynamic models must be narrowed.
|
||||
|
||||
@@ -32,12 +32,13 @@ for (const model of [
|
||||
}
|
||||
|
||||
const unsupported = {
|
||||
anthropic: ai.request({ model: Anthropic.configure().model("fixture") }),
|
||||
openaiChat: ai.request({ model: OpenAI.configure().chat("fixture") }),
|
||||
azureChat: ai.request({ model: Azure.configure({ resourceName: "test" }).chat("fixture") }),
|
||||
xaiChat: ai.request({ model: XAI.configure().chat("fixture") }),
|
||||
anthropic: ai.request({ model: Anthropic.configure().model("fixture"), prompt: "Hello" }),
|
||||
openaiChat: ai.request({ model: OpenAI.configure().chat("fixture"), prompt: "Hello" }),
|
||||
azureChat: ai.request({ model: Azure.configure({ resourceName: "test" }).chat("fixture"), prompt: "Hello" }),
|
||||
xaiChat: ai.request({ model: XAI.configure().chat("fixture"), prompt: "Hello" }),
|
||||
compatible: ai.request({
|
||||
model: OpenAICompatibleResponses.configure({ baseURL: "https://example.com" }).model("fixture"),
|
||||
prompt: "Hello",
|
||||
}),
|
||||
}
|
||||
// @ts-expect-error Anthropic has no standalone compact endpoint.
|
||||
@@ -64,7 +65,10 @@ ai.compact(switched)
|
||||
ai.compact(LLMRequest.update(switched, { model: openai }))
|
||||
ai.compact(
|
||||
// @ts-expect-error Replacing the route also replaces compaction capability.
|
||||
ai.request({ model: LanguageModel.update(openai, { route: Anthropic.configure().model("fixture").route }) }),
|
||||
ai.request({
|
||||
model: LanguageModel.update(openai, { route: Anthropic.configure().model("fixture").route }),
|
||||
prompt: "Hello",
|
||||
}),
|
||||
)
|
||||
|
||||
declare const dynamicModel: LanguageModel
|
||||
@@ -110,6 +114,7 @@ ai.compact(ai.request({ model: openai, prompt: "hello" })).pipe(
|
||||
)
|
||||
ai.request({
|
||||
model: openai,
|
||||
prompt: "Hello",
|
||||
providerOptions: {
|
||||
// @ts-expect-error A token threshold is numeric.
|
||||
contextManagement: [{ type: "compaction", compactThreshold: "100000" }],
|
||||
@@ -118,6 +123,7 @@ ai.request({
|
||||
const anthropic = Anthropic.configure().model("claude-opus-4-6")
|
||||
ai.request({
|
||||
model: anthropic,
|
||||
prompt: "Hello",
|
||||
providerOptions: {
|
||||
contextManagement: {
|
||||
edits: [{ type: "compact_20260112", pauseAfterCompaction: true, instructions: "Summarize without using tools" }],
|
||||
@@ -126,6 +132,7 @@ ai.request({
|
||||
})
|
||||
ai.request({
|
||||
model: anthropic,
|
||||
prompt: "Hello",
|
||||
providerOptions: {
|
||||
// @ts-expect-error A pause setting is boolean.
|
||||
contextManagement: { edits: [{ type: "compact_20260112", pauseAfterCompaction: "yes" }] },
|
||||
|
||||
@@ -3,24 +3,31 @@ import { MiniMax } from "../../src/providers.js"
|
||||
|
||||
const minimax = MiniMax.configure()
|
||||
|
||||
ai.request({ model: minimax.model("MiniMax-M3"), providerOptions: { thinking: { type: "adaptive" } } })
|
||||
ai.request({ model: minimax.chat("MiniMax-M3"), providerOptions: { thinking: { type: "disabled" } } })
|
||||
ai.request({ model: minimax.chat("MiniMax-M3"), providerOptions: { reasoningSplit: false } })
|
||||
ai.request({ model: minimax.responses("MiniMax-M3"), providerOptions: { reasoningEffort: "minimal" } })
|
||||
ai.request({ model: minimax.responses("MiniMax-M3"), providerOptions: { reasoningEffort: "future-effort" } })
|
||||
ai.request({ model: minimax.model("MiniMax-M3"), prompt: "Hello", providerOptions: { thinking: { type: "adaptive" } } })
|
||||
ai.request({ model: minimax.chat("MiniMax-M3"), prompt: "Hello", providerOptions: { thinking: { type: "disabled" } } })
|
||||
ai.request({ model: minimax.chat("MiniMax-M3"), prompt: "Hello", providerOptions: { reasoningSplit: false } })
|
||||
ai.request({ model: minimax.responses("MiniMax-M3"), prompt: "Hello", providerOptions: { reasoningEffort: "minimal" } })
|
||||
ai.request({
|
||||
model: minimax.responses("MiniMax-M3"),
|
||||
prompt: "Hello",
|
||||
providerOptions: { reasoningEffort: "future-effort" },
|
||||
})
|
||||
|
||||
ai.request({
|
||||
model: minimax.model("MiniMax-M3"),
|
||||
prompt: "Hello",
|
||||
// @ts-expect-error MiniMax Messages has no documented effort setting.
|
||||
providerOptions: { effort: "high" },
|
||||
})
|
||||
ai.request({
|
||||
model: minimax.chat("MiniMax-M3"),
|
||||
prompt: "Hello",
|
||||
// @ts-expect-error Chat reasoning_split is a boolean.
|
||||
providerOptions: { reasoningSplit: "true" },
|
||||
})
|
||||
ai.request({
|
||||
model: minimax.responses("MiniMax-M3"),
|
||||
prompt: "Hello",
|
||||
// @ts-expect-error MiniMax Responses uses reasoning effort rather than Messages thinking.
|
||||
providerOptions: { thinking: { type: "adaptive" } },
|
||||
})
|
||||
|
||||
@@ -3,27 +3,43 @@ import { Moonshot } from "../../src/providers.js"
|
||||
|
||||
const moonshot = Moonshot.configure()
|
||||
|
||||
ai.request({ model: moonshot.model("kimi-k2.6"), providerOptions: { thinking: { type: "enabled", keep: "all" } } })
|
||||
ai.request({ model: moonshot.chat("kimi-k2.6"), providerOptions: { thinking: { type: "disabled", keep: null } } })
|
||||
ai.request({ model: moonshot.chat("kimi-k3"), providerOptions: { reasoningEffort: "high" } })
|
||||
ai.request({
|
||||
model: moonshot.model("kimi-k2.6"),
|
||||
prompt: "Hello",
|
||||
providerOptions: { thinking: { type: "enabled", keep: "all" } },
|
||||
})
|
||||
ai.request({
|
||||
model: moonshot.chat("kimi-k2.6"),
|
||||
prompt: "Hello",
|
||||
providerOptions: { thinking: { type: "disabled", keep: null } },
|
||||
})
|
||||
ai.request({ model: moonshot.chat("kimi-k3"), prompt: "Hello", providerOptions: { reasoningEffort: "high" } })
|
||||
ai.request({
|
||||
model: moonshot.messages("kimi-k3"),
|
||||
prompt: "Hello",
|
||||
providerOptions: { effort: "low", metadata: { user_id: "fixture" } },
|
||||
})
|
||||
ai.request({ model: moonshot.responses("kimi-k3"), providerOptions: { reasoningEffort: "future-effort" } })
|
||||
ai.request({
|
||||
model: moonshot.responses("kimi-k3"),
|
||||
prompt: "Hello",
|
||||
providerOptions: { reasoningEffort: "future-effort" },
|
||||
})
|
||||
|
||||
ai.request({
|
||||
model: moonshot.messages("kimi-k3"),
|
||||
prompt: "Hello",
|
||||
// @ts-expect-error Messages exposes effort rather than the K2 Chat thinking parameter.
|
||||
providerOptions: { thinking: { type: "enabled" } },
|
||||
})
|
||||
ai.request({
|
||||
model: moonshot.chat("kimi-k2.6"),
|
||||
prompt: "Hello",
|
||||
// @ts-expect-error Preserved thinking takes a string or null.
|
||||
providerOptions: { thinking: { type: "enabled", keep: true } },
|
||||
})
|
||||
ai.request({
|
||||
model: moonshot.responses("kimi-k3"),
|
||||
prompt: "Hello",
|
||||
// @ts-expect-error Responses uses reasoningEffort rather than the Messages effort option.
|
||||
providerOptions: { effort: "high" },
|
||||
})
|
||||
|
||||
@@ -3,24 +3,37 @@ import { Venice } from "../../src/providers.js"
|
||||
|
||||
ai.request({
|
||||
model: Venice.chat("qwen3-6-27b"),
|
||||
providerOptions: { reasoningEffort: "high", reasoning: { summary: "concise" }, veniceParameters: { includeVeniceSystemPrompt: false } },
|
||||
prompt: "Hello",
|
||||
providerOptions: {
|
||||
reasoningEffort: "high",
|
||||
reasoning: { summary: "concise" },
|
||||
veniceParameters: { includeVeniceSystemPrompt: false },
|
||||
},
|
||||
})
|
||||
ai.request({
|
||||
model: Venice.configure({ providerOptions: { reasoningEffort: "future-effort" } }).model("future-model"),
|
||||
providerOptions: { reasoning: { enabled: false }, promptCacheRetention: "future-retention", parallelToolCalls: false },
|
||||
prompt: "Hello",
|
||||
providerOptions: {
|
||||
reasoning: { enabled: false },
|
||||
promptCacheRetention: "future-retention",
|
||||
parallelToolCalls: false,
|
||||
},
|
||||
})
|
||||
ai.request({
|
||||
model: Venice.chat("qwen3-6-27b"),
|
||||
prompt: "Hello",
|
||||
// @ts-expect-error Thinking toggles are boolean.
|
||||
providerOptions: { reasoning: { enabled: "false" } },
|
||||
})
|
||||
ai.request({
|
||||
model: Venice.chat("qwen3-6-27b"),
|
||||
prompt: "Hello",
|
||||
// @ts-expect-error Venice uses nested reasoning, not Anthropic thinking controls.
|
||||
providerOptions: { thinking: { type: "disabled" } },
|
||||
})
|
||||
ai.request({
|
||||
model: Venice.chat("qwen3-6-27b"),
|
||||
prompt: "Hello",
|
||||
// @ts-expect-error Venice's system-prompt toggle is boolean.
|
||||
providerOptions: { veniceParameters: { includeVeniceSystemPrompt: "false" } },
|
||||
})
|
||||
|
||||
@@ -3,30 +3,40 @@ import { ZAI, ZAICodingPlan } from "../../src/providers.js"
|
||||
|
||||
ai.request({
|
||||
model: ZAI.chat("glm-5.3"),
|
||||
prompt: "Hello",
|
||||
providerOptions: { thinking: { clear_thinking: false }, reasoningEffort: "max" },
|
||||
})
|
||||
ai.request({
|
||||
model: ZAI.chat("glm-5.2"),
|
||||
prompt: "Hello",
|
||||
providerOptions: { thinking: { type: "disabled" }, toolStream: false, responseFormat: { type: "json_object" } },
|
||||
})
|
||||
ai.request({
|
||||
model: ZAICodingPlan.messages("glm-5.3"),
|
||||
prompt: "Hello",
|
||||
providerOptions: { thinking: { type: "enabled" }, effort: "high" },
|
||||
})
|
||||
ai.request({ model: ZAICodingPlan.responses("glm-5.3"), providerOptions: { reasoningEffort: "future-effort" } })
|
||||
ai.request({
|
||||
model: ZAICodingPlan.responses("glm-5.3"),
|
||||
prompt: "Hello",
|
||||
providerOptions: { reasoningEffort: "future-effort" },
|
||||
})
|
||||
|
||||
ai.request({
|
||||
model: ZAI.chat("glm-5.3"),
|
||||
prompt: "Hello",
|
||||
// @ts-expect-error clear_thinking is a boolean.
|
||||
providerOptions: { thinking: { clear_thinking: "false" } },
|
||||
})
|
||||
ai.request({
|
||||
model: ZAICodingPlan.messages("glm-5.3"),
|
||||
prompt: "Hello",
|
||||
// @ts-expect-error Messages uses effort.
|
||||
providerOptions: { reasoningEffort: "high" },
|
||||
})
|
||||
ai.request({
|
||||
model: ZAICodingPlan.responses("glm-5.3"),
|
||||
prompt: "Hello",
|
||||
// @ts-expect-error Responses uses reasoning effort, not Chat thinking controls.
|
||||
providerOptions: { thinking: { type: "enabled" } },
|
||||
})
|
||||
|
||||
@@ -306,7 +306,10 @@ describe("provider package entrypoints", () => {
|
||||
baseURL: "https://messages.example.test/v1",
|
||||
})
|
||||
expect(
|
||||
Endpoint.render(selected.route.endpoint, { request: ai.request({ model: selected }), body: {} }).toString(),
|
||||
Endpoint.render(selected.route.endpoint, {
|
||||
request: ai.request({ model: selected, prompt: "Hello" }),
|
||||
body: {},
|
||||
}).toString(),
|
||||
).toBe("https://messages.example.test/v1/messages")
|
||||
expect(selected.route.defaults.headers).toEqual({ "x-application": "opencode" })
|
||||
expect(selected.route.defaults.http?.body).toEqual({ metadata: { user_id: "user_1" } })
|
||||
|
||||
@@ -64,7 +64,7 @@ it.effect("Alibaba owns regional shared and workspace-specific endpoints", () =>
|
||||
]) {
|
||||
const provider = Alibaba.configure({ region, apiKey: "fixture" })
|
||||
for (const api of ["chat", "messages", "responses"] as const) {
|
||||
const request = ai.request({ model: provider[api]("qwen3.8-max") })
|
||||
const request = ai.request({ model: provider[api]("qwen3.8-max"), prompt: "Hello" })
|
||||
const compiled = yield* compileRequest(request)
|
||||
expect(Endpoint.render(request.model.route.endpoint, { request, body: compiled.body }).toString()).toBe(
|
||||
`https://${host}${paths[api]}`,
|
||||
@@ -118,7 +118,7 @@ it.effect("Alibaba resolves explicit auth, API keys, and regional environment cr
|
||||
]) {
|
||||
const provider = Alibaba.configure({ region: "ap-southeast-1", ...item.config })
|
||||
for (const api of ["chat", "messages", "responses"] as const) {
|
||||
const request = ai.request({ model: provider[api]("qwen3.8-max") })
|
||||
const request = ai.request({ model: provider[api]("qwen3.8-max"), prompt: "Hello" })
|
||||
const headers = yield* request.model.route.auth
|
||||
.apply({ request, method: "POST", url: "https://fixture", body: "{}", headers: Headers.empty })
|
||||
.pipe(Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env: item.env }))))
|
||||
@@ -133,13 +133,21 @@ it.effect("Alibaba keeps native reasoning controls and future efforts on their s
|
||||
const provider = Alibaba.configure({ region: "ap-southeast-1", apiKey: "fixture" })
|
||||
for (const effort of ["none", "minimal", "low", "medium", "high", "xhigh", "max", "future-effort"]) {
|
||||
const chat = yield* compileRequest(
|
||||
ai.request({ model: provider.chat("qwen3.8-max"), providerOptions: { reasoningEffort: effort } }),
|
||||
ai.request({
|
||||
model: provider.chat("qwen3.8-max"),
|
||||
prompt: "Hello",
|
||||
providerOptions: { reasoningEffort: effort },
|
||||
}),
|
||||
)
|
||||
const messages = yield* compileRequest(
|
||||
ai.request({ model: provider.messages("qwen3.8-max"), providerOptions: { effort } }),
|
||||
ai.request({ model: provider.messages("qwen3.8-max"), prompt: "Hello", providerOptions: { effort } }),
|
||||
)
|
||||
const responses = yield* compileRequest(
|
||||
ai.request({ model: provider.responses("qwen3.8-max"), providerOptions: { reasoningEffort: effort } }),
|
||||
ai.request({
|
||||
model: provider.responses("qwen3.8-max"),
|
||||
prompt: "Hello",
|
||||
providerOptions: { reasoningEffort: effort },
|
||||
}),
|
||||
)
|
||||
expect(chat.body.reasoning_effort).toBe(effort)
|
||||
expect(messages.body.output_config).toEqual({ effort })
|
||||
@@ -153,6 +161,7 @@ it.effect("Alibaba keeps native reasoning controls and future efforts on their s
|
||||
const chat = yield* compileRequest(
|
||||
ai.request({
|
||||
model: provider.chat("qwen3.7-plus"),
|
||||
prompt: "Hello",
|
||||
tools: [tool],
|
||||
generation: { maxTokens: 1234, topK: 20 },
|
||||
providerOptions: {
|
||||
@@ -190,6 +199,7 @@ it.effect("Alibaba keeps native reasoning controls and future efforts on their s
|
||||
const responses = yield* compileRequest(
|
||||
ai.request({
|
||||
model: provider.responses("qwen3.7-plus"),
|
||||
prompt: "Hello",
|
||||
providerOptions: { enableThinking, store: false, previousResponseId: "resp_previous" },
|
||||
}),
|
||||
)
|
||||
@@ -206,7 +216,7 @@ it.effect("Alibaba keeps native reasoning controls and future efforts on their s
|
||||
{ type: "future", budget_tokens: 4096 },
|
||||
]) {
|
||||
const messages = yield* compileRequest(
|
||||
ai.request({ model: provider.messages("qwen3.7-plus"), providerOptions: { thinking } }),
|
||||
ai.request({ model: provider.messages("qwen3.7-plus"), prompt: "Hello", providerOptions: { thinking } }),
|
||||
)
|
||||
expect(messages.body.thinking).toEqual({
|
||||
type: thinking.type,
|
||||
@@ -252,7 +262,7 @@ it.effect("Alibaba validates malformed options before execution", () =>
|
||||
["responses", { enableThinking: "false" }],
|
||||
] as const) {
|
||||
const model = provider[api]("qwen3.8-max").route.with({ providerOptions }).model({ id: "qwen3.8-max" })
|
||||
const error = yield* compileRequest(ai.request({ model })).pipe(Effect.flip)
|
||||
const error = yield* compileRequest(ai.request({ model, prompt: "Hello" })).pipe(Effect.flip)
|
||||
expect(error.reason._tag).toBe("InvalidRequest")
|
||||
}
|
||||
}),
|
||||
|
||||
@@ -276,7 +276,10 @@ testEffect(dynamicResponse(() => Effect.die("Must reject before sending"))).effe
|
||||
() =>
|
||||
Effect.gen(function* () {
|
||||
const client = yield* LLMClient.Service
|
||||
const unsupported = ai.request({ model: Azure.configure({ resourceName: "fixture" }).responses("fixture") })
|
||||
const unsupported = ai.request({
|
||||
model: Azure.configure({ resourceName: "fixture" }).responses("fixture"),
|
||||
prompt: "Hello",
|
||||
})
|
||||
expect(ai.canCompact(unsupported)).toBe(true)
|
||||
expect(ai.canCompact(unsupported, trigger)).toBe(false)
|
||||
// @ts-expect-error Exercise untyped consumers; the service must reject before sending.
|
||||
|
||||
@@ -214,6 +214,7 @@ it.effect("Cohere thinking budgets must be positive integers", () =>
|
||||
const error = yield* compileRequest(
|
||||
ai.request({
|
||||
model: cohere.model("command-a-reasoning-08-2025"),
|
||||
prompt: "Hello",
|
||||
providerOptions: { thinking: { tokenBudget: 0 } },
|
||||
}),
|
||||
).pipe(Effect.flip)
|
||||
|
||||
@@ -73,13 +73,18 @@ describe("MiniMax provider", () => {
|
||||
Effect.gen(function* () {
|
||||
const minimax = MiniMax.configure({ apiKey: "fixture" })
|
||||
const messages = yield* compileRequest(
|
||||
ai.request({ model: minimax.model("MiniMax-M3"), providerOptions: { thinking: { type: "adaptive" } } }),
|
||||
ai.request({
|
||||
model: minimax.model("MiniMax-M3"),
|
||||
prompt: "Hello",
|
||||
providerOptions: { thinking: { type: "adaptive" } },
|
||||
}),
|
||||
)
|
||||
expect(messages.body.thinking).toEqual({ type: "adaptive" })
|
||||
expect(messages.body.output_config).toBeUndefined()
|
||||
const chat = yield* compileRequest(
|
||||
ai.request({
|
||||
model: minimax.chat("MiniMax-M3"),
|
||||
prompt: "Hello",
|
||||
generation: { maxTokens: 128 },
|
||||
providerOptions: { thinking: { type: "disabled" }, reasoningSplit: false },
|
||||
}),
|
||||
@@ -92,7 +97,11 @@ describe("MiniMax provider", () => {
|
||||
})
|
||||
expect(chat.body.store).toBeUndefined()
|
||||
const responses = yield* compileRequest(
|
||||
ai.request({ model: minimax.responses("MiniMax-M3"), providerOptions: { reasoningEffort: "minimal" } }),
|
||||
ai.request({
|
||||
model: minimax.responses("MiniMax-M3"),
|
||||
prompt: "Hello",
|
||||
providerOptions: { reasoningEffort: "minimal" },
|
||||
}),
|
||||
)
|
||||
expect(responses.body.reasoning).toEqual({ effort: "minimal" })
|
||||
expect(responses.body.include).toBeUndefined()
|
||||
|
||||
@@ -104,20 +104,24 @@ it.effect("Moonshot lowers API-specific reasoning options without adding unrelat
|
||||
const moonshot = Moonshot.configure({ apiKey: "fixture" })
|
||||
for (const thinking of [{ type: "disabled" }, { type: "enabled", keep: "all" }, { type: "enabled", keep: null }]) {
|
||||
const result = yield* compileRequest(
|
||||
ai.request({ model: moonshot.chat("kimi-k2.6"), providerOptions: { thinking } }),
|
||||
ai.request({ model: moonshot.chat("kimi-k2.6"), prompt: "Hello", providerOptions: { thinking } }),
|
||||
)
|
||||
expect(result.body.thinking).toEqual(thinking)
|
||||
expect(result.body.reasoning_effort).toBeUndefined()
|
||||
}
|
||||
for (const effort of ["low", "high", "max", "future-effort"]) {
|
||||
const chat = yield* compileRequest(
|
||||
ai.request({ model: moonshot.chat("kimi-k3"), providerOptions: { reasoningEffort: effort } }),
|
||||
ai.request({ model: moonshot.chat("kimi-k3"), prompt: "Hello", providerOptions: { reasoningEffort: effort } }),
|
||||
)
|
||||
const messages = yield* compileRequest(
|
||||
ai.request({ model: moonshot.messages("kimi-k3"), providerOptions: { effort } }),
|
||||
ai.request({ model: moonshot.messages("kimi-k3"), prompt: "Hello", providerOptions: { effort } }),
|
||||
)
|
||||
const responses = yield* compileRequest(
|
||||
ai.request({ model: moonshot.responses("kimi-k3"), providerOptions: { reasoningEffort: effort } }),
|
||||
ai.request({
|
||||
model: moonshot.responses("kimi-k3"),
|
||||
prompt: "Hello",
|
||||
providerOptions: { reasoningEffort: effort },
|
||||
}),
|
||||
)
|
||||
expect(chat.body.reasoning_effort).toBe(effort)
|
||||
expect(messages.body.output_config).toEqual({ effort })
|
||||
@@ -135,7 +139,7 @@ it.effect("Moonshot validates native Chat thinking options", () =>
|
||||
.chat("kimi-k2.6")
|
||||
.route.with({ providerOptions: { thinking: { type: "enabled", keep: 42 } } })
|
||||
.model({ id: "kimi-k2.6" })
|
||||
const failure = yield* compileRequest(ai.request({ model: invalid })).pipe(Effect.flip)
|
||||
const failure = yield* compileRequest(ai.request({ model: invalid, prompt: "Hello" })).pipe(Effect.flip)
|
||||
expect(failure.reason._tag).toBe("InvalidRequest")
|
||||
expect(failure.message).toContain("keep")
|
||||
}),
|
||||
|
||||
@@ -180,6 +180,7 @@ describe("Open Responses-compatible route", () => {
|
||||
const prepared = yield* compileRequest(
|
||||
ai.request({
|
||||
model,
|
||||
prompt: "Hello",
|
||||
tools: [
|
||||
{
|
||||
type: "namespace",
|
||||
|
||||
@@ -223,6 +223,7 @@ describe("OpenAI Responses route", () => {
|
||||
const prepared = yield* compileRequest(
|
||||
ai.request({
|
||||
model,
|
||||
prompt: "Hello",
|
||||
tools: [
|
||||
{
|
||||
type: "namespace",
|
||||
@@ -265,6 +266,7 @@ describe("OpenAI Responses route", () => {
|
||||
const prepared = yield* compileRequest(
|
||||
ai.request({
|
||||
model,
|
||||
prompt: "Hello",
|
||||
tools: [
|
||||
{
|
||||
type: "namespace",
|
||||
|
||||
@@ -53,6 +53,7 @@ it.effect("Venice lowers typed options, model defaults, and explicit reasoning o
|
||||
model: Venice.configure({ apiKey: "fixture", providerOptions: { reasoningEffort: "low" } }).model(
|
||||
"qwen3-6-27b",
|
||||
),
|
||||
prompt: "Hello",
|
||||
generation: { maxTokens: 200, topK: 20 },
|
||||
providerOptions: {
|
||||
reasoningEffort: "future-effort",
|
||||
@@ -97,10 +98,12 @@ it.effect("Venice lowers typed options, model defaults, and explicit reasoning o
|
||||
expect(compiled.body.reasoning_effort).toBeUndefined()
|
||||
expect(compiled.body.max_tokens).toBeUndefined()
|
||||
expect(
|
||||
(yield* compileRequest(ai.request({ model, providerOptions: { reasoning: { enabled: false } } }))).body.reasoning,
|
||||
(yield* compileRequest(
|
||||
ai.request({ model, prompt: "Hello", providerOptions: { reasoning: { enabled: false } } }),
|
||||
)).body.reasoning,
|
||||
).toEqual({ enabled: false })
|
||||
expect(
|
||||
(yield* compileRequest(ai.request({ model, cache: "none", promptCacheKey: "session-123" }))).body
|
||||
(yield* compileRequest(ai.request({ model, prompt: "Hello", cache: "none", promptCacheKey: "session-123" }))).body
|
||||
.prompt_cache_key,
|
||||
).toBeUndefined()
|
||||
}),
|
||||
|
||||
@@ -106,6 +106,7 @@ it.effect("ZAI Chat retains native thinking fields and scopes tool streaming to
|
||||
const result = yield* compileRequest(
|
||||
ai.request({
|
||||
model: provider.chat("glm-5.2"),
|
||||
prompt: "Hello",
|
||||
providerOptions: {
|
||||
thinking,
|
||||
toolStream: false,
|
||||
@@ -160,18 +161,23 @@ it.effect("ZAI lowers effort using the selected native API without inventing thi
|
||||
const standard = yield* compileRequest(
|
||||
ai.request({
|
||||
model: ZAI.configure({ apiKey: "fixture" }).chat("glm-5.3"),
|
||||
prompt: "Hello",
|
||||
providerOptions: { reasoningEffort: effort },
|
||||
}),
|
||||
)
|
||||
const coding = ZAICodingPlan.configure({ apiKey: "fixture" })
|
||||
const chat = yield* compileRequest(
|
||||
ai.request({ model: coding.chat("glm-5.3"), providerOptions: { reasoningEffort: effort } }),
|
||||
ai.request({ model: coding.chat("glm-5.3"), prompt: "Hello", providerOptions: { reasoningEffort: effort } }),
|
||||
)
|
||||
const messages = yield* compileRequest(
|
||||
ai.request({ model: coding.messages("glm-5.3"), providerOptions: { effort } }),
|
||||
ai.request({ model: coding.messages("glm-5.3"), prompt: "Hello", providerOptions: { effort } }),
|
||||
)
|
||||
const responses = yield* compileRequest(
|
||||
ai.request({ model: coding.responses("glm-5.3"), providerOptions: { reasoningEffort: effort } }),
|
||||
ai.request({
|
||||
model: coding.responses("glm-5.3"),
|
||||
prompt: "Hello",
|
||||
providerOptions: { reasoningEffort: effort },
|
||||
}),
|
||||
)
|
||||
expect(standard.body.reasoning_effort).toBe(effort)
|
||||
expect(chat.body.reasoning_effort).toBe(effort)
|
||||
@@ -185,6 +191,7 @@ it.effect("ZAI lowers effort using the selected native API without inventing thi
|
||||
model: ZAICodingPlan.configure({ apiKey: "fixture", providerOptions: { thinking: { type } } }).messages(
|
||||
"glm-5.3",
|
||||
),
|
||||
prompt: "Hello",
|
||||
}),
|
||||
)
|
||||
expect(result.body.thinking).toEqual({ type })
|
||||
@@ -230,7 +237,7 @@ it.effect("ZAI rejects invalid typed thinking options before execution", () =>
|
||||
.chat("glm-5.3")
|
||||
.route.with({ providerOptions: { thinking: { clear_thinking: "false" } } })
|
||||
.model({ id: "glm-5.3" })
|
||||
const error = yield* compileRequest(ai.request({ model })).pipe(Effect.flip)
|
||||
const error = yield* compileRequest(ai.request({ model, prompt: "Hello" })).pipe(Effect.flip)
|
||||
expect(error.reason._tag).toBe("InvalidRequest")
|
||||
expect(error.message).toContain("clear_thinking")
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user