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
+1
View File
@@ -41,6 +41,7 @@ export * from "./utils/event-stream.ts";
export * from "./utils/json-parse.ts";
export * from "./utils/overflow.ts";
export * from "./utils/retry.ts";
export { contentText } from "./utils/text.ts";
export * from "./utils/typebox-helpers.ts";
export { uuidv7 } from "./utils/uuid.ts";
export * from "./utils/validation.ts";
+12
View File
@@ -0,0 +1,12 @@
import type { ImageContent, TextContent, ThinkingContent, ToolCall } from "../types.ts";
type Content = TextContent | ImageContent | ThinkingContent | ToolCall;
/** Extract and join text from message content. */
export function contentText(content: string | readonly Content[], separator = "\n"): string {
if (typeof content === "string") return content;
return content
.filter((block) => block.type === "text")
.map((block) => block.text)
.join(separator);
}