@copilotkit/react-core 1.72.1-canary.sp-longthread-perf → 1.73.2-canary.1790068297
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-D5fPO8hJ.d.cts → copilotkit-C7c_w9iV.d.cts} +88 -9
- package/dist/copilotkit-C7c_w9iV.d.cts.map +1 -0
- package/dist/{copilotkit-BRPxLJnI.d.mts → copilotkit-CfyJ1-Nx.d.mts} +88 -9
- package/dist/copilotkit-CfyJ1-Nx.d.mts.map +1 -0
- package/dist/{copilotkit-B2TZRWwp.mjs → copilotkit-CwVE-0JG.mjs} +154 -99
- package/dist/copilotkit-CwVE-0JG.mjs.map +1 -0
- package/dist/{copilotkit-BV7MguMm.cjs → copilotkit-D_c2dJ9t.cjs} +156 -95
- package/dist/copilotkit-D_c2dJ9t.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +8 -2
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/headless.cjs +101 -2
- package/dist/v2/headless.cjs.map +1 -1
- package/dist/v2/headless.d.cts +53 -1
- package/dist/v2/headless.d.cts.map +1 -1
- package/dist/v2/headless.d.mts +53 -1
- package/dist/v2/headless.d.mts.map +1 -1
- package/dist/v2/headless.mjs +101 -3
- package/dist/v2/headless.mjs.map +1 -1
- package/dist/v2/index.cjs +1285 -55
- package/dist/v2/index.d.cts +2 -4
- package/dist/v2/index.d.mts +2 -4
- package/dist/v2/index.mjs +2 -6
- package/dist/v2/index.umd.js +1439 -155
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +12 -11
- package/dist/copilotkit-B2TZRWwp.mjs.map +0 -1
- package/dist/copilotkit-BRPxLJnI.d.mts.map +0 -1
- package/dist/copilotkit-BV7MguMm.cjs.map +0 -1
- package/dist/copilotkit-D5fPO8hJ.d.cts.map +0 -1
package/dist/v2/headless.cjs
CHANGED
|
@@ -543,10 +543,10 @@ function useAgent({ agentId, threadId, runtimeAgentId, updates, throttleMs } = {
|
|
|
543
543
|
|
|
544
544
|
//#endregion
|
|
545
545
|
//#region src/v2/hooks/use-frontend-tool.tsx
|
|
546
|
-
const EMPTY_DEPS$
|
|
546
|
+
const EMPTY_DEPS$2 = [];
|
|
547
547
|
function useFrontendTool(tool, deps) {
|
|
548
548
|
const { copilotkit } = (0, _copilotkit_react_core_v2_context.useCopilotKit)();
|
|
549
|
-
const extraDeps = deps ?? EMPTY_DEPS$
|
|
549
|
+
const extraDeps = deps ?? EMPTY_DEPS$2;
|
|
550
550
|
(0, react.useLayoutEffect)(() => {
|
|
551
551
|
const name = tool.name;
|
|
552
552
|
if (copilotkit.getTool({
|
|
@@ -575,6 +575,103 @@ function useFrontendTool(tool, deps) {
|
|
|
575
575
|
]);
|
|
576
576
|
}
|
|
577
577
|
|
|
578
|
+
//#endregion
|
|
579
|
+
//#region src/v2/hooks/use-frontend-tools.tsx
|
|
580
|
+
const EMPTY_DEPS$1 = [];
|
|
581
|
+
const EMPTY_TOOLS = [];
|
|
582
|
+
/**
|
|
583
|
+
* Register a list of frontend tools whose length can change between renders.
|
|
584
|
+
*
|
|
585
|
+
* `useFrontendTool` registers exactly one tool per call, so it cannot be called
|
|
586
|
+
* in a loop over a runtime-length list without breaking the rules of hooks.
|
|
587
|
+
* This hook runs a single effect over the whole array instead, which makes it
|
|
588
|
+
* safe to build the list from state, props, or a server response.
|
|
589
|
+
*
|
|
590
|
+
* Tools are keyed by `name` plus `agentId`, the same as `useFrontendTool`. A
|
|
591
|
+
* tool that disappears from the array is unregistered on the next render, and
|
|
592
|
+
* every tool is unregistered on unmount. Renderers stay registered after
|
|
593
|
+
* unmount so past tool calls still render in the chat history.
|
|
594
|
+
*
|
|
595
|
+
* @param tools - The tools to register. May be empty and may change length.
|
|
596
|
+
* @param deps - Extra dependencies that force re-registration, compared by
|
|
597
|
+
* identity like the second argument of `useEffect`. Use this when a handler
|
|
598
|
+
* closes over a value that is not part of the tool definition. Keep the array
|
|
599
|
+
* a constant length across renders.
|
|
600
|
+
*
|
|
601
|
+
* @example
|
|
602
|
+
* Register one tool per item in application state:
|
|
603
|
+
* ```tsx
|
|
604
|
+
* const [reports, setReports] = useState<Report[]>([]);
|
|
605
|
+
*
|
|
606
|
+
* useFrontendTools(
|
|
607
|
+
* reports.map((report) => ({
|
|
608
|
+
* name: `open_${report.id}`,
|
|
609
|
+
* description: `Open the ${report.title} report`,
|
|
610
|
+
* handler: async () => navigate(`/reports/${report.id}`),
|
|
611
|
+
* })),
|
|
612
|
+
* [navigate],
|
|
613
|
+
* );
|
|
614
|
+
* ```
|
|
615
|
+
*
|
|
616
|
+
* @example
|
|
617
|
+
* Register tools described by the backend:
|
|
618
|
+
* ```tsx
|
|
619
|
+
* const { data } = useQuery(fetchToolDescriptors);
|
|
620
|
+
*
|
|
621
|
+
* useFrontendTools(
|
|
622
|
+
* (data ?? []).map((descriptor) => ({
|
|
623
|
+
* name: descriptor.name,
|
|
624
|
+
* description: descriptor.description,
|
|
625
|
+
* parameters: z.object({ query: z.string() }),
|
|
626
|
+
* handler: async ({ query }) => runDescriptor(descriptor.id, query),
|
|
627
|
+
* })),
|
|
628
|
+
* );
|
|
629
|
+
* ```
|
|
630
|
+
*/
|
|
631
|
+
function useFrontendTools(tools, deps) {
|
|
632
|
+
const { copilotkit } = (0, _copilotkit_react_core_v2_context.useCopilotKit)();
|
|
633
|
+
const toolList = tools ?? EMPTY_TOOLS;
|
|
634
|
+
const extraDeps = deps ?? EMPTY_DEPS$1;
|
|
635
|
+
(0, react.useLayoutEffect)(() => {
|
|
636
|
+
const deduped = /* @__PURE__ */ new Map();
|
|
637
|
+
for (const tool of toolList) {
|
|
638
|
+
const key = `${tool.agentId ?? ""}:${tool.name}`;
|
|
639
|
+
if (deduped.has(key)) console.warn(`Tool '${tool.name}' is listed more than once for agent '${tool.agentId || "global"}' in the same useFrontendTools call. Using the last entry.`);
|
|
640
|
+
deduped.set(key, tool);
|
|
641
|
+
}
|
|
642
|
+
const registered = [...deduped.values()];
|
|
643
|
+
for (const tool of registered) {
|
|
644
|
+
if (copilotkit.getTool({
|
|
645
|
+
toolName: tool.name,
|
|
646
|
+
agentId: tool.agentId
|
|
647
|
+
})) {
|
|
648
|
+
console.warn(`Tool '${tool.name}' already exists for agent '${tool.agentId || "global"}'. Overriding with latest registration.`);
|
|
649
|
+
copilotkit.removeTool(tool.name, tool.agentId);
|
|
650
|
+
}
|
|
651
|
+
copilotkit.addTool(tool);
|
|
652
|
+
if (tool.render) copilotkit.addHookRenderToolCall({
|
|
653
|
+
name: tool.name,
|
|
654
|
+
args: tool.parameters,
|
|
655
|
+
agentId: tool.agentId,
|
|
656
|
+
render: tool.render
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
return () => {
|
|
660
|
+
for (const tool of registered) copilotkit.removeTool(tool.name, tool.agentId);
|
|
661
|
+
};
|
|
662
|
+
}, [
|
|
663
|
+
JSON.stringify(toolList.map((tool) => [
|
|
664
|
+
tool.name,
|
|
665
|
+
tool.description ?? null,
|
|
666
|
+
tool.agentId ?? null,
|
|
667
|
+
tool.available ?? null,
|
|
668
|
+
tool.webmcp ?? null
|
|
669
|
+
])),
|
|
670
|
+
copilotkit,
|
|
671
|
+
...extraDeps
|
|
672
|
+
]);
|
|
673
|
+
}
|
|
674
|
+
|
|
578
675
|
//#endregion
|
|
579
676
|
//#region src/v2/hooks/use-component.tsx
|
|
580
677
|
/**
|
|
@@ -721,6 +818,7 @@ function useHumanInTheLoop(tool, deps) {
|
|
|
721
818
|
]);
|
|
722
819
|
useFrontendTool({
|
|
723
820
|
...tool,
|
|
821
|
+
type: "human-in-the-loop",
|
|
724
822
|
handler,
|
|
725
823
|
render: RenderComponent
|
|
726
824
|
}, deps);
|
|
@@ -1706,6 +1804,7 @@ Object.defineProperty(exports, 'useCopilotKit', {
|
|
|
1706
1804
|
}
|
|
1707
1805
|
});
|
|
1708
1806
|
exports.useFrontendTool = useFrontendTool;
|
|
1807
|
+
exports.useFrontendTools = useFrontendTools;
|
|
1709
1808
|
exports.useHumanInTheLoop = useHumanInTheLoop;
|
|
1710
1809
|
exports.useInterrupt = useInterrupt;
|
|
1711
1810
|
exports.useRenderTool = useRenderTool;
|