@tanstack/ai
Version:
Type-safe TypeScript AI SDK for streaming chat, tool calling, agents, structured outputs, and multimodal generation.
38 lines (37 loc) • 1.08 kB
JavaScript
const CONTENT_PART_TYPES = /* @__PURE__ */ new Set([
"text",
"image",
"audio",
"video",
"document"
]);
function isContentPart(value) {
if (typeof value !== "object" || value === null) return false;
const part = value;
if (typeof part.type !== "string" || !CONTENT_PART_TYPES.has(part.type)) {
return false;
}
if (part.type === "text") {
return typeof part.content === "string";
}
const source = part.source;
if (typeof source !== "object" || source === null) return false;
const src = source;
if (typeof src.value !== "string") return false;
if (src.type === "data") return typeof src.mimeType === "string";
return src.type === "url";
}
function isContentPartArray(value) {
return Array.isArray(value) && value.length > 0 && value.every(isContentPart);
}
function normalizeToolResult(result) {
if (typeof result === "string") return result;
if (isContentPartArray(result)) return result;
return JSON.stringify(result);
}
export {
isContentPart,
isContentPartArray,
normalizeToolResult
};
//# sourceMappingURL=tool-result.js.map