fix(pi): converge worker failures and thinking state

This commit is contained in:
2026-08-25 11:45:14 +08:00
parent 274187e3cf
commit 61817b161f
28 changed files with 2019 additions and 118 deletions

View File

@@ -9,6 +9,7 @@ export interface ProductModelRef {
export interface ConversationModelState {
model: ProductModelRef | null;
modelResolution: 'resolved' | 'required';
availableThinkingLevels?: ConversationThinkingLevel[];
}
export interface PublicUsage {

View File

@@ -54,6 +54,7 @@ const RUN_STATUSES = new Set([
]);
const WORKER_STATUSES = new Set(['stopped', 'starting', 'ready', 'recovering', 'error']);
const THINKING_LEVELS = new Set(['off', 'minimal', 'low', 'medium', 'high']);
const ERROR_CODES = new Set([
'CODING_RUNTIME_START_FAILED',
'CODING_RUNTIME_READY_TIMEOUT',
@@ -115,12 +116,18 @@ function isPublicError(value: unknown): value is CodingRuntimePublicError {
function isModelState(value: unknown): boolean {
const record = asRecord(value);
if (!record || !['resolved', 'required'].includes(String(record.modelResolution))) return false;
if (record.model === null) return record.modelResolution === 'required';
if (record.model === null) {
return record.modelResolution === 'required' && record.availableThinkingLevels === undefined;
}
const model = asRecord(record.model);
return model !== null
&& isNonEmptyString(model.accountId)
&& isNonEmptyString(model.modelId)
&& ['off', 'minimal', 'low', 'medium', 'high'].includes(String(model.thinkingLevel))
&& THINKING_LEVELS.has(String(model.thinkingLevel))
&& (record.availableThinkingLevels === undefined
|| (Array.isArray(record.availableThinkingLevels)
&& record.availableThinkingLevels.length > 0
&& record.availableThinkingLevels.every((level) => THINKING_LEVELS.has(String(level)))))
&& record.modelResolution === 'resolved';
}

View File

@@ -1,5 +1,15 @@
export type ImportedModelModality = 'text' | 'audio' | 'image' | 'pdf';
export type ImportedVisionTokenEstimator = 'qwen-32px-grid';
export type ImportedThinkingLevel = 'off' | 'minimal' | 'low' | 'medium' | 'high';
export interface ImportedPiModelProfile {
reasoning: boolean;
thinkingLevelMap?: Partial<Record<ImportedThinkingLevel, string | null>>;
compat?: {
thinkingFormat?: 'deepseek' | 'openrouter';
requiresReasoningContentOnAssistantMessages?: boolean;
};
}
export interface ImportedModelProfile {
modalities: {
@@ -11,6 +21,7 @@ export interface ImportedModelProfile {
output: number;
};
visionTokenEstimator?: ImportedVisionTokenEstimator;
pi?: ImportedPiModelProfile;
}
const VERIFIED_QWEN_PLUS_MODEL_IDS = new Set([
@@ -31,6 +42,32 @@ function imageModalities(): ImportedModelProfile['modalities'] {
export function getImportedModelProfile(rawModelId: string): ImportedModelProfile | null {
const modelId = rawModelId.trim();
if (modelId.toLowerCase() === 'deepseek-v4-pro') {
return {
modalities: {
input: ['text'],
output: ['text'],
},
limit: {
context: 1_000_000,
output: 384_000,
},
pi: {
reasoning: true,
thinkingLevelMap: {
off: null,
minimal: null,
low: null,
medium: null,
high: 'high',
},
compat: {
thinkingFormat: 'deepseek',
requiresReasoningContentOnAssistantMessages: true,
},
},
};
}
if (VERIFIED_QWEN_PLUS_MODEL_IDS.has(modelId.toLowerCase())) {
return {
modalities: imageModalities(),