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:
@@ -165,6 +165,18 @@ return async (request, response) => {
|
||||
if (method === 'POST') { if (workerForProject(store, projectId)) throw workerConflict('受限子项目不能修改MCP登记,请返回父项目。'); const input = await body(request);
|
||||
return json(response, mcpMatch[2] ? registry.configure(projectId, input) : registry.register(projectId, input), mcpMatch[2] ? 200 : 201); }
|
||||
}
|
||||
const mnemoBridgeMatch = route.match(/^\/api\/projects\/([a-f0-9-]+)\/memory-bridge(?:\/(configure|sources|lookup)(?:\/([a-f0-9-]+))?)?$/i);
|
||||
if (mnemoBridgeMatch) {
|
||||
const projectId = mnemoBridgeMatch[1], bridge = runtime.mnemoBridge();
|
||||
if (method === 'GET' && !mnemoBridgeMatch[2]) return json(response, await bridge.view(projectId));
|
||||
if (method === 'POST') {
|
||||
if (workerForProject(store, projectId)) throw workerConflict('请从来源项目管理可选记忆桥。');
|
||||
const input = await body(request);
|
||||
if (mnemoBridgeMatch[2] === 'configure' && !mnemoBridgeMatch[3]) return json(response, await bridge.configure(projectId, input));
|
||||
if (mnemoBridgeMatch[2] === 'lookup') { if (typeof input.memoryId !== 'string' || Object.keys(input).length !== 1) throw new Error('需要原来源ID。'); return json(response, await bridge.lookupSource(projectId, input.memoryId)); }
|
||||
if (mnemoBridgeMatch[2] === 'sources' && mnemoBridgeMatch[3]) return json(response, await bridge.changeSource(projectId, mnemoBridgeMatch[3], input));
|
||||
}
|
||||
}
|
||||
const projectMemoryMatch = route.match(/^\/api\/projects\/([a-f0-9-]+)\/memories$/i);
|
||||
if (projectMemoryMatch && method === 'GET') {
|
||||
const includeExpired = url.searchParams.get('include_expired') !== '0';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { randomUUID, createHash } from 'node:crypto';
|
||||
|
||||
export const APP_VERSION = '1.25.12';
|
||||
export const APP_VERSION = '1.25.13';
|
||||
|
||||
export function executionEnvironment() {
|
||||
const windows = process.platform === 'win32';
|
||||
|
||||
+73
-33
@@ -13,6 +13,18 @@ import { hostAuthority } from '../core/desktop/host-authority.mjs';
|
||||
import { CredentialVault } from '../core/models/credential-vault.mjs';
|
||||
import { NetworkDiagnostics } from '../core/models/network-diagnostics.mjs';
|
||||
import { StateDatabase } from '../core/storage/state-database.mjs';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { ownedChild } from '../core/desktop/file-state.mjs';
|
||||
|
||||
// Only the installing bundle owns this synchronous undo closure. Its ledger
|
||||
// guard refuses any new/changed outcome before restoring the previous objects.
|
||||
export function rollbackUnchangedUpgrade(context, { appDirectory } = {}) {
|
||||
const adoption = context.server?.workbenchLedgerAdoption;
|
||||
if (!adoption || adoption.root !== fs.realpathSync.native(path.resolve(appDirectory))
|
||||
|| adoption.store !== context.store || adoption.provider !== context.provider || adoption.runtime !== context.runtime) throw new Error('No source-bound unchanged ledger adoption is available for rollback.');
|
||||
adoption.restore();
|
||||
return { restored: true, newRequestsDispatched: false };
|
||||
}
|
||||
|
||||
// Keep the existing objects and their in-memory connection. No credential is
|
||||
// extracted, transferred, returned, or persisted by this operation.
|
||||
@@ -30,7 +42,11 @@ export function installUpgrade(context, { appDirectory, updateServiceInfo = true
|
||||
const root = fs.realpathSync.native(path.resolve(appDirectory));
|
||||
if (!fs.existsSync(path.join(root, 'dist-client', 'index.html'))) throw new Error('The new client bundle is missing.');
|
||||
const oldHandlers = server.listeners('request');
|
||||
const serviceInfoFile = ownedChild(store.directory, 'service-info.json', { missing: true });
|
||||
const originalServiceInfo = fs.existsSync(serviceInfoFile) ? fs.readFileSync(serviceInfoFile) : null;
|
||||
let publishedServiceInfo = null;
|
||||
const oldCompanion = server.workbenchCompanion;
|
||||
const oldLedgerAdoption = server.workbenchLedgerAdoption;
|
||||
const oldAuthority = server.workbenchHostAuthority, oldAuthorityProperties = oldAuthority ? { ...oldAuthority } : null;
|
||||
const oldAuthorityPrototype = oldAuthority ? Object.getPrototypeOf(oldAuthority) : null;
|
||||
const oldPrototypes = [Object.getPrototypeOf(store), Object.getPrototypeOf(provider), Object.getPrototypeOf(runtime)];
|
||||
@@ -41,9 +57,10 @@ export function installUpgrade(context, { appDirectory, updateServiceInfo = true
|
||||
network: provider.hub?.networkChecks ? Object.getPrototypeOf(provider.hub.networkChecks) : null,
|
||||
catalog: provider.hub?.catalog ? Object.getPrototypeOf(provider.hub.catalog) : null };
|
||||
const oldStoreProperties = { ...store };
|
||||
const oldHubProperties = provider.hub ? { ...provider.hub } : null, oldStoragePrototype = store.storage ? Object.getPrototypeOf(store.storage) : null;
|
||||
const oldHubProperties = provider.hub ? { ...provider.hub } : null, oldHubDescriptors = provider.hub ? Object.getOwnPropertyDescriptors(provider.hub) : null;
|
||||
const oldStoragePrototype = store.storage ? Object.getPrototypeOf(store.storage) : null;
|
||||
let initializedLedger = null;
|
||||
const oldRuntimeProperties = { filePreviews: runtime.filePreviews, browsing: runtime.browsing, previews: runtime.previews, evaluations:runtime.evaluations, environments: runtime.environments, appDirectory: runtime.appDirectory, workers: runtime.workers, controlledEngines: runtime.controlledEngines, checks: runtime.checks, deliveries: runtime.deliveries, codeIndex: runtime.codeIndex, changeSets: runtime.changeSets, contextPlans: runtime.contextPlans, workspaces: runtime.workspaces, research: runtime.research, engines: runtime.engines, browser: runtime.browser, taskPlans: runtime.taskPlans, projectMemories: runtime.projectMemories, taskCheckpoints: runtime.taskCheckpoints, skills: runtime.skills, mcp: runtime.mcp };
|
||||
const oldRuntimeProperties = { results: runtime.results, filePreviews: runtime.filePreviews, browsing: runtime.browsing, previews: runtime.previews, evaluations:runtime.evaluations, environments: runtime.environments, appDirectory: runtime.appDirectory, workers: runtime.workers, controlledEngines: runtime.controlledEngines, checks: runtime.checks, deliveries: runtime.deliveries, codeIndex: runtime.codeIndex, changeSets: runtime.changeSets, contextPlans: runtime.contextPlans, workspaces: runtime.workspaces, research: runtime.research, engines: runtime.engines, browser: runtime.browser, taskPlans: runtime.taskPlans, projectMemories: runtime.projectMemories, taskCheckpoints: runtime.taskCheckpoints, skills: runtime.skills, mcp: runtime.mcp };
|
||||
const oldUpdates = store.listeners('update');
|
||||
const oldInputs = runtime.inputs;
|
||||
const oldResumes = runtime.resumes;
|
||||
@@ -51,6 +68,55 @@ export function installUpgrade(context, { appDirectory, updateServiceInfo = true
|
||||
if (oldUpdates.length > 1) throw new Error('Unexpected Store observers; preserve their ownership before upgrading.');
|
||||
const handler = createRequestHandler({ appDirectory: root, server, store, provider, runtime, token, clients, started,
|
||||
exampleProject, shutdown, getPort: () => server.address().port });
|
||||
const restoreOriginal = () => {
|
||||
const readServiceInfo = () => fs.existsSync(serviceInfoFile) ? fs.readFileSync(ownedChild(store.directory, 'service-info.json')) : null;
|
||||
const expectedServiceInfo = publishedServiceInfo ?? originalServiceInfo;
|
||||
const currentServiceInfo = readServiceInfo();
|
||||
if (expectedServiceInfo ? !currentServiceInfo?.equals(expectedServiceInfo) : currentServiceInfo !== null) throw new Error('The host index changed outside this adoption; preserve its current bytes before rollback.');
|
||||
initializedLedger?.rollbackInitialization();
|
||||
if (oldCompanion) server.workbenchCompanion = oldCompanion; else delete server.workbenchCompanion;
|
||||
if (oldLedgerAdoption) server.workbenchLedgerAdoption = oldLedgerAdoption; else delete server.workbenchLedgerAdoption;
|
||||
if (oldAuthority) {
|
||||
for (const key of Object.keys(oldAuthority)) if (!Object.hasOwn(oldAuthorityProperties, key)) delete oldAuthority[key];
|
||||
Object.assign(oldAuthority, oldAuthorityProperties); Object.setPrototypeOf(oldAuthority, oldAuthorityPrototype);
|
||||
server.workbenchHostAuthority = oldAuthority;
|
||||
} else delete server.workbenchHostAuthority;
|
||||
server.removeListener('close', closeStorage);
|
||||
if (store.storage && store.storage !== oldStoreProperties.storage) {
|
||||
const filename = store.storage.filename;
|
||||
store.close();
|
||||
if (path.resolve(filename) !== path.join(path.resolve(oldStoreProperties.directory), 'workbench.sqlite')) throw new Error('Upgrade rollback database path is invalid.');
|
||||
for (const suffix of ['', '-wal', '-shm']) if (fs.existsSync(filename + suffix)) fs.renameSync(filename + suffix, filename + '.rolledback-' + Date.now() + suffix);
|
||||
}
|
||||
for (const key of Object.keys(store)) if (!Object.hasOwn(oldStoreProperties, key)) delete store[key];
|
||||
Object.assign(store, oldStoreProperties);
|
||||
Object.assign(runtime, oldRuntimeProperties);
|
||||
if (oldInputs === undefined) delete runtime.inputs; else runtime.inputs = oldInputs;
|
||||
if (oldResumes === undefined) delete runtime.resumes; else runtime.resumes = oldResumes;
|
||||
Object.setPrototypeOf(store, oldPrototypes[0]); Object.setPrototypeOf(provider, oldPrototypes[1]); Object.setPrototypeOf(runtime, oldPrototypes[2]);
|
||||
if (oldStoragePrototype && store.storage === oldStoreProperties.storage) Object.setPrototypeOf(store.storage, oldStoragePrototype);
|
||||
if (oldHubProperties) { for (const key of Object.keys(provider.hub)) if (!Object.hasOwn(oldHubProperties, key)) delete provider.hub[key]; Object.defineProperties(provider.hub, oldHubDescriptors); }
|
||||
if (oldModelPrototypes.hub) Object.setPrototypeOf(provider.hub, oldModelPrototypes.hub);
|
||||
if (oldModelPrototypes.ledger) Object.setPrototypeOf(provider.hub.ledger, oldModelPrototypes.ledger);
|
||||
if (oldModelPrototypes.importer) Object.setPrototypeOf(provider.hub.importer, oldModelPrototypes.importer);
|
||||
if (oldModelPrototypes.vault) Object.setPrototypeOf(provider.hub.credentialVault, oldModelPrototypes.vault);
|
||||
if (oldModelPrototypes.network) Object.setPrototypeOf(provider.hub.networkChecks, oldModelPrototypes.network);
|
||||
if (oldModelPrototypes.catalog) Object.setPrototypeOf(provider.hub.catalog, oldModelPrototypes.catalog);
|
||||
store.removeAllListeners('update'); for (const observer of oldUpdates) store.on('update', observer);
|
||||
server.removeAllListeners('request'); for (const previous of oldHandlers) server.on('request', previous);
|
||||
// Restoring an already-bound authority makes refreshInstallation a no-op.
|
||||
// Restore its public index explicitly, after proving our published bytes
|
||||
// are still current. Never re-create registration secrets or credentials.
|
||||
if (publishedServiceInfo && !publishedServiceInfo.equals(originalServiceInfo ?? Buffer.alloc(0))) {
|
||||
const latest = readServiceInfo();
|
||||
if (!latest?.equals(publishedServiceInfo)) throw new Error('The published host index changed while restoring the original handler.');
|
||||
if (originalServiceInfo) {
|
||||
const temporary = ownedChild(store.directory, 'service-info.rollback-' + randomUUID() + '.json', { missing: true });
|
||||
fs.writeFileSync(temporary, originalServiceInfo, { flag: 'wx', mode: 0o600 });
|
||||
try { fs.renameSync(temporary, serviceInfoFile); } finally { if (fs.existsSync(temporary)) fs.unlinkSync(temporary); }
|
||||
} else fs.unlinkSync(serviceInfoFile);
|
||||
}
|
||||
};
|
||||
try {
|
||||
Object.setPrototypeOf(store, Store.prototype);
|
||||
Object.setPrototypeOf(provider, Provider.prototype);
|
||||
@@ -80,41 +146,15 @@ export function installUpgrade(context, { appDirectory, updateServiceInfo = true
|
||||
server.prependOnceListener('close', closeStorage);
|
||||
if (updateServiceInfo) {
|
||||
const authority = hostAuthority({ appDirectory: root, server, store, provider, runtime });
|
||||
authority.initialize(); authority.refreshInstallation();
|
||||
authority.initialize(); publishedServiceInfo = fs.readFileSync(serviceInfoFile);
|
||||
authority.refreshInstallation(); publishedServiceInfo = fs.readFileSync(serviceInfoFile);
|
||||
}
|
||||
if (initializedLedger) server.workbenchLedgerAdoption = { root, store, provider, runtime, restore: restoreOriginal };
|
||||
else delete server.workbenchLedgerAdoption;
|
||||
void oldRuntimeProperties.filePreviews?.stopAll();
|
||||
return { version: APP_VERSION, pid: process.pid, hasKey: provider.hasKey(), projects: store.projects.length, sessions: store.sessions.size, appDirectory: root };
|
||||
} catch (error) {
|
||||
initializedLedger?.rollbackInitialization();
|
||||
if (oldCompanion) server.workbenchCompanion = oldCompanion; else delete server.workbenchCompanion;
|
||||
if (oldAuthority) {
|
||||
for (const key of Object.keys(oldAuthority)) if (!Object.hasOwn(oldAuthorityProperties, key)) delete oldAuthority[key];
|
||||
Object.assign(oldAuthority, oldAuthorityProperties); Object.setPrototypeOf(oldAuthority, oldAuthorityPrototype);
|
||||
server.workbenchHostAuthority = oldAuthority;
|
||||
} else delete server.workbenchHostAuthority;
|
||||
server.removeListener('close', closeStorage);
|
||||
if (store.storage && store.storage !== oldStoreProperties.storage) {
|
||||
const filename = store.storage.filename;
|
||||
store.close();
|
||||
if (path.resolve(filename) !== path.join(path.resolve(oldStoreProperties.directory), 'workbench.sqlite')) throw new Error('Upgrade rollback database path is invalid.');
|
||||
for (const suffix of ['', '-wal', '-shm']) if (fs.existsSync(filename + suffix)) fs.renameSync(filename + suffix, filename + '.rolledback-' + Date.now() + suffix);
|
||||
}
|
||||
for (const key of Object.keys(store)) if (!Object.hasOwn(oldStoreProperties, key)) delete store[key];
|
||||
Object.assign(store, oldStoreProperties);
|
||||
Object.assign(runtime, oldRuntimeProperties);
|
||||
if (oldInputs === undefined) delete runtime.inputs; else runtime.inputs = oldInputs;
|
||||
if (oldResumes === undefined) delete runtime.resumes; else runtime.resumes = oldResumes;
|
||||
Object.setPrototypeOf(store, oldPrototypes[0]); Object.setPrototypeOf(provider, oldPrototypes[1]); Object.setPrototypeOf(runtime, oldPrototypes[2]);
|
||||
if (oldStoragePrototype && store.storage === oldStoreProperties.storage) Object.setPrototypeOf(store.storage, oldStoragePrototype);
|
||||
if (oldHubProperties) { for (const key of Object.keys(provider.hub)) if (!Object.hasOwn(oldHubProperties, key)) delete provider.hub[key]; Object.assign(provider.hub, oldHubProperties); }
|
||||
if (oldModelPrototypes.hub) Object.setPrototypeOf(provider.hub, oldModelPrototypes.hub);
|
||||
if (oldModelPrototypes.ledger) Object.setPrototypeOf(provider.hub.ledger, oldModelPrototypes.ledger);
|
||||
if (oldModelPrototypes.importer) Object.setPrototypeOf(provider.hub.importer, oldModelPrototypes.importer);
|
||||
if (oldModelPrototypes.vault) Object.setPrototypeOf(provider.hub.credentialVault, oldModelPrototypes.vault);
|
||||
if (oldModelPrototypes.network) Object.setPrototypeOf(provider.hub.networkChecks, oldModelPrototypes.network);
|
||||
if (oldModelPrototypes.catalog) Object.setPrototypeOf(provider.hub.catalog, oldModelPrototypes.catalog);
|
||||
store.removeAllListeners('update'); for (const observer of oldUpdates) store.on('update', observer);
|
||||
server.removeAllListeners('request'); for (const previous of oldHandlers) server.on('request', previous);
|
||||
restoreOriginal();
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,6 +228,11 @@ export class Provider {
|
||||
return responseDetails;
|
||||
};
|
||||
try {
|
||||
if (body && options.beforePhysicalDispatch) {
|
||||
await options.beforePhysicalDispatch({ attemptId: receipt.attemptId, body });
|
||||
signal?.throwIfAborted();
|
||||
options.beforeDispatch?.({ previousFailure });
|
||||
}
|
||||
dispatched = true;
|
||||
const transport=this.fetcher?null:(this.transport??=new ModelTransport());
|
||||
if(transport)onProgress?.({phase:'running',transport:transport.profile,attempt,maxAttempts:policy.attempts,wireAttemptId:receipt.attemptId});
|
||||
@@ -315,6 +320,9 @@ export class Provider {
|
||||
onProgress?.({ phase: 'completed', attempt, maxAttempts: policy.attempts, durationMs: Date.now() - startedAt, modelIdentity: receipt.modelIdentity });
|
||||
return result;
|
||||
} catch (error) {
|
||||
// No HTTP has been submitted. The runtime can prepare the original
|
||||
// task without its now-invalid optional remote memory, once.
|
||||
if (!dispatched && error.code === 'PROJECT_SELECTION_STALE') throw error;
|
||||
outcome = signal?.aborted ? 'interrupted' : readingStream && !streamTerminalSeen ? 'unknown' : 'failed';
|
||||
signal?.throwIfAborted();
|
||||
let diagnostic = connectionFailure(error, { ...context, method:body?'POST':'GET',responseReceived:receipt.httpStatus!==undefined,
|
||||
|
||||
+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