fix: expose deepseek model source contract

This commit is contained in:
Codex
2026-05-21 14:00:36 +00:00
parent 541539c1a8
commit 7fde2a3e1a
4 changed files with 101 additions and 2 deletions
@@ -39,6 +39,17 @@ export const opencodeNpmPackage = "opencode-ai@1.14.48";
export const defaultCodeExecutionMode: CodeExecutionMode = "default";
export const codeExecutionModes: CodeExecutionMode[] = ["default", "windows-native"];
export interface CodeModelProviderSourceConfig {
codeModels: string[];
codexModels?: string[];
deepseekApiBase: string;
deepseekApiKey: string;
deepseekModel: string;
minimaxApiBase: string;
minimaxApiKey: string;
minimaxModel: string;
}
function proxyUrlFromEnv(env: NodeJS.ProcessEnv): string {
for (const key of gitProxyEnvKeys) {
const value = env[key];
@@ -122,6 +133,63 @@ export function codeModelPorts(models: string[]): Record<string, CodeAgentPortKi
return Object.fromEntries(models.map((model) => [model, codeAgentPortForModel(model)]));
}
function envRef(name: string, env: NodeJS.ProcessEnv): Record<string, JsonValue> {
const value = env[name];
return {
ref: `env:${name}`,
present: typeof value === "string" && value.trim().length > 0,
valuesPrinted: false,
};
}
function configRef(name: string, configuredValue: string, env: NodeJS.ProcessEnv): Record<string, JsonValue> {
return {
...envRef(name, env),
present: configuredValue.trim().length > 0,
envPresent: envRef(name, env).present,
};
}
export function codeModelProviderSourceContract(config: CodeModelProviderSourceConfig, env: NodeJS.ProcessEnv = process.env): Record<string, JsonValue> {
const codeModels = Array.from(new Set(config.codeModels.map(normalizeCodeModel).filter(Boolean)));
return {
check: "code-model-provider-source-contract",
valuesPrinted: false,
codeModels,
codexModels: config.codexModels ?? codeModels.filter((model) => codeAgentPortForModel(model) === "codex"),
opencodeModels: opencodeModels(codeModels),
modelPorts: codeModelPorts(codeModels) as unknown as JsonValue,
providers: {
deepseek: {
runner: "opencode",
publicModel: deepseekChatModel,
providerModel: config.deepseekModel.trim() || deepseekChatModel,
credentialSource: {
apiKey: {
...configRef("DEEPSEEK_API_KEY", config.deepseekApiKey, env),
present: config.deepseekApiKey.trim().length > 0,
},
baseURL: configRef("DEEPSEEK_API_BASE", config.deepseekApiBase, env),
model: configRef("DEEPSEEK_MODEL", config.deepseekModel, env),
},
},
minimax: {
runner: "opencode",
publicModel: minimaxM27Model,
providerModel: config.minimaxModel.trim() || "MiniMax-M2.7",
credentialSource: {
apiKey: {
...configRef("MINIMAX_API_KEY", config.minimaxApiKey, env),
present: config.minimaxApiKey.trim().length > 0,
},
baseURL: configRef("MINIMAX_API_BASE", config.minimaxApiBase, env),
model: configRef("MINIMAX_MODEL", config.minimaxModel, env),
},
},
},
};
}
export function codeAgentPortInfo(kind: CodeAgentPortKind): Record<string, JsonValue> {
return {
kind,
@@ -34,6 +34,7 @@ import {
defaultCodeModels,
extractRecord,
extractString,
codeModelProviderSourceContract,
normalizeCodeExecutionMode,
normalizeCodeModel,
terminalStatus,
@@ -5255,6 +5256,7 @@ async function route(req: Request): Promise<Response> {
status: "starting",
databaseReady,
databaseLastError,
modelProviderConfig: codeModelProviderSourceContract(config),
skills: collectSkillsStatus(),
startedAt: serviceStartedAt,
}, 503);
@@ -5271,6 +5273,7 @@ async function route(req: Request): Promise<Response> {
schedulerEnabled: config.schedulerEnabled,
schedulerPollIntervalMs: config.schedulerPollIntervalMs,
queue: queueSummary(false, state.tasks),
modelProviderConfig: codeModelProviderSourceContract(config),
executionDiagnostics: executionDiagnosticsForTasks(state.tasks),
skills: collectSkillsStatus(),
egressProxy: await providerGatewayEgressProxyStatus(),
@@ -1,7 +1,7 @@
// 重构前 index.ts 只读参考:commit 6a04144d3f5103014f75b637d7e6bc2f45bf007fblob 56e590c1a6b5ca7ad128bf2c992f60e46c355a58;可用 `git show 6a04144d3f5103014f75b637d7e6bc2f45bf007f:src/components/microservices/code-queue/src/index.ts` 查看。
import postgres from "postgres";
import { codeAgentPortForModel, codeAgentPortInfo, codeExecutionModeInfo, codeExecutionModes, codeModelPorts as codeModelPortsFor, opencodeModels as opencodeModelsFor } from "./code-agent/common";
import { codeAgentPortForModel, codeAgentPortInfo, codeExecutionModeInfo, codeExecutionModes, codeModelProviderSourceContract, codeModelPorts as codeModelPortsFor, opencodeModels as opencodeModelsFor } from "./code-agent/common";
import { claudeQqNotificationOutboxStats, notificationTargetConfigured, notificationTargetLabel } from "./notifications";
import { executionModeOptions, executionProviderOptions } from "./provider-runtime";
import { taskFullOutput } from "./task-output";
@@ -13,7 +13,7 @@ import type { ActiveRun, ActiveRunSlotWaiter } from "./code-agent/common";
import type { JsonValue, QueueRecord, QueuedStatusReason, QueueTask, RuntimeConfig, TaskStatus, TranscriptLine } from "./types";
export interface QueueApiContext {
config: Pick<RuntimeConfig, "codeModels" | "codexModels" | "codexSqliteLogExportBatchSize" | "codexSqliteLogExportEnabled" | "codexSqliteLogExportIntervalMs" | "codexSqliteLogMaxBytes" | "defaultModel" | "defaultReasoningEffort" | "defaultWorkdir" | "judgeMaxTokens" | "judgeRepairAttempts" | "mainProviderId" | "maxActiveQueues" | "maxInMemoryEventRecords" | "maxInMemoryOutputRecords" | "minimaxApiKey" | "minimaxModel" | "modelReasoningEfforts" | "notifyClaudeQqBaseUrl" | "notifyClaudeQqEnabled" | "notifyClaudeQqMaxResponseChars" | "notifyClaudeQqRetryIntervalMs" | "notifyClaudeQqSendAttempts" | "notifyClaudeQqTargetType" | "notifyClaudeQqTimeoutMs" | "outputArchiveDir" | "remoteDefaultWorkdir" | "schedulerEnabled" | "schedulerPollIntervalMs" | "windowsNativeCodexDefaultWorkdir">;
config: Pick<RuntimeConfig, "codeModels" | "codexModels" | "codexSqliteLogExportBatchSize" | "codexSqliteLogExportEnabled" | "codexSqliteLogExportIntervalMs" | "codexSqliteLogMaxBytes" | "deepseekApiBase" | "deepseekApiKey" | "deepseekModel" | "defaultModel" | "defaultReasoningEffort" | "defaultWorkdir" | "judgeMaxTokens" | "judgeRepairAttempts" | "mainProviderId" | "maxActiveQueues" | "maxInMemoryEventRecords" | "maxInMemoryOutputRecords" | "minimaxApiBase" | "minimaxApiKey" | "minimaxModel" | "modelReasoningEfforts" | "notifyClaudeQqBaseUrl" | "notifyClaudeQqEnabled" | "notifyClaudeQqMaxResponseChars" | "notifyClaudeQqRetryIntervalMs" | "notifyClaudeQqSendAttempts" | "notifyClaudeQqTargetType" | "notifyClaudeQqTimeoutMs" | "outputArchiveDir" | "remoteDefaultWorkdir" | "schedulerEnabled" | "schedulerPollIntervalMs" | "windowsNativeCodexDefaultWorkdir">;
activeRunSlotQueueIds: () => string[];
activeRunSlotWaiterSummaries: () => JsonValue[];
activeRuns: Map<string, ActiveRun>;
@@ -478,6 +478,7 @@ function queueSummary(includeDevReady = true, tasks: QueueTask[] = ctx().tasks()
codexModels: ctx().config.codexModels,
opencodeModels: opencodeModelsFor(ctx().config.codeModels),
modelPorts: codeModelPortsFor(ctx().config.codeModels) as unknown as JsonValue,
modelProviderConfig: codeModelProviderSourceContract(ctx().config) as unknown as JsonValue,
executionModes: executionModeOptions(),
executionModeInfo: Object.fromEntries(codeExecutionModes.map((mode) => [mode, codeExecutionModeInfo(mode)])) as unknown as JsonValue,
agentPorts: {