@copilotkit/react-core 1.63.1 → 1.63.2-canary.1784918757
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/{copilotkit-CN_LykOC.d.mts → copilotkit-BE1n5tSI.d.mts} +16 -1
- package/dist/copilotkit-BE1n5tSI.d.mts.map +1 -0
- package/dist/{copilotkit-BHs-vx6l.d.cts → copilotkit-CXvuYw_F.d.cts} +16 -1
- package/dist/copilotkit-CXvuYw_F.d.cts.map +1 -0
- package/dist/{copilotkit-BLh58_Tt.mjs → copilotkit-DL0LvmwQ.mjs} +169 -141
- package/dist/copilotkit-DL0LvmwQ.mjs.map +1 -0
- package/dist/{copilotkit-nu7NwzH6.cjs → copilotkit-rYTwMndy.cjs} +169 -141
- package/dist/copilotkit-rYTwMndy.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.umd.js +103 -122
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/headless.cjs +177 -119
- package/dist/v2/headless.cjs.map +1 -1
- package/dist/v2/headless.d.cts +45 -2
- package/dist/v2/headless.d.cts.map +1 -1
- package/dist/v2/headless.d.mts +34 -3
- package/dist/v2/headless.d.mts.map +1 -1
- package/dist/v2/headless.mjs +183 -133
- package/dist/v2/headless.mjs.map +1 -1
- package/dist/v2/index.cjs +1 -1
- package/dist/v2/index.d.cts +1 -1
- package/dist/v2/index.d.mts +1 -1
- package/dist/v2/index.mjs +1 -1
- package/dist/v2/index.umd.js +168 -140
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +7 -7
- package/dist/copilotkit-BHs-vx6l.d.cts.map +0 -1
- package/dist/copilotkit-BLh58_Tt.mjs.map +0 -1
- package/dist/copilotkit-CN_LykOC.d.mts.map +0 -1
- package/dist/copilotkit-nu7NwzH6.cjs.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React$1 from "react";
|
|
2
2
|
import React, { createContext, forwardRef, memo, useCallback, useContext, useEffect, useId, useImperativeHandle, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore } from "react";
|
|
3
|
-
import { CopilotKitCore, CopilotKitCoreRuntimeConnectionStatus, ProxiedCopilotRuntimeAgent, ToolCallStatus, isRunCompletionAware, ɵcreateThreadStore, ɵselectFetchMoreError, ɵselectHasNextPage, ɵselectIsFetchingNextPage, ɵselectIsMutating, ɵselectMemories, ɵselectMemoriesAvailable, ɵselectMemoriesError, ɵselectMemoriesIsLoading, ɵselectMemoriesRealtimeStatus, ɵselectThreads, ɵselectThreadsError, ɵselectThreadsIsLoading } from "@copilotkit/core";
|
|
4
|
-
import { HttpAgent,
|
|
3
|
+
import { CopilotKitCore, CopilotKitCoreRuntimeConnectionStatus, ProxiedCopilotRuntimeAgent, ToolCallStatus, isRunCompletionAware, ɵInterruptState, ɵcreateThreadStore, ɵselectFetchMoreError, ɵselectHasNextPage, ɵselectIsFetchingNextPage, ɵselectIsMutating, ɵselectMemories, ɵselectMemoriesAvailable, ɵselectMemoriesError, ɵselectMemoriesIsLoading, ɵselectMemoriesRealtimeStatus, ɵselectThreads, ɵselectThreadsError, ɵselectThreadsIsLoading } from "@copilotkit/core";
|
|
4
|
+
import { HttpAgent, randomUUID } from "@ag-ui/client";
|
|
5
5
|
import { extendTailwindMerge, twMerge } from "tailwind-merge";
|
|
6
6
|
import { ArrowUp, Check, ChevronDown, ChevronLeft, ChevronRight, ChevronRightIcon, Copy, Edit, Loader2, MessageCircle, Mic, PanelLeftOpen, Play, Plus, RefreshCw, Square, ThumbsDown, ThumbsUp, Upload, Volume2, X } from "lucide-react";
|
|
7
7
|
import { A2UI_DEFAULT_DESIGN_GUIDELINES, A2UI_DEFAULT_GENERATION_GUIDELINES, COPILOT_CLOUD_API_URL, COPILOT_CLOUD_CHAT_URL, COPILOT_CLOUD_PUBLIC_API_KEY_HEADER, ConfigurationError, CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitLowLevelError, CopilotKitRemoteEndpointDiscoveryError, DEFAULT_AGENT_ID, ErrorVisibility, MissingPublicApiKeyError, Severity, TranscriptionErrorCode, TranscriptionErrorCode as TranscriptionErrorCode$1, copyToClipboard, createLicenseContextValue, dataToUUID, exceedsMaxSize, formatFileSize, generateVideoThumbnail, getDocumentIcon, getModalityFromMimeType, getSourceUrl, matchesAcceptFilter, parseJson, partialJSONParse, randomId, randomUUID as randomUUID$1, readFileAsBase64, schemaToJsonSchema } from "@copilotkit/shared";
|
|
@@ -22,7 +22,7 @@ import { StickToBottom, useStickToBottomContext } from "use-stick-to-bottom";
|
|
|
22
22
|
import { COPILOTKIT_THREADS_DRAWER_TAG, defineCopilotKitThreadsDrawer } from "@copilotkit/web-components/threads-drawer";
|
|
23
23
|
import ReactMarkdown from "react-markdown";
|
|
24
24
|
|
|
25
|
-
//#region src/v2/lib/
|
|
25
|
+
//#region src/v2/lib/shallow-stable-ref.ts
|
|
26
26
|
/**
|
|
27
27
|
* Shallow equality comparison for objects.
|
|
28
28
|
*/
|
|
@@ -62,64 +62,6 @@ function useShallowStableRef(value) {
|
|
|
62
62
|
ref.current = value;
|
|
63
63
|
return ref.current;
|
|
64
64
|
}
|
|
65
|
-
/**
|
|
66
|
-
* Check if a value is a React component type (function, class, forwardRef, memo, etc.)
|
|
67
|
-
*/
|
|
68
|
-
function isReactComponentType(value) {
|
|
69
|
-
if (typeof value === "function") return true;
|
|
70
|
-
if (value && typeof value === "object" && "$$typeof" in value && !React.isValidElement(value)) return true;
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Internal function to render a slot value as a React element (non-memoized).
|
|
75
|
-
*/
|
|
76
|
-
function renderSlotElement(slot, DefaultComponent, props) {
|
|
77
|
-
if (typeof slot === "string") {
|
|
78
|
-
const existingClassName = props.className;
|
|
79
|
-
return React.createElement(DefaultComponent, {
|
|
80
|
-
...props,
|
|
81
|
-
className: twMerge(existingClassName, slot)
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
if (isReactComponentType(slot)) return React.createElement(slot, props);
|
|
85
|
-
if (slot && typeof slot === "object" && !React.isValidElement(slot)) return React.createElement(DefaultComponent, {
|
|
86
|
-
...props,
|
|
87
|
-
...slot
|
|
88
|
-
});
|
|
89
|
-
return React.createElement(DefaultComponent, props);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Internal memoized wrapper component for renderSlot.
|
|
93
|
-
* Uses forwardRef to support ref forwarding.
|
|
94
|
-
*/
|
|
95
|
-
const MemoizedSlotWrapper = React.memo(React.forwardRef(function MemoizedSlotWrapper(props, ref) {
|
|
96
|
-
const { $slot, $component, ...rest } = props;
|
|
97
|
-
return renderSlotElement($slot, $component, ref !== null ? {
|
|
98
|
-
...rest,
|
|
99
|
-
ref
|
|
100
|
-
} : rest);
|
|
101
|
-
}), (prev, next) => {
|
|
102
|
-
if (prev.$slot !== next.$slot) return false;
|
|
103
|
-
if (prev.$component !== next.$component) return false;
|
|
104
|
-
const { $slot: _ps, $component: _pc, ...prevRest } = prev;
|
|
105
|
-
const { $slot: _ns, $component: _nc, ...nextRest } = next;
|
|
106
|
-
return shallowEqual(prevRest, nextRest);
|
|
107
|
-
});
|
|
108
|
-
/**
|
|
109
|
-
* Renders a slot value as a memoized React element.
|
|
110
|
-
* Automatically prevents unnecessary re-renders using shallow prop comparison.
|
|
111
|
-
* Supports ref forwarding.
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* renderSlot(customInput, CopilotChatInput, { onSubmit: handleSubmit })
|
|
115
|
-
*/
|
|
116
|
-
function renderSlot(slot, DefaultComponent, props) {
|
|
117
|
-
return React.createElement(MemoizedSlotWrapper, {
|
|
118
|
-
...props,
|
|
119
|
-
$slot: slot,
|
|
120
|
-
$component: DefaultComponent
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
65
|
|
|
124
66
|
//#endregion
|
|
125
67
|
//#region src/v2/providers/CopilotChatConfigurationProvider.tsx
|
|
@@ -423,12 +365,13 @@ function Tooltip({ ...props }) {
|
|
|
423
365
|
...props
|
|
424
366
|
}) });
|
|
425
367
|
}
|
|
426
|
-
function TooltipTrigger({ ...props }) {
|
|
368
|
+
const TooltipTrigger = React$1.forwardRef(function TooltipTrigger({ ...props }, ref) {
|
|
427
369
|
return /* @__PURE__ */ jsx(TooltipPrimitive.Trigger, {
|
|
370
|
+
ref,
|
|
428
371
|
"data-slot": "tooltip-trigger",
|
|
429
372
|
...props
|
|
430
373
|
});
|
|
431
|
-
}
|
|
374
|
+
});
|
|
432
375
|
function TooltipContent({ className, sideOffset = 0, children, ...props }) {
|
|
433
376
|
return /* @__PURE__ */ jsx(TooltipPrimitive.Portal, { children: /* @__PURE__ */ jsxs(TooltipPrimitive.Content, {
|
|
434
377
|
"data-copilotkit": true,
|
|
@@ -448,12 +391,13 @@ function DropdownMenu({ ...props }) {
|
|
|
448
391
|
...props
|
|
449
392
|
});
|
|
450
393
|
}
|
|
451
|
-
function DropdownMenuTrigger({ ...props }) {
|
|
394
|
+
const DropdownMenuTrigger = React$1.forwardRef(function DropdownMenuTrigger({ ...props }, ref) {
|
|
452
395
|
return /* @__PURE__ */ jsx(DropdownMenuPrimitive.Trigger, {
|
|
396
|
+
ref,
|
|
453
397
|
"data-slot": "dropdown-menu-trigger",
|
|
454
398
|
...props
|
|
455
399
|
});
|
|
456
|
-
}
|
|
400
|
+
});
|
|
457
401
|
function DropdownMenuContent({ className, sideOffset = 4, ...props }) {
|
|
458
402
|
return /* @__PURE__ */ jsx(DropdownMenuPrimitive.Portal, { children: /* @__PURE__ */ jsx(DropdownMenuPrimitive.Content, {
|
|
459
403
|
"data-copilotkit": true,
|
|
@@ -702,6 +646,67 @@ const CopilotChatAudioRecorder = forwardRef((props, ref) => {
|
|
|
702
646
|
});
|
|
703
647
|
CopilotChatAudioRecorder.displayName = "CopilotChatAudioRecorder";
|
|
704
648
|
|
|
649
|
+
//#endregion
|
|
650
|
+
//#region src/v2/lib/slots.tsx
|
|
651
|
+
/**
|
|
652
|
+
* Check if a value is a React component type (function, class, forwardRef, memo, etc.)
|
|
653
|
+
*/
|
|
654
|
+
function isReactComponentType(value) {
|
|
655
|
+
if (typeof value === "function") return true;
|
|
656
|
+
if (value && typeof value === "object" && "$$typeof" in value && !React.isValidElement(value)) return true;
|
|
657
|
+
return false;
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Internal function to render a slot value as a React element (non-memoized).
|
|
661
|
+
*/
|
|
662
|
+
function renderSlotElement(slot, DefaultComponent, props) {
|
|
663
|
+
if (typeof slot === "string") {
|
|
664
|
+
const existingClassName = props.className;
|
|
665
|
+
return React.createElement(DefaultComponent, {
|
|
666
|
+
...props,
|
|
667
|
+
className: twMerge(existingClassName, slot)
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
if (isReactComponentType(slot)) return React.createElement(slot, props);
|
|
671
|
+
if (slot && typeof slot === "object" && !React.isValidElement(slot)) return React.createElement(DefaultComponent, {
|
|
672
|
+
...props,
|
|
673
|
+
...slot
|
|
674
|
+
});
|
|
675
|
+
return React.createElement(DefaultComponent, props);
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* Internal memoized wrapper component for renderSlot.
|
|
679
|
+
* Uses forwardRef to support ref forwarding.
|
|
680
|
+
*/
|
|
681
|
+
const MemoizedSlotWrapper = React.memo(React.forwardRef(function MemoizedSlotWrapper(props, ref) {
|
|
682
|
+
const { $slot, $component, ...rest } = props;
|
|
683
|
+
return renderSlotElement($slot, $component, ref !== null ? {
|
|
684
|
+
...rest,
|
|
685
|
+
ref
|
|
686
|
+
} : rest);
|
|
687
|
+
}), (prev, next) => {
|
|
688
|
+
if (prev.$slot !== next.$slot) return false;
|
|
689
|
+
if (prev.$component !== next.$component) return false;
|
|
690
|
+
const { $slot: _ps, $component: _pc, ...prevRest } = prev;
|
|
691
|
+
const { $slot: _ns, $component: _nc, ...nextRest } = next;
|
|
692
|
+
return shallowEqual(prevRest, nextRest);
|
|
693
|
+
});
|
|
694
|
+
/**
|
|
695
|
+
* Renders a slot value as a memoized React element.
|
|
696
|
+
* Automatically prevents unnecessary re-renders using shallow prop comparison.
|
|
697
|
+
* Supports ref forwarding.
|
|
698
|
+
*
|
|
699
|
+
* @example
|
|
700
|
+
* renderSlot(customInput, CopilotChatInput, { onSubmit: handleSubmit })
|
|
701
|
+
*/
|
|
702
|
+
function renderSlot(slot, DefaultComponent, props) {
|
|
703
|
+
return React.createElement(MemoizedSlotWrapper, {
|
|
704
|
+
...props,
|
|
705
|
+
$slot: slot,
|
|
706
|
+
$component: DefaultComponent
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
|
|
705
710
|
//#endregion
|
|
706
711
|
//#region src/v2/components/chat/CopilotChatInput.tsx
|
|
707
712
|
const SLASH_MENU_MAX_VISIBLE_ITEMS = 5;
|
|
@@ -1055,7 +1060,6 @@ function CopilotChatInput({ mode = "input", onSubmitMessage, onStop, isRunning =
|
|
|
1055
1060
|
}
|
|
1056
1061
|
if (typeof window !== "undefined" && typeof window.matchMedia === "function") {
|
|
1057
1062
|
if (window.matchMedia("(max-width: 767px)").matches) {
|
|
1058
|
-
ensureMeasurements();
|
|
1059
1063
|
adjustTextareaHeight();
|
|
1060
1064
|
updateLayout("expanded");
|
|
1061
1065
|
return;
|
|
@@ -4396,11 +4400,14 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
|
|
|
4396
4400
|
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
4397
4401
|
const updateFlags = useMemo(() => updates ?? ALL_UPDATES, [JSON.stringify(updates)]);
|
|
4398
4402
|
const provisionalAgentCache = useRef(/* @__PURE__ */ new Map());
|
|
4399
|
-
const agent = useMemo(() => {
|
|
4403
|
+
const { agent, isReady } = useMemo(() => {
|
|
4400
4404
|
const existing = copilotkit.getAgent(resolvedAgentId);
|
|
4401
4405
|
if (existing) {
|
|
4402
4406
|
provisionalAgentCache.current.delete(resolvedAgentId);
|
|
4403
|
-
return
|
|
4407
|
+
return {
|
|
4408
|
+
agent: existing,
|
|
4409
|
+
isReady: true
|
|
4410
|
+
};
|
|
4404
4411
|
}
|
|
4405
4412
|
const isRuntimeConfigured = copilotkit.runtimeUrl !== void 0;
|
|
4406
4413
|
const status = copilotkit.runtimeConnectionStatus;
|
|
@@ -4408,7 +4415,10 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
|
|
|
4408
4415
|
const cached = provisionalAgentCache.current.get(resolvedAgentId);
|
|
4409
4416
|
if (cached) {
|
|
4410
4417
|
copilotkit.applyHeadersToAgent(cached);
|
|
4411
|
-
return
|
|
4418
|
+
return {
|
|
4419
|
+
agent: cached,
|
|
4420
|
+
isReady: false
|
|
4421
|
+
};
|
|
4412
4422
|
}
|
|
4413
4423
|
const provisional = new ProxiedCopilotRuntimeAgent({
|
|
4414
4424
|
runtimeUrl: copilotkit.runtimeUrl,
|
|
@@ -4418,13 +4428,19 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
|
|
|
4418
4428
|
});
|
|
4419
4429
|
copilotkit.applyHeadersToAgent(provisional);
|
|
4420
4430
|
provisionalAgentCache.current.set(resolvedAgentId, provisional);
|
|
4421
|
-
return
|
|
4431
|
+
return {
|
|
4432
|
+
agent: provisional,
|
|
4433
|
+
isReady: false
|
|
4434
|
+
};
|
|
4422
4435
|
}
|
|
4423
4436
|
if (isRuntimeConfigured && status === CopilotKitCoreRuntimeConnectionStatus.Error) {
|
|
4424
4437
|
const cached = provisionalAgentCache.current.get(resolvedAgentId);
|
|
4425
4438
|
if (cached) {
|
|
4426
4439
|
copilotkit.applyHeadersToAgent(cached);
|
|
4427
|
-
return
|
|
4440
|
+
return {
|
|
4441
|
+
agent: cached,
|
|
4442
|
+
isReady: false
|
|
4443
|
+
};
|
|
4428
4444
|
}
|
|
4429
4445
|
const provisional = new ProxiedCopilotRuntimeAgent({
|
|
4430
4446
|
runtimeUrl: copilotkit.runtimeUrl,
|
|
@@ -4434,7 +4450,10 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
|
|
|
4434
4450
|
});
|
|
4435
4451
|
copilotkit.applyHeadersToAgent(provisional);
|
|
4436
4452
|
provisionalAgentCache.current.set(resolvedAgentId, provisional);
|
|
4437
|
-
return
|
|
4453
|
+
return {
|
|
4454
|
+
agent: provisional,
|
|
4455
|
+
isReady: false
|
|
4456
|
+
};
|
|
4438
4457
|
}
|
|
4439
4458
|
const knownAgents = Object.keys(copilotkit.agents ?? {});
|
|
4440
4459
|
const runtimePart = isRuntimeConfigured ? `runtimeUrl=${copilotkit.runtimeUrl}` : "no runtimeUrl";
|
|
@@ -4495,7 +4514,10 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
|
|
|
4495
4514
|
configThreadId,
|
|
4496
4515
|
configHasExplicitThreadId
|
|
4497
4516
|
]);
|
|
4498
|
-
return {
|
|
4517
|
+
return {
|
|
4518
|
+
agent,
|
|
4519
|
+
isReady
|
|
4520
|
+
};
|
|
4499
4521
|
}
|
|
4500
4522
|
|
|
4501
4523
|
//#endregion
|
|
@@ -4803,8 +4825,9 @@ function useInterrupt(config) {
|
|
|
4803
4825
|
const pendingRef = useRef(pending);
|
|
4804
4826
|
pendingRef.current = pending;
|
|
4805
4827
|
const [handlerResult, setHandlerResult] = useState(null);
|
|
4806
|
-
const
|
|
4828
|
+
const interruptStateRef = useRef(new ɵInterruptState());
|
|
4807
4829
|
useEffect(() => {
|
|
4830
|
+
const interruptState = interruptStateRef.current;
|
|
4808
4831
|
let localLegacy = null;
|
|
4809
4832
|
let localStandard = null;
|
|
4810
4833
|
const subscription = agent.subscribe({
|
|
@@ -4820,106 +4843,111 @@ function useInterrupt(config) {
|
|
|
4820
4843
|
onRunStartedEvent: () => {
|
|
4821
4844
|
localLegacy = null;
|
|
4822
4845
|
localStandard = null;
|
|
4823
|
-
|
|
4846
|
+
interruptState.clear();
|
|
4824
4847
|
setPending(null);
|
|
4825
4848
|
},
|
|
4826
4849
|
onRunFinalized: () => {
|
|
4827
|
-
if (localStandard && localStandard.length > 0)
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
})
|
|
4831
|
-
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
});
|
|
4850
|
+
if (localStandard && localStandard.length > 0) {
|
|
4851
|
+
interruptState.setStandard(localStandard);
|
|
4852
|
+
setPending(interruptState.pending);
|
|
4853
|
+
} else if (localLegacy) {
|
|
4854
|
+
interruptState.setLegacy(localLegacy);
|
|
4855
|
+
setPending(interruptState.pending);
|
|
4856
|
+
}
|
|
4835
4857
|
localLegacy = null;
|
|
4836
4858
|
localStandard = null;
|
|
4837
4859
|
},
|
|
4838
4860
|
onRunFailed: () => {
|
|
4839
4861
|
localLegacy = null;
|
|
4840
4862
|
localStandard = null;
|
|
4841
|
-
|
|
4863
|
+
interruptState.clear();
|
|
4842
4864
|
setPending(null);
|
|
4843
4865
|
}
|
|
4844
4866
|
});
|
|
4845
|
-
return () =>
|
|
4867
|
+
return () => {
|
|
4868
|
+
subscription.unsubscribe();
|
|
4869
|
+
interruptState.clear();
|
|
4870
|
+
};
|
|
4846
4871
|
}, [agent]);
|
|
4847
|
-
const
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
if (
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
setPending(null);
|
|
4854
|
-
return;
|
|
4855
|
-
}
|
|
4856
|
-
const resume = buildResumeArray(interrupts, responsesRef.current);
|
|
4857
|
-
for (const i of interrupts) {
|
|
4858
|
-
if (!i.toolCallId) continue;
|
|
4859
|
-
const response = responsesRef.current[i.id];
|
|
4860
|
-
const content = response.status === "cancelled" ? { status: "cancelled" } : response.payload ?? { status: "resolved" };
|
|
4861
|
-
agent.addMessage({
|
|
4862
|
-
id: randomUUID(),
|
|
4863
|
-
role: "tool",
|
|
4864
|
-
toolCallId: i.toolCallId,
|
|
4865
|
-
content: JSON.stringify(content)
|
|
4866
|
-
});
|
|
4867
|
-
}
|
|
4868
|
-
responsesRef.current = {};
|
|
4869
|
-
try {
|
|
4872
|
+
const resolve = useCallback(async (payload, interruptId) => {
|
|
4873
|
+
const current = pendingRef.current;
|
|
4874
|
+
if (!current) return;
|
|
4875
|
+
if (current.kind === "standard" && current.interrupts.length > 1 && interruptId === void 0) console.warn(`[CopilotKit] useInterrupt: resolve()/cancel() called without an interruptId while ${current.interrupts.length} interrupts are open; defaulting to the first. Pass an interruptId to address a specific interrupt.`);
|
|
4876
|
+
const decision = interruptStateRef.current.resolve(payload, interruptId);
|
|
4877
|
+
if (decision.kind === "legacy-resume") try {
|
|
4870
4878
|
return await copilotkit.runAgent({
|
|
4871
4879
|
agent,
|
|
4872
|
-
|
|
4880
|
+
forwardedProps: { command: {
|
|
4881
|
+
resume: decision.payload,
|
|
4882
|
+
interruptEvent: decision.interruptValue
|
|
4883
|
+
} }
|
|
4873
4884
|
});
|
|
4874
4885
|
} catch (err) {
|
|
4875
4886
|
console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);
|
|
4876
4887
|
setPending(null);
|
|
4877
4888
|
throw err;
|
|
4878
4889
|
}
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
|
|
4890
|
+
if (decision.kind === "expired") {
|
|
4891
|
+
console.error(`[CopilotKit] useInterrupt: interrupt ${decision.interrupt.id} expired at ${decision.interrupt.expiresAt}; not resuming.`);
|
|
4892
|
+
interruptStateRef.current.clear();
|
|
4893
|
+
setPending(null);
|
|
4894
|
+
return;
|
|
4895
|
+
}
|
|
4896
|
+
if (decision.kind !== "resume") return;
|
|
4897
|
+
for (const toolResult of decision.toolResults) agent.addMessage({
|
|
4898
|
+
id: randomUUID(),
|
|
4899
|
+
role: "tool",
|
|
4900
|
+
toolCallId: toolResult.toolCallId,
|
|
4901
|
+
content: toolResult.content
|
|
4902
|
+
});
|
|
4903
|
+
try {
|
|
4884
4904
|
return await copilotkit.runAgent({
|
|
4885
4905
|
agent,
|
|
4886
|
-
|
|
4887
|
-
resume: payload,
|
|
4888
|
-
interruptEvent: current.event.value
|
|
4889
|
-
} }
|
|
4906
|
+
resume: decision.resume
|
|
4890
4907
|
});
|
|
4891
4908
|
} catch (err) {
|
|
4892
4909
|
console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);
|
|
4910
|
+
interruptStateRef.current.clear();
|
|
4893
4911
|
setPending(null);
|
|
4894
4912
|
throw err;
|
|
4895
4913
|
}
|
|
4896
|
-
|
|
4897
|
-
const id = interruptId ?? current.interrupts[0]?.id;
|
|
4898
|
-
if (!id) return;
|
|
4899
|
-
responsesRef.current[id] = {
|
|
4900
|
-
status: "resolved",
|
|
4901
|
-
payload
|
|
4902
|
-
};
|
|
4903
|
-
return submitStandardIfComplete(current.interrupts);
|
|
4904
|
-
}, [
|
|
4905
|
-
agent,
|
|
4906
|
-
copilotkit,
|
|
4907
|
-
submitStandardIfComplete
|
|
4908
|
-
]);
|
|
4914
|
+
}, [agent, copilotkit]);
|
|
4909
4915
|
const cancel = useCallback(async (interruptId) => {
|
|
4910
4916
|
const current = pendingRef.current;
|
|
4911
4917
|
if (!current) return;
|
|
4912
|
-
if (current.kind === "
|
|
4918
|
+
if (current.kind === "standard" && current.interrupts.length > 1 && interruptId === void 0) console.warn(`[CopilotKit] useInterrupt: resolve()/cancel() called without an interruptId while ${current.interrupts.length} interrupts are open; defaulting to the first. Pass an interruptId to address a specific interrupt.`);
|
|
4919
|
+
const decision = interruptStateRef.current.cancel(interruptId);
|
|
4920
|
+
if (decision.kind === "dismiss") {
|
|
4913
4921
|
console.warn("[CopilotKit] useInterrupt: cancel() is not supported for legacy on_interrupt interrupts; dismissing.");
|
|
4922
|
+
interruptStateRef.current.clear();
|
|
4914
4923
|
setPending(null);
|
|
4915
4924
|
return;
|
|
4916
4925
|
}
|
|
4917
|
-
if (
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4926
|
+
if (decision.kind === "expired") {
|
|
4927
|
+
console.error(`[CopilotKit] useInterrupt: interrupt ${decision.interrupt.id} expired at ${decision.interrupt.expiresAt}; not resuming.`);
|
|
4928
|
+
interruptStateRef.current.clear();
|
|
4929
|
+
setPending(null);
|
|
4930
|
+
return;
|
|
4931
|
+
}
|
|
4932
|
+
if (decision.kind !== "resume") return;
|
|
4933
|
+
for (const toolResult of decision.toolResults) agent.addMessage({
|
|
4934
|
+
id: randomUUID(),
|
|
4935
|
+
role: "tool",
|
|
4936
|
+
toolCallId: toolResult.toolCallId,
|
|
4937
|
+
content: toolResult.content
|
|
4938
|
+
});
|
|
4939
|
+
try {
|
|
4940
|
+
return await copilotkit.runAgent({
|
|
4941
|
+
agent,
|
|
4942
|
+
resume: decision.resume
|
|
4943
|
+
});
|
|
4944
|
+
} catch (err) {
|
|
4945
|
+
console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);
|
|
4946
|
+
interruptStateRef.current.clear();
|
|
4947
|
+
setPending(null);
|
|
4948
|
+
throw err;
|
|
4949
|
+
}
|
|
4950
|
+
}, [agent, copilotkit]);
|
|
4923
4951
|
const renderRef = useRef(config.render);
|
|
4924
4952
|
renderRef.current = config.render;
|
|
4925
4953
|
const enabledRef = useRef(config.enabled);
|
|
@@ -4961,7 +4989,7 @@ function useInterrupt(config) {
|
|
|
4961
4989
|
maybePromise = handler({
|
|
4962
4990
|
event: legacyEvent,
|
|
4963
4991
|
interrupt: pending.kind === "standard" ? pending.interrupts[0] : null,
|
|
4964
|
-
interrupts: pending.kind === "standard" ? pending.interrupts : [],
|
|
4992
|
+
interrupts: pending.kind === "standard" ? [...pending.interrupts] : [],
|
|
4965
4993
|
resolve: resolveRef.current,
|
|
4966
4994
|
cancel: cancelRef.current
|
|
4967
4995
|
});
|
|
@@ -4990,7 +5018,7 @@ function useInterrupt(config) {
|
|
|
4990
5018
|
return renderRef.current({
|
|
4991
5019
|
event: legacyEvent,
|
|
4992
5020
|
interrupt: pending.kind === "standard" ? pending.interrupts[0] : null,
|
|
4993
|
-
interrupts: pending.kind === "standard" ? pending.interrupts : [],
|
|
5021
|
+
interrupts: pending.kind === "standard" ? [...pending.interrupts] : [],
|
|
4994
5022
|
result: handlerResult,
|
|
4995
5023
|
resolve,
|
|
4996
5024
|
cancel
|
|
@@ -11603,4 +11631,4 @@ function validateProps(props) {
|
|
|
11603
11631
|
|
|
11604
11632
|
//#endregion
|
|
11605
11633
|
export { useCapabilities as $, CopilotChatMessageView as A, CopilotChatConfigurationProvider as At, CopilotChatAssistantMessage_default as B, CopilotModalHeader as C, CopilotKitInspector as Ct, CopilotChat as D, CopilotChatInput_default as Dt, DefaultOpenIcon as E, CopilotKitCoreReact as Et, CopilotChatSuggestionView as F, useLearnFromUserActionInCurrentThread as G, useLearningContainersInCurrentThread as H, CopilotChatSuggestionPill as I, useThreads$1 as J, useLearnFromUserAction as K, CopilotChatReasoningMessage_default as L, IntelligenceIndicator as M, getIntelligenceTurnAnchors as N, CopilotChatView_default as O, AudioRecorderError as Ot, IntelligenceIndicatorView as P, useAgentContext as Q, CopilotChatUserMessage_default as R, CopilotSidebarView as S, ɵrunMcpFollowUp as St, DefaultCloseIcon as T, useCopilotKit as Tt, useLearningContainers as U, CopilotChatToolCallsView as V, useAttachments as W, useConfigureSuggestions as X, useInterrupt as Y, useSuggestions as Z, WildcardToolCallRender as _, SandboxFunctionsContext as _t, ThreadsProvider as a, useComponent as at, CopilotSidebar as b, MCPAppsActivityRenderer as bt, CoAgentStateRendersProvider as c, useRenderCustomMessages as ct, shouldShowDevConsole as d, createA2UIMessageRenderer as dt, UseAgentUpdate as et, useToast as f, GenerateSandboxedUiArgsSchema as ft, useCopilotContext as g, OpenGenerativeUIToolRenderer as gt, CopilotContext as h, OpenGenerativeUIContentSchema as ht, ThreadsContext as i, useRenderTool as it, INTELLIGENCE_TURN_HEAD as j, useCopilotChatConfiguration as jt, CopilotChatAttachmentQueue as k, CopilotChatAudioRecorder as kt, useCoAgentStateRenders as l, CopilotKitProvider as lt, useCopilotMessagesContext as m, OpenGenerativeUIActivityType as mt, defaultCopilotContextCategories as n, useHumanInTheLoop as nt, useThreads as o, useFrontendTool as ot, CopilotMessagesContext as p, OpenGenerativeUIActivityRenderer as pt, useMemories as q, CoAgentStateRenderBridge as r, useDefaultRenderTool as rt, CoAgentStateRendersContext as s, useRenderActivityMessage as st, CopilotKit as t, useAgent as tt, useAsyncCallback as u, defineToolCallRenderer as ut, CopilotThreadsDrawer as v, useSandboxFunctions as vt, CopilotChatToggleButton as w, useRenderToolCall as wt, CopilotPopupView as x, MCPAppsActivityType as xt, CopilotPopup as y, MCPAppsActivityContentSchema as yt, CopilotChatAttachmentRenderer as z };
|
|
11606
|
-
//# sourceMappingURL=copilotkit-
|
|
11634
|
+
//# sourceMappingURL=copilotkit-DL0LvmwQ.mjs.map
|