fix: complete unrestricted waits catalog and network flows
This commit is contained in:
@@ -73,8 +73,8 @@ export function verifyEngineModelInput(store, session, job, request) {
|
||||
if (input.owner.sessionId !== job.sessionId || input.owner.taskId !== job.taskId || input.owner.runId !== job.runId || input.owner.projectId !== job.projectId
|
||||
|| controlledDigest(input.native) !== request.sourceSha256 || metrics.sha256 !== request.requestSha256 || metrics.bytes !== request.requestBytes
|
||||
|| !Number.isSafeInteger(request.maxAttempts) || request.maxAttempts < 1 || request.maxAttempts > 8
|
||||
|| (job.model.capacityMode !== 'passthrough' && (!Number.isSafeInteger(input.native.maxTokens) || input.native.maxTokens < 1))
|
||||
|| !requestVariants(input.body).every(body => outputReservation(body) === (job.model.capacityMode === 'passthrough' ? null : input.native.maxTokens))
|
||||
|| (job.model?.capacityMode !== 'passthrough' && (!Number.isSafeInteger(input.native.maxTokens) || input.native.maxTokens < 1))
|
||||
|| !requestVariants(input.body).every(body => outputReservation(body) === (job.model?.capacityMode === 'passthrough' ? null : input.native.maxTokens))
|
||||
|| request.reservedPerAttempt !== (request.reservationVersion===1?request.tokenReservation.reservedTokens:metrics.estimatedInputTokens + 128 + input.native.maxTokens)) throw engineError('原引擎模型输入、归属或预算核对失败。');
|
||||
if(input.view){
|
||||
const view=input.view,source=store.owned('artifact',view.sourceArtifactId,session.id),sourceValue=JSON.parse(store.artifactStore.read(source));
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import { unrestricted } from './execution-policy.mjs';
|
||||
|
||||
// Editable fallbacks for upstreams that do not publish capacity. These values
|
||||
// are not verified model capabilities or ceilings on larger models.
|
||||
export const DEFAULT_MODEL_CAPACITY = Object.freeze({ contextLimit: 128000, maxOutputTokens: 16384 });
|
||||
export const CAPACITY_RANGES = Object.freeze({ contextLimit: [1000, Number.MAX_SAFE_INTEGER], maxOutputTokens: [256, Number.MAX_SAFE_INTEGER] });
|
||||
|
||||
export function capacitySettings(input = {}, previous = DEFAULT_MODEL_CAPACITY) {
|
||||
export function capacitySettings(input = {}, previous = DEFAULT_MODEL_CAPACITY, config = {}) {
|
||||
return Object.fromEntries(Object.entries(CAPACITY_RANGES).map(([key, [min, max]]) => {
|
||||
const value = input[key] ?? previous[key] ?? DEFAULT_MODEL_CAPACITY[key];
|
||||
if (!Number.isSafeInteger(value) || value < min || value > max) throw Object.assign(new Error(key + ' 需要不小于 ' + min + ' 的安全整数,请核对模型实际容量。'), { status: 400 });
|
||||
const minimum = unrestricted(config) ? 1 : min;
|
||||
if (!Number.isSafeInteger(value) || value < minimum || value > max) throw Object.assign(new Error(key + ' 需要不小于 ' + minimum + ' 的安全整数,请核对模型实际容量。'), { status: 400 });
|
||||
return [key, value];
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ export interface CatalogModel {
|
||||
}
|
||||
export interface CatalogPreview {
|
||||
id: string; entries: CatalogModel[]; fetchedAt: string; expiresAt: string; complete: boolean; warning: string;
|
||||
source: { name: string; baseUrl: string; protocol: string }; limits: { connections: number; poolMembers: number; catalog: number };
|
||||
source: { name: string; baseUrl: string; protocol: string }; limits: { connections: number | null; poolMembers: number | null; catalog: number | null };
|
||||
}
|
||||
export function catalogRoute(config: { protocol?: string; baseUrl: string }): string;
|
||||
export function catalogModel(item: unknown): CatalogModel;
|
||||
export function catalogPage(response: unknown): { entries: CatalogModel[]; hasMore: boolean; cursor: string };
|
||||
export function catalogModel(item: unknown, config?: { executionMode?: string }): CatalogModel;
|
||||
export function catalogPage(response: unknown, config?: { executionMode?: string }): { entries: CatalogModel[]; hasMore: boolean; cursor: string };
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { modelProtocol } from './model-capabilities.mjs';
|
||||
import { ceiling, unrestricted } from './execution-policy.mjs';
|
||||
|
||||
const fail = message => Object.assign(new Error(message), { status: 400 });
|
||||
const text = (value, max = 200) => typeof value === 'string' ? value.trim().slice(0, max) : '';
|
||||
@@ -15,10 +16,11 @@ export function catalogRoute(config) {
|
||||
|
||||
// Metadata is an upstream declaration, never capability-test evidence. Keep
|
||||
// unsupported adapter features visible without passing arbitrary vendor fields.
|
||||
export function catalogModel(item) {
|
||||
export function catalogModel(item, config = {}) {
|
||||
if (typeof item === 'string') item = { id: item };
|
||||
if (!item || typeof item !== 'object' || Array.isArray(item)) throw fail('上游模型目录含无效条目。');
|
||||
const id = text(item.id ?? item.name);
|
||||
const field = (value, maximum = 200) => text(value, ceiling(config, maximum));
|
||||
const id = field(item.id ?? item.name);
|
||||
if (!id || id.length !== String(item.id ?? item.name).trim().length || /[\x00-\x1f\x7f]/.test(id)) throw fail('上游模型名称为空、过长或含控制字符。');
|
||||
const caps = item.capabilities && typeof item.capabilities === 'object' && !Array.isArray(item.capabilities) ? item.capabilities : {};
|
||||
const declarations = Object.fromEntries(['text', 'tools', 'streaming', 'vision', 'audio'].map(key => [key,
|
||||
@@ -30,12 +32,12 @@ export function catalogModel(item) {
|
||||
if (input.includes('audio') && declarations.audio === 'unknown') declarations.audio = 'supported';
|
||||
}
|
||||
if (Array.isArray(output) && output.includes('text') && declarations.text === 'unknown') declarations.text = 'supported';
|
||||
const parameters = Array.isArray(item.supported_parameters) ? [...new Set(item.supported_parameters.filter(value => typeof value === 'string' && value.length <= 80))].slice(0, 80) : [];
|
||||
const parameters = Array.isArray(item.supported_parameters) ? [...new Set(item.supported_parameters.filter(value => typeof value === 'string' && (unrestricted(config) || value.length <= 80)))].slice(0, ceiling(config, 80)) : [];
|
||||
if (declarations.tools === 'unknown' && parameters.includes('tools')) declarations.tools = 'supported';
|
||||
const efforts = ['minimal', 'low', 'medium', 'high', 'xhigh', 'max'].filter(value => supported(caps.effort?.[value]) === 'supported');
|
||||
const modes = ['disabled', 'enabled', 'adaptive'].filter(value => supported(caps.thinking?.types?.[value]) === 'supported');
|
||||
const features = Object.fromEntries(['thinking', 'effort', 'pdf_input', 'structured_outputs', 'server_tools', 'code_execution', 'batch', 'citations', 'context_management'].map(key => [key, supported(caps[key])]));
|
||||
return { id, name: text(item.display_name ?? item.name ?? id), owner: text(item.owned_by ?? item.provider, 100),
|
||||
return { id, name: field(item.display_name ?? item.name ?? id), owner: field(item.owned_by ?? item.provider, 100),
|
||||
lifecycle: ['active', 'deprecated', 'retired'].includes(item.lifecycle) ? item.lifecycle : null,
|
||||
contextLimit: positive(item.context_length ?? item.max_input_tokens ?? item.context_window),
|
||||
maxOutputTokens: positive(item.max_output_tokens ?? item.max_tokens ?? item.top_provider?.max_completion_tokens),
|
||||
@@ -43,12 +45,12 @@ export function catalogModel(item) {
|
||||
metadataSource: 'upstream-model-list' };
|
||||
}
|
||||
|
||||
export function catalogPage(response) {
|
||||
export function catalogPage(response, config = {}) {
|
||||
const data = response?.data ?? response?.models;
|
||||
if (!Array.isArray(data)) throw fail('上游未返回 data 或 models 模型列表;可核对接口或使用手动兼容入口。');
|
||||
const entries = data.map(catalogModel);
|
||||
const entries = data.map(item => catalogModel(item, config));
|
||||
const hasMore = response.has_more === true;
|
||||
const cursor = hasMore ? text(response.last_id ?? entries.at(-1)?.id) : '';
|
||||
const cursor = hasMore ? text(response.last_id ?? entries.at(-1)?.id, ceiling(config, 200)) : '';
|
||||
if (hasMore && !cursor) throw fail('上游声明还有下一页,却未提供有效游标。');
|
||||
return { entries, hasMore, cursor };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user