fix: preserve upstream model errors and native request parameters
This commit is contained in:
+13
-1
@@ -1,6 +1,7 @@
|
||||
import { spawn, execFile } from 'node:child_process';
|
||||
import path from 'node:path';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { sanitizeModelText } from '../core/models/upstream-error.mjs';
|
||||
import { StringDecoder } from 'node:string_decoder';
|
||||
import { setImmediate as yieldExecution } from 'node:timers/promises';
|
||||
import { safePath, listFiles, readLines, searchFiles, proposeFile, proposePatch } from './files.mjs';
|
||||
@@ -317,6 +318,17 @@ export class Runtime {
|
||||
if (run.worker) { planned.record.workerUsageAccounted = true; this.store.save(session); }
|
||||
return;
|
||||
}
|
||||
if (progress.responseCapture !== undefined || progress.streamCapture !== undefined) {
|
||||
const raw = progress.responseCapture ?? progress.streamCapture;
|
||||
const decoded = raw.toString('utf8'), redacted = sanitizeModelText(decoded, value => this.provider.redact(value));
|
||||
const captured = redacted === decoded ? raw : Buffer.from(redacted, 'utf8');
|
||||
const artifact = this.store.artifactStore.write(session, run.record, captured, { kind: progress.streamCapture !== undefined ? 'model-stream-response' : 'model-http-response', mediaType: 'text/plain' });
|
||||
this.store.core.artifact.set(artifact.id, artifact);
|
||||
if (progress.upstream) Object.assign(progress.upstream, { artifactId: artifact.id, artifactSha256: artifact.sha256,
|
||||
artifactScope: progress.streamCapture !== undefined ? 'sse-stream' : 'http-body', sessionId: session.id });
|
||||
if (progress.upstream?.capture) Object.assign(progress.upstream.capture, { retention: 'artifact', storedBytes: artifact.bytes });
|
||||
this.store.save(session); return;
|
||||
}
|
||||
if (!requestEvent) requestEvent = this.store.event(session, { kind: externalEngine ? 'engine' : 'model', runId: run.id,
|
||||
source: externalEngine ? 'controlled_engine' : 'model_connection', label: externalEngine ? '受控引擎执行' : '请求模型服务', phase: 'running', startedAt: now(), contextPlanId: planned.record.id });
|
||||
if (progress.engineRunId) requestEvent.engineRunId = progress.engineRunId;
|
||||
@@ -472,7 +484,7 @@ export class Runtime {
|
||||
this.store.message(session, 'system', budget?.message ?? '任务已停止,执行记录已保存。');
|
||||
} else {
|
||||
session.status = 'failed';
|
||||
const diagnostic = error.diagnostic ?? { source: 'workbench', stage: 'agent_loop', kind: 'runtime',
|
||||
const diagnostic = error.diagnostic ?? { source: 'workbench', origin: 'local', stage: 'agent_loop', kind: 'runtime',
|
||||
title: '工作台任务需要处理', message: this.provider.redact(error.message ?? String(error)), occurredAt: now() };
|
||||
session.lastFailure = { ...diagnostic, runId: run.id };
|
||||
const message = this.store.message(session, 'system', diagnostic.message);
|
||||
|
||||
Reference in New Issue
Block a user