mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-19 08:39:02 +03:00
refactor(ai): replace model and route defaults with model options (#61494)
This commit is contained in:
committed by
GitHub
Unverified
parent
6666acc12c
commit
e6e6a5152b
@@ -85,11 +85,7 @@ const observer = (options: Options) => {
|
||||
if (event.type === "response.created") {
|
||||
const created = event.response?.id
|
||||
if (responseID)
|
||||
return yield* ProviderShared.eventError(
|
||||
options.id,
|
||||
`${options.name} emitted duplicate response.created`,
|
||||
frame,
|
||||
)
|
||||
return yield* ProviderShared.eventError(options.id, `${options.name} emitted duplicate response.created`, frame)
|
||||
if (!created)
|
||||
return yield* ProviderShared.eventError(
|
||||
options.id,
|
||||
@@ -108,11 +104,7 @@ const observer = (options: Options) => {
|
||||
frame,
|
||||
)
|
||||
if (event.response?.id && event.response.id !== responseID)
|
||||
return yield* ProviderShared.eventError(
|
||||
options.id,
|
||||
`${options.name} response ID changed during execution`,
|
||||
frame,
|
||||
)
|
||||
return yield* ProviderShared.eventError(options.id, `${options.name} response ID changed during execution`, frame)
|
||||
if (event.type === "response.completed") {
|
||||
terminal = true
|
||||
return { type: "completed", frame }
|
||||
|
||||
@@ -15,7 +15,7 @@ export const route = Route.make({
|
||||
protocol: OpenResponses.protocol,
|
||||
endpoint: Endpoint.path(OpenResponses.PATH),
|
||||
transport: OpenResponses.httpTransport,
|
||||
defaults: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
|
||||
options: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
|
||||
})
|
||||
|
||||
export * as OpenAICompatibleResponses from "./openai-compatible-responses.js"
|
||||
|
||||
@@ -360,7 +360,7 @@ export const route = Route.make({
|
||||
endpoint,
|
||||
auth,
|
||||
transport,
|
||||
defaults: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
|
||||
options: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
|
||||
})
|
||||
|
||||
export * as OpenAIResponses from "./openai-responses.js"
|
||||
|
||||
@@ -5,7 +5,7 @@ import { AlibabaImages } from "../protocols/alibaba-images.js"
|
||||
import { AlibabaMessages } from "../protocols/alibaba-messages.js"
|
||||
import { AlibabaResponses } from "../protocols/alibaba-responses.js"
|
||||
import { AuthOptions, type AtLeastOne, type ProviderAuthOption } from "../route/auth-options.js"
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Route } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { Framing } from "../route/framing.js"
|
||||
import { MediaRoute } from "../route/media.js"
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
ToolDefinition,
|
||||
type ModelID,
|
||||
type ProviderOptions,
|
||||
type RequestOptions,
|
||||
} from "../schema/index.js"
|
||||
|
||||
export const id = ProviderID.make("alibaba")
|
||||
@@ -39,7 +40,7 @@ type Location = AtLeastOne<{
|
||||
}> & { readonly workspaceID?: string }
|
||||
|
||||
export type Config = Location &
|
||||
Omit<RouteDefaultsInput, "providerOptions"> &
|
||||
Omit<RequestOptions, "providerOptions"> &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
readonly providerOptions?: ChatOptionsInput | MessagesOptionsInput | ResponsesOptionsInput
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Route } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import { AnthropicMessages } from "../protocols/anthropic-messages.js"
|
||||
@@ -6,7 +6,7 @@ import { OpenAIChat } from "../protocols/openai-chat.js"
|
||||
import { OpenResponses } from "../protocols/open-responses.js"
|
||||
import { BedrockAuth, type Credentials } from "../protocols/utils/bedrock-auth.js"
|
||||
import { claudeVersion } from "../protocols/utils/claude-model.js"
|
||||
import { ProviderConfigurationError, ProviderID, type ModelID } from "../schema/index.js"
|
||||
import { ProviderConfigurationError, ProviderID, type ModelID, type RequestOptions } from "../schema/index.js"
|
||||
import { withOpenAIOptions, type OpenAIProviderOptionsInput } from "./openai-options.js"
|
||||
|
||||
export const id = ProviderID.make("amazon-bedrock")
|
||||
@@ -14,7 +14,7 @@ export const id = ProviderID.make("amazon-bedrock")
|
||||
export type OpenAIOptionsInput = OpenAIProviderOptionsInput
|
||||
export type MessagesOptionsInput = AnthropicMessages.ProviderOptionsInput
|
||||
|
||||
export type Config = Omit<RouteDefaultsInput, "providerOptions"> & {
|
||||
export type Config = Omit<RequestOptions, "providerOptions"> & {
|
||||
/** Bedrock API key. Falls back to `AWS_BEARER_TOKEN_BEDROCK`; bearer auth takes precedence over SigV4. */
|
||||
readonly apiKey?: string
|
||||
/** `sigv4` ignores `apiKey` fallbacks from the environment; `bearer` requires a token. */
|
||||
@@ -55,7 +55,7 @@ const responsesRoute = Route.make({
|
||||
protocol: OpenResponses.protocol,
|
||||
endpoint: Endpoint.path(OpenResponses.PATH),
|
||||
transport: OpenResponses.httpTransport,
|
||||
defaults: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
|
||||
options: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
|
||||
})
|
||||
|
||||
const chatRoute = OpenAIChat.route.with({
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import type { RouteDefaultsInput } from "../route/client.js"
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import { ProviderConfigurationError, ProviderID, type ModelID } from "../schema/index.js"
|
||||
import { ProviderConfigurationError, ProviderID, type ModelID, type RequestOptions } from "../schema/index.js"
|
||||
import * as BedrockConverse from "../protocols/bedrock-converse.js"
|
||||
import type { BedrockCredentials } from "../protocols/bedrock-converse.js"
|
||||
import { BedrockAuth } from "../protocols/utils/bedrock-auth.js"
|
||||
|
||||
export const id = ProviderID.make("amazon-bedrock")
|
||||
|
||||
export type Config = RouteDefaultsInput & {
|
||||
export type Config = RequestOptions & {
|
||||
/** Bedrock API key. Falls back to `AWS_BEARER_TOKEN_BEDROCK`; bearer auth takes precedence over SigV4. */
|
||||
readonly apiKey?: string
|
||||
/** `sigv4` ignores `apiKey` fallbacks from the environment; `bearer` requires a token. */
|
||||
|
||||
@@ -2,8 +2,7 @@ import type { ProviderPackage } from "../provider-package.js"
|
||||
import { AnthropicMessages } from "../protocols/anthropic-messages.js"
|
||||
import { Auth } from "../route/auth.js"
|
||||
import { AuthOptions, type ProviderAuthOption } from "../route/auth-options.js"
|
||||
import type { RouteDefaultsInput } from "../route/client.js"
|
||||
import { ProviderConfigurationError, ProviderID, type ModelID } from "../schema/index.js"
|
||||
import { ProviderConfigurationError, ProviderID, type ModelID, type RequestOptions } from "../schema/index.js"
|
||||
|
||||
export type AnthropicOptionsInput = AnthropicMessages.OptionsInput
|
||||
export type AnthropicProviderOptionsInput = AnthropicMessages.ProviderOptionsInput
|
||||
@@ -11,7 +10,7 @@ export type AnthropicThinkingInput = AnthropicMessages.ThinkingInput
|
||||
|
||||
export const id = ProviderID.make("anthropic-compatible")
|
||||
|
||||
export type Config = RouteDefaultsInput &
|
||||
export type Config = RequestOptions &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
readonly provider?: string
|
||||
readonly baseURL: string
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import type { RouteDefaultsInput } from "../route/client.js"
|
||||
import { Auth } from "../route/auth.js"
|
||||
import { AuthOptions, type ProviderAuthOption } from "../route/auth-options.js"
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import { ProviderConfigurationError, ProviderID, type ModelID } from "../schema/index.js"
|
||||
import { ProviderConfigurationError, ProviderID, type ModelID, type RequestOptions } from "../schema/index.js"
|
||||
import { AnthropicMessages } from "../protocols/anthropic-messages.js"
|
||||
import { AnthropicCompatible } from "./anthropic-compatible.js"
|
||||
|
||||
@@ -14,7 +13,7 @@ export const id = ProviderID.make("anthropic")
|
||||
|
||||
export const routes = [AnthropicMessages.route]
|
||||
|
||||
export type Config = RouteDefaultsInput &
|
||||
export type Config = RequestOptions &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
readonly baseURL?: string
|
||||
readonly providerOptions?: AnthropicMessages.ProviderOptionsInput
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import { Auth } from "../route/auth.js"
|
||||
import { AuthOptions, type AtLeastOne, type ProviderAuthOption } from "../route/auth-options.js"
|
||||
import type { Route, RouteDefaultsInput, CompactionOperations } from "../route/client.js"
|
||||
import type { Route, CompactionOperations } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import { MediaRoute } from "../route/media.js"
|
||||
import { ProviderConfigurationError, ProviderID, type ModelID, type ProviderOptions } from "../schema/index.js"
|
||||
import {
|
||||
ProviderConfigurationError,
|
||||
ProviderID,
|
||||
type ModelID,
|
||||
type ProviderOptions,
|
||||
type RequestOptions,
|
||||
} from "../schema/index.js"
|
||||
import { AnthropicMessages } from "../protocols/anthropic-messages.js"
|
||||
import { OpenAIImages } from "../protocols/openai-images.js"
|
||||
import * as OpenAIChat from "../protocols/openai-chat.js"
|
||||
@@ -20,7 +26,7 @@ const RESPONSES_WEBSOCKET_ROTATE_AFTER_MS = 55 * 60 * 1000
|
||||
type AzureURL = AtLeastOne<{ readonly resourceName: string; readonly baseURL: string }>
|
||||
|
||||
export type Config = AzureURL &
|
||||
RouteDefaultsInput &
|
||||
RequestOptions &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
readonly apiVersion?: string
|
||||
readonly queryParams?: Record<string, string>
|
||||
|
||||
@@ -3,17 +3,17 @@ import type { ProviderPackage } from "../provider-package.js"
|
||||
import { OpenAIChat } from "../protocols/openai-chat.js"
|
||||
import { SystemOne } from "../protocols/system-one.js"
|
||||
import type { ProviderAuthOption } from "../route/auth-options.js"
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Route } from "../route/client.js"
|
||||
import { DecisionRoute } from "../route/decision.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { ProviderID, type ModelID, type ProviderOptions } from "../schema/index.js"
|
||||
import { ProviderID, type ModelID, type ProviderOptions, type RequestOptions } from "../schema/index.js"
|
||||
import type { OpenAIProviderOptionsInput } from "./openai-options.js"
|
||||
import { bearerRouteDefaults, toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("baseten")
|
||||
const baseURL = "https://inference.baseten.co/v1"
|
||||
|
||||
export type Config = Omit<RouteDefaultsInput, "providerOptions"> &
|
||||
export type Config = Omit<RequestOptions, "providerOptions"> &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
readonly baseURL?: string
|
||||
readonly providerOptions?: OpenAIProviderOptionsInput
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import { OpenAIChat } from "../protocols/openai-chat.js"
|
||||
import type { ProviderAuthOption } from "../route/auth-options.js"
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Route } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { ProviderID, type ModelID } from "../schema/index.js"
|
||||
import { ProviderID, type ModelID, type RequestOptions } from "../schema/index.js"
|
||||
import type { OpenAIProviderOptionsInput } from "./openai-options.js"
|
||||
import { bearerRouteDefaults, toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("cerebras")
|
||||
const baseURL = "https://api.cerebras.ai/v1"
|
||||
|
||||
export type Config = Omit<RouteDefaultsInput, "providerOptions"> &
|
||||
export type Config = Omit<RequestOptions, "providerOptions"> &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
readonly baseURL?: string
|
||||
readonly providerOptions?: OpenAIProviderOptionsInput
|
||||
|
||||
@@ -4,8 +4,7 @@ import { CloudflareRunDecisions } from "../protocols/cloudflare-run-decisions.js
|
||||
import { AnthropicMessages, OpenAIChat, OpenAIResponses } from "../protocols/index.js"
|
||||
import { Auth } from "../route/auth.js"
|
||||
import { AuthOptions, type AtLeastOne, type ProviderAuthOption } from "../route/auth-options.js"
|
||||
import type { RouteDefaultsInput } from "../route/client.js"
|
||||
import { ProviderID, type ModelID, type ProviderOptions } from "../schema/index.js"
|
||||
import { ProviderID, type ModelID, type ProviderOptions, type RequestOptions } from "../schema/index.js"
|
||||
import { encodeJson } from "../utils/json.js"
|
||||
import type { OpenAIProviderOptionsInput } from "./openai-options.js"
|
||||
import { CloudflareShared } from "./cloudflare-shared.js"
|
||||
@@ -29,7 +28,7 @@ type GatewayOptions = {
|
||||
|
||||
export type Config = GatewayURL &
|
||||
GatewayOptions &
|
||||
Omit<RouteDefaultsInput, "providerOptions"> &
|
||||
Omit<RequestOptions, "providerOptions"> &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
readonly gatewayApiKey?: string | Redacted.Redacted | Config.Config<string | Redacted.Redacted>
|
||||
readonly providerOptions?: OpenAIProviderOptionsInput
|
||||
|
||||
@@ -4,10 +4,10 @@ import { CloudflareRunDecisions } from "../protocols/cloudflare-run-decisions.js
|
||||
import { CloudflareWorkersAIImages } from "../protocols/cloudflare-workers-ai-images.js"
|
||||
import { OpenAIChat } from "../protocols/openai-chat.js"
|
||||
import { AuthOptions, type AtLeastOne, type ProviderAuthOption } from "../route/auth-options.js"
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Route } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { MediaRoute } from "../route/media.js"
|
||||
import { ProviderID, type ModelID, type ProviderOptions } from "../schema/index.js"
|
||||
import { ProviderID, type ModelID, type ProviderOptions, type RequestOptions } from "../schema/index.js"
|
||||
import type { OpenAIProviderOptionsInput } from "./openai-options.js"
|
||||
import { CloudflareShared } from "./cloudflare-shared.js"
|
||||
|
||||
@@ -20,7 +20,7 @@ type WorkersAIURL = AtLeastOne<{
|
||||
}>
|
||||
|
||||
export type Config = WorkersAIURL &
|
||||
Omit<RouteDefaultsInput, "providerOptions"> &
|
||||
Omit<RequestOptions, "providerOptions"> &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
readonly providerOptions?: OpenAIProviderOptionsInput
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { CohereChat } from "../protocols/cohere-chat.js"
|
||||
import { OpenAIChat } from "../protocols/openai-chat.js"
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Route } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import type { ProviderAuthOption } from "../route/auth-options.js"
|
||||
import { ProviderID, type ModelID, type OpenString } from "../schema/index.js"
|
||||
import { ProviderID, type ModelID, type OpenString, type RequestOptions } from "../schema/index.js"
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import { bearerRouteDefaults, toConfig } from "./settings.js"
|
||||
|
||||
@@ -11,7 +11,7 @@ export const id = ProviderID.make("cohere")
|
||||
const COMPATIBILITY_BASE_URL = "https://api.cohere.ai/compatibility/v1"
|
||||
export type ChatOptionsInput = { readonly reasoningEffort?: OpenString<"none" | "high"> }
|
||||
export type ProviderOptions = CohereChat.ProviderOptionsInput & ChatOptionsInput
|
||||
export type Config = Omit<RouteDefaultsInput, "providerOptions"> &
|
||||
export type Config = Omit<RequestOptions, "providerOptions"> &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
readonly baseURL?: string
|
||||
readonly providerOptions?: ProviderOptions
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import { OpenAIChat } from "../protocols/openai-chat.js"
|
||||
import type { ProviderAuthOption } from "../route/auth-options.js"
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Route } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { ProviderID, type ModelID } from "../schema/index.js"
|
||||
import { ProviderID, type ModelID, type RequestOptions } from "../schema/index.js"
|
||||
import type { OpenAIProviderOptionsInput } from "./openai-options.js"
|
||||
import { bearerRouteDefaults, toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("deepinfra")
|
||||
const baseURL = "https://api.deepinfra.com/v1/openai"
|
||||
|
||||
export type Config = Omit<RouteDefaultsInput, "providerOptions"> &
|
||||
export type Config = Omit<RequestOptions, "providerOptions"> &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
readonly baseURL?: string
|
||||
readonly providerOptions?: OpenAIProviderOptionsInput
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import { OpenAIChat } from "../protocols/openai-chat.js"
|
||||
import type { ProviderAuthOption } from "../route/auth-options.js"
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Route } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { ProviderID, type ModelID } from "../schema/index.js"
|
||||
import { ProviderID, type ModelID, type RequestOptions } from "../schema/index.js"
|
||||
import type { OpenAIProviderOptionsInput } from "./openai-options.js"
|
||||
import { bearerRouteDefaults, toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("deepseek")
|
||||
const baseURL = "https://api.deepseek.com/v1"
|
||||
|
||||
export type Config = Omit<RouteDefaultsInput, "providerOptions"> &
|
||||
export type Config = Omit<RequestOptions, "providerOptions"> &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
readonly baseURL?: string
|
||||
readonly providerOptions?: OpenAIProviderOptionsInput
|
||||
|
||||
@@ -5,11 +5,11 @@ import { OpenResponses } from "../protocols/open-responses.js"
|
||||
import { SystemOne } from "../protocols/system-one.js"
|
||||
import { cacheControl } from "../protocols/utils/cache.js"
|
||||
import type { ProviderAuthOption } from "../route/auth-options.js"
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Route } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { MediaRoute } from "../route/media.js"
|
||||
import { Protocol } from "../route/protocol.js"
|
||||
import { ProviderID, type ModelID, type ProviderOptions } from "../schema/index.js"
|
||||
import { ProviderID, type ModelID, type ProviderOptions, type RequestOptions } from "../schema/index.js"
|
||||
import type { OpenAIProviderOptionsInput } from "./openai-options.js"
|
||||
import type { OpenResponsesProviderOptionsInput } from "./open-responses-options.js"
|
||||
import { bearerRouteDefaults } from "./settings.js"
|
||||
@@ -17,7 +17,7 @@ import { bearerRouteDefaults } from "./settings.js"
|
||||
export const id = ProviderID.make("digitalocean")
|
||||
const baseURL = "https://inference.do-ai.run/v1"
|
||||
|
||||
export type Config = Omit<RouteDefaultsInput, "providerOptions"> &
|
||||
export type Config = Omit<RequestOptions, "providerOptions"> &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
readonly baseURL?: string
|
||||
readonly providerOptions?: OpenAIProviderOptionsInput | OpenResponsesProviderOptionsInput
|
||||
@@ -51,7 +51,7 @@ const responsesRoute = Route.make({
|
||||
protocol: OpenResponses.protocol,
|
||||
endpoint: Endpoint.path("/responses", { baseURL }),
|
||||
transport: OpenResponses.httpTransport,
|
||||
defaults: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
|
||||
options: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
|
||||
})
|
||||
|
||||
export const routes = [route, responsesRoute]
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import { OpenAIChat } from "../protocols/openai-chat.js"
|
||||
import type { ProviderAuthOption } from "../route/auth-options.js"
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Route } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { ProviderID, type ModelID } from "../schema/index.js"
|
||||
import { ProviderID, type ModelID, type RequestOptions } from "../schema/index.js"
|
||||
import type { OpenAIProviderOptionsInput } from "./openai-options.js"
|
||||
import { bearerRouteDefaults, toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("fireworks")
|
||||
const baseURL = "https://api.fireworks.ai/inference/v1"
|
||||
|
||||
export type Config = Omit<RouteDefaultsInput, "providerOptions"> &
|
||||
export type Config = Omit<RequestOptions, "providerOptions"> &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
readonly baseURL?: string
|
||||
readonly providerOptions?: OpenAIProviderOptionsInput
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import { OpenAIChat } from "../protocols/openai-chat.js"
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Route } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { ProviderID, type ModelID } from "../schema/index.js"
|
||||
import { ProviderID, type ModelID, type RequestOptions } from "../schema/index.js"
|
||||
import { GoogleVertexShared } from "./google-vertex-shared.js"
|
||||
import type { OpenAIProviderOptionsInput } from "./openai-options.js"
|
||||
|
||||
export const id = ProviderID.make("google-vertex")
|
||||
|
||||
export type Config = RouteDefaultsInput &
|
||||
export type Config = RequestOptions &
|
||||
GoogleVertexShared.OAuthOptions & {
|
||||
readonly baseURL?: string
|
||||
readonly location?: string
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import { GoogleInteractions } from "../protocols/google-interactions.js"
|
||||
import { Auth } from "../route/auth.js"
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Route } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { Framing } from "../route/framing.js"
|
||||
import { ProviderConfigurationError, ProviderID, type ModelID } from "../schema/index.js"
|
||||
import { ProviderConfigurationError, ProviderID, type ModelID, type RequestOptions } from "../schema/index.js"
|
||||
import { GoogleVertexShared } from "./google-vertex-shared.js"
|
||||
|
||||
export type GoogleInteractionsOptionsInput = GoogleInteractions.OptionsInput
|
||||
|
||||
export const id = ProviderID.make("google-vertex")
|
||||
|
||||
export type Config = RouteDefaultsInput &
|
||||
export type Config = RequestOptions &
|
||||
GoogleVertexShared.ApiKeyOptions & {
|
||||
readonly baseURL?: string
|
||||
readonly location?: string
|
||||
|
||||
@@ -2,10 +2,10 @@ import { Effect, Schema, Struct } from "effect"
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import { AnthropicMessages } from "../protocols/anthropic-messages.js"
|
||||
import { Auth } from "../route/auth.js"
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Route } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { Protocol } from "../route/protocol.js"
|
||||
import { ProviderID, type ModelID } from "../schema/index.js"
|
||||
import { ProviderID, type ModelID, type RequestOptions } from "../schema/index.js"
|
||||
import { GoogleVertexShared } from "./google-vertex-shared.js"
|
||||
|
||||
export type AnthropicOptionsInput = AnthropicMessages.OptionsInput
|
||||
@@ -17,7 +17,7 @@ const HEADER_VERSION = "2023-06-01" as const
|
||||
|
||||
export const id = ProviderID.make("google-vertex")
|
||||
|
||||
export type Config = RouteDefaultsInput &
|
||||
export type Config = RequestOptions &
|
||||
GoogleVertexShared.OAuthOptions & {
|
||||
readonly baseURL?: string
|
||||
readonly location?: string
|
||||
|
||||
@@ -2,16 +2,16 @@ import { Effect, Schema, Struct } from "effect"
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import { MistralChat } from "../protocols/mistral-chat.js"
|
||||
import { Auth } from "../route/auth.js"
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Route } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { Protocol } from "../route/protocol.js"
|
||||
import { HttpTransport } from "../route/transport/index.js"
|
||||
import { ProviderID, type ModelID } from "../schema/index.js"
|
||||
import { ProviderID, type ModelID, type RequestOptions } from "../schema/index.js"
|
||||
import { GoogleVertexShared } from "./google-vertex-shared.js"
|
||||
|
||||
export const id = ProviderID.make("google-vertex")
|
||||
|
||||
export type Config = RouteDefaultsInput &
|
||||
export type Config = RequestOptions &
|
||||
GoogleVertexShared.OAuthOptions & {
|
||||
readonly baseURL?: string
|
||||
readonly location?: string
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import { OpenResponses } from "../protocols/open-responses.js"
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Route } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { ProviderID, type ModelID } from "../schema/index.js"
|
||||
import { ProviderID, type ModelID, type RequestOptions } from "../schema/index.js"
|
||||
import { GoogleVertexShared } from "./google-vertex-shared.js"
|
||||
import type { OpenResponsesProviderOptionsInput } from "./open-responses-options.js"
|
||||
|
||||
export const id = ProviderID.make("google-vertex")
|
||||
|
||||
export type Config = RouteDefaultsInput &
|
||||
export type Config = RequestOptions &
|
||||
GoogleVertexShared.OAuthOptions & {
|
||||
readonly baseURL?: string
|
||||
readonly location?: string
|
||||
@@ -32,7 +32,7 @@ const route = Route.make({
|
||||
protocol: OpenResponses.protocol,
|
||||
endpoint: Endpoint.path(OpenResponses.PATH),
|
||||
transport: OpenResponses.httpTransport,
|
||||
defaults: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
|
||||
options: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
|
||||
})
|
||||
|
||||
export const routes = [route]
|
||||
|
||||
@@ -2,8 +2,8 @@ import type { AnyAuthClient, GoogleAuthOptions } from "google-auth-library"
|
||||
import { Effect, Redacted } from "effect"
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import { Auth, MissingCredentialError } from "../route/auth.js"
|
||||
import type { CompactionOperations, Route, RouteDefaultsInput } from "../route/client.js"
|
||||
import { ProviderConfigurationError, ProviderID } from "../schema/index.js"
|
||||
import type { CompactionOperations, Route } from "../route/client.js"
|
||||
import { ProviderConfigurationError, ProviderID, type RequestOptions } from "../schema/index.js"
|
||||
|
||||
const SCOPE = "https://www.googleapis.com/auth/cloud-platform"
|
||||
const id = ProviderID.make("google-vertex")
|
||||
@@ -117,7 +117,7 @@ export const oauth = (input: OAuthOptions, project?: string) => {
|
||||
export const oauthRoute = <Body, Prepared, Compact extends CompactionOperations | undefined>(
|
||||
route: Route<Body, Prepared, Compact>,
|
||||
label: string,
|
||||
input: RouteDefaultsInput &
|
||||
input: RequestOptions &
|
||||
OAuthOptions & { readonly baseURL?: string; readonly location?: string; readonly project?: string },
|
||||
url: (project: string, location: string) => string,
|
||||
) => {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Gemini } from "../protocols/gemini.js"
|
||||
import { GoogleImages } from "../protocols/google-images.js"
|
||||
import { ProviderShared } from "../protocols/shared.js"
|
||||
import { Auth } from "../route/auth.js"
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Route } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { MediaRoute } from "../route/media.js"
|
||||
import {
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
type LLMRequest,
|
||||
type ModelID,
|
||||
type ProviderOptions,
|
||||
type RequestOptions,
|
||||
} from "../schema/index.js"
|
||||
import { GoogleVertexShared } from "./google-vertex-shared.js"
|
||||
|
||||
@@ -24,7 +25,7 @@ export type GeminiProviderOptionsInput = GeminiOptionsInput
|
||||
|
||||
export const id = ProviderID.make("google-vertex")
|
||||
|
||||
export type Config = RouteDefaultsInput &
|
||||
export type Config = RequestOptions &
|
||||
GoogleVertexShared.ApiKeyOptions & {
|
||||
readonly baseURL?: string
|
||||
readonly location?: string
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import type { RouteDefaultsInput } from "../route/client.js"
|
||||
import { Auth } from "../route/auth.js"
|
||||
import { AuthOptions, type ProviderAuthOption } from "../route/auth-options.js"
|
||||
import { MediaRoute } from "../route/media.js"
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import { ProviderID, type ModelID, type ProviderOptions } from "../schema/index.js"
|
||||
import { ProviderID, type ModelID, type ProviderOptions, type RequestOptions } from "../schema/index.js"
|
||||
import { Gemini } from "../protocols/gemini.js"
|
||||
import { GoogleInteractions } from "../protocols/google-interactions.js"
|
||||
import { GoogleImages } from "../protocols/google-images.js"
|
||||
@@ -24,7 +23,7 @@ export const id = ProviderID.make("google")
|
||||
|
||||
export const routes = [Gemini.route, GoogleInteractions.route]
|
||||
|
||||
export type Config = RouteDefaultsInput &
|
||||
export type Config = RequestOptions &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
readonly baseURL?: string
|
||||
readonly providerOptions?: Gemini.ProviderOptionsInput & GoogleInteractions.ProviderOptionsInput
|
||||
|
||||
@@ -3,10 +3,10 @@ import type { ProviderPackage } from "../provider-package.js"
|
||||
import { OpenAIChat } from "../protocols/openai-chat.js"
|
||||
import { ProviderShared } from "../protocols/shared.js"
|
||||
import type { ProviderAuthOption } from "../route/auth-options.js"
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Route } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { Protocol } from "../route/protocol.js"
|
||||
import { ProviderID, type ModelID, type LLMRequest } from "../schema/index.js"
|
||||
import { ProviderID, type ModelID, type LLMRequest, type RequestOptions } from "../schema/index.js"
|
||||
import type { OpenAIProviderOptionsInput } from "./openai-options.js"
|
||||
import { bearerRouteDefaults, toConfig } from "./settings.js"
|
||||
|
||||
@@ -21,7 +21,7 @@ export type ProviderOptions = Pick<OpenAIProviderOptionsInput, "reasoningEffort"
|
||||
readonly user?: string
|
||||
}
|
||||
|
||||
export type Config = Omit<RouteDefaultsInput, "providerOptions"> &
|
||||
export type Config = Omit<RequestOptions, "providerOptions"> &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
readonly baseURL?: string
|
||||
readonly providerOptions?: ProviderOptions
|
||||
|
||||
@@ -5,10 +5,10 @@ import { MetaResponses } from "../protocols/meta-responses.js"
|
||||
import { MetaMessages } from "../protocols/meta-messages.js"
|
||||
import { MetaImages } from "../protocols/meta-images.js"
|
||||
import type { ProviderAuthOption } from "../route/auth-options.js"
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Route } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { MediaRoute } from "../route/media.js"
|
||||
import { ProviderID, ToolDefinition, type ModelID, type OpenString } from "../schema/index.js"
|
||||
import { ProviderID, ToolDefinition, type ModelID, type OpenString, type RequestOptions } from "../schema/index.js"
|
||||
import type { OpenResponsesProviderOptionsInput } from "./open-responses-options.js"
|
||||
import { bearerRouteDefaults, toConfig } from "./settings.js"
|
||||
|
||||
@@ -75,7 +75,7 @@ export const imageGeneration = (options: ImageGenerationOptions = {}) =>
|
||||
},
|
||||
})
|
||||
|
||||
export type Config = Omit<RouteDefaultsInput, "providerOptions"> &
|
||||
export type Config = Omit<RequestOptions, "providerOptions"> &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
readonly baseURL?: string
|
||||
readonly providerOptions?: ProviderOptionsInput
|
||||
@@ -95,7 +95,7 @@ const responsesRoute = Route.make({
|
||||
endpoint: Endpoint.path("/responses", { baseURL }),
|
||||
// Meta Responses does not support WebSocket upgrades; always use HTTP/SSE.
|
||||
transport: MetaResponses.httpTransport,
|
||||
defaults: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
|
||||
options: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
|
||||
})
|
||||
|
||||
const chatRoute = Route.make({
|
||||
@@ -114,7 +114,7 @@ const messagesRoute = Route.make({
|
||||
protocol: MetaMessages.protocol,
|
||||
endpoint: Endpoint.path("/messages", { baseURL }),
|
||||
framing: AnthropicMessages.framing,
|
||||
defaults: { providerOptions: { thinking: { type: "adaptive", display: "omitted" } } },
|
||||
options: { providerOptions: { thinking: { type: "adaptive", display: "omitted" } } },
|
||||
})
|
||||
|
||||
export const routes = [responsesRoute, chatRoute, messagesRoute]
|
||||
|
||||
@@ -6,12 +6,18 @@ import { OpenAIChat } from "../protocols/openai-chat.js"
|
||||
import { OpenResponses } from "../protocols/open-responses.js"
|
||||
import { ProviderShared } from "../protocols/shared.js"
|
||||
import type { ProviderAuthOption } from "../route/auth-options.js"
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Route } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { Framing } from "../route/framing.js"
|
||||
import { MediaRoute } from "../route/media.js"
|
||||
import { Protocol } from "../route/protocol.js"
|
||||
import { ProviderID, type LLMRequest, type ModelID, type ProviderOptions } from "../schema/index.js"
|
||||
import {
|
||||
ProviderID,
|
||||
type LLMRequest,
|
||||
type ModelID,
|
||||
type ProviderOptions,
|
||||
type RequestOptions,
|
||||
} from "../schema/index.js"
|
||||
import { bearerRouteDefaults, toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("minimax")
|
||||
@@ -36,7 +42,7 @@ export type ResponsesOptionsInput = {
|
||||
|
||||
export type ProviderOptionsInput = MessagesOptionsInput | ChatOptionsInput | ResponsesOptionsInput
|
||||
|
||||
export type Config = Omit<RouteDefaultsInput, "providerOptions"> &
|
||||
export type Config = Omit<RequestOptions, "providerOptions"> &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
/** Overrides the selected API's base URL, including its version prefix. */
|
||||
readonly baseURL?: string
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import { MistralChat } from "../protocols/mistral-chat.js"
|
||||
import type { ProviderAuthOption } from "../route/auth-options.js"
|
||||
import type { RouteDefaultsInput } from "../route/client.js"
|
||||
import { ProviderID, type ModelID } from "../schema/index.js"
|
||||
import { ProviderID, type ModelID, type RequestOptions } from "../schema/index.js"
|
||||
import { bearerRouteDefaults, toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("mistral")
|
||||
|
||||
export type ProviderOptions = MistralChat.ProviderOptionsInput
|
||||
|
||||
export type Config = Omit<RouteDefaultsInput, "providerOptions"> &
|
||||
export type Config = Omit<RequestOptions, "providerOptions"> &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
readonly baseURL?: string
|
||||
readonly providerOptions?: ProviderOptions
|
||||
|
||||
@@ -5,11 +5,11 @@ import { OpenAIChat } from "../protocols/openai-chat.js"
|
||||
import { OpenResponses } from "../protocols/open-responses.js"
|
||||
import { ProviderShared } from "../protocols/shared.js"
|
||||
import type { ProviderAuthOption } from "../route/auth-options.js"
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Route } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { Framing } from "../route/framing.js"
|
||||
import { Protocol } from "../route/protocol.js"
|
||||
import { ProviderID, type LLMRequest, type ModelID } from "../schema/index.js"
|
||||
import { ProviderID, type LLMRequest, type ModelID, type RequestOptions } from "../schema/index.js"
|
||||
import { bearerRouteDefaults, toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("moonshotai")
|
||||
@@ -36,7 +36,7 @@ export type ResponsesOptionsInput = {
|
||||
readonly safetyIdentifier?: string
|
||||
}
|
||||
|
||||
export type Config = Omit<RouteDefaultsInput, "providerOptions"> &
|
||||
export type Config = Omit<RequestOptions, "providerOptions"> &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
/** Overrides the selected API's base URL, including its version prefix. */
|
||||
readonly baseURL?: string
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import { OpenAICompatibleResponses } from "../protocols/openai-compatible-responses.js"
|
||||
import { AuthOptions, type ProviderAuthOption } from "../route/auth-options.js"
|
||||
import type { RouteDefaultsInput } from "../route/client.js"
|
||||
import { ProviderID, type ModelID } from "../schema/index.js"
|
||||
import { ProviderID, type ModelID, type RequestOptions } from "../schema/index.js"
|
||||
import type { OpenResponsesProviderOptionsInput } from "./open-responses-options.js"
|
||||
import { toConfig } from "./settings.js"
|
||||
|
||||
@@ -10,7 +9,7 @@ export type { OpenResponsesOptionsInput, OpenResponsesProviderOptionsInput } fro
|
||||
|
||||
export const id = ProviderID.make("openai-compatible")
|
||||
|
||||
export type Config = RouteDefaultsInput &
|
||||
export type Config = RequestOptions &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
readonly provider?: string
|
||||
readonly baseURL: string
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
import { mergeProviderOptions, ProviderID, type ModelID, type ProviderOptions } from "../schema/index.js"
|
||||
import {
|
||||
mergeProviderOptions,
|
||||
ProviderID,
|
||||
type ModelID,
|
||||
type ProviderOptions,
|
||||
type RequestOptions,
|
||||
} from "../schema/index.js"
|
||||
import { OpenAICompatibleChat } from "../protocols/openai-compatible-chat.js"
|
||||
import { OpenAIImages } from "../protocols/openai-images.js"
|
||||
import { MediaRoute } from "../route/media.js"
|
||||
import type { RouteDefaultsInput } from "../route/client.js"
|
||||
import { AuthOptions, type ProviderAuthOption } from "../route/auth-options.js"
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import type { OpenAIProviderOptionsInput } from "./openai-options.js"
|
||||
@@ -10,7 +15,7 @@ import { toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("openai-compatible")
|
||||
|
||||
export type Config = Omit<RouteDefaultsInput, "providerOptions"> &
|
||||
export type Config = Omit<RequestOptions, "providerOptions"> &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
readonly provider?: string
|
||||
readonly baseURL: string
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
import { AuthOptions, type ProviderAuthOption } from "../route/auth-options.js"
|
||||
import type { Route, RouteDefaultsInput, CompactionOperations } from "../route/client.js"
|
||||
import type { Route, CompactionOperations } from "../route/client.js"
|
||||
import { MediaRoute } from "../route/media.js"
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import { ProviderID, ToolDefinition, type ModelID, type OpenString, type ProviderOptions } from "../schema/index.js"
|
||||
import {
|
||||
ProviderID,
|
||||
ToolDefinition,
|
||||
type ModelID,
|
||||
type OpenString,
|
||||
type ProviderOptions,
|
||||
type RequestOptions,
|
||||
} from "../schema/index.js"
|
||||
import * as OpenAIChat from "../protocols/openai-chat.js"
|
||||
import * as OpenAIResponses from "../protocols/openai-responses.js"
|
||||
import { withOpenAIOptions, type OpenAIProviderOptionsInput } from "./openai-options.js"
|
||||
@@ -24,7 +31,7 @@ export const routes = [OpenAIResponses.route, OpenAIChat.route]
|
||||
// This provider facade wraps the lower-level Responses and Chat model factories
|
||||
// with OpenAI-specific conveniences: typed options, API-key sugar, env fallback,
|
||||
// and default option normalization.
|
||||
export type Config = RouteDefaultsInput &
|
||||
export type Config = RequestOptions &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
readonly baseURL?: string
|
||||
readonly queryParams?: Record<string, string>
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
import { Effect, Schema } from "effect"
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Route } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { Protocol } from "../route/protocol.js"
|
||||
import type { ProviderAuthOption } from "../route/auth-options.js"
|
||||
import { ProviderID, type ModelID, type OpenString, type ProviderOptions } from "../schema/index.js"
|
||||
import {
|
||||
ProviderID,
|
||||
type ModelID,
|
||||
type OpenString,
|
||||
type ProviderOptions,
|
||||
type RequestOptions,
|
||||
} from "../schema/index.js"
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import { SystemOne } from "../protocols/system-one.js"
|
||||
import { OpenAIImages, type OpenAIImageSizing } from "../protocols/openai-images.js"
|
||||
@@ -87,7 +93,7 @@ export interface OpenRouterDecisionOptions {
|
||||
readonly user?: string
|
||||
}
|
||||
|
||||
export type Config = Omit<RouteDefaultsInput, "providerOptions"> &
|
||||
export type Config = Omit<RequestOptions, "providerOptions"> &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
readonly baseURL?: string
|
||||
readonly providerOptions?: OpenRouterProviderOptionsInput | OpenRouterResponsesProviderOptionsInput
|
||||
@@ -238,7 +244,7 @@ const responsesRoute = Route.make({
|
||||
protocol: responsesProtocol,
|
||||
endpoint: Endpoint.path("/responses", { baseURL }),
|
||||
transport: HttpTransport.sseJson.with<OpenRouterResponsesBody>(),
|
||||
defaults: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
|
||||
options: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
|
||||
})
|
||||
|
||||
export const routes = [route, responsesRoute]
|
||||
|
||||
@@ -31,7 +31,7 @@ export function toConfig({ apiKey, baseURL, body, headers, ...providerOptions }:
|
||||
type BearerInput = ProviderAuthOption<"optional"> & { readonly baseURL?: string }
|
||||
|
||||
/**
|
||||
* Turns provider config into route defaults with `Authorization: Bearer` auth. The endpoint falls back to
|
||||
* Turns provider config into route options with `Authorization: Bearer` auth. The endpoint falls back to
|
||||
* `baseURL` when given, otherwise it is left to the route.
|
||||
*/
|
||||
export function bearerRouteDefaults<Input extends BearerInput>(
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import { OpenAIChat } from "../protocols/openai-chat.js"
|
||||
import type { ProviderAuthOption } from "../route/auth-options.js"
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Route } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { ProviderID, type ModelID } from "../schema/index.js"
|
||||
import { ProviderID, type ModelID, type RequestOptions } from "../schema/index.js"
|
||||
import type { OpenAIProviderOptionsInput } from "./openai-options.js"
|
||||
import { bearerRouteDefaults, toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("togetherai")
|
||||
const baseURL = "https://api.together.xyz/v1"
|
||||
|
||||
export type Config = Omit<RouteDefaultsInput, "providerOptions"> &
|
||||
export type Config = Omit<RequestOptions, "providerOptions"> &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
readonly baseURL?: string
|
||||
readonly providerOptions?: OpenAIProviderOptionsInput
|
||||
|
||||
@@ -3,14 +3,14 @@ import { VeniceChat } from "../protocols/venice-chat.js"
|
||||
import { OpenAIChat } from "../protocols/openai-chat.js"
|
||||
import { OpenResponses } from "../protocols/open-responses.js"
|
||||
import { AuthOptions, type ProviderAuthOption } from "../route/auth-options.js"
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Route } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { ProviderID, type ModelID } from "../schema/index.js"
|
||||
import { ProviderID, type ModelID, type RequestOptions } from "../schema/index.js"
|
||||
import type { OpenResponsesProviderOptionsInput } from "./open-responses-options.js"
|
||||
|
||||
export const id = ProviderID.make("venice")
|
||||
export type ChatOptionsInput = VeniceChat.OptionsInput
|
||||
export type Config = Omit<RouteDefaultsInput, "providerOptions"> &
|
||||
export type Config = Omit<RequestOptions, "providerOptions"> &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
readonly baseURL?: string
|
||||
readonly queryParams?: Readonly<Record<string, string>>
|
||||
@@ -40,7 +40,7 @@ const responsesRoute = Route.make({
|
||||
protocol: OpenResponses.protocol,
|
||||
endpoint: Endpoint.path("/responses", { baseURL }),
|
||||
transport: OpenResponses.httpTransport,
|
||||
defaults: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
|
||||
options: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
|
||||
})
|
||||
export const routes = [route, responsesRoute]
|
||||
|
||||
@@ -52,13 +52,11 @@ export const configure = (input: Config = {}) => {
|
||||
auth: AuthOptions.bearer(input, "VENICE_API_KEY"),
|
||||
}
|
||||
const chat = (modelID: string | ModelID) =>
|
||||
route
|
||||
.with(options)
|
||||
.model<ChatOptionsInput>({
|
||||
id: modelID,
|
||||
compatibility: VeniceChat.compatibility,
|
||||
capabilities: VeniceChat.capabilities,
|
||||
})
|
||||
route.with(options).model<ChatOptionsInput>({
|
||||
id: modelID,
|
||||
compatibility: VeniceChat.compatibility,
|
||||
capabilities: VeniceChat.capabilities,
|
||||
})
|
||||
const responses = (modelID: string | ModelID) =>
|
||||
responsesRoute.with(options).model<OpenResponsesProviderOptionsInput>({ id: modelID })
|
||||
return { id, model: chat, chat, responses, configure }
|
||||
|
||||
@@ -9,7 +9,7 @@ import { ProviderShared } from "../protocols/shared.js"
|
||||
import { gatewayProtocol } from "../protocols/utils/gateway-protocol.js"
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import type { ProviderAuthOption } from "../route/auth-options.js"
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Route } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { Framing } from "../route/framing.js"
|
||||
import { MediaRoute } from "../route/media.js"
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
ProviderMetadata,
|
||||
ReasoningEffort,
|
||||
type ProviderOptions,
|
||||
type RequestOptions,
|
||||
} from "../schema/index.js"
|
||||
import type { OpenResponsesProviderOptionsInput } from "./open-responses-options.js"
|
||||
import { bearerRouteDefaults, toConfig } from "./settings.js"
|
||||
@@ -100,7 +101,7 @@ export type ProviderOptionsInput = OpenResponsesProviderOptionsInput &
|
||||
readonly cacheAnchorItems?: number
|
||||
}
|
||||
|
||||
export type Config = Omit<RouteDefaultsInput, "providerOptions"> &
|
||||
export type Config = Omit<RequestOptions, "providerOptions"> &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
readonly baseURL?: string
|
||||
readonly providerOptions?: ProviderOptionsInput
|
||||
@@ -174,7 +175,7 @@ const route = <Body, Event, State>(input: {
|
||||
readonly api: "messages" | "responses" | "chat"
|
||||
readonly path: string
|
||||
readonly framing: Framing.Definition<string>
|
||||
readonly defaults?: RouteDefaultsInput
|
||||
readonly options?: RequestOptions
|
||||
}) =>
|
||||
Route.make({
|
||||
id: input.id,
|
||||
@@ -185,7 +186,7 @@ const route = <Body, Event, State>(input: {
|
||||
framing: input.framing,
|
||||
headers: ({ request }): Record<string, string> =>
|
||||
request.promptCacheKey ? { "x-session-affinity": request.promptCacheKey } : {},
|
||||
defaults: input.defaults,
|
||||
options: input.options,
|
||||
})
|
||||
|
||||
const messagesRoute = route({
|
||||
@@ -194,7 +195,7 @@ const messagesRoute = route({
|
||||
api: "messages",
|
||||
path: "/messages",
|
||||
framing: AnthropicMessages.framing,
|
||||
defaults: { headers: { "anthropic-version": "2023-06-01" } },
|
||||
options: { headers: { "anthropic-version": "2023-06-01" } },
|
||||
})
|
||||
const responsesRoute = route({
|
||||
id: "vercel-ai-gateway-responses",
|
||||
@@ -202,7 +203,7 @@ const responsesRoute = route({
|
||||
api: "responses",
|
||||
path: "/responses",
|
||||
framing: Framing.sse,
|
||||
defaults: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
|
||||
options: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
|
||||
})
|
||||
const chatRoute = route({
|
||||
id: "vercel-ai-gateway-chat",
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { AuthOptions, type ProviderAuthOption } from "../route/auth-options.js"
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Route } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { MediaRoute } from "../route/media.js"
|
||||
import { ProviderID, type ModelID, type ProviderOptions } from "../schema/index.js"
|
||||
import { ProviderID, type ModelID, type ProviderOptions, type RequestOptions } from "../schema/index.js"
|
||||
import { OpenAIChat } from "../protocols/openai-chat.js"
|
||||
import { OpenResponsesChannel } from "../protocols/open-responses-channel.js"
|
||||
import { XAIResponses } from "../protocols/xai-responses.js"
|
||||
@@ -18,7 +18,7 @@ const baseURL = "https://api.x.ai/v1"
|
||||
export type XAIProviderOptionsInput = OpenAIOptionsInput &
|
||||
XAIResponses.OptionsInput & { readonly contextManagement?: never }
|
||||
|
||||
export type Config = Omit<RouteDefaultsInput, "providerOptions"> &
|
||||
export type Config = Omit<RequestOptions, "providerOptions"> &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
readonly baseURL?: string
|
||||
readonly providerOptions?: XAIProviderOptionsInput
|
||||
@@ -51,7 +51,7 @@ const responsesRoute = Route.make({
|
||||
// rejects `instructions` next to `previous_response_id` and keeps the instructions of the response it continues.
|
||||
continuation: ({ instructions: _instructions, ...request }) => (request.store === false ? undefined : request),
|
||||
}),
|
||||
defaults: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
|
||||
options: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
|
||||
})
|
||||
|
||||
const chatRoute = Route.make({
|
||||
|
||||
@@ -5,10 +5,10 @@ import { OpenResponses } from "../protocols/open-responses.js"
|
||||
import { ZAIChat } from "../protocols/zai-chat.js"
|
||||
import { ZAIMessages } from "../protocols/zai-messages.js"
|
||||
import type { ProviderAuthOption } from "../route/auth-options.js"
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Route } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { Framing } from "../route/framing.js"
|
||||
import { ProviderID, type ModelID } from "../schema/index.js"
|
||||
import { ProviderID, type ModelID, type RequestOptions } from "../schema/index.js"
|
||||
import { bearerRouteDefaults, toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("zai-coding-plan")
|
||||
@@ -17,7 +17,7 @@ export type ChatOptionsInput = ZAIChat.OptionsInput
|
||||
export type MessagesOptionsInput = ZAIMessages.OptionsInput
|
||||
export type ResponsesOptionsInput = { readonly reasoningEffort?: ZAIChat.ReasoningEffort }
|
||||
|
||||
export type Config = Omit<RouteDefaultsInput, "providerOptions"> &
|
||||
export type Config = Omit<RequestOptions, "providerOptions"> &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
/** Overrides the selected API's complete base URL. */
|
||||
readonly baseURL?: string
|
||||
@@ -61,13 +61,11 @@ export const routes = [chatRoute, messagesRoute, responsesRoute]
|
||||
export const configure = (input: Config = {}) => {
|
||||
const defaults = bearerRouteDefaults(input, "ZAI_API_KEY")
|
||||
const chat = (modelID: string | ModelID) =>
|
||||
chatRoute
|
||||
.with(defaults)
|
||||
.model<ChatOptionsInput>({
|
||||
id: modelID,
|
||||
compatibility: ZAIChat.compatibility,
|
||||
capabilities: ZAIChat.capabilities,
|
||||
})
|
||||
chatRoute.with(defaults).model<ChatOptionsInput>({
|
||||
id: modelID,
|
||||
compatibility: ZAIChat.compatibility,
|
||||
capabilities: ZAIChat.capabilities,
|
||||
})
|
||||
const messages = (modelID: string | ModelID) =>
|
||||
messagesRoute
|
||||
.with(defaults)
|
||||
|
||||
@@ -3,17 +3,17 @@ import { ZAIChat } from "../protocols/zai-chat.js"
|
||||
import { ZAIImages } from "../protocols/zai-images.js"
|
||||
import { OpenAIChat } from "../protocols/openai-chat.js"
|
||||
import type { ProviderAuthOption } from "../route/auth-options.js"
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Route } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { MediaRoute } from "../route/media.js"
|
||||
import { ProviderID, type ModelID, type ProviderOptions } from "../schema/index.js"
|
||||
import { ProviderID, type ModelID, type ProviderOptions, type RequestOptions } from "../schema/index.js"
|
||||
import { bearerRouteDefaults, toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("zai")
|
||||
|
||||
export type ChatOptionsInput = ZAIChat.OptionsInput
|
||||
|
||||
export type Config = Omit<RouteDefaultsInput, "providerOptions"> &
|
||||
export type Config = Omit<RequestOptions, "providerOptions"> &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
readonly baseURL?: string
|
||||
readonly providerOptions?: ChatOptionsInput
|
||||
@@ -41,13 +41,11 @@ export const routes = [chatRoute]
|
||||
export const configure = (input: Config = {}) => {
|
||||
const defaults = bearerRouteDefaults(input, "ZAI_API_KEY")
|
||||
const chat = (modelID: string | ModelID) =>
|
||||
chatRoute
|
||||
.with(defaults)
|
||||
.model<ChatOptionsInput>({
|
||||
id: modelID,
|
||||
compatibility: ZAIChat.compatibility,
|
||||
capabilities: ZAIChat.capabilities,
|
||||
})
|
||||
chatRoute.with(defaults).model<ChatOptionsInput>({
|
||||
id: modelID,
|
||||
compatibility: ZAIChat.compatibility,
|
||||
capabilities: ZAIChat.capabilities,
|
||||
})
|
||||
const media = MediaRoute.deployment(input, defaults.auth)
|
||||
const image = (modelID: string | ModelID, providerOptions?: ProviderOptions) =>
|
||||
ZAIImages.model({ ...media, id: modelID, providerOptions })
|
||||
|
||||
@@ -93,7 +93,7 @@ export type {
|
||||
ContentPartInput,
|
||||
GenerationOptionsFields,
|
||||
HttpOptions,
|
||||
LanguageModelDefaults,
|
||||
RequestOptions,
|
||||
LanguageModelInput,
|
||||
LanguageModelProviderOptions,
|
||||
LLMRequest,
|
||||
|
||||
@@ -31,9 +31,10 @@ import {
|
||||
ToolEntry,
|
||||
type LLMRequest,
|
||||
mergeGeneration,
|
||||
mergeRequestOptions,
|
||||
mergeProviderOptions,
|
||||
mergeTransport,
|
||||
type LanguageModelDefaults,
|
||||
type RequestOptions,
|
||||
withPartial,
|
||||
} from "../schema/index.js"
|
||||
|
||||
@@ -60,7 +61,8 @@ export interface Route<
|
||||
/** Deployment headers resolved once for every operation, before transport authentication. */
|
||||
readonly headers?: (input: { readonly request: LLMRequest }) => Record<string, string>
|
||||
readonly transport: Transport<Body, Prepared, unknown>
|
||||
readonly defaults: RouteDefaults
|
||||
/** Options every model built on this route starts from. */
|
||||
readonly options?: RequestOptions
|
||||
readonly body: RouteBody<Body>
|
||||
readonly supportsEffortUpdates?: (request: LLMRequest) => boolean
|
||||
readonly sanitizer?: LanguageModelSanitizerCompatibility
|
||||
@@ -103,11 +105,7 @@ export type RouteLanguageModelInput = Omit<LanguageModel.Input, "provider" | "ro
|
||||
|
||||
export type RouteRoutedLanguageModelInput = Omit<LanguageModel.Input, "route">
|
||||
|
||||
export type RouteDefaults = LanguageModelDefaults
|
||||
|
||||
export type RouteDefaultsInput = LanguageModelDefaults
|
||||
|
||||
export interface RoutePatch<Body, Prepared> extends RouteDefaultsInput {
|
||||
export interface RoutePatch<Body, Prepared> extends RequestOptions {
|
||||
readonly compact?: CompactionOperations
|
||||
readonly id?: string
|
||||
readonly provider?: string | ProviderID
|
||||
@@ -137,14 +135,6 @@ const makeRouteLanguageModel = <Options extends ProviderOptions, Compact extends
|
||||
})
|
||||
}
|
||||
|
||||
const mergeRouteDefaults = (base: RouteDefaults | undefined, patch: RouteDefaultsInput): RouteDefaults => ({
|
||||
...base,
|
||||
...patch,
|
||||
...mergeTransport(base, patch),
|
||||
...mergeGeneration(base, patch),
|
||||
providerOptions: mergeProviderOptions(base?.providerOptions, patch.providerOptions),
|
||||
})
|
||||
|
||||
export interface Interface {
|
||||
readonly compact: CompactMethod
|
||||
readonly stream: StreamMethod
|
||||
@@ -255,17 +245,12 @@ export type Service = LLMClientService
|
||||
const resolveRequestOptions = (request: LLMRequest): LLMRequest => {
|
||||
const messages = normalizeToolHistory(request.messages)
|
||||
const normalized = messages === request.messages ? request : { ...request, messages }
|
||||
const routeDefaults = normalized.model.route.defaults
|
||||
const modelDefaults = normalized.model.defaults
|
||||
const options = normalized.model.options
|
||||
return {
|
||||
...normalized,
|
||||
...mergeGeneration(routeDefaults, modelDefaults, normalized),
|
||||
providerOptions: mergeProviderOptions(
|
||||
routeDefaults.providerOptions,
|
||||
modelDefaults?.providerOptions,
|
||||
normalized.providerOptions,
|
||||
),
|
||||
...mergeTransport(routeDefaults, modelDefaults, normalized),
|
||||
...mergeGeneration(options, normalized),
|
||||
providerOptions: mergeProviderOptions(options?.providerOptions, normalized.providerOptions),
|
||||
...mergeTransport(options, normalized),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,8 +272,8 @@ export interface MakeInput<Body, Frame, Event, State> {
|
||||
readonly framing: Framing.Definition<Frame>
|
||||
/** Static / per-request headers added before `auth` runs. */
|
||||
readonly headers?: (input: { readonly request: LLMRequest }) => Record<string, string>
|
||||
/** Route/request defaults used when compiling requests for this route. */
|
||||
readonly defaults?: RouteDefaultsInput
|
||||
/** Options every model built on this route starts from. */
|
||||
readonly options?: RequestOptions
|
||||
}
|
||||
|
||||
export interface MakeTransportInput<Body, Prepared, Frame, Event, State> {
|
||||
@@ -309,8 +294,8 @@ export interface MakeTransportInput<Body, Prepared, Frame, Event, State> {
|
||||
readonly headers?: (input: { readonly request: LLMRequest }) => Record<string, string>
|
||||
/** Runnable transport route. */
|
||||
readonly transport: Transport<Body, Prepared, Frame>
|
||||
/** Route/request defaults used when compiling requests for this route. */
|
||||
readonly defaults?: RouteDefaultsInput
|
||||
/** Options every model built on this route starts from. */
|
||||
readonly options?: RequestOptions
|
||||
}
|
||||
|
||||
const streamError = (route: string, message: string, cause: Cause.Cause<unknown>) => {
|
||||
@@ -375,9 +360,7 @@ function makeFromTransport<Body, Prepared, Frame, Event, State>(
|
||||
),
|
||||
)
|
||||
|
||||
type BuiltRouteInput = Omit<MakeTransportInput<Body, Prepared, Frame, Event, State>, "defaults"> & {
|
||||
readonly defaults?: RouteDefaults
|
||||
}
|
||||
type BuiltRouteInput = MakeTransportInput<Body, Prepared, Frame, Event, State>
|
||||
|
||||
const build = (routeInput: BuiltRouteInput): Route<Body, Prepared> => {
|
||||
const route: Route<Body, Prepared> = {
|
||||
@@ -390,12 +373,12 @@ function makeFromTransport<Body, Prepared, Frame, Event, State>(
|
||||
auth: routeInput.auth ?? Auth.none,
|
||||
headers: routeInput.headers,
|
||||
transport: routeInput.transport,
|
||||
defaults: routeInput.defaults ?? {},
|
||||
options: routeInput.options,
|
||||
body: protocol.body,
|
||||
supportsEffortUpdates: protocol.supportsEffortUpdates,
|
||||
sanitizer: protocol.sanitizer,
|
||||
with: (patch: RoutePatch<Body, Prepared>) => {
|
||||
const { compact, id, provider, providerMetadataKey, auth, transport, endpoint, ...defaults } = patch
|
||||
const { compact, id, provider, providerMetadataKey, auth, transport, endpoint, ...options } = patch
|
||||
return build({
|
||||
...routeInput,
|
||||
compact: "compact" in patch ? compact : routeInput.compact,
|
||||
@@ -407,7 +390,7 @@ function makeFromTransport<Body, Prepared, Frame, Event, State>(
|
||||
auth: auth ?? routeInput.auth,
|
||||
endpoint: endpoint ? Endpoint.merge(routeInput.endpoint, endpoint) : routeInput.endpoint,
|
||||
transport: (transport as Transport<Body, Prepared, Frame> | undefined) ?? routeInput.transport,
|
||||
defaults: mergeRouteDefaults(route.defaults, defaults),
|
||||
options: mergeRequestOptions(route.options, options),
|
||||
})
|
||||
},
|
||||
model: <Options extends ProviderOptions = ProviderOptions>(input: RouteMappedLanguageModelInput) =>
|
||||
@@ -507,7 +490,7 @@ function makeFromTransport<Body, Prepared, Frame, Event, State>(
|
||||
return route
|
||||
}
|
||||
|
||||
return build({ ...input, defaults: mergeRouteDefaults(undefined, input.defaults ?? {}) })
|
||||
return build({ ...input, options: mergeRequestOptions(input.options) })
|
||||
}
|
||||
|
||||
export function make<Body, Prepared, Frame, Event, State, Compact extends CompactionOperations>(
|
||||
@@ -552,7 +535,7 @@ export function make<Body, Prepared, Frame, Event, State>(
|
||||
auth: input.auth,
|
||||
headers: input.headers,
|
||||
transport: HttpTransport.httpJson({ framing: input.framing }),
|
||||
defaults: input.defaults,
|
||||
options: input.options,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,6 @@ export { Route, LLMClient } from "./client.js"
|
||||
export type {
|
||||
RouteLanguageModelInput,
|
||||
RouteRoutedLanguageModelInput,
|
||||
RouteDefaults,
|
||||
RouteDefaultsInput,
|
||||
AnyRoute,
|
||||
LLMClientService,
|
||||
StreamOptions,
|
||||
|
||||
@@ -161,11 +161,23 @@ export const mergeGeneration = (...items: ReadonlyArray<GenerationOptionsFields
|
||||
[...GENERATION_KEYS].map((key) => [key, last(items.map((item) => item?.[key as keyof GenerationOptionsFields]))]),
|
||||
) as GenerationOptionsFields
|
||||
|
||||
/** Request defaults a selected model applies under each request. */
|
||||
export interface LanguageModelDefaults extends TransportOptions, GenerationOptionsFields {
|
||||
/** Request options a model applies under each request: the same keys as a request, and the request wins. */
|
||||
export interface RequestOptions extends TransportOptions, GenerationOptionsFields {
|
||||
readonly providerOptions?: ProviderOptions
|
||||
}
|
||||
|
||||
/** Merge model options; later items win per key. Empty results are `undefined`. */
|
||||
export const mergeRequestOptions = (
|
||||
...items: ReadonlyArray<RequestOptions | undefined>
|
||||
): RequestOptions | undefined => {
|
||||
const merged = Object.entries({
|
||||
...mergeTransport(...items),
|
||||
...mergeGeneration(...items),
|
||||
providerOptions: mergeProviderOptions(...items.map((item) => item?.providerOptions)),
|
||||
}).filter(([, value]) => value !== undefined)
|
||||
return merged.length === 0 ? undefined : (Object.fromEntries(merged) as RequestOptions)
|
||||
}
|
||||
|
||||
/** Provider-defined string enum: known values for autocomplete, any string accepted. */
|
||||
export type OpenString<Known extends string> = Known | (string & {})
|
||||
|
||||
@@ -280,7 +292,7 @@ export class LanguageModel<
|
||||
readonly id: ModelID
|
||||
readonly provider: ProviderID
|
||||
readonly route: AnyRoute<Compact>
|
||||
readonly defaults?: LanguageModelDefaults
|
||||
readonly options?: RequestOptions
|
||||
readonly capabilities?: Capabilities
|
||||
readonly compatibility?: LanguageModelCompatibility
|
||||
|
||||
@@ -288,7 +300,7 @@ export class LanguageModel<
|
||||
this.id = input.id
|
||||
this.provider = input.provider
|
||||
this.route = input.route
|
||||
this.defaults = input.defaults
|
||||
this.options = input.options
|
||||
this.capabilities = input.capabilities
|
||||
this.compatibility = input.compatibility
|
||||
}
|
||||
@@ -301,7 +313,8 @@ export class LanguageModel<
|
||||
id: ModelID.make(input.id),
|
||||
provider: ProviderID.make(input.provider),
|
||||
route: input.route,
|
||||
defaults: input.defaults,
|
||||
// The route's options are a preset under the model's own.
|
||||
options: mergeRequestOptions(input.route.options, input.options),
|
||||
capabilities: input.capabilities,
|
||||
compatibility:
|
||||
input.compatibility === undefined ? undefined : LanguageModelCompatibility.make(input.compatibility),
|
||||
@@ -315,7 +328,7 @@ export class LanguageModel<
|
||||
id: model.id,
|
||||
provider: model.provider,
|
||||
route: model.route,
|
||||
defaults: model.defaults,
|
||||
options: model.options,
|
||||
capabilities: model.capabilities,
|
||||
compatibility: model.compatibility,
|
||||
}
|
||||
@@ -348,7 +361,7 @@ export namespace LanguageModel {
|
||||
readonly id: ModelID
|
||||
readonly provider: ProviderID
|
||||
readonly route: AnyRoute<Compact>
|
||||
readonly defaults?: LanguageModelDefaults
|
||||
readonly options?: RequestOptions
|
||||
readonly capabilities?: Capabilities
|
||||
readonly compatibility?: LanguageModelCompatibility
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ describe("request option precedence", () => {
|
||||
})
|
||||
const model = route.model({
|
||||
id: "gpt-4o-mini",
|
||||
defaults: {
|
||||
options: {
|
||||
maxTokens: 20,
|
||||
temperature: 0.5,
|
||||
frequencyPenalty: 0.25,
|
||||
@@ -203,7 +203,7 @@ describe("request option precedence", () => {
|
||||
})
|
||||
.model({
|
||||
id: "gpt-4o-mini",
|
||||
defaults: {
|
||||
options: {
|
||||
headers: { "x-model": "model", "x-shared": "model" },
|
||||
http: {
|
||||
body: { metadata: { model: true, shared: "model" }, value: "model" },
|
||||
|
||||
@@ -160,7 +160,7 @@ describe("llm constructors", () => {
|
||||
})
|
||||
const updated = LanguageModel.update(base, {
|
||||
route: responsesRoute,
|
||||
defaults: { maxTokens: 20 },
|
||||
options: { maxTokens: 20 },
|
||||
compatibility: { sanitizer: "gemini", requireFinishReason: false },
|
||||
})
|
||||
const updatedInput = LanguageModel.input(updated)
|
||||
@@ -168,9 +168,9 @@ describe("llm constructors", () => {
|
||||
expect(updated).toBeInstanceOf(LanguageModel)
|
||||
expect(String(updated.id)).toBe("fake-model")
|
||||
expect(updated.route).toBe(responsesRoute)
|
||||
expect(updated.defaults?.maxTokens).toBe(20)
|
||||
expect(updated.options?.maxTokens).toBe(20)
|
||||
expect(updated.compatibility).toEqual({ sanitizer: "gemini", requireFinishReason: false })
|
||||
expect(updatedInput.defaults).toBe(updated.defaults)
|
||||
expect(updatedInput.options).toBe(updated.options)
|
||||
expect(updatedInput.compatibility).toBe(updated.compatibility)
|
||||
expect(String(updatedInput.provider)).toBe("fake")
|
||||
expect(LanguageModel.update(updated, {})).toBe(updated)
|
||||
@@ -179,7 +179,7 @@ describe("llm constructors", () => {
|
||||
test("carries model defaults and compatibility through route model selection", () => {
|
||||
const model = chatRoute.model({
|
||||
id: "kimi-k2",
|
||||
defaults: {
|
||||
options: {
|
||||
maxTokens: 1_024,
|
||||
stop: ["END"],
|
||||
providerOptions: { parallelToolCalls: false },
|
||||
@@ -189,9 +189,9 @@ describe("llm constructors", () => {
|
||||
})
|
||||
const request = ai.request({ model, prompt: "Say hello." })
|
||||
|
||||
expect(request.model.defaults).toMatchObject({ maxTokens: 1_024, stop: ["END"] })
|
||||
expect(request.model.defaults?.providerOptions).toEqual({ parallelToolCalls: false })
|
||||
expect(request.model.defaults?.http).toEqual({ body: { extra_body: true } })
|
||||
expect(request.model.options).toMatchObject({ maxTokens: 1_024, stop: ["END"] })
|
||||
expect(request.model.options?.providerOptions).toEqual({ parallelToolCalls: false })
|
||||
expect(request.model.options?.http).toEqual({ body: { extra_body: true } })
|
||||
expect(request.model.compatibility).toEqual({ sanitizer: "moonshot" })
|
||||
expect(request.maxTokens).toBeUndefined()
|
||||
expect(request.providerOptions).toBeUndefined()
|
||||
|
||||
@@ -47,7 +47,7 @@ for (const selected of [
|
||||
OpenAI.model("fixture", {}),
|
||||
model.route.with({ headers: { fixture: "test" } }).model({ id: "fixture" }),
|
||||
LanguageModel.make(LanguageModel.input(model)),
|
||||
LanguageModel.update(model, { defaults: { maxTokens: 100 } }),
|
||||
LanguageModel.update(model, { options: { maxTokens: 100 } }),
|
||||
]) {
|
||||
ai.compact(ai.request({ model: selected, prompt: "Hello" }), { mechanism: "trigger" })
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ for (const model of [
|
||||
Azure.responsesModel("fixture", { resourceName: "test" }),
|
||||
XAI.model("fixture", {}),
|
||||
openai.route.with({ headers: { "x-test": "test" } }).model({ id: "fixture" }),
|
||||
LanguageModel.update(openai, { defaults: { maxTokens: 100 } }),
|
||||
LanguageModel.update(openai, { options: { maxTokens: 100 } }),
|
||||
LanguageModel.make(LanguageModel.input(openai)),
|
||||
]) {
|
||||
ai.compact(ai.request({ model, prompt: "hello" }))
|
||||
|
||||
@@ -29,8 +29,8 @@ describe("provider package entrypoints", () => {
|
||||
expect(model.route.endpoint.baseURL).toBe(
|
||||
`https://llm-fixture.eu-central-1.maas.aliyuncs.com/${index === 2 ? "apps/anthropic/v1" : "compatible-mode/v1"}`,
|
||||
)
|
||||
expect(model.route.defaults.headers).toEqual(settings.headers)
|
||||
expect(model.route.defaults.http?.body).toEqual(settings.body)
|
||||
expect(model.options?.headers).toEqual(settings.headers)
|
||||
expect(model.options?.http?.body).toEqual(settings.body)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -53,8 +53,8 @@ describe("provider package entrypoints", () => {
|
||||
expect(selected.provider).toBe("moonshotai")
|
||||
expect(selected.route.id).toBe(routes[index])
|
||||
expect(selected.route.endpoint.baseURL).toBe(settings.baseURL)
|
||||
expect(selected.route.defaults.headers).toEqual(settings.headers)
|
||||
expect(selected.route.defaults.http?.body).toEqual(settings.body)
|
||||
expect(selected.options?.headers).toEqual(settings.headers)
|
||||
expect(selected.options?.http?.body).toEqual(settings.body)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -91,9 +91,9 @@ describe("provider package entrypoints", () => {
|
||||
expect(selected.route.id).toBe(`${provider}-responses`)
|
||||
expect(selected.route.protocol).toBe(protocol)
|
||||
expect(selected.route.endpoint).toMatchObject({ baseURL, path: "/responses" })
|
||||
expect(selected.route.defaults.headers).toEqual(settings.headers)
|
||||
expect(selected.route.defaults.http?.body).toEqual(settings.body)
|
||||
expect(selected.route.defaults.providerOptions).toEqual({
|
||||
expect(selected.options?.headers).toEqual(settings.headers)
|
||||
expect(selected.options?.http?.body).toEqual(settings.body)
|
||||
expect(selected.options?.providerOptions).toEqual({
|
||||
reasoningEffort: "low",
|
||||
store: false,
|
||||
include: ["reasoning.encrypted_content"],
|
||||
@@ -118,8 +118,8 @@ describe("provider package entrypoints", () => {
|
||||
const selected = module.model("command-a-03-2025", settings)
|
||||
expect(selected.provider).toBe("cohere")
|
||||
expect([selected.route.id, selected.route.endpoint.baseURL]).toEqual(routes[index])
|
||||
expect(selected.route.defaults.headers).toEqual(settings.headers)
|
||||
expect(selected.route.defaults.http?.body).toEqual(settings.body)
|
||||
expect(selected.options?.headers).toEqual(settings.headers)
|
||||
expect(selected.options?.http?.body).toEqual(settings.body)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -142,8 +142,8 @@ describe("provider package entrypoints", () => {
|
||||
expect(selected.provider).toBe("minimax")
|
||||
expect(selected.route.id).toBe(routes[index])
|
||||
expect(selected.route.endpoint.baseURL).toBe(settings.baseURL)
|
||||
expect(selected.route.defaults.headers).toEqual(settings.headers)
|
||||
expect(selected.route.defaults.http?.body).toEqual(settings.body)
|
||||
expect(selected.options?.headers).toEqual(settings.headers)
|
||||
expect(selected.options?.http?.body).toEqual(settings.body)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -175,8 +175,8 @@ describe("provider package entrypoints", () => {
|
||||
expect(selected.provider).toBe(index < 2 ? "zai" : "zai-coding-plan")
|
||||
expect(selected.route.id).toBe(routes[index])
|
||||
expect(selected.route.endpoint.baseURL).toBe(settings.baseURL)
|
||||
expect(selected.route.defaults.headers).toEqual(settings.headers)
|
||||
expect(selected.route.defaults.http?.body).toEqual(settings.body)
|
||||
expect(selected.options?.headers).toEqual(settings.headers)
|
||||
expect(selected.options?.http?.body).toEqual(settings.body)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -193,9 +193,9 @@ describe("provider package entrypoints", () => {
|
||||
|
||||
expect(deepinfra.route.id).toBe("deepinfra-chat")
|
||||
expect(deepinfra.route.endpoint.baseURL).toBe("https://provider.example.test/v1/openai")
|
||||
expect(deepinfra.route.defaults.providerOptions).toEqual({ reasoningEffort: "high" })
|
||||
expect(deepinfra.route.defaults.headers).toEqual(settings.headers)
|
||||
expect(deepinfra.route.defaults.http?.body).toEqual(settings.body)
|
||||
expect(deepinfra.options?.providerOptions).toEqual({ reasoningEffort: "high" })
|
||||
expect(deepinfra.options?.headers).toEqual(settings.headers)
|
||||
expect(deepinfra.options?.http?.body).toEqual(settings.body)
|
||||
})
|
||||
|
||||
test("maps Cloudflare package settings onto provider-owned models", async () => {
|
||||
@@ -213,9 +213,9 @@ describe("provider package entrypoints", () => {
|
||||
})
|
||||
expect(selected.provider).toBe(provider.id)
|
||||
expect(selected.route.endpoint.baseURL).toBe(provider.baseURL({ accountId: "account" }))
|
||||
expect(selected.route.defaults.headers).toMatchObject({ "x-application": "opencode" })
|
||||
expect(selected.route.defaults.http?.body).toEqual({ custom: true })
|
||||
expect(selected.route.defaults.providerOptions).toEqual({ reasoningEffort: "high" })
|
||||
expect(selected.options?.headers).toMatchObject({ "x-application": "opencode" })
|
||||
expect(selected.options?.http?.body).toEqual({ custom: true })
|
||||
expect(selected.options?.providerOptions).toEqual({ reasoningEffort: "high" })
|
||||
}
|
||||
})
|
||||
|
||||
@@ -239,11 +239,11 @@ describe("provider package entrypoints", () => {
|
||||
|
||||
for (const selected of [openrouter, xai]) {
|
||||
expect(selected.route.endpoint.baseURL).toBe(settings.baseURL)
|
||||
expect(selected.route.defaults.headers).toEqual(settings.headers)
|
||||
expect(selected.route.defaults.http?.body).toEqual(settings.body)
|
||||
expect(selected.options?.headers).toEqual(settings.headers)
|
||||
expect(selected.options?.http?.body).toEqual(settings.body)
|
||||
}
|
||||
expect(openrouter.route.defaults.providerOptions).toEqual({ usage: true })
|
||||
expect(xai.route.defaults.providerOptions).toMatchObject({ reasoningEffort: "high", store: false })
|
||||
expect(openrouter.options?.providerOptions).toEqual({ usage: true })
|
||||
expect(xai.options?.providerOptions).toMatchObject({ reasoningEffort: "high", store: false })
|
||||
})
|
||||
|
||||
test("maps package settings onto the executable model", () => {
|
||||
@@ -256,8 +256,8 @@ describe("provider package entrypoints", () => {
|
||||
})
|
||||
|
||||
expect(selected.route.id).toBe("openai-responses")
|
||||
expect(selected.route.defaults.headers).toEqual({ "x-application": "opencode" })
|
||||
expect(selected.route.defaults.http?.body).toEqual({ service_tier: "priority" })
|
||||
expect(selected.options?.headers).toEqual({ "x-application": "opencode" })
|
||||
expect(selected.options?.http?.body).toEqual({ service_tier: "priority" })
|
||||
})
|
||||
|
||||
test("maps OpenAI-compatible Responses settings onto the executable model", async () => {
|
||||
@@ -278,9 +278,9 @@ describe("provider package entrypoints", () => {
|
||||
baseURL: "https://responses.example.test/v1",
|
||||
path: "/responses",
|
||||
})
|
||||
expect(selected.route.defaults.headers).toEqual({ "x-application": "opencode" })
|
||||
expect(selected.route.defaults.http?.body).toEqual({ service_tier: "priority" })
|
||||
expect(selected.route.defaults.providerOptions).toEqual({
|
||||
expect(selected.options?.headers).toEqual({ "x-application": "opencode" })
|
||||
expect(selected.options?.http?.body).toEqual({ service_tier: "priority" })
|
||||
expect(selected.options?.providerOptions).toEqual({
|
||||
reasoningEffort: "low",
|
||||
store: true,
|
||||
include: ["reasoning.encrypted_content"],
|
||||
@@ -311,9 +311,9 @@ describe("provider package entrypoints", () => {
|
||||
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" } })
|
||||
expect(selected.route.defaults.providerOptions).toEqual({ effort: "low" })
|
||||
expect(selected.options?.headers).toEqual({ "x-application": "opencode" })
|
||||
expect(selected.options?.http?.body).toEqual({ metadata: { user_id: "user_1" } })
|
||||
expect(selected.options?.providerOptions).toEqual({ effort: "low" })
|
||||
})
|
||||
|
||||
test("maps Anthropic provider options onto the executable model", async () => {
|
||||
@@ -324,7 +324,7 @@ describe("provider package entrypoints", () => {
|
||||
})
|
||||
|
||||
expect(selected.route.id).toBe("anthropic-messages")
|
||||
expect(selected.route.defaults.providerOptions).toEqual({ thinking: { type: "adaptive" } })
|
||||
expect(selected.options?.providerOptions).toEqual({ thinking: { type: "adaptive" } })
|
||||
})
|
||||
|
||||
test("requires an Anthropic-compatible base URL at runtime", async () => {
|
||||
@@ -362,7 +362,7 @@ describe("provider package entrypoints", () => {
|
||||
project: "proj_123",
|
||||
})
|
||||
|
||||
expect(selected.route.defaults.headers).toMatchObject({
|
||||
expect(selected.options?.headers).toMatchObject({
|
||||
"OpenAI-Organization": "org_123",
|
||||
"OpenAI-Project": "proj_123",
|
||||
})
|
||||
@@ -385,8 +385,8 @@ describe("provider package entrypoints", () => {
|
||||
expect(Azure.model("deployment", settings).route.id).toBe("azure-openai-responses")
|
||||
expect(responses.route.id).toBe("azure-openai-responses")
|
||||
expect(responses.route.endpoint.baseURL).toBe("https://opencode-test.openai.azure.com/openai/v1")
|
||||
expect(responses.route.defaults.headers).toEqual({ "x-application": "opencode" })
|
||||
expect(responses.route.defaults.http?.body).toEqual({ service_tier: "priority" })
|
||||
expect(responses.options?.headers).toEqual({ "x-application": "opencode" })
|
||||
expect(responses.options?.http?.body).toEqual({ service_tier: "priority" })
|
||||
expect(chat.route.id).toBe("azure-openai-chat")
|
||||
})
|
||||
|
||||
@@ -424,9 +424,9 @@ describe("provider package entrypoints", () => {
|
||||
|
||||
expect(selected.route.id).toBe("gemini")
|
||||
expect(selected.route.endpoint.baseURL).toBe("https://generativelanguage.test/v1beta")
|
||||
expect(selected.route.defaults.headers).toEqual({ "x-application": "opencode" })
|
||||
expect(selected.route.defaults.http?.body).toEqual({ safetySettings: [] })
|
||||
expect(selected.route.defaults.providerOptions).toEqual({ thinkingConfig: { thinkingBudget: 1_024 } })
|
||||
expect(selected.options?.headers).toEqual({ "x-application": "opencode" })
|
||||
expect(selected.options?.http?.body).toEqual({ safetySettings: [] })
|
||||
expect(selected.options?.providerOptions).toEqual({ thinkingConfig: { thinkingBudget: 1_024 } })
|
||||
const interactions = GoogleInteractions.model("gemini-3.8-flash", {
|
||||
apiKey: "fixture",
|
||||
baseURL: "https://generativelanguage.test/v1beta",
|
||||
@@ -435,7 +435,7 @@ describe("provider package entrypoints", () => {
|
||||
})
|
||||
expect(interactions.route.id).toBe("google-interactions")
|
||||
expect(interactions.route.endpoint.baseURL).toBe("https://generativelanguage.test/v1beta")
|
||||
expect(interactions.route.defaults.providerOptions).toEqual({ thinkingLevel: "low", store: true })
|
||||
expect(interactions.options?.providerOptions).toEqual({ thinkingLevel: "low", store: true })
|
||||
expect(Google.configure().interactions("gemini-3.8-flash").route.protocol).toBe("google-interactions")
|
||||
})
|
||||
|
||||
@@ -468,8 +468,8 @@ describe("provider package entrypoints", () => {
|
||||
expect(gemini.route.id).toBe("google-vertex-gemini")
|
||||
expect(gemini.route.protocol).toBe("gemini")
|
||||
expect(gemini.route.endpoint.baseURL).toBe("https://aiplatform.googleapis.com/v1/publishers/google")
|
||||
expect(gemini.route.defaults.headers).toEqual({ "x-application": "opencode" })
|
||||
expect(gemini.route.defaults.http?.body).toEqual({ safetySettings: [] })
|
||||
expect(gemini.options?.headers).toEqual({ "x-application": "opencode" })
|
||||
expect(gemini.options?.http?.body).toEqual({ safetySettings: [] })
|
||||
expect(
|
||||
GoogleVertex.model("gemini-3.5-flash", {
|
||||
accessToken: "fixture",
|
||||
@@ -494,7 +494,7 @@ describe("provider package entrypoints", () => {
|
||||
baseURL: "https://aiplatform.googleapis.com/v1/projects/vertex-project/locations/global/endpoints/openapi",
|
||||
path: "/responses",
|
||||
})
|
||||
expect(responses.route.defaults.providerOptions).toEqual({
|
||||
expect(responses.options?.providerOptions).toEqual({
|
||||
store: false,
|
||||
include: ["reasoning.encrypted_content"],
|
||||
})
|
||||
@@ -518,9 +518,9 @@ describe("provider package entrypoints", () => {
|
||||
path: "/interactions",
|
||||
query: { alt: "sse" },
|
||||
})
|
||||
expect(selected.route.defaults.headers).toEqual({ "x-application": "opencode" })
|
||||
expect(selected.route.defaults.http?.body).toEqual({ generation_config: { temperature: 0.5 } })
|
||||
expect(selected.route.defaults.providerOptions).toEqual({ thinkingLevel: "low", store: false })
|
||||
expect(selected.options?.headers).toEqual({ "x-application": "opencode" })
|
||||
expect(selected.options?.http?.body).toEqual({ generation_config: { temperature: 0.5 } })
|
||||
expect(selected.options?.providerOptions).toEqual({ thinkingLevel: "low", store: false })
|
||||
})
|
||||
|
||||
test("rejects conflicting Vertex auth settings at runtime", async () => {
|
||||
|
||||
@@ -153,7 +153,7 @@ describe("Cloudflare", () => {
|
||||
}),
|
||||
)
|
||||
|
||||
expect(prepared.model.route.defaults.headers).toMatchObject({ "cf-aig-gateway-id": "default" })
|
||||
expect(prepared.model.options?.headers).toMatchObject({ "cf-aig-gateway-id": "default" })
|
||||
}),
|
||||
)
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ test("Cohere exposes native and compatible endpoints without Core remapping", ()
|
||||
expect(cohere.chat("command-a-03-2025").route.endpoint.baseURL).toBe("https://api.cohere.ai/compatibility/v1")
|
||||
expect(
|
||||
Cohere.model("command-a-03-2025", { apiKey: "fixture", headers: { "X-Test": "yes" }, body: { temperature: 0 } })
|
||||
.route.defaults?.http,
|
||||
.options?.http,
|
||||
).toMatchObject({ body: { temperature: 0 } })
|
||||
})
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ describe("DigitalOcean", () => {
|
||||
headers: { "X-Test": "fixture" },
|
||||
body: { temperature: 0 },
|
||||
})
|
||||
expect(model.route.defaults).toMatchObject({
|
||||
expect(model.options).toMatchObject({
|
||||
headers: { "X-Test": "fixture" },
|
||||
http: { body: { temperature: 0 } },
|
||||
})
|
||||
|
||||
@@ -61,7 +61,7 @@ testEffect(
|
||||
headers.push(String(request.model.id))
|
||||
return { "x-deployment": "fixture", "x-override": "route" }
|
||||
},
|
||||
defaults: {
|
||||
options: {
|
||||
headers: { "x-default": "configured", "x-override": "configured" },
|
||||
providerOptions: { store: false },
|
||||
http: { body: { instructions: "default instructions" } },
|
||||
|
||||
@@ -48,8 +48,8 @@ it.effect("Groq lowers its own options for custom catalog identities and endpoin
|
||||
}),
|
||||
)
|
||||
expect(model.route.endpoint.baseURL).toBe("https://gateway.example/v1")
|
||||
expect(model.route.defaults.headers).toEqual({ "x-client": "test" })
|
||||
expect(model.route.defaults.http?.body).toEqual({ custom: "value" })
|
||||
expect(model.options?.headers).toEqual({ "x-client": "test" })
|
||||
expect(model.options?.http?.body).toEqual({ custom: "value" })
|
||||
expect(compiled.body).toMatchObject({
|
||||
reasoning_effort: "default",
|
||||
reasoning_format: "parsed",
|
||||
|
||||
@@ -90,8 +90,8 @@ it.effect("Meta package selectors preserve overrides and Chat token policy on cu
|
||||
reasoningEffort: "future-effort",
|
||||
})
|
||||
expect(model.route.endpoint.baseURL).toBe("https://gateway.example/v1")
|
||||
expect(model.route.defaults.headers).toEqual({ "x-client": "test" })
|
||||
expect(model.route.defaults.http?.body).toEqual({ custom: "value" })
|
||||
expect(model.options?.headers).toEqual({ "x-client": "test" })
|
||||
expect(model.options?.http?.body).toEqual({ custom: "value" })
|
||||
const compiled = yield* compileRequest(
|
||||
ai.request({
|
||||
model,
|
||||
|
||||
@@ -213,9 +213,9 @@ describe("native OpenAI-compatible providers", () => {
|
||||
})
|
||||
|
||||
expect(selected.route.endpoint.baseURL).toBe("https://gateway.example/v1")
|
||||
expect(selected.route.defaults.headers).toEqual({ "x-application": "opencode" })
|
||||
expect(selected.route.defaults.http?.body).toEqual({ service_tier: "priority" })
|
||||
expect(selected.route.defaults.providerOptions).toEqual({ reasoningEffort: "high" })
|
||||
expect(selected.options?.headers).toEqual({ "x-application": "opencode" })
|
||||
expect(selected.options?.http?.body).toEqual({ service_tier: "priority" })
|
||||
expect(selected.options?.providerOptions).toEqual({ reasoningEffort: "high" })
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ describe("Route.with", () => {
|
||||
path: "/chat/completions",
|
||||
query: { keep: "patch", base: "1", patch: "1" },
|
||||
})
|
||||
expect(route.defaults.headers).toEqual({
|
||||
expect(route.options?.headers).toEqual({
|
||||
"x-base": "base",
|
||||
"x-override": "patch",
|
||||
"x-patch": "patch",
|
||||
@@ -48,7 +48,7 @@ describe("Route.with", () => {
|
||||
|
||||
expect(route.providerMetadataKey).toBe("azure")
|
||||
expect(overridden.providerMetadataKey).toBe("custom-azure")
|
||||
expect(overridden.defaults).not.toHaveProperty("providerMetadataKey")
|
||||
expect(overridden.options).not.toHaveProperty("providerMetadataKey")
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -389,7 +389,7 @@ function modelFromLanguage(info: RuntimeInfo, language: LanguageModelV3) {
|
||||
prepare: (input) => Effect.succeed(input.body),
|
||||
execute: () => Effect.succeed({ frames: Stream.empty }),
|
||||
},
|
||||
defaults: {
|
||||
options: {
|
||||
headers: info.headers,
|
||||
http: projected.body === undefined ? undefined : { body: { ...projected.body } },
|
||||
providerOptions: projected.settings,
|
||||
|
||||
@@ -253,10 +253,10 @@ const resolveCatalogModel = Effect.fn("ModelResolver.resolveCatalogModel")(funct
|
||||
compatibility: resolved.compatibility
|
||||
? Object.assign({}, runtime.compatibility, Struct.omit(resolved.compatibility, CAPABILITY_KEYS))
|
||||
: runtime.compatibility,
|
||||
// Timeouts and body encoding are transport policy, so they land on the route's HTTP defaults instead of package settings.
|
||||
defaults: {
|
||||
...runtime.defaults,
|
||||
...mergeTransport(runtime.defaults, {
|
||||
// Timeouts and body encoding are transport policy, so they land on the model's options instead of package settings.
|
||||
options: {
|
||||
...runtime.options,
|
||||
...mergeTransport(runtime.options, {
|
||||
timeout: { total: timeouts.timeout, headers: timeouts.headerTimeout, chunk: timeouts.chunkTimeout },
|
||||
http: { encoding: Provider.encoding(configured) },
|
||||
}),
|
||||
|
||||
@@ -16,7 +16,7 @@ import { Npm } from "@opencode/util/npm"
|
||||
import { withEnv } from "./fixture/env"
|
||||
import { it } from "./lib/effect"
|
||||
|
||||
interface ModelOptions {
|
||||
interface RequestOptions {
|
||||
readonly providerID?: Provider.ID
|
||||
readonly canonical?: Provider.ID
|
||||
readonly modelID?: string
|
||||
@@ -28,7 +28,7 @@ interface ModelOptions {
|
||||
readonly limit?: Info["limit"]
|
||||
}
|
||||
|
||||
function model(packageName: string | undefined, options: ModelOptions = {}) {
|
||||
function model(packageName: string | undefined, options: RequestOptions = {}) {
|
||||
const info: Model.MutableInfo = {
|
||||
id: ID.make("test-model"),
|
||||
modelID: ID.make(options.modelID ?? "api-test-model"),
|
||||
@@ -275,10 +275,10 @@ describe("ModelResolver", () => {
|
||||
id: "openai-responses",
|
||||
providerMetadataKey: "openai",
|
||||
endpoint: { baseURL: "https://openai.example/v1" },
|
||||
defaults: {
|
||||
headers: { "x-test": "header" },
|
||||
http: { body: { custom_extension: { enabled: true } } },
|
||||
},
|
||||
})
|
||||
expect(resolved.options).toMatchObject({
|
||||
headers: { "x-test": "header" },
|
||||
http: { body: { custom_extension: { enabled: true } } },
|
||||
})
|
||||
const prepared = yield* compileRequest(ai.request({ model: resolved, prompt: "Hello" }))
|
||||
expect(prepared.body.max_output_tokens).toBeUndefined()
|
||||
@@ -412,7 +412,7 @@ describe("ModelResolver", () => {
|
||||
method: "POST",
|
||||
url: resolved.model.route.endpoint.baseURL ?? "",
|
||||
body: "{}",
|
||||
headers: Headers.fromInput(resolved.model.route.defaults.headers),
|
||||
headers: Headers.fromInput(resolved.model.options?.headers),
|
||||
})
|
||||
|
||||
expect(resolved.limit).toEqual(selection.limit)
|
||||
@@ -493,7 +493,7 @@ describe("ModelResolver", () => {
|
||||
expect(prepared.body).toMatchObject({ max_completion_tokens: 10 })
|
||||
expect(prepared.body).not.toHaveProperty("max_tokens")
|
||||
expect(resolved.route.endpoint.baseURL).toBe("https://compatible.example/v1")
|
||||
expect(resolved.route.defaults.http?.body).toEqual({})
|
||||
expect(resolved.options?.http?.body).toBeUndefined()
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -560,14 +560,14 @@ describe("ModelResolver", () => {
|
||||
Credential.Key.make({ type: "key", key: "secret" }),
|
||||
)
|
||||
|
||||
expect(resolved.route.defaults.headers).toMatchObject({ "x-test": "header", "x-variant": "high" })
|
||||
expect(resolved.route.defaults.http?.body).toEqual({
|
||||
expect(resolved.options?.headers).toMatchObject({ "x-test": "header", "x-variant": "high" })
|
||||
expect(resolved.options?.http?.body).toEqual({
|
||||
custom_extension: { enabled: true },
|
||||
store: false,
|
||||
service_tier: "priority",
|
||||
temperature: 0.2,
|
||||
})
|
||||
expect(resolved.route.defaults.providerOptions).toEqual({
|
||||
expect(resolved.options?.providerOptions).toEqual({
|
||||
store: false,
|
||||
reasoningEffort: "xhigh",
|
||||
reasoningSummary: "auto",
|
||||
@@ -619,7 +619,7 @@ describe("ModelResolver", () => {
|
||||
})
|
||||
const resolved = yield* ModelResolver.resolveModel(catalog, VariantID.make("high"))
|
||||
|
||||
expect(resolved.route.defaults.http?.body).toEqual({
|
||||
expect(resolved.options?.http?.body).toEqual({
|
||||
custom_extension: { enabled: true },
|
||||
store: false,
|
||||
reasoning_effort: "high",
|
||||
@@ -659,10 +659,10 @@ describe("ModelResolver", () => {
|
||||
})
|
||||
const resolved = yield* ModelResolver.resolveModel(catalog, VariantID.make("high"))
|
||||
|
||||
expect(resolved.route.defaults.http?.body).toEqual({
|
||||
expect(resolved.options?.http?.body).toEqual({
|
||||
custom_extension: { enabled: true },
|
||||
})
|
||||
expect(resolved.route.defaults.providerOptions).toEqual({
|
||||
expect(resolved.options?.providerOptions).toEqual({
|
||||
thinking: { type: "enabled", budgetTokens: 12000 },
|
||||
})
|
||||
}),
|
||||
@@ -799,7 +799,7 @@ describe("ModelResolver", () => {
|
||||
|
||||
expect(failure).toBeInstanceOf(ModelResolver.ModelConfigurationError)
|
||||
expect(resolved.route.endpoint.baseURL).toBe("https://configured-resource.openai.azure.com/openai/v1")
|
||||
expect(resolved.route.defaults.http?.body).toEqual({})
|
||||
expect(resolved.options?.http?.body).toBeUndefined()
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -821,7 +821,7 @@ describe("ModelResolver", () => {
|
||||
}),
|
||||
)
|
||||
|
||||
expect(resolved.route.defaults.http?.body).toEqual({})
|
||||
expect(resolved.options?.http?.body).toBeUndefined()
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -863,7 +863,7 @@ describe("ModelResolver", () => {
|
||||
id: "openai-responses",
|
||||
endpoint: { baseURL: "https://chatgpt.com/backend-api/codex" },
|
||||
})
|
||||
expect(resolved.route.defaults.headers).toMatchObject({ "chatgpt-account-id": "acct_123" })
|
||||
expect(resolved.options?.headers).toMatchObject({ "chatgpt-account-id": "acct_123" })
|
||||
expect(headers.authorization).toBe("Bearer chatgpt-token")
|
||||
expect(prepared.body).toMatchObject({
|
||||
instructions: "Base instructions.\nProject instructions.",
|
||||
@@ -904,7 +904,7 @@ describe("ModelResolver", () => {
|
||||
}),
|
||||
)
|
||||
|
||||
expect(resolved.route.defaults.headers).toMatchObject({
|
||||
expect(resolved.options?.headers).toMatchObject({
|
||||
"OpenAI-Organization": "org_123",
|
||||
"OpenAI-Project": "proj_123",
|
||||
})
|
||||
@@ -1357,41 +1357,41 @@ describe("ModelResolver", () => {
|
||||
)
|
||||
|
||||
expect(google.route.id).toBe("gemini")
|
||||
expect(google.route.defaults.providerOptions).toEqual({ thinkingConfig: { thinkingBudget: 1_024 } })
|
||||
expect(google.options?.providerOptions).toEqual({ thinkingConfig: { thinkingBudget: 1_024 } })
|
||||
expect(openrouter.route.id).toBe("openrouter")
|
||||
expect(openrouter.route.defaults.providerOptions).toEqual({ reasoning: { effort: "high" } })
|
||||
expect(openrouter.options?.providerOptions).toEqual({ reasoning: { effort: "high" } })
|
||||
expect(cerebras.route.id).toBe("cerebras-chat")
|
||||
expect(cerebras.route.defaults.providerOptions).toEqual({ reasoningEffort: "high" })
|
||||
expect(cerebras.options?.providerOptions).toEqual({ reasoningEffort: "high" })
|
||||
expect(String(cerebras.provider)).toBe("test-provider")
|
||||
expect(deepinfra.route.id).toBe("deepinfra-chat")
|
||||
expect(deepinfra.route.endpoint.baseURL).toBe("https://deepinfra.example/provider-root/openai")
|
||||
expect(deepinfra.route.defaults.providerOptions).toEqual({ reasoningEffort: "none" })
|
||||
expect(deepinfra.options?.providerOptions).toEqual({ reasoningEffort: "none" })
|
||||
expect(String(deepinfra.provider)).toBe("test-provider")
|
||||
expect(togetherai.route.id).toBe("togetherai-chat")
|
||||
expect(togetherai.route.defaults.providerOptions).toEqual({ reasoningEffort: "high" })
|
||||
expect(togetherai.options?.providerOptions).toEqual({ reasoningEffort: "high" })
|
||||
expect(String(togetherai.provider)).toBe("test-provider")
|
||||
expect(groq.route.id).toBe("groq-chat")
|
||||
expect(groq.route.protocol).toBe("groq-chat")
|
||||
expect(groq.route.defaults.providerOptions).toEqual({ reasoningEffort: "high", parallelToolCalls: false })
|
||||
expect(groq.options?.providerOptions).toEqual({ reasoningEffort: "high", parallelToolCalls: false })
|
||||
expect(String(groq.provider)).toBe("test-provider")
|
||||
expect(mistral.route.id).toBe("mistral-chat")
|
||||
expect(mistral.route.defaults.providerOptions).toEqual({
|
||||
expect(mistral.options?.providerOptions).toEqual({
|
||||
safePrompt: true,
|
||||
promptCacheKey: "session-123",
|
||||
reasoningEffort: "high",
|
||||
})
|
||||
expect(String(mistral.provider)).toBe("test-provider")
|
||||
expect(xai.route.id).toBe("xai-responses")
|
||||
expect(xai.route.defaults.providerOptions).toEqual({
|
||||
expect(xai.options?.providerOptions).toEqual({
|
||||
reasoningEffort: "high",
|
||||
store: false,
|
||||
include: ["reasoning.encrypted_content"],
|
||||
})
|
||||
expect(bedrock.route.id).toBe("bedrock-converse")
|
||||
expect(bedrock.route.defaults.topP).toBe(0.8)
|
||||
expect(bedrock.route.defaults.http?.body).toEqual({ serviceTier: { type: "priority" } })
|
||||
expect(bedrock.options?.topP).toBe(0.8)
|
||||
expect(bedrock.options?.http?.body).toEqual({ serviceTier: { type: "priority" } })
|
||||
expect(mantle.route.id).toBe("bedrock-mantle-chat")
|
||||
expect(mantle.route.defaults.topP).toBe(0.6)
|
||||
expect(mantle.options?.topP).toBe(0.6)
|
||||
expect(workers.route.endpoint.baseURL).toBe("https://api.cloudflare.com/client/v4/accounts/account/ai/v1")
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -1619,7 +1619,10 @@ describe("SessionRunnerLLM", () => {
|
||||
}),
|
||||
)
|
||||
yield* s.admit("Echo before moving")
|
||||
yield* s.llm.push(TestLLM.toolCall("call-move", "echo", { text: "moving" }), TestLLM.text("Done", "text-after-move"))
|
||||
yield* s.llm.push(
|
||||
TestLLM.toolCall("call-move", "echo", { text: "moving" }),
|
||||
TestLLM.text("Done", "text-after-move"),
|
||||
)
|
||||
const tools = yield* s.blockTools()
|
||||
const run = yield* s.resume.pipe(Effect.forkChild)
|
||||
yield* tools.started
|
||||
@@ -2325,7 +2328,7 @@ describe("SessionRunnerLLM", () => {
|
||||
sessionID,
|
||||
model: { ...model, variant: Model.VariantID.make("low") },
|
||||
})
|
||||
s.currentModel = LanguageModel.update(s.currentModel, { defaults: { providerOptions: { effort: "low" } } })
|
||||
s.currentModel = LanguageModel.update(s.currentModel, { options: { providerOptions: { effort: "low" } } })
|
||||
yield* s.llm.push(TestLLM.text("Later answer", "text-effort-low"))
|
||||
yield* s.runPrompt("Second")
|
||||
|
||||
@@ -5780,7 +5783,11 @@ describe("SessionRunnerLLM", () => {
|
||||
expect(s.requests).toHaveLength(1)
|
||||
expect(yield* s.context).toMatchObject([
|
||||
Expected.user("Fail durably"),
|
||||
{ type: "assistant", finish: "error", error: { type: "provider.invalid-request", message: "Provider unavailable" } },
|
||||
{
|
||||
type: "assistant",
|
||||
finish: "error",
|
||||
error: { type: "provider.invalid-request", message: "Provider unavailable" },
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
@@ -5792,7 +5799,11 @@ describe("SessionRunnerLLM", () => {
|
||||
expect(s.requests).toHaveLength(1)
|
||||
expect(yield* s.context).toMatchObject([
|
||||
Expected.user("Fail before step"),
|
||||
{ type: "assistant", finish: "error", error: { type: "provider.invalid-request", message: "Provider unavailable" } },
|
||||
{
|
||||
type: "assistant",
|
||||
finish: "error",
|
||||
error: { type: "provider.invalid-request", message: "Provider unavailable" },
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
@@ -6120,7 +6131,10 @@ describe("SessionRunnerLLM", () => {
|
||||
// the window instead of rejecting it.
|
||||
s.currentModel = recoveryModel
|
||||
yield* s.llm.push(
|
||||
TestLLM.complete({ reason: { normalized: "length" }, usage: { inputTokens: 199_994, nonCachedInputTokens: 199_994, outputTokens: 0 } }),
|
||||
TestLLM.complete({
|
||||
reason: { normalized: "length" },
|
||||
usage: { inputTokens: 199_994, nonCachedInputTokens: 199_994, outputTokens: 0 },
|
||||
}),
|
||||
TestLLM.text("## Objective\n- summary", "summary"),
|
||||
TestLLM.text("Done", "done"),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user