@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
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  useCopilotAuthenticatedAction_c
3
- } from "../chunk-3GURHDG7.mjs";
4
- import "../chunk-TXI72QHK.mjs";
3
+ } from "../chunk-BPJ6V4YX.mjs";
4
+ import "../chunk-EG56H77V.mjs";
5
5
  import "../chunk-NBK4KBLX.mjs";
6
- import "../chunk-NG26QEGF.mjs";
6
+ import "../chunk-T2VBHAAP.mjs";
7
7
  import "../chunk-7DTB7S5V.mjs";
8
8
  import "../chunk-WVLHXIFP.mjs";
9
9
  import "../chunk-SKC7AJIV.mjs";
@@ -83,7 +83,7 @@ __export(use_copilot_chat_headless_c_exports, {
83
83
  useCopilotChatHeadless_c: () => useCopilotChatHeadless_c
84
84
  });
85
85
  module.exports = __toCommonJS(use_copilot_chat_headless_c_exports);
86
- var import_react14 = require("react");
86
+ var import_react17 = require("react");
87
87
 
88
88
  // src/context/copilot-context.tsx
89
89
  var import_react = __toESM(require("react"));
@@ -187,7 +187,7 @@ function returnAndThrowInDebug(_value) {
187
187
  }
188
188
 
189
189
  // src/hooks/use-copilot-chat_internal.ts
190
- var import_react12 = require("react");
190
+ var import_react15 = require("react");
191
191
 
192
192
  // src/components/error-boundary/error-utils.tsx
193
193
  var import_react3 = require("react");
@@ -335,13 +335,45 @@ function useCoAgentStateRenders() {
335
335
  }
336
336
 
337
337
  // src/hooks/use-langgraph-interrupt-render.ts
338
- var import_react5 = __toESM(require("react"));
338
+ var import_react7 = __toESM(require("react"));
339
339
  var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
340
340
  var import_shared2 = require("@copilotkit/shared");
341
+
342
+ // src/hooks/use-agent-nodename.ts
343
+ var import_react5 = require("react");
344
+ var import_react6 = require("@copilotkitnext/react");
345
+ function useAgentNodeName(agentName) {
346
+ const { agent } = (0, import_react6.useAgent)({ agentId: agentName });
347
+ const nodeNameRef = (0, import_react5.useRef)("start");
348
+ (0, import_react5.useEffect)(() => {
349
+ if (!agent)
350
+ return;
351
+ const subscriber = {
352
+ onStepStartedEvent: ({ event }) => {
353
+ nodeNameRef.current = event.stepName;
354
+ },
355
+ onRunStartedEvent: () => {
356
+ nodeNameRef.current = "start";
357
+ },
358
+ onRunFinishedEvent: () => {
359
+ nodeNameRef.current = "end";
360
+ }
361
+ };
362
+ const subscription = agent.subscribe(subscriber);
363
+ return () => {
364
+ subscription.unsubscribe();
365
+ };
366
+ }, [agent]);
367
+ return nodeNameRef.current;
368
+ }
369
+
370
+ // src/hooks/use-langgraph-interrupt-render.ts
371
+ var import_react8 = require("@copilotkitnext/react");
341
372
  var InterruptRenderer = ({ event, result, render, resolve }) => {
342
373
  return render({ event, result, resolve });
343
374
  };
344
375
  function useLangGraphInterruptRender(agent) {
376
+ var _a;
345
377
  const {
346
378
  interruptActions,
347
379
  agentSession,
@@ -350,7 +382,10 @@ function useLangGraphInterruptRender(agent) {
350
382
  addInterruptEvent,
351
383
  removeInterruptEvent
352
384
  } = useCopilotContext();
353
- (0, import_react5.useEffect)(() => {
385
+ const existingConfig = (0, import_react8.useCopilotChatConfiguration)();
386
+ const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
387
+ const nodeName = useAgentNodeName(resolvedAgentId);
388
+ (0, import_react7.useEffect)(() => {
354
389
  if (!agent)
355
390
  return;
356
391
  const subscriber = {
@@ -375,7 +410,7 @@ function useLangGraphInterruptRender(agent) {
375
410
  unsubscribe();
376
411
  };
377
412
  }, [agent, threadId]);
378
- const handleResolve = (0, import_react5.useCallback)(
413
+ const handleResolve = (0, import_react7.useCallback)(
379
414
  (eventId, response) => {
380
415
  agent == null ? void 0 : agent.runAgent({
381
416
  forwardedProps: {
@@ -389,10 +424,10 @@ function useLangGraphInterruptRender(agent) {
389
424
  // eslint-disable-next-line react-hooks/exhaustive-deps
390
425
  [agent, threadId]
391
426
  );
392
- return (0, import_react5.useMemo)(() => {
427
+ return (0, import_react7.useMemo)(() => {
393
428
  const eventQueue = interruptEventQueue[threadId] || [];
394
429
  const currentQueuedEvent = eventQueue.find((qe) => !qe.event.response);
395
- if (!currentQueuedEvent)
430
+ if (!currentQueuedEvent || !agentSession)
396
431
  return null;
397
432
  const allActions = Object.values(interruptActions);
398
433
  const matchingAction = allActions.find((action) => {
@@ -400,7 +435,9 @@ function useLangGraphInterruptRender(agent) {
400
435
  return true;
401
436
  return action.enabled({
402
437
  eventValue: currentQueuedEvent.event.value,
403
- agentMetadata: agentSession
438
+ agentMetadata: __spreadProps(__spreadValues({}, agentSession), {
439
+ nodeName
440
+ })
404
441
  });
405
442
  });
406
443
  if (!matchingAction)
@@ -418,7 +455,7 @@ function useLangGraphInterruptRender(agent) {
418
455
  }
419
456
  if (!render)
420
457
  return null;
421
- return import_react5.default.createElement(InterruptRenderer, {
458
+ return import_react7.default.createElement(InterruptRenderer, {
422
459
  event: currentQueuedEvent.event,
423
460
  result,
424
461
  render,
@@ -428,14 +465,14 @@ function useLangGraphInterruptRender(agent) {
428
465
  }
429
466
 
430
467
  // src/hooks/use-copilot-chat_internal.ts
431
- var import_react13 = require("@copilotkitnext/react");
468
+ var import_react16 = require("@copilotkitnext/react");
432
469
 
433
470
  // src/hooks/use-lazy-tool-renderer.tsx
434
- var import_react6 = require("@copilotkitnext/react");
435
- var import_react7 = require("react");
471
+ var import_react9 = require("@copilotkitnext/react");
472
+ var import_react10 = require("react");
436
473
  function useLazyToolRenderer() {
437
- const renderToolCall = (0, import_react6.useRenderToolCall)();
438
- return (0, import_react7.useCallback)(
474
+ const renderToolCall = (0, import_react9.useRenderToolCall)();
475
+ return (0, import_react10.useCallback)(
439
476
  (message, messages) => {
440
477
  var _a;
441
478
  if (!((_a = message == null ? void 0 : message.toolCalls) == null ? void 0 : _a.length))
@@ -456,34 +493,36 @@ function useLazyToolRenderer() {
456
493
  }
457
494
 
458
495
  // src/hooks/use-configure-chat-suggestions.tsx
459
- var import_react8 = require("@copilotkitnext/react");
460
- var import_react9 = require("react");
496
+ var import_react11 = require("@copilotkitnext/react");
497
+ var import_react12 = require("react");
461
498
  function useConfigureChatSuggestions(config, dependencies = []) {
462
- const { agentSession } = useCopilotContext();
463
- const { copilotkit } = (0, import_react8.useCopilotKit)();
499
+ var _a;
500
+ const existingConfig = (0, import_react11.useCopilotChatConfiguration)();
501
+ const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
502
+ const { copilotkit } = (0, import_react11.useCopilotKit)();
464
503
  const available = config.available === "enabled" ? "always" : config.available;
465
504
  const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
466
505
  available,
467
- consumerAgentId: agentSession == null ? void 0 : agentSession.agentName
506
+ consumerAgentId: resolvedAgentId
468
507
  // Use chatConfig.agentId here
469
508
  });
470
- (0, import_react8.useConfigureSuggestions)(finalSuggestionConfig, { deps: dependencies });
471
- const result = (0, import_react8.useSuggestions)({ agentId: agentSession == null ? void 0 : agentSession.agentName });
472
- (0, import_react9.useEffect)(() => {
509
+ (0, import_react11.useConfigureSuggestions)(finalSuggestionConfig, dependencies);
510
+ const result = (0, import_react11.useSuggestions)({ agentId: resolvedAgentId });
511
+ (0, import_react12.useEffect)(() => {
473
512
  if (finalSuggestionConfig.available === "disabled")
474
513
  return;
475
514
  const subscription = copilotkit.subscribe({
476
515
  onAgentsChanged: () => {
477
- const agent = copilotkit.getAgent(agentSession == null ? void 0 : agentSession.agentName);
516
+ const agent = copilotkit.getAgent(resolvedAgentId);
478
517
  if (agent && !agent.isRunning && !result.suggestions.length) {
479
- copilotkit.reloadSuggestions(agentSession == null ? void 0 : agentSession.agentName);
518
+ copilotkit.reloadSuggestions(resolvedAgentId);
480
519
  }
481
520
  }
482
521
  });
483
522
  return () => {
484
523
  subscription.unsubscribe();
485
524
  };
486
- }, []);
525
+ }, [resolvedAgentId]);
487
526
  return result;
488
527
  }
489
528
 
@@ -893,10 +932,12 @@ var EventSchemas = import_zod2.z.discriminatedUnion("type", [
893
932
  ]);
894
933
 
895
934
  // src/hooks/use-coagent-state-render-bridge.tsx
896
- var import_react10 = require("@copilotkitnext/react");
897
- var import_react11 = require("react");
935
+ var import_react13 = require("@copilotkitnext/react");
936
+ var import_react14 = require("react");
898
937
  var import_shared3 = require("@copilotkit/shared");
899
938
  function getStateWithoutConstantKeys(state) {
939
+ if (!state)
940
+ return {};
900
941
  const _a = state, { messages, tools, copilotkit } = _a, stateWithoutConstantKeys = __objRest(_a, ["messages", "tools", "copilotkit"]);
901
942
  return stateWithoutConstantKeys;
902
943
  }
@@ -919,11 +960,11 @@ function useCoagentStateRenderBridge(agentId, props) {
919
960
  var _a;
920
961
  const { stateSnapshot, messageIndexInRun, message } = props;
921
962
  const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();
922
- const { agent } = (0, import_react10.useAgent)({ agentId });
923
- const [nodeName, setNodeName] = (0, import_react11.useState)(void 0);
963
+ const { agent } = (0, import_react13.useAgent)({ agentId });
964
+ const [nodeName, setNodeName] = (0, import_react14.useState)(void 0);
924
965
  const runId = (_a = props.runId) != null ? _a : message.runId;
925
966
  const effectiveRunId = runId || "pending";
926
- (0, import_react11.useEffect)(() => {
967
+ (0, import_react14.useEffect)(() => {
927
968
  if (!agent)
928
969
  return;
929
970
  const subscriber = {
@@ -943,10 +984,7 @@ function useCoagentStateRenderBridge(agentId, props) {
943
984
  unsubscribe();
944
985
  };
945
986
  }, [agentId, nodeName]);
946
- if (messageIndexInRun !== 0) {
947
- return null;
948
- }
949
- const getStateRender = (0, import_react11.useCallback)(
987
+ const getStateRender = (0, import_react14.useCallback)(
950
988
  (messageId) => {
951
989
  return Object.entries(coAgentStateRenders).find(([stateRenderId, stateRender]) => {
952
990
  if (claimsRef.current[messageId]) {
@@ -988,8 +1026,11 @@ function useCoagentStateRenderBridge(agentId, props) {
988
1026
  claimsRef.current[messageId] = { stateRenderId, runId: runId2 };
989
1027
  return true;
990
1028
  };
991
- return (0, import_react11.useMemo)(() => {
1029
+ return (0, import_react14.useMemo)(() => {
992
1030
  var _a2, _b, _c;
1031
+ if (messageIndexInRun !== 0) {
1032
+ return null;
1033
+ }
993
1034
  const [stateRenderId, stateRender] = (_a2 = getStateRender(message.id)) != null ? _a2 : [];
994
1035
  if (!stateRender || !stateRenderId) {
995
1036
  return null;
@@ -1036,7 +1077,8 @@ function useCoagentStateRenderBridge(agentId, props) {
1036
1077
  agent == null ? void 0 : agent.isRunning,
1037
1078
  nodeName,
1038
1079
  effectiveRunId,
1039
- message.id
1080
+ message.id,
1081
+ messageIndexInRun
1040
1082
  ]);
1041
1083
  }
1042
1084
  function CoAgentStateRenderBridge(props) {
@@ -1064,15 +1106,15 @@ function useConfigureSuggestions2(suggestions) {
1064
1106
  function useCopilotChatInternal({
1065
1107
  suggestions
1066
1108
  } = {}) {
1067
- var _a, _b, _c, _d;
1068
- const { copilotkit } = (0, import_react13.useCopilotKit)();
1109
+ var _a, _b, _c;
1110
+ const { copilotkit } = (0, import_react16.useCopilotKit)();
1069
1111
  const { threadId, agentSession } = useCopilotContext();
1070
- const existingConfig = (0, import_react13.useCopilotChatConfiguration)();
1071
- const [agentAvailable, setAgentAvailable] = (0, import_react12.useState)(false);
1112
+ const existingConfig = (0, import_react16.useCopilotChatConfiguration)();
1113
+ const [agentAvailable, setAgentAvailable] = (0, import_react15.useState)(false);
1072
1114
  useConfigureSuggestions2(suggestions);
1073
- const resolvedAgentId = (_b = (_a = agentSession == null ? void 0 : agentSession.agentName) != null ? _a : existingConfig == null ? void 0 : existingConfig.agentId) != null ? _b : "default";
1074
- const { agent } = (0, import_react13.useAgent)({ agentId: resolvedAgentId });
1075
- (0, import_react12.useEffect)(() => {
1115
+ const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
1116
+ const { agent } = (0, import_react16.useAgent)({ agentId: resolvedAgentId });
1117
+ (0, import_react15.useEffect)(() => {
1076
1118
  const connect = (agent2) => __async(this, null, function* () {
1077
1119
  setAgentAvailable(false);
1078
1120
  try {
@@ -1097,7 +1139,7 @@ function useCopilotChatInternal({
1097
1139
  agent == null ? void 0 : agent.setMessages([]);
1098
1140
  agent == null ? void 0 : agent.setState(null);
1099
1141
  };
1100
- const deleteMessage = (0, import_react12.useCallback)(
1142
+ const deleteMessage = (0, import_react15.useCallback)(
1101
1143
  (messageId) => {
1102
1144
  var _a2;
1103
1145
  const filteredMessages = ((_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []).filter(
@@ -1108,13 +1150,13 @@ function useCopilotChatInternal({
1108
1150
  [agent == null ? void 0 : agent.setMessages, agent == null ? void 0 : agent.messages]
1109
1151
  );
1110
1152
  const latestDelete = useUpdatedRef(deleteMessage);
1111
- const latestDeleteFunc = (0, import_react12.useCallback)(
1153
+ const latestDeleteFunc = (0, import_react15.useCallback)(
1112
1154
  (messageId) => {
1113
1155
  return latestDelete.current(messageId);
1114
1156
  },
1115
1157
  [latestDelete]
1116
1158
  );
1117
- const currentSuggestions = (0, import_react13.useSuggestions)({ agentId: resolvedAgentId });
1159
+ const currentSuggestions = (0, import_react16.useSuggestions)({ agentId: resolvedAgentId });
1118
1160
  const reload = useAsyncCallback(
1119
1161
  (reloadMessageId) => __async(this, null, function* () {
1120
1162
  var _a2;
@@ -1182,7 +1224,7 @@ function useCopilotChatInternal({
1182
1224
  [latestSendMessageFunc]
1183
1225
  );
1184
1226
  const latestSetMessages = useUpdatedRef(agent == null ? void 0 : agent.setMessages);
1185
- const latestSetMessagesFunc = (0, import_react12.useCallback)(
1227
+ const latestSetMessagesFunc = (0, import_react15.useCallback)(
1186
1228
  (messages) => {
1187
1229
  var _a2, _b2;
1188
1230
  if (messages.every((message) => message instanceof import_runtime_client_gql2.Message)) {
@@ -1200,24 +1242,24 @@ function useCopilotChatInternal({
1200
1242
  [latestReload]
1201
1243
  );
1202
1244
  const latestStop = useUpdatedRef(agent == null ? void 0 : agent.abortRun);
1203
- const latestStopFunc = (0, import_react12.useCallback)(() => {
1245
+ const latestStopFunc = (0, import_react15.useCallback)(() => {
1204
1246
  var _a2;
1205
1247
  return (_a2 = latestStop.current) == null ? void 0 : _a2.call(latestStop);
1206
1248
  }, [latestStop]);
1207
1249
  const latestReset = useUpdatedRef(reset);
1208
- const latestResetFunc = (0, import_react12.useCallback)(() => {
1250
+ const latestResetFunc = (0, import_react15.useCallback)(() => {
1209
1251
  return latestReset.current();
1210
1252
  }, [latestReset]);
1211
1253
  const lazyToolRendered = useLazyToolRenderer();
1212
- const renderCustomMessage = (0, import_react13.useRenderCustomMessages)();
1254
+ const renderCustomMessage = (0, import_react16.useRenderCustomMessages)();
1213
1255
  const legacyCustomMessageRenderer = useLegacyCoagentRenderer({
1214
1256
  copilotkit,
1215
1257
  agent,
1216
1258
  agentId: resolvedAgentId,
1217
- threadId: (_c = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _c : threadId
1259
+ threadId: (_b = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _b : threadId
1218
1260
  });
1219
- const allMessages = (_d = agent == null ? void 0 : agent.messages) != null ? _d : [];
1220
- const resolvedMessages = (0, import_react12.useMemo)(() => {
1261
+ const allMessages = (_c = agent == null ? void 0 : agent.messages) != null ? _c : [];
1262
+ const resolvedMessages = (0, import_react15.useMemo)(() => {
1221
1263
  let processedMessages = allMessages.map((message) => {
1222
1264
  if (message.role !== "assistant") {
1223
1265
  return message;
@@ -1245,31 +1287,13 @@ function useCopilotChatInternal({
1245
1287
  return message;
1246
1288
  });
1247
1289
  const hasAssistantMessages = processedMessages.some((msg) => msg.role === "assistant");
1248
- if (legacyCustomMessageRenderer && !hasAssistantMessages) {
1249
- const placeholderId = `coagent-state-render-${resolvedAgentId}`;
1250
- const placeholderMessage = {
1251
- id: placeholderId,
1252
- role: "assistant",
1253
- content: "",
1254
- name: "coagent-state-render"
1255
- };
1256
- processedMessages = [
1257
- ...processedMessages,
1258
- __spreadProps(__spreadValues({}, placeholderMessage), {
1259
- generativeUI: () => legacyCustomMessageRenderer({
1260
- message: placeholderMessage,
1261
- position: "before"
1262
- })
1263
- })
1264
- ];
1265
- }
1266
1290
  return processedMessages;
1267
1291
  }, [
1268
1292
  agent == null ? void 0 : agent.messages,
1269
1293
  lazyToolRendered,
1270
1294
  allMessages,
1271
1295
  renderCustomMessage,
1272
- legacyCustomMessageRenderer,
1296
+ // legacyCustomMessageRenderer,
1273
1297
  resolvedAgentId
1274
1298
  ]);
1275
1299
  return {
@@ -1281,7 +1305,7 @@ function useCopilotChatInternal({
1281
1305
  stopGeneration: latestStopFunc,
1282
1306
  reset: latestResetFunc,
1283
1307
  deleteMessage: latestDeleteFunc,
1284
- isAvailable: !agentAvailable,
1308
+ isAvailable: agentAvailable,
1285
1309
  isLoading: Boolean(agent == null ? void 0 : agent.isRunning),
1286
1310
  // mcpServers,
1287
1311
  // setMcpServers,
@@ -1298,8 +1322,8 @@ function useCopilotChatInternal({
1298
1322
  };
1299
1323
  }
1300
1324
  function useUpdatedRef(value) {
1301
- const ref = (0, import_react12.useRef)(value);
1302
- (0, import_react12.useEffect)(() => {
1325
+ const ref = (0, import_react15.useRef)(value);
1326
+ (0, import_react15.useEffect)(() => {
1303
1327
  ref.current = value;
1304
1328
  }, [value]);
1305
1329
  return ref;
@@ -1310,20 +1334,19 @@ function useLegacyCoagentRenderer({
1310
1334
  agentId,
1311
1335
  threadId
1312
1336
  }) {
1313
- return (0, import_react12.useMemo)(() => {
1337
+ return (0, import_react15.useMemo)(() => {
1314
1338
  if (!copilotkit || !agent) {
1315
1339
  return null;
1316
1340
  }
1317
1341
  return ({ message, position }) => {
1318
1342
  var _a;
1319
1343
  const effectiveThreadId = (_a = threadId != null ? threadId : agent.threadId) != null ? _a : "default";
1320
- const existingRunId = copilotkit.getRunIdForMessage(
1321
- agentId,
1322
- effectiveThreadId,
1323
- message.id
1324
- );
1344
+ const existingRunId = copilotkit.getRunIdForMessage(agentId, effectiveThreadId, message.id);
1325
1345
  const runId = existingRunId || `pending:${message.id}`;
1326
- const messageIndex = Math.max(agent.messages.findIndex((msg) => msg.id === message.id), 0);
1346
+ const messageIndex = Math.max(
1347
+ agent.messages.findIndex((msg) => msg.id === message.id),
1348
+ 0
1349
+ );
1327
1350
  const bridgeProps = {
1328
1351
  message,
1329
1352
  position,
@@ -1334,7 +1357,7 @@ function useLegacyCoagentRenderer({
1334
1357
  agentId,
1335
1358
  stateSnapshot: message.state
1336
1359
  };
1337
- return (0, import_react12.createElement)(CoAgentStateRenderBridge, bridgeProps);
1360
+ return (0, import_react15.createElement)(CoAgentStateRenderBridge, bridgeProps);
1338
1361
  };
1339
1362
  }, [agent, agentId, copilotkit, threadId]);
1340
1363
  }
@@ -1406,7 +1429,7 @@ function useCopilotChatHeadless_c(options = {}) {
1406
1429
  const { copilotApiConfig, setBannerError } = useCopilotContext();
1407
1430
  const hasPublicApiKey = Boolean(copilotApiConfig.publicApiKey);
1408
1431
  const internalResult = useCopilotChatInternal(options);
1409
- (0, import_react14.useEffect)(() => {
1432
+ (0, import_react17.useEffect)(() => {
1410
1433
  if (!hasPublicApiKey) {
1411
1434
  setBannerError(
1412
1435
  new import_shared4.CopilotKitError({