@copilotkit/react-core 1.57.0-canary.1778146769 → 1.57.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-BNlJq5UO.d.mts → copilotkit-BN4I_y1n.d.mts} +6 -4
- package/dist/copilotkit-BN4I_y1n.d.mts.map +1 -0
- package/dist/{copilotkit-B_k0HSNz.cjs → copilotkit-C3k13WZn.cjs} +197 -198
- package/dist/copilotkit-C3k13WZn.cjs.map +1 -0
- package/dist/{copilotkit-ak8sGvQr.mjs → copilotkit-DjxXMYHG.mjs} +198 -199
- package/dist/copilotkit-DjxXMYHG.mjs.map +1 -0
- package/dist/{copilotkit-DgC5oCFO.d.cts → copilotkit-sQWiKtxA.d.cts} +6 -4
- package/dist/copilotkit-sQWiKtxA.d.cts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.umd.js +207 -205
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/context.cjs +135 -0
- package/dist/v2/context.cjs.map +1 -0
- package/dist/v2/context.d.cts +148 -0
- package/dist/v2/context.d.cts.map +1 -0
- package/dist/v2/context.d.mts +148 -0
- package/dist/v2/context.d.mts.map +1 -0
- package/dist/v2/context.mjs +129 -0
- package/dist/v2/context.mjs.map +1 -0
- package/dist/v2/headless.cjs +1043 -0
- package/dist/v2/headless.cjs.map +1 -0
- package/dist/v2/headless.d.cts +605 -0
- package/dist/v2/headless.d.cts.map +1 -0
- package/dist/v2/headless.d.mts +512 -0
- package/dist/v2/headless.d.mts.map +1 -0
- package/dist/v2/headless.mjs +997 -0
- package/dist/v2/headless.mjs.map +1 -0
- package/dist/v2/index.cjs +1 -1
- package/dist/v2/index.d.cts +1 -1
- package/dist/v2/index.d.mts +1 -1
- package/dist/v2/index.mjs +1 -1
- package/dist/v2/index.umd.js +209 -208
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +14 -6
- package/src/v2/context.ts +62 -0
- package/src/v2/headless.ts +42 -0
- package/src/v2/hooks/__tests__/standard-schema.test.tsx +2 -2
- package/src/v2/hooks/__tests__/use-agent-context.test.tsx +3 -3
- package/src/v2/hooks/__tests__/use-agent-stability.test.tsx +3 -3
- package/src/v2/hooks/__tests__/use-agent-throttle.test.tsx +85 -85
- package/src/v2/hooks/__tests__/use-interrupt.test.tsx +2 -2
- package/src/v2/hooks/__tests__/use-render-tool.test.tsx +2 -2
- package/src/v2/hooks/__tests__/use-threads.test.tsx +2 -2
- package/src/v2/hooks/__tests__/zod-regression.test.tsx +2 -2
- package/src/v2/hooks/use-agent-context.tsx +1 -1
- package/src/v2/hooks/use-agent.tsx +2 -2
- package/src/v2/hooks/use-configure-suggestions.tsx +1 -1
- package/src/v2/hooks/use-frontend-tool.tsx +2 -2
- package/src/v2/hooks/use-human-in-the-loop.tsx +1 -1
- package/src/v2/hooks/use-interrupt.tsx +1 -1
- package/src/v2/hooks/use-render-tool-call.tsx +1 -1
- package/src/v2/hooks/use-render-tool.tsx +2 -2
- package/src/v2/hooks/use-suggestions.tsx +1 -1
- package/src/v2/hooks/use-threads.tsx +1 -1
- package/src/v2/providers/CopilotKitProvider.tsx +19 -59
- package/tsdown.config.ts +75 -0
- package/dist/copilotkit-BNlJq5UO.d.mts.map +0 -1
- package/dist/copilotkit-B_k0HSNz.cjs.map +0 -1
- package/dist/copilotkit-DgC5oCFO.d.cts.map +0 -1
- package/dist/copilotkit-ak8sGvQr.mjs.map +0 -1
|
@@ -1294,6 +1294,197 @@ function useKatexStyles() {
|
|
|
1294
1294
|
}, []);
|
|
1295
1295
|
}
|
|
1296
1296
|
|
|
1297
|
+
//#endregion
|
|
1298
|
+
//#region src/v2/lib/react-core.ts
|
|
1299
|
+
var CopilotKitCoreReact = class extends CopilotKitCore {
|
|
1300
|
+
constructor(config) {
|
|
1301
|
+
super(config);
|
|
1302
|
+
this._renderToolCalls = [];
|
|
1303
|
+
this._hookRenderToolCalls = /* @__PURE__ */ new Map();
|
|
1304
|
+
this._cachedMergedRenderToolCalls = null;
|
|
1305
|
+
this._renderCustomMessages = [];
|
|
1306
|
+
this._renderActivityMessages = [];
|
|
1307
|
+
this._interruptElement = null;
|
|
1308
|
+
this._renderToolCalls = config.renderToolCalls ?? [];
|
|
1309
|
+
this._renderCustomMessages = config.renderCustomMessages ?? [];
|
|
1310
|
+
this._renderActivityMessages = config.renderActivityMessages ?? [];
|
|
1311
|
+
}
|
|
1312
|
+
get renderCustomMessages() {
|
|
1313
|
+
return this._renderCustomMessages;
|
|
1314
|
+
}
|
|
1315
|
+
get renderActivityMessages() {
|
|
1316
|
+
return this._renderActivityMessages;
|
|
1317
|
+
}
|
|
1318
|
+
get renderToolCalls() {
|
|
1319
|
+
if (this._hookRenderToolCalls.size === 0) return this._renderToolCalls;
|
|
1320
|
+
if (this._cachedMergedRenderToolCalls) return this._cachedMergedRenderToolCalls;
|
|
1321
|
+
const merged = /* @__PURE__ */ new Map();
|
|
1322
|
+
for (const rc of this._renderToolCalls) merged.set(`${rc.agentId ?? ""}:${rc.name}`, rc);
|
|
1323
|
+
for (const [key, rc] of this._hookRenderToolCalls) merged.set(key, rc);
|
|
1324
|
+
this._cachedMergedRenderToolCalls = Array.from(merged.values());
|
|
1325
|
+
return this._cachedMergedRenderToolCalls;
|
|
1326
|
+
}
|
|
1327
|
+
setRenderActivityMessages(renderers) {
|
|
1328
|
+
this._renderActivityMessages = renderers;
|
|
1329
|
+
}
|
|
1330
|
+
setRenderCustomMessages(renderers) {
|
|
1331
|
+
this._renderCustomMessages = renderers;
|
|
1332
|
+
}
|
|
1333
|
+
setRenderToolCalls(renderToolCalls) {
|
|
1334
|
+
this._renderToolCalls = renderToolCalls;
|
|
1335
|
+
this._cachedMergedRenderToolCalls = null;
|
|
1336
|
+
this._notifyRenderToolCallsChanged();
|
|
1337
|
+
}
|
|
1338
|
+
addHookRenderToolCall(entry) {
|
|
1339
|
+
const key = `${entry.agentId ?? ""}:${entry.name}`;
|
|
1340
|
+
this._hookRenderToolCalls.set(key, entry);
|
|
1341
|
+
this._cachedMergedRenderToolCalls = null;
|
|
1342
|
+
this._notifyRenderToolCallsChanged();
|
|
1343
|
+
}
|
|
1344
|
+
removeHookRenderToolCall(name, agentId) {
|
|
1345
|
+
const key = `${agentId ?? ""}:${name}`;
|
|
1346
|
+
if (this._hookRenderToolCalls.delete(key)) {
|
|
1347
|
+
this._cachedMergedRenderToolCalls = null;
|
|
1348
|
+
this._notifyRenderToolCallsChanged();
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
_notifyRenderToolCallsChanged() {
|
|
1352
|
+
this.notifySubscribers((subscriber) => {
|
|
1353
|
+
const reactSubscriber = subscriber;
|
|
1354
|
+
if (reactSubscriber.onRenderToolCallsChanged) reactSubscriber.onRenderToolCallsChanged({
|
|
1355
|
+
copilotkit: this,
|
|
1356
|
+
renderToolCalls: this.renderToolCalls
|
|
1357
|
+
});
|
|
1358
|
+
}, "Subscriber onRenderToolCallsChanged error:");
|
|
1359
|
+
}
|
|
1360
|
+
get interruptElement() {
|
|
1361
|
+
return this._interruptElement;
|
|
1362
|
+
}
|
|
1363
|
+
setInterruptElement(element) {
|
|
1364
|
+
this._interruptElement = element;
|
|
1365
|
+
this.notifySubscribers((subscriber) => {
|
|
1366
|
+
subscriber.onInterruptElementChanged?.({
|
|
1367
|
+
copilotkit: this,
|
|
1368
|
+
interruptElement: this._interruptElement
|
|
1369
|
+
});
|
|
1370
|
+
}, "Subscriber onInterruptElementChanged error:");
|
|
1371
|
+
}
|
|
1372
|
+
subscribe(subscriber) {
|
|
1373
|
+
return super.subscribe(subscriber);
|
|
1374
|
+
}
|
|
1375
|
+
/**
|
|
1376
|
+
* Wait for pending React state updates before the follow-up agent run.
|
|
1377
|
+
*
|
|
1378
|
+
* When a frontend tool handler calls setState(), React 18 batches the update
|
|
1379
|
+
* and schedules a commit via its internal scheduler (MessageChannel). The
|
|
1380
|
+
* useAgentContext hook registers context via useLayoutEffect, which runs
|
|
1381
|
+
* synchronously after React commits that batch.
|
|
1382
|
+
*
|
|
1383
|
+
* Awaiting a zero-delay timeout yields to the macrotask queue. React's
|
|
1384
|
+
* MessageChannel task runs first, committing the pending state and running
|
|
1385
|
+
* useLayoutEffect (which updates the context store). The follow-up runAgent
|
|
1386
|
+
* call then reads fresh context.
|
|
1387
|
+
*/
|
|
1388
|
+
async waitForPendingFrameworkUpdates() {
|
|
1389
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
1390
|
+
}
|
|
1391
|
+
};
|
|
1392
|
+
|
|
1393
|
+
//#endregion
|
|
1394
|
+
//#region src/v2/context.ts
|
|
1395
|
+
const CopilotKitContext = createContext(null);
|
|
1396
|
+
const useCopilotKit = () => {
|
|
1397
|
+
const context = useContext(CopilotKitContext);
|
|
1398
|
+
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
1399
|
+
if (!context) throw new Error("useCopilotKit must be used within CopilotKitProvider");
|
|
1400
|
+
useEffect(() => {
|
|
1401
|
+
const subscription = context.copilotkit.subscribe({ onRuntimeConnectionStatusChanged: () => {
|
|
1402
|
+
forceUpdate();
|
|
1403
|
+
} });
|
|
1404
|
+
return () => {
|
|
1405
|
+
subscription.unsubscribe();
|
|
1406
|
+
};
|
|
1407
|
+
}, []);
|
|
1408
|
+
return context;
|
|
1409
|
+
};
|
|
1410
|
+
const LicenseContext = createContext({
|
|
1411
|
+
status: null,
|
|
1412
|
+
license: null,
|
|
1413
|
+
checkFeature: () => true,
|
|
1414
|
+
getLimit: () => null
|
|
1415
|
+
});
|
|
1416
|
+
const useLicenseContext = () => useContext(LicenseContext);
|
|
1417
|
+
|
|
1418
|
+
//#endregion
|
|
1419
|
+
//#region src/v2/hooks/use-render-tool-call.tsx
|
|
1420
|
+
/**
|
|
1421
|
+
* Memoized component that renders a single tool call.
|
|
1422
|
+
* This prevents unnecessary re-renders when parent components update
|
|
1423
|
+
* but the tool call data hasn't changed.
|
|
1424
|
+
*/
|
|
1425
|
+
const ToolCallRenderer = React.memo(function ToolCallRenderer({ toolCall, toolMessage, RenderComponent, isExecuting }) {
|
|
1426
|
+
const args = useMemo(() => partialJSONParse(toolCall.function.arguments), [toolCall.function.arguments]);
|
|
1427
|
+
const toolName = toolCall.function.name;
|
|
1428
|
+
if (toolMessage) return /* @__PURE__ */ jsx(RenderComponent, {
|
|
1429
|
+
name: toolName,
|
|
1430
|
+
toolCallId: toolCall.id,
|
|
1431
|
+
args,
|
|
1432
|
+
status: ToolCallStatus.Complete,
|
|
1433
|
+
result: toolMessage.content
|
|
1434
|
+
});
|
|
1435
|
+
else if (isExecuting) return /* @__PURE__ */ jsx(RenderComponent, {
|
|
1436
|
+
name: toolName,
|
|
1437
|
+
toolCallId: toolCall.id,
|
|
1438
|
+
args,
|
|
1439
|
+
status: ToolCallStatus.Executing,
|
|
1440
|
+
result: void 0
|
|
1441
|
+
});
|
|
1442
|
+
else return /* @__PURE__ */ jsx(RenderComponent, {
|
|
1443
|
+
name: toolName,
|
|
1444
|
+
toolCallId: toolCall.id,
|
|
1445
|
+
args,
|
|
1446
|
+
status: ToolCallStatus.InProgress,
|
|
1447
|
+
result: void 0
|
|
1448
|
+
});
|
|
1449
|
+
}, (prevProps, nextProps) => {
|
|
1450
|
+
if (prevProps.toolCall.id !== nextProps.toolCall.id) return false;
|
|
1451
|
+
if (prevProps.toolCall.function.name !== nextProps.toolCall.function.name) return false;
|
|
1452
|
+
if (prevProps.toolCall.function.arguments !== nextProps.toolCall.function.arguments) return false;
|
|
1453
|
+
if (prevProps.toolMessage?.content !== nextProps.toolMessage?.content) return false;
|
|
1454
|
+
if (prevProps.isExecuting !== nextProps.isExecuting) return false;
|
|
1455
|
+
if (prevProps.RenderComponent !== nextProps.RenderComponent) return false;
|
|
1456
|
+
return true;
|
|
1457
|
+
});
|
|
1458
|
+
/**
|
|
1459
|
+
* Hook that returns a function to render tool calls based on the render functions
|
|
1460
|
+
* defined in CopilotKitProvider.
|
|
1461
|
+
*
|
|
1462
|
+
* @returns A function that takes a tool call and optional tool message and returns the rendered component
|
|
1463
|
+
*/
|
|
1464
|
+
function useRenderToolCall() {
|
|
1465
|
+
const { copilotkit, executingToolCallIds } = useCopilotKit();
|
|
1466
|
+
const agentId = useCopilotChatConfiguration()?.agentId ?? DEFAULT_AGENT_ID;
|
|
1467
|
+
const renderToolCalls = useSyncExternalStore((callback) => {
|
|
1468
|
+
return copilotkit.subscribe({ onRenderToolCallsChanged: callback }).unsubscribe;
|
|
1469
|
+
}, () => copilotkit.renderToolCalls, () => copilotkit.renderToolCalls);
|
|
1470
|
+
return useCallback(({ toolCall, toolMessage }) => {
|
|
1471
|
+
const exactMatches = renderToolCalls.filter((rc) => rc.name === toolCall.function.name);
|
|
1472
|
+
const renderConfig = exactMatches.find((rc) => rc.agentId === agentId) || exactMatches.find((rc) => !rc.agentId) || exactMatches[0] || renderToolCalls.find((rc) => rc.name === "*");
|
|
1473
|
+
if (!renderConfig) return null;
|
|
1474
|
+
const RenderComponent = renderConfig.render;
|
|
1475
|
+
return /* @__PURE__ */ jsx(ToolCallRenderer, {
|
|
1476
|
+
toolCall,
|
|
1477
|
+
toolMessage,
|
|
1478
|
+
RenderComponent,
|
|
1479
|
+
isExecuting: executingToolCallIds.has(toolCall.id)
|
|
1480
|
+
}, toolCall.id);
|
|
1481
|
+
}, [
|
|
1482
|
+
renderToolCalls,
|
|
1483
|
+
executingToolCallIds,
|
|
1484
|
+
agentId
|
|
1485
|
+
]);
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1297
1488
|
//#endregion
|
|
1298
1489
|
//#region src/v2/components/CopilotKitInspector.tsx
|
|
1299
1490
|
const CopilotKitInspector = ({ core, ...rest }) => {
|
|
@@ -2937,102 +3128,6 @@ function A2UICatalogContext({ catalog, includeSchema }) {
|
|
|
2937
3128
|
return null;
|
|
2938
3129
|
}
|
|
2939
3130
|
|
|
2940
|
-
//#endregion
|
|
2941
|
-
//#region src/v2/lib/react-core.ts
|
|
2942
|
-
var CopilotKitCoreReact = class extends CopilotKitCore {
|
|
2943
|
-
constructor(config) {
|
|
2944
|
-
super(config);
|
|
2945
|
-
this._renderToolCalls = [];
|
|
2946
|
-
this._hookRenderToolCalls = /* @__PURE__ */ new Map();
|
|
2947
|
-
this._cachedMergedRenderToolCalls = null;
|
|
2948
|
-
this._renderCustomMessages = [];
|
|
2949
|
-
this._renderActivityMessages = [];
|
|
2950
|
-
this._interruptElement = null;
|
|
2951
|
-
this._renderToolCalls = config.renderToolCalls ?? [];
|
|
2952
|
-
this._renderCustomMessages = config.renderCustomMessages ?? [];
|
|
2953
|
-
this._renderActivityMessages = config.renderActivityMessages ?? [];
|
|
2954
|
-
}
|
|
2955
|
-
get renderCustomMessages() {
|
|
2956
|
-
return this._renderCustomMessages;
|
|
2957
|
-
}
|
|
2958
|
-
get renderActivityMessages() {
|
|
2959
|
-
return this._renderActivityMessages;
|
|
2960
|
-
}
|
|
2961
|
-
get renderToolCalls() {
|
|
2962
|
-
if (this._hookRenderToolCalls.size === 0) return this._renderToolCalls;
|
|
2963
|
-
if (this._cachedMergedRenderToolCalls) return this._cachedMergedRenderToolCalls;
|
|
2964
|
-
const merged = /* @__PURE__ */ new Map();
|
|
2965
|
-
for (const rc of this._renderToolCalls) merged.set(`${rc.agentId ?? ""}:${rc.name}`, rc);
|
|
2966
|
-
for (const [key, rc] of this._hookRenderToolCalls) merged.set(key, rc);
|
|
2967
|
-
this._cachedMergedRenderToolCalls = Array.from(merged.values());
|
|
2968
|
-
return this._cachedMergedRenderToolCalls;
|
|
2969
|
-
}
|
|
2970
|
-
setRenderActivityMessages(renderers) {
|
|
2971
|
-
this._renderActivityMessages = renderers;
|
|
2972
|
-
}
|
|
2973
|
-
setRenderCustomMessages(renderers) {
|
|
2974
|
-
this._renderCustomMessages = renderers;
|
|
2975
|
-
}
|
|
2976
|
-
setRenderToolCalls(renderToolCalls) {
|
|
2977
|
-
this._renderToolCalls = renderToolCalls;
|
|
2978
|
-
this._cachedMergedRenderToolCalls = null;
|
|
2979
|
-
this._notifyRenderToolCallsChanged();
|
|
2980
|
-
}
|
|
2981
|
-
addHookRenderToolCall(entry) {
|
|
2982
|
-
const key = `${entry.agentId ?? ""}:${entry.name}`;
|
|
2983
|
-
this._hookRenderToolCalls.set(key, entry);
|
|
2984
|
-
this._cachedMergedRenderToolCalls = null;
|
|
2985
|
-
this._notifyRenderToolCallsChanged();
|
|
2986
|
-
}
|
|
2987
|
-
removeHookRenderToolCall(name, agentId) {
|
|
2988
|
-
const key = `${agentId ?? ""}:${name}`;
|
|
2989
|
-
if (this._hookRenderToolCalls.delete(key)) {
|
|
2990
|
-
this._cachedMergedRenderToolCalls = null;
|
|
2991
|
-
this._notifyRenderToolCallsChanged();
|
|
2992
|
-
}
|
|
2993
|
-
}
|
|
2994
|
-
_notifyRenderToolCallsChanged() {
|
|
2995
|
-
this.notifySubscribers((subscriber) => {
|
|
2996
|
-
const reactSubscriber = subscriber;
|
|
2997
|
-
if (reactSubscriber.onRenderToolCallsChanged) reactSubscriber.onRenderToolCallsChanged({
|
|
2998
|
-
copilotkit: this,
|
|
2999
|
-
renderToolCalls: this.renderToolCalls
|
|
3000
|
-
});
|
|
3001
|
-
}, "Subscriber onRenderToolCallsChanged error:");
|
|
3002
|
-
}
|
|
3003
|
-
get interruptElement() {
|
|
3004
|
-
return this._interruptElement;
|
|
3005
|
-
}
|
|
3006
|
-
setInterruptElement(element) {
|
|
3007
|
-
this._interruptElement = element;
|
|
3008
|
-
this.notifySubscribers((subscriber) => {
|
|
3009
|
-
subscriber.onInterruptElementChanged?.({
|
|
3010
|
-
copilotkit: this,
|
|
3011
|
-
interruptElement: this._interruptElement
|
|
3012
|
-
});
|
|
3013
|
-
}, "Subscriber onInterruptElementChanged error:");
|
|
3014
|
-
}
|
|
3015
|
-
subscribe(subscriber) {
|
|
3016
|
-
return super.subscribe(subscriber);
|
|
3017
|
-
}
|
|
3018
|
-
/**
|
|
3019
|
-
* Wait for pending React state updates before the follow-up agent run.
|
|
3020
|
-
*
|
|
3021
|
-
* When a frontend tool handler calls setState(), React 18 batches the update
|
|
3022
|
-
* and schedules a commit via its internal scheduler (MessageChannel). The
|
|
3023
|
-
* useAgentContext hook registers context via useLayoutEffect, which runs
|
|
3024
|
-
* synchronously after React commits that batch.
|
|
3025
|
-
*
|
|
3026
|
-
* Awaiting a zero-delay timeout yields to the macrotask queue. React's
|
|
3027
|
-
* MessageChannel task runs first, committing the pending state and running
|
|
3028
|
-
* useLayoutEffect (which updates the context store). The follow-up runAgent
|
|
3029
|
-
* call then reads fresh context.
|
|
3030
|
-
*/
|
|
3031
|
-
async waitForPendingFrameworkUpdates() {
|
|
3032
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
3033
|
-
}
|
|
3034
|
-
};
|
|
3035
|
-
|
|
3036
3131
|
//#endregion
|
|
3037
3132
|
//#region src/v2/providers/CopilotKitProvider.tsx
|
|
3038
3133
|
const HEADER_NAME = "X-CopilotCloud-Public-Api-Key";
|
|
@@ -3048,12 +3143,6 @@ const DEFAULT_DESIGN_SKILL = `When generating UI with generateSandboxedUi, follo
|
|
|
3048
3143
|
- Minimal transitions (150ms) for hover/focus states only. No decorative animations.
|
|
3049
3144
|
- Keep the UI focused and dense — avoid excessive padding. Use compact spacing (8–12px gaps, 10–14px padding in controls).`;
|
|
3050
3145
|
const GENERATE_SANDBOXED_UI_DESCRIPTION = "Generate sandboxed UI. IMPORTANT: The generated code runs in a sandboxed iframe WITHOUT same-origin access. Do NOT use localStorage, sessionStorage, document.cookie, IndexedDB, or fetch/XMLHttpRequest to same-origin URLs. To communicate with the host application, use Websandbox.connection.remote.<functionName>(args) which returns a Promise.\n\nYou CAN use external libraries from CDNs by including <script> or <link> tags in the HTML <head> (e.g., Chart.js, D3, Three.js, x-data-spreadsheet, etc.). CDN resources load normally inside the sandbox.\n\nPARAMETER ORDER IS CRITICAL — generate parameters in exactly this order:\n1. initialHeight + placeholderMessages (shown to user while generating)\n2. css (all styles FIRST — the user sees a placeholder until CSS is complete)\n3. html (streams in live — the user watches the UI build as HTML is generated)\n4. jsFunctions (reusable helper functions)\n5. jsExpressions (applied one-by-one — the user sees each expression take effect)";
|
|
3051
|
-
const CopilotKitContext = createContext({
|
|
3052
|
-
copilotkit: null,
|
|
3053
|
-
executingToolCallIds: /* @__PURE__ */ new Set()
|
|
3054
|
-
});
|
|
3055
|
-
const LicenseContext = createContext(createLicenseContextValue(null));
|
|
3056
|
-
const useLicenseContext = () => useContext(LicenseContext);
|
|
3057
3146
|
function useStableArrayProp(prop, warningMessage, isMeaningfulChange) {
|
|
3058
3147
|
const empty = useMemo(() => [], []);
|
|
3059
3148
|
const value = prop ?? empty;
|
|
@@ -3275,13 +3364,9 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = {}, c
|
|
|
3275
3364
|
onErrorRef.current = onError;
|
|
3276
3365
|
}, [onError]);
|
|
3277
3366
|
useEffect(() => {
|
|
3278
|
-
if (!onErrorRef.current) return;
|
|
3279
3367
|
const subscription = copilotkit.subscribe({ onError: (event) => {
|
|
3280
|
-
onErrorRef.current
|
|
3281
|
-
|
|
3282
|
-
code: event.code,
|
|
3283
|
-
context: event.context
|
|
3284
|
-
});
|
|
3368
|
+
if (onErrorRef.current) onErrorRef.current(event);
|
|
3369
|
+
else console.error(`[CopilotKit] Error (${event.code}):`, event.error, event.context ?? {});
|
|
3285
3370
|
} });
|
|
3286
3371
|
return () => {
|
|
3287
3372
|
subscription.unsubscribe();
|
|
@@ -3396,90 +3481,6 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = {}, c
|
|
|
3396
3481
|
})
|
|
3397
3482
|
});
|
|
3398
3483
|
};
|
|
3399
|
-
const useCopilotKit = () => {
|
|
3400
|
-
const context = useContext(CopilotKitContext);
|
|
3401
|
-
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
3402
|
-
if (!context) throw new Error("useCopilotKit must be used within CopilotKitProvider");
|
|
3403
|
-
useEffect(() => {
|
|
3404
|
-
const subscription = context.copilotkit.subscribe({ onRuntimeConnectionStatusChanged: () => {
|
|
3405
|
-
forceUpdate();
|
|
3406
|
-
} });
|
|
3407
|
-
return () => {
|
|
3408
|
-
subscription.unsubscribe();
|
|
3409
|
-
};
|
|
3410
|
-
}, []);
|
|
3411
|
-
return context;
|
|
3412
|
-
};
|
|
3413
|
-
|
|
3414
|
-
//#endregion
|
|
3415
|
-
//#region src/v2/hooks/use-render-tool-call.tsx
|
|
3416
|
-
/**
|
|
3417
|
-
* Memoized component that renders a single tool call.
|
|
3418
|
-
* This prevents unnecessary re-renders when parent components update
|
|
3419
|
-
* but the tool call data hasn't changed.
|
|
3420
|
-
*/
|
|
3421
|
-
const ToolCallRenderer = React.memo(function ToolCallRenderer({ toolCall, toolMessage, RenderComponent, isExecuting }) {
|
|
3422
|
-
const args = useMemo(() => partialJSONParse(toolCall.function.arguments), [toolCall.function.arguments]);
|
|
3423
|
-
const toolName = toolCall.function.name;
|
|
3424
|
-
if (toolMessage) return /* @__PURE__ */ jsx(RenderComponent, {
|
|
3425
|
-
name: toolName,
|
|
3426
|
-
toolCallId: toolCall.id,
|
|
3427
|
-
args,
|
|
3428
|
-
status: ToolCallStatus.Complete,
|
|
3429
|
-
result: toolMessage.content
|
|
3430
|
-
});
|
|
3431
|
-
else if (isExecuting) return /* @__PURE__ */ jsx(RenderComponent, {
|
|
3432
|
-
name: toolName,
|
|
3433
|
-
toolCallId: toolCall.id,
|
|
3434
|
-
args,
|
|
3435
|
-
status: ToolCallStatus.Executing,
|
|
3436
|
-
result: void 0
|
|
3437
|
-
});
|
|
3438
|
-
else return /* @__PURE__ */ jsx(RenderComponent, {
|
|
3439
|
-
name: toolName,
|
|
3440
|
-
toolCallId: toolCall.id,
|
|
3441
|
-
args,
|
|
3442
|
-
status: ToolCallStatus.InProgress,
|
|
3443
|
-
result: void 0
|
|
3444
|
-
});
|
|
3445
|
-
}, (prevProps, nextProps) => {
|
|
3446
|
-
if (prevProps.toolCall.id !== nextProps.toolCall.id) return false;
|
|
3447
|
-
if (prevProps.toolCall.function.name !== nextProps.toolCall.function.name) return false;
|
|
3448
|
-
if (prevProps.toolCall.function.arguments !== nextProps.toolCall.function.arguments) return false;
|
|
3449
|
-
if (prevProps.toolMessage?.content !== nextProps.toolMessage?.content) return false;
|
|
3450
|
-
if (prevProps.isExecuting !== nextProps.isExecuting) return false;
|
|
3451
|
-
if (prevProps.RenderComponent !== nextProps.RenderComponent) return false;
|
|
3452
|
-
return true;
|
|
3453
|
-
});
|
|
3454
|
-
/**
|
|
3455
|
-
* Hook that returns a function to render tool calls based on the render functions
|
|
3456
|
-
* defined in CopilotKitProvider.
|
|
3457
|
-
*
|
|
3458
|
-
* @returns A function that takes a tool call and optional tool message and returns the rendered component
|
|
3459
|
-
*/
|
|
3460
|
-
function useRenderToolCall() {
|
|
3461
|
-
const { copilotkit, executingToolCallIds } = useCopilotKit();
|
|
3462
|
-
const agentId = useCopilotChatConfiguration()?.agentId ?? DEFAULT_AGENT_ID;
|
|
3463
|
-
const renderToolCalls = useSyncExternalStore((callback) => {
|
|
3464
|
-
return copilotkit.subscribe({ onRenderToolCallsChanged: callback }).unsubscribe;
|
|
3465
|
-
}, () => copilotkit.renderToolCalls, () => copilotkit.renderToolCalls);
|
|
3466
|
-
return useCallback(({ toolCall, toolMessage }) => {
|
|
3467
|
-
const exactMatches = renderToolCalls.filter((rc) => rc.name === toolCall.function.name);
|
|
3468
|
-
const renderConfig = exactMatches.find((rc) => rc.agentId === agentId) || exactMatches.find((rc) => !rc.agentId) || exactMatches[0] || renderToolCalls.find((rc) => rc.name === "*");
|
|
3469
|
-
if (!renderConfig) return null;
|
|
3470
|
-
const RenderComponent = renderConfig.render;
|
|
3471
|
-
return /* @__PURE__ */ jsx(ToolCallRenderer, {
|
|
3472
|
-
toolCall,
|
|
3473
|
-
toolMessage,
|
|
3474
|
-
RenderComponent,
|
|
3475
|
-
isExecuting: executingToolCallIds.has(toolCall.id)
|
|
3476
|
-
}, toolCall.id);
|
|
3477
|
-
}, [
|
|
3478
|
-
renderToolCalls,
|
|
3479
|
-
executingToolCallIds,
|
|
3480
|
-
agentId
|
|
3481
|
-
]);
|
|
3482
|
-
}
|
|
3483
3484
|
|
|
3484
3485
|
//#endregion
|
|
3485
3486
|
//#region src/v2/hooks/use-render-custom-messages.tsx
|
|
@@ -3593,8 +3594,7 @@ function useFrontendTool(tool, deps) {
|
|
|
3593
3594
|
tool.name,
|
|
3594
3595
|
tool.available,
|
|
3595
3596
|
copilotkit,
|
|
3596
|
-
extraDeps
|
|
3597
|
-
...extraDeps
|
|
3597
|
+
JSON.stringify(extraDeps)
|
|
3598
3598
|
]);
|
|
3599
3599
|
}
|
|
3600
3600
|
|
|
@@ -3733,8 +3733,7 @@ function useRenderTool(config, deps) {
|
|
|
3733
3733
|
}, [
|
|
3734
3734
|
config.name,
|
|
3735
3735
|
copilotkit,
|
|
3736
|
-
extraDeps
|
|
3737
|
-
...extraDeps
|
|
3736
|
+
JSON.stringify(extraDeps)
|
|
3738
3737
|
]);
|
|
3739
3738
|
}
|
|
3740
3739
|
|
|
@@ -4080,7 +4079,7 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
|
|
|
4080
4079
|
});
|
|
4081
4080
|
}
|
|
4082
4081
|
};
|
|
4083
|
-
if (updateFlags.includes(UseAgentUpdate.OnMessagesChanged)) handlers.onMessagesChanged =
|
|
4082
|
+
if (updateFlags.includes(UseAgentUpdate.OnMessagesChanged)) handlers.onMessagesChanged = batchedForceUpdate;
|
|
4084
4083
|
if (updateFlags.includes(UseAgentUpdate.OnStateChanged)) handlers.onStateChanged = batchedForceUpdate;
|
|
4085
4084
|
if (updateFlags.includes(UseAgentUpdate.OnRunStatusChanged)) {
|
|
4086
4085
|
handlers.onRunInitialized = batchedForceUpdate;
|
|
@@ -9934,5 +9933,5 @@ function validateProps(props) {
|
|
|
9934
9933
|
}
|
|
9935
9934
|
|
|
9936
9935
|
//#endregion
|
|
9937
|
-
export {
|
|
9938
|
-
//# sourceMappingURL=copilotkit-
|
|
9936
|
+
export { CopilotKitProvider as $, IntelligenceIndicator as A, useInterrupt as B, CopilotChatToggleButton as C, CopilotChatView_default as D, CopilotChat as E, CopilotChatAttachmentRenderer as F, useAgent as G, useSuggestions as H, CopilotChatAssistantMessage_default as I, useRenderTool as J, useHumanInTheLoop as K, CopilotChatToolCallsView as L, CopilotChatSuggestionPill as M, CopilotChatReasoningMessage_default as N, CopilotChatAttachmentQueue as O, CopilotChatUserMessage_default as P, useRenderCustomMessages as Q, useAttachments as R, CopilotModalHeader as S, DefaultOpenIcon as T, useCapabilities as U, useConfigureSuggestions as V, UseAgentUpdate as W, useFrontendTool as X, useComponent as Y, useRenderActivityMessage as Z, WildcardToolCallRender as _, ThreadsProvider as a, MCPAppsActivityContentSchema as at, CopilotPopupView as b, CoAgentStateRendersProvider as c, CopilotKitInspector as ct, shouldShowDevConsole as d, CopilotKitCoreReact as dt, useAgentContext as et, useToast as f, CopilotChatInput_default as ft, useCopilotContext as g, useCopilotChatConfiguration as gt, CopilotContext as h, CopilotChatConfigurationProvider as ht, ThreadsContext as i, useSandboxFunctions as it, CopilotChatSuggestionView as j, CopilotChatMessageView as k, useCoAgentStateRenders as l, useRenderToolCall as lt, useCopilotMessagesContext as m, CopilotChatAudioRecorder as mt, defaultCopilotContextCategories as n, createA2UIMessageRenderer as nt, useThreads as o, MCPAppsActivityRenderer as ot, CopilotMessagesContext as p, AudioRecorderError as pt, useDefaultRenderTool as q, CoAgentStateRenderBridge as r, SandboxFunctionsContext as rt, CoAgentStateRendersContext as s, MCPAppsActivityType as st, CopilotKit as t, defineToolCallRenderer as tt, useAsyncCallback as u, useCopilotKit as ut, CopilotPopup as v, DefaultCloseIcon as w, CopilotSidebarView as x, CopilotSidebar as y, useThreads$1 as z };
|
|
9937
|
+
//# sourceMappingURL=copilotkit-DjxXMYHG.mjs.map
|