@copilotkit/react-core 1.79.1 → 1.80.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/{copilotkit-CD3uPUN3.mjs → copilotkit-BNLtgOyD.mjs} +1855 -221
- package/dist/copilotkit-BNLtgOyD.mjs.map +1 -0
- package/dist/{copilotkit-Yz8qXx00.d.mts → copilotkit-CWOSXhRO.d.mts} +277 -40
- package/dist/copilotkit-CWOSXhRO.d.mts.map +1 -0
- package/dist/{copilotkit-DEaA0Cat.cjs → copilotkit-DKICi3nC.cjs} +1843 -196
- package/dist/copilotkit-DKICi3nC.cjs.map +1 -0
- package/dist/{copilotkit-k7IYk2AN.d.cts → copilotkit-Dfw9HzO9.d.cts} +277 -40
- package/dist/copilotkit-Dfw9HzO9.d.cts.map +1 -0
- package/dist/index.cjs +15 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +15 -3
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +127 -16
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/context.d.cts +7 -0
- package/dist/v2/context.d.cts.map +1 -1
- package/dist/v2/context.d.mts +7 -0
- package/dist/v2/context.d.mts.map +1 -1
- package/dist/v2/headless.cjs +106 -16
- package/dist/v2/headless.cjs.map +1 -1
- package/dist/v2/headless.d.cts +20 -2
- package/dist/v2/headless.d.cts.map +1 -1
- package/dist/v2/headless.d.mts +20 -2
- package/dist/v2/headless.d.mts.map +1 -1
- package/dist/v2/headless.mjs +106 -16
- package/dist/v2/headless.mjs.map +1 -1
- package/dist/v2/index.cjs +3 -1
- package/dist/v2/index.css +1 -1
- package/dist/v2/index.d.cts +2 -2
- package/dist/v2/index.d.mts +2 -2
- package/dist/v2/index.mjs +2 -2
- package/dist/v2/index.umd.js +1858 -222
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +11 -8
- package/dist/copilotkit-CD3uPUN3.mjs.map +0 -1
- package/dist/copilotkit-DEaA0Cat.cjs.map +0 -1
- package/dist/copilotkit-Yz8qXx00.d.mts.map +0 -1
- package/dist/copilotkit-k7IYk2AN.d.cts.map +0 -1
package/dist/v2/context.d.cts
CHANGED
|
@@ -18,6 +18,13 @@ interface ReactToolCallRenderer<T = unknown> {
|
|
|
18
18
|
* If specified, this renderer will only be used for the specified agent.
|
|
19
19
|
*/
|
|
20
20
|
agentId?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Whether calls this renderer draws join the chat's tool-call groups (see
|
|
23
|
+
* `toolCallDisplay` on `CopilotChatMessageView`). CopilotKit's built-in card
|
|
24
|
+
* sets it; a renderer that leaves it unset always shows its calls on their
|
|
25
|
+
* own, since the chat can't tell what it draws (it may even draw nothing).
|
|
26
|
+
*/
|
|
27
|
+
group?: boolean;
|
|
21
28
|
render: React.ComponentType<{
|
|
22
29
|
name: string;
|
|
23
30
|
toolCallId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.cts","names":[],"sources":["../../src/v2/types/react-tool-call-renderer.ts","../../src/v2/types/react-activity-message-renderer.ts","../../src/v2/types/react-custom-message-renderer.ts","../../src/v2/lib/react-core.ts","../../src/v2/context.ts"],"mappings":";;;;;;;;UAGiB,qBAAA;EACf,IAAA;;;;;EAKA,IAAA,GAAO,gBAAA,MAAsB,CAAA;EANO;;;;EAWpC,OAAA;EACA,MAAA,EAAQ,KAAA,CAAM,aAAA;IAER,IAAA;IACA,UAAA;IACA,IAAA,EAAM,OAAA,CAAQ,CAAA;IACd,MAAA,EAAQ,cAAA,CAAe,UAAA;IACvB,MAAA;EAAA;IAGA,IAAA;IACA,UAAA;IACA,IAAA,EAAM,CAAA;IACN,MAAA,EAAQ,cAAA,CAAe,SAAA;IACvB,MAAA;EAAA;IAGA,IAAA;IACA,UAAA;IACA,IAAA,EAAM,CAAA;IACN,MAAA,EAAQ,cAAA,CAAe,QAAA;IACvB,MAAA;EAAA;AAAA;;;
|
|
1
|
+
{"version":3,"file":"context.d.cts","names":[],"sources":["../../src/v2/types/react-tool-call-renderer.ts","../../src/v2/types/react-activity-message-renderer.ts","../../src/v2/types/react-custom-message-renderer.ts","../../src/v2/lib/react-core.ts","../../src/v2/context.ts"],"mappings":";;;;;;;;UAGiB,qBAAA;EACf,IAAA;;;;;EAKA,IAAA,GAAO,gBAAA,MAAsB,CAAA;EANO;;;;EAWpC,OAAA;EAYY;;;;;;EALZ,KAAA;EACA,MAAA,EAAQ,KAAA,CAAM,aAAA;IAER,IAAA;IACA,UAAA;IACA,IAAA,EAAM,OAAA,CAAQ,CAAA;IACd,MAAA,EAAQ,cAAA,CAAe,UAAA;IACvB,MAAA;EAAA;IAGA,IAAA;IACA,UAAA;IACA,IAAA,EAAM,CAAA;IACN,MAAA,EAAQ,cAAA,CAAe,SAAA;IACvB,MAAA;EAAA;IAGA,IAAA;IACA,UAAA;IACA,IAAA,EAAM,CAAA;IACN,MAAA,EAAQ,cAAA,CAAe,QAAA;IACvB,MAAA;EAAA;AAAA;;;UCtCS,4BAAA;;;;EAIf,YAAA;EDLe;;;ECSf,OAAA;EDHO;;;ECOP,OAAA,EAAS,gBAAA,MAAsB,gBAAA;EDiBnB;;;ECbZ,MAAA,EAAQ,KAAA,CAAM,aAAA;IACZ,YAAA;IACA,OAAA,EAAS,gBAAA;IACT,OAAA,EAAS,eAAA;IACT,KAAA,EAAO,aAAA;EAAA;AAAA;;;KCtBC,kCAAA;AAAA,UAEK,0BAAA;EACf,OAAA;EACA,MAAA,EAAQ,KAAA,CAAM,aAAA;IACZ,OAAA,EAAS,OAAA;IACT,QAAA,EAAU,kCAAA;IACV,KAAA;IACA,YAAA;IACA,iBAAA;IACA,qBAAA;IACA,OAAA;IACA,aAAA;EAAA;AAAA;;;UCJa,yBAAA,SAAkC,oBAAA;EAEjD,eAAA,GAAkB,qBAAA;EAClB,sBAAA,GAAyB,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AAA,sBAAA;AAAA,cAIjB,aAAA,QAAoB,sBAAA;AAAA,cA6BpB,cAAA,EAAc,KAAA,CAAA,OAAA,CAAA,mBAAA;AAAA,cAOd,iBAAA,QAAwB,mBAAA;AAAA,cAgBxB,wBAAA,EAEZ,KAAA,CAFoC,OAAA;AAAA,cAIxB,iBAAA"}
|
package/dist/v2/context.d.mts
CHANGED
|
@@ -18,6 +18,13 @@ interface ReactToolCallRenderer<T = unknown> {
|
|
|
18
18
|
* If specified, this renderer will only be used for the specified agent.
|
|
19
19
|
*/
|
|
20
20
|
agentId?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Whether calls this renderer draws join the chat's tool-call groups (see
|
|
23
|
+
* `toolCallDisplay` on `CopilotChatMessageView`). CopilotKit's built-in card
|
|
24
|
+
* sets it; a renderer that leaves it unset always shows its calls on their
|
|
25
|
+
* own, since the chat can't tell what it draws (it may even draw nothing).
|
|
26
|
+
*/
|
|
27
|
+
group?: boolean;
|
|
21
28
|
render: React.ComponentType<{
|
|
22
29
|
name: string;
|
|
23
30
|
toolCallId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.mts","names":[],"sources":["../../src/v2/types/react-tool-call-renderer.ts","../../src/v2/types/react-activity-message-renderer.ts","../../src/v2/types/react-custom-message-renderer.ts","../../src/v2/lib/react-core.ts","../../src/v2/context.ts"],"mappings":";;;;;;;;UAGiB,qBAAA;EACf,IAAA;;;;;EAKA,IAAA,GAAO,gBAAA,MAAsB,CAAA;EANO;;;;EAWpC,OAAA;EACA,MAAA,EAAQ,KAAA,CAAM,aAAA;IAER,IAAA;IACA,UAAA;IACA,IAAA,EAAM,OAAA,CAAQ,CAAA;IACd,MAAA,EAAQ,cAAA,CAAe,UAAA;IACvB,MAAA;EAAA;IAGA,IAAA;IACA,UAAA;IACA,IAAA,EAAM,CAAA;IACN,MAAA,EAAQ,cAAA,CAAe,SAAA;IACvB,MAAA;EAAA;IAGA,IAAA;IACA,UAAA;IACA,IAAA,EAAM,CAAA;IACN,MAAA,EAAQ,cAAA,CAAe,QAAA;IACvB,MAAA;EAAA;AAAA;;;
|
|
1
|
+
{"version":3,"file":"context.d.mts","names":[],"sources":["../../src/v2/types/react-tool-call-renderer.ts","../../src/v2/types/react-activity-message-renderer.ts","../../src/v2/types/react-custom-message-renderer.ts","../../src/v2/lib/react-core.ts","../../src/v2/context.ts"],"mappings":";;;;;;;;UAGiB,qBAAA;EACf,IAAA;;;;;EAKA,IAAA,GAAO,gBAAA,MAAsB,CAAA;EANO;;;;EAWpC,OAAA;EAYY;;;;;;EALZ,KAAA;EACA,MAAA,EAAQ,KAAA,CAAM,aAAA;IAER,IAAA;IACA,UAAA;IACA,IAAA,EAAM,OAAA,CAAQ,CAAA;IACd,MAAA,EAAQ,cAAA,CAAe,UAAA;IACvB,MAAA;EAAA;IAGA,IAAA;IACA,UAAA;IACA,IAAA,EAAM,CAAA;IACN,MAAA,EAAQ,cAAA,CAAe,SAAA;IACvB,MAAA;EAAA;IAGA,IAAA;IACA,UAAA;IACA,IAAA,EAAM,CAAA;IACN,MAAA,EAAQ,cAAA,CAAe,QAAA;IACvB,MAAA;EAAA;AAAA;;;UCtCS,4BAAA;;;;EAIf,YAAA;EDLe;;;ECSf,OAAA;EDHO;;;ECOP,OAAA,EAAS,gBAAA,MAAsB,gBAAA;EDiBnB;;;ECbZ,MAAA,EAAQ,KAAA,CAAM,aAAA;IACZ,YAAA;IACA,OAAA,EAAS,gBAAA;IACT,OAAA,EAAS,eAAA;IACT,KAAA,EAAO,aAAA;EAAA;AAAA;;;KCtBC,kCAAA;AAAA,UAEK,0BAAA;EACf,OAAA;EACA,MAAA,EAAQ,KAAA,CAAM,aAAA;IACZ,OAAA,EAAS,OAAA;IACT,QAAA,EAAU,kCAAA;IACV,KAAA;IACA,YAAA;IACA,iBAAA;IACA,qBAAA;IACA,OAAA;IACA,aAAA;EAAA;AAAA;;;UCJa,yBAAA,SAAkC,oBAAA;EAEjD,eAAA,GAAkB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A,EAAiB,KAAA,CAAA,OAAA,CAAA,sBAAA;AAAA,cAIjB,aAAA,QAAoB,sBAAA;AAAA,cA6BpB,cAAA,EAAc,KAAA,CAAA,OAAA,CAAA,mBAAA;AAAA,cAOd,iBAAA,QAAwB,mBAAA;AAAA,cAgBxB,wBAAA,EAEZ,KAAA,CAFoC,OAAA;AAAA,cAIxB,iBAAA"}
|
package/dist/v2/headless.cjs
CHANGED
|
@@ -51,7 +51,7 @@ function shallowEqual(obj1, obj2) {
|
|
|
51
51
|
* Returns true only for plain JS objects (`{}`), excluding arrays, Dates,
|
|
52
52
|
* class instances, and other exotic objects that happen to have typeof "object".
|
|
53
53
|
*/
|
|
54
|
-
function isPlainObject(obj) {
|
|
54
|
+
function isPlainObject$1(obj) {
|
|
55
55
|
return obj !== null && typeof obj === "object" && Object.prototype.toString.call(obj) === "[object Object]";
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
@@ -70,7 +70,7 @@ function isPlainObject(obj) {
|
|
|
70
70
|
function useShallowStableRef(value) {
|
|
71
71
|
const ref = (0, react.useRef)(value);
|
|
72
72
|
if (ref.current === value) return ref.current;
|
|
73
|
-
if (isPlainObject(ref.current) && isPlainObject(value)) {
|
|
73
|
+
if (isPlainObject$1(ref.current) && isPlainObject$1(value)) {
|
|
74
74
|
if (shallowEqual(ref.current, value)) return ref.current;
|
|
75
75
|
}
|
|
76
76
|
ref.current = value;
|
|
@@ -86,6 +86,8 @@ const CopilotChatDefaultLabels = {
|
|
|
86
86
|
chatInputToolbarFinishTranscribeButtonLabel: "Finish",
|
|
87
87
|
chatInputToolbarAddButtonLabel: "Add attachments",
|
|
88
88
|
chatInputToolbarToolsButtonLabel: "Tools",
|
|
89
|
+
chatInputToolbarSendButtonLabel: "Send message",
|
|
90
|
+
chatInputToolbarStopButtonLabel: "Stop",
|
|
89
91
|
assistantMessageToolbarCopyCodeLabel: "Copy",
|
|
90
92
|
assistantMessageToolbarCopyCodeCopiedLabel: "Copied",
|
|
91
93
|
assistantMessageToolbarCopyMessageLabel: "Copy",
|
|
@@ -98,13 +100,18 @@ const CopilotChatDefaultLabels = {
|
|
|
98
100
|
assistantMessageToolbarInspectorHideDescription: "Until you reload this page",
|
|
99
101
|
assistantMessageToolbarThumbsUpLabel: "Good response",
|
|
100
102
|
assistantMessageToolbarThumbsDownLabel: "Bad response",
|
|
103
|
+
assistantMessageFeedbackCommentPlaceholder: "Add a comment (optional)",
|
|
104
|
+
assistantMessageFeedbackCommentSubmitLabel: "Send comment",
|
|
101
105
|
assistantMessageToolbarReadAloudLabel: "Read aloud",
|
|
102
106
|
assistantMessageToolbarRegenerateLabel: "Regenerate",
|
|
103
107
|
userMessageToolbarCopyMessageLabel: "Copy",
|
|
104
108
|
userMessageToolbarEditMessageLabel: "Edit",
|
|
109
|
+
userMessageToolbarPreviousBranchLabel: "Previous branch",
|
|
110
|
+
userMessageToolbarNextBranchLabel: "Next branch",
|
|
105
111
|
chatDisclaimerText: "AI can make mistakes. Please verify important information.",
|
|
106
112
|
chatToggleOpenLabel: "Open chat",
|
|
107
113
|
chatToggleCloseLabel: "Close chat",
|
|
114
|
+
chatScrollToBottomLabel: "Scroll to bottom",
|
|
108
115
|
modalHeaderTitle: "CopilotKit Chat",
|
|
109
116
|
welcomeMessageText: "How can I help you today?"
|
|
110
117
|
};
|
|
@@ -562,12 +569,86 @@ function useAgent({ agentId, threadId, runtimeAgentId, updates, throttleMs } = {
|
|
|
562
569
|
};
|
|
563
570
|
}
|
|
564
571
|
|
|
572
|
+
//#endregion
|
|
573
|
+
//#region src/v2/hooks/tool-registration.ts
|
|
574
|
+
/**
|
|
575
|
+
* Deps comparison shared by `useFrontendTool` (and through it
|
|
576
|
+
* `useHumanInTheLoop` and `useComponent`) and `useRenderTool`. Not part of the
|
|
577
|
+
* public API.
|
|
578
|
+
*/
|
|
579
|
+
const EMPTY_DEPS$1 = [];
|
|
580
|
+
function isPlainObject(value) {
|
|
581
|
+
const proto = Object.getPrototypeOf(value);
|
|
582
|
+
return proto === Object.prototype || proto === null;
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* Plain data (primitives, plain objects, arrays, dates) compares by value.
|
|
586
|
+
* Functions always compare equal: these hooks used to compare
|
|
587
|
+
* `JSON.stringify(deps)`, which turns every function into `null`, and a
|
|
588
|
+
* function that counted as changed would re-register on every render when it
|
|
589
|
+
* is written inline (and loop in a component that also reads
|
|
590
|
+
* `useRenderToolCall`). Everything else (class instances, maps, sets) compares
|
|
591
|
+
* by identity. A cycle inside plain data is safe: a pair already being
|
|
592
|
+
* compared counts as equal for that branch.
|
|
593
|
+
*/
|
|
594
|
+
function depEqual(a, b, seen) {
|
|
595
|
+
if (Object.is(a, b)) return true;
|
|
596
|
+
if (typeof a === "function" && typeof b === "function") return true;
|
|
597
|
+
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
|
|
598
|
+
if (a instanceof Date && b instanceof Date) return Object.is(a.getTime(), b.getTime());
|
|
599
|
+
const aIsArray = Array.isArray(a);
|
|
600
|
+
if (aIsArray !== Array.isArray(b)) return false;
|
|
601
|
+
if (!aIsArray && !(isPlainObject(a) && isPlainObject(b))) return false;
|
|
602
|
+
if (seen.get(a) === b) return true;
|
|
603
|
+
seen.set(a, b);
|
|
604
|
+
if (aIsArray) {
|
|
605
|
+
const left = a;
|
|
606
|
+
const right = b;
|
|
607
|
+
if (left.length !== right.length) return false;
|
|
608
|
+
for (let i = 0; i < left.length; i++) if (!depEqual(left[i], right[i], seen)) return false;
|
|
609
|
+
return true;
|
|
610
|
+
}
|
|
611
|
+
const left = a;
|
|
612
|
+
const right = b;
|
|
613
|
+
const leftKeys = Object.keys(left);
|
|
614
|
+
if (leftKeys.length !== Object.keys(right).length) return false;
|
|
615
|
+
for (const key of leftKeys) {
|
|
616
|
+
if (!Object.prototype.hasOwnProperty.call(right, key)) return false;
|
|
617
|
+
if (!depEqual(left[key], right[key], seen)) return false;
|
|
618
|
+
}
|
|
619
|
+
return true;
|
|
620
|
+
}
|
|
621
|
+
/** Whether two deps arrays are equal. A change in length is always a change. */
|
|
622
|
+
function depsEqual(prev, next) {
|
|
623
|
+
if (prev.length !== next.length) return false;
|
|
624
|
+
const seen = /* @__PURE__ */ new Map();
|
|
625
|
+
for (let i = 0; i < prev.length; i++) if (!depEqual(prev[i], next[i], seen)) return false;
|
|
626
|
+
return true;
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Turns a caller's `deps` array into a number that changes exactly when the
|
|
630
|
+
* deps change, by the rules of {@link depsEqual}. Put the number, not the
|
|
631
|
+
* array, in the registration effect's dependency list: that keeps the list a
|
|
632
|
+
* constant length and never serializes a value.
|
|
633
|
+
*/
|
|
634
|
+
function useDepsVersion(deps) {
|
|
635
|
+
const next = deps ?? EMPTY_DEPS$1;
|
|
636
|
+
const ref = (0, react.useRef)({
|
|
637
|
+
deps: next,
|
|
638
|
+
version: 0
|
|
639
|
+
});
|
|
640
|
+
if (ref.current.deps !== next && !depsEqual(ref.current.deps, next)) ref.current = {
|
|
641
|
+
deps: next,
|
|
642
|
+
version: ref.current.version + 1
|
|
643
|
+
};
|
|
644
|
+
return ref.current.version;
|
|
645
|
+
}
|
|
646
|
+
|
|
565
647
|
//#endregion
|
|
566
648
|
//#region src/v2/hooks/use-frontend-tool.tsx
|
|
567
|
-
const EMPTY_DEPS$2 = [];
|
|
568
649
|
function useFrontendTool(tool, deps) {
|
|
569
650
|
const { copilotkit } = (0, _copilotkit_react_core_v2_context.useCopilotKit)();
|
|
570
|
-
const
|
|
651
|
+
const depsVersion = useDepsVersion(deps);
|
|
571
652
|
(0, react.useLayoutEffect)(() => {
|
|
572
653
|
const name = tool.name;
|
|
573
654
|
if (copilotkit.getTool({
|
|
@@ -591,14 +672,14 @@ function useFrontendTool(tool, deps) {
|
|
|
591
672
|
tool.name,
|
|
592
673
|
tool.available,
|
|
593
674
|
copilotkit,
|
|
594
|
-
|
|
675
|
+
depsVersion,
|
|
595
676
|
JSON.stringify(tool.webmcp ?? null)
|
|
596
677
|
]);
|
|
597
678
|
}
|
|
598
679
|
|
|
599
680
|
//#endregion
|
|
600
681
|
//#region src/v2/hooks/use-frontend-tools.tsx
|
|
601
|
-
const EMPTY_DEPS
|
|
682
|
+
const EMPTY_DEPS = [];
|
|
602
683
|
const EMPTY_TOOLS = [];
|
|
603
684
|
/**
|
|
604
685
|
* Register a list of frontend tools whose length can change between renders.
|
|
@@ -652,7 +733,7 @@ const EMPTY_TOOLS = [];
|
|
|
652
733
|
function useFrontendTools(tools, deps) {
|
|
653
734
|
const { copilotkit } = (0, _copilotkit_react_core_v2_context.useCopilotKit)();
|
|
654
735
|
const toolList = tools ?? EMPTY_TOOLS;
|
|
655
|
-
const extraDeps = deps ?? EMPTY_DEPS
|
|
736
|
+
const extraDeps = deps ?? EMPTY_DEPS;
|
|
656
737
|
(0, react.useLayoutEffect)(() => {
|
|
657
738
|
const deduped = /* @__PURE__ */ new Map();
|
|
658
739
|
for (const tool of toolList) {
|
|
@@ -1564,13 +1645,13 @@ function defineToolCallRenderer(def) {
|
|
|
1564
1645
|
name: def.name,
|
|
1565
1646
|
args: argsSchema,
|
|
1566
1647
|
render: def.render,
|
|
1567
|
-
...def.agentId ? { agentId: def.agentId } : {}
|
|
1648
|
+
...def.agentId ? { agentId: def.agentId } : {},
|
|
1649
|
+
...def.group ? { group: true } : {}
|
|
1568
1650
|
};
|
|
1569
1651
|
}
|
|
1570
1652
|
|
|
1571
1653
|
//#endregion
|
|
1572
1654
|
//#region src/v2/hooks/use-render-tool.tsx
|
|
1573
|
-
const EMPTY_DEPS = [];
|
|
1574
1655
|
/**
|
|
1575
1656
|
* Registers a renderer entry in CopilotKit's `renderToolCalls` registry.
|
|
1576
1657
|
*
|
|
@@ -1614,7 +1695,7 @@ const EMPTY_DEPS = [];
|
|
|
1614
1695
|
*/
|
|
1615
1696
|
function useRenderTool(config, deps) {
|
|
1616
1697
|
const { copilotkit } = (0, _copilotkit_react_core_v2_context.useCopilotKit)();
|
|
1617
|
-
const
|
|
1698
|
+
const depsVersion = useDepsVersion(deps);
|
|
1618
1699
|
(0, react.useEffect)(() => {
|
|
1619
1700
|
const renderer = config.name === "*" && !config.parameters ? defineToolCallRenderer({
|
|
1620
1701
|
name: "*",
|
|
@@ -1622,7 +1703,8 @@ function useRenderTool(config, deps) {
|
|
|
1622
1703
|
...props,
|
|
1623
1704
|
parameters: props.args
|
|
1624
1705
|
}),
|
|
1625
|
-
...config.agentId ? { agentId: config.agentId } : {}
|
|
1706
|
+
...config.agentId ? { agentId: config.agentId } : {},
|
|
1707
|
+
group: config.group
|
|
1626
1708
|
}) : defineToolCallRenderer({
|
|
1627
1709
|
name: config.name,
|
|
1628
1710
|
args: config.parameters,
|
|
@@ -1640,13 +1722,15 @@ function useRenderTool(config, deps) {
|
|
|
1640
1722
|
parameters: props.args
|
|
1641
1723
|
});
|
|
1642
1724
|
},
|
|
1643
|
-
...config.agentId ? { agentId: config.agentId } : {}
|
|
1725
|
+
...config.agentId ? { agentId: config.agentId } : {},
|
|
1726
|
+
group: config.group
|
|
1644
1727
|
});
|
|
1645
1728
|
copilotkit.addHookRenderToolCall(renderer);
|
|
1646
1729
|
}, [
|
|
1647
1730
|
config.name,
|
|
1731
|
+
config.group,
|
|
1648
1732
|
copilotkit,
|
|
1649
|
-
|
|
1733
|
+
depsVersion
|
|
1650
1734
|
]);
|
|
1651
1735
|
}
|
|
1652
1736
|
|
|
@@ -1714,6 +1798,14 @@ function warnAboutUnrenderedToolCalls(toolNames, registered, alreadyWarned) {
|
|
|
1714
1798
|
}
|
|
1715
1799
|
}
|
|
1716
1800
|
/**
|
|
1801
|
+
* The tool-call renderers registered on the provider, kept current.
|
|
1802
|
+
* @internal
|
|
1803
|
+
*/
|
|
1804
|
+
function useToolCallRenderers() {
|
|
1805
|
+
const { copilotkit } = (0, _copilotkit_react_core_v2_context.useCopilotKit)();
|
|
1806
|
+
return (0, react.useSyncExternalStore)((callback) => copilotkit.subscribe({ onRenderToolCallsChanged: callback }).unsubscribe, () => copilotkit.renderToolCalls, () => copilotkit.renderToolCalls);
|
|
1807
|
+
}
|
|
1808
|
+
/**
|
|
1717
1809
|
* Hook that returns a function to render tool calls based on the render functions
|
|
1718
1810
|
* defined in CopilotKitProvider.
|
|
1719
1811
|
*
|
|
@@ -1724,9 +1816,7 @@ function useRenderToolCall() {
|
|
|
1724
1816
|
const agentId = useCopilotChatConfiguration()?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
1725
1817
|
const unrenderedToolNames = (0, react.useRef)(/* @__PURE__ */ new Set());
|
|
1726
1818
|
const warnedToolNames = (0, react.useRef)(/* @__PURE__ */ new Set());
|
|
1727
|
-
const renderToolCalls = (
|
|
1728
|
-
return copilotkit.subscribe({ onRenderToolCallsChanged: callback }).unsubscribe;
|
|
1729
|
-
}, () => copilotkit.renderToolCalls, () => copilotkit.renderToolCalls);
|
|
1819
|
+
const renderToolCalls = useToolCallRenderers();
|
|
1730
1820
|
const renderToolCall = (0, react.useCallback)(({ toolCall, toolMessage }) => {
|
|
1731
1821
|
const exactMatches = renderToolCalls.filter((rc) => rc.name === toolCall.function.name);
|
|
1732
1822
|
const renderConfig = exactMatches.find((rc) => rc.agentId === agentId) || exactMatches.find((rc) => !rc.agentId) || exactMatches[0] || renderToolCalls.find((rc) => rc.name === "*");
|