@cometchat/chat-uikit-react
Version:
Ready-to-use Chat UI Components for React
40 lines (37 loc) • 1.91 kB
JavaScript
import './index.css';
import { useLocale } from './chunk-UVWJYQJ3.js';
import { useMemo } from 'react';
import { jsx, jsxs } from 'react/jsx-runtime';
function extractToolCalls(message) {
try {
const msgWithData = message;
return msgWithData.getToolArgumentMessageData?.()?.getToolCalls?.() ?? [];
} catch {
return [];
}
}
function formatArguments(argsString) {
try {
return JSON.stringify(JSON.parse(argsString), null, 2);
} catch {
return argsString;
}
}
var CometChatToolCallArgumentBubble = ({
message,
className
}) => {
const { getLocalizedString } = useLocale();
const toolCalls = useMemo(() => extractToolCalls(message), [message]);
if (toolCalls.length === 0) return null;
const rootClasses = ["cometchat-toolcall-argument-bubble", className].filter(Boolean).join(" ");
return /* @__PURE__ */ jsx("div", { className: rootClasses, children: toolCalls.map((toolCall, index) => /* @__PURE__ */ jsxs("div", { className: "cometchat-toolcall-argument-bubble__item", children: [
/* @__PURE__ */ jsx("div", { className: "cometchat-toolcall-argument-bubble__name", children: toolCall.displayName ?? "Tool" }),
toolCall.executionText && /* @__PURE__ */ jsx("div", { className: "cometchat-toolcall-argument-bubble__execution-text", children: toolCall.executionText }),
/* @__PURE__ */ jsx("div", { className: "cometchat-toolcall-argument-bubble__label", children: getLocalizedString("ai_tool_call_arguments") }),
/* @__PURE__ */ jsx("pre", { className: "cometchat-toolcall-argument-bubble__code", children: formatArguments(toolCall.function?.arguments ?? "{}") })
] }, toolCall.id ?? index)) });
};
CometChatToolCallArgumentBubble.displayName = "CometChatToolCallArgumentBubble";
var CometChatToolCallArgumentBubble_default = CometChatToolCallArgumentBubble;
export { CometChatToolCallArgumentBubble, CometChatToolCallArgumentBubble_default };