@copilotkit/react-core 2.0.0-rc.7 → 2.0.0-rc.9
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-CS35epe1.d.mts} +17 -33
- package/dist/MarkdownRendererContext-CS35epe1.d.mts.map +1 -0
- package/dist/{MarkdownRendererContext-CRKFzsEB.d.mts → MarkdownRendererContext-CfTh92vk.d.cts} +17 -33
- package/dist/MarkdownRendererContext-CfTh92vk.d.cts.map +1 -0
- package/dist/{MarkdownSurfaces-S4wfUl3J.cjs → MarkdownSurfaces-Ije2ZQh0.cjs} +111 -89
- package/dist/MarkdownSurfaces-Ije2ZQh0.cjs.map +1 -0
- package/dist/{MarkdownSurfaces-Bd--93O1.mjs → MarkdownSurfaces-iFKorV2w.mjs} +95 -80
- package/dist/MarkdownSurfaces-iFKorV2w.mjs.map +1 -0
- package/dist/context.cjs +20 -17
- 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 +20 -17
- package/dist/context.mjs.map +1 -1
- package/dist/generative-ui.cjs +541 -520
- 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 +37 -17
- package/dist/generative-ui.mjs.map +1 -1
- package/dist/headless.cjs +50 -76
- 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 +43 -74
- package/dist/headless.mjs.map +1 -1
- package/dist/index.cjs +765 -1292
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +176 -518
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +175 -517
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +469 -1251
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +867 -1375
- package/dist/index.umd.js.map +1 -1
- package/package.json +15 -16
- 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,10 +30,9 @@ 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
|
|
@@ -79,51 +78,6 @@ function useShallowStableRef(value) {
|
|
|
79
78
|
|
|
80
79
|
//#endregion
|
|
81
80
|
//#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
81
|
/**
|
|
128
82
|
* Mobile breakpoint below which the chat modal and the thread-list drawer are
|
|
129
83
|
* mutually exclusive. At or above this width both surfaces may coexist. This
|
|
@@ -148,7 +102,7 @@ const CopilotChatConfigurationProvider = ({ children, labels, agentId, threadId,
|
|
|
148
102
|
const parentConfig = (0, react.useContext)(CopilotChatConfiguration);
|
|
149
103
|
const stableLabels = useShallowStableRef(labels);
|
|
150
104
|
const mergedLabels = (0, react.useMemo)(() => ({
|
|
151
|
-
...CopilotChatDefaultLabels,
|
|
105
|
+
..._copilotkit_core.CopilotChatDefaultLabels,
|
|
152
106
|
...parentConfig?.labels,
|
|
153
107
|
...stableLabels
|
|
154
108
|
}), [stableLabels, parentConfig?.labels]);
|
|
@@ -655,6 +609,30 @@ function useDepsVersion(deps) {
|
|
|
655
609
|
|
|
656
610
|
//#endregion
|
|
657
611
|
//#region src/hooks/use-frontend-tool.tsx
|
|
612
|
+
/**
|
|
613
|
+
* Register a frontend tool while the component is mounted. The agent can
|
|
614
|
+
* call it, and its `render` component draws the call in the chat.
|
|
615
|
+
*
|
|
616
|
+
* A tool with the same name and agentId as a tool that is already registered
|
|
617
|
+
* (for example one from the provider's `tools`) overrides it while this
|
|
618
|
+
* component is mounted. When the component unmounts, the overridden tool is
|
|
619
|
+
* active again. The renderer stays registered after unmount, so past tool
|
|
620
|
+
* calls still render in the chat history.
|
|
621
|
+
*
|
|
622
|
+
* @param tool - The tool to register.
|
|
623
|
+
* @param deps - Extra values that re-register the tool when they change. Use
|
|
624
|
+
* it when the handler closes over a value that is not part of the tool.
|
|
625
|
+
*
|
|
626
|
+
* @example
|
|
627
|
+
* ```tsx
|
|
628
|
+
* useFrontendTool({
|
|
629
|
+
* name: "showWeather",
|
|
630
|
+
* description: "Show the weather for a city",
|
|
631
|
+
* parameters: z.object({ city: z.string() }),
|
|
632
|
+
* handler: async ({ city }) => `Sunny in ${city}`,
|
|
633
|
+
* });
|
|
634
|
+
* ```
|
|
635
|
+
*/
|
|
658
636
|
function useFrontendTool(tool, deps) {
|
|
659
637
|
const { copilotkit } = (0, _copilotkit_react_core_context.useCopilotKit)();
|
|
660
638
|
const depsVersion = useDepsVersion(deps);
|
|
@@ -663,11 +641,8 @@ function useFrontendTool(tool, deps) {
|
|
|
663
641
|
if (copilotkit.getTool({
|
|
664
642
|
toolName: name,
|
|
665
643
|
agentId: tool.agentId
|
|
666
|
-
})) {
|
|
667
|
-
|
|
668
|
-
copilotkit.removeTool(name, tool.agentId);
|
|
669
|
-
}
|
|
670
|
-
copilotkit.addTool(tool);
|
|
644
|
+
})) console.warn(`Tool '${name}' already exists for agent '${tool.agentId || "global"}'. Overriding with latest registration.`);
|
|
645
|
+
const unregister = copilotkit.addTool(tool);
|
|
671
646
|
if (tool.render) copilotkit.addHookRenderToolCall({
|
|
672
647
|
name,
|
|
673
648
|
args: tool.parameters,
|
|
@@ -675,7 +650,7 @@ function useFrontendTool(tool, deps) {
|
|
|
675
650
|
render: tool.render
|
|
676
651
|
});
|
|
677
652
|
return () => {
|
|
678
|
-
|
|
653
|
+
unregister();
|
|
679
654
|
};
|
|
680
655
|
}, [
|
|
681
656
|
tool.name,
|
|
@@ -700,8 +675,10 @@ const EMPTY_TOOLS = [];
|
|
|
700
675
|
*
|
|
701
676
|
* Tools are keyed by `name` plus `agentId`, the same as `useFrontendTool`. A
|
|
702
677
|
* tool that disappears from the array is unregistered on the next render, and
|
|
703
|
-
* every tool is unregistered on unmount.
|
|
704
|
-
*
|
|
678
|
+
* every tool is unregistered on unmount. A listed tool hides a tool with the
|
|
679
|
+
* same name and agentId (for example one from the provider's `tools`) until it
|
|
680
|
+
* is unregistered, and then the hidden tool is active again. Renderers stay
|
|
681
|
+
* registered after unmount so past tool calls still render in the chat history.
|
|
705
682
|
*
|
|
706
683
|
* @param tools - The tools to register. May be empty and may change length.
|
|
707
684
|
* @param deps - Extra dependencies that force re-registration, compared by
|
|
@@ -751,15 +728,13 @@ function useFrontendTools(tools, deps) {
|
|
|
751
728
|
deduped.set(key, tool);
|
|
752
729
|
}
|
|
753
730
|
const registered = [...deduped.values()];
|
|
731
|
+
const unregisters = [];
|
|
754
732
|
for (const tool of registered) {
|
|
755
733
|
if (copilotkit.getTool({
|
|
756
734
|
toolName: tool.name,
|
|
757
735
|
agentId: tool.agentId
|
|
758
|
-
})) {
|
|
759
|
-
|
|
760
|
-
copilotkit.removeTool(tool.name, tool.agentId);
|
|
761
|
-
}
|
|
762
|
-
copilotkit.addTool(tool);
|
|
736
|
+
})) console.warn(`Tool '${tool.name}' already exists for agent '${tool.agentId || "global"}'. Overriding with latest registration.`);
|
|
737
|
+
unregisters.push(copilotkit.addTool(tool));
|
|
763
738
|
if (tool.render) copilotkit.addHookRenderToolCall({
|
|
764
739
|
name: tool.name,
|
|
765
740
|
args: tool.parameters,
|
|
@@ -768,7 +743,7 @@ function useFrontendTools(tools, deps) {
|
|
|
768
743
|
});
|
|
769
744
|
}
|
|
770
745
|
return () => {
|
|
771
|
-
for (const
|
|
746
|
+
for (const unregister of unregisters) unregister();
|
|
772
747
|
};
|
|
773
748
|
}, [
|
|
774
749
|
JSON.stringify(toolList.map((tool) => [
|
|
@@ -944,11 +919,6 @@ function useHumanInTheLoop(tool, deps) {
|
|
|
944
919
|
]);
|
|
945
920
|
}
|
|
946
921
|
|
|
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
922
|
//#endregion
|
|
953
923
|
//#region src/hooks/use-interrupt.tsx
|
|
954
924
|
/** Recognize thenables returned by interrupt preprocessing handlers. */
|
|
@@ -959,7 +929,7 @@ function isPromiseLike(value) {
|
|
|
959
929
|
function toLegacyEvent(pending) {
|
|
960
930
|
if (pending.kind === "legacy") return pending.event;
|
|
961
931
|
return {
|
|
962
|
-
name: INTERRUPT_EVENT_NAME,
|
|
932
|
+
name: _copilotkit_core.INTERRUPT_EVENT_NAME,
|
|
963
933
|
value: pending.interrupts[0]
|
|
964
934
|
};
|
|
965
935
|
}
|
|
@@ -1006,7 +976,7 @@ function useInterrupt(config) {
|
|
|
1006
976
|
let localStandard = null;
|
|
1007
977
|
const subscription = agent.subscribe({
|
|
1008
978
|
onCustomEvent: ({ event }) => {
|
|
1009
|
-
if (event.name === INTERRUPT_EVENT_NAME) localLegacy = {
|
|
979
|
+
if (event.name === _copilotkit_core.INTERRUPT_EVENT_NAME) localLegacy = {
|
|
1010
980
|
name: event.name,
|
|
1011
981
|
value: event.value
|
|
1012
982
|
};
|
|
@@ -1664,7 +1634,7 @@ function useThreads({ agentId, includeArchived, limit, enabled = true }) {
|
|
|
1664
1634
|
//#endregion
|
|
1665
1635
|
//#region src/types/defineToolCallRenderer.ts
|
|
1666
1636
|
function defineToolCallRenderer(def) {
|
|
1667
|
-
const argsSchema = def.name === "*" && !def.args ?
|
|
1637
|
+
const argsSchema = def.name === "*" && !def.args ? _copilotkit_shared.ɵanySchema : def.args;
|
|
1668
1638
|
return {
|
|
1669
1639
|
name: def.name,
|
|
1670
1640
|
args: argsSchema,
|
|
@@ -1842,18 +1812,17 @@ function useRenderToolCall() {
|
|
|
1842
1812
|
const warnedToolNames = (0, react.useRef)(/* @__PURE__ */ new Set());
|
|
1843
1813
|
const renderToolCalls = useToolCallRenderers();
|
|
1844
1814
|
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 === "*");
|
|
1815
|
+
const renderConfig = (0, _copilotkit_core.ɵresolveToolCallRenderer)(renderToolCalls, toolCall.function.name, agentId);
|
|
1847
1816
|
if (!renderConfig) {
|
|
1848
1817
|
if (IS_DEVELOPMENT) unrenderedToolNames.current.add(toolCall.function.name);
|
|
1849
1818
|
return null;
|
|
1850
1819
|
}
|
|
1851
|
-
const
|
|
1820
|
+
const isExecuting = executingToolCallIds.has(toolCall.id);
|
|
1852
1821
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolCallRenderer, {
|
|
1853
1822
|
toolCall,
|
|
1854
1823
|
toolMessage,
|
|
1855
|
-
RenderComponent,
|
|
1856
|
-
isExecuting
|
|
1824
|
+
RenderComponent: renderConfig.render,
|
|
1825
|
+
isExecuting
|
|
1857
1826
|
}, toolCall.id);
|
|
1858
1827
|
}, [
|
|
1859
1828
|
renderToolCalls,
|
|
@@ -1895,7 +1864,12 @@ function useCapabilities(agentId) {
|
|
|
1895
1864
|
|
|
1896
1865
|
//#endregion
|
|
1897
1866
|
exports.CopilotChatConfigurationProvider = CopilotChatConfigurationProvider;
|
|
1898
|
-
exports
|
|
1867
|
+
Object.defineProperty(exports, 'CopilotChatDefaultLabels', {
|
|
1868
|
+
enumerable: true,
|
|
1869
|
+
get: function () {
|
|
1870
|
+
return _copilotkit_core.CopilotChatDefaultLabels;
|
|
1871
|
+
}
|
|
1872
|
+
});
|
|
1899
1873
|
Object.defineProperty(exports, 'CopilotKitCoreReact', {
|
|
1900
1874
|
enumerable: true,
|
|
1901
1875
|
get: function () {
|