@copilotkit/react-core 1.8.7 → 1.8.8-next.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 (115) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/{chunk-GOK4PDQO.mjs → chunk-2ZKWBDBN.mjs} +2 -2
  3. package/dist/{chunk-UR6DW5BN.mjs → chunk-477456TY.mjs} +2 -2
  4. package/dist/{chunk-7VCWAAWC.mjs → chunk-4EXRQ5D5.mjs} +2 -2
  5. package/dist/{chunk-UDUFMGWQ.mjs → chunk-7WG4MNRX.mjs} +1 -1
  6. package/dist/chunk-7WG4MNRX.mjs.map +1 -0
  7. package/dist/{chunk-7HP5NS5T.mjs → chunk-A4DYMTV4.mjs} +3 -3
  8. package/dist/{chunk-5TVV6FJD.mjs → chunk-B3CERZDI.mjs} +2 -2
  9. package/dist/{chunk-KF5SB2VB.mjs → chunk-GBAZTXPQ.mjs} +2 -2
  10. package/dist/{chunk-JWE4IXSG.mjs → chunk-INRN7B2F.mjs} +2 -2
  11. package/dist/{chunk-Y3N54L72.mjs → chunk-IWOK6HLS.mjs} +36 -21
  12. package/dist/chunk-IWOK6HLS.mjs.map +1 -0
  13. package/dist/{chunk-JF5EIUQ7.mjs → chunk-K5FB4UFF.mjs} +2 -2
  14. package/dist/{chunk-KAMKS5U6.mjs → chunk-LDZIBBRX.mjs} +4 -6
  15. package/dist/chunk-LDZIBBRX.mjs.map +1 -0
  16. package/dist/{chunk-DMQB35FC.mjs → chunk-OSVDTMKA.mjs} +2 -2
  17. package/dist/{chunk-FRRPZKXW.mjs → chunk-W3QHAZKD.mjs} +3 -3
  18. package/dist/{chunk-FNTV7DBR.mjs → chunk-YN3P6OCX.mjs} +3 -3
  19. package/dist/{chunk-6OMSQLHC.mjs → chunk-ZXJHNU6Q.mjs} +20 -13
  20. package/dist/chunk-ZXJHNU6Q.mjs.map +1 -0
  21. package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
  22. package/dist/components/copilot-provider/copilot-messages.mjs +2 -2
  23. package/dist/components/copilot-provider/copilotkit-props.d.ts +1 -18
  24. package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
  25. package/dist/components/copilot-provider/copilotkit.d.ts +1 -1
  26. package/dist/components/copilot-provider/copilotkit.js +1 -3
  27. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  28. package/dist/components/copilot-provider/copilotkit.mjs +3 -3
  29. package/dist/components/copilot-provider/index.d.ts +1 -1
  30. package/dist/components/copilot-provider/index.js +1 -3
  31. package/dist/components/copilot-provider/index.js.map +1 -1
  32. package/dist/components/copilot-provider/index.mjs +3 -3
  33. package/dist/components/index.d.ts +1 -1
  34. package/dist/components/index.js +1 -3
  35. package/dist/components/index.js.map +1 -1
  36. package/dist/components/index.mjs +3 -3
  37. package/dist/context/copilot-context.d.ts +1 -1
  38. package/dist/context/copilot-context.js.map +1 -1
  39. package/dist/context/copilot-context.mjs +1 -1
  40. package/dist/context/index.d.ts +1 -1
  41. package/dist/context/index.js.map +1 -1
  42. package/dist/context/index.mjs +1 -1
  43. package/dist/{copilot-context-0e923eb1.d.ts → copilot-context-8fb74a85.d.ts} +1 -1
  44. package/dist/hooks/index.d.ts +1 -1
  45. package/dist/hooks/index.js +50 -28
  46. package/dist/hooks/index.js.map +1 -1
  47. package/dist/hooks/index.mjs +14 -14
  48. package/dist/hooks/use-chat.d.ts +1 -1
  49. package/dist/hooks/use-chat.js +19 -12
  50. package/dist/hooks/use-chat.js.map +1 -1
  51. package/dist/hooks/use-chat.mjs +1 -1
  52. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  53. package/dist/hooks/use-coagent-state-render.mjs +2 -2
  54. package/dist/hooks/use-coagent.d.ts +1 -1
  55. package/dist/hooks/use-coagent.js +50 -28
  56. package/dist/hooks/use-coagent.js.map +1 -1
  57. package/dist/hooks/use-coagent.mjs +6 -6
  58. package/dist/hooks/use-copilot-action.js.map +1 -1
  59. package/dist/hooks/use-copilot-action.mjs +2 -2
  60. package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
  61. package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
  62. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
  63. package/dist/hooks/use-copilot-authenticated-action.mjs +3 -3
  64. package/dist/hooks/use-copilot-chat.d.ts +8 -2
  65. package/dist/hooks/use-copilot-chat.js +50 -28
  66. package/dist/hooks/use-copilot-chat.js.map +1 -1
  67. package/dist/hooks/use-copilot-chat.mjs +5 -5
  68. package/dist/hooks/use-copilot-readable.js.map +1 -1
  69. package/dist/hooks/use-copilot-readable.mjs +2 -2
  70. package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
  71. package/dist/hooks/use-langgraph-interrupt-render.mjs +2 -2
  72. package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
  73. package/dist/hooks/use-langgraph-interrupt.js +50 -28
  74. package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
  75. package/dist/hooks/use-langgraph-interrupt.mjs +6 -6
  76. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  77. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  78. package/dist/index.d.ts +1 -1
  79. package/dist/index.js +51 -31
  80. package/dist/index.js.map +1 -1
  81. package/dist/index.mjs +15 -15
  82. package/dist/lib/copilot-task.d.ts +1 -1
  83. package/dist/lib/copilot-task.js.map +1 -1
  84. package/dist/lib/copilot-task.mjs +4 -4
  85. package/dist/lib/index.d.ts +1 -1
  86. package/dist/lib/index.js.map +1 -1
  87. package/dist/lib/index.mjs +4 -4
  88. package/dist/types/interrupt-action.d.ts +1 -1
  89. package/dist/utils/extract.d.ts +1 -1
  90. package/dist/utils/extract.js.map +1 -1
  91. package/dist/utils/extract.mjs +3 -3
  92. package/dist/utils/index.d.ts +1 -1
  93. package/dist/utils/index.js.map +1 -1
  94. package/dist/utils/index.mjs +3 -3
  95. package/package.json +3 -3
  96. package/src/components/copilot-provider/copilotkit-props.tsx +0 -16
  97. package/src/components/copilot-provider/copilotkit.tsx +0 -2
  98. package/src/context/copilot-context.tsx +1 -1
  99. package/src/hooks/use-chat.ts +30 -4
  100. package/src/hooks/use-copilot-chat.ts +52 -27
  101. package/dist/chunk-6OMSQLHC.mjs.map +0 -1
  102. package/dist/chunk-KAMKS5U6.mjs.map +0 -1
  103. package/dist/chunk-UDUFMGWQ.mjs.map +0 -1
  104. package/dist/chunk-Y3N54L72.mjs.map +0 -1
  105. /package/dist/{chunk-GOK4PDQO.mjs.map → chunk-2ZKWBDBN.mjs.map} +0 -0
  106. /package/dist/{chunk-UR6DW5BN.mjs.map → chunk-477456TY.mjs.map} +0 -0
  107. /package/dist/{chunk-7VCWAAWC.mjs.map → chunk-4EXRQ5D5.mjs.map} +0 -0
  108. /package/dist/{chunk-7HP5NS5T.mjs.map → chunk-A4DYMTV4.mjs.map} +0 -0
  109. /package/dist/{chunk-5TVV6FJD.mjs.map → chunk-B3CERZDI.mjs.map} +0 -0
  110. /package/dist/{chunk-KF5SB2VB.mjs.map → chunk-GBAZTXPQ.mjs.map} +0 -0
  111. /package/dist/{chunk-JWE4IXSG.mjs.map → chunk-INRN7B2F.mjs.map} +0 -0
  112. /package/dist/{chunk-JF5EIUQ7.mjs.map → chunk-K5FB4UFF.mjs.map} +0 -0
  113. /package/dist/{chunk-DMQB35FC.mjs.map → chunk-OSVDTMKA.mjs.map} +0 -0
  114. /package/dist/{chunk-FRRPZKXW.mjs.map → chunk-W3QHAZKD.mjs.map} +0 -0
  115. /package/dist/{chunk-FNTV7DBR.mjs.map → chunk-YN3P6OCX.mjs.map} +0 -0
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  useCoAgentStateRender
3
- } from "../chunk-5TVV6FJD.mjs";
4
- import "../chunk-UDUFMGWQ.mjs";
3
+ } from "../chunk-B3CERZDI.mjs";
4
+ import "../chunk-7WG4MNRX.mjs";
5
5
  import "../chunk-22ENANUU.mjs";
6
6
  import "../chunk-O7ARI5CV.mjs";
7
7
  import "../chunk-SKC7AJIV.mjs";
@@ -1,4 +1,4 @@
1
- import { a as CopilotContextParams } from '../copilot-context-0e923eb1.js';
1
+ import { a as CopilotContextParams } from '../copilot-context-8fb74a85.js';
2
2
  import { CopilotMessagesContextParams } from '../context/copilot-messages-context.js';
3
3
  import { Message } from '@copilotkit/runtime-client-gql';
4
4
  import '@copilotkit/shared';
@@ -426,7 +426,7 @@ function useChat(options) {
426
426
  });
427
427
  const runChatCompletion = useAsyncCallback(
428
428
  (previousMessages) => __async(this, null, function* () {
429
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
429
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
430
430
  setIsLoading(true);
431
431
  const interruptEvent = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event;
432
432
  if ((interruptEvent == null ? void 0 : interruptEvent.name) === import_runtime_client_gql3.MetaEventName.LangGraphInterruptEvent && (interruptEvent == null ? void 0 : interruptEvent.value) && !(interruptEvent == null ? void 0 : interruptEvent.response) && agentSessionRef.current) {
@@ -447,8 +447,15 @@ function useChat(options) {
447
447
  const systemMessage = makeSystemMessageCallback();
448
448
  const messagesWithContext = [systemMessage, ...initialMessages || [], ...previousMessages];
449
449
  const finalProperties = __spreadValues({}, copilotConfig.properties || {});
450
- if (copilotConfig.mcpEndpoints && copilotConfig.mcpEndpoints.length > 0) {
451
- finalProperties.mcpEndpoints = copilotConfig.mcpEndpoints;
450
+ let mcpServersToUse = null;
451
+ if (copilotConfig.mcpServers && Array.isArray(copilotConfig.mcpServers) && copilotConfig.mcpServers.length > 0) {
452
+ mcpServersToUse = copilotConfig.mcpServers;
453
+ } else if (((_a = copilotConfig.properties) == null ? void 0 : _a.mcpServers) && Array.isArray(copilotConfig.properties.mcpServers) && copilotConfig.properties.mcpServers.length > 0) {
454
+ mcpServersToUse = copilotConfig.properties.mcpServers;
455
+ }
456
+ if (mcpServersToUse) {
457
+ finalProperties.mcpServers = mcpServersToUse;
458
+ copilotConfig.mcpServers = mcpServersToUse;
452
459
  }
453
460
  const isAgentRun = agentSessionRef.current !== null;
454
461
  const stream = runtimeClient.asStream(
@@ -464,7 +471,7 @@ function useChat(options) {
464
471
  metaEvents: composeAndFlushMetaEventsInput([langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event]),
465
472
  messages: (0, import_runtime_client_gql3.convertMessagesToGqlInput)((0, import_runtime_client_gql3.filterAgentStateMessages)(messagesWithContext))
466
473
  }, copilotConfig.cloud ? {
467
- cloud: __spreadValues({}, ((_c = (_b = (_a = copilotConfig.cloud.guardrails) == null ? void 0 : _a.input) == null ? void 0 : _b.restrictToTopic) == null ? void 0 : _c.enabled) ? {
474
+ cloud: __spreadValues({}, ((_d = (_c = (_b = copilotConfig.cloud.guardrails) == null ? void 0 : _b.input) == null ? void 0 : _c.restrictToTopic) == null ? void 0 : _d.enabled) ? {
468
475
  guardrails: {
469
476
  inputValidationRules: {
470
477
  allowList: copilotConfig.cloud.guardrails.input.restrictToTopic.validTopics,
@@ -490,10 +497,10 @@ function useChat(options) {
490
497
  forwardedParameters: options.forwardedParameters || {}
491
498
  }),
492
499
  properties: finalProperties,
493
- signal: (_d = chatAbortControllerRef.current) == null ? void 0 : _d.signal
500
+ signal: (_e = chatAbortControllerRef.current) == null ? void 0 : _e.signal
494
501
  })
495
502
  );
496
- const guardrailsEnabled = ((_g = (_f = (_e = copilotConfig.cloud) == null ? void 0 : _e.guardrails) == null ? void 0 : _f.input) == null ? void 0 : _g.restrictToTopic.enabled) || false;
503
+ const guardrailsEnabled = ((_h = (_g = (_f = copilotConfig.cloud) == null ? void 0 : _f.guardrails) == null ? void 0 : _g.input) == null ? void 0 : _h.restrictToTopic.enabled) || false;
497
504
  const reader = stream.getReader();
498
505
  let executedCoAgentStateRenders = [];
499
506
  let followUp = void 0;
@@ -526,7 +533,7 @@ function useChat(options) {
526
533
  setRunId(runIdRef.current);
527
534
  setExtensions(extensionsRef.current);
528
535
  let rawMessagesResponse = value.generateCopilotResponse.messages;
529
- const metaEvents = (_i = (_h = value.generateCopilotResponse) == null ? void 0 : _h.metaEvents) != null ? _i : [];
536
+ const metaEvents = (_j = (_i = value.generateCopilotResponse) == null ? void 0 : _i.metaEvents) != null ? _j : [];
530
537
  (metaEvents != null ? metaEvents : []).forEach((ev) => {
531
538
  if (ev.name === import_runtime_client_gql3.MetaEventName.LangGraphInterruptEvent) {
532
539
  let eventValue = (0, import_runtime_client_gql3.langGraphInterruptEvent)(ev).value;
@@ -553,11 +560,11 @@ function useChat(options) {
553
560
  continue;
554
561
  }
555
562
  newMessages = [];
556
- if (((_j = value.generateCopilotResponse.status) == null ? void 0 : _j.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
563
+ if (((_k = value.generateCopilotResponse.status) == null ? void 0 : _k.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
557
564
  newMessages = [
558
565
  new import_runtime_client_gql3.TextMessage({
559
566
  role: import_runtime_client_gql3.MessageRole.Assistant,
560
- content: ((_k = value.generateCopilotResponse.status.details) == null ? void 0 : _k.guardrailsReason) || ""
567
+ content: ((_l = value.generateCopilotResponse.status.details) == null ? void 0 : _l.guardrailsReason) || ""
561
568
  })
562
569
  ];
563
570
  setMessages([...previousMessages, ...newMessages]);
@@ -692,11 +699,11 @@ function useChat(options) {
692
699
  followUp !== false && // and we executed an action
693
700
  (didExecuteAction || // the last message is a server side result
694
701
  !isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
695
- !((_l = chatAbortControllerRef.current) == null ? void 0 : _l.signal.aborted)
702
+ !((_m = chatAbortControllerRef.current) == null ? void 0 : _m.signal.aborted)
696
703
  ) {
697
704
  yield new Promise((resolve) => setTimeout(resolve, 10));
698
705
  return yield runChatCompletionRef.current(finalMessages);
699
- } else if ((_m = chatAbortControllerRef.current) == null ? void 0 : _m.signal.aborted) {
706
+ } else if ((_n = chatAbortControllerRef.current) == null ? void 0 : _n.signal.aborted) {
700
707
  const repairedMessages = finalMessages.filter((message, actionExecutionIndex) => {
701
708
  if (message.isActionExecutionMessage()) {
702
709
  return finalMessages.find(
@@ -707,7 +714,7 @@ function useChat(options) {
707
714
  });
708
715
  const repairedMessageIds = repairedMessages.map((message) => message.id);
709
716
  setMessages(repairedMessages);
710
- if ((_n = agentSessionRef.current) == null ? void 0 : _n.nodeName) {
717
+ if ((_o = agentSessionRef.current) == null ? void 0 : _o.nodeName) {
711
718
  setAgentSession({
712
719
  threadId: agentSessionRef.current.threadId,
713
720
  agentName: agentSessionRef.current.agentName,
@@ -937,21 +944,20 @@ function useCopilotChat(_a = {}) {
937
944
  setLangGraphInterruptAction
938
945
  } = useCopilotContext();
939
946
  const { messages, setMessages } = useCopilotMessagesContext();
940
- const latestGetContextString = useUpdatedRef(getContextString);
941
- const deleteMessage = (0, import_react8.useCallback)(
942
- (messageId) => {
943
- setMessages((prev) => prev.filter((message) => message.id !== messageId));
944
- },
945
- [setMessages]
946
- );
947
- const makeSystemMessageCallback = (0, import_react8.useCallback)(() => {
948
- const systemMessageMaker = makeSystemMessage || defaultSystemMessage;
949
- const contextString = latestGetContextString.current([], defaultCopilotContextCategories);
950
- return new import_runtime_client_gql4.TextMessage({
951
- content: systemMessageMaker(contextString, chatInstructions),
952
- role: import_runtime_client_gql4.Role.System
953
- });
954
- }, [getContextString, makeSystemMessage, chatInstructions]);
947
+ const [mcpServers, setLocalMcpServers] = (0, import_react8.useState)([]);
948
+ (0, import_react8.useEffect)(() => {
949
+ if (mcpServers.length > 0) {
950
+ const serversCopy = [...mcpServers];
951
+ copilotApiConfig.mcpServers = serversCopy;
952
+ if (!copilotApiConfig.properties) {
953
+ copilotApiConfig.properties = {};
954
+ }
955
+ copilotApiConfig.properties.mcpServers = serversCopy;
956
+ }
957
+ }, [mcpServers, copilotApiConfig]);
958
+ const setMcpServers = (0, import_react8.useCallback)((servers) => {
959
+ setLocalMcpServers(servers);
960
+ }, []);
955
961
  const onCoAgentStateRender = useAsyncCallback(
956
962
  (args) => __async(this, null, function* () {
957
963
  var _a2;
@@ -970,6 +976,20 @@ function useCopilotChat(_a = {}) {
970
976
  }),
971
977
  [coAgentStateRenders]
972
978
  );
979
+ const makeSystemMessageCallback = (0, import_react8.useCallback)(() => {
980
+ const systemMessageMaker = makeSystemMessage || defaultSystemMessage;
981
+ const contextString = getContextString([], defaultCopilotContextCategories);
982
+ return new import_runtime_client_gql4.TextMessage({
983
+ content: systemMessageMaker(contextString, chatInstructions),
984
+ role: import_runtime_client_gql4.Role.System
985
+ });
986
+ }, [getContextString, makeSystemMessage, chatInstructions]);
987
+ const deleteMessage = (0, import_react8.useCallback)(
988
+ (messageId) => {
989
+ setMessages((prev) => prev.filter((message) => message.id !== messageId));
990
+ },
991
+ [setMessages]
992
+ );
973
993
  const { append, reload, stop, runChatCompletion } = useChat(__spreadProps(__spreadValues({}, options), {
974
994
  actions: Object.values(actions),
975
995
  copilotConfig: copilotApiConfig,
@@ -1066,7 +1086,9 @@ function useCopilotChat(_a = {}) {
1066
1086
  reset: latestResetFunc,
1067
1087
  deleteMessage: latestDeleteFunc,
1068
1088
  runChatCompletion: latestRunChatCompletionFunc,
1069
- isLoading
1089
+ isLoading,
1090
+ mcpServers,
1091
+ setMcpServers
1070
1092
  };
1071
1093
  }
1072
1094
  function useUpdatedRef(value) {