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>
12 lines
516 B
TypeScript
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("");
|
|
}
|