@copilotkit/react-core 1.63.2 → 1.64.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-BE1n5tSI.d.mts.map +1 -1
- package/dist/copilotkit-CXvuYw_F.d.cts.map +1 -1
- package/dist/{copilotkit-CN2JVeH3.mjs → copilotkit-D_Ao1X-u.mjs} +117 -100
- package/dist/copilotkit-D_Ao1X-u.mjs.map +1 -0
- package/dist/{copilotkit-DDVfoiRM.cjs → copilotkit-DiLTL1ZM.cjs} +119 -102
- package/dist/copilotkit-DiLTL1ZM.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.umd.js +22 -63
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/headless.cjs +96 -60
- 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 +100 -72
- 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 +118 -101
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +7 -7
- package/skills/react-core/references/threads.md +1 -2
- 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
|
|
@@ -358,17 +314,15 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
|
|
|
358
314
|
const status = copilotkit.runtimeConnectionStatus;
|
|
359
315
|
if (isRuntimeConfigured && (status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Disconnected || status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Connecting)) {
|
|
360
316
|
const cached = provisionalAgentCache.current.get(resolvedAgentId);
|
|
361
|
-
if (cached) {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
isReady: false
|
|
366
|
-
};
|
|
367
|
-
}
|
|
317
|
+
if (cached) return {
|
|
318
|
+
agent: cached,
|
|
319
|
+
isReady: false
|
|
320
|
+
};
|
|
368
321
|
const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
|
|
369
322
|
runtimeUrl: copilotkit.runtimeUrl,
|
|
370
323
|
agentId: resolvedAgentId,
|
|
371
324
|
transport: copilotkit.runtimeTransport,
|
|
325
|
+
credentials: copilotkit.credentials,
|
|
372
326
|
runtimeMode: "pending"
|
|
373
327
|
});
|
|
374
328
|
copilotkit.applyHeadersToAgent(provisional);
|
|
@@ -380,17 +334,15 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
|
|
|
380
334
|
}
|
|
381
335
|
if (isRuntimeConfigured && status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Error) {
|
|
382
336
|
const cached = provisionalAgentCache.current.get(resolvedAgentId);
|
|
383
|
-
if (cached) {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
isReady: false
|
|
388
|
-
};
|
|
389
|
-
}
|
|
337
|
+
if (cached) return {
|
|
338
|
+
agent: cached,
|
|
339
|
+
isReady: false
|
|
340
|
+
};
|
|
390
341
|
const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
|
|
391
342
|
runtimeUrl: copilotkit.runtimeUrl,
|
|
392
343
|
agentId: resolvedAgentId,
|
|
393
344
|
transport: copilotkit.runtimeTransport,
|
|
345
|
+
credentials: copilotkit.credentials,
|
|
394
346
|
runtimeMode: "pending"
|
|
395
347
|
});
|
|
396
348
|
copilotkit.applyHeadersToAgent(provisional);
|
|
@@ -409,6 +361,7 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
|
|
|
409
361
|
copilotkit.runtimeConnectionStatus,
|
|
410
362
|
copilotkit.runtimeUrl,
|
|
411
363
|
copilotkit.runtimeTransport,
|
|
364
|
+
copilotkit.credentials,
|
|
412
365
|
JSON.stringify(copilotkit.headers)
|
|
413
366
|
]);
|
|
414
367
|
(0, react.useEffect)(() => {
|
|
@@ -448,7 +401,12 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
|
|
|
448
401
|
]);
|
|
449
402
|
(0, react.useEffect)(() => {
|
|
450
403
|
if (agent instanceof _ag_ui_client.HttpAgent) copilotkit.applyHeadersToAgent(agent);
|
|
451
|
-
|
|
404
|
+
if (agent instanceof _copilotkit_core.ProxiedCopilotRuntimeAgent) agent.credentials = copilotkit.credentials;
|
|
405
|
+
}, [
|
|
406
|
+
agent,
|
|
407
|
+
JSON.stringify(copilotkit.headers),
|
|
408
|
+
copilotkit.credentials
|
|
409
|
+
]);
|
|
452
410
|
const configThreadId = chatConfig?.threadId;
|
|
453
411
|
const configHasExplicitThreadId = chatConfig?.hasExplicitThreadId;
|
|
454
412
|
(0, react.useEffect)(() => {
|
|
@@ -1442,6 +1400,76 @@ function useRenderTool(config, deps) {
|
|
|
1442
1400
|
]);
|
|
1443
1401
|
}
|
|
1444
1402
|
|
|
1403
|
+
//#endregion
|
|
1404
|
+
//#region src/v2/hooks/use-render-tool-call.tsx
|
|
1405
|
+
/**
|
|
1406
|
+
* Memoized component that renders a single tool call.
|
|
1407
|
+
* This prevents unnecessary re-renders when parent components update
|
|
1408
|
+
* but the tool call data hasn't changed.
|
|
1409
|
+
*/
|
|
1410
|
+
const ToolCallRenderer = react.default.memo(function ToolCallRenderer({ toolCall, toolMessage, RenderComponent, isExecuting }) {
|
|
1411
|
+
const args = (0, react.useMemo)(() => (0, _copilotkit_shared.partialJSONParse)(toolCall.function.arguments), [toolCall.function.arguments]);
|
|
1412
|
+
const toolName = toolCall.function.name;
|
|
1413
|
+
if (toolMessage) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
|
|
1414
|
+
name: toolName,
|
|
1415
|
+
toolCallId: toolCall.id,
|
|
1416
|
+
args,
|
|
1417
|
+
status: _copilotkit_core.ToolCallStatus.Complete,
|
|
1418
|
+
result: toolMessage.content
|
|
1419
|
+
});
|
|
1420
|
+
else if (isExecuting) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
|
|
1421
|
+
name: toolName,
|
|
1422
|
+
toolCallId: toolCall.id,
|
|
1423
|
+
args,
|
|
1424
|
+
status: _copilotkit_core.ToolCallStatus.Executing,
|
|
1425
|
+
result: void 0
|
|
1426
|
+
});
|
|
1427
|
+
else return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
|
|
1428
|
+
name: toolName,
|
|
1429
|
+
toolCallId: toolCall.id,
|
|
1430
|
+
args,
|
|
1431
|
+
status: _copilotkit_core.ToolCallStatus.InProgress,
|
|
1432
|
+
result: void 0
|
|
1433
|
+
});
|
|
1434
|
+
}, (prevProps, nextProps) => {
|
|
1435
|
+
if (prevProps.toolCall.id !== nextProps.toolCall.id) return false;
|
|
1436
|
+
if (prevProps.toolCall.function.name !== nextProps.toolCall.function.name) return false;
|
|
1437
|
+
if (prevProps.toolCall.function.arguments !== nextProps.toolCall.function.arguments) return false;
|
|
1438
|
+
if (prevProps.toolMessage?.content !== nextProps.toolMessage?.content) return false;
|
|
1439
|
+
if (prevProps.isExecuting !== nextProps.isExecuting) return false;
|
|
1440
|
+
if (prevProps.RenderComponent !== nextProps.RenderComponent) return false;
|
|
1441
|
+
return true;
|
|
1442
|
+
});
|
|
1443
|
+
/**
|
|
1444
|
+
* Hook that returns a function to render tool calls based on the render functions
|
|
1445
|
+
* defined in CopilotKitProvider.
|
|
1446
|
+
*
|
|
1447
|
+
* @returns A function that takes a tool call and optional tool message and returns the rendered component
|
|
1448
|
+
*/
|
|
1449
|
+
function useRenderToolCall() {
|
|
1450
|
+
const { copilotkit, executingToolCallIds } = (0, _copilotkit_react_core_v2_context.useCopilotKit)();
|
|
1451
|
+
const agentId = useCopilotChatConfiguration()?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
1452
|
+
const renderToolCalls = (0, react.useSyncExternalStore)((callback) => {
|
|
1453
|
+
return copilotkit.subscribe({ onRenderToolCallsChanged: callback }).unsubscribe;
|
|
1454
|
+
}, () => copilotkit.renderToolCalls, () => copilotkit.renderToolCalls);
|
|
1455
|
+
return (0, react.useCallback)(({ toolCall, toolMessage }) => {
|
|
1456
|
+
const exactMatches = renderToolCalls.filter((rc) => rc.name === toolCall.function.name);
|
|
1457
|
+
const renderConfig = exactMatches.find((rc) => rc.agentId === agentId) || exactMatches.find((rc) => !rc.agentId) || exactMatches[0] || renderToolCalls.find((rc) => rc.name === "*");
|
|
1458
|
+
if (!renderConfig) return null;
|
|
1459
|
+
const RenderComponent = renderConfig.render;
|
|
1460
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolCallRenderer, {
|
|
1461
|
+
toolCall,
|
|
1462
|
+
toolMessage,
|
|
1463
|
+
RenderComponent,
|
|
1464
|
+
isExecuting: executingToolCallIds.has(toolCall.id)
|
|
1465
|
+
}, toolCall.id);
|
|
1466
|
+
}, [
|
|
1467
|
+
renderToolCalls,
|
|
1468
|
+
executingToolCallIds,
|
|
1469
|
+
agentId
|
|
1470
|
+
]);
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1445
1473
|
//#endregion
|
|
1446
1474
|
//#region src/v2/hooks/use-capabilities.tsx
|
|
1447
1475
|
/**
|
|
@@ -1471,6 +1499,7 @@ Object.defineProperty(exports, 'CopilotKitCoreReact', {
|
|
|
1471
1499
|
return _copilotkit_react_core_v2_context.CopilotKitCoreReact;
|
|
1472
1500
|
}
|
|
1473
1501
|
});
|
|
1502
|
+
exports.UseAgentUpdate = UseAgentUpdate;
|
|
1474
1503
|
exports.defineToolCallRenderer = defineToolCallRenderer;
|
|
1475
1504
|
exports.useAgent = useAgent;
|
|
1476
1505
|
exports.useAgentContext = useAgentContext;
|
|
@@ -1478,10 +1507,17 @@ exports.useCapabilities = useCapabilities;
|
|
|
1478
1507
|
exports.useComponent = useComponent;
|
|
1479
1508
|
exports.useConfigureSuggestions = useConfigureSuggestions;
|
|
1480
1509
|
exports.useCopilotChatConfiguration = useCopilotChatConfiguration;
|
|
1510
|
+
Object.defineProperty(exports, 'useCopilotKit', {
|
|
1511
|
+
enumerable: true,
|
|
1512
|
+
get: function () {
|
|
1513
|
+
return _copilotkit_react_core_v2_context.useCopilotKit;
|
|
1514
|
+
}
|
|
1515
|
+
});
|
|
1481
1516
|
exports.useFrontendTool = useFrontendTool;
|
|
1482
1517
|
exports.useHumanInTheLoop = useHumanInTheLoop;
|
|
1483
1518
|
exports.useInterrupt = useInterrupt;
|
|
1484
1519
|
exports.useRenderTool = useRenderTool;
|
|
1520
|
+
exports.useRenderToolCall = useRenderToolCall;
|
|
1485
1521
|
exports.useSuggestions = useSuggestions;
|
|
1486
1522
|
exports.useThreads = useThreads;
|
|
1487
1523
|
//# sourceMappingURL=headless.cjs.map
|