multica/src/agent/extract-text.ts
Naiyuan Qing d04bed8175 feat(agent): add streaming support for AI message generation
AsyncAgent now subscribes to pi-agent-core events (message_start,
message_update, message_end) and forwards incremental text deltas
through a stream callback. Hub registers the callback and sends
stream payloads to the requesting client via Gateway.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 17:18:10 +08:00

12 lines
516 B
TypeScript

import type { AgentMessage } from "@mariozechner/pi-agent-core";
/** Extract plain text content from an AgentMessage */
export function extractText(message: AgentMessage | undefined): string {
if (!message || typeof message !== "object" || !("content" in message)) return "";
const content = (message as { content?: Array<{ type: string; text?: string }> }).content;
if (!Array.isArray(content)) return "";
return content
.filter((c) => c.type === "text")
.map((c) => c.text ?? "")
.join("");
}