UNPKG

@cometchat/chat-uikit-react

Version:

Ready-to-use Chat UI Components for React

43 lines (39 loc) 2.1 kB
'use strict'; var chunkKMTY4OFY_cjs = require('./chunk-KMTY4OFY.cjs'); var react = require('react'); var jsxRuntime = require('react/jsx-runtime'); require('./index.css'); 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 } = chunkKMTY4OFY_cjs.useLocale(); const toolCalls = react.useMemo(() => extractToolCalls(message), [message]); if (toolCalls.length === 0) return null; const rootClasses = ["cometchat-toolcall-argument-bubble", className].filter(Boolean).join(" "); return /* @__PURE__ */ jsxRuntime.jsx("div", { className: rootClasses, children: toolCalls.map((toolCall, index) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cometchat-toolcall-argument-bubble__item", children: [ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cometchat-toolcall-argument-bubble__name", children: toolCall.displayName ?? "Tool" }), toolCall.executionText && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cometchat-toolcall-argument-bubble__execution-text", children: toolCall.executionText }), /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cometchat-toolcall-argument-bubble__label", children: getLocalizedString("ai_tool_call_arguments") }), /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "cometchat-toolcall-argument-bubble__code", children: formatArguments(toolCall.function?.arguments ?? "{}") }) ] }, toolCall.id ?? index)) }); }; CometChatToolCallArgumentBubble.displayName = "CometChatToolCallArgumentBubble"; var CometChatToolCallArgumentBubble_default = CometChatToolCallArgumentBubble; exports.CometChatToolCallArgumentBubble = CometChatToolCallArgumentBubble; exports.CometChatToolCallArgumentBubble_default = CometChatToolCallArgumentBubble_default;