@copilotkit/react-core 1.5.15-next.3 → 1.5.15-next.4

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 (131) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/{chunk-DZCTHC4G.mjs → chunk-5SGZKEPX.mjs} +3 -3
  3. package/dist/chunk-6PNZ77RB.mjs +66 -0
  4. package/dist/chunk-6PNZ77RB.mjs.map +1 -0
  5. package/dist/{chunk-7QGQVBD7.mjs → chunk-7HWSAEOY.mjs} +2 -2
  6. package/dist/{chunk-YJT6IYNV.mjs → chunk-AL3MOOKF.mjs} +2 -2
  7. package/dist/{chunk-67W2A4DM.mjs → chunk-DEPX7JPX.mjs} +10 -6
  8. package/dist/chunk-DEPX7JPX.mjs.map +1 -0
  9. package/dist/{chunk-KGCYVAIN.mjs → chunk-FMROB4TE.mjs} +49 -10
  10. package/dist/chunk-FMROB4TE.mjs.map +1 -0
  11. package/dist/{chunk-PMHLIIAI.mjs → chunk-GANI4ZZM.mjs} +3 -3
  12. package/dist/{chunk-VEQGQAGN.mjs → chunk-H2OR7FUU.mjs} +2 -2
  13. package/dist/chunk-IGLITGLC.mjs +1 -0
  14. package/dist/{chunk-V74U56PX.mjs → chunk-IHWTLSHY.mjs} +2 -2
  15. package/dist/{chunk-TJTOQRGB.mjs → chunk-IU7OLWWW.mjs} +26 -6
  16. package/dist/chunk-IU7OLWWW.mjs.map +1 -0
  17. package/dist/{chunk-GPWNMXSU.mjs → chunk-WU53OU3E.mjs} +2 -2
  18. package/dist/{chunk-S5MSFDGS.mjs → chunk-XOHLZIZK.mjs} +2 -2
  19. package/dist/chunk-ZAU4EMBM.mjs +48 -0
  20. package/dist/chunk-ZAU4EMBM.mjs.map +1 -0
  21. package/dist/{chunk-RKYHRYN3.mjs → chunk-ZM56S3LJ.mjs} +5 -2
  22. package/dist/chunk-ZM56S3LJ.mjs.map +1 -0
  23. package/dist/components/copilot-provider/copilot-messages.js +4 -1
  24. package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
  25. package/dist/components/copilot-provider/copilot-messages.mjs +2 -2
  26. package/dist/components/copilot-provider/copilotkit-props.d.ts +1 -0
  27. package/dist/components/copilot-provider/copilotkit.d.ts +1 -0
  28. package/dist/components/copilot-provider/copilotkit.js +25 -2
  29. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  30. package/dist/components/copilot-provider/copilotkit.mjs +3 -3
  31. package/dist/components/copilot-provider/index.d.ts +1 -0
  32. package/dist/components/copilot-provider/index.js +25 -2
  33. package/dist/components/copilot-provider/index.js.map +1 -1
  34. package/dist/components/copilot-provider/index.mjs +3 -3
  35. package/dist/components/index.d.ts +1 -0
  36. package/dist/components/index.js +25 -2
  37. package/dist/components/index.js.map +1 -1
  38. package/dist/components/index.mjs +3 -3
  39. package/dist/context/copilot-context.d.ts +5 -1
  40. package/dist/context/copilot-context.js +4 -1
  41. package/dist/context/copilot-context.js.map +1 -1
  42. package/dist/context/copilot-context.mjs +1 -1
  43. package/dist/context/index.d.ts +1 -0
  44. package/dist/context/index.js +4 -1
  45. package/dist/context/index.js.map +1 -1
  46. package/dist/context/index.mjs +1 -1
  47. package/dist/hooks/index.d.ts +3 -0
  48. package/dist/hooks/index.js +150 -13
  49. package/dist/hooks/index.js.map +1 -1
  50. package/dist/hooks/index.mjs +20 -12
  51. package/dist/hooks/use-chat.d.ts +4 -1
  52. package/dist/hooks/use-chat.js +45 -7
  53. package/dist/hooks/use-chat.js.map +1 -1
  54. package/dist/hooks/use-chat.mjs +1 -1
  55. package/dist/hooks/use-coagent-state-render.js +4 -1
  56. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  57. package/dist/hooks/use-coagent-state-render.mjs +2 -2
  58. package/dist/hooks/use-coagent.d.ts +1 -0
  59. package/dist/hooks/use-coagent.js +58 -13
  60. package/dist/hooks/use-coagent.js.map +1 -1
  61. package/dist/hooks/use-coagent.mjs +6 -6
  62. package/dist/hooks/use-copilot-action.js +4 -1
  63. package/dist/hooks/use-copilot-action.js.map +1 -1
  64. package/dist/hooks/use-copilot-action.mjs +2 -2
  65. package/dist/hooks/use-copilot-authenticated-action.js +4 -1
  66. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
  67. package/dist/hooks/use-copilot-authenticated-action.mjs +3 -3
  68. package/dist/hooks/use-copilot-chat.d.ts +2 -1
  69. package/dist/hooks/use-copilot-chat.js +58 -13
  70. package/dist/hooks/use-copilot-chat.js.map +1 -1
  71. package/dist/hooks/use-copilot-chat.mjs +5 -5
  72. package/dist/hooks/use-copilot-readable.js +4 -1
  73. package/dist/hooks/use-copilot-readable.js.map +1 -1
  74. package/dist/hooks/use-copilot-readable.mjs +2 -2
  75. package/dist/hooks/use-langgraph-interrupt-render.d.ts +5 -0
  76. package/dist/hooks/use-langgraph-interrupt-render.js +184 -0
  77. package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -0
  78. package/dist/hooks/use-langgraph-interrupt-render.mjs +11 -0
  79. package/dist/hooks/use-langgraph-interrupt-render.mjs.map +1 -0
  80. package/dist/hooks/use-langgraph-interrupt.d.ts +7 -0
  81. package/dist/hooks/use-langgraph-interrupt.js +1050 -0
  82. package/dist/hooks/use-langgraph-interrupt.js.map +1 -0
  83. package/dist/hooks/use-langgraph-interrupt.mjs +25 -0
  84. package/dist/hooks/use-langgraph-interrupt.mjs.map +1 -0
  85. package/dist/hooks/use-make-copilot-document-readable.js +4 -1
  86. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  87. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  88. package/dist/index.d.ts +3 -0
  89. package/dist/index.js +178 -21
  90. package/dist/index.js.map +1 -1
  91. package/dist/index.mjs +21 -13
  92. package/dist/lib/copilot-task.d.ts +1 -0
  93. package/dist/lib/copilot-task.js.map +1 -1
  94. package/dist/lib/copilot-task.mjs +4 -4
  95. package/dist/lib/index.d.ts +1 -0
  96. package/dist/lib/index.js.map +1 -1
  97. package/dist/lib/index.mjs +4 -4
  98. package/dist/types/interrupt-action.d.ts +35 -0
  99. package/dist/types/interrupt-action.js +19 -0
  100. package/dist/types/interrupt-action.js.map +1 -0
  101. package/dist/types/interrupt-action.mjs +1 -0
  102. package/dist/types/interrupt-action.mjs.map +1 -0
  103. package/dist/utils/extract.d.ts +1 -0
  104. package/dist/utils/extract.js.map +1 -1
  105. package/dist/utils/extract.mjs +3 -3
  106. package/dist/utils/index.d.ts +1 -0
  107. package/dist/utils/index.js.map +1 -1
  108. package/dist/utils/index.mjs +3 -3
  109. package/package.json +3 -3
  110. package/src/components/copilot-provider/copilotkit.tsx +25 -0
  111. package/src/context/copilot-context.tsx +12 -3
  112. package/src/hooks/index.ts +2 -0
  113. package/src/hooks/use-chat.ts +52 -1
  114. package/src/hooks/use-copilot-chat.ts +4 -0
  115. package/src/hooks/use-langgraph-interrupt-render.ts +63 -0
  116. package/src/hooks/use-langgraph-interrupt.ts +62 -0
  117. package/src/types/interrupt-action.ts +35 -0
  118. package/dist/chunk-67W2A4DM.mjs.map +0 -1
  119. package/dist/chunk-KGCYVAIN.mjs.map +0 -1
  120. package/dist/chunk-NR2BTA6Z.mjs +0 -1
  121. package/dist/chunk-RKYHRYN3.mjs.map +0 -1
  122. package/dist/chunk-TJTOQRGB.mjs.map +0 -1
  123. /package/dist/{chunk-DZCTHC4G.mjs.map → chunk-5SGZKEPX.mjs.map} +0 -0
  124. /package/dist/{chunk-7QGQVBD7.mjs.map → chunk-7HWSAEOY.mjs.map} +0 -0
  125. /package/dist/{chunk-YJT6IYNV.mjs.map → chunk-AL3MOOKF.mjs.map} +0 -0
  126. /package/dist/{chunk-PMHLIIAI.mjs.map → chunk-GANI4ZZM.mjs.map} +0 -0
  127. /package/dist/{chunk-VEQGQAGN.mjs.map → chunk-H2OR7FUU.mjs.map} +0 -0
  128. /package/dist/{chunk-NR2BTA6Z.mjs.map → chunk-IGLITGLC.mjs.map} +0 -0
  129. /package/dist/{chunk-V74U56PX.mjs.map → chunk-IHWTLSHY.mjs.map} +0 -0
  130. /package/dist/{chunk-GPWNMXSU.mjs.map → chunk-WU53OU3E.mjs.map} +0 -0
  131. /package/dist/{chunk-S5MSFDGS.mjs.map → chunk-XOHLZIZK.mjs.map} +0 -0
package/dist/index.js CHANGED
@@ -100,6 +100,8 @@ __export(src_exports, {
100
100
  useCopilotMessagesContext: () => useCopilotMessagesContext,
101
101
  useCopilotReadable: () => useCopilotReadable,
102
102
  useCopilotRuntimeClient: () => useCopilotRuntimeClient,
103
+ useLangGraphInterrupt: () => useLangGraphInterrupt,
104
+ useLangGraphInterruptRender: () => useLangGraphInterruptRender,
103
105
  useMakeCopilotDocumentReadable: () => useMakeCopilotDocumentReadable
104
106
  });
105
107
  module.exports = __toCommonJS(src_exports);
@@ -174,7 +176,10 @@ var emptyCopilotContext = {
174
176
  availableAgents: [],
175
177
  extensions: {},
176
178
  setExtensions: () => {
177
- }
179
+ },
180
+ langGraphInterruptAction: null,
181
+ setLangGraphInterruptAction: () => null,
182
+ removeLangGraphInterruptAction: () => null
178
183
  };
179
184
  var CopilotContext = import_react.default.createContext(emptyCopilotContext);
180
185
  function useCopilotContext() {
@@ -1403,6 +1408,23 @@ ${nonDocumentStrings}`;
1403
1408
  const [runId, setRunId] = (0, import_react10.useState)(null);
1404
1409
  const chatAbortControllerRef = (0, import_react10.useRef)(null);
1405
1410
  const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
1411
+ const [langGraphInterruptAction, _setLangGraphInterruptAction] = (0, import_react10.useState)(null);
1412
+ const setLangGraphInterruptAction = (0, import_react10.useCallback)((action) => {
1413
+ _setLangGraphInterruptAction((prev) => {
1414
+ if (prev == null)
1415
+ return action;
1416
+ if (action == null)
1417
+ return null;
1418
+ let event = prev.event;
1419
+ if (action.event) {
1420
+ event = __spreadValues(__spreadValues({}, prev.event), action.event);
1421
+ }
1422
+ return __spreadProps(__spreadValues(__spreadValues({}, prev), action), { event });
1423
+ });
1424
+ }, []);
1425
+ const removeLangGraphInterruptAction = (0, import_react10.useCallback)(() => {
1426
+ setLangGraphInterruptAction(null);
1427
+ }, []);
1406
1428
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1407
1429
  CopilotContext.Provider,
1408
1430
  {
@@ -1449,7 +1471,10 @@ ${nonDocumentStrings}`;
1449
1471
  authStates_c: authStates,
1450
1472
  setAuthStates_c: setAuthStates,
1451
1473
  extensions,
1452
- setExtensions
1474
+ setExtensions,
1475
+ langGraphInterruptAction,
1476
+ setLangGraphInterruptAction,
1477
+ removeLangGraphInterruptAction
1453
1478
  },
1454
1479
  children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CopilotMessages, { children })
1455
1480
  }
@@ -1498,7 +1523,7 @@ function validateProps(props) {
1498
1523
 
1499
1524
  // src/hooks/use-copilot-chat.ts
1500
1525
  var import_react12 = require("react");
1501
- var import_runtime_client_gql7 = require("@copilotkit/runtime-client-gql");
1526
+ var import_runtime_client_gql8 = require("@copilotkit/runtime-client-gql");
1502
1527
 
1503
1528
  // src/hooks/use-chat.ts
1504
1529
  var import_react11 = require("react");
@@ -1531,6 +1556,7 @@ function processActionsForRuntimeRequest(actions) {
1531
1556
  }
1532
1557
 
1533
1558
  // src/hooks/use-chat.ts
1559
+ var import_runtime_client_gql7 = require("@copilotkit/runtime-client-gql");
1534
1560
  function useChat(options) {
1535
1561
  const {
1536
1562
  messages,
@@ -1554,7 +1580,9 @@ function useChat(options) {
1554
1580
  chatAbortControllerRef,
1555
1581
  agentLock,
1556
1582
  extensions,
1557
- setExtensions
1583
+ setExtensions,
1584
+ langGraphInterruptAction,
1585
+ setLangGraphInterruptAction
1558
1586
  } = options;
1559
1587
  const runChatCompletionRef = (0, import_react11.useRef)();
1560
1588
  const addErrorToast = useErrorToast();
@@ -1574,7 +1602,7 @@ function useChat(options) {
1574
1602
  });
1575
1603
  const runChatCompletion = useAsyncCallback(
1576
1604
  (previousMessages) => __async(this, null, function* () {
1577
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1605
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
1578
1606
  setIsLoading(true);
1579
1607
  let newMessages = [
1580
1608
  new import_runtime_client_gql6.TextMessage({
@@ -1597,6 +1625,7 @@ function useChat(options) {
1597
1625
  threadId,
1598
1626
  runId: runIdRef.current,
1599
1627
  extensions: extensionsRef.current,
1628
+ metaEvents: composeAndFlushMetaEventsInput([langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event]),
1600
1629
  messages: (0, import_runtime_client_gql6.convertMessagesToGqlInput)((0, import_runtime_client_gql6.filterAgentStateMessages)(messagesWithContext))
1601
1630
  }, copilotConfig.cloud ? {
1602
1631
  cloud: __spreadValues({}, ((_c = (_b = (_a = copilotConfig.cloud.guardrails) == null ? void 0 : _a.input) == null ? void 0 : _b.restrictToTopic) == null ? void 0 : _c.enabled) ? {
@@ -1658,15 +1687,22 @@ function useChat(options) {
1658
1687
  messages2 = (0, import_runtime_client_gql6.convertGqlOutputToMessages)(
1659
1688
  (0, import_runtime_client_gql6.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
1660
1689
  );
1690
+ ((_i = (_h = value.generateCopilotResponse) == null ? void 0 : _h.metaEvents) != null ? _i : []).forEach((ev) => {
1691
+ if (ev.name === "LangGraphInterruptEvent") {
1692
+ setLangGraphInterruptAction({
1693
+ event: (0, import_runtime_client_gql6.langGraphInterruptEvent)(ev)
1694
+ });
1695
+ }
1696
+ });
1661
1697
  if (messages2.length === 0) {
1662
1698
  continue;
1663
1699
  }
1664
1700
  newMessages = [];
1665
- if (((_h = value.generateCopilotResponse.status) == null ? void 0 : _h.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
1701
+ if (((_j = value.generateCopilotResponse.status) == null ? void 0 : _j.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
1666
1702
  newMessages = [
1667
1703
  new import_runtime_client_gql6.TextMessage({
1668
1704
  role: import_runtime_client_gql6.MessageRole.Assistant,
1669
- content: ((_i = value.generateCopilotResponse.status.details) == null ? void 0 : _i.guardrailsReason) || ""
1705
+ content: ((_k = value.generateCopilotResponse.status.details) == null ? void 0 : _k.guardrailsReason) || ""
1670
1706
  })
1671
1707
  ];
1672
1708
  setMessages([...previousMessages, ...newMessages]);
@@ -1804,11 +1840,11 @@ function useChat(options) {
1804
1840
  followUp !== false && // and we executed an action
1805
1841
  (didExecuteAction || // the last message is a server side result
1806
1842
  !isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
1807
- !((_j = chatAbortControllerRef.current) == null ? void 0 : _j.signal.aborted)
1843
+ !((_l = chatAbortControllerRef.current) == null ? void 0 : _l.signal.aborted)
1808
1844
  ) {
1809
1845
  yield new Promise((resolve) => setTimeout(resolve, 10));
1810
1846
  return yield runChatCompletionRef.current(finalMessages);
1811
- } else if ((_k = chatAbortControllerRef.current) == null ? void 0 : _k.signal.aborted) {
1847
+ } else if ((_m = chatAbortControllerRef.current) == null ? void 0 : _m.signal.aborted) {
1812
1848
  const repairedMessages = finalMessages.filter((message, actionExecutionIndex) => {
1813
1849
  if (message.isActionExecutionMessage()) {
1814
1850
  return finalMessages.find(
@@ -1819,7 +1855,7 @@ function useChat(options) {
1819
1855
  });
1820
1856
  const repairedMessageIds = repairedMessages.map((message) => message.id);
1821
1857
  setMessages(repairedMessages);
1822
- if ((_l = agentSessionRef.current) == null ? void 0 : _l.nodeName) {
1858
+ if ((_n = agentSessionRef.current) == null ? void 0 : _n.nodeName) {
1823
1859
  setAgentSession({
1824
1860
  threadId: agentSessionRef.current.threadId,
1825
1861
  agentName: agentSessionRef.current.agentName,
@@ -1858,6 +1894,33 @@ function useChat(options) {
1858
1894
  }),
1859
1895
  [messages]
1860
1896
  );
1897
+ const composeAndFlushMetaEventsInput = (0, import_react11.useCallback)(
1898
+ (metaEvents) => {
1899
+ return metaEvents.reduce((acc, event) => {
1900
+ if (!event)
1901
+ return acc;
1902
+ switch (event.name) {
1903
+ case import_runtime_client_gql7.MetaEventName.LangGraphInterruptEvent:
1904
+ if (event.response) {
1905
+ setLangGraphInterruptAction(null);
1906
+ return [
1907
+ ...acc,
1908
+ {
1909
+ type: event.type,
1910
+ name: event.name,
1911
+ value: event.value,
1912
+ response: event.response
1913
+ }
1914
+ ];
1915
+ }
1916
+ return acc;
1917
+ default:
1918
+ return acc;
1919
+ }
1920
+ }, []);
1921
+ },
1922
+ [setLangGraphInterruptAction]
1923
+ );
1861
1924
  const append = useAsyncCallback(
1862
1925
  (message, options2) => __async(this, null, function* () {
1863
1926
  var _a;
@@ -1942,7 +2005,9 @@ function useCopilotChat(_a = {}) {
1942
2005
  setRunId,
1943
2006
  chatAbortControllerRef,
1944
2007
  extensions,
1945
- setExtensions
2008
+ setExtensions,
2009
+ langGraphInterruptAction,
2010
+ setLangGraphInterruptAction
1946
2011
  } = useCopilotContext();
1947
2012
  const { messages, setMessages } = useCopilotMessagesContext();
1948
2013
  const latestGetContextString = useUpdatedRef(getContextString);
@@ -1955,9 +2020,9 @@ function useCopilotChat(_a = {}) {
1955
2020
  const makeSystemMessageCallback = (0, import_react12.useCallback)(() => {
1956
2021
  const systemMessageMaker = makeSystemMessage2 || defaultSystemMessage;
1957
2022
  const contextString = latestGetContextString.current([], defaultCopilotContextCategories);
1958
- return new import_runtime_client_gql7.TextMessage({
2023
+ return new import_runtime_client_gql8.TextMessage({
1959
2024
  content: systemMessageMaker(contextString, chatInstructions),
1960
- role: import_runtime_client_gql7.Role.System
2025
+ role: import_runtime_client_gql8.Role.System
1961
2026
  });
1962
2027
  }, [getContextString, makeSystemMessage2, chatInstructions]);
1963
2028
  const onCoAgentStateRender = useAsyncCallback(
@@ -2001,7 +2066,9 @@ function useCopilotChat(_a = {}) {
2001
2066
  chatAbortControllerRef,
2002
2067
  agentLock,
2003
2068
  extensions,
2004
- setExtensions
2069
+ setExtensions,
2070
+ langGraphInterruptAction,
2071
+ setLangGraphInterruptAction
2005
2072
  }));
2006
2073
  const latestAppend = useUpdatedRef(append);
2007
2074
  const latestAppendFunc = useAsyncCallback(
@@ -2479,8 +2546,96 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
2479
2546
  );
2480
2547
  }
2481
2548
 
2549
+ // src/hooks/use-langgraph-interrupt.ts
2550
+ var import_react20 = require("react");
2551
+ var import_shared12 = require("@copilotkit/shared");
2552
+ function useLangGraphInterrupt(action, dependencies) {
2553
+ var _a;
2554
+ const { setLangGraphInterruptAction, removeLangGraphInterruptAction, langGraphInterruptAction } = (0, import_react20.useContext)(CopilotContext);
2555
+ const { runChatCompletion } = useCopilotChat();
2556
+ const { addToast } = useToast();
2557
+ const actionId = (0, import_shared12.dataToUUID)(JSON.stringify(action), "lgAction");
2558
+ const hasAction = (0, import_react20.useMemo)(
2559
+ () => Boolean(langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id),
2560
+ [langGraphInterruptAction]
2561
+ );
2562
+ const isCurrentAction = (0, import_react20.useMemo)(
2563
+ () => (langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id) && (langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id) === actionId,
2564
+ [langGraphInterruptAction]
2565
+ );
2566
+ (0, import_react20.useEffect)(() => {
2567
+ var _a2;
2568
+ if (hasAction && isCurrentAction && ((_a2 = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event) == null ? void 0 : _a2.response)) {
2569
+ runChatCompletion();
2570
+ }
2571
+ }, [(_a = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event) == null ? void 0 : _a.response, runChatCompletion, hasAction, isCurrentAction]);
2572
+ (0, import_react20.useEffect)(() => {
2573
+ var _a2;
2574
+ if (!action)
2575
+ return;
2576
+ if (hasAction && !isCurrentAction && !((_a2 = action.conditions) == null ? void 0 : _a2.length)) {
2577
+ addToast({
2578
+ type: "warning",
2579
+ message: "An action is already registered for the interrupt event"
2580
+ });
2581
+ return;
2582
+ }
2583
+ if (hasAction && isCurrentAction) {
2584
+ return;
2585
+ }
2586
+ setLangGraphInterruptAction(__spreadProps(__spreadValues({}, action), { id: actionId }));
2587
+ }, [
2588
+ action,
2589
+ hasAction,
2590
+ isCurrentAction,
2591
+ setLangGraphInterruptAction,
2592
+ removeLangGraphInterruptAction,
2593
+ ...dependencies || []
2594
+ ]);
2595
+ }
2596
+
2597
+ // src/hooks/use-langgraph-interrupt-render.ts
2598
+ var import_react21 = __toESM(require("react"));
2599
+ var import_shared13 = require("@copilotkit/shared");
2600
+ var InterruptRenderer = ({ event, result, render, resolve }) => {
2601
+ return render({ event, result, resolve });
2602
+ };
2603
+ function useLangGraphInterruptRender() {
2604
+ const { langGraphInterruptAction, setLangGraphInterruptAction } = useCopilotContext();
2605
+ const responseRef = import_react21.default.useRef();
2606
+ const resolveInterrupt = (0, import_react21.useCallback)(
2607
+ (response) => {
2608
+ responseRef.current = response;
2609
+ setTimeout(() => {
2610
+ setLangGraphInterruptAction({ event: { response } });
2611
+ }, 0);
2612
+ },
2613
+ [setLangGraphInterruptAction]
2614
+ );
2615
+ if (!langGraphInterruptAction || !langGraphInterruptAction.event || !langGraphInterruptAction.render)
2616
+ return null;
2617
+ const { render, handler, event, conditions } = langGraphInterruptAction;
2618
+ const conditionsMet = (0, import_shared13.executeConditions)({ conditions, value: event.value });
2619
+ if (!conditionsMet) {
2620
+ return null;
2621
+ }
2622
+ let result = null;
2623
+ if (handler) {
2624
+ result = handler({
2625
+ event,
2626
+ resolve: resolveInterrupt
2627
+ });
2628
+ }
2629
+ return import_react21.default.createElement(InterruptRenderer, {
2630
+ event,
2631
+ result,
2632
+ render,
2633
+ resolve: resolveInterrupt
2634
+ });
2635
+ }
2636
+
2482
2637
  // src/lib/copilot-task.ts
2483
- var import_runtime_client_gql8 = require("@copilotkit/runtime-client-gql");
2638
+ var import_runtime_client_gql9 = require("@copilotkit/runtime-client-gql");
2484
2639
  var CopilotTask = class {
2485
2640
  constructor(config) {
2486
2641
  this.instructions = config.instructions;
@@ -2508,12 +2663,12 @@ var CopilotTask = class {
2508
2663
  if (this.includeCopilotReadable) {
2509
2664
  contextString += context.getContextString([], defaultCopilotContextCategories);
2510
2665
  }
2511
- const systemMessage = new import_runtime_client_gql8.TextMessage({
2666
+ const systemMessage = new import_runtime_client_gql9.TextMessage({
2512
2667
  content: taskSystemMessage(contextString, this.instructions),
2513
- role: import_runtime_client_gql8.Role.System
2668
+ role: import_runtime_client_gql9.Role.System
2514
2669
  });
2515
2670
  const messages = [systemMessage];
2516
- const runtimeClient = new import_runtime_client_gql8.CopilotRuntimeClient({
2671
+ const runtimeClient = new import_runtime_client_gql9.CopilotRuntimeClient({
2517
2672
  url: context.copilotApiConfig.chatApiEndpoint,
2518
2673
  publicApiKey: context.copilotApiConfig.publicApiKey,
2519
2674
  headers: context.copilotApiConfig.headers,
@@ -2525,9 +2680,9 @@ var CopilotTask = class {
2525
2680
  actions: processActionsForRuntimeRequest(Object.values(actions)),
2526
2681
  url: window.location.href
2527
2682
  },
2528
- messages: (0, import_runtime_client_gql8.convertMessagesToGqlInput)((0, import_runtime_client_gql8.filterAgentStateMessages)(messages)),
2683
+ messages: (0, import_runtime_client_gql9.convertMessagesToGqlInput)((0, import_runtime_client_gql9.filterAgentStateMessages)(messages)),
2529
2684
  metadata: {
2530
- requestType: import_runtime_client_gql8.CopilotRequestType.Task
2685
+ requestType: import_runtime_client_gql9.CopilotRequestType.Task
2531
2686
  },
2532
2687
  forwardedParameters: __spreadProps(__spreadValues({}, (_a = this.forwardedParameters) != null ? _a : {}), {
2533
2688
  toolChoice: "required"
@@ -2536,7 +2691,7 @@ var CopilotTask = class {
2536
2691
  properties: context.copilotApiConfig.properties
2537
2692
  }).toPromise();
2538
2693
  const functionCallHandler = context.getFunctionCallHandler(actions);
2539
- const functionCalls = (0, import_runtime_client_gql8.convertGqlOutputToMessages)(
2694
+ const functionCalls = (0, import_runtime_client_gql9.convertGqlOutputToMessages)(
2540
2695
  ((_c = (_b = response.data) == null ? void 0 : _b.generateCopilotResponse) == null ? void 0 : _c.messages) || []
2541
2696
  ).filter((m) => m.isActionExecutionMessage());
2542
2697
  for (const functionCall of functionCalls) {
@@ -2595,6 +2750,8 @@ ${instructions}
2595
2750
  useCopilotMessagesContext,
2596
2751
  useCopilotReadable,
2597
2752
  useCopilotRuntimeClient,
2753
+ useLangGraphInterrupt,
2754
+ useLangGraphInterruptRender,
2598
2755
  useMakeCopilotDocumentReadable
2599
2756
  });
2600
2757
  //# sourceMappingURL=index.js.map