feat(ai): add shared contentText utility (#6840)
Co-authored-by: Armin Ronacher <armin.ronacher@active-4.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user