fix(agent-debug): stream execution traces with platform mocks and coverage

This commit is contained in:
Hyu
2026-09-05 15:34:29 +08:00
parent a4d36aa2db
commit 8f0a55a1f4
47 changed files with 1815 additions and 562 deletions
+49
View File
@@ -1,4 +1,5 @@
import { BaseHttpClient, type RequestConfig } from './BaseHttpClient';
import type { DebugExecutionEvent } from '@/app/infra/entities/api/agent-debug';
import {
ApiRespProviderRequesters,
ApiRespProviderRequester,
@@ -288,6 +289,7 @@ export class BackendClient extends BaseHttpClient {
conversation_id?: string;
actor?: Record<string, unknown>;
subject?: Record<string, unknown>;
mock?: Record<string, unknown>;
},
): Promise<{
event_id: string;
@@ -303,6 +305,53 @@ export class BackendClient extends BaseHttpClient {
return this.post(`/api/v1/agents/${uuid}/debug`, payload);
}
public async streamDebugAgent(
uuid: string,
payload: Parameters<BackendClient['debugAgent']>[1],
onResult: (event: DebugExecutionEvent) => void,
signal: AbortSignal,
): ReturnType<BackendClient['debugAgent']> {
let offset = 0;
let result: Awaited<ReturnType<BackendClient['debugAgent']>> | undefined;
let failure: { code: string; msg: string } | undefined;
const consume = (text: string) => {
let end: number;
while ((end = text.indexOf('\n', offset)) !== -1) {
const line = text.slice(offset, end).trim();
offset = end + 1;
if (!line) continue;
const frame = JSON.parse(line);
if (frame.kind === 'result') onResult(frame.data);
else if (frame.kind === 'completed') result = frame.data;
else if (frame.kind === 'error') failure = frame;
}
};
const response = await this.instance.post<string>(
`/api/v1/agents/${uuid}/debug/stream`,
payload,
{
adapter: 'xhr',
responseType: 'text',
timeout: 0,
signal,
headers: { Accept: 'application/x-ndjson' },
transformResponse: [(data) => data],
onDownloadProgress: (progress) => {
const xhr = progress.event?.target as XMLHttpRequest | undefined;
if (xhr?.status === 200) consume(xhr.responseText);
},
},
);
consume(response.data);
if (failure) throw failure;
if (!result)
throw {
code: 'runner_protocol_error',
msg: 'Debug stream ended before completion',
};
return result;
}
public getGeneralPipelineMetadata(): Promise<GetPipelineMetadataResponseData> {
// as designed, this method will be deprecated, and only for developer to check the prefered config schema
return this.get('/api/v1/pipelines/_/metadata');