@copilotkit/react-ui 1.0.3 → 1.0.4

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 (56) hide show
  1. package/.turbo/turbo-build.log +44 -44
  2. package/CHANGELOG.md +10 -0
  3. package/README.md +1 -1
  4. package/dist/{chunk-DYXI54LF.mjs → chunk-4Z2WDXSK.mjs} +1 -1
  5. package/dist/chunk-4Z2WDXSK.mjs.map +1 -0
  6. package/dist/{chunk-MHTQKDHI.mjs → chunk-5BL3YDGU.mjs} +4 -4
  7. package/dist/chunk-5BL3YDGU.mjs.map +1 -0
  8. package/dist/{chunk-ADMZDZCJ.mjs → chunk-DYHXNV2B.mjs} +2 -2
  9. package/dist/{chunk-2K5GFKKP.mjs → chunk-OLL5TU65.mjs} +3 -3
  10. package/dist/{chunk-NYDX3JVD.mjs → chunk-QHAVUMXM.mjs} +2 -2
  11. package/dist/{chunk-LTCJCXCP.mjs → chunk-RMK4ADB6.mjs} +3 -3
  12. package/dist/{chunk-LTCJCXCP.mjs.map → chunk-RMK4ADB6.mjs.map} +1 -1
  13. package/dist/components/chat/Chat.js +2 -2
  14. package/dist/components/chat/Chat.js.map +1 -1
  15. package/dist/components/chat/Chat.mjs +2 -2
  16. package/dist/components/chat/Messages.js.map +1 -1
  17. package/dist/components/chat/Messages.mjs +1 -1
  18. package/dist/components/chat/Modal.js +2 -2
  19. package/dist/components/chat/Modal.js.map +1 -1
  20. package/dist/components/chat/Modal.mjs +3 -3
  21. package/dist/components/chat/Popup.js +2 -2
  22. package/dist/components/chat/Popup.js.map +1 -1
  23. package/dist/components/chat/Popup.mjs +4 -4
  24. package/dist/components/chat/Sidebar.js +2 -2
  25. package/dist/components/chat/Sidebar.js.map +1 -1
  26. package/dist/components/chat/Sidebar.mjs +4 -4
  27. package/dist/components/chat/index.js +2 -2
  28. package/dist/components/chat/index.js.map +1 -1
  29. package/dist/components/chat/index.mjs +5 -5
  30. package/dist/components/index.js +2 -2
  31. package/dist/components/index.js.map +1 -1
  32. package/dist/components/index.mjs +5 -5
  33. package/dist/hooks/index.js +2 -2
  34. package/dist/hooks/index.js.map +1 -1
  35. package/dist/hooks/index.mjs +1 -1
  36. package/dist/hooks/use-copilot-chat-suggestions.js +2 -2
  37. package/dist/hooks/use-copilot-chat-suggestions.js.map +1 -1
  38. package/dist/hooks/use-copilot-chat-suggestions.mjs +1 -1
  39. package/dist/index.js +4 -4
  40. package/dist/index.js.map +1 -1
  41. package/dist/index.mjs +6 -6
  42. package/dist/lib/utils.d.ts +1 -2
  43. package/dist/lib/utils.js +2 -9
  44. package/dist/lib/utils.js.map +1 -1
  45. package/dist/lib/utils.mjs +1 -7
  46. package/dist/lib/utils.mjs.map +1 -1
  47. package/package.json +7 -8
  48. package/src/components/chat/Chat.tsx +2 -2
  49. package/src/components/chat/Messages.tsx +0 -1
  50. package/src/hooks/use-copilot-chat-suggestions.tsx +3 -4
  51. package/src/lib/utils.ts +0 -7
  52. package/dist/chunk-DYXI54LF.mjs.map +0 -1
  53. package/dist/chunk-MHTQKDHI.mjs.map +0 -1
  54. /package/dist/{chunk-ADMZDZCJ.mjs.map → chunk-DYHXNV2B.mjs.map} +0 -0
  55. /package/dist/{chunk-2K5GFKKP.mjs.map → chunk-OLL5TU65.mjs.map} +0 -0
  56. /package/dist/{chunk-NYDX3JVD.mjs.map → chunk-QHAVUMXM.mjs.map} +0 -0
package/dist/index.mjs CHANGED
@@ -4,22 +4,22 @@ import "./chunk-JD7BAH7U.mjs";
4
4
  import "./chunk-MRFF7GSQ.mjs";
5
5
  import {
6
6
  CopilotSidebar
7
- } from "./chunk-NYDX3JVD.mjs";
7
+ } from "./chunk-QHAVUMXM.mjs";
8
8
  import "./chunk-WB3YULQ4.mjs";
9
9
  import {
10
10
  CopilotPopup
11
- } from "./chunk-ADMZDZCJ.mjs";
12
- import "./chunk-2K5GFKKP.mjs";
11
+ } from "./chunk-DYHXNV2B.mjs";
12
+ import "./chunk-OLL5TU65.mjs";
13
13
  import "./chunk-B7DNOYVQ.mjs";
14
14
  import "./chunk-SE6DAYSX.mjs";
15
15
  import "./chunk-UC3Y7MWX.mjs";
16
16
  import {
17
17
  CopilotChat
18
- } from "./chunk-MHTQKDHI.mjs";
18
+ } from "./chunk-5BL3YDGU.mjs";
19
19
  import "./chunk-KSCXPA74.mjs";
20
20
  import "./chunk-U6J5DGOE.mjs";
21
21
  import "./chunk-YQFVRDNC.mjs";
22
- import "./chunk-DYXI54LF.mjs";
22
+ import "./chunk-4Z2WDXSK.mjs";
23
23
  import "./chunk-YQ3D5IQV.mjs";
24
24
  import "./chunk-XSUSSWDS.mjs";
25
25
  import {
@@ -31,7 +31,7 @@ import "./chunk-IU3WTXLQ.mjs";
31
31
  import "./chunk-T26KLXLH.mjs";
32
32
  import {
33
33
  useCopilotChatSuggestions
34
- } from "./chunk-LTCJCXCP.mjs";
34
+ } from "./chunk-RMK4ADB6.mjs";
35
35
  import "./chunk-54JAUBUJ.mjs";
36
36
  import "./chunk-VOBX4JOA.mjs";
37
37
  import "./chunk-MRXNTQOX.mjs";
@@ -1,5 +1,4 @@
1
- declare const nanoid: (size?: number | undefined) => string;
2
1
  declare function fetcher<JSON = any>(input: RequestInfo, init?: RequestInit): Promise<JSON>;
3
2
  declare function formatDate(input: string | number | Date): string;
4
3
 
5
- export { fetcher, formatDate, nanoid };
4
+ export { fetcher, formatDate };
package/dist/lib/utils.js CHANGED
@@ -41,15 +41,9 @@ var __async = (__this, __arguments, generator) => {
41
41
  var utils_exports = {};
42
42
  __export(utils_exports, {
43
43
  fetcher: () => fetcher,
44
- formatDate: () => formatDate,
45
- nanoid: () => nanoid
44
+ formatDate: () => formatDate
46
45
  });
47
46
  module.exports = __toCommonJS(utils_exports);
48
- var import_nanoid = require("nanoid");
49
- var nanoid = (0, import_nanoid.customAlphabet)(
50
- "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
51
- 7
52
- );
53
47
  function fetcher(input, init) {
54
48
  return __async(this, null, function* () {
55
49
  const res = yield fetch(input, init);
@@ -77,7 +71,6 @@ function formatDate(input) {
77
71
  // Annotate the CommonJS export names for ESM import in node:
78
72
  0 && (module.exports = {
79
73
  fetcher,
80
- formatDate,
81
- nanoid
74
+ formatDate
82
75
  });
83
76
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/utils.ts"],"sourcesContent":["import { customAlphabet } from \"nanoid\";\n\nexport const nanoid = customAlphabet(\n \"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\",\n 7,\n); // 7-character random string\n\nexport async function fetcher<JSON = any>(input: RequestInfo, init?: RequestInit): Promise<JSON> {\n const res = await fetch(input, init);\n\n if (!res.ok) {\n const json = await res.json();\n if (json.error) {\n const error = new Error(json.error) as Error & {\n status: number;\n };\n error.status = res.status;\n throw error;\n } else {\n throw new Error(\"An unexpected error occurred\");\n }\n }\n\n return res.json();\n}\n\nexport function formatDate(input: string | number | Date): string {\n const date = new Date(input);\n return date.toLocaleDateString(\"en-US\", {\n month: \"long\",\n day: \"numeric\",\n year: \"numeric\",\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA+B;AAExB,IAAM,aAAS;AAAA,EACpB;AAAA,EACA;AACF;AAEA,SAAsB,QAAoB,OAAoB,MAAmC;AAAA;AAC/F,UAAM,MAAM,MAAM,MAAM,OAAO,IAAI;AAEnC,QAAI,CAAC,IAAI,IAAI;AACX,YAAM,OAAO,MAAM,IAAI,KAAK;AAC5B,UAAI,KAAK,OAAO;AACd,cAAM,QAAQ,IAAI,MAAM,KAAK,KAAK;AAGlC,cAAM,SAAS,IAAI;AACnB,cAAM;AAAA,MACR,OAAO;AACL,cAAM,IAAI,MAAM,8BAA8B;AAAA,MAChD;AAAA,IACF;AAEA,WAAO,IAAI,KAAK;AAAA,EAClB;AAAA;AAEO,SAAS,WAAW,OAAuC;AAChE,QAAM,OAAO,IAAI,KAAK,KAAK;AAC3B,SAAO,KAAK,mBAAmB,SAAS;AAAA,IACtC,OAAO;AAAA,IACP,KAAK;AAAA,IACL,MAAM;AAAA,EACR,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../src/lib/utils.ts"],"sourcesContent":["export async function fetcher<JSON = any>(input: RequestInfo, init?: RequestInit): Promise<JSON> {\n const res = await fetch(input, init);\n\n if (!res.ok) {\n const json = await res.json();\n if (json.error) {\n const error = new Error(json.error) as Error & {\n status: number;\n };\n error.status = res.status;\n throw error;\n } else {\n throw new Error(\"An unexpected error occurred\");\n }\n }\n\n return res.json();\n}\n\nexport function formatDate(input: string | number | Date): string {\n const date = new Date(input);\n return date.toLocaleDateString(\"en-US\", {\n month: \"long\",\n day: \"numeric\",\n year: \"numeric\",\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAsB,QAAoB,OAAoB,MAAmC;AAAA;AAC/F,UAAM,MAAM,MAAM,MAAM,OAAO,IAAI;AAEnC,QAAI,CAAC,IAAI,IAAI;AACX,YAAM,OAAO,MAAM,IAAI,KAAK;AAC5B,UAAI,KAAK,OAAO;AACd,cAAM,QAAQ,IAAI,MAAM,KAAK,KAAK;AAGlC,cAAM,SAAS,IAAI;AACnB,cAAM;AAAA,MACR,OAAO;AACL,cAAM,IAAI,MAAM,8BAA8B;AAAA,MAChD;AAAA,IACF;AAEA,WAAO,IAAI,KAAK;AAAA,EAClB;AAAA;AAEO,SAAS,WAAW,OAAuC;AAChE,QAAM,OAAO,IAAI,KAAK,KAAK;AAC3B,SAAO,KAAK,mBAAmB,SAAS;AAAA,IACtC,OAAO;AAAA,IACP,KAAK;AAAA,IACL,MAAM;AAAA,EACR,CAAC;AACH;","names":[]}
@@ -3,11 +3,6 @@ import {
3
3
  } from "../chunk-MRXNTQOX.mjs";
4
4
 
5
5
  // src/lib/utils.ts
6
- import { customAlphabet } from "nanoid";
7
- var nanoid = customAlphabet(
8
- "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
9
- 7
10
- );
11
6
  function fetcher(input, init) {
12
7
  return __async(this, null, function* () {
13
8
  const res = yield fetch(input, init);
@@ -34,7 +29,6 @@ function formatDate(input) {
34
29
  }
35
30
  export {
36
31
  fetcher,
37
- formatDate,
38
- nanoid
32
+ formatDate
39
33
  };
40
34
  //# sourceMappingURL=utils.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/utils.ts"],"sourcesContent":["import { customAlphabet } from \"nanoid\";\n\nexport const nanoid = customAlphabet(\n \"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\",\n 7,\n); // 7-character random string\n\nexport async function fetcher<JSON = any>(input: RequestInfo, init?: RequestInit): Promise<JSON> {\n const res = await fetch(input, init);\n\n if (!res.ok) {\n const json = await res.json();\n if (json.error) {\n const error = new Error(json.error) as Error & {\n status: number;\n };\n error.status = res.status;\n throw error;\n } else {\n throw new Error(\"An unexpected error occurred\");\n }\n }\n\n return res.json();\n}\n\nexport function formatDate(input: string | number | Date): string {\n const date = new Date(input);\n return date.toLocaleDateString(\"en-US\", {\n month: \"long\",\n day: \"numeric\",\n year: \"numeric\",\n });\n}\n"],"mappings":";;;;;AAAA,SAAS,sBAAsB;AAExB,IAAM,SAAS;AAAA,EACpB;AAAA,EACA;AACF;AAEA,SAAsB,QAAoB,OAAoB,MAAmC;AAAA;AAC/F,UAAM,MAAM,MAAM,MAAM,OAAO,IAAI;AAEnC,QAAI,CAAC,IAAI,IAAI;AACX,YAAM,OAAO,MAAM,IAAI,KAAK;AAC5B,UAAI,KAAK,OAAO;AACd,cAAM,QAAQ,IAAI,MAAM,KAAK,KAAK;AAGlC,cAAM,SAAS,IAAI;AACnB,cAAM;AAAA,MACR,OAAO;AACL,cAAM,IAAI,MAAM,8BAA8B;AAAA,MAChD;AAAA,IACF;AAEA,WAAO,IAAI,KAAK;AAAA,EAClB;AAAA;AAEO,SAAS,WAAW,OAAuC;AAChE,QAAM,OAAO,IAAI,KAAK,KAAK;AAC3B,SAAO,KAAK,mBAAmB,SAAS;AAAA,IACtC,OAAO;AAAA,IACP,KAAK;AAAA,IACL,MAAM;AAAA,EACR,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../src/lib/utils.ts"],"sourcesContent":["export async function fetcher<JSON = any>(input: RequestInfo, init?: RequestInit): Promise<JSON> {\n const res = await fetch(input, init);\n\n if (!res.ok) {\n const json = await res.json();\n if (json.error) {\n const error = new Error(json.error) as Error & {\n status: number;\n };\n error.status = res.status;\n throw error;\n } else {\n throw new Error(\"An unexpected error occurred\");\n }\n }\n\n return res.json();\n}\n\nexport function formatDate(input: string | number | Date): string {\n const date = new Date(input);\n return date.toLocaleDateString(\"en-US\", {\n month: \"long\",\n day: \"numeric\",\n year: \"numeric\",\n });\n}\n"],"mappings":";;;;;AAAA,SAAsB,QAAoB,OAAoB,MAAmC;AAAA;AAC/F,UAAM,MAAM,MAAM,MAAM,OAAO,IAAI;AAEnC,QAAI,CAAC,IAAI,IAAI;AACX,YAAM,OAAO,MAAM,IAAI,KAAK;AAC5B,UAAI,KAAK,OAAO;AACd,cAAM,QAAQ,IAAI,MAAM,KAAK,KAAK;AAGlC,cAAM,SAAS,IAAI;AACnB,cAAM;AAAA,MACR,OAAO;AACL,cAAM,IAAI,MAAM,8BAA8B;AAAA,MAChD;AAAA,IACF;AAEA,WAAO,IAAI,KAAK;AAAA,EAClB;AAAA;AAEO,SAAS,WAAW,OAAuC;AAChE,QAAM,OAAO,IAAI,KAAK,KAAK;AAC3B,SAAO,KAAK,mBAAmB,SAAS;AAAA,IACtC,OAAO;AAAA,IACP,KAAK;AAAA,IACL,MAAM;AAAA,EACR,CAAC;AACH;","names":[]}
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "publishConfig": {
10
10
  "access": "public"
11
11
  },
12
- "version": "1.0.3",
12
+ "version": "1.0.4",
13
13
  "sideEffects": [
14
14
  "**/*.css"
15
15
  ],
@@ -40,19 +40,18 @@
40
40
  "ts-jest": "^29.1.1",
41
41
  "tsup": "^6.7.0",
42
42
  "typescript": "^5.2.3",
43
- "eslint-config-custom": "1.0.0",
44
- "tailwind-config": "1.0.0",
45
- "tsconfig": "1.0.0"
43
+ "eslint-config-custom": "1.0.1",
44
+ "tailwind-config": "1.0.1",
45
+ "tsconfig": "1.0.1"
46
46
  },
47
47
  "dependencies": {
48
- "nanoid": "^4.0.2",
49
48
  "react-markdown": "^8.0.7",
50
49
  "react-syntax-highlighter": "^15.5.0",
51
50
  "remark-gfm": "^3.0.1",
52
51
  "remark-math": "^5.1.1",
53
- "@copilotkit/react-core": "1.0.3",
54
- "@copilotkit/runtime-client-gql": "1.0.3",
55
- "@copilotkit/shared": "1.0.3"
52
+ "@copilotkit/react-core": "1.0.4",
53
+ "@copilotkit/runtime-client-gql": "1.0.4",
54
+ "@copilotkit/shared": "1.0.4"
56
55
  },
57
56
  "keywords": [
58
57
  "copilotkit",
@@ -56,11 +56,11 @@ import { ResponseButton as DefaultResponseButton } from "./Response";
56
56
  import { Suggestion } from "./Suggestion";
57
57
  import React, { useEffect, useRef, useState } from "react";
58
58
  import { SystemMessageFunction, useCopilotChat, useCopilotContext } from "@copilotkit/react-core";
59
- import { nanoid } from "nanoid";
60
59
  import { reloadSuggestions } from "./Suggestion";
61
60
  import { CopilotChatSuggestion } from "../../types/suggestions";
62
61
  import { Message, Role, TextMessage } from "@copilotkit/runtime-client-gql";
63
62
  import { InputProps, MessagesProps, ResponseButtonProps } from "./props";
63
+ import { randomId } from "@copilotkit/shared";
64
64
 
65
65
  /**
66
66
  * Props for CopilotChat component.
@@ -230,7 +230,7 @@ export const useCopilotChatLogic = (
230
230
  ) => {
231
231
  const { visibleMessages, appendMessage, reloadMessages, stopGeneration, isLoading } =
232
232
  useCopilotChat({
233
- id: nanoid(),
233
+ id: randomId(),
234
234
  makeSystemMessage,
235
235
  });
236
236
 
@@ -1,7 +1,6 @@
1
1
  import React, { useEffect, useMemo } from "react";
2
2
  import { MessagesProps } from "./props";
3
3
  import { useChatContext } from "./ChatContext";
4
- import { nanoid } from "nanoid";
5
4
  import { Markdown } from "./Markdown";
6
5
  import { RenderFunctionStatus, useCopilotContext } from "@copilotkit/react-core";
7
6
  import {
@@ -64,9 +64,8 @@
64
64
  */
65
65
 
66
66
  import { useEffect } from "react";
67
- import { useChatContext } from "../components";
68
- import { nanoid } from "nanoid";
69
- import { CopilotChatSuggestionConfiguration, useCopilotContext } from "@copilotkit/react-core";
67
+ import { useCopilotContext } from "@copilotkit/react-core";
68
+ import { randomId } from "@copilotkit/shared";
70
69
 
71
70
  interface UseCopilotChatSuggestionsConfiguration {
72
71
  /**
@@ -101,7 +100,7 @@ export function useCopilotChatSuggestions(
101
100
  const context = useCopilotContext();
102
101
 
103
102
  useEffect(() => {
104
- const id = nanoid();
103
+ const id = randomId();
105
104
 
106
105
  context.addChatSuggestionConfiguration(id, {
107
106
  instructions,
package/src/lib/utils.ts CHANGED
@@ -1,10 +1,3 @@
1
- import { customAlphabet } from "nanoid";
2
-
3
- export const nanoid = customAlphabet(
4
- "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
5
- 7,
6
- ); // 7-character random string
7
-
8
1
  export async function fetcher<JSON = any>(input: RequestInfo, init?: RequestInit): Promise<JSON> {
9
2
  const res = await fetch(input, init);
10
3
 
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/components/chat/Messages.tsx"],"sourcesContent":["import React, { useEffect, useMemo } from \"react\";\nimport { MessagesProps } from \"./props\";\nimport { useChatContext } from \"./ChatContext\";\nimport { nanoid } from \"nanoid\";\nimport { Markdown } from \"./Markdown\";\nimport { RenderFunctionStatus, useCopilotContext } from \"@copilotkit/react-core\";\nimport {\n MessageStatusCode,\n ActionExecutionMessage,\n Message,\n ResultMessage,\n TextMessage,\n Role,\n} from \"@copilotkit/runtime-client-gql\";\n\nexport const Messages = ({ messages, inProgress, children }: MessagesProps) => {\n const { chatComponentsCache } = useCopilotContext();\n\n const context = useChatContext();\n const initialMessages = useMemo(\n () => makeInitialMessages(context.labels.initial),\n [context.labels.initial],\n );\n messages = [...initialMessages, ...messages];\n\n const functionResults: Record<string, string> = {};\n\n for (let i = 0; i < messages.length; i++) {\n if (messages[i] instanceof ActionExecutionMessage) {\n const id = messages[i].id;\n const resultMessage: ResultMessage | undefined = messages.find(\n (message) => message instanceof ResultMessage && message.actionExecutionId === id,\n ) as ResultMessage | undefined;\n\n if (resultMessage) {\n functionResults[id] = ResultMessage.decodeResult(resultMessage.result || \"\");\n }\n }\n }\n\n const messagesEndRef = React.useRef<HTMLDivElement>(null);\n\n const scrollToBottom = () => {\n if (messagesEndRef.current) {\n messagesEndRef.current.scrollIntoView({\n behavior: \"auto\",\n });\n }\n };\n\n useEffect(() => {\n scrollToBottom();\n }, [messages]);\n\n return (\n <div className=\"copilotKitMessages\">\n {messages.map((message, index) => {\n const isCurrentMessage = index === messages.length - 1;\n\n if (message instanceof TextMessage && message.role === \"user\") {\n return (\n <div key={index} className=\"copilotKitMessage copilotKitUserMessage\">\n {message.content}\n </div>\n );\n } else if (message instanceof TextMessage && message.role == \"assistant\") {\n return (\n <div key={index} className={`copilotKitMessage copilotKitAssistantMessage`}>\n {isCurrentMessage && inProgress && !message.content ? (\n context.icons.spinnerIcon\n ) : (\n <Markdown content={message.content} />\n )}\n </div>\n );\n } else if (message instanceof ActionExecutionMessage) {\n if (chatComponentsCache.current !== null && chatComponentsCache.current[message.name]) {\n const render = chatComponentsCache.current[message.name];\n // render a static string\n if (typeof render === \"string\") {\n // when render is static, we show it only when in progress\n if (isCurrentMessage && inProgress) {\n return (\n <div key={index} className={`copilotKitMessage copilotKitAssistantMessage`}>\n {context.icons.spinnerIcon} <span className=\"inProgressLabel\">{render}</span>\n </div>\n );\n }\n // Done - silent by default to avoid a series of \"done\" messages\n else {\n return null;\n }\n }\n // render is a function\n else {\n const args = message.arguments;\n\n let status: RenderFunctionStatus = \"inProgress\";\n\n if (functionResults[message.id] !== undefined) {\n status = \"complete\";\n } else if (message.status.code !== MessageStatusCode.Pending) {\n status = \"executing\";\n }\n\n const toRender = render({\n status: status as any,\n args,\n result: functionResults[message.id],\n });\n\n // No result and complete: stay silent\n if (!toRender && status === \"complete\") {\n return null;\n }\n\n if (typeof toRender === \"string\") {\n return (\n <div key={index} className={`copilotKitMessage copilotKitAssistantMessage`}>\n {isCurrentMessage && inProgress && context.icons.spinnerIcon} {toRender}\n </div>\n );\n } else {\n return (\n <div key={index} className=\"copilotKitCustomAssistantMessage\">\n {toRender}\n </div>\n );\n }\n }\n }\n // No render function found- show the default message\n else if (!inProgress || !isCurrentMessage) {\n // Done - silent by default to avoid a series of \"done\" messages\n return null;\n } else {\n // In progress\n return (\n <div key={index} className={`copilotKitMessage copilotKitAssistantMessage`}>\n {context.icons.spinnerIcon}\n </div>\n );\n }\n }\n })}\n <footer ref={messagesEndRef}>{children}</footer>\n </div>\n );\n};\n\nfunction makeInitialMessages(initial?: string | string[]): Message[] {\n let initialArray: string[] = [];\n if (initial) {\n if (Array.isArray(initial)) {\n initialArray.push(...initial);\n } else {\n initialArray.push(initial);\n }\n }\n\n return initialArray.map(\n (message) =>\n new TextMessage({\n role: Role.Assistant,\n content: message,\n }),\n );\n}\n"],"mappings":";;;;;;;;AAAA,OAAO,SAAS,WAAW,eAAe;AAK1C,SAA+B,yBAAyB;AACxD;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAgDK,cAsBM,YAtBN;AA9CL,IAAM,WAAW,CAAC,EAAE,UAAU,YAAY,SAAS,MAAqB;AAC7E,QAAM,EAAE,oBAAoB,IAAI,kBAAkB;AAElD,QAAM,UAAU,eAAe;AAC/B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yB,CAAC;AAC9B,MAAI,SAAS;AACX,QAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,mBAAa,KAAK,GAAG,OAAO;AAAA,IAC9B,OAAO;AACL,mBAAa,KAAK,OAAO;AAAA,IAC3B;AAAA,EACF;AAEA,SAAO,aAAa;AAAA,IAClB,CAAC,YACC,IAAI,YAAY;AAAA,MACd,MAAM,KAAK;AAAA,MACX,SAAS;AAAA,IACX,CAAC;AAAA,EACL;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/components/chat/Chat.tsx"],"sourcesContent":["/**\n * An embeddable chat panel for CopilotKit.\n *\n * <img src=\"/images/CopilotChat/CopilotChat.gif\" width=\"500\" />\n *\n * A chatbot panel component for the CopilotKit framework. The component allows for a high degree\n * of customization through various props and custom CSS.\n *\n * <RequestExample>\n * ```jsx CopilotChat Example\n * import { CopilotChat } from \"@copilotkit/react-ui\";\n *\n * <CopilotChat\n * labels={{\n * title: \"Your Assistant\",\n * initial: \"Hi! 👋 How can I assist you today?\",\n * }}\n * />\n * ```\n * </RequestExample>\n *\n * ## Custom CSS\n *\n * You can customize the colors of the panel by overriding the CSS variables\n * defined in the [default styles](https://github.com/CopilotKit/CopilotKit/blob/main/CopilotKit/packages/react-ui/src/css/colors.css).\n *\n * For example, to set the primary color to purple:\n *\n * ```jsx\n * <div style={{ \"--copilot-kit-primary-color\": \"#7D5BA6\" }}>\n * <CopilotPopup />\n * </div>\n * ```\n *\n * To further customize the panel, you can override the CSS classes defined\n * [here](https://github.com/CopilotKit/CopilotKit/blob/main/CopilotKit/packages/react-ui/src/css/).\n *\n * For example:\n *\n * ```css\n * .copilotKitButton {\n * border-radius: 0;\n * }\n * ```\n */\n\nimport {\n ChatContext,\n ChatContextProvider,\n CopilotChatIcons,\n CopilotChatLabels,\n} from \"./ChatContext\";\nimport { Messages as DefaultMessages } from \"./Messages\";\nimport { Input as DefaultInput } from \"./Input\";\nimport { ResponseButton as DefaultResponseButton } from \"./Response\";\nimport { Suggestion } from \"./Suggestion\";\nimport React, { useEffect, useRef, useState } from \"react\";\nimport { SystemMessageFunction, useCopilotChat, useCopilotContext } from \"@copilotkit/react-core\";\nimport { nanoid } from \"nanoid\";\nimport { reloadSuggestions } from \"./Suggestion\";\nimport { CopilotChatSuggestion } from \"../../types/suggestions\";\nimport { Message, Role, TextMessage } from \"@copilotkit/runtime-client-gql\";\nimport { InputProps, MessagesProps, ResponseButtonProps } from \"./props\";\n\n/**\n * Props for CopilotChat component.\n */\nexport interface CopilotChatProps {\n /**\n * Custom instructions to be added to the system message. Use this property to\n * provide additional context or guidance to the language model, influencing\n * its responses. These instructions can include specific directions,\n * preferences, or criteria that the model should consider when generating\n * its output, thereby tailoring the conversation more precisely to the\n * user's needs or the application's requirements.\n */\n instructions?: string;\n\n /**\n * A callback that gets called when the in progress state changes.\n */\n onInProgress?: (inProgress: boolean) => void;\n\n /**\n * A callback that gets called when a new message it submitted.\n */\n onSubmitMessage?: (message: string) => void;\n\n /**\n * Icons can be used to set custom icons for the chat window.\n */\n icons?: CopilotChatIcons;\n\n /**\n * Labels can be used to set custom labels for the chat window.\n */\n labels?: CopilotChatLabels;\n\n /**\n * A function that takes in context string and instructions and returns\n * the system message to include in the chat request.\n * Use this to completely override the system message, when providing\n * instructions is not enough.\n */\n makeSystemMessage?: SystemMessageFunction;\n\n /**\n * Whether to show the response button.\n * @default true\n */\n showResponseButton?: boolean;\n\n /**\n * A custom Messages component to use instead of the default.\n */\n Messages?: React.ComponentType<MessagesProps>;\n\n /**\n * A custom Input component to use instead of the default.\n */\n Input?: React.ComponentType<InputProps>;\n\n /**\n * A custom ResponseButton component to use instead of the default.\n */\n ResponseButton?: React.ComponentType<ResponseButtonProps>;\n\n /**\n * A class name to apply to the root element.\n */\n className?: string;\n\n /**\n * Children to render.\n */\n children?: React.ReactNode;\n}\n\nexport function CopilotChat({\n instructions,\n onSubmitMessage,\n makeSystemMessage,\n showResponseButton = true,\n onInProgress,\n Messages = DefaultMessages,\n Input = DefaultInput,\n ResponseButton = DefaultResponseButton,\n className,\n icons,\n labels,\n}: CopilotChatProps) {\n const context = useCopilotContext();\n\n useEffect(() => {\n context.setChatInstructions(instructions || \"\");\n }, [instructions]);\n\n const {\n visibleMessages,\n isLoading,\n currentSuggestions,\n sendMessage,\n stopGeneration,\n reloadMessages,\n } = useCopilotChatLogic(makeSystemMessage, onInProgress, onSubmitMessage);\n\n const chatContext = React.useContext(ChatContext);\n const isVisible = chatContext ? chatContext.open : true;\n\n return (\n <WrappedCopilotChat icons={icons} labels={labels} className={className}>\n <Messages messages={visibleMessages} inProgress={isLoading}>\n {currentSuggestions.length > 0 && (\n <div>\n <h6>Suggested:</h6>\n <div className=\"suggestions\">\n {currentSuggestions.map((suggestion, index) => (\n <Suggestion\n key={index}\n title={suggestion.title}\n message={suggestion.message}\n partial={suggestion.partial}\n className={suggestion.className}\n onClick={(message) => sendMessage(message)}\n />\n ))}\n </div>\n </div>\n )}\n {showResponseButton && visibleMessages.length > 0 && (\n <ResponseButton\n onClick={isLoading ? stopGeneration : reloadMessages}\n inProgress={isLoading}\n />\n )}\n </Messages>\n <Input inProgress={isLoading} onSend={sendMessage} isVisible={isVisible} />\n </WrappedCopilotChat>\n );\n}\n\nexport function WrappedCopilotChat({\n children,\n icons,\n labels,\n className,\n}: {\n children: React.ReactNode;\n icons?: CopilotChatIcons;\n labels?: CopilotChatLabels;\n className?: string;\n}) {\n const chatContext = React.useContext(ChatContext);\n if (!chatContext) {\n return (\n <ChatContextProvider icons={icons} labels={labels} open={true} setOpen={() => {}}>\n <div className={`copilotKitChat ${className}`}>{children}</div>\n </ChatContextProvider>\n );\n }\n return <>{children}</>;\n}\n\nconst SUGGESTIONS_DEBOUNCE_TIMEOUT = 1000;\n\nexport const useCopilotChatLogic = (\n makeSystemMessage?: SystemMessageFunction,\n onInProgress?: (isLoading: boolean) => void,\n onSubmitMessage?: (messageContent: string) => void,\n) => {\n const { visibleMessages, appendMessage, reloadMessages, stopGeneration, isLoading } =\n useCopilotChat({\n id: nanoid(),\n makeSystemMessage,\n });\n\n const [currentSuggestions, setCurrentSuggestions] = useState<CopilotChatSuggestion[]>([]);\n const suggestionsAbortControllerRef = useRef<AbortController | null>(null);\n const debounceTimerRef = useRef<any>();\n\n const abortSuggestions = () => {\n suggestionsAbortControllerRef.current?.abort();\n suggestionsAbortControllerRef.current = null;\n };\n\n const context = useCopilotContext();\n\n useEffect(() => {\n onInProgress?.(isLoading);\n\n abortSuggestions();\n\n debounceTimerRef.current = setTimeout(\n () => {\n if (!isLoading && Object.keys(context.chatSuggestionConfiguration).length !== 0) {\n suggestionsAbortControllerRef.current = new AbortController();\n reloadSuggestions(\n context,\n context.chatSuggestionConfiguration,\n setCurrentSuggestions,\n suggestionsAbortControllerRef,\n );\n }\n },\n currentSuggestions.length == 0 ? 0 : SUGGESTIONS_DEBOUNCE_TIMEOUT,\n );\n\n return () => {\n clearTimeout(debounceTimerRef.current);\n };\n }, [isLoading, context.chatSuggestionConfiguration]);\n\n const sendMessage = async (messageContent: string) => {\n abortSuggestions();\n setCurrentSuggestions([]);\n onSubmitMessage?.(messageContent);\n const message: Message = new TextMessage({\n content: messageContent,\n role: Role.User,\n });\n appendMessage(message);\n return message;\n };\n\n return {\n visibleMessages,\n isLoading,\n currentSuggestions,\n sendMessage,\n stopGeneration,\n reloadMessages,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAwDA,OAAO,SAAS,WAAW,QAAQ,gBAAgB;AACnD,SAAgC,gBAAgB,yBAAyB;AACzE,SAAS,cAAc;AAGvB,SAAkB,MAAM,mBAAmB;AAgHjC,SA+CD,UA9CG,KADF;AAnCH,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA,qBAAqB;AAAA,EACrB;AAAA,EACA,UAAAA,YAAW;AAAA,EACX,OAAAC,SAAQ;AAAA,EACR,gBAAAC,kBAAiB;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AACF,GAAqB;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