@copilotkit/react-ui 0.37.0 → 0.38.0-beta.0
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.
- package/.turbo/turbo-build.log +72 -77
- package/CHANGELOG.md +13 -0
- package/dist/{chunk-IEV5SYHX.mjs → chunk-5B6K3N4M.mjs} +7 -7
- package/dist/{chunk-GKZ5DRPT.mjs → chunk-B5UDC4YJ.mjs} +2 -2
- package/dist/chunk-DYXI54LF.mjs +126 -0
- package/dist/chunk-DYXI54LF.mjs.map +1 -0
- package/dist/{chunk-F4KCDLRJ.mjs → chunk-GICTFOCR.mjs} +11 -11
- package/dist/chunk-GICTFOCR.mjs.map +1 -0
- package/dist/{chunk-MSSOYSBR.mjs → chunk-U3TLLYFC.mjs} +2 -2
- package/dist/{chunk-4MKP23AD.mjs → chunk-U566UC72.mjs} +9 -2
- package/dist/chunk-U566UC72.mjs.map +1 -0
- package/dist/{chunk-LZHY5L7A.mjs → chunk-U6J5DGOE.mjs} +2 -2
- package/dist/{chunk-ANO23V2M.mjs → chunk-VOBX4JOA.mjs} +5 -2
- package/dist/chunk-VOBX4JOA.mjs.map +1 -0
- package/dist/components/chat/Button.d.ts +1 -1
- package/dist/components/chat/Chat.d.ts +1 -1
- package/dist/components/chat/Chat.js +73 -65
- package/dist/components/chat/Chat.js.map +1 -1
- package/dist/components/chat/Chat.mjs +7 -7
- package/dist/components/chat/Header.d.ts +1 -1
- package/dist/components/chat/Input.d.ts +1 -1
- package/dist/components/chat/Input.js +4 -1
- package/dist/components/chat/Input.js.map +1 -1
- package/dist/components/chat/Input.mjs +2 -2
- package/dist/components/chat/Messages.d.ts +1 -1
- package/dist/components/chat/Messages.js +55 -59
- package/dist/components/chat/Messages.js.map +1 -1
- package/dist/components/chat/Messages.mjs +2 -2
- package/dist/components/chat/Modal.d.ts +1 -1
- package/dist/components/chat/Modal.js +73 -65
- package/dist/components/chat/Modal.js.map +1 -1
- package/dist/components/chat/Modal.mjs +8 -8
- package/dist/components/chat/Popup.d.ts +1 -1
- package/dist/components/chat/Popup.js +73 -65
- package/dist/components/chat/Popup.js.map +1 -1
- package/dist/components/chat/Popup.mjs +9 -9
- package/dist/components/chat/Response.d.ts +1 -1
- package/dist/components/chat/Sidebar.d.ts +1 -1
- package/dist/components/chat/Sidebar.js +73 -65
- package/dist/components/chat/Sidebar.js.map +1 -1
- package/dist/components/chat/Sidebar.mjs +9 -9
- package/dist/components/chat/Suggestion.d.ts +1 -1
- package/dist/components/chat/Suggestion.js +8 -1
- package/dist/components/chat/Suggestion.js.map +1 -1
- package/dist/components/chat/Suggestion.mjs +1 -1
- package/dist/components/chat/Window.d.ts +1 -1
- package/dist/components/chat/index.d.ts +1 -1
- package/dist/components/chat/index.js +73 -65
- package/dist/components/chat/index.js.map +1 -1
- package/dist/components/chat/index.mjs +10 -10
- package/dist/components/chat/props.d.ts +1 -1
- package/dist/components/chat/props.js.map +1 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +73 -65
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +10 -10
- package/dist/hooks/use-push-to-talk.d.ts +1 -1
- package/dist/hooks/use-push-to-talk.js +4 -1
- package/dist/hooks/use-push-to-talk.js.map +1 -1
- package/dist/hooks/use-push-to-talk.mjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +75 -67
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -10
- package/package.json +7 -6
- package/src/components/chat/Chat.tsx +4 -5
- package/src/components/chat/Messages.tsx +98 -98
- package/src/components/chat/Suggestion.tsx +9 -1
- package/src/components/chat/props.ts +1 -1
- package/src/hooks/use-push-to-talk.tsx +5 -3
- package/dist/chunk-23PTCJ2T.mjs +0 -122
- package/dist/chunk-23PTCJ2T.mjs.map +0 -1
- package/dist/chunk-4MKP23AD.mjs.map +0 -1
- package/dist/chunk-ANO23V2M.mjs.map +0 -1
- package/dist/chunk-F4KCDLRJ.mjs.map +0 -1
- package/dist/types/types.d.ts +0 -16
- package/dist/types/types.js +0 -19
- package/dist/types/types.js.map +0 -1
- package/dist/types/types.mjs +0 -1
- package/dist/types/types.mjs.map +0 -1
- package/src/types/types.ts +0 -18
- /package/dist/{chunk-IEV5SYHX.mjs.map → chunk-5B6K3N4M.mjs.map} +0 -0
- /package/dist/{chunk-GKZ5DRPT.mjs.map → chunk-B5UDC4YJ.mjs.map} +0 -0
- /package/dist/{chunk-MSSOYSBR.mjs.map → chunk-U3TLLYFC.mjs.map} +0 -0
- /package/dist/{chunk-LZHY5L7A.mjs.map → chunk-U6J5DGOE.mjs.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/chat/Suggestion.tsx","../../../src/components/chat/Icons.tsx"],"sourcesContent":["import {\n CopilotContextParams,\n extract,\n CopilotChatSuggestionConfiguration,\n} from \"@copilotkit/react-core\";\nimport { SuggestionsProps } from \"./props\";\nimport { SmallSpinnerIcon } from \"./Icons\";\nimport { CopilotChatSuggestion } from \"../../types/suggestions\";\n\nexport function Suggestion({ title, message, onClick, partial, className }: SuggestionsProps) {\n return (\n <button\n disabled={partial}\n onClick={(e) => {\n e.preventDefault();\n onClick(message);\n }}\n className={className || \"suggestion\"}\n >\n {partial && SmallSpinnerIcon}\n <span>{title}</span>\n </button>\n );\n}\n\nexport const reloadSuggestions = async (\n context: CopilotContextParams,\n chatSuggestionConfiguration: { [key: string]: CopilotChatSuggestionConfiguration },\n setCurrentSuggestions: (suggestions: { title: string; message: string }[]) => void,\n abortControllerRef: React.MutableRefObject<AbortController | null>,\n) => {\n const abortController = abortControllerRef.current;\n const tools = JSON.stringify(context.getChatCompletionFunctionDescriptions(context.entryPoints));\n\n const allSuggestions: CopilotChatSuggestion[] = [];\n\n for (const config of Object.values(chatSuggestionConfiguration)) {\n try {\n const numOfSuggestionsInstructions =\n config.minSuggestions === 0\n ? `Produce up to ${config.maxSuggestions} suggestions. ` +\n `If there are no highly relevant suggestions you can think of, provide an empty array.`\n : `Produce between ${config.minSuggestions} and ${config.maxSuggestions} suggestions.`;\n const result = await extract({\n context,\n instructions:\n \"Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls. \" +\n config.instructions +\n \"\\n\\n\" +\n numOfSuggestionsInstructions,\n data: \"Available tools: \" + tools + \"\\n\\n\",\n parameters: [\n {\n name: \"suggestions\",\n type: \"object[]\",\n attributes: [\n {\n name: \"title\",\n description:\n \"The title of the suggestion. This is shown as a button and should be short.\",\n type: \"string\",\n },\n {\n name: \"message\",\n description:\n \"The message to send when the suggestion is clicked. This should be a clear, complete sentence and will be sent as an instruction to the AI.\",\n type: \"string\",\n },\n ],\n },\n ],\n include: {\n messages: true,\n readable: true,\n },\n abortSignal: abortController?.signal,\n stream: ({ status, args }) => {\n const suggestions = args.suggestions || [];\n const newSuggestions: CopilotChatSuggestion[] = [];\n for (let i = 0; i < suggestions.length; i++) {\n // if GPT provides too many suggestions, limit the number of suggestions\n if (config.maxSuggestions !== undefined && i >= config.maxSuggestions) {\n break;\n }\n const { title, message } = suggestions[i];\n\n // If this is the last suggestion and the status is not complete, mark it as partial\n const partial = i == suggestions.length - 1 && status !== \"complete\";\n\n newSuggestions.push({\n title,\n message,\n partial,\n className: config.className,\n });\n }\n setCurrentSuggestions([...allSuggestions, ...newSuggestions]);\n },\n });\n allSuggestions.push(...result.suggestions);\n } catch (error) {\n console.error(\"Error loading suggestions\", error);\n }\n }\n\n if (abortControllerRef.current === abortController) {\n abortControllerRef.current = null;\n }\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 SmallSpinnerIcon = (\n <svg\n style={{\n animation: \"copilotKitSpinAnimation 1s linear infinite\",\n }}\n width=\"13\"\n height=\"13\"\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\nexport const PushToTalkIcon = (\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 className=\"w-6 h-6\"\n >\n <path\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n d=\"M12 18.75a6 6 0 0 0 6-6v-1.5m-6 7.5a6 6 0 0 1-6-6v-1.5m6 7.5v3.75m-3.75 0h7.5M12 15.75a3 3 0 0 1-3-3V4.5a3 3 0 1 1 6 0v8.25a3 3 0 0 1-3 3Z\"\n />\n </svg>\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAIO;;;ACOD;AAmFC,IAAM,mBACX;AAAA,EAAC;AAAA;AAAA,IACC,OAAO;AAAA,MACL,WAAW;AAAA,IACb;AAAA,IACA,OAAM;AAAA,IACN,QAAO;AAAA,IACP,OAAM;AAAA,IACN,MAAK;AAAA,IACL,SAAQ;AAAA,IAER;AAAA;AAAA,QAAC;AAAA;AAAA,UACC,OAAO,EAAE,SAAS,KAAK;A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;AAAA,UACF;AAAA,QACF;AAAA,QACA,SAAS;AAAA,UACP,UAAU;AAAA,UACV,UAAU;AAAA,QACZ;AAAA,QACA,aAAa,mDAAiB;AAAA,QAC9B,QAAQ,CAAC,EAAE,QAAQ,KAAK,MAAM;AAC5B,gBAAM,cAAc,KAAK,eAAe,CAAC;AACzC,gBAAM,iBAA0C,CAAC;AACjD,mBAAS,IAAI,GAAG,IAAI,YAAY,QAAQ,KAAK;AAE3C,gBAAI,OAAO,mBAAmB,UAAa,KAAK,OAAO,gBAAgB;AACrE;AAAA,YACF;AACA,kBAAM,EAAE,OAAO,QAAQ,IAAI,YAAY,CAAC;AAGxC,kBAAM,UAAU,KAAK,YAAY,SAAS,KAAK,WAAW;AAE1D,2BAAe,KAAK;AAAA,cAClB;AAAA,cACA;AAAA,cACA;AAAA,cACA,WAAW,OAAO;AAAA,YACpB,CAAC;AAAA,UACH;AACA,gCAAsB,CAAC,GAAG,gBAAgB,GAAG,cAAc,CAAC;AAAA,QAC9D;AAAA,MACF,CAAC;AACD,qBAAe,KAAK,GAAG,OAAO,WAAW;AAAA,IAC3C,SAAS,OAAP;AACA,cAAQ,MAAM,6BAA6B,KAAK;AAAA,IAClD;AAAA,EACF;AAEA,MAAI,mBAAmB,YAAY,iBAAiB;AAClD,uBAAmB,UAAU;AAAA,EAC/B;AACF;","names":["import_jsx_runtime"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/chat/Suggestion.tsx","../../../src/components/chat/Icons.tsx"],"sourcesContent":["import {\n CopilotContextParams,\n extract,\n CopilotChatSuggestionConfiguration,\n} from \"@copilotkit/react-core\";\nimport { SuggestionsProps } from \"./props\";\nimport { SmallSpinnerIcon } from \"./Icons\";\nimport { CopilotChatSuggestion } from \"../../types/suggestions\";\nimport { actionParametersToJsonSchema } from \"@copilotkit/shared\";\n\nexport function Suggestion({ title, message, onClick, partial, className }: SuggestionsProps) {\n return (\n <button\n disabled={partial}\n onClick={(e) => {\n e.preventDefault();\n onClick(message);\n }}\n className={className || \"suggestion\"}\n >\n {partial && SmallSpinnerIcon}\n <span>{title}</span>\n </button>\n );\n}\n\nexport const reloadSuggestions = async (\n context: CopilotContextParams,\n chatSuggestionConfiguration: { [key: string]: CopilotChatSuggestionConfiguration },\n setCurrentSuggestions: (suggestions: { title: string; message: string }[]) => void,\n abortControllerRef: React.MutableRefObject<AbortController | null>,\n) => {\n const abortController = abortControllerRef.current;\n\n const tools = JSON.stringify(\n Object.values(context.actions).map((action) => ({\n name: action.name,\n description: action.description,\n jsonSchema: JSON.stringify(actionParametersToJsonSchema(action.parameters)),\n })),\n );\n\n const allSuggestions: CopilotChatSuggestion[] = [];\n\n for (const config of Object.values(chatSuggestionConfiguration)) {\n try {\n const numOfSuggestionsInstructions =\n config.minSuggestions === 0\n ? `Produce up to ${config.maxSuggestions} suggestions. ` +\n `If there are no highly relevant suggestions you can think of, provide an empty array.`\n : `Produce between ${config.minSuggestions} and ${config.maxSuggestions} suggestions.`;\n const result = await extract({\n context,\n instructions:\n \"Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls. \" +\n config.instructions +\n \"\\n\\n\" +\n numOfSuggestionsInstructions,\n data: \"Available tools: \" + tools + \"\\n\\n\",\n parameters: [\n {\n name: \"suggestions\",\n type: \"object[]\",\n attributes: [\n {\n name: \"title\",\n description:\n \"The title of the suggestion. This is shown as a button and should be short.\",\n type: \"string\",\n },\n {\n name: \"message\",\n description:\n \"The message to send when the suggestion is clicked. This should be a clear, complete sentence and will be sent as an instruction to the AI.\",\n type: \"string\",\n },\n ],\n },\n ],\n include: {\n messages: true,\n readable: true,\n },\n abortSignal: abortController?.signal,\n stream: ({ status, args }) => {\n const suggestions = args.suggestions || [];\n const newSuggestions: CopilotChatSuggestion[] = [];\n for (let i = 0; i < suggestions.length; i++) {\n // if GPT provides too many suggestions, limit the number of suggestions\n if (config.maxSuggestions !== undefined && i >= config.maxSuggestions) {\n break;\n }\n const { title, message } = suggestions[i];\n\n // If this is the last suggestion and the status is not complete, mark it as partial\n const partial = i == suggestions.length - 1 && status !== \"complete\";\n\n newSuggestions.push({\n title,\n message,\n partial,\n className: config.className,\n });\n }\n setCurrentSuggestions([...allSuggestions, ...newSuggestions]);\n },\n });\n allSuggestions.push(...result.suggestions);\n } catch (error) {\n console.error(\"Error loading suggestions\", error);\n }\n }\n\n if (abortControllerRef.current === abortController) {\n abortControllerRef.current = null;\n }\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 SmallSpinnerIcon = (\n <svg\n style={{\n animation: \"copilotKitSpinAnimation 1s linear infinite\",\n }}\n width=\"13\"\n height=\"13\"\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\nexport const PushToTalkIcon = (\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 className=\"w-6 h-6\"\n >\n <path\n strokeLinecap=\"round\"\n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A,cACA,WAAW,OAAO;AAAA,YACpB,CAAC;AAAA,UACH;AACA,gCAAsB,CAAC,GAAG,gBAAgB,GAAG,cAAc,CAAC;AAAA,QAC9D;AAAA,MACF,CAAC;AACD,qBAAe,KAAK,GAAG,OAAO,WAAW;AAAA,IAC3C,SAAS,OAAP;AACA,cAAQ,MAAM,6BAA6B,KAAK;AAAA,IAClD;AAAA,EACF;AAEA,MAAI,mBAAmB,YAAY,iBAAiB;AAClD,uBAAmB,UAAU;AAAA,EAC/B;AACF;","names":["import_jsx_runtime"]}
|
|
@@ -3,7 +3,7 @@ export { CopilotPopup } from './Popup.js';
|
|
|
3
3
|
export { CopilotSidebar } from './Sidebar.js';
|
|
4
4
|
export { CopilotChat } from './Chat.js';
|
|
5
5
|
export { useChatContext } from './ChatContext.js';
|
|
6
|
-
import '@copilotkit/
|
|
6
|
+
import '@copilotkit/runtime-client-gql';
|
|
7
7
|
import './Modal.js';
|
|
8
8
|
import 'react';
|
|
9
9
|
import '@copilotkit/react-core';
|
|
@@ -515,8 +515,6 @@ var Header = ({ setOpen }) => {
|
|
|
515
515
|
|
|
516
516
|
// src/components/chat/Messages.tsx
|
|
517
517
|
var import_react5 = __toESM(require("react"));
|
|
518
|
-
var import_nanoid = require("nanoid");
|
|
519
|
-
var import_shared = require("@copilotkit/shared");
|
|
520
518
|
|
|
521
519
|
// src/components/chat/Markdown.tsx
|
|
522
520
|
var import_react4 = require("react");
|
|
@@ -988,6 +986,7 @@ var components = {
|
|
|
988
986
|
|
|
989
987
|
// src/components/chat/Messages.tsx
|
|
990
988
|
var import_react_core = require("@copilotkit/react-core");
|
|
989
|
+
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
991
990
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
992
991
|
var Messages = ({ messages, inProgress, children }) => {
|
|
993
992
|
const { chatComponentsCache } = (0, import_react_core.useCopilotContext)();
|
|
@@ -999,10 +998,13 @@ var Messages = ({ messages, inProgress, children }) => {
|
|
|
999
998
|
messages = [...initialMessages, ...messages];
|
|
1000
999
|
const functionResults = {};
|
|
1001
1000
|
for (let i = 0; i < messages.length; i++) {
|
|
1002
|
-
if (messages[i]
|
|
1001
|
+
if (messages[i] instanceof import_runtime_client_gql.ActionExecutionMessage) {
|
|
1003
1002
|
const id = messages[i].id;
|
|
1004
|
-
|
|
1005
|
-
|
|
1003
|
+
const resultMessage = messages.find(
|
|
1004
|
+
(message) => message instanceof import_runtime_client_gql.ResultMessage && message.actionExecutionId === id
|
|
1005
|
+
);
|
|
1006
|
+
if (resultMessage) {
|
|
1007
|
+
functionResults[id] = import_runtime_client_gql.ResultMessage.decodeResult(resultMessage.result || "");
|
|
1006
1008
|
}
|
|
1007
1009
|
}
|
|
1008
1010
|
}
|
|
@@ -1019,60 +1021,55 @@ var Messages = ({ messages, inProgress, children }) => {
|
|
|
1019
1021
|
}, [messages]);
|
|
1020
1022
|
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "copilotKitMessages", children: [
|
|
1021
1023
|
messages.map((message, index) => {
|
|
1022
|
-
var _a, _b, _c;
|
|
1023
1024
|
const isCurrentMessage = index === messages.length - 1;
|
|
1024
|
-
if (message.role === "user") {
|
|
1025
|
+
if (message instanceof import_runtime_client_gql.TextMessage && message.role === "user") {
|
|
1025
1026
|
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "copilotKitMessage copilotKitUserMessage", children: message.content }, index);
|
|
1026
|
-
} else if (message.role == "assistant") {
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
const
|
|
1031
|
-
if (
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "inProgressLabel", children: render })
|
|
1039
|
-
] }, index);
|
|
1040
|
-
} else {
|
|
1041
|
-
return null;
|
|
1042
|
-
}
|
|
1027
|
+
} else if (message instanceof import_runtime_client_gql.TextMessage && message.role == "assistant") {
|
|
1028
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: isCurrentMessage && inProgress && !message.content ? context.icons.spinnerIcon : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Markdown, { content: message.content }) }, index);
|
|
1029
|
+
} else if (message instanceof import_runtime_client_gql.ActionExecutionMessage) {
|
|
1030
|
+
if (chatComponentsCache.current !== null && chatComponentsCache.current[message.name]) {
|
|
1031
|
+
const render = chatComponentsCache.current[message.name];
|
|
1032
|
+
if (typeof render === "string") {
|
|
1033
|
+
if (isCurrentMessage && inProgress) {
|
|
1034
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
1035
|
+
context.icons.spinnerIcon,
|
|
1036
|
+
" ",
|
|
1037
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "inProgressLabel", children: render })
|
|
1038
|
+
] }, index);
|
|
1043
1039
|
} else {
|
|
1044
|
-
|
|
1045
|
-
let status = "inProgress";
|
|
1046
|
-
if (functionResults[message.id] !== void 0) {
|
|
1047
|
-
status = "complete";
|
|
1048
|
-
} else if (message.function_call) {
|
|
1049
|
-
status = "executing";
|
|
1050
|
-
}
|
|
1051
|
-
const toRender = render({
|
|
1052
|
-
status,
|
|
1053
|
-
args,
|
|
1054
|
-
result: functionResults[message.id]
|
|
1055
|
-
});
|
|
1056
|
-
if (!toRender && status === "complete") {
|
|
1057
|
-
return null;
|
|
1058
|
-
}
|
|
1059
|
-
if (typeof toRender === "string") {
|
|
1060
|
-
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
1061
|
-
isCurrentMessage && inProgress && context.icons.spinnerIcon,
|
|
1062
|
-
" ",
|
|
1063
|
-
toRender
|
|
1064
|
-
] }, index);
|
|
1065
|
-
} else {
|
|
1066
|
-
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "copilotKitCustomAssistantMessage", children: toRender }, index);
|
|
1067
|
-
}
|
|
1040
|
+
return null;
|
|
1068
1041
|
}
|
|
1069
|
-
} else if ((!inProgress || !isCurrentMessage) && message.function_call) {
|
|
1070
|
-
return null;
|
|
1071
1042
|
} else {
|
|
1072
|
-
|
|
1043
|
+
const args = message.arguments;
|
|
1044
|
+
let status = "inProgress";
|
|
1045
|
+
if (functionResults[message.id] !== void 0) {
|
|
1046
|
+
status = "complete";
|
|
1047
|
+
} else if (message.status.code !== import_runtime_client_gql.MessageStatusCode.Pending) {
|
|
1048
|
+
status = "executing";
|
|
1049
|
+
}
|
|
1050
|
+
const toRender = render({
|
|
1051
|
+
status,
|
|
1052
|
+
args,
|
|
1053
|
+
result: functionResults[message.id]
|
|
1054
|
+
});
|
|
1055
|
+
if (!toRender && status === "complete") {
|
|
1056
|
+
return null;
|
|
1057
|
+
}
|
|
1058
|
+
if (typeof toRender === "string") {
|
|
1059
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
1060
|
+
isCurrentMessage && inProgress && context.icons.spinnerIcon,
|
|
1061
|
+
" ",
|
|
1062
|
+
toRender
|
|
1063
|
+
] }, index);
|
|
1064
|
+
} else {
|
|
1065
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "copilotKitCustomAssistantMessage", children: toRender }, index);
|
|
1066
|
+
}
|
|
1073
1067
|
}
|
|
1068
|
+
} else if (!inProgress || !isCurrentMessage) {
|
|
1069
|
+
return null;
|
|
1070
|
+
} else {
|
|
1071
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: context.icons.spinnerIcon }, index);
|
|
1074
1072
|
}
|
|
1075
|
-
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Markdown, { content: message.content }) }, index);
|
|
1076
1073
|
}
|
|
1077
1074
|
}),
|
|
1078
1075
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("footer", { ref: messagesEndRef, children })
|
|
@@ -1087,11 +1084,12 @@ function makeInitialMessages(initial) {
|
|
|
1087
1084
|
initialArray.push(initial);
|
|
1088
1085
|
}
|
|
1089
1086
|
}
|
|
1090
|
-
return initialArray.map(
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1087
|
+
return initialArray.map(
|
|
1088
|
+
(message) => new import_runtime_client_gql.TextMessage({
|
|
1089
|
+
role: import_runtime_client_gql.Role.Assistant,
|
|
1090
|
+
content: message
|
|
1091
|
+
})
|
|
1092
|
+
);
|
|
1095
1093
|
}
|
|
1096
1094
|
|
|
1097
1095
|
// src/components/chat/Input.tsx
|
|
@@ -1148,6 +1146,7 @@ var Textarea_default = AutoResizingTextarea;
|
|
|
1148
1146
|
|
|
1149
1147
|
// src/hooks/use-push-to-talk.tsx
|
|
1150
1148
|
var import_react_core2 = require("@copilotkit/react-core");
|
|
1149
|
+
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
1151
1150
|
var import_react7 = require("react");
|
|
1152
1151
|
var startRecording = (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => __async(void 0, null, function* () {
|
|
1153
1152
|
if (!mediaStreamRef.current || !audioContextRef.current) {
|
|
@@ -1237,7 +1236,9 @@ var usePushToTalk = ({
|
|
|
1237
1236
|
const lastMessageIndex = context.messages.findIndex(
|
|
1238
1237
|
(message) => message.id === startReadingFromMessageId
|
|
1239
1238
|
);
|
|
1240
|
-
const messagesAfterLast = context.messages.slice(lastMessageIndex + 1).filter(
|
|
1239
|
+
const messagesAfterLast = context.messages.slice(lastMessageIndex + 1).filter(
|
|
1240
|
+
(message) => message instanceof import_runtime_client_gql2.TextMessage && message.role === "assistant"
|
|
1241
|
+
);
|
|
1241
1242
|
const text = messagesAfterLast.map((message) => message.content).join("\n");
|
|
1242
1243
|
playAudioResponse(text, context.copilotApiConfig.textToSpeechUrl, audioContextRef.current);
|
|
1243
1244
|
setStartReadingFromMessageId(null);
|
|
@@ -1326,6 +1327,7 @@ var ResponseButton = ({ onClick, inProgress }) => {
|
|
|
1326
1327
|
|
|
1327
1328
|
// src/components/chat/Suggestion.tsx
|
|
1328
1329
|
var import_react_core4 = require("@copilotkit/react-core");
|
|
1330
|
+
var import_shared = require("@copilotkit/shared");
|
|
1329
1331
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
1330
1332
|
function Suggestion({ title, message, onClick, partial, className }) {
|
|
1331
1333
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
|
|
@@ -1346,7 +1348,13 @@ function Suggestion({ title, message, onClick, partial, className }) {
|
|
|
1346
1348
|
}
|
|
1347
1349
|
var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggestions, abortControllerRef) => __async(void 0, null, function* () {
|
|
1348
1350
|
const abortController = abortControllerRef.current;
|
|
1349
|
-
const tools = JSON.stringify(
|
|
1351
|
+
const tools = JSON.stringify(
|
|
1352
|
+
Object.values(context.actions).map((action) => ({
|
|
1353
|
+
name: action.name,
|
|
1354
|
+
description: action.description,
|
|
1355
|
+
jsonSchema: JSON.stringify((0, import_shared.actionParametersToJsonSchema)(action.parameters))
|
|
1356
|
+
}))
|
|
1357
|
+
);
|
|
1350
1358
|
const allSuggestions = [];
|
|
1351
1359
|
for (const config of Object.values(chatSuggestionConfiguration)) {
|
|
1352
1360
|
try {
|
|
@@ -1410,7 +1418,8 @@ var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggest
|
|
|
1410
1418
|
// src/components/chat/Chat.tsx
|
|
1411
1419
|
var import_react9 = __toESM(require("react"));
|
|
1412
1420
|
var import_react_core5 = require("@copilotkit/react-core");
|
|
1413
|
-
var
|
|
1421
|
+
var import_nanoid = require("nanoid");
|
|
1422
|
+
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
1414
1423
|
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
1415
1424
|
function CopilotChat({
|
|
1416
1425
|
instructions,
|
|
@@ -1482,7 +1491,7 @@ function WrappedCopilotChat({
|
|
|
1482
1491
|
var SUGGESTIONS_DEBOUNCE_TIMEOUT = 1e3;
|
|
1483
1492
|
var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) => {
|
|
1484
1493
|
const { visibleMessages, appendMessage, reloadMessages, stopGeneration, isLoading } = (0, import_react_core5.useCopilotChat)({
|
|
1485
|
-
id: (0,
|
|
1494
|
+
id: (0, import_nanoid.nanoid)(),
|
|
1486
1495
|
makeSystemMessage
|
|
1487
1496
|
});
|
|
1488
1497
|
const [currentSuggestions, setCurrentSuggestions] = (0, import_react9.useState)([]);
|
|
@@ -1519,11 +1528,10 @@ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) =>
|
|
|
1519
1528
|
abortSuggestions();
|
|
1520
1529
|
setCurrentSuggestions([]);
|
|
1521
1530
|
onSubmitMessage == null ? void 0 : onSubmitMessage(messageContent);
|
|
1522
|
-
const message = {
|
|
1523
|
-
id: (0, import_nanoid2.nanoid)(),
|
|
1531
|
+
const message = new import_runtime_client_gql3.TextMessage({
|
|
1524
1532
|
content: messageContent,
|
|
1525
|
-
role:
|
|
1526
|
-
};
|
|
1533
|
+
role: import_runtime_client_gql3.Role.User
|
|
1534
|
+
});
|
|
1527
1535
|
appendMessage(message);
|
|
1528
1536
|
return message;
|
|
1529
1537
|
});
|