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

@@ -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';
}