UNPKG

@artinet/sdk

Version:

A TypeScript SDK for building collaborative AI agents.

35 lines (34 loc) 1.18 kB
/** * Copyright 2025 The Artinet Project * SPDX-License-Identifier: Apache-2.0 */ import { getParts } from './part.js'; /** * Extracts the content of an agent response. * @param input - The input event. * @param legacy - Whether to use the legacy content extraction logic. * @returns The content of the input event. */ export function extractTextContent(input, legacy = true) { const parts = getParts(input?.parts ?? input?.status?.message?.parts ?? input?.status?.message?.parts ?? input?.artifact?.parts ?? []); if (legacy) { return (parts.text ?? parts.file?.map((file) => file.bytes).join('\n') ?? parts.file?.map((file) => file.uri).join('\n') ?? parts.data?.map((data) => JSON.stringify(data)).join('\n') ?? undefined); } return parts.text && parts.text !== '' ? parts.text : (parts.file?.map((file) => file.bytes ?? file.uri).join('\n') ?? parts.data?.map((data) => JSON.stringify(data)).join('\n') ?? undefined); } /** * @deprecated Use extractTextContent instead. */ export const getContent = extractTextContent;