@copilotkit/react-core 1.83.0 → 2.0.0-rc.0
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/{runtime-context-CrHq-iTf.d.mts → MarkdownRendererContext-B4Us6mwL.d.cts} +127 -97
- package/dist/MarkdownRendererContext-B4Us6mwL.d.cts.map +1 -0
- package/dist/{runtime-context-D3NcP9oE.d.cts → MarkdownRendererContext-CRKFzsEB.d.mts} +127 -97
- package/dist/MarkdownRendererContext-CRKFzsEB.d.mts.map +1 -0
- package/dist/{MarkdownSurfaces-FF5za2kU.cjs → MarkdownSurfaces-C2XZISKn.cjs} +203 -55
- package/dist/MarkdownSurfaces-C2XZISKn.cjs.map +1 -0
- package/dist/{MarkdownSurfaces-DGpjmPaB.mjs → MarkdownSurfaces-ChSlVYOk.mjs} +171 -47
- package/dist/MarkdownSurfaces-ChSlVYOk.mjs.map +1 -0
- package/dist/{v2/context.cjs → context.cjs} +2 -2
- package/dist/context.cjs.map +1 -0
- package/dist/{v2/context.d.cts → context.d.cts} +5 -5
- package/dist/context.d.cts.map +1 -0
- package/dist/{v2/context.d.mts → context.d.mts} +5 -5
- package/dist/context.d.mts.map +1 -0
- package/dist/{v2/context.mjs → context.mjs} +2 -2
- package/dist/context.mjs.map +1 -0
- package/dist/{v2/generative-ui.cjs → generative-ui.cjs} +40 -43
- package/dist/generative-ui.cjs.map +1 -0
- package/dist/{v2/generative-ui.d.cts → generative-ui.d.cts} +14 -12
- package/dist/generative-ui.d.cts.map +1 -0
- package/dist/{v2/generative-ui.d.mts → generative-ui.d.mts} +14 -12
- package/dist/generative-ui.d.mts.map +1 -0
- package/dist/{v2/generative-ui.mjs → generative-ui.mjs} +40 -43
- package/dist/generative-ui.mjs.map +1 -0
- package/dist/{v2/headless.cjs → headless.cjs} +68 -53
- package/dist/headless.cjs.map +1 -0
- package/dist/{v2/headless.d.cts → headless.d.cts} +24 -23
- package/dist/headless.d.cts.map +1 -0
- package/dist/{v2/headless.d.mts → headless.d.mts} +21 -20
- package/dist/headless.d.mts.map +1 -0
- package/dist/{v2/headless.mjs → headless.mjs} +51 -36
- package/dist/headless.mjs.map +1 -0
- package/dist/index.cjs +15391 -1862
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +2 -0
- package/dist/index.d.cts +3252 -1370
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3234 -1369
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +13733 -1815
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +11944 -5481
- package/dist/index.umd.js.map +1 -1
- package/package.json +21 -30
- package/dist/MarkdownSurfaces-DGpjmPaB.mjs.map +0 -1
- package/dist/MarkdownSurfaces-FF5za2kU.cjs.map +0 -1
- package/dist/copilotkit-BuIuo-Z1.cjs +0 -16531
- package/dist/copilotkit-BuIuo-Z1.cjs.map +0 -1
- package/dist/copilotkit-C765tOUi.d.mts +0 -4112
- package/dist/copilotkit-C765tOUi.d.mts.map +0 -1
- package/dist/copilotkit-DyxwF9wL.mjs +0 -16025
- package/dist/copilotkit-DyxwF9wL.mjs.map +0 -1
- package/dist/copilotkit-wqaNanhw.d.cts +0 -4129
- package/dist/copilotkit-wqaNanhw.d.cts.map +0 -1
- package/dist/runtime-context-CrHq-iTf.d.mts.map +0 -1
- package/dist/runtime-context-D3NcP9oE.d.cts.map +0 -1
- package/dist/v2/context.cjs.map +0 -1
- package/dist/v2/context.d.cts.map +0 -1
- package/dist/v2/context.d.mts.map +0 -1
- package/dist/v2/context.mjs.map +0 -1
- package/dist/v2/generative-ui.cjs.map +0 -1
- package/dist/v2/generative-ui.d.cts.map +0 -1
- package/dist/v2/generative-ui.d.mts.map +0 -1
- package/dist/v2/generative-ui.mjs.map +0 -1
- package/dist/v2/headless.cjs.map +0 -1
- package/dist/v2/headless.d.cts.map +0 -1
- package/dist/v2/headless.d.mts.map +0 -1
- package/dist/v2/headless.mjs.map +0 -1
- package/dist/v2/index.cjs +0 -1635
- package/dist/v2/index.css +0 -2
- package/dist/v2/index.d.cts +0 -4
- package/dist/v2/index.d.mts +0 -4
- package/dist/v2/index.mjs +0 -8
- package/dist/v2/index.umd.js +0 -20695
- package/dist/v2/index.umd.js.map +0 -1
|
@@ -26,7 +26,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
}) : target, mod));
|
|
27
27
|
|
|
28
28
|
//#endregion
|
|
29
|
-
let
|
|
29
|
+
let _copilotkit_react_core_context = require("@copilotkit/react-core/context");
|
|
30
30
|
let react = require("react");
|
|
31
31
|
react = __toESM(react);
|
|
32
32
|
let _copilotkit_shared = require("@copilotkit/shared");
|
|
@@ -36,7 +36,7 @@ let _ag_ui_client = require("@ag-ui/client");
|
|
|
36
36
|
let zod = require("zod");
|
|
37
37
|
let _ag_ui_core = require("@ag-ui/core");
|
|
38
38
|
|
|
39
|
-
//#region src/
|
|
39
|
+
//#region src/lib/shallow-stable-ref.ts
|
|
40
40
|
/**
|
|
41
41
|
* Shallow equality comparison for objects.
|
|
42
42
|
*/
|
|
@@ -78,7 +78,7 @@ function useShallowStableRef(value) {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
//#endregion
|
|
81
|
-
//#region src/
|
|
81
|
+
//#region src/providers/CopilotChatConfigurationProvider.tsx
|
|
82
82
|
const CopilotChatDefaultLabels = {
|
|
83
83
|
chatInputPlaceholder: "Type a message...",
|
|
84
84
|
chatInputToolbarStartTranscribeButtonLabel: "Transcribe",
|
|
@@ -152,7 +152,7 @@ const CopilotChatConfigurationProvider = ({ children, labels, agentId, threadId,
|
|
|
152
152
|
...parentConfig?.labels,
|
|
153
153
|
...stableLabels
|
|
154
154
|
}), [stableLabels, parentConfig?.labels]);
|
|
155
|
-
const providerAgentId = (0,
|
|
155
|
+
const providerAgentId = (0, _copilotkit_react_core_context.useDefaultAgentId)();
|
|
156
156
|
const resolvedAgentId = agentId ?? parentConfig?.agentId ?? providerAgentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
157
157
|
const threadIdPropIsAuthoritative = threadId !== void 0 && hasExplicitThreadId !== false;
|
|
158
158
|
const isThreadIdControlled = threadIdPropIsAuthoritative;
|
|
@@ -169,7 +169,7 @@ const CopilotChatConfigurationProvider = ({ children, labels, agentId, threadId,
|
|
|
169
169
|
parentConfig?.threadId,
|
|
170
170
|
activeThreadOverride
|
|
171
171
|
]);
|
|
172
|
-
const copilotkit = (0, react.useContext)(
|
|
172
|
+
const copilotkit = (0, react.useContext)(_copilotkit_react_core_context.CopilotKitContext)?.copilotkit;
|
|
173
173
|
const openThreadRef = (0, react.useRef)(null);
|
|
174
174
|
const latestThreadIdRef = (0, react.useRef)(resolvedThreadId);
|
|
175
175
|
latestThreadIdRef.current = resolvedThreadId;
|
|
@@ -381,7 +381,7 @@ const ControlledModalOpenScope = ({ children, open, onOpenChange }) => {
|
|
|
381
381
|
ControlledModalOpenScope.displayName = "ControlledModalOpenScope";
|
|
382
382
|
|
|
383
383
|
//#endregion
|
|
384
|
-
//#region src/
|
|
384
|
+
//#region src/hooks/use-agent.tsx
|
|
385
385
|
let UseAgentUpdate = /* @__PURE__ */ function(UseAgentUpdate) {
|
|
386
386
|
UseAgentUpdate["OnMessagesChanged"] = "OnMessagesChanged";
|
|
387
387
|
UseAgentUpdate["OnStateChanged"] = "OnStateChanged";
|
|
@@ -398,9 +398,9 @@ function useAgent({ agentId, threadId, runtimeAgentId, updates, throttleMs } = {
|
|
|
398
398
|
if (runtimeAgentId != null && threadId == null) throw new Error(`useAgent: \`runtimeAgentId\` requires \`threadId\`. A proxied agent exists to scope a thread to a private instance; without a threadId it behaves like the shared agent while adding a registration and a local agentId to keep unique. Either pass the thread, e.g. useAgent({ agentId: "${agentId ?? "chat-1"}", runtimeAgentId: "${runtimeAgentId}", threadId }), or bind to the agent directly with useAgent({ agentId: "${runtimeAgentId}" }).`);
|
|
399
399
|
if (runtimeAgentId != null && agentId == null) throw new Error(`useAgent: \`runtimeAgentId\` requires an explicit \`agentId\`. The proxied agent is registered under \`agentId\`, and the usual fallbacks (chat configuration, then "${_copilotkit_shared.DEFAULT_AGENT_ID}") name agents that already exist — registering over one throws or shadows it. Pick a local id for this hook, e.g. useAgent({ agentId: "chat-1", runtimeAgentId: "${runtimeAgentId}", threadId }).`);
|
|
400
400
|
const chatConfig = useCopilotChatConfiguration();
|
|
401
|
-
const providerAgentId = (0,
|
|
401
|
+
const providerAgentId = (0, _copilotkit_react_core_context.useDefaultAgentId)();
|
|
402
402
|
const resolvedAgentId = agentId ?? chatConfig?.agentId ?? providerAgentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
403
|
-
const { copilotkit } = (0,
|
|
403
|
+
const { copilotkit } = (0, _copilotkit_react_core_context.useCopilotKit)();
|
|
404
404
|
const providerThrottleMs = copilotkit.defaultThrottleMs;
|
|
405
405
|
const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
|
|
406
406
|
const updateFlags = (0, react.useMemo)(() => updates ?? ALL_UPDATES, [JSON.stringify(updates)]);
|
|
@@ -579,7 +579,7 @@ function useAgent({ agentId, threadId, runtimeAgentId, updates, throttleMs } = {
|
|
|
579
579
|
}
|
|
580
580
|
|
|
581
581
|
//#endregion
|
|
582
|
-
//#region src/
|
|
582
|
+
//#region src/hooks/tool-registration.ts
|
|
583
583
|
/**
|
|
584
584
|
* Deps comparison shared by `useFrontendTool` (and through it
|
|
585
585
|
* `useHumanInTheLoop` and `useComponent`) and `useRenderTool`. Not part of the
|
|
@@ -654,9 +654,9 @@ function useDepsVersion(deps) {
|
|
|
654
654
|
}
|
|
655
655
|
|
|
656
656
|
//#endregion
|
|
657
|
-
//#region src/
|
|
657
|
+
//#region src/hooks/use-frontend-tool.tsx
|
|
658
658
|
function useFrontendTool(tool, deps) {
|
|
659
|
-
const { copilotkit } = (0,
|
|
659
|
+
const { copilotkit } = (0, _copilotkit_react_core_context.useCopilotKit)();
|
|
660
660
|
const depsVersion = useDepsVersion(deps);
|
|
661
661
|
(0, react.useLayoutEffect)(() => {
|
|
662
662
|
const name = tool.name;
|
|
@@ -687,7 +687,7 @@ function useFrontendTool(tool, deps) {
|
|
|
687
687
|
}
|
|
688
688
|
|
|
689
689
|
//#endregion
|
|
690
|
-
//#region src/
|
|
690
|
+
//#region src/hooks/use-frontend-tools.tsx
|
|
691
691
|
const EMPTY_DEPS = [];
|
|
692
692
|
const EMPTY_TOOLS = [];
|
|
693
693
|
/**
|
|
@@ -740,7 +740,7 @@ const EMPTY_TOOLS = [];
|
|
|
740
740
|
* ```
|
|
741
741
|
*/
|
|
742
742
|
function useFrontendTools(tools, deps) {
|
|
743
|
-
const { copilotkit } = (0,
|
|
743
|
+
const { copilotkit } = (0, _copilotkit_react_core_context.useCopilotKit)();
|
|
744
744
|
const toolList = tools ?? EMPTY_TOOLS;
|
|
745
745
|
const extraDeps = deps ?? EMPTY_DEPS;
|
|
746
746
|
(0, react.useLayoutEffect)(() => {
|
|
@@ -784,7 +784,7 @@ function useFrontendTools(tools, deps) {
|
|
|
784
784
|
}
|
|
785
785
|
|
|
786
786
|
//#endregion
|
|
787
|
-
//#region src/
|
|
787
|
+
//#region src/hooks/use-component.tsx
|
|
788
788
|
/**
|
|
789
789
|
* Registers a React component as a frontend tool renderer in chat.
|
|
790
790
|
*
|
|
@@ -852,11 +852,11 @@ function useComponent(config, deps) {
|
|
|
852
852
|
}
|
|
853
853
|
|
|
854
854
|
//#endregion
|
|
855
|
-
//#region src/
|
|
855
|
+
//#region src/hooks/use-human-in-the-loop.tsx
|
|
856
856
|
/** Registration name of a catch-all tool: handles any otherwise-unhandled call. */
|
|
857
857
|
const WILDCARD_TOOL_NAME = "*";
|
|
858
858
|
function useHumanInTheLoop(tool, deps) {
|
|
859
|
-
const { copilotkit } = (0,
|
|
859
|
+
const { copilotkit } = (0, _copilotkit_react_core_context.useCopilotKit)();
|
|
860
860
|
const resolvePromiseRef = (0, react.useRef)(null);
|
|
861
861
|
const cleanupAbortRef = (0, react.useRef)(null);
|
|
862
862
|
const respond = (0, react.useCallback)(async (result) => {
|
|
@@ -945,12 +945,13 @@ function useHumanInTheLoop(tool, deps) {
|
|
|
945
945
|
}
|
|
946
946
|
|
|
947
947
|
//#endregion
|
|
948
|
-
//#region src/
|
|
948
|
+
//#region src/types/interrupt.ts
|
|
949
949
|
/** Name of the legacy custom event agents emit to signal an interrupt. */
|
|
950
950
|
const INTERRUPT_EVENT_NAME = "on_interrupt";
|
|
951
951
|
|
|
952
952
|
//#endregion
|
|
953
|
-
//#region src/
|
|
953
|
+
//#region src/hooks/use-interrupt.tsx
|
|
954
|
+
/** Recognize thenables returned by interrupt preprocessing handlers. */
|
|
954
955
|
function isPromiseLike(value) {
|
|
955
956
|
return (typeof value === "object" || typeof value === "function") && value !== null && typeof Reflect.get(value, "then") === "function";
|
|
956
957
|
}
|
|
@@ -990,7 +991,7 @@ function toLegacyEvent(pending) {
|
|
|
990
991
|
* ```
|
|
991
992
|
*/
|
|
992
993
|
function useInterrupt(config) {
|
|
993
|
-
const { copilotkit } = (0,
|
|
994
|
+
const { copilotkit } = (0, _copilotkit_react_core_context.useCopilotKit)();
|
|
994
995
|
const { agent } = useAgent({
|
|
995
996
|
agentId: config.agentId,
|
|
996
997
|
updates: []
|
|
@@ -1001,7 +1002,6 @@ function useInterrupt(config) {
|
|
|
1001
1002
|
const [handlerResult, setHandlerResult] = (0, react.useState)(null);
|
|
1002
1003
|
const interruptStateRef = (0, react.useRef)(new _copilotkit_core.ɵInterruptState());
|
|
1003
1004
|
(0, react.useEffect)(() => {
|
|
1004
|
-
const interruptState = interruptStateRef.current;
|
|
1005
1005
|
let localLegacy = null;
|
|
1006
1006
|
let localStandard = null;
|
|
1007
1007
|
const subscription = agent.subscribe({
|
|
@@ -1014,19 +1014,21 @@ function useInterrupt(config) {
|
|
|
1014
1014
|
onRunFinishedEvent: (params) => {
|
|
1015
1015
|
if (params.outcome === "interrupt") localStandard = params.interrupts;
|
|
1016
1016
|
},
|
|
1017
|
-
onRunStartedEvent: () => {
|
|
1017
|
+
onRunStartedEvent: (params) => {
|
|
1018
|
+
if (!agent.pendingInterrupts?.length || params?.input?.resume !== void 0) (0, _copilotkit_core.ɵclearAgentInterruptState)(agent);
|
|
1018
1019
|
localLegacy = null;
|
|
1019
1020
|
localStandard = null;
|
|
1020
|
-
|
|
1021
|
+
interruptStateRef.current = new _copilotkit_core.ɵInterruptState();
|
|
1021
1022
|
setPending(null);
|
|
1022
1023
|
},
|
|
1023
1024
|
onRunFinalized: () => {
|
|
1024
1025
|
if (localStandard && localStandard.length > 0) {
|
|
1025
|
-
|
|
1026
|
-
setPending(
|
|
1026
|
+
interruptStateRef.current = (0, _copilotkit_core.ɵgetAgentInterruptState)(agent, localStandard);
|
|
1027
|
+
setPending(interruptStateRef.current.pending);
|
|
1027
1028
|
} else if (localLegacy) {
|
|
1028
|
-
|
|
1029
|
-
|
|
1029
|
+
interruptStateRef.current = new _copilotkit_core.ɵInterruptState();
|
|
1030
|
+
interruptStateRef.current.setLegacy(localLegacy);
|
|
1031
|
+
setPending(interruptStateRef.current.pending);
|
|
1030
1032
|
}
|
|
1031
1033
|
localLegacy = null;
|
|
1032
1034
|
localStandard = null;
|
|
@@ -1034,20 +1036,27 @@ function useInterrupt(config) {
|
|
|
1034
1036
|
onRunFailed: () => {
|
|
1035
1037
|
localLegacy = null;
|
|
1036
1038
|
localStandard = null;
|
|
1037
|
-
|
|
1039
|
+
interruptStateRef.current = new _copilotkit_core.ɵInterruptState();
|
|
1038
1040
|
setPending(null);
|
|
1039
1041
|
}
|
|
1040
1042
|
});
|
|
1043
|
+
interruptStateRef.current = agent.pendingInterrupts?.length ? (0, _copilotkit_core.ɵgetAgentInterruptState)(agent) : new _copilotkit_core.ɵInterruptState();
|
|
1044
|
+
setPending(interruptStateRef.current.pending);
|
|
1041
1045
|
return () => {
|
|
1042
1046
|
subscription.unsubscribe();
|
|
1043
|
-
|
|
1047
|
+
interruptStateRef.current = new _copilotkit_core.ɵInterruptState();
|
|
1044
1048
|
};
|
|
1045
1049
|
}, [agent]);
|
|
1050
|
+
/** Record an explicit answer and resume once the complete batch is addressed. */
|
|
1046
1051
|
const resolve = (0, react.useCallback)(async (payload, interruptId) => {
|
|
1047
1052
|
const current = pendingRef.current;
|
|
1048
1053
|
if (!current) return;
|
|
1049
1054
|
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.`);
|
|
1050
|
-
|
|
1055
|
+
if (interruptStateRef.current.isCompletedToolCall(interruptId, agent.messages)) {
|
|
1056
|
+
console.warn("[CopilotKit] useInterrupt: ignoring an answer for an already completed frontend tool call.");
|
|
1057
|
+
return;
|
|
1058
|
+
}
|
|
1059
|
+
const decision = interruptStateRef.current.resolve(payload, interruptId, agent.messages);
|
|
1051
1060
|
if (decision.kind === "legacy-resume") try {
|
|
1052
1061
|
return await copilotkit.runAgent({
|
|
1053
1062
|
agent,
|
|
@@ -1063,7 +1072,7 @@ function useInterrupt(config) {
|
|
|
1063
1072
|
}
|
|
1064
1073
|
if (decision.kind === "expired") {
|
|
1065
1074
|
console.error(`[CopilotKit] useInterrupt: interrupt ${decision.interrupt.id} expired at ${decision.interrupt.expiresAt}; not resuming.`);
|
|
1066
|
-
interruptStateRef.current
|
|
1075
|
+
interruptStateRef.current = new _copilotkit_core.ɵInterruptState();
|
|
1067
1076
|
setPending(null);
|
|
1068
1077
|
return;
|
|
1069
1078
|
}
|
|
@@ -1081,25 +1090,30 @@ function useInterrupt(config) {
|
|
|
1081
1090
|
});
|
|
1082
1091
|
} catch (err) {
|
|
1083
1092
|
console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);
|
|
1084
|
-
interruptStateRef.current
|
|
1093
|
+
interruptStateRef.current = new _copilotkit_core.ɵInterruptState();
|
|
1085
1094
|
setPending(null);
|
|
1086
1095
|
throw err;
|
|
1087
1096
|
}
|
|
1088
1097
|
}, [agent, copilotkit]);
|
|
1098
|
+
/** Cancel a standard interrupt or dismiss a legacy interrupt locally. */
|
|
1089
1099
|
const cancel = (0, react.useCallback)(async (interruptId) => {
|
|
1090
1100
|
const current = pendingRef.current;
|
|
1091
1101
|
if (!current) return;
|
|
1092
1102
|
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.`);
|
|
1093
|
-
|
|
1103
|
+
if (interruptStateRef.current.isCompletedToolCall(interruptId, agent.messages)) {
|
|
1104
|
+
console.warn("[CopilotKit] useInterrupt: ignoring an answer for an already completed frontend tool call.");
|
|
1105
|
+
return;
|
|
1106
|
+
}
|
|
1107
|
+
const decision = interruptStateRef.current.cancel(interruptId, agent.messages);
|
|
1094
1108
|
if (decision.kind === "dismiss") {
|
|
1095
1109
|
console.warn("[CopilotKit] useInterrupt: cancel() is not supported for legacy on_interrupt interrupts; dismissing.");
|
|
1096
|
-
interruptStateRef.current
|
|
1110
|
+
interruptStateRef.current = new _copilotkit_core.ɵInterruptState();
|
|
1097
1111
|
setPending(null);
|
|
1098
1112
|
return;
|
|
1099
1113
|
}
|
|
1100
1114
|
if (decision.kind === "expired") {
|
|
1101
1115
|
console.error(`[CopilotKit] useInterrupt: interrupt ${decision.interrupt.id} expired at ${decision.interrupt.expiresAt}; not resuming.`);
|
|
1102
|
-
interruptStateRef.current
|
|
1116
|
+
interruptStateRef.current = new _copilotkit_core.ɵInterruptState();
|
|
1103
1117
|
setPending(null);
|
|
1104
1118
|
return;
|
|
1105
1119
|
}
|
|
@@ -1117,7 +1131,7 @@ function useInterrupt(config) {
|
|
|
1117
1131
|
});
|
|
1118
1132
|
} catch (err) {
|
|
1119
1133
|
console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);
|
|
1120
|
-
interruptStateRef.current
|
|
1134
|
+
interruptStateRef.current = new _copilotkit_core.ɵInterruptState();
|
|
1121
1135
|
setPending(null);
|
|
1122
1136
|
throw err;
|
|
1123
1137
|
}
|
|
@@ -1132,6 +1146,7 @@ function useInterrupt(config) {
|
|
|
1132
1146
|
resolveRef.current = resolve;
|
|
1133
1147
|
const cancelRef = (0, react.useRef)(cancel);
|
|
1134
1148
|
cancelRef.current = cancel;
|
|
1149
|
+
/** Evaluate the consumer filter, logging failures and disabling their UI. */
|
|
1135
1150
|
const isEnabled = (event) => {
|
|
1136
1151
|
const predicate = enabledRef.current;
|
|
1137
1152
|
if (!predicate) return true;
|
|
@@ -1221,11 +1236,11 @@ function useInterrupt(config) {
|
|
|
1221
1236
|
}
|
|
1222
1237
|
|
|
1223
1238
|
//#endregion
|
|
1224
|
-
//#region src/
|
|
1239
|
+
//#region src/hooks/use-suggestions.tsx
|
|
1225
1240
|
function useSuggestions({ agentId } = {}) {
|
|
1226
|
-
const { copilotkit } = (0,
|
|
1241
|
+
const { copilotkit } = (0, _copilotkit_react_core_context.useCopilotKit)();
|
|
1227
1242
|
const config = useCopilotChatConfiguration();
|
|
1228
|
-
const providerAgentId = (0,
|
|
1243
|
+
const providerAgentId = (0, _copilotkit_react_core_context.useDefaultAgentId)();
|
|
1229
1244
|
const resolvedAgentId = (0, react.useMemo)(() => agentId ?? config?.agentId ?? providerAgentId ?? _copilotkit_shared.DEFAULT_AGENT_ID, [
|
|
1230
1245
|
agentId,
|
|
1231
1246
|
config?.agentId,
|
|
@@ -1279,9 +1294,9 @@ function useSuggestions({ agentId } = {}) {
|
|
|
1279
1294
|
}
|
|
1280
1295
|
|
|
1281
1296
|
//#endregion
|
|
1282
|
-
//#region src/
|
|
1297
|
+
//#region src/hooks/use-configure-suggestions.tsx
|
|
1283
1298
|
function useConfigureSuggestions(config, deps) {
|
|
1284
|
-
const { copilotkit } = (0,
|
|
1299
|
+
const { copilotkit } = (0, _copilotkit_react_core_context.useCopilotKit)();
|
|
1285
1300
|
const chatConfig = useCopilotChatConfiguration();
|
|
1286
1301
|
const extraDeps = deps ?? [];
|
|
1287
1302
|
const resolvedConsumerAgentId = (0, react.useMemo)(() => chatConfig?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID, [chatConfig?.agentId]);
|
|
@@ -1438,10 +1453,10 @@ function normalizeStaticSuggestions(suggestions) {
|
|
|
1438
1453
|
}
|
|
1439
1454
|
|
|
1440
1455
|
//#endregion
|
|
1441
|
-
//#region src/
|
|
1456
|
+
//#region src/hooks/use-agent-context.tsx
|
|
1442
1457
|
function useAgentContext(context) {
|
|
1443
1458
|
const { description, value } = context;
|
|
1444
|
-
const { copilotkit } = (0,
|
|
1459
|
+
const { copilotkit } = (0, _copilotkit_react_core_context.useCopilotKit)();
|
|
1445
1460
|
const stringValue = (0, react.useMemo)(() => {
|
|
1446
1461
|
if (typeof value === "string") return value;
|
|
1447
1462
|
return JSON.stringify(value);
|
|
@@ -1463,7 +1478,7 @@ function useAgentContext(context) {
|
|
|
1463
1478
|
}
|
|
1464
1479
|
|
|
1465
1480
|
//#endregion
|
|
1466
|
-
//#region src/
|
|
1481
|
+
//#region src/hooks/use-threads.tsx
|
|
1467
1482
|
function useThreadStoreSelector(store, selector) {
|
|
1468
1483
|
return (0, react.useSyncExternalStore)((0, react.useCallback)((onStoreChange) => {
|
|
1469
1484
|
const subscription = store.select(selector).subscribe(onStoreChange);
|
|
@@ -1512,7 +1527,7 @@ function useThreadStoreSelector(store, selector) {
|
|
|
1512
1527
|
* ```
|
|
1513
1528
|
*/
|
|
1514
1529
|
function useThreads({ agentId, includeArchived, limit, enabled = true }) {
|
|
1515
|
-
const { copilotkit } = (0,
|
|
1530
|
+
const { copilotkit } = (0, _copilotkit_react_core_context.useCopilotKit)();
|
|
1516
1531
|
const [store] = (0, react.useState)(() => (0, _copilotkit_core.ɵcreateThreadStore)({ fetch: copilotkit.ɵruntimeFetch }));
|
|
1517
1532
|
const coreThreads = useThreadStoreSelector(store, _copilotkit_core.ɵselectThreads);
|
|
1518
1533
|
const threads = (0, react.useMemo)(() => coreThreads.map(({ id, agentId, name, archived, createdAt, updatedAt, lastRunAt }) => ({
|
|
@@ -1647,7 +1662,7 @@ function useThreads({ agentId, includeArchived, limit, enabled = true }) {
|
|
|
1647
1662
|
}
|
|
1648
1663
|
|
|
1649
1664
|
//#endregion
|
|
1650
|
-
//#region src/
|
|
1665
|
+
//#region src/types/defineToolCallRenderer.ts
|
|
1651
1666
|
function defineToolCallRenderer(def) {
|
|
1652
1667
|
const argsSchema = def.name === "*" && !def.args ? zod.z.any() : def.args;
|
|
1653
1668
|
return {
|
|
@@ -1660,7 +1675,7 @@ function defineToolCallRenderer(def) {
|
|
|
1660
1675
|
}
|
|
1661
1676
|
|
|
1662
1677
|
//#endregion
|
|
1663
|
-
//#region src/
|
|
1678
|
+
//#region src/hooks/use-render-tool.tsx
|
|
1664
1679
|
/**
|
|
1665
1680
|
* Registers a renderer entry in CopilotKit's `renderToolCalls` registry.
|
|
1666
1681
|
*
|
|
@@ -1703,7 +1718,7 @@ function defineToolCallRenderer(def) {
|
|
|
1703
1718
|
* ```
|
|
1704
1719
|
*/
|
|
1705
1720
|
function useRenderTool(config, deps) {
|
|
1706
|
-
const { copilotkit } = (0,
|
|
1721
|
+
const { copilotkit } = (0, _copilotkit_react_core_context.useCopilotKit)();
|
|
1707
1722
|
const depsVersion = useDepsVersion(deps);
|
|
1708
1723
|
(0, react.useEffect)(() => {
|
|
1709
1724
|
const renderer = config.name === "*" && !config.parameters ? defineToolCallRenderer({
|
|
@@ -1744,7 +1759,7 @@ function useRenderTool(config, deps) {
|
|
|
1744
1759
|
}
|
|
1745
1760
|
|
|
1746
1761
|
//#endregion
|
|
1747
|
-
//#region src/
|
|
1762
|
+
//#region src/hooks/use-render-tool-call.tsx
|
|
1748
1763
|
/**
|
|
1749
1764
|
* Memoized component that renders a single tool call.
|
|
1750
1765
|
* This prevents unnecessary re-renders when parent components update
|
|
@@ -1811,7 +1826,7 @@ function warnAboutUnrenderedToolCalls(toolNames, registered, alreadyWarned) {
|
|
|
1811
1826
|
* @internal
|
|
1812
1827
|
*/
|
|
1813
1828
|
function useToolCallRenderers() {
|
|
1814
|
-
const { copilotkit } = (0,
|
|
1829
|
+
const { copilotkit } = (0, _copilotkit_react_core_context.useCopilotKit)();
|
|
1815
1830
|
return (0, react.useSyncExternalStore)((callback) => copilotkit.subscribe({ onRenderToolCallsChanged: callback }).unsubscribe, () => copilotkit.renderToolCalls, () => copilotkit.renderToolCalls);
|
|
1816
1831
|
}
|
|
1817
1832
|
/**
|
|
@@ -1821,7 +1836,7 @@ function useToolCallRenderers() {
|
|
|
1821
1836
|
* @returns A function that takes a tool call and optional tool message and returns the rendered component
|
|
1822
1837
|
*/
|
|
1823
1838
|
function useRenderToolCall() {
|
|
1824
|
-
const { copilotkit, executingToolCallIds } = (0,
|
|
1839
|
+
const { copilotkit, executingToolCallIds } = (0, _copilotkit_react_core_context.useCopilotKit)();
|
|
1825
1840
|
const agentId = useCopilotChatConfiguration()?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
1826
1841
|
const unrenderedToolNames = (0, react.useRef)(/* @__PURE__ */ new Set());
|
|
1827
1842
|
const warnedToolNames = (0, react.useRef)(/* @__PURE__ */ new Set());
|
|
@@ -1859,7 +1874,7 @@ function useRenderToolCall() {
|
|
|
1859
1874
|
}
|
|
1860
1875
|
|
|
1861
1876
|
//#endregion
|
|
1862
|
-
//#region src/
|
|
1877
|
+
//#region src/hooks/use-capabilities.tsx
|
|
1863
1878
|
/**
|
|
1864
1879
|
* Returns the capabilities declared by the given agent (or the agent resolved
|
|
1865
1880
|
* from the surrounding chat configuration, falling back to the default agent).
|
|
@@ -1884,7 +1899,7 @@ exports.CopilotChatDefaultLabels = CopilotChatDefaultLabels;
|
|
|
1884
1899
|
Object.defineProperty(exports, 'CopilotKitCoreReact', {
|
|
1885
1900
|
enumerable: true,
|
|
1886
1901
|
get: function () {
|
|
1887
|
-
return
|
|
1902
|
+
return _copilotkit_react_core_context.CopilotKitCoreReact;
|
|
1888
1903
|
}
|
|
1889
1904
|
});
|
|
1890
1905
|
exports.UseAgentUpdate = UseAgentUpdate;
|
|
@@ -1898,7 +1913,7 @@ exports.useCopilotChatConfiguration = useCopilotChatConfiguration;
|
|
|
1898
1913
|
Object.defineProperty(exports, 'useCopilotKit', {
|
|
1899
1914
|
enumerable: true,
|
|
1900
1915
|
get: function () {
|
|
1901
|
-
return
|
|
1916
|
+
return _copilotkit_react_core_context.useCopilotKit;
|
|
1902
1917
|
}
|
|
1903
1918
|
});
|
|
1904
1919
|
exports.useFrontendTool = useFrontendTool;
|