@copilotkitnext/react 0.0.34-alpha.0 → 2.0.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +17 -7
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +32 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -18
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +2 -2
- package/package.json +14 -11
package/dist/index.mjs
CHANGED
|
@@ -2293,6 +2293,12 @@ function useHumanInTheLoop(tool, deps) {
|
|
|
2293
2293
|
import { useMemo as useMemo5, useEffect as useEffect8, useReducer as useReducer2 } from "react";
|
|
2294
2294
|
import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID4 } from "@copilotkitnext/shared";
|
|
2295
2295
|
import { ProxiedCopilotRuntimeAgent, CopilotKitCoreRuntimeConnectionStatus } from "@copilotkitnext/core";
|
|
2296
|
+
var UseAgentUpdate = /* @__PURE__ */ ((UseAgentUpdate2) => {
|
|
2297
|
+
UseAgentUpdate2["OnMessagesChanged"] = "OnMessagesChanged";
|
|
2298
|
+
UseAgentUpdate2["OnStateChanged"] = "OnStateChanged";
|
|
2299
|
+
UseAgentUpdate2["OnRunStatusChanged"] = "OnRunStatusChanged";
|
|
2300
|
+
return UseAgentUpdate2;
|
|
2301
|
+
})(UseAgentUpdate || {});
|
|
2296
2302
|
var ALL_UPDATES = [
|
|
2297
2303
|
"OnMessagesChanged" /* OnMessagesChanged */,
|
|
2298
2304
|
"OnStateChanged" /* OnStateChanged */,
|
|
@@ -3210,7 +3216,7 @@ CopilotChatSuggestionView.displayName = "CopilotChatSuggestionView";
|
|
|
3210
3216
|
var CopilotChatSuggestionView_default = CopilotChatSuggestionView;
|
|
3211
3217
|
|
|
3212
3218
|
// src/components/chat/CopilotChatMessageView.tsx
|
|
3213
|
-
import React12 from "react";
|
|
3219
|
+
import React12, { useEffect as useEffect12, useReducer as useReducer3 } from "react";
|
|
3214
3220
|
import { twMerge as twMerge6 } from "tailwind-merge";
|
|
3215
3221
|
import { jsx as jsx18, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
3216
3222
|
var MemoizedAssistantMessage = React12.memo(
|
|
@@ -3304,6 +3310,7 @@ var MemoizedCustomMessage = React12.memo(
|
|
|
3304
3310
|
if (prevProps.position !== nextProps.position) return false;
|
|
3305
3311
|
if (prevProps.message.content !== nextProps.message.content) return false;
|
|
3306
3312
|
if (prevProps.message.role !== nextProps.message.role) return false;
|
|
3313
|
+
if (JSON.stringify(prevProps.stateSnapshot) !== JSON.stringify(nextProps.stateSnapshot)) return false;
|
|
3307
3314
|
return true;
|
|
3308
3315
|
}
|
|
3309
3316
|
);
|
|
@@ -3319,8 +3326,27 @@ function CopilotChatMessageView({
|
|
|
3319
3326
|
}) {
|
|
3320
3327
|
const renderCustomMessage = useRenderCustomMessages();
|
|
3321
3328
|
const renderActivityMessage = useRenderActivityMessage();
|
|
3329
|
+
const { copilotkit } = useCopilotKit();
|
|
3330
|
+
const config = useCopilotChatConfiguration();
|
|
3331
|
+
const [, forceUpdate] = useReducer3((x) => x + 1, 0);
|
|
3332
|
+
useEffect12(() => {
|
|
3333
|
+
if (!config?.agentId) return;
|
|
3334
|
+
const agent = copilotkit.getAgent(config.agentId);
|
|
3335
|
+
if (!agent) return;
|
|
3336
|
+
const subscription = agent.subscribe({
|
|
3337
|
+
onStateChanged: () => forceUpdate()
|
|
3338
|
+
});
|
|
3339
|
+
return () => subscription.unsubscribe();
|
|
3340
|
+
}, [config?.agentId, copilotkit]);
|
|
3341
|
+
const getStateSnapshotForMessage = (messageId) => {
|
|
3342
|
+
if (!config) return void 0;
|
|
3343
|
+
const runId = copilotkit.getRunIdForMessage(config.agentId, config.threadId, messageId);
|
|
3344
|
+
if (!runId) return void 0;
|
|
3345
|
+
return copilotkit.getStateByRun(config.agentId, config.threadId, runId);
|
|
3346
|
+
};
|
|
3322
3347
|
const messageElements = messages.flatMap((message) => {
|
|
3323
3348
|
const elements = [];
|
|
3349
|
+
const stateSnapshot = getStateSnapshotForMessage(message.id);
|
|
3324
3350
|
if (renderCustomMessage) {
|
|
3325
3351
|
elements.push(
|
|
3326
3352
|
/* @__PURE__ */ jsx18(
|
|
@@ -3328,7 +3354,8 @@ function CopilotChatMessageView({
|
|
|
3328
3354
|
{
|
|
3329
3355
|
message,
|
|
3330
3356
|
position: "before",
|
|
3331
|
-
renderCustomMessage
|
|
3357
|
+
renderCustomMessage,
|
|
3358
|
+
stateSnapshot
|
|
3332
3359
|
},
|
|
3333
3360
|
`${message.id}-custom-before`
|
|
3334
3361
|
)
|
|
@@ -3379,7 +3406,8 @@ function CopilotChatMessageView({
|
|
|
3379
3406
|
{
|
|
3380
3407
|
message,
|
|
3381
3408
|
position: "after",
|
|
3382
|
-
renderCustomMessage
|
|
3409
|
+
renderCustomMessage,
|
|
3410
|
+
stateSnapshot
|
|
3383
3411
|
},
|
|
3384
3412
|
`${message.id}-custom-after`
|
|
3385
3413
|
)
|
|
@@ -3407,13 +3435,13 @@ CopilotChatMessageView.Cursor = function Cursor({ className, ...props }) {
|
|
|
3407
3435
|
var CopilotChatMessageView_default = CopilotChatMessageView;
|
|
3408
3436
|
|
|
3409
3437
|
// src/components/chat/CopilotChatView.tsx
|
|
3410
|
-
import React13, { useRef as useRef7, useState as useState10, useEffect as
|
|
3438
|
+
import React13, { useRef as useRef7, useState as useState10, useEffect as useEffect14 } from "react";
|
|
3411
3439
|
import { twMerge as twMerge7 } from "tailwind-merge";
|
|
3412
3440
|
import { StickToBottom, useStickToBottom, useStickToBottomContext } from "use-stick-to-bottom";
|
|
3413
3441
|
import { ChevronDown } from "lucide-react";
|
|
3414
3442
|
|
|
3415
3443
|
// src/hooks/use-keyboard-height.tsx
|
|
3416
|
-
import { useState as useState9, useEffect as
|
|
3444
|
+
import { useState as useState9, useEffect as useEffect13 } from "react";
|
|
3417
3445
|
function useKeyboardHeight() {
|
|
3418
3446
|
const [keyboardState, setKeyboardState] = useState9({
|
|
3419
3447
|
isKeyboardOpen: false,
|
|
@@ -3421,7 +3449,7 @@ function useKeyboardHeight() {
|
|
|
3421
3449
|
availableHeight: typeof window !== "undefined" ? window.innerHeight : 0,
|
|
3422
3450
|
viewportHeight: typeof window !== "undefined" ? window.innerHeight : 0
|
|
3423
3451
|
});
|
|
3424
|
-
|
|
3452
|
+
useEffect13(() => {
|
|
3425
3453
|
if (typeof window === "undefined") {
|
|
3426
3454
|
return;
|
|
3427
3455
|
}
|
|
@@ -3479,7 +3507,7 @@ function CopilotChatView({
|
|
|
3479
3507
|
const [isResizing, setIsResizing] = useState10(false);
|
|
3480
3508
|
const resizeTimeoutRef = useRef7(null);
|
|
3481
3509
|
const { isKeyboardOpen, keyboardHeight, availableHeight } = useKeyboardHeight();
|
|
3482
|
-
|
|
3510
|
+
useEffect14(() => {
|
|
3483
3511
|
const element = inputContainerRef.current;
|
|
3484
3512
|
if (!element) return;
|
|
3485
3513
|
const resizeObserver = new ResizeObserver((entries) => {
|
|
@@ -3591,10 +3619,10 @@ function CopilotChatView({
|
|
|
3591
3619
|
const [hasMounted, setHasMounted] = useState10(false);
|
|
3592
3620
|
const { scrollRef, contentRef, scrollToBottom } = useStickToBottom();
|
|
3593
3621
|
const [showScrollButton, setShowScrollButton] = useState10(false);
|
|
3594
|
-
|
|
3622
|
+
useEffect14(() => {
|
|
3595
3623
|
setHasMounted(true);
|
|
3596
3624
|
}, []);
|
|
3597
|
-
|
|
3625
|
+
useEffect14(() => {
|
|
3598
3626
|
if (autoScroll) return;
|
|
3599
3627
|
const scrollElement = scrollRef.current;
|
|
3600
3628
|
if (!scrollElement) return;
|
|
@@ -3726,7 +3754,7 @@ var CopilotChatView_default = CopilotChatView;
|
|
|
3726
3754
|
|
|
3727
3755
|
// src/components/chat/CopilotChat.tsx
|
|
3728
3756
|
import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID7, randomUUID as randomUUID2 } from "@copilotkitnext/shared";
|
|
3729
|
-
import { useCallback as useCallback8, useEffect as
|
|
3757
|
+
import { useCallback as useCallback8, useEffect as useEffect15, useMemo as useMemo10 } from "react";
|
|
3730
3758
|
import { merge } from "ts-deepmerge";
|
|
3731
3759
|
import { AGUIConnectNotImplementedError } from "@ag-ui/client";
|
|
3732
3760
|
import { jsx as jsx20 } from "react/jsx-runtime";
|
|
@@ -3746,7 +3774,7 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
3746
3774
|
suggestionView: providedSuggestionView,
|
|
3747
3775
|
...restProps
|
|
3748
3776
|
} = props;
|
|
3749
|
-
|
|
3777
|
+
useEffect15(() => {
|
|
3750
3778
|
const connect = async (agent2) => {
|
|
3751
3779
|
try {
|
|
3752
3780
|
await copilotkit.connectAgent({ agent: agent2 });
|
|
@@ -3965,7 +3993,7 @@ CopilotChatToggleButton.displayName = "CopilotChatToggleButton";
|
|
|
3965
3993
|
var CopilotChatToggleButton_default = CopilotChatToggleButton;
|
|
3966
3994
|
|
|
3967
3995
|
// src/components/chat/CopilotSidebarView.tsx
|
|
3968
|
-
import { useEffect as
|
|
3996
|
+
import { useEffect as useEffect16, useRef as useRef8, useState as useState12 } from "react";
|
|
3969
3997
|
|
|
3970
3998
|
// src/components/chat/CopilotModalHeader.tsx
|
|
3971
3999
|
import { useCallback as useCallback9 } from "react";
|
|
@@ -4069,7 +4097,7 @@ function CopilotSidebarView({ header, width, ...props }) {
|
|
|
4069
4097
|
}
|
|
4070
4098
|
return w;
|
|
4071
4099
|
};
|
|
4072
|
-
|
|
4100
|
+
useEffect16(() => {
|
|
4073
4101
|
if (width !== void 0) {
|
|
4074
4102
|
return;
|
|
4075
4103
|
}
|
|
@@ -4148,7 +4176,7 @@ function CopilotSidebarView({ header, width, ...props }) {
|
|
|
4148
4176
|
CopilotSidebarView.displayName = "CopilotSidebarView";
|
|
4149
4177
|
|
|
4150
4178
|
// src/components/chat/CopilotPopupView.tsx
|
|
4151
|
-
import { useEffect as
|
|
4179
|
+
import { useEffect as useEffect17, useMemo as useMemo11, useRef as useRef9, useState as useState13 } from "react";
|
|
4152
4180
|
import { Fragment as Fragment8, jsx as jsx24, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
4153
4181
|
var DEFAULT_POPUP_WIDTH = 420;
|
|
4154
4182
|
var DEFAULT_POPUP_HEIGHT = 560;
|
|
@@ -4176,7 +4204,7 @@ function CopilotPopupView({
|
|
|
4176
4204
|
const containerRef = useRef9(null);
|
|
4177
4205
|
const [isRendered, setIsRendered] = useState13(isPopupOpen);
|
|
4178
4206
|
const [isAnimatingOut, setIsAnimatingOut] = useState13(false);
|
|
4179
|
-
|
|
4207
|
+
useEffect17(() => {
|
|
4180
4208
|
if (isPopupOpen) {
|
|
4181
4209
|
setIsRendered(true);
|
|
4182
4210
|
setIsAnimatingOut(false);
|
|
@@ -4192,7 +4220,7 @@ function CopilotPopupView({
|
|
|
4192
4220
|
}, 200);
|
|
4193
4221
|
return () => clearTimeout(timeout);
|
|
4194
4222
|
}, [isPopupOpen, isRendered]);
|
|
4195
|
-
|
|
4223
|
+
useEffect17(() => {
|
|
4196
4224
|
if (!isPopupOpen) {
|
|
4197
4225
|
return;
|
|
4198
4226
|
}
|
|
@@ -4208,7 +4236,7 @@ function CopilotPopupView({
|
|
|
4208
4236
|
window.addEventListener("keydown", handleKeyDown);
|
|
4209
4237
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
4210
4238
|
}, [isPopupOpen, setModalOpen]);
|
|
4211
|
-
|
|
4239
|
+
useEffect17(() => {
|
|
4212
4240
|
if (!isPopupOpen) {
|
|
4213
4241
|
return;
|
|
4214
4242
|
}
|
|
@@ -4217,7 +4245,7 @@ function CopilotPopupView({
|
|
|
4217
4245
|
}, 200);
|
|
4218
4246
|
return () => clearTimeout(focusTimer);
|
|
4219
4247
|
}, [isPopupOpen]);
|
|
4220
|
-
|
|
4248
|
+
useEffect17(() => {
|
|
4221
4249
|
if (!isPopupOpen || !clickOutsideToClose) {
|
|
4222
4250
|
return;
|
|
4223
4251
|
}
|
|
@@ -4481,6 +4509,7 @@ export {
|
|
|
4481
4509
|
MCPAppsActivityContentSchema,
|
|
4482
4510
|
MCPAppsActivityRenderer,
|
|
4483
4511
|
MCPAppsActivityType,
|
|
4512
|
+
UseAgentUpdate,
|
|
4484
4513
|
WildcardToolCallRender,
|
|
4485
4514
|
defineToolCallRenderer,
|
|
4486
4515
|
useAgent,
|