UNPKG

@assistant-ui/react

Version:

Typescript/React library for AI Chat

74 lines (73 loc) 2.47 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/runtimes/edge/converters/toCoreMessages.ts var toCoreMessages_exports = {}; __export(toCoreMessages_exports, { toCoreMessage: () => toCoreMessage, toCoreMessages: () => toCoreMessages }); module.exports = __toCommonJS(toCoreMessages_exports); var toCoreMessages = (messages, options = {}) => { return messages.map((message) => toCoreMessage(message, options)); }; var toCoreMessage = (message, options = {}) => { const includeId = options.unstable_includeId ?? false; const role = message.role; switch (role) { case "assistant": return { role, content: message.content.map((part) => { if (part.type === "reasoning" || part.type === "source" || part.type === "file") return null; if (part.type === "tool-call") { const { argsText, ...rest } = part; return rest; } return part; }).filter((c) => !!c), ...includeId ? { unstable_id: message.id } : {} }; case "user": return { role, content: [ ...message.content, ...message.attachments.map((a) => a.content).flat() ], ...includeId ? { unstable_id: message.id } : {} }; case "system": return { role, content: message.content, ...includeId ? { unstable_id: message.id } : {} }; default: { const unsupportedRole = role; throw new Error(`Unknown message role: ${unsupportedRole}`); } } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { toCoreMessage, toCoreMessages }); //# sourceMappingURL=toCoreMessages.js.map