Add DeepSeek provider support to onboarding flow

This commit is contained in:
10946620@163.com 2026-01-28 14:23:24 +08:00
parent 93c2d65398
commit 87c62498e9
19 changed files with 331 additions and 1 deletions

View File

@ -47,10 +47,13 @@
- Type-check/build: `pnpm build` (tsc)
- Lint/format: `pnpm lint` (oxlint), `pnpm format` (oxfmt)
- Tests: `pnpm test` (vitest); coverage: `pnpm test:coverage`
- Run single test: `pnpm vitest run src/path/to/test.ts` (fastest feedback loop).
## Coding Style & Naming Conventions
- Language: TypeScript (ESM). Prefer strict typing; avoid `any`.
- Formatting/linting via Oxlint and Oxfmt; run `pnpm lint` before commits.
- Formatting/linting via Oxlint and Oxfmt; run `pnpm lint` before commits. Use `pnpm lint:fix` to auto-fix both.
- Imports: Use standard ESM imports. No path aliases are configured; use relative paths.
- Error Handling: Use strongly typed errors where possible. Handle specific error types rather than catching generic `Error`.
- Add brief code comments for tricky or non-obvious logic.
- Keep files concise; extract helpers instead of “V2” copies. Use existing patterns for CLI options and dependency injection via `createDefaultDeps`.
- Aim to keep files under ~700 LOC; guideline only (not a hard guardrail). Split/refactor when it improves clarity or testability.

19
findings.md Normal file
View File

@ -0,0 +1,19 @@
# Findings
## Onboarding Implementation
- Onboarding logic is spread across `src/commands/onboard-*` and `src/wizard/onboarding*.ts`.
- `onboard-auth.ts` exports functions to apply configurations for various providers.
- `onboard-auth.config-core.ts` and `onboard-auth.credentials.ts` handle core provider setup.
- `onboard-auth.models.ts` defines model defaults.
- **DeepSeek is currently missing** from the onboarding flow.
## DeepSeek Integration Plan
1. **Define Defaults**: Add DeepSeek model constants in `src/commands/onboard-auth.models.ts` (reuse constants from `models-config.providers.ts` if possible, but they are private there, so likely redefine or export).
2. **Config Applicator**: Create `applyDeepSeekProviderConfig` and `applyDeepSeekConfig` in `src/commands/onboard-auth.config-core.ts` (or a new file if needed, but core seems fine).
3. **Credential Setter**: Add `setDeepSeekApiKey` in `src/commands/onboard-auth.credentials.ts`.
4. **Interactive Flow**: Update `src/commands/onboard-interactive.ts` or `src/commands/auth-choice.ts` to include DeepSeek as an option.
5. **Export**: Update `src/commands/onboard-auth.ts` to export the new functions.
## Implementation Details
- `DEEPSEEK_DEFAULT_MODEL_ID` = `deepseek-chat`
- `DEEPSEEK_DEFAULT_MODEL_REF` = `deepseek/deepseek-chat`

9
progress.md Normal file
View File

@ -0,0 +1,9 @@
# Progress Log
## Session Start
- Initialized planning files.
- Started Discovery phase.
- Identified onboarding files.
- Implemented `DeepSeek` in onboarding flow.
- Verified compilation with `bunx tsc`.
- Completed task.

View File

@ -283,6 +283,7 @@ export function resolveEnvApiKey(provider: string): EnvApiKeyResult | null {
minimax: "MINIMAX_API_KEY",
synthetic: "SYNTHETIC_API_KEY",
venice: "VENICE_API_KEY",
deepseek: "DEEPSEEK_API_KEY",
mistral: "MISTRAL_API_KEY",
opencode: "OPENCODE_API_KEY",
};

View File

@ -64,6 +64,18 @@ const QWEN_PORTAL_DEFAULT_COST = {
cacheWrite: 0,
};
const DEEPSEEK_BASE_URL = "https://api.deepseek.com";
const DEEPSEEK_CHAT_MODEL_ID = "deepseek-chat";
const DEEPSEEK_REASONER_MODEL_ID = "deepseek-reasoner";
const DEEPSEEK_DEFAULT_CONTEXT_WINDOW = 64000;
const DEEPSEEK_DEFAULT_MAX_TOKENS = 8192;
const DEEPSEEK_DEFAULT_COST = {
input: 0.14,
output: 0.28,
cacheRead: 0.014,
cacheWrite: 0.14,
};
const OLLAMA_BASE_URL = "http://127.0.0.1:11434/v1";
const OLLAMA_API_BASE_URL = "http://127.0.0.1:11434";
const OLLAMA_DEFAULT_CONTEXT_WINDOW = 128000;
@ -333,6 +345,33 @@ function buildQwenPortalProvider(): ProviderConfig {
};
}
function buildDeepSeekProvider(): ProviderConfig {
return {
baseUrl: DEEPSEEK_BASE_URL,
api: "openai-completions",
models: [
{
id: DEEPSEEK_CHAT_MODEL_ID,
name: "DeepSeek Chat (V3)",
reasoning: false,
input: ["text"],
cost: DEEPSEEK_DEFAULT_COST,
contextWindow: DEEPSEEK_DEFAULT_CONTEXT_WINDOW,
maxTokens: DEEPSEEK_DEFAULT_MAX_TOKENS,
},
{
id: DEEPSEEK_REASONER_MODEL_ID,
name: "DeepSeek Reasoner (R1)",
reasoning: true,
input: ["text"],
cost: DEEPSEEK_DEFAULT_COST,
contextWindow: DEEPSEEK_DEFAULT_CONTEXT_WINDOW,
maxTokens: DEEPSEEK_DEFAULT_MAX_TOKENS,
},
],
};
}
function buildSyntheticProvider(): ProviderConfig {
return {
baseUrl: SYNTHETIC_BASE_URL,
@ -374,6 +413,13 @@ export async function resolveImplicitProviders(params: {
providers.minimax = { ...buildMinimaxProvider(), apiKey: minimaxKey };
}
const deepseekKey =
resolveEnvApiKeyVarName("deepseek") ??
resolveApiKeyFromProfiles({ provider: "deepseek", store: authStore });
if (deepseekKey) {
providers.deepseek = { ...buildDeepSeekProvider(), apiKey: deepseekKey };
}
const moonshotKey =
resolveEnvApiKeyVarName("moonshot") ??
resolveApiKeyFromProfiles({ provider: "moonshot", store: authStore });

View File

@ -20,6 +20,7 @@ export type AuthChoiceGroupId =
| "minimax"
| "synthetic"
| "venice"
| "deepseek"
| "qwen";
export type AuthChoiceGroup = {
@ -53,6 +54,12 @@ const AUTH_CHOICE_GROUP_DEFS: {
hint: "M2.1 (recommended)",
choices: ["minimax-api", "minimax-api-lightning"],
},
{
value: "deepseek",
label: "DeepSeek",
hint: "V3 / R1 (low cost)",
choices: ["deepseek-api-key"],
},
{
value: "qwen",
label: "Qwen",
@ -147,6 +154,7 @@ export function buildAuthChoiceOptions(params: {
label: "Venice AI API key",
hint: "Privacy-focused inference (uncensored models)",
});
options.push({ value: "deepseek-api-key", label: "DeepSeek API key" });
options.push({
value: "github-copilot",
label: "GitHub Copilot (GitHub device login)",

View File

@ -0,0 +1,92 @@
import { ensureAuthProfileStore, resolveAuthProfileOrder } from "../agents/auth-profiles.js";
import { resolveEnvApiKey } from "../agents/model-auth.js";
import {
formatApiKeyPreview,
normalizeApiKeyInput,
validateApiKeyInput,
} from "./auth-choice.api-key.js";
import type { ApplyAuthChoiceParams, ApplyAuthChoiceResult } from "./auth-choice.apply.js";
import { applyDefaultModelChoice } from "./auth-choice.default-model.js";
import {
applyAuthProfileConfig,
applyDeepSeekConfig,
applyDeepSeekProviderConfig,
DEEPSEEK_DEFAULT_MODEL_REF,
setDeepSeekApiKey,
} from "./onboard-auth.js";
export async function applyAuthChoiceDeepSeek(
params: ApplyAuthChoiceParams,
): Promise<ApplyAuthChoiceResult | null> {
let nextConfig = params.config;
let agentModelOverride: string | undefined;
const noteAgentModel = async (model: string) => {
if (!params.agentId) return;
await params.prompter.note(
`Default model set to ${model} for agent "${params.agentId}".`,
"Model configured",
);
};
const authChoice = params.authChoice;
if (
authChoice === "deepseek-api-key" ||
(authChoice === "apiKey" && params.opts?.tokenProvider === "deepseek")
) {
let hasCredential = false;
if (!hasCredential && params.opts?.token && params.opts?.tokenProvider === "deepseek") {
await setDeepSeekApiKey(normalizeApiKeyInput(params.opts.token), params.agentDir);
hasCredential = true;
}
if (!hasCredential) {
await params.prompter.note(
[
"DeepSeek provides low-cost, high-performance models (V3, R1).",
"Get your API key at: https://platform.deepseek.com/api_keys",
].join("\n"),
"DeepSeek",
);
}
const envKey = resolveEnvApiKey("deepseek");
if (envKey) {
const useExisting = await params.prompter.confirm({
message: `Use existing DEEPSEEK_API_KEY (${envKey.source}, ${formatApiKeyPreview(envKey.apiKey)})?`,
initialValue: true,
});
if (useExisting) {
await setDeepSeekApiKey(envKey.apiKey, params.agentDir);
hasCredential = true;
}
}
if (!hasCredential) {
const key = await params.prompter.text({
message: "Enter DeepSeek API key",
validate: validateApiKeyInput,
});
await setDeepSeekApiKey(normalizeApiKeyInput(String(key)), params.agentDir);
}
nextConfig = applyAuthProfileConfig(nextConfig, {
profileId: "deepseek:default",
provider: "deepseek",
mode: "api_key",
});
{
const applied = await applyDefaultModelChoice({
config: nextConfig,
setDefaultModel: params.setDefaultModel,
defaultModel: DEEPSEEK_DEFAULT_MODEL_REF,
applyDefaultConfig: applyDeepSeekConfig,
applyProviderConfig: applyDeepSeekProviderConfig,
noteDefault: DEEPSEEK_DEFAULT_MODEL_REF,
noteAgentModel,
prompter: params.prompter,
});
nextConfig = applied.config;
agentModelOverride = applied.agentModelOverride ?? agentModelOverride;
}
return { config: nextConfig, agentModelOverride };
}
return null;
}

View File

@ -4,6 +4,7 @@ import type { WizardPrompter } from "../wizard/prompts.js";
import { applyAuthChoiceAnthropic } from "./auth-choice.apply.anthropic.js";
import { applyAuthChoiceApiProviders } from "./auth-choice.apply.api-providers.js";
import { applyAuthChoiceCopilotProxy } from "./auth-choice.apply.copilot-proxy.js";
import { applyAuthChoiceDeepSeek } from "./auth-choice.apply.deepseek.js";
import { applyAuthChoiceGitHubCopilot } from "./auth-choice.apply.github-copilot.js";
import { applyAuthChoiceGoogleAntigravity } from "./auth-choice.apply.google-antigravity.js";
import { applyAuthChoiceGoogleGeminiCli } from "./auth-choice.apply.google-gemini-cli.js";
@ -45,6 +46,7 @@ export async function applyAuthChoice(
applyAuthChoiceGoogleAntigravity,
applyAuthChoiceGoogleGeminiCli,
applyAuthChoiceCopilotProxy,
applyAuthChoiceDeepSeek,
applyAuthChoiceQwenPortal,
];

View File

@ -19,6 +19,10 @@ import {
import {
buildKimiCodeModelDefinition,
buildMoonshotModelDefinition,
buildDeepSeekModelDefinition,
DEEPSEEK_BASE_URL,
DEEPSEEK_DEFAULT_MODEL_ID,
DEEPSEEK_DEFAULT_MODEL_REF,
KIMI_CODE_BASE_URL,
KIMI_CODE_MODEL_ID,
KIMI_CODE_MODEL_REF,
@ -27,6 +31,71 @@ import {
MOONSHOT_DEFAULT_MODEL_REF,
} from "./onboard-auth.models.js";
export function applyDeepSeekProviderConfig(cfg: MoltbotConfig): MoltbotConfig {
const models = { ...cfg.agents?.defaults?.models };
models[DEEPSEEK_DEFAULT_MODEL_REF] = {
...models[DEEPSEEK_DEFAULT_MODEL_REF],
alias: models[DEEPSEEK_DEFAULT_MODEL_REF]?.alias ?? "DeepSeek V3",
};
const providers = { ...cfg.models?.providers };
const existingProvider = providers.deepseek;
const existingModels = Array.isArray(existingProvider?.models) ? existingProvider.models : [];
const defaultModel = buildDeepSeekModelDefinition();
const hasDefaultModel = existingModels.some((model) => model.id === DEEPSEEK_DEFAULT_MODEL_ID);
const mergedModels = hasDefaultModel ? existingModels : [...existingModels, defaultModel];
const { apiKey: existingApiKey, ...existingProviderRest } = (existingProvider ?? {}) as Record<
string,
unknown
> as { apiKey?: string };
const resolvedApiKey = typeof existingApiKey === "string" ? existingApiKey : undefined;
const normalizedApiKey = resolvedApiKey?.trim();
providers.deepseek = {
...existingProviderRest,
baseUrl: DEEPSEEK_BASE_URL,
api: "openai-completions",
...(normalizedApiKey ? { apiKey: normalizedApiKey } : {}),
models: mergedModels.length > 0 ? mergedModels : [defaultModel],
};
return {
...cfg,
agents: {
...cfg.agents,
defaults: {
...cfg.agents?.defaults,
models,
},
},
models: {
mode: cfg.models?.mode ?? "merge",
providers,
},
};
}
export function applyDeepSeekConfig(cfg: MoltbotConfig): MoltbotConfig {
const next = applyDeepSeekProviderConfig(cfg);
const existingModel = next.agents?.defaults?.model;
return {
...next,
agents: {
...next.agents,
defaults: {
...next.agents?.defaults,
model: {
...(existingModel && "fallbacks" in (existingModel as Record<string, unknown>)
? {
fallbacks: (existingModel as { fallbacks?: string[] }).fallbacks,
}
: undefined),
primary: DEEPSEEK_DEFAULT_MODEL_REF,
},
},
},
};
}
export function applyZaiConfig(cfg: MoltbotConfig): MoltbotConfig {
const models = { ...cfg.agents?.defaults?.models };
models[ZAI_DEFAULT_MODEL_REF] = {

View File

@ -73,6 +73,19 @@ export async function setMoonshotApiKey(key: string, agentDir?: string) {
});
}
export async function setDeepSeekApiKey(key: string, agentDir?: string) {
// Write to resolved agent dir so gateway finds credentials on startup.
upsertAuthProfile({
profileId: "deepseek:default",
credential: {
type: "api_key",
provider: "deepseek",
key,
},
agentDir: resolveAuthAgentDir(agentDir),
});
}
export async function setKimiCodeApiKey(key: string, agentDir?: string) {
// Write to resolved agent dir so gateway finds credentials on startup.
upsertAuthProfile({

View File

@ -21,6 +21,18 @@ export const KIMI_CODE_HEADERS = { "User-Agent": "KimiCLI/0.77" } as const;
export const KIMI_CODE_COMPAT = { supportsDeveloperRole: false } as const;
// Pricing: MiniMax doesn't publish public rates. Override in models.json for accurate costs.
export const DEEPSEEK_BASE_URL = "https://api.deepseek.com";
export const DEEPSEEK_DEFAULT_MODEL_ID = "deepseek-chat";
export const DEEPSEEK_DEFAULT_MODEL_REF = `deepseek/${DEEPSEEK_DEFAULT_MODEL_ID}`;
export const DEEPSEEK_DEFAULT_CONTEXT_WINDOW = 64000;
export const DEEPSEEK_DEFAULT_MAX_TOKENS = 8192;
export const DEEPSEEK_DEFAULT_COST = {
input: 0.14,
output: 0.28,
cacheRead: 0.014,
cacheWrite: 0.14,
};
export const MINIMAX_API_COST = {
input: 15,
output: 60,
@ -103,6 +115,18 @@ export function buildMoonshotModelDefinition(): ModelDefinitionConfig {
};
}
export function buildDeepSeekModelDefinition(): ModelDefinitionConfig {
return {
id: DEEPSEEK_DEFAULT_MODEL_ID,
name: "DeepSeek Chat (V3)",
reasoning: false,
input: ["text"],
cost: DEEPSEEK_DEFAULT_COST,
contextWindow: DEEPSEEK_DEFAULT_CONTEXT_WINDOW,
maxTokens: DEEPSEEK_DEFAULT_MAX_TOKENS,
};
}
export function buildKimiCodeModelDefinition(): ModelDefinitionConfig {
return {
id: KIMI_CODE_MODEL_ID,

View File

@ -5,6 +5,8 @@ export {
export { VENICE_DEFAULT_MODEL_ID, VENICE_DEFAULT_MODEL_REF } from "../agents/venice-models.js";
export {
applyAuthProfileConfig,
applyDeepSeekConfig,
applyDeepSeekProviderConfig,
applyKimiCodeConfig,
applyKimiCodeProviderConfig,
applyMoonshotConfig,
@ -35,6 +37,7 @@ export {
export {
OPENROUTER_DEFAULT_MODEL_REF,
setAnthropicApiKey,
setDeepSeekApiKey,
setGeminiApiKey,
setKimiCodeApiKey,
setMinimaxApiKey,
@ -50,10 +53,12 @@ export {
ZAI_DEFAULT_MODEL_REF,
} from "./onboard-auth.credentials.js";
export {
buildDeepSeekModelDefinition,
buildKimiCodeModelDefinition,
buildMinimaxApiModelDefinition,
buildMinimaxModelDefinition,
buildMoonshotModelDefinition,
DEEPSEEK_DEFAULT_MODEL_REF,
DEFAULT_MINIMAX_BASE_URL,
KIMI_CODE_BASE_URL,
KIMI_CODE_MODEL_ID,

View File

@ -27,6 +27,7 @@ export type AuthChoice =
| "minimax"
| "minimax-api"
| "minimax-api-lightning"
| "deepseek-api-key"
| "opencode-zen"
| "github-copilot"
| "copilot-proxy"
@ -68,6 +69,7 @@ export type OnboardOptions = {
geminiApiKey?: string;
zaiApiKey?: string;
minimaxApiKey?: string;
deepseekApiKey?: string;
syntheticApiKey?: string;
veniceApiKey?: string;
opencodeZenApiKey?: string;

View File

@ -0,0 +1,17 @@
import type { ProviderUsageSnapshot } from "./provider-usage.types.js";
export async function fetchDeepSeekUsage(
_token: string,
_timeoutMs: number,
_fetchFn: typeof fetch,
): Promise<ProviderUsageSnapshot> {
// DeepSeek API currently does not provide a standard usage/subscription endpoint
// that matches the OpenAI format or similar.
// We return a placeholder to satisfy the interface.
return {
provider: "deepseek",
displayName: "DeepSeek",
windows: [],
// error: "Usage API not supported", // Optional: hide error if we don't want it to show up as failed
};
}

View File

@ -4,4 +4,5 @@ export { fetchCodexUsage } from "./provider-usage.fetch.codex.js";
export { fetchCopilotUsage } from "./provider-usage.fetch.copilot.js";
export { fetchGeminiUsage } from "./provider-usage.fetch.gemini.js";
export { fetchMinimaxUsage } from "./provider-usage.fetch.minimax.js";
export { fetchDeepSeekUsage } from "./provider-usage.fetch.deepseek.js";
export { fetchZaiUsage } from "./provider-usage.fetch.zai.js";

View File

@ -4,6 +4,7 @@ import {
fetchClaudeUsage,
fetchCodexUsage,
fetchCopilotUsage,
fetchDeepSeekUsage,
fetchGeminiUsage,
fetchMinimaxUsage,
fetchZaiUsage,
@ -66,6 +67,8 @@ export async function loadProviderUsageSummary(
return await fetchCodexUsage(auth.token, auth.accountId, timeoutMs, fetchFn);
case "minimax":
return await fetchMinimaxUsage(auth.token, timeoutMs, fetchFn);
case "deepseek":
return await fetchDeepSeekUsage(auth.token, timeoutMs, fetchFn);
case "zai":
return await fetchZaiUsage(auth.token, timeoutMs, fetchFn);
default:

View File

@ -9,6 +9,7 @@ export const PROVIDER_LABELS: Record<UsageProviderId, string> = {
"google-gemini-cli": "Gemini",
"google-antigravity": "Antigravity",
minimax: "MiniMax",
deepseek: "DeepSeek",
"openai-codex": "Codex",
zai: "z.ai",
};
@ -19,6 +20,7 @@ export const usageProviders: UsageProviderId[] = [
"google-gemini-cli",
"google-antigravity",
"minimax",
"deepseek",
"openai-codex",
"zai",
];

View File

@ -23,5 +23,6 @@ export type UsageProviderId =
| "google-gemini-cli"
| "google-antigravity"
| "minimax"
| "deepseek"
| "openai-codex"
| "zai";

13
task_plan.md Normal file
View File

@ -0,0 +1,13 @@
# Task Plan: Enable DeepSeek in Onboarding
## Goal
Verify and enable DeepSeek provider support in the `moltbot onboard` command.
## Phases
- [ ] Discovery: Analyze `moltbot onboard` implementation to see how providers are listed. <!-- id: 0 -->
- [ ] Implementation: Add DeepSeek to the onboarding provider list if missing. <!-- id: 1 -->
- [ ] Verification: Verify the changes. <!-- id: 2 -->
## Current Status
- Phase: Discovery
- Status: Pending