feat(ai): add shared contentText utility (#6840)

Co-authored-by: Armin Ronacher <armin.ronacher@active-4.com>
This commit is contained in:
Alexey Zaytsev
2026-07-19 20:50:36 -03:00
committed by GitHub
parent 75cb0b873a
commit 94373d815d
12 changed files with 92 additions and 111 deletions
+10 -16
View File
@@ -1,4 +1,11 @@
import type { AssistantMessage, ImageContent, Model, Models, UserMessage } from "@earendil-works/pi-ai";
import {
type AssistantMessage,
contentText,
type ImageContent,
type Model,
type Models,
type UserMessage,
} from "@earendil-works/pi-ai";
import { runAgentLoop } from "../agent-loop.ts";
import type {
AgentContext,
@@ -781,23 +788,10 @@ export class AgentHarness<
let newLeafId: string | null;
if (targetEntry.type === "message" && targetEntry.message.role === "user") {
newLeafId = targetEntry.parentId;
const content = targetEntry.message.content;
editorText =
typeof content === "string"
? content
: content
.filter((c): c is { readonly type: "text"; readonly text: string } => c.type === "text")
.map((c) => c.text)
.join("");
editorText = contentText(targetEntry.message.content, "");
} else if (targetEntry.type === "custom_message") {
newLeafId = targetEntry.parentId;
editorText =
typeof targetEntry.content === "string"
? targetEntry.content
: targetEntry.content
.filter((c): c is { readonly type: "text"; readonly text: string } => c.type === "text")
.map((c) => c.text)
.join("");
editorText = contentText(targetEntry.content, "");
} else {
newLeafId = targetId;
}