diff --git a/extensions/deepinfra/index.ts b/extensions/deepinfra/index.ts index e69de29bb2d..9ef33860680 100644 --- a/extensions/deepinfra/index.ts +++ b/extensions/deepinfra/index.ts @@ -0,0 +1,70 @@ +import { definePluginEntry } from "openclaw/plugin-sdk/core"; +import { createProviderApiKeyAuthMethod } from "openclaw/plugin-sdk/provider-auth"; +import { buildSingleProviderApiKeyCatalog } from "openclaw/plugin-sdk/provider-catalog"; +import { applyDeepInfraConfig, DEEPINFRA_DEFAULT_MODEL_REF } from "./onboard.js"; +import { buildDeepInfraProviderWithDiscovery } from "./provider-catalog.js"; + +const PROVIDER_ID = "deepinfra"; + +const DEEPINFRA_CACHE_TTL_MODEL_PREFIXES = [ + "anthropic/", + "moonshot/", + "moonshotai/", + "zai/", + "zai-org/", +] as const; + +function isDeepInfraCacheTtlModel(modelId: string): boolean { + return DEEPINFRA_CACHE_TTL_MODEL_PREFIXES.some((prefix) => modelId.startsWith(prefix)); +} + +export default definePluginEntry({ + id: PROVIDER_ID, + name: "DeepInfra Provider", + description: "Bundled DeepInfra provider plugin", + register(api) { + api.registerProvider({ + id: PROVIDER_ID, + label: "DeepInfra", + docsPath: "/providers/deepinfra", + envVars: ["DEEPINFRA_API_KEY"], + auth: [ + createProviderApiKeyAuthMethod({ + providerId: PROVIDER_ID, + methodId: "api-key", + label: "DeepInfra API key", + hint: "Unified API for open source models", + optionKey: "deepinfraApiKey", + flagName: "--deepinfra-api-key", + envVar: "DEEPINFRA_API_KEY", + promptMessage: "Enter DeepInfra API key", + defaultModel: DEEPINFRA_DEFAULT_MODEL_REF, + expectedProviders: ["deepinfra"], + applyConfig: (cfg) => applyDeepInfraConfig(cfg), + wizard: { + choiceId: "deepinfra-api-key", + choiceLabel: "DeepInfra API key", + groupId: "deepinfra", + groupLabel: "DeepInfra", + groupHint: "Unified API for open source models", + }, + }), + ], + catalog: { + order: "simple", + run: (ctx) => + buildSingleProviderApiKeyCatalog({ + ctx, + providerId: PROVIDER_ID, + buildProvider: buildDeepInfraProviderWithDiscovery, + }), + }, + capabilities: { + openAiCompatTurnValidation: false, + geminiThoughtSignatureSanitization: true, + geminiThoughtSignatureModelHints: ["gemini"], + }, + isCacheTtlEligible: (ctx) => isDeepInfraCacheTtlModel(ctx.modelId), + }); + }, +}); diff --git a/extensions/deepinfra/onboard.ts b/extensions/deepinfra/onboard.ts new file mode 100644 index 00000000000..248eac4ba4c --- /dev/null +++ b/extensions/deepinfra/onboard.ts @@ -0,0 +1,35 @@ +import { + DEEPINFRA_BASE_URL, + DEEPINFRA_DEFAULT_MODEL_REF, +} from "openclaw/plugin-sdk/provider-models"; +import { + applyAgentDefaultModelPrimary, + applyProviderConfigWithModelCatalog, + type OpenClawConfig, +} from "openclaw/plugin-sdk/provider-onboard"; +import { buildDeepInfraStaticProvider } from "./provider-catalog.js"; + +export { DEEPINFRA_BASE_URL, DEEPINFRA_DEFAULT_MODEL_REF }; + +export function applyDeepInfraProviderConfig(cfg: OpenClawConfig): OpenClawConfig { + const models = { ...cfg.agents?.defaults?.models }; + models[DEEPINFRA_DEFAULT_MODEL_REF] = { + ...models[DEEPINFRA_DEFAULT_MODEL_REF], + alias: models[DEEPINFRA_DEFAULT_MODEL_REF]?.alias ?? "DeepInfra", + }; + + return applyProviderConfigWithModelCatalog(cfg, { + agentModels: models, + providerId: "deepinfra", + api: "openai-completions", + baseUrl: DEEPINFRA_BASE_URL, + catalogModels: buildDeepInfraStaticProvider().models ?? [], + }); +} + +export function applyDeepInfraConfig(cfg: OpenClawConfig): OpenClawConfig { + return applyAgentDefaultModelPrimary( + applyDeepInfraProviderConfig(cfg), + DEEPINFRA_DEFAULT_MODEL_REF, + ); +} diff --git a/extensions/deepinfra/openclaw.plugin.json b/extensions/deepinfra/openclaw.plugin.json new file mode 100644 index 00000000000..cac903f6973 --- /dev/null +++ b/extensions/deepinfra/openclaw.plugin.json @@ -0,0 +1,28 @@ +{ + "id": "deepinfra", + "providers": ["deepinfra"], + "providerAuthEnvVars": { + "deepinfra": ["DEEPINFRA_API_KEY"] + }, + "providerAuthChoices": [ + { + "provider": "deepinfra", + "method": "api-key", + "choiceId": "deepinfra-api-key", + "choiceLabel": "DeepInfra API key", + "choiceHint": "Unified API for open source models", + "groupId": "deepinfra", + "groupLabel": "DeepInfra", + "groupHint": "Unified API for open source models", + "optionKey": "deepinfraApiKey", + "cliFlag": "--deepinfra-api-key", + "cliOption": "--deepinfra-api-key ", + "cliDescription": "DeepInfra API key" + } + ], + "configSchema": { + "type": "object", + "additionalProperties": false, + "properties": {} + } +} diff --git a/extensions/deepinfra/package.json b/extensions/deepinfra/package.json new file mode 100644 index 00000000000..67915591d64 --- /dev/null +++ b/extensions/deepinfra/package.json @@ -0,0 +1,12 @@ +{ + "name": "@openclaw/deepinfra-provider", + "version": "2026.3.14", + "private": true, + "description": "OpenClaw DeepInfra provider plugin", + "type": "module", + "openclaw": { + "extensions": [ + "./index.ts" + ] + } +} diff --git a/extensions/deepinfra/provider-catalog.ts b/extensions/deepinfra/provider-catalog.ts index c047e32d986..bedfc5d7fdc 100644 --- a/extensions/deepinfra/provider-catalog.ts +++ b/extensions/deepinfra/provider-catalog.ts @@ -1,13 +1,11 @@ import { - DEEPINFRA_BASE_URL, -} from "../providers/deepinfra-shared.ts"; + type ModelProviderConfig, + discoverDeepInfraModels, + buildDeepInfraStaticCatalog, + DEEPINFRA_BASE_URL, +} from "openclaw/plugin-sdk/provider-models"; -import { - discoverDeepInfraModels, - buildStaticCatalog - } from "./deepinfra-models.js"; - -export async function buildDeepInfraProviderWithDiscovery(): Promise { +export async function buildDeepInfraProviderWithDiscovery(): Promise { const models = await discoverDeepInfraModels(); return { baseUrl: DEEPINFRA_BASE_URL, @@ -16,10 +14,10 @@ export async function buildDeepInfraProviderWithDiscovery(): Promise; -type ProviderConfig = NonNullable[string]; -type ProviderModelConfig = NonNullable[number]; - -const MINIMAX_PORTAL_BASE_URL = "https://api.minimax.io/anthropic"; -const MINIMAX_DEFAULT_MODEL_ID = "MiniMax-M2.5"; -const MINIMAX_DEFAULT_VISION_MODEL_ID = "MiniMax-VL-01"; -const MINIMAX_DEFAULT_CONTEXT_WINDOW = 200000; -const MINIMAX_DEFAULT_MAX_TOKENS = 8192; -const MINIMAX_API_COST = { - input: 0.3, - output: 1.2, - cacheRead: 0.03, - cacheWrite: 0.12, -}; - -function buildMinimaxModel(params: { - id: string; - name: string; - reasoning: boolean; - input: ProviderModelConfig["input"]; -}): ProviderModelConfig { - return { - id: params.id, - name: params.name, - reasoning: params.reasoning, - input: params.input, - cost: MINIMAX_API_COST, - contextWindow: MINIMAX_DEFAULT_CONTEXT_WINDOW, - maxTokens: MINIMAX_DEFAULT_MAX_TOKENS, - }; -} - -function buildMinimaxTextModel(params: { - id: string; - name: string; - reasoning: boolean; -}): ProviderModelConfig { - return buildMinimaxModel({ ...params, input: ["text"] }); -} - -const XIAOMI_BASE_URL = "https://api.xiaomimimo.com/anthropic"; -export const XIAOMI_DEFAULT_MODEL_ID = "mimo-v2-flash"; -const XIAOMI_DEFAULT_CONTEXT_WINDOW = 262144; -const XIAOMI_DEFAULT_MAX_TOKENS = 8192; -const XIAOMI_DEFAULT_COST = { - input: 0, - output: 0, - cacheRead: 0, - cacheWrite: 0, -}; - -const MOONSHOT_BASE_URL = "https://api.moonshot.ai/v1"; -const MOONSHOT_DEFAULT_MODEL_ID = "kimi-k2.5"; -const MOONSHOT_DEFAULT_CONTEXT_WINDOW = 256000; -const MOONSHOT_DEFAULT_MAX_TOKENS = 8192; -const MOONSHOT_DEFAULT_COST = { - input: 0, - output: 0, - cacheRead: 0, - cacheWrite: 0, -}; - -const KIMI_CODING_BASE_URL = "https://api.kimi.com/coding/"; -const KIMI_CODING_DEFAULT_MODEL_ID = "k2p5"; -const KIMI_CODING_DEFAULT_CONTEXT_WINDOW = 262144; -const KIMI_CODING_DEFAULT_MAX_TOKENS = 32768; -const KIMI_CODING_DEFAULT_COST = { - input: 0, - output: 0, - cacheRead: 0, - cacheWrite: 0, -}; - -const QWEN_PORTAL_BASE_URL = "https://portal.qwen.ai/v1"; -const QWEN_PORTAL_DEFAULT_CONTEXT_WINDOW = 128000; -const QWEN_PORTAL_DEFAULT_MAX_TOKENS = 8192; -const QWEN_PORTAL_DEFAULT_COST = { - input: 0, - output: 0, - cacheRead: 0, - cacheWrite: 0, -}; - -const OPENROUTER_BASE_URL = "https://openrouter.ai/api/v1"; -const OPENROUTER_DEFAULT_MODEL_ID = "auto"; -const OPENROUTER_DEFAULT_CONTEXT_WINDOW = 200000; -const OPENROUTER_DEFAULT_MAX_TOKENS = 8192; -const OPENROUTER_DEFAULT_COST = { - input: 0, - output: 0, - cacheRead: 0, - cacheWrite: 0, -}; - -export const QIANFAN_BASE_URL = "https://qianfan.baidubce.com/v2"; -export const QIANFAN_DEFAULT_MODEL_ID = "deepseek-v3.2"; -const QIANFAN_DEFAULT_CONTEXT_WINDOW = 98304; -const QIANFAN_DEFAULT_MAX_TOKENS = 32768; -const QIANFAN_DEFAULT_COST = { - input: 0, - output: 0, - cacheRead: 0, - cacheWrite: 0, -}; - -export const MODELSTUDIO_BASE_URL = "https://coding-intl.dashscope.aliyuncs.com/v1"; -export const MODELSTUDIO_DEFAULT_MODEL_ID = "qwen3.5-plus"; -const MODELSTUDIO_DEFAULT_COST = { - input: 0, - output: 0, - cacheRead: 0, - cacheWrite: 0, -}; - -const MODELSTUDIO_MODEL_CATALOG: ReadonlyArray = [ - { - id: "qwen3.5-plus", - name: "qwen3.5-plus", - reasoning: false, - input: ["text", "image"], - cost: MODELSTUDIO_DEFAULT_COST, - contextWindow: 1_000_000, - maxTokens: 65_536, - }, - { - id: "qwen3-max-2026-01-23", - name: "qwen3-max-2026-01-23", - reasoning: false, - input: ["text"], - cost: MODELSTUDIO_DEFAULT_COST, - contextWindow: 262_144, - maxTokens: 65_536, - }, - { - id: "qwen3-coder-next", - name: "qwen3-coder-next", - reasoning: false, - input: ["text"], - cost: MODELSTUDIO_DEFAULT_COST, - contextWindow: 262_144, - maxTokens: 65_536, - }, - { - id: "qwen3-coder-plus", - name: "qwen3-coder-plus", - reasoning: false, - input: ["text"], - cost: MODELSTUDIO_DEFAULT_COST, - contextWindow: 1_000_000, - maxTokens: 65_536, - }, - { - id: "MiniMax-M2.5", - name: "MiniMax-M2.5", - reasoning: false, - input: ["text"], - cost: MODELSTUDIO_DEFAULT_COST, - contextWindow: 1_000_000, - maxTokens: 65_536, - }, - { - id: "glm-5", - name: "glm-5", - reasoning: false, - input: ["text"], - cost: MODELSTUDIO_DEFAULT_COST, - contextWindow: 202_752, - maxTokens: 16_384, - }, - { - id: "glm-4.7", - name: "glm-4.7", - reasoning: false, - input: ["text"], - cost: MODELSTUDIO_DEFAULT_COST, - contextWindow: 202_752, - maxTokens: 16_384, - }, - { - id: "kimi-k2.5", - name: "kimi-k2.5", - reasoning: false, - input: ["text", "image"], - cost: MODELSTUDIO_DEFAULT_COST, - contextWindow: 262_144, - maxTokens: 32_768, - }, -]; - -const NVIDIA_BASE_URL = "https://integrate.api.nvidia.com/v1"; -const NVIDIA_DEFAULT_MODEL_ID = "nvidia/llama-3.1-nemotron-70b-instruct"; -const NVIDIA_DEFAULT_CONTEXT_WINDOW = 131072; -const NVIDIA_DEFAULT_MAX_TOKENS = 4096; -const NVIDIA_DEFAULT_COST = { - input: 0, - output: 0, - cacheRead: 0, - cacheWrite: 0, -}; - -const OPENAI_CODEX_BASE_URL = "https://chatgpt.com/backend-api"; - -export function buildMinimaxProvider(): ProviderConfig { - return { - baseUrl: MINIMAX_PORTAL_BASE_URL, - api: "anthropic-messages", - authHeader: true, - models: [ - buildMinimaxModel({ - id: MINIMAX_DEFAULT_VISION_MODEL_ID, - name: "MiniMax VL 01", - reasoning: false, - input: ["text", "image"], - }), - buildMinimaxTextModel({ - id: "MiniMax-M2.5", - name: "MiniMax M2.5", - reasoning: true, - }), - buildMinimaxTextModel({ - id: "MiniMax-M2.5-highspeed", - name: "MiniMax M2.5 Highspeed", - reasoning: true, - }), - ], - }; -} - -export function buildMinimaxPortalProvider(): ProviderConfig { - return { - baseUrl: MINIMAX_PORTAL_BASE_URL, - api: "anthropic-messages", - authHeader: true, - models: [ - buildMinimaxModel({ - id: MINIMAX_DEFAULT_VISION_MODEL_ID, - name: "MiniMax VL 01", - reasoning: false, - input: ["text", "image"], - }), - buildMinimaxTextModel({ - id: MINIMAX_DEFAULT_MODEL_ID, - name: "MiniMax M2.5", - reasoning: true, - }), - buildMinimaxTextModel({ - id: "MiniMax-M2.5-highspeed", - name: "MiniMax M2.5 Highspeed", - reasoning: true, - }), - ], - }; -} - -export function buildMoonshotProvider(): ProviderConfig { - return { - baseUrl: MOONSHOT_BASE_URL, - api: "openai-completions", - models: [ - { - id: MOONSHOT_DEFAULT_MODEL_ID, - name: "Kimi K2.5", - reasoning: false, - input: ["text", "image"], - cost: MOONSHOT_DEFAULT_COST, - contextWindow: MOONSHOT_DEFAULT_CONTEXT_WINDOW, - maxTokens: MOONSHOT_DEFAULT_MAX_TOKENS, - }, - ], - }; -} - -export function buildKimiCodingProvider(): ProviderConfig { - return { - baseUrl: KIMI_CODING_BASE_URL, - api: "anthropic-messages", - models: [ - { - id: KIMI_CODING_DEFAULT_MODEL_ID, - name: "Kimi for Coding", - reasoning: true, - input: ["text", "image"], - cost: KIMI_CODING_DEFAULT_COST, - contextWindow: KIMI_CODING_DEFAULT_CONTEXT_WINDOW, - maxTokens: KIMI_CODING_DEFAULT_MAX_TOKENS, - }, - ], - }; -} - -export function buildQwenPortalProvider(): ProviderConfig { - return { - baseUrl: QWEN_PORTAL_BASE_URL, - api: "openai-completions", - models: [ - { - id: "coder-model", - name: "Qwen Coder", - reasoning: false, - input: ["text"], - cost: QWEN_PORTAL_DEFAULT_COST, - contextWindow: QWEN_PORTAL_DEFAULT_CONTEXT_WINDOW, - maxTokens: QWEN_PORTAL_DEFAULT_MAX_TOKENS, - }, - { - id: "vision-model", - name: "Qwen Vision", - reasoning: false, - input: ["text", "image"], - cost: QWEN_PORTAL_DEFAULT_COST, - contextWindow: QWEN_PORTAL_DEFAULT_CONTEXT_WINDOW, - maxTokens: QWEN_PORTAL_DEFAULT_MAX_TOKENS, - }, - ], - }; -} - -export function buildSyntheticProvider(): ProviderConfig { - return { - baseUrl: SYNTHETIC_BASE_URL, - api: "anthropic-messages", - models: SYNTHETIC_MODEL_CATALOG.map(buildSyntheticModelDefinition), - }; -} - -export function buildDoubaoProvider(): ProviderConfig { - return { - baseUrl: DOUBAO_BASE_URL, - api: "openai-completions", - models: DOUBAO_MODEL_CATALOG.map(buildDoubaoModelDefinition), - }; -} - -export function buildDoubaoCodingProvider(): ProviderConfig { - return { - baseUrl: DOUBAO_CODING_BASE_URL, - api: "openai-completions", - models: DOUBAO_CODING_MODEL_CATALOG.map(buildDoubaoModelDefinition), - }; -} - -export function buildBytePlusProvider(): ProviderConfig { - return { - baseUrl: BYTEPLUS_BASE_URL, - api: "openai-completions", - models: BYTEPLUS_MODEL_CATALOG.map(buildBytePlusModelDefinition), - }; -} - -export function buildBytePlusCodingProvider(): ProviderConfig { - return { - baseUrl: BYTEPLUS_CODING_BASE_URL, - api: "openai-completions", - models: BYTEPLUS_CODING_MODEL_CATALOG.map(buildBytePlusModelDefinition), - }; -} - -export function buildXiaomiProvider(): ProviderConfig { - return { - baseUrl: XIAOMI_BASE_URL, - api: "anthropic-messages", - models: [ - { - id: XIAOMI_DEFAULT_MODEL_ID, - name: "Xiaomi MiMo V2 Flash", - reasoning: false, - input: ["text"], - cost: XIAOMI_DEFAULT_COST, - contextWindow: XIAOMI_DEFAULT_CONTEXT_WINDOW, - maxTokens: XIAOMI_DEFAULT_MAX_TOKENS, - }, - ], - }; -} - -export function buildTogetherProvider(): ProviderConfig { - return { - baseUrl: TOGETHER_BASE_URL, - api: "openai-completions", - models: TOGETHER_MODEL_CATALOG.map(buildTogetherModelDefinition), - }; -} - -export function buildOpenrouterProvider(): ProviderConfig { - return { - baseUrl: OPENROUTER_BASE_URL, - api: "openai-completions", - models: [ - { - id: OPENROUTER_DEFAULT_MODEL_ID, - name: "OpenRouter Auto", - reasoning: false, - input: ["text", "image"], - cost: OPENROUTER_DEFAULT_COST, - contextWindow: OPENROUTER_DEFAULT_CONTEXT_WINDOW, - maxTokens: OPENROUTER_DEFAULT_MAX_TOKENS, - }, - { - id: "openrouter/hunter-alpha", - name: "Hunter Alpha", - reasoning: true, - input: ["text"], - cost: OPENROUTER_DEFAULT_COST, - contextWindow: 1048576, - maxTokens: 65536, - }, - { - id: "openrouter/healer-alpha", - name: "Healer Alpha", - reasoning: true, - input: ["text", "image"], - cost: OPENROUTER_DEFAULT_COST, - contextWindow: 262144, - maxTokens: 65536, - }, - ], - }; -} - -export function buildOpenAICodexProvider(): ProviderConfig { - return { - baseUrl: OPENAI_CODEX_BASE_URL, - api: "openai-codex-responses", - models: [], - }; -} - -export function buildQianfanProvider(): ProviderConfig { - return { - baseUrl: QIANFAN_BASE_URL, - api: "openai-completions", - models: [ - { - id: QIANFAN_DEFAULT_MODEL_ID, - name: "DEEPSEEK V3.2", - reasoning: true, - input: ["text"], - cost: QIANFAN_DEFAULT_COST, - contextWindow: QIANFAN_DEFAULT_CONTEXT_WINDOW, - maxTokens: QIANFAN_DEFAULT_MAX_TOKENS, - }, - { - id: "ernie-5.0-thinking-preview", - name: "ERNIE-5.0-Thinking-Preview", - reasoning: true, - input: ["text", "image"], - cost: QIANFAN_DEFAULT_COST, - contextWindow: 119000, - maxTokens: 64000, - }, - ], - }; -} - -export function buildModelStudioProvider(): ProviderConfig { - return { - baseUrl: MODELSTUDIO_BASE_URL, - api: "openai-completions", - models: MODELSTUDIO_MODEL_CATALOG.map((model) => ({ ...model })), - }; -} - -export function buildNvidiaProvider(): ProviderConfig { - return { - baseUrl: NVIDIA_BASE_URL, - api: "openai-completions", - models: [ - { - id: NVIDIA_DEFAULT_MODEL_ID, - name: "NVIDIA Llama 3.1 Nemotron 70B Instruct", - reasoning: false, - input: ["text"], - cost: NVIDIA_DEFAULT_COST, - contextWindow: NVIDIA_DEFAULT_CONTEXT_WINDOW, - maxTokens: NVIDIA_DEFAULT_MAX_TOKENS, - }, - { - id: "meta/llama-3.3-70b-instruct", - name: "Meta Llama 3.3 70B Instruct", - reasoning: false, - input: ["text"], - cost: NVIDIA_DEFAULT_COST, - contextWindow: 131072, - maxTokens: 4096, - }, - { - id: "nvidia/mistral-nemo-minitron-8b-8k-instruct", - name: "NVIDIA Mistral NeMo Minitron 8B Instruct", - reasoning: false, - input: ["text"], - cost: NVIDIA_DEFAULT_COST, - contextWindow: 8192, - maxTokens: 2048, - }, - ], - }; -} - -export function buildKilocodeProvider(): ProviderConfig { - return { - baseUrl: KILOCODE_BASE_URL, - api: "openai-completions", - models: KILOCODE_MODEL_CATALOG.map((model) => ({ - id: model.id, - name: model.name, - reasoning: model.reasoning, - input: model.input, - cost: KILOCODE_DEFAULT_COST, - contextWindow: model.contextWindow ?? KILOCODE_DEFAULT_CONTEXT_WINDOW, - maxTokens: model.maxTokens ?? KILOCODE_DEFAULT_MAX_TOKENS, - })), - }; -} - -export function buildDeepInfraStaticProvider(): ProviderConfig { - return { - baseUrl: DEEPINFRA_BASE_URL, - api: "openai-completions", - models: buildStaticCatalog(), - }; -} ->>>>>>> c1f76e734 (Addressed comment: Duplicated catalog-mapping logic with buildDeepInfraStaticProvider) diff --git a/src/agents/models-config.providers.ts b/src/agents/models-config.providers.ts index af9c3d6e34a..1fa7289ef54 100644 --- a/src/agents/models-config.providers.ts +++ b/src/agents/models-config.providers.ts @@ -11,6 +11,7 @@ import { ensureAuthProfileStore, listProfilesForProvider } from "./auth-profiles import { discoverBedrockModels } from "./bedrock-discovery.js"; import { normalizeGoogleModelId } from "./model-id-normalization.js"; import { resolveOllamaApiBase } from "./models-config.providers.discovery.js"; +export { buildDeepInfraStaticProvider } from "../../extensions/deepinfra/provider-catalog.js"; export { buildKimiCodingProvider } from "../../extensions/kimi-coding/provider-catalog.js"; export { buildKilocodeProvider } from "../../extensions/kilocode/provider-catalog.js"; export { diff --git a/src/agents/pi-embedded-runner/cache-ttl.test.ts b/src/agents/pi-embedded-runner/cache-ttl.test.ts index 066cb555a30..a806309a240 100644 --- a/src/agents/pi-embedded-runner/cache-ttl.test.ts +++ b/src/agents/pi-embedded-runner/cache-ttl.test.ts @@ -15,6 +15,11 @@ vi.mock("../../plugins/provider-runtime.js", () => ({ params.context.modelId.startsWith(prefix), ); } + if (params.context.provider === "deepinfra") { + return ["anthropic/", "moonshot/", "moonshotai/", "zai/", "zai-org/"].some((prefix) => + params.context.modelId.startsWith(prefix), + ); + } return undefined; }, })); diff --git a/src/agents/pi-embedded-runner/deepinfra.test.ts b/src/agents/pi-embedded-runner/deepinfra.test.ts index 710514637e5..7c8a19a9a67 100644 --- a/src/agents/pi-embedded-runner/deepinfra.test.ts +++ b/src/agents/pi-embedded-runner/deepinfra.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from "vitest"; -import { isCacheTtlEligibleProvider } from "./cache-ttl.ts"; +import { isCacheTtlEligibleProvider } from "./cache-ttl.js"; describe("deepinfra cache-ttl eligibility", () => { it("is eligible when model starts with zai", () => { diff --git a/src/commands/onboard-auth.config-core.deepinfra.test.ts b/src/commands/onboard-auth.config-core.deepinfra.test.ts index bc3c19f6b9c..b80b2a4544f 100644 --- a/src/commands/onboard-auth.config-core.deepinfra.test.ts +++ b/src/commands/onboard-auth.config-core.deepinfra.test.ts @@ -2,20 +2,23 @@ import { mkdtempSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { describe, expect, it } from "vitest"; +import { + applyDeepInfraProviderConfig, + applyDeepInfraConfig, +} from "../../extensions/deepinfra/onboard.js"; import { resolveApiKeyForProvider, resolveEnvApiKey } from "../agents/model-auth.js"; import type { OpenClawConfig } from "../config/config.js"; import { resolveAgentModelPrimaryValue } from "../config/model-input.js"; import { DEEPINFRA_BASE_URL, + DEEPINFRA_DEFAULT_CONTEXT_WINDOW, + DEEPINFRA_DEFAULT_COST, DEEPINFRA_DEFAULT_MODEL_ID, DEEPINFRA_DEFAULT_MODEL_REF, - DEEPINFRA_DEFAULT_CONTEXT_WINDOW, DEEPINFRA_DEFAULT_MAX_TOKENS, - DEEPINFRA_DEFAULT_COST, DEEPINFRA_MODEL_CATALOG, } from "../providers/deepinfra-shared.js"; import { captureEnv } from "../test-utils/env.js"; -import { applyDeepInfraProviderConfig, applyDeepInfraConfig } from "./onboard-auth.config-core.js"; const emptyCfg: OpenClawConfig = {}; const DEEPINFRA_MODEL_IDS = DEEPINFRA_MODEL_CATALOG.map((m) => m.id); diff --git a/src/commands/onboard-auth.ts b/src/commands/onboard-auth.ts deleted file mode 100644 index ab154bbc58f..00000000000 --- a/src/commands/onboard-auth.ts +++ /dev/null @@ -1,141 +0,0 @@ -export { - SYNTHETIC_DEFAULT_MODEL_ID, - SYNTHETIC_DEFAULT_MODEL_REF, -} from "../agents/synthetic-models.js"; -export { VENICE_DEFAULT_MODEL_ID, VENICE_DEFAULT_MODEL_REF } from "../agents/venice-models.js"; -export { - applyAuthProfileConfig, - applyCloudflareAiGatewayConfig, - applyCloudflareAiGatewayProviderConfig, - applyHuggingfaceConfig, - applyHuggingfaceProviderConfig, - applyDeepInfraConfig, - applyDeepInfraProviderConfig, - applyKilocodeConfig, - applyKilocodeProviderConfig, - applyQianfanConfig, - applyQianfanProviderConfig, - applyKimiCodeConfig, - applyKimiCodeProviderConfig, - applyLitellmConfig, - applyLitellmProviderConfig, - applyMistralConfig, - applyMistralProviderConfig, - applyMoonshotConfig, - applyMoonshotConfigCn, - applyMoonshotProviderConfig, - applyMoonshotProviderConfigCn, - applyOpenrouterConfig, - applyOpenrouterProviderConfig, - applySyntheticConfig, - applySyntheticProviderConfig, - applyTogetherConfig, - applyTogetherProviderConfig, - applyVeniceConfig, - applyVeniceProviderConfig, - applyVercelAiGatewayConfig, - applyVercelAiGatewayProviderConfig, - applyXaiConfig, - applyXaiProviderConfig, - applyXiaomiConfig, - applyXiaomiProviderConfig, - applyZaiConfig, - applyZaiProviderConfig, - applyModelStudioConfig, - applyModelStudioConfigCn, - applyModelStudioProviderConfig, - applyModelStudioProviderConfigCn, - KILOCODE_BASE_URL, -} from "./onboard-auth.config-core.js"; -export { - applyMinimaxApiConfig, - applyMinimaxApiConfigCn, - applyMinimaxApiProviderConfig, - applyMinimaxApiProviderConfigCn, - applyMinimaxConfig, - applyMinimaxHostedConfig, - applyMinimaxHostedProviderConfig, - applyMinimaxProviderConfig, -} from "./onboard-auth.config-minimax.js"; - -export { - applyOpencodeZenConfig, - applyOpencodeZenProviderConfig, -} from "./onboard-auth.config-opencode.js"; -export { - applyOpencodeGoConfig, - applyOpencodeGoProviderConfig, -} from "./onboard-auth.config-opencode-go.js"; -export { - CLOUDFLARE_AI_GATEWAY_DEFAULT_MODEL_REF, - DEEPINFRA_DEFAULT_MODEL_REF, - KILOCODE_DEFAULT_MODEL_REF, - LITELLM_DEFAULT_MODEL_REF, - OPENROUTER_DEFAULT_MODEL_REF, - setOpenaiApiKey, - setAnthropicApiKey, - setCloudflareAiGatewayConfig, - setByteplusApiKey, - setQianfanApiKey, - setGeminiApiKey, - setDeepInfraApiKey, - setKilocodeApiKey, - setLitellmApiKey, - setKimiCodingApiKey, - setMinimaxApiKey, - setMistralApiKey, - setMoonshotApiKey, - setOpencodeGoApiKey, - setOpencodeZenApiKey, - setOpenrouterApiKey, - setSyntheticApiKey, - setTogetherApiKey, - setHuggingfaceApiKey, - setVeniceApiKey, - setVercelAiGatewayApiKey, - setXiaomiApiKey, - setVolcengineApiKey, - setZaiApiKey, - setXaiApiKey, - setModelStudioApiKey, - writeOAuthCredentials, - HUGGINGFACE_DEFAULT_MODEL_REF, - VERCEL_AI_GATEWAY_DEFAULT_MODEL_REF, - XIAOMI_DEFAULT_MODEL_REF, - ZAI_DEFAULT_MODEL_REF, - TOGETHER_DEFAULT_MODEL_REF, - MISTRAL_DEFAULT_MODEL_REF, - XAI_DEFAULT_MODEL_REF, - MODELSTUDIO_DEFAULT_MODEL_REF, -} from "./onboard-auth.credentials.js"; -export { - buildKilocodeModelDefinition, - buildMinimaxApiModelDefinition, - buildMinimaxModelDefinition, - buildMistralModelDefinition, - buildMoonshotModelDefinition, - buildZaiModelDefinition, - DEFAULT_MINIMAX_BASE_URL, - KILOCODE_DEFAULT_MODEL_ID, - MOONSHOT_CN_BASE_URL, - QIANFAN_BASE_URL, - QIANFAN_DEFAULT_MODEL_ID, - QIANFAN_DEFAULT_MODEL_REF, - KIMI_CODING_MODEL_ID, - KIMI_CODING_MODEL_REF, - MINIMAX_API_BASE_URL, - MINIMAX_CN_API_BASE_URL, - MINIMAX_HOSTED_MODEL_ID, - MINIMAX_HOSTED_MODEL_REF, - MOONSHOT_BASE_URL, - MOONSHOT_DEFAULT_MODEL_ID, - MOONSHOT_DEFAULT_MODEL_REF, - MISTRAL_BASE_URL, - MISTRAL_DEFAULT_MODEL_ID, - resolveZaiBaseUrl, - ZAI_CODING_CN_BASE_URL, - ZAI_DEFAULT_MODEL_ID, - ZAI_CODING_GLOBAL_BASE_URL, - ZAI_CN_BASE_URL, - ZAI_GLOBAL_BASE_URL, -} from "./onboard-auth.models.js"; diff --git a/src/plugin-sdk/provider-models.ts b/src/plugin-sdk/provider-models.ts index 7103147e91d..b2d033ae138 100644 --- a/src/plugin-sdk/provider-models.ts +++ b/src/plugin-sdk/provider-models.ts @@ -105,6 +105,11 @@ export { discoverVercelAiGatewayModels, VERCEL_AI_GATEWAY_BASE_URL, } from "../agents/vercel-ai-gateway.js"; +export { DEEPINFRA_BASE_URL, DEEPINFRA_DEFAULT_MODEL_REF } from "../providers/deepinfra-shared.js"; +export { + buildStaticCatalog as buildDeepInfraStaticCatalog, + discoverDeepInfraModels, +} from "../agents/deepinfra-models.js"; export function buildKilocodeModelDefinition(): ModelDefinitionConfig { return { diff --git a/src/plugins/bundled-provider-auth-env-vars.generated.ts b/src/plugins/bundled-provider-auth-env-vars.generated.ts index 80ebcedc2b9..116f83e16a7 100644 --- a/src/plugins/bundled-provider-auth-env-vars.generated.ts +++ b/src/plugins/bundled-provider-auth-env-vars.generated.ts @@ -6,6 +6,7 @@ export const BUNDLED_PROVIDER_AUTH_ENV_VAR_CANDIDATES = { byteplus: ["BYTEPLUS_API_KEY"], chutes: ["CHUTES_API_KEY", "CHUTES_OAUTH_TOKEN"], "cloudflare-ai-gateway": ["CLOUDFLARE_AI_GATEWAY_API_KEY"], + deepinfra: ["DEEPINFRA_API_KEY"], fal: ["FAL_KEY"], firecrawl: ["FIRECRAWL_API_KEY"], "github-copilot": ["COPILOT_GITHUB_TOKEN", "GH_TOKEN", "GITHUB_TOKEN"], diff --git a/src/plugins/contracts/registry.ts b/src/plugins/contracts/registry.ts index cde5b8e8e2d..130747ad683 100644 --- a/src/plugins/contracts/registry.ts +++ b/src/plugins/contracts/registry.ts @@ -5,6 +5,7 @@ import byteplusPlugin from "../../../extensions/byteplus/index.js"; import chutesPlugin from "../../../extensions/chutes/index.js"; import cloudflareAiGatewayPlugin from "../../../extensions/cloudflare-ai-gateway/index.js"; import copilotProxyPlugin from "../../../extensions/copilot-proxy/index.js"; +import deepinfraPlugin from "../../../extensions/deepinfra/index.js"; import elevenLabsPlugin from "../../../extensions/elevenlabs/index.js"; import falPlugin from "../../../extensions/fal/index.js"; import firecrawlPlugin from "../../../extensions/firecrawl/index.js"; @@ -360,6 +361,7 @@ const bundledProviderPlugins = dedupePlugins([ chutesPlugin, cloudflareAiGatewayPlugin, copilotProxyPlugin, + deepinfraPlugin, githubCopilotPlugin, falPlugin, googlePlugin, diff --git a/src/secrets/provider-env-vars.ts b/src/secrets/provider-env-vars.ts index d0cd661a999..269b37d836a 100644 --- a/src/secrets/provider-env-vars.ts +++ b/src/secrets/provider-env-vars.ts @@ -7,7 +7,6 @@ const CORE_PROVIDER_AUTH_ENV_VAR_CANDIDATES = { deepgram: ["DEEPGRAM_API_KEY"], cerebras: ["CEREBRAS_API_KEY"], litellm: ["LITELLM_API_KEY"], - deepinfra: ["DEEPINFRA_API_KEY"], } as const; const CORE_PROVIDER_SETUP_ENV_VAR_OVERRIDES = {