mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-19 08:39:02 +03:00
refactor(ai): share provider settings conversion (#61145)
This commit is contained in:
committed by
GitHub
Unverified
parent
c6571b007e
commit
66d113c4e4
@@ -8,6 +8,7 @@ import { DecisionRoute } from "../route/decision.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { ProviderID, type ModelID, type ProviderOptions } from "../schema/index.js"
|
||||
import type { OpenAIProviderOptionsInput } from "./openai-options.js"
|
||||
import { toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("baseten")
|
||||
const baseURL = "https://inference.baseten.co/v1"
|
||||
@@ -84,20 +85,10 @@ export const provider = configure()
|
||||
export const decision = provider.decision
|
||||
|
||||
export const model: ProviderPackage.Model<Settings, OpenAIProviderOptionsInput> = (modelID, settings) =>
|
||||
configure(config(settings)).model(modelID)
|
||||
configure(toConfig(settings)).model(modelID)
|
||||
export const decisionModel = (modelID: string, settings?: Settings) => {
|
||||
const input = config(settings)
|
||||
const input = toConfig(settings)
|
||||
return configure(input).decision(modelID, input.providerOptions)
|
||||
}
|
||||
|
||||
function config({ apiKey, baseURL, body, headers, ...providerOptions }: Settings = {}) {
|
||||
return {
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
}
|
||||
}
|
||||
|
||||
export * as Baseten from "./baseten.js"
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { ProviderID, type ModelID } from "../schema/index.js"
|
||||
import type { OpenAIProviderOptionsInput } from "./openai-options.js"
|
||||
import { toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("cerebras")
|
||||
const baseURL = "https://api.cerebras.ai/v1"
|
||||
@@ -56,14 +57,5 @@ export const configure = (input: Config = {}) => {
|
||||
|
||||
export const provider = configure()
|
||||
|
||||
export const model: ProviderPackage.Model<Settings, OpenAIProviderOptionsInput> = (
|
||||
modelID,
|
||||
{ apiKey, baseURL, body, headers, ...providerOptions }: Settings = {},
|
||||
) =>
|
||||
configure({
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
}).model(modelID)
|
||||
export const model: ProviderPackage.Model<Settings, OpenAIProviderOptionsInput> = (modelID, settings) =>
|
||||
configure(toConfig(settings)).model(modelID)
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Endpoint } from "../route/endpoint.js"
|
||||
import { AuthOptions, type ProviderAuthOption } from "../route/auth-options.js"
|
||||
import { ProviderID, type ModelID, type OpenString } from "../schema/index.js"
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import { toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("cohere")
|
||||
const COMPATIBILITY_BASE_URL = "https://api.cohere.ai/compatibility/v1"
|
||||
@@ -51,15 +52,6 @@ export const configure = (input: Config = {}) => {
|
||||
}
|
||||
export const provider = configure()
|
||||
export const chat = provider.chat
|
||||
export const model: ProviderPackage.Model<Settings, CohereChat.ProviderOptionsInput> = (
|
||||
modelID,
|
||||
{ apiKey, baseURL, body, headers, ...providerOptions }: Settings = {},
|
||||
) =>
|
||||
configure({
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
}).model(modelID)
|
||||
export const model: ProviderPackage.Model<Settings, CohereChat.ProviderOptionsInput> = (modelID, settings) =>
|
||||
configure(toConfig(settings)).model(modelID)
|
||||
export * as Cohere from "./cohere.js"
|
||||
|
||||
@@ -1,16 +1,8 @@
|
||||
import type { ProviderPackage } from "../../provider-package.js"
|
||||
import { Cohere } from "../cohere.js"
|
||||
import { toConfig } from "../settings.js"
|
||||
|
||||
export type Settings = Cohere.Settings<Cohere.ChatOptionsInput>
|
||||
|
||||
export const model: ProviderPackage.Model<Settings, Cohere.ChatOptionsInput> = (
|
||||
modelID,
|
||||
{ apiKey, baseURL, body, headers, ...providerOptions }: Settings = {},
|
||||
) =>
|
||||
Cohere.configure({
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
}).chat(modelID)
|
||||
export const model: ProviderPackage.Model<Settings, Cohere.ChatOptionsInput> = (modelID, settings) =>
|
||||
Cohere.configure(toConfig(settings)).chat(modelID)
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { ProviderID, type ModelID } from "../schema/index.js"
|
||||
import type { OpenAIProviderOptionsInput } from "./openai-options.js"
|
||||
import { toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("deepinfra")
|
||||
const baseURL = "https://api.deepinfra.com/v1/openai"
|
||||
@@ -59,14 +60,5 @@ export const configure = (input: Config = {}) => {
|
||||
|
||||
export const provider = configure()
|
||||
|
||||
export const model: ProviderPackage.Model<Settings, OpenAIProviderOptionsInput> = (
|
||||
modelID,
|
||||
{ apiKey, baseURL, body, headers, ...providerOptions }: Settings = {},
|
||||
) =>
|
||||
configure({
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
}).model(modelID)
|
||||
export const model: ProviderPackage.Model<Settings, OpenAIProviderOptionsInput> = (modelID, settings) =>
|
||||
configure(toConfig(settings)).model(modelID)
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { ProviderID, type ModelID } from "../schema/index.js"
|
||||
import type { OpenAIProviderOptionsInput } from "./openai-options.js"
|
||||
import { toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("deepseek")
|
||||
const baseURL = "https://api.deepseek.com/v1"
|
||||
@@ -52,16 +53,7 @@ export const configure = (input: Config = {}) => {
|
||||
|
||||
export const provider = configure()
|
||||
|
||||
export const model: ProviderPackage.Model<Settings, OpenAIProviderOptionsInput> = (
|
||||
modelID,
|
||||
{ apiKey, baseURL, body, headers, ...providerOptions }: Settings = {},
|
||||
) =>
|
||||
configure({
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
}).model(modelID)
|
||||
export const model: ProviderPackage.Model<Settings, OpenAIProviderOptionsInput> = (modelID, settings) =>
|
||||
configure(toConfig(settings)).model(modelID)
|
||||
|
||||
export * as DeepSeek from "./deepseek.js"
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { ProviderID, type ModelID } from "../schema/index.js"
|
||||
import type { OpenAIProviderOptionsInput } from "./openai-options.js"
|
||||
import { toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("fireworks")
|
||||
const baseURL = "https://api.fireworks.ai/inference/v1"
|
||||
@@ -49,16 +50,7 @@ export const configure = (input: Config = {}) => {
|
||||
|
||||
export const provider = configure()
|
||||
|
||||
export const model: ProviderPackage.Model<Settings, OpenAIProviderOptionsInput> = (
|
||||
modelID,
|
||||
{ apiKey, baseURL, body, headers, ...providerOptions }: Settings = {},
|
||||
) =>
|
||||
configure({
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
}).model(modelID)
|
||||
export const model: ProviderPackage.Model<Settings, OpenAIProviderOptionsInput> = (modelID, settings) =>
|
||||
configure(toConfig(settings)).model(modelID)
|
||||
|
||||
export * as Fireworks from "./fireworks.js"
|
||||
|
||||
@@ -10,6 +10,7 @@ import { GoogleImages } from "../protocols/google-images.js"
|
||||
import { GoogleSpeech } from "../protocols/google-speech.js"
|
||||
import { GoogleTranscription } from "../protocols/google-transcription.js"
|
||||
import { GoogleVideo } from "../protocols/google-video.js"
|
||||
import { toConfig } from "./settings.js"
|
||||
|
||||
export type { GoogleImageOptions } from "../protocols/google-images.js"
|
||||
export type { GoogleSpeechOptions } from "../protocols/google-speech.js"
|
||||
@@ -69,22 +70,12 @@ export const configure = (input: Config = {}) => {
|
||||
|
||||
export const provider = configure()
|
||||
export const model: ProviderPackage.Model<Settings, Gemini.ProviderOptionsInput> = (modelID, settings) =>
|
||||
configure(config(settings)).model(modelID)
|
||||
configure(toConfig(settings)).model(modelID)
|
||||
export const imageModel = (modelID: string, settings?: Settings) => {
|
||||
const input = config(settings)
|
||||
const input = toConfig(settings)
|
||||
return configure(input).image(modelID, input.providerOptions)
|
||||
}
|
||||
|
||||
function config({ apiKey, baseURL, body, headers, ...providerOptions }: Settings = {}) {
|
||||
return {
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
}
|
||||
}
|
||||
|
||||
export const image = provider.image
|
||||
export const gemini = provider.gemini
|
||||
export const interactions = provider.interactions
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { configure } from "../google.js"
|
||||
import type { ProviderPackage } from "../../provider-package.js"
|
||||
import type { GoogleInteractions } from "../../protocols/google-interactions.js"
|
||||
import { toConfig } from "../settings.js"
|
||||
|
||||
export type Settings = ProviderPackage.Settings &
|
||||
GoogleInteractions.ProviderOptionsInput & {
|
||||
@@ -8,14 +9,5 @@ export type Settings = ProviderPackage.Settings &
|
||||
readonly baseURL?: string
|
||||
}
|
||||
|
||||
export const model: ProviderPackage.Model<Settings, GoogleInteractions.ProviderOptionsInput> = (
|
||||
modelID,
|
||||
{ apiKey, baseURL, body, headers, ...providerOptions }: Settings = {},
|
||||
) =>
|
||||
configure({
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
}).interactions(modelID)
|
||||
export const model: ProviderPackage.Model<Settings, GoogleInteractions.ProviderOptionsInput> = (modelID, settings) =>
|
||||
configure(toConfig(settings)).interactions(modelID)
|
||||
|
||||
@@ -8,6 +8,7 @@ import { Endpoint } from "../route/endpoint.js"
|
||||
import { Protocol } from "../route/protocol.js"
|
||||
import { ProviderID, type ModelID, type LLMRequest } from "../schema/index.js"
|
||||
import type { OpenAIProviderOptionsInput } from "./openai-options.js"
|
||||
import { toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("groq")
|
||||
const baseURL = "https://api.groq.com/openai/v1"
|
||||
@@ -96,16 +97,7 @@ export const configure = (input: Config = {}) => {
|
||||
|
||||
export const provider = configure()
|
||||
|
||||
export const model: ProviderPackage.Model<Settings, ProviderOptions> = (
|
||||
modelID,
|
||||
{ apiKey, baseURL, body, headers, ...providerOptions }: Settings = {},
|
||||
) =>
|
||||
configure({
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
}).model(modelID)
|
||||
export const model: ProviderPackage.Model<Settings, ProviderOptions> = (modelID, settings) =>
|
||||
configure(toConfig(settings)).model(modelID)
|
||||
|
||||
export * as Groq from "./groq.js"
|
||||
|
||||
@@ -10,6 +10,7 @@ import { Endpoint } from "../route/endpoint.js"
|
||||
import { MediaRoute } from "../route/media.js"
|
||||
import { ProviderID, ToolDefinition, type ModelID, type OpenString } from "../schema/index.js"
|
||||
import type { OpenResponsesProviderOptionsInput } from "./open-responses-options.js"
|
||||
import { toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("meta")
|
||||
const baseURL = "https://api.meta.ai/v1"
|
||||
@@ -151,24 +152,14 @@ export const messages = provider.messages
|
||||
export const image = provider.image
|
||||
|
||||
export const model: ProviderPackage.Model<Settings, OpenResponsesProviderOptionsInput> = (modelID, settings) =>
|
||||
fromSettings(settings).responses(modelID)
|
||||
configure(toConfig(settings)).responses(modelID)
|
||||
|
||||
export const chatModel: ProviderPackage.Model<Settings, OpenResponsesProviderOptionsInput> = (modelID, settings) =>
|
||||
fromSettings(settings).chat(modelID)
|
||||
configure(toConfig(settings)).chat(modelID)
|
||||
|
||||
export const messagesModel: ProviderPackage.Model<Settings, MessagesOptionsInput> = (modelID, settings) =>
|
||||
fromSettings(settings).messages(modelID)
|
||||
configure(toConfig(settings)).messages(modelID)
|
||||
|
||||
export const imageModel = (modelID: string, settings?: Settings) => fromSettings(settings).image(modelID)
|
||||
|
||||
function fromSettings({ apiKey, baseURL, body, headers, ...providerOptions }: Settings = {}) {
|
||||
return configure({
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
})
|
||||
}
|
||||
export const imageModel = (modelID: string, settings?: Settings) => configure(toConfig(settings)).image(modelID)
|
||||
|
||||
export * as Meta from "./meta.js"
|
||||
|
||||
@@ -12,6 +12,7 @@ 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 { toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("minimax")
|
||||
|
||||
@@ -137,9 +138,9 @@ export const configure = (input: Config = {}) => {
|
||||
export const provider = configure()
|
||||
|
||||
export const model: ProviderPackage.Model<Settings<MessagesOptionsInput>, MessagesOptionsInput> = (modelID, settings) =>
|
||||
configure(config(settings)).model(modelID)
|
||||
configure(toConfig(settings)).model(modelID)
|
||||
export const imageModel = (modelID: string, settings?: Settings<MiniMaxImageOptions>) => {
|
||||
const input = config(settings)
|
||||
const input = toConfig<Settings<{}>>(settings)
|
||||
return configure(input).image(modelID, input.providerOptions)
|
||||
}
|
||||
|
||||
@@ -148,14 +149,4 @@ export const chat = provider.chat
|
||||
export const responses = provider.responses
|
||||
export const image = provider.image
|
||||
|
||||
function config({ apiKey, baseURL, body, headers, ...providerOptions }: Settings<{}> = {}) {
|
||||
return {
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
}
|
||||
}
|
||||
|
||||
export * as MiniMax from "./minimax.js"
|
||||
|
||||
@@ -1,16 +1,8 @@
|
||||
import type { ProviderPackage } from "../../provider-package.js"
|
||||
import { MiniMax } from "../minimax.js"
|
||||
import { toConfig } from "../settings.js"
|
||||
|
||||
export type Settings = MiniMax.Settings<MiniMax.ChatOptionsInput>
|
||||
|
||||
export const model: ProviderPackage.Model<Settings, MiniMax.ChatOptionsInput> = (
|
||||
modelID,
|
||||
{ apiKey, baseURL, body, headers, ...providerOptions }: Settings = {},
|
||||
) =>
|
||||
MiniMax.configure({
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
}).chat(modelID)
|
||||
export const model: ProviderPackage.Model<Settings, MiniMax.ChatOptionsInput> = (modelID, settings) =>
|
||||
MiniMax.configure(toConfig(settings)).chat(modelID)
|
||||
|
||||
@@ -1,16 +1,8 @@
|
||||
import type { ProviderPackage } from "../../provider-package.js"
|
||||
import { MiniMax } from "../minimax.js"
|
||||
import { toConfig } from "../settings.js"
|
||||
|
||||
export type Settings = MiniMax.Settings<MiniMax.ResponsesOptionsInput>
|
||||
|
||||
export const model: ProviderPackage.Model<Settings, MiniMax.ResponsesOptionsInput> = (
|
||||
modelID,
|
||||
{ apiKey, baseURL, body, headers, ...providerOptions }: Settings = {},
|
||||
) =>
|
||||
MiniMax.configure({
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
}).responses(modelID)
|
||||
export const model: ProviderPackage.Model<Settings, MiniMax.ResponsesOptionsInput> = (modelID, settings) =>
|
||||
MiniMax.configure(toConfig(settings)).responses(modelID)
|
||||
|
||||
@@ -3,6 +3,7 @@ import { MistralChat } from "../protocols/mistral-chat.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 { toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("mistral")
|
||||
|
||||
@@ -39,16 +40,7 @@ export const configure = (input: Config = {}) => {
|
||||
|
||||
export const provider = configure()
|
||||
|
||||
export const model: ProviderPackage.Model<Settings, ProviderOptions> = (
|
||||
modelID,
|
||||
{ apiKey, baseURL, body, headers, ...providerOptions }: Settings = {},
|
||||
) =>
|
||||
configure({
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
}).model(modelID)
|
||||
export const model: ProviderPackage.Model<Settings, ProviderOptions> = (modelID, settings) =>
|
||||
configure(toConfig(settings)).model(modelID)
|
||||
|
||||
export * as Mistral from "./mistral.js"
|
||||
|
||||
@@ -10,6 +10,7 @@ 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 { toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("moonshotai")
|
||||
|
||||
@@ -133,16 +134,7 @@ export const chat = provider.chat
|
||||
export const messages = provider.messages
|
||||
export const responses = provider.responses
|
||||
|
||||
export const model: ProviderPackage.Model<Settings, ChatOptionsInput> = (
|
||||
modelID,
|
||||
{ apiKey, baseURL, body, headers, ...providerOptions }: Settings = {},
|
||||
) =>
|
||||
configure({
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
}).model(modelID)
|
||||
export const model: ProviderPackage.Model<Settings, ChatOptionsInput> = (modelID, settings) =>
|
||||
configure(toConfig(settings)).model(modelID)
|
||||
|
||||
export * as Moonshot from "./moonshot.js"
|
||||
|
||||
@@ -1,16 +1,8 @@
|
||||
import type { ProviderPackage } from "../../provider-package.js"
|
||||
import { Moonshot } from "../moonshot.js"
|
||||
import { toConfig } from "../settings.js"
|
||||
|
||||
export type Settings = Moonshot.Settings<Moonshot.MessagesOptionsInput>
|
||||
|
||||
export const model: ProviderPackage.Model<Settings, Moonshot.MessagesOptionsInput> = (
|
||||
modelID,
|
||||
{ apiKey, baseURL, body, headers, ...providerOptions }: Settings = {},
|
||||
) =>
|
||||
Moonshot.configure({
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
}).messages(modelID)
|
||||
export const model: ProviderPackage.Model<Settings, Moonshot.MessagesOptionsInput> = (modelID, settings) =>
|
||||
Moonshot.configure(toConfig(settings)).messages(modelID)
|
||||
|
||||
@@ -1,16 +1,8 @@
|
||||
import type { ProviderPackage } from "../../provider-package.js"
|
||||
import { Moonshot } from "../moonshot.js"
|
||||
import { toConfig } from "../settings.js"
|
||||
|
||||
export type Settings = Moonshot.Settings<Moonshot.ResponsesOptionsInput>
|
||||
|
||||
export const model: ProviderPackage.Model<Settings, Moonshot.ResponsesOptionsInput> = (
|
||||
modelID,
|
||||
{ apiKey, baseURL, body, headers, ...providerOptions }: Settings = {},
|
||||
) =>
|
||||
Moonshot.configure({
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
}).responses(modelID)
|
||||
export const model: ProviderPackage.Model<Settings, Moonshot.ResponsesOptionsInput> = (modelID, settings) =>
|
||||
Moonshot.configure(toConfig(settings)).responses(modelID)
|
||||
|
||||
@@ -4,6 +4,7 @@ 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 type { OpenResponsesProviderOptionsInput } from "./open-responses-options.js"
|
||||
import { toConfig } from "./settings.js"
|
||||
|
||||
export type { OpenResponsesOptionsInput, OpenResponsesProviderOptionsInput } from "./open-responses-options.js"
|
||||
|
||||
@@ -48,13 +49,5 @@ export const provider = {
|
||||
|
||||
export const model: ProviderPackage.Model<Settings, OpenResponsesProviderOptionsInput> = (
|
||||
modelID,
|
||||
{ apiKey, baseURL, body, headers, provider, ...providerOptions },
|
||||
) =>
|
||||
configure({
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
provider,
|
||||
providerOptions,
|
||||
}).model(modelID)
|
||||
{ provider, ...settings },
|
||||
) => configure({ ...toConfig(settings), provider }).model(modelID)
|
||||
|
||||
@@ -6,6 +6,7 @@ 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"
|
||||
import { toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("openai-compatible")
|
||||
|
||||
@@ -67,15 +68,8 @@ export const imageModel = (modelID: string, settings: Settings) => {
|
||||
return configure(input).image(modelID, input.providerOptions)
|
||||
}
|
||||
|
||||
function config({ apiKey, baseURL, body, headers, provider, ...providerOptions }: Settings) {
|
||||
return {
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
provider,
|
||||
providerOptions,
|
||||
}
|
||||
function config({ provider, ...settings }: Settings) {
|
||||
return { ...toConfig(settings), provider }
|
||||
}
|
||||
|
||||
export * as OpenAICompatible from "./openai-compatible.js"
|
||||
|
||||
@@ -2,6 +2,7 @@ import { HttpOptions, ProviderID, type ModelID, type ProviderOptions } from "../
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import { AuthOptions, type ProviderAuthOption } from "../route/auth-options.js"
|
||||
import { SystemOne } from "../protocols/system-one.js"
|
||||
import { toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("opencode")
|
||||
const baseURL = "https://opencode.ai/inference/systemone/v1"
|
||||
@@ -32,10 +33,9 @@ export const configure = (input: Config = {}) => {
|
||||
export const provider = configure()
|
||||
export const decision = provider.decision
|
||||
|
||||
export const decisionModel = (modelID: string, { apiKey, baseURL, body, headers, ...providerOptions }: Settings = {}) =>
|
||||
configure({ apiKey, baseURL, headers, http: body === undefined ? undefined : { body } }).decision(
|
||||
modelID,
|
||||
providerOptions,
|
||||
)
|
||||
export const decisionModel = (modelID: string, settings?: Settings) => {
|
||||
const input = toConfig(settings)
|
||||
return configure(input).decision(modelID, input.providerOptions)
|
||||
}
|
||||
|
||||
export * as OpenCode from "./opencode.js"
|
||||
|
||||
@@ -14,6 +14,7 @@ import { OpenResponses } from "../protocols/open-responses.js"
|
||||
import { cacheControl } from "../protocols/utils/cache.js"
|
||||
import { isRecord, JsonObject, lenient, ProviderShared } from "../protocols/shared.js"
|
||||
import type { OpenResponsesProviderOptionsInput } from "./open-responses-options.js"
|
||||
import { toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("openrouter")
|
||||
const baseURL = "https://openrouter.ai/api/v1"
|
||||
@@ -292,28 +293,18 @@ export const image = provider.image
|
||||
export const chat = provider.chat
|
||||
export const responses = provider.responses
|
||||
export const model: ProviderPackage.Model<Settings, OpenRouterProviderOptionsInput> = (modelID, settings) =>
|
||||
configure(config(settings)).model(modelID)
|
||||
configure(toConfig(settings)).model(modelID)
|
||||
export const responsesModel: ProviderPackage.Model<
|
||||
Settings<OpenRouterResponsesProviderOptionsInput>,
|
||||
OpenRouterResponsesProviderOptionsInput
|
||||
> = (modelID, settings) => configure(config(settings)).responses(modelID)
|
||||
> = (modelID, settings) => configure(toConfig(settings)).responses(modelID)
|
||||
export const imageModel = (modelID: string, settings?: Settings) => {
|
||||
const input = config(settings)
|
||||
const input = toConfig(settings)
|
||||
return configure(input).image(modelID, input.providerOptions)
|
||||
}
|
||||
export const decisionModel = (modelID: string, settings?: Settings) => {
|
||||
const input = config(settings)
|
||||
const input = toConfig(settings)
|
||||
return configure(input).decision(modelID, input.providerOptions)
|
||||
}
|
||||
|
||||
function config({ apiKey, baseURL, body, headers, ...providerOptions }: Settings<Config["providerOptions"]> = {}) {
|
||||
return {
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
}
|
||||
}
|
||||
|
||||
export * as OpenRouter from "./openrouter.js"
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
|
||||
type Connection = "apiKey" | "baseURL" | "body" | "headers"
|
||||
|
||||
/**
|
||||
* Splits flat provider settings into connection config, treating every other key as a provider option.
|
||||
* The overload keeps each provider's option keys; a generic rest would type them as `Omit`, which collapses
|
||||
* to the `Settings` index signature.
|
||||
*/
|
||||
export function toConfig<Settings extends ProviderPackage.Settings>(
|
||||
settings?: Settings,
|
||||
): {
|
||||
apiKey: Settings["apiKey"]
|
||||
baseURL: Settings["baseURL"]
|
||||
headers: Settings["headers"]
|
||||
http: { body: NonNullable<Settings["body"]> } | undefined
|
||||
providerOptions: { [Key in keyof Settings as Key extends Connection ? never : Key]: Settings[Key] }
|
||||
}
|
||||
export function toConfig({ apiKey, baseURL, body, headers, ...providerOptions }: ProviderPackage.Settings = {}) {
|
||||
return {
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { ProviderID, type ModelID } from "../schema/index.js"
|
||||
import type { OpenAIProviderOptionsInput } from "./openai-options.js"
|
||||
import { toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("togetherai")
|
||||
const baseURL = "https://api.together.xyz/v1"
|
||||
@@ -52,14 +53,5 @@ export const configure = (input: Config = {}) => {
|
||||
|
||||
export const provider = configure()
|
||||
|
||||
export const model: ProviderPackage.Model<Settings, OpenAIProviderOptionsInput> = (
|
||||
modelID,
|
||||
{ apiKey, baseURL, body, headers, ...providerOptions }: Settings = {},
|
||||
) =>
|
||||
configure({
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
}).model(modelID)
|
||||
export const model: ProviderPackage.Model<Settings, OpenAIProviderOptionsInput> = (modelID, settings) =>
|
||||
configure(toConfig(settings)).model(modelID)
|
||||
|
||||
@@ -2,6 +2,7 @@ import { HttpOptions, ProviderID, type ModelID, type ProviderOptions } from "../
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import { AuthOptions, type ProviderAuthOption } from "../route/auth-options.js"
|
||||
import { SystemOne } from "../protocols/system-one.js"
|
||||
import { toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("typesafe-ai")
|
||||
const baseURL = "https://api.typesafe.ai/v1"
|
||||
@@ -32,10 +33,9 @@ export const configure = (input: Config = {}) => {
|
||||
export const provider = configure()
|
||||
export const decision = provider.decision
|
||||
|
||||
export const decisionModel = (modelID: string, { apiKey, baseURL, body, headers, ...providerOptions }: Settings = {}) =>
|
||||
configure({ apiKey, baseURL, headers, http: body === undefined ? undefined : { body } }).decision(
|
||||
modelID,
|
||||
providerOptions,
|
||||
)
|
||||
export const decisionModel = (modelID: string, settings?: Settings) => {
|
||||
const input = toConfig(settings)
|
||||
return configure(input).decision(modelID, input.providerOptions)
|
||||
}
|
||||
|
||||
export * as TypeSafeAI from "./typesafe-ai.js"
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
type ProviderOptions,
|
||||
} from "../schema/index.js"
|
||||
import type { OpenResponsesProviderOptionsInput } from "./open-responses-options.js"
|
||||
import { toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("vercel-ai-gateway")
|
||||
const baseURL = "https://ai-gateway.vercel.sh/v1"
|
||||
@@ -269,30 +270,20 @@ export const chat = provider.chat
|
||||
export const image = provider.image
|
||||
|
||||
export const model: ProviderPackage.Model<Settings, ProviderOptionsInput> = (modelID, settings) =>
|
||||
configure(config(settings)).model(modelID)
|
||||
configure(toConfig(settings)).model(modelID)
|
||||
export const messagesModel: ProviderPackage.Model<Settings, ProviderOptionsInput> = (modelID, settings) =>
|
||||
configure(config(settings)).messages(modelID)
|
||||
configure(toConfig(settings)).messages(modelID)
|
||||
export const responsesModel: ProviderPackage.Model<Settings, ProviderOptionsInput> = (modelID, settings) =>
|
||||
configure(config(settings)).responses(modelID)
|
||||
configure(toConfig(settings)).responses(modelID)
|
||||
export const chatModel: ProviderPackage.Model<Settings, ProviderOptionsInput> = (modelID, settings) =>
|
||||
configure(config(settings)).chat(modelID)
|
||||
configure(toConfig(settings)).chat(modelID)
|
||||
export const imageModel = (modelID: string, settings?: Settings) => {
|
||||
const input = config(settings)
|
||||
const input = toConfig(settings)
|
||||
return configure(input).image(modelID, input.providerOptions)
|
||||
}
|
||||
export const decisionModel = (modelID: string, settings?: Settings) => {
|
||||
const input = config(settings)
|
||||
const input = toConfig(settings)
|
||||
return configure(input).decision(modelID, input.providerOptions)
|
||||
}
|
||||
|
||||
function config({ apiKey, baseURL, headers, body, ...providerOptions }: Settings = {}) {
|
||||
return {
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
}
|
||||
}
|
||||
|
||||
export * as VercelAIGateway from "./vercel-ai-gateway.js"
|
||||
|
||||
@@ -10,6 +10,7 @@ import { XAIImages } from "../protocols/xai-images.js"
|
||||
import { XAIVideo } from "../protocols/xai-video.js"
|
||||
import type { OpenAIOptionsInput } from "./openai-options.js"
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import { toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("xai")
|
||||
const baseURL = "https://api.x.ai/v1"
|
||||
@@ -108,21 +109,11 @@ export const provider = configure()
|
||||
export const model: ProviderPackage.Model<Settings, XAIProviderOptionsInput, typeof responsesRoute.compact> = (
|
||||
modelID,
|
||||
settings,
|
||||
) => configure(config(settings)).model(modelID)
|
||||
) => configure(toConfig(settings)).model(modelID)
|
||||
export const imageModel = (modelID: string, settings?: Settings) => {
|
||||
const input = config(settings)
|
||||
const input = toConfig(settings)
|
||||
return configure(input).image(modelID, input.providerOptions)
|
||||
}
|
||||
|
||||
function config({ apiKey, baseURL, body, headers, ...providerOptions }: Settings = {}) {
|
||||
return {
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
}
|
||||
}
|
||||
export const responses = provider.responses
|
||||
export const chat = provider.chat
|
||||
export const image = provider.image
|
||||
|
||||
@@ -9,6 +9,7 @@ import { Route, type RouteDefaultsInput } 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 { toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("zai-coding-plan")
|
||||
|
||||
@@ -80,16 +81,7 @@ export const chat = provider.chat
|
||||
export const messages = provider.messages
|
||||
export const responses = provider.responses
|
||||
|
||||
export const model: ProviderPackage.Model<Settings, ChatOptionsInput> = (
|
||||
modelID,
|
||||
{ apiKey, baseURL, body, headers, ...providerOptions }: Settings = {},
|
||||
) =>
|
||||
configure({
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
}).model(modelID)
|
||||
export const model: ProviderPackage.Model<Settings, ChatOptionsInput> = (modelID, settings) =>
|
||||
configure(toConfig(settings)).model(modelID)
|
||||
|
||||
export * as ZAICodingPlan from "./zai-coding-plan.js"
|
||||
|
||||
@@ -1,16 +1,8 @@
|
||||
import type { ProviderPackage } from "../../provider-package.js"
|
||||
import { ZAICodingPlan } from "../zai-coding-plan.js"
|
||||
import { toConfig } from "../settings.js"
|
||||
|
||||
export type Settings = ZAICodingPlan.Settings<ZAICodingPlan.MessagesOptionsInput>
|
||||
|
||||
export const model: ProviderPackage.Model<Settings, ZAICodingPlan.MessagesOptionsInput> = (
|
||||
modelID,
|
||||
{ apiKey, baseURL, body, headers, ...providerOptions }: Settings = {},
|
||||
) =>
|
||||
ZAICodingPlan.configure({
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
}).messages(modelID)
|
||||
export const model: ProviderPackage.Model<Settings, ZAICodingPlan.MessagesOptionsInput> = (modelID, settings) =>
|
||||
ZAICodingPlan.configure(toConfig(settings)).messages(modelID)
|
||||
|
||||
@@ -1,16 +1,8 @@
|
||||
import type { ProviderPackage } from "../../provider-package.js"
|
||||
import { ZAICodingPlan } from "../zai-coding-plan.js"
|
||||
import { toConfig } from "../settings.js"
|
||||
|
||||
export type Settings = ZAICodingPlan.Settings<ZAICodingPlan.ResponsesOptionsInput>
|
||||
|
||||
export const model: ProviderPackage.Model<Settings, ZAICodingPlan.ResponsesOptionsInput> = (
|
||||
modelID,
|
||||
{ apiKey, baseURL, body, headers, ...providerOptions }: Settings = {},
|
||||
) =>
|
||||
ZAICodingPlan.configure({
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
}).responses(modelID)
|
||||
export const model: ProviderPackage.Model<Settings, ZAICodingPlan.ResponsesOptionsInput> = (modelID, settings) =>
|
||||
ZAICodingPlan.configure(toConfig(settings)).responses(modelID)
|
||||
|
||||
@@ -7,6 +7,7 @@ import { Route, type RouteDefaultsInput } 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 { toConfig } from "./settings.js"
|
||||
|
||||
export const id = ProviderID.make("zai")
|
||||
|
||||
@@ -67,20 +68,10 @@ export const image = provider.image
|
||||
export const chat = provider.chat
|
||||
|
||||
export const model: ProviderPackage.Model<Settings, ChatOptionsInput> = (modelID, settings) =>
|
||||
configure(config(settings)).model(modelID)
|
||||
configure(toConfig(settings)).model(modelID)
|
||||
export const imageModel = (modelID: string, settings?: Settings) => {
|
||||
const input = config(settings)
|
||||
const input = toConfig(settings)
|
||||
return configure(input).image(modelID, input.providerOptions)
|
||||
}
|
||||
|
||||
function config({ apiKey, baseURL, body, headers, ...providerOptions }: Settings = {}) {
|
||||
return {
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
}
|
||||
}
|
||||
|
||||
export * as ZAI from "./zai.js"
|
||||
|
||||
Reference in New Issue
Block a user