@copilotkit/react-ui 1.10.0-next.4 → 1.10.0-next.5
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 +10 -0
- package/dist/{chunk-WYEGK6BP.mjs → chunk-BXX6RM44.mjs} +2 -2
- package/dist/chunk-BXX6RM44.mjs.map +1 -0
- package/dist/chunk-BY42E5VF.mjs +203 -0
- package/dist/chunk-BY42E5VF.mjs.map +1 -0
- package/dist/{chunk-P6O2MZGT.mjs → chunk-K344MVUT.mjs} +58 -5
- package/dist/chunk-K344MVUT.mjs.map +1 -0
- package/dist/{chunk-2TABXABK.mjs → chunk-MYWIJSW6.mjs} +2 -2
- package/dist/chunk-MYWIJSW6.mjs.map +1 -0
- package/dist/components/chat/Chat.d.ts +10 -5
- package/dist/components/chat/Chat.js +54 -7
- package/dist/components/chat/Chat.js.map +1 -1
- package/dist/components/chat/Chat.mjs +1 -1
- package/dist/components/chat/Modal.d.ts +1 -1
- package/dist/components/chat/Modal.js +157 -52
- package/dist/components/chat/Modal.js.map +1 -1
- package/dist/components/chat/Modal.mjs +2 -2
- package/dist/components/chat/Popup.js +157 -52
- package/dist/components/chat/Popup.js.map +1 -1
- package/dist/components/chat/Popup.mjs +3 -3
- package/dist/components/chat/Sidebar.js +157 -52
- package/dist/components/chat/Sidebar.js.map +1 -1
- package/dist/components/chat/Sidebar.mjs +3 -3
- package/dist/components/chat/index.d.ts +1 -1
- package/dist/components/chat/index.js +157 -52
- package/dist/components/chat/index.js.map +1 -1
- package/dist/components/chat/index.mjs +4 -4
- package/dist/components/chat/props.d.ts +39 -1
- package/dist/components/chat/props.js.map +1 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +157 -52
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +161 -56
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -4
- package/package.json +4 -4
- package/src/components/chat/Chat.tsx +98 -4
- package/src/components/chat/Modal.tsx +107 -41
- package/src/components/chat/Popup.tsx +20 -0
- package/src/components/chat/Sidebar.tsx +22 -0
- package/src/components/chat/props.ts +46 -0
- package/dist/chunk-2TABXABK.mjs.map +0 -1
- package/dist/chunk-P6O2MZGT.mjs.map +0 -1
- package/dist/chunk-QKDRZ7WA.mjs +0 -144
- package/dist/chunk-QKDRZ7WA.mjs.map +0 -1
- package/dist/chunk-WYEGK6BP.mjs.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CopilotPopup
|
|
3
|
-
} from "../../chunk-
|
|
4
|
-
import "../../chunk-
|
|
3
|
+
} from "../../chunk-BXX6RM44.mjs";
|
|
4
|
+
import "../../chunk-BY42E5VF.mjs";
|
|
5
5
|
import "../../chunk-C3GSYRC3.mjs";
|
|
6
6
|
import "../../chunk-GDSZGYCE.mjs";
|
|
7
7
|
import "../../chunk-V7W6IM2V.mjs";
|
|
@@ -12,7 +12,7 @@ import "../../chunk-KXE2JCUH.mjs";
|
|
|
12
12
|
import "../../chunk-NRA3CFEE.mjs";
|
|
13
13
|
import "../../chunk-BH6PCAAL.mjs";
|
|
14
14
|
import "../../chunk-UFN2VWSR.mjs";
|
|
15
|
-
import "../../chunk-
|
|
15
|
+
import "../../chunk-K344MVUT.mjs";
|
|
16
16
|
import "../../chunk-JHUTTP5C.mjs";
|
|
17
17
|
import "../../chunk-GCKKSSBU.mjs";
|
|
18
18
|
import "../../chunk-DBKRAOH7.mjs";
|
|
@@ -2169,6 +2169,7 @@ function RenderMessage(_a) {
|
|
|
2169
2169
|
var import_react14 = __toESM(require("react"));
|
|
2170
2170
|
var import_react_core9 = require("@copilotkit/react-core");
|
|
2171
2171
|
var import_shared3 = require("@copilotkit/shared");
|
|
2172
|
+
var import_shared4 = require("@copilotkit/shared");
|
|
2172
2173
|
var import_react_core10 = require("@copilotkit/react-core");
|
|
2173
2174
|
|
|
2174
2175
|
// src/components/chat/ImageUploadQueue.tsx
|
|
@@ -2314,11 +2315,31 @@ function CopilotChat({
|
|
|
2314
2315
|
ImageRenderer: ImageRenderer2 = ImageRenderer,
|
|
2315
2316
|
imageUploadsEnabled,
|
|
2316
2317
|
inputFileAccept = "image/*",
|
|
2317
|
-
hideStopButton
|
|
2318
|
+
hideStopButton,
|
|
2319
|
+
observabilityHooks
|
|
2318
2320
|
}) {
|
|
2319
|
-
const { additionalInstructions, setChatInstructions } = (0, import_react_core9.useCopilotContext)();
|
|
2321
|
+
const { additionalInstructions, setChatInstructions, copilotApiConfig, setBannerError } = (0, import_react_core9.useCopilotContext)();
|
|
2320
2322
|
const [selectedImages, setSelectedImages] = (0, import_react14.useState)([]);
|
|
2321
2323
|
const fileInputRef = (0, import_react14.useRef)(null);
|
|
2324
|
+
const triggerObservabilityHook = (0, import_react14.useCallback)(
|
|
2325
|
+
(hookName, ...args) => {
|
|
2326
|
+
if (copilotApiConfig.publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
|
|
2327
|
+
observabilityHooks[hookName](...args);
|
|
2328
|
+
}
|
|
2329
|
+
if ((observabilityHooks == null ? void 0 : observabilityHooks[hookName]) && !copilotApiConfig.publicApiKey) {
|
|
2330
|
+
setBannerError(
|
|
2331
|
+
new import_shared3.CopilotKitError({
|
|
2332
|
+
message: "observabilityHooks requires a publicApiKey to function.",
|
|
2333
|
+
code: import_shared3.CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,
|
|
2334
|
+
severity: import_shared3.Severity.CRITICAL,
|
|
2335
|
+
visibility: import_shared3.ErrorVisibility.BANNER
|
|
2336
|
+
})
|
|
2337
|
+
);
|
|
2338
|
+
import_shared3.styledConsole.publicApiKeyRequired("observabilityHooks");
|
|
2339
|
+
}
|
|
2340
|
+
},
|
|
2341
|
+
[copilotApiConfig.publicApiKey, observabilityHooks]
|
|
2342
|
+
);
|
|
2322
2343
|
(0, import_react14.useEffect)(() => {
|
|
2323
2344
|
if (!imageUploadsEnabled)
|
|
2324
2345
|
return;
|
|
@@ -2391,12 +2412,24 @@ function CopilotChat({
|
|
|
2391
2412
|
onStopGeneration,
|
|
2392
2413
|
onReloadMessages
|
|
2393
2414
|
);
|
|
2415
|
+
const prevIsLoading = (0, import_react14.useRef)(isLoading);
|
|
2416
|
+
(0, import_react14.useEffect)(() => {
|
|
2417
|
+
if (prevIsLoading.current !== isLoading) {
|
|
2418
|
+
if (isLoading) {
|
|
2419
|
+
triggerObservabilityHook("onChatStarted");
|
|
2420
|
+
} else {
|
|
2421
|
+
triggerObservabilityHook("onChatStopped");
|
|
2422
|
+
}
|
|
2423
|
+
prevIsLoading.current = isLoading;
|
|
2424
|
+
}
|
|
2425
|
+
}, [isLoading, triggerObservabilityHook]);
|
|
2394
2426
|
const handleSendMessage = (text) => {
|
|
2395
2427
|
const images = selectedImages;
|
|
2396
2428
|
setSelectedImages([]);
|
|
2397
2429
|
if (fileInputRef.current) {
|
|
2398
2430
|
fileInputRef.current.value = "";
|
|
2399
2431
|
}
|
|
2432
|
+
triggerObservabilityHook("onMessageSent", text);
|
|
2400
2433
|
return sendMessage(text, images);
|
|
2401
2434
|
};
|
|
2402
2435
|
const chatContext = import_react14.default.useContext(ChatContext);
|
|
@@ -2405,12 +2438,14 @@ function CopilotChat({
|
|
|
2405
2438
|
if (onRegenerate) {
|
|
2406
2439
|
onRegenerate(messageId);
|
|
2407
2440
|
}
|
|
2441
|
+
triggerObservabilityHook("onMessageRegenerated", messageId);
|
|
2408
2442
|
reloadMessages(messageId);
|
|
2409
2443
|
};
|
|
2410
2444
|
const handleCopy = (message) => {
|
|
2411
2445
|
if (onCopy) {
|
|
2412
2446
|
onCopy(message);
|
|
2413
2447
|
}
|
|
2448
|
+
triggerObservabilityHook("onMessageCopied", message);
|
|
2414
2449
|
};
|
|
2415
2450
|
const handleImageUpload = (event) => __async(this, null, function* () {
|
|
2416
2451
|
if (!event.target.files || event.target.files.length === 0) {
|
|
@@ -2446,6 +2481,18 @@ function CopilotChat({
|
|
|
2446
2481
|
const removeSelectedImage = (index) => {
|
|
2447
2482
|
setSelectedImages((prev) => prev.filter((_, i) => i !== index));
|
|
2448
2483
|
};
|
|
2484
|
+
const handleThumbsUp = (message) => {
|
|
2485
|
+
if (onThumbsUp) {
|
|
2486
|
+
onThumbsUp(message);
|
|
2487
|
+
}
|
|
2488
|
+
triggerObservabilityHook("onFeedbackGiven", message.id, "thumbsUp");
|
|
2489
|
+
};
|
|
2490
|
+
const handleThumbsDown = (message) => {
|
|
2491
|
+
if (onThumbsDown) {
|
|
2492
|
+
onThumbsDown(message);
|
|
2493
|
+
}
|
|
2494
|
+
triggerObservabilityHook("onFeedbackGiven", message.id, "thumbsDown");
|
|
2495
|
+
};
|
|
2449
2496
|
return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(WrappedCopilotChat, { icons, labels, className, children: [
|
|
2450
2497
|
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
2451
2498
|
Messages2,
|
|
@@ -2457,8 +2504,8 @@ function CopilotChat({
|
|
|
2457
2504
|
inProgress: isLoading,
|
|
2458
2505
|
onRegenerate: handleRegenerate,
|
|
2459
2506
|
onCopy: handleCopy,
|
|
2460
|
-
onThumbsUp,
|
|
2461
|
-
onThumbsDown,
|
|
2507
|
+
onThumbsUp: handleThumbsUp,
|
|
2508
|
+
onThumbsDown: handleThumbsDown,
|
|
2462
2509
|
markdownTagRenderers,
|
|
2463
2510
|
ImageRenderer: ImageRenderer2,
|
|
2464
2511
|
children: currentSuggestions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
@@ -2614,7 +2661,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
|
|
|
2614
2661
|
let firstMessage = null;
|
|
2615
2662
|
if (messageContent.trim().length > 0) {
|
|
2616
2663
|
const textMessage = {
|
|
2617
|
-
id: (0,
|
|
2664
|
+
id: (0, import_shared4.randomId)(),
|
|
2618
2665
|
role: "user",
|
|
2619
2666
|
content: messageContent
|
|
2620
2667
|
};
|
|
@@ -2636,7 +2683,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
|
|
|
2636
2683
|
if (images.length > 0) {
|
|
2637
2684
|
for (let i = 0; i < images.length; i++) {
|
|
2638
2685
|
const imageMessage = {
|
|
2639
|
-
id: (0,
|
|
2686
|
+
id: (0, import_shared4.randomId)(),
|
|
2640
2687
|
role: "user",
|
|
2641
2688
|
image: {
|
|
2642
2689
|
format: images[i].contentType.replace("image/", ""),
|
|
@@ -2650,7 +2697,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
|
|
|
2650
2697
|
}
|
|
2651
2698
|
}
|
|
2652
2699
|
if (!firstMessage) {
|
|
2653
|
-
return { role: "user", content: "", id: (0,
|
|
2700
|
+
return { role: "user", content: "", id: (0, import_shared4.randomId)() };
|
|
2654
2701
|
}
|
|
2655
2702
|
return firstMessage;
|
|
2656
2703
|
});
|
|
@@ -2749,7 +2796,75 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
|
|
|
2749
2796
|
};
|
|
2750
2797
|
|
|
2751
2798
|
// src/components/chat/Modal.tsx
|
|
2799
|
+
var import_react_core11 = require("@copilotkit/react-core");
|
|
2752
2800
|
var import_jsx_runtime24 = require("react/jsx-runtime");
|
|
2801
|
+
var CopilotModalInner = (_a) => {
|
|
2802
|
+
var _b = _a, {
|
|
2803
|
+
observabilityHooks,
|
|
2804
|
+
onSetOpen,
|
|
2805
|
+
clickOutsideToClose,
|
|
2806
|
+
hitEscapeToClose,
|
|
2807
|
+
shortcut,
|
|
2808
|
+
className,
|
|
2809
|
+
children,
|
|
2810
|
+
Window: Window2,
|
|
2811
|
+
Button: Button2,
|
|
2812
|
+
Header: Header2
|
|
2813
|
+
} = _b, chatProps = __objRest(_b, [
|
|
2814
|
+
"observabilityHooks",
|
|
2815
|
+
"onSetOpen",
|
|
2816
|
+
"clickOutsideToClose",
|
|
2817
|
+
"hitEscapeToClose",
|
|
2818
|
+
"shortcut",
|
|
2819
|
+
"className",
|
|
2820
|
+
"children",
|
|
2821
|
+
"Window",
|
|
2822
|
+
"Button",
|
|
2823
|
+
"Header"
|
|
2824
|
+
]);
|
|
2825
|
+
const { copilotApiConfig } = (0, import_react_core11.useCopilotContext)();
|
|
2826
|
+
const triggerObservabilityHook = (0, import_react15.useCallback)(
|
|
2827
|
+
(hookName, ...args) => {
|
|
2828
|
+
if (copilotApiConfig.publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
|
|
2829
|
+
observabilityHooks[hookName](...args);
|
|
2830
|
+
}
|
|
2831
|
+
},
|
|
2832
|
+
[copilotApiConfig.publicApiKey, observabilityHooks]
|
|
2833
|
+
);
|
|
2834
|
+
const { open } = useChatContext();
|
|
2835
|
+
const prevOpen = (0, import_react15.useRef)(open);
|
|
2836
|
+
(0, import_react15.useEffect)(() => {
|
|
2837
|
+
if (prevOpen.current !== open) {
|
|
2838
|
+
onSetOpen == null ? void 0 : onSetOpen(open);
|
|
2839
|
+
if (open) {
|
|
2840
|
+
triggerObservabilityHook("onChatExpanded");
|
|
2841
|
+
} else {
|
|
2842
|
+
triggerObservabilityHook("onChatMinimized");
|
|
2843
|
+
}
|
|
2844
|
+
prevOpen.current = open;
|
|
2845
|
+
}
|
|
2846
|
+
}, [open, onSetOpen, triggerObservabilityHook]);
|
|
2847
|
+
const memoizedHeader = (0, import_react15.useMemo)(() => /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Header2, {}), [Header2]);
|
|
2848
|
+
const memoizedChildren = (0, import_react15.useMemo)(() => children, [children]);
|
|
2849
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(import_jsx_runtime24.Fragment, { children: [
|
|
2850
|
+
memoizedChildren,
|
|
2851
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className, children: [
|
|
2852
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Button2, {}),
|
|
2853
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
|
|
2854
|
+
Window2,
|
|
2855
|
+
{
|
|
2856
|
+
clickOutsideToClose,
|
|
2857
|
+
shortcut,
|
|
2858
|
+
hitEscapeToClose,
|
|
2859
|
+
children: [
|
|
2860
|
+
memoizedHeader,
|
|
2861
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(CopilotChat, __spreadProps(__spreadValues({}, chatProps), { observabilityHooks }))
|
|
2862
|
+
]
|
|
2863
|
+
}
|
|
2864
|
+
)
|
|
2865
|
+
] })
|
|
2866
|
+
] });
|
|
2867
|
+
};
|
|
2753
2868
|
var CopilotModal = (_a) => {
|
|
2754
2869
|
var _b = _a, {
|
|
2755
2870
|
instructions,
|
|
@@ -2778,7 +2893,8 @@ var CopilotModal = (_a) => {
|
|
|
2778
2893
|
onRegenerate,
|
|
2779
2894
|
markdownTagRenderers,
|
|
2780
2895
|
className,
|
|
2781
|
-
children
|
|
2896
|
+
children,
|
|
2897
|
+
observabilityHooks
|
|
2782
2898
|
} = _b, props = __objRest(_b, [
|
|
2783
2899
|
"instructions",
|
|
2784
2900
|
"defaultOpen",
|
|
@@ -2806,52 +2922,41 @@ var CopilotModal = (_a) => {
|
|
|
2806
2922
|
"onRegenerate",
|
|
2807
2923
|
"markdownTagRenderers",
|
|
2808
2924
|
"className",
|
|
2809
|
-
"children"
|
|
2925
|
+
"children",
|
|
2926
|
+
"observabilityHooks"
|
|
2810
2927
|
]);
|
|
2811
2928
|
const [openState, setOpenState] = import_react15.default.useState(defaultOpen);
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
onThumbsUp,
|
|
2844
|
-
onThumbsDown,
|
|
2845
|
-
onCopy,
|
|
2846
|
-
onRegenerate,
|
|
2847
|
-
markdownTagRenderers
|
|
2848
|
-
})
|
|
2849
|
-
)
|
|
2850
|
-
]
|
|
2851
|
-
}
|
|
2852
|
-
)
|
|
2853
|
-
] })
|
|
2854
|
-
] });
|
|
2929
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ChatContextProvider, { icons, labels, open: openState, setOpen: setOpenState, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
2930
|
+
CopilotModalInner,
|
|
2931
|
+
__spreadProps(__spreadValues({
|
|
2932
|
+
observabilityHooks,
|
|
2933
|
+
onSetOpen,
|
|
2934
|
+
clickOutsideToClose: clickOutsideToClose != null ? clickOutsideToClose : true,
|
|
2935
|
+
hitEscapeToClose: hitEscapeToClose != null ? hitEscapeToClose : true,
|
|
2936
|
+
shortcut: shortcut != null ? shortcut : "/",
|
|
2937
|
+
className,
|
|
2938
|
+
Window: Window2,
|
|
2939
|
+
Button: Button2,
|
|
2940
|
+
Header: Header2,
|
|
2941
|
+
instructions,
|
|
2942
|
+
onSubmitMessage,
|
|
2943
|
+
onStopGeneration,
|
|
2944
|
+
onReloadMessages,
|
|
2945
|
+
makeSystemMessage,
|
|
2946
|
+
onInProgress,
|
|
2947
|
+
Messages: Messages2,
|
|
2948
|
+
Input: Input2,
|
|
2949
|
+
AssistantMessage: AssistantMessage2,
|
|
2950
|
+
UserMessage: UserMessage2,
|
|
2951
|
+
onThumbsUp,
|
|
2952
|
+
onThumbsDown,
|
|
2953
|
+
onCopy,
|
|
2954
|
+
onRegenerate,
|
|
2955
|
+
markdownTagRenderers
|
|
2956
|
+
}, props), {
|
|
2957
|
+
children
|
|
2958
|
+
})
|
|
2959
|
+
) });
|
|
2855
2960
|
};
|
|
2856
2961
|
|
|
2857
2962
|
// src/components/chat/Sidebar.tsx
|