@copilotkit/react-core 1.63.2 → 1.63.3-canary.rc-1
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-BE1n5tSI.d.mts.map +1 -1
- package/dist/copilotkit-CXvuYw_F.d.cts.map +1 -1
- package/dist/{copilotkit-CN2JVeH3.mjs → copilotkit-DL0LvmwQ.mjs} +69 -65
- package/dist/copilotkit-DL0LvmwQ.mjs.map +1 -0
- package/dist/{copilotkit-DDVfoiRM.cjs → copilotkit-rYTwMndy.cjs} +71 -67
- package/dist/copilotkit-rYTwMndy.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.umd.js +5 -48
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/headless.cjs +79 -45
- package/dist/v2/headless.cjs.map +1 -1
- package/dist/v2/headless.d.cts +30 -2
- package/dist/v2/headless.d.cts.map +1 -1
- package/dist/v2/headless.d.mts +19 -3
- package/dist/v2/headless.d.mts.map +1 -1
- package/dist/v2/headless.mjs +83 -57
- package/dist/v2/headless.mjs.map +1 -1
- package/dist/v2/index.cjs +1 -1
- package/dist/v2/index.mjs +1 -1
- package/dist/v2/index.umd.js +70 -66
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +7 -7
- package/dist/copilotkit-CN2JVeH3.mjs.map +0 -1
- package/dist/copilotkit-DDVfoiRM.cjs.map +0 -1
package/dist/v2/headless.cjs
CHANGED
|
@@ -30,13 +30,12 @@ let _copilotkit_react_core_v2_context = require("@copilotkit/react-core/v2/conte
|
|
|
30
30
|
let react = require("react");
|
|
31
31
|
react = __toESM(react);
|
|
32
32
|
let _copilotkit_shared = require("@copilotkit/shared");
|
|
33
|
-
let tailwind_merge = require("tailwind-merge");
|
|
34
33
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
35
34
|
let _ag_ui_client = require("@ag-ui/client");
|
|
36
35
|
let _copilotkit_core = require("@copilotkit/core");
|
|
37
36
|
let zod = require("zod");
|
|
38
37
|
|
|
39
|
-
//#region src/v2/lib/
|
|
38
|
+
//#region src/v2/lib/shallow-stable-ref.ts
|
|
40
39
|
/**
|
|
41
40
|
* Shallow equality comparison for objects.
|
|
42
41
|
*/
|
|
@@ -76,49 +75,6 @@ function useShallowStableRef(value) {
|
|
|
76
75
|
ref.current = value;
|
|
77
76
|
return ref.current;
|
|
78
77
|
}
|
|
79
|
-
/**
|
|
80
|
-
* Check if a value is a React component type (function, class, forwardRef, memo, etc.)
|
|
81
|
-
*/
|
|
82
|
-
function isReactComponentType(value) {
|
|
83
|
-
if (typeof value === "function") return true;
|
|
84
|
-
if (value && typeof value === "object" && "$$typeof" in value && !react.default.isValidElement(value)) return true;
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Internal function to render a slot value as a React element (non-memoized).
|
|
89
|
-
*/
|
|
90
|
-
function renderSlotElement(slot, DefaultComponent, props) {
|
|
91
|
-
if (typeof slot === "string") {
|
|
92
|
-
const existingClassName = props.className;
|
|
93
|
-
return react.default.createElement(DefaultComponent, {
|
|
94
|
-
...props,
|
|
95
|
-
className: (0, tailwind_merge.twMerge)(existingClassName, slot)
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
if (isReactComponentType(slot)) return react.default.createElement(slot, props);
|
|
99
|
-
if (slot && typeof slot === "object" && !react.default.isValidElement(slot)) return react.default.createElement(DefaultComponent, {
|
|
100
|
-
...props,
|
|
101
|
-
...slot
|
|
102
|
-
});
|
|
103
|
-
return react.default.createElement(DefaultComponent, props);
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Internal memoized wrapper component for renderSlot.
|
|
107
|
-
* Uses forwardRef to support ref forwarding.
|
|
108
|
-
*/
|
|
109
|
-
const MemoizedSlotWrapper = react.default.memo(react.default.forwardRef(function MemoizedSlotWrapper(props, ref) {
|
|
110
|
-
const { $slot, $component, ...rest } = props;
|
|
111
|
-
return renderSlotElement($slot, $component, ref !== null ? {
|
|
112
|
-
...rest,
|
|
113
|
-
ref
|
|
114
|
-
} : rest);
|
|
115
|
-
}), (prev, next) => {
|
|
116
|
-
if (prev.$slot !== next.$slot) return false;
|
|
117
|
-
if (prev.$component !== next.$component) return false;
|
|
118
|
-
const { $slot: _ps, $component: _pc, ...prevRest } = prev;
|
|
119
|
-
const { $slot: _ns, $component: _nc, ...nextRest } = next;
|
|
120
|
-
return shallowEqual(prevRest, nextRest);
|
|
121
|
-
});
|
|
122
78
|
|
|
123
79
|
//#endregion
|
|
124
80
|
//#region src/v2/providers/CopilotChatConfigurationProvider.tsx
|
|
@@ -1442,6 +1398,76 @@ function useRenderTool(config, deps) {
|
|
|
1442
1398
|
]);
|
|
1443
1399
|
}
|
|
1444
1400
|
|
|
1401
|
+
//#endregion
|
|
1402
|
+
//#region src/v2/hooks/use-render-tool-call.tsx
|
|
1403
|
+
/**
|
|
1404
|
+
* Memoized component that renders a single tool call.
|
|
1405
|
+
* This prevents unnecessary re-renders when parent components update
|
|
1406
|
+
* but the tool call data hasn't changed.
|
|
1407
|
+
*/
|
|
1408
|
+
const ToolCallRenderer = react.default.memo(function ToolCallRenderer({ toolCall, toolMessage, RenderComponent, isExecuting }) {
|
|
1409
|
+
const args = (0, react.useMemo)(() => (0, _copilotkit_shared.partialJSONParse)(toolCall.function.arguments), [toolCall.function.arguments]);
|
|
1410
|
+
const toolName = toolCall.function.name;
|
|
1411
|
+
if (toolMessage) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
|
|
1412
|
+
name: toolName,
|
|
1413
|
+
toolCallId: toolCall.id,
|
|
1414
|
+
args,
|
|
1415
|
+
status: _copilotkit_core.ToolCallStatus.Complete,
|
|
1416
|
+
result: toolMessage.content
|
|
1417
|
+
});
|
|
1418
|
+
else if (isExecuting) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
|
|
1419
|
+
name: toolName,
|
|
1420
|
+
toolCallId: toolCall.id,
|
|
1421
|
+
args,
|
|
1422
|
+
status: _copilotkit_core.ToolCallStatus.Executing,
|
|
1423
|
+
result: void 0
|
|
1424
|
+
});
|
|
1425
|
+
else return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
|
|
1426
|
+
name: toolName,
|
|
1427
|
+
toolCallId: toolCall.id,
|
|
1428
|
+
args,
|
|
1429
|
+
status: _copilotkit_core.ToolCallStatus.InProgress,
|
|
1430
|
+
result: void 0
|
|
1431
|
+
});
|
|
1432
|
+
}, (prevProps, nextProps) => {
|
|
1433
|
+
if (prevProps.toolCall.id !== nextProps.toolCall.id) return false;
|
|
1434
|
+
if (prevProps.toolCall.function.name !== nextProps.toolCall.function.name) return false;
|
|
1435
|
+
if (prevProps.toolCall.function.arguments !== nextProps.toolCall.function.arguments) return false;
|
|
1436
|
+
if (prevProps.toolMessage?.content !== nextProps.toolMessage?.content) return false;
|
|
1437
|
+
if (prevProps.isExecuting !== nextProps.isExecuting) return false;
|
|
1438
|
+
if (prevProps.RenderComponent !== nextProps.RenderComponent) return false;
|
|
1439
|
+
return true;
|
|
1440
|
+
});
|
|
1441
|
+
/**
|
|
1442
|
+
* Hook that returns a function to render tool calls based on the render functions
|
|
1443
|
+
* defined in CopilotKitProvider.
|
|
1444
|
+
*
|
|
1445
|
+
* @returns A function that takes a tool call and optional tool message and returns the rendered component
|
|
1446
|
+
*/
|
|
1447
|
+
function useRenderToolCall() {
|
|
1448
|
+
const { copilotkit, executingToolCallIds } = (0, _copilotkit_react_core_v2_context.useCopilotKit)();
|
|
1449
|
+
const agentId = useCopilotChatConfiguration()?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
1450
|
+
const renderToolCalls = (0, react.useSyncExternalStore)((callback) => {
|
|
1451
|
+
return copilotkit.subscribe({ onRenderToolCallsChanged: callback }).unsubscribe;
|
|
1452
|
+
}, () => copilotkit.renderToolCalls, () => copilotkit.renderToolCalls);
|
|
1453
|
+
return (0, react.useCallback)(({ toolCall, toolMessage }) => {
|
|
1454
|
+
const exactMatches = renderToolCalls.filter((rc) => rc.name === toolCall.function.name);
|
|
1455
|
+
const renderConfig = exactMatches.find((rc) => rc.agentId === agentId) || exactMatches.find((rc) => !rc.agentId) || exactMatches[0] || renderToolCalls.find((rc) => rc.name === "*");
|
|
1456
|
+
if (!renderConfig) return null;
|
|
1457
|
+
const RenderComponent = renderConfig.render;
|
|
1458
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolCallRenderer, {
|
|
1459
|
+
toolCall,
|
|
1460
|
+
toolMessage,
|
|
1461
|
+
RenderComponent,
|
|
1462
|
+
isExecuting: executingToolCallIds.has(toolCall.id)
|
|
1463
|
+
}, toolCall.id);
|
|
1464
|
+
}, [
|
|
1465
|
+
renderToolCalls,
|
|
1466
|
+
executingToolCallIds,
|
|
1467
|
+
agentId
|
|
1468
|
+
]);
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1445
1471
|
//#endregion
|
|
1446
1472
|
//#region src/v2/hooks/use-capabilities.tsx
|
|
1447
1473
|
/**
|
|
@@ -1471,6 +1497,7 @@ Object.defineProperty(exports, 'CopilotKitCoreReact', {
|
|
|
1471
1497
|
return _copilotkit_react_core_v2_context.CopilotKitCoreReact;
|
|
1472
1498
|
}
|
|
1473
1499
|
});
|
|
1500
|
+
exports.UseAgentUpdate = UseAgentUpdate;
|
|
1474
1501
|
exports.defineToolCallRenderer = defineToolCallRenderer;
|
|
1475
1502
|
exports.useAgent = useAgent;
|
|
1476
1503
|
exports.useAgentContext = useAgentContext;
|
|
@@ -1478,10 +1505,17 @@ exports.useCapabilities = useCapabilities;
|
|
|
1478
1505
|
exports.useComponent = useComponent;
|
|
1479
1506
|
exports.useConfigureSuggestions = useConfigureSuggestions;
|
|
1480
1507
|
exports.useCopilotChatConfiguration = useCopilotChatConfiguration;
|
|
1508
|
+
Object.defineProperty(exports, 'useCopilotKit', {
|
|
1509
|
+
enumerable: true,
|
|
1510
|
+
get: function () {
|
|
1511
|
+
return _copilotkit_react_core_v2_context.useCopilotKit;
|
|
1512
|
+
}
|
|
1513
|
+
});
|
|
1481
1514
|
exports.useFrontendTool = useFrontendTool;
|
|
1482
1515
|
exports.useHumanInTheLoop = useHumanInTheLoop;
|
|
1483
1516
|
exports.useInterrupt = useInterrupt;
|
|
1484
1517
|
exports.useRenderTool = useRenderTool;
|
|
1518
|
+
exports.useRenderToolCall = useRenderToolCall;
|
|
1485
1519
|
exports.useSuggestions = useSuggestions;
|
|
1486
1520
|
exports.useThreads = useThreads;
|
|
1487
1521
|
//# sourceMappingURL=headless.cjs.map
|