@copilotkit/react-core 1.50.0-beta.0 → 1.50.0-beta.2

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 (141) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/{chunk-IUSKVYUI.mjs → chunk-2CYJN455.mjs} +2 -1
  3. package/dist/{chunk-IUSKVYUI.mjs.map → chunk-2CYJN455.mjs.map} +1 -1
  4. package/dist/{chunk-UJBV5GAG.mjs → chunk-6F7Q6CPI.mjs} +17 -36
  5. package/dist/chunk-6F7Q6CPI.mjs.map +1 -0
  6. package/dist/{chunk-JRT5BJF3.mjs → chunk-6SK26J65.mjs} +2 -2
  7. package/dist/{chunk-3GURHDG7.mjs → chunk-BPJ6V4YX.mjs} +2 -2
  8. package/dist/{chunk-TXI72QHK.mjs → chunk-EG56H77V.mjs} +2 -2
  9. package/dist/{chunk-3R423LZT.mjs → chunk-EHXVGFWN.mjs} +2 -2
  10. package/dist/{chunk-CB7CRBDG.mjs → chunk-FBVI3LQ6.mjs} +11 -11
  11. package/dist/chunk-FBVI3LQ6.mjs.map +1 -0
  12. package/dist/chunk-I76HKHPJ.mjs +32 -0
  13. package/dist/chunk-I76HKHPJ.mjs.map +1 -0
  14. package/dist/{chunk-R4MR43UQ.mjs → chunk-ISNVEPPQ.mjs} +17 -3
  15. package/dist/chunk-ISNVEPPQ.mjs.map +1 -0
  16. package/dist/{chunk-FBD24VEH.mjs → chunk-LD3MGPZB.mjs} +1 -1
  17. package/dist/{chunk-FBD24VEH.mjs.map → chunk-LD3MGPZB.mjs.map} +1 -1
  18. package/dist/{chunk-GMI4KO4X.mjs → chunk-OAEX7G5G.mjs} +2 -2
  19. package/dist/{chunk-DCHSCK62.mjs → chunk-SD7TUPQM.mjs} +13 -14
  20. package/dist/chunk-SD7TUPQM.mjs.map +1 -0
  21. package/dist/{chunk-NG26QEGF.mjs → chunk-T2VBHAAP.mjs} +9 -3
  22. package/dist/chunk-T2VBHAAP.mjs.map +1 -0
  23. package/dist/{chunk-NROJOTQP.mjs → chunk-TGIWTM6S.mjs} +8 -5
  24. package/dist/chunk-TGIWTM6S.mjs.map +1 -0
  25. package/dist/{chunk-QU6NONOD.mjs → chunk-U2ZRVVKT.mjs} +2 -2
  26. package/dist/{chunk-5X5DJRQQ.mjs → chunk-WF65O6HX.mjs} +2 -7
  27. package/dist/chunk-WF65O6HX.mjs.map +1 -0
  28. package/dist/{chunk-24SCZAB4.mjs → chunk-ZYTXB6HH.mjs} +22 -14
  29. package/dist/chunk-ZYTXB6HH.mjs.map +1 -0
  30. package/dist/components/CopilotListeners.js +13 -146
  31. package/dist/components/CopilotListeners.js.map +1 -1
  32. package/dist/components/CopilotListeners.mjs +1 -6
  33. package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
  34. package/dist/components/copilot-provider/copilot-messages.mjs +1 -1
  35. package/dist/components/copilot-provider/copilotkit-props.d.ts +1 -1
  36. package/dist/components/copilot-provider/copilotkit.d.ts +1 -1
  37. package/dist/components/copilot-provider/copilotkit.js +11 -11
  38. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  39. package/dist/components/copilot-provider/copilotkit.mjs +6 -6
  40. package/dist/components/copilot-provider/index.d.ts +1 -1
  41. package/dist/components/copilot-provider/index.js +11 -11
  42. package/dist/components/copilot-provider/index.js.map +1 -1
  43. package/dist/components/copilot-provider/index.mjs +6 -6
  44. package/dist/components/index.d.ts +1 -1
  45. package/dist/components/index.js +11 -11
  46. package/dist/components/index.js.map +1 -1
  47. package/dist/components/index.mjs +6 -6
  48. package/dist/context/copilot-context.d.ts +1 -1
  49. package/dist/context/index.d.ts +1 -1
  50. package/dist/{copilot-context-1cd70a3f.d.ts → copilot-context-81022020.d.ts} +1 -1
  51. package/dist/hooks/index.d.ts +1 -1
  52. package/dist/hooks/index.js +187 -155
  53. package/dist/hooks/index.js.map +1 -1
  54. package/dist/hooks/index.mjs +24 -23
  55. package/dist/hooks/use-agent-nodename.d.ts +3 -0
  56. package/dist/hooks/use-agent-nodename.js +56 -0
  57. package/dist/hooks/use-agent-nodename.js.map +1 -0
  58. package/dist/hooks/use-agent-nodename.mjs +8 -0
  59. package/dist/hooks/use-agent-nodename.mjs.map +1 -0
  60. package/dist/hooks/use-coagent-state-render-bridge.js +7 -4
  61. package/dist/hooks/use-coagent-state-render-bridge.js.map +1 -1
  62. package/dist/hooks/use-coagent-state-render-bridge.mjs +1 -1
  63. package/dist/hooks/use-coagent.js +58 -21
  64. package/dist/hooks/use-coagent.js.map +1 -1
  65. package/dist/hooks/use-coagent.mjs +2 -1
  66. package/dist/hooks/use-configure-chat-suggestions.js +13 -144
  67. package/dist/hooks/use-configure-chat-suggestions.js.map +1 -1
  68. package/dist/hooks/use-configure-chat-suggestions.mjs +1 -6
  69. package/dist/hooks/use-copilot-action.js +5 -1
  70. package/dist/hooks/use-copilot-action.js.map +1 -1
  71. package/dist/hooks/use-copilot-action.mjs +2 -2
  72. package/dist/hooks/use-copilot-authenticated-action.js +5 -1
  73. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
  74. package/dist/hooks/use-copilot-authenticated-action.mjs +3 -3
  75. package/dist/hooks/use-copilot-chat-headless_c.js +107 -84
  76. package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -1
  77. package/dist/hooks/use-copilot-chat-headless_c.mjs +6 -5
  78. package/dist/hooks/use-copilot-chat.js +105 -82
  79. package/dist/hooks/use-copilot-chat.js.map +1 -1
  80. package/dist/hooks/use-copilot-chat.mjs +6 -5
  81. package/dist/hooks/use-copilot-chat_internal.d.ts +1 -1
  82. package/dist/hooks/use-copilot-chat_internal.js +105 -82
  83. package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
  84. package/dist/hooks/use-copilot-chat_internal.mjs +5 -4
  85. package/dist/hooks/use-copilot-readable.d.ts +1 -1
  86. package/dist/hooks/use-copilot-readable.js +1 -0
  87. package/dist/hooks/use-copilot-readable.js.map +1 -1
  88. package/dist/hooks/use-copilot-readable.mjs +1 -1
  89. package/dist/hooks/use-default-tool.js +5 -1
  90. package/dist/hooks/use-default-tool.js.map +1 -1
  91. package/dist/hooks/use-default-tool.mjs +3 -3
  92. package/dist/hooks/use-frontend-tool.js +5 -1
  93. package/dist/hooks/use-frontend-tool.js.map +1 -1
  94. package/dist/hooks/use-frontend-tool.mjs +1 -1
  95. package/dist/hooks/use-langgraph-interrupt-render.js +61 -7
  96. package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
  97. package/dist/hooks/use-langgraph-interrupt-render.mjs +2 -1
  98. package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
  99. package/dist/index.d.ts +1 -1
  100. package/dist/index.js +184 -155
  101. package/dist/index.js.map +1 -1
  102. package/dist/index.mjs +31 -30
  103. package/dist/lib/copilot-task.d.ts +1 -1
  104. package/dist/lib/copilot-task.js.map +1 -1
  105. package/dist/lib/copilot-task.mjs +7 -7
  106. package/dist/lib/index.d.ts +1 -1
  107. package/dist/lib/index.js.map +1 -1
  108. package/dist/lib/index.mjs +7 -7
  109. package/dist/types/index.d.ts +1 -1
  110. package/dist/types/index.mjs +1 -1
  111. package/dist/types/interrupt-action.d.ts +1 -1
  112. package/dist/types/interrupt-action.js.map +1 -1
  113. package/jest.config.js +12 -0
  114. package/package.json +22 -21
  115. package/src/components/CopilotListeners.tsx +1 -2
  116. package/src/components/copilot-provider/copilot-messages.tsx +0 -41
  117. package/src/components/copilot-provider/copilotkit.tsx +2 -2
  118. package/src/hooks/__tests__/use-coagent-config.test.ts +189 -129
  119. package/src/hooks/use-agent-nodename.ts +30 -0
  120. package/src/hooks/use-coagent-state-render-bridge.tsx +20 -20
  121. package/src/hooks/use-coagent.ts +22 -13
  122. package/src/hooks/use-configure-chat-suggestions.tsx +8 -7
  123. package/src/hooks/use-copilot-chat_internal.ts +44 -42
  124. package/src/hooks/use-copilot-readable.ts +2 -1
  125. package/src/hooks/use-frontend-tool.ts +10 -2
  126. package/src/hooks/use-langgraph-interrupt-render.ts +10 -2
  127. package/src/types/interrupt-action.ts +1 -1
  128. package/dist/chunk-24SCZAB4.mjs.map +0 -1
  129. package/dist/chunk-5X5DJRQQ.mjs.map +0 -1
  130. package/dist/chunk-CB7CRBDG.mjs.map +0 -1
  131. package/dist/chunk-DCHSCK62.mjs.map +0 -1
  132. package/dist/chunk-NG26QEGF.mjs.map +0 -1
  133. package/dist/chunk-NROJOTQP.mjs.map +0 -1
  134. package/dist/chunk-R4MR43UQ.mjs.map +0 -1
  135. package/dist/chunk-UJBV5GAG.mjs.map +0 -1
  136. /package/dist/{chunk-JRT5BJF3.mjs.map → chunk-6SK26J65.mjs.map} +0 -0
  137. /package/dist/{chunk-3GURHDG7.mjs.map → chunk-BPJ6V4YX.mjs.map} +0 -0
  138. /package/dist/{chunk-TXI72QHK.mjs.map → chunk-EG56H77V.mjs.map} +0 -0
  139. /package/dist/{chunk-3R423LZT.mjs.map → chunk-EHXVGFWN.mjs.map} +0 -0
  140. /package/dist/{chunk-GMI4KO4X.mjs.map → chunk-OAEX7G5G.mjs.map} +0 -0
  141. /package/dist/{chunk-QU6NONOD.mjs.map → chunk-U2ZRVVKT.mjs.map} +0 -0
@@ -102,7 +102,7 @@ __export(hooks_exports, {
102
102
  module.exports = __toCommonJS(hooks_exports);
103
103
 
104
104
  // src/hooks/use-copilot-chat_internal.ts
105
- var import_react12 = require("react");
105
+ var import_react15 = require("react");
106
106
 
107
107
  // src/context/copilot-context.tsx
108
108
  var import_react = __toESM(require("react"));
@@ -351,13 +351,45 @@ function useCoAgentStateRenders() {
351
351
  }
352
352
 
353
353
  // src/hooks/use-langgraph-interrupt-render.ts
354
- var import_react5 = __toESM(require("react"));
354
+ var import_react7 = __toESM(require("react"));
355
355
  var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
356
356
  var import_shared2 = require("@copilotkit/shared");
357
+
358
+ // src/hooks/use-agent-nodename.ts
359
+ var import_react5 = require("react");
360
+ var import_react6 = require("@copilotkitnext/react");
361
+ function useAgentNodeName(agentName) {
362
+ const { agent } = (0, import_react6.useAgent)({ agentId: agentName });
363
+ const nodeNameRef = (0, import_react5.useRef)("start");
364
+ (0, import_react5.useEffect)(() => {
365
+ if (!agent)
366
+ return;
367
+ const subscriber = {
368
+ onStepStartedEvent: ({ event }) => {
369
+ nodeNameRef.current = event.stepName;
370
+ },
371
+ onRunStartedEvent: () => {
372
+ nodeNameRef.current = "start";
373
+ },
374
+ onRunFinishedEvent: () => {
375
+ nodeNameRef.current = "end";
376
+ }
377
+ };
378
+ const subscription = agent.subscribe(subscriber);
379
+ return () => {
380
+ subscription.unsubscribe();
381
+ };
382
+ }, [agent]);
383
+ return nodeNameRef.current;
384
+ }
385
+
386
+ // src/hooks/use-langgraph-interrupt-render.ts
387
+ var import_react8 = require("@copilotkitnext/react");
357
388
  var InterruptRenderer = ({ event, result, render, resolve }) => {
358
389
  return render({ event, result, resolve });
359
390
  };
360
391
  function useLangGraphInterruptRender(agent) {
392
+ var _a;
361
393
  const {
362
394
  interruptActions,
363
395
  agentSession,
@@ -366,7 +398,10 @@ function useLangGraphInterruptRender(agent) {
366
398
  addInterruptEvent,
367
399
  removeInterruptEvent
368
400
  } = useCopilotContext();
369
- (0, import_react5.useEffect)(() => {
401
+ const existingConfig = (0, import_react8.useCopilotChatConfiguration)();
402
+ const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
403
+ const nodeName = useAgentNodeName(resolvedAgentId);
404
+ (0, import_react7.useEffect)(() => {
370
405
  if (!agent)
371
406
  return;
372
407
  const subscriber = {
@@ -391,7 +426,7 @@ function useLangGraphInterruptRender(agent) {
391
426
  unsubscribe();
392
427
  };
393
428
  }, [agent, threadId]);
394
- const handleResolve = (0, import_react5.useCallback)(
429
+ const handleResolve = (0, import_react7.useCallback)(
395
430
  (eventId, response) => {
396
431
  agent == null ? void 0 : agent.runAgent({
397
432
  forwardedProps: {
@@ -405,10 +440,10 @@ function useLangGraphInterruptRender(agent) {
405
440
  // eslint-disable-next-line react-hooks/exhaustive-deps
406
441
  [agent, threadId]
407
442
  );
408
- return (0, import_react5.useMemo)(() => {
443
+ return (0, import_react7.useMemo)(() => {
409
444
  const eventQueue = interruptEventQueue[threadId] || [];
410
445
  const currentQueuedEvent = eventQueue.find((qe) => !qe.event.response);
411
- if (!currentQueuedEvent)
446
+ if (!currentQueuedEvent || !agentSession)
412
447
  return null;
413
448
  const allActions = Object.values(interruptActions);
414
449
  const matchingAction = allActions.find((action) => {
@@ -416,7 +451,9 @@ function useLangGraphInterruptRender(agent) {
416
451
  return true;
417
452
  return action.enabled({
418
453
  eventValue: currentQueuedEvent.event.value,
419
- agentMetadata: agentSession
454
+ agentMetadata: __spreadProps(__spreadValues({}, agentSession), {
455
+ nodeName
456
+ })
420
457
  });
421
458
  });
422
459
  if (!matchingAction)
@@ -434,7 +471,7 @@ function useLangGraphInterruptRender(agent) {
434
471
  }
435
472
  if (!render)
436
473
  return null;
437
- return import_react5.default.createElement(InterruptRenderer, {
474
+ return import_react7.default.createElement(InterruptRenderer, {
438
475
  event: currentQueuedEvent.event,
439
476
  result,
440
477
  render,
@@ -444,14 +481,14 @@ function useLangGraphInterruptRender(agent) {
444
481
  }
445
482
 
446
483
  // src/hooks/use-copilot-chat_internal.ts
447
- var import_react13 = require("@copilotkitnext/react");
484
+ var import_react16 = require("@copilotkitnext/react");
448
485
 
449
486
  // src/hooks/use-lazy-tool-renderer.tsx
450
- var import_react6 = require("@copilotkitnext/react");
451
- var import_react7 = require("react");
487
+ var import_react9 = require("@copilotkitnext/react");
488
+ var import_react10 = require("react");
452
489
  function useLazyToolRenderer() {
453
- const renderToolCall = (0, import_react6.useRenderToolCall)();
454
- return (0, import_react7.useCallback)(
490
+ const renderToolCall = (0, import_react9.useRenderToolCall)();
491
+ return (0, import_react10.useCallback)(
455
492
  (message, messages) => {
456
493
  var _a;
457
494
  if (!((_a = message == null ? void 0 : message.toolCalls) == null ? void 0 : _a.length))
@@ -472,34 +509,36 @@ function useLazyToolRenderer() {
472
509
  }
473
510
 
474
511
  // src/hooks/use-configure-chat-suggestions.tsx
475
- var import_react8 = require("@copilotkitnext/react");
476
- var import_react9 = require("react");
512
+ var import_react11 = require("@copilotkitnext/react");
513
+ var import_react12 = require("react");
477
514
  function useConfigureChatSuggestions(config, dependencies = []) {
478
- const { agentSession } = useCopilotContext();
479
- const { copilotkit } = (0, import_react8.useCopilotKit)();
515
+ var _a;
516
+ const existingConfig = (0, import_react11.useCopilotChatConfiguration)();
517
+ const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
518
+ const { copilotkit } = (0, import_react11.useCopilotKit)();
480
519
  const available = config.available === "enabled" ? "always" : config.available;
481
520
  const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
482
521
  available,
483
- consumerAgentId: agentSession == null ? void 0 : agentSession.agentName
522
+ consumerAgentId: resolvedAgentId
484
523
  // Use chatConfig.agentId here
485
524
  });
486
- (0, import_react8.useConfigureSuggestions)(finalSuggestionConfig, { deps: dependencies });
487
- const result = (0, import_react8.useSuggestions)({ agentId: agentSession == null ? void 0 : agentSession.agentName });
488
- (0, import_react9.useEffect)(() => {
525
+ (0, import_react11.useConfigureSuggestions)(finalSuggestionConfig, dependencies);
526
+ const result = (0, import_react11.useSuggestions)({ agentId: resolvedAgentId });
527
+ (0, import_react12.useEffect)(() => {
489
528
  if (finalSuggestionConfig.available === "disabled")
490
529
  return;
491
530
  const subscription = copilotkit.subscribe({
492
531
  onAgentsChanged: () => {
493
- const agent = copilotkit.getAgent(agentSession == null ? void 0 : agentSession.agentName);
532
+ const agent = copilotkit.getAgent(resolvedAgentId);
494
533
  if (agent && !agent.isRunning && !result.suggestions.length) {
495
- copilotkit.reloadSuggestions(agentSession == null ? void 0 : agentSession.agentName);
534
+ copilotkit.reloadSuggestions(resolvedAgentId);
496
535
  }
497
536
  }
498
537
  });
499
538
  return () => {
500
539
  subscription.unsubscribe();
501
540
  };
502
- }, []);
541
+ }, [resolvedAgentId]);
503
542
  return result;
504
543
  }
505
544
 
@@ -909,10 +948,12 @@ var EventSchemas = import_zod2.z.discriminatedUnion("type", [
909
948
  ]);
910
949
 
911
950
  // src/hooks/use-coagent-state-render-bridge.tsx
912
- var import_react10 = require("@copilotkitnext/react");
913
- var import_react11 = require("react");
951
+ var import_react13 = require("@copilotkitnext/react");
952
+ var import_react14 = require("react");
914
953
  var import_shared3 = require("@copilotkit/shared");
915
954
  function getStateWithoutConstantKeys(state) {
955
+ if (!state)
956
+ return {};
916
957
  const _a = state, { messages, tools, copilotkit } = _a, stateWithoutConstantKeys = __objRest(_a, ["messages", "tools", "copilotkit"]);
917
958
  return stateWithoutConstantKeys;
918
959
  }
@@ -935,11 +976,11 @@ function useCoagentStateRenderBridge(agentId, props) {
935
976
  var _a;
936
977
  const { stateSnapshot, messageIndexInRun, message } = props;
937
978
  const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();
938
- const { agent } = (0, import_react10.useAgent)({ agentId });
939
- const [nodeName, setNodeName] = (0, import_react11.useState)(void 0);
979
+ const { agent } = (0, import_react13.useAgent)({ agentId });
980
+ const [nodeName, setNodeName] = (0, import_react14.useState)(void 0);
940
981
  const runId = (_a = props.runId) != null ? _a : message.runId;
941
982
  const effectiveRunId = runId || "pending";
942
- (0, import_react11.useEffect)(() => {
983
+ (0, import_react14.useEffect)(() => {
943
984
  if (!agent)
944
985
  return;
945
986
  const subscriber = {
@@ -959,10 +1000,7 @@ function useCoagentStateRenderBridge(agentId, props) {
959
1000
  unsubscribe();
960
1001
  };
961
1002
  }, [agentId, nodeName]);
962
- if (messageIndexInRun !== 0) {
963
- return null;
964
- }
965
- const getStateRender = (0, import_react11.useCallback)(
1003
+ const getStateRender = (0, import_react14.useCallback)(
966
1004
  (messageId) => {
967
1005
  return Object.entries(coAgentStateRenders).find(([stateRenderId, stateRender]) => {
968
1006
  if (claimsRef.current[messageId]) {
@@ -1004,8 +1042,11 @@ function useCoagentStateRenderBridge(agentId, props) {
1004
1042
  claimsRef.current[messageId] = { stateRenderId, runId: runId2 };
1005
1043
  return true;
1006
1044
  };
1007
- return (0, import_react11.useMemo)(() => {
1045
+ return (0, import_react14.useMemo)(() => {
1008
1046
  var _a2, _b, _c;
1047
+ if (messageIndexInRun !== 0) {
1048
+ return null;
1049
+ }
1009
1050
  const [stateRenderId, stateRender] = (_a2 = getStateRender(message.id)) != null ? _a2 : [];
1010
1051
  if (!stateRender || !stateRenderId) {
1011
1052
  return null;
@@ -1052,7 +1093,8 @@ function useCoagentStateRenderBridge(agentId, props) {
1052
1093
  agent == null ? void 0 : agent.isRunning,
1053
1094
  nodeName,
1054
1095
  effectiveRunId,
1055
- message.id
1096
+ message.id,
1097
+ messageIndexInRun
1056
1098
  ]);
1057
1099
  }
1058
1100
  function CoAgentStateRenderBridge(props) {
@@ -1080,15 +1122,15 @@ function useConfigureSuggestions2(suggestions) {
1080
1122
  function useCopilotChatInternal({
1081
1123
  suggestions
1082
1124
  } = {}) {
1083
- var _a, _b, _c, _d;
1084
- const { copilotkit } = (0, import_react13.useCopilotKit)();
1125
+ var _a, _b, _c;
1126
+ const { copilotkit } = (0, import_react16.useCopilotKit)();
1085
1127
  const { threadId, agentSession } = useCopilotContext();
1086
- const existingConfig = (0, import_react13.useCopilotChatConfiguration)();
1087
- const [agentAvailable, setAgentAvailable] = (0, import_react12.useState)(false);
1128
+ const existingConfig = (0, import_react16.useCopilotChatConfiguration)();
1129
+ const [agentAvailable, setAgentAvailable] = (0, import_react15.useState)(false);
1088
1130
  useConfigureSuggestions2(suggestions);
1089
- const resolvedAgentId = (_b = (_a = agentSession == null ? void 0 : agentSession.agentName) != null ? _a : existingConfig == null ? void 0 : existingConfig.agentId) != null ? _b : "default";
1090
- const { agent } = (0, import_react13.useAgent)({ agentId: resolvedAgentId });
1091
- (0, import_react12.useEffect)(() => {
1131
+ const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
1132
+ const { agent } = (0, import_react16.useAgent)({ agentId: resolvedAgentId });
1133
+ (0, import_react15.useEffect)(() => {
1092
1134
  const connect = (agent2) => __async(this, null, function* () {
1093
1135
  setAgentAvailable(false);
1094
1136
  try {
@@ -1113,7 +1155,7 @@ function useCopilotChatInternal({
1113
1155
  agent == null ? void 0 : agent.setMessages([]);
1114
1156
  agent == null ? void 0 : agent.setState(null);
1115
1157
  };
1116
- const deleteMessage = (0, import_react12.useCallback)(
1158
+ const deleteMessage = (0, import_react15.useCallback)(
1117
1159
  (messageId) => {
1118
1160
  var _a2;
1119
1161
  const filteredMessages = ((_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []).filter(
@@ -1124,13 +1166,13 @@ function useCopilotChatInternal({
1124
1166
  [agent == null ? void 0 : agent.setMessages, agent == null ? void 0 : agent.messages]
1125
1167
  );
1126
1168
  const latestDelete = useUpdatedRef(deleteMessage);
1127
- const latestDeleteFunc = (0, import_react12.useCallback)(
1169
+ const latestDeleteFunc = (0, import_react15.useCallback)(
1128
1170
  (messageId) => {
1129
1171
  return latestDelete.current(messageId);
1130
1172
  },
1131
1173
  [latestDelete]
1132
1174
  );
1133
- const currentSuggestions = (0, import_react13.useSuggestions)({ agentId: resolvedAgentId });
1175
+ const currentSuggestions = (0, import_react16.useSuggestions)({ agentId: resolvedAgentId });
1134
1176
  const reload = useAsyncCallback(
1135
1177
  (reloadMessageId) => __async(this, null, function* () {
1136
1178
  var _a2;
@@ -1198,7 +1240,7 @@ function useCopilotChatInternal({
1198
1240
  [latestSendMessageFunc]
1199
1241
  );
1200
1242
  const latestSetMessages = useUpdatedRef(agent == null ? void 0 : agent.setMessages);
1201
- const latestSetMessagesFunc = (0, import_react12.useCallback)(
1243
+ const latestSetMessagesFunc = (0, import_react15.useCallback)(
1202
1244
  (messages) => {
1203
1245
  var _a2, _b2;
1204
1246
  if (messages.every((message) => message instanceof import_runtime_client_gql2.Message)) {
@@ -1216,24 +1258,24 @@ function useCopilotChatInternal({
1216
1258
  [latestReload]
1217
1259
  );
1218
1260
  const latestStop = useUpdatedRef(agent == null ? void 0 : agent.abortRun);
1219
- const latestStopFunc = (0, import_react12.useCallback)(() => {
1261
+ const latestStopFunc = (0, import_react15.useCallback)(() => {
1220
1262
  var _a2;
1221
1263
  return (_a2 = latestStop.current) == null ? void 0 : _a2.call(latestStop);
1222
1264
  }, [latestStop]);
1223
1265
  const latestReset = useUpdatedRef(reset);
1224
- const latestResetFunc = (0, import_react12.useCallback)(() => {
1266
+ const latestResetFunc = (0, import_react15.useCallback)(() => {
1225
1267
  return latestReset.current();
1226
1268
  }, [latestReset]);
1227
1269
  const lazyToolRendered = useLazyToolRenderer();
1228
- const renderCustomMessage = (0, import_react13.useRenderCustomMessages)();
1270
+ const renderCustomMessage = (0, import_react16.useRenderCustomMessages)();
1229
1271
  const legacyCustomMessageRenderer = useLegacyCoagentRenderer({
1230
1272
  copilotkit,
1231
1273
  agent,
1232
1274
  agentId: resolvedAgentId,
1233
- threadId: (_c = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _c : threadId
1275
+ threadId: (_b = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _b : threadId
1234
1276
  });
1235
- const allMessages = (_d = agent == null ? void 0 : agent.messages) != null ? _d : [];
1236
- const resolvedMessages = (0, import_react12.useMemo)(() => {
1277
+ const allMessages = (_c = agent == null ? void 0 : agent.messages) != null ? _c : [];
1278
+ const resolvedMessages = (0, import_react15.useMemo)(() => {
1237
1279
  let processedMessages = allMessages.map((message) => {
1238
1280
  if (message.role !== "assistant") {
1239
1281
  return message;
@@ -1261,31 +1303,13 @@ function useCopilotChatInternal({
1261
1303
  return message;
1262
1304
  });
1263
1305
  const hasAssistantMessages = processedMessages.some((msg) => msg.role === "assistant");
1264
- if (legacyCustomMessageRenderer && !hasAssistantMessages) {
1265
- const placeholderId = `coagent-state-render-${resolvedAgentId}`;
1266
- const placeholderMessage = {
1267
- id: placeholderId,
1268
- role: "assistant",
1269
- content: "",
1270
- name: "coagent-state-render"
1271
- };
1272
- processedMessages = [
1273
- ...processedMessages,
1274
- __spreadProps(__spreadValues({}, placeholderMessage), {
1275
- generativeUI: () => legacyCustomMessageRenderer({
1276
- message: placeholderMessage,
1277
- position: "before"
1278
- })
1279
- })
1280
- ];
1281
- }
1282
1306
  return processedMessages;
1283
1307
  }, [
1284
1308
  agent == null ? void 0 : agent.messages,
1285
1309
  lazyToolRendered,
1286
1310
  allMessages,
1287
1311
  renderCustomMessage,
1288
- legacyCustomMessageRenderer,
1312
+ // legacyCustomMessageRenderer,
1289
1313
  resolvedAgentId
1290
1314
  ]);
1291
1315
  return {
@@ -1297,7 +1321,7 @@ function useCopilotChatInternal({
1297
1321
  stopGeneration: latestStopFunc,
1298
1322
  reset: latestResetFunc,
1299
1323
  deleteMessage: latestDeleteFunc,
1300
- isAvailable: !agentAvailable,
1324
+ isAvailable: agentAvailable,
1301
1325
  isLoading: Boolean(agent == null ? void 0 : agent.isRunning),
1302
1326
  // mcpServers,
1303
1327
  // setMcpServers,
@@ -1314,8 +1338,8 @@ function useCopilotChatInternal({
1314
1338
  };
1315
1339
  }
1316
1340
  function useUpdatedRef(value) {
1317
- const ref = (0, import_react12.useRef)(value);
1318
- (0, import_react12.useEffect)(() => {
1341
+ const ref = (0, import_react15.useRef)(value);
1342
+ (0, import_react15.useEffect)(() => {
1319
1343
  ref.current = value;
1320
1344
  }, [value]);
1321
1345
  return ref;
@@ -1326,20 +1350,19 @@ function useLegacyCoagentRenderer({
1326
1350
  agentId,
1327
1351
  threadId
1328
1352
  }) {
1329
- return (0, import_react12.useMemo)(() => {
1353
+ return (0, import_react15.useMemo)(() => {
1330
1354
  if (!copilotkit || !agent) {
1331
1355
  return null;
1332
1356
  }
1333
1357
  return ({ message, position }) => {
1334
1358
  var _a;
1335
1359
  const effectiveThreadId = (_a = threadId != null ? threadId : agent.threadId) != null ? _a : "default";
1336
- const existingRunId = copilotkit.getRunIdForMessage(
1337
- agentId,
1338
- effectiveThreadId,
1339
- message.id
1340
- );
1360
+ const existingRunId = copilotkit.getRunIdForMessage(agentId, effectiveThreadId, message.id);
1341
1361
  const runId = existingRunId || `pending:${message.id}`;
1342
- const messageIndex = Math.max(agent.messages.findIndex((msg) => msg.id === message.id), 0);
1362
+ const messageIndex = Math.max(
1363
+ agent.messages.findIndex((msg) => msg.id === message.id),
1364
+ 0
1365
+ );
1343
1366
  const bridgeProps = {
1344
1367
  message,
1345
1368
  position,
@@ -1350,7 +1373,7 @@ function useLegacyCoagentRenderer({
1350
1373
  agentId,
1351
1374
  stateSnapshot: message.state
1352
1375
  };
1353
- return (0, import_react12.createElement)(CoAgentStateRenderBridge, bridgeProps);
1376
+ return (0, import_react15.createElement)(CoAgentStateRenderBridge, bridgeProps);
1354
1377
  };
1355
1378
  }, [agent, agentId, copilotkit, threadId]);
1356
1379
  }
@@ -1384,7 +1407,7 @@ function useCopilotChat(options = {}) {
1384
1407
  }
1385
1408
 
1386
1409
  // src/hooks/use-copilot-chat-headless_c.ts
1387
- var import_react14 = require("react");
1410
+ var import_react17 = require("react");
1388
1411
  var import_shared4 = require("@copilotkit/shared");
1389
1412
  var createNonFunctionalReturn = () => ({
1390
1413
  visibleMessages: [],
@@ -1425,7 +1448,7 @@ function useCopilotChatHeadless_c(options = {}) {
1425
1448
  const { copilotApiConfig, setBannerError } = useCopilotContext();
1426
1449
  const hasPublicApiKey = Boolean(copilotApiConfig.publicApiKey);
1427
1450
  const internalResult = useCopilotChatInternal(options);
1428
- (0, import_react14.useEffect)(() => {
1451
+ (0, import_react17.useEffect)(() => {
1429
1452
  if (!hasPublicApiKey) {
1430
1453
  setBannerError(
1431
1454
  new import_shared4.CopilotKitError({
@@ -1450,13 +1473,13 @@ function useCopilotChatHeadless_c(options = {}) {
1450
1473
  }
1451
1474
 
1452
1475
  // src/hooks/use-copilot-action.ts
1453
- var import_react21 = require("react");
1476
+ var import_react24 = require("react");
1454
1477
 
1455
1478
  // src/hooks/use-frontend-tool.ts
1456
- var import_react15 = __toESM(require("react"));
1479
+ var import_react18 = __toESM(require("react"));
1457
1480
  var import_shared5 = require("@copilotkit/shared");
1458
1481
  var import_shared6 = require("@copilotkit/shared");
1459
- var import_react16 = require("@copilotkitnext/react");
1482
+ var import_react19 = require("@copilotkitnext/react");
1460
1483
  function useFrontendTool(tool, dependencies) {
1461
1484
  const { name, description, parameters, render, followUp } = tool;
1462
1485
  const zodParameters = (0, import_shared5.getZodParameters)(parameters);
@@ -1466,7 +1489,11 @@ function useFrontendTool(tool, dependencies) {
1466
1489
  }
1467
1490
  if (typeof render === "string") {
1468
1491
  const staticRender = render;
1469
- return () => import_react15.default.createElement(import_react15.default.Fragment, null, staticRender);
1492
+ return () => import_react18.default.createElement(
1493
+ import_react18.default.Fragment,
1494
+ null,
1495
+ staticRender
1496
+ );
1470
1497
  }
1471
1498
  return (args) => {
1472
1499
  const renderArgs = __spreadProps(__spreadValues({}, args), {
@@ -1474,12 +1501,12 @@ function useFrontendTool(tool, dependencies) {
1474
1501
  });
1475
1502
  const rendered = render(renderArgs);
1476
1503
  if (typeof rendered === "string") {
1477
- return import_react15.default.createElement(import_react15.default.Fragment, null, rendered);
1504
+ return import_react18.default.createElement(import_react18.default.Fragment, null, rendered);
1478
1505
  }
1479
1506
  return rendered != null ? rendered : null;
1480
1507
  };
1481
1508
  })();
1482
- (0, import_react16.useFrontendTool)({
1509
+ (0, import_react19.useFrontendTool)({
1483
1510
  name,
1484
1511
  description,
1485
1512
  parameters: zodParameters,
@@ -1491,23 +1518,23 @@ function useFrontendTool(tool, dependencies) {
1491
1518
 
1492
1519
  // src/hooks/use-render-tool-call.ts
1493
1520
  var import_shared7 = require("@copilotkit/shared");
1494
- var import_react17 = require("react");
1495
- var import_react18 = require("@copilotkitnext/react");
1521
+ var import_react20 = require("react");
1522
+ var import_react21 = require("@copilotkitnext/react");
1496
1523
  var import_shared8 = require("@copilotkit/shared");
1497
1524
  function useRenderToolCall2(tool, dependencies) {
1498
- const { copilotkit } = (0, import_react18.useCopilotKit)();
1499
- const hasAddedRef = (0, import_react17.useRef)(false);
1500
- (0, import_react17.useEffect)(() => {
1525
+ const { copilotkit } = (0, import_react21.useCopilotKit)();
1526
+ const hasAddedRef = (0, import_react20.useRef)(false);
1527
+ (0, import_react20.useEffect)(() => {
1501
1528
  const { name, parameters, render } = tool;
1502
1529
  const zodParameters = (0, import_shared7.getZodParameters)(parameters);
1503
- const renderToolCall = name === "*" ? (0, import_react18.defineToolCallRenderer)({
1530
+ const renderToolCall = name === "*" ? (0, import_react21.defineToolCallRenderer)({
1504
1531
  name: "*",
1505
1532
  render: (args) => {
1506
1533
  return render(__spreadProps(__spreadValues({}, args), {
1507
1534
  result: args.result ? (0, import_shared8.parseJson)(args.result, args.result) : args.result
1508
1535
  }));
1509
1536
  }
1510
- }) : (0, import_react18.defineToolCallRenderer)({
1537
+ }) : (0, import_react21.defineToolCallRenderer)({
1511
1538
  name,
1512
1539
  args: zodParameters,
1513
1540
  render: (args) => {
@@ -1536,18 +1563,18 @@ function useRenderToolCall2(tool, dependencies) {
1536
1563
 
1537
1564
  // src/hooks/use-human-in-the-loop.ts
1538
1565
  var import_shared9 = require("@copilotkit/shared");
1539
- var import_react19 = require("@copilotkitnext/react");
1566
+ var import_react22 = require("@copilotkitnext/react");
1540
1567
  var import_core = require("@copilotkitnext/core");
1541
- var import_react20 = __toESM(require("react"));
1568
+ var import_react23 = __toESM(require("react"));
1542
1569
  function useHumanInTheLoop(tool, dependencies) {
1543
1570
  const _a = tool, { render } = _a, toolRest = __objRest(_a, ["render"]);
1544
1571
  const { name, description, parameters, followUp } = toolRest;
1545
1572
  const zodParameters = (0, import_shared9.getZodParameters)(parameters);
1546
- const renderRef = (0, import_react20.useRef)(null);
1547
- (0, import_react20.useEffect)(() => {
1573
+ const renderRef = (0, import_react23.useRef)(null);
1574
+ (0, import_react23.useEffect)(() => {
1548
1575
  renderRef.current = (args) => {
1549
1576
  if (typeof render === "string") {
1550
- return import_react20.default.createElement(import_react20.default.Fragment, null, render);
1577
+ return import_react23.default.createElement(import_react23.default.Fragment, null, render);
1551
1578
  }
1552
1579
  if (!render) {
1553
1580
  return null;
@@ -1587,12 +1614,12 @@ function useHumanInTheLoop(tool, dependencies) {
1587
1614
  })();
1588
1615
  const rendered = render(renderProps);
1589
1616
  if (typeof rendered === "string") {
1590
- return import_react20.default.createElement(import_react20.default.Fragment, null, rendered);
1617
+ return import_react23.default.createElement(import_react23.default.Fragment, null, rendered);
1591
1618
  }
1592
1619
  return rendered != null ? rendered : null;
1593
1620
  };
1594
1621
  }, [render, ...dependencies != null ? dependencies : []]);
1595
- (0, import_react19.useHumanInTheLoop)({
1622
+ (0, import_react22.useHumanInTheLoop)({
1596
1623
  name,
1597
1624
  description,
1598
1625
  followUp,
@@ -1648,7 +1675,7 @@ function getActionConfig(action) {
1648
1675
  throw new Error("Invalid action configuration");
1649
1676
  }
1650
1677
  function useCopilotAction(action, dependencies) {
1651
- const [initialActionConfig] = (0, import_react21.useState)(getActionConfig(action));
1678
+ const [initialActionConfig] = (0, import_react24.useState)(getActionConfig(action));
1652
1679
  const currentActionConfig = getActionConfig(action);
1653
1680
  if (initialActionConfig.type !== currentActionConfig.type) {
1654
1681
  throw new Error("Action configuration changed between renders");
@@ -1666,14 +1693,14 @@ function useCopilotAction(action, dependencies) {
1666
1693
  }
1667
1694
 
1668
1695
  // src/hooks/use-coagent-state-render.ts
1669
- var import_react22 = require("react");
1696
+ var import_react25 = require("react");
1670
1697
  var import_shared10 = require("@copilotkit/shared");
1671
1698
  function useCoAgentStateRender(action, dependencies) {
1672
- const { chatComponentsCache, availableAgents } = (0, import_react22.useContext)(CopilotContext);
1699
+ const { chatComponentsCache, availableAgents } = (0, import_react25.useContext)(CopilotContext);
1673
1700
  const { setCoAgentStateRender, removeCoAgentStateRender, coAgentStateRenders } = useCoAgentStateRenders();
1674
- const idRef = (0, import_react22.useRef)((0, import_shared10.randomId)());
1701
+ const idRef = (0, import_react25.useRef)((0, import_shared10.randomId)());
1675
1702
  const { setBannerError, addToast } = useToast();
1676
- (0, import_react22.useEffect)(() => {
1703
+ (0, import_react25.useEffect)(() => {
1677
1704
  if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === action.name)) {
1678
1705
  const message = `(useCoAgentStateRender): Agent "${action.name}" not found. Make sure the agent exists and is properly configured.`;
1679
1706
  const agentError = new import_shared10.CopilotKitAgentDiscoveryError({
@@ -1694,7 +1721,7 @@ function useCoAgentStateRender(action, dependencies) {
1694
1721
  }
1695
1722
  }
1696
1723
  }
1697
- (0, import_react22.useEffect)(() => {
1724
+ (0, import_react25.useEffect)(() => {
1698
1725
  const currentId = idRef.current;
1699
1726
  const hasDuplicate = Object.entries(coAgentStateRenders).some(([id, otherAction]) => {
1700
1727
  if (id === currentId)
@@ -1718,7 +1745,7 @@ function useCoAgentStateRender(action, dependencies) {
1718
1745
  });
1719
1746
  }
1720
1747
  }, [coAgentStateRenders]);
1721
- (0, import_react22.useEffect)(() => {
1748
+ (0, import_react25.useEffect)(() => {
1722
1749
  setCoAgentStateRender(idRef.current, action);
1723
1750
  if (chatComponentsCache.current !== null && action.render !== void 0) {
1724
1751
  chatComponentsCache.current.coAgentStateRenders[key] = action.render;
@@ -1738,11 +1765,11 @@ function useCoAgentStateRender(action, dependencies) {
1738
1765
  }
1739
1766
 
1740
1767
  // src/hooks/use-make-copilot-document-readable.ts
1741
- var import_react23 = require("react");
1768
+ var import_react26 = require("react");
1742
1769
  function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
1743
1770
  const { addDocumentContext, removeDocumentContext } = useCopilotContext();
1744
- const idRef = (0, import_react23.useRef)(void 0);
1745
- (0, import_react23.useEffect)(() => {
1771
+ const idRef = (0, import_react26.useRef)(void 0);
1772
+ (0, import_react26.useEffect)(() => {
1746
1773
  const id = addDocumentContext(document, categories);
1747
1774
  idRef.current = id;
1748
1775
  return () => {
@@ -1753,21 +1780,23 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
1753
1780
  }
1754
1781
 
1755
1782
  // src/hooks/use-copilot-readable.ts
1756
- var import_react24 = require("@copilotkitnext/react");
1783
+ var import_react27 = require("@copilotkitnext/react");
1757
1784
  function useCopilotReadable({ description, value }, dependencies) {
1758
- (0, import_react24.useAgentContext)({
1785
+ (0, import_react27.useAgentContext)({
1759
1786
  description,
1760
1787
  value
1761
1788
  });
1789
+ return;
1762
1790
  }
1763
1791
 
1764
1792
  // src/hooks/use-coagent.ts
1765
- var import_react25 = require("react");
1766
- var import_react26 = require("@copilotkitnext/react");
1793
+ var import_react28 = require("react");
1794
+ var import_react29 = require("@copilotkitnext/react");
1767
1795
  function useCoAgent(options) {
1768
- const { agent } = (0, import_react26.useAgent)({ agentId: options.name });
1769
- const nodeNameRef = (0, import_react25.useRef)("start");
1770
- const handleStateUpdate = (0, import_react25.useCallback)(
1796
+ const { agent } = (0, import_react29.useAgent)({ agentId: options.name });
1797
+ const { copilotkit } = (0, import_react29.useCopilotKit)();
1798
+ const nodeName = useAgentNodeName(options.name);
1799
+ const handleStateUpdate = (0, import_react28.useCallback)(
1771
1800
  (newState) => {
1772
1801
  if (!agent)
1773
1802
  return;
@@ -1780,22 +1809,34 @@ function useCoAgent(options) {
1780
1809
  },
1781
1810
  [agent == null ? void 0 : agent.state, agent == null ? void 0 : agent.setState]
1782
1811
  );
1783
- const externalStateStr = (0, import_react25.useMemo)(
1812
+ (0, import_react28.useEffect)(() => {
1813
+ var _a;
1814
+ if (!options.config && !options.configurable)
1815
+ return;
1816
+ let config = (_a = options.config) != null ? _a : {};
1817
+ if (options.configurable) {
1818
+ config = __spreadProps(__spreadValues({}, config), {
1819
+ configurable: __spreadValues(__spreadValues({}, options.configurable), config.configurable)
1820
+ });
1821
+ }
1822
+ copilotkit.setProperties(config);
1823
+ }, [options.config, options.configurable]);
1824
+ const externalStateStr = (0, import_react28.useMemo)(
1784
1825
  () => isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0,
1785
1826
  [isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]
1786
1827
  );
1787
- (0, import_react25.useEffect)(() => {
1828
+ (0, import_react28.useEffect)(() => {
1788
1829
  if ((agent == null ? void 0 : agent.state) && isExternalStateManagement(options) && JSON.stringify(options.state) !== JSON.stringify(agent.state)) {
1789
1830
  handleStateUpdate(options.state);
1790
1831
  }
1791
1832
  }, [agent, externalStateStr, handleStateUpdate]);
1792
- const hasStateValues = (0, import_react25.useCallback)((value) => {
1833
+ const hasStateValues = (0, import_react28.useCallback)((value) => {
1793
1834
  return Boolean(value && Object.keys(value).length);
1794
1835
  }, []);
1795
- const initialStateRef = (0, import_react25.useRef)(
1836
+ const initialStateRef = (0, import_react28.useRef)(
1796
1837
  isExternalStateManagement(options) ? options.state : "initialState" in options ? options.initialState : void 0
1797
1838
  );
1798
- (0, import_react25.useEffect)(() => {
1839
+ (0, import_react28.useEffect)(() => {
1799
1840
  if (isExternalStateManagement(options)) {
1800
1841
  initialStateRef.current = options.state;
1801
1842
  } else if ("initialState" in options) {
@@ -1804,7 +1845,7 @@ function useCoAgent(options) {
1804
1845
  }, [
1805
1846
  isExternalStateManagement(options) ? JSON.stringify(options.state) : "initialState" in options ? JSON.stringify(options.initialState) : void 0
1806
1847
  ]);
1807
- (0, import_react25.useEffect)(() => {
1848
+ (0, import_react28.useEffect)(() => {
1808
1849
  if (!agent)
1809
1850
  return;
1810
1851
  const subscriber = {
@@ -1825,15 +1866,6 @@ function useCoAgent(options) {
1825
1866
  if (initialStateRef.current !== void 0) {
1826
1867
  handleStateUpdate(initialStateRef.current);
1827
1868
  }
1828
- },
1829
- onStepStartedEvent: ({ event }) => {
1830
- nodeNameRef.current = event.stepName;
1831
- },
1832
- onRunStartedEvent: () => {
1833
- nodeNameRef.current = "start";
1834
- },
1835
- onRunFinishedEvent: () => {
1836
- nodeNameRef.current = "end";
1837
1869
  }
1838
1870
  };
1839
1871
  const subscription = agent.subscribe(subscriber);
@@ -1841,7 +1873,7 @@ function useCoAgent(options) {
1841
1873
  subscription.unsubscribe();
1842
1874
  };
1843
1875
  }, [agent, handleStateUpdate, hasStateValues]);
1844
- return (0, import_react25.useMemo)(() => {
1876
+ return (0, import_react28.useMemo)(() => {
1845
1877
  var _a, _b, _c;
1846
1878
  if (!agent) {
1847
1879
  const noop = () => {
@@ -1857,7 +1889,7 @@ function useCoAgent(options) {
1857
1889
  );
1858
1890
  return {
1859
1891
  name: options.name,
1860
- nodeName: nodeNameRef.current,
1892
+ nodeName,
1861
1893
  threadId: void 0,
1862
1894
  running: false,
1863
1895
  state: initialState,
@@ -1869,7 +1901,7 @@ function useCoAgent(options) {
1869
1901
  }
1870
1902
  return {
1871
1903
  name: (_c = agent == null ? void 0 : agent.agentId) != null ? _c : options.name,
1872
- nodeName: nodeNameRef.current,
1904
+ nodeName,
1873
1905
  threadId: agent.threadId,
1874
1906
  running: agent.isRunning,
1875
1907
  state: agent.state,
@@ -1897,12 +1929,12 @@ var isExternalStateManagement = (options) => {
1897
1929
 
1898
1930
  // src/hooks/use-copilot-runtime-client.ts
1899
1931
  var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
1900
- var import_react27 = require("react");
1932
+ var import_react30 = require("react");
1901
1933
  var import_shared11 = require("@copilotkit/shared");
1902
1934
  var useCopilotRuntimeClient = (options) => {
1903
1935
  const { setBannerError } = useToast();
1904
1936
  const _a = options, { showDevConsole, onError } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onError"]);
1905
- const lastStructuredErrorRef = (0, import_react27.useRef)(null);
1937
+ const lastStructuredErrorRef = (0, import_react30.useRef)(null);
1906
1938
  const traceUIError = (error, originalError) => __async(void 0, null, function* () {
1907
1939
  try {
1908
1940
  const errorEvent = {
@@ -1928,7 +1960,7 @@ var useCopilotRuntimeClient = (options) => {
1928
1960
  console.error("Error in onError handler:", error2);
1929
1961
  }
1930
1962
  });
1931
- const runtimeClient = (0, import_react27.useMemo)(() => {
1963
+ const runtimeClient = (0, import_react30.useMemo)(() => {
1932
1964
  return new import_runtime_client_gql3.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
1933
1965
  handleGQLErrors: (error) => {
1934
1966
  var _a2;
@@ -2007,28 +2039,28 @@ function createStructuredError(gqlError) {
2007
2039
  }
2008
2040
 
2009
2041
  // src/hooks/use-copilot-authenticated-action.ts
2010
- var import_react28 = require("react");
2011
- var import_react29 = __toESM(require("react"));
2042
+ var import_react31 = require("react");
2043
+ var import_react32 = __toESM(require("react"));
2012
2044
  function useCopilotAuthenticatedAction_c(action, dependencies) {
2013
2045
  const { authConfig_c, authStates_c, setAuthStates_c } = useCopilotContext();
2014
- const pendingActionRef = (0, import_react28.useRef)(null);
2015
- const executeAction = (0, import_react28.useCallback)(
2046
+ const pendingActionRef = (0, import_react31.useRef)(null);
2047
+ const executeAction = (0, import_react31.useCallback)(
2016
2048
  (props) => {
2017
2049
  if (typeof action.render === "function") {
2018
2050
  return action.render(props);
2019
2051
  }
2020
- return action.render || import_react29.default.createElement(import_react28.Fragment);
2052
+ return action.render || import_react32.default.createElement(import_react31.Fragment);
2021
2053
  },
2022
2054
  [action]
2023
2055
  );
2024
- const wrappedRender = (0, import_react28.useCallback)(
2056
+ const wrappedRender = (0, import_react31.useCallback)(
2025
2057
  (props) => {
2026
2058
  const isAuthenticated = Object.values(authStates_c || {}).some(
2027
2059
  (state) => state.status === "authenticated"
2028
2060
  );
2029
2061
  if (!isAuthenticated) {
2030
2062
  pendingActionRef.current = props;
2031
- return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ? import_react29.default.createElement(authConfig_c.SignInComponent, {
2063
+ return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ? import_react32.default.createElement(authConfig_c.SignInComponent, {
2032
2064
  onSignInComplete: (authState) => {
2033
2065
  setAuthStates_c == null ? void 0 : setAuthStates_c((prev) => __spreadProps(__spreadValues({}, prev), { [action.name]: authState }));
2034
2066
  if (pendingActionRef.current) {
@@ -2036,7 +2068,7 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
2036
2068
  pendingActionRef.current = null;
2037
2069
  }
2038
2070
  }
2039
- }) : import_react29.default.createElement(import_react28.Fragment);
2071
+ }) : import_react32.default.createElement(import_react31.Fragment);
2040
2072
  }
2041
2073
  return executeAction(props);
2042
2074
  },
@@ -2051,13 +2083,13 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
2051
2083
  }
2052
2084
 
2053
2085
  // src/hooks/use-langgraph-interrupt.ts
2054
- var import_react30 = require("react");
2086
+ var import_react33 = require("react");
2055
2087
  var import_shared12 = require("@copilotkit/shared");
2056
2088
  function useLangGraphInterrupt(action, dependencies) {
2057
- const { setInterruptAction, removeInterruptAction, interruptActions, threadId } = (0, import_react30.useContext)(CopilotContext);
2089
+ const { setInterruptAction, removeInterruptAction, interruptActions, threadId } = (0, import_react33.useContext)(CopilotContext);
2058
2090
  const { addToast } = useToast();
2059
2091
  const actionId = (0, import_shared12.dataToUUID)(JSON.stringify(action), "lgAction");
2060
- (0, import_react30.useEffect)(() => {
2092
+ (0, import_react33.useEffect)(() => {
2061
2093
  if (!action)
2062
2094
  return;
2063
2095
  setInterruptAction(threadId, __spreadProps(__spreadValues({}, action), { id: actionId }));
@@ -2068,10 +2100,10 @@ function useLangGraphInterrupt(action, dependencies) {
2068
2100
  }
2069
2101
 
2070
2102
  // src/hooks/use-copilot-additional-instructions.ts
2071
- var import_react31 = require("react");
2103
+ var import_react34 = require("react");
2072
2104
  function useCopilotAdditionalInstructions({ instructions, available = "enabled" }, dependencies) {
2073
2105
  const { setAdditionalInstructions } = useCopilotContext();
2074
- (0, import_react31.useEffect)(() => {
2106
+ (0, import_react34.useEffect)(() => {
2075
2107
  if (available === "disabled")
2076
2108
  return;
2077
2109
  setAdditionalInstructions((prevInstructions) => [...prevInstructions || [], instructions]);