mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 02:07:26 +00:00
feat: Add Kilo Gateway provider (#20212)
* feat: Add Kilo Gateway provider Add support for Kilo Gateway as a model provider, similar to OpenRouter. Kilo Gateway provides a unified API that routes requests to many models behind a single endpoint and API key. Changes: - Add kilocode provider option to auth-choice and onboarding flows - Add KILOCODE_API_KEY environment variable support - Add kilocode/ model prefix handling in model-auth and extra-params - Add provider documentation in docs/providers/kilocode.md - Update model-providers.md with Kilo Gateway section - Add design doc for the integration * kilocode: add provider tests and normalize onboard auth-choice registration * kilocode: register in resolveImplicitProviders so models appear in provider filter * kilocode: update base URL from /api/openrouter/ to /api/gateway/ * docs: fix formatting in kilocode docs * fix: address PR review — remove kilocode from cacheRetention, fix stale model refs and CLI name in docs, fix TS2742 * docs: fix stale refs in design doc — Moltbot to OpenClaw, MoltbotConfig to OpenClawConfig, remove extra-params section, fix doc path * fix: use resolveAgentModelPrimaryValue for AgentModelConfig union type --------- Co-authored-by: Mark IJbema <mark@kilocode.ai>
This commit is contained in:
@@ -322,6 +322,7 @@ export function resolveEnvApiKey(provider: string): EnvApiKeyResult | null {
|
||||
qianfan: "QIANFAN_API_KEY",
|
||||
ollama: "OLLAMA_API_KEY",
|
||||
vllm: "VLLM_API_KEY",
|
||||
kilocode: "KILOCODE_API_KEY",
|
||||
};
|
||||
const envVar = envMap[normalized];
|
||||
if (!envVar) {
|
||||
|
||||
49
src/agents/models-config.providers.kilocode.test.ts
Normal file
49
src/agents/models-config.providers.kilocode.test.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { mkdtempSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { captureEnv } from "../test-utils/env.js";
|
||||
import { buildKilocodeProvider, resolveImplicitProviders } from "./models-config.providers.js";
|
||||
|
||||
describe("Kilo Gateway implicit provider", () => {
|
||||
it("should include kilocode when KILOCODE_API_KEY is configured", async () => {
|
||||
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
|
||||
const envSnapshot = captureEnv(["KILOCODE_API_KEY"]);
|
||||
process.env.KILOCODE_API_KEY = "test-key";
|
||||
|
||||
try {
|
||||
const providers = await resolveImplicitProviders({ agentDir });
|
||||
expect(providers?.kilocode).toBeDefined();
|
||||
expect(providers?.kilocode?.models?.length).toBeGreaterThan(0);
|
||||
} finally {
|
||||
envSnapshot.restore();
|
||||
}
|
||||
});
|
||||
|
||||
it("should not include kilocode when no API key is configured", async () => {
|
||||
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
|
||||
const envSnapshot = captureEnv(["KILOCODE_API_KEY"]);
|
||||
delete process.env.KILOCODE_API_KEY;
|
||||
|
||||
try {
|
||||
const providers = await resolveImplicitProviders({ agentDir });
|
||||
expect(providers?.kilocode).toBeUndefined();
|
||||
} finally {
|
||||
envSnapshot.restore();
|
||||
}
|
||||
});
|
||||
|
||||
it("should build kilocode provider with correct configuration", () => {
|
||||
const provider = buildKilocodeProvider();
|
||||
expect(provider.baseUrl).toBe("https://api.kilo.ai/api/gateway/");
|
||||
expect(provider.api).toBe("openai-completions");
|
||||
expect(provider.models).toBeDefined();
|
||||
expect(provider.models.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("should include the default kilocode model", () => {
|
||||
const provider = buildKilocodeProvider();
|
||||
const modelIds = provider.models.map((m) => m.id);
|
||||
expect(modelIds).toContain("anthropic/claude-opus-4.6");
|
||||
});
|
||||
});
|
||||
@@ -764,6 +764,36 @@ export function buildNvidiaProvider(): ProviderConfig {
|
||||
};
|
||||
}
|
||||
|
||||
// Kilo Gateway provider
|
||||
const KILOCODE_BASE_URL = "https://api.kilo.ai/api/gateway/";
|
||||
const KILOCODE_DEFAULT_MODEL_ID = "anthropic/claude-opus-4.6";
|
||||
const KILOCODE_DEFAULT_CONTEXT_WINDOW = 200000;
|
||||
const KILOCODE_DEFAULT_MAX_TOKENS = 8192;
|
||||
const KILOCODE_DEFAULT_COST = {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
};
|
||||
|
||||
export function buildKilocodeProvider(): ProviderConfig {
|
||||
return {
|
||||
baseUrl: KILOCODE_BASE_URL,
|
||||
api: "openai-completions",
|
||||
models: [
|
||||
{
|
||||
id: KILOCODE_DEFAULT_MODEL_ID,
|
||||
name: "Claude Opus 4.6",
|
||||
reasoning: true,
|
||||
input: ["text", "image"],
|
||||
cost: KILOCODE_DEFAULT_COST,
|
||||
contextWindow: KILOCODE_DEFAULT_CONTEXT_WINDOW,
|
||||
maxTokens: KILOCODE_DEFAULT_MAX_TOKENS,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
export async function resolveImplicitProviders(params: {
|
||||
agentDir: string;
|
||||
explicitProviders?: Record<string, ProviderConfig> | null;
|
||||
@@ -951,6 +981,13 @@ export async function resolveImplicitProviders(params: {
|
||||
providers.nvidia = { ...buildNvidiaProvider(), apiKey: nvidiaKey };
|
||||
}
|
||||
|
||||
const kilocodeKey =
|
||||
resolveEnvApiKeyVarName("kilocode") ??
|
||||
resolveApiKeyFromProfiles({ provider: "kilocode", store: authStore });
|
||||
if (kilocodeKey) {
|
||||
providers.kilocode = { ...buildKilocodeProvider(), apiKey: kilocodeKey };
|
||||
}
|
||||
|
||||
return providers;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,9 @@ export function isCacheTtlEligibleProvider(provider: string, modelId: string): b
|
||||
if (normalizedProvider === "openrouter" && isOpenRouterCacheTtlModel(normalizedModelId)) {
|
||||
return true;
|
||||
}
|
||||
if (normalizedProvider === "kilocode" && normalizedModelId.startsWith("anthropic/")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
21
src/agents/pi-embedded-runner/kilocode.test.ts
Normal file
21
src/agents/pi-embedded-runner/kilocode.test.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { isCacheTtlEligibleProvider } from "./cache-ttl.js";
|
||||
|
||||
describe("kilocode cache-ttl eligibility", () => {
|
||||
it("is eligible when model starts with anthropic/", () => {
|
||||
expect(isCacheTtlEligibleProvider("kilocode", "anthropic/claude-opus-4.6")).toBe(true);
|
||||
});
|
||||
|
||||
it("is eligible with other anthropic models", () => {
|
||||
expect(isCacheTtlEligibleProvider("kilocode", "anthropic/claude-sonnet-4")).toBe(true);
|
||||
});
|
||||
|
||||
it("is not eligible for non-anthropic models on kilocode", () => {
|
||||
expect(isCacheTtlEligibleProvider("kilocode", "openai/gpt-5")).toBe(false);
|
||||
});
|
||||
|
||||
it("is case-insensitive for provider name", () => {
|
||||
expect(isCacheTtlEligibleProvider("Kilocode", "anthropic/claude-opus-4.6")).toBe(true);
|
||||
expect(isCacheTtlEligibleProvider("KILOCODE", "Anthropic/claude-opus-4.6")).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -91,7 +91,7 @@ export function resolveTranscriptPolicy(params: {
|
||||
!OPENAI_COMPAT_TURN_MERGE_EXCLUDED_PROVIDERS.has(provider);
|
||||
const isMistral = isMistralModel({ provider, modelId });
|
||||
const isOpenRouterGemini =
|
||||
(provider === "openrouter" || provider === "opencode") &&
|
||||
(provider === "openrouter" || provider === "opencode" || provider === "kilocode") &&
|
||||
modelId.toLowerCase().includes("gemini");
|
||||
const isCopilotClaude = provider === "github-copilot" && modelId.toLowerCase().includes("claude");
|
||||
|
||||
|
||||
@@ -133,6 +133,7 @@ export function registerOnboardCommand(program: Command) {
|
||||
openaiApiKey: opts.openaiApiKey as string | undefined,
|
||||
mistralApiKey: opts.mistralApiKey as string | undefined,
|
||||
openrouterApiKey: opts.openrouterApiKey as string | undefined,
|
||||
kilocodeApiKey: opts.kilocodeApiKey as string | undefined,
|
||||
aiGatewayApiKey: opts.aiGatewayApiKey as string | undefined,
|
||||
cloudflareAiGatewayAccountId: opts.cloudflareAiGatewayAccountId as string | undefined,
|
||||
cloudflareAiGatewayGatewayId: opts.cloudflareAiGatewayGatewayId as string | undefined,
|
||||
|
||||
@@ -94,6 +94,12 @@ const AUTH_CHOICE_GROUP_DEFS: {
|
||||
hint: "API key",
|
||||
choices: ["openrouter-api-key"],
|
||||
},
|
||||
{
|
||||
value: "kilocode",
|
||||
label: "Kilo Gateway",
|
||||
hint: "API key (OpenRouter-compatible)",
|
||||
choices: ["kilocode-api-key"],
|
||||
},
|
||||
{
|
||||
value: "qwen",
|
||||
label: "Qwen",
|
||||
@@ -206,6 +212,7 @@ const BASE_AUTH_CHOICE_OPTIONS: ReadonlyArray<AuthChoiceOption> = [
|
||||
label: "Qianfan API key",
|
||||
},
|
||||
{ value: "openrouter-api-key", label: "OpenRouter API key" },
|
||||
{ value: "kilocode-api-key", label: "Kilo Gateway API key" },
|
||||
{
|
||||
value: "litellm-api-key",
|
||||
label: "LiteLLM API key",
|
||||
|
||||
@@ -23,6 +23,8 @@ import {
|
||||
applyAuthProfileConfig,
|
||||
applyCloudflareAiGatewayConfig,
|
||||
applyCloudflareAiGatewayProviderConfig,
|
||||
applyKilocodeConfig,
|
||||
applyKilocodeProviderConfig,
|
||||
applyQianfanConfig,
|
||||
applyQianfanProviderConfig,
|
||||
applyKimiCodeConfig,
|
||||
@@ -50,6 +52,7 @@ import {
|
||||
applyZaiConfig,
|
||||
applyZaiProviderConfig,
|
||||
CLOUDFLARE_AI_GATEWAY_DEFAULT_MODEL_REF,
|
||||
KILOCODE_DEFAULT_MODEL_REF,
|
||||
LITELLM_DEFAULT_MODEL_REF,
|
||||
QIANFAN_DEFAULT_MODEL_REF,
|
||||
KIMI_CODING_MODEL_REF,
|
||||
@@ -63,6 +66,7 @@ import {
|
||||
setCloudflareAiGatewayConfig,
|
||||
setQianfanApiKey,
|
||||
setGeminiApiKey,
|
||||
setKilocodeApiKey,
|
||||
setLitellmApiKey,
|
||||
setKimiCodingApiKey,
|
||||
setMistralApiKey,
|
||||
@@ -97,6 +101,7 @@ const API_KEY_TOKEN_PROVIDER_AUTH_CHOICE: Record<string, AuthChoice> = {
|
||||
huggingface: "huggingface-api-key",
|
||||
mistral: "mistral-api-key",
|
||||
opencode: "opencode-zen",
|
||||
kilocode: "kilocode-api-key",
|
||||
qianfan: "qianfan-api-key",
|
||||
};
|
||||
|
||||
@@ -277,6 +282,18 @@ const SIMPLE_API_KEY_PROVIDER_FLOWS: Partial<Record<AuthChoice, SimpleApiKeyProv
|
||||
].join("\n"),
|
||||
noteTitle: "QIANFAN",
|
||||
},
|
||||
"kilocode-api-key": {
|
||||
provider: "kilocode",
|
||||
profileId: "kilocode:default",
|
||||
expectedProviders: ["kilocode"],
|
||||
envLabel: "KILOCODE_API_KEY",
|
||||
promptMessage: "Enter Kilo Gateway API key",
|
||||
setCredential: setKilocodeApiKey,
|
||||
defaultModel: KILOCODE_DEFAULT_MODEL_REF,
|
||||
applyDefaultConfig: applyKilocodeConfig,
|
||||
applyProviderConfig: applyKilocodeProviderConfig,
|
||||
noteDefault: KILOCODE_DEFAULT_MODEL_REF,
|
||||
},
|
||||
"synthetic-api-key": {
|
||||
provider: "synthetic",
|
||||
profileId: "synthetic:default",
|
||||
|
||||
@@ -12,6 +12,7 @@ const PREFERRED_PROVIDER_BY_AUTH_CHOICE: Partial<Record<AuthChoice, string>> = {
|
||||
chutes: "chutes",
|
||||
"openai-api-key": "openai",
|
||||
"openrouter-api-key": "openrouter",
|
||||
"kilocode-api-key": "kilocode",
|
||||
"ai-gateway-api-key": "vercel-ai-gateway",
|
||||
"cloudflare-ai-gateway-api-key": "cloudflare-ai-gateway",
|
||||
"moonshot-api-key": "moonshot",
|
||||
|
||||
168
src/commands/onboard-auth.config-core.kilocode.test.ts
Normal file
168
src/commands/onboard-auth.config-core.kilocode.test.ts
Normal file
@@ -0,0 +1,168 @@
|
||||
import { mkdtempSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { resolveApiKeyForProvider, resolveEnvApiKey } from "../agents/model-auth.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { resolveAgentModelPrimaryValue } from "../config/model-input.js";
|
||||
import { captureEnv } from "../test-utils/env.js";
|
||||
import {
|
||||
applyKilocodeProviderConfig,
|
||||
applyKilocodeConfig,
|
||||
KILOCODE_BASE_URL,
|
||||
} from "./onboard-auth.config-core.js";
|
||||
import { KILOCODE_DEFAULT_MODEL_REF } from "./onboard-auth.credentials.js";
|
||||
import {
|
||||
buildKilocodeModelDefinition,
|
||||
KILOCODE_DEFAULT_MODEL_ID,
|
||||
KILOCODE_DEFAULT_CONTEXT_WINDOW,
|
||||
KILOCODE_DEFAULT_MAX_TOKENS,
|
||||
KILOCODE_DEFAULT_COST,
|
||||
} from "./onboard-auth.models.js";
|
||||
|
||||
const emptyCfg: OpenClawConfig = {};
|
||||
|
||||
describe("Kilo Gateway provider config", () => {
|
||||
describe("constants", () => {
|
||||
it("KILOCODE_BASE_URL points to kilo openrouter endpoint", () => {
|
||||
expect(KILOCODE_BASE_URL).toBe("https://api.kilo.ai/api/gateway/");
|
||||
});
|
||||
|
||||
it("KILOCODE_DEFAULT_MODEL_REF includes provider prefix", () => {
|
||||
expect(KILOCODE_DEFAULT_MODEL_REF).toBe("kilocode/anthropic/claude-opus-4.6");
|
||||
});
|
||||
|
||||
it("KILOCODE_DEFAULT_MODEL_ID is anthropic/claude-opus-4.6", () => {
|
||||
expect(KILOCODE_DEFAULT_MODEL_ID).toBe("anthropic/claude-opus-4.6");
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildKilocodeModelDefinition", () => {
|
||||
it("returns correct model shape", () => {
|
||||
const model = buildKilocodeModelDefinition();
|
||||
expect(model.id).toBe(KILOCODE_DEFAULT_MODEL_ID);
|
||||
expect(model.name).toBe("Claude Opus 4.6");
|
||||
expect(model.reasoning).toBe(true);
|
||||
expect(model.input).toEqual(["text", "image"]);
|
||||
expect(model.contextWindow).toBe(KILOCODE_DEFAULT_CONTEXT_WINDOW);
|
||||
expect(model.maxTokens).toBe(KILOCODE_DEFAULT_MAX_TOKENS);
|
||||
expect(model.cost).toEqual(KILOCODE_DEFAULT_COST);
|
||||
});
|
||||
});
|
||||
|
||||
describe("applyKilocodeProviderConfig", () => {
|
||||
it("registers kilocode provider with correct baseUrl and api", () => {
|
||||
const result = applyKilocodeProviderConfig(emptyCfg);
|
||||
const provider = result.models?.providers?.kilocode;
|
||||
expect(provider).toBeDefined();
|
||||
expect(provider?.baseUrl).toBe(KILOCODE_BASE_URL);
|
||||
expect(provider?.api).toBe("openai-completions");
|
||||
});
|
||||
|
||||
it("includes the default model in the provider model list", () => {
|
||||
const result = applyKilocodeProviderConfig(emptyCfg);
|
||||
const provider = result.models?.providers?.kilocode;
|
||||
const models = provider?.models;
|
||||
expect(Array.isArray(models)).toBe(true);
|
||||
const modelIds = models?.map((m) => m.id) ?? [];
|
||||
expect(modelIds).toContain(KILOCODE_DEFAULT_MODEL_ID);
|
||||
});
|
||||
|
||||
it("sets Kilo Gateway alias in agent default models", () => {
|
||||
const result = applyKilocodeProviderConfig(emptyCfg);
|
||||
const agentModel = result.agents?.defaults?.models?.[KILOCODE_DEFAULT_MODEL_REF];
|
||||
expect(agentModel).toBeDefined();
|
||||
expect(agentModel?.alias).toBe("Kilo Gateway");
|
||||
});
|
||||
|
||||
it("preserves existing alias if already set", () => {
|
||||
const cfg: OpenClawConfig = {
|
||||
agents: {
|
||||
defaults: {
|
||||
models: {
|
||||
[KILOCODE_DEFAULT_MODEL_REF]: { alias: "My Custom Alias" },
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const result = applyKilocodeProviderConfig(cfg);
|
||||
const agentModel = result.agents?.defaults?.models?.[KILOCODE_DEFAULT_MODEL_REF];
|
||||
expect(agentModel?.alias).toBe("My Custom Alias");
|
||||
});
|
||||
|
||||
it("does not change the default model selection", () => {
|
||||
const cfg: OpenClawConfig = {
|
||||
agents: {
|
||||
defaults: {
|
||||
model: { primary: "openai/gpt-5" },
|
||||
},
|
||||
},
|
||||
};
|
||||
const result = applyKilocodeProviderConfig(cfg);
|
||||
expect(resolveAgentModelPrimaryValue(result.agents?.defaults?.model)).toBe("openai/gpt-5");
|
||||
});
|
||||
});
|
||||
|
||||
describe("applyKilocodeConfig", () => {
|
||||
it("sets kilocode as the default model", () => {
|
||||
const result = applyKilocodeConfig(emptyCfg);
|
||||
expect(resolveAgentModelPrimaryValue(result.agents?.defaults?.model)).toBe(
|
||||
KILOCODE_DEFAULT_MODEL_REF,
|
||||
);
|
||||
});
|
||||
|
||||
it("also registers the provider", () => {
|
||||
const result = applyKilocodeConfig(emptyCfg);
|
||||
const provider = result.models?.providers?.kilocode;
|
||||
expect(provider).toBeDefined();
|
||||
expect(provider?.baseUrl).toBe(KILOCODE_BASE_URL);
|
||||
});
|
||||
});
|
||||
|
||||
describe("env var resolution", () => {
|
||||
it("resolves KILOCODE_API_KEY from env", () => {
|
||||
const envSnapshot = captureEnv(["KILOCODE_API_KEY"]);
|
||||
process.env.KILOCODE_API_KEY = "test-kilo-key";
|
||||
|
||||
try {
|
||||
const result = resolveEnvApiKey("kilocode");
|
||||
expect(result).not.toBeNull();
|
||||
expect(result?.apiKey).toBe("test-kilo-key");
|
||||
expect(result?.source).toContain("KILOCODE_API_KEY");
|
||||
} finally {
|
||||
envSnapshot.restore();
|
||||
}
|
||||
});
|
||||
|
||||
it("returns null when KILOCODE_API_KEY is not set", () => {
|
||||
const envSnapshot = captureEnv(["KILOCODE_API_KEY"]);
|
||||
delete process.env.KILOCODE_API_KEY;
|
||||
|
||||
try {
|
||||
const result = resolveEnvApiKey("kilocode");
|
||||
expect(result).toBeNull();
|
||||
} finally {
|
||||
envSnapshot.restore();
|
||||
}
|
||||
});
|
||||
|
||||
it("resolves the kilocode api key via resolveApiKeyForProvider", async () => {
|
||||
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
|
||||
const envSnapshot = captureEnv(["KILOCODE_API_KEY"]);
|
||||
process.env.KILOCODE_API_KEY = "kilo-provider-test-key";
|
||||
|
||||
try {
|
||||
const auth = await resolveApiKeyForProvider({
|
||||
provider: "kilocode",
|
||||
agentDir,
|
||||
});
|
||||
|
||||
expect(auth.apiKey).toBe("kilo-provider-test-key");
|
||||
expect(auth.mode).toBe("api-key");
|
||||
expect(auth.source).toContain("KILOCODE_API_KEY");
|
||||
} finally {
|
||||
envSnapshot.restore();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -31,6 +31,7 @@ import type { OpenClawConfig } from "../config/config.js";
|
||||
import type { ModelApi } from "../config/types.models.js";
|
||||
import {
|
||||
HUGGINGFACE_DEFAULT_MODEL_REF,
|
||||
KILOCODE_DEFAULT_MODEL_REF,
|
||||
MISTRAL_DEFAULT_MODEL_REF,
|
||||
OPENROUTER_DEFAULT_MODEL_REF,
|
||||
TOGETHER_DEFAULT_MODEL_REF,
|
||||
@@ -58,10 +59,12 @@ import {
|
||||
applyProviderConfigWithModelCatalog,
|
||||
} from "./onboard-auth.config-shared.js";
|
||||
import {
|
||||
buildKilocodeModelDefinition,
|
||||
buildMistralModelDefinition,
|
||||
buildZaiModelDefinition,
|
||||
buildMoonshotModelDefinition,
|
||||
buildXaiModelDefinition,
|
||||
KILOCODE_DEFAULT_MODEL_ID,
|
||||
MISTRAL_BASE_URL,
|
||||
MISTRAL_DEFAULT_MODEL_ID,
|
||||
QIANFAN_BASE_URL,
|
||||
@@ -430,6 +433,40 @@ export function applyMistralConfig(cfg: OpenClawConfig): OpenClawConfig {
|
||||
return applyAgentDefaultModelPrimary(next, MISTRAL_DEFAULT_MODEL_REF);
|
||||
}
|
||||
|
||||
export const KILOCODE_BASE_URL = "https://api.kilo.ai/api/gateway/";
|
||||
|
||||
/**
|
||||
* Apply Kilo Gateway provider configuration without changing the default model.
|
||||
* Registers Kilo Gateway and sets up the provider, but preserves existing model selection.
|
||||
*/
|
||||
export function applyKilocodeProviderConfig(cfg: OpenClawConfig): OpenClawConfig {
|
||||
const models = { ...cfg.agents?.defaults?.models };
|
||||
models[KILOCODE_DEFAULT_MODEL_REF] = {
|
||||
...models[KILOCODE_DEFAULT_MODEL_REF],
|
||||
alias: models[KILOCODE_DEFAULT_MODEL_REF]?.alias ?? "Kilo Gateway",
|
||||
};
|
||||
|
||||
const defaultModel = buildKilocodeModelDefinition();
|
||||
|
||||
return applyProviderConfigWithDefaultModel(cfg, {
|
||||
agentModels: models,
|
||||
providerId: "kilocode",
|
||||
api: "openai-completions",
|
||||
baseUrl: KILOCODE_BASE_URL,
|
||||
defaultModel,
|
||||
defaultModelId: KILOCODE_DEFAULT_MODEL_ID,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply Kilo Gateway provider configuration AND set Kilo Gateway as the default model.
|
||||
* Use this when Kilo Gateway is the primary provider choice during onboarding.
|
||||
*/
|
||||
export function applyKilocodeConfig(cfg: OpenClawConfig): OpenClawConfig {
|
||||
const next = applyKilocodeProviderConfig(cfg);
|
||||
return applyAgentDefaultModelPrimary(next, KILOCODE_DEFAULT_MODEL_REF);
|
||||
}
|
||||
|
||||
export function applyAuthProfileConfig(
|
||||
cfg: OpenClawConfig,
|
||||
params: {
|
||||
|
||||
@@ -213,6 +213,7 @@ export const HUGGINGFACE_DEFAULT_MODEL_REF = "huggingface/deepseek-ai/DeepSeek-R
|
||||
export const TOGETHER_DEFAULT_MODEL_REF = "together/moonshotai/Kimi-K2.5";
|
||||
export const LITELLM_DEFAULT_MODEL_REF = "litellm/claude-opus-4-6";
|
||||
export const VERCEL_AI_GATEWAY_DEFAULT_MODEL_REF = "vercel-ai-gateway/anthropic/claude-opus-4.6";
|
||||
export const KILOCODE_DEFAULT_MODEL_REF = "kilocode/anthropic/claude-opus-4.6";
|
||||
|
||||
export async function setZaiApiKey(key: string, agentDir?: string) {
|
||||
// Write to resolved agent dir so gateway finds credentials on startup.
|
||||
@@ -372,3 +373,15 @@ export async function setMistralApiKey(key: string, agentDir?: string) {
|
||||
agentDir: resolveAuthAgentDir(agentDir),
|
||||
});
|
||||
}
|
||||
|
||||
export async function setKilocodeApiKey(key: string, agentDir?: string) {
|
||||
upsertAuthProfile({
|
||||
profileId: "kilocode:default",
|
||||
credential: {
|
||||
type: "api_key",
|
||||
provider: "kilocode",
|
||||
key,
|
||||
},
|
||||
agentDir: resolveAuthAgentDir(agentDir),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -204,3 +204,26 @@ export function buildXaiModelDefinition(): ModelDefinitionConfig {
|
||||
maxTokens: XAI_DEFAULT_MAX_TOKENS,
|
||||
};
|
||||
}
|
||||
|
||||
// Kilo Gateway model definitions
|
||||
export const KILOCODE_DEFAULT_MODEL_ID = "anthropic/claude-opus-4.6";
|
||||
export const KILOCODE_DEFAULT_CONTEXT_WINDOW = 200000;
|
||||
export const KILOCODE_DEFAULT_MAX_TOKENS = 8192;
|
||||
export const KILOCODE_DEFAULT_COST = {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
};
|
||||
|
||||
export function buildKilocodeModelDefinition(): ModelDefinitionConfig {
|
||||
return {
|
||||
id: KILOCODE_DEFAULT_MODEL_ID,
|
||||
name: "Claude Opus 4.6",
|
||||
reasoning: true,
|
||||
input: ["text", "image"],
|
||||
cost: KILOCODE_DEFAULT_COST,
|
||||
contextWindow: KILOCODE_DEFAULT_CONTEXT_WINDOW,
|
||||
maxTokens: KILOCODE_DEFAULT_MAX_TOKENS,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ export {
|
||||
applyCloudflareAiGatewayProviderConfig,
|
||||
applyHuggingfaceConfig,
|
||||
applyHuggingfaceProviderConfig,
|
||||
applyKilocodeConfig,
|
||||
applyKilocodeProviderConfig,
|
||||
applyQianfanConfig,
|
||||
applyQianfanProviderConfig,
|
||||
applyKimiCodeConfig,
|
||||
@@ -37,6 +39,7 @@ export {
|
||||
applyXiaomiProviderConfig,
|
||||
applyZaiConfig,
|
||||
applyZaiProviderConfig,
|
||||
KILOCODE_BASE_URL,
|
||||
} from "./onboard-auth.config-core.js";
|
||||
export {
|
||||
applyMinimaxApiConfig,
|
||||
@@ -55,12 +58,14 @@ export {
|
||||
} from "./onboard-auth.config-opencode.js";
|
||||
export {
|
||||
CLOUDFLARE_AI_GATEWAY_DEFAULT_MODEL_REF,
|
||||
KILOCODE_DEFAULT_MODEL_REF,
|
||||
LITELLM_DEFAULT_MODEL_REF,
|
||||
OPENROUTER_DEFAULT_MODEL_REF,
|
||||
setAnthropicApiKey,
|
||||
setCloudflareAiGatewayConfig,
|
||||
setQianfanApiKey,
|
||||
setGeminiApiKey,
|
||||
setKilocodeApiKey,
|
||||
setLitellmApiKey,
|
||||
setKimiCodingApiKey,
|
||||
setMinimaxApiKey,
|
||||
@@ -86,12 +91,14 @@ export {
|
||||
XAI_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,
|
||||
|
||||
@@ -14,6 +14,7 @@ type AuthChoiceFlagOptions = Pick<
|
||||
| "openaiApiKey"
|
||||
| "mistralApiKey"
|
||||
| "openrouterApiKey"
|
||||
| "kilocodeApiKey"
|
||||
| "aiGatewayApiKey"
|
||||
| "cloudflareAiGatewayApiKey"
|
||||
| "moonshotApiKey"
|
||||
|
||||
@@ -12,6 +12,7 @@ import { applyPrimaryModel } from "../../model-picker.js";
|
||||
import {
|
||||
applyAuthProfileConfig,
|
||||
applyCloudflareAiGatewayConfig,
|
||||
applyKilocodeConfig,
|
||||
applyQianfanConfig,
|
||||
applyKimiCodeConfig,
|
||||
applyMinimaxApiConfig,
|
||||
@@ -35,6 +36,7 @@ import {
|
||||
setCloudflareAiGatewayConfig,
|
||||
setQianfanApiKey,
|
||||
setGeminiApiKey,
|
||||
setKilocodeApiKey,
|
||||
setKimiCodingApiKey,
|
||||
setLitellmApiKey,
|
||||
setMistralApiKey,
|
||||
@@ -441,6 +443,29 @@ export async function applyNonInteractiveAuthChoice(params: {
|
||||
return applyOpenrouterConfig(nextConfig);
|
||||
}
|
||||
|
||||
if (authChoice === "kilocode-api-key") {
|
||||
const resolved = await resolveNonInteractiveApiKey({
|
||||
provider: "kilocode",
|
||||
cfg: baseConfig,
|
||||
flagValue: opts.kilocodeApiKey,
|
||||
flagName: "--kilocode-api-key",
|
||||
envVar: "KILOCODE_API_KEY",
|
||||
runtime,
|
||||
});
|
||||
if (!resolved) {
|
||||
return null;
|
||||
}
|
||||
if (resolved.source !== "profile") {
|
||||
await setKilocodeApiKey(resolved.key);
|
||||
}
|
||||
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||
profileId: "kilocode:default",
|
||||
provider: "kilocode",
|
||||
mode: "api_key",
|
||||
});
|
||||
return applyKilocodeConfig(nextConfig);
|
||||
}
|
||||
|
||||
if (authChoice === "litellm-api-key") {
|
||||
const resolved = await resolveNonInteractiveApiKey({
|
||||
provider: "litellm",
|
||||
|
||||
@@ -6,6 +6,7 @@ type OnboardProviderAuthOptionKey = keyof Pick<
|
||||
| "openaiApiKey"
|
||||
| "mistralApiKey"
|
||||
| "openrouterApiKey"
|
||||
| "kilocodeApiKey"
|
||||
| "aiGatewayApiKey"
|
||||
| "cloudflareAiGatewayApiKey"
|
||||
| "moonshotApiKey"
|
||||
@@ -64,6 +65,13 @@ export const ONBOARD_PROVIDER_AUTH_FLAGS: ReadonlyArray<OnboardProviderAuthFlag>
|
||||
cliOption: "--openrouter-api-key <key>",
|
||||
description: "OpenRouter API key",
|
||||
},
|
||||
{
|
||||
optionKey: "kilocodeApiKey",
|
||||
authChoice: "kilocode-api-key",
|
||||
cliFlag: "--kilocode-api-key",
|
||||
cliOption: "--kilocode-api-key <key>",
|
||||
description: "Kilo Gateway API key",
|
||||
},
|
||||
{
|
||||
optionKey: "aiGatewayApiKey",
|
||||
authChoice: "ai-gateway-api-key",
|
||||
|
||||
@@ -13,6 +13,7 @@ export type AuthChoice =
|
||||
| "openai-codex"
|
||||
| "openai-api-key"
|
||||
| "openrouter-api-key"
|
||||
| "kilocode-api-key"
|
||||
| "litellm-api-key"
|
||||
| "ai-gateway-api-key"
|
||||
| "cloudflare-ai-gateway-api-key"
|
||||
@@ -58,6 +59,7 @@ export type AuthChoiceGroupId =
|
||||
| "google"
|
||||
| "copilot"
|
||||
| "openrouter"
|
||||
| "kilocode"
|
||||
| "litellm"
|
||||
| "ai-gateway"
|
||||
| "cloudflare-ai-gateway"
|
||||
@@ -108,6 +110,7 @@ export type OnboardOptions = {
|
||||
openaiApiKey?: string;
|
||||
mistralApiKey?: string;
|
||||
openrouterApiKey?: string;
|
||||
kilocodeApiKey?: string;
|
||||
litellmApiKey?: string;
|
||||
aiGatewayApiKey?: string;
|
||||
cloudflareAiGatewayAccountId?: string;
|
||||
|
||||
@@ -62,6 +62,7 @@ const SHELL_ENV_EXPECTED_KEYS = [
|
||||
"AI_GATEWAY_API_KEY",
|
||||
"MINIMAX_API_KEY",
|
||||
"SYNTHETIC_API_KEY",
|
||||
"KILOCODE_API_KEY",
|
||||
"ELEVENLABS_API_KEY",
|
||||
"TELEGRAM_BOT_TOKEN",
|
||||
"DISCORD_BOT_TOKEN",
|
||||
|
||||
Reference in New Issue
Block a user