@copilotkit/react-ui 0.22.0-multi-release-alpha.0 → 0.22.0-multi-feature-usecopilotreadable.3

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 (45) hide show
  1. package/.turbo/turbo-build.log +89 -93
  2. package/CHANGELOG.md +40 -4
  3. package/dist/components/chat/Button.mjs +6 -30
  4. package/dist/components/chat/Button.mjs.map +1 -1
  5. package/dist/components/chat/Chat.mjs +16 -1198
  6. package/dist/components/chat/Chat.mjs.map +1 -1
  7. package/dist/components/chat/ChatContext.mjs +7 -217
  8. package/dist/components/chat/ChatContext.mjs.map +1 -1
  9. package/dist/components/chat/CodeBlock.mjs +8 -483
  10. package/dist/components/chat/CodeBlock.mjs.map +1 -1
  11. package/dist/components/chat/Header.mjs +6 -23
  12. package/dist/components/chat/Header.mjs.map +1 -1
  13. package/dist/components/chat/Icons.mjs +14 -218
  14. package/dist/components/chat/Icons.mjs.map +1 -1
  15. package/dist/components/chat/Input.mjs +7 -116
  16. package/dist/components/chat/Input.mjs.map +1 -1
  17. package/dist/components/chat/Markdown.mjs +7 -547
  18. package/dist/components/chat/Markdown.mjs.map +1 -1
  19. package/dist/components/chat/Messages.mjs +9 -678
  20. package/dist/components/chat/Messages.mjs.map +1 -1
  21. package/dist/components/chat/Popup.mjs +17 -1207
  22. package/dist/components/chat/Popup.mjs.map +1 -1
  23. package/dist/components/chat/Response.mjs +6 -23
  24. package/dist/components/chat/Response.mjs.map +1 -1
  25. package/dist/components/chat/Sidebar.mjs +17 -1218
  26. package/dist/components/chat/Sidebar.mjs.map +1 -1
  27. package/dist/components/chat/Textarea.mjs +4 -48
  28. package/dist/components/chat/Textarea.mjs.map +1 -1
  29. package/dist/components/chat/Window.mjs +4 -105
  30. package/dist/components/chat/Window.mjs.map +1 -1
  31. package/dist/components/chat/index.mjs +24 -1225
  32. package/dist/components/chat/index.mjs.map +1 -1
  33. package/dist/components/chat/props.mjs +1 -0
  34. package/dist/components/index.mjs +25 -1225
  35. package/dist/components/index.mjs.map +1 -1
  36. package/dist/context/index.mjs +1 -0
  37. package/dist/hooks/index.mjs +1 -0
  38. package/dist/hooks/use-copy-to-clipboard.mjs +4 -21
  39. package/dist/hooks/use-copy-to-clipboard.mjs.map +1 -1
  40. package/dist/index.mjs +28 -1225
  41. package/dist/index.mjs.map +1 -1
  42. package/dist/lib/utils.mjs +3 -20
  43. package/dist/lib/utils.mjs.map +1 -1
  44. package/dist/types/index.mjs +1 -0
  45. package/package.json +6 -6
@@ -1,681 +1,12 @@
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
- import { decodeResult } from "@copilotkit/shared";
103
-
104
- // src/components/chat/Markdown.tsx
105
- import { memo as memo2 } from "react";
106
- import ReactMarkdown from "react-markdown";
107
-
108
- // src/components/chat/CodeBlock.tsx
109
- import { memo } from "react";
110
- import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
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
- var highlightStyle = {
230
- 'pre[class*="language-"]': {
231
- color: "#d4d4d4",
232
- fontSize: "13px",
233
- textShadow: "none",
234
- fontFamily: 'Menlo, Monaco, Consolas, "Andale Mono", "Ubuntu Mono", "Courier New", monospace',
235
- direction: "ltr",
236
- textAlign: "left",
237
- whiteSpace: "pre",
238
- wordSpacing: "normal",
239
- wordBreak: "normal",
240
- lineHeight: "1.5",
241
- MozTabSize: "4",
242
- OTabSize: "4",
243
- tabSize: "4",
244
- WebkitHyphens: "none",
245
- MozHyphens: "none",
246
- msHyphens: "none",
247
- hyphens: "none",
248
- padding: "1em",
249
- margin: ".5em 0",
250
- overflow: "auto",
251
- background: "#1e1e1e"
252
- },
253
- 'code[class*="language-"]': {
254
- color: "#d4d4d4",
255
- fontSize: "13px",
256
- textShadow: "none",
257
- fontFamily: 'Menlo, Monaco, Consolas, "Andale Mono", "Ubuntu Mono", "Courier New", monospace',
258
- direction: "ltr",
259
- textAlign: "left",
260
- whiteSpace: "pre",
261
- wordSpacing: "normal",
262
- wordBreak: "normal",
263
- lineHeight: "1.5",
264
- MozTabSize: "4",
265
- OTabSize: "4",
266
- tabSize: "4",
267
- WebkitHyphens: "none",
268
- MozHyphens: "none",
269
- msHyphens: "none",
270
- hyphens: "none"
271
- },
272
- 'pre[class*="language-"]::selection': {
273
- textShadow: "none",
274
- background: "#264F78"
275
- },
276
- 'code[class*="language-"]::selection': {
277
- textShadow: "none",
278
- background: "#264F78"
279
- },
280
- 'pre[class*="language-"] *::selection': {
281
- textShadow: "none",
282
- background: "#264F78"
283
- },
284
- 'code[class*="language-"] *::selection': {
285
- textShadow: "none",
286
- background: "#264F78"
287
- },
288
- ':not(pre) > code[class*="language-"]': {
289
- padding: ".1em .3em",
290
- borderRadius: ".3em",
291
- color: "#db4c69",
292
- background: "#1e1e1e"
293
- },
294
- ".namespace": {
295
- Opacity: ".7"
296
- },
297
- "doctype.doctype-tag": {
298
- color: "#569CD6"
299
- },
300
- "doctype.name": {
301
- color: "#9cdcfe"
302
- },
303
- comment: {
304
- color: "#6a9955"
305
- },
306
- prolog: {
307
- color: "#6a9955"
308
- },
309
- punctuation: {
310
- color: "#d4d4d4"
311
- },
312
- ".language-html .language-css .token.punctuation": {
313
- color: "#d4d4d4"
314
- },
315
- ".language-html .language-javascript .token.punctuation": {
316
- color: "#d4d4d4"
317
- },
318
- property: {
319
- color: "#9cdcfe"
320
- },
321
- tag: {
322
- color: "#569cd6"
323
- },
324
- boolean: {
325
- color: "#569cd6"
326
- },
327
- number: {
328
- color: "#b5cea8"
329
- },
330
- constant: {
331
- color: "#9cdcfe"
332
- },
333
- symbol: {
334
- color: "#b5cea8"
335
- },
336
- inserted: {
337
- color: "#b5cea8"
338
- },
339
- unit: {
340
- color: "#b5cea8"
341
- },
342
- selector: {
343
- color: "#d7ba7d"
344
- },
345
- "attr-name": {
346
- color: "#9cdcfe"
347
- },
348
- string: {
349
- color: "#ce9178"
350
- },
351
- char: {
352
- color: "#ce9178"
353
- },
354
- builtin: {
355
- color: "#ce9178"
356
- },
357
- deleted: {
358
- color: "#ce9178"
359
- },
360
- ".language-css .token.string.url": {
361
- textDecoration: "underline"
362
- },
363
- operator: {
364
- color: "#d4d4d4"
365
- },
366
- entity: {
367
- color: "#569cd6"
368
- },
369
- "operator.arrow": {
370
- color: "#569CD6"
371
- },
372
- atrule: {
373
- color: "#ce9178"
374
- },
375
- "atrule.rule": {
376
- color: "#c586c0"
377
- },
378
- "atrule.url": {
379
- color: "#9cdcfe"
380
- },
381
- "atrule.url.function": {
382
- color: "#dcdcaa"
383
- },
384
- "atrule.url.punctuation": {
385
- color: "#d4d4d4"
386
- },
387
- keyword: {
388
- color: "#569CD6"
389
- },
390
- "keyword.module": {
391
- color: "#c586c0"
392
- },
393
- "keyword.control-flow": {
394
- color: "#c586c0"
395
- },
396
- function: {
397
- color: "#dcdcaa"
398
- },
399
- "function.maybe-class-name": {
400
- color: "#dcdcaa"
401
- },
402
- regex: {
403
- color: "#d16969"
404
- },
405
- important: {
406
- color: "#569cd6"
407
- },
408
- italic: {
409
- fontStyle: "italic"
410
- },
411
- "class-name": {
412
- color: "#4ec9b0"
413
- },
414
- "maybe-class-name": {
415
- color: "#4ec9b0"
416
- },
417
- console: {
418
- color: "#9cdcfe"
419
- },
420
- parameter: {
421
- color: "#9cdcfe"
422
- },
423
- interpolation: {
424
- color: "#9cdcfe"
425
- },
426
- "punctuation.interpolation-punctuation": {
427
- color: "#569cd6"
428
- },
429
- variable: {
430
- color: "#9cdcfe"
431
- },
432
- "imports.maybe-class-name": {
433
- color: "#9cdcfe"
434
- },
435
- "exports.maybe-class-name": {
436
- color: "#9cdcfe"
437
- },
438
- escape: {
439
- color: "#d7ba7d"
440
- },
441
- "tag.punctuation": {
442
- color: "#808080"
443
- },
444
- cdata: {
445
- color: "#808080"
446
- },
447
- "attr-value": {
448
- color: "#ce9178"
449
- },
450
- "attr-value.punctuation": {
451
- color: "#ce9178"
452
- },
453
- "attr-value.punctuation.attr-equals": {
454
- color: "#d4d4d4"
455
- },
456
- namespace: {
457
- color: "#4ec9b0"
458
- },
459
- 'pre[class*="language-javascript"]': {
460
- color: "#9cdcfe"
461
- },
462
- 'code[class*="language-javascript"]': {
463
- color: "#9cdcfe"
464
- },
465
- 'pre[class*="language-jsx"]': {
466
- color: "#9cdcfe"
467
- },
468
- 'code[class*="language-jsx"]': {
469
- color: "#9cdcfe"
470
- },
471
- 'pre[class*="language-typescript"]': {
472
- color: "#9cdcfe"
473
- },
474
- 'code[class*="language-typescript"]': {
475
- color: "#9cdcfe"
476
- },
477
- 'pre[class*="language-tsx"]': {
478
- color: "#9cdcfe"
479
- },
480
- 'code[class*="language-tsx"]': {
481
- color: "#9cdcfe"
482
- },
483
- 'pre[class*="language-css"]': {
484
- color: "#ce9178"
485
- },
486
- 'code[class*="language-css"]': {
487
- color: "#ce9178"
488
- },
489
- 'pre[class*="language-html"]': {
490
- color: "#d4d4d4"
491
- },
492
- 'code[class*="language-html"]': {
493
- color: "#d4d4d4"
494
- },
495
- ".language-regex .token.anchor": {
496
- color: "#dcdcaa"
497
- },
498
- ".language-html .token.punctuation": {
499
- color: "#808080"
500
- },
501
- 'pre[class*="language-"] > code[class*="language-"]': {
502
- position: "relative",
503
- zIndex: "1"
504
- },
505
- ".line-highlight.line-highlight": {
506
- background: "#f7ebc6",
507
- boxShadow: "inset 5px 0 0 #f7d87c",
508
- zIndex: "0"
509
- }
510
- };
511
-
512
- // src/components/chat/Markdown.tsx
513
- import remarkGfm from "remark-gfm";
514
- import remarkMath from "remark-math";
515
- import { jsx as jsx4 } from "react/jsx-runtime";
516
- var MemoizedReactMarkdown = memo2(
517
- ReactMarkdown,
518
- (prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.className === nextProps.className
519
- );
520
- var Markdown = ({ content }) => {
521
- return /* @__PURE__ */ jsx4("div", { className: "copilotKitMarkdown", children: /* @__PURE__ */ jsx4(MemoizedReactMarkdown, { components, remarkPlugins: [remarkGfm, remarkMath], children: content }) });
522
- };
523
- var components = {
524
- p({ children }) {
525
- return /* @__PURE__ */ jsx4("p", { children });
526
- },
527
- a(_a) {
528
- var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
529
- return /* @__PURE__ */ jsx4(
530
- "a",
531
- __spreadProps(__spreadValues({
532
- style: { color: "blue", textDecoration: "underline" }
533
- }, props), {
534
- target: "_blank",
535
- rel: "noopener noreferrer",
536
- children
537
- })
538
- );
539
- },
540
- code(_c) {
541
- var _d = _c, { children, className, inline } = _d, props = __objRest(_d, ["children", "className", "inline"]);
542
- if (children.length) {
543
- if (children[0] == "\u258D") {
544
- return /* @__PURE__ */ jsx4(
545
- "span",
546
- {
547
- style: {
548
- animation: "pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite",
549
- marginTop: "0.25rem"
550
- },
551
- children: "\u258D"
552
- }
553
- );
554
- }
555
- children[0] = children[0].replace("`\u258D`", "\u258D");
556
- }
557
- const match = /language-(\w+)/.exec(className || "");
558
- if (inline) {
559
- return /* @__PURE__ */ jsx4("code", __spreadProps(__spreadValues({ className }, props), { children }));
560
- }
561
- return /* @__PURE__ */ jsx4(
562
- CodeBlock,
563
- __spreadValues({
564
- language: match && match[1] || "",
565
- value: String(children).replace(/\n$/, "")
566
- }, props),
567
- Math.random()
568
- );
569
- }
570
- };
571
-
572
- // src/components/chat/Messages.tsx
573
- import { useCopilotContext } from "@copilotkit/react-core";
574
- import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
575
- var Messages = ({ messages, inProgress }) => {
576
- const { chatComponentsCache } = useCopilotContext();
577
- const context = useChatContext();
578
- const initialMessages = useMemo2(
579
- () => makeInitialMessages(context.labels.initial),
580
- [context.labels.initial]
581
- );
582
- messages = [...initialMessages, ...messages];
583
- const functionResults = {};
584
- for (let i = 0; i < messages.length; i++) {
585
- if (messages[i].role === "assistant" && messages[i].function_call) {
586
- const id = messages[i].id;
587
- if (i + 1 < messages.length && messages[i + 1].role === "function") {
588
- functionResults[id] = decodeResult(messages[i + 1].content || "");
589
- }
590
- }
591
- }
592
- const messagesEndRef = React3.useRef(null);
593
- const scrollToBottom = () => {
594
- if (messagesEndRef.current) {
595
- messagesEndRef.current.scrollIntoView({
596
- behavior: "auto"
597
- });
598
- }
599
- };
600
- useEffect(() => {
601
- scrollToBottom();
602
- }, [messages]);
603
- return /* @__PURE__ */ jsxs3("div", { className: "copilotKitMessages", children: [
604
- messages.map((message, index) => {
605
- var _a, _b, _c;
606
- const isCurrentMessage = index === messages.length - 1;
607
- if (message.role === "user") {
608
- return /* @__PURE__ */ jsx5("div", { className: "copilotKitMessage copilotKitUserMessage", children: message.content }, index);
609
- } else if (message.role == "assistant") {
610
- if (isCurrentMessage && inProgress && !message.content && !message.partialFunctionCall) {
611
- return /* @__PURE__ */ jsx5("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: context.icons.spinnerIcon }, index);
612
- } else if (message.function_call || message.partialFunctionCall) {
613
- const functionCallName = ((_a = message.function_call) == null ? void 0 : _a.name) || ((_b = message.partialFunctionCall) == null ? void 0 : _b.name);
614
- if (chatComponentsCache.current !== null && chatComponentsCache.current[functionCallName]) {
615
- const render = chatComponentsCache.current[functionCallName];
616
- if (typeof render === "string") {
617
- if (isCurrentMessage && inProgress) {
618
- return /* @__PURE__ */ jsxs3("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
619
- context.icons.spinnerIcon,
620
- " ",
621
- /* @__PURE__ */ jsx5("span", { className: "inProgressLabel", children: render })
622
- ] }, index);
623
- } else {
624
- return null;
625
- }
626
- } else {
627
- const args = message.function_call ? JSON.parse(message.function_call.arguments || "{}") : (_c = message.partialFunctionCall) == null ? void 0 : _c.arguments;
628
- let status = "inProgress";
629
- if (functionResults[message.id] !== void 0) {
630
- status = "complete";
631
- } else if (message.function_call) {
632
- status = "executing";
633
- }
634
- const toRender = render({
635
- status,
636
- args,
637
- result: functionResults[message.id]
638
- });
639
- if (!toRender && status === "complete") {
640
- return null;
641
- }
642
- if (typeof toRender === "string") {
643
- return /* @__PURE__ */ jsxs3("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
644
- isCurrentMessage && inProgress && context.icons.spinnerIcon,
645
- " ",
646
- toRender
647
- ] }, index);
648
- } else {
649
- return /* @__PURE__ */ jsx5("div", { className: "copilotKitCustomAssistantMessage", children: toRender }, index);
650
- }
651
- }
652
- } else if ((!inProgress || !isCurrentMessage) && message.function_call) {
653
- return null;
654
- } else {
655
- return /* @__PURE__ */ jsx5("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: context.icons.spinnerIcon }, index);
656
- }
657
- }
658
- return /* @__PURE__ */ jsx5("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: /* @__PURE__ */ jsx5(Markdown, { content: message.content }) }, index);
659
- }
660
- }),
661
- /* @__PURE__ */ jsx5("div", { ref: messagesEndRef })
662
- ] });
663
- };
664
- function makeInitialMessages(initial) {
665
- let initialArray = [];
666
- if (initial) {
667
- if (Array.isArray(initial)) {
668
- initialArray.push(...initial);
669
- } else {
670
- initialArray.push(initial);
671
- }
672
- }
673
- return initialArray.map((message) => ({
674
- id: nanoid(),
675
- role: "assistant",
676
- content: message
677
- }));
678
- }
1
+ import {
2
+ Messages
3
+ } from "../../chunk-73EBDGYK.mjs";
4
+ import "../../chunk-WDHLWSSU.mjs";
5
+ import "../../chunk-MBYUBR3F.mjs";
6
+ import "../../chunk-7LMXXGJT.mjs";
7
+ import "../../chunk-7YXG7D47.mjs";
8
+ import "../../chunk-54JAUBUJ.mjs";
9
+ import "../../chunk-MRXNTQOX.mjs";
679
10
  export {
680
11
  Messages
681
12
  };