@copilotkit/react-ui 0.22.0 → 0.36.0-mme-pre.1
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 +211 -178
- package/CHANGELOG.md +24 -0
- package/dist/chunk-4MKP23AD.mjs +97 -0
- package/dist/chunk-4MKP23AD.mjs.map +1 -0
- package/dist/{chunk-T3WYKWNC.mjs → chunk-6XLZXLM5.mjs} +6 -6
- package/dist/chunk-6XLZXLM5.mjs.map +1 -0
- package/dist/{chunk-73EBDGYK.mjs → chunk-7FES2IQA.mjs} +5 -5
- package/dist/chunk-7FES2IQA.mjs.map +1 -0
- package/dist/chunk-ANO23V2M.mjs +135 -0
- package/dist/chunk-ANO23V2M.mjs.map +1 -0
- package/dist/chunk-BL65ZC6L.mjs +83 -0
- package/dist/chunk-BL65ZC6L.mjs.map +1 -0
- package/dist/{chunk-YEHO5VMA.mjs → chunk-CE7PJAAO.mjs} +2 -2
- package/dist/{chunk-7YXG7D47.mjs → chunk-FZC7X5PK.mjs} +57 -2
- package/dist/chunk-FZC7X5PK.mjs.map +1 -0
- package/dist/chunk-LTCJCXCP.mjs +29 -0
- package/dist/chunk-LTCJCXCP.mjs.map +1 -0
- package/dist/chunk-MRFF7GSQ.mjs +1 -0
- package/dist/{chunk-7JYUCW7H.mjs → chunk-PAQWLSA4.mjs} +2 -2
- package/dist/{chunk-YTIGBBTC.mjs → chunk-RT2XG2T7.mjs} +2 -2
- package/dist/chunk-RT2XG2T7.mjs.map +1 -0
- package/dist/chunk-T26KLXLH.mjs +1 -0
- package/dist/{chunk-6U3O2JZP.mjs → chunk-T3JTSIHT.mjs} +32 -39
- package/dist/chunk-T3JTSIHT.mjs.map +1 -0
- package/dist/{chunk-MBYUBR3F.mjs → chunk-UPTB2MVO.mjs} +2 -2
- package/dist/chunk-VUZA5AFH.mjs +73 -0
- package/dist/chunk-VUZA5AFH.mjs.map +1 -0
- package/dist/{chunk-YAORLSQ3.mjs → chunk-XRODMID5.mjs} +6 -6
- package/dist/chunk-XRODMID5.mjs.map +1 -0
- package/dist/{chunk-WDHLWSSU.mjs → chunk-YQ3D5IQV.mjs} +2 -2
- package/dist/{chunk-WM6BS77F.mjs → chunk-YQFVRDNC.mjs} +2 -2
- package/dist/{chunk-WM6BS77F.mjs.map → chunk-YQFVRDNC.mjs.map} +1 -1
- package/dist/chunk-ZO3GLN23.mjs +137 -0
- package/dist/chunk-ZO3GLN23.mjs.map +1 -0
- package/dist/components/chat/Button.js.map +1 -1
- package/dist/components/chat/Button.mjs +3 -3
- package/dist/components/chat/Chat.d.ts +66 -46
- package/dist/components/chat/Chat.js +433 -278
- package/dist/components/chat/Chat.js.map +1 -1
- package/dist/components/chat/Chat.mjs +15 -14
- package/dist/components/chat/ChatContext.d.ts +16 -16
- package/dist/components/chat/ChatContext.js +43 -27
- package/dist/components/chat/ChatContext.js.map +1 -1
- package/dist/components/chat/ChatContext.mjs +2 -2
- package/dist/components/chat/CodeBlock.js.map +1 -1
- package/dist/components/chat/CodeBlock.mjs +2 -2
- package/dist/components/chat/Header.js.map +1 -1
- package/dist/components/chat/Header.mjs +3 -3
- package/dist/components/chat/Icons.d.ts +7 -5
- package/dist/components/chat/Icons.js +57 -0
- package/dist/components/chat/Icons.js.map +1 -1
- package/dist/components/chat/Icons.mjs +5 -1
- package/dist/components/chat/Input.d.ts +1 -1
- package/dist/components/chat/Input.js +148 -11
- package/dist/components/chat/Input.js.map +1 -1
- package/dist/components/chat/Input.mjs +5 -4
- package/dist/components/chat/Markdown.js.map +1 -1
- package/dist/components/chat/Markdown.mjs +3 -3
- package/dist/components/chat/Messages.d.ts +1 -1
- package/dist/components/chat/Messages.js +2 -2
- package/dist/components/chat/Messages.js.map +1 -1
- package/dist/components/chat/Messages.mjs +5 -5
- package/dist/components/chat/Modal.d.ts +50 -0
- package/dist/components/chat/Modal.js +1584 -0
- package/dist/components/chat/Modal.js.map +1 -0
- package/dist/components/chat/Modal.mjs +23 -0
- package/dist/components/chat/Modal.mjs.map +1 -0
- package/dist/components/chat/Popup.d.ts +56 -4
- package/dist/components/chat/Popup.js +428 -78
- package/dist/components/chat/Popup.js.map +1 -1
- package/dist/components/chat/Popup.mjs +15 -12
- package/dist/components/chat/Response.js.map +1 -1
- package/dist/components/chat/Response.mjs +3 -3
- package/dist/components/chat/Sidebar.d.ts +7 -8
- package/dist/components/chat/Sidebar.js +430 -80
- package/dist/components/chat/Sidebar.js.map +1 -1
- package/dist/components/chat/Sidebar.mjs +15 -12
- package/dist/components/chat/Suggestion.d.ts +13 -0
- package/dist/components/chat/Suggestion.js +172 -0
- package/dist/components/chat/Suggestion.js.map +1 -0
- package/dist/components/chat/Suggestion.mjs +11 -0
- package/dist/components/chat/Suggestion.mjs.map +1 -0
- package/dist/components/chat/Textarea.d.ts +4 -4
- package/dist/components/chat/Textarea.js +1 -1
- package/dist/components/chat/Textarea.js.map +1 -1
- package/dist/components/chat/Textarea.mjs +1 -1
- package/dist/components/chat/index.d.ts +4 -2
- package/dist/components/chat/index.js +436 -84
- package/dist/components/chat/index.js.map +1 -1
- package/dist/components/chat/index.mjs +22 -16
- package/dist/components/chat/props.d.ts +10 -3
- package/dist/components/chat/props.js.map +1 -1
- package/dist/components/index.d.ts +4 -2
- package/dist/components/index.js +436 -84
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +22 -16
- package/dist/hooks/index.d.ts +1 -2
- package/dist/hooks/index.js +36 -0
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +8 -1
- package/dist/hooks/use-copilot-chat-suggestions.d.ts +87 -0
- package/dist/hooks/use-copilot-chat-suggestions.js +53 -0
- package/dist/hooks/use-copilot-chat-suggestions.js.map +1 -0
- package/dist/hooks/use-copilot-chat-suggestions.mjs +8 -0
- package/dist/hooks/use-copilot-chat-suggestions.mjs.map +1 -0
- package/dist/hooks/use-push-to-talk.d.ts +19 -0
- package/dist/hooks/use-push-to-talk.js +177 -0
- package/dist/hooks/use-push-to-talk.js.map +1 -0
- package/dist/hooks/use-push-to-talk.mjs +12 -0
- package/dist/hooks/use-push-to-talk.mjs.map +1 -0
- package/dist/index.css +101 -13
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.js +465 -86
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -19
- package/dist/types/suggestions.d.ts +8 -0
- package/dist/types/suggestions.js +19 -0
- package/dist/types/suggestions.js.map +1 -0
- package/dist/types/suggestions.mjs +1 -0
- package/dist/types/suggestions.mjs.map +1 -0
- package/package.json +6 -6
- package/src/components/chat/Button.tsx +1 -2
- package/src/components/chat/Chat.tsx +163 -104
- package/src/components/chat/ChatContext.tsx +36 -38
- package/src/components/chat/Icons.tsx +44 -0
- package/src/components/chat/Input.tsx +38 -7
- package/src/components/chat/Messages.tsx +3 -3
- package/src/components/chat/Modal.tsx +115 -0
- package/src/components/chat/Popup.tsx +53 -7
- package/src/components/chat/Sidebar.tsx +62 -9
- package/src/components/chat/Suggestion.tsx +109 -0
- package/src/components/chat/Textarea.tsx +1 -1
- package/src/components/chat/index.tsx +1 -0
- package/src/components/chat/props.ts +10 -2
- package/src/css/input.css +18 -8
- package/src/css/messages.css +7 -1
- package/src/css/panel.css +38 -0
- package/src/css/response.css +1 -4
- package/src/css/suggestions.css +35 -0
- package/src/css/window.css +3 -1
- package/src/hooks/index.ts +1 -1
- package/src/hooks/use-copilot-chat-suggestions.tsx +117 -0
- package/src/hooks/use-push-to-talk.tsx +162 -0
- package/src/styles.css +2 -0
- package/src/types/suggestions.ts +6 -0
- package/typedoc.json +4 -0
- package/dist/chunk-6U3O2JZP.mjs.map +0 -1
- package/dist/chunk-73EBDGYK.mjs.map +0 -1
- package/dist/chunk-7LMXXGJT.mjs +0 -75
- package/dist/chunk-7LMXXGJT.mjs.map +0 -1
- package/dist/chunk-7YXG7D47.mjs.map +0 -1
- package/dist/chunk-H4VKQGVU.mjs +0 -1
- package/dist/chunk-KE3N45ZY.mjs +0 -63
- package/dist/chunk-KE3N45ZY.mjs.map +0 -1
- package/dist/chunk-T3WYKWNC.mjs.map +0 -1
- package/dist/chunk-UGQQ4WEQ.mjs +0 -1
- package/dist/chunk-YAORLSQ3.mjs.map +0 -1
- package/dist/chunk-YTIGBBTC.mjs.map +0 -1
- /package/dist/{chunk-YEHO5VMA.mjs.map → chunk-CE7PJAAO.mjs.map} +0 -0
- /package/dist/{chunk-H4VKQGVU.mjs.map → chunk-MRFF7GSQ.mjs.map} +0 -0
- /package/dist/{chunk-7JYUCW7H.mjs.map → chunk-PAQWLSA4.mjs.map} +0 -0
- /package/dist/{chunk-UGQQ4WEQ.mjs.map → chunk-T26KLXLH.mjs.map} +0 -0
- /package/dist/{chunk-MBYUBR3F.mjs.map → chunk-UPTB2MVO.mjs.map} +0 -0
- /package/dist/{chunk-WDHLWSSU.mjs.map → chunk-YQ3D5IQV.mjs.map} +0 -0
|
@@ -0,0 +1,1584 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __objRest = (source, exclude) => {
|
|
26
|
+
var target = {};
|
|
27
|
+
for (var prop in source)
|
|
28
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
if (source != null && __getOwnPropSymbols)
|
|
31
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
+
target[prop] = source[prop];
|
|
34
|
+
}
|
|
35
|
+
return target;
|
|
36
|
+
};
|
|
37
|
+
var __export = (target, all) => {
|
|
38
|
+
for (var name in all)
|
|
39
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
40
|
+
};
|
|
41
|
+
var __copyProps = (to, from, except, desc) => {
|
|
42
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
43
|
+
for (let key of __getOwnPropNames(from))
|
|
44
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
45
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
46
|
+
}
|
|
47
|
+
return to;
|
|
48
|
+
};
|
|
49
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
50
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
51
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
52
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
53
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
54
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
55
|
+
mod
|
|
56
|
+
));
|
|
57
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
58
|
+
var __async = (__this, __arguments, generator) => {
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
var fulfilled = (value) => {
|
|
61
|
+
try {
|
|
62
|
+
step(generator.next(value));
|
|
63
|
+
} catch (e) {
|
|
64
|
+
reject(e);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
var rejected = (value) => {
|
|
68
|
+
try {
|
|
69
|
+
step(generator.throw(value));
|
|
70
|
+
} catch (e) {
|
|
71
|
+
reject(e);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
75
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// src/components/chat/Modal.tsx
|
|
80
|
+
var Modal_exports = {};
|
|
81
|
+
__export(Modal_exports, {
|
|
82
|
+
CopilotModal: () => CopilotModal
|
|
83
|
+
});
|
|
84
|
+
module.exports = __toCommonJS(Modal_exports);
|
|
85
|
+
var import_react10 = __toESM(require("react"));
|
|
86
|
+
|
|
87
|
+
// src/components/chat/ChatContext.tsx
|
|
88
|
+
var import_react = __toESM(require("react"));
|
|
89
|
+
|
|
90
|
+
// src/components/chat/Icons.tsx
|
|
91
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
92
|
+
var OpenIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
93
|
+
"svg",
|
|
94
|
+
{
|
|
95
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
96
|
+
viewBox: "0 0 24 24",
|
|
97
|
+
fill: "currentColor",
|
|
98
|
+
width: "24",
|
|
99
|
+
height: "24",
|
|
100
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("g", { transform: "translate(24, 0) scale(-1, 1)", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
101
|
+
"path",
|
|
102
|
+
{
|
|
103
|
+
fillRule: "evenodd",
|
|
104
|
+
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",
|
|
105
|
+
clipRule: "evenodd"
|
|
106
|
+
}
|
|
107
|
+
) })
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
var CloseIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
111
|
+
"svg",
|
|
112
|
+
{
|
|
113
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
114
|
+
fill: "none",
|
|
115
|
+
viewBox: "0 0 24 24",
|
|
116
|
+
strokeWidth: "1.5",
|
|
117
|
+
stroke: "currentColor",
|
|
118
|
+
width: "24",
|
|
119
|
+
height: "24",
|
|
120
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M19.5 8.25l-7.5 7.5-7.5-7.5" })
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
var HeaderCloseIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
124
|
+
"svg",
|
|
125
|
+
{
|
|
126
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
127
|
+
fill: "none",
|
|
128
|
+
viewBox: "0 0 24 24",
|
|
129
|
+
strokeWidth: "1.5",
|
|
130
|
+
stroke: "currentColor",
|
|
131
|
+
width: "24",
|
|
132
|
+
height: "24",
|
|
133
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 18L18 6M6 6l12 12" })
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
var SendIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
137
|
+
"svg",
|
|
138
|
+
{
|
|
139
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
140
|
+
fill: "none",
|
|
141
|
+
viewBox: "0 0 24 24",
|
|
142
|
+
strokeWidth: 1.5,
|
|
143
|
+
stroke: "currentColor",
|
|
144
|
+
width: "24",
|
|
145
|
+
height: "24",
|
|
146
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
147
|
+
"path",
|
|
148
|
+
{
|
|
149
|
+
strokeLinecap: "round",
|
|
150
|
+
strokeLinejoin: "round",
|
|
151
|
+
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"
|
|
152
|
+
}
|
|
153
|
+
)
|
|
154
|
+
}
|
|
155
|
+
);
|
|
156
|
+
var SpinnerIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
157
|
+
"svg",
|
|
158
|
+
{
|
|
159
|
+
style: {
|
|
160
|
+
animation: "copilotKitSpinAnimation 1s linear infinite",
|
|
161
|
+
color: "rgb(107 114 128)"
|
|
162
|
+
},
|
|
163
|
+
width: "24",
|
|
164
|
+
height: "24",
|
|
165
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
166
|
+
fill: "none",
|
|
167
|
+
viewBox: "0 0 24 24",
|
|
168
|
+
children: [
|
|
169
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
170
|
+
"circle",
|
|
171
|
+
{
|
|
172
|
+
style: { opacity: 0.25 },
|
|
173
|
+
cx: "12",
|
|
174
|
+
cy: "12",
|
|
175
|
+
r: "10",
|
|
176
|
+
stroke: "currentColor",
|
|
177
|
+
strokeWidth: "4"
|
|
178
|
+
}
|
|
179
|
+
),
|
|
180
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
181
|
+
"path",
|
|
182
|
+
{
|
|
183
|
+
style: { opacity: 0.75 },
|
|
184
|
+
fill: "currentColor",
|
|
185
|
+
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"
|
|
186
|
+
}
|
|
187
|
+
)
|
|
188
|
+
]
|
|
189
|
+
}
|
|
190
|
+
);
|
|
191
|
+
var SmallSpinnerIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
192
|
+
"svg",
|
|
193
|
+
{
|
|
194
|
+
style: {
|
|
195
|
+
animation: "copilotKitSpinAnimation 1s linear infinite"
|
|
196
|
+
},
|
|
197
|
+
width: "13",
|
|
198
|
+
height: "13",
|
|
199
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
200
|
+
fill: "none",
|
|
201
|
+
viewBox: "0 0 24 24",
|
|
202
|
+
children: [
|
|
203
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
204
|
+
"circle",
|
|
205
|
+
{
|
|
206
|
+
style: { opacity: 0.25 },
|
|
207
|
+
cx: "12",
|
|
208
|
+
cy: "12",
|
|
209
|
+
r: "10",
|
|
210
|
+
stroke: "currentColor",
|
|
211
|
+
strokeWidth: "4"
|
|
212
|
+
}
|
|
213
|
+
),
|
|
214
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
215
|
+
"path",
|
|
216
|
+
{
|
|
217
|
+
style: { opacity: 0.75 },
|
|
218
|
+
fill: "currentColor",
|
|
219
|
+
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"
|
|
220
|
+
}
|
|
221
|
+
)
|
|
222
|
+
]
|
|
223
|
+
}
|
|
224
|
+
);
|
|
225
|
+
var ActivityIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
226
|
+
"svg",
|
|
227
|
+
{
|
|
228
|
+
style: {
|
|
229
|
+
display: "inline-block",
|
|
230
|
+
marginLeft: "0.25rem",
|
|
231
|
+
marginRight: "0.25rem"
|
|
232
|
+
},
|
|
233
|
+
height: "24",
|
|
234
|
+
width: "24",
|
|
235
|
+
viewBox: "0 0 27 27",
|
|
236
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
237
|
+
fill: "currentColor",
|
|
238
|
+
children: [
|
|
239
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { className: "copilotKitActivityDot1", cx: "4", cy: "12", r: "3" }),
|
|
240
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { className: "copilotKitActivityDot1 copilotKitActivityDot2", cx: "12", cy: "12", r: "3" }),
|
|
241
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { className: "copilotKitActivityDot1 copilotKitActivityDot3", cx: "20", cy: "12", r: "3" })
|
|
242
|
+
]
|
|
243
|
+
}
|
|
244
|
+
);
|
|
245
|
+
function CheckIcon(_a) {
|
|
246
|
+
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
247
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
248
|
+
"svg",
|
|
249
|
+
__spreadProps(__spreadValues({
|
|
250
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
251
|
+
viewBox: "0 0 256 256",
|
|
252
|
+
fill: "currentColor",
|
|
253
|
+
style: { height: "1rem", width: "1rem" },
|
|
254
|
+
className
|
|
255
|
+
}, props), {
|
|
256
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.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" })
|
|
257
|
+
})
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
function DownloadIcon(_a) {
|
|
261
|
+
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
262
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
263
|
+
"svg",
|
|
264
|
+
__spreadProps(__spreadValues({
|
|
265
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
266
|
+
viewBox: "0 0 256 256",
|
|
267
|
+
fill: "currentColor",
|
|
268
|
+
style: { height: "1rem", width: "1rem" },
|
|
269
|
+
className
|
|
270
|
+
}, props), {
|
|
271
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.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" })
|
|
272
|
+
})
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
function CopyIcon(_a) {
|
|
276
|
+
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
277
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
278
|
+
"svg",
|
|
279
|
+
__spreadProps(__spreadValues({
|
|
280
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
281
|
+
viewBox: "0 0 256 256",
|
|
282
|
+
fill: "currentColor",
|
|
283
|
+
style: { height: "1rem", width: "1rem" },
|
|
284
|
+
className
|
|
285
|
+
}, props), {
|
|
286
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.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" })
|
|
287
|
+
})
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
var StopIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
291
|
+
"svg",
|
|
292
|
+
{
|
|
293
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
294
|
+
viewBox: "0 0 256 256",
|
|
295
|
+
fill: "currentColor",
|
|
296
|
+
style: { height: "1rem", width: "1rem" },
|
|
297
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("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" })
|
|
298
|
+
}
|
|
299
|
+
);
|
|
300
|
+
var RegenerateIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
301
|
+
"svg",
|
|
302
|
+
{
|
|
303
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
304
|
+
viewBox: "0 0 256 256",
|
|
305
|
+
fill: "currentColor",
|
|
306
|
+
style: { height: "1rem", width: "1rem" },
|
|
307
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("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" })
|
|
308
|
+
}
|
|
309
|
+
);
|
|
310
|
+
var PushToTalkIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
311
|
+
"svg",
|
|
312
|
+
{
|
|
313
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
314
|
+
fill: "none",
|
|
315
|
+
viewBox: "0 0 24 24",
|
|
316
|
+
strokeWidth: 1.5,
|
|
317
|
+
stroke: "currentColor",
|
|
318
|
+
className: "w-6 h-6",
|
|
319
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
320
|
+
"path",
|
|
321
|
+
{
|
|
322
|
+
strokeLinecap: "round",
|
|
323
|
+
strokeLinejoin: "round",
|
|
324
|
+
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"
|
|
325
|
+
}
|
|
326
|
+
)
|
|
327
|
+
}
|
|
328
|
+
);
|
|
329
|
+
|
|
330
|
+
// src/components/chat/ChatContext.tsx
|
|
331
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
332
|
+
var ChatContext = import_react.default.createContext(void 0);
|
|
333
|
+
function useChatContext() {
|
|
334
|
+
const context = import_react.default.useContext(ChatContext);
|
|
335
|
+
if (context === void 0) {
|
|
336
|
+
throw new Error(
|
|
337
|
+
"Context not found. Did you forget to wrap your app in a <ChatContextProvider> component?"
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
return context;
|
|
341
|
+
}
|
|
342
|
+
var ChatContextProvider = ({
|
|
343
|
+
// temperature,
|
|
344
|
+
// instructions,
|
|
345
|
+
// maxFeedback,
|
|
346
|
+
labels,
|
|
347
|
+
icons,
|
|
348
|
+
children,
|
|
349
|
+
open,
|
|
350
|
+
setOpen
|
|
351
|
+
}) => {
|
|
352
|
+
const context = {
|
|
353
|
+
labels: __spreadValues(__spreadValues({}, {
|
|
354
|
+
initial: "",
|
|
355
|
+
title: "CopilotKit",
|
|
356
|
+
placeholder: "Type a message...",
|
|
357
|
+
error: "\u274C An error occurred. Please try again.",
|
|
358
|
+
stopGenerating: "Stop generating",
|
|
359
|
+
regenerateResponse: "Regenerate response"
|
|
360
|
+
}), labels),
|
|
361
|
+
icons: __spreadProps(__spreadValues({}, {
|
|
362
|
+
openIcon: OpenIcon,
|
|
363
|
+
closeIcon: CloseIcon,
|
|
364
|
+
headerCloseIcon: HeaderCloseIcon,
|
|
365
|
+
sendIcon: SendIcon,
|
|
366
|
+
activityIcon: ActivityIcon,
|
|
367
|
+
spinnerIcon: SpinnerIcon,
|
|
368
|
+
stopIcon: StopIcon,
|
|
369
|
+
regenerateIcon: RegenerateIcon,
|
|
370
|
+
pushToTalkIcon: PushToTalkIcon
|
|
371
|
+
}), {
|
|
372
|
+
icons
|
|
373
|
+
}),
|
|
374
|
+
open,
|
|
375
|
+
setOpen
|
|
376
|
+
};
|
|
377
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChatContext.Provider, { value: context, children });
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
// src/components/chat/Window.tsx
|
|
381
|
+
var import_react2 = __toESM(require("react"));
|
|
382
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
383
|
+
var Window = ({
|
|
384
|
+
open,
|
|
385
|
+
setOpen,
|
|
386
|
+
children,
|
|
387
|
+
clickOutsideToClose,
|
|
388
|
+
shortcut,
|
|
389
|
+
hitEscapeToClose
|
|
390
|
+
}) => {
|
|
391
|
+
const windowRef = import_react2.default.useRef(null);
|
|
392
|
+
const handleClickOutside = (0, import_react2.useCallback)(
|
|
393
|
+
(event) => {
|
|
394
|
+
var _a;
|
|
395
|
+
if (!clickOutsideToClose) {
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
const parentElement = (_a = windowRef.current) == null ? void 0 : _a.parentElement;
|
|
399
|
+
if (open && parentElement && !parentElement.contains(event.target)) {
|
|
400
|
+
setOpen(false);
|
|
401
|
+
}
|
|
402
|
+
},
|
|
403
|
+
[clickOutsideToClose, open, setOpen]
|
|
404
|
+
);
|
|
405
|
+
const handleKeyDown = (0, import_react2.useCallback)(
|
|
406
|
+
(event) => {
|
|
407
|
+
var _a;
|
|
408
|
+
const target = event.target;
|
|
409
|
+
const isInput = target.tagName === "INPUT" || target.tagName === "SELECT" || target.tagName === "TEXTAREA" || target.isContentEditable;
|
|
410
|
+
const isDescendantOfWrapper = (_a = windowRef.current) == null ? void 0 : _a.contains(target);
|
|
411
|
+
if (open && event.key === "Escape" && (!isInput || isDescendantOfWrapper) && hitEscapeToClose) {
|
|
412
|
+
setOpen(false);
|
|
413
|
+
} else if (event.key === shortcut && (isMacOS() && event.metaKey || !isMacOS() && event.ctrlKey) && (!isInput || isDescendantOfWrapper)) {
|
|
414
|
+
setOpen(!open);
|
|
415
|
+
}
|
|
416
|
+
},
|
|
417
|
+
[hitEscapeToClose, shortcut, open, setOpen]
|
|
418
|
+
);
|
|
419
|
+
const adjustForMobile = (0, import_react2.useCallback)(() => {
|
|
420
|
+
const copilotKitWindow = windowRef.current;
|
|
421
|
+
const vv = window.visualViewport;
|
|
422
|
+
if (!copilotKitWindow || !vv) {
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
if (window.innerWidth < 640 && open) {
|
|
426
|
+
copilotKitWindow.style.height = `${vv.height}px`;
|
|
427
|
+
copilotKitWindow.style.left = `${vv.offsetLeft}px`;
|
|
428
|
+
copilotKitWindow.style.top = `${vv.offsetTop}px`;
|
|
429
|
+
document.body.style.position = "fixed";
|
|
430
|
+
document.body.style.width = "100%";
|
|
431
|
+
document.body.style.height = `${window.innerHeight}px`;
|
|
432
|
+
document.body.style.overflow = "hidden";
|
|
433
|
+
document.body.style.touchAction = "none";
|
|
434
|
+
document.body.addEventListener("touchmove", preventScroll, {
|
|
435
|
+
passive: false
|
|
436
|
+
});
|
|
437
|
+
} else {
|
|
438
|
+
copilotKitWindow.style.height = "";
|
|
439
|
+
copilotKitWindow.style.left = "";
|
|
440
|
+
copilotKitWindow.style.top = "";
|
|
441
|
+
document.body.style.position = "";
|
|
442
|
+
document.body.style.height = "";
|
|
443
|
+
document.body.style.width = "";
|
|
444
|
+
document.body.style.overflow = "";
|
|
445
|
+
document.body.style.top = "";
|
|
446
|
+
document.body.style.touchAction = "";
|
|
447
|
+
document.body.removeEventListener("touchmove", preventScroll);
|
|
448
|
+
}
|
|
449
|
+
}, [open]);
|
|
450
|
+
(0, import_react2.useEffect)(() => {
|
|
451
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
452
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
453
|
+
if (window.visualViewport) {
|
|
454
|
+
window.visualViewport.addEventListener("resize", adjustForMobile);
|
|
455
|
+
adjustForMobile();
|
|
456
|
+
}
|
|
457
|
+
return () => {
|
|
458
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
459
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
460
|
+
if (window.visualViewport) {
|
|
461
|
+
window.visualViewport.removeEventListener("resize", adjustForMobile);
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
}, [adjustForMobile, handleClickOutside, handleKeyDown]);
|
|
465
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: `copilotKitWindow${open ? " open" : ""}`, ref: windowRef, children });
|
|
466
|
+
};
|
|
467
|
+
var preventScroll = (event) => {
|
|
468
|
+
let targetElement = event.target;
|
|
469
|
+
const hasParentWithClass = (element, className) => {
|
|
470
|
+
while (element && element !== document.body) {
|
|
471
|
+
if (element.classList.contains(className)) {
|
|
472
|
+
return true;
|
|
473
|
+
}
|
|
474
|
+
element = element.parentElement;
|
|
475
|
+
}
|
|
476
|
+
return false;
|
|
477
|
+
};
|
|
478
|
+
if (!hasParentWithClass(targetElement, "copilotKitMessages")) {
|
|
479
|
+
event.preventDefault();
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
function isMacOS() {
|
|
483
|
+
return /Mac|iMac|Macintosh/i.test(navigator.userAgent);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// src/components/chat/Button.tsx
|
|
487
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
488
|
+
var Button = ({ open, setOpen }) => {
|
|
489
|
+
const context = useChatContext();
|
|
490
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { onClick: () => setOpen(!open), children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
491
|
+
"button",
|
|
492
|
+
{
|
|
493
|
+
className: `copilotKitButton ${open ? "open" : ""}`,
|
|
494
|
+
"aria-label": open ? "Close Chat" : "Open Chat",
|
|
495
|
+
children: [
|
|
496
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "copilotKitButtonIcon copilotKitButtonIconOpen", children: context.icons.openIcon }),
|
|
497
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "copilotKitButtonIcon copilotKitButtonIconClose", children: context.icons.closeIcon })
|
|
498
|
+
]
|
|
499
|
+
}
|
|
500
|
+
) });
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
// src/components/chat/Header.tsx
|
|
504
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
505
|
+
var Header = ({ setOpen }) => {
|
|
506
|
+
const context = useChatContext();
|
|
507
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "copilotKitHeader", children: [
|
|
508
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { children: context.labels.title }),
|
|
509
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { onClick: () => setOpen(false), "aria-label": "Close", children: context.icons.headerCloseIcon })
|
|
510
|
+
] });
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
// src/components/chat/Messages.tsx
|
|
514
|
+
var import_react5 = __toESM(require("react"));
|
|
515
|
+
var import_nanoid = require("nanoid");
|
|
516
|
+
var import_shared = require("@copilotkit/shared");
|
|
517
|
+
|
|
518
|
+
// src/components/chat/Markdown.tsx
|
|
519
|
+
var import_react4 = require("react");
|
|
520
|
+
var import_react_markdown = __toESM(require("react-markdown"));
|
|
521
|
+
|
|
522
|
+
// src/components/chat/CodeBlock.tsx
|
|
523
|
+
var import_react3 = require("react");
|
|
524
|
+
var import_react_syntax_highlighter = require("react-syntax-highlighter");
|
|
525
|
+
|
|
526
|
+
// src/hooks/use-copy-to-clipboard.tsx
|
|
527
|
+
var React3 = __toESM(require("react"));
|
|
528
|
+
function useCopyToClipboard({ timeout = 2e3 }) {
|
|
529
|
+
const [isCopied, setIsCopied] = React3.useState(false);
|
|
530
|
+
const copyToClipboard = (value) => {
|
|
531
|
+
var _a;
|
|
532
|
+
if (typeof window === "undefined" || !((_a = navigator.clipboard) == null ? void 0 : _a.writeText)) {
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
if (!value) {
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
navigator.clipboard.writeText(value).then(() => {
|
|
539
|
+
setIsCopied(true);
|
|
540
|
+
setTimeout(() => {
|
|
541
|
+
setIsCopied(false);
|
|
542
|
+
}, timeout);
|
|
543
|
+
});
|
|
544
|
+
};
|
|
545
|
+
return { isCopied, copyToClipboard };
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
// src/components/chat/CodeBlock.tsx
|
|
549
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
550
|
+
var programmingLanguages = {
|
|
551
|
+
javascript: ".js",
|
|
552
|
+
python: ".py",
|
|
553
|
+
java: ".java",
|
|
554
|
+
c: ".c",
|
|
555
|
+
cpp: ".cpp",
|
|
556
|
+
"c++": ".cpp",
|
|
557
|
+
"c#": ".cs",
|
|
558
|
+
ruby: ".rb",
|
|
559
|
+
php: ".php",
|
|
560
|
+
swift: ".swift",
|
|
561
|
+
"objective-c": ".m",
|
|
562
|
+
kotlin: ".kt",
|
|
563
|
+
typescript: ".ts",
|
|
564
|
+
go: ".go",
|
|
565
|
+
perl: ".pl",
|
|
566
|
+
rust: ".rs",
|
|
567
|
+
scala: ".scala",
|
|
568
|
+
haskell: ".hs",
|
|
569
|
+
lua: ".lua",
|
|
570
|
+
shell: ".sh",
|
|
571
|
+
sql: ".sql",
|
|
572
|
+
html: ".html",
|
|
573
|
+
css: ".css"
|
|
574
|
+
// add more file extensions here, make sure the key is same as language prop in CodeBlock.tsx component
|
|
575
|
+
};
|
|
576
|
+
var generateRandomString = (length, lowercase = false) => {
|
|
577
|
+
const chars = "ABCDEFGHJKLMNPQRSTUVWXY3456789";
|
|
578
|
+
let result = "";
|
|
579
|
+
for (let i = 0; i < length; i++) {
|
|
580
|
+
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
581
|
+
}
|
|
582
|
+
return lowercase ? result.toLowerCase() : result;
|
|
583
|
+
};
|
|
584
|
+
var CodeBlock = (0, import_react3.memo)(({ language, value }) => {
|
|
585
|
+
const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2e3 });
|
|
586
|
+
const downloadAsFile = () => {
|
|
587
|
+
if (typeof window === "undefined") {
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
const fileExtension = programmingLanguages[language] || ".file";
|
|
591
|
+
const suggestedFileName = `file-${generateRandomString(3, true)}${fileExtension}`;
|
|
592
|
+
const fileName = window.prompt("Enter file name", suggestedFileName);
|
|
593
|
+
if (!fileName) {
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
const blob = new Blob([value], { type: "text/plain" });
|
|
597
|
+
const url = URL.createObjectURL(blob);
|
|
598
|
+
const link = document.createElement("a");
|
|
599
|
+
link.download = fileName;
|
|
600
|
+
link.href = url;
|
|
601
|
+
link.style.display = "none";
|
|
602
|
+
document.body.appendChild(link);
|
|
603
|
+
link.click();
|
|
604
|
+
document.body.removeChild(link);
|
|
605
|
+
URL.revokeObjectURL(url);
|
|
606
|
+
};
|
|
607
|
+
const onCopy = () => {
|
|
608
|
+
if (isCopied)
|
|
609
|
+
return;
|
|
610
|
+
copyToClipboard(value);
|
|
611
|
+
};
|
|
612
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "copilotKitCodeBlock", children: [
|
|
613
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "copilotKitCodeBlockToolbar", children: [
|
|
614
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "copilotKitCodeBlockToolbarLanguage", children: language }),
|
|
615
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "copilotKitCodeBlockToolbarButtons", children: [
|
|
616
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("button", { className: "copilotKitCodeBlockToolbarButton", onClick: downloadAsFile, children: [
|
|
617
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(DownloadIcon, {}),
|
|
618
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "sr-only", children: "Download" })
|
|
619
|
+
] }),
|
|
620
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("button", { className: "copilotKitCodeBlockToolbarButton", onClick: onCopy, children: [
|
|
621
|
+
isCopied ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CheckIcon, {}) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CopyIcon, {}),
|
|
622
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "sr-only", children: "Copy code" })
|
|
623
|
+
] })
|
|
624
|
+
] })
|
|
625
|
+
] }),
|
|
626
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
627
|
+
import_react_syntax_highlighter.Prism,
|
|
628
|
+
{
|
|
629
|
+
language,
|
|
630
|
+
style: highlightStyle,
|
|
631
|
+
PreTag: "div",
|
|
632
|
+
customStyle: {
|
|
633
|
+
margin: 0,
|
|
634
|
+
borderBottomLeftRadius: "0.375rem",
|
|
635
|
+
borderBottomRightRadius: "0.375rem"
|
|
636
|
+
},
|
|
637
|
+
children: value
|
|
638
|
+
}
|
|
639
|
+
)
|
|
640
|
+
] });
|
|
641
|
+
});
|
|
642
|
+
CodeBlock.displayName = "CodeBlock";
|
|
643
|
+
var highlightStyle = {
|
|
644
|
+
'pre[class*="language-"]': {
|
|
645
|
+
color: "#d4d4d4",
|
|
646
|
+
fontSize: "13px",
|
|
647
|
+
textShadow: "none",
|
|
648
|
+
fontFamily: 'Menlo, Monaco, Consolas, "Andale Mono", "Ubuntu Mono", "Courier New", monospace',
|
|
649
|
+
direction: "ltr",
|
|
650
|
+
textAlign: "left",
|
|
651
|
+
whiteSpace: "pre",
|
|
652
|
+
wordSpacing: "normal",
|
|
653
|
+
wordBreak: "normal",
|
|
654
|
+
lineHeight: "1.5",
|
|
655
|
+
MozTabSize: "4",
|
|
656
|
+
OTabSize: "4",
|
|
657
|
+
tabSize: "4",
|
|
658
|
+
WebkitHyphens: "none",
|
|
659
|
+
MozHyphens: "none",
|
|
660
|
+
msHyphens: "none",
|
|
661
|
+
hyphens: "none",
|
|
662
|
+
padding: "1em",
|
|
663
|
+
margin: ".5em 0",
|
|
664
|
+
overflow: "auto",
|
|
665
|
+
background: "#1e1e1e"
|
|
666
|
+
},
|
|
667
|
+
'code[class*="language-"]': {
|
|
668
|
+
color: "#d4d4d4",
|
|
669
|
+
fontSize: "13px",
|
|
670
|
+
textShadow: "none",
|
|
671
|
+
fontFamily: 'Menlo, Monaco, Consolas, "Andale Mono", "Ubuntu Mono", "Courier New", monospace',
|
|
672
|
+
direction: "ltr",
|
|
673
|
+
textAlign: "left",
|
|
674
|
+
whiteSpace: "pre",
|
|
675
|
+
wordSpacing: "normal",
|
|
676
|
+
wordBreak: "normal",
|
|
677
|
+
lineHeight: "1.5",
|
|
678
|
+
MozTabSize: "4",
|
|
679
|
+
OTabSize: "4",
|
|
680
|
+
tabSize: "4",
|
|
681
|
+
WebkitHyphens: "none",
|
|
682
|
+
MozHyphens: "none",
|
|
683
|
+
msHyphens: "none",
|
|
684
|
+
hyphens: "none"
|
|
685
|
+
},
|
|
686
|
+
'pre[class*="language-"]::selection': {
|
|
687
|
+
textShadow: "none",
|
|
688
|
+
background: "#264F78"
|
|
689
|
+
},
|
|
690
|
+
'code[class*="language-"]::selection': {
|
|
691
|
+
textShadow: "none",
|
|
692
|
+
background: "#264F78"
|
|
693
|
+
},
|
|
694
|
+
'pre[class*="language-"] *::selection': {
|
|
695
|
+
textShadow: "none",
|
|
696
|
+
background: "#264F78"
|
|
697
|
+
},
|
|
698
|
+
'code[class*="language-"] *::selection': {
|
|
699
|
+
textShadow: "none",
|
|
700
|
+
background: "#264F78"
|
|
701
|
+
},
|
|
702
|
+
':not(pre) > code[class*="language-"]': {
|
|
703
|
+
padding: ".1em .3em",
|
|
704
|
+
borderRadius: ".3em",
|
|
705
|
+
color: "#db4c69",
|
|
706
|
+
background: "#1e1e1e"
|
|
707
|
+
},
|
|
708
|
+
".namespace": {
|
|
709
|
+
Opacity: ".7"
|
|
710
|
+
},
|
|
711
|
+
"doctype.doctype-tag": {
|
|
712
|
+
color: "#569CD6"
|
|
713
|
+
},
|
|
714
|
+
"doctype.name": {
|
|
715
|
+
color: "#9cdcfe"
|
|
716
|
+
},
|
|
717
|
+
comment: {
|
|
718
|
+
color: "#6a9955"
|
|
719
|
+
},
|
|
720
|
+
prolog: {
|
|
721
|
+
color: "#6a9955"
|
|
722
|
+
},
|
|
723
|
+
punctuation: {
|
|
724
|
+
color: "#d4d4d4"
|
|
725
|
+
},
|
|
726
|
+
".language-html .language-css .token.punctuation": {
|
|
727
|
+
color: "#d4d4d4"
|
|
728
|
+
},
|
|
729
|
+
".language-html .language-javascript .token.punctuation": {
|
|
730
|
+
color: "#d4d4d4"
|
|
731
|
+
},
|
|
732
|
+
property: {
|
|
733
|
+
color: "#9cdcfe"
|
|
734
|
+
},
|
|
735
|
+
tag: {
|
|
736
|
+
color: "#569cd6"
|
|
737
|
+
},
|
|
738
|
+
boolean: {
|
|
739
|
+
color: "#569cd6"
|
|
740
|
+
},
|
|
741
|
+
number: {
|
|
742
|
+
color: "#b5cea8"
|
|
743
|
+
},
|
|
744
|
+
constant: {
|
|
745
|
+
color: "#9cdcfe"
|
|
746
|
+
},
|
|
747
|
+
symbol: {
|
|
748
|
+
color: "#b5cea8"
|
|
749
|
+
},
|
|
750
|
+
inserted: {
|
|
751
|
+
color: "#b5cea8"
|
|
752
|
+
},
|
|
753
|
+
unit: {
|
|
754
|
+
color: "#b5cea8"
|
|
755
|
+
},
|
|
756
|
+
selector: {
|
|
757
|
+
color: "#d7ba7d"
|
|
758
|
+
},
|
|
759
|
+
"attr-name": {
|
|
760
|
+
color: "#9cdcfe"
|
|
761
|
+
},
|
|
762
|
+
string: {
|
|
763
|
+
color: "#ce9178"
|
|
764
|
+
},
|
|
765
|
+
char: {
|
|
766
|
+
color: "#ce9178"
|
|
767
|
+
},
|
|
768
|
+
builtin: {
|
|
769
|
+
color: "#ce9178"
|
|
770
|
+
},
|
|
771
|
+
deleted: {
|
|
772
|
+
color: "#ce9178"
|
|
773
|
+
},
|
|
774
|
+
".language-css .token.string.url": {
|
|
775
|
+
textDecoration: "underline"
|
|
776
|
+
},
|
|
777
|
+
operator: {
|
|
778
|
+
color: "#d4d4d4"
|
|
779
|
+
},
|
|
780
|
+
entity: {
|
|
781
|
+
color: "#569cd6"
|
|
782
|
+
},
|
|
783
|
+
"operator.arrow": {
|
|
784
|
+
color: "#569CD6"
|
|
785
|
+
},
|
|
786
|
+
atrule: {
|
|
787
|
+
color: "#ce9178"
|
|
788
|
+
},
|
|
789
|
+
"atrule.rule": {
|
|
790
|
+
color: "#c586c0"
|
|
791
|
+
},
|
|
792
|
+
"atrule.url": {
|
|
793
|
+
color: "#9cdcfe"
|
|
794
|
+
},
|
|
795
|
+
"atrule.url.function": {
|
|
796
|
+
color: "#dcdcaa"
|
|
797
|
+
},
|
|
798
|
+
"atrule.url.punctuation": {
|
|
799
|
+
color: "#d4d4d4"
|
|
800
|
+
},
|
|
801
|
+
keyword: {
|
|
802
|
+
color: "#569CD6"
|
|
803
|
+
},
|
|
804
|
+
"keyword.module": {
|
|
805
|
+
color: "#c586c0"
|
|
806
|
+
},
|
|
807
|
+
"keyword.control-flow": {
|
|
808
|
+
color: "#c586c0"
|
|
809
|
+
},
|
|
810
|
+
function: {
|
|
811
|
+
color: "#dcdcaa"
|
|
812
|
+
},
|
|
813
|
+
"function.maybe-class-name": {
|
|
814
|
+
color: "#dcdcaa"
|
|
815
|
+
},
|
|
816
|
+
regex: {
|
|
817
|
+
color: "#d16969"
|
|
818
|
+
},
|
|
819
|
+
important: {
|
|
820
|
+
color: "#569cd6"
|
|
821
|
+
},
|
|
822
|
+
italic: {
|
|
823
|
+
fontStyle: "italic"
|
|
824
|
+
},
|
|
825
|
+
"class-name": {
|
|
826
|
+
color: "#4ec9b0"
|
|
827
|
+
},
|
|
828
|
+
"maybe-class-name": {
|
|
829
|
+
color: "#4ec9b0"
|
|
830
|
+
},
|
|
831
|
+
console: {
|
|
832
|
+
color: "#9cdcfe"
|
|
833
|
+
},
|
|
834
|
+
parameter: {
|
|
835
|
+
color: "#9cdcfe"
|
|
836
|
+
},
|
|
837
|
+
interpolation: {
|
|
838
|
+
color: "#9cdcfe"
|
|
839
|
+
},
|
|
840
|
+
"punctuation.interpolation-punctuation": {
|
|
841
|
+
color: "#569cd6"
|
|
842
|
+
},
|
|
843
|
+
variable: {
|
|
844
|
+
color: "#9cdcfe"
|
|
845
|
+
},
|
|
846
|
+
"imports.maybe-class-name": {
|
|
847
|
+
color: "#9cdcfe"
|
|
848
|
+
},
|
|
849
|
+
"exports.maybe-class-name": {
|
|
850
|
+
color: "#9cdcfe"
|
|
851
|
+
},
|
|
852
|
+
escape: {
|
|
853
|
+
color: "#d7ba7d"
|
|
854
|
+
},
|
|
855
|
+
"tag.punctuation": {
|
|
856
|
+
color: "#808080"
|
|
857
|
+
},
|
|
858
|
+
cdata: {
|
|
859
|
+
color: "#808080"
|
|
860
|
+
},
|
|
861
|
+
"attr-value": {
|
|
862
|
+
color: "#ce9178"
|
|
863
|
+
},
|
|
864
|
+
"attr-value.punctuation": {
|
|
865
|
+
color: "#ce9178"
|
|
866
|
+
},
|
|
867
|
+
"attr-value.punctuation.attr-equals": {
|
|
868
|
+
color: "#d4d4d4"
|
|
869
|
+
},
|
|
870
|
+
namespace: {
|
|
871
|
+
color: "#4ec9b0"
|
|
872
|
+
},
|
|
873
|
+
'pre[class*="language-javascript"]': {
|
|
874
|
+
color: "#9cdcfe"
|
|
875
|
+
},
|
|
876
|
+
'code[class*="language-javascript"]': {
|
|
877
|
+
color: "#9cdcfe"
|
|
878
|
+
},
|
|
879
|
+
'pre[class*="language-jsx"]': {
|
|
880
|
+
color: "#9cdcfe"
|
|
881
|
+
},
|
|
882
|
+
'code[class*="language-jsx"]': {
|
|
883
|
+
color: "#9cdcfe"
|
|
884
|
+
},
|
|
885
|
+
'pre[class*="language-typescript"]': {
|
|
886
|
+
color: "#9cdcfe"
|
|
887
|
+
},
|
|
888
|
+
'code[class*="language-typescript"]': {
|
|
889
|
+
color: "#9cdcfe"
|
|
890
|
+
},
|
|
891
|
+
'pre[class*="language-tsx"]': {
|
|
892
|
+
color: "#9cdcfe"
|
|
893
|
+
},
|
|
894
|
+
'code[class*="language-tsx"]': {
|
|
895
|
+
color: "#9cdcfe"
|
|
896
|
+
},
|
|
897
|
+
'pre[class*="language-css"]': {
|
|
898
|
+
color: "#ce9178"
|
|
899
|
+
},
|
|
900
|
+
'code[class*="language-css"]': {
|
|
901
|
+
color: "#ce9178"
|
|
902
|
+
},
|
|
903
|
+
'pre[class*="language-html"]': {
|
|
904
|
+
color: "#d4d4d4"
|
|
905
|
+
},
|
|
906
|
+
'code[class*="language-html"]': {
|
|
907
|
+
color: "#d4d4d4"
|
|
908
|
+
},
|
|
909
|
+
".language-regex .token.anchor": {
|
|
910
|
+
color: "#dcdcaa"
|
|
911
|
+
},
|
|
912
|
+
".language-html .token.punctuation": {
|
|
913
|
+
color: "#808080"
|
|
914
|
+
},
|
|
915
|
+
'pre[class*="language-"] > code[class*="language-"]': {
|
|
916
|
+
position: "relative",
|
|
917
|
+
zIndex: "1"
|
|
918
|
+
},
|
|
919
|
+
".line-highlight.line-highlight": {
|
|
920
|
+
background: "#f7ebc6",
|
|
921
|
+
boxShadow: "inset 5px 0 0 #f7d87c",
|
|
922
|
+
zIndex: "0"
|
|
923
|
+
}
|
|
924
|
+
};
|
|
925
|
+
|
|
926
|
+
// src/components/chat/Markdown.tsx
|
|
927
|
+
var import_remark_gfm = __toESM(require("remark-gfm"));
|
|
928
|
+
var import_remark_math = __toESM(require("remark-math"));
|
|
929
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
930
|
+
var MemoizedReactMarkdown = (0, import_react4.memo)(
|
|
931
|
+
import_react_markdown.default,
|
|
932
|
+
(prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.className === nextProps.className
|
|
933
|
+
);
|
|
934
|
+
var Markdown = ({ content }) => {
|
|
935
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "copilotKitMarkdown", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(MemoizedReactMarkdown, { components, remarkPlugins: [import_remark_gfm.default, import_remark_math.default], children: content }) });
|
|
936
|
+
};
|
|
937
|
+
var components = {
|
|
938
|
+
p({ children }) {
|
|
939
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children });
|
|
940
|
+
},
|
|
941
|
+
a(_a) {
|
|
942
|
+
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
943
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
944
|
+
"a",
|
|
945
|
+
__spreadProps(__spreadValues({
|
|
946
|
+
style: { color: "blue", textDecoration: "underline" }
|
|
947
|
+
}, props), {
|
|
948
|
+
target: "_blank",
|
|
949
|
+
rel: "noopener noreferrer",
|
|
950
|
+
children
|
|
951
|
+
})
|
|
952
|
+
);
|
|
953
|
+
},
|
|
954
|
+
code(_c) {
|
|
955
|
+
var _d = _c, { children, className, inline } = _d, props = __objRest(_d, ["children", "className", "inline"]);
|
|
956
|
+
if (children.length) {
|
|
957
|
+
if (children[0] == "\u258D") {
|
|
958
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
959
|
+
"span",
|
|
960
|
+
{
|
|
961
|
+
style: {
|
|
962
|
+
animation: "pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite",
|
|
963
|
+
marginTop: "0.25rem"
|
|
964
|
+
},
|
|
965
|
+
children: "\u258D"
|
|
966
|
+
}
|
|
967
|
+
);
|
|
968
|
+
}
|
|
969
|
+
children[0] = children[0].replace("`\u258D`", "\u258D");
|
|
970
|
+
}
|
|
971
|
+
const match = /language-(\w+)/.exec(className || "");
|
|
972
|
+
if (inline) {
|
|
973
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("code", __spreadProps(__spreadValues({ className }, props), { children }));
|
|
974
|
+
}
|
|
975
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
976
|
+
CodeBlock,
|
|
977
|
+
__spreadValues({
|
|
978
|
+
language: match && match[1] || "",
|
|
979
|
+
value: String(children).replace(/\n$/, "")
|
|
980
|
+
}, props),
|
|
981
|
+
Math.random()
|
|
982
|
+
);
|
|
983
|
+
}
|
|
984
|
+
};
|
|
985
|
+
|
|
986
|
+
// src/components/chat/Messages.tsx
|
|
987
|
+
var import_react_core = require("@copilotkit/react-core");
|
|
988
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
989
|
+
var Messages = ({ messages, inProgress, children }) => {
|
|
990
|
+
const { chatComponentsCache } = (0, import_react_core.useCopilotContext)();
|
|
991
|
+
const context = useChatContext();
|
|
992
|
+
const initialMessages = (0, import_react5.useMemo)(
|
|
993
|
+
() => makeInitialMessages(context.labels.initial),
|
|
994
|
+
[context.labels.initial]
|
|
995
|
+
);
|
|
996
|
+
messages = [...initialMessages, ...messages];
|
|
997
|
+
const functionResults = {};
|
|
998
|
+
for (let i = 0; i < messages.length; i++) {
|
|
999
|
+
if (messages[i].role === "assistant" && messages[i].function_call) {
|
|
1000
|
+
const id = messages[i].id;
|
|
1001
|
+
if (i + 1 < messages.length && messages[i + 1].role === "function") {
|
|
1002
|
+
functionResults[id] = (0, import_shared.decodeResult)(messages[i + 1].content || "");
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
const messagesEndRef = import_react5.default.useRef(null);
|
|
1007
|
+
const scrollToBottom = () => {
|
|
1008
|
+
if (messagesEndRef.current) {
|
|
1009
|
+
messagesEndRef.current.scrollIntoView({
|
|
1010
|
+
behavior: "auto"
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
};
|
|
1014
|
+
(0, import_react5.useEffect)(() => {
|
|
1015
|
+
scrollToBottom();
|
|
1016
|
+
}, [messages]);
|
|
1017
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "copilotKitMessages", children: [
|
|
1018
|
+
messages.map((message, index) => {
|
|
1019
|
+
var _a, _b, _c;
|
|
1020
|
+
const isCurrentMessage = index === messages.length - 1;
|
|
1021
|
+
if (message.role === "user") {
|
|
1022
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "copilotKitMessage copilotKitUserMessage", children: message.content }, index);
|
|
1023
|
+
} else if (message.role == "assistant") {
|
|
1024
|
+
if (isCurrentMessage && inProgress && !message.content && !message.partialFunctionCall) {
|
|
1025
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: context.icons.spinnerIcon }, index);
|
|
1026
|
+
} else if (message.function_call || message.partialFunctionCall) {
|
|
1027
|
+
const functionCallName = ((_a = message.function_call) == null ? void 0 : _a.name) || ((_b = message.partialFunctionCall) == null ? void 0 : _b.name);
|
|
1028
|
+
if (chatComponentsCache.current !== null && chatComponentsCache.current[functionCallName]) {
|
|
1029
|
+
const render = chatComponentsCache.current[functionCallName];
|
|
1030
|
+
if (typeof render === "string") {
|
|
1031
|
+
if (isCurrentMessage && inProgress) {
|
|
1032
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
1033
|
+
context.icons.spinnerIcon,
|
|
1034
|
+
" ",
|
|
1035
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "inProgressLabel", children: render })
|
|
1036
|
+
] }, index);
|
|
1037
|
+
} else {
|
|
1038
|
+
return null;
|
|
1039
|
+
}
|
|
1040
|
+
} else {
|
|
1041
|
+
const args = message.function_call ? JSON.parse(message.function_call.arguments || "{}") : (_c = message.partialFunctionCall) == null ? void 0 : _c.arguments;
|
|
1042
|
+
let status = "inProgress";
|
|
1043
|
+
if (functionResults[message.id] !== void 0) {
|
|
1044
|
+
status = "complete";
|
|
1045
|
+
} else if (message.function_call) {
|
|
1046
|
+
status = "executing";
|
|
1047
|
+
}
|
|
1048
|
+
const toRender = render({
|
|
1049
|
+
status,
|
|
1050
|
+
args,
|
|
1051
|
+
result: functionResults[message.id]
|
|
1052
|
+
});
|
|
1053
|
+
if (!toRender && status === "complete") {
|
|
1054
|
+
return null;
|
|
1055
|
+
}
|
|
1056
|
+
if (typeof toRender === "string") {
|
|
1057
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
1058
|
+
isCurrentMessage && inProgress && context.icons.spinnerIcon,
|
|
1059
|
+
" ",
|
|
1060
|
+
toRender
|
|
1061
|
+
] }, index);
|
|
1062
|
+
} else {
|
|
1063
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "copilotKitCustomAssistantMessage", children: toRender }, index);
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
} else if ((!inProgress || !isCurrentMessage) && message.function_call) {
|
|
1067
|
+
return null;
|
|
1068
|
+
} else {
|
|
1069
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: context.icons.spinnerIcon }, index);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Markdown, { content: message.content }) }, index);
|
|
1073
|
+
}
|
|
1074
|
+
}),
|
|
1075
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("footer", { ref: messagesEndRef, children })
|
|
1076
|
+
] });
|
|
1077
|
+
};
|
|
1078
|
+
function makeInitialMessages(initial) {
|
|
1079
|
+
let initialArray = [];
|
|
1080
|
+
if (initial) {
|
|
1081
|
+
if (Array.isArray(initial)) {
|
|
1082
|
+
initialArray.push(...initial);
|
|
1083
|
+
} else {
|
|
1084
|
+
initialArray.push(initial);
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
return initialArray.map((message) => ({
|
|
1088
|
+
id: (0, import_nanoid.nanoid)(),
|
|
1089
|
+
role: "assistant",
|
|
1090
|
+
content: message
|
|
1091
|
+
}));
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
// src/components/chat/Input.tsx
|
|
1095
|
+
var import_react8 = require("react");
|
|
1096
|
+
|
|
1097
|
+
// src/components/chat/Textarea.tsx
|
|
1098
|
+
var import_react6 = require("react");
|
|
1099
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1100
|
+
var AutoResizingTextarea = (0, import_react6.forwardRef)(
|
|
1101
|
+
({ maxRows = 1, placeholder, value, onChange, onKeyDown, autoFocus }, ref) => {
|
|
1102
|
+
const internalTextareaRef = (0, import_react6.useRef)(null);
|
|
1103
|
+
const [maxHeight, setMaxHeight] = (0, import_react6.useState)(0);
|
|
1104
|
+
(0, import_react6.useImperativeHandle)(ref, () => internalTextareaRef.current);
|
|
1105
|
+
(0, import_react6.useEffect)(() => {
|
|
1106
|
+
const calculateMaxHeight = () => {
|
|
1107
|
+
const textarea = internalTextareaRef.current;
|
|
1108
|
+
if (textarea) {
|
|
1109
|
+
textarea.style.height = "auto";
|
|
1110
|
+
const singleRowHeight = textarea.scrollHeight;
|
|
1111
|
+
setMaxHeight(singleRowHeight * maxRows);
|
|
1112
|
+
if (autoFocus) {
|
|
1113
|
+
textarea.focus();
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1117
|
+
calculateMaxHeight();
|
|
1118
|
+
}, [maxRows]);
|
|
1119
|
+
(0, import_react6.useEffect)(() => {
|
|
1120
|
+
const textarea = internalTextareaRef.current;
|
|
1121
|
+
if (textarea) {
|
|
1122
|
+
textarea.style.height = "auto";
|
|
1123
|
+
textarea.style.height = `${Math.min(textarea.scrollHeight, maxHeight)}px`;
|
|
1124
|
+
}
|
|
1125
|
+
}, [value, maxHeight]);
|
|
1126
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1127
|
+
"textarea",
|
|
1128
|
+
{
|
|
1129
|
+
ref: internalTextareaRef,
|
|
1130
|
+
value,
|
|
1131
|
+
onChange,
|
|
1132
|
+
onKeyDown,
|
|
1133
|
+
placeholder,
|
|
1134
|
+
style: {
|
|
1135
|
+
overflow: "auto",
|
|
1136
|
+
resize: "none",
|
|
1137
|
+
maxHeight: `${maxHeight}px`
|
|
1138
|
+
},
|
|
1139
|
+
rows: 1
|
|
1140
|
+
}
|
|
1141
|
+
);
|
|
1142
|
+
}
|
|
1143
|
+
);
|
|
1144
|
+
var Textarea_default = AutoResizingTextarea;
|
|
1145
|
+
|
|
1146
|
+
// src/hooks/use-push-to-talk.tsx
|
|
1147
|
+
var import_react_core2 = require("@copilotkit/react-core");
|
|
1148
|
+
var import_react7 = require("react");
|
|
1149
|
+
var startRecording = (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => __async(void 0, null, function* () {
|
|
1150
|
+
if (!mediaStreamRef.current || !audioContextRef.current) {
|
|
1151
|
+
mediaStreamRef.current = yield navigator.mediaDevices.getUserMedia({ audio: true });
|
|
1152
|
+
audioContextRef.current = new window.AudioContext();
|
|
1153
|
+
yield audioContextRef.current.resume();
|
|
1154
|
+
}
|
|
1155
|
+
mediaRecorderRef.current = new MediaRecorder(mediaStreamRef.current);
|
|
1156
|
+
mediaRecorderRef.current.start(1e3);
|
|
1157
|
+
mediaRecorderRef.current.ondataavailable = (event) => {
|
|
1158
|
+
recordedChunks.push(event.data);
|
|
1159
|
+
};
|
|
1160
|
+
mediaRecorderRef.current.onstop = onStop;
|
|
1161
|
+
});
|
|
1162
|
+
var stopRecording = (mediaRecorderRef) => {
|
|
1163
|
+
if (mediaRecorderRef.current && mediaRecorderRef.current.state !== "inactive") {
|
|
1164
|
+
mediaRecorderRef.current.stop();
|
|
1165
|
+
}
|
|
1166
|
+
};
|
|
1167
|
+
var transcribeAudio = (recordedChunks, transcribeAudioUrl) => __async(void 0, null, function* () {
|
|
1168
|
+
const completeBlob = new Blob(recordedChunks, { type: "audio/mp4" });
|
|
1169
|
+
const formData = new FormData();
|
|
1170
|
+
formData.append("file", completeBlob, "recording.mp4");
|
|
1171
|
+
const response = yield fetch(transcribeAudioUrl, {
|
|
1172
|
+
method: "POST",
|
|
1173
|
+
body: formData
|
|
1174
|
+
});
|
|
1175
|
+
if (!response.ok) {
|
|
1176
|
+
throw new Error(`Error: ${response.statusText}`);
|
|
1177
|
+
}
|
|
1178
|
+
const transcription = yield response.json();
|
|
1179
|
+
return transcription.text;
|
|
1180
|
+
});
|
|
1181
|
+
var playAudioResponse = (text, textToSpeechUrl, audioContext) => {
|
|
1182
|
+
const encodedText = encodeURIComponent(text);
|
|
1183
|
+
const url = `${textToSpeechUrl}?text=${encodedText}`;
|
|
1184
|
+
fetch(url).then((response) => response.arrayBuffer()).then((arrayBuffer) => audioContext.decodeAudioData(arrayBuffer)).then((audioBuffer) => {
|
|
1185
|
+
const source = audioContext.createBufferSource();
|
|
1186
|
+
source.buffer = audioBuffer;
|
|
1187
|
+
source.connect(audioContext.destination);
|
|
1188
|
+
source.start(0);
|
|
1189
|
+
}).catch((error) => {
|
|
1190
|
+
console.error("Error with decoding audio data", error);
|
|
1191
|
+
});
|
|
1192
|
+
};
|
|
1193
|
+
var usePushToTalk = ({
|
|
1194
|
+
sendFunction,
|
|
1195
|
+
inProgress
|
|
1196
|
+
}) => {
|
|
1197
|
+
const [pushToTalkState, setPushToTalkState] = (0, import_react7.useState)("idle");
|
|
1198
|
+
const mediaStreamRef = (0, import_react7.useRef)(null);
|
|
1199
|
+
const audioContextRef = (0, import_react7.useRef)(null);
|
|
1200
|
+
const mediaRecorderRef = (0, import_react7.useRef)(null);
|
|
1201
|
+
const recordedChunks = (0, import_react7.useRef)([]);
|
|
1202
|
+
const context = (0, import_react_core2.useCopilotContext)();
|
|
1203
|
+
const [startReadingFromMessageId, setStartReadingFromMessageId] = (0, import_react7.useState)(null);
|
|
1204
|
+
(0, import_react7.useEffect)(() => {
|
|
1205
|
+
if (pushToTalkState === "recording") {
|
|
1206
|
+
startRecording(
|
|
1207
|
+
mediaStreamRef,
|
|
1208
|
+
mediaRecorderRef,
|
|
1209
|
+
audioContextRef,
|
|
1210
|
+
recordedChunks.current,
|
|
1211
|
+
() => {
|
|
1212
|
+
setPushToTalkState("transcribing");
|
|
1213
|
+
}
|
|
1214
|
+
);
|
|
1215
|
+
} else {
|
|
1216
|
+
stopRecording(mediaRecorderRef);
|
|
1217
|
+
if (pushToTalkState === "transcribing") {
|
|
1218
|
+
transcribeAudio(recordedChunks.current, context.copilotApiConfig.transcribeAudioUrl).then(
|
|
1219
|
+
(transcription) => __async(void 0, null, function* () {
|
|
1220
|
+
recordedChunks.current = [];
|
|
1221
|
+
setPushToTalkState("idle");
|
|
1222
|
+
const message = yield sendFunction(transcription);
|
|
1223
|
+
setStartReadingFromMessageId(message.id);
|
|
1224
|
+
})
|
|
1225
|
+
);
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
return () => {
|
|
1229
|
+
stopRecording(mediaRecorderRef);
|
|
1230
|
+
};
|
|
1231
|
+
}, [pushToTalkState]);
|
|
1232
|
+
(0, import_react7.useEffect)(() => {
|
|
1233
|
+
if (inProgress === false && startReadingFromMessageId) {
|
|
1234
|
+
const lastMessageIndex = context.messages.findIndex(
|
|
1235
|
+
(message) => message.id === startReadingFromMessageId
|
|
1236
|
+
);
|
|
1237
|
+
const messagesAfterLast = context.messages.slice(lastMessageIndex + 1).filter((message) => message.role === "assistant" && message.content);
|
|
1238
|
+
const text = messagesAfterLast.map((message) => message.content).join("\n");
|
|
1239
|
+
playAudioResponse(text, context.copilotApiConfig.textToSpeechUrl, audioContextRef.current);
|
|
1240
|
+
setStartReadingFromMessageId(null);
|
|
1241
|
+
}
|
|
1242
|
+
}, [startReadingFromMessageId, inProgress]);
|
|
1243
|
+
return { pushToTalkState, setPushToTalkState };
|
|
1244
|
+
};
|
|
1245
|
+
|
|
1246
|
+
// src/components/chat/Input.tsx
|
|
1247
|
+
var import_react_core3 = require("@copilotkit/react-core");
|
|
1248
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
1249
|
+
var Input = ({ inProgress, onSend, isVisible = false }) => {
|
|
1250
|
+
const context = useChatContext();
|
|
1251
|
+
const copilotContext = (0, import_react_core3.useCopilotContext)();
|
|
1252
|
+
const pushToTalkConfigured = copilotContext.copilotApiConfig.textToSpeechUrl !== void 0 && copilotContext.copilotApiConfig.transcribeAudioUrl !== void 0;
|
|
1253
|
+
const textareaRef = (0, import_react8.useRef)(null);
|
|
1254
|
+
const handleDivClick = (event) => {
|
|
1255
|
+
var _a;
|
|
1256
|
+
if (event.target !== event.currentTarget)
|
|
1257
|
+
return;
|
|
1258
|
+
(_a = textareaRef.current) == null ? void 0 : _a.focus();
|
|
1259
|
+
};
|
|
1260
|
+
const [text, setText] = (0, import_react8.useState)("");
|
|
1261
|
+
const send = () => {
|
|
1262
|
+
var _a;
|
|
1263
|
+
if (inProgress)
|
|
1264
|
+
return;
|
|
1265
|
+
onSend(text);
|
|
1266
|
+
setText("");
|
|
1267
|
+
(_a = textareaRef.current) == null ? void 0 : _a.focus();
|
|
1268
|
+
};
|
|
1269
|
+
(0, import_react8.useEffect)(() => {
|
|
1270
|
+
var _a;
|
|
1271
|
+
if (isVisible) {
|
|
1272
|
+
(_a = textareaRef.current) == null ? void 0 : _a.focus();
|
|
1273
|
+
}
|
|
1274
|
+
}, [isVisible]);
|
|
1275
|
+
const { pushToTalkState, setPushToTalkState } = usePushToTalk({
|
|
1276
|
+
sendFunction: onSend,
|
|
1277
|
+
inProgress
|
|
1278
|
+
});
|
|
1279
|
+
const sendIcon = inProgress || pushToTalkState === "transcribing" ? context.icons.activityIcon : context.icons.sendIcon;
|
|
1280
|
+
const showPushToTalk = pushToTalkConfigured && (pushToTalkState === "idle" || pushToTalkState === "recording") && !inProgress;
|
|
1281
|
+
const sendDisabled = inProgress || text.length === 0 || pushToTalkState !== "idle";
|
|
1282
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "copilotKitInput", onClick: handleDivClick, children: [
|
|
1283
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
1284
|
+
Textarea_default,
|
|
1285
|
+
{
|
|
1286
|
+
ref: textareaRef,
|
|
1287
|
+
placeholder: context.labels.placeholder,
|
|
1288
|
+
autoFocus: true,
|
|
1289
|
+
maxRows: 5,
|
|
1290
|
+
value: text,
|
|
1291
|
+
onChange: (event) => setText(event.target.value),
|
|
1292
|
+
onKeyDown: (event) => {
|
|
1293
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
1294
|
+
event.preventDefault();
|
|
1295
|
+
send();
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
),
|
|
1300
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "copilotKitInputControls", children: [
|
|
1301
|
+
showPushToTalk && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
1302
|
+
"button",
|
|
1303
|
+
{
|
|
1304
|
+
onClick: () => setPushToTalkState(pushToTalkState === "idle" ? "recording" : "transcribing"),
|
|
1305
|
+
className: pushToTalkState === "recording" ? "copilotKitPushToTalkRecording" : "",
|
|
1306
|
+
children: context.icons.pushToTalkIcon
|
|
1307
|
+
}
|
|
1308
|
+
),
|
|
1309
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { disabled: sendDisabled, onClick: send, children: sendIcon })
|
|
1310
|
+
] })
|
|
1311
|
+
] });
|
|
1312
|
+
};
|
|
1313
|
+
|
|
1314
|
+
// src/components/chat/Response.tsx
|
|
1315
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
1316
|
+
var ResponseButton = ({ onClick, inProgress }) => {
|
|
1317
|
+
const context = useChatContext();
|
|
1318
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("button", { onClick, className: "copilotKitResponseButton", children: [
|
|
1319
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { children: inProgress ? context.icons.stopIcon : context.icons.regenerateIcon }),
|
|
1320
|
+
inProgress ? context.labels.stopGenerating : context.labels.regenerateResponse
|
|
1321
|
+
] });
|
|
1322
|
+
};
|
|
1323
|
+
|
|
1324
|
+
// src/components/chat/Suggestion.tsx
|
|
1325
|
+
var import_react_core4 = require("@copilotkit/react-core");
|
|
1326
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
1327
|
+
function Suggestion({ title, message, onClick, partial, className }) {
|
|
1328
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
|
|
1329
|
+
"button",
|
|
1330
|
+
{
|
|
1331
|
+
disabled: partial,
|
|
1332
|
+
onClick: (e) => {
|
|
1333
|
+
e.preventDefault();
|
|
1334
|
+
onClick(message);
|
|
1335
|
+
},
|
|
1336
|
+
className: className || "suggestion",
|
|
1337
|
+
children: [
|
|
1338
|
+
partial && SmallSpinnerIcon,
|
|
1339
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { children: title })
|
|
1340
|
+
]
|
|
1341
|
+
}
|
|
1342
|
+
);
|
|
1343
|
+
}
|
|
1344
|
+
var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggestions, abortControllerRef) => __async(void 0, null, function* () {
|
|
1345
|
+
const abortController = abortControllerRef.current;
|
|
1346
|
+
const tools = JSON.stringify(context.getChatCompletionFunctionDescriptions(context.entryPoints));
|
|
1347
|
+
const allSuggestions = [];
|
|
1348
|
+
for (const config of Object.values(chatSuggestionConfiguration)) {
|
|
1349
|
+
try {
|
|
1350
|
+
const numOfSuggestionsInstructions = config.minSuggestions === 0 ? `Produce up to ${config.maxSuggestions} suggestions. If there are no highly relevant suggestions you can think of, provide an empty array.` : `Produce between ${config.minSuggestions} and ${config.maxSuggestions} suggestions.`;
|
|
1351
|
+
const result = yield (0, import_react_core4.extract)({
|
|
1352
|
+
context,
|
|
1353
|
+
instructions: "Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls. " + config.instructions + "\n\n" + numOfSuggestionsInstructions,
|
|
1354
|
+
data: "Available tools: " + tools + "\n\n",
|
|
1355
|
+
parameters: [
|
|
1356
|
+
{
|
|
1357
|
+
name: "suggestions",
|
|
1358
|
+
type: "object[]",
|
|
1359
|
+
attributes: [
|
|
1360
|
+
{
|
|
1361
|
+
name: "title",
|
|
1362
|
+
description: "The title of the suggestion. This is shown as a button and should be short.",
|
|
1363
|
+
type: "string"
|
|
1364
|
+
},
|
|
1365
|
+
{
|
|
1366
|
+
name: "message",
|
|
1367
|
+
description: "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.",
|
|
1368
|
+
type: "string"
|
|
1369
|
+
}
|
|
1370
|
+
]
|
|
1371
|
+
}
|
|
1372
|
+
],
|
|
1373
|
+
include: {
|
|
1374
|
+
messages: true,
|
|
1375
|
+
readable: true
|
|
1376
|
+
},
|
|
1377
|
+
abortSignal: abortController == null ? void 0 : abortController.signal,
|
|
1378
|
+
stream: ({ status, args }) => {
|
|
1379
|
+
const suggestions = args.suggestions || [];
|
|
1380
|
+
const newSuggestions = [];
|
|
1381
|
+
for (let i = 0; i < suggestions.length; i++) {
|
|
1382
|
+
if (config.maxSuggestions !== void 0 && i >= config.maxSuggestions) {
|
|
1383
|
+
break;
|
|
1384
|
+
}
|
|
1385
|
+
const { title, message } = suggestions[i];
|
|
1386
|
+
const partial = i == suggestions.length - 1 && status !== "complete";
|
|
1387
|
+
newSuggestions.push({
|
|
1388
|
+
title,
|
|
1389
|
+
message,
|
|
1390
|
+
partial,
|
|
1391
|
+
className: config.className
|
|
1392
|
+
});
|
|
1393
|
+
}
|
|
1394
|
+
setCurrentSuggestions([...allSuggestions, ...newSuggestions]);
|
|
1395
|
+
}
|
|
1396
|
+
});
|
|
1397
|
+
allSuggestions.push(...result.suggestions);
|
|
1398
|
+
} catch (error) {
|
|
1399
|
+
console.error("Error loading suggestions", error);
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
if (abortControllerRef.current === abortController) {
|
|
1403
|
+
abortControllerRef.current = null;
|
|
1404
|
+
}
|
|
1405
|
+
});
|
|
1406
|
+
|
|
1407
|
+
// src/components/chat/Chat.tsx
|
|
1408
|
+
var import_react9 = __toESM(require("react"));
|
|
1409
|
+
var import_react_core5 = require("@copilotkit/react-core");
|
|
1410
|
+
var import_nanoid2 = require("nanoid");
|
|
1411
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
1412
|
+
function CopilotChat({
|
|
1413
|
+
instructions,
|
|
1414
|
+
onSubmitMessage,
|
|
1415
|
+
icons,
|
|
1416
|
+
labels,
|
|
1417
|
+
makeSystemMessage,
|
|
1418
|
+
showResponseButton = true,
|
|
1419
|
+
onInProgress,
|
|
1420
|
+
Messages: Messages2 = Messages,
|
|
1421
|
+
Input: Input2 = Input,
|
|
1422
|
+
ResponseButton: ResponseButton2 = ResponseButton,
|
|
1423
|
+
className
|
|
1424
|
+
}) {
|
|
1425
|
+
const { visibleMessages, isLoading, currentSuggestions, sendMessage, stop, reload } = useCopilotChatLogic(instructions, makeSystemMessage, onInProgress, onSubmitMessage);
|
|
1426
|
+
const context = import_react9.default.useContext(ChatContext);
|
|
1427
|
+
let open = true;
|
|
1428
|
+
let setOpen = () => {
|
|
1429
|
+
};
|
|
1430
|
+
if (context) {
|
|
1431
|
+
icons = context.icons;
|
|
1432
|
+
labels = context.labels;
|
|
1433
|
+
open = context.open;
|
|
1434
|
+
setOpen = context.setOpen;
|
|
1435
|
+
}
|
|
1436
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(ChatContextProvider, { icons, labels, open, setOpen, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: `copilotKitPanel ${className}`, children: [
|
|
1437
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(Messages2, { messages: visibleMessages, inProgress: isLoading, children: [
|
|
1438
|
+
currentSuggestions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { children: [
|
|
1439
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("h6", { children: "Suggested:" }),
|
|
1440
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "suggestions", children: currentSuggestions.map((suggestion, index) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
1441
|
+
Suggestion,
|
|
1442
|
+
{
|
|
1443
|
+
title: suggestion.title,
|
|
1444
|
+
message: suggestion.message,
|
|
1445
|
+
partial: suggestion.partial,
|
|
1446
|
+
className: suggestion.className,
|
|
1447
|
+
onClick: (message) => sendMessage(message)
|
|
1448
|
+
},
|
|
1449
|
+
index
|
|
1450
|
+
)) })
|
|
1451
|
+
] }),
|
|
1452
|
+
showResponseButton && visibleMessages.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(ResponseButton2, { onClick: isLoading ? stop : reload, inProgress: isLoading })
|
|
1453
|
+
] }),
|
|
1454
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Input2, { inProgress: isLoading, onSend: sendMessage, isVisible: true })
|
|
1455
|
+
] }) });
|
|
1456
|
+
}
|
|
1457
|
+
var SUGGESTIONS_DEBOUNCE_TIMEOUT = 1e3;
|
|
1458
|
+
var useCopilotChatLogic = (instructions, makeSystemMessage, onInProgress, onSubmitMessage) => {
|
|
1459
|
+
const { visibleMessages, append, reload, stop, isLoading, input, setInput } = (0, import_react_core5.useCopilotChat)({
|
|
1460
|
+
id: (0, import_nanoid2.nanoid)(),
|
|
1461
|
+
makeSystemMessage,
|
|
1462
|
+
additionalInstructions: instructions
|
|
1463
|
+
});
|
|
1464
|
+
const [currentSuggestions, setCurrentSuggestions] = (0, import_react9.useState)([]);
|
|
1465
|
+
const suggestionsAbortControllerRef = (0, import_react9.useRef)(null);
|
|
1466
|
+
const debounceTimerRef = (0, import_react9.useRef)();
|
|
1467
|
+
const abortSuggestions = () => {
|
|
1468
|
+
var _a;
|
|
1469
|
+
(_a = suggestionsAbortControllerRef.current) == null ? void 0 : _a.abort();
|
|
1470
|
+
suggestionsAbortControllerRef.current = null;
|
|
1471
|
+
};
|
|
1472
|
+
const context = (0, import_react_core5.useCopilotContext)();
|
|
1473
|
+
(0, import_react9.useEffect)(() => {
|
|
1474
|
+
onInProgress == null ? void 0 : onInProgress(isLoading);
|
|
1475
|
+
abortSuggestions();
|
|
1476
|
+
debounceTimerRef.current = setTimeout(
|
|
1477
|
+
() => {
|
|
1478
|
+
if (!isLoading && Object.keys(context.chatSuggestionConfiguration).length !== 0) {
|
|
1479
|
+
suggestionsAbortControllerRef.current = new AbortController();
|
|
1480
|
+
reloadSuggestions(
|
|
1481
|
+
context,
|
|
1482
|
+
context.chatSuggestionConfiguration,
|
|
1483
|
+
setCurrentSuggestions,
|
|
1484
|
+
suggestionsAbortControllerRef
|
|
1485
|
+
);
|
|
1486
|
+
}
|
|
1487
|
+
},
|
|
1488
|
+
currentSuggestions.length == 0 ? 0 : SUGGESTIONS_DEBOUNCE_TIMEOUT
|
|
1489
|
+
);
|
|
1490
|
+
return () => {
|
|
1491
|
+
clearTimeout(debounceTimerRef.current);
|
|
1492
|
+
};
|
|
1493
|
+
}, [isLoading, context.chatSuggestionConfiguration]);
|
|
1494
|
+
const sendMessage = (messageContent) => __async(void 0, null, function* () {
|
|
1495
|
+
abortSuggestions();
|
|
1496
|
+
setCurrentSuggestions([]);
|
|
1497
|
+
onSubmitMessage == null ? void 0 : onSubmitMessage(messageContent);
|
|
1498
|
+
const message = {
|
|
1499
|
+
id: (0, import_nanoid2.nanoid)(),
|
|
1500
|
+
content: messageContent,
|
|
1501
|
+
role: "user"
|
|
1502
|
+
};
|
|
1503
|
+
append(message);
|
|
1504
|
+
return message;
|
|
1505
|
+
});
|
|
1506
|
+
return {
|
|
1507
|
+
visibleMessages,
|
|
1508
|
+
isLoading,
|
|
1509
|
+
currentSuggestions,
|
|
1510
|
+
sendMessage,
|
|
1511
|
+
stop,
|
|
1512
|
+
reload,
|
|
1513
|
+
input,
|
|
1514
|
+
setInput
|
|
1515
|
+
};
|
|
1516
|
+
};
|
|
1517
|
+
|
|
1518
|
+
// src/components/chat/Modal.tsx
|
|
1519
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
1520
|
+
var CopilotModal = ({
|
|
1521
|
+
instructions,
|
|
1522
|
+
defaultOpen = false,
|
|
1523
|
+
clickOutsideToClose = true,
|
|
1524
|
+
hitEscapeToClose = true,
|
|
1525
|
+
onSetOpen,
|
|
1526
|
+
onSubmitMessage,
|
|
1527
|
+
shortcut = "/",
|
|
1528
|
+
icons,
|
|
1529
|
+
labels,
|
|
1530
|
+
makeSystemMessage,
|
|
1531
|
+
showResponseButton = true,
|
|
1532
|
+
onInProgress,
|
|
1533
|
+
Window: Window2 = Window,
|
|
1534
|
+
Button: Button2 = Button,
|
|
1535
|
+
Header: Header2 = Header,
|
|
1536
|
+
Messages: Messages2 = Messages,
|
|
1537
|
+
Input: Input2 = Input,
|
|
1538
|
+
ResponseButton: ResponseButton2 = ResponseButton,
|
|
1539
|
+
className,
|
|
1540
|
+
children
|
|
1541
|
+
}) => {
|
|
1542
|
+
const [openState, setOpenState] = import_react10.default.useState(defaultOpen);
|
|
1543
|
+
const setOpen = (open) => {
|
|
1544
|
+
onSetOpen == null ? void 0 : onSetOpen(open);
|
|
1545
|
+
setOpenState(open);
|
|
1546
|
+
};
|
|
1547
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(ChatContextProvider, { icons, labels, open: openState, setOpen: setOpenState, children: [
|
|
1548
|
+
children,
|
|
1549
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className, children: [
|
|
1550
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Button2, { open: openState, setOpen }),
|
|
1551
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
|
|
1552
|
+
Window2,
|
|
1553
|
+
{
|
|
1554
|
+
open: openState,
|
|
1555
|
+
setOpen,
|
|
1556
|
+
clickOutsideToClose,
|
|
1557
|
+
shortcut,
|
|
1558
|
+
hitEscapeToClose,
|
|
1559
|
+
children: [
|
|
1560
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Header2, { open: openState, setOpen }),
|
|
1561
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1562
|
+
CopilotChat,
|
|
1563
|
+
{
|
|
1564
|
+
instructions,
|
|
1565
|
+
makeSystemMessage,
|
|
1566
|
+
onInProgress,
|
|
1567
|
+
onSubmitMessage,
|
|
1568
|
+
showResponseButton,
|
|
1569
|
+
Messages: Messages2,
|
|
1570
|
+
Input: Input2,
|
|
1571
|
+
ResponseButton: ResponseButton2
|
|
1572
|
+
}
|
|
1573
|
+
)
|
|
1574
|
+
]
|
|
1575
|
+
}
|
|
1576
|
+
)
|
|
1577
|
+
] })
|
|
1578
|
+
] });
|
|
1579
|
+
};
|
|
1580
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1581
|
+
0 && (module.exports = {
|
|
1582
|
+
CopilotModal
|
|
1583
|
+
});
|
|
1584
|
+
//# sourceMappingURL=Modal.js.map
|