This commit is contained in:
Oleg Maslov
2026-09-02 10:14:22 +02:00
parent 0c3e2ead3b
commit b20b138fe4
771 changed files with 161561 additions and 9027 deletions

View File

@@ -127,6 +127,7 @@ export async function runChannelChatTurn(req: ChatTurnRequest): Promise<ChatTurn
let content = '';
let approvalRequired = false;
let error: string | undefined;
let sawDone = false;
for (;;) {
const { done, value } = await reader.read();
@@ -135,6 +136,7 @@ export async function runChannelChatTurn(req: ChatTurnRequest): Promise<ChatTurn
buffer = drained.rest;
for (const evt of drained.events) {
if (evt.event === 'done') {
sawDone = true;
const d = evt.data as { content?: string };
if (typeof d?.content === 'string') content = d.content;
} else if (evt.event === 'approval_required') {
@@ -147,6 +149,10 @@ export async function runChannelChatTurn(req: ChatTurnRequest): Promise<ChatTurn
if (done) break;
}
if (!sawDone && !approvalRequired && !error) {
error = 'INCOMPLETE_COMPLETION: Agent turn ended before the done event';
}
return { content, approvalRequired, error };
} catch (e: unknown) {
const aborted = e instanceof Error && e.name === 'AbortError';