@copilotkit/react-ui 0.16.0 → 0.17.0-demofixes.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/.turbo/turbo-build.log +190 -186
  2. package/CHANGELOG.md +36 -0
  3. package/dist/components/chat/Button.mjs +30 -6
  4. package/dist/components/chat/Button.mjs.map +1 -1
  5. package/dist/components/chat/Chat.mjs +830 -16
  6. package/dist/components/chat/Chat.mjs.map +1 -1
  7. package/dist/components/chat/ChatContext.mjs +214 -7
  8. package/dist/components/chat/ChatContext.mjs.map +1 -1
  9. package/dist/components/chat/CodeBlock.mjs +202 -8
  10. package/dist/components/chat/CodeBlock.mjs.map +1 -1
  11. package/dist/components/chat/Header.mjs +23 -6
  12. package/dist/components/chat/Header.mjs.map +1 -1
  13. package/dist/components/chat/Icons.mjs +218 -14
  14. package/dist/components/chat/Icons.mjs.map +1 -1
  15. package/dist/components/chat/Input.mjs +110 -7
  16. package/dist/components/chat/Input.mjs.map +1 -1
  17. package/dist/components/chat/Markdown.mjs +253 -7
  18. package/dist/components/chat/Markdown.mjs.map +1 -1
  19. package/dist/components/chat/Messages.mjs +329 -9
  20. package/dist/components/chat/Messages.mjs.map +1 -1
  21. package/dist/components/chat/Popup.mjs +839 -17
  22. package/dist/components/chat/Popup.mjs.map +1 -1
  23. package/dist/components/chat/Response.mjs +23 -6
  24. package/dist/components/chat/Response.mjs.map +1 -1
  25. package/dist/components/chat/Sidebar.mjs +853 -17
  26. package/dist/components/chat/Sidebar.mjs.map +1 -1
  27. package/dist/components/chat/Textarea.mjs +48 -4
  28. package/dist/components/chat/Textarea.mjs.map +1 -1
  29. package/dist/components/chat/Window.mjs +105 -4
  30. package/dist/components/chat/Window.mjs.map +1 -1
  31. package/dist/components/chat/index.mjs +860 -22
  32. package/dist/components/chat/index.mjs.map +1 -1
  33. package/dist/components/chat/props.mjs +0 -1
  34. package/dist/components/index.mjs +860 -23
  35. package/dist/components/index.mjs.map +1 -1
  36. package/dist/context/index.mjs +0 -1
  37. package/dist/hooks/index.mjs +0 -1
  38. package/dist/hooks/use-copy-to-clipboard.mjs +22 -4
  39. package/dist/hooks/use-copy-to-clipboard.mjs.map +1 -1
  40. package/dist/index.mjs +860 -26
  41. package/dist/index.mjs.map +1 -1
  42. package/dist/lib/utils.d.ts +1 -4
  43. package/dist/lib/utils.js +0 -7
  44. package/dist/lib/utils.js.map +1 -1
  45. package/dist/lib/utils.mjs +20 -9
  46. package/dist/lib/utils.mjs.map +1 -1
  47. package/dist/types/index.mjs +0 -1
  48. package/package.json +6 -24
  49. package/src/lib/utils.ts +0 -6
@@ -1,10 +1,256 @@
1
- import {
2
- Markdown
3
- } from "../../chunk-GWGHQNRI.mjs";
4
- import "../../chunk-DPRH4HX3.mjs";
5
- import "../../chunk-7YXG7D47.mjs";
6
- import "../../chunk-POVINPXX.mjs";
7
- import "../../chunk-MRXNTQOX.mjs";
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
32
+
33
+ // src/components/chat/Markdown.tsx
34
+ import { memo as memo2 } from "react";
35
+ import ReactMarkdown from "react-markdown";
36
+
37
+ // src/components/chat/CodeBlock.tsx
38
+ import { memo } from "react";
39
+ import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
40
+ import { vscDarkPlus as highlightStyle } from "react-syntax-highlighter/dist/esm/styles/prism";
41
+
42
+ // src/hooks/use-copy-to-clipboard.tsx
43
+ import * as React from "react";
44
+ function useCopyToClipboard({ timeout = 2e3 }) {
45
+ const [isCopied, setIsCopied] = React.useState(false);
46
+ const copyToClipboard = (value) => {
47
+ var _a;
48
+ if (typeof window === "undefined" || !((_a = navigator.clipboard) == null ? void 0 : _a.writeText)) {
49
+ return;
50
+ }
51
+ if (!value) {
52
+ return;
53
+ }
54
+ navigator.clipboard.writeText(value).then(() => {
55
+ setIsCopied(true);
56
+ setTimeout(() => {
57
+ setIsCopied(false);
58
+ }, timeout);
59
+ });
60
+ };
61
+ return { isCopied, copyToClipboard };
62
+ }
63
+
64
+ // src/components/chat/Icons.tsx
65
+ import { jsx, jsxs } from "react/jsx-runtime";
66
+ function CheckIcon(_a) {
67
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
68
+ return /* @__PURE__ */ jsx(
69
+ "svg",
70
+ __spreadProps(__spreadValues({
71
+ xmlns: "http://www.w3.org/2000/svg",
72
+ viewBox: "0 0 256 256",
73
+ fill: "currentColor",
74
+ style: { height: "1rem", width: "1rem" },
75
+ className
76
+ }, props), {
77
+ children: /* @__PURE__ */ jsx("path", { d: "m229.66 77.66-128 128a8 8 0 0 1-11.32 0l-56-56a8 8 0 0 1 11.32-11.32L96 188.69 218.34 66.34a8 8 0 0 1 11.32 11.32Z" })
78
+ })
79
+ );
80
+ }
81
+ function DownloadIcon(_a) {
82
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
83
+ return /* @__PURE__ */ jsx(
84
+ "svg",
85
+ __spreadProps(__spreadValues({
86
+ xmlns: "http://www.w3.org/2000/svg",
87
+ viewBox: "0 0 256 256",
88
+ fill: "currentColor",
89
+ style: { height: "1rem", width: "1rem" },
90
+ className
91
+ }, props), {
92
+ children: /* @__PURE__ */ jsx("path", { d: "M224 152v56a16 16 0 0 1-16 16H48a16 16 0 0 1-16-16v-56a8 8 0 0 1 16 0v56h160v-56a8 8 0 0 1 16 0Zm-101.66 5.66a8 8 0 0 0 11.32 0l40-40a8 8 0 0 0-11.32-11.32L136 132.69V40a8 8 0 0 0-16 0v92.69l-26.34-26.35a8 8 0 0 0-11.32 11.32Z" })
93
+ })
94
+ );
95
+ }
96
+ function CopyIcon(_a) {
97
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
98
+ return /* @__PURE__ */ jsx(
99
+ "svg",
100
+ __spreadProps(__spreadValues({
101
+ xmlns: "http://www.w3.org/2000/svg",
102
+ viewBox: "0 0 256 256",
103
+ fill: "currentColor",
104
+ style: { height: "1rem", width: "1rem" },
105
+ className
106
+ }, props), {
107
+ children: /* @__PURE__ */ jsx("path", { d: "M216 32H88a8 8 0 0 0-8 8v40H40a8 8 0 0 0-8 8v128a8 8 0 0 0 8 8h128a8 8 0 0 0 8-8v-40h40a8 8 0 0 0 8-8V40a8 8 0 0 0-8-8Zm-56 176H48V96h112Zm48-48h-32V88a8 8 0 0 0-8-8H96V48h112Z" })
108
+ })
109
+ );
110
+ }
111
+
112
+ // src/components/chat/CodeBlock.tsx
113
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
114
+ var programmingLanguages = {
115
+ javascript: ".js",
116
+ python: ".py",
117
+ java: ".java",
118
+ c: ".c",
119
+ cpp: ".cpp",
120
+ "c++": ".cpp",
121
+ "c#": ".cs",
122
+ ruby: ".rb",
123
+ php: ".php",
124
+ swift: ".swift",
125
+ "objective-c": ".m",
126
+ kotlin: ".kt",
127
+ typescript: ".ts",
128
+ go: ".go",
129
+ perl: ".pl",
130
+ rust: ".rs",
131
+ scala: ".scala",
132
+ haskell: ".hs",
133
+ lua: ".lua",
134
+ shell: ".sh",
135
+ sql: ".sql",
136
+ html: ".html",
137
+ css: ".css"
138
+ // add more file extensions here, make sure the key is same as language prop in CodeBlock.tsx component
139
+ };
140
+ var generateRandomString = (length, lowercase = false) => {
141
+ const chars = "ABCDEFGHJKLMNPQRSTUVWXY3456789";
142
+ let result = "";
143
+ for (let i = 0; i < length; i++) {
144
+ result += chars.charAt(Math.floor(Math.random() * chars.length));
145
+ }
146
+ return lowercase ? result.toLowerCase() : result;
147
+ };
148
+ var CodeBlock = memo(({ language, value }) => {
149
+ const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2e3 });
150
+ const downloadAsFile = () => {
151
+ if (typeof window === "undefined") {
152
+ return;
153
+ }
154
+ const fileExtension = programmingLanguages[language] || ".file";
155
+ const suggestedFileName = `file-${generateRandomString(3, true)}${fileExtension}`;
156
+ const fileName = window.prompt("Enter file name", suggestedFileName);
157
+ if (!fileName) {
158
+ return;
159
+ }
160
+ const blob = new Blob([value], { type: "text/plain" });
161
+ const url = URL.createObjectURL(blob);
162
+ const link = document.createElement("a");
163
+ link.download = fileName;
164
+ link.href = url;
165
+ link.style.display = "none";
166
+ document.body.appendChild(link);
167
+ link.click();
168
+ document.body.removeChild(link);
169
+ URL.revokeObjectURL(url);
170
+ };
171
+ const onCopy = () => {
172
+ if (isCopied)
173
+ return;
174
+ copyToClipboard(value);
175
+ };
176
+ return /* @__PURE__ */ jsxs2("div", { className: "copilotKitCodeBlock", children: [
177
+ /* @__PURE__ */ jsxs2("div", { className: "copilotKitCodeBlockToolbar", children: [
178
+ /* @__PURE__ */ jsx2("span", { className: "copilotKitCodeBlockToolbarLanguage", children: language }),
179
+ /* @__PURE__ */ jsxs2("div", { className: "copilotKitCodeBlockToolbarButtons", children: [
180
+ /* @__PURE__ */ jsxs2("button", { className: "copilotKitCodeBlockToolbarButton", onClick: downloadAsFile, children: [
181
+ /* @__PURE__ */ jsx2(DownloadIcon, {}),
182
+ /* @__PURE__ */ jsx2("span", { className: "sr-only", children: "Download" })
183
+ ] }),
184
+ /* @__PURE__ */ jsxs2("button", { className: "copilotKitCodeBlockToolbarButton", onClick: onCopy, children: [
185
+ isCopied ? /* @__PURE__ */ jsx2(CheckIcon, {}) : /* @__PURE__ */ jsx2(CopyIcon, {}),
186
+ /* @__PURE__ */ jsx2("span", { className: "sr-only", children: "Copy code" })
187
+ ] })
188
+ ] })
189
+ ] }),
190
+ /* @__PURE__ */ jsx2(
191
+ SyntaxHighlighter,
192
+ {
193
+ language,
194
+ style: highlightStyle,
195
+ PreTag: "div",
196
+ customStyle: {
197
+ margin: 0,
198
+ borderBottomLeftRadius: "0.375rem",
199
+ borderBottomRightRadius: "0.375rem"
200
+ },
201
+ children: value
202
+ }
203
+ )
204
+ ] });
205
+ });
206
+ CodeBlock.displayName = "CodeBlock";
207
+
208
+ // src/components/chat/Markdown.tsx
209
+ import remarkGfm from "remark-gfm";
210
+ import remarkMath from "remark-math";
211
+ import { jsx as jsx3 } from "react/jsx-runtime";
212
+ var MemoizedReactMarkdown = memo2(
213
+ ReactMarkdown,
214
+ (prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.className === nextProps.className
215
+ );
216
+ var Markdown = ({ content }) => {
217
+ return /* @__PURE__ */ jsx3("div", { className: "copilotKitMarkdown", children: /* @__PURE__ */ jsx3(MemoizedReactMarkdown, { components, remarkPlugins: [remarkGfm, remarkMath], children: content }) });
218
+ };
219
+ var components = {
220
+ p({ children }) {
221
+ return /* @__PURE__ */ jsx3("p", { children });
222
+ },
223
+ code(_a) {
224
+ var _b = _a, { children, className, inline } = _b, props = __objRest(_b, ["children", "className", "inline"]);
225
+ if (children.length) {
226
+ if (children[0] == "\u258D") {
227
+ return /* @__PURE__ */ jsx3(
228
+ "span",
229
+ {
230
+ style: {
231
+ animation: "pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite",
232
+ marginTop: "0.25rem"
233
+ },
234
+ children: "\u258D"
235
+ }
236
+ );
237
+ }
238
+ children[0] = children[0].replace("`\u258D`", "\u258D");
239
+ }
240
+ const match = /language-(\w+)/.exec(className || "");
241
+ if (inline) {
242
+ return /* @__PURE__ */ jsx3("code", __spreadProps(__spreadValues({ className }, props), { children }));
243
+ }
244
+ return /* @__PURE__ */ jsx3(
245
+ CodeBlock,
246
+ __spreadValues({
247
+ language: match && match[1] || "",
248
+ value: String(children).replace(/\n$/, "")
249
+ }, props),
250
+ Math.random()
251
+ );
252
+ }
253
+ };
8
254
  export {
9
255
  Markdown
10
256
  };
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"sources":["../../../src/components/chat/Markdown.tsx","../../../src/components/chat/CodeBlock.tsx","../../../src/hooks/use-copy-to-clipboard.tsx","../../../src/components/chat/Icons.tsx"],"sourcesContent":["import { FC, memo } from \"react\";\nimport ReactMarkdown, { Options, Components } from \"react-markdown\";\nimport { CodeBlock } from \"./CodeBlock\";\nimport remarkGfm from \"remark-gfm\";\nimport remarkMath from \"remark-math\";\n\nconst MemoizedReactMarkdown: FC<Options> = memo(\n ReactMarkdown,\n (prevProps, nextProps) =>\n prevProps.children === nextProps.children && prevProps.className === nextProps.className,\n);\n\ntype MarkdownProps = {\n content: string;\n};\n\nexport const Markdown = ({ content }: MarkdownProps) => {\n return (\n <div className=\"copilotKitMarkdown\">\n <MemoizedReactMarkdown components={components} remarkPlugins={[remarkGfm, remarkMath]}>\n {content}\n </MemoizedReactMarkdown>\n </div>\n );\n};\n\nconst components: Components = {\n p({ children }) {\n return <p>{children}</p>;\n },\n code({ children, className, inline, ...props }) {\n if (children.length) {\n if (children[0] == \"▍\") {\n return (\n <span\n style={{\n animation: \"pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite\",\n marginTop: \"0.25rem\",\n }}\n >\n ▍\n </span>\n );\n }\n\n children[0] = (children[0] as string).replace(\"`▍`\", \"▍\");\n }\n\n const match = /language-(\\w+)/.exec(className || \"\");\n\n if (inline) {\n return (\n <code className={className} {...props}>\n {children}\n </code>\n );\n }\n\n return (\n <CodeBlock\n key={Math.random()}\n language={(match && match[1]) || \"\"}\n value={String(children).replace(/\\n$/, \"\")}\n {...props}\n />\n );\n },\n};\n","\"use client\";\n\nimport { FC, memo } from \"react\";\nimport { Prism as SyntaxHighlighter } from \"react-syntax-highlighter\";\nimport { vscDarkPlus as highlightStyle } from \"react-syntax-highlighter/dist/esm/styles/prism\";\n\nimport { useCopyToClipboard } from \"../../hooks/use-copy-to-clipboard\";\nimport { CheckIcon, CopyIcon, DownloadIcon } from \"./Icons\";\n\ninterface CodeActionButtonProps {\n onClick: () => void;\n children: React.ReactNode;\n}\n\ninterface Props {\n language: string;\n value: string;\n}\n\ninterface languageMap {\n [key: string]: string | undefined;\n}\n\nexport const programmingLanguages: languageMap = {\n javascript: \".js\",\n python: \".py\",\n java: \".java\",\n c: \".c\",\n cpp: \".cpp\",\n \"c++\": \".cpp\",\n \"c#\": \".cs\",\n ruby: \".rb\",\n php: \".php\",\n swift: \".swift\",\n \"objective-c\": \".m\",\n kotlin: \".kt\",\n typescript: \".ts\",\n go: \".go\",\n perl: \".pl\",\n rust: \".rs\",\n scala: \".scala\",\n haskell: \".hs\",\n lua: \".lua\",\n shell: \".sh\",\n sql: \".sql\",\n html: \".html\",\n css: \".css\",\n // add more file extensions here, make sure the key is same as language prop in CodeBlock.tsx component\n};\n\nexport const generateRandomString = (length: number, lowercase = false) => {\n const chars = \"ABCDEFGHJKLMNPQRSTUVWXY3456789\"; // excluding similar looking characters like Z, 2, I, 1, O, 0\n let result = \"\";\n for (let i = 0; i < length; i++) {\n result += chars.charAt(Math.floor(Math.random() * chars.length));\n }\n return lowercase ? result.toLowerCase() : result;\n};\n\nconst CodeBlock: FC<Props> = memo(({ language, value }) => {\n const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2000 });\n\n const downloadAsFile = () => {\n if (typeof window === \"undefined\") {\n return;\n }\n const fileExtension = programmingLanguages[language] || \".file\";\n const suggestedFileName = `file-${generateRandomString(3, true)}${fileExtension}`;\n const fileName = window.prompt(\"Enter file name\" || \"\", suggestedFileName);\n\n if (!fileName) {\n // User pressed cancel on prompt.\n return;\n }\n\n const blob = new Blob([value], { type: \"text/plain\" });\n const url = URL.createObjectURL(blob);\n const link = document.createElement(\"a\");\n link.download = fileName;\n link.href = url;\n link.style.display = \"none\";\n document.body.appendChild(link);\n link.click();\n document.body.removeChild(link);\n URL.revokeObjectURL(url);\n };\n\n const onCopy = () => {\n if (isCopied) return;\n copyToClipboard(value);\n };\n\n return (\n <div className=\"copilotKitCodeBlock\">\n <div className=\"copilotKitCodeBlockToolbar\">\n <span className=\"copilotKitCodeBlockToolbarLanguage\">{language}</span>\n <div className=\"copilotKitCodeBlockToolbarButtons\">\n <button className=\"copilotKitCodeBlockToolbarButton\" onClick={downloadAsFile}>\n <DownloadIcon />\n <span className=\"sr-only\">Download</span>\n </button>\n <button className=\"copilotKitCodeBlockToolbarButton\" onClick={onCopy}>\n {isCopied ? <CheckIcon /> : <CopyIcon />}\n <span className=\"sr-only\">Copy code</span>\n </button>\n </div>\n </div>\n <SyntaxHighlighter\n language={language}\n style={highlightStyle}\n PreTag=\"div\"\n customStyle={{\n margin: 0,\n borderBottomLeftRadius: \"0.375rem\",\n borderBottomRightRadius: \"0.375rem\",\n }}\n >\n {value}\n </SyntaxHighlighter>\n </div>\n );\n});\nCodeBlock.displayName = \"CodeBlock\";\n\nexport { CodeBlock };\n","\"use client\";\n\nimport * as React from \"react\";\n\nexport interface useCopyToClipboardProps {\n timeout?: number;\n}\n\nexport function useCopyToClipboard({ timeout = 2000 }: useCopyToClipboardProps) {\n const [isCopied, setIsCopied] = React.useState<Boolean>(false);\n\n const copyToClipboard = (value: string) => {\n if (typeof window === \"undefined\" || !navigator.clipboard?.writeText) {\n return;\n }\n\n if (!value) {\n return;\n }\n\n navigator.clipboard.writeText(value).then(() => {\n setIsCopied(true);\n\n setTimeout(() => {\n setIsCopied(false);\n }, timeout);\n });\n };\n\n return { isCopied, copyToClipboard };\n}\n","import React from \"react\";\n\nexport const OpenIcon = (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n width=\"24\"\n height=\"24\"\n >\n <g transform=\"translate(24, 0) scale(-1, 1)\">\n <path\n fillRule=\"evenodd\"\n d=\"M5.337 21.718a6.707 6.707 0 01-.533-.074.75.75 0 01-.44-1.223 3.73 3.73 0 00.814-1.686c.023-.115-.022-.317-.254-.543C3.274 16.587 2.25 14.41 2.25 12c0-5.03 4.428-9 9.75-9s9.75 3.97 9.75 9c0 5.03-4.428 9-9.75 9-.833 0-1.643-.097-2.417-.279a6.721 6.721 0 01-4.246.997z\"\n clipRule=\"evenodd\"\n />\n </g>\n </svg>\n);\n\nexport const CloseIcon = (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n fill=\"none\"\n viewBox=\"0 0 24 24\"\n strokeWidth=\"1.5\"\n stroke=\"currentColor\"\n width=\"24\"\n height=\"24\"\n >\n <path strokeLinecap=\"round\" strokeLinejoin=\"round\" d=\"M19.5 8.25l-7.5 7.5-7.5-7.5\" />\n </svg>\n);\n\nexport const HeaderCloseIcon = (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n fill=\"none\"\n viewBox=\"0 0 24 24\"\n strokeWidth=\"1.5\"\n stroke=\"currentColor\"\n width=\"24\"\n height=\"24\"\n >\n <path strokeLinecap=\"round\" strokeLinejoin=\"round\" d=\"M6 18L18 6M6 6l12 12\" />\n </svg>\n);\n\nexport const SendIcon = (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n fill=\"none\"\n viewBox=\"0 0 24 24\"\n strokeWidth={1.5}\n stroke=\"currentColor\"\n width=\"24\"\n height=\"24\"\n >\n <path\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n d=\"M6 12L3.269 3.126A59.768 59.768 0 0121.485 12 59.77 59.77 0 013.27 20.876L5.999 12zm0 0h7.5\"\n />\n </svg>\n);\n\nexport const SpinnerIcon = (\n <svg\n style={{\n animation: \"copilotKitSpinAnimation 1s linear infinite\",\n color: \"rgb(107 114 128)\",\n }}\n width=\"24\"\n height=\"24\"\n xmlns=\"http://www.w3.org/2000/svg\"\n fill=\"none\"\n viewBox=\"0 0 24 24\"\n >\n <circle\n style={{ opacity: 0.25 }}\n cx=\"12\"\n cy=\"12\"\n r=\"10\"\n stroke=\"currentColor\"\n strokeWidth=\"4\"\n ></circle>\n <path\n style={{ opacity: 0.75 }}\n fill=\"currentColor\"\n d=\"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z\"\n ></path>\n </svg>\n);\n\nexport const ActivityIcon = (\n <svg\n style={{\n display: \"inline-block\",\n marginLeft: \"0.25rem\",\n marginRight: \"0.25rem\",\n }}\n height=\"24\"\n width=\"24\"\n viewBox=\"0 0 27 27\"\n xmlns=\"http://www.w3.org/2000/svg\"\n fill=\"currentColor\"\n >\n <circle className=\"copilotKitActivityDot1\" cx=\"4\" cy=\"12\" r=\"3\" />\n <circle className=\"copilotKitActivityDot1 copilotKitActivityDot2\" cx=\"12\" cy=\"12\" r=\"3\" />\n <circle className=\"copilotKitActivityDot1 copilotKitActivityDot3\" cx=\"20\" cy=\"12\" r=\"3\" />\n </svg>\n);\n\nexport function CheckIcon({ className, ...props }: React.ComponentProps<\"svg\">) {\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 256 256\"\n fill=\"currentColor\"\n style={{ height: \"1rem\", width: \"1rem\" }}\n className={className}\n {...props}\n >\n <path d=\"m229.66 77.66-128 128a8 8 0 0 1-11.32 0l-56-56a8 8 0 0 1 11.32-11.32L96 188.69 218.34 66.34a8 8 0 0 1 11.32 11.32Z\" />\n </svg>\n );\n}\n\nexport function DownloadIcon({ className, ...props }: React.ComponentProps<\"svg\">) {\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 256 256\"\n fill=\"currentColor\"\n style={{ height: \"1rem\", width: \"1rem\" }}\n className={className}\n {...props}\n >\n <path d=\"M224 152v56a16 16 0 0 1-16 16H48a16 16 0 0 1-16-16v-56a8 8 0 0 1 16 0v56h160v-56a8 8 0 0 1 16 0Zm-101.66 5.66a8 8 0 0 0 11.32 0l40-40a8 8 0 0 0-11.32-11.32L136 132.69V40a8 8 0 0 0-16 0v92.69l-26.34-26.35a8 8 0 0 0-11.32 11.32Z\" />\n </svg>\n );\n}\n\nexport function CopyIcon({ className, ...props }: React.ComponentProps<\"svg\">) {\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 256 256\"\n fill=\"currentColor\"\n style={{ height: \"1rem\", width: \"1rem\" }}\n className={className}\n {...props}\n >\n <path d=\"M216 32H88a8 8 0 0 0-8 8v40H40a8 8 0 0 0-8 8v128a8 8 0 0 0 8 8h128a8 8 0 0 0 8-8v-40h40a8 8 0 0 0 8-8V40a8 8 0 0 0-8-8Zm-56 176H48V96h112Zm48-48h-32V88a8 8 0 0 0-8-8H96V48h112Z\" />\n </svg>\n );\n}\n\nexport const StopIcon = (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 256 256\"\n fill=\"currentColor\"\n style={{ height: \"1rem\", width: \"1rem\" }}\n >\n <path d=\"M128 24a104 104 0 1 0 104 104A104.11 104.11 0 0 0 128 24Zm0 192a88 88 0 1 1 88-88 88.1 88.1 0 0 1-88 88Zm24-120h-48a8 8 0 0 0-8 8v48a8 8 0 0 0 8 8h48a8 8 0 0 0 8-8v-48a8 8 0 0 0-8-8Zm-8 48h-32v-32h32Z\" />\n </svg>\n);\n\nexport const RegenerateIcon = (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 256 256\"\n fill=\"currentColor\"\n style={{ height: \"1rem\", width: \"1rem\" }}\n >\n <path d=\"M197.67 186.37a8 8 0 0 1 0 11.29C196.58 198.73 170.82 224 128 224c-37.39 0-64.53-22.4-80-39.85V208a8 8 0 0 1-16 0v-48a8 8 0 0 1 8-8h48a8 8 0 0 1 0 16H55.44C67.76 183.35 93 208 128 208c36 0 58.14-21.46 58.36-21.68a8 8 0 0 1 11.31.05ZM216 40a8 8 0 0 0-8 8v23.85C192.53 54.4 165.39 32 128 32c-42.82 0-68.58 25.27-69.66 26.34a8 8 0 0 0 11.3 11.34C69.86 69.46 92 48 128 48c35 0 60.24 24.65 72.56 40H168a8 8 0 0 0 0 16h48a8 8 0 0 0 8-8V48a8 8 0 0 0-8-8Z\" />\n </svg>\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAa,QAAAA,aAAY;AACzB,OAAO,mBAA4C;;;ACCnD,SAAa,YAAY;AACzB,SAAS,SAAS,yBAAyB;AAC3C,SAAS,eAAe,sBAAsB;;;ACF9C,YAAY,WAAW;AAMhB,SAAS,mBAAmB,EAAE,UAAU,IAAK,GAA4B;AAC9E,QAAM,CAAC,UAAU,WAAW,IAAU,eAAkB,KAAK;AAE7D,QAAM,kBAAkB,CAAC,UAAkB;AAX7C;AAYI,QAAI,OAAO,WAAW,eAAe,GAAC,eAAU,cAAV,mBAAqB,YAAW;AACpE;AAAA,IACF;AAEA,QAAI,CAAC,OAAO;AACV;AAAA,IACF;AAEA,cAAU,UAAU,UAAU,KAAK,EAAE,KAAK,MAAM;AAC9C,kBAAY,IAAI;AAEhB,iBAAW,MAAM;AACf,oBAAY,KAAK;AAAA,MACnB,GAAG,OAAO;AAAA,IACZ,CAAC;AAAA,EACH;AAEA,SAAO,EAAE,UAAU,g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,IAA2C;AAA3C,iBAAE,YAAU,WAAW,OA9B9B,IA8BO,IAAkC,kBAAlC,IAAkC,CAAhC,YAAU,aAAW;AAC1B,QAAI,SAAS,QAAQ;AACnB,UAAI,SAAS,CAAC,KAAK,UAAK;AACtB,eACE,gBAAAA;AAAA,UAAC;AAAA;AAAA,YACC,OAAO;AAAA,cACL,WAAW;AAAA,cACX,WAAW;AAAA,YACb;AAAA,YACD;AAAA;AAAA,QAED;AAAA,MAEJ;AAEA,eAAS,CAAC,IAAK,SAAS,CAAC,EAAa,QAAQ,YAAO,QAAG;AAAA,IAC1D;AAEA,UAAM,QAAQ,iBAAiB,KAAK,aAAa,EAAE;AAEnD,QAAI,QAAQ;AACV,aACE,gBAAAA,KAAC,uCAAK,aAA0B,QAA/B,EACE,WACH;AAAA,IAEJ;AAEA,WACE,gBAAAA;AAAA,MAAC;AAAA;AAAA,QAEC,UAAW,SAAS,MAAM,CAAC,KAAM;AAAA,QACjC,OAAO,OAAO,QAAQ,EAAE,QAAQ,OAAO,EAAE;AAAA,SACrC;AAAA,MAHC,KAAK,OAAO;AAAA,IAInB;AAAA,EAEJ;AACF;","names":["memo","jsx","jsxs","jsx","memo"]}
@@ -1,12 +1,332 @@
1
- import {
2
- Messages
3
- } from "../../chunk-3M4HWSE7.mjs";
4
- import "../../chunk-GWGHQNRI.mjs";
5
- import "../../chunk-DPRH4HX3.mjs";
6
- import "../../chunk-OF66AL5Z.mjs";
7
- import "../../chunk-7YXG7D47.mjs";
8
- import "../../chunk-POVINPXX.mjs";
9
- import "../../chunk-MRXNTQOX.mjs";
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
32
+
33
+ // src/components/chat/Messages.tsx
34
+ import React3, { useEffect, useMemo as useMemo2 } from "react";
35
+
36
+ // src/components/chat/ChatContext.tsx
37
+ import React, { useMemo } from "react";
38
+
39
+ // src/components/chat/Icons.tsx
40
+ import { jsx, jsxs } from "react/jsx-runtime";
41
+ function CheckIcon(_a) {
42
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
43
+ return /* @__PURE__ */ jsx(
44
+ "svg",
45
+ __spreadProps(__spreadValues({
46
+ xmlns: "http://www.w3.org/2000/svg",
47
+ viewBox: "0 0 256 256",
48
+ fill: "currentColor",
49
+ style: { height: "1rem", width: "1rem" },
50
+ className
51
+ }, props), {
52
+ children: /* @__PURE__ */ jsx("path", { d: "m229.66 77.66-128 128a8 8 0 0 1-11.32 0l-56-56a8 8 0 0 1 11.32-11.32L96 188.69 218.34 66.34a8 8 0 0 1 11.32 11.32Z" })
53
+ })
54
+ );
55
+ }
56
+ function DownloadIcon(_a) {
57
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
58
+ return /* @__PURE__ */ jsx(
59
+ "svg",
60
+ __spreadProps(__spreadValues({
61
+ xmlns: "http://www.w3.org/2000/svg",
62
+ viewBox: "0 0 256 256",
63
+ fill: "currentColor",
64
+ style: { height: "1rem", width: "1rem" },
65
+ className
66
+ }, props), {
67
+ children: /* @__PURE__ */ jsx("path", { d: "M224 152v56a16 16 0 0 1-16 16H48a16 16 0 0 1-16-16v-56a8 8 0 0 1 16 0v56h160v-56a8 8 0 0 1 16 0Zm-101.66 5.66a8 8 0 0 0 11.32 0l40-40a8 8 0 0 0-11.32-11.32L136 132.69V40a8 8 0 0 0-16 0v92.69l-26.34-26.35a8 8 0 0 0-11.32 11.32Z" })
68
+ })
69
+ );
70
+ }
71
+ function CopyIcon(_a) {
72
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
73
+ return /* @__PURE__ */ jsx(
74
+ "svg",
75
+ __spreadProps(__spreadValues({
76
+ xmlns: "http://www.w3.org/2000/svg",
77
+ viewBox: "0 0 256 256",
78
+ fill: "currentColor",
79
+ style: { height: "1rem", width: "1rem" },
80
+ className
81
+ }, props), {
82
+ children: /* @__PURE__ */ jsx("path", { d: "M216 32H88a8 8 0 0 0-8 8v40H40a8 8 0 0 0-8 8v128a8 8 0 0 0 8 8h128a8 8 0 0 0 8-8v-40h40a8 8 0 0 0 8-8V40a8 8 0 0 0-8-8Zm-56 176H48V96h112Zm48-48h-32V88a8 8 0 0 0-8-8H96V48h112Z" })
83
+ })
84
+ );
85
+ }
86
+
87
+ // src/components/chat/ChatContext.tsx
88
+ import { jsx as jsx2 } from "react/jsx-runtime";
89
+ var ChatContext = React.createContext(void 0);
90
+ function useChatContext() {
91
+ const context = React.useContext(ChatContext);
92
+ if (context === void 0) {
93
+ throw new Error(
94
+ "Context not found. Did you forget to wrap your app in a <ChatContextProvider> component?"
95
+ );
96
+ }
97
+ return context;
98
+ }
99
+
100
+ // src/components/chat/Messages.tsx
101
+ import { nanoid } from "nanoid";
102
+
103
+ // src/components/chat/Markdown.tsx
104
+ import { memo as memo2 } from "react";
105
+ import ReactMarkdown from "react-markdown";
106
+
107
+ // src/components/chat/CodeBlock.tsx
108
+ import { memo } from "react";
109
+ import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
110
+ import { vscDarkPlus as highlightStyle } from "react-syntax-highlighter/dist/esm/styles/prism";
111
+
112
+ // src/hooks/use-copy-to-clipboard.tsx
113
+ import * as React2 from "react";
114
+ function useCopyToClipboard({ timeout = 2e3 }) {
115
+ const [isCopied, setIsCopied] = React2.useState(false);
116
+ const copyToClipboard = (value) => {
117
+ var _a;
118
+ if (typeof window === "undefined" || !((_a = navigator.clipboard) == null ? void 0 : _a.writeText)) {
119
+ return;
120
+ }
121
+ if (!value) {
122
+ return;
123
+ }
124
+ navigator.clipboard.writeText(value).then(() => {
125
+ setIsCopied(true);
126
+ setTimeout(() => {
127
+ setIsCopied(false);
128
+ }, timeout);
129
+ });
130
+ };
131
+ return { isCopied, copyToClipboard };
132
+ }
133
+
134
+ // src/components/chat/CodeBlock.tsx
135
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
136
+ var programmingLanguages = {
137
+ javascript: ".js",
138
+ python: ".py",
139
+ java: ".java",
140
+ c: ".c",
141
+ cpp: ".cpp",
142
+ "c++": ".cpp",
143
+ "c#": ".cs",
144
+ ruby: ".rb",
145
+ php: ".php",
146
+ swift: ".swift",
147
+ "objective-c": ".m",
148
+ kotlin: ".kt",
149
+ typescript: ".ts",
150
+ go: ".go",
151
+ perl: ".pl",
152
+ rust: ".rs",
153
+ scala: ".scala",
154
+ haskell: ".hs",
155
+ lua: ".lua",
156
+ shell: ".sh",
157
+ sql: ".sql",
158
+ html: ".html",
159
+ css: ".css"
160
+ // add more file extensions here, make sure the key is same as language prop in CodeBlock.tsx component
161
+ };
162
+ var generateRandomString = (length, lowercase = false) => {
163
+ const chars = "ABCDEFGHJKLMNPQRSTUVWXY3456789";
164
+ let result = "";
165
+ for (let i = 0; i < length; i++) {
166
+ result += chars.charAt(Math.floor(Math.random() * chars.length));
167
+ }
168
+ return lowercase ? result.toLowerCase() : result;
169
+ };
170
+ var CodeBlock = memo(({ language, value }) => {
171
+ const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2e3 });
172
+ const downloadAsFile = () => {
173
+ if (typeof window === "undefined") {
174
+ return;
175
+ }
176
+ const fileExtension = programmingLanguages[language] || ".file";
177
+ const suggestedFileName = `file-${generateRandomString(3, true)}${fileExtension}`;
178
+ const fileName = window.prompt("Enter file name", suggestedFileName);
179
+ if (!fileName) {
180
+ return;
181
+ }
182
+ const blob = new Blob([value], { type: "text/plain" });
183
+ const url = URL.createObjectURL(blob);
184
+ const link = document.createElement("a");
185
+ link.download = fileName;
186
+ link.href = url;
187
+ link.style.display = "none";
188
+ document.body.appendChild(link);
189
+ link.click();
190
+ document.body.removeChild(link);
191
+ URL.revokeObjectURL(url);
192
+ };
193
+ const onCopy = () => {
194
+ if (isCopied)
195
+ return;
196
+ copyToClipboard(value);
197
+ };
198
+ return /* @__PURE__ */ jsxs2("div", { className: "copilotKitCodeBlock", children: [
199
+ /* @__PURE__ */ jsxs2("div", { className: "copilotKitCodeBlockToolbar", children: [
200
+ /* @__PURE__ */ jsx3("span", { className: "copilotKitCodeBlockToolbarLanguage", children: language }),
201
+ /* @__PURE__ */ jsxs2("div", { className: "copilotKitCodeBlockToolbarButtons", children: [
202
+ /* @__PURE__ */ jsxs2("button", { className: "copilotKitCodeBlockToolbarButton", onClick: downloadAsFile, children: [
203
+ /* @__PURE__ */ jsx3(DownloadIcon, {}),
204
+ /* @__PURE__ */ jsx3("span", { className: "sr-only", children: "Download" })
205
+ ] }),
206
+ /* @__PURE__ */ jsxs2("button", { className: "copilotKitCodeBlockToolbarButton", onClick: onCopy, children: [
207
+ isCopied ? /* @__PURE__ */ jsx3(CheckIcon, {}) : /* @__PURE__ */ jsx3(CopyIcon, {}),
208
+ /* @__PURE__ */ jsx3("span", { className: "sr-only", children: "Copy code" })
209
+ ] })
210
+ ] })
211
+ ] }),
212
+ /* @__PURE__ */ jsx3(
213
+ SyntaxHighlighter,
214
+ {
215
+ language,
216
+ style: highlightStyle,
217
+ PreTag: "div",
218
+ customStyle: {
219
+ margin: 0,
220
+ borderBottomLeftRadius: "0.375rem",
221
+ borderBottomRightRadius: "0.375rem"
222
+ },
223
+ children: value
224
+ }
225
+ )
226
+ ] });
227
+ });
228
+ CodeBlock.displayName = "CodeBlock";
229
+
230
+ // src/components/chat/Markdown.tsx
231
+ import remarkGfm from "remark-gfm";
232
+ import remarkMath from "remark-math";
233
+ import { jsx as jsx4 } from "react/jsx-runtime";
234
+ var MemoizedReactMarkdown = memo2(
235
+ ReactMarkdown,
236
+ (prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.className === nextProps.className
237
+ );
238
+ var Markdown = ({ content }) => {
239
+ return /* @__PURE__ */ jsx4("div", { className: "copilotKitMarkdown", children: /* @__PURE__ */ jsx4(MemoizedReactMarkdown, { components, remarkPlugins: [remarkGfm, remarkMath], children: content }) });
240
+ };
241
+ var components = {
242
+ p({ children }) {
243
+ return /* @__PURE__ */ jsx4("p", { children });
244
+ },
245
+ code(_a) {
246
+ var _b = _a, { children, className, inline } = _b, props = __objRest(_b, ["children", "className", "inline"]);
247
+ if (children.length) {
248
+ if (children[0] == "\u258D") {
249
+ return /* @__PURE__ */ jsx4(
250
+ "span",
251
+ {
252
+ style: {
253
+ animation: "pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite",
254
+ marginTop: "0.25rem"
255
+ },
256
+ children: "\u258D"
257
+ }
258
+ );
259
+ }
260
+ children[0] = children[0].replace("`\u258D`", "\u258D");
261
+ }
262
+ const match = /language-(\w+)/.exec(className || "");
263
+ if (inline) {
264
+ return /* @__PURE__ */ jsx4("code", __spreadProps(__spreadValues({ className }, props), { children }));
265
+ }
266
+ return /* @__PURE__ */ jsx4(
267
+ CodeBlock,
268
+ __spreadValues({
269
+ language: match && match[1] || "",
270
+ value: String(children).replace(/\n$/, "")
271
+ }, props),
272
+ Math.random()
273
+ );
274
+ }
275
+ };
276
+
277
+ // src/components/chat/Messages.tsx
278
+ import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
279
+ var Messages = ({ messages, inProgress }) => {
280
+ const context = useChatContext();
281
+ const initialMessages = useMemo2(
282
+ () => makeInitialMessages(context.labels.initial),
283
+ [context.labels.initial]
284
+ );
285
+ messages = [...initialMessages, ...messages];
286
+ const messagesEndRef = React3.useRef(null);
287
+ const scrollToBottom = () => {
288
+ if (messagesEndRef.current) {
289
+ messagesEndRef.current.scrollIntoView({
290
+ behavior: "auto"
291
+ });
292
+ }
293
+ };
294
+ useEffect(() => {
295
+ scrollToBottom();
296
+ }, [messages]);
297
+ return /* @__PURE__ */ jsxs3("div", { className: "copilotKitMessages", children: [
298
+ messages.map((message, index) => {
299
+ const isCurrentMessage = index === messages.length - 1;
300
+ if (message.role === "user") {
301
+ return /* @__PURE__ */ jsx5("div", { className: "copilotKitMessage copilotKitUserMessage", children: message.content }, index);
302
+ } else if (message.role == "assistant") {
303
+ if (isCurrentMessage && inProgress && !message.content) {
304
+ return /* @__PURE__ */ jsx5("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: context.icons.spinnerIcon }, index);
305
+ } else if ((!inProgress || index != messages.length - 1) && !message.content && message.function_call) {
306
+ return /* @__PURE__ */ jsx5("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: context.labels.done }, index);
307
+ } else {
308
+ return /* @__PURE__ */ jsx5("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: /* @__PURE__ */ jsx5(Markdown, { content: message.content }) }, index);
309
+ }
310
+ }
311
+ }),
312
+ /* @__PURE__ */ jsx5("div", { ref: messagesEndRef })
313
+ ] });
314
+ };
315
+ function makeInitialMessages(initial) {
316
+ let initialArray = [];
317
+ if (initial) {
318
+ if (Array.isArray(initial)) {
319
+ initialArray.push(...initial);
320
+ } else {
321
+ initialArray.push(initial);
322
+ }
323
+ }
324
+ return initialArray.map((message) => ({
325
+ id: nanoid(),
326
+ role: "assistant",
327
+ content: message
328
+ }));
329
+ }
10
330
  export {
11
331
  Messages
12
332
  };