feat(memory): release Mnemo project bridge and schema2 recovery
Official contracts and Windows source CI / windows-source (push) Has been cancelled
Official contracts and Windows source CI / windows-source (push) Has been cancelled
This commit is contained in:
+27
-6
@@ -59,6 +59,7 @@ import { currentBrowserVerification } from '../core/browser/browser-manager.mjs'
|
||||
import { taskPlanInput, taskProofInput, PLAN_READ_TOOLS } from '../shared/contracts/task-plans.mjs';
|
||||
import { taskPlanToolDefinitions } from '../shared/contracts/task-plan-tools.mjs';
|
||||
import { ProjectMemoryManager } from '../core/memory/project-memory.mjs';
|
||||
import { MnemoBridge } from '../core/memory/mnemo-bridge.mjs';
|
||||
import { TaskCheckpointManager } from '../core/tasks/task-checkpoint-manager.mjs';
|
||||
import { SkillRegistry, skillToolDefinitions, skillReadInput } from '../core/skills/skill-registry.mjs';
|
||||
import { McpRegistry } from '../core/tools/mcp-registry.mjs';
|
||||
@@ -236,6 +237,7 @@ export class Runtime {
|
||||
resumeBudget(id,input){const session=this.store.session(id),plan=this.budgetResumes().verify(session,input);return this.start(id,'',true,{resumePlan:plan});}
|
||||
engineRunner() { return this.controlledEngines ??= new EngineRunner(this.store, this.provider, { appDirectory: this.appDirectory }); }
|
||||
memoryManager() { return this.projectMemories ??= new ProjectMemoryManager(this.store, { redact: value => this.provider.redact(value) }); }
|
||||
mnemoBridge() { return this.mnemoMemories ??= new MnemoBridge(this.store, { memories: this.memoryManager() }); }
|
||||
checkpointManager() { return this.taskCheckpoints ??= new TaskCheckpointManager(this.store, {
|
||||
taskPlans: this.taskPlanner(), redact: value => this.provider.redact(value) }); }
|
||||
skillRegistry() { return this.skills ??= new SkillRegistry(this.store, {
|
||||
@@ -495,14 +497,17 @@ export class Runtime {
|
||||
purpose: run.record.purpose ?? 'execution', workerId: run.worker?.id ?? null },
|
||||
reason: name => run.worker && !unrestricted(config) && !WORKER_TOOLS.has(name) ? 'disabled_by_worker_contract'
|
||||
: !taskToolAllowed(task, run.record, name) ? 'disabled_by_task_contract' : 'disabled_by_execution_mode' });
|
||||
const projectMemory = await this.memoryManager().context(session, { redact: value => this.provider.redact(value) });
|
||||
let projectMemory = await this.memoryManager().context(session, { redact: value => this.provider.redact(value) });
|
||||
const lastInput = providerHistory(session, run.record).findLast(message => message.role === 'user')?.content;
|
||||
let mnemoMemory = config.mode === 'compatible' && !run.worker?.engine
|
||||
? await this.mnemoBridge().context(session, (typeof lastInput === 'string' ? lastInput : JSON.stringify(lastInput ?? '当前项目')).slice(0, 4000) || '当前项目') : null;
|
||||
signal.throwIfAborted();
|
||||
let reminder = config.mode === 'compatible' && !run.worker && (config.capacityMode === 'passthrough' || config.historyPolicy === 'preserve')
|
||||
? this.reminderManager().prepare(session, run.record, toolSurface) : null;
|
||||
const prepare = selected => this.requestPlanner().prepare(session, run.record, permissionConfig, {
|
||||
system: stablePrefix ? this.provider.redact(fixedContext) : context + (selected ? '\n' + selected.message.content : ''),
|
||||
contextTail: stablePrefix ? context + (selected ? '\n' + selected.message.content : '') : null,
|
||||
progressReminder: selected?.ref ?? null, tools, toolSurface, stepId: stepRecord.id, projectMemory, skillCatalog, mcpCatalog,
|
||||
progressReminder: selected?.ref ?? null, tools, toolSurface, stepId: stepRecord.id, projectMemory, mnemoMemory, skillCatalog, mcpCatalog,
|
||||
transportReservationTokens: run.worker?.engine ? ENGINE_SEED_RESERVATION : 0, engineStepOnly: !!run.worker?.engine });
|
||||
let planned;
|
||||
try { planned = prepare(reminder); }
|
||||
@@ -530,6 +535,7 @@ export class Runtime {
|
||||
requestStarted = true;
|
||||
const progressHandler = progress => {
|
||||
if (progress.consumption) {
|
||||
this.mnemoMemories?.observePhysical(session, planned.record, progress.consumption);
|
||||
finalAttemptUsage = progress.consumption.usage ?? null;
|
||||
this.store.recordConsumption(session, run.record, { ...progress.consumption, requestId: planned.record.id }, planned.record.tokenReservation?.reservedTokens??planned.record.estimatedInputTokens + config.maxOutputTokens);
|
||||
responseAccounted = true;
|
||||
@@ -574,12 +580,27 @@ export class Runtime {
|
||||
this.store.save(session);
|
||||
};
|
||||
const requestConfig=config.modelRouting&&!externalEngine?{...config,modelRouting:{...config.modelRouting,maxAttempts:Math.min(config.modelRouting.maxAttempts,planned.record.maxBudgetAttempts)}}:config;
|
||||
const dispatchModel = () => this.provider.complete(requestConfig, planned.messages, run.project, signal, progressHandler, planned.record, tools,
|
||||
{ ...(config.mode === 'demo' ? { demoHistory: providerHistory(session, run.record) } : {}),
|
||||
onSubmitted: submission => {
|
||||
try { this.mnemoMemories?.submitted(session, planned.record, submission); }
|
||||
finally { if (reminder) this.reminderManager().dispatch(session, run.record, planned.record, submission); }
|
||||
},
|
||||
...(planned.record.mnemoMemoryArtifactId ? { beforePhysicalDispatch: ({ attemptId }) => this.mnemoBridge().beforePhysical(session, run.record, planned.record, attemptId) } : {}),
|
||||
maxBudgetAttempts: planned.record.maxBudgetAttempts, beforeDispatch: ({ previousFailure } = {}) => checkModelDispatchBudget(this.store, session, run.record, requestConfig, planned.body, 0, previousFailure) });
|
||||
response = externalEngine
|
||||
? await this.engineRunner().complete(session, run, planned.messages, progressHandler, planned.record, tools)
|
||||
: await this.provider.complete(requestConfig, planned.messages, run.project, signal, progressHandler, planned.record, tools,
|
||||
{ ...(config.mode === 'demo' ? { demoHistory: providerHistory(session, run.record) } : {}),
|
||||
...(reminder ? { onSubmitted: submission => this.reminderManager().dispatch(session, run.record, planned.record, submission) } : {}),
|
||||
maxBudgetAttempts:planned.record.maxBudgetAttempts,beforeDispatch:({previousFailure}={})=>checkModelDispatchBudget(this.store,session,run.record,requestConfig,planned.body,0,previousFailure)});
|
||||
: await dispatchModel().catch(async cause => {
|
||||
if (cause.code !== 'PROJECT_SELECTION_STALE' || !planned.record.mnemoMemoryArtifactId) throw cause;
|
||||
const previousPlan = planned.record;
|
||||
this.requestPlanner().finish(session, previousPlan, { error: cause, attempts: previousPlan.requestAttempts });
|
||||
mnemoMemory = { schemaVersion: 1, kind: 'mnemo-authorized-project-memory', projectId: session.projectId, entries: [], omittedPlanId: previousPlan.id,
|
||||
issue: { code: cause.code, message: cause.message } };
|
||||
if (requestEvent) { requestEvent.phase = 'interrupted'; requestEvent.finishedAt = now(); requestEvent.output = cause.message; this.store.save(session); requestEvent = null; }
|
||||
projectMemory = await this.memoryManager().context(session, { redact: value => this.provider.redact(value) });
|
||||
planned = prepare(reminder);
|
||||
return dispatchModel();
|
||||
});
|
||||
if (response.compatibility?.length && requestEvent) { requestEvent.compatibility = response.compatibility; this.store.save(session); }
|
||||
this.requestPlanner().finish(session, planned.record, { response, attempts: planned.record.requestAttempts });
|
||||
if (run.worker && !externalEngine && !responseAccounted) {
|
||||
|
||||
Reference in New Issue
Block a user