Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/chat/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* AG-UI streaming adapter for dynamic agents.
*
* Calls POST <authUrl>/api/v1/chat/stream/start with body:
* { message, conversation_id, agent_id, protocol: "agui", context? }
* { message, conversation_id, agent_id, protocol: "agui", client_context, context? }
*
* Each user turn prepends a `<client-context>` date block so agents resolve
* "this week" / "today" without relying on model cutoff.
Expand Down Expand Up @@ -151,7 +151,7 @@ function shouldTryNextClientType(status: number, bodyText: string): boolean {
/**
* Calls the dynamic agents streaming endpoint via the caipe-ui BFF.
*
* Body: { message, conversation_id, agent_id, protocol: "agui" }
* Body: { message, conversation_id, agent_id, protocol: "agui", client_context: { source: "cli" } }
* Events: AG-UI SSE — RUN_STARTED, TEXT_MESSAGE_CONTENT, TOOL_CALL_START,
* TOOL_CALL_END, RUN_FINISHED, RUN_ERROR, CUSTOM
*/
Expand Down Expand Up @@ -276,6 +276,7 @@ export class AguiAdapter implements StreamAdapter {
conversation_id: conversationId,
agent_id: agentId,
protocol: "agui",
client_context: { source: "cli" },
};
const ctx = payload.systemContext?.trim();
if (ctx) bodyObj.context = ctx;
Expand Down
21 changes: 21 additions & 0 deletions tests/stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,27 @@ describe("AguiAdapter", () => {
global.fetch = originalFetch;
}
});

it("identifies stream requests as coming from the CLI", async () => {
let capturedBody = "";
const originalFetch = global.fetch;
global.fetch = vi.fn((_url, init) => {
capturedBody = (init?.body as string) ?? "";
return Promise.resolve(new Response("error", { status: 503 }));
}) as unknown as typeof fetch;

try {
const adapter = new AguiAdapter(DEFAULT_AGENT, SERVER_URL, getToken);
for await (const _ of adapter.connect(PAYLOAD)) {
/* drain */
}

const body = JSON.parse(capturedBody) as Record<string, unknown>;
expect(body.client_context).toEqual({ source: "cli" });
} finally {
global.fetch = originalFetch;
}
});
});

// ── createAdapter factory ─────────────────────────────────────────────────────
Expand Down