@copilotkit/react-core 2.0.0-rc.2 → 2.0.0-rc.20
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/{MarkdownRendererContext-B4Us6mwL.d.cts → MarkdownRendererContext-Bsl28Gmn.d.mts} +17 -33
- package/dist/MarkdownRendererContext-Bsl28Gmn.d.mts.map +1 -0
- package/dist/{MarkdownRendererContext-CRKFzsEB.d.mts → MarkdownRendererContext-CBppkb5j.d.cts} +17 -33
- package/dist/MarkdownRendererContext-CBppkb5j.d.cts.map +1 -0
- package/dist/{MarkdownSurfaces-Bd--93O1.mjs → MarkdownSurfaces-Bt7TD_U1.mjs} +177 -136
- package/dist/MarkdownSurfaces-Bt7TD_U1.mjs.map +1 -0
- package/dist/{MarkdownSurfaces-S4wfUl3J.cjs → MarkdownSurfaces-CoUoPhR9.cjs} +198 -156
- package/dist/MarkdownSurfaces-CoUoPhR9.cjs.map +1 -0
- package/dist/context.cjs +28 -26
- package/dist/context.cjs.map +1 -1
- package/dist/context.d.cts +38 -98
- package/dist/context.d.cts.map +1 -1
- package/dist/context.d.mts +38 -98
- package/dist/context.d.mts.map +1 -1
- package/dist/context.mjs +28 -26
- package/dist/context.mjs.map +1 -1
- package/dist/generative-ui.cjs +570 -567
- package/dist/generative-ui.cjs.map +1 -1
- package/dist/generative-ui.d.cts +2137 -4178
- package/dist/generative-ui.d.cts.map +1 -1
- package/dist/generative-ui.d.mts +2137 -4178
- package/dist/generative-ui.d.mts.map +1 -1
- package/dist/generative-ui.mjs +75 -73
- package/dist/generative-ui.mjs.map +1 -1
- package/dist/headless.cjs +55 -84
- package/dist/headless.cjs.map +1 -1
- package/dist/headless.d.cts +78 -253
- package/dist/headless.d.cts.map +1 -1
- package/dist/headless.d.mts +56 -202
- package/dist/headless.d.mts.map +1 -1
- package/dist/headless.mjs +48 -82
- package/dist/headless.mjs.map +1 -1
- package/dist/index.cjs +1628 -2398
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +203 -540
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +202 -539
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +965 -2248
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +1776 -2466
- package/dist/index.umd.js.map +1 -1
- package/package.json +17 -18
- package/dist/MarkdownRendererContext-B4Us6mwL.d.cts.map +0 -1
- package/dist/MarkdownRendererContext-CRKFzsEB.d.mts.map +0 -1
- package/dist/MarkdownSurfaces-Bd--93O1.mjs.map +0 -1
- package/dist/MarkdownSurfaces-S4wfUl3J.cjs.map +0 -1
package/dist/headless.cjs
CHANGED
|
@@ -30,22 +30,18 @@ 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");
|
|
33
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
34
33
|
let _copilotkit_core = require("@copilotkit/core");
|
|
34
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
35
35
|
let _ag_ui_client = require("@ag-ui/client");
|
|
36
|
-
let zod = require("zod");
|
|
37
36
|
let _ag_ui_core = require("@ag-ui/core");
|
|
38
37
|
|
|
39
38
|
//#region src/lib/shallow-stable-ref.ts
|
|
40
39
|
/**
|
|
41
|
-
* Shallow equality comparison for objects
|
|
40
|
+
* Shallow equality comparison for objects: same own keys, each holding the
|
|
41
|
+
* same value (`Object.is`). Core's `ɵshallowEqualRecord` holds the rule.
|
|
42
42
|
*/
|
|
43
43
|
function shallowEqual(obj1, obj2) {
|
|
44
|
-
|
|
45
|
-
const keys2 = Object.keys(obj2);
|
|
46
|
-
if (keys1.length !== keys2.length) return false;
|
|
47
|
-
for (const key of keys1) if (obj1[key] !== obj2[key]) return false;
|
|
48
|
-
return true;
|
|
44
|
+
return (0, _copilotkit_core.ɵshallowEqualRecord)(obj1, obj2);
|
|
49
45
|
}
|
|
50
46
|
/**
|
|
51
47
|
* Returns true only for plain JS objects (`{}`), excluding arrays, Dates,
|
|
@@ -79,51 +75,6 @@ function useShallowStableRef(value) {
|
|
|
79
75
|
|
|
80
76
|
//#endregion
|
|
81
77
|
//#region src/providers/CopilotChatConfigurationProvider.tsx
|
|
82
|
-
const CopilotChatDefaultLabels = {
|
|
83
|
-
chatInputPlaceholder: "Type a message...",
|
|
84
|
-
chatInputToolbarStartTranscribeButtonLabel: "Transcribe",
|
|
85
|
-
chatInputToolbarCancelTranscribeButtonLabel: "Cancel",
|
|
86
|
-
chatInputToolbarFinishTranscribeButtonLabel: "Finish",
|
|
87
|
-
chatInputToolbarAddButtonLabel: "Add attachments",
|
|
88
|
-
chatInputToolbarToolsButtonLabel: "Tools",
|
|
89
|
-
chatInputToolbarSendButtonLabel: "Send message",
|
|
90
|
-
chatInputToolbarStopButtonLabel: "Stop",
|
|
91
|
-
assistantMessageToolbarCopyCodeLabel: "Copy",
|
|
92
|
-
assistantMessageToolbarCopyCodeCopiedLabel: "Copied",
|
|
93
|
-
assistantMessageToolbarCopyMessageLabel: "Copy",
|
|
94
|
-
assistantMessageToolbarInspectorLabel: "View in Inspector",
|
|
95
|
-
assistantMessageToolbarInspectorDescription: "Open this message in the Inspector",
|
|
96
|
-
assistantMessageToolbarInspectorLocalOnlyLabel: "Local only",
|
|
97
|
-
assistantMessageToolbarInspectorLocalOnlyDescription: "Only visible on localhost or loopback hosts in development. Never shown in production.",
|
|
98
|
-
assistantMessageToolbarInspectorTitle: "CopilotKit Inspector",
|
|
99
|
-
assistantMessageToolbarInspectorHideLabel: "Hide this icon",
|
|
100
|
-
assistantMessageToolbarInspectorHideDescription: "Until you reload this page",
|
|
101
|
-
assistantMessageToolbarThumbsUpLabel: "Good response",
|
|
102
|
-
assistantMessageToolbarThumbsDownLabel: "Bad response",
|
|
103
|
-
assistantMessageFeedbackCommentPlaceholder: "Add a comment (optional)",
|
|
104
|
-
assistantMessageFeedbackCommentSubmitLabel: "Send comment",
|
|
105
|
-
assistantMessageToolbarReadAloudLabel: "Read aloud",
|
|
106
|
-
assistantMessageToolbarRegenerateLabel: "Regenerate",
|
|
107
|
-
userMessageToolbarCopyMessageLabel: "Copy",
|
|
108
|
-
userMessageToolbarEditMessageLabel: "Edit",
|
|
109
|
-
userMessageToolbarPreviousBranchLabel: "Previous branch",
|
|
110
|
-
userMessageToolbarNextBranchLabel: "Next branch",
|
|
111
|
-
chatDisclaimerText: "AI can make mistakes. Please verify important information.",
|
|
112
|
-
chatToggleOpenLabel: "Open chat",
|
|
113
|
-
chatToggleCloseLabel: "Close chat",
|
|
114
|
-
chatScrollToBottomLabel: "Scroll to bottom",
|
|
115
|
-
modalHeaderTitle: "CopilotKit Chat",
|
|
116
|
-
welcomeMessageText: "How can I help you today?",
|
|
117
|
-
reasoningMessageThinkingLabel: "Thinking…",
|
|
118
|
-
chatInputSlashMenuLabel: "Slash commands",
|
|
119
|
-
chatInputSlashMenuEmptyText: "No commands found",
|
|
120
|
-
attachmentRemoveButtonLabel: "Remove attachment",
|
|
121
|
-
attachmentPlayVideoButtonLabel: "Play video",
|
|
122
|
-
attachmentPreviewCloseButtonLabel: "Close preview",
|
|
123
|
-
modalHeaderCloseButtonLabel: "Close",
|
|
124
|
-
modalHeaderThreadsButtonLabel: "Open threads",
|
|
125
|
-
sidebarLabel: "Copilot chat sidebar"
|
|
126
|
-
};
|
|
127
78
|
/**
|
|
128
79
|
* Mobile breakpoint below which the chat modal and the thread-list drawer are
|
|
129
80
|
* mutually exclusive. At or above this width both surfaces may coexist. This
|
|
@@ -148,7 +99,7 @@ const CopilotChatConfigurationProvider = ({ children, labels, agentId, threadId,
|
|
|
148
99
|
const parentConfig = (0, react.useContext)(CopilotChatConfiguration);
|
|
149
100
|
const stableLabels = useShallowStableRef(labels);
|
|
150
101
|
const mergedLabels = (0, react.useMemo)(() => ({
|
|
151
|
-
...CopilotChatDefaultLabels,
|
|
102
|
+
..._copilotkit_core.CopilotChatDefaultLabels,
|
|
152
103
|
...parentConfig?.labels,
|
|
153
104
|
...stableLabels
|
|
154
105
|
}), [stableLabels, parentConfig?.labels]);
|
|
@@ -655,6 +606,30 @@ function useDepsVersion(deps) {
|
|
|
655
606
|
|
|
656
607
|
//#endregion
|
|
657
608
|
//#region src/hooks/use-frontend-tool.tsx
|
|
609
|
+
/**
|
|
610
|
+
* Register a frontend tool while the component is mounted. The agent can
|
|
611
|
+
* call it, and its `render` component draws the call in the chat.
|
|
612
|
+
*
|
|
613
|
+
* A tool with the same name and agentId as a tool that is already registered
|
|
614
|
+
* (for example one from the provider's `tools`) overrides it while this
|
|
615
|
+
* component is mounted. When the component unmounts, the overridden tool is
|
|
616
|
+
* active again. The renderer stays registered after unmount, so past tool
|
|
617
|
+
* calls still render in the chat history.
|
|
618
|
+
*
|
|
619
|
+
* @param tool - The tool to register.
|
|
620
|
+
* @param deps - Extra values that re-register the tool when they change. Use
|
|
621
|
+
* it when the handler closes over a value that is not part of the tool.
|
|
622
|
+
*
|
|
623
|
+
* @example
|
|
624
|
+
* ```tsx
|
|
625
|
+
* useFrontendTool({
|
|
626
|
+
* name: "showWeather",
|
|
627
|
+
* description: "Show the weather for a city",
|
|
628
|
+
* parameters: z.object({ city: z.string() }),
|
|
629
|
+
* handler: async ({ city }) => `Sunny in ${city}`,
|
|
630
|
+
* });
|
|
631
|
+
* ```
|
|
632
|
+
*/
|
|
658
633
|
function useFrontendTool(tool, deps) {
|
|
659
634
|
const { copilotkit } = (0, _copilotkit_react_core_context.useCopilotKit)();
|
|
660
635
|
const depsVersion = useDepsVersion(deps);
|
|
@@ -663,11 +638,8 @@ function useFrontendTool(tool, deps) {
|
|
|
663
638
|
if (copilotkit.getTool({
|
|
664
639
|
toolName: name,
|
|
665
640
|
agentId: tool.agentId
|
|
666
|
-
})) {
|
|
667
|
-
|
|
668
|
-
copilotkit.removeTool(name, tool.agentId);
|
|
669
|
-
}
|
|
670
|
-
copilotkit.addTool(tool);
|
|
641
|
+
})) console.warn(`Tool '${name}' already exists for agent '${tool.agentId || "global"}'. Overriding with latest registration.`);
|
|
642
|
+
const unregister = copilotkit.addTool(tool);
|
|
671
643
|
if (tool.render) copilotkit.addHookRenderToolCall({
|
|
672
644
|
name,
|
|
673
645
|
args: tool.parameters,
|
|
@@ -675,7 +647,7 @@ function useFrontendTool(tool, deps) {
|
|
|
675
647
|
render: tool.render
|
|
676
648
|
});
|
|
677
649
|
return () => {
|
|
678
|
-
|
|
650
|
+
unregister();
|
|
679
651
|
};
|
|
680
652
|
}, [
|
|
681
653
|
tool.name,
|
|
@@ -700,8 +672,10 @@ const EMPTY_TOOLS = [];
|
|
|
700
672
|
*
|
|
701
673
|
* Tools are keyed by `name` plus `agentId`, the same as `useFrontendTool`. A
|
|
702
674
|
* tool that disappears from the array is unregistered on the next render, and
|
|
703
|
-
* every tool is unregistered on unmount.
|
|
704
|
-
*
|
|
675
|
+
* every tool is unregistered on unmount. A listed tool hides a tool with the
|
|
676
|
+
* same name and agentId (for example one from the provider's `tools`) until it
|
|
677
|
+
* is unregistered, and then the hidden tool is active again. Renderers stay
|
|
678
|
+
* registered after unmount so past tool calls still render in the chat history.
|
|
705
679
|
*
|
|
706
680
|
* @param tools - The tools to register. May be empty and may change length.
|
|
707
681
|
* @param deps - Extra dependencies that force re-registration, compared by
|
|
@@ -751,15 +725,13 @@ function useFrontendTools(tools, deps) {
|
|
|
751
725
|
deduped.set(key, tool);
|
|
752
726
|
}
|
|
753
727
|
const registered = [...deduped.values()];
|
|
728
|
+
const unregisters = [];
|
|
754
729
|
for (const tool of registered) {
|
|
755
730
|
if (copilotkit.getTool({
|
|
756
731
|
toolName: tool.name,
|
|
757
732
|
agentId: tool.agentId
|
|
758
|
-
})) {
|
|
759
|
-
|
|
760
|
-
copilotkit.removeTool(tool.name, tool.agentId);
|
|
761
|
-
}
|
|
762
|
-
copilotkit.addTool(tool);
|
|
733
|
+
})) console.warn(`Tool '${tool.name}' already exists for agent '${tool.agentId || "global"}'. Overriding with latest registration.`);
|
|
734
|
+
unregisters.push(copilotkit.addTool(tool));
|
|
763
735
|
if (tool.render) copilotkit.addHookRenderToolCall({
|
|
764
736
|
name: tool.name,
|
|
765
737
|
args: tool.parameters,
|
|
@@ -768,7 +740,7 @@ function useFrontendTools(tools, deps) {
|
|
|
768
740
|
});
|
|
769
741
|
}
|
|
770
742
|
return () => {
|
|
771
|
-
for (const
|
|
743
|
+
for (const unregister of unregisters) unregister();
|
|
772
744
|
};
|
|
773
745
|
}, [
|
|
774
746
|
JSON.stringify(toolList.map((tool) => [
|
|
@@ -944,11 +916,6 @@ function useHumanInTheLoop(tool, deps) {
|
|
|
944
916
|
]);
|
|
945
917
|
}
|
|
946
918
|
|
|
947
|
-
//#endregion
|
|
948
|
-
//#region src/types/interrupt.ts
|
|
949
|
-
/** Name of the legacy custom event agents emit to signal an interrupt. */
|
|
950
|
-
const INTERRUPT_EVENT_NAME = "on_interrupt";
|
|
951
|
-
|
|
952
919
|
//#endregion
|
|
953
920
|
//#region src/hooks/use-interrupt.tsx
|
|
954
921
|
/** Recognize thenables returned by interrupt preprocessing handlers. */
|
|
@@ -959,7 +926,7 @@ function isPromiseLike(value) {
|
|
|
959
926
|
function toLegacyEvent(pending) {
|
|
960
927
|
if (pending.kind === "legacy") return pending.event;
|
|
961
928
|
return {
|
|
962
|
-
name: INTERRUPT_EVENT_NAME,
|
|
929
|
+
name: _copilotkit_core.INTERRUPT_EVENT_NAME,
|
|
963
930
|
value: pending.interrupts[0]
|
|
964
931
|
};
|
|
965
932
|
}
|
|
@@ -1006,7 +973,7 @@ function useInterrupt(config) {
|
|
|
1006
973
|
let localStandard = null;
|
|
1007
974
|
const subscription = agent.subscribe({
|
|
1008
975
|
onCustomEvent: ({ event }) => {
|
|
1009
|
-
if (event.name === INTERRUPT_EVENT_NAME) localLegacy = {
|
|
976
|
+
if (event.name === _copilotkit_core.INTERRUPT_EVENT_NAME) localLegacy = {
|
|
1010
977
|
name: event.name,
|
|
1011
978
|
value: event.value
|
|
1012
979
|
};
|
|
@@ -1177,7 +1144,7 @@ function useInterrupt(config) {
|
|
|
1177
1144
|
try {
|
|
1178
1145
|
maybePromise = handler({
|
|
1179
1146
|
event: legacyEvent,
|
|
1180
|
-
interrupt: pending.kind === "standard" ? pending.interrupts[0] : null,
|
|
1147
|
+
interrupt: pending.kind === "standard" ? pending.interrupts[0] ?? null : null,
|
|
1181
1148
|
interrupts: pending.kind === "standard" ? [...pending.interrupts] : [],
|
|
1182
1149
|
resolve: resolveRef.current,
|
|
1183
1150
|
cancel: cancelRef.current
|
|
@@ -1206,7 +1173,7 @@ function useInterrupt(config) {
|
|
|
1206
1173
|
if (!isEnabled(legacyEvent)) return null;
|
|
1207
1174
|
return renderRef.current({
|
|
1208
1175
|
event: legacyEvent,
|
|
1209
|
-
interrupt: pending.kind === "standard" ? pending.interrupts[0] : null,
|
|
1176
|
+
interrupt: pending.kind === "standard" ? pending.interrupts[0] ?? null : null,
|
|
1210
1177
|
interrupts: pending.kind === "standard" ? [...pending.interrupts] : [],
|
|
1211
1178
|
result: handlerResult,
|
|
1212
1179
|
resolve,
|
|
@@ -1664,7 +1631,7 @@ function useThreads({ agentId, includeArchived, limit, enabled = true }) {
|
|
|
1664
1631
|
//#endregion
|
|
1665
1632
|
//#region src/types/defineToolCallRenderer.ts
|
|
1666
1633
|
function defineToolCallRenderer(def) {
|
|
1667
|
-
const argsSchema = def.name === "*" && !def.args ?
|
|
1634
|
+
const argsSchema = def.name === "*" && !def.args ? _copilotkit_shared.ɵanySchema : def.args;
|
|
1668
1635
|
return {
|
|
1669
1636
|
name: def.name,
|
|
1670
1637
|
args: argsSchema,
|
|
@@ -1842,18 +1809,17 @@ function useRenderToolCall() {
|
|
|
1842
1809
|
const warnedToolNames = (0, react.useRef)(/* @__PURE__ */ new Set());
|
|
1843
1810
|
const renderToolCalls = useToolCallRenderers();
|
|
1844
1811
|
const renderToolCall = (0, react.useCallback)(({ toolCall, toolMessage }) => {
|
|
1845
|
-
const
|
|
1846
|
-
const renderConfig = exactMatches.find((rc) => rc.agentId === agentId) || exactMatches.find((rc) => !rc.agentId) || exactMatches[0] || renderToolCalls.find((rc) => rc.name === "*");
|
|
1812
|
+
const renderConfig = (0, _copilotkit_core.ɵresolveToolCallRenderer)(renderToolCalls, toolCall.function.name, agentId);
|
|
1847
1813
|
if (!renderConfig) {
|
|
1848
1814
|
if (IS_DEVELOPMENT) unrenderedToolNames.current.add(toolCall.function.name);
|
|
1849
1815
|
return null;
|
|
1850
1816
|
}
|
|
1851
|
-
const
|
|
1817
|
+
const isExecuting = executingToolCallIds.has(toolCall.id);
|
|
1852
1818
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolCallRenderer, {
|
|
1853
1819
|
toolCall,
|
|
1854
1820
|
toolMessage,
|
|
1855
|
-
RenderComponent,
|
|
1856
|
-
isExecuting
|
|
1821
|
+
RenderComponent: renderConfig.render,
|
|
1822
|
+
isExecuting
|
|
1857
1823
|
}, toolCall.id);
|
|
1858
1824
|
}, [
|
|
1859
1825
|
renderToolCalls,
|
|
@@ -1895,7 +1861,12 @@ function useCapabilities(agentId) {
|
|
|
1895
1861
|
|
|
1896
1862
|
//#endregion
|
|
1897
1863
|
exports.CopilotChatConfigurationProvider = CopilotChatConfigurationProvider;
|
|
1898
|
-
exports
|
|
1864
|
+
Object.defineProperty(exports, 'CopilotChatDefaultLabels', {
|
|
1865
|
+
enumerable: true,
|
|
1866
|
+
get: function () {
|
|
1867
|
+
return _copilotkit_core.CopilotChatDefaultLabels;
|
|
1868
|
+
}
|
|
1869
|
+
});
|
|
1899
1870
|
Object.defineProperty(exports, 'CopilotKitCoreReact', {
|
|
1900
1871
|
enumerable: true,
|
|
1901
1872
|
get: function () {
|