fix: hand off complete changes and retain verified source context
This commit is contained in:
@@ -4,10 +4,10 @@ import { api } from './api';
|
||||
import { Modal } from './components';
|
||||
import type { Config,Session } from './types';
|
||||
import './input-attachments.css';
|
||||
import { budgetPausePresentation } from '../shared/budget-presentation.mjs';
|
||||
|
||||
type Fields={contextLimit:number;maxOutputTokens:number;maxRunTokens:number;maxTaskTokens:number;maxSteps:number;maxRunDurationMs:number};
|
||||
type Preview={id:string;sha256:string;taskId:string;runId:string;config:Fields&{model:string};eligibleConnections:{id:string;name:string;model:string}[];budget:{inputBudget:number;contextLimit:number};completedToolIds:string[];unknownToolIds:string[];attachmentIds:string[];note:string};
|
||||
const reasons:Record<string,string>={context_limit:'上下文窗口不足',engine_input_budget:'原生引擎输入或剩余预算不足',token_limit:'本次运行预算不足',task_token_limit:'任务累计预算不足',time_limit:'本次运行时间已用完'};
|
||||
const labels:Record<string,string>={transportAndImageFramingTokens:'请求格式与图片说明',goalAndContextTextTokens:'目标、全部要求及工程上下文',toolDefinitionTokens:'工具定义',historyAndEvidenceTokens:'必需历史及实际依据',imageReservationTokens:'图像本地预留',requestOverheadTokens:'请求格式',fixedInstructionTokens:'完整目标与原生提示',retainedHistoryAndViewTokens:'保留历史与工具结果'};
|
||||
|
||||
export function BudgetPausePanel({session,config,onSession,onRecovery}:{session:Session;config:Config;onSession:(value:Session)=>void;onRecovery?:()=>void}){
|
||||
@@ -16,13 +16,15 @@ export function BudgetPausePanel({session,config,onSession,onRecovery}:{session:
|
||||
maxRunTokens:config.maxRunTokens,maxTaskTokens:session.execution?.task?.budget.maxTokens??config.maxTaskTokens,maxSteps:config.maxSteps,maxRunDurationMs:config.maxRunDurationMs});
|
||||
const [selection,setSelection]=useState(''),[options,setOptions]=useState<{value:string;name:string}[]>([]);
|
||||
const run=session.execution?.run,pause=run?.budgetPause,reason=pause?.reason??run?.stopReason??'';
|
||||
const diagnosis=budgetPausePresentation(pause,reason);
|
||||
const controlled=session.execution?.task?.origin==='isolated-worker'||run?.engine==='deepseek-workbench';
|
||||
const calibrationSources=new Set(pause?.tokenReservation?.routes.flatMap(route=>route.sources.map(source=>source.attemptId))??[]).size;
|
||||
if(!['paused','failed'].includes(session.status)||!reasons[reason])return null;
|
||||
if(!['paused','failed'].includes(session.status)||!diagnosis)return null;
|
||||
async function start(){setOpen(true);setError('');setPlan(null);try{const center=await api<{selected:{type:string;id:string};connections:{id:string;name:string;contextLimit:number}[];pools:{id:string;name:string}[]}>('/model-center');setSelection(center.selected.type+':'+center.selected.id);setOptions([...center.connections.map(row=>({value:(row.id==='legacy-default'?'legacy':'connection')+':'+row.id,name:row.name+' · '+row.contextLimit.toLocaleString()+' 上下文'})),...center.pools.map(row=>({value:'pool:'+row.id,name:row.name+' · 按成员最小容量'}))]);}catch(cause){setError((cause as Error).message);}}
|
||||
async function preview(){setBusy(true);setError('');setPlan(null);try{const [type,id]=selection.split(':');const value=await api<Preview>('/sessions/'+session.id+'/resume-preview',{...fields,...(selection?{selection:{type,id}}:{})});setPlan(value);onSession(await api<Session>('/sessions/'+session.id));}catch(cause){setError((cause as Error).message);}finally{setBusy(false);}}
|
||||
async function confirm(){if(!plan)return;setBusy(true);setError('');try{onSession(await api<Session>('/sessions/'+session.id+'/resume-budget',{planId:plan.id,sha256:plan.sha256}));setOpen(false);}catch(cause){setError((cause as Error).message);}finally{setBusy(false);}}
|
||||
return <aside className="budget-pause" aria-label="任务预算诊断"><h3>{reasons[reason]}</h3>{pause?.requiredInputTokens!==undefined?<><p>完整要求与必需输入估算 <strong>{pause.requiredInputTokens.toLocaleString()}</strong> tokens;当前可用输入 <strong>{pause.inputBudget?.toLocaleString()}</strong>。请求已暂停,原任务和工具结果保留。</p><dl className="budget-facts">{Object.entries(pause.breakdown??{}).map(([key,value])=><div key={key} style={{display:'contents'}}><dt>{labels[key]??key}</dt><dd>{value.toLocaleString()}</dd></div>)}<dt>所选上下文窗口</dt><dd>{pause.contextLimit?.toLocaleString()}</dd><dt>响应预留 / 安全余量</dt><dd>{pause.outputReservation?.toLocaleString()} / {pause.safetyTokens?.toLocaleString()}</dd><dt>运行 / 任务剩余</dt><dd>{pause.runRemainingTokens?.toLocaleString()??'不限'} / {pause.taskRemainingTokens?.toLocaleString()??'不限'}</dd></dl></>:<p>原 Task 已保存。可核对剩余预算和模型容量,再准备同一任务的新 Run;旧记录没有的预算分解不补造。</p>}
|
||||
return <aside className="budget-pause" aria-label="任务预算诊断"><h3>{diagnosis.title}</h3>{pause?.requiredInputTokens!==undefined?<><p>完整要求与必需输入估算 <strong>{pause.requiredInputTokens.toLocaleString()}</strong> tokens;{diagnosis.inputLabel} <strong>{pause.inputBudget?.toLocaleString()}</strong>。请求已暂停,原任务和工具结果保留。</p><dl className="budget-facts">{Object.entries(pause.breakdown??{}).map(([key,value])=><div key={key} style={{display:'contents'}}><dt>{labels[key]??key}</dt><dd>{value.toLocaleString()}</dd></div>)}<dt>所选上下文窗口</dt><dd>{pause.contextLimit?.toLocaleString()}</dd><dt>响应预留 / 安全余量</dt><dd>{pause.outputReservation?.toLocaleString()} / {pause.safetyTokens?.toLocaleString()}</dd><dt>运行 / 任务剩余</dt><dd>{pause.runRemainingTokens?.toLocaleString()??'不限'} / {pause.taskRemainingTokens?.toLocaleString()??'不限'}</dd></dl></>:<p>原 Task 已保存。可核对剩余预算和模型容量,再准备同一任务的新 Run;旧记录没有的预算分解不补造。</p>}
|
||||
{diagnosis.guidance&&<p>{diagnosis.guidance}</p>}
|
||||
{pause?.originalInputTokens!==undefined&&<p>原生完整历史估算 {pause.originalInputTokens.toLocaleString()} tokens。原始输入、历史索引与拒绝正文已保存为任务工件,本次拒绝没有发送模型请求。</p>}
|
||||
{!!pause?.transportReservationTokens&&<p>准备原生任务时另留 {pause.transportReservationTokens.toLocaleString()} tokens 给引擎提示和消息封装;实际原生请求仍单独核对容量。</p>}
|
||||
{!!pause?.imageReservationTokens&&<p>图像使用单独的本地预留,属于容量估算;实际计费与服务报告用量分列。</p>}
|
||||
|
||||
@@ -18,6 +18,7 @@ import { FileResultsPanel } from './FileResultsPanel';
|
||||
const stopReasons: Record<string, string> = { no_progress: '重复读取未推进任务,请核对后继续', context_limit: '完整任务要求超过请求上下文预算', time_limit: '到达运行时间预算', token_limit: '到达本次 token 预算', task_token_limit: '到达任务累计预算', step_limit: '到达工具轮次上限', cancelled: '用户停止', model_error: '模型请求失败', interrupted: '进程中断' };
|
||||
const number = (value: number | undefined) => (value ?? 0).toLocaleString('zh-CN');
|
||||
stopReasons.git_review = 'Git预览已保存,等待审查与确认';
|
||||
stopReasons.change_set_review = '完整文件批次已封存,等待审查与应用';
|
||||
stopReasons.git_review_declined = 'Git预览已撤回,文件和检查记录保留';
|
||||
stopReasons.task_plan_incomplete = '执行计划仍有未核验或失效步骤,请核对后继续';
|
||||
stopReasons.diagnostic_answered = '诊断答复已完成;原任务的目标与交付状态保持';
|
||||
|
||||
@@ -47,6 +47,7 @@ export interface InputAttachment { id:string;name:string;status:string;mediaType
|
||||
export interface BudgetPause { reason:string;requiredInputTokens?:number;contextLimit?:number;inputBudget?:number;outputReservation?:number;safetyTokens?:number;runRemainingTokens?:number|null;taskRemainingTokens?:number|null;imageReservationTokens?:number;breakdown?:Record<string,number> }
|
||||
export interface Run { budgetPause?:BudgetPause }
|
||||
export interface BudgetPause { originalInputTokens?:number;transportReservationTokens?:number }
|
||||
export interface BudgetPause { limitingReason?:string }
|
||||
export interface BudgetPause { modelFailure?:RuntimeFailure }
|
||||
export interface TokenBudgetCounter { maximumTokens:number;reportedTokens:number;unknownRequests:number;estimatedUnknownTokens:number;accountedTokens:number;remainingTokens:number|null;exceededTokens:number }
|
||||
export interface BudgetPause { remainingTokens?:number;tokenReservation?:{schemaVersion:number;reservedTokens:number;routes:{sources:{runId:string;attemptId:string}[]}[]};tokenAccounting?:{schemaVersion:number;singleInFlightResponseMayExceed:boolean;run:TokenBudgetCounter;task:TokenBudgetCounter} }
|
||||
|
||||
@@ -181,6 +181,7 @@ export class RequestPlanner {
|
||||
let omitted = [], reference = null, workingReference = null, latestReference = null;
|
||||
const latestDocument = latestToolDocument(this.store, session, run, groups);
|
||||
const entries = [];
|
||||
let retainedSources = [];
|
||||
const metricsFor = (indices, includeNotice = true, currentEntries = entries, includeLatest = true) => {
|
||||
const missing = groups.filter(group => !indices.has(group.index));
|
||||
const messages = [fixed, ...(missing.length && includeNotice ? [notice({ id: PLACEHOLDER_ID, sha256: PLACEHOLDER_SHA }, missing, descriptions, evidence)] : []),
|
||||
@@ -194,22 +195,25 @@ export class RequestPlanner {
|
||||
const mandatory = metricsFor(selected);
|
||||
if (mandatory.estimatedInputTokens > budget.inputBudget) throw pause(budget, mandatory, breakdown);
|
||||
const observed = workingCandidates(this.store, session, run, groups);
|
||||
// Reserve other small source files before admitting a new result group.
|
||||
// Historical locator pages are optional; they cannot evict actual code.
|
||||
// Admit complete small source observations before optional raw history.
|
||||
// A reservation alone does not keep code in the actual sent request.
|
||||
const newest = groups.at(-1);
|
||||
const newestFiles = new Set((newest?.messages[0].tool_calls ?? []).filter(call => call.function.name === 'read_file').map(call => {
|
||||
try { return JSON.parse(call.function.arguments).path; } catch { return null; }
|
||||
}));
|
||||
const pinned = observed.filter(candidate => candidate.observation.kind === 'file' && candidate.observation.content.length <= 2000
|
||||
&& !newestFiles.has(candidate.observation.path)).slice(0, 12).map(candidate => workingEntry(candidate, candidate.observation.content.length));
|
||||
const retention = Math.min(2048, Math.max(0, metricsFor(selected, true, pinned).estimatedInputTokens - mandatory.estimatedInputTokens));
|
||||
const retentionTarget = budget.inputBudget;
|
||||
for (const candidate of observed.filter(candidate => candidate.observation.kind === 'file' && candidate.observation.content.length <= 2000)) {
|
||||
if (entries.length >= 12) break;
|
||||
const entry = workingEntry(candidate, candidate.observation.content.length);
|
||||
if (metricsFor(selected, true, [...entries, entry]).estimatedInputTokens <= retentionTarget) entries.push(entry);
|
||||
}
|
||||
retainedSources = [...entries];
|
||||
const newestUseful = newest?.messages.every(message => {
|
||||
if (message.role !== 'tool') return true;
|
||||
try { const result = JSON.parse(message.content); return !result.kind?.startsWith('context-') && result.kind !== 'tool-result'; } catch { return true; }
|
||||
});
|
||||
if (newestUseful && !selected.has(newest.index) && newest.contributionTokens <= budget.inputBudget) {
|
||||
selected.add(newest.index);
|
||||
if (metricsFor(selected).estimatedInputTokens + retention > budget.inputBudget) selected.delete(newest.index);
|
||||
const remaining = entries.filter(entry => entry.source.group_index !== newest.index);
|
||||
if (metricsFor(selected, true, remaining).estimatedInputTokens > budget.inputBudget) selected.delete(newest.index);
|
||||
else entries.splice(0, entries.length, ...remaining);
|
||||
}
|
||||
const target = Math.max(budget.targetInputTokens, metricsFor(selected).estimatedInputTokens);
|
||||
const priority = [...new Set(evidence.map(value => value.group_index))].map(index => groups[index]);
|
||||
@@ -220,7 +224,8 @@ export class RequestPlanner {
|
||||
};
|
||||
// A small result in a mixed large group must remain usable. It is a
|
||||
// separate, provenance-checked observation, never a broken tool pair.
|
||||
const candidates = observed.filter(candidate => !selected.has(candidate.source.group_index));
|
||||
const candidates = observed.filter(candidate => !selected.has(candidate.source.group_index)
|
||||
&& !entries.some(entry => entry.source.call_id === candidate.source.call_id));
|
||||
for (const [index, candidate] of candidates.entries()) {
|
||||
if (entries.length >= 12) break;
|
||||
const remaining = target - metricsFor(selected).estimatedInputTokens;
|
||||
@@ -325,9 +330,9 @@ export class RequestPlanner {
|
||||
// The next result replaces the current latest-result feedback. Do not
|
||||
// reserve both views when sizing that result's actual protocol page.
|
||||
nextReadFixedInputTokens: metricsFor(new Set(lastUser ? [lastUser.index] : []), true, [], false).estimatedInputTokens,
|
||||
workingRetentionTokens: Math.min(2048, Math.max(0, metricsFor(new Set(lastUser ? [lastUser.index] : []), true,
|
||||
entries.filter(entry => entry.observation.kind === 'file' && !entry.truncated && entry.total_content_characters <= 2000)).estimatedInputTokens
|
||||
- metricsFor(new Set(lastUser ? [lastUser.index] : []), true, []).estimatedInputTokens)),
|
||||
workingRetentionTokens: Math.max(0, metricsFor(new Set(lastUser ? [lastUser.index] : []), true, retainedSources).estimatedInputTokens
|
||||
- metricsFor(new Set(lastUser ? [lastUser.index] : []), true, []).estimatedInputTokens),
|
||||
workingRetentionPolicyVersion: 1,
|
||||
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),
|
||||
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,
|
||||
@@ -400,7 +405,8 @@ export function verifyPlanEvidence(store, session, plan, cache = new Map()) {
|
||||
|| (frozen.workingSetSha256 ?? null) !== (plan.workingSetSha256 ?? null)
|
||||
|| (frozen.workingSetEntries ?? 0) !== (plan.workingSetEntries ?? 0)) throw new Error('工作依据与发送前的封存记录不匹配。');
|
||||
if ((frozen.workingSetViewVersion ?? 1) !== (plan.workingSetViewVersion ?? 1)
|
||||
|| (frozen.workingRetentionTokens ?? 0) !== (plan.workingRetentionTokens ?? 0)) throw new Error('工作依据视图或保留预算与封存记录不匹配。');
|
||||
|| (frozen.workingRetentionTokens ?? 0) !== (plan.workingRetentionTokens ?? 0)
|
||||
|| (frozen.workingRetentionPolicyVersion ?? 0) !== (plan.workingRetentionPolicyVersion ?? 0)) throw new Error('工作依据视图或保留预算与封存记录不匹配。');
|
||||
if ((frozen.nextReadFixedInputTokens ?? null) !== (plan.nextReadFixedInputTokens ?? null)) throw new Error('下一工具页的固定预算与封存记录不匹配。');
|
||||
if ((frozen.latestToolsArtifactId ?? null) !== (plan.latestToolsArtifactId ?? null)
|
||||
|| (frozen.latestToolsSha256 ?? null) !== (plan.latestToolsSha256 ?? null)
|
||||
|
||||
@@ -81,7 +81,8 @@ export function workingCandidates(store, session, run, groups) {
|
||||
}
|
||||
// Keep complete small modules/requirements before larger evidence excerpts.
|
||||
// Every selected page still identifies the exact invocation that read it.
|
||||
primary.sort((a, b) => Number(a.observation.content.length > 2000) - Number(b.observation.content.length > 2000));
|
||||
primary.sort((a, b) => Number(a.observation.content.length > 2000) - Number(b.observation.content.length > 2000)
|
||||
|| a.observation.content.length - b.observation.content.length || a.observation.path.localeCompare(b.observation.path));
|
||||
const checks = candidates.filter(candidate => ['check-results', 'command-result'].includes(candidate.observation.kind));
|
||||
const artifacts = candidates.filter(candidate => candidate.observation.kind === 'artifact-page');
|
||||
return [...primary, ...checks, ...artifacts, ...secondary].slice(0, 24);
|
||||
|
||||
@@ -226,7 +226,9 @@ class EngineRunDriver {
|
||||
const rejected=this.store.artifactStore.write(this.session,this.run.record,
|
||||
JSON.parse(this.provider.redact(JSON.stringify({schemaVersion:1,owner,view,body,budget:contextBudget,dispatched:false}))),{kind:'engine-model-rejection'});
|
||||
this.store.core.artifact.set(rejected.id,rejected);(this.job.inputRejections??=[]).push({artifactId:rejected.id,sha256:rejected.sha256,...contextBudget});this.save('input_rejected');
|
||||
const error=new BudgetExceeded('engine_input_budget','原引擎必需目标、最新结果或剩余尝试超出封存预算,未发送模型请求。原输入和容量分项已保存;请核对上下文/预算后显式继续。');
|
||||
const error=new BudgetExceeded('engine_input_budget',contextBudget.limitingReason==='context_limit'
|
||||
?'原引擎必需输入超过上下文窗口可用容量,未发送模型请求。原输入和容量分项已保存;请核对模型容量后显式继续。'
|
||||
:'原引擎输入可容纳于上下文窗口,但下一次请求的用量预留超过剩余预算,未发送模型请求。原输入和容量分项已保存;请核对运行和任务预算后显式继续。');
|
||||
error.contextBudget={...contextBudget,rejectionArtifactId:rejected.id,rejectionSha256:rejected.sha256};throw error;
|
||||
}
|
||||
const selected = config.modelRouting ? { ...config, modelRouting: { ...config.modelRouting, maxAttempts: attempts } } : config;
|
||||
|
||||
@@ -130,6 +130,23 @@ export class ChangeSetManager {
|
||||
for (let index = 0; index < set.files.length; index++) set.files[index].state = observations[index].state;
|
||||
return observations;
|
||||
}
|
||||
async reviewReady(session, id, run) {
|
||||
const set = this.own(session, id, null, { current: true });
|
||||
if (session.runId !== run.id || session.taskId !== run.taskId || set.status !== 'prepared' || set.attemptedAt) return false;
|
||||
const pending = session.changes.filter(change => change.taskId === run.taskId && ['pending', 'conflict'].includes(change.status));
|
||||
if (pending.length !== set.files.length || pending.some(change => change.status !== 'pending'
|
||||
|| !set.files.some(file => file.changeId === change.id))) return false;
|
||||
if ([...this.store.core.tool.values()].some(tool => tool.sessionId === session.id && tool.taskId === run.taskId && tool.requiresVerification)) return false;
|
||||
assertMcpResolved(this.store, session.projectId);
|
||||
assertWorkersResolved(this.store, session.projectId);
|
||||
this.snapshots(session, set, { pending: true });
|
||||
const project = this.store.project(session.projectId);
|
||||
await verifyWorkspaceProject(this.store, project);
|
||||
const inspection = await inspectProject(project);
|
||||
return session.runId === run.id && session.taskId === run.taskId && set.status === 'prepared'
|
||||
&& JSON.stringify(gitBaseline(inspection)) === JSON.stringify(set.baseline)
|
||||
&& this.inspect(session, set).every(value => value.state === 'before');
|
||||
}
|
||||
async prepare(session, changeIds, { source = 'user', collaborationBinding = null } = {}) {
|
||||
if (!Array.isArray(changeIds) || !changeIds.length || changeIds.length > 32 || new Set(changeIds).size !== changeIds.length) throw conflict('变更集需要1到32个不同的提案ID。');
|
||||
this.requireIdle(session, { source });
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { randomUUID, createHash } from 'node:crypto';
|
||||
|
||||
export const APP_VERSION = '1.24.0';
|
||||
export const APP_VERSION = '1.24.1';
|
||||
|
||||
export function executionEnvironment() {
|
||||
const windows = process.platform === 'win32';
|
||||
|
||||
@@ -498,6 +498,7 @@ export class Runtime {
|
||||
this.store.save(session); return;
|
||||
}
|
||||
let deliveryReview = null, mcpReview = null;
|
||||
const preparedSets = new Set();
|
||||
for (const call of calls) {
|
||||
let result;
|
||||
if (deliveryReview || mcpReview) {
|
||||
@@ -513,6 +514,7 @@ export class Runtime {
|
||||
else if (signal.aborted) result = { status: 'interrupted', message: '用户停止了任务,这次调用没有执行。' };
|
||||
else result = await this.executeTool(session, call, run);
|
||||
session.providerMessages.push({ role: 'tool', tool_call_id: call.id, content: JSON.stringify(result) });
|
||||
if (call.function.name === 'prepare_change_set' && result.status === 'awaiting_review') preparedSets.add(result.change_set_id);
|
||||
if (call.function.name === 'call_registered_mcp' && result.requires_verification) mcpReview = result.mcp_job_id;
|
||||
if (call.function.name === 'plan_delivery' && result.status === 'awaiting_review') {
|
||||
deliveryReview = this.store.owned('delivery_plan', result.plan_id, session.id);
|
||||
@@ -534,6 +536,22 @@ export class Runtime {
|
||||
this.store.save(session, { type: 'delivery.awaiting_review', detail: { planId: deliveryReview.id } });
|
||||
return;
|
||||
}
|
||||
// Settle the whole model turn first: later proposals can make a sealed
|
||||
// set partial, and later tools may fail or need verification/stop.
|
||||
for (const id of preparedSets) {
|
||||
let ready = false;
|
||||
try { ready = await this.changeSetManager().reviewReady(session, id, run.record); }
|
||||
catch (error) {
|
||||
this.store.event(session, { kind: 'system', source: 'workbench', label: '变更批次交接预检未通过', phase: 'failed',
|
||||
output: this.provider.redact(error.message ?? String(error)) });
|
||||
}
|
||||
signal.throwIfAborted();
|
||||
if (!ready) continue;
|
||||
session.status = 'needs_review'; run.stopReason = 'change_set_review';
|
||||
this.store.message(session, 'system', '当前任务的完整变更批次已封存,同轮工具结果已保存。请审查并应用或撤销批次;等待审查期间不继续请求模型。应用后可显式续接原任务进行检查。');
|
||||
this.store.save(session, { type: 'change_set.awaiting_review', detail: { changeSetId: id } });
|
||||
return;
|
||||
}
|
||||
if (this.store.core.task.get(run.taskId).readProgress?.pause) throw new BudgetExceeded('no_progress',
|
||||
'模型连续重复读取工件或核对相同的工程状态,未推进当前任务。实际结果和原任务已保存,请核对后继续。');
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
export interface BudgetPauseSource { reason?: string; limitingReason?: string }
|
||||
export function budgetPausePresentation(pause?: BudgetPauseSource, stopReason?: string): {
|
||||
title: string; inputLabel: string; guidance: string;
|
||||
} | null;
|
||||
@@ -0,0 +1,18 @@
|
||||
const reasons = {
|
||||
context_limit: '上下文窗口不足', engine_input_budget: '原生引擎输入或剩余预算不足',
|
||||
token_limit: '本次运行预算不足', task_token_limit: '任务累计预算不足', time_limit: '本次运行时间已用完',
|
||||
};
|
||||
|
||||
export function budgetPausePresentation(pause, stopReason = '') {
|
||||
const reason = pause?.reason ?? stopReason;
|
||||
if (!reasons[reason]) return null;
|
||||
if (reason === 'engine_input_budget' && pause?.limitingReason === 'remaining_token_budget') return {
|
||||
title: '原生引擎剩余预算不足', inputLabel: '当前窗口可用输入',
|
||||
guidance: '输入可容纳于当前上下文窗口;下一次请求的用量预留超过剩余预算。请核对运行和任务预算。',
|
||||
};
|
||||
if (reason === 'engine_input_budget' && pause?.limitingReason === 'context_limit') return {
|
||||
title: '原生引擎上下文窗口不足', inputLabel: '当前窗口可用输入',
|
||||
guidance: '必需输入超过当前上下文窗口可用容量。请核对模型容量和输入范围。',
|
||||
};
|
||||
return { title: reasons[reason], inputLabel: '当前可用输入', guidance: '' };
|
||||
}
|
||||
Reference in New Issue
Block a user