20 lines
1.3 KiB
JavaScript
20 lines
1.3 KiB
JavaScript
import { CAPACITY_RANGES, capacityMode } from '../../shared/contracts/model-capacity.mjs';
|
|
|
|
const ranges = {
|
|
...CAPACITY_RANGES, maxSteps: [1, 30],
|
|
maxRunDurationMs: [1000, 3600000], maxRunTokens: [1000, 2000000], maxTaskTokens: [1000, 10000000],
|
|
};
|
|
|
|
// Budget-only edits cannot change the selected route, endpoint or credential.
|
|
export function validateRuntimeBudgets(input) {
|
|
if (!input || typeof input !== 'object' || Array.isArray(input) || !Object.keys(input).length
|
|
|| Object.keys(input).some(key => !['capacityMode', 'historyPolicy'].includes(key) && !Object.hasOwn(ranges, key))) throw new Error('只接受运行预算字段;模型连接请在模型选择中切换。');
|
|
for (const [key, value] of Object.entries(input)) {
|
|
if (key === 'capacityMode') { capacityMode(value); continue; }
|
|
if (key === 'historyPolicy') { if (!['preserve', 'compact'].includes(value)) throw new Error('请选择完整传递或允许整理历史。'); continue; }
|
|
const [min, max] = ranges[key];
|
|
if (!Number.isSafeInteger(value) || value < min || value > max) throw new Error(key + ' 需填写范围内的整数。');
|
|
}
|
|
return { ...input, ...(!Object.hasOwn(input, 'capacityMode') && ['contextLimit', 'maxOutputTokens'].some(key => Object.hasOwn(input, key)) ? { capacityMode: 'manual' } : {}) };
|
|
}
|