@copilotkit/react-core 1.57.0 → 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.
Files changed (82) hide show
  1. package/dist/{copilotkit-DFaI4j2r.d.mts → copilotkit-BN4I_y1n.d.mts} +64 -8
  2. package/dist/copilotkit-BN4I_y1n.d.mts.map +1 -0
  3. package/dist/{copilotkit-DGbvw8n2.cjs → copilotkit-C3k13WZn.cjs} +572 -435
  4. package/dist/copilotkit-C3k13WZn.cjs.map +1 -0
  5. package/dist/{copilotkit-CPe2-340.mjs → copilotkit-DjxXMYHG.mjs} +571 -440
  6. package/dist/copilotkit-DjxXMYHG.mjs.map +1 -0
  7. package/dist/{copilotkit-Dg4r4Gi_.d.cts → copilotkit-sQWiKtxA.d.cts} +64 -8
  8. package/dist/copilotkit-sQWiKtxA.d.cts.map +1 -0
  9. package/dist/index.cjs +2 -5
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +1 -1
  12. package/dist/index.d.mts +1 -1
  13. package/dist/index.mjs +2 -5
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/index.umd.js +449 -502
  16. package/dist/index.umd.js.map +1 -1
  17. package/dist/v2/context.cjs +135 -0
  18. package/dist/v2/context.cjs.map +1 -0
  19. package/dist/v2/context.d.cts +148 -0
  20. package/dist/v2/context.d.cts.map +1 -0
  21. package/dist/v2/context.d.mts +148 -0
  22. package/dist/v2/context.d.mts.map +1 -0
  23. package/dist/v2/context.mjs +129 -0
  24. package/dist/v2/context.mjs.map +1 -0
  25. package/dist/v2/headless.cjs +1043 -0
  26. package/dist/v2/headless.cjs.map +1 -0
  27. package/dist/v2/headless.d.cts +605 -0
  28. package/dist/v2/headless.d.cts.map +1 -0
  29. package/dist/v2/headless.d.mts +512 -0
  30. package/dist/v2/headless.d.mts.map +1 -0
  31. package/dist/v2/headless.mjs +997 -0
  32. package/dist/v2/headless.mjs.map +1 -0
  33. package/dist/v2/index.cjs +2 -1
  34. package/dist/v2/index.css +1 -1
  35. package/dist/v2/index.d.cts +2 -2
  36. package/dist/v2/index.d.mts +2 -2
  37. package/dist/v2/index.mjs +2 -2
  38. package/dist/v2/index.umd.js +584 -441
  39. package/dist/v2/index.umd.js.map +1 -1
  40. package/package.json +14 -6
  41. package/src/hooks/__tests__/use-copilot-chat-internal-connect.test.tsx +5 -6
  42. package/src/hooks/use-copilot-chat_internal.ts +0 -1
  43. package/src/v2/components/chat/CopilotChat.tsx +2 -1
  44. package/src/v2/components/chat/CopilotChatMessageView.tsx +24 -9
  45. package/src/v2/components/chat/CopilotChatView.tsx +2 -2
  46. package/src/v2/components/chat/__tests__/CopilotChat.welcomeGate.test.tsx +1 -3
  47. package/src/v2/components/chat/__tests__/CopilotChatActivityRendering.e2e.test.tsx +29 -25
  48. package/src/v2/components/chat/__tests__/MCPAppsUiMessage.e2e.test.tsx +5 -60
  49. package/src/v2/components/index.ts +1 -0
  50. package/src/v2/components/intelligence-indicator/IntelligenceIndicator.tsx +286 -0
  51. package/src/v2/components/intelligence-indicator/__tests__/IntelligenceIndicator.e2e.test.tsx +464 -0
  52. package/src/v2/components/intelligence-indicator/index.ts +2 -0
  53. package/src/v2/context.ts +62 -0
  54. package/src/v2/headless.ts +42 -0
  55. package/src/v2/hooks/__tests__/standard-schema.test.tsx +2 -2
  56. package/src/v2/hooks/__tests__/use-agent-context.test.tsx +3 -3
  57. package/src/v2/hooks/__tests__/use-agent-stability.test.tsx +3 -3
  58. package/src/v2/hooks/__tests__/use-agent-throttle.test.tsx +85 -85
  59. package/src/v2/hooks/__tests__/use-interrupt.test.tsx +2 -2
  60. package/src/v2/hooks/__tests__/use-render-tool.test.tsx +2 -2
  61. package/src/v2/hooks/__tests__/use-threads.test.tsx +2 -2
  62. package/src/v2/hooks/__tests__/zod-regression.test.tsx +2 -2
  63. package/src/v2/hooks/use-agent-context.tsx +1 -1
  64. package/src/v2/hooks/use-agent.tsx +9 -118
  65. package/src/v2/hooks/use-configure-suggestions.tsx +1 -1
  66. package/src/v2/hooks/use-frontend-tool.tsx +2 -2
  67. package/src/v2/hooks/use-human-in-the-loop.tsx +1 -1
  68. package/src/v2/hooks/use-interrupt.tsx +1 -1
  69. package/src/v2/hooks/use-render-activity-message.tsx +3 -11
  70. package/src/v2/hooks/use-render-custom-messages.tsx +1 -6
  71. package/src/v2/hooks/use-render-tool-call.tsx +1 -1
  72. package/src/v2/hooks/use-render-tool.tsx +2 -2
  73. package/src/v2/hooks/use-suggestions.tsx +1 -1
  74. package/src/v2/hooks/use-threads.tsx +1 -1
  75. package/src/v2/providers/CopilotKitProvider.tsx +19 -59
  76. package/src/v2/styles/globals.css +118 -0
  77. package/tsdown.config.ts +75 -0
  78. package/dist/copilotkit-CPe2-340.mjs.map +0 -1
  79. package/dist/copilotkit-DFaI4j2r.d.mts.map +0 -1
  80. package/dist/copilotkit-DGbvw8n2.cjs.map +0 -1
  81. package/dist/copilotkit-Dg4r4Gi_.d.cts.map +0 -1
  82. package/src/v2/hooks/__tests__/use-agent-thread-isolation.test.tsx +0 -333
@@ -1335,6 +1335,207 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
1335
1335
  }, []);
1336
1336
  }
1337
1337
 
1338
+ //#endregion
1339
+ //#region src/v2/lib/react-core.ts
1340
+ var CopilotKitCoreReact = class extends _copilotkit_core.CopilotKitCore {
1341
+ constructor(config) {
1342
+ var _config$renderToolCal, _config$renderCustomM, _config$renderActivit;
1343
+ super(config);
1344
+ this._renderToolCalls = [];
1345
+ this._hookRenderToolCalls = /* @__PURE__ */ new Map();
1346
+ this._cachedMergedRenderToolCalls = null;
1347
+ this._renderCustomMessages = [];
1348
+ this._renderActivityMessages = [];
1349
+ this._interruptElement = null;
1350
+ this._renderToolCalls = (_config$renderToolCal = config.renderToolCalls) !== null && _config$renderToolCal !== void 0 ? _config$renderToolCal : [];
1351
+ this._renderCustomMessages = (_config$renderCustomM = config.renderCustomMessages) !== null && _config$renderCustomM !== void 0 ? _config$renderCustomM : [];
1352
+ this._renderActivityMessages = (_config$renderActivit = config.renderActivityMessages) !== null && _config$renderActivit !== void 0 ? _config$renderActivit : [];
1353
+ }
1354
+ get renderCustomMessages() {
1355
+ return this._renderCustomMessages;
1356
+ }
1357
+ get renderActivityMessages() {
1358
+ return this._renderActivityMessages;
1359
+ }
1360
+ get renderToolCalls() {
1361
+ if (this._hookRenderToolCalls.size === 0) return this._renderToolCalls;
1362
+ if (this._cachedMergedRenderToolCalls) return this._cachedMergedRenderToolCalls;
1363
+ const merged = /* @__PURE__ */ new Map();
1364
+ for (const rc of this._renderToolCalls) {
1365
+ var _rc$agentId;
1366
+ merged.set(`${(_rc$agentId = rc.agentId) !== null && _rc$agentId !== void 0 ? _rc$agentId : ""}:${rc.name}`, rc);
1367
+ }
1368
+ for (const [key, rc] of this._hookRenderToolCalls) merged.set(key, rc);
1369
+ this._cachedMergedRenderToolCalls = Array.from(merged.values());
1370
+ return this._cachedMergedRenderToolCalls;
1371
+ }
1372
+ setRenderActivityMessages(renderers) {
1373
+ this._renderActivityMessages = renderers;
1374
+ }
1375
+ setRenderCustomMessages(renderers) {
1376
+ this._renderCustomMessages = renderers;
1377
+ }
1378
+ setRenderToolCalls(renderToolCalls) {
1379
+ this._renderToolCalls = renderToolCalls;
1380
+ this._cachedMergedRenderToolCalls = null;
1381
+ this._notifyRenderToolCallsChanged();
1382
+ }
1383
+ addHookRenderToolCall(entry) {
1384
+ var _entry$agentId;
1385
+ const key = `${(_entry$agentId = entry.agentId) !== null && _entry$agentId !== void 0 ? _entry$agentId : ""}:${entry.name}`;
1386
+ this._hookRenderToolCalls.set(key, entry);
1387
+ this._cachedMergedRenderToolCalls = null;
1388
+ this._notifyRenderToolCallsChanged();
1389
+ }
1390
+ removeHookRenderToolCall(name, agentId) {
1391
+ const key = `${agentId !== null && agentId !== void 0 ? agentId : ""}:${name}`;
1392
+ if (this._hookRenderToolCalls.delete(key)) {
1393
+ this._cachedMergedRenderToolCalls = null;
1394
+ this._notifyRenderToolCallsChanged();
1395
+ }
1396
+ }
1397
+ _notifyRenderToolCallsChanged() {
1398
+ this.notifySubscribers((subscriber) => {
1399
+ const reactSubscriber = subscriber;
1400
+ if (reactSubscriber.onRenderToolCallsChanged) reactSubscriber.onRenderToolCallsChanged({
1401
+ copilotkit: this,
1402
+ renderToolCalls: this.renderToolCalls
1403
+ });
1404
+ }, "Subscriber onRenderToolCallsChanged error:");
1405
+ }
1406
+ get interruptElement() {
1407
+ return this._interruptElement;
1408
+ }
1409
+ setInterruptElement(element) {
1410
+ this._interruptElement = element;
1411
+ this.notifySubscribers((subscriber) => {
1412
+ var _reactSubscriber$onIn;
1413
+ const reactSubscriber = subscriber;
1414
+ (_reactSubscriber$onIn = reactSubscriber.onInterruptElementChanged) === null || _reactSubscriber$onIn === void 0 || _reactSubscriber$onIn.call(reactSubscriber, {
1415
+ copilotkit: this,
1416
+ interruptElement: this._interruptElement
1417
+ });
1418
+ }, "Subscriber onInterruptElementChanged error:");
1419
+ }
1420
+ subscribe(subscriber) {
1421
+ return super.subscribe(subscriber);
1422
+ }
1423
+ /**
1424
+ * Wait for pending React state updates before the follow-up agent run.
1425
+ *
1426
+ * When a frontend tool handler calls setState(), React 18 batches the update
1427
+ * and schedules a commit via its internal scheduler (MessageChannel). The
1428
+ * useAgentContext hook registers context via useLayoutEffect, which runs
1429
+ * synchronously after React commits that batch.
1430
+ *
1431
+ * Awaiting a zero-delay timeout yields to the macrotask queue. React's
1432
+ * MessageChannel task runs first, committing the pending state and running
1433
+ * useLayoutEffect (which updates the context store). The follow-up runAgent
1434
+ * call then reads fresh context.
1435
+ */
1436
+ async waitForPendingFrameworkUpdates() {
1437
+ await new Promise((resolve) => setTimeout(resolve, 0));
1438
+ }
1439
+ };
1440
+
1441
+ //#endregion
1442
+ //#region src/v2/context.ts
1443
+ const CopilotKitContext = (0, react.createContext)(null);
1444
+ const useCopilotKit = () => {
1445
+ const context = (0, react.useContext)(CopilotKitContext);
1446
+ const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
1447
+ if (!context) throw new Error("useCopilotKit must be used within CopilotKitProvider");
1448
+ (0, react.useEffect)(() => {
1449
+ const subscription = context.copilotkit.subscribe({ onRuntimeConnectionStatusChanged: () => {
1450
+ forceUpdate();
1451
+ } });
1452
+ return () => {
1453
+ subscription.unsubscribe();
1454
+ };
1455
+ }, []);
1456
+ return context;
1457
+ };
1458
+ const LicenseContext = (0, react.createContext)({
1459
+ status: null,
1460
+ license: null,
1461
+ checkFeature: () => true,
1462
+ getLimit: () => null
1463
+ });
1464
+ const useLicenseContext = () => (0, react.useContext)(LicenseContext);
1465
+
1466
+ //#endregion
1467
+ //#region src/v2/hooks/use-render-tool-call.tsx
1468
+ /**
1469
+ * Memoized component that renders a single tool call.
1470
+ * This prevents unnecessary re-renders when parent components update
1471
+ * but the tool call data hasn't changed.
1472
+ */
1473
+ const ToolCallRenderer = react.default.memo(function ToolCallRenderer({ toolCall, toolMessage, RenderComponent, isExecuting }) {
1474
+ const args = (0, react.useMemo)(() => (0, _copilotkit_shared.partialJSONParse)(toolCall.function.arguments), [toolCall.function.arguments]);
1475
+ const toolName = toolCall.function.name;
1476
+ if (toolMessage) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
1477
+ name: toolName,
1478
+ toolCallId: toolCall.id,
1479
+ args,
1480
+ status: _copilotkit_core.ToolCallStatus.Complete,
1481
+ result: toolMessage.content
1482
+ });
1483
+ else if (isExecuting) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
1484
+ name: toolName,
1485
+ toolCallId: toolCall.id,
1486
+ args,
1487
+ status: _copilotkit_core.ToolCallStatus.Executing,
1488
+ result: void 0
1489
+ });
1490
+ else return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
1491
+ name: toolName,
1492
+ toolCallId: toolCall.id,
1493
+ args,
1494
+ status: _copilotkit_core.ToolCallStatus.InProgress,
1495
+ result: void 0
1496
+ });
1497
+ }, (prevProps, nextProps) => {
1498
+ var _prevProps$toolMessag, _nextProps$toolMessag;
1499
+ if (prevProps.toolCall.id !== nextProps.toolCall.id) return false;
1500
+ if (prevProps.toolCall.function.name !== nextProps.toolCall.function.name) return false;
1501
+ if (prevProps.toolCall.function.arguments !== nextProps.toolCall.function.arguments) return false;
1502
+ if (((_prevProps$toolMessag = prevProps.toolMessage) === null || _prevProps$toolMessag === void 0 ? void 0 : _prevProps$toolMessag.content) !== ((_nextProps$toolMessag = nextProps.toolMessage) === null || _nextProps$toolMessag === void 0 ? void 0 : _nextProps$toolMessag.content)) return false;
1503
+ if (prevProps.isExecuting !== nextProps.isExecuting) return false;
1504
+ if (prevProps.RenderComponent !== nextProps.RenderComponent) return false;
1505
+ return true;
1506
+ });
1507
+ /**
1508
+ * Hook that returns a function to render tool calls based on the render functions
1509
+ * defined in CopilotKitProvider.
1510
+ *
1511
+ * @returns A function that takes a tool call and optional tool message and returns the rendered component
1512
+ */
1513
+ function useRenderToolCall() {
1514
+ var _config$agentId;
1515
+ const { copilotkit, executingToolCallIds } = useCopilotKit();
1516
+ const config = useCopilotChatConfiguration();
1517
+ const agentId = (_config$agentId = config === null || config === void 0 ? void 0 : config.agentId) !== null && _config$agentId !== void 0 ? _config$agentId : _copilotkit_shared.DEFAULT_AGENT_ID;
1518
+ const renderToolCalls = (0, react.useSyncExternalStore)((callback) => {
1519
+ return copilotkit.subscribe({ onRenderToolCallsChanged: callback }).unsubscribe;
1520
+ }, () => copilotkit.renderToolCalls, () => copilotkit.renderToolCalls);
1521
+ return (0, react.useCallback)(({ toolCall, toolMessage }) => {
1522
+ const exactMatches = renderToolCalls.filter((rc) => rc.name === toolCall.function.name);
1523
+ const renderConfig = exactMatches.find((rc) => rc.agentId === agentId) || exactMatches.find((rc) => !rc.agentId) || exactMatches[0] || renderToolCalls.find((rc) => rc.name === "*");
1524
+ if (!renderConfig) return null;
1525
+ const RenderComponent = renderConfig.render;
1526
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolCallRenderer, {
1527
+ toolCall,
1528
+ toolMessage,
1529
+ RenderComponent,
1530
+ isExecuting: executingToolCallIds.has(toolCall.id)
1531
+ }, toolCall.id);
1532
+ }, [
1533
+ renderToolCalls,
1534
+ executingToolCallIds,
1535
+ agentId
1536
+ ]);
1537
+ }
1538
+
1338
1539
  //#endregion
1339
1540
  //#region src/v2/components/CopilotKitInspector.tsx
1340
1541
  const CopilotKitInspector = ({ core, ...rest }) => {
@@ -2996,109 +3197,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2996
3197
  return null;
2997
3198
  }
2998
3199
 
2999
- //#endregion
3000
- //#region src/v2/lib/react-core.ts
3001
- var CopilotKitCoreReact = class extends _copilotkit_core.CopilotKitCore {
3002
- constructor(config) {
3003
- var _config$renderToolCal, _config$renderCustomM, _config$renderActivit;
3004
- super(config);
3005
- this._renderToolCalls = [];
3006
- this._hookRenderToolCalls = /* @__PURE__ */ new Map();
3007
- this._cachedMergedRenderToolCalls = null;
3008
- this._renderCustomMessages = [];
3009
- this._renderActivityMessages = [];
3010
- this._interruptElement = null;
3011
- this._renderToolCalls = (_config$renderToolCal = config.renderToolCalls) !== null && _config$renderToolCal !== void 0 ? _config$renderToolCal : [];
3012
- this._renderCustomMessages = (_config$renderCustomM = config.renderCustomMessages) !== null && _config$renderCustomM !== void 0 ? _config$renderCustomM : [];
3013
- this._renderActivityMessages = (_config$renderActivit = config.renderActivityMessages) !== null && _config$renderActivit !== void 0 ? _config$renderActivit : [];
3014
- }
3015
- get renderCustomMessages() {
3016
- return this._renderCustomMessages;
3017
- }
3018
- get renderActivityMessages() {
3019
- return this._renderActivityMessages;
3020
- }
3021
- get renderToolCalls() {
3022
- if (this._hookRenderToolCalls.size === 0) return this._renderToolCalls;
3023
- if (this._cachedMergedRenderToolCalls) return this._cachedMergedRenderToolCalls;
3024
- const merged = /* @__PURE__ */ new Map();
3025
- for (const rc of this._renderToolCalls) {
3026
- var _rc$agentId;
3027
- merged.set(`${(_rc$agentId = rc.agentId) !== null && _rc$agentId !== void 0 ? _rc$agentId : ""}:${rc.name}`, rc);
3028
- }
3029
- for (const [key, rc] of this._hookRenderToolCalls) merged.set(key, rc);
3030
- this._cachedMergedRenderToolCalls = Array.from(merged.values());
3031
- return this._cachedMergedRenderToolCalls;
3032
- }
3033
- setRenderActivityMessages(renderers) {
3034
- this._renderActivityMessages = renderers;
3035
- }
3036
- setRenderCustomMessages(renderers) {
3037
- this._renderCustomMessages = renderers;
3038
- }
3039
- setRenderToolCalls(renderToolCalls) {
3040
- this._renderToolCalls = renderToolCalls;
3041
- this._cachedMergedRenderToolCalls = null;
3042
- this._notifyRenderToolCallsChanged();
3043
- }
3044
- addHookRenderToolCall(entry) {
3045
- var _entry$agentId;
3046
- const key = `${(_entry$agentId = entry.agentId) !== null && _entry$agentId !== void 0 ? _entry$agentId : ""}:${entry.name}`;
3047
- this._hookRenderToolCalls.set(key, entry);
3048
- this._cachedMergedRenderToolCalls = null;
3049
- this._notifyRenderToolCallsChanged();
3050
- }
3051
- removeHookRenderToolCall(name, agentId) {
3052
- const key = `${agentId !== null && agentId !== void 0 ? agentId : ""}:${name}`;
3053
- if (this._hookRenderToolCalls.delete(key)) {
3054
- this._cachedMergedRenderToolCalls = null;
3055
- this._notifyRenderToolCallsChanged();
3056
- }
3057
- }
3058
- _notifyRenderToolCallsChanged() {
3059
- this.notifySubscribers((subscriber) => {
3060
- const reactSubscriber = subscriber;
3061
- if (reactSubscriber.onRenderToolCallsChanged) reactSubscriber.onRenderToolCallsChanged({
3062
- copilotkit: this,
3063
- renderToolCalls: this.renderToolCalls
3064
- });
3065
- }, "Subscriber onRenderToolCallsChanged error:");
3066
- }
3067
- get interruptElement() {
3068
- return this._interruptElement;
3069
- }
3070
- setInterruptElement(element) {
3071
- this._interruptElement = element;
3072
- this.notifySubscribers((subscriber) => {
3073
- var _reactSubscriber$onIn;
3074
- const reactSubscriber = subscriber;
3075
- (_reactSubscriber$onIn = reactSubscriber.onInterruptElementChanged) === null || _reactSubscriber$onIn === void 0 || _reactSubscriber$onIn.call(reactSubscriber, {
3076
- copilotkit: this,
3077
- interruptElement: this._interruptElement
3078
- });
3079
- }, "Subscriber onInterruptElementChanged error:");
3080
- }
3081
- subscribe(subscriber) {
3082
- return super.subscribe(subscriber);
3083
- }
3084
- /**
3085
- * Wait for pending React state updates before the follow-up agent run.
3086
- *
3087
- * When a frontend tool handler calls setState(), React 18 batches the update
3088
- * and schedules a commit via its internal scheduler (MessageChannel). The
3089
- * useAgentContext hook registers context via useLayoutEffect, which runs
3090
- * synchronously after React commits that batch.
3091
- *
3092
- * Awaiting a zero-delay timeout yields to the macrotask queue. React's
3093
- * MessageChannel task runs first, committing the pending state and running
3094
- * useLayoutEffect (which updates the context store). The follow-up runAgent
3095
- * call then reads fresh context.
3096
- */
3097
- async waitForPendingFrameworkUpdates() {
3098
- await new Promise((resolve) => setTimeout(resolve, 0));
3099
- }
3100
- };
3101
-
3102
3200
  //#endregion
3103
3201
  //#region src/v2/providers/CopilotKitProvider.tsx
3104
3202
  const HEADER_NAME = "X-CopilotCloud-Public-Api-Key";
@@ -3114,12 +3212,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3114
3212
  - Minimal transitions (150ms) for hover/focus states only. No decorative animations.
3115
3213
  - Keep the UI focused and dense — avoid excessive padding. Use compact spacing (8–12px gaps, 10–14px padding in controls).`;
3116
3214
  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)";
3117
- const CopilotKitContext = (0, react.createContext)({
3118
- copilotkit: null,
3119
- executingToolCallIds: /* @__PURE__ */ new Set()
3120
- });
3121
- const LicenseContext = (0, react.createContext)((0, _copilotkit_shared.createLicenseContextValue)(null));
3122
- const useLicenseContext = () => (0, react.useContext)(LicenseContext);
3123
3215
  function useStableArrayProp(prop, warningMessage, isMeaningfulChange) {
3124
3216
  const empty = (0, react.useMemo)(() => [], []);
3125
3217
  const value = prop !== null && prop !== void 0 ? prop : empty;
@@ -3348,14 +3440,12 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3348
3440
  onErrorRef.current = onError;
3349
3441
  }, [onError]);
3350
3442
  (0, react.useEffect)(() => {
3351
- if (!onErrorRef.current) return;
3352
3443
  const subscription = copilotkit.subscribe({ onError: (event) => {
3353
- var _onErrorRef$current;
3354
- (_onErrorRef$current = onErrorRef.current) === null || _onErrorRef$current === void 0 || _onErrorRef$current.call(onErrorRef, {
3355
- error: event.error,
3356
- code: event.code,
3357
- context: event.context
3358
- });
3444
+ if (onErrorRef.current) onErrorRef.current(event);
3445
+ else {
3446
+ var _event$context;
3447
+ console.error(`[CopilotKit] Error (${event.code}):`, event.error, (_event$context = event.context) !== null && _event$context !== void 0 ? _event$context : {});
3448
+ }
3359
3449
  } });
3360
3450
  return () => {
3361
3451
  subscription.unsubscribe();
@@ -3410,318 +3500,66 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3410
3500
  value: designSkill
3411
3501
  });
3412
3502
  return () => {
3413
- copilotkit.removeContext(id);
3414
- };
3415
- }, [
3416
- copilotkit,
3417
- designSkill,
3418
- openGenUIActive
3419
- ]);
3420
- const sandboxFunctionsDescriptors = (0, react.useMemo)(() => {
3421
- if (sandboxFunctionsList.length === 0) return null;
3422
- return JSON.stringify(sandboxFunctionsList.map((fn) => ({
3423
- name: fn.name,
3424
- description: fn.description,
3425
- parameters: (0, _copilotkit_shared.schemaToJsonSchema)(fn.parameters, { zodToJsonSchema: zod_to_json_schema.zodToJsonSchema })
3426
- })));
3427
- }, [sandboxFunctionsList]);
3428
- (0, react.useLayoutEffect)(() => {
3429
- if (!copilotkit || !sandboxFunctionsDescriptors || !openGenUIActive) return;
3430
- const id = copilotkit.addContext({
3431
- description: "Sandbox functions available in generated sandboxed UI code. Call via: await Websandbox.connection.remote.<functionName>(args)",
3432
- value: sandboxFunctionsDescriptors
3433
- });
3434
- return () => {
3435
- copilotkit.removeContext(id);
3436
- };
3437
- }, [
3438
- copilotkit,
3439
- sandboxFunctionsDescriptors,
3440
- openGenUIActive
3441
- ]);
3442
- const contextValue = (0, react.useMemo)(() => ({
3443
- copilotkit,
3444
- executingToolCallIds
3445
- }), [copilotkit, executingToolCallIds]);
3446
- const licenseContextValue = (0, react.useMemo)(() => (0, _copilotkit_shared.createLicenseContextValue)(null), []);
3447
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SandboxFunctionsContext.Provider, {
3448
- value: sandboxFunctionsList,
3449
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitContext.Provider, {
3450
- value: contextValue,
3451
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(LicenseContext.Provider, {
3452
- value: licenseContextValue,
3453
- children: [
3454
- runtimeA2UIEnabled && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UIBuiltInToolCallRenderer, {}),
3455
- runtimeA2UIEnabled && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UICatalogContext, {
3456
- catalog: a2ui === null || a2ui === void 0 ? void 0 : a2ui.catalog,
3457
- includeSchema: a2ui === null || a2ui === void 0 ? void 0 : a2ui.includeSchema
3458
- }),
3459
- children,
3460
- shouldRenderInspector ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitInspector, {
3461
- core: copilotkit,
3462
- defaultAnchor: inspectorDefaultAnchor
3463
- }) : null,
3464
- runtimeLicenseStatus === "none" && !resolvedPublicKey && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "no_license" }),
3465
- runtimeLicenseStatus === "expired" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "expired" }),
3466
- runtimeLicenseStatus === "invalid" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "invalid" }),
3467
- runtimeLicenseStatus === "expiring" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "expiring" })
3468
- ]
3469
- })
3470
- })
3471
- });
3472
- };
3473
- const useCopilotKit = () => {
3474
- const context = (0, react.useContext)(CopilotKitContext);
3475
- const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
3476
- if (!context) throw new Error("useCopilotKit must be used within CopilotKitProvider");
3477
- (0, react.useEffect)(() => {
3478
- const subscription = context.copilotkit.subscribe({ onRuntimeConnectionStatusChanged: () => {
3479
- forceUpdate();
3480
- } });
3481
- return () => {
3482
- subscription.unsubscribe();
3483
- };
3484
- }, []);
3485
- return context;
3486
- };
3487
-
3488
- //#endregion
3489
- //#region src/v2/hooks/use-render-tool-call.tsx
3490
- /**
3491
- * Memoized component that renders a single tool call.
3492
- * This prevents unnecessary re-renders when parent components update
3493
- * but the tool call data hasn't changed.
3494
- */
3495
- const ToolCallRenderer = react.default.memo(function ToolCallRenderer({ toolCall, toolMessage, RenderComponent, isExecuting }) {
3496
- const args = (0, react.useMemo)(() => (0, _copilotkit_shared.partialJSONParse)(toolCall.function.arguments), [toolCall.function.arguments]);
3497
- const toolName = toolCall.function.name;
3498
- if (toolMessage) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
3499
- name: toolName,
3500
- toolCallId: toolCall.id,
3501
- args,
3502
- status: _copilotkit_core.ToolCallStatus.Complete,
3503
- result: toolMessage.content
3504
- });
3505
- else if (isExecuting) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
3506
- name: toolName,
3507
- toolCallId: toolCall.id,
3508
- args,
3509
- status: _copilotkit_core.ToolCallStatus.Executing,
3510
- result: void 0
3511
- });
3512
- else return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
3513
- name: toolName,
3514
- toolCallId: toolCall.id,
3515
- args,
3516
- status: _copilotkit_core.ToolCallStatus.InProgress,
3517
- result: void 0
3518
- });
3519
- }, (prevProps, nextProps) => {
3520
- var _prevProps$toolMessag, _nextProps$toolMessag;
3521
- if (prevProps.toolCall.id !== nextProps.toolCall.id) return false;
3522
- if (prevProps.toolCall.function.name !== nextProps.toolCall.function.name) return false;
3523
- if (prevProps.toolCall.function.arguments !== nextProps.toolCall.function.arguments) return false;
3524
- if (((_prevProps$toolMessag = prevProps.toolMessage) === null || _prevProps$toolMessag === void 0 ? void 0 : _prevProps$toolMessag.content) !== ((_nextProps$toolMessag = nextProps.toolMessage) === null || _nextProps$toolMessag === void 0 ? void 0 : _nextProps$toolMessag.content)) return false;
3525
- if (prevProps.isExecuting !== nextProps.isExecuting) return false;
3526
- if (prevProps.RenderComponent !== nextProps.RenderComponent) return false;
3527
- return true;
3528
- });
3529
- /**
3530
- * Hook that returns a function to render tool calls based on the render functions
3531
- * defined in CopilotKitProvider.
3532
- *
3533
- * @returns A function that takes a tool call and optional tool message and returns the rendered component
3534
- */
3535
- function useRenderToolCall() {
3536
- var _config$agentId;
3537
- const { copilotkit, executingToolCallIds } = useCopilotKit();
3538
- const config = useCopilotChatConfiguration();
3539
- const agentId = (_config$agentId = config === null || config === void 0 ? void 0 : config.agentId) !== null && _config$agentId !== void 0 ? _config$agentId : _copilotkit_shared.DEFAULT_AGENT_ID;
3540
- const renderToolCalls = (0, react.useSyncExternalStore)((callback) => {
3541
- return copilotkit.subscribe({ onRenderToolCallsChanged: callback }).unsubscribe;
3542
- }, () => copilotkit.renderToolCalls, () => copilotkit.renderToolCalls);
3543
- return (0, react.useCallback)(({ toolCall, toolMessage }) => {
3544
- const exactMatches = renderToolCalls.filter((rc) => rc.name === toolCall.function.name);
3545
- const renderConfig = exactMatches.find((rc) => rc.agentId === agentId) || exactMatches.find((rc) => !rc.agentId) || exactMatches[0] || renderToolCalls.find((rc) => rc.name === "*");
3546
- if (!renderConfig) return null;
3547
- const RenderComponent = renderConfig.render;
3548
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolCallRenderer, {
3549
- toolCall,
3550
- toolMessage,
3551
- RenderComponent,
3552
- isExecuting: executingToolCallIds.has(toolCall.id)
3553
- }, toolCall.id);
3554
- }, [
3555
- renderToolCalls,
3556
- executingToolCallIds,
3557
- agentId
3558
- ]);
3559
- }
3560
-
3561
- //#endregion
3562
- //#region src/v2/hooks/use-agent.tsx
3563
- let UseAgentUpdate = /* @__PURE__ */ function(UseAgentUpdate) {
3564
- UseAgentUpdate["OnMessagesChanged"] = "OnMessagesChanged";
3565
- UseAgentUpdate["OnStateChanged"] = "OnStateChanged";
3566
- UseAgentUpdate["OnRunStatusChanged"] = "OnRunStatusChanged";
3567
- return UseAgentUpdate;
3568
- }({});
3569
- const ALL_UPDATES = [
3570
- UseAgentUpdate.OnMessagesChanged,
3571
- UseAgentUpdate.OnStateChanged,
3572
- UseAgentUpdate.OnRunStatusChanged
3573
- ];
3574
- /**
3575
- * Clone a registry agent for per-thread isolation.
3576
- * Copies agent configuration (transport, headers, etc.) but resets conversation
3577
- * state (messages, threadId, state) so each thread starts fresh.
3578
- */
3579
- function cloneForThread(source, threadId, headers) {
3580
- const clone = source.clone();
3581
- if (clone === source) throw new Error(`useAgent: ${source.constructor.name}.clone() returned the same instance. clone() must return a new, independent object.`);
3582
- clone.threadId = threadId;
3583
- clone.setMessages([]);
3584
- clone.setState({});
3585
- if (clone instanceof _ag_ui_client.HttpAgent) clone.headers = { ...headers };
3586
- return clone;
3587
- }
3588
- /**
3589
- * Module-level WeakMap: registryAgent → (threadId → clone).
3590
- * Shared across all useAgent() calls so that every component using the same
3591
- * (agentId, threadId) pair receives the same agent instance. Using WeakMap
3592
- * ensures the clone map is garbage-collected when the registry agent is
3593
- * replaced (e.g. after reconnect or hot-reload).
3594
- */
3595
- const globalThreadCloneMap = /* @__PURE__ */ new WeakMap();
3596
- /**
3597
- * Look up an existing per-thread clone without creating one.
3598
- * Returns undefined when no clone has been created yet for this pair.
3599
- */
3600
- function getThreadClone(registryAgent, threadId) {
3601
- var _globalThreadCloneMap;
3602
- if (!registryAgent || !threadId) return void 0;
3603
- return (_globalThreadCloneMap = globalThreadCloneMap.get(registryAgent)) === null || _globalThreadCloneMap === void 0 ? void 0 : _globalThreadCloneMap.get(threadId);
3604
- }
3605
- function getOrCreateThreadClone(existing, threadId, headers) {
3606
- let byThread = globalThreadCloneMap.get(existing);
3607
- if (!byThread) {
3608
- byThread = /* @__PURE__ */ new Map();
3609
- globalThreadCloneMap.set(existing, byThread);
3610
- }
3611
- const cached = byThread.get(threadId);
3612
- if (cached) return cached;
3613
- const clone = cloneForThread(existing, threadId, headers);
3614
- byThread.set(threadId, clone);
3615
- return clone;
3616
- }
3617
- function useAgent({ agentId, threadId, updates, throttleMs } = {}) {
3618
- var _agentId, _threadId;
3619
- (_agentId = agentId) !== null && _agentId !== void 0 || (agentId = _copilotkit_shared.DEFAULT_AGENT_ID);
3620
- const { copilotkit } = useCopilotKit();
3621
- const providerThrottleMs = copilotkit.defaultThrottleMs;
3622
- const chatConfig = useCopilotChatConfiguration();
3623
- (_threadId = threadId) !== null && _threadId !== void 0 || (threadId = chatConfig === null || chatConfig === void 0 ? void 0 : chatConfig.threadId);
3624
- const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
3625
- const updateFlags = (0, react.useMemo)(() => updates !== null && updates !== void 0 ? updates : ALL_UPDATES, [JSON.stringify(updates)]);
3626
- const provisionalAgentCache = (0, react.useRef)(/* @__PURE__ */ new Map());
3627
- const agent = (0, react.useMemo)(() => {
3628
- var _copilotkit$agents;
3629
- const cacheKey = threadId ? `${agentId}:${threadId}` : agentId;
3630
- const existing = copilotkit.getAgent(agentId);
3631
- if (existing) {
3632
- provisionalAgentCache.current.delete(cacheKey);
3633
- provisionalAgentCache.current.delete(agentId);
3634
- if (!threadId) return existing;
3635
- return getOrCreateThreadClone(existing, threadId, copilotkit.headers);
3636
- }
3637
- const isRuntimeConfigured = copilotkit.runtimeUrl !== void 0;
3638
- const status = copilotkit.runtimeConnectionStatus;
3639
- if (isRuntimeConfigured && (status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Disconnected || status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Connecting)) {
3640
- const cached = provisionalAgentCache.current.get(cacheKey);
3641
- if (cached) {
3642
- cached.headers = { ...copilotkit.headers };
3643
- return cached;
3644
- }
3645
- const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
3646
- runtimeUrl: copilotkit.runtimeUrl,
3647
- agentId,
3648
- transport: copilotkit.runtimeTransport,
3649
- runtimeMode: "pending"
3650
- });
3651
- provisional.headers = { ...copilotkit.headers };
3652
- if (threadId) provisional.threadId = threadId;
3653
- provisionalAgentCache.current.set(cacheKey, provisional);
3654
- return provisional;
3655
- }
3656
- if (isRuntimeConfigured && status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Error) {
3657
- const cached = provisionalAgentCache.current.get(cacheKey);
3658
- if (cached) {
3659
- cached.headers = { ...copilotkit.headers };
3660
- return cached;
3661
- }
3662
- const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
3663
- runtimeUrl: copilotkit.runtimeUrl,
3664
- agentId,
3665
- transport: copilotkit.runtimeTransport,
3666
- runtimeMode: "pending"
3667
- });
3668
- provisional.headers = { ...copilotkit.headers };
3669
- if (threadId) provisional.threadId = threadId;
3670
- provisionalAgentCache.current.set(cacheKey, provisional);
3671
- return provisional;
3672
- }
3673
- const knownAgents = Object.keys((_copilotkit$agents = copilotkit.agents) !== null && _copilotkit$agents !== void 0 ? _copilotkit$agents : {});
3674
- const runtimePart = isRuntimeConfigured ? `runtimeUrl=${copilotkit.runtimeUrl}` : "no runtimeUrl";
3675
- throw new Error(`useAgent: Agent '${agentId}' not found after runtime sync (${runtimePart}). ` + (knownAgents.length ? `Known agents: [${knownAgents.join(", ")}]` : "No agents registered.") + " Verify your runtime /info and/or agents__unsafe_dev_only.");
3503
+ copilotkit.removeContext(id);
3504
+ };
3676
3505
  }, [
3677
- agentId,
3678
- threadId,
3679
- copilotkit.agents,
3680
- copilotkit.runtimeConnectionStatus,
3681
- copilotkit.runtimeUrl,
3682
- copilotkit.runtimeTransport,
3683
- JSON.stringify(copilotkit.headers)
3506
+ copilotkit,
3507
+ designSkill,
3508
+ openGenUIActive
3684
3509
  ]);
3685
- (0, react.useEffect)(() => {
3686
- if (updateFlags.length === 0) return;
3687
- let active = true;
3688
- const handlers = {};
3689
- let batchScheduled = false;
3690
- const batchedForceUpdate = () => {
3691
- if (!active) return;
3692
- if (!batchScheduled) {
3693
- batchScheduled = true;
3694
- queueMicrotask(() => {
3695
- batchScheduled = false;
3696
- if (active) forceUpdate();
3697
- });
3698
- }
3699
- };
3700
- if (updateFlags.includes(UseAgentUpdate.OnMessagesChanged)) handlers.onMessagesChanged = forceUpdate;
3701
- if (updateFlags.includes(UseAgentUpdate.OnStateChanged)) handlers.onStateChanged = batchedForceUpdate;
3702
- if (updateFlags.includes(UseAgentUpdate.OnRunStatusChanged)) {
3703
- handlers.onRunInitialized = batchedForceUpdate;
3704
- handlers.onRunFinalized = batchedForceUpdate;
3705
- handlers.onRunFailed = batchedForceUpdate;
3706
- handlers.onRunErrorEvent = batchedForceUpdate;
3707
- }
3708
- const subscription = copilotkit.subscribeToAgentWithOptions(agent, handlers, { throttleMs });
3510
+ const sandboxFunctionsDescriptors = (0, react.useMemo)(() => {
3511
+ if (sandboxFunctionsList.length === 0) return null;
3512
+ return JSON.stringify(sandboxFunctionsList.map((fn) => ({
3513
+ name: fn.name,
3514
+ description: fn.description,
3515
+ parameters: (0, _copilotkit_shared.schemaToJsonSchema)(fn.parameters, { zodToJsonSchema: zod_to_json_schema.zodToJsonSchema })
3516
+ })));
3517
+ }, [sandboxFunctionsList]);
3518
+ (0, react.useLayoutEffect)(() => {
3519
+ if (!copilotkit || !sandboxFunctionsDescriptors || !openGenUIActive) return;
3520
+ const id = copilotkit.addContext({
3521
+ description: "Sandbox functions available in generated sandboxed UI code. Call via: await Websandbox.connection.remote.<functionName>(args)",
3522
+ value: sandboxFunctionsDescriptors
3523
+ });
3709
3524
  return () => {
3710
- active = false;
3711
- subscription.unsubscribe();
3525
+ copilotkit.removeContext(id);
3712
3526
  };
3713
3527
  }, [
3714
- agent,
3715
- forceUpdate,
3716
- throttleMs,
3717
- providerThrottleMs,
3718
- updateFlags
3528
+ copilotkit,
3529
+ sandboxFunctionsDescriptors,
3530
+ openGenUIActive
3719
3531
  ]);
3720
- (0, react.useEffect)(() => {
3721
- if (agent instanceof _ag_ui_client.HttpAgent) agent.headers = { ...copilotkit.headers };
3722
- }, [agent, JSON.stringify(copilotkit.headers)]);
3723
- return { agent };
3724
- }
3532
+ const contextValue = (0, react.useMemo)(() => ({
3533
+ copilotkit,
3534
+ executingToolCallIds
3535
+ }), [copilotkit, executingToolCallIds]);
3536
+ const licenseContextValue = (0, react.useMemo)(() => (0, _copilotkit_shared.createLicenseContextValue)(null), []);
3537
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SandboxFunctionsContext.Provider, {
3538
+ value: sandboxFunctionsList,
3539
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitContext.Provider, {
3540
+ value: contextValue,
3541
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(LicenseContext.Provider, {
3542
+ value: licenseContextValue,
3543
+ children: [
3544
+ runtimeA2UIEnabled && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UIBuiltInToolCallRenderer, {}),
3545
+ runtimeA2UIEnabled && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UICatalogContext, {
3546
+ catalog: a2ui === null || a2ui === void 0 ? void 0 : a2ui.catalog,
3547
+ includeSchema: a2ui === null || a2ui === void 0 ? void 0 : a2ui.includeSchema
3548
+ }),
3549
+ children,
3550
+ shouldRenderInspector ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitInspector, {
3551
+ core: copilotkit,
3552
+ defaultAnchor: inspectorDefaultAnchor
3553
+ }) : null,
3554
+ runtimeLicenseStatus === "none" && !resolvedPublicKey && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "no_license" }),
3555
+ runtimeLicenseStatus === "expired" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "expired" }),
3556
+ runtimeLicenseStatus === "invalid" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "invalid" }),
3557
+ runtimeLicenseStatus === "expiring" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "expiring" })
3558
+ ]
3559
+ })
3560
+ })
3561
+ });
3562
+ };
3725
3563
 
3726
3564
  //#endregion
3727
3565
  //#region src/v2/hooks/use-render-custom-messages.tsx
@@ -3736,13 +3574,12 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3736
3574
  return aHasAgent ? -1 : 1;
3737
3575
  });
3738
3576
  return function(params) {
3739
- var _copilotkit$getRunIdF, _getThreadClone;
3577
+ var _copilotkit$getRunIdF;
3740
3578
  if (!customMessageRenderers.length) return null;
3741
3579
  const { message, position } = params;
3742
3580
  const resolvedRunId = (_copilotkit$getRunIdF = copilotkit.getRunIdForMessage(agentId, threadId, message.id)) !== null && _copilotkit$getRunIdF !== void 0 ? _copilotkit$getRunIdF : copilotkit.getRunIdsForThread(agentId, threadId).slice(-1)[0];
3743
3581
  const runId = resolvedRunId !== null && resolvedRunId !== void 0 ? resolvedRunId : `missing-run-id:${message.id}`;
3744
- const registryAgent = copilotkit.getAgent(agentId);
3745
- const agent = (_getThreadClone = getThreadClone(registryAgent, threadId)) !== null && _getThreadClone !== void 0 ? _getThreadClone : registryAgent;
3582
+ const agent = copilotkit.getAgent(agentId);
3746
3583
  if (!agent) return null;
3747
3584
  const messagesIdsInRun = resolvedRunId ? agent.messages.filter((msg) => copilotkit.getRunIdForMessage(agentId, threadId, msg.id) === resolvedRunId).map((msg) => msg.id) : [message.id];
3748
3585
  const rawMessageIndex = agent.messages.findIndex((msg) => msg.id === message.id);
@@ -3773,10 +3610,9 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3773
3610
  //#endregion
3774
3611
  //#region src/v2/hooks/use-render-activity-message.tsx
3775
3612
  function useRenderActivityMessage() {
3776
- var _config$agentId;
3613
+ var _useCopilotChatConfig, _useCopilotChatConfig2;
3777
3614
  const { copilotkit } = useCopilotKit();
3778
- const config = useCopilotChatConfiguration();
3779
- const agentId = (_config$agentId = config === null || config === void 0 ? void 0 : config.agentId) !== null && _config$agentId !== void 0 ? _config$agentId : _copilotkit_shared.DEFAULT_AGENT_ID;
3615
+ const agentId = (_useCopilotChatConfig = (_useCopilotChatConfig2 = useCopilotChatConfiguration()) === null || _useCopilotChatConfig2 === void 0 ? void 0 : _useCopilotChatConfig2.agentId) !== null && _useCopilotChatConfig !== void 0 ? _useCopilotChatConfig : _copilotkit_shared.DEFAULT_AGENT_ID;
3780
3616
  const renderers = copilotkit.renderActivityMessages;
3781
3617
  const findRenderer = (0, react.useCallback)((activityType) => {
3782
3618
  var _ref, _ref2, _matches$find;
@@ -3785,7 +3621,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3785
3621
  return (_ref = (_ref2 = (_matches$find = matches.find((candidate) => candidate.agentId === agentId)) !== null && _matches$find !== void 0 ? _matches$find : matches.find((candidate) => candidate.agentId === void 0)) !== null && _ref2 !== void 0 ? _ref2 : renderers.find((candidate) => candidate.activityType === "*")) !== null && _ref !== void 0 ? _ref : null;
3786
3622
  }, [agentId, renderers]);
3787
3623
  const renderActivityMessage = (0, react.useCallback)((message) => {
3788
- var _getThreadClone;
3789
3624
  const renderer = findRenderer(message.activityType);
3790
3625
  if (!renderer) return null;
3791
3626
  const parseResult = renderer.content.safeParse(message.content);
@@ -3794,8 +3629,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3794
3629
  return null;
3795
3630
  }
3796
3631
  const Component = renderer.render;
3797
- const registryAgent = copilotkit.getAgent(agentId);
3798
- const agent = (_getThreadClone = getThreadClone(registryAgent, config === null || config === void 0 ? void 0 : config.threadId)) !== null && _getThreadClone !== void 0 ? _getThreadClone : registryAgent;
3632
+ const agent = copilotkit.getAgent(agentId);
3799
3633
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Component, {
3800
3634
  activityType: message.activityType,
3801
3635
  content: parseResult.data,
@@ -3804,7 +3638,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3804
3638
  }, message.id);
3805
3639
  }, [
3806
3640
  agentId,
3807
- config === null || config === void 0 ? void 0 : config.threadId,
3808
3641
  copilotkit,
3809
3642
  findRenderer
3810
3643
  ]);
@@ -3843,8 +3676,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3843
3676
  tool.name,
3844
3677
  tool.available,
3845
3678
  copilotkit,
3846
- extraDeps.length,
3847
- ...extraDeps
3679
+ JSON.stringify(extraDeps)
3848
3680
  ]);
3849
3681
  }
3850
3682
 
@@ -3983,8 +3815,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3983
3815
  }, [
3984
3816
  config.name,
3985
3817
  copilotkit,
3986
- extraDeps.length,
3987
- ...extraDeps
3818
+ JSON.stringify(extraDeps)
3988
3819
  ]);
3989
3820
  }
3990
3821
 
@@ -4245,6 +4076,120 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
4245
4076
  ]);
4246
4077
  }
4247
4078
 
4079
+ //#endregion
4080
+ //#region src/v2/hooks/use-agent.tsx
4081
+ let UseAgentUpdate = /* @__PURE__ */ function(UseAgentUpdate) {
4082
+ UseAgentUpdate["OnMessagesChanged"] = "OnMessagesChanged";
4083
+ UseAgentUpdate["OnStateChanged"] = "OnStateChanged";
4084
+ UseAgentUpdate["OnRunStatusChanged"] = "OnRunStatusChanged";
4085
+ return UseAgentUpdate;
4086
+ }({});
4087
+ const ALL_UPDATES = [
4088
+ UseAgentUpdate.OnMessagesChanged,
4089
+ UseAgentUpdate.OnStateChanged,
4090
+ UseAgentUpdate.OnRunStatusChanged
4091
+ ];
4092
+ function useAgent({ agentId, updates, throttleMs } = {}) {
4093
+ var _agentId;
4094
+ (_agentId = agentId) !== null && _agentId !== void 0 || (agentId = _copilotkit_shared.DEFAULT_AGENT_ID);
4095
+ const { copilotkit } = useCopilotKit();
4096
+ const providerThrottleMs = copilotkit.defaultThrottleMs;
4097
+ const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
4098
+ const updateFlags = (0, react.useMemo)(() => updates !== null && updates !== void 0 ? updates : ALL_UPDATES, [JSON.stringify(updates)]);
4099
+ const provisionalAgentCache = (0, react.useRef)(/* @__PURE__ */ new Map());
4100
+ const agent = (0, react.useMemo)(() => {
4101
+ var _copilotkit$agents;
4102
+ const existing = copilotkit.getAgent(agentId);
4103
+ if (existing) {
4104
+ provisionalAgentCache.current.delete(agentId);
4105
+ return existing;
4106
+ }
4107
+ const isRuntimeConfigured = copilotkit.runtimeUrl !== void 0;
4108
+ const status = copilotkit.runtimeConnectionStatus;
4109
+ if (isRuntimeConfigured && (status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Disconnected || status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Connecting)) {
4110
+ const cached = provisionalAgentCache.current.get(agentId);
4111
+ if (cached) {
4112
+ cached.headers = { ...copilotkit.headers };
4113
+ return cached;
4114
+ }
4115
+ const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
4116
+ runtimeUrl: copilotkit.runtimeUrl,
4117
+ agentId,
4118
+ transport: copilotkit.runtimeTransport,
4119
+ runtimeMode: "pending"
4120
+ });
4121
+ provisional.headers = { ...copilotkit.headers };
4122
+ provisionalAgentCache.current.set(agentId, provisional);
4123
+ return provisional;
4124
+ }
4125
+ if (isRuntimeConfigured && status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Error) {
4126
+ const cached = provisionalAgentCache.current.get(agentId);
4127
+ if (cached) {
4128
+ cached.headers = { ...copilotkit.headers };
4129
+ return cached;
4130
+ }
4131
+ const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
4132
+ runtimeUrl: copilotkit.runtimeUrl,
4133
+ agentId,
4134
+ transport: copilotkit.runtimeTransport,
4135
+ runtimeMode: "pending"
4136
+ });
4137
+ provisional.headers = { ...copilotkit.headers };
4138
+ provisionalAgentCache.current.set(agentId, provisional);
4139
+ return provisional;
4140
+ }
4141
+ const knownAgents = Object.keys((_copilotkit$agents = copilotkit.agents) !== null && _copilotkit$agents !== void 0 ? _copilotkit$agents : {});
4142
+ const runtimePart = isRuntimeConfigured ? `runtimeUrl=${copilotkit.runtimeUrl}` : "no runtimeUrl";
4143
+ throw new Error(`useAgent: Agent '${agentId}' not found after runtime sync (${runtimePart}). ` + (knownAgents.length ? `Known agents: [${knownAgents.join(", ")}]` : "No agents registered.") + " Verify your runtime /info and/or agents__unsafe_dev_only.");
4144
+ }, [
4145
+ agentId,
4146
+ copilotkit.agents,
4147
+ copilotkit.runtimeConnectionStatus,
4148
+ copilotkit.runtimeUrl,
4149
+ copilotkit.runtimeTransport,
4150
+ JSON.stringify(copilotkit.headers)
4151
+ ]);
4152
+ (0, react.useEffect)(() => {
4153
+ if (updateFlags.length === 0) return;
4154
+ let active = true;
4155
+ const handlers = {};
4156
+ let batchScheduled = false;
4157
+ const batchedForceUpdate = () => {
4158
+ if (!active) return;
4159
+ if (!batchScheduled) {
4160
+ batchScheduled = true;
4161
+ queueMicrotask(() => {
4162
+ batchScheduled = false;
4163
+ if (active) forceUpdate();
4164
+ });
4165
+ }
4166
+ };
4167
+ if (updateFlags.includes(UseAgentUpdate.OnMessagesChanged)) handlers.onMessagesChanged = batchedForceUpdate;
4168
+ if (updateFlags.includes(UseAgentUpdate.OnStateChanged)) handlers.onStateChanged = batchedForceUpdate;
4169
+ if (updateFlags.includes(UseAgentUpdate.OnRunStatusChanged)) {
4170
+ handlers.onRunInitialized = batchedForceUpdate;
4171
+ handlers.onRunFinalized = batchedForceUpdate;
4172
+ handlers.onRunFailed = batchedForceUpdate;
4173
+ handlers.onRunErrorEvent = batchedForceUpdate;
4174
+ }
4175
+ const subscription = copilotkit.subscribeToAgentWithOptions(agent, handlers, { throttleMs });
4176
+ return () => {
4177
+ active = false;
4178
+ subscription.unsubscribe();
4179
+ };
4180
+ }, [
4181
+ agent,
4182
+ forceUpdate,
4183
+ throttleMs,
4184
+ providerThrottleMs,
4185
+ updateFlags
4186
+ ]);
4187
+ (0, react.useEffect)(() => {
4188
+ if (agent instanceof _ag_ui_client.HttpAgent) agent.headers = { ...copilotkit.headers };
4189
+ }, [agent, JSON.stringify(copilotkit.headers)]);
4190
+ return { agent };
4191
+ }
4192
+
4248
4193
  //#endregion
4249
4194
  //#region src/v2/hooks/use-capabilities.tsx
4250
4195
  /**
@@ -5753,6 +5698,199 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
5753
5698
  */
5754
5699
  const ScrollElementContext = react.default.createContext(null);
5755
5700
 
5701
+ //#endregion
5702
+ //#region src/v2/components/intelligence-indicator/IntelligenceIndicator.tsx
5703
+ /**
5704
+ * Grace window before showing the spinner. A matching tool call must
5705
+ * remain unresolved (no `tool`-role result message in `agent.messages`)
5706
+ * for at least this long before the pill appears. This filters out
5707
+ * history-replay flashes — during `connectAgent` replay, tool calls and
5708
+ * their results arrive back-to-back in sub-millisecond bursts, so the
5709
+ * timer is cancelled before it fires. Live runs cross the threshold
5710
+ * easily because the tool actually has to execute.
5711
+ */
5712
+ const PENDING_THRESHOLD_MS = 100;
5713
+ /** Hold the checkmark briefly before fading out. */
5714
+ const CHECK_HOLD_MS = 800;
5715
+ /**
5716
+ * Duration of the fade-out animation. Must match
5717
+ * `cpk-intelligence-pill-fade-out` keyframes in `v2/styles/globals.css`.
5718
+ */
5719
+ const FADE_OUT_ANIMATION_MS = 480;
5720
+ /**
5721
+ * Tool-name regex patterns that trigger the indicator. Currently
5722
+ * hardcoded to the Intelligence MCP server's canonical tool name. If
5723
+ * we add per-instance customization later (e.g. a `CopilotKitProvider`
5724
+ * prop or a runtime-info field), this constant becomes the fallback.
5725
+ */
5726
+ const DEFAULT_TOOL_PATTERNS = [/^copilotkit_knowledge_base_shell$/];
5727
+ const isMatchingToolCallName = (name) => typeof name === "string" && DEFAULT_TOOL_PATTERNS.some((p) => p.test(name));
5728
+ /**
5729
+ * "Tool-call-like" messages do NOT count as a real follow-up: tool
5730
+ * result messages, assistant messages that carry tool calls, and
5731
+ * empty-content assistant messages (which some providers emit as a
5732
+ * standalone wrapper around a batch of tool calls). A real follow-up
5733
+ * is anything else — most importantly an assistant message with prose
5734
+ * content, or a fresh user message.
5735
+ */
5736
+ const isToolCallLikeMessage = (m) => {
5737
+ if (m.role === "tool") return true;
5738
+ if (m.role === "assistant") {
5739
+ if ((Array.isArray(m.toolCalls) ? m.toolCalls : []).length > 0) return true;
5740
+ const content = m.content;
5741
+ return typeof content !== "string" || content.trim().length === 0;
5742
+ }
5743
+ return false;
5744
+ };
5745
+ /**
5746
+ * The "Using CopilotKit Intelligence" pill. Auto-mounted by
5747
+ * `CopilotChatMessageView` for every message slot when
5748
+ * `copilotkit.intelligence` is configured — callers do not register
5749
+ * this themselves. Self-gates so only the canonical message renders a
5750
+ * pill.
5751
+ *
5752
+ * Render gates (all must hold):
5753
+ * 1. `copilotkit.intelligence !== undefined`
5754
+ * 2. The message is an assistant message with at least one tool call
5755
+ * whose name matches {@link DEFAULT_TOOL_PATTERNS}
5756
+ * 3. The message is the *latest* such matching-assistant message in
5757
+ * `agent.messages` — tool-result messages and prose-only assistant
5758
+ * messages don't invalidate the slot, so the pill stays
5759
+ * continuously through a multi-step tool chain.
5760
+ * 4. The phase machine is past `idle` (the pending-grace timer fired)
5761
+ * and not yet `hidden`.
5762
+ *
5763
+ * Phase machine (per-instance, all timers local):
5764
+ * - Starts in `idle` — nothing rendered.
5765
+ * - `idle → spinner` once a matching tool call has been pending
5766
+ * (no `tool`-role result with a matching `toolCallId`) for
5767
+ * {@link PENDING_THRESHOLD_MS}. Replay flashes (tool call + result
5768
+ * in the same tick) never cross this threshold.
5769
+ * - `spinner → check` as soon as EITHER `agent.isRunning` flips
5770
+ * false OR a non-tool-call-like message appears later in
5771
+ * `agent.messages` (i.e. the agent has produced a "real"
5772
+ * follow-up — prose answer or a new user turn).
5773
+ * - `check → fading` after {@link CHECK_HOLD_MS}.
5774
+ * - `fading → hidden` after {@link FADE_OUT_ANIMATION_MS}.
5775
+ *
5776
+ * Once `hidden`, the phase is sticky — a finished pill never re-spawns
5777
+ * on the same message. New runs mount fresh indicator instances on
5778
+ * their own assistant messages.
5779
+ *
5780
+ * The "exactly one pill at a time" guarantee is structural: only one
5781
+ * message satisfies the latest-matching-assistant gate at any moment.
5782
+ */
5783
+ function IntelligenceIndicator(props) {
5784
+ const { message, agentId, label = "Using CopilotKit Intelligence" } = props;
5785
+ const { copilotkit } = useCopilotKit();
5786
+ const config = useCopilotChatConfiguration();
5787
+ const { agent } = useAgent({
5788
+ agentId,
5789
+ updates: [UseAgentUpdate.OnRunStatusChanged, UseAgentUpdate.OnMessagesChanged]
5790
+ });
5791
+ const matchingToolCallIds = (0, react.useMemo)(() => {
5792
+ if (message.role !== "assistant") return [];
5793
+ const tcs = Array.isArray(message.toolCalls) ? message.toolCalls : [];
5794
+ const ids = [];
5795
+ for (const tc of tcs) {
5796
+ var _tc$function;
5797
+ if (isMatchingToolCallName(tc === null || tc === void 0 || (_tc$function = tc.function) === null || _tc$function === void 0 ? void 0 : _tc$function.name) && (tc === null || tc === void 0 ? void 0 : tc.id)) ids.push(tc.id);
5798
+ }
5799
+ return ids;
5800
+ }, [message]);
5801
+ const hasPending = (0, react.useMemo)(() => {
5802
+ if (matchingToolCallIds.length === 0) return false;
5803
+ const resolved = /* @__PURE__ */ new Set();
5804
+ for (const m of agent.messages) if (m.role === "tool" && m.toolCallId) resolved.add(m.toolCallId);
5805
+ return matchingToolCallIds.some((id) => !resolved.has(id));
5806
+ }, [matchingToolCallIds, agent.messages]);
5807
+ const sawRealFollowup = (0, react.useMemo)(() => {
5808
+ const idx = agent.messages.findIndex((m) => m.id === message.id);
5809
+ if (idx < 0) return false;
5810
+ for (let i = idx + 1; i < agent.messages.length; i += 1) if (!isToolCallLikeMessage(agent.messages[i])) return true;
5811
+ return false;
5812
+ }, [agent.messages, message.id]);
5813
+ const [phase, setPhase] = (0, react.useState)("idle");
5814
+ (0, react.useEffect)(() => {
5815
+ if (phase !== "idle") return void 0;
5816
+ if (!hasPending) return void 0;
5817
+ const t = setTimeout(() => setPhase("spinner"), PENDING_THRESHOLD_MS);
5818
+ return () => clearTimeout(t);
5819
+ }, [phase, hasPending]);
5820
+ (0, react.useEffect)(() => {
5821
+ if (phase !== "spinner") return void 0;
5822
+ if (!agent.isRunning || sawRealFollowup) setPhase("check");
5823
+ }, [
5824
+ phase,
5825
+ agent.isRunning,
5826
+ sawRealFollowup
5827
+ ]);
5828
+ (0, react.useEffect)(() => {
5829
+ if (phase !== "check") return void 0;
5830
+ const t = setTimeout(() => setPhase("fading"), CHECK_HOLD_MS);
5831
+ return () => clearTimeout(t);
5832
+ }, [phase]);
5833
+ (0, react.useEffect)(() => {
5834
+ if (phase !== "fading") return void 0;
5835
+ const t = setTimeout(() => setPhase("hidden"), FADE_OUT_ANIMATION_MS);
5836
+ return () => clearTimeout(t);
5837
+ }, [phase]);
5838
+ if (copilotkit.intelligence === void 0) return null;
5839
+ if (!config) return null;
5840
+ if (phase === "idle" || phase === "hidden") return null;
5841
+ if (message.role !== "assistant") return null;
5842
+ if (!(Array.isArray(message.toolCalls) ? message.toolCalls : []).some((tc) => {
5843
+ var _tc$function2;
5844
+ return isMatchingToolCallName(tc === null || tc === void 0 || (_tc$function2 = tc.function) === null || _tc$function2 === void 0 ? void 0 : _tc$function2.name);
5845
+ })) return null;
5846
+ let latestMatchingAssistantId;
5847
+ for (let i = agent.messages.length - 1; i >= 0; i -= 1) {
5848
+ const m = agent.messages[i];
5849
+ if (m.role !== "assistant") continue;
5850
+ if ((Array.isArray(m.toolCalls) ? m.toolCalls : []).some((tc) => {
5851
+ var _tc$function3;
5852
+ return isMatchingToolCallName(tc === null || tc === void 0 || (_tc$function3 = tc.function) === null || _tc$function3 === void 0 ? void 0 : _tc$function3.name);
5853
+ })) {
5854
+ latestMatchingAssistantId = m.id;
5855
+ break;
5856
+ }
5857
+ }
5858
+ if (latestMatchingAssistantId !== message.id) return null;
5859
+ const showSpinner = phase === "spinner";
5860
+ const isFading = phase === "fading";
5861
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
5862
+ className: "cpk-intelligence-pill" + (isFading ? " cpk-intelligence-pill--fading" : ""),
5863
+ role: "status",
5864
+ "aria-live": "polite",
5865
+ "aria-hidden": isFading || void 0,
5866
+ "data-testid": `cpk-intelligence-pill-${message.id}`,
5867
+ title: label,
5868
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
5869
+ className: "cpk-intelligence-pill__icon",
5870
+ viewBox: "0 0 24 24",
5871
+ width: "14",
5872
+ height: "14",
5873
+ "aria-hidden": "true",
5874
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
5875
+ cx: "12",
5876
+ cy: "12",
5877
+ r: "9",
5878
+ fill: "none",
5879
+ strokeWidth: "2.5",
5880
+ strokeLinecap: "round",
5881
+ className: "cpk-intelligence-pill__ring" + (showSpinner ? "" : " cpk-intelligence-pill__ring--done")
5882
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
5883
+ d: "M8 12.5l3 3 5-6",
5884
+ fill: "none",
5885
+ strokeWidth: "2.5",
5886
+ strokeLinecap: "round",
5887
+ strokeLinejoin: "round",
5888
+ className: "cpk-intelligence-pill__check" + (showSpinner ? "" : " cpk-intelligence-pill__check--shown")
5889
+ })]
5890
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: label })]
5891
+ });
5892
+ }
5893
+
5756
5894
  //#endregion
5757
5895
  //#region src/v2/components/chat/CopilotChatMessageView.tsx
5758
5896
  /**
@@ -5913,16 +6051,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
5913
6051
  const config = useCopilotChatConfiguration();
5914
6052
  const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
5915
6053
  (0, react.useEffect)(() => {
5916
- var _getThreadClone;
5917
6054
  if (!(config === null || config === void 0 ? void 0 : config.agentId)) return;
5918
- const registryAgent = copilotkit.getAgent(config.agentId);
5919
- const agent = (_getThreadClone = getThreadClone(registryAgent, config.threadId)) !== null && _getThreadClone !== void 0 ? _getThreadClone : registryAgent;
6055
+ const agent = copilotkit.getAgent(config.agentId);
5920
6056
  if (!agent) return;
5921
6057
  const subscription = agent.subscribe({ onStateChanged: forceUpdate });
5922
6058
  return () => subscription.unsubscribe();
5923
6059
  }, [
5924
6060
  config === null || config === void 0 ? void 0 : config.agentId,
5925
- config === null || config === void 0 ? void 0 : config.threadId,
5926
6061
  copilotkit,
5927
6062
  forceUpdate
5928
6063
  ]);
@@ -6008,6 +6143,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6008
6143
  renderCustomMessage,
6009
6144
  stateSnapshot
6010
6145
  }, `${message.id}-custom-after`));
6146
+ if (copilotkit.intelligence !== void 0 && message.role === "assistant") {
6147
+ var _config$agentId;
6148
+ elements.push(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(IntelligenceIndicator, {
6149
+ message,
6150
+ agentId: (_config$agentId = config === null || config === void 0 ? void 0 : config.agentId) !== null && _config$agentId !== void 0 ? _config$agentId : _copilotkit_shared.DEFAULT_AGENT_ID
6151
+ }, `${message.id}-intelligence`));
6152
+ }
6011
6153
  return elements.filter(Boolean);
6012
6154
  };
6013
6155
  const messageElements = shouldVirtualize ? [] : deduplicatedMessages.flatMap(renderMessageBlock);
@@ -6961,7 +7103,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6961
7103
  const hasExplicitThreadId = !!threadId || !!(existingConfig === null || existingConfig === void 0 ? void 0 : existingConfig.hasExplicitThreadId);
6962
7104
  const { agent } = useAgent({
6963
7105
  agentId: resolvedAgentId,
6964
- threadId: resolvedThreadId,
6965
7106
  throttleMs
6966
7107
  });
6967
7108
  const { copilotkit } = useCopilotKit();
@@ -7007,6 +7148,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
7007
7148
  let detached = false;
7008
7149
  const connectAbortController = new AbortController();
7009
7150
  if (agent instanceof _ag_ui_client.HttpAgent) agent.abortController = connectAbortController;
7151
+ agent.threadId = resolvedThreadId;
7010
7152
  const connect = async (agent) => {
7011
7153
  try {
7012
7154
  await copilotkit.connectAgent({ agent });
@@ -9922,6 +10064,7 @@ Object.defineProperty(exports, 'CopilotSidebarView', {
9922
10064
  return CopilotSidebarView;
9923
10065
  }
9924
10066
  });
10067
+ exports.IntelligenceIndicator = IntelligenceIndicator;
9925
10068
  exports.MCPAppsActivityContentSchema = MCPAppsActivityContentSchema;
9926
10069
  exports.MCPAppsActivityRenderer = MCPAppsActivityRenderer;
9927
10070
  exports.MCPAppsActivityType = MCPAppsActivityType;