@copilotkit/react-ui 1.10.4-next.1 → 1.10.4-next.2
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/CHANGELOG.md +11 -0
- package/dist/{chunk-SHPG2T4O.mjs → chunk-FJFWH5AF.mjs} +3 -3
- package/dist/{chunk-FWQRAZ5S.mjs → chunk-KCRWXHWT.mjs} +2 -2
- package/dist/{chunk-X5AO5A3L.mjs → chunk-PHH6DYUW.mjs} +5 -2
- package/dist/chunk-PHH6DYUW.mjs.map +1 -0
- package/dist/{chunk-7XIE7UOW.mjs → chunk-QQDCZRPA.mjs} +2 -2
- package/dist/chunk-SRY5COHG.mjs +63 -0
- package/dist/chunk-SRY5COHG.mjs.map +1 -0
- package/dist/{chunk-EL7NCWNZ.mjs → chunk-Z66Y3KRE.mjs} +51 -21
- package/dist/chunk-Z66Y3KRE.mjs.map +1 -0
- package/dist/components/chat/Chat.d.ts +24 -13
- package/dist/components/chat/Chat.js +144 -62
- package/dist/components/chat/Chat.js.map +1 -1
- package/dist/components/chat/Chat.mjs +3 -2
- package/dist/components/chat/Messages.d.ts +1 -1
- package/dist/components/chat/Messages.js +4 -1
- package/dist/components/chat/Messages.js.map +1 -1
- package/dist/components/chat/Messages.mjs +1 -1
- package/dist/components/chat/Modal.d.ts +1 -1
- package/dist/components/chat/Modal.js +158 -76
- package/dist/components/chat/Modal.js.map +1 -1
- package/dist/components/chat/Modal.mjs +4 -3
- package/dist/components/chat/Popup.d.ts +1 -1
- package/dist/components/chat/Popup.js +160 -78
- package/dist/components/chat/Popup.js.map +1 -1
- package/dist/components/chat/Popup.mjs +5 -4
- package/dist/components/chat/Sidebar.d.ts +1 -1
- package/dist/components/chat/Sidebar.js +162 -80
- package/dist/components/chat/Sidebar.js.map +1 -1
- package/dist/components/chat/Sidebar.mjs +5 -4
- package/dist/components/chat/index.d.ts +2 -2
- package/dist/components/chat/index.js +164 -82
- package/dist/components/chat/index.js.map +1 -1
- package/dist/components/chat/index.mjs +6 -5
- package/dist/components/chat/messages/ErrorMessage.d.ts +9 -0
- package/dist/components/chat/messages/ErrorMessage.js +711 -0
- package/dist/components/chat/messages/ErrorMessage.js.map +1 -0
- package/dist/components/chat/messages/ErrorMessage.mjs +13 -0
- package/dist/components/chat/messages/ErrorMessage.mjs.map +1 -0
- package/dist/components/chat/props.d.ts +26 -1
- package/dist/components/chat/props.js.map +1 -1
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.js +164 -82
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +6 -5
- package/dist/index.d.ts +2 -2
- package/dist/index.js +166 -84
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -6
- package/package.json +4 -4
- package/src/components/chat/Chat.tsx +64 -26
- package/src/components/chat/Messages.tsx +3 -0
- package/src/components/chat/messages/ErrorMessage.tsx +59 -0
- package/src/components/chat/props.ts +31 -0
- package/dist/chunk-EL7NCWNZ.mjs.map +0 -1
- package/dist/chunk-X5AO5A3L.mjs.map +0 -1
- /package/dist/{chunk-SHPG2T4O.mjs.map → chunk-FJFWH5AF.mjs.map} +0 -0
- /package/dist/{chunk-FWQRAZ5S.mjs.map → chunk-KCRWXHWT.mjs.map} +0 -0
- /package/dist/{chunk-7XIE7UOW.mjs.map → chunk-QQDCZRPA.mjs.map} +0 -0
|
@@ -82,7 +82,7 @@ __export(Modal_exports, {
|
|
|
82
82
|
CopilotModal: () => CopilotModal
|
|
83
83
|
});
|
|
84
84
|
module.exports = __toCommonJS(Modal_exports);
|
|
85
|
-
var
|
|
85
|
+
var import_react16 = __toESM(require("react"));
|
|
86
86
|
|
|
87
87
|
// src/components/chat/ChatContext.tsx
|
|
88
88
|
var import_react = __toESM(require("react"));
|
|
@@ -1870,12 +1870,14 @@ var Messages = ({
|
|
|
1870
1870
|
RenderMessage: RenderMessage2,
|
|
1871
1871
|
AssistantMessage: AssistantMessage2,
|
|
1872
1872
|
UserMessage: UserMessage2,
|
|
1873
|
+
ErrorMessage: ErrorMessage2,
|
|
1873
1874
|
ImageRenderer: ImageRenderer2,
|
|
1874
1875
|
onRegenerate,
|
|
1875
1876
|
onCopy,
|
|
1876
1877
|
onThumbsUp,
|
|
1877
1878
|
onThumbsDown,
|
|
1878
1879
|
markdownTagRenderers,
|
|
1880
|
+
chatError,
|
|
1879
1881
|
// Legacy props
|
|
1880
1882
|
RenderTextMessage,
|
|
1881
1883
|
RenderActionExecutionMessage,
|
|
@@ -1936,7 +1938,8 @@ var Messages = ({
|
|
|
1936
1938
|
index
|
|
1937
1939
|
);
|
|
1938
1940
|
}),
|
|
1939
|
-
interrupt
|
|
1941
|
+
interrupt,
|
|
1942
|
+
chatError && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ErrorMessage2, { error: chatError, isCurrentMessage: true })
|
|
1940
1943
|
] }),
|
|
1941
1944
|
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("footer", { className: "copilotKitMessagesFooter", ref: messagesEndRef, children })
|
|
1942
1945
|
] });
|
|
@@ -2319,15 +2322,67 @@ var Input = ({
|
|
|
2319
2322
|
] });
|
|
2320
2323
|
};
|
|
2321
2324
|
|
|
2325
|
+
// src/components/chat/messages/ErrorMessage.tsx
|
|
2326
|
+
var import_react14 = require("react");
|
|
2327
|
+
var import_jsx_runtime21 = require("react/jsx-runtime");
|
|
2328
|
+
var ErrorMessage = (props) => {
|
|
2329
|
+
const { icons, labels } = useChatContext();
|
|
2330
|
+
const { error, onRegenerate, onCopy, isCurrentMessage } = props;
|
|
2331
|
+
const [copied, setCopied] = (0, import_react14.useState)(false);
|
|
2332
|
+
const handleCopy = () => {
|
|
2333
|
+
const content = error.message;
|
|
2334
|
+
if (content && onCopy) {
|
|
2335
|
+
navigator.clipboard.writeText(content);
|
|
2336
|
+
setCopied(true);
|
|
2337
|
+
onCopy(content);
|
|
2338
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
2339
|
+
} else if (content) {
|
|
2340
|
+
navigator.clipboard.writeText(content);
|
|
2341
|
+
setCopied(true);
|
|
2342
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
2343
|
+
}
|
|
2344
|
+
};
|
|
2345
|
+
const handleRegenerate = () => {
|
|
2346
|
+
if (onRegenerate)
|
|
2347
|
+
onRegenerate();
|
|
2348
|
+
};
|
|
2349
|
+
console.log(error);
|
|
2350
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "copilotKitMessage copilotKitAssistantMessage", children: [
|
|
2351
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Markdown, { content: error.message }),
|
|
2352
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: `copilotKitMessageControls ${isCurrentMessage ? "currentMessage" : ""}`, children: [
|
|
2353
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
2354
|
+
"button",
|
|
2355
|
+
{
|
|
2356
|
+
className: "copilotKitMessageControlButton",
|
|
2357
|
+
onClick: handleRegenerate,
|
|
2358
|
+
"aria-label": labels.regenerateResponse,
|
|
2359
|
+
title: labels.regenerateResponse,
|
|
2360
|
+
children: icons.regenerateIcon
|
|
2361
|
+
}
|
|
2362
|
+
),
|
|
2363
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
2364
|
+
"button",
|
|
2365
|
+
{
|
|
2366
|
+
className: "copilotKitMessageControlButton",
|
|
2367
|
+
onClick: handleCopy,
|
|
2368
|
+
"aria-label": labels.copyToClipboard,
|
|
2369
|
+
title: labels.copyToClipboard,
|
|
2370
|
+
children: copied ? /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { style: { fontSize: "10px", fontWeight: "bold" }, children: "\u2713" }) : icons.copyIcon
|
|
2371
|
+
}
|
|
2372
|
+
)
|
|
2373
|
+
] })
|
|
2374
|
+
] });
|
|
2375
|
+
};
|
|
2376
|
+
|
|
2322
2377
|
// src/components/chat/Chat.tsx
|
|
2323
|
-
var
|
|
2378
|
+
var import_react15 = __toESM(require("react"));
|
|
2324
2379
|
var import_react_core9 = require("@copilotkit/react-core");
|
|
2325
2380
|
var import_shared3 = require("@copilotkit/shared");
|
|
2326
2381
|
var import_shared4 = require("@copilotkit/shared");
|
|
2327
2382
|
var import_react_core10 = require("@copilotkit/react-core");
|
|
2328
2383
|
|
|
2329
2384
|
// src/components/chat/ImageUploadQueue.tsx
|
|
2330
|
-
var
|
|
2385
|
+
var import_jsx_runtime22 = require("react/jsx-runtime");
|
|
2331
2386
|
var ImageUploadQueue = ({
|
|
2332
2387
|
images,
|
|
2333
2388
|
onRemoveImage,
|
|
@@ -2335,7 +2390,7 @@ var ImageUploadQueue = ({
|
|
|
2335
2390
|
}) => {
|
|
2336
2391
|
if (images.length === 0)
|
|
2337
2392
|
return null;
|
|
2338
|
-
return /* @__PURE__ */ (0,
|
|
2393
|
+
return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
|
2339
2394
|
"div",
|
|
2340
2395
|
{
|
|
2341
2396
|
className: `copilotKitImageUploadQueue ${className}`,
|
|
@@ -2346,7 +2401,7 @@ var ImageUploadQueue = ({
|
|
|
2346
2401
|
margin: "8px",
|
|
2347
2402
|
padding: "8px"
|
|
2348
2403
|
},
|
|
2349
|
-
children: images.map((image, index) => /* @__PURE__ */ (0,
|
|
2404
|
+
children: images.map((image, index) => /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(
|
|
2350
2405
|
"div",
|
|
2351
2406
|
{
|
|
2352
2407
|
className: "copilotKitImageUploadQueueItem",
|
|
@@ -2359,7 +2414,7 @@ var ImageUploadQueue = ({
|
|
|
2359
2414
|
overflow: "hidden"
|
|
2360
2415
|
},
|
|
2361
2416
|
children: [
|
|
2362
|
-
/* @__PURE__ */ (0,
|
|
2417
|
+
/* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
|
2363
2418
|
"img",
|
|
2364
2419
|
{
|
|
2365
2420
|
src: `data:${image.contentType};base64,${image.bytes}`,
|
|
@@ -2371,7 +2426,7 @@ var ImageUploadQueue = ({
|
|
|
2371
2426
|
}
|
|
2372
2427
|
}
|
|
2373
2428
|
),
|
|
2374
|
-
/* @__PURE__ */ (0,
|
|
2429
|
+
/* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
|
2375
2430
|
"button",
|
|
2376
2431
|
{
|
|
2377
2432
|
onClick: () => onRemoveImage(index),
|
|
@@ -2406,12 +2461,12 @@ var ImageUploadQueue = ({
|
|
|
2406
2461
|
|
|
2407
2462
|
// src/components/chat/Suggestion.tsx
|
|
2408
2463
|
var import_react_core8 = require("@copilotkit/react-core");
|
|
2409
|
-
var
|
|
2464
|
+
var import_jsx_runtime23 = require("react/jsx-runtime");
|
|
2410
2465
|
function Suggestion({ title, onClick, partial, className }) {
|
|
2411
2466
|
if (!title)
|
|
2412
2467
|
return null;
|
|
2413
2468
|
const { isLoading } = (0, import_react_core8.useCopilotChatInternal)();
|
|
2414
|
-
return /* @__PURE__ */ (0,
|
|
2469
|
+
return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
2415
2470
|
"button",
|
|
2416
2471
|
{
|
|
2417
2472
|
disabled: partial || isLoading,
|
|
@@ -2421,15 +2476,15 @@ function Suggestion({ title, onClick, partial, className }) {
|
|
|
2421
2476
|
},
|
|
2422
2477
|
className: className || (partial ? "suggestion loading" : "suggestion"),
|
|
2423
2478
|
"data-test-id": "suggestion",
|
|
2424
|
-
children: partial ? SmallSpinnerIcon : /* @__PURE__ */ (0,
|
|
2479
|
+
children: partial ? SmallSpinnerIcon : /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { children: title })
|
|
2425
2480
|
}
|
|
2426
2481
|
);
|
|
2427
2482
|
}
|
|
2428
2483
|
|
|
2429
2484
|
// src/components/chat/Suggestions.tsx
|
|
2430
|
-
var
|
|
2485
|
+
var import_jsx_runtime24 = require("react/jsx-runtime");
|
|
2431
2486
|
function Suggestions({ suggestions, onSuggestionClick }) {
|
|
2432
|
-
return /* @__PURE__ */ (0,
|
|
2487
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "suggestions", children: suggestions.map((suggestion, index) => /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
2433
2488
|
Suggestion,
|
|
2434
2489
|
{
|
|
2435
2490
|
title: suggestion.title,
|
|
@@ -2443,7 +2498,7 @@ function Suggestions({ suggestions, onSuggestionClick }) {
|
|
|
2443
2498
|
}
|
|
2444
2499
|
|
|
2445
2500
|
// src/components/chat/Chat.tsx
|
|
2446
|
-
var
|
|
2501
|
+
var import_jsx_runtime25 = require("react/jsx-runtime");
|
|
2447
2502
|
function CopilotChat({
|
|
2448
2503
|
instructions,
|
|
2449
2504
|
suggestions = "auto",
|
|
@@ -2468,11 +2523,13 @@ function CopilotChat({
|
|
|
2468
2523
|
AssistantMessage: AssistantMessage2 = AssistantMessage,
|
|
2469
2524
|
UserMessage: UserMessage2 = UserMessage,
|
|
2470
2525
|
ImageRenderer: ImageRenderer2 = ImageRenderer,
|
|
2526
|
+
ErrorMessage: ErrorMessage2 = ErrorMessage,
|
|
2471
2527
|
imageUploadsEnabled,
|
|
2472
2528
|
inputFileAccept = "image/*",
|
|
2473
2529
|
hideStopButton,
|
|
2474
2530
|
observabilityHooks,
|
|
2475
2531
|
renderError,
|
|
2532
|
+
onError,
|
|
2476
2533
|
// Legacy props - deprecated
|
|
2477
2534
|
RenderTextMessage,
|
|
2478
2535
|
RenderActionExecutionMessage,
|
|
@@ -2480,12 +2537,19 @@ function CopilotChat({
|
|
|
2480
2537
|
RenderResultMessage,
|
|
2481
2538
|
RenderImageMessage
|
|
2482
2539
|
}) {
|
|
2483
|
-
const {
|
|
2540
|
+
const {
|
|
2541
|
+
additionalInstructions,
|
|
2542
|
+
setChatInstructions,
|
|
2543
|
+
copilotApiConfig,
|
|
2544
|
+
setBannerError,
|
|
2545
|
+
setInternalErrorHandler,
|
|
2546
|
+
removeInternalErrorHandler
|
|
2547
|
+
} = (0, import_react_core9.useCopilotContext)();
|
|
2484
2548
|
const { publicApiKey, chatApiEndpoint } = copilotApiConfig;
|
|
2485
|
-
const [selectedImages, setSelectedImages] = (0,
|
|
2486
|
-
const [chatError, setChatError] = (0,
|
|
2487
|
-
const fileInputRef = (0,
|
|
2488
|
-
const triggerObservabilityHook = (0,
|
|
2549
|
+
const [selectedImages, setSelectedImages] = (0, import_react15.useState)([]);
|
|
2550
|
+
const [chatError, setChatError] = (0, import_react15.useState)(null);
|
|
2551
|
+
const fileInputRef = (0, import_react15.useRef)(null);
|
|
2552
|
+
const triggerObservabilityHook = (0, import_react15.useCallback)(
|
|
2489
2553
|
(hookName, ...args) => {
|
|
2490
2554
|
if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
|
|
2491
2555
|
observabilityHooks[hookName](...args);
|
|
@@ -2504,7 +2568,7 @@ function CopilotChat({
|
|
|
2504
2568
|
},
|
|
2505
2569
|
[publicApiKey, observabilityHooks, setBannerError]
|
|
2506
2570
|
);
|
|
2507
|
-
const triggerChatError = (0,
|
|
2571
|
+
const triggerChatError = (0, import_react15.useCallback)(
|
|
2508
2572
|
(error, operation, originalError) => {
|
|
2509
2573
|
const errorMessage = (error == null ? void 0 : error.message) || (error == null ? void 0 : error.toString()) || "An error occurred";
|
|
2510
2574
|
setChatError({
|
|
@@ -2512,25 +2576,28 @@ function CopilotChat({
|
|
|
2512
2576
|
operation,
|
|
2513
2577
|
timestamp: Date.now()
|
|
2514
2578
|
});
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
startTime: Date.now()
|
|
2525
|
-
},
|
|
2526
|
-
technical: {
|
|
2527
|
-
environment: "browser",
|
|
2528
|
-
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
2529
|
-
stackTrace: originalError instanceof Error ? originalError.stack : void 0
|
|
2530
|
-
}
|
|
2579
|
+
const errorEvent = {
|
|
2580
|
+
type: "error",
|
|
2581
|
+
timestamp: Date.now(),
|
|
2582
|
+
context: {
|
|
2583
|
+
source: "ui",
|
|
2584
|
+
request: {
|
|
2585
|
+
operation,
|
|
2586
|
+
url: chatApiEndpoint,
|
|
2587
|
+
startTime: Date.now()
|
|
2531
2588
|
},
|
|
2532
|
-
|
|
2533
|
-
|
|
2589
|
+
technical: {
|
|
2590
|
+
environment: "browser",
|
|
2591
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
2592
|
+
stackTrace: originalError instanceof Error ? originalError.stack : void 0
|
|
2593
|
+
}
|
|
2594
|
+
},
|
|
2595
|
+
error
|
|
2596
|
+
};
|
|
2597
|
+
if (onError) {
|
|
2598
|
+
onError(errorEvent);
|
|
2599
|
+
}
|
|
2600
|
+
if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks.onError)) {
|
|
2534
2601
|
observabilityHooks.onError(errorEvent);
|
|
2535
2602
|
}
|
|
2536
2603
|
if ((observabilityHooks == null ? void 0 : observabilityHooks.onError) && !publicApiKey) {
|
|
@@ -2547,7 +2614,20 @@ function CopilotChat({
|
|
|
2547
2614
|
},
|
|
2548
2615
|
[publicApiKey, chatApiEndpoint, observabilityHooks, setBannerError]
|
|
2549
2616
|
);
|
|
2550
|
-
(0,
|
|
2617
|
+
(0, import_react15.useEffect)(() => {
|
|
2618
|
+
const id = "chat-component";
|
|
2619
|
+
setInternalErrorHandler({
|
|
2620
|
+
[id]: (error) => {
|
|
2621
|
+
if (!error)
|
|
2622
|
+
return;
|
|
2623
|
+
triggerChatError(error.error, "sendMessage");
|
|
2624
|
+
}
|
|
2625
|
+
});
|
|
2626
|
+
return () => {
|
|
2627
|
+
removeInternalErrorHandler == null ? void 0 : removeInternalErrorHandler(id);
|
|
2628
|
+
};
|
|
2629
|
+
}, [triggerChatError, setInternalErrorHandler, removeInternalErrorHandler]);
|
|
2630
|
+
(0, import_react15.useEffect)(() => {
|
|
2551
2631
|
if (!imageUploadsEnabled)
|
|
2552
2632
|
return;
|
|
2553
2633
|
const handlePaste = (e) => __async(this, null, function* () {
|
|
@@ -2593,7 +2673,7 @@ function CopilotChat({
|
|
|
2593
2673
|
document.addEventListener("paste", handlePaste);
|
|
2594
2674
|
return () => document.removeEventListener("paste", handlePaste);
|
|
2595
2675
|
}, [imageUploadsEnabled, triggerChatError]);
|
|
2596
|
-
(0,
|
|
2676
|
+
(0, import_react15.useEffect)(() => {
|
|
2597
2677
|
if (!(additionalInstructions == null ? void 0 : additionalInstructions.length)) {
|
|
2598
2678
|
setChatInstructions(instructions || "");
|
|
2599
2679
|
return;
|
|
@@ -2621,8 +2701,8 @@ function CopilotChat({
|
|
|
2621
2701
|
onStopGeneration,
|
|
2622
2702
|
onReloadMessages
|
|
2623
2703
|
);
|
|
2624
|
-
const prevIsLoading = (0,
|
|
2625
|
-
(0,
|
|
2704
|
+
const prevIsLoading = (0, import_react15.useRef)(isLoading);
|
|
2705
|
+
(0, import_react15.useEffect)(() => {
|
|
2626
2706
|
if (prevIsLoading.current !== isLoading) {
|
|
2627
2707
|
if (isLoading) {
|
|
2628
2708
|
triggerObservabilityHook("onChatStarted");
|
|
@@ -2641,7 +2721,7 @@ function CopilotChat({
|
|
|
2641
2721
|
triggerObservabilityHook("onMessageSent", text);
|
|
2642
2722
|
return sendMessage(text, images);
|
|
2643
2723
|
};
|
|
2644
|
-
const chatContext =
|
|
2724
|
+
const chatContext = import_react15.default.useContext(ChatContext);
|
|
2645
2725
|
const isVisible = chatContext ? chatContext.open : true;
|
|
2646
2726
|
const handleRegenerate = (messageId) => {
|
|
2647
2727
|
if (onRegenerate) {
|
|
@@ -2703,14 +2783,14 @@ function CopilotChat({
|
|
|
2703
2783
|
}
|
|
2704
2784
|
triggerObservabilityHook("onFeedbackGiven", message.id, "thumbsDown");
|
|
2705
2785
|
};
|
|
2706
|
-
return /* @__PURE__ */ (0,
|
|
2786
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(WrappedCopilotChat, { icons, labels, className, children: [
|
|
2707
2787
|
chatError && renderError && renderError(__spreadProps(__spreadValues({}, chatError), {
|
|
2708
2788
|
onDismiss: () => setChatError(null),
|
|
2709
2789
|
onRetry: () => {
|
|
2710
2790
|
setChatError(null);
|
|
2711
2791
|
}
|
|
2712
2792
|
})),
|
|
2713
|
-
/* @__PURE__ */ (0,
|
|
2793
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
2714
2794
|
Messages2,
|
|
2715
2795
|
{
|
|
2716
2796
|
AssistantMessage: AssistantMessage2,
|
|
@@ -2724,12 +2804,14 @@ function CopilotChat({
|
|
|
2724
2804
|
onThumbsDown: handleThumbsDown,
|
|
2725
2805
|
markdownTagRenderers,
|
|
2726
2806
|
ImageRenderer: ImageRenderer2,
|
|
2807
|
+
ErrorMessage: ErrorMessage2,
|
|
2808
|
+
chatError,
|
|
2727
2809
|
RenderTextMessage,
|
|
2728
2810
|
RenderActionExecutionMessage,
|
|
2729
2811
|
RenderAgentStateMessage,
|
|
2730
2812
|
RenderResultMessage,
|
|
2731
2813
|
RenderImageMessage,
|
|
2732
|
-
children: currentSuggestions.length > 0 && /* @__PURE__ */ (0,
|
|
2814
|
+
children: currentSuggestions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
2733
2815
|
RenderSuggestionsList,
|
|
2734
2816
|
{
|
|
2735
2817
|
onSuggestionClick: handleSendMessage,
|
|
@@ -2738,9 +2820,9 @@ function CopilotChat({
|
|
|
2738
2820
|
)
|
|
2739
2821
|
}
|
|
2740
2822
|
),
|
|
2741
|
-
imageUploadsEnabled && /* @__PURE__ */ (0,
|
|
2742
|
-
/* @__PURE__ */ (0,
|
|
2743
|
-
/* @__PURE__ */ (0,
|
|
2823
|
+
imageUploadsEnabled && /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(import_jsx_runtime25.Fragment, { children: [
|
|
2824
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(ImageUploadQueue, { images: selectedImages, onRemoveImage: removeSelectedImage }),
|
|
2825
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
2744
2826
|
"input",
|
|
2745
2827
|
{
|
|
2746
2828
|
type: "file",
|
|
@@ -2752,7 +2834,7 @@ function CopilotChat({
|
|
|
2752
2834
|
}
|
|
2753
2835
|
)
|
|
2754
2836
|
] }),
|
|
2755
|
-
/* @__PURE__ */ (0,
|
|
2837
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
2756
2838
|
Input2,
|
|
2757
2839
|
{
|
|
2758
2840
|
inProgress: isLoading,
|
|
@@ -2774,12 +2856,12 @@ function WrappedCopilotChat({
|
|
|
2774
2856
|
labels,
|
|
2775
2857
|
className
|
|
2776
2858
|
}) {
|
|
2777
|
-
const chatContext =
|
|
2859
|
+
const chatContext = import_react15.default.useContext(ChatContext);
|
|
2778
2860
|
if (!chatContext) {
|
|
2779
|
-
return /* @__PURE__ */ (0,
|
|
2780
|
-
}, children: /* @__PURE__ */ (0,
|
|
2861
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(ChatContextProvider, { icons, labels, open: true, setOpen: () => {
|
|
2862
|
+
}, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: `copilotKitChat ${className != null ? className : ""}`, children }) });
|
|
2781
2863
|
}
|
|
2782
|
-
return /* @__PURE__ */ (0,
|
|
2864
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_jsx_runtime25.Fragment, { children });
|
|
2783
2865
|
}
|
|
2784
2866
|
var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, disableSystemMessage, onInProgress, onSubmitMessage, onStopGeneration, onReloadMessages) => {
|
|
2785
2867
|
var _a;
|
|
@@ -2803,15 +2885,15 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, disableSystemMess
|
|
|
2803
2885
|
const generalContext = (0, import_react_core9.useCopilotContext)();
|
|
2804
2886
|
const messagesContext = (0, import_react_core9.useCopilotMessagesContext)();
|
|
2805
2887
|
const { actions } = generalContext;
|
|
2806
|
-
const [suggestionsFailed, setSuggestionsFailed] = (0,
|
|
2807
|
-
const hasGeneratedInitialSuggestions = (0,
|
|
2808
|
-
(0,
|
|
2888
|
+
const [suggestionsFailed, setSuggestionsFailed] = (0, import_react15.useState)(false);
|
|
2889
|
+
const hasGeneratedInitialSuggestions = (0, import_react15.useRef)(false);
|
|
2890
|
+
(0, import_react15.useEffect)(() => {
|
|
2809
2891
|
if (Array.isArray(chatSuggestions)) {
|
|
2810
2892
|
setSuggestions(chatSuggestions);
|
|
2811
2893
|
hasGeneratedInitialSuggestions.current = true;
|
|
2812
2894
|
}
|
|
2813
2895
|
}, [JSON.stringify(chatSuggestions), setSuggestions]);
|
|
2814
|
-
const generateSuggestionsWithErrorHandling = (0,
|
|
2896
|
+
const generateSuggestionsWithErrorHandling = (0, import_react15.useCallback)(
|
|
2815
2897
|
(context) => __async(void 0, null, function* () {
|
|
2816
2898
|
try {
|
|
2817
2899
|
yield generateSuggestions();
|
|
@@ -2822,7 +2904,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, disableSystemMess
|
|
|
2822
2904
|
}),
|
|
2823
2905
|
[generateSuggestions]
|
|
2824
2906
|
);
|
|
2825
|
-
(0,
|
|
2907
|
+
(0, import_react15.useEffect)(() => {
|
|
2826
2908
|
if (chatSuggestions !== "auto" || isLoadingSuggestions || suggestionsFailed) {
|
|
2827
2909
|
return;
|
|
2828
2910
|
}
|
|
@@ -2852,13 +2934,13 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, disableSystemMess
|
|
|
2852
2934
|
// Use stable string instead of object reference
|
|
2853
2935
|
generateSuggestionsWithErrorHandling
|
|
2854
2936
|
]);
|
|
2855
|
-
(0,
|
|
2937
|
+
(0, import_react15.useEffect)(() => {
|
|
2856
2938
|
if (chatSuggestions !== "auto") {
|
|
2857
2939
|
hasGeneratedInitialSuggestions.current = false;
|
|
2858
2940
|
setSuggestionsFailed(false);
|
|
2859
2941
|
}
|
|
2860
2942
|
}, [chatSuggestions]);
|
|
2861
|
-
const stableContext = (0,
|
|
2943
|
+
const stableContext = (0, import_react15.useMemo)(
|
|
2862
2944
|
() => __spreadValues(__spreadValues({}, generalContext), messagesContext),
|
|
2863
2945
|
[
|
|
2864
2946
|
// Only include stable dependencies
|
|
@@ -2867,12 +2949,12 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, disableSystemMess
|
|
|
2867
2949
|
generalContext.isLoading
|
|
2868
2950
|
]
|
|
2869
2951
|
);
|
|
2870
|
-
const resetSuggestions = (0,
|
|
2952
|
+
const resetSuggestions = (0, import_react15.useCallback)(() => {
|
|
2871
2953
|
resetSuggestionsFromHook();
|
|
2872
2954
|
setSuggestionsFailed(false);
|
|
2873
2955
|
hasGeneratedInitialSuggestions.current = false;
|
|
2874
2956
|
}, [resetSuggestionsFromHook]);
|
|
2875
|
-
(0,
|
|
2957
|
+
(0, import_react15.useEffect)(() => {
|
|
2876
2958
|
onInProgress == null ? void 0 : onInProgress(isLoading);
|
|
2877
2959
|
}, [onInProgress, isLoading]);
|
|
2878
2960
|
const safelySendMessage = (messageContent, imagesToUse) => __async(void 0, null, function* () {
|
|
@@ -3018,7 +3100,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, disableSystemMess
|
|
|
3018
3100
|
// src/components/chat/Modal.tsx
|
|
3019
3101
|
var import_react_core11 = require("@copilotkit/react-core");
|
|
3020
3102
|
var import_shared5 = require("@copilotkit/shared");
|
|
3021
|
-
var
|
|
3103
|
+
var import_jsx_runtime26 = require("react/jsx-runtime");
|
|
3022
3104
|
var CopilotModalInner = (_a) => {
|
|
3023
3105
|
var _b = _a, {
|
|
3024
3106
|
observabilityHooks,
|
|
@@ -3045,7 +3127,7 @@ var CopilotModalInner = (_a) => {
|
|
|
3045
3127
|
]);
|
|
3046
3128
|
const { copilotApiConfig, setBannerError } = (0, import_react_core11.useCopilotContext)();
|
|
3047
3129
|
const { publicApiKey } = copilotApiConfig;
|
|
3048
|
-
const triggerObservabilityHook = (0,
|
|
3130
|
+
const triggerObservabilityHook = (0, import_react16.useCallback)(
|
|
3049
3131
|
(hookName, ...args) => {
|
|
3050
3132
|
if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
|
|
3051
3133
|
observabilityHooks[hookName](...args);
|
|
@@ -3065,8 +3147,8 @@ var CopilotModalInner = (_a) => {
|
|
|
3065
3147
|
[publicApiKey, observabilityHooks, setBannerError]
|
|
3066
3148
|
);
|
|
3067
3149
|
const { open } = useChatContext();
|
|
3068
|
-
const prevOpen = (0,
|
|
3069
|
-
(0,
|
|
3150
|
+
const prevOpen = (0, import_react16.useRef)(open);
|
|
3151
|
+
(0, import_react16.useEffect)(() => {
|
|
3070
3152
|
if (prevOpen.current !== open) {
|
|
3071
3153
|
onSetOpen == null ? void 0 : onSetOpen(open);
|
|
3072
3154
|
if (open) {
|
|
@@ -3077,13 +3159,13 @@ var CopilotModalInner = (_a) => {
|
|
|
3077
3159
|
prevOpen.current = open;
|
|
3078
3160
|
}
|
|
3079
3161
|
}, [open, onSetOpen, triggerObservabilityHook]);
|
|
3080
|
-
const memoizedHeader = (0,
|
|
3081
|
-
const memoizedChildren = (0,
|
|
3082
|
-
return /* @__PURE__ */ (0,
|
|
3162
|
+
const memoizedHeader = (0, import_react16.useMemo)(() => /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(Header2, {}), [Header2]);
|
|
3163
|
+
const memoizedChildren = (0, import_react16.useMemo)(() => children, [children]);
|
|
3164
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(import_jsx_runtime26.Fragment, { children: [
|
|
3083
3165
|
memoizedChildren,
|
|
3084
|
-
/* @__PURE__ */ (0,
|
|
3085
|
-
/* @__PURE__ */ (0,
|
|
3086
|
-
/* @__PURE__ */ (0,
|
|
3166
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("div", { className, children: [
|
|
3167
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)(Button2, {}),
|
|
3168
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(
|
|
3087
3169
|
Window2,
|
|
3088
3170
|
{
|
|
3089
3171
|
clickOutsideToClose,
|
|
@@ -3091,7 +3173,7 @@ var CopilotModalInner = (_a) => {
|
|
|
3091
3173
|
hitEscapeToClose,
|
|
3092
3174
|
children: [
|
|
3093
3175
|
memoizedHeader,
|
|
3094
|
-
/* @__PURE__ */ (0,
|
|
3176
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)(CopilotChat, __spreadProps(__spreadValues({}, chatProps), { observabilityHooks }))
|
|
3095
3177
|
]
|
|
3096
3178
|
}
|
|
3097
3179
|
)
|
|
@@ -3158,8 +3240,8 @@ var CopilotModal = (_a) => {
|
|
|
3158
3240
|
"children",
|
|
3159
3241
|
"observabilityHooks"
|
|
3160
3242
|
]);
|
|
3161
|
-
const [openState, setOpenState] =
|
|
3162
|
-
return /* @__PURE__ */ (0,
|
|
3243
|
+
const [openState, setOpenState] = import_react16.default.useState(defaultOpen);
|
|
3244
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(ChatContextProvider, { icons, labels, open: openState, setOpen: setOpenState, children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
3163
3245
|
CopilotModalInner,
|
|
3164
3246
|
__spreadProps(__spreadValues({
|
|
3165
3247
|
observabilityHooks,
|