feat(runtime): default to passthrough and persist execution permissions
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { unrestricted, ceiling } from '../../shared/contracts/execution-policy.mjs';
|
||||
import { ModelRequestError } from '../../server/diagnostics.mjs';
|
||||
export const protocolFailure = (message, kind = 'protocol', extra = null) => new ModelRequestError({ kind, source: 'model_connection', origin: 'local', stage: 'model_request',
|
||||
title: '模型响应未通过完整性核对', message, retryable: false, occurredAt: new Date().toISOString(), ...(extra ? extra : {}) });
|
||||
@@ -46,12 +47,12 @@ function acceptsEmptyObject(tools, name) {
|
||||
['type', 'properties', 'required', 'additionalProperties', 'description', 'title', '$schema'].includes(key));
|
||||
}
|
||||
|
||||
export function validateModelResponse(value, tools) {
|
||||
export function validateModelResponse(value, tools, config = {}) {
|
||||
const choice = value.choices?.[0], message = choice?.message;
|
||||
if (choice?.finish_reason === 'length') throw outputTruncatedFailure();
|
||||
if (!message || choice.finish_reason === 'content_filter') throw protocolFailure('模型响应缺少完整message或因内容过滤未完整结束,未执行工具。');
|
||||
const calls = message.tool_calls;
|
||||
if (calls !== undefined && (!Array.isArray(calls) || calls.length > 12)) throw protocolFailure('模型工具调用数量或格式无效。');
|
||||
if (calls !== undefined && (!Array.isArray(calls) || !unrestricted(config) && calls.length > 12)) throw protocolFailure('模型工具调用数量或格式无效。');
|
||||
const ids = new Set();
|
||||
for (const call of calls ?? []) {
|
||||
if (!call.id || typeof call.id !== 'string' || ids.has(call.id) || call.type !== 'function' || typeof call.function?.name !== 'string' || !call.function.name || typeof call.function.arguments !== 'string') throw protocolFailure('模型工具身份或参数无效。');
|
||||
|
||||
Reference in New Issue
Block a user