@copilotkitnext/react 0.0.22-alpha.9 → 0.0.23
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/dist/index.d.mts +15 -17
- package/dist/index.d.ts +15 -17
- package/dist/index.js +984 -578
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +894 -474
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -11
package/dist/index.js
CHANGED
|
@@ -1,47 +1,87 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var webInspector = require('@copilotkitnext/web-inspector');
|
|
19
|
-
var useStickToBottom = require('use-stick-to-bottom');
|
|
20
|
-
var tsDeepmerge = require('ts-deepmerge');
|
|
21
|
-
var client = require('@ag-ui/client');
|
|
22
|
-
|
|
23
|
-
function _interopNamespace(e) {
|
|
24
|
-
if (e && e.__esModule) return e;
|
|
25
|
-
var n = Object.create(null);
|
|
26
|
-
if (e) {
|
|
27
|
-
Object.keys(e).forEach(function (k) {
|
|
28
|
-
if (k !== 'default') {
|
|
29
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
30
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
get: function () { return e[k]; }
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
});
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
36
18
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
28
|
+
mod
|
|
29
|
+
));
|
|
30
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
40
31
|
|
|
41
|
-
|
|
42
|
-
var
|
|
43
|
-
|
|
32
|
+
// src/index.ts
|
|
33
|
+
var index_exports = {};
|
|
34
|
+
__export(index_exports, {
|
|
35
|
+
AudioRecorderError: () => AudioRecorderError,
|
|
36
|
+
CopilotChat: () => CopilotChat,
|
|
37
|
+
CopilotChatAssistantMessage: () => CopilotChatAssistantMessage_default,
|
|
38
|
+
CopilotChatAudioRecorder: () => CopilotChatAudioRecorder,
|
|
39
|
+
CopilotChatConfigurationProvider: () => CopilotChatConfigurationProvider,
|
|
40
|
+
CopilotChatInput: () => CopilotChatInput_default,
|
|
41
|
+
CopilotChatMessageView: () => CopilotChatMessageView_default,
|
|
42
|
+
CopilotChatSuggestionPill: () => CopilotChatSuggestionPill_default,
|
|
43
|
+
CopilotChatSuggestionView: () => CopilotChatSuggestionView_default,
|
|
44
|
+
CopilotChatToggleButton: () => CopilotChatToggleButton,
|
|
45
|
+
CopilotChatToggleButtonCloseIcon: () => DefaultCloseIcon,
|
|
46
|
+
CopilotChatToggleButtonOpenIcon: () => DefaultOpenIcon,
|
|
47
|
+
CopilotChatToolCallsView: () => CopilotChatToolCallsView_default,
|
|
48
|
+
CopilotChatUserMessage: () => CopilotChatUserMessage_default,
|
|
49
|
+
CopilotChatView: () => CopilotChatView_default,
|
|
50
|
+
CopilotKitCoreReact: () => CopilotKitCoreReact,
|
|
51
|
+
CopilotKitInspector: () => CopilotKitInspector,
|
|
52
|
+
CopilotKitProvider: () => CopilotKitProvider,
|
|
53
|
+
CopilotModalHeader: () => CopilotModalHeader,
|
|
54
|
+
CopilotPopup: () => CopilotPopup,
|
|
55
|
+
CopilotPopupView: () => CopilotPopupView,
|
|
56
|
+
CopilotSidebar: () => CopilotSidebar,
|
|
57
|
+
CopilotSidebarView: () => CopilotSidebarView,
|
|
58
|
+
WildcardToolCallRender: () => WildcardToolCallRender,
|
|
59
|
+
defineToolCallRenderer: () => defineToolCallRenderer,
|
|
60
|
+
useAgent: () => useAgent,
|
|
61
|
+
useAgentContext: () => useAgentContext,
|
|
62
|
+
useConfigureSuggestions: () => useConfigureSuggestions,
|
|
63
|
+
useCopilotChatConfiguration: () => useCopilotChatConfiguration,
|
|
64
|
+
useCopilotKit: () => useCopilotKit,
|
|
65
|
+
useFrontendTool: () => useFrontendTool,
|
|
66
|
+
useHumanInTheLoop: () => useHumanInTheLoop,
|
|
67
|
+
useRenderActivityMessage: () => useRenderActivityMessage,
|
|
68
|
+
useRenderCustomMessages: () => useRenderCustomMessages,
|
|
69
|
+
useRenderToolCall: () => useRenderToolCall,
|
|
70
|
+
useSuggestions: () => useSuggestions
|
|
71
|
+
});
|
|
72
|
+
module.exports = __toCommonJS(index_exports);
|
|
73
|
+
__reExport(index_exports, require("@ag-ui/core"), module.exports);
|
|
74
|
+
__reExport(index_exports, require("@ag-ui/client"), module.exports);
|
|
44
75
|
|
|
76
|
+
// src/components/chat/CopilotChatInput.tsx
|
|
77
|
+
var import_react4 = require("react");
|
|
78
|
+
var import_tailwind_merge3 = require("tailwind-merge");
|
|
79
|
+
var import_lucide_react2 = require("lucide-react");
|
|
80
|
+
|
|
81
|
+
// src/providers/CopilotChatConfigurationProvider.tsx
|
|
82
|
+
var import_react = require("react");
|
|
83
|
+
var import_shared = require("@copilotkitnext/shared");
|
|
84
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
45
85
|
var CopilotChatDefaultLabels = {
|
|
46
86
|
chatInputPlaceholder: "Type a message...",
|
|
47
87
|
chatInputToolbarStartTranscribeButtonLabel: "Transcribe",
|
|
@@ -63,10 +103,10 @@ var CopilotChatDefaultLabels = {
|
|
|
63
103
|
chatToggleCloseLabel: "Close chat",
|
|
64
104
|
modalHeaderTitle: "CopilotKit Chat"
|
|
65
105
|
};
|
|
66
|
-
var CopilotChatConfiguration =
|
|
106
|
+
var CopilotChatConfiguration = (0, import_react.createContext)(null);
|
|
67
107
|
var CopilotChatConfigurationProvider = ({ children, labels, agentId, threadId, isModalDefaultOpen }) => {
|
|
68
|
-
const parentConfig =
|
|
69
|
-
const mergedLabels =
|
|
108
|
+
const parentConfig = (0, import_react.useContext)(CopilotChatConfiguration);
|
|
109
|
+
const mergedLabels = (0, import_react.useMemo)(
|
|
70
110
|
() => ({
|
|
71
111
|
...CopilotChatDefaultLabels,
|
|
72
112
|
...parentConfig?.labels ?? {},
|
|
@@ -74,23 +114,23 @@ var CopilotChatConfigurationProvider = ({ children, labels, agentId, threadId, i
|
|
|
74
114
|
}),
|
|
75
115
|
[labels, parentConfig?.labels]
|
|
76
116
|
);
|
|
77
|
-
const resolvedAgentId = agentId ?? parentConfig?.agentId ??
|
|
78
|
-
const resolvedThreadId =
|
|
117
|
+
const resolvedAgentId = agentId ?? parentConfig?.agentId ?? import_shared.DEFAULT_AGENT_ID;
|
|
118
|
+
const resolvedThreadId = (0, import_react.useMemo)(() => {
|
|
79
119
|
if (threadId) {
|
|
80
120
|
return threadId;
|
|
81
121
|
}
|
|
82
122
|
if (parentConfig?.threadId) {
|
|
83
123
|
return parentConfig.threadId;
|
|
84
124
|
}
|
|
85
|
-
return
|
|
125
|
+
return (0, import_shared.randomUUID)();
|
|
86
126
|
}, [threadId, parentConfig?.threadId]);
|
|
87
127
|
const resolvedDefaultOpen = isModalDefaultOpen ?? parentConfig?.isModalDefaultOpen ?? true;
|
|
88
|
-
const [internalModalOpen, setInternalModalOpen] =
|
|
128
|
+
const [internalModalOpen, setInternalModalOpen] = (0, import_react.useState)(
|
|
89
129
|
parentConfig?.isModalOpen ?? resolvedDefaultOpen
|
|
90
130
|
);
|
|
91
131
|
const resolvedIsModalOpen = parentConfig?.isModalOpen ?? internalModalOpen;
|
|
92
132
|
const resolvedSetModalOpen = parentConfig?.setModalOpen ?? setInternalModalOpen;
|
|
93
|
-
const configurationValue =
|
|
133
|
+
const configurationValue = (0, import_react.useMemo)(
|
|
94
134
|
() => ({
|
|
95
135
|
labels: mergedLabels,
|
|
96
136
|
agentId: resolvedAgentId,
|
|
@@ -108,16 +148,27 @@ var CopilotChatConfigurationProvider = ({ children, labels, agentId, threadId, i
|
|
|
108
148
|
resolvedDefaultOpen
|
|
109
149
|
]
|
|
110
150
|
);
|
|
111
|
-
return /* @__PURE__ */
|
|
151
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CopilotChatConfiguration.Provider, { value: configurationValue, children });
|
|
112
152
|
};
|
|
113
153
|
var useCopilotChatConfiguration = () => {
|
|
114
|
-
const configuration =
|
|
154
|
+
const configuration = (0, import_react.useContext)(CopilotChatConfiguration);
|
|
115
155
|
return configuration;
|
|
116
156
|
};
|
|
157
|
+
|
|
158
|
+
// src/components/ui/button.tsx
|
|
159
|
+
var import_react_slot = require("@radix-ui/react-slot");
|
|
160
|
+
var import_class_variance_authority = require("class-variance-authority");
|
|
161
|
+
|
|
162
|
+
// src/lib/utils.ts
|
|
163
|
+
var import_clsx = require("clsx");
|
|
164
|
+
var import_tailwind_merge = require("tailwind-merge");
|
|
117
165
|
function cn(...inputs) {
|
|
118
|
-
return
|
|
166
|
+
return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
|
|
119
167
|
}
|
|
120
|
-
|
|
168
|
+
|
|
169
|
+
// src/components/ui/button.tsx
|
|
170
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
171
|
+
var buttonVariants = (0, import_class_variance_authority.cva)(
|
|
121
172
|
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
|
122
173
|
{
|
|
123
174
|
variants: {
|
|
@@ -213,8 +264,8 @@ function Button({
|
|
|
213
264
|
asChild = false,
|
|
214
265
|
...props
|
|
215
266
|
}) {
|
|
216
|
-
const Comp = asChild ?
|
|
217
|
-
return /* @__PURE__ */
|
|
267
|
+
const Comp = asChild ? import_react_slot.Slot : "button";
|
|
268
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
218
269
|
Comp,
|
|
219
270
|
{
|
|
220
271
|
"data-slot": "button",
|
|
@@ -223,12 +274,16 @@ function Button({
|
|
|
223
274
|
}
|
|
224
275
|
);
|
|
225
276
|
}
|
|
277
|
+
|
|
278
|
+
// src/components/ui/tooltip.tsx
|
|
279
|
+
var TooltipPrimitive = __toESM(require("@radix-ui/react-tooltip"));
|
|
280
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
226
281
|
function TooltipProvider({
|
|
227
282
|
delayDuration = 0,
|
|
228
283
|
...props
|
|
229
284
|
}) {
|
|
230
|
-
return /* @__PURE__ */
|
|
231
|
-
|
|
285
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
286
|
+
TooltipPrimitive.Provider,
|
|
232
287
|
{
|
|
233
288
|
"data-slot": "tooltip-provider",
|
|
234
289
|
delayDuration,
|
|
@@ -239,12 +294,12 @@ function TooltipProvider({
|
|
|
239
294
|
function Tooltip({
|
|
240
295
|
...props
|
|
241
296
|
}) {
|
|
242
|
-
return /* @__PURE__ */
|
|
297
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TooltipProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TooltipPrimitive.Root, { "data-slot": "tooltip", ...props }) });
|
|
243
298
|
}
|
|
244
299
|
function TooltipTrigger({
|
|
245
300
|
...props
|
|
246
301
|
}) {
|
|
247
|
-
return /* @__PURE__ */
|
|
302
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TooltipPrimitive.Trigger, { "data-slot": "tooltip-trigger", ...props });
|
|
248
303
|
}
|
|
249
304
|
function TooltipContent({
|
|
250
305
|
className,
|
|
@@ -252,8 +307,8 @@ function TooltipContent({
|
|
|
252
307
|
children,
|
|
253
308
|
...props
|
|
254
309
|
}) {
|
|
255
|
-
return /* @__PURE__ */
|
|
256
|
-
|
|
310
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TooltipPrimitive.Portal, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
311
|
+
TooltipPrimitive.Content,
|
|
257
312
|
{
|
|
258
313
|
"data-slot": "tooltip-content",
|
|
259
314
|
sideOffset,
|
|
@@ -264,21 +319,26 @@ function TooltipContent({
|
|
|
264
319
|
...props,
|
|
265
320
|
children: [
|
|
266
321
|
children,
|
|
267
|
-
/* @__PURE__ */
|
|
322
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TooltipPrimitive.Arrow, { className: "bg-primary fill-primary z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]" })
|
|
268
323
|
]
|
|
269
324
|
}
|
|
270
325
|
) });
|
|
271
326
|
}
|
|
327
|
+
|
|
328
|
+
// src/components/ui/dropdown-menu.tsx
|
|
329
|
+
var DropdownMenuPrimitive = __toESM(require("@radix-ui/react-dropdown-menu"));
|
|
330
|
+
var import_lucide_react = require("lucide-react");
|
|
331
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
272
332
|
function DropdownMenu({
|
|
273
333
|
...props
|
|
274
334
|
}) {
|
|
275
|
-
return /* @__PURE__ */
|
|
335
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(DropdownMenuPrimitive.Root, { "data-slot": "dropdown-menu", ...props });
|
|
276
336
|
}
|
|
277
337
|
function DropdownMenuTrigger({
|
|
278
338
|
...props
|
|
279
339
|
}) {
|
|
280
|
-
return /* @__PURE__ */
|
|
281
|
-
|
|
340
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
341
|
+
DropdownMenuPrimitive.Trigger,
|
|
282
342
|
{
|
|
283
343
|
"data-slot": "dropdown-menu-trigger",
|
|
284
344
|
...props
|
|
@@ -290,8 +350,8 @@ function DropdownMenuContent({
|
|
|
290
350
|
sideOffset = 4,
|
|
291
351
|
...props
|
|
292
352
|
}) {
|
|
293
|
-
return /* @__PURE__ */
|
|
294
|
-
|
|
353
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(DropdownMenuPrimitive.Portal, { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
354
|
+
DropdownMenuPrimitive.Content,
|
|
295
355
|
{
|
|
296
356
|
"data-slot": "dropdown-menu-content",
|
|
297
357
|
sideOffset,
|
|
@@ -309,8 +369,8 @@ function DropdownMenuItem({
|
|
|
309
369
|
variant = "default",
|
|
310
370
|
...props
|
|
311
371
|
}) {
|
|
312
|
-
return /* @__PURE__ */
|
|
313
|
-
|
|
372
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
373
|
+
DropdownMenuPrimitive.Item,
|
|
314
374
|
{
|
|
315
375
|
"data-slot": "dropdown-menu-item",
|
|
316
376
|
"data-inset": inset,
|
|
@@ -327,8 +387,8 @@ function DropdownMenuSeparator({
|
|
|
327
387
|
className,
|
|
328
388
|
...props
|
|
329
389
|
}) {
|
|
330
|
-
return /* @__PURE__ */
|
|
331
|
-
|
|
390
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
391
|
+
DropdownMenuPrimitive.Separator,
|
|
332
392
|
{
|
|
333
393
|
"data-slot": "dropdown-menu-separator",
|
|
334
394
|
className: cn("bg-border -mx-1 my-1 h-px", className),
|
|
@@ -339,7 +399,7 @@ function DropdownMenuSeparator({
|
|
|
339
399
|
function DropdownMenuSub({
|
|
340
400
|
...props
|
|
341
401
|
}) {
|
|
342
|
-
return /* @__PURE__ */
|
|
402
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(DropdownMenuPrimitive.Sub, { "data-slot": "dropdown-menu-sub", ...props });
|
|
343
403
|
}
|
|
344
404
|
function DropdownMenuSubTrigger({
|
|
345
405
|
className,
|
|
@@ -347,8 +407,8 @@ function DropdownMenuSubTrigger({
|
|
|
347
407
|
children,
|
|
348
408
|
...props
|
|
349
409
|
}) {
|
|
350
|
-
return /* @__PURE__ */
|
|
351
|
-
|
|
410
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
411
|
+
DropdownMenuPrimitive.SubTrigger,
|
|
352
412
|
{
|
|
353
413
|
"data-slot": "dropdown-menu-sub-trigger",
|
|
354
414
|
"data-inset": inset,
|
|
@@ -359,7 +419,7 @@ function DropdownMenuSubTrigger({
|
|
|
359
419
|
...props,
|
|
360
420
|
children: [
|
|
361
421
|
children,
|
|
362
|
-
/* @__PURE__ */
|
|
422
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_lucide_react.ChevronRightIcon, { className: "ml-auto size-4" })
|
|
363
423
|
]
|
|
364
424
|
}
|
|
365
425
|
);
|
|
@@ -368,8 +428,8 @@ function DropdownMenuSubContent({
|
|
|
368
428
|
className,
|
|
369
429
|
...props
|
|
370
430
|
}) {
|
|
371
|
-
return /* @__PURE__ */
|
|
372
|
-
|
|
431
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
432
|
+
DropdownMenuPrimitive.SubContent,
|
|
373
433
|
{
|
|
374
434
|
"data-slot": "dropdown-menu-sub-content",
|
|
375
435
|
className: cn(
|
|
@@ -380,15 +440,20 @@ function DropdownMenuSubContent({
|
|
|
380
440
|
}
|
|
381
441
|
);
|
|
382
442
|
}
|
|
443
|
+
|
|
444
|
+
// src/components/chat/CopilotChatAudioRecorder.tsx
|
|
445
|
+
var import_react2 = require("react");
|
|
446
|
+
var import_tailwind_merge2 = require("tailwind-merge");
|
|
447
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
383
448
|
var AudioRecorderError = class extends Error {
|
|
384
449
|
constructor(message) {
|
|
385
450
|
super(message);
|
|
386
451
|
this.name = "AudioRecorderError";
|
|
387
452
|
}
|
|
388
453
|
};
|
|
389
|
-
var CopilotChatAudioRecorder =
|
|
454
|
+
var CopilotChatAudioRecorder = (0, import_react2.forwardRef)((props, ref) => {
|
|
390
455
|
const { className, ...divProps } = props;
|
|
391
|
-
const canvasRef =
|
|
456
|
+
const canvasRef = (0, import_react2.useRef)(null);
|
|
392
457
|
const getLoudness = (n) => {
|
|
393
458
|
const elapsed = Date.now() / 1e3;
|
|
394
459
|
const samples = [];
|
|
@@ -405,7 +470,7 @@ var CopilotChatAudioRecorder = React2.forwardRef((props, ref) => {
|
|
|
405
470
|
}
|
|
406
471
|
return samples;
|
|
407
472
|
};
|
|
408
|
-
|
|
473
|
+
(0, import_react2.useEffect)(() => {
|
|
409
474
|
const canvas = canvasRef.current;
|
|
410
475
|
if (!canvas) return;
|
|
411
476
|
const ctx = canvas.getContext("2d");
|
|
@@ -449,7 +514,7 @@ var CopilotChatAudioRecorder = React2.forwardRef((props, ref) => {
|
|
|
449
514
|
}
|
|
450
515
|
};
|
|
451
516
|
}, []);
|
|
452
|
-
|
|
517
|
+
(0, import_react2.useImperativeHandle)(
|
|
453
518
|
ref,
|
|
454
519
|
() => ({
|
|
455
520
|
get state() {
|
|
@@ -466,7 +531,7 @@ var CopilotChatAudioRecorder = React2.forwardRef((props, ref) => {
|
|
|
466
531
|
}),
|
|
467
532
|
[]
|
|
468
533
|
);
|
|
469
|
-
return /* @__PURE__ */
|
|
534
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: (0, import_tailwind_merge2.twMerge)("h-[44px] w-full px-5", className), ...divProps, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
470
535
|
"canvas",
|
|
471
536
|
{
|
|
472
537
|
ref: canvasRef,
|
|
@@ -476,25 +541,63 @@ var CopilotChatAudioRecorder = React2.forwardRef((props, ref) => {
|
|
|
476
541
|
) });
|
|
477
542
|
});
|
|
478
543
|
CopilotChatAudioRecorder.displayName = "WebAudioRecorder";
|
|
479
|
-
|
|
544
|
+
|
|
545
|
+
// src/lib/slots.tsx
|
|
546
|
+
var import_react3 = __toESM(require("react"));
|
|
547
|
+
function shallowEqual(obj1, obj2) {
|
|
548
|
+
const keys1 = Object.keys(obj1);
|
|
549
|
+
const keys2 = Object.keys(obj2);
|
|
550
|
+
if (keys1.length !== keys2.length) return false;
|
|
551
|
+
for (const key of keys1) {
|
|
552
|
+
if (obj1[key] !== obj2[key]) return false;
|
|
553
|
+
}
|
|
554
|
+
return true;
|
|
555
|
+
}
|
|
556
|
+
function renderSlotElement(slot, DefaultComponent, props) {
|
|
480
557
|
if (typeof slot === "string") {
|
|
481
|
-
return
|
|
558
|
+
return import_react3.default.createElement(DefaultComponent, {
|
|
482
559
|
...props,
|
|
483
560
|
className: slot
|
|
484
561
|
});
|
|
485
562
|
}
|
|
486
563
|
if (typeof slot === "function") {
|
|
487
|
-
|
|
488
|
-
return React2__namespace.default.createElement(Comp, props);
|
|
564
|
+
return import_react3.default.createElement(slot, props);
|
|
489
565
|
}
|
|
490
|
-
if (slot && typeof slot === "object" && !
|
|
491
|
-
return
|
|
566
|
+
if (slot && typeof slot === "object" && !import_react3.default.isValidElement(slot)) {
|
|
567
|
+
return import_react3.default.createElement(DefaultComponent, {
|
|
492
568
|
...props,
|
|
493
569
|
...slot
|
|
494
570
|
});
|
|
495
571
|
}
|
|
496
|
-
return
|
|
572
|
+
return import_react3.default.createElement(DefaultComponent, props);
|
|
573
|
+
}
|
|
574
|
+
var MemoizedSlotWrapper = import_react3.default.memo(
|
|
575
|
+
import_react3.default.forwardRef(function MemoizedSlotWrapper2(props, ref) {
|
|
576
|
+
const { $slot, $component, ...rest } = props;
|
|
577
|
+
const propsWithRef = ref !== null ? { ...rest, ref } : rest;
|
|
578
|
+
return renderSlotElement($slot, $component, propsWithRef);
|
|
579
|
+
}),
|
|
580
|
+
(prev, next) => {
|
|
581
|
+
if (prev.$slot !== next.$slot) return false;
|
|
582
|
+
if (prev.$component !== next.$component) return false;
|
|
583
|
+
const { $slot: _ps, $component: _pc, ...prevRest } = prev;
|
|
584
|
+
const { $slot: _ns, $component: _nc, ...nextRest } = next;
|
|
585
|
+
return shallowEqual(
|
|
586
|
+
prevRest,
|
|
587
|
+
nextRest
|
|
588
|
+
);
|
|
589
|
+
}
|
|
590
|
+
);
|
|
591
|
+
function renderSlot(slot, DefaultComponent, props) {
|
|
592
|
+
return import_react3.default.createElement(MemoizedSlotWrapper, {
|
|
593
|
+
...props,
|
|
594
|
+
$slot: slot,
|
|
595
|
+
$component: DefaultComponent
|
|
596
|
+
});
|
|
497
597
|
}
|
|
598
|
+
|
|
599
|
+
// src/components/chat/CopilotChatInput.tsx
|
|
600
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
498
601
|
var SLASH_MENU_MAX_VISIBLE_ITEMS = 5;
|
|
499
602
|
var SLASH_MENU_ITEM_HEIGHT_PX = 40;
|
|
500
603
|
function CopilotChatInput({
|
|
@@ -522,36 +625,36 @@ function CopilotChatInput({
|
|
|
522
625
|
...props
|
|
523
626
|
}) {
|
|
524
627
|
const isControlled = value !== void 0;
|
|
525
|
-
const [internalValue, setInternalValue] =
|
|
526
|
-
|
|
628
|
+
const [internalValue, setInternalValue] = (0, import_react4.useState)(() => value ?? "");
|
|
629
|
+
(0, import_react4.useEffect)(() => {
|
|
527
630
|
if (!isControlled && value !== void 0) {
|
|
528
631
|
setInternalValue(value);
|
|
529
632
|
}
|
|
530
633
|
}, [isControlled, value]);
|
|
531
634
|
const resolvedValue = isControlled ? value ?? "" : internalValue;
|
|
532
|
-
const [layout, setLayout] =
|
|
533
|
-
const ignoreResizeRef =
|
|
534
|
-
const resizeEvaluationRafRef =
|
|
635
|
+
const [layout, setLayout] = (0, import_react4.useState)("compact");
|
|
636
|
+
const ignoreResizeRef = (0, import_react4.useRef)(false);
|
|
637
|
+
const resizeEvaluationRafRef = (0, import_react4.useRef)(null);
|
|
535
638
|
const isExpanded = mode === "input" && layout === "expanded";
|
|
536
|
-
const [commandQuery, setCommandQuery] =
|
|
537
|
-
const [slashHighlightIndex, setSlashHighlightIndex] =
|
|
538
|
-
const inputRef =
|
|
539
|
-
const gridRef =
|
|
540
|
-
const addButtonContainerRef =
|
|
541
|
-
const actionsContainerRef =
|
|
542
|
-
const audioRecorderRef =
|
|
543
|
-
const slashMenuRef =
|
|
639
|
+
const [commandQuery, setCommandQuery] = (0, import_react4.useState)(null);
|
|
640
|
+
const [slashHighlightIndex, setSlashHighlightIndex] = (0, import_react4.useState)(0);
|
|
641
|
+
const inputRef = (0, import_react4.useRef)(null);
|
|
642
|
+
const gridRef = (0, import_react4.useRef)(null);
|
|
643
|
+
const addButtonContainerRef = (0, import_react4.useRef)(null);
|
|
644
|
+
const actionsContainerRef = (0, import_react4.useRef)(null);
|
|
645
|
+
const audioRecorderRef = (0, import_react4.useRef)(null);
|
|
646
|
+
const slashMenuRef = (0, import_react4.useRef)(null);
|
|
544
647
|
const config = useCopilotChatConfiguration();
|
|
545
648
|
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
546
|
-
const previousModalStateRef =
|
|
547
|
-
const measurementCanvasRef =
|
|
548
|
-
const measurementsRef =
|
|
649
|
+
const previousModalStateRef = (0, import_react4.useRef)(void 0);
|
|
650
|
+
const measurementCanvasRef = (0, import_react4.useRef)(null);
|
|
651
|
+
const measurementsRef = (0, import_react4.useRef)({
|
|
549
652
|
singleLineHeight: 0,
|
|
550
653
|
maxHeight: 0,
|
|
551
654
|
paddingLeft: 0,
|
|
552
655
|
paddingRight: 0
|
|
553
656
|
});
|
|
554
|
-
const commandItems =
|
|
657
|
+
const commandItems = (0, import_react4.useMemo)(() => {
|
|
555
658
|
const entries = [];
|
|
556
659
|
const seen = /* @__PURE__ */ new Set();
|
|
557
660
|
const pushItem = (item) => {
|
|
@@ -582,7 +685,7 @@ function CopilotChatInput({
|
|
|
582
685
|
}
|
|
583
686
|
return entries;
|
|
584
687
|
}, [labels.chatInputToolbarAddButtonLabel, onAddFile, toolsMenu]);
|
|
585
|
-
const filteredCommands =
|
|
688
|
+
const filteredCommands = (0, import_react4.useMemo)(() => {
|
|
586
689
|
if (commandQuery === null) {
|
|
587
690
|
return [];
|
|
588
691
|
}
|
|
@@ -605,7 +708,7 @@ function CopilotChatInput({
|
|
|
605
708
|
}
|
|
606
709
|
return [...startsWith, ...contains];
|
|
607
710
|
}, [commandItems, commandQuery]);
|
|
608
|
-
|
|
711
|
+
(0, import_react4.useEffect)(() => {
|
|
609
712
|
if (!autoFocus) {
|
|
610
713
|
previousModalStateRef.current = config?.isModalOpen;
|
|
611
714
|
return;
|
|
@@ -615,19 +718,19 @@ function CopilotChatInput({
|
|
|
615
718
|
}
|
|
616
719
|
previousModalStateRef.current = config?.isModalOpen;
|
|
617
720
|
}, [config?.isModalOpen, autoFocus]);
|
|
618
|
-
|
|
721
|
+
(0, import_react4.useEffect)(() => {
|
|
619
722
|
if (commandItems.length === 0 && commandQuery !== null) {
|
|
620
723
|
setCommandQuery(null);
|
|
621
724
|
}
|
|
622
725
|
}, [commandItems.length, commandQuery]);
|
|
623
|
-
const previousCommandQueryRef =
|
|
624
|
-
|
|
726
|
+
const previousCommandQueryRef = (0, import_react4.useRef)(null);
|
|
727
|
+
(0, import_react4.useEffect)(() => {
|
|
625
728
|
if (commandQuery !== null && commandQuery !== previousCommandQueryRef.current && filteredCommands.length > 0) {
|
|
626
729
|
setSlashHighlightIndex(0);
|
|
627
730
|
}
|
|
628
731
|
previousCommandQueryRef.current = commandQuery;
|
|
629
732
|
}, [commandQuery, filteredCommands.length]);
|
|
630
|
-
|
|
733
|
+
(0, import_react4.useEffect)(() => {
|
|
631
734
|
if (commandQuery === null) {
|
|
632
735
|
setSlashHighlightIndex(0);
|
|
633
736
|
return;
|
|
@@ -638,7 +741,7 @@ function CopilotChatInput({
|
|
|
638
741
|
setSlashHighlightIndex(0);
|
|
639
742
|
}
|
|
640
743
|
}, [commandQuery, filteredCommands, slashHighlightIndex]);
|
|
641
|
-
|
|
744
|
+
(0, import_react4.useEffect)(() => {
|
|
642
745
|
const recorder = audioRecorderRef.current;
|
|
643
746
|
if (!recorder) {
|
|
644
747
|
return;
|
|
@@ -651,13 +754,13 @@ function CopilotChatInput({
|
|
|
651
754
|
}
|
|
652
755
|
}
|
|
653
756
|
}, [mode]);
|
|
654
|
-
|
|
757
|
+
(0, import_react4.useEffect)(() => {
|
|
655
758
|
if (mode !== "input") {
|
|
656
759
|
setLayout("compact");
|
|
657
760
|
setCommandQuery(null);
|
|
658
761
|
}
|
|
659
762
|
}, [mode]);
|
|
660
|
-
const updateSlashState =
|
|
763
|
+
const updateSlashState = (0, import_react4.useCallback)(
|
|
661
764
|
(value2) => {
|
|
662
765
|
if (commandItems.length === 0) {
|
|
663
766
|
setCommandQuery((prev) => prev === null ? prev : null);
|
|
@@ -673,7 +776,7 @@ function CopilotChatInput({
|
|
|
673
776
|
},
|
|
674
777
|
[commandItems.length]
|
|
675
778
|
);
|
|
676
|
-
|
|
779
|
+
(0, import_react4.useEffect)(() => {
|
|
677
780
|
updateSlashState(resolvedValue);
|
|
678
781
|
}, [resolvedValue, updateSlashState]);
|
|
679
782
|
const handleChange = (e) => {
|
|
@@ -684,7 +787,7 @@ function CopilotChatInput({
|
|
|
684
787
|
onChange?.(nextValue);
|
|
685
788
|
updateSlashState(nextValue);
|
|
686
789
|
};
|
|
687
|
-
const clearInputValue =
|
|
790
|
+
const clearInputValue = (0, import_react4.useCallback)(() => {
|
|
688
791
|
if (!isControlled) {
|
|
689
792
|
setInternalValue("");
|
|
690
793
|
}
|
|
@@ -692,7 +795,7 @@ function CopilotChatInput({
|
|
|
692
795
|
onChange("");
|
|
693
796
|
}
|
|
694
797
|
}, [isControlled, onChange]);
|
|
695
|
-
const runCommand =
|
|
798
|
+
const runCommand = (0, import_react4.useCallback)(
|
|
696
799
|
(item) => {
|
|
697
800
|
clearInputValue();
|
|
698
801
|
item.action?.();
|
|
@@ -780,7 +883,7 @@ function CopilotChatInput({
|
|
|
780
883
|
onChange: handleChange,
|
|
781
884
|
onKeyDown: handleKeyDown,
|
|
782
885
|
autoFocus,
|
|
783
|
-
className:
|
|
886
|
+
className: (0, import_tailwind_merge3.twMerge)(
|
|
784
887
|
"w-full py-3",
|
|
785
888
|
isExpanded ? "px-5" : "pr-5"
|
|
786
889
|
)
|
|
@@ -801,7 +904,7 @@ function CopilotChatInput({
|
|
|
801
904
|
const BoundSendButton = renderSlot(sendButton, CopilotChatInput.SendButton, {
|
|
802
905
|
onClick: handleSendButtonClick,
|
|
803
906
|
disabled: isProcessing ? !canStop : !canSend,
|
|
804
|
-
children: isProcessing && canStop ? /* @__PURE__ */
|
|
907
|
+
children: isProcessing && canStop ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react2.Square, { className: "size-[18px] fill-current" }) : void 0
|
|
805
908
|
});
|
|
806
909
|
const BoundStartTranscribeButton = renderSlot(startTranscribeButton, CopilotChatInput.StartTranscribeButton, {
|
|
807
910
|
onClick: onStartTranscribe
|
|
@@ -837,7 +940,7 @@ function CopilotChatInput({
|
|
|
837
940
|
toolsMenu,
|
|
838
941
|
autoFocus
|
|
839
942
|
};
|
|
840
|
-
return /* @__PURE__ */
|
|
943
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_jsx_runtime6.Fragment, { children: children(childProps) });
|
|
841
944
|
}
|
|
842
945
|
const handleContainerClick = (e) => {
|
|
843
946
|
const target = e.target;
|
|
@@ -845,7 +948,7 @@ function CopilotChatInput({
|
|
|
845
948
|
inputRef.current.focus();
|
|
846
949
|
}
|
|
847
950
|
};
|
|
848
|
-
const ensureMeasurements =
|
|
951
|
+
const ensureMeasurements = (0, import_react4.useCallback)(() => {
|
|
849
952
|
const textarea = inputRef.current;
|
|
850
953
|
if (!textarea) {
|
|
851
954
|
return;
|
|
@@ -872,7 +975,7 @@ function CopilotChatInput({
|
|
|
872
975
|
textarea.style.height = previousHeight;
|
|
873
976
|
textarea.style.maxHeight = `${maxHeight}px`;
|
|
874
977
|
}, []);
|
|
875
|
-
const adjustTextareaHeight =
|
|
978
|
+
const adjustTextareaHeight = (0, import_react4.useCallback)(() => {
|
|
876
979
|
const textarea = inputRef.current;
|
|
877
980
|
if (!textarea) {
|
|
878
981
|
return 0;
|
|
@@ -893,7 +996,7 @@ function CopilotChatInput({
|
|
|
893
996
|
}
|
|
894
997
|
return scrollHeight;
|
|
895
998
|
}, [ensureMeasurements]);
|
|
896
|
-
const updateLayout =
|
|
999
|
+
const updateLayout = (0, import_react4.useCallback)((nextLayout) => {
|
|
897
1000
|
setLayout((prev) => {
|
|
898
1001
|
if (prev === nextLayout) {
|
|
899
1002
|
return prev;
|
|
@@ -902,7 +1005,7 @@ function CopilotChatInput({
|
|
|
902
1005
|
return nextLayout;
|
|
903
1006
|
});
|
|
904
1007
|
}, []);
|
|
905
|
-
const evaluateLayout =
|
|
1008
|
+
const evaluateLayout = (0, import_react4.useCallback)(() => {
|
|
906
1009
|
if (mode !== "input") {
|
|
907
1010
|
updateLayout("compact");
|
|
908
1011
|
return;
|
|
@@ -973,10 +1076,10 @@ function CopilotChatInput({
|
|
|
973
1076
|
const nextLayout = shouldExpand ? "expanded" : "compact";
|
|
974
1077
|
updateLayout(nextLayout);
|
|
975
1078
|
}, [adjustTextareaHeight, ensureMeasurements, mode, resolvedValue, updateLayout]);
|
|
976
|
-
|
|
1079
|
+
(0, import_react4.useLayoutEffect)(() => {
|
|
977
1080
|
evaluateLayout();
|
|
978
1081
|
}, [evaluateLayout]);
|
|
979
|
-
|
|
1082
|
+
(0, import_react4.useEffect)(() => {
|
|
980
1083
|
if (typeof ResizeObserver === "undefined") {
|
|
981
1084
|
return;
|
|
982
1085
|
}
|
|
@@ -1020,7 +1123,7 @@ function CopilotChatInput({
|
|
|
1020
1123
|
};
|
|
1021
1124
|
}, [evaluateLayout]);
|
|
1022
1125
|
const slashMenuVisible = commandQuery !== null && commandItems.length > 0;
|
|
1023
|
-
|
|
1126
|
+
(0, import_react4.useEffect)(() => {
|
|
1024
1127
|
if (!slashMenuVisible || slashHighlightIndex < 0) {
|
|
1025
1128
|
return;
|
|
1026
1129
|
}
|
|
@@ -1029,7 +1132,7 @@ function CopilotChatInput({
|
|
|
1029
1132
|
);
|
|
1030
1133
|
active?.scrollIntoView({ block: "nearest" });
|
|
1031
1134
|
}, [slashMenuVisible, slashHighlightIndex]);
|
|
1032
|
-
const slashMenu = slashMenuVisible ? /* @__PURE__ */
|
|
1135
|
+
const slashMenu = slashMenuVisible ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1033
1136
|
"div",
|
|
1034
1137
|
{
|
|
1035
1138
|
"data-testid": "copilot-slash-menu",
|
|
@@ -1038,9 +1141,9 @@ function CopilotChatInput({
|
|
|
1038
1141
|
ref: slashMenuRef,
|
|
1039
1142
|
className: "absolute bottom-full left-0 right-0 z-30 mb-2 max-h-64 overflow-y-auto rounded-lg border border-border bg-white shadow-lg dark:border-[#3a3a3a] dark:bg-[#1f1f1f]",
|
|
1040
1143
|
style: { maxHeight: `${SLASH_MENU_MAX_VISIBLE_ITEMS * SLASH_MENU_ITEM_HEIGHT_PX}px` },
|
|
1041
|
-
children: filteredCommands.length === 0 ? /* @__PURE__ */
|
|
1144
|
+
children: filteredCommands.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "px-3 py-2 text-sm text-muted-foreground", children: "No commands found" }) : filteredCommands.map((item, index) => {
|
|
1042
1145
|
const isActive = index === slashHighlightIndex;
|
|
1043
|
-
return /* @__PURE__ */
|
|
1146
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1044
1147
|
"button",
|
|
1045
1148
|
{
|
|
1046
1149
|
type: "button",
|
|
@@ -1048,7 +1151,7 @@ function CopilotChatInput({
|
|
|
1048
1151
|
"aria-selected": isActive,
|
|
1049
1152
|
"data-active": isActive ? "true" : void 0,
|
|
1050
1153
|
"data-slash-index": index,
|
|
1051
|
-
className:
|
|
1154
|
+
className: (0, import_tailwind_merge3.twMerge)(
|
|
1052
1155
|
"w-full px-3 py-2 text-left text-sm transition-colors",
|
|
1053
1156
|
"hover:bg-muted dark:hover:bg-[#2f2f2f]",
|
|
1054
1157
|
isActive ? "bg-muted dark:bg-[#2f2f2f]" : "bg-transparent"
|
|
@@ -1065,10 +1168,10 @@ function CopilotChatInput({
|
|
|
1065
1168
|
})
|
|
1066
1169
|
}
|
|
1067
1170
|
) : null;
|
|
1068
|
-
return /* @__PURE__ */
|
|
1171
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1069
1172
|
"div",
|
|
1070
1173
|
{
|
|
1071
|
-
className:
|
|
1174
|
+
className: (0, import_tailwind_merge3.twMerge)(
|
|
1072
1175
|
// Layout
|
|
1073
1176
|
"flex w-full flex-col items-center justify-center",
|
|
1074
1177
|
// Interaction
|
|
@@ -1084,21 +1187,21 @@ function CopilotChatInput({
|
|
|
1084
1187
|
onClick: handleContainerClick,
|
|
1085
1188
|
...props,
|
|
1086
1189
|
"data-layout": isExpanded ? "expanded" : "compact",
|
|
1087
|
-
children: /* @__PURE__ */
|
|
1190
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
1088
1191
|
"div",
|
|
1089
1192
|
{
|
|
1090
1193
|
ref: gridRef,
|
|
1091
|
-
className:
|
|
1194
|
+
className: (0, import_tailwind_merge3.twMerge)(
|
|
1092
1195
|
"grid w-full gap-x-3 gap-y-3 px-3 py-2",
|
|
1093
1196
|
isExpanded ? "grid-cols-[auto_minmax(0,1fr)_auto] grid-rows-[auto_auto]" : "grid-cols-[auto_minmax(0,1fr)_auto] items-center"
|
|
1094
1197
|
),
|
|
1095
1198
|
"data-layout": isExpanded ? "expanded" : "compact",
|
|
1096
1199
|
children: [
|
|
1097
|
-
/* @__PURE__ */
|
|
1200
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1098
1201
|
"div",
|
|
1099
1202
|
{
|
|
1100
1203
|
ref: addButtonContainerRef,
|
|
1101
|
-
className:
|
|
1204
|
+
className: (0, import_tailwind_merge3.twMerge)(
|
|
1102
1205
|
"flex items-center",
|
|
1103
1206
|
isExpanded ? "row-start-2" : "row-start-1",
|
|
1104
1207
|
"col-start-1"
|
|
@@ -1106,31 +1209,31 @@ function CopilotChatInput({
|
|
|
1106
1209
|
children: BoundAddMenuButton
|
|
1107
1210
|
}
|
|
1108
1211
|
),
|
|
1109
|
-
/* @__PURE__ */
|
|
1212
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1110
1213
|
"div",
|
|
1111
1214
|
{
|
|
1112
|
-
className:
|
|
1215
|
+
className: (0, import_tailwind_merge3.twMerge)(
|
|
1113
1216
|
"relative flex min-w-0 flex-col",
|
|
1114
1217
|
isExpanded ? "col-span-3 row-start-1" : "col-start-2 row-start-1"
|
|
1115
1218
|
),
|
|
1116
|
-
children: mode === "transcribe" ? BoundAudioRecorder : /* @__PURE__ */
|
|
1219
|
+
children: mode === "transcribe" ? BoundAudioRecorder : /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
1117
1220
|
BoundTextArea,
|
|
1118
1221
|
slashMenu
|
|
1119
1222
|
] })
|
|
1120
1223
|
}
|
|
1121
1224
|
),
|
|
1122
|
-
/* @__PURE__ */
|
|
1225
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1123
1226
|
"div",
|
|
1124
1227
|
{
|
|
1125
1228
|
ref: actionsContainerRef,
|
|
1126
|
-
className:
|
|
1229
|
+
className: (0, import_tailwind_merge3.twMerge)(
|
|
1127
1230
|
"flex items-center justify-end gap-2",
|
|
1128
1231
|
isExpanded ? "col-start-3 row-start-2" : "col-start-3 row-start-1"
|
|
1129
1232
|
),
|
|
1130
|
-
children: mode === "transcribe" ? /* @__PURE__ */
|
|
1233
|
+
children: mode === "transcribe" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
1131
1234
|
onCancelTranscribe && BoundCancelTranscribeButton,
|
|
1132
1235
|
onFinishTranscribe && BoundFinishTranscribeButton
|
|
1133
|
-
] }) : /* @__PURE__ */
|
|
1236
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
1134
1237
|
onStartTranscribe && BoundStartTranscribeButton,
|
|
1135
1238
|
BoundSendButton
|
|
1136
1239
|
] })
|
|
@@ -1143,7 +1246,7 @@ function CopilotChatInput({
|
|
|
1143
1246
|
);
|
|
1144
1247
|
}
|
|
1145
1248
|
((CopilotChatInput2) => {
|
|
1146
|
-
CopilotChatInput2.SendButton = ({ className, children, ...props }) => /* @__PURE__ */
|
|
1249
|
+
CopilotChatInput2.SendButton = ({ className, children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "mr-[10px]", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1147
1250
|
Button,
|
|
1148
1251
|
{
|
|
1149
1252
|
type: "button",
|
|
@@ -1151,49 +1254,49 @@ function CopilotChatInput({
|
|
|
1151
1254
|
size: "chatInputToolbarIcon",
|
|
1152
1255
|
className,
|
|
1153
1256
|
...props,
|
|
1154
|
-
children: children ?? /* @__PURE__ */
|
|
1257
|
+
children: children ?? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react2.ArrowUp, { className: "size-[18px]" })
|
|
1155
1258
|
}
|
|
1156
1259
|
) });
|
|
1157
1260
|
CopilotChatInput2.ToolbarButton = ({ icon, labelKey, defaultClassName, className, ...props }) => {
|
|
1158
1261
|
const config = useCopilotChatConfiguration();
|
|
1159
1262
|
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
1160
|
-
return /* @__PURE__ */
|
|
1161
|
-
/* @__PURE__ */
|
|
1263
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Tooltip, { children: [
|
|
1264
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1162
1265
|
Button,
|
|
1163
1266
|
{
|
|
1164
1267
|
type: "button",
|
|
1165
1268
|
variant: "chatInputToolbarSecondary",
|
|
1166
1269
|
size: "chatInputToolbarIcon",
|
|
1167
|
-
className:
|
|
1270
|
+
className: (0, import_tailwind_merge3.twMerge)(defaultClassName, className),
|
|
1168
1271
|
...props,
|
|
1169
1272
|
children: icon
|
|
1170
1273
|
}
|
|
1171
1274
|
) }),
|
|
1172
|
-
/* @__PURE__ */
|
|
1275
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(TooltipContent, { side: "bottom", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { children: labels[labelKey] }) })
|
|
1173
1276
|
] });
|
|
1174
1277
|
};
|
|
1175
|
-
CopilotChatInput2.StartTranscribeButton = (props) => /* @__PURE__ */
|
|
1278
|
+
CopilotChatInput2.StartTranscribeButton = (props) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1176
1279
|
CopilotChatInput2.ToolbarButton,
|
|
1177
1280
|
{
|
|
1178
|
-
icon: /* @__PURE__ */
|
|
1281
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react2.Mic, { className: "size-[18px]" }),
|
|
1179
1282
|
labelKey: "chatInputToolbarStartTranscribeButtonLabel",
|
|
1180
1283
|
defaultClassName: "mr-2",
|
|
1181
1284
|
...props
|
|
1182
1285
|
}
|
|
1183
1286
|
);
|
|
1184
|
-
CopilotChatInput2.CancelTranscribeButton = (props) => /* @__PURE__ */
|
|
1287
|
+
CopilotChatInput2.CancelTranscribeButton = (props) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1185
1288
|
CopilotChatInput2.ToolbarButton,
|
|
1186
1289
|
{
|
|
1187
|
-
icon: /* @__PURE__ */
|
|
1290
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react2.X, { className: "size-[18px]" }),
|
|
1188
1291
|
labelKey: "chatInputToolbarCancelTranscribeButtonLabel",
|
|
1189
1292
|
defaultClassName: "mr-2",
|
|
1190
1293
|
...props
|
|
1191
1294
|
}
|
|
1192
1295
|
);
|
|
1193
|
-
CopilotChatInput2.FinishTranscribeButton = (props) => /* @__PURE__ */
|
|
1296
|
+
CopilotChatInput2.FinishTranscribeButton = (props) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1194
1297
|
CopilotChatInput2.ToolbarButton,
|
|
1195
1298
|
{
|
|
1196
|
-
icon: /* @__PURE__ */
|
|
1299
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react2.Check, { className: "size-[18px]" }),
|
|
1197
1300
|
labelKey: "chatInputToolbarFinishTranscribeButtonLabel",
|
|
1198
1301
|
defaultClassName: "mr-[10px]",
|
|
1199
1302
|
...props
|
|
@@ -1202,7 +1305,7 @@ function CopilotChatInput({
|
|
|
1202
1305
|
CopilotChatInput2.AddMenuButton = ({ className, toolsMenu, onAddFile, disabled, ...props }) => {
|
|
1203
1306
|
const config = useCopilotChatConfiguration();
|
|
1204
1307
|
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
1205
|
-
const menuItems =
|
|
1308
|
+
const menuItems = (0, import_react4.useMemo)(() => {
|
|
1206
1309
|
const items = [];
|
|
1207
1310
|
if (onAddFile) {
|
|
1208
1311
|
items.push({
|
|
@@ -1230,51 +1333,51 @@ function CopilotChatInput({
|
|
|
1230
1333
|
}
|
|
1231
1334
|
return items;
|
|
1232
1335
|
}, [onAddFile, toolsMenu, labels.chatInputToolbarAddButtonLabel]);
|
|
1233
|
-
const renderMenuItems =
|
|
1336
|
+
const renderMenuItems = (0, import_react4.useCallback)(
|
|
1234
1337
|
(items) => items.map((item, index) => {
|
|
1235
1338
|
if (item === "-") {
|
|
1236
|
-
return /* @__PURE__ */
|
|
1339
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(DropdownMenuSeparator, {}, `separator-${index}`);
|
|
1237
1340
|
}
|
|
1238
1341
|
if (item.items && item.items.length > 0) {
|
|
1239
|
-
return /* @__PURE__ */
|
|
1240
|
-
/* @__PURE__ */
|
|
1241
|
-
/* @__PURE__ */
|
|
1342
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(DropdownMenuSub, { children: [
|
|
1343
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(DropdownMenuSubTrigger, { children: item.label }),
|
|
1344
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(DropdownMenuSubContent, { children: renderMenuItems(item.items) })
|
|
1242
1345
|
] }, `group-${index}`);
|
|
1243
1346
|
}
|
|
1244
|
-
return /* @__PURE__ */
|
|
1347
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(DropdownMenuItem, { onClick: item.action, children: item.label }, `item-${index}`);
|
|
1245
1348
|
}),
|
|
1246
1349
|
[]
|
|
1247
1350
|
);
|
|
1248
1351
|
const hasMenuItems = menuItems.length > 0;
|
|
1249
1352
|
const isDisabled = disabled || !hasMenuItems;
|
|
1250
|
-
return /* @__PURE__ */
|
|
1251
|
-
/* @__PURE__ */
|
|
1252
|
-
/* @__PURE__ */
|
|
1353
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(DropdownMenu, { children: [
|
|
1354
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Tooltip, { children: [
|
|
1355
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1253
1356
|
Button,
|
|
1254
1357
|
{
|
|
1255
1358
|
type: "button",
|
|
1256
1359
|
variant: "chatInputToolbarSecondary",
|
|
1257
1360
|
size: "chatInputToolbarIcon",
|
|
1258
|
-
className:
|
|
1361
|
+
className: (0, import_tailwind_merge3.twMerge)("ml-1", className),
|
|
1259
1362
|
disabled: isDisabled,
|
|
1260
1363
|
...props,
|
|
1261
|
-
children: /* @__PURE__ */
|
|
1364
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react2.Plus, { className: "size-[20px]" })
|
|
1262
1365
|
}
|
|
1263
1366
|
) }) }),
|
|
1264
|
-
/* @__PURE__ */
|
|
1265
|
-
/* @__PURE__ */
|
|
1266
|
-
/* @__PURE__ */
|
|
1367
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(TooltipContent, { side: "bottom", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("p", { className: "flex items-center gap-1 text-xs font-medium", children: [
|
|
1368
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: "Add files and more" }),
|
|
1369
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("code", { className: "rounded bg-[#4a4a4a] px-1 py-[1px] font-mono text-[11px] text-white dark:bg-[#e0e0e0] dark:text-black", children: "/" })
|
|
1267
1370
|
] }) })
|
|
1268
1371
|
] }),
|
|
1269
|
-
hasMenuItems && /* @__PURE__ */
|
|
1372
|
+
hasMenuItems && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(DropdownMenuContent, { side: "top", align: "start", children: renderMenuItems(menuItems) })
|
|
1270
1373
|
] });
|
|
1271
1374
|
};
|
|
1272
|
-
CopilotChatInput2.TextArea =
|
|
1273
|
-
const internalTextareaRef =
|
|
1375
|
+
CopilotChatInput2.TextArea = (0, import_react4.forwardRef)(function TextArea2({ style, className, autoFocus, ...props }, ref) {
|
|
1376
|
+
const internalTextareaRef = (0, import_react4.useRef)(null);
|
|
1274
1377
|
const config = useCopilotChatConfiguration();
|
|
1275
1378
|
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
1276
|
-
|
|
1277
|
-
|
|
1379
|
+
(0, import_react4.useImperativeHandle)(ref, () => internalTextareaRef.current);
|
|
1380
|
+
(0, import_react4.useEffect)(() => {
|
|
1278
1381
|
const textarea = internalTextareaRef.current;
|
|
1279
1382
|
if (!textarea) return;
|
|
1280
1383
|
const handleFocus = () => {
|
|
@@ -1285,12 +1388,12 @@ function CopilotChatInput({
|
|
|
1285
1388
|
textarea.addEventListener("focus", handleFocus);
|
|
1286
1389
|
return () => textarea.removeEventListener("focus", handleFocus);
|
|
1287
1390
|
}, []);
|
|
1288
|
-
|
|
1391
|
+
(0, import_react4.useEffect)(() => {
|
|
1289
1392
|
if (autoFocus) {
|
|
1290
1393
|
internalTextareaRef.current?.focus();
|
|
1291
1394
|
}
|
|
1292
1395
|
}, [autoFocus]);
|
|
1293
|
-
return /* @__PURE__ */
|
|
1396
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1294
1397
|
"textarea",
|
|
1295
1398
|
{
|
|
1296
1399
|
ref: internalTextareaRef,
|
|
@@ -1301,7 +1404,7 @@ function CopilotChatInput({
|
|
|
1301
1404
|
...style
|
|
1302
1405
|
},
|
|
1303
1406
|
placeholder: labels.chatInputPlaceholder,
|
|
1304
|
-
className:
|
|
1407
|
+
className: (0, import_tailwind_merge3.twMerge)(
|
|
1305
1408
|
"bg-transparent outline-none antialiased font-regular leading-relaxed text-[16px] placeholder:text-[#00000077] dark:placeholder:text-[#fffc]",
|
|
1306
1409
|
className
|
|
1307
1410
|
),
|
|
@@ -1319,7 +1422,25 @@ CopilotChatInput.CancelTranscribeButton.displayName = "CopilotChatInput.CancelTr
|
|
|
1319
1422
|
CopilotChatInput.FinishTranscribeButton.displayName = "CopilotChatInput.FinishTranscribeButton";
|
|
1320
1423
|
CopilotChatInput.AddMenuButton.displayName = "CopilotChatInput.AddMenuButton";
|
|
1321
1424
|
var CopilotChatInput_default = CopilotChatInput;
|
|
1322
|
-
|
|
1425
|
+
|
|
1426
|
+
// src/components/chat/CopilotChatAssistantMessage.tsx
|
|
1427
|
+
var import_react17 = require("react");
|
|
1428
|
+
var import_lucide_react3 = require("lucide-react");
|
|
1429
|
+
var import_tailwind_merge4 = require("tailwind-merge");
|
|
1430
|
+
var import_katex_min = require("katex/dist/katex.min.css");
|
|
1431
|
+
var import_streamdown = require("streamdown");
|
|
1432
|
+
|
|
1433
|
+
// src/hooks/use-render-tool-call.tsx
|
|
1434
|
+
var import_react7 = __toESM(require("react"));
|
|
1435
|
+
var import_core2 = require("@copilotkitnext/core");
|
|
1436
|
+
|
|
1437
|
+
// src/providers/CopilotKitProvider.tsx
|
|
1438
|
+
var import_react6 = require("react");
|
|
1439
|
+
var import_zod = require("zod");
|
|
1440
|
+
|
|
1441
|
+
// src/lib/react-core.ts
|
|
1442
|
+
var import_core = require("@copilotkitnext/core");
|
|
1443
|
+
var CopilotKitCoreReact = class extends import_core.CopilotKitCore {
|
|
1323
1444
|
_renderToolCalls = [];
|
|
1324
1445
|
_renderCustomMessages = [];
|
|
1325
1446
|
_renderActivityMessages = [];
|
|
@@ -1357,26 +1478,29 @@ var CopilotKitCoreReact = class extends core.CopilotKitCore {
|
|
|
1357
1478
|
subscribe(subscriber) {
|
|
1358
1479
|
return super.subscribe(subscriber);
|
|
1359
1480
|
}
|
|
1360
|
-
unsubscribe(subscriber) {
|
|
1361
|
-
super.unsubscribe(subscriber);
|
|
1362
|
-
}
|
|
1363
1481
|
};
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1482
|
+
|
|
1483
|
+
// src/components/CopilotKitInspector.tsx
|
|
1484
|
+
var React4 = __toESM(require("react"));
|
|
1485
|
+
var import_react5 = require("@lit-labs/react");
|
|
1486
|
+
var import_web_inspector = require("@copilotkitnext/web-inspector");
|
|
1487
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1488
|
+
(0, import_web_inspector.defineWebInspector)();
|
|
1489
|
+
var CopilotKitInspectorBase = (0, import_react5.createComponent)({
|
|
1490
|
+
tagName: import_web_inspector.WEB_INSPECTOR_TAG,
|
|
1491
|
+
elementClass: import_web_inspector.WebInspectorElement,
|
|
1492
|
+
react: React4
|
|
1369
1493
|
});
|
|
1370
|
-
var CopilotKitInspector =
|
|
1494
|
+
var CopilotKitInspector = React4.forwardRef(
|
|
1371
1495
|
({ core, ...rest }, ref) => {
|
|
1372
|
-
const innerRef =
|
|
1373
|
-
|
|
1374
|
-
|
|
1496
|
+
const innerRef = React4.useRef(null);
|
|
1497
|
+
React4.useImperativeHandle(ref, () => innerRef.current, []);
|
|
1498
|
+
React4.useEffect(() => {
|
|
1375
1499
|
if (innerRef.current) {
|
|
1376
1500
|
innerRef.current.core = core ?? null;
|
|
1377
1501
|
}
|
|
1378
1502
|
}, [core]);
|
|
1379
|
-
return /* @__PURE__ */
|
|
1503
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1380
1504
|
CopilotKitInspectorBase,
|
|
1381
1505
|
{
|
|
1382
1506
|
...rest,
|
|
@@ -1386,14 +1510,17 @@ var CopilotKitInspector = React2__namespace.forwardRef(
|
|
|
1386
1510
|
}
|
|
1387
1511
|
);
|
|
1388
1512
|
CopilotKitInspector.displayName = "CopilotKitInspector";
|
|
1389
|
-
|
|
1513
|
+
|
|
1514
|
+
// src/providers/CopilotKitProvider.tsx
|
|
1515
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1516
|
+
var CopilotKitContext = (0, import_react6.createContext)({
|
|
1390
1517
|
copilotkit: null
|
|
1391
1518
|
});
|
|
1392
1519
|
function useStableArrayProp(prop, warningMessage, isMeaningfulChange) {
|
|
1393
|
-
const empty =
|
|
1520
|
+
const empty = (0, import_react6.useMemo)(() => [], []);
|
|
1394
1521
|
const value = prop ?? empty;
|
|
1395
|
-
const initial =
|
|
1396
|
-
|
|
1522
|
+
const initial = (0, import_react6.useRef)(value);
|
|
1523
|
+
(0, import_react6.useEffect)(() => {
|
|
1397
1524
|
if (warningMessage && value !== initial.current && (isMeaningfulChange ? isMeaningfulChange(initial.current, value) : true)) {
|
|
1398
1525
|
console.error(warningMessage);
|
|
1399
1526
|
}
|
|
@@ -1414,8 +1541,8 @@ var CopilotKitProvider = ({
|
|
|
1414
1541
|
showDevConsole = false,
|
|
1415
1542
|
useSingleEndpoint = false
|
|
1416
1543
|
}) => {
|
|
1417
|
-
const [shouldRenderInspector, setShouldRenderInspector] =
|
|
1418
|
-
|
|
1544
|
+
const [shouldRenderInspector, setShouldRenderInspector] = (0, import_react6.useState)(false);
|
|
1545
|
+
(0, import_react6.useEffect)(() => {
|
|
1419
1546
|
if (typeof window === "undefined") {
|
|
1420
1547
|
return;
|
|
1421
1548
|
}
|
|
@@ -1461,7 +1588,7 @@ var CopilotKitProvider = ({
|
|
|
1461
1588
|
humanInTheLoop,
|
|
1462
1589
|
"humanInTheLoop must be a stable array. If you want to dynamically add or remove human-in-the-loop tools, use `useHumanInTheLoop` instead."
|
|
1463
1590
|
);
|
|
1464
|
-
const processedHumanInTheLoopTools =
|
|
1591
|
+
const processedHumanInTheLoopTools = (0, import_react6.useMemo)(() => {
|
|
1465
1592
|
const processedTools = [];
|
|
1466
1593
|
const processedRenderToolCalls = [];
|
|
1467
1594
|
humanInTheLoopList.forEach((tool) => {
|
|
@@ -1490,17 +1617,17 @@ var CopilotKitProvider = ({
|
|
|
1490
1617
|
});
|
|
1491
1618
|
return { tools: processedTools, renderToolCalls: processedRenderToolCalls };
|
|
1492
1619
|
}, [humanInTheLoopList]);
|
|
1493
|
-
const allTools =
|
|
1620
|
+
const allTools = (0, import_react6.useMemo)(() => {
|
|
1494
1621
|
const tools = [];
|
|
1495
1622
|
tools.push(...frontendToolsList);
|
|
1496
1623
|
tools.push(...processedHumanInTheLoopTools.tools);
|
|
1497
1624
|
return tools;
|
|
1498
1625
|
}, [frontendToolsList, processedHumanInTheLoopTools]);
|
|
1499
|
-
const allRenderToolCalls =
|
|
1626
|
+
const allRenderToolCalls = (0, import_react6.useMemo)(() => {
|
|
1500
1627
|
const combined = [...renderToolCallsList];
|
|
1501
1628
|
frontendToolsList.forEach((tool) => {
|
|
1502
1629
|
if (tool.render) {
|
|
1503
|
-
const args = tool.parameters || (tool.name === "*" ?
|
|
1630
|
+
const args = tool.parameters || (tool.name === "*" ? import_zod.z.any() : void 0);
|
|
1504
1631
|
if (args) {
|
|
1505
1632
|
combined.push({
|
|
1506
1633
|
name: tool.name,
|
|
@@ -1513,7 +1640,7 @@ var CopilotKitProvider = ({
|
|
|
1513
1640
|
combined.push(...processedHumanInTheLoopTools.renderToolCalls);
|
|
1514
1641
|
return combined;
|
|
1515
1642
|
}, [renderToolCallsList, frontendToolsList, processedHumanInTheLoopTools]);
|
|
1516
|
-
const copilotkit =
|
|
1643
|
+
const copilotkit = (0, import_react6.useMemo)(() => {
|
|
1517
1644
|
const copilotkit2 = new CopilotKitCoreReact({
|
|
1518
1645
|
runtimeUrl,
|
|
1519
1646
|
runtimeTransport: useSingleEndpoint ? "single" : "rest",
|
|
@@ -1527,25 +1654,25 @@ var CopilotKitProvider = ({
|
|
|
1527
1654
|
});
|
|
1528
1655
|
return copilotkit2;
|
|
1529
1656
|
}, [allTools, allRenderToolCalls, renderActivityMessagesList, renderCustomMessagesList, useSingleEndpoint]);
|
|
1530
|
-
const [, forceUpdate] =
|
|
1531
|
-
|
|
1532
|
-
const
|
|
1657
|
+
const [, forceUpdate] = (0, import_react6.useReducer)((x) => x + 1, 0);
|
|
1658
|
+
(0, import_react6.useEffect)(() => {
|
|
1659
|
+
const subscription = copilotkit.subscribe({
|
|
1533
1660
|
onRenderToolCallsChanged: () => {
|
|
1534
1661
|
forceUpdate();
|
|
1535
1662
|
}
|
|
1536
1663
|
});
|
|
1537
1664
|
return () => {
|
|
1538
|
-
unsubscribe();
|
|
1665
|
+
subscription.unsubscribe();
|
|
1539
1666
|
};
|
|
1540
1667
|
}, [copilotkit]);
|
|
1541
|
-
|
|
1668
|
+
(0, import_react6.useEffect)(() => {
|
|
1542
1669
|
copilotkit.setRuntimeUrl(runtimeUrl);
|
|
1543
1670
|
copilotkit.setRuntimeTransport(useSingleEndpoint ? "single" : "rest");
|
|
1544
1671
|
copilotkit.setHeaders(headers);
|
|
1545
1672
|
copilotkit.setProperties(properties);
|
|
1546
1673
|
copilotkit.setAgents__unsafe_dev_only(agents);
|
|
1547
1674
|
}, [runtimeUrl, headers, properties, agents, useSingleEndpoint]);
|
|
1548
|
-
return /* @__PURE__ */
|
|
1675
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
1549
1676
|
CopilotKitContext.Provider,
|
|
1550
1677
|
{
|
|
1551
1678
|
value: {
|
|
@@ -1553,45 +1680,107 @@ var CopilotKitProvider = ({
|
|
|
1553
1680
|
},
|
|
1554
1681
|
children: [
|
|
1555
1682
|
children,
|
|
1556
|
-
shouldRenderInspector ? /* @__PURE__ */
|
|
1683
|
+
shouldRenderInspector ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(CopilotKitInspector, { core: copilotkit }) : null
|
|
1557
1684
|
]
|
|
1558
1685
|
}
|
|
1559
1686
|
);
|
|
1560
1687
|
};
|
|
1561
1688
|
var useCopilotKit = () => {
|
|
1562
|
-
const context =
|
|
1563
|
-
const [, forceUpdate] =
|
|
1689
|
+
const context = (0, import_react6.useContext)(CopilotKitContext);
|
|
1690
|
+
const [, forceUpdate] = (0, import_react6.useReducer)((x) => x + 1, 0);
|
|
1564
1691
|
if (!context) {
|
|
1565
1692
|
throw new Error("useCopilotKit must be used within CopilotKitProvider");
|
|
1566
1693
|
}
|
|
1567
|
-
|
|
1568
|
-
const
|
|
1694
|
+
(0, import_react6.useEffect)(() => {
|
|
1695
|
+
const subscription = context.copilotkit.subscribe({
|
|
1569
1696
|
onRuntimeConnectionStatusChanged: () => {
|
|
1570
1697
|
forceUpdate();
|
|
1571
1698
|
}
|
|
1572
1699
|
});
|
|
1573
1700
|
return () => {
|
|
1574
|
-
unsubscribe();
|
|
1701
|
+
subscription.unsubscribe();
|
|
1575
1702
|
};
|
|
1576
1703
|
}, []);
|
|
1577
1704
|
return context;
|
|
1578
1705
|
};
|
|
1706
|
+
|
|
1707
|
+
// src/hooks/use-render-tool-call.tsx
|
|
1708
|
+
var import_shared2 = require("@copilotkitnext/shared");
|
|
1709
|
+
var import_shared3 = require("@copilotkitnext/shared");
|
|
1710
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1711
|
+
var ToolCallRenderer = import_react7.default.memo(
|
|
1712
|
+
function ToolCallRenderer2({
|
|
1713
|
+
toolCall,
|
|
1714
|
+
toolMessage,
|
|
1715
|
+
RenderComponent,
|
|
1716
|
+
isExecuting
|
|
1717
|
+
}) {
|
|
1718
|
+
const args = (0, import_react7.useMemo)(
|
|
1719
|
+
() => (0, import_shared3.partialJSONParse)(toolCall.function.arguments),
|
|
1720
|
+
[toolCall.function.arguments]
|
|
1721
|
+
);
|
|
1722
|
+
const toolName = toolCall.function.name;
|
|
1723
|
+
if (toolMessage) {
|
|
1724
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1725
|
+
RenderComponent,
|
|
1726
|
+
{
|
|
1727
|
+
name: toolName,
|
|
1728
|
+
args,
|
|
1729
|
+
status: import_core2.ToolCallStatus.Complete,
|
|
1730
|
+
result: toolMessage.content
|
|
1731
|
+
}
|
|
1732
|
+
);
|
|
1733
|
+
} else if (isExecuting) {
|
|
1734
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1735
|
+
RenderComponent,
|
|
1736
|
+
{
|
|
1737
|
+
name: toolName,
|
|
1738
|
+
args,
|
|
1739
|
+
status: import_core2.ToolCallStatus.Executing,
|
|
1740
|
+
result: void 0
|
|
1741
|
+
}
|
|
1742
|
+
);
|
|
1743
|
+
} else {
|
|
1744
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1745
|
+
RenderComponent,
|
|
1746
|
+
{
|
|
1747
|
+
name: toolName,
|
|
1748
|
+
args,
|
|
1749
|
+
status: import_core2.ToolCallStatus.InProgress,
|
|
1750
|
+
result: void 0
|
|
1751
|
+
}
|
|
1752
|
+
);
|
|
1753
|
+
}
|
|
1754
|
+
},
|
|
1755
|
+
// Custom comparison function to prevent re-renders when tool call data hasn't changed
|
|
1756
|
+
(prevProps, nextProps) => {
|
|
1757
|
+
if (prevProps.toolCall.id !== nextProps.toolCall.id) return false;
|
|
1758
|
+
if (prevProps.toolCall.function.name !== nextProps.toolCall.function.name) return false;
|
|
1759
|
+
if (prevProps.toolCall.function.arguments !== nextProps.toolCall.function.arguments) return false;
|
|
1760
|
+
const prevResult = prevProps.toolMessage?.content;
|
|
1761
|
+
const nextResult = nextProps.toolMessage?.content;
|
|
1762
|
+
if (prevResult !== nextResult) return false;
|
|
1763
|
+
if (prevProps.isExecuting !== nextProps.isExecuting) return false;
|
|
1764
|
+
if (prevProps.RenderComponent !== nextProps.RenderComponent) return false;
|
|
1765
|
+
return true;
|
|
1766
|
+
}
|
|
1767
|
+
);
|
|
1579
1768
|
function useRenderToolCall() {
|
|
1580
1769
|
const { copilotkit } = useCopilotKit();
|
|
1581
1770
|
const config = useCopilotChatConfiguration();
|
|
1582
|
-
const agentId = config?.agentId ??
|
|
1583
|
-
const [executingToolCallIds, setExecutingToolCallIds] =
|
|
1584
|
-
const renderToolCalls =
|
|
1771
|
+
const agentId = config?.agentId ?? import_shared2.DEFAULT_AGENT_ID;
|
|
1772
|
+
const [executingToolCallIds, setExecutingToolCallIds] = (0, import_react7.useState)(() => /* @__PURE__ */ new Set());
|
|
1773
|
+
const renderToolCalls = (0, import_react7.useSyncExternalStore)(
|
|
1585
1774
|
(callback) => {
|
|
1586
1775
|
return copilotkit.subscribe({
|
|
1587
1776
|
onRenderToolCallsChanged: callback
|
|
1588
|
-
});
|
|
1777
|
+
}).unsubscribe;
|
|
1589
1778
|
},
|
|
1590
1779
|
() => copilotkit.renderToolCalls,
|
|
1591
1780
|
() => copilotkit.renderToolCalls
|
|
1592
1781
|
);
|
|
1593
|
-
|
|
1594
|
-
const
|
|
1782
|
+
(0, import_react7.useEffect)(() => {
|
|
1783
|
+
const subscription = copilotkit.subscribe({
|
|
1595
1784
|
onToolExecutionStart: ({ toolCallId }) => {
|
|
1596
1785
|
setExecutingToolCallIds((prev) => {
|
|
1597
1786
|
if (prev.has(toolCallId)) return prev;
|
|
@@ -1609,9 +1798,9 @@ function useRenderToolCall() {
|
|
|
1609
1798
|
});
|
|
1610
1799
|
}
|
|
1611
1800
|
});
|
|
1612
|
-
return () => unsubscribe();
|
|
1801
|
+
return () => subscription.unsubscribe();
|
|
1613
1802
|
}, [copilotkit]);
|
|
1614
|
-
const renderToolCall =
|
|
1803
|
+
const renderToolCall = (0, import_react7.useCallback)(
|
|
1615
1804
|
({
|
|
1616
1805
|
toolCall,
|
|
1617
1806
|
toolMessage
|
|
@@ -1624,47 +1813,25 @@ function useRenderToolCall() {
|
|
|
1624
1813
|
return null;
|
|
1625
1814
|
}
|
|
1626
1815
|
const RenderComponent = renderConfig.render;
|
|
1627
|
-
const
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
name: toolName,
|
|
1634
|
-
args,
|
|
1635
|
-
status: core.ToolCallStatus.Complete,
|
|
1636
|
-
result: toolMessage.content
|
|
1637
|
-
},
|
|
1638
|
-
toolCall.id
|
|
1639
|
-
);
|
|
1640
|
-
} else if (executingToolCallIds.has(toolCall.id)) {
|
|
1641
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1642
|
-
RenderComponent,
|
|
1643
|
-
{
|
|
1644
|
-
name: toolName,
|
|
1645
|
-
args,
|
|
1646
|
-
status: core.ToolCallStatus.Executing,
|
|
1647
|
-
result: void 0
|
|
1648
|
-
},
|
|
1649
|
-
toolCall.id
|
|
1650
|
-
);
|
|
1651
|
-
} else {
|
|
1652
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1816
|
+
const isExecuting = executingToolCallIds.has(toolCall.id);
|
|
1817
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1818
|
+
ToolCallRenderer,
|
|
1819
|
+
{
|
|
1820
|
+
toolCall,
|
|
1821
|
+
toolMessage,
|
|
1653
1822
|
RenderComponent,
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
result: void 0
|
|
1659
|
-
},
|
|
1660
|
-
toolCall.id
|
|
1661
|
-
);
|
|
1662
|
-
}
|
|
1823
|
+
isExecuting
|
|
1824
|
+
},
|
|
1825
|
+
toolCall.id
|
|
1826
|
+
);
|
|
1663
1827
|
},
|
|
1664
1828
|
[renderToolCalls, executingToolCallIds, agentId]
|
|
1665
1829
|
);
|
|
1666
1830
|
return renderToolCall;
|
|
1667
1831
|
}
|
|
1832
|
+
|
|
1833
|
+
// src/hooks/use-render-custom-messages.tsx
|
|
1834
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
1668
1835
|
function useRenderCustomMessages() {
|
|
1669
1836
|
const { copilotkit } = useCopilotKit();
|
|
1670
1837
|
const config = useCopilotChatConfiguration();
|
|
@@ -1699,7 +1866,7 @@ function useRenderCustomMessages() {
|
|
|
1699
1866
|
continue;
|
|
1700
1867
|
}
|
|
1701
1868
|
const Component = renderer.render;
|
|
1702
|
-
result = /* @__PURE__ */
|
|
1869
|
+
result = /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
1703
1870
|
Component,
|
|
1704
1871
|
{
|
|
1705
1872
|
message,
|
|
@@ -1720,12 +1887,17 @@ function useRenderCustomMessages() {
|
|
|
1720
1887
|
return result;
|
|
1721
1888
|
};
|
|
1722
1889
|
}
|
|
1890
|
+
|
|
1891
|
+
// src/hooks/use-render-activity-message.tsx
|
|
1892
|
+
var import_shared4 = require("@copilotkitnext/shared");
|
|
1893
|
+
var import_react8 = require("react");
|
|
1894
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
1723
1895
|
function useRenderActivityMessage() {
|
|
1724
1896
|
const { copilotkit } = useCopilotKit();
|
|
1725
1897
|
const config = useCopilotChatConfiguration();
|
|
1726
|
-
const agentId = config?.agentId ??
|
|
1898
|
+
const agentId = config?.agentId ?? import_shared4.DEFAULT_AGENT_ID;
|
|
1727
1899
|
const renderers = copilotkit.renderActivityMessages;
|
|
1728
|
-
return
|
|
1900
|
+
return (0, import_react8.useCallback)(
|
|
1729
1901
|
(message) => {
|
|
1730
1902
|
if (!renderers.length) {
|
|
1731
1903
|
return null;
|
|
@@ -1747,7 +1919,7 @@ function useRenderActivityMessage() {
|
|
|
1747
1919
|
}
|
|
1748
1920
|
const Component = renderer.render;
|
|
1749
1921
|
const agent = copilotkit.getAgent(agentId);
|
|
1750
|
-
return /* @__PURE__ */
|
|
1922
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
1751
1923
|
Component,
|
|
1752
1924
|
{
|
|
1753
1925
|
activityType: message.activityType,
|
|
@@ -1761,9 +1933,14 @@ function useRenderActivityMessage() {
|
|
|
1761
1933
|
[agentId, copilotkit, renderers]
|
|
1762
1934
|
);
|
|
1763
1935
|
}
|
|
1764
|
-
|
|
1936
|
+
|
|
1937
|
+
// src/hooks/use-frontend-tool.tsx
|
|
1938
|
+
var import_react9 = require("react");
|
|
1939
|
+
var EMPTY_DEPS = [];
|
|
1940
|
+
function useFrontendTool(tool, deps) {
|
|
1765
1941
|
const { copilotkit } = useCopilotKit();
|
|
1766
|
-
|
|
1942
|
+
const extraDeps = deps ?? EMPTY_DEPS;
|
|
1943
|
+
(0, import_react9.useEffect)(() => {
|
|
1767
1944
|
const name = tool.name;
|
|
1768
1945
|
if (copilotkit.getTool({ toolName: name, agentId: tool.agentId })) {
|
|
1769
1946
|
console.warn(
|
|
@@ -1791,23 +1968,27 @@ function useFrontendTool(tool) {
|
|
|
1791
1968
|
return () => {
|
|
1792
1969
|
copilotkit.removeTool(name, tool.agentId);
|
|
1793
1970
|
};
|
|
1794
|
-
}, [tool.name, copilotkit]);
|
|
1971
|
+
}, [tool.name, copilotkit, extraDeps.length, ...extraDeps]);
|
|
1795
1972
|
}
|
|
1796
|
-
|
|
1973
|
+
|
|
1974
|
+
// src/hooks/use-human-in-the-loop.tsx
|
|
1975
|
+
var import_react10 = require("react");
|
|
1976
|
+
var import_react11 = __toESM(require("react"));
|
|
1977
|
+
function useHumanInTheLoop(tool, deps) {
|
|
1797
1978
|
const { copilotkit } = useCopilotKit();
|
|
1798
|
-
const resolvePromiseRef =
|
|
1799
|
-
const respond =
|
|
1979
|
+
const resolvePromiseRef = (0, import_react10.useRef)(null);
|
|
1980
|
+
const respond = (0, import_react10.useCallback)(async (result) => {
|
|
1800
1981
|
if (resolvePromiseRef.current) {
|
|
1801
1982
|
resolvePromiseRef.current(result);
|
|
1802
1983
|
resolvePromiseRef.current = null;
|
|
1803
1984
|
}
|
|
1804
1985
|
}, []);
|
|
1805
|
-
const handler =
|
|
1986
|
+
const handler = (0, import_react10.useCallback)(async () => {
|
|
1806
1987
|
return new Promise((resolve) => {
|
|
1807
1988
|
resolvePromiseRef.current = resolve;
|
|
1808
1989
|
});
|
|
1809
1990
|
}, []);
|
|
1810
|
-
const RenderComponent =
|
|
1991
|
+
const RenderComponent = (0, import_react10.useCallback)(
|
|
1811
1992
|
(props) => {
|
|
1812
1993
|
const ToolComponent = tool.render;
|
|
1813
1994
|
if (props.status === "inProgress") {
|
|
@@ -1817,7 +1998,7 @@ function useHumanInTheLoop(tool) {
|
|
|
1817
1998
|
description: tool.description || "",
|
|
1818
1999
|
respond: void 0
|
|
1819
2000
|
};
|
|
1820
|
-
return
|
|
2001
|
+
return import_react11.default.createElement(ToolComponent, enhancedProps);
|
|
1821
2002
|
} else if (props.status === "executing") {
|
|
1822
2003
|
const enhancedProps = {
|
|
1823
2004
|
...props,
|
|
@@ -1825,7 +2006,7 @@ function useHumanInTheLoop(tool) {
|
|
|
1825
2006
|
description: tool.description || "",
|
|
1826
2007
|
respond
|
|
1827
2008
|
};
|
|
1828
|
-
return
|
|
2009
|
+
return import_react11.default.createElement(ToolComponent, enhancedProps);
|
|
1829
2010
|
} else if (props.status === "complete") {
|
|
1830
2011
|
const enhancedProps = {
|
|
1831
2012
|
...props,
|
|
@@ -1833,9 +2014,9 @@ function useHumanInTheLoop(tool) {
|
|
|
1833
2014
|
description: tool.description || "",
|
|
1834
2015
|
respond: void 0
|
|
1835
2016
|
};
|
|
1836
|
-
return
|
|
2017
|
+
return import_react11.default.createElement(ToolComponent, enhancedProps);
|
|
1837
2018
|
}
|
|
1838
|
-
return
|
|
2019
|
+
return import_react11.default.createElement(ToolComponent, props);
|
|
1839
2020
|
},
|
|
1840
2021
|
[tool.render, tool.name, tool.description, respond]
|
|
1841
2022
|
);
|
|
@@ -1844,8 +2025,8 @@ function useHumanInTheLoop(tool) {
|
|
|
1844
2025
|
handler,
|
|
1845
2026
|
render: RenderComponent
|
|
1846
2027
|
};
|
|
1847
|
-
useFrontendTool(frontendTool);
|
|
1848
|
-
|
|
2028
|
+
useFrontendTool(frontendTool, deps);
|
|
2029
|
+
(0, import_react10.useEffect)(() => {
|
|
1849
2030
|
return () => {
|
|
1850
2031
|
const keyOf = (rc) => `${rc.agentId ?? ""}:${rc.name}`;
|
|
1851
2032
|
const currentRenderToolCalls = copilotkit.renderToolCalls;
|
|
@@ -1856,31 +2037,55 @@ function useHumanInTheLoop(tool) {
|
|
|
1856
2037
|
};
|
|
1857
2038
|
}, [copilotkit, tool.name, tool.agentId]);
|
|
1858
2039
|
}
|
|
2040
|
+
|
|
2041
|
+
// src/hooks/use-agent.tsx
|
|
2042
|
+
var import_react12 = require("react");
|
|
2043
|
+
var import_shared5 = require("@copilotkitnext/shared");
|
|
2044
|
+
var import_core3 = require("@copilotkitnext/core");
|
|
1859
2045
|
var ALL_UPDATES = [
|
|
1860
2046
|
"OnMessagesChanged" /* OnMessagesChanged */,
|
|
1861
2047
|
"OnStateChanged" /* OnStateChanged */,
|
|
1862
2048
|
"OnRunStatusChanged" /* OnRunStatusChanged */
|
|
1863
2049
|
];
|
|
1864
2050
|
function useAgent({ agentId, updates } = {}) {
|
|
1865
|
-
agentId ??=
|
|
2051
|
+
agentId ??= import_shared5.DEFAULT_AGENT_ID;
|
|
1866
2052
|
const { copilotkit } = useCopilotKit();
|
|
1867
|
-
const [, forceUpdate] =
|
|
1868
|
-
const updateFlags =
|
|
2053
|
+
const [, forceUpdate] = (0, import_react12.useReducer)((x) => x + 1, 0);
|
|
2054
|
+
const updateFlags = (0, import_react12.useMemo)(
|
|
1869
2055
|
() => updates ?? ALL_UPDATES,
|
|
1870
2056
|
[JSON.stringify(updates)]
|
|
1871
2057
|
);
|
|
1872
|
-
const agent =
|
|
1873
|
-
|
|
2058
|
+
const agent = (0, import_react12.useMemo)(() => {
|
|
2059
|
+
const existing = copilotkit.getAgent(agentId);
|
|
2060
|
+
if (existing) {
|
|
2061
|
+
return existing;
|
|
2062
|
+
}
|
|
2063
|
+
const isRuntimeConfigured = copilotkit.runtimeUrl !== void 0;
|
|
2064
|
+
const status = copilotkit.runtimeConnectionStatus;
|
|
2065
|
+
if (isRuntimeConfigured && (status === import_core3.CopilotKitCoreRuntimeConnectionStatus.Disconnected || status === import_core3.CopilotKitCoreRuntimeConnectionStatus.Connecting)) {
|
|
2066
|
+
const provisional = new import_core3.ProxiedCopilotRuntimeAgent({
|
|
2067
|
+
runtimeUrl: copilotkit.runtimeUrl,
|
|
2068
|
+
agentId,
|
|
2069
|
+
transport: copilotkit.runtimeTransport
|
|
2070
|
+
});
|
|
2071
|
+
provisional.headers = { ...copilotkit.headers };
|
|
2072
|
+
return provisional;
|
|
2073
|
+
}
|
|
2074
|
+
const knownAgents = Object.keys(copilotkit.agents ?? {});
|
|
2075
|
+
const runtimePart = isRuntimeConfigured ? `runtimeUrl=${copilotkit.runtimeUrl}` : "no runtimeUrl";
|
|
2076
|
+
throw new Error(
|
|
2077
|
+
`useAgent: Agent '${agentId}' not found after runtime sync (${runtimePart}). ` + (knownAgents.length ? `Known agents: [${knownAgents.join(", ")}]` : "No agents registered.") + " Verify your runtime /info and/or agents__unsafe_dev_only."
|
|
2078
|
+
);
|
|
1874
2079
|
}, [
|
|
1875
2080
|
agentId,
|
|
1876
2081
|
copilotkit.agents,
|
|
1877
2082
|
copilotkit.runtimeConnectionStatus,
|
|
2083
|
+
copilotkit.runtimeUrl,
|
|
2084
|
+
copilotkit.runtimeTransport,
|
|
2085
|
+
JSON.stringify(copilotkit.headers),
|
|
1878
2086
|
copilotkit
|
|
1879
2087
|
]);
|
|
1880
|
-
|
|
1881
|
-
if (!agent) {
|
|
1882
|
-
return;
|
|
1883
|
-
}
|
|
2088
|
+
(0, import_react12.useEffect)(() => {
|
|
1884
2089
|
if (updateFlags.length === 0) {
|
|
1885
2090
|
return;
|
|
1886
2091
|
}
|
|
@@ -1913,10 +2118,13 @@ function useAgent({ agentId, updates } = {}) {
|
|
|
1913
2118
|
agent
|
|
1914
2119
|
};
|
|
1915
2120
|
}
|
|
2121
|
+
|
|
2122
|
+
// src/hooks/use-agent-context.tsx
|
|
2123
|
+
var import_react13 = require("react");
|
|
1916
2124
|
function useAgentContext(context) {
|
|
1917
2125
|
const { description, value } = context;
|
|
1918
2126
|
const { copilotkit } = useCopilotKit();
|
|
1919
|
-
|
|
2127
|
+
(0, import_react13.useEffect)(() => {
|
|
1920
2128
|
if (!copilotkit) return;
|
|
1921
2129
|
const id = copilotkit.addContext(context);
|
|
1922
2130
|
return () => {
|
|
@@ -1924,25 +2132,29 @@ function useAgentContext(context) {
|
|
|
1924
2132
|
};
|
|
1925
2133
|
}, [description, value, copilotkit]);
|
|
1926
2134
|
}
|
|
2135
|
+
|
|
2136
|
+
// src/hooks/use-suggestions.tsx
|
|
2137
|
+
var import_react14 = require("react");
|
|
2138
|
+
var import_shared6 = require("@copilotkitnext/shared");
|
|
1927
2139
|
function useSuggestions({ agentId } = {}) {
|
|
1928
2140
|
const { copilotkit } = useCopilotKit();
|
|
1929
2141
|
const config = useCopilotChatConfiguration();
|
|
1930
|
-
const resolvedAgentId =
|
|
1931
|
-
const [suggestions, setSuggestions] =
|
|
2142
|
+
const resolvedAgentId = (0, import_react14.useMemo)(() => agentId ?? config?.agentId ?? import_shared6.DEFAULT_AGENT_ID, [agentId, config?.agentId]);
|
|
2143
|
+
const [suggestions, setSuggestions] = (0, import_react14.useState)(() => {
|
|
1932
2144
|
const result = copilotkit.getSuggestions(resolvedAgentId);
|
|
1933
2145
|
return result.suggestions;
|
|
1934
2146
|
});
|
|
1935
|
-
const [isLoading, setIsLoading] =
|
|
2147
|
+
const [isLoading, setIsLoading] = (0, import_react14.useState)(() => {
|
|
1936
2148
|
const result = copilotkit.getSuggestions(resolvedAgentId);
|
|
1937
2149
|
return result.isLoading;
|
|
1938
2150
|
});
|
|
1939
|
-
|
|
2151
|
+
(0, import_react14.useEffect)(() => {
|
|
1940
2152
|
const result = copilotkit.getSuggestions(resolvedAgentId);
|
|
1941
2153
|
setSuggestions(result.suggestions);
|
|
1942
2154
|
setIsLoading(result.isLoading);
|
|
1943
2155
|
}, [copilotkit, resolvedAgentId]);
|
|
1944
|
-
|
|
1945
|
-
const
|
|
2156
|
+
(0, import_react14.useEffect)(() => {
|
|
2157
|
+
const subscription = copilotkit.subscribe({
|
|
1946
2158
|
onSuggestionsChanged: ({ agentId: changedAgentId, suggestions: suggestions2 }) => {
|
|
1947
2159
|
if (changedAgentId !== resolvedAgentId) {
|
|
1948
2160
|
return;
|
|
@@ -1968,13 +2180,13 @@ function useSuggestions({ agentId } = {}) {
|
|
|
1968
2180
|
}
|
|
1969
2181
|
});
|
|
1970
2182
|
return () => {
|
|
1971
|
-
unsubscribe();
|
|
2183
|
+
subscription.unsubscribe();
|
|
1972
2184
|
};
|
|
1973
2185
|
}, [copilotkit, resolvedAgentId]);
|
|
1974
|
-
const reloadSuggestions =
|
|
2186
|
+
const reloadSuggestions = (0, import_react14.useCallback)(() => {
|
|
1975
2187
|
copilotkit.reloadSuggestions(resolvedAgentId);
|
|
1976
2188
|
}, [copilotkit, resolvedAgentId]);
|
|
1977
|
-
const clearSuggestions =
|
|
2189
|
+
const clearSuggestions = (0, import_react14.useCallback)(() => {
|
|
1978
2190
|
copilotkit.clearSuggestions(resolvedAgentId);
|
|
1979
2191
|
}, [copilotkit, resolvedAgentId]);
|
|
1980
2192
|
return {
|
|
@@ -1984,18 +2196,21 @@ function useSuggestions({ agentId } = {}) {
|
|
|
1984
2196
|
isLoading
|
|
1985
2197
|
};
|
|
1986
2198
|
}
|
|
1987
|
-
|
|
1988
|
-
|
|
2199
|
+
|
|
2200
|
+
// src/hooks/use-configure-suggestions.tsx
|
|
2201
|
+
var import_react15 = require("react");
|
|
2202
|
+
var import_shared7 = require("@copilotkitnext/shared");
|
|
2203
|
+
function useConfigureSuggestions(config, deps) {
|
|
1989
2204
|
const { copilotkit } = useCopilotKit();
|
|
1990
2205
|
const chatConfig = useCopilotChatConfiguration();
|
|
1991
|
-
const extraDeps =
|
|
1992
|
-
const resolvedConsumerAgentId =
|
|
1993
|
-
const rawConsumerAgentId =
|
|
1994
|
-
const normalizationCacheRef =
|
|
2206
|
+
const extraDeps = deps ?? [];
|
|
2207
|
+
const resolvedConsumerAgentId = (0, import_react15.useMemo)(() => chatConfig?.agentId ?? import_shared7.DEFAULT_AGENT_ID, [chatConfig?.agentId]);
|
|
2208
|
+
const rawConsumerAgentId = (0, import_react15.useMemo)(() => config ? config.consumerAgentId : void 0, [config]);
|
|
2209
|
+
const normalizationCacheRef = (0, import_react15.useRef)({
|
|
1995
2210
|
serialized: null,
|
|
1996
2211
|
config: null
|
|
1997
2212
|
});
|
|
1998
|
-
const { normalizedConfig, serializedConfig } =
|
|
2213
|
+
const { normalizedConfig, serializedConfig } = (0, import_react15.useMemo)(() => {
|
|
1999
2214
|
if (!config) {
|
|
2000
2215
|
normalizationCacheRef.current = { serialized: null, config: null };
|
|
2001
2216
|
return { normalizedConfig: null, serializedConfig: null };
|
|
@@ -2025,10 +2240,10 @@ function useConfigureSuggestions(config, options) {
|
|
|
2025
2240
|
normalizationCacheRef.current = { serialized, config: built };
|
|
2026
2241
|
return { normalizedConfig: built, serializedConfig: serialized };
|
|
2027
2242
|
}, [config, resolvedConsumerAgentId, ...extraDeps]);
|
|
2028
|
-
const latestConfigRef =
|
|
2243
|
+
const latestConfigRef = (0, import_react15.useRef)(null);
|
|
2029
2244
|
latestConfigRef.current = normalizedConfig;
|
|
2030
|
-
const previousSerializedConfigRef =
|
|
2031
|
-
const targetAgentId =
|
|
2245
|
+
const previousSerializedConfigRef = (0, import_react15.useRef)(null);
|
|
2246
|
+
const targetAgentId = (0, import_react15.useMemo)(() => {
|
|
2032
2247
|
if (!normalizedConfig) {
|
|
2033
2248
|
return resolvedConsumerAgentId;
|
|
2034
2249
|
}
|
|
@@ -2039,7 +2254,7 @@ function useConfigureSuggestions(config, options) {
|
|
|
2039
2254
|
return consumer;
|
|
2040
2255
|
}, [normalizedConfig, resolvedConsumerAgentId]);
|
|
2041
2256
|
const isGlobalConfig = rawConsumerAgentId === void 0 || rawConsumerAgentId === "*";
|
|
2042
|
-
const requestReload =
|
|
2257
|
+
const requestReload = (0, import_react15.useCallback)(() => {
|
|
2043
2258
|
if (!normalizedConfig) {
|
|
2044
2259
|
return;
|
|
2045
2260
|
}
|
|
@@ -2061,7 +2276,7 @@ function useConfigureSuggestions(config, options) {
|
|
|
2061
2276
|
}
|
|
2062
2277
|
copilotkit.reloadSuggestions(targetAgentId);
|
|
2063
2278
|
}, [copilotkit, isGlobalConfig, normalizedConfig, targetAgentId]);
|
|
2064
|
-
|
|
2279
|
+
(0, import_react15.useEffect)(() => {
|
|
2065
2280
|
if (!serializedConfig || !latestConfigRef.current) {
|
|
2066
2281
|
return;
|
|
2067
2282
|
}
|
|
@@ -2071,7 +2286,7 @@ function useConfigureSuggestions(config, options) {
|
|
|
2071
2286
|
copilotkit.removeSuggestionsConfig(id);
|
|
2072
2287
|
};
|
|
2073
2288
|
}, [copilotkit, serializedConfig, requestReload]);
|
|
2074
|
-
|
|
2289
|
+
(0, import_react15.useEffect)(() => {
|
|
2075
2290
|
if (!normalizedConfig) {
|
|
2076
2291
|
previousSerializedConfigRef.current = null;
|
|
2077
2292
|
return;
|
|
@@ -2084,7 +2299,7 @@ function useConfigureSuggestions(config, options) {
|
|
|
2084
2299
|
}
|
|
2085
2300
|
requestReload();
|
|
2086
2301
|
}, [normalizedConfig, requestReload, serializedConfig]);
|
|
2087
|
-
|
|
2302
|
+
(0, import_react15.useEffect)(() => {
|
|
2088
2303
|
if (!normalizedConfig || extraDeps.length === 0) {
|
|
2089
2304
|
return;
|
|
2090
2305
|
}
|
|
@@ -2100,6 +2315,10 @@ function normalizeStaticSuggestions(suggestions) {
|
|
|
2100
2315
|
isLoading: suggestion.isLoading ?? false
|
|
2101
2316
|
}));
|
|
2102
2317
|
}
|
|
2318
|
+
|
|
2319
|
+
// src/components/chat/CopilotChatToolCallsView.tsx
|
|
2320
|
+
var import_react16 = __toESM(require("react"));
|
|
2321
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
2103
2322
|
function CopilotChatToolCallsView({
|
|
2104
2323
|
message,
|
|
2105
2324
|
messages = []
|
|
@@ -2108,17 +2327,20 @@ function CopilotChatToolCallsView({
|
|
|
2108
2327
|
if (!message.toolCalls || message.toolCalls.length === 0) {
|
|
2109
2328
|
return null;
|
|
2110
2329
|
}
|
|
2111
|
-
return /* @__PURE__ */
|
|
2330
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_jsx_runtime12.Fragment, { children: message.toolCalls.map((toolCall) => {
|
|
2112
2331
|
const toolMessage = messages.find(
|
|
2113
2332
|
(m) => m.role === "tool" && m.toolCallId === toolCall.id
|
|
2114
2333
|
);
|
|
2115
|
-
return /* @__PURE__ */
|
|
2334
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_react16.default.Fragment, { children: renderToolCall({
|
|
2116
2335
|
toolCall,
|
|
2117
2336
|
toolMessage
|
|
2118
2337
|
}) }, toolCall.id);
|
|
2119
2338
|
}) });
|
|
2120
2339
|
}
|
|
2121
2340
|
var CopilotChatToolCallsView_default = CopilotChatToolCallsView;
|
|
2341
|
+
|
|
2342
|
+
// src/components/chat/CopilotChatAssistantMessage.tsx
|
|
2343
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
2122
2344
|
function CopilotChatAssistantMessage({
|
|
2123
2345
|
message,
|
|
2124
2346
|
messages,
|
|
@@ -2195,7 +2417,7 @@ function CopilotChatAssistantMessage({
|
|
|
2195
2417
|
toolbar,
|
|
2196
2418
|
CopilotChatAssistantMessage.Toolbar,
|
|
2197
2419
|
{
|
|
2198
|
-
children: /* @__PURE__ */
|
|
2420
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "flex items-center gap-1", children: [
|
|
2199
2421
|
boundCopyButton,
|
|
2200
2422
|
(onThumbsUp || thumbsUpButton) && boundThumbsUpButton,
|
|
2201
2423
|
(onThumbsDown || thumbsDownButton) && boundThumbsDownButton,
|
|
@@ -2217,7 +2439,7 @@ function CopilotChatAssistantMessage({
|
|
|
2217
2439
|
const isLatestAssistantMessage = message.role === "assistant" && messages?.[messages.length - 1]?.id === message.id;
|
|
2218
2440
|
const shouldShowToolbar = toolbarVisible && hasContent && !(isRunning && isLatestAssistantMessage);
|
|
2219
2441
|
if (children) {
|
|
2220
|
-
return /* @__PURE__ */
|
|
2442
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_jsx_runtime13.Fragment, { children: children({
|
|
2221
2443
|
markdownRenderer: boundMarkdownRenderer,
|
|
2222
2444
|
toolbar: boundToolbar,
|
|
2223
2445
|
toolCallsView: boundToolCallsView,
|
|
@@ -2237,10 +2459,10 @@ function CopilotChatAssistantMessage({
|
|
|
2237
2459
|
toolbarVisible: shouldShowToolbar
|
|
2238
2460
|
}) });
|
|
2239
2461
|
}
|
|
2240
|
-
return /* @__PURE__ */
|
|
2462
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
|
|
2241
2463
|
"div",
|
|
2242
2464
|
{
|
|
2243
|
-
className:
|
|
2465
|
+
className: (0, import_tailwind_merge4.twMerge)(
|
|
2244
2466
|
"prose max-w-full break-words dark:prose-invert",
|
|
2245
2467
|
className
|
|
2246
2468
|
),
|
|
@@ -2255,14 +2477,14 @@ function CopilotChatAssistantMessage({
|
|
|
2255
2477
|
);
|
|
2256
2478
|
}
|
|
2257
2479
|
((CopilotChatAssistantMessage2) => {
|
|
2258
|
-
CopilotChatAssistantMessage2.MarkdownRenderer = ({ content, className, ...props }) => /* @__PURE__ */
|
|
2480
|
+
CopilotChatAssistantMessage2.MarkdownRenderer = ({ content, className, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_streamdown.Streamdown, { className, ...props, children: content ?? "" });
|
|
2259
2481
|
CopilotChatAssistantMessage2.Toolbar = ({
|
|
2260
2482
|
className,
|
|
2261
2483
|
...props
|
|
2262
|
-
}) => /* @__PURE__ */
|
|
2484
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
2263
2485
|
"div",
|
|
2264
2486
|
{
|
|
2265
|
-
className:
|
|
2487
|
+
className: (0, import_tailwind_merge4.twMerge)(
|
|
2266
2488
|
"w-full bg-transparent flex items-center -ml-[5px] -mt-[0px]",
|
|
2267
2489
|
className
|
|
2268
2490
|
),
|
|
@@ -2270,8 +2492,8 @@ function CopilotChatAssistantMessage({
|
|
|
2270
2492
|
}
|
|
2271
2493
|
);
|
|
2272
2494
|
CopilotChatAssistantMessage2.ToolbarButton = ({ title, children, ...props }) => {
|
|
2273
|
-
return /* @__PURE__ */
|
|
2274
|
-
/* @__PURE__ */
|
|
2495
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(Tooltip, { children: [
|
|
2496
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
2275
2497
|
Button,
|
|
2276
2498
|
{
|
|
2277
2499
|
type: "button",
|
|
@@ -2281,13 +2503,13 @@ function CopilotChatAssistantMessage({
|
|
|
2281
2503
|
children
|
|
2282
2504
|
}
|
|
2283
2505
|
) }),
|
|
2284
|
-
/* @__PURE__ */
|
|
2506
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(TooltipContent, { side: "bottom", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("p", { children: title }) })
|
|
2285
2507
|
] });
|
|
2286
2508
|
};
|
|
2287
2509
|
CopilotChatAssistantMessage2.CopyButton = ({ className, title, onClick, ...props }) => {
|
|
2288
2510
|
const config = useCopilotChatConfiguration();
|
|
2289
2511
|
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
2290
|
-
const [copied, setCopied] =
|
|
2512
|
+
const [copied, setCopied] = (0, import_react17.useState)(false);
|
|
2291
2513
|
const handleClick = (event) => {
|
|
2292
2514
|
setCopied(true);
|
|
2293
2515
|
setTimeout(() => setCopied(false), 2e3);
|
|
@@ -2295,62 +2517,62 @@ function CopilotChatAssistantMessage({
|
|
|
2295
2517
|
onClick(event);
|
|
2296
2518
|
}
|
|
2297
2519
|
};
|
|
2298
|
-
return /* @__PURE__ */
|
|
2520
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
2299
2521
|
CopilotChatAssistantMessage2.ToolbarButton,
|
|
2300
2522
|
{
|
|
2301
2523
|
title: title || labels.assistantMessageToolbarCopyMessageLabel,
|
|
2302
2524
|
onClick: handleClick,
|
|
2303
2525
|
className,
|
|
2304
2526
|
...props,
|
|
2305
|
-
children: copied ? /* @__PURE__ */
|
|
2527
|
+
children: copied ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_lucide_react3.Check, { className: "size-[18px]" }) : /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_lucide_react3.Copy, { className: "size-[18px]" })
|
|
2306
2528
|
}
|
|
2307
2529
|
);
|
|
2308
2530
|
};
|
|
2309
2531
|
CopilotChatAssistantMessage2.ThumbsUpButton = ({ title, ...props }) => {
|
|
2310
2532
|
const config = useCopilotChatConfiguration();
|
|
2311
2533
|
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
2312
|
-
return /* @__PURE__ */
|
|
2534
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
2313
2535
|
CopilotChatAssistantMessage2.ToolbarButton,
|
|
2314
2536
|
{
|
|
2315
2537
|
title: title || labels.assistantMessageToolbarThumbsUpLabel,
|
|
2316
2538
|
...props,
|
|
2317
|
-
children: /* @__PURE__ */
|
|
2539
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_lucide_react3.ThumbsUp, { className: "size-[18px]" })
|
|
2318
2540
|
}
|
|
2319
2541
|
);
|
|
2320
2542
|
};
|
|
2321
2543
|
CopilotChatAssistantMessage2.ThumbsDownButton = ({ title, ...props }) => {
|
|
2322
2544
|
const config = useCopilotChatConfiguration();
|
|
2323
2545
|
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
2324
|
-
return /* @__PURE__ */
|
|
2546
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
2325
2547
|
CopilotChatAssistantMessage2.ToolbarButton,
|
|
2326
2548
|
{
|
|
2327
2549
|
title: title || labels.assistantMessageToolbarThumbsDownLabel,
|
|
2328
2550
|
...props,
|
|
2329
|
-
children: /* @__PURE__ */
|
|
2551
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_lucide_react3.ThumbsDown, { className: "size-[18px]" })
|
|
2330
2552
|
}
|
|
2331
2553
|
);
|
|
2332
2554
|
};
|
|
2333
2555
|
CopilotChatAssistantMessage2.ReadAloudButton = ({ title, ...props }) => {
|
|
2334
2556
|
const config = useCopilotChatConfiguration();
|
|
2335
2557
|
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
2336
|
-
return /* @__PURE__ */
|
|
2558
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
2337
2559
|
CopilotChatAssistantMessage2.ToolbarButton,
|
|
2338
2560
|
{
|
|
2339
2561
|
title: title || labels.assistantMessageToolbarReadAloudLabel,
|
|
2340
2562
|
...props,
|
|
2341
|
-
children: /* @__PURE__ */
|
|
2563
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_lucide_react3.Volume2, { className: "size-[20px]" })
|
|
2342
2564
|
}
|
|
2343
2565
|
);
|
|
2344
2566
|
};
|
|
2345
2567
|
CopilotChatAssistantMessage2.RegenerateButton = ({ title, ...props }) => {
|
|
2346
2568
|
const config = useCopilotChatConfiguration();
|
|
2347
2569
|
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
2348
|
-
return /* @__PURE__ */
|
|
2570
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
2349
2571
|
CopilotChatAssistantMessage2.ToolbarButton,
|
|
2350
2572
|
{
|
|
2351
2573
|
title: title || labels.assistantMessageToolbarRegenerateLabel,
|
|
2352
2574
|
...props,
|
|
2353
|
-
children: /* @__PURE__ */
|
|
2575
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_lucide_react3.RefreshCw, { className: "size-[18px]" })
|
|
2354
2576
|
}
|
|
2355
2577
|
);
|
|
2356
2578
|
};
|
|
@@ -2363,6 +2585,12 @@ CopilotChatAssistantMessage.ThumbsDownButton.displayName = "CopilotChatAssistant
|
|
|
2363
2585
|
CopilotChatAssistantMessage.ReadAloudButton.displayName = "CopilotChatAssistantMessage.ReadAloudButton";
|
|
2364
2586
|
CopilotChatAssistantMessage.RegenerateButton.displayName = "CopilotChatAssistantMessage.RegenerateButton";
|
|
2365
2587
|
var CopilotChatAssistantMessage_default = CopilotChatAssistantMessage;
|
|
2588
|
+
|
|
2589
|
+
// src/components/chat/CopilotChatUserMessage.tsx
|
|
2590
|
+
var import_react18 = require("react");
|
|
2591
|
+
var import_lucide_react4 = require("lucide-react");
|
|
2592
|
+
var import_tailwind_merge5 = require("tailwind-merge");
|
|
2593
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
2366
2594
|
function flattenUserMessageContent(content) {
|
|
2367
2595
|
if (!content) {
|
|
2368
2596
|
return "";
|
|
@@ -2393,7 +2621,7 @@ function CopilotChatUserMessage({
|
|
|
2393
2621
|
className,
|
|
2394
2622
|
...props
|
|
2395
2623
|
}) {
|
|
2396
|
-
const flattenedContent =
|
|
2624
|
+
const flattenedContent = (0, import_react18.useMemo)(
|
|
2397
2625
|
() => flattenUserMessageContent(message.content),
|
|
2398
2626
|
[message.content]
|
|
2399
2627
|
);
|
|
@@ -2438,7 +2666,7 @@ function CopilotChatUserMessage({
|
|
|
2438
2666
|
);
|
|
2439
2667
|
const showBranchNavigation = numberOfBranches && numberOfBranches > 1 && onSwitchToBranch;
|
|
2440
2668
|
const BoundToolbar = renderSlot(toolbar, CopilotChatUserMessage.Toolbar, {
|
|
2441
|
-
children: /* @__PURE__ */
|
|
2669
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "flex items-center gap-1 justify-end", children: [
|
|
2442
2670
|
additionalToolbarItems,
|
|
2443
2671
|
BoundCopyButton,
|
|
2444
2672
|
onEditMessage && BoundEditButton,
|
|
@@ -2446,7 +2674,7 @@ function CopilotChatUserMessage({
|
|
|
2446
2674
|
] })
|
|
2447
2675
|
});
|
|
2448
2676
|
if (children) {
|
|
2449
|
-
return /* @__PURE__ */
|
|
2677
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_jsx_runtime14.Fragment, { children: children({
|
|
2450
2678
|
messageRenderer: BoundMessageRenderer,
|
|
2451
2679
|
toolbar: BoundToolbar,
|
|
2452
2680
|
copyButton: BoundCopyButton,
|
|
@@ -2458,10 +2686,10 @@ function CopilotChatUserMessage({
|
|
|
2458
2686
|
additionalToolbarItems
|
|
2459
2687
|
}) });
|
|
2460
2688
|
}
|
|
2461
|
-
return /* @__PURE__ */
|
|
2689
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
|
|
2462
2690
|
"div",
|
|
2463
2691
|
{
|
|
2464
|
-
className:
|
|
2692
|
+
className: (0, import_tailwind_merge5.twMerge)("flex flex-col items-end group pt-10", className),
|
|
2465
2693
|
"data-message-id": message.id,
|
|
2466
2694
|
...props,
|
|
2467
2695
|
children: [
|
|
@@ -2472,18 +2700,18 @@ function CopilotChatUserMessage({
|
|
|
2472
2700
|
);
|
|
2473
2701
|
}
|
|
2474
2702
|
((CopilotChatUserMessage2) => {
|
|
2475
|
-
CopilotChatUserMessage2.Container = ({ children, className, ...props }) => /* @__PURE__ */
|
|
2703
|
+
CopilotChatUserMessage2.Container = ({ children, className, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
2476
2704
|
"div",
|
|
2477
2705
|
{
|
|
2478
|
-
className:
|
|
2706
|
+
className: (0, import_tailwind_merge5.twMerge)("flex flex-col items-end group", className),
|
|
2479
2707
|
...props,
|
|
2480
2708
|
children
|
|
2481
2709
|
}
|
|
2482
2710
|
);
|
|
2483
|
-
CopilotChatUserMessage2.MessageRenderer = ({ content, className }) => /* @__PURE__ */
|
|
2711
|
+
CopilotChatUserMessage2.MessageRenderer = ({ content, className }) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
2484
2712
|
"div",
|
|
2485
2713
|
{
|
|
2486
|
-
className:
|
|
2714
|
+
className: (0, import_tailwind_merge5.twMerge)(
|
|
2487
2715
|
"prose dark:prose-invert bg-muted relative max-w-[80%] rounded-[18px] px-4 py-1.5 data-[multiline]:py-3 inline-block whitespace-pre-wrap",
|
|
2488
2716
|
className
|
|
2489
2717
|
),
|
|
@@ -2493,10 +2721,10 @@ function CopilotChatUserMessage({
|
|
|
2493
2721
|
CopilotChatUserMessage2.Toolbar = ({
|
|
2494
2722
|
className,
|
|
2495
2723
|
...props
|
|
2496
|
-
}) => /* @__PURE__ */
|
|
2724
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
2497
2725
|
"div",
|
|
2498
2726
|
{
|
|
2499
|
-
className:
|
|
2727
|
+
className: (0, import_tailwind_merge5.twMerge)(
|
|
2500
2728
|
"w-full bg-transparent flex items-center justify-end -mr-[5px] mt-[4px] invisible group-hover:visible",
|
|
2501
2729
|
className
|
|
2502
2730
|
),
|
|
@@ -2504,25 +2732,25 @@ function CopilotChatUserMessage({
|
|
|
2504
2732
|
}
|
|
2505
2733
|
);
|
|
2506
2734
|
CopilotChatUserMessage2.ToolbarButton = ({ title, children, className, ...props }) => {
|
|
2507
|
-
return /* @__PURE__ */
|
|
2508
|
-
/* @__PURE__ */
|
|
2735
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(Tooltip, { children: [
|
|
2736
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
2509
2737
|
Button,
|
|
2510
2738
|
{
|
|
2511
2739
|
type: "button",
|
|
2512
2740
|
variant: "assistantMessageToolbarButton",
|
|
2513
2741
|
"aria-label": title,
|
|
2514
|
-
className:
|
|
2742
|
+
className: (0, import_tailwind_merge5.twMerge)(className),
|
|
2515
2743
|
...props,
|
|
2516
2744
|
children
|
|
2517
2745
|
}
|
|
2518
2746
|
) }),
|
|
2519
|
-
/* @__PURE__ */
|
|
2747
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(TooltipContent, { side: "bottom", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("p", { children: title }) })
|
|
2520
2748
|
] });
|
|
2521
2749
|
};
|
|
2522
2750
|
CopilotChatUserMessage2.CopyButton = ({ className, title, onClick, ...props }) => {
|
|
2523
2751
|
const config = useCopilotChatConfiguration();
|
|
2524
2752
|
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
2525
|
-
const [copied, setCopied] =
|
|
2753
|
+
const [copied, setCopied] = (0, import_react18.useState)(false);
|
|
2526
2754
|
const handleClick = (event) => {
|
|
2527
2755
|
setCopied(true);
|
|
2528
2756
|
setTimeout(() => setCopied(false), 2e3);
|
|
@@ -2530,27 +2758,27 @@ function CopilotChatUserMessage({
|
|
|
2530
2758
|
onClick(event);
|
|
2531
2759
|
}
|
|
2532
2760
|
};
|
|
2533
|
-
return /* @__PURE__ */
|
|
2761
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
2534
2762
|
CopilotChatUserMessage2.ToolbarButton,
|
|
2535
2763
|
{
|
|
2536
2764
|
title: title || labels.userMessageToolbarCopyMessageLabel,
|
|
2537
2765
|
onClick: handleClick,
|
|
2538
2766
|
className,
|
|
2539
2767
|
...props,
|
|
2540
|
-
children: copied ? /* @__PURE__ */
|
|
2768
|
+
children: copied ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_lucide_react4.Check, { className: "size-[18px]" }) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_lucide_react4.Copy, { className: "size-[18px]" })
|
|
2541
2769
|
}
|
|
2542
2770
|
);
|
|
2543
2771
|
};
|
|
2544
2772
|
CopilotChatUserMessage2.EditButton = ({ className, title, ...props }) => {
|
|
2545
2773
|
const config = useCopilotChatConfiguration();
|
|
2546
2774
|
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
2547
|
-
return /* @__PURE__ */
|
|
2775
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
2548
2776
|
CopilotChatUserMessage2.ToolbarButton,
|
|
2549
2777
|
{
|
|
2550
2778
|
title: title || labels.userMessageToolbarEditMessageLabel,
|
|
2551
2779
|
className,
|
|
2552
2780
|
...props,
|
|
2553
|
-
children: /* @__PURE__ */
|
|
2781
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_lucide_react4.Edit, { className: "size-[18px]" })
|
|
2554
2782
|
}
|
|
2555
2783
|
);
|
|
2556
2784
|
};
|
|
@@ -2567,8 +2795,8 @@ function CopilotChatUserMessage({
|
|
|
2567
2795
|
}
|
|
2568
2796
|
const canGoPrev = currentBranch > 0;
|
|
2569
2797
|
const canGoNext = currentBranch < numberOfBranches - 1;
|
|
2570
|
-
return /* @__PURE__ */
|
|
2571
|
-
/* @__PURE__ */
|
|
2798
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: (0, import_tailwind_merge5.twMerge)("flex items-center gap-1", className), ...props, children: [
|
|
2799
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
2572
2800
|
Button,
|
|
2573
2801
|
{
|
|
2574
2802
|
type: "button",
|
|
@@ -2580,15 +2808,15 @@ function CopilotChatUserMessage({
|
|
|
2580
2808
|
}),
|
|
2581
2809
|
disabled: !canGoPrev,
|
|
2582
2810
|
className: "h-6 w-6 p-0",
|
|
2583
|
-
children: /* @__PURE__ */
|
|
2811
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_lucide_react4.ChevronLeft, { className: "size-[20px]" })
|
|
2584
2812
|
}
|
|
2585
2813
|
),
|
|
2586
|
-
/* @__PURE__ */
|
|
2814
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("span", { className: "text-sm text-muted-foreground px-0 font-medium", children: [
|
|
2587
2815
|
currentBranch + 1,
|
|
2588
2816
|
"/",
|
|
2589
2817
|
numberOfBranches
|
|
2590
2818
|
] }),
|
|
2591
|
-
/* @__PURE__ */
|
|
2819
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
2592
2820
|
Button,
|
|
2593
2821
|
{
|
|
2594
2822
|
type: "button",
|
|
@@ -2600,7 +2828,7 @@ function CopilotChatUserMessage({
|
|
|
2600
2828
|
}),
|
|
2601
2829
|
disabled: !canGoNext,
|
|
2602
2830
|
className: "h-6 w-6 p-0",
|
|
2603
|
-
children: /* @__PURE__ */
|
|
2831
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_lucide_react4.ChevronRight, { className: "size-[20px]" })
|
|
2604
2832
|
}
|
|
2605
2833
|
)
|
|
2606
2834
|
] });
|
|
@@ -2614,11 +2842,16 @@ CopilotChatUserMessage.CopyButton.displayName = "CopilotChatUserMessage.CopyButt
|
|
|
2614
2842
|
CopilotChatUserMessage.EditButton.displayName = "CopilotChatUserMessage.EditButton";
|
|
2615
2843
|
CopilotChatUserMessage.BranchNavigation.displayName = "CopilotChatUserMessage.BranchNavigation";
|
|
2616
2844
|
var CopilotChatUserMessage_default = CopilotChatUserMessage;
|
|
2845
|
+
|
|
2846
|
+
// src/components/chat/CopilotChatSuggestionPill.tsx
|
|
2847
|
+
var import_react19 = __toESM(require("react"));
|
|
2848
|
+
var import_lucide_react5 = require("lucide-react");
|
|
2849
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
2617
2850
|
var baseClasses = "group inline-flex h-7 sm:h-8 items-center gap-1 sm:gap-1.5 rounded-full border border-border/60 bg-background px-2.5 sm:px-3 text-[11px] sm:text-xs leading-none text-foreground transition-colors cursor-pointer hover:bg-accent/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:text-muted-foreground disabled:hover:bg-background disabled:hover:text-muted-foreground pointer-events-auto";
|
|
2618
2851
|
var labelClasses = "whitespace-nowrap font-medium leading-none";
|
|
2619
|
-
var CopilotChatSuggestionPill =
|
|
2852
|
+
var CopilotChatSuggestionPill = import_react19.default.forwardRef(function CopilotChatSuggestionPill2({ className, children, icon, isLoading, type, ...props }, ref) {
|
|
2620
2853
|
const showIcon = !isLoading && icon;
|
|
2621
|
-
return /* @__PURE__ */
|
|
2854
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
|
|
2622
2855
|
"button",
|
|
2623
2856
|
{
|
|
2624
2857
|
ref,
|
|
@@ -2629,16 +2862,20 @@ var CopilotChatSuggestionPill = React2__namespace.default.forwardRef(function Co
|
|
|
2629
2862
|
disabled: isLoading || props.disabled,
|
|
2630
2863
|
...props,
|
|
2631
2864
|
children: [
|
|
2632
|
-
isLoading ? /* @__PURE__ */
|
|
2633
|
-
/* @__PURE__ */
|
|
2865
|
+
isLoading ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "flex h-3.5 sm:h-4 w-3.5 sm:w-4 items-center justify-center text-muted-foreground", children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_lucide_react5.Loader2, { className: "h-3.5 sm:h-4 w-3.5 sm:w-4 animate-spin", "aria-hidden": "true" }) }) : showIcon && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "flex h-3.5 sm:h-4 w-3.5 sm:w-4 items-center justify-center text-muted-foreground", children: icon }),
|
|
2866
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: labelClasses, children })
|
|
2634
2867
|
]
|
|
2635
2868
|
}
|
|
2636
2869
|
);
|
|
2637
2870
|
});
|
|
2638
2871
|
CopilotChatSuggestionPill.displayName = "CopilotChatSuggestionPill";
|
|
2639
2872
|
var CopilotChatSuggestionPill_default = CopilotChatSuggestionPill;
|
|
2640
|
-
|
|
2641
|
-
|
|
2873
|
+
|
|
2874
|
+
// src/components/chat/CopilotChatSuggestionView.tsx
|
|
2875
|
+
var import_react20 = __toESM(require("react"));
|
|
2876
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
2877
|
+
var DefaultContainer = import_react20.default.forwardRef(function DefaultContainer2({ className, ...props }, ref) {
|
|
2878
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
2642
2879
|
"div",
|
|
2643
2880
|
{
|
|
2644
2881
|
ref,
|
|
@@ -2650,7 +2887,7 @@ var DefaultContainer = React2__namespace.default.forwardRef(function DefaultCont
|
|
|
2650
2887
|
}
|
|
2651
2888
|
);
|
|
2652
2889
|
});
|
|
2653
|
-
var CopilotChatSuggestionView =
|
|
2890
|
+
var CopilotChatSuggestionView = import_react20.default.forwardRef(function CopilotChatSuggestionView2({
|
|
2654
2891
|
suggestions,
|
|
2655
2892
|
onSelectSuggestion,
|
|
2656
2893
|
loadingIndexes,
|
|
@@ -2660,7 +2897,7 @@ var CopilotChatSuggestionView = React2__namespace.default.forwardRef(function Co
|
|
|
2660
2897
|
children,
|
|
2661
2898
|
...restProps
|
|
2662
2899
|
}, ref) {
|
|
2663
|
-
const loadingSet =
|
|
2900
|
+
const loadingSet = import_react20.default.useMemo(() => {
|
|
2664
2901
|
if (!loadingIndexes || loadingIndexes.length === 0) {
|
|
2665
2902
|
return /* @__PURE__ */ new Set();
|
|
2666
2903
|
}
|
|
@@ -2679,11 +2916,11 @@ var CopilotChatSuggestionView = React2__namespace.default.forwardRef(function Co
|
|
|
2679
2916
|
type: "button",
|
|
2680
2917
|
onClick: () => onSelectSuggestion?.(suggestion, index)
|
|
2681
2918
|
});
|
|
2682
|
-
return
|
|
2919
|
+
return import_react20.default.cloneElement(pill, {
|
|
2683
2920
|
key: `${suggestion.title}-${index}`
|
|
2684
2921
|
});
|
|
2685
2922
|
});
|
|
2686
|
-
const boundContainer =
|
|
2923
|
+
const boundContainer = import_react20.default.cloneElement(
|
|
2687
2924
|
ContainerElement,
|
|
2688
2925
|
void 0,
|
|
2689
2926
|
suggestionElements
|
|
@@ -2694,7 +2931,7 @@ var CopilotChatSuggestionView = React2__namespace.default.forwardRef(function Co
|
|
|
2694
2931
|
isLoading: suggestions.length > 0 ? loadingSet.has(0) || suggestions[0]?.isLoading === true : false,
|
|
2695
2932
|
type: "button"
|
|
2696
2933
|
});
|
|
2697
|
-
return /* @__PURE__ */
|
|
2934
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_jsx_runtime16.Fragment, { children: children({
|
|
2698
2935
|
container: boundContainer,
|
|
2699
2936
|
suggestion: sampleSuggestion,
|
|
2700
2937
|
suggestions,
|
|
@@ -2705,7 +2942,7 @@ var CopilotChatSuggestionView = React2__namespace.default.forwardRef(function Co
|
|
|
2705
2942
|
}) });
|
|
2706
2943
|
}
|
|
2707
2944
|
if (children) {
|
|
2708
|
-
return /* @__PURE__ */
|
|
2945
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_jsx_runtime16.Fragment, { children: [
|
|
2709
2946
|
boundContainer,
|
|
2710
2947
|
children
|
|
2711
2948
|
] });
|
|
@@ -2714,6 +2951,105 @@ var CopilotChatSuggestionView = React2__namespace.default.forwardRef(function Co
|
|
|
2714
2951
|
});
|
|
2715
2952
|
CopilotChatSuggestionView.displayName = "CopilotChatSuggestionView";
|
|
2716
2953
|
var CopilotChatSuggestionView_default = CopilotChatSuggestionView;
|
|
2954
|
+
|
|
2955
|
+
// src/components/chat/CopilotChatMessageView.tsx
|
|
2956
|
+
var import_react21 = __toESM(require("react"));
|
|
2957
|
+
var import_tailwind_merge6 = require("tailwind-merge");
|
|
2958
|
+
var import_jsx_runtime17 = require("react/jsx-runtime");
|
|
2959
|
+
var MemoizedAssistantMessage = import_react21.default.memo(
|
|
2960
|
+
function MemoizedAssistantMessage2({
|
|
2961
|
+
message,
|
|
2962
|
+
messages,
|
|
2963
|
+
isRunning,
|
|
2964
|
+
AssistantMessageComponent
|
|
2965
|
+
}) {
|
|
2966
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
2967
|
+
AssistantMessageComponent,
|
|
2968
|
+
{
|
|
2969
|
+
message,
|
|
2970
|
+
messages,
|
|
2971
|
+
isRunning
|
|
2972
|
+
}
|
|
2973
|
+
);
|
|
2974
|
+
},
|
|
2975
|
+
(prevProps, nextProps) => {
|
|
2976
|
+
if (prevProps.message.id !== nextProps.message.id) return false;
|
|
2977
|
+
if (prevProps.message.content !== nextProps.message.content) return false;
|
|
2978
|
+
const prevToolCalls = prevProps.message.toolCalls;
|
|
2979
|
+
const nextToolCalls = nextProps.message.toolCalls;
|
|
2980
|
+
if (prevToolCalls?.length !== nextToolCalls?.length) return false;
|
|
2981
|
+
if (prevToolCalls && nextToolCalls) {
|
|
2982
|
+
for (let i = 0; i < prevToolCalls.length; i++) {
|
|
2983
|
+
const prevTc = prevToolCalls[i];
|
|
2984
|
+
const nextTc = nextToolCalls[i];
|
|
2985
|
+
if (!prevTc || !nextTc) return false;
|
|
2986
|
+
if (prevTc.id !== nextTc.id) return false;
|
|
2987
|
+
if (prevTc.function.arguments !== nextTc.function.arguments) return false;
|
|
2988
|
+
}
|
|
2989
|
+
}
|
|
2990
|
+
if (prevToolCalls && prevToolCalls.length > 0) {
|
|
2991
|
+
const toolCallIds = new Set(prevToolCalls.map((tc) => tc.id));
|
|
2992
|
+
const prevToolResults = prevProps.messages.filter(
|
|
2993
|
+
(m) => m.role === "tool" && toolCallIds.has(m.toolCallId)
|
|
2994
|
+
);
|
|
2995
|
+
const nextToolResults = nextProps.messages.filter(
|
|
2996
|
+
(m) => m.role === "tool" && toolCallIds.has(m.toolCallId)
|
|
2997
|
+
);
|
|
2998
|
+
if (prevToolResults.length !== nextToolResults.length) return false;
|
|
2999
|
+
for (let i = 0; i < prevToolResults.length; i++) {
|
|
3000
|
+
if (prevToolResults[i].content !== nextToolResults[i].content) return false;
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
const nextIsLatest = nextProps.messages[nextProps.messages.length - 1]?.id === nextProps.message.id;
|
|
3004
|
+
if (nextIsLatest && prevProps.isRunning !== nextProps.isRunning) return false;
|
|
3005
|
+
if (prevProps.AssistantMessageComponent !== nextProps.AssistantMessageComponent) return false;
|
|
3006
|
+
return true;
|
|
3007
|
+
}
|
|
3008
|
+
);
|
|
3009
|
+
var MemoizedUserMessage = import_react21.default.memo(
|
|
3010
|
+
function MemoizedUserMessage2({
|
|
3011
|
+
message,
|
|
3012
|
+
UserMessageComponent
|
|
3013
|
+
}) {
|
|
3014
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(UserMessageComponent, { message });
|
|
3015
|
+
},
|
|
3016
|
+
(prevProps, nextProps) => {
|
|
3017
|
+
if (prevProps.message.id !== nextProps.message.id) return false;
|
|
3018
|
+
if (prevProps.message.content !== nextProps.message.content) return false;
|
|
3019
|
+
if (prevProps.UserMessageComponent !== nextProps.UserMessageComponent) return false;
|
|
3020
|
+
return true;
|
|
3021
|
+
}
|
|
3022
|
+
);
|
|
3023
|
+
var MemoizedActivityMessage = import_react21.default.memo(
|
|
3024
|
+
function MemoizedActivityMessage2({
|
|
3025
|
+
message,
|
|
3026
|
+
renderActivityMessage
|
|
3027
|
+
}) {
|
|
3028
|
+
return renderActivityMessage(message);
|
|
3029
|
+
},
|
|
3030
|
+
(prevProps, nextProps) => {
|
|
3031
|
+
if (prevProps.message.id !== nextProps.message.id) return false;
|
|
3032
|
+
if (prevProps.message.activityType !== nextProps.message.activityType) return false;
|
|
3033
|
+
if (JSON.stringify(prevProps.message.content) !== JSON.stringify(nextProps.message.content)) return false;
|
|
3034
|
+
return true;
|
|
3035
|
+
}
|
|
3036
|
+
);
|
|
3037
|
+
var MemoizedCustomMessage = import_react21.default.memo(
|
|
3038
|
+
function MemoizedCustomMessage2({
|
|
3039
|
+
message,
|
|
3040
|
+
position,
|
|
3041
|
+
renderCustomMessage
|
|
3042
|
+
}) {
|
|
3043
|
+
return renderCustomMessage({ message, position });
|
|
3044
|
+
},
|
|
3045
|
+
(prevProps, nextProps) => {
|
|
3046
|
+
if (prevProps.message.id !== nextProps.message.id) return false;
|
|
3047
|
+
if (prevProps.position !== nextProps.position) return false;
|
|
3048
|
+
if (prevProps.message.content !== nextProps.message.content) return false;
|
|
3049
|
+
if (prevProps.message.role !== nextProps.message.role) return false;
|
|
3050
|
+
return true;
|
|
3051
|
+
}
|
|
3052
|
+
);
|
|
2717
3053
|
function CopilotChatMessageView({
|
|
2718
3054
|
messages = [],
|
|
2719
3055
|
assistantMessage,
|
|
@@ -2730,40 +3066,66 @@ function CopilotChatMessageView({
|
|
|
2730
3066
|
const elements = [];
|
|
2731
3067
|
if (renderCustomMessage) {
|
|
2732
3068
|
elements.push(
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
3069
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
3070
|
+
MemoizedCustomMessage,
|
|
3071
|
+
{
|
|
3072
|
+
message,
|
|
3073
|
+
position: "before",
|
|
3074
|
+
renderCustomMessage
|
|
3075
|
+
},
|
|
3076
|
+
`${message.id}-custom-before`
|
|
3077
|
+
)
|
|
2737
3078
|
);
|
|
2738
3079
|
}
|
|
2739
3080
|
if (message.role === "assistant") {
|
|
3081
|
+
const AssistantComponent = typeof assistantMessage === "function" ? assistantMessage : CopilotChatAssistantMessage_default;
|
|
2740
3082
|
elements.push(
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
3083
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
3084
|
+
MemoizedAssistantMessage,
|
|
3085
|
+
{
|
|
3086
|
+
message,
|
|
3087
|
+
messages,
|
|
3088
|
+
isRunning,
|
|
3089
|
+
AssistantMessageComponent: AssistantComponent
|
|
3090
|
+
},
|
|
3091
|
+
message.id
|
|
3092
|
+
)
|
|
2747
3093
|
);
|
|
2748
3094
|
} else if (message.role === "user") {
|
|
3095
|
+
const UserComponent = typeof userMessage === "function" ? userMessage : CopilotChatUserMessage_default;
|
|
2749
3096
|
elements.push(
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
3097
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
3098
|
+
MemoizedUserMessage,
|
|
3099
|
+
{
|
|
3100
|
+
message,
|
|
3101
|
+
UserMessageComponent: UserComponent
|
|
3102
|
+
},
|
|
3103
|
+
message.id
|
|
3104
|
+
)
|
|
2754
3105
|
);
|
|
2755
3106
|
} else if (message.role === "activity") {
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
3107
|
+
elements.push(
|
|
3108
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
3109
|
+
MemoizedActivityMessage,
|
|
3110
|
+
{
|
|
3111
|
+
message,
|
|
3112
|
+
renderActivityMessage
|
|
3113
|
+
},
|
|
3114
|
+
message.id
|
|
3115
|
+
)
|
|
3116
|
+
);
|
|
2760
3117
|
}
|
|
2761
3118
|
if (renderCustomMessage) {
|
|
2762
3119
|
elements.push(
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
3120
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
3121
|
+
MemoizedCustomMessage,
|
|
3122
|
+
{
|
|
3123
|
+
message,
|
|
3124
|
+
position: "after",
|
|
3125
|
+
renderCustomMessage
|
|
3126
|
+
},
|
|
3127
|
+
`${message.id}-custom-after`
|
|
3128
|
+
)
|
|
2767
3129
|
);
|
|
2768
3130
|
}
|
|
2769
3131
|
return elements;
|
|
@@ -2771,29 +3133,38 @@ function CopilotChatMessageView({
|
|
|
2771
3133
|
if (children) {
|
|
2772
3134
|
return children({ messageElements, messages, isRunning });
|
|
2773
3135
|
}
|
|
2774
|
-
return /* @__PURE__ */
|
|
3136
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: (0, import_tailwind_merge6.twMerge)("flex flex-col", className), ...props, children: [
|
|
2775
3137
|
messageElements,
|
|
2776
3138
|
isRunning && renderSlot(cursor, CopilotChatMessageView.Cursor, {})
|
|
2777
3139
|
] });
|
|
2778
3140
|
}
|
|
2779
3141
|
CopilotChatMessageView.Cursor = function Cursor({ className, ...props }) {
|
|
2780
|
-
return /* @__PURE__ */
|
|
3142
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
2781
3143
|
"div",
|
|
2782
3144
|
{
|
|
2783
|
-
className:
|
|
3145
|
+
className: (0, import_tailwind_merge6.twMerge)("w-[11px] h-[11px] rounded-full bg-foreground animate-pulse-cursor ml-1", className),
|
|
2784
3146
|
...props
|
|
2785
3147
|
}
|
|
2786
3148
|
);
|
|
2787
3149
|
};
|
|
2788
3150
|
var CopilotChatMessageView_default = CopilotChatMessageView;
|
|
3151
|
+
|
|
3152
|
+
// src/components/chat/CopilotChatView.tsx
|
|
3153
|
+
var import_react23 = __toESM(require("react"));
|
|
3154
|
+
var import_tailwind_merge7 = require("tailwind-merge");
|
|
3155
|
+
var import_use_stick_to_bottom = require("use-stick-to-bottom");
|
|
3156
|
+
var import_lucide_react6 = require("lucide-react");
|
|
3157
|
+
|
|
3158
|
+
// src/hooks/use-keyboard-height.tsx
|
|
3159
|
+
var import_react22 = require("react");
|
|
2789
3160
|
function useKeyboardHeight() {
|
|
2790
|
-
const [keyboardState, setKeyboardState] =
|
|
3161
|
+
const [keyboardState, setKeyboardState] = (0, import_react22.useState)({
|
|
2791
3162
|
isKeyboardOpen: false,
|
|
2792
3163
|
keyboardHeight: 0,
|
|
2793
3164
|
availableHeight: typeof window !== "undefined" ? window.innerHeight : 0,
|
|
2794
3165
|
viewportHeight: typeof window !== "undefined" ? window.innerHeight : 0
|
|
2795
3166
|
});
|
|
2796
|
-
|
|
3167
|
+
(0, import_react22.useEffect)(() => {
|
|
2797
3168
|
if (typeof window === "undefined") {
|
|
2798
3169
|
return;
|
|
2799
3170
|
}
|
|
@@ -2823,6 +3194,9 @@ function useKeyboardHeight() {
|
|
|
2823
3194
|
}, []);
|
|
2824
3195
|
return keyboardState;
|
|
2825
3196
|
}
|
|
3197
|
+
|
|
3198
|
+
// src/components/chat/CopilotChatView.tsx
|
|
3199
|
+
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
2826
3200
|
function CopilotChatView({
|
|
2827
3201
|
messageView,
|
|
2828
3202
|
input,
|
|
@@ -2843,12 +3217,12 @@ function CopilotChatView({
|
|
|
2843
3217
|
className,
|
|
2844
3218
|
...props
|
|
2845
3219
|
}) {
|
|
2846
|
-
const inputContainerRef =
|
|
2847
|
-
const [inputContainerHeight, setInputContainerHeight] =
|
|
2848
|
-
const [isResizing, setIsResizing] =
|
|
2849
|
-
const resizeTimeoutRef =
|
|
3220
|
+
const inputContainerRef = (0, import_react23.useRef)(null);
|
|
3221
|
+
const [inputContainerHeight, setInputContainerHeight] = (0, import_react23.useState)(0);
|
|
3222
|
+
const [isResizing, setIsResizing] = (0, import_react23.useState)(false);
|
|
3223
|
+
const resizeTimeoutRef = (0, import_react23.useRef)(null);
|
|
2850
3224
|
const { isKeyboardOpen, keyboardHeight, availableHeight } = useKeyboardHeight();
|
|
2851
|
-
|
|
3225
|
+
(0, import_react23.useEffect)(() => {
|
|
2852
3226
|
const element = inputContainerRef.current;
|
|
2853
3227
|
if (!element) return;
|
|
2854
3228
|
const resizeObserver = new ResizeObserver((entries) => {
|
|
@@ -2884,25 +3258,21 @@ function CopilotChatView({
|
|
|
2884
3258
|
});
|
|
2885
3259
|
const BoundInput = renderSlot(input, CopilotChatInput_default, inputProps ?? {});
|
|
2886
3260
|
const hasSuggestions = Array.isArray(suggestions) && suggestions.length > 0;
|
|
2887
|
-
const BoundSuggestionView = hasSuggestions ? renderSlot(
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
onSelectSuggestion,
|
|
2894
|
-
className: "mb-3 lg:ml-4 lg:mr-4 ml-0 mr-0"
|
|
2895
|
-
}
|
|
2896
|
-
) : null;
|
|
3261
|
+
const BoundSuggestionView = hasSuggestions ? renderSlot(suggestionView, CopilotChatSuggestionView_default, {
|
|
3262
|
+
suggestions,
|
|
3263
|
+
loadingIndexes: suggestionLoadingIndexes,
|
|
3264
|
+
onSelectSuggestion,
|
|
3265
|
+
className: "mb-3 lg:ml-4 lg:mr-4 ml-0 mr-0"
|
|
3266
|
+
}) : null;
|
|
2897
3267
|
const BoundFeather = renderSlot(feather, CopilotChatView.Feather, {});
|
|
2898
3268
|
const BoundScrollView = renderSlot(scrollView, CopilotChatView.ScrollView, {
|
|
2899
3269
|
autoScroll,
|
|
2900
3270
|
scrollToBottomButton,
|
|
2901
3271
|
inputContainerHeight,
|
|
2902
3272
|
isResizing,
|
|
2903
|
-
children: /* @__PURE__ */
|
|
3273
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { style: { paddingBottom: `${inputContainerHeight + (hasSuggestions ? 4 : 32)}px` }, children: /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "max-w-3xl mx-auto", children: [
|
|
2904
3274
|
BoundMessageView,
|
|
2905
|
-
hasSuggestions ? /* @__PURE__ */
|
|
3275
|
+
hasSuggestions ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "pl-0 pr-4 sm:px-0 mt-4", children: BoundSuggestionView }) : null
|
|
2906
3276
|
] }) })
|
|
2907
3277
|
});
|
|
2908
3278
|
const BoundScrollToBottomButton = renderSlot(scrollToBottomButton, CopilotChatView.ScrollToBottomButton, {});
|
|
@@ -2910,8 +3280,8 @@ function CopilotChatView({
|
|
|
2910
3280
|
const BoundInputContainer = renderSlot(inputContainer, CopilotChatView.InputContainer, {
|
|
2911
3281
|
ref: inputContainerRef,
|
|
2912
3282
|
keyboardHeight: isKeyboardOpen ? keyboardHeight : 0,
|
|
2913
|
-
children: /* @__PURE__ */
|
|
2914
|
-
/* @__PURE__ */
|
|
3283
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [
|
|
3284
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "max-w-3xl mx-auto py-0 px-4 sm:px-0 [div[data-sidebar-chat]_&]:px-8 [div[data-popup-chat]_&]:px-6 pointer-events-auto", children: BoundInput }),
|
|
2915
3285
|
BoundDisclaimer
|
|
2916
3286
|
] })
|
|
2917
3287
|
});
|
|
@@ -2924,10 +3294,10 @@ function CopilotChatView({
|
|
|
2924
3294
|
feather: BoundFeather,
|
|
2925
3295
|
inputContainer: BoundInputContainer,
|
|
2926
3296
|
disclaimer: BoundDisclaimer,
|
|
2927
|
-
suggestionView: BoundSuggestionView ?? /* @__PURE__ */
|
|
3297
|
+
suggestionView: BoundSuggestionView ?? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_jsx_runtime18.Fragment, {})
|
|
2928
3298
|
});
|
|
2929
3299
|
}
|
|
2930
|
-
return /* @__PURE__ */
|
|
3300
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: (0, import_tailwind_merge7.twMerge)("relative h-full", className), ...props, children: [
|
|
2931
3301
|
BoundScrollView,
|
|
2932
3302
|
BoundFeather,
|
|
2933
3303
|
BoundInputContainer
|
|
@@ -2935,10 +3305,10 @@ function CopilotChatView({
|
|
|
2935
3305
|
}
|
|
2936
3306
|
((CopilotChatView2) => {
|
|
2937
3307
|
const ScrollContent = ({ children, scrollToBottomButton, inputContainerHeight, isResizing }) => {
|
|
2938
|
-
const { isAtBottom, scrollToBottom } =
|
|
2939
|
-
return /* @__PURE__ */
|
|
2940
|
-
/* @__PURE__ */
|
|
2941
|
-
!isAtBottom && !isResizing && /* @__PURE__ */
|
|
3308
|
+
const { isAtBottom, scrollToBottom } = (0, import_use_stick_to_bottom.useStickToBottomContext)();
|
|
3309
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [
|
|
3310
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_use_stick_to_bottom.StickToBottom.Content, { className: "overflow-y-scroll overflow-x-hidden", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "px-4 sm:px-0 [div[data-sidebar-chat]_&]:px-8 [div[data-popup-chat]_&]:px-6", children }) }),
|
|
3311
|
+
!isAtBottom && !isResizing && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
2942
3312
|
"div",
|
|
2943
3313
|
{
|
|
2944
3314
|
className: "absolute inset-x-0 flex justify-center z-10 pointer-events-none",
|
|
@@ -2961,13 +3331,13 @@ function CopilotChatView({
|
|
|
2961
3331
|
className,
|
|
2962
3332
|
...props
|
|
2963
3333
|
}) => {
|
|
2964
|
-
const [hasMounted, setHasMounted] =
|
|
2965
|
-
const { scrollRef, contentRef, scrollToBottom } =
|
|
2966
|
-
const [showScrollButton, setShowScrollButton] =
|
|
2967
|
-
|
|
3334
|
+
const [hasMounted, setHasMounted] = (0, import_react23.useState)(false);
|
|
3335
|
+
const { scrollRef, contentRef, scrollToBottom } = (0, import_use_stick_to_bottom.useStickToBottom)();
|
|
3336
|
+
const [showScrollButton, setShowScrollButton] = (0, import_react23.useState)(false);
|
|
3337
|
+
(0, import_react23.useEffect)(() => {
|
|
2968
3338
|
setHasMounted(true);
|
|
2969
3339
|
}, []);
|
|
2970
|
-
|
|
3340
|
+
(0, import_react23.useEffect)(() => {
|
|
2971
3341
|
if (autoScroll) return;
|
|
2972
3342
|
const scrollElement = scrollRef.current;
|
|
2973
3343
|
if (!scrollElement) return;
|
|
@@ -2985,10 +3355,10 @@ function CopilotChatView({
|
|
|
2985
3355
|
};
|
|
2986
3356
|
}, [scrollRef, autoScroll]);
|
|
2987
3357
|
if (!hasMounted) {
|
|
2988
|
-
return /* @__PURE__ */
|
|
3358
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "h-full max-h-full flex flex-col min-h-0 overflow-y-scroll overflow-x-hidden", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "px-4 sm:px-0 [div[data-sidebar-chat]_&]:px-8 [div[data-popup-chat]_&]:px-6", children }) });
|
|
2989
3359
|
}
|
|
2990
3360
|
if (!autoScroll) {
|
|
2991
|
-
return /* @__PURE__ */
|
|
3361
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(
|
|
2992
3362
|
"div",
|
|
2993
3363
|
{
|
|
2994
3364
|
ref: scrollRef,
|
|
@@ -2998,8 +3368,8 @@ function CopilotChatView({
|
|
|
2998
3368
|
),
|
|
2999
3369
|
...props,
|
|
3000
3370
|
children: [
|
|
3001
|
-
/* @__PURE__ */
|
|
3002
|
-
showScrollButton && !isResizing && /* @__PURE__ */
|
|
3371
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { ref: contentRef, className: "px-4 sm:px-0 [div[data-sidebar-chat]_&]:px-8 [div[data-popup-chat]_&]:px-6", children }),
|
|
3372
|
+
showScrollButton && !isResizing && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
3003
3373
|
"div",
|
|
3004
3374
|
{
|
|
3005
3375
|
className: "absolute inset-x-0 flex justify-center z-10 pointer-events-none",
|
|
@@ -3015,14 +3385,14 @@ function CopilotChatView({
|
|
|
3015
3385
|
}
|
|
3016
3386
|
);
|
|
3017
3387
|
}
|
|
3018
|
-
return /* @__PURE__ */
|
|
3019
|
-
|
|
3388
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
3389
|
+
import_use_stick_to_bottom.StickToBottom,
|
|
3020
3390
|
{
|
|
3021
3391
|
className: cn("h-full max-h-full flex flex-col min-h-0 relative", className),
|
|
3022
3392
|
resize: "smooth",
|
|
3023
3393
|
initial: "smooth",
|
|
3024
3394
|
...props,
|
|
3025
|
-
children: /* @__PURE__ */
|
|
3395
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
3026
3396
|
ScrollContent,
|
|
3027
3397
|
{
|
|
3028
3398
|
scrollToBottomButton,
|
|
@@ -3037,12 +3407,12 @@ function CopilotChatView({
|
|
|
3037
3407
|
CopilotChatView2.ScrollToBottomButton = ({
|
|
3038
3408
|
className,
|
|
3039
3409
|
...props
|
|
3040
|
-
}) => /* @__PURE__ */
|
|
3410
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
3041
3411
|
Button,
|
|
3042
3412
|
{
|
|
3043
3413
|
variant: "outline",
|
|
3044
3414
|
size: "sm",
|
|
3045
|
-
className:
|
|
3415
|
+
className: (0, import_tailwind_merge7.twMerge)(
|
|
3046
3416
|
"rounded-full w-10 h-10 p-0 pointer-events-auto",
|
|
3047
3417
|
"bg-white dark:bg-gray-900",
|
|
3048
3418
|
"shadow-lg border border-gray-200 dark:border-gray-700",
|
|
@@ -3051,10 +3421,10 @@ function CopilotChatView({
|
|
|
3051
3421
|
className
|
|
3052
3422
|
),
|
|
3053
3423
|
...props,
|
|
3054
|
-
children: /* @__PURE__ */
|
|
3424
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_lucide_react6.ChevronDown, { className: "w-4 h-4 text-gray-600 dark:text-white" })
|
|
3055
3425
|
}
|
|
3056
3426
|
);
|
|
3057
|
-
CopilotChatView2.Feather = ({ className, style, ...props }) => /* @__PURE__ */
|
|
3427
|
+
CopilotChatView2.Feather = ({ className, style, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
3058
3428
|
"div",
|
|
3059
3429
|
{
|
|
3060
3430
|
className: cn(
|
|
@@ -3067,7 +3437,7 @@ function CopilotChatView({
|
|
|
3067
3437
|
...props
|
|
3068
3438
|
}
|
|
3069
3439
|
);
|
|
3070
|
-
CopilotChatView2.InputContainer =
|
|
3440
|
+
CopilotChatView2.InputContainer = import_react23.default.forwardRef(({ children, className, keyboardHeight = 0, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
3071
3441
|
"div",
|
|
3072
3442
|
{
|
|
3073
3443
|
ref,
|
|
@@ -3085,7 +3455,7 @@ function CopilotChatView({
|
|
|
3085
3455
|
CopilotChatView2.Disclaimer = ({ className, ...props }) => {
|
|
3086
3456
|
const config = useCopilotChatConfiguration();
|
|
3087
3457
|
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
3088
|
-
return /* @__PURE__ */
|
|
3458
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
3089
3459
|
"div",
|
|
3090
3460
|
{
|
|
3091
3461
|
className: cn("text-center text-xs text-muted-foreground py-3 px-4 max-w-3xl mx-auto", className),
|
|
@@ -3096,11 +3466,18 @@ function CopilotChatView({
|
|
|
3096
3466
|
};
|
|
3097
3467
|
})(CopilotChatView || (CopilotChatView = {}));
|
|
3098
3468
|
var CopilotChatView_default = CopilotChatView;
|
|
3469
|
+
|
|
3470
|
+
// src/components/chat/CopilotChat.tsx
|
|
3471
|
+
var import_shared8 = require("@copilotkitnext/shared");
|
|
3472
|
+
var import_react24 = require("react");
|
|
3473
|
+
var import_ts_deepmerge = require("ts-deepmerge");
|
|
3474
|
+
var import_client = require("@ag-ui/client");
|
|
3475
|
+
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
3099
3476
|
function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen, ...props }) {
|
|
3100
3477
|
const existingConfig = useCopilotChatConfiguration();
|
|
3101
|
-
const resolvedAgentId = agentId ?? existingConfig?.agentId ??
|
|
3102
|
-
const resolvedThreadId =
|
|
3103
|
-
() => threadId ?? existingConfig?.threadId ??
|
|
3478
|
+
const resolvedAgentId = agentId ?? existingConfig?.agentId ?? import_shared8.DEFAULT_AGENT_ID;
|
|
3479
|
+
const resolvedThreadId = (0, import_react24.useMemo)(
|
|
3480
|
+
() => threadId ?? existingConfig?.threadId ?? (0, import_shared8.randomUUID)(),
|
|
3104
3481
|
[threadId, existingConfig?.threadId]
|
|
3105
3482
|
);
|
|
3106
3483
|
const { agent } = useAgent({ agentId: resolvedAgentId });
|
|
@@ -3112,47 +3489,41 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
3112
3489
|
suggestionView: providedSuggestionView,
|
|
3113
3490
|
...restProps
|
|
3114
3491
|
} = props;
|
|
3115
|
-
|
|
3492
|
+
(0, import_react24.useEffect)(() => {
|
|
3116
3493
|
const connect = async (agent2) => {
|
|
3117
3494
|
try {
|
|
3118
3495
|
await copilotkit.connectAgent({ agent: agent2 });
|
|
3119
3496
|
} catch (error) {
|
|
3120
|
-
if (error instanceof
|
|
3497
|
+
if (error instanceof import_client.AGUIConnectNotImplementedError) {
|
|
3498
|
+
} else {
|
|
3121
3499
|
throw error;
|
|
3122
3500
|
}
|
|
3123
3501
|
}
|
|
3124
3502
|
};
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
connect(agent);
|
|
3128
|
-
}
|
|
3503
|
+
agent.threadId = resolvedThreadId;
|
|
3504
|
+
connect(agent);
|
|
3129
3505
|
return () => {
|
|
3130
3506
|
};
|
|
3131
3507
|
}, [resolvedThreadId, agent, copilotkit, resolvedAgentId]);
|
|
3132
|
-
const onSubmitInput =
|
|
3508
|
+
const onSubmitInput = (0, import_react24.useCallback)(
|
|
3133
3509
|
async (value) => {
|
|
3134
|
-
agent
|
|
3135
|
-
id:
|
|
3510
|
+
agent.addMessage({
|
|
3511
|
+
id: (0, import_shared8.randomUUID)(),
|
|
3136
3512
|
role: "user",
|
|
3137
3513
|
content: value
|
|
3138
3514
|
});
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
console.error("CopilotChat: runAgent failed", error);
|
|
3144
|
-
}
|
|
3515
|
+
try {
|
|
3516
|
+
await copilotkit.runAgent({ agent });
|
|
3517
|
+
} catch (error) {
|
|
3518
|
+
console.error("CopilotChat: runAgent failed", error);
|
|
3145
3519
|
}
|
|
3146
3520
|
},
|
|
3147
3521
|
[agent, copilotkit]
|
|
3148
3522
|
);
|
|
3149
|
-
const handleSelectSuggestion =
|
|
3523
|
+
const handleSelectSuggestion = (0, import_react24.useCallback)(
|
|
3150
3524
|
async (suggestion) => {
|
|
3151
|
-
if (!agent) {
|
|
3152
|
-
return;
|
|
3153
|
-
}
|
|
3154
3525
|
agent.addMessage({
|
|
3155
|
-
id:
|
|
3526
|
+
id: (0, import_shared8.randomUUID)(),
|
|
3156
3527
|
role: "user",
|
|
3157
3528
|
content: suggestion.message
|
|
3158
3529
|
});
|
|
@@ -3164,10 +3535,7 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
3164
3535
|
},
|
|
3165
3536
|
[agent, copilotkit]
|
|
3166
3537
|
);
|
|
3167
|
-
const stopCurrentRun =
|
|
3168
|
-
if (!agent) {
|
|
3169
|
-
return;
|
|
3170
|
-
}
|
|
3538
|
+
const stopCurrentRun = (0, import_react24.useCallback)(() => {
|
|
3171
3539
|
try {
|
|
3172
3540
|
copilotkit.stopAgent({ agent });
|
|
3173
3541
|
} catch (error) {
|
|
@@ -3179,9 +3547,9 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
3179
3547
|
}
|
|
3180
3548
|
}
|
|
3181
3549
|
}, [agent, copilotkit]);
|
|
3182
|
-
const mergedProps =
|
|
3550
|
+
const mergedProps = (0, import_ts_deepmerge.merge)(
|
|
3183
3551
|
{
|
|
3184
|
-
isRunning: agent
|
|
3552
|
+
isRunning: agent.isRunning,
|
|
3185
3553
|
suggestions: autoSuggestions,
|
|
3186
3554
|
onSelectSuggestion: handleSelectSuggestion,
|
|
3187
3555
|
suggestionView: providedSuggestionView
|
|
@@ -3192,22 +3560,22 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
3192
3560
|
}
|
|
3193
3561
|
);
|
|
3194
3562
|
const providedStopHandler = providedInputProps?.onStop;
|
|
3195
|
-
const hasMessages =
|
|
3196
|
-
const shouldAllowStop =
|
|
3563
|
+
const hasMessages = agent.messages.length > 0;
|
|
3564
|
+
const shouldAllowStop = agent.isRunning && hasMessages;
|
|
3197
3565
|
const effectiveStopHandler = shouldAllowStop ? providedStopHandler ?? stopCurrentRun : providedStopHandler;
|
|
3198
3566
|
const finalInputProps = {
|
|
3199
3567
|
...providedInputProps,
|
|
3200
3568
|
onSubmitMessage: onSubmitInput,
|
|
3201
3569
|
onStop: effectiveStopHandler,
|
|
3202
|
-
isRunning: agent
|
|
3570
|
+
isRunning: agent.isRunning
|
|
3203
3571
|
};
|
|
3204
|
-
finalInputProps.mode = agent
|
|
3205
|
-
const finalProps =
|
|
3206
|
-
messages: agent
|
|
3572
|
+
finalInputProps.mode = agent.isRunning ? "processing" : finalInputProps.mode ?? "input";
|
|
3573
|
+
const finalProps = (0, import_ts_deepmerge.merge)(mergedProps, {
|
|
3574
|
+
messages: agent.messages,
|
|
3207
3575
|
inputProps: finalInputProps
|
|
3208
3576
|
});
|
|
3209
3577
|
const RenderedChatView = renderSlot(chatView, CopilotChatView, finalProps);
|
|
3210
|
-
return /* @__PURE__ */
|
|
3578
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
|
3211
3579
|
CopilotChatConfigurationProvider,
|
|
3212
3580
|
{
|
|
3213
3581
|
agentId: resolvedAgentId,
|
|
@@ -3221,14 +3589,19 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
3221
3589
|
((CopilotChat2) => {
|
|
3222
3590
|
CopilotChat2.View = CopilotChatView;
|
|
3223
3591
|
})(CopilotChat || (CopilotChat = {}));
|
|
3592
|
+
|
|
3593
|
+
// src/components/chat/CopilotChatToggleButton.tsx
|
|
3594
|
+
var import_react25 = __toESM(require("react"));
|
|
3595
|
+
var import_lucide_react7 = require("lucide-react");
|
|
3596
|
+
var import_jsx_runtime20 = require("react/jsx-runtime");
|
|
3224
3597
|
var DefaultOpenIcon = ({
|
|
3225
3598
|
className,
|
|
3226
3599
|
...props
|
|
3227
|
-
}) => /* @__PURE__ */
|
|
3600
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_lucide_react7.MessageCircle, { className: cn("h-6 w-6", className), strokeWidth: 1.75, fill: "currentColor", ...props });
|
|
3228
3601
|
var DefaultCloseIcon = ({
|
|
3229
3602
|
className,
|
|
3230
3603
|
...props
|
|
3231
|
-
}) => /* @__PURE__ */
|
|
3604
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_lucide_react7.X, { className: cn("h-6 w-6", className), strokeWidth: 1.75, ...props });
|
|
3232
3605
|
DefaultOpenIcon.displayName = "CopilotChatToggleButton.OpenIcon";
|
|
3233
3606
|
DefaultCloseIcon.displayName = "CopilotChatToggleButton.CloseIcon";
|
|
3234
3607
|
var ICON_TRANSITION_STYLE = Object.freeze({
|
|
@@ -3245,11 +3618,11 @@ var BUTTON_BASE_CLASSES = cn(
|
|
|
3245
3618
|
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 focus-visible:ring-offset-2 focus-visible:ring-offset-background",
|
|
3246
3619
|
"disabled:pointer-events-none disabled:opacity-60"
|
|
3247
3620
|
);
|
|
3248
|
-
var CopilotChatToggleButton =
|
|
3621
|
+
var CopilotChatToggleButton = import_react25.default.forwardRef(function CopilotChatToggleButton2({ openIcon, closeIcon, className, ...buttonProps }, ref) {
|
|
3249
3622
|
const { onClick, type, disabled, ...restProps } = buttonProps;
|
|
3250
3623
|
const configuration = useCopilotChatConfiguration();
|
|
3251
3624
|
const labels = configuration?.labels ?? CopilotChatDefaultLabels;
|
|
3252
|
-
const [fallbackOpen, setFallbackOpen] =
|
|
3625
|
+
const [fallbackOpen, setFallbackOpen] = (0, import_react25.useState)(false);
|
|
3253
3626
|
const isOpen = configuration?.isModalOpen ?? fallbackOpen;
|
|
3254
3627
|
const setModalOpen = configuration?.setModalOpen ?? setFallbackOpen;
|
|
3255
3628
|
const handleClick = (event) => {
|
|
@@ -3283,7 +3656,7 @@ var CopilotChatToggleButton = React2__namespace.default.forwardRef(function Copi
|
|
|
3283
3656
|
focusable: false
|
|
3284
3657
|
}
|
|
3285
3658
|
);
|
|
3286
|
-
const openIconElement = /* @__PURE__ */
|
|
3659
|
+
const openIconElement = /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
3287
3660
|
"span",
|
|
3288
3661
|
{
|
|
3289
3662
|
"aria-hidden": "true",
|
|
@@ -3297,7 +3670,7 @@ var CopilotChatToggleButton = React2__namespace.default.forwardRef(function Copi
|
|
|
3297
3670
|
children: renderedOpenIcon
|
|
3298
3671
|
}
|
|
3299
3672
|
);
|
|
3300
|
-
const closeIconElement = /* @__PURE__ */
|
|
3673
|
+
const closeIconElement = /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
3301
3674
|
"span",
|
|
3302
3675
|
{
|
|
3303
3676
|
"aria-hidden": "true",
|
|
@@ -3311,7 +3684,7 @@ var CopilotChatToggleButton = React2__namespace.default.forwardRef(function Copi
|
|
|
3311
3684
|
children: renderedCloseIcon
|
|
3312
3685
|
}
|
|
3313
3686
|
);
|
|
3314
|
-
return /* @__PURE__ */
|
|
3687
|
+
return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
|
|
3315
3688
|
"button",
|
|
3316
3689
|
{
|
|
3317
3690
|
ref,
|
|
@@ -3333,6 +3706,14 @@ var CopilotChatToggleButton = React2__namespace.default.forwardRef(function Copi
|
|
|
3333
3706
|
});
|
|
3334
3707
|
CopilotChatToggleButton.displayName = "CopilotChatToggleButton";
|
|
3335
3708
|
var CopilotChatToggleButton_default = CopilotChatToggleButton;
|
|
3709
|
+
|
|
3710
|
+
// src/components/chat/CopilotSidebarView.tsx
|
|
3711
|
+
var import_react27 = require("react");
|
|
3712
|
+
|
|
3713
|
+
// src/components/chat/CopilotModalHeader.tsx
|
|
3714
|
+
var import_react26 = require("react");
|
|
3715
|
+
var import_lucide_react8 = require("lucide-react");
|
|
3716
|
+
var import_jsx_runtime21 = require("react/jsx-runtime");
|
|
3336
3717
|
function CopilotModalHeader({
|
|
3337
3718
|
title,
|
|
3338
3719
|
titleContent,
|
|
@@ -3344,7 +3725,7 @@ function CopilotModalHeader({
|
|
|
3344
3725
|
const configuration = useCopilotChatConfiguration();
|
|
3345
3726
|
const fallbackTitle = configuration?.labels.modalHeaderTitle ?? CopilotChatDefaultLabels.modalHeaderTitle;
|
|
3346
3727
|
const resolvedTitle = title ?? fallbackTitle;
|
|
3347
|
-
const handleClose =
|
|
3728
|
+
const handleClose = (0, import_react26.useCallback)(() => {
|
|
3348
3729
|
configuration?.setModalOpen(false);
|
|
3349
3730
|
}, [configuration]);
|
|
3350
3731
|
const BoundTitle = renderSlot(titleContent, CopilotModalHeader.Title, {
|
|
@@ -3361,7 +3742,7 @@ function CopilotModalHeader({
|
|
|
3361
3742
|
...rest
|
|
3362
3743
|
});
|
|
3363
3744
|
}
|
|
3364
|
-
return /* @__PURE__ */
|
|
3745
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
3365
3746
|
"header",
|
|
3366
3747
|
{
|
|
3367
3748
|
"data-slot": "copilot-modal-header",
|
|
@@ -3371,17 +3752,17 @@ function CopilotModalHeader({
|
|
|
3371
3752
|
className
|
|
3372
3753
|
),
|
|
3373
3754
|
...rest,
|
|
3374
|
-
children: /* @__PURE__ */
|
|
3375
|
-
/* @__PURE__ */
|
|
3376
|
-
/* @__PURE__ */
|
|
3377
|
-
/* @__PURE__ */
|
|
3755
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex w-full items-center gap-2", children: [
|
|
3756
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "flex-1", "aria-hidden": "true" }),
|
|
3757
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "flex flex-1 justify-center text-center", children: BoundTitle }),
|
|
3758
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "flex flex-1 justify-end", children: BoundCloseButton })
|
|
3378
3759
|
] })
|
|
3379
3760
|
}
|
|
3380
3761
|
);
|
|
3381
3762
|
}
|
|
3382
3763
|
CopilotModalHeader.displayName = "CopilotModalHeader";
|
|
3383
3764
|
((CopilotModalHeader2) => {
|
|
3384
|
-
CopilotModalHeader2.Title = ({ children, className, ...props }) => /* @__PURE__ */
|
|
3765
|
+
CopilotModalHeader2.Title = ({ children, className, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
3385
3766
|
"div",
|
|
3386
3767
|
{
|
|
3387
3768
|
className: cn(
|
|
@@ -3395,7 +3776,7 @@ CopilotModalHeader.displayName = "CopilotModalHeader";
|
|
|
3395
3776
|
CopilotModalHeader2.CloseButton = ({
|
|
3396
3777
|
className,
|
|
3397
3778
|
...props
|
|
3398
|
-
}) => /* @__PURE__ */
|
|
3779
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
3399
3780
|
"button",
|
|
3400
3781
|
{
|
|
3401
3782
|
type: "button",
|
|
@@ -3406,19 +3787,22 @@ CopilotModalHeader.displayName = "CopilotModalHeader";
|
|
|
3406
3787
|
),
|
|
3407
3788
|
"aria-label": "Close",
|
|
3408
3789
|
...props,
|
|
3409
|
-
children: /* @__PURE__ */
|
|
3790
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_lucide_react8.X, { className: "h-4 w-4", "aria-hidden": "true" })
|
|
3410
3791
|
}
|
|
3411
3792
|
);
|
|
3412
3793
|
})(CopilotModalHeader || (CopilotModalHeader = {}));
|
|
3413
3794
|
CopilotModalHeader.Title.displayName = "CopilotModalHeader.Title";
|
|
3414
3795
|
CopilotModalHeader.CloseButton.displayName = "CopilotModalHeader.CloseButton";
|
|
3796
|
+
|
|
3797
|
+
// src/components/chat/CopilotSidebarView.tsx
|
|
3798
|
+
var import_jsx_runtime22 = require("react/jsx-runtime");
|
|
3415
3799
|
var DEFAULT_SIDEBAR_WIDTH = 480;
|
|
3416
3800
|
var SIDEBAR_TRANSITION_MS = 260;
|
|
3417
3801
|
function CopilotSidebarView({ header, width, ...props }) {
|
|
3418
3802
|
const configuration = useCopilotChatConfiguration();
|
|
3419
3803
|
const isSidebarOpen = configuration?.isModalOpen ?? false;
|
|
3420
|
-
const sidebarRef =
|
|
3421
|
-
const [sidebarWidth, setSidebarWidth] =
|
|
3804
|
+
const sidebarRef = (0, import_react27.useRef)(null);
|
|
3805
|
+
const [sidebarWidth, setSidebarWidth] = (0, import_react27.useState)(width ?? DEFAULT_SIDEBAR_WIDTH);
|
|
3422
3806
|
const widthToCss = (w) => {
|
|
3423
3807
|
return typeof w === "number" ? `${w}px` : w;
|
|
3424
3808
|
};
|
|
@@ -3428,7 +3812,7 @@ function CopilotSidebarView({ header, width, ...props }) {
|
|
|
3428
3812
|
}
|
|
3429
3813
|
return w;
|
|
3430
3814
|
};
|
|
3431
|
-
|
|
3815
|
+
(0, import_react27.useEffect)(() => {
|
|
3432
3816
|
if (width !== void 0) {
|
|
3433
3817
|
return;
|
|
3434
3818
|
}
|
|
@@ -3455,8 +3839,8 @@ function CopilotSidebarView({ header, width, ...props }) {
|
|
|
3455
3839
|
return () => window.removeEventListener("resize", updateWidth);
|
|
3456
3840
|
}, [width]);
|
|
3457
3841
|
const headerElement = renderSlot(header, CopilotModalHeader, {});
|
|
3458
|
-
return /* @__PURE__ */
|
|
3459
|
-
isSidebarOpen && /* @__PURE__ */
|
|
3842
|
+
return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(import_jsx_runtime22.Fragment, { children: [
|
|
3843
|
+
isSidebarOpen && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
|
3460
3844
|
"style",
|
|
3461
3845
|
{
|
|
3462
3846
|
dangerouslySetInnerHTML: {
|
|
@@ -3470,8 +3854,8 @@ function CopilotSidebarView({ header, width, ...props }) {
|
|
|
3470
3854
|
}
|
|
3471
3855
|
}
|
|
3472
3856
|
),
|
|
3473
|
-
/* @__PURE__ */
|
|
3474
|
-
/* @__PURE__ */
|
|
3857
|
+
/* @__PURE__ */ (0, import_jsx_runtime22.jsx)(CopilotChatToggleButton_default, {}),
|
|
3858
|
+
/* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
|
3475
3859
|
"aside",
|
|
3476
3860
|
{
|
|
3477
3861
|
ref: sidebarRef,
|
|
@@ -3496,15 +3880,19 @@ function CopilotSidebarView({ header, width, ...props }) {
|
|
|
3496
3880
|
"aria-hidden": !isSidebarOpen,
|
|
3497
3881
|
"aria-label": "Copilot chat sidebar",
|
|
3498
3882
|
role: "complementary",
|
|
3499
|
-
children: /* @__PURE__ */
|
|
3883
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { className: "flex h-full w-full flex-col overflow-hidden", children: [
|
|
3500
3884
|
headerElement,
|
|
3501
|
-
/* @__PURE__ */
|
|
3885
|
+
/* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { className: "flex-1 overflow-hidden", "data-sidebar-chat": true, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(CopilotChatView_default, { ...props }) })
|
|
3502
3886
|
] })
|
|
3503
3887
|
}
|
|
3504
3888
|
)
|
|
3505
3889
|
] });
|
|
3506
3890
|
}
|
|
3507
3891
|
CopilotSidebarView.displayName = "CopilotSidebarView";
|
|
3892
|
+
|
|
3893
|
+
// src/components/chat/CopilotPopupView.tsx
|
|
3894
|
+
var import_react28 = require("react");
|
|
3895
|
+
var import_jsx_runtime23 = require("react/jsx-runtime");
|
|
3508
3896
|
var DEFAULT_POPUP_WIDTH = 420;
|
|
3509
3897
|
var DEFAULT_POPUP_HEIGHT = 560;
|
|
3510
3898
|
var dimensionToCss = (value, fallback) => {
|
|
@@ -3528,10 +3916,10 @@ function CopilotPopupView({
|
|
|
3528
3916
|
const isPopupOpen = configuration?.isModalOpen ?? false;
|
|
3529
3917
|
const setModalOpen = configuration?.setModalOpen;
|
|
3530
3918
|
const labels = configuration?.labels ?? CopilotChatDefaultLabels;
|
|
3531
|
-
const containerRef =
|
|
3532
|
-
const [isRendered, setIsRendered] =
|
|
3533
|
-
const [isAnimatingOut, setIsAnimatingOut] =
|
|
3534
|
-
|
|
3919
|
+
const containerRef = (0, import_react28.useRef)(null);
|
|
3920
|
+
const [isRendered, setIsRendered] = (0, import_react28.useState)(isPopupOpen);
|
|
3921
|
+
const [isAnimatingOut, setIsAnimatingOut] = (0, import_react28.useState)(false);
|
|
3922
|
+
(0, import_react28.useEffect)(() => {
|
|
3535
3923
|
if (isPopupOpen) {
|
|
3536
3924
|
setIsRendered(true);
|
|
3537
3925
|
setIsAnimatingOut(false);
|
|
@@ -3547,7 +3935,7 @@ function CopilotPopupView({
|
|
|
3547
3935
|
}, 200);
|
|
3548
3936
|
return () => clearTimeout(timeout);
|
|
3549
3937
|
}, [isPopupOpen, isRendered]);
|
|
3550
|
-
|
|
3938
|
+
(0, import_react28.useEffect)(() => {
|
|
3551
3939
|
if (!isPopupOpen) {
|
|
3552
3940
|
return;
|
|
3553
3941
|
}
|
|
@@ -3563,7 +3951,7 @@ function CopilotPopupView({
|
|
|
3563
3951
|
window.addEventListener("keydown", handleKeyDown);
|
|
3564
3952
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
3565
3953
|
}, [isPopupOpen, setModalOpen]);
|
|
3566
|
-
|
|
3954
|
+
(0, import_react28.useEffect)(() => {
|
|
3567
3955
|
if (!isPopupOpen) {
|
|
3568
3956
|
return;
|
|
3569
3957
|
}
|
|
@@ -3572,7 +3960,7 @@ function CopilotPopupView({
|
|
|
3572
3960
|
}, 200);
|
|
3573
3961
|
return () => clearTimeout(focusTimer);
|
|
3574
3962
|
}, [isPopupOpen]);
|
|
3575
|
-
|
|
3963
|
+
(0, import_react28.useEffect)(() => {
|
|
3576
3964
|
if (!isPopupOpen || !clickOutsideToClose) {
|
|
3577
3965
|
return;
|
|
3578
3966
|
}
|
|
@@ -3597,10 +3985,10 @@ function CopilotPopupView({
|
|
|
3597
3985
|
document.addEventListener("pointerdown", handlePointerDown);
|
|
3598
3986
|
return () => document.removeEventListener("pointerdown", handlePointerDown);
|
|
3599
3987
|
}, [isPopupOpen, clickOutsideToClose, setModalOpen]);
|
|
3600
|
-
const headerElement =
|
|
3988
|
+
const headerElement = (0, import_react28.useMemo)(() => renderSlot(header, CopilotModalHeader, {}), [header]);
|
|
3601
3989
|
const resolvedWidth = dimensionToCss(width, DEFAULT_POPUP_WIDTH);
|
|
3602
3990
|
const resolvedHeight = dimensionToCss(height, DEFAULT_POPUP_HEIGHT);
|
|
3603
|
-
const popupStyle =
|
|
3991
|
+
const popupStyle = (0, import_react28.useMemo)(
|
|
3604
3992
|
() => ({
|
|
3605
3993
|
"--copilot-popup-width": resolvedWidth,
|
|
3606
3994
|
"--copilot-popup-height": resolvedHeight,
|
|
@@ -3614,14 +4002,14 @@ function CopilotPopupView({
|
|
|
3614
4002
|
[resolvedHeight, resolvedWidth]
|
|
3615
4003
|
);
|
|
3616
4004
|
const popupAnimationClass = isPopupOpen && !isAnimatingOut ? "pointer-events-auto translate-y-0 opacity-100 md:scale-100" : "pointer-events-none translate-y-4 opacity-0 md:translate-y-5 md:scale-[0.95]";
|
|
3617
|
-
const popupContent = isRendered ? /* @__PURE__ */
|
|
4005
|
+
const popupContent = isRendered ? /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
3618
4006
|
"div",
|
|
3619
4007
|
{
|
|
3620
4008
|
className: cn(
|
|
3621
4009
|
"fixed inset-0 z-[1200] flex max-w-full flex-col items-stretch",
|
|
3622
4010
|
"md:inset-auto md:bottom-24 md:right-6 md:items-end md:gap-4"
|
|
3623
4011
|
),
|
|
3624
|
-
children: /* @__PURE__ */
|
|
4012
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(
|
|
3625
4013
|
"div",
|
|
3626
4014
|
{
|
|
3627
4015
|
ref: containerRef,
|
|
@@ -3642,7 +4030,7 @@ function CopilotPopupView({
|
|
|
3642
4030
|
style: popupStyle,
|
|
3643
4031
|
children: [
|
|
3644
4032
|
headerElement,
|
|
3645
|
-
/* @__PURE__ */
|
|
4033
|
+
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: "flex-1 overflow-hidden", "data-popup-chat": true, children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
3646
4034
|
CopilotChatView_default,
|
|
3647
4035
|
{
|
|
3648
4036
|
...restProps,
|
|
@@ -3654,17 +4042,21 @@ function CopilotPopupView({
|
|
|
3654
4042
|
)
|
|
3655
4043
|
}
|
|
3656
4044
|
) : null;
|
|
3657
|
-
return /* @__PURE__ */
|
|
3658
|
-
/* @__PURE__ */
|
|
4045
|
+
return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(import_jsx_runtime23.Fragment, { children: [
|
|
4046
|
+
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)(CopilotChatToggleButton_default, {}),
|
|
3659
4047
|
popupContent
|
|
3660
4048
|
] });
|
|
3661
4049
|
}
|
|
3662
4050
|
CopilotPopupView.displayName = "CopilotPopupView";
|
|
4051
|
+
|
|
4052
|
+
// src/components/chat/CopilotSidebar.tsx
|
|
4053
|
+
var import_react29 = require("react");
|
|
4054
|
+
var import_jsx_runtime24 = require("react/jsx-runtime");
|
|
3663
4055
|
function CopilotSidebar({ header, defaultOpen, width, ...chatProps }) {
|
|
3664
|
-
const SidebarViewOverride =
|
|
4056
|
+
const SidebarViewOverride = (0, import_react29.useMemo)(() => {
|
|
3665
4057
|
const Component = (viewProps) => {
|
|
3666
4058
|
const { header: viewHeader, width: viewWidth, ...restProps } = viewProps;
|
|
3667
|
-
return /* @__PURE__ */
|
|
4059
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
3668
4060
|
CopilotSidebarView,
|
|
3669
4061
|
{
|
|
3670
4062
|
...restProps,
|
|
@@ -3675,7 +4067,7 @@ function CopilotSidebar({ header, defaultOpen, width, ...chatProps }) {
|
|
|
3675
4067
|
};
|
|
3676
4068
|
return Object.assign(Component, CopilotChatView_default);
|
|
3677
4069
|
}, [header, width]);
|
|
3678
|
-
return /* @__PURE__ */
|
|
4070
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
3679
4071
|
CopilotChat,
|
|
3680
4072
|
{
|
|
3681
4073
|
...chatProps,
|
|
@@ -3685,6 +4077,10 @@ function CopilotSidebar({ header, defaultOpen, width, ...chatProps }) {
|
|
|
3685
4077
|
);
|
|
3686
4078
|
}
|
|
3687
4079
|
CopilotSidebar.displayName = "CopilotSidebar";
|
|
4080
|
+
|
|
4081
|
+
// src/components/chat/CopilotPopup.tsx
|
|
4082
|
+
var import_react30 = require("react");
|
|
4083
|
+
var import_jsx_runtime25 = require("react/jsx-runtime");
|
|
3688
4084
|
function CopilotPopup({
|
|
3689
4085
|
header,
|
|
3690
4086
|
defaultOpen,
|
|
@@ -3693,7 +4089,7 @@ function CopilotPopup({
|
|
|
3693
4089
|
clickOutsideToClose,
|
|
3694
4090
|
...chatProps
|
|
3695
4091
|
}) {
|
|
3696
|
-
const PopupViewOverride =
|
|
4092
|
+
const PopupViewOverride = (0, import_react30.useMemo)(() => {
|
|
3697
4093
|
const Component = (viewProps) => {
|
|
3698
4094
|
const {
|
|
3699
4095
|
header: viewHeader,
|
|
@@ -3702,7 +4098,7 @@ function CopilotPopup({
|
|
|
3702
4098
|
clickOutsideToClose: viewClickOutsideToClose,
|
|
3703
4099
|
...restProps
|
|
3704
4100
|
} = viewProps;
|
|
3705
|
-
return /* @__PURE__ */
|
|
4101
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
3706
4102
|
CopilotPopupView,
|
|
3707
4103
|
{
|
|
3708
4104
|
...restProps,
|
|
@@ -3715,7 +4111,7 @@ function CopilotPopup({
|
|
|
3715
4111
|
};
|
|
3716
4112
|
return Object.assign(Component, CopilotChatView_default);
|
|
3717
4113
|
}, [clickOutsideToClose, header, height, width]);
|
|
3718
|
-
return /* @__PURE__ */
|
|
4114
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
3719
4115
|
CopilotChat,
|
|
3720
4116
|
{
|
|
3721
4117
|
...chatProps,
|
|
@@ -3725,8 +4121,11 @@ function CopilotPopup({
|
|
|
3725
4121
|
);
|
|
3726
4122
|
}
|
|
3727
4123
|
CopilotPopup.displayName = "CopilotPopup";
|
|
4124
|
+
|
|
4125
|
+
// src/types/defineToolCallRenderer.ts
|
|
4126
|
+
var import_zod2 = require("zod");
|
|
3728
4127
|
function defineToolCallRenderer(def) {
|
|
3729
|
-
const argsSchema = def.name === "*" && !def.args ?
|
|
4128
|
+
const argsSchema = def.name === "*" && !def.args ? import_zod2.z.any() : def.args;
|
|
3730
4129
|
return {
|
|
3731
4130
|
name: def.name,
|
|
3732
4131
|
args: argsSchema,
|
|
@@ -3734,23 +4133,27 @@ function defineToolCallRenderer(def) {
|
|
|
3734
4133
|
...def.agentId ? { agentId: def.agentId } : {}
|
|
3735
4134
|
};
|
|
3736
4135
|
}
|
|
4136
|
+
|
|
4137
|
+
// src/components/WildcardToolCallRender.tsx
|
|
4138
|
+
var import_react31 = require("react");
|
|
4139
|
+
var import_jsx_runtime26 = require("react/jsx-runtime");
|
|
3737
4140
|
var WildcardToolCallRender = defineToolCallRenderer({
|
|
3738
4141
|
name: "*",
|
|
3739
4142
|
render: ({ args, result, name, status }) => {
|
|
3740
|
-
const [isExpanded, setIsExpanded] =
|
|
4143
|
+
const [isExpanded, setIsExpanded] = (0, import_react31.useState)(false);
|
|
3741
4144
|
const statusString = String(status);
|
|
3742
4145
|
const isActive = statusString === "inProgress" || statusString === "executing";
|
|
3743
4146
|
const isComplete = statusString === "complete";
|
|
3744
4147
|
const statusStyles = isActive ? "bg-amber-100 text-amber-800 dark:bg-amber-500/15 dark:text-amber-400" : isComplete ? "bg-emerald-100 text-emerald-800 dark:bg-emerald-500/15 dark:text-emerald-400" : "bg-zinc-100 text-zinc-800 dark:bg-zinc-700/40 dark:text-zinc-300";
|
|
3745
|
-
return /* @__PURE__ */
|
|
3746
|
-
/* @__PURE__ */
|
|
4148
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", { className: "mt-2 pb-2", children: /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("div", { className: "rounded-xl border border-zinc-200/60 dark:border-zinc-800/60 bg-white/70 dark:bg-zinc-900/50 shadow-sm backdrop-blur p-4", children: [
|
|
4149
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(
|
|
3747
4150
|
"div",
|
|
3748
4151
|
{
|
|
3749
4152
|
className: "flex items-center justify-between gap-3 cursor-pointer",
|
|
3750
4153
|
onClick: () => setIsExpanded(!isExpanded),
|
|
3751
4154
|
children: [
|
|
3752
|
-
/* @__PURE__ */
|
|
3753
|
-
/* @__PURE__ */
|
|
4155
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("div", { className: "flex items-center gap-2 min-w-0", children: [
|
|
4156
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
3754
4157
|
"svg",
|
|
3755
4158
|
{
|
|
3756
4159
|
className: `h-4 w-4 text-zinc-500 dark:text-zinc-400 transition-transform ${isExpanded ? "rotate-90" : ""}`,
|
|
@@ -3758,7 +4161,7 @@ var WildcardToolCallRender = defineToolCallRenderer({
|
|
|
3758
4161
|
viewBox: "0 0 24 24",
|
|
3759
4162
|
strokeWidth: 2,
|
|
3760
4163
|
stroke: "currentColor",
|
|
3761
|
-
children: /* @__PURE__ */
|
|
4164
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
3762
4165
|
"path",
|
|
3763
4166
|
{
|
|
3764
4167
|
strokeLinecap: "round",
|
|
@@ -3768,10 +4171,10 @@ var WildcardToolCallRender = defineToolCallRenderer({
|
|
|
3768
4171
|
)
|
|
3769
4172
|
}
|
|
3770
4173
|
),
|
|
3771
|
-
/* @__PURE__ */
|
|
3772
|
-
/* @__PURE__ */
|
|
4174
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)("span", { className: "inline-block h-2 w-2 rounded-full bg-blue-500" }),
|
|
4175
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)("span", { className: "truncate text-sm font-medium text-zinc-900 dark:text-zinc-100", children: name })
|
|
3773
4176
|
] }),
|
|
3774
|
-
/* @__PURE__ */
|
|
4177
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
3775
4178
|
"span",
|
|
3776
4179
|
{
|
|
3777
4180
|
className: `inline-flex items-center rounded-full px-2 py-1 text-xs font-medium ${statusStyles}`,
|
|
@@ -3781,55 +4184,58 @@ var WildcardToolCallRender = defineToolCallRenderer({
|
|
|
3781
4184
|
]
|
|
3782
4185
|
}
|
|
3783
4186
|
),
|
|
3784
|
-
isExpanded && /* @__PURE__ */
|
|
3785
|
-
/* @__PURE__ */
|
|
3786
|
-
/* @__PURE__ */
|
|
3787
|
-
/* @__PURE__ */
|
|
4187
|
+
isExpanded && /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("div", { className: "mt-3 grid gap-4", children: [
|
|
4188
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("div", { children: [
|
|
4189
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", { className: "text-xs uppercase tracking-wide text-zinc-500 dark:text-zinc-400", children: "Arguments" }),
|
|
4190
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)("pre", { className: "mt-2 max-h-64 overflow-auto rounded-md bg-zinc-50 dark:bg-zinc-800/60 p-3 text-xs leading-relaxed text-zinc-800 dark:text-zinc-200 whitespace-pre-wrap break-words", children: JSON.stringify(args ?? {}, null, 2) })
|
|
3788
4191
|
] }),
|
|
3789
|
-
result !== void 0 && /* @__PURE__ */
|
|
3790
|
-
/* @__PURE__ */
|
|
3791
|
-
/* @__PURE__ */
|
|
4192
|
+
result !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("div", { children: [
|
|
4193
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", { className: "text-xs uppercase tracking-wide text-zinc-500 dark:text-zinc-400", children: "Result" }),
|
|
4194
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)("pre", { className: "mt-2 max-h-64 overflow-auto rounded-md bg-zinc-50 dark:bg-zinc-800/60 p-3 text-xs leading-relaxed text-zinc-800 dark:text-zinc-200 whitespace-pre-wrap break-words", children: typeof result === "string" ? result : JSON.stringify(result, null, 2) })
|
|
3792
4195
|
] })
|
|
3793
4196
|
] })
|
|
3794
4197
|
] }) });
|
|
3795
4198
|
}
|
|
3796
4199
|
});
|
|
3797
|
-
|
|
3798
|
-
exports
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
4200
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
4201
|
+
0 && (module.exports = {
|
|
4202
|
+
AudioRecorderError,
|
|
4203
|
+
CopilotChat,
|
|
4204
|
+
CopilotChatAssistantMessage,
|
|
4205
|
+
CopilotChatAudioRecorder,
|
|
4206
|
+
CopilotChatConfigurationProvider,
|
|
4207
|
+
CopilotChatInput,
|
|
4208
|
+
CopilotChatMessageView,
|
|
4209
|
+
CopilotChatSuggestionPill,
|
|
4210
|
+
CopilotChatSuggestionView,
|
|
4211
|
+
CopilotChatToggleButton,
|
|
4212
|
+
CopilotChatToggleButtonCloseIcon,
|
|
4213
|
+
CopilotChatToggleButtonOpenIcon,
|
|
4214
|
+
CopilotChatToolCallsView,
|
|
4215
|
+
CopilotChatUserMessage,
|
|
4216
|
+
CopilotChatView,
|
|
4217
|
+
CopilotKitCoreReact,
|
|
4218
|
+
CopilotKitInspector,
|
|
4219
|
+
CopilotKitProvider,
|
|
4220
|
+
CopilotModalHeader,
|
|
4221
|
+
CopilotPopup,
|
|
4222
|
+
CopilotPopupView,
|
|
4223
|
+
CopilotSidebar,
|
|
4224
|
+
CopilotSidebarView,
|
|
4225
|
+
WildcardToolCallRender,
|
|
4226
|
+
defineToolCallRenderer,
|
|
4227
|
+
useAgent,
|
|
4228
|
+
useAgentContext,
|
|
4229
|
+
useConfigureSuggestions,
|
|
4230
|
+
useCopilotChatConfiguration,
|
|
4231
|
+
useCopilotKit,
|
|
4232
|
+
useFrontendTool,
|
|
4233
|
+
useHumanInTheLoop,
|
|
4234
|
+
useRenderActivityMessage,
|
|
4235
|
+
useRenderCustomMessages,
|
|
4236
|
+
useRenderToolCall,
|
|
4237
|
+
useSuggestions,
|
|
4238
|
+
...require("@ag-ui/core"),
|
|
4239
|
+
...require("@ag-ui/client")
|
|
4240
|
+
});
|
|
3835
4241
|
//# sourceMappingURL=index.js.map
|