@assistant-ui/react
Version:
React components for AI chat.
103 lines (102 loc) • 3.38 kB
JavaScript
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/external-store/ThreadMessageLike.tsx
var ThreadMessageLike_exports = {};
__export(ThreadMessageLike_exports, {
fromThreadMessageLike: () => fromThreadMessageLike
});
module.exports = __toCommonJS(ThreadMessageLike_exports);
var fromThreadMessageLike = (like, fallbackId, fallbackStatus) => {
const { role, id, createdAt, attachments, status } = like;
const common = {
id: id ?? fallbackId,
createdAt: createdAt ?? /* @__PURE__ */ new Date()
};
const content = typeof like.content === "string" ? [{ type: "text", text: like.content }] : like.content;
if (role !== "user" && attachments)
throw new Error("Attachments are only supported for user messages");
switch (role) {
case "assistant":
return {
...common,
role,
content: content.map((part) => {
const type = part.type;
switch (type) {
case "text":
if (part.text.trim().length === 0) return null;
return part;
case "ui":
return part;
case "tool-call": {
if ("argsText" in part) return part;
return {
...part,
argsText: JSON.stringify(part.args)
};
}
default: {
const unhandledType = type;
throw new Error(`Unknown content part type: ${unhandledType}`);
}
}
}).filter((c) => !!c),
status: status ?? fallbackStatus
};
case "user":
return {
...common,
role,
content: content.map((part) => {
const type = part.type;
switch (type) {
case "text":
case "ui":
case "image":
case "audio":
return part;
default: {
const unhandledType = type;
throw new Error(`Unknown content part type: ${unhandledType}`);
}
}
}),
attachments: attachments ?? []
};
case "system":
if (content.length !== 1 || content[0].type !== "text")
throw new Error(
"System messages must have exactly one text content part."
);
return {
...common,
role,
content
};
default: {
const unsupportedRole = role;
throw new Error(`Unknown message role: ${unsupportedRole}`);
}
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
fromThreadMessageLike
});
//# sourceMappingURL=ThreadMessageLike.js.map
;