fix(runtime): preserve model capacity history and cache evidence with resumable file proposals
This commit is contained in:
@@ -2,10 +2,11 @@ import { randomUUID,createHash } from 'node:crypto';
|
||||
import { budgetFor } from './request-plan.mjs';
|
||||
import { accountedTokens,emptyUsage } from '../../shared/contracts/execution.mjs';
|
||||
import { capabilityRejections } from '../../shared/contracts/model-capabilities.mjs';
|
||||
import { CAPACITY_RANGES } from '../../shared/contracts/model-capacity.mjs';
|
||||
|
||||
const fail=(message,status=409)=>Object.assign(new Error(message),{status});
|
||||
const hash=value=>createHash('sha256').update(JSON.stringify(value)).digest('hex');
|
||||
const ranges={contextLimit:[1000,200000],maxOutputTokens:[256,16000],maxSteps:[1,30],maxRunTokens:[1000,2000000],maxTaskTokens:[1000,10000000],maxRunDurationMs:[1000,3600000]};
|
||||
const ranges={...CAPACITY_RANGES,maxSteps:[1,30],maxRunTokens:[1000,2000000],maxTaskTokens:[1000,10000000],maxRunDurationMs:[1000,3600000]};
|
||||
|
||||
export class BudgetResume {
|
||||
constructor(store,provider,runtime){this.store=store;this.provider=provider;this.runtime=runtime;}
|
||||
@@ -18,7 +19,7 @@ export class BudgetResume {
|
||||
prepare(session,input){
|
||||
const {task,run}=this.current(session);
|
||||
if(!input||Object.keys(input).some(key=>![...Object.keys(ranges),'selection'].includes(key)))throw fail('续接预览字段无效。',400);
|
||||
const config={...this.store.config,maxTaskTokens:task.budget.maxTokens};
|
||||
const config={...this.store.config,capacityMode:'manual',maxTaskTokens:task.budget.maxTokens};
|
||||
for(const [key,[minimum,maximum]] of Object.entries(ranges))if(input[key]!==undefined){
|
||||
if(!Number.isSafeInteger(input[key])||input[key]<minimum||input[key]>maximum)throw fail('续接预算 '+key+' 超出允许范围。',400);
|
||||
config[key]=input[key];
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { createHash } from 'node:crypto';
|
||||
|
||||
const hash = value => createHash('sha256').update(value).digest('hex');
|
||||
const variants = body => body.kind === 'model-route-plan' ? body.variants : [{ connectionId: null, protocol: body.input ? 'responses' : Array.isArray(body.system) ? 'anthropic-messages' : 'chat-completions', body }];
|
||||
const prompt = body => Buffer.from(JSON.stringify({ model: body.model, tools: body.tools ?? [], system: body.system ?? null, messages: body.messages ?? body.input ?? [] }));
|
||||
|
||||
// This measures ordered prompt fields, not a supplier cache hit or saved
|
||||
// tokens. Metadata stays outside the request and cannot invalidate its prefix.
|
||||
export function prefixAudit(body, previous = null) {
|
||||
const old = previous ? variants(previous) : [];
|
||||
return { schemaVersion: 1, method: 'ordered-wire-prompt-fields-utf8', upstreamCache: 'unknown', variants: variants(body).map(current => {
|
||||
const tools = JSON.stringify(current.body.tools ?? []), bytes = prompt(current.body);
|
||||
const prior = old.find(value => value.connectionId === current.connectionId && value.protocol === current.protocol && value.body.model === current.body.model);
|
||||
const previousBytes = prior ? prompt(prior.body) : null;
|
||||
let common = 0;
|
||||
if (previousBytes) while (common < Math.min(previousBytes.length, bytes.length) && previousBytes[common] === bytes[common]) common++;
|
||||
const toolsChanged = !!prior && JSON.stringify(prior.body.tools ?? []) !== tools;
|
||||
return { connectionId: current.connectionId, protocol: current.protocol, model: current.body.model,
|
||||
toolsSha256: hash(tools), toolBytes: Buffer.byteLength(tools), toolNames: (current.body.tools ?? []).map(tool => tool.function?.name ?? tool.name),
|
||||
promptBytes: bytes.length, previousPromptBytes: previousBytes?.length ?? null, commonPrefixBytes: common,
|
||||
reason: !prior ? 'new_route_or_first_request' : toolsChanged ? 'tool_surface_changed' : bytes.equals(previousBytes) ? 'same_prompt' : 'prompt_append_or_change' };
|
||||
}) };
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import { skillCatalogMessage, SKILL_LIMITS } from '../skills/skill-registry.mjs'
|
||||
import { mcpCatalogMessage, MCP_LIMITS } from '../tools/mcp-contract.mjs';
|
||||
import { modelReservation,taskConsumption,verifyModelReservation } from '../../shared/contracts/model-reservation.mjs';
|
||||
import { fileContinuation } from './read-continuation.mjs';
|
||||
import { prefixAudit } from './prefix-audit.mjs';
|
||||
|
||||
const hash = value => createHash('sha256').update(typeof value === 'string' ? value : JSON.stringify(value), 'utf8').digest('hex');
|
||||
const PLACEHOLDER_ID = '00000000-0000-0000-0000-000000000000';
|
||||
@@ -61,7 +62,7 @@ export function budgetFor(config, run, task, transportReservationTokens = 0) {
|
||||
if (taskRemainingTokens !== null && taskRemainingTokens < limit) { limit = taskRemainingTokens; reason = 'task_token_limit'; }
|
||||
if(!Number.isSafeInteger(transportReservationTokens)||transportReservationTokens<0)throw new Error('请求封装预留无效。');
|
||||
const inputBudget = limit - outputReservation - safetyTokens - transportReservationTokens;
|
||||
return { contextLimit: config.contextLimit, outputReservation, safetyTokens, ...(transportReservationTokens?{transportReservationTokens}:{}), inputBudget, targetInputTokens: Math.min(16000, inputBudget),
|
||||
return { contextLimit: config.contextLimit, outputReservation, safetyTokens, ...(transportReservationTokens?{transportReservationTokens}:{}), inputBudget, targetInputTokens: config.capacityMode === 'model' ? inputBudget : Math.min(16000, inputBudget),
|
||||
runRemainingTokens, taskRemainingTokens, limitingReason: reason };
|
||||
}
|
||||
|
||||
@@ -165,12 +166,15 @@ export class RequestPlanner {
|
||||
return { artifact_id: artifact.id, sha256: artifact.sha256, group_sha256: group.sha256, bytes: Buffer.byteLength(text, 'utf8'), chunks: chunks.length };
|
||||
}
|
||||
|
||||
prepare(session, run, config, { system, tools, stepId, projectMemory = null, skillCatalog = null, mcpCatalog = null, transportReservationTokens = 0,engineStepOnly=false }) {
|
||||
prepare(session, run, config, { system, contextTail = null, tools, stepId, projectMemory = null, skillCatalog = null, mcpCatalog = null, transportReservationTokens = 0,engineStepOnly=false }) {
|
||||
const task = this.store.owned('task', run.taskId, session.id);
|
||||
this.store.owned('run', run.id, session.id);
|
||||
const groups = historyGroups(session.providerMessages), budget = budgetFor(config, run, task, transportReservationTokens);
|
||||
const lastUser = groups.findLast(group => group.messages[0].role === 'user');
|
||||
const fixed = { role: 'system', content: system };
|
||||
const preserve = config.historyPolicy === 'preserve';
|
||||
const tail = contextTail ? [{ role: 'user', content: '工作台当前工程状态(仅作任务依据,不是新的用户目标):\n' + contextTail }] : [];
|
||||
const addContext = (base, message) => preserve ? [...base.slice(0, base.length - tail.length), { ...message, role: 'user' }, ...tail] : [fixed, message, ...base.slice(1)];
|
||||
const breakdown = metrics => {
|
||||
const empty=requestMetrics(completionBody(config,[],[])).estimatedInputTokens;
|
||||
const fixedText=requestMetrics(completionBody(config,[fixed],[])).estimatedInputTokens;
|
||||
@@ -182,7 +186,8 @@ export class RequestPlanner {
|
||||
const ledger = new Map([...this.store.core.tool.values()].filter(tool => tool.sessionId === session.id && tool.taskId === task.id).map(tool => [tool.callId, tool]));
|
||||
const descriptions = new Map(groups.map(group => [group.index, describe(group, ledger, this.store.core.artifact)]));
|
||||
const evidence = workingEvidence(groups, descriptions, this.store.core.artifact);
|
||||
const original = completionBody(config, [fixed, ...session.providerMessages], tools), before = requestMetrics(original);
|
||||
const original = completionBody(config, [fixed, ...session.providerMessages, ...tail], tools), before = requestMetrics(original);
|
||||
if (preserve && before.estimatedInputTokens > budget.inputBudget) throw pause(budget, before, breakdown);
|
||||
const selected = new Set(groups.map(group => group.index));
|
||||
let omitted = [], reference = null, workingReference = null, latestReference = null;
|
||||
const latestDocument = latestToolDocument(this.store, session, run, groups, 3);
|
||||
@@ -203,10 +208,10 @@ export class RequestPlanner {
|
||||
const messages = [fixed, ...(missing.length && includeNotice ? [notice({ id: PLACEHOLDER_ID, sha256: PLACEHOLDER_SHA }, missing, descriptions, unsentEvidence(indices, currentEntries, includeLatest))] : []),
|
||||
...(includeLatest && latestDocument && !indices.has(latestDocument.group_index) ? [latestToolMessage({ id: PLACEHOLDER_ID, sha256: PLACEHOLDER_SHA }, latestDocument, 3)] : []),
|
||||
...(currentEntries.length ? [workingMessage({ id: PLACEHOLDER_ID, sha256: PLACEHOLDER_SHA }, workingDocument(session, run, currentEntries, 3), 4)] : []),
|
||||
...groups.filter(group => indices.has(group.index)).flatMap(group => group.messages)];
|
||||
...groups.filter(group => indices.has(group.index)).flatMap(group => group.messages), ...tail];
|
||||
return requestMetrics(completionBody(config, messages, tools));
|
||||
};
|
||||
if (before.estimatedInputTokens > budget.targetInputTokens) {
|
||||
if (!preserve && before.estimatedInputTokens > budget.targetInputTokens) {
|
||||
selected.clear(); if (lastUser) selected.add(lastUser.index);
|
||||
const mandatory = metricsFor(selected);
|
||||
if (mandatory.estimatedInputTokens > budget.inputBudget) throw pause(budget, mandatory, breakdown);
|
||||
@@ -288,19 +293,19 @@ export class RequestPlanner {
|
||||
const messages = [fixed, ...(reference ? [notice(reference, omitted, descriptions, unsentEvidence(selected, entries, true))] : []),
|
||||
...(latestReference ? [latestToolMessage(latestReference, latestDocument, 3)] : []),
|
||||
...(workingReference ? [workingMessage(workingReference, workingDocument(session, run, entries, 3), 4)] : []),
|
||||
...structuredClone(groups.filter(group => selected.has(group.index)).flatMap(group => group.messages))];
|
||||
...structuredClone(groups.filter(group => selected.has(group.index)).flatMap(group => group.messages)), ...tail];
|
||||
let mcpReference = null, mcpDocument = null;
|
||||
if (mcpCatalog?.projectId === session.projectId && mcpCatalog.entries?.length) {
|
||||
mcpDocument = { ...mcpCatalog, sessionId: session.id, taskId: run.taskId, runId: run.id, entries: [] };
|
||||
for (const entry of mcpCatalog.entries.slice(0, MCP_LIMITS.allowedTools)) {
|
||||
mcpDocument.entries.push(entry);
|
||||
const candidate = [fixed, mcpCatalogMessage({ id: PLACEHOLDER_ID, sha256: PLACEHOLDER_SHA }, mcpDocument), ...messages.slice(1)];
|
||||
const candidate = addContext(messages, mcpCatalogMessage({ id: PLACEHOLDER_ID, sha256: PLACEHOLDER_SHA }, mcpDocument));
|
||||
if (Buffer.byteLength(JSON.stringify(mcpDocument), 'utf8') > 24000
|
||||
|| requestMetrics(completionBody(config, candidate, tools)).estimatedInputTokens > Math.min(budget.inputBudget, budget.targetInputTokens)) mcpDocument.entries.pop();
|
||||
}
|
||||
if (mcpDocument.entries.length) {
|
||||
mcpReference = this.artifact(session, run, mcpDocument, 'context-mcp-catalog');
|
||||
messages.splice(1, 0, mcpCatalogMessage(mcpReference, mcpDocument));
|
||||
messages.splice(0, messages.length, ...addContext(messages, mcpCatalogMessage(mcpReference, mcpDocument)));
|
||||
}
|
||||
}
|
||||
let skillReference = null, skillDocument = null;
|
||||
@@ -308,13 +313,13 @@ export class RequestPlanner {
|
||||
skillDocument = { ...skillCatalog, sessionId: session.id, taskId: run.taskId, runId: run.id, entries: [] };
|
||||
for (const entry of skillCatalog.entries.slice(0, SKILL_LIMITS.enabled)) {
|
||||
skillDocument.entries.push(entry);
|
||||
const candidate = [fixed, skillCatalogMessage({ id: PLACEHOLDER_ID, sha256: PLACEHOLDER_SHA }, skillDocument), ...messages.slice(1)];
|
||||
const candidate = addContext(messages, skillCatalogMessage({ id: PLACEHOLDER_ID, sha256: PLACEHOLDER_SHA }, skillDocument));
|
||||
if (Buffer.byteLength(JSON.stringify(skillDocument), 'utf8') > SKILL_LIMITS.catalogBytes
|
||||
|| requestMetrics(completionBody(config, candidate, tools)).estimatedInputTokens > Math.min(budget.inputBudget, budget.targetInputTokens)) skillDocument.entries.pop();
|
||||
}
|
||||
if (skillDocument.entries.length) {
|
||||
skillReference = this.artifact(session, run, skillDocument, 'context-skill-catalog');
|
||||
messages.splice(1, 0, skillCatalogMessage(skillReference, skillDocument));
|
||||
messages.splice(0, messages.length, ...addContext(messages, skillCatalogMessage(skillReference, skillDocument)));
|
||||
}
|
||||
}
|
||||
// Optional catalogs and memory use only space left after goals, paired history and current code evidence.
|
||||
@@ -325,13 +330,13 @@ export class RequestPlanner {
|
||||
for (const entry of projectMemory.entries.slice(0, MEMORY_CONTEXT_LIMITS.entries)) {
|
||||
if (entry.sourceFingerprint !== projectMemory.sourceFingerprint) continue;
|
||||
memoryDocument.entries.push(entry);
|
||||
const candidate = [fixed, projectMemoryMessage({ id: PLACEHOLDER_ID, sha256: PLACEHOLDER_SHA }, memoryDocument), ...messages.slice(1)];
|
||||
const candidate = addContext(messages, projectMemoryMessage({ id: PLACEHOLDER_ID, sha256: PLACEHOLDER_SHA }, memoryDocument));
|
||||
if (Buffer.byteLength(JSON.stringify(memoryDocument), 'utf8') > MEMORY_CONTEXT_LIMITS.bytes
|
||||
|| requestMetrics(completionBody(config, candidate, tools)).estimatedInputTokens > memoryBudget) memoryDocument.entries.pop();
|
||||
}
|
||||
if (memoryDocument.entries.length) {
|
||||
memoryReference = this.artifact(session, run, memoryDocument, 'context-project-memory');
|
||||
messages.splice(1, 0, projectMemoryMessage(memoryReference, memoryDocument));
|
||||
messages.splice(0, messages.length, ...addContext(messages, projectMemoryMessage(memoryReference, memoryDocument)));
|
||||
}
|
||||
}
|
||||
const body = completionBody(config, messages, tools), metrics = requestMetrics(body);
|
||||
@@ -341,11 +346,18 @@ export class RequestPlanner {
|
||||
if(tokenReservation&&tokenReservation.reservedTokens>credit)throw pause({...budget,limitingReason:runCredit<=taskCredit?'token_limit':'task_token_limit',
|
||||
tokenReservation,remainingTokens:credit,pauseKind:'request_reservation'},metrics,breakdown);
|
||||
const requestArtifact = this.artifact(session, run, body, 'model-request');
|
||||
const tailArtifact = tail.length ? this.artifact(session, run, tail[0], 'context-state-tail') : null;
|
||||
const previousPlan = [...this.store.core.context_plan.values()].filter(plan => plan.sessionId === session.id && plan.taskId === task.id && plan.requestAttempts > 0)
|
||||
.sort((a, b) => a.createdAt.localeCompare(b.createdAt) || a.requestIndex - b.requestIndex).at(-1) ?? null;
|
||||
const previousBody = previousPlan ? JSON.parse(this.store.artifactStore.read(this.store.owned('artifact', previousPlan.requestArtifactId, session.id))) : null;
|
||||
const prefix = { ...prefixAudit(body, previousBody), previousPlanId: previousPlan?.id ?? null, previousRequestSha256: previousPlan?.requestSha256 ?? null };
|
||||
const record = { schemaVersion: 1, id: randomUUID(), sessionId: session.id, projectId: session.projectId, taskId: run.taskId,
|
||||
runId: run.id, stepId, requestIndex: [...this.store.core.context_plan.values()].filter(plan => plan.runId === run.id).length + 1,
|
||||
status: 'prepared', createdAt: new Date().toISOString(), finishedAt: null,
|
||||
requestSha256: metrics.sha256, requestBytes: metrics.bytes, estimatedInputTokens: metrics.estimatedInputTokens,
|
||||
requestArtifactId: requestArtifact.id,
|
||||
prefixAudit: prefix,
|
||||
...(preserve ? { contextLayout: 'stable-prefix-1', historyPolicy: 'preserve', contextTailArtifactId: tailArtifact?.id ?? null, contextTailSha256: tailArtifact?.sha256 ?? null } : {}),
|
||||
...(tokenReservation?{tokenReservation,maxBudgetAttempts:Math.min(8,Math.floor(credit/tokenReservation.reservedTokens))}:{engineStepOnly:true}),
|
||||
estimateMethod: metrics.estimateMethod, beforeInputTokens: before.estimatedInputTokens, beforeBytes: before.bytes, budget,
|
||||
...(metrics.imageCount?{imageCount:metrics.imageCount,imageReservationTokens:metrics.imageReservationTokens,imageEstimate:metrics.imageEstimate,
|
||||
@@ -358,7 +370,7 @@ export class RequestPlanner {
|
||||
- metricsFor(new Set(lastUser ? [lastUser.index] : []), true, []).estimatedInputTokens),
|
||||
workingRetentionPolicyVersion: 1,
|
||||
readBudgetPolicyVersion: 3,
|
||||
originalMessages: session.providerMessages.length, retainedMessages: messages.length - 1 - (reference ? 1 : 0) - (workingReference ? 1 : 0) - (latestReference ? 1 : 0) - (memoryReference ? 1 : 0) - (skillReference ? 1 : 0) - (mcpReference ? 1 : 0),
|
||||
originalMessages: session.providerMessages.length, retainedMessages: messages.length - 1 - tail.length - (reference ? 1 : 0) - (workingReference ? 1 : 0) - (latestReference ? 1 : 0) - (memoryReference ? 1 : 0) - (skillReference ? 1 : 0) - (mcpReference ? 1 : 0),
|
||||
archivedGroups: omitted.length, retainedGroups: groups.filter(group => selected.has(group.index)).map(group => group.index),
|
||||
historyIndexArtifactId: reference?.id ?? null, historyIndexSha256: reference?.sha256 ?? null, actualUsage: null,
|
||||
workingSetArtifactId: workingReference?.id ?? null, workingSetSha256: workingReference?.sha256 ?? null, workingSetEntries: entries.length,
|
||||
@@ -404,6 +416,23 @@ export function verifyPlanEvidence(store, session, plan, cache = new Map()) {
|
||||
historyGroups(requestHistory(body));
|
||||
for (const variant of requestVariants(body)) historyGroups(requestHistory(variant));
|
||||
const frozen = JSON.parse(store.artifactStore.read(get(plan.artifactId, 'context-plan')));
|
||||
for (const key of ['contextLayout', 'historyPolicy', 'contextTailArtifactId', 'contextTailSha256', 'prefixAudit']) {
|
||||
if (JSON.stringify(frozen[key] ?? null) !== JSON.stringify(plan[key] ?? null)) throw new Error('前缀或历史策略与发送前封存不匹配。');
|
||||
}
|
||||
if (plan.prefixAudit) {
|
||||
const previous = plan.prefixAudit.previousPlanId ? store.owned('context_plan', plan.prefixAudit.previousPlanId, session.id) : null;
|
||||
if (previous && (previous.taskId !== plan.taskId || previous.id === plan.id || previous.createdAt > plan.createdAt || previous.requestSha256 !== plan.prefixAudit.previousRequestSha256)) throw new Error('前缀对照来源不匹配。');
|
||||
const previousBody = previous ? JSON.parse(store.artifactStore.read(get(previous.requestArtifactId, 'model-request', previous.requestSha256))) : null;
|
||||
const expected = { ...prefixAudit(body, previousBody), previousPlanId: previous?.id ?? null, previousRequestSha256: previous?.requestSha256 ?? null };
|
||||
if (JSON.stringify(expected) !== JSON.stringify(plan.prefixAudit)) throw new Error('前缀观测与原请求字节不匹配。');
|
||||
}
|
||||
const carriesContext = content => requestHistory(body).filter(value => typeof value.content === 'string'
|
||||
&& (value.role === 'system' && value.content === content || plan.contextLayout === 'stable-prefix-1' && value.role === 'user' && value.content.includes(content))).length === 1;
|
||||
if (plan.contextTailArtifactId) {
|
||||
const artifact = get(plan.contextTailArtifactId, 'context-state-tail', plan.contextTailSha256);
|
||||
const tail = JSON.parse(store.artifactStore.read(artifact));
|
||||
if (artifact.taskId !== plan.taskId || artifact.runId !== plan.runId || tail.role !== 'user' || !carriesContext(tail.content)) throw new Error('动态状态与实际发送内容不匹配。');
|
||||
}
|
||||
for(const key of ['tokenReservation','maxBudgetAttempts'])if(JSON.stringify(frozen[key]??null)!==JSON.stringify(plan[key]??null))throw new Error('模型用量预留与发送前封存不一致。');
|
||||
for(const key of ['imageCount','imageReservationTokens','imageEstimate','inputImages']) {
|
||||
if(JSON.stringify(frozen[key]??null)!==JSON.stringify(plan[key]??null))throw new Error('图片身份或预算与发送前封存不匹配。');
|
||||
@@ -451,7 +480,7 @@ export function verifyPlanEvidence(store, session, plan, cache = new Map()) {
|
||||
|| document.entries.length > MEMORY_CONTEXT_LIMITS.entries || Buffer.byteLength(JSON.stringify(document), 'utf8') > MEMORY_CONTEXT_LIMITS.bytes
|
||||
|| document.entries.some(entry => entry.sourceFingerprint !== document.sourceFingerprint)) throw new Error('项目记忆工件归属或范围不匹配。');
|
||||
const message = projectMemoryMessage(artifact, document);
|
||||
if (requestHistory(body).filter(value => value.role === 'system' && value.content === message.content).length !== 1) throw new Error('项目记忆与实际发送内容不匹配。');
|
||||
if (!carriesContext(message.content)) throw new Error('项目记忆与实际发送内容不匹配。');
|
||||
}
|
||||
if ((frozen.skillCatalogArtifactId ?? null) !== (plan.skillCatalogArtifactId ?? null)
|
||||
|| (frozen.skillCatalogSha256 ?? null) !== (plan.skillCatalogSha256 ?? null)
|
||||
@@ -465,7 +494,7 @@ export function verifyPlanEvidence(store, session, plan, cache = new Map()) {
|
||||
|| document.entries.length > SKILL_LIMITS.enabled || Buffer.byteLength(JSON.stringify(document), 'utf8') > SKILL_LIMITS.catalogBytes
|
||||
|| new Set(document.entries.map(entry => entry.id)).size !== document.entries.length) throw new Error('技能目录归属或范围不匹配。');
|
||||
const message = skillCatalogMessage(artifact, document);
|
||||
if (requestHistory(body).filter(value => value.role === 'system' && value.content === message.content).length !== 1) throw new Error('技能目录与实际发送内容不匹配。');
|
||||
if (!carriesContext(message.content)) throw new Error('技能目录与实际发送内容不匹配。');
|
||||
}
|
||||
if ((frozen.mcpCatalogArtifactId ?? null) !== (plan.mcpCatalogArtifactId ?? null)
|
||||
|| (frozen.mcpCatalogSha256 ?? null) !== (plan.mcpCatalogSha256 ?? null)
|
||||
@@ -478,7 +507,7 @@ export function verifyPlanEvidence(store, session, plan, cache = new Map()) {
|
||||
|| document.kind !== 'registered-mcp-catalog' || !Array.isArray(document.entries) || document.entries.length !== plan.mcpCatalogEntries
|
||||
|| document.entries.length > MCP_LIMITS.allowedTools || Buffer.byteLength(JSON.stringify(document), 'utf8') > 24000) throw new Error('MCP目录归属或范围不匹配。');
|
||||
const message = mcpCatalogMessage(artifact, document);
|
||||
if (requestHistory(body).filter(value => value.role === 'system' && value.content === message.content).length !== 1) throw new Error('MCP目录与实际发送内容不匹配。');
|
||||
if (!carriesContext(message.content)) throw new Error('MCP目录与实际发送内容不匹配。');
|
||||
}
|
||||
if (plan.latestToolsArtifactId) {
|
||||
const artifact = get(plan.latestToolsArtifactId, 'context-latest-tools', plan.latestToolsSha256);
|
||||
|
||||
Reference in New Issue
Block a user