@copilotkit/react-core 1.10.5-next.0 → 1.10.5-next.10

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 (153) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/dist/{chunk-6INCKUL6.mjs → chunk-3N4MVKFZ.mjs} +32 -18
  3. package/dist/chunk-3N4MVKFZ.mjs.map +1 -0
  4. package/dist/{chunk-CLQLVMW4.mjs → chunk-3WUDRJTT.mjs} +2 -2
  5. package/dist/{chunk-AGP7SAEE.mjs → chunk-7LTRT3IV.mjs} +4 -4
  6. package/dist/{chunk-CXDK6XA5.mjs → chunk-BBUQMG45.mjs} +2 -2
  7. package/dist/{chunk-G2GQX4FI.mjs → chunk-CUWOXXM5.mjs} +3 -3
  8. package/dist/{chunk-YHT6CWIY.mjs → chunk-EUX2P2E7.mjs} +5 -3
  9. package/dist/{chunk-YHT6CWIY.mjs.map → chunk-EUX2P2E7.mjs.map} +1 -1
  10. package/dist/{chunk-4JBVPOHK.mjs → chunk-GIGUZ2OK.mjs} +3 -3
  11. package/dist/{chunk-36FJAVOF.mjs → chunk-HDOG2RTM.mjs} +2 -2
  12. package/dist/{chunk-AR7HJPGU.mjs → chunk-HI6SPUOX.mjs} +2 -2
  13. package/dist/{chunk-FCRODLLL.mjs → chunk-HYJUBYMU.mjs} +5 -5
  14. package/dist/{chunk-7D4OASUM.mjs → chunk-IHV5PTID.mjs} +2 -2
  15. package/dist/{chunk-7LZXD5RJ.mjs → chunk-ITDKIB5E.mjs} +30 -23
  16. package/dist/chunk-ITDKIB5E.mjs.map +1 -0
  17. package/dist/{chunk-KA3NCZEJ.mjs → chunk-JBACWIFW.mjs} +2 -2
  18. package/dist/{chunk-HHLBUGRA.mjs → chunk-JCHRWCYH.mjs} +3 -3
  19. package/dist/{chunk-NALRM7KT.mjs → chunk-L5MS4UDD.mjs} +11 -5
  20. package/dist/chunk-L5MS4UDD.mjs.map +1 -0
  21. package/dist/{chunk-MY2BUA6F.mjs → chunk-M37URBJS.mjs} +2 -2
  22. package/dist/{chunk-MZ37BAAE.mjs → chunk-MGWRDFBE.mjs} +2 -2
  23. package/dist/{chunk-23SOG4FI.mjs → chunk-TUTNHDM3.mjs} +2 -2
  24. package/dist/{chunk-QF3Q5LUN.mjs → chunk-ZVOLWJCY.mjs} +5 -5
  25. package/dist/chunk-ZVOLWJCY.mjs.map +1 -0
  26. package/dist/components/copilot-provider/copilot-messages.js +4 -2
  27. package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
  28. package/dist/components/copilot-provider/copilot-messages.mjs +2 -2
  29. package/dist/components/copilot-provider/copilotkit-props.d.ts +1 -1
  30. package/dist/components/copilot-provider/copilotkit.d.ts +1 -1
  31. package/dist/components/copilot-provider/copilotkit.js +30 -21
  32. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  33. package/dist/components/copilot-provider/copilotkit.mjs +5 -5
  34. package/dist/components/copilot-provider/index.d.ts +1 -1
  35. package/dist/components/copilot-provider/index.js +30 -21
  36. package/dist/components/copilot-provider/index.js.map +1 -1
  37. package/dist/components/copilot-provider/index.mjs +5 -5
  38. package/dist/components/dev-console/console-trigger.js +4 -2
  39. package/dist/components/dev-console/console-trigger.js.map +1 -1
  40. package/dist/components/dev-console/console-trigger.mjs +3 -3
  41. package/dist/components/dev-console/developer-console-modal.js +4 -2
  42. package/dist/components/dev-console/developer-console-modal.js.map +1 -1
  43. package/dist/components/dev-console/developer-console-modal.mjs +2 -2
  44. package/dist/components/index.d.ts +1 -1
  45. package/dist/components/index.js +30 -21
  46. package/dist/components/index.js.map +1 -1
  47. package/dist/components/index.mjs +5 -5
  48. package/dist/context/copilot-context.d.ts +1 -1
  49. package/dist/context/copilot-context.js +4 -2
  50. package/dist/context/copilot-context.js.map +1 -1
  51. package/dist/context/copilot-context.mjs +1 -1
  52. package/dist/context/copilot-messages-context.d.ts +2 -2
  53. package/dist/context/index.d.ts +2 -2
  54. package/dist/context/index.js +4 -2
  55. package/dist/context/index.js.map +1 -1
  56. package/dist/context/index.mjs +1 -1
  57. package/dist/{copilot-context-59740e82.d.ts → copilot-context-cf9de848.d.ts} +2 -2
  58. package/dist/hooks/index.d.ts +2 -2
  59. package/dist/hooks/index.js +44 -22
  60. package/dist/hooks/index.js.map +1 -1
  61. package/dist/hooks/index.mjs +18 -18
  62. package/dist/hooks/use-chat.d.ts +1 -1
  63. package/dist/hooks/use-chat.js +33 -17
  64. package/dist/hooks/use-chat.js.map +1 -1
  65. package/dist/hooks/use-chat.mjs +2 -2
  66. package/dist/hooks/use-coagent-state-render.js +4 -2
  67. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  68. package/dist/hooks/use-coagent-state-render.mjs +2 -2
  69. package/dist/hooks/use-coagent.d.ts +1 -1
  70. package/dist/hooks/use-coagent.js +36 -20
  71. package/dist/hooks/use-coagent.js.map +1 -1
  72. package/dist/hooks/use-coagent.mjs +9 -9
  73. package/dist/hooks/use-copilot-action.js +4 -2
  74. package/dist/hooks/use-copilot-action.js.map +1 -1
  75. package/dist/hooks/use-copilot-action.mjs +2 -2
  76. package/dist/hooks/use-copilot-additional-instructions.js +4 -2
  77. package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
  78. package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
  79. package/dist/hooks/use-copilot-authenticated-action.js +4 -2
  80. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
  81. package/dist/hooks/use-copilot-authenticated-action.mjs +3 -3
  82. package/dist/hooks/use-copilot-chat-headless_c.d.ts +2 -2
  83. package/dist/hooks/use-copilot-chat-headless_c.js +36 -20
  84. package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -1
  85. package/dist/hooks/use-copilot-chat-headless_c.mjs +9 -9
  86. package/dist/hooks/use-copilot-chat.d.ts +2 -2
  87. package/dist/hooks/use-copilot-chat.js +36 -20
  88. package/dist/hooks/use-copilot-chat.js.map +1 -1
  89. package/dist/hooks/use-copilot-chat.mjs +9 -9
  90. package/dist/hooks/use-copilot-chat_internal.d.ts +2 -2
  91. package/dist/hooks/use-copilot-chat_internal.js +36 -20
  92. package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
  93. package/dist/hooks/use-copilot-chat_internal.mjs +8 -8
  94. package/dist/hooks/use-copilot-readable.js +4 -2
  95. package/dist/hooks/use-copilot-readable.js.map +1 -1
  96. package/dist/hooks/use-copilot-readable.mjs +2 -2
  97. package/dist/hooks/use-langgraph-interrupt-render.js +7 -5
  98. package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
  99. package/dist/hooks/use-langgraph-interrupt-render.mjs +2 -2
  100. package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
  101. package/dist/hooks/use-langgraph-interrupt.js +44 -22
  102. package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
  103. package/dist/hooks/use-langgraph-interrupt.mjs +9 -9
  104. package/dist/hooks/use-make-copilot-document-readable.js +4 -2
  105. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  106. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  107. package/dist/{index-d1743abe.d.ts → index-1f5b66ac.d.ts} +1 -1
  108. package/dist/index.d.ts +2 -2
  109. package/dist/index.js +70 -41
  110. package/dist/index.js.map +1 -1
  111. package/dist/index.mjs +19 -19
  112. package/dist/lib/copilot-task.d.ts +1 -1
  113. package/dist/lib/copilot-task.js.map +1 -1
  114. package/dist/lib/copilot-task.mjs +6 -6
  115. package/dist/lib/index.d.ts +1 -1
  116. package/dist/lib/index.js.map +1 -1
  117. package/dist/lib/index.mjs +6 -6
  118. package/dist/types/interrupt-action.d.ts +1 -1
  119. package/dist/types/interrupt-action.js.map +1 -1
  120. package/dist/utils/extract.d.ts +2 -2
  121. package/dist/utils/extract.js.map +1 -1
  122. package/dist/utils/extract.mjs +5 -5
  123. package/dist/utils/index.d.ts +2 -2
  124. package/dist/utils/index.js.map +1 -1
  125. package/dist/utils/index.mjs +5 -5
  126. package/dist/utils/suggestions.d.ts +2 -2
  127. package/dist/utils/suggestions.js.map +1 -1
  128. package/dist/utils/suggestions.mjs +5 -5
  129. package/package.json +3 -3
  130. package/src/components/copilot-provider/copilotkit.tsx +27 -17
  131. package/src/context/copilot-context.tsx +3 -3
  132. package/src/hooks/use-chat.ts +27 -11
  133. package/src/hooks/use-langgraph-interrupt-render.ts +4 -3
  134. package/src/hooks/use-langgraph-interrupt.ts +8 -3
  135. package/src/types/interrupt-action.ts +4 -1
  136. package/dist/chunk-6INCKUL6.mjs.map +0 -1
  137. package/dist/chunk-7LZXD5RJ.mjs.map +0 -1
  138. package/dist/chunk-NALRM7KT.mjs.map +0 -1
  139. package/dist/chunk-QF3Q5LUN.mjs.map +0 -1
  140. /package/dist/{chunk-CLQLVMW4.mjs.map → chunk-3WUDRJTT.mjs.map} +0 -0
  141. /package/dist/{chunk-AGP7SAEE.mjs.map → chunk-7LTRT3IV.mjs.map} +0 -0
  142. /package/dist/{chunk-CXDK6XA5.mjs.map → chunk-BBUQMG45.mjs.map} +0 -0
  143. /package/dist/{chunk-G2GQX4FI.mjs.map → chunk-CUWOXXM5.mjs.map} +0 -0
  144. /package/dist/{chunk-4JBVPOHK.mjs.map → chunk-GIGUZ2OK.mjs.map} +0 -0
  145. /package/dist/{chunk-36FJAVOF.mjs.map → chunk-HDOG2RTM.mjs.map} +0 -0
  146. /package/dist/{chunk-AR7HJPGU.mjs.map → chunk-HI6SPUOX.mjs.map} +0 -0
  147. /package/dist/{chunk-FCRODLLL.mjs.map → chunk-HYJUBYMU.mjs.map} +0 -0
  148. /package/dist/{chunk-7D4OASUM.mjs.map → chunk-IHV5PTID.mjs.map} +0 -0
  149. /package/dist/{chunk-KA3NCZEJ.mjs.map → chunk-JBACWIFW.mjs.map} +0 -0
  150. /package/dist/{chunk-HHLBUGRA.mjs.map → chunk-JCHRWCYH.mjs.map} +0 -0
  151. /package/dist/{chunk-MY2BUA6F.mjs.map → chunk-M37URBJS.mjs.map} +0 -0
  152. /package/dist/{chunk-MZ37BAAE.mjs.map → chunk-MGWRDFBE.mjs.map} +0 -0
  153. /package/dist/{chunk-23SOG4FI.mjs.map → chunk-TUTNHDM3.mjs.map} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,79 @@
1
1
  # ui
2
2
 
3
+ ## 1.10.5-next.10
4
+
5
+ ### Patch Changes
6
+
7
+ - b79ed5c: - fix: prevent double action calls on none render copilot actions
8
+ - @copilotkit/runtime-client-gql@1.10.5-next.10
9
+ - @copilotkit/shared@1.10.5-next.10
10
+
11
+ ## 1.10.5-next.9
12
+
13
+ ### Patch Changes
14
+
15
+ - @copilotkit/runtime-client-gql@1.10.5-next.9
16
+ - @copilotkit/shared@1.10.5-next.9
17
+
18
+ ## 1.10.5-next.8
19
+
20
+ ### Patch Changes
21
+
22
+ - @copilotkit/runtime-client-gql@1.10.5-next.8
23
+ - @copilotkit/shared@1.10.5-next.8
24
+
25
+ ## 1.10.5-next.7
26
+
27
+ ### Patch Changes
28
+
29
+ - @copilotkit/runtime-client-gql@1.10.5-next.7
30
+ - @copilotkit/shared@1.10.5-next.7
31
+
32
+ ## 1.10.5-next.6
33
+
34
+ ### Patch Changes
35
+
36
+ - f3fdd7a: - fix: stop chat from contacting agent that has errored
37
+ - @copilotkit/runtime-client-gql@1.10.5-next.6
38
+ - @copilotkit/shared@1.10.5-next.6
39
+
40
+ ## 1.10.5-next.5
41
+
42
+ ### Patch Changes
43
+
44
+ - 6112a67: - fix: consider edge cases when regenerate button is used
45
+ - @copilotkit/runtime-client-gql@1.10.5-next.5
46
+ - @copilotkit/shared@1.10.5-next.5
47
+
48
+ ## 1.10.5-next.4
49
+
50
+ ### Patch Changes
51
+
52
+ - @copilotkit/runtime-client-gql@1.10.5-next.4
53
+ - @copilotkit/shared@1.10.5-next.4
54
+
55
+ ## 1.10.5-next.3
56
+
57
+ ### Patch Changes
58
+
59
+ - @copilotkit/runtime-client-gql@1.10.5-next.3
60
+ - @copilotkit/shared@1.10.5-next.3
61
+
62
+ ## 1.10.5-next.2
63
+
64
+ ### Patch Changes
65
+
66
+ - @copilotkit/runtime-client-gql@1.10.5-next.2
67
+ - @copilotkit/shared@1.10.5-next.2
68
+
69
+ ## 1.10.5-next.1
70
+
71
+ ### Patch Changes
72
+
73
+ - b7bc3a0: - feat: pass copilot readable context to agui agents
74
+ - @copilotkit/runtime-client-gql@1.10.5-next.1
75
+ - @copilotkit/shared@1.10.5-next.1
76
+
3
77
  ## 1.10.5-next.0
4
78
 
5
79
  ### Patch Changes
@@ -10,7 +10,7 @@ import {
10
10
  } from "./chunk-Q3MCVRO3.mjs";
11
11
  import {
12
12
  useCopilotContext
13
- } from "./chunk-YHT6CWIY.mjs";
13
+ } from "./chunk-EUX2P2E7.mjs";
14
14
  import {
15
15
  useToast
16
16
  } from "./chunk-EFL5OBKN.mjs";
@@ -21,7 +21,7 @@ import {
21
21
  } from "./chunk-SKC7AJIV.mjs";
22
22
 
23
23
  // src/hooks/use-chat.ts
24
- import { useCallback, useEffect, useRef } from "react";
24
+ import { useCallback, useEffect, useMemo, useRef } from "react";
25
25
  import { flushSync } from "react-dom";
26
26
  import {
27
27
  COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,
@@ -78,7 +78,18 @@ function useChat(options) {
78
78
  const runChatCompletionRef = useRef();
79
79
  const addErrorToast = useErrorToast();
80
80
  const { setBannerError } = useToast();
81
- const { onError } = useCopilotContext();
81
+ const { onError, showDevConsole, getAllContext } = useCopilotContext();
82
+ const copilotReadableContext = getAllContext();
83
+ const context = useMemo(
84
+ () => copilotReadableContext.map((contextItem) => {
85
+ const [description, ...valueParts] = contextItem.value.split(":");
86
+ return {
87
+ description: description.trim(),
88
+ value: valueParts.join(":").trim()
89
+ };
90
+ }),
91
+ [copilotReadableContext]
92
+ );
82
93
  const traceUIError = (error, originalError) => __async(this, null, function* () {
83
94
  try {
84
95
  const traceEvent = {
@@ -112,7 +123,6 @@ function useChat(options) {
112
123
  extensionsRef.current = extensions;
113
124
  const publicApiKey = copilotConfig.publicApiKey;
114
125
  const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
115
- const { showDevConsole } = useCopilotContext();
116
126
  const runtimeClient = useCopilotRuntimeClient({
117
127
  url: copilotConfig.chatApiEndpoint,
118
128
  publicApiKey: copilotConfig.publicApiKey,
@@ -193,7 +203,8 @@ function useChat(options) {
193
203
  }
194
204
  return stateObject;
195
205
  }),
196
- forwardedParameters: options.forwardedParameters || {}
206
+ forwardedParameters: options.forwardedParameters || {},
207
+ context
197
208
  }),
198
209
  properties: finalProperties,
199
210
  signal: (_e = chatAbortControllerRef.current) == null ? void 0 : _e.signal
@@ -237,7 +248,7 @@ function useChat(options) {
237
248
  if (ev.name === MetaEventName.LangGraphInterruptEvent) {
238
249
  let eventValue = langGraphInterruptEvent(ev).value;
239
250
  eventValue = parseJson(eventValue, eventValue);
240
- setLangGraphInterruptAction({
251
+ setLangGraphInterruptAction(threadId, {
241
252
  event: __spreadProps(__spreadValues({}, langGraphInterruptEvent(ev)), {
242
253
  value: eventValue
243
254
  })
@@ -300,7 +311,7 @@ function useChat(options) {
300
311
  preservedStructure: !!originalCode
301
312
  });
302
313
  setIsLoading(false);
303
- break;
314
+ throw new Error(structuredError.message);
304
315
  } else if (messages2.length > 0) {
305
316
  newMessages = [...messages2];
306
317
  for (const message of messages2) {
@@ -421,8 +432,8 @@ function useChat(options) {
421
432
  }
422
433
  const currentResultMessagePairedFeAction = message.isResultMessage() ? getPairedFeAction(actions, message) : null;
423
434
  if (action && message.isActionExecutionMessage()) {
424
- const isRenderAndWaitAction = (action == null ? void 0 : action._isRenderAndWait) || false;
425
- const alreadyProcessed = isRenderAndWaitAction && finalMessages.some(
435
+ const pairedFeAction = getPairedFeAction(actions, message);
436
+ const alreadyProcessed = !pairedFeAction && finalMessages.some(
426
437
  (fm) => fm.isResultMessage() && fm.actionExecutionId === message.id
427
438
  );
428
439
  if (alreadyProcessed) {
@@ -431,16 +442,16 @@ function useChat(options) {
431
442
  action,
432
443
  message
433
444
  );
434
- const pairedFeAction = getPairedFeAction(actions, resultMessage);
435
- if (pairedFeAction) {
445
+ const pairedFeAction2 = getPairedFeAction(actions, resultMessage);
446
+ if (pairedFeAction2) {
436
447
  const newExecutionMessage = new ActionExecutionMessage({
437
- name: pairedFeAction.name,
448
+ name: pairedFeAction2.name,
438
449
  arguments: parseJson(resultMessage.result, resultMessage.result),
439
450
  status: message.status,
440
451
  createdAt: message.createdAt,
441
452
  parentMessageId: message.parentMessageId
442
453
  });
443
- yield executeActionFromMessage(pairedFeAction, newExecutionMessage);
454
+ yield executeActionFromMessage(pairedFeAction2, newExecutionMessage);
444
455
  }
445
456
  }
446
457
  } else if (message.isResultMessage() && currentResultMessagePairedFeAction) {
@@ -505,7 +516,8 @@ function useChat(options) {
505
516
  coagentStatesRef,
506
517
  agentSession,
507
518
  setAgentSession,
508
- disableSystemMessage
519
+ disableSystemMessage,
520
+ context
509
521
  ]
510
522
  );
511
523
  runChatCompletionRef.current = runChatCompletion;
@@ -534,7 +546,7 @@ function useChat(options) {
534
546
  switch (event.name) {
535
547
  case MetaEventName.LangGraphInterruptEvent:
536
548
  if (event.response) {
537
- setLangGraphInterruptAction(null);
549
+ setLangGraphInterruptAction(threadId, null);
538
550
  const value = event.value;
539
551
  return [
540
552
  ...acc,
@@ -584,8 +596,8 @@ function useChat(options) {
584
596
  console.warn(`Regenerate cannot be performed on ${reloadMessageRole} role`);
585
597
  return;
586
598
  }
587
- let historyCutoff = [];
588
- if (messages.length > 2) {
599
+ let historyCutoff = [messages[0]];
600
+ if (messages.length > 2 && reloadMessageIndex !== 0) {
589
601
  const lastUserMessageBeforeRegenerate = messages.slice(0, reloadMessageIndex).reverse().find(
590
602
  (msg) => (
591
603
  // @ts-expect-error -- message has role
@@ -596,6 +608,8 @@ function useChat(options) {
596
608
  (msg) => msg.id === lastUserMessageBeforeRegenerate.id
597
609
  );
598
610
  historyCutoff = messages.slice(0, indexOfLastUserMessageBeforeRegenerate + 1);
611
+ } else if (messages.length > 2 && reloadMessageIndex === 0) {
612
+ historyCutoff = [messages[0], messages[1]];
599
613
  }
600
614
  setMessages(historyCutoff);
601
615
  return runChatCompletionAndHandleFunctionCall(historyCutoff);
@@ -706,4 +720,4 @@ function getPairedFeAction(actions, message) {
706
720
  export {
707
721
  useChat
708
722
  };
709
- //# sourceMappingURL=chunk-6INCKUL6.mjs.map
723
+ //# sourceMappingURL=chunk-3N4MVKFZ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-chat.ts"],"sourcesContent":["import React, { useCallback, useEffect, useMemo, useRef } from \"react\";\nimport { flushSync } from \"react-dom\";\nimport {\n FunctionCallHandler,\n COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,\n CoAgentStateRenderHandler,\n randomId,\n parseJson,\n CopilotKitError,\n CopilotKitErrorCode,\n} from \"@copilotkit/shared\";\nimport {\n Message,\n TextMessage,\n ResultMessage,\n convertMessagesToGqlInput,\n filterAdjacentAgentStateMessages,\n filterAgentStateMessages,\n convertGqlOutputToMessages,\n MessageStatusCode,\n MessageRole,\n Role,\n CopilotRequestType,\n ForwardedParametersInput,\n loadMessagesFromJsonRepresentation,\n ExtensionsInput,\n CopilotRuntimeClient,\n langGraphInterruptEvent,\n MetaEvent,\n MetaEventName,\n ActionExecutionMessage,\n CopilotKitLangGraphInterruptEvent,\n LangGraphInterruptEvent,\n MetaEventInput,\n AgentStateInput,\n} from \"@copilotkit/runtime-client-gql\";\n\nimport { CopilotApiConfig } from \"../context\";\nimport { FrontendAction, processActionsForRuntimeRequest } from \"../types/frontend-action\";\nimport { CoagentState } from \"../types/coagent-state\";\nimport { AgentSession, useCopilotContext } from \"../context/copilot-context\";\nimport { useCopilotRuntimeClient } from \"./use-copilot-runtime-client\";\nimport { useAsyncCallback, useErrorToast } from \"../components/error-boundary/error-utils\";\nimport { useToast } from \"../components/toast/toast-provider\";\nimport {\n LangGraphInterruptAction,\n LangGraphInterruptActionSetter,\n} from \"../types/interrupt-action\";\n\nexport type UseChatOptions = {\n /**\n * System messages of the chat. Defaults to an empty array.\n */\n initialMessages?: Message[];\n /**\n * Callback function to be called when a function call is received.\n * If the function returns a `ChatRequest` object, the request will be sent\n * automatically to the API and will be used to update the chat.\n */\n onFunctionCall?: FunctionCallHandler;\n\n /**\n * Callback function to be called when a coagent action is received.\n */\n onCoAgentStateRender?: CoAgentStateRenderHandler;\n\n /**\n * Function definitions to be sent to the API.\n */\n actions: FrontendAction<any>[];\n\n /**\n * The CopilotKit API configuration.\n */\n copilotConfig: CopilotApiConfig;\n\n /**\n * The current list of messages in the chat.\n */\n messages: Message[];\n /**\n * The setState-powered method to update the chat messages.\n */\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\n\n /**\n * A callback to get the latest system message.\n */\n makeSystemMessageCallback: () => TextMessage;\n\n /**\n * Whether the API request is in progress\n */\n isLoading: boolean;\n\n /**\n * setState-powered method to update the isChatLoading value\n */\n setIsLoading: React.Dispatch<React.SetStateAction<boolean>>;\n\n /**\n * The current list of coagent states.\n */\n coagentStatesRef: React.RefObject<Record<string, CoagentState>>;\n\n /**\n * setState-powered method to update the agent states\n */\n setCoagentStatesWithRef: React.Dispatch<React.SetStateAction<Record<string, CoagentState>>>;\n\n /**\n * The current agent session.\n */\n agentSession: AgentSession | null;\n\n /**\n * setState-powered method to update the agent session\n */\n setAgentSession: React.Dispatch<React.SetStateAction<AgentSession | null>>;\n\n /**\n * The forwarded parameters.\n */\n forwardedParameters?: Pick<ForwardedParametersInput, \"temperature\">;\n\n /**\n * The current thread ID.\n */\n threadId: string;\n /**\n * set the current thread ID\n */\n setThreadId: (threadId: string) => void;\n /**\n * The current run ID.\n */\n runId: string | null;\n /**\n * set the current run ID\n */\n setRunId: (runId: string | null) => void;\n /**\n * The global chat abort controller.\n */\n chatAbortControllerRef: React.MutableRefObject<AbortController | null>;\n /**\n * The agent lock.\n */\n agentLock: string | null;\n /**\n * The extensions.\n */\n extensions: ExtensionsInput;\n /**\n * The setState-powered method to update the extensions.\n */\n setExtensions: React.Dispatch<React.SetStateAction<ExtensionsInput>>;\n\n langGraphInterruptAction: LangGraphInterruptAction | null;\n\n setLangGraphInterruptAction: LangGraphInterruptActionSetter;\n\n disableSystemMessage?: boolean;\n};\n\nexport type UseChatHelpers = {\n /**\n * Append a user message to the chat list. This triggers the API call to fetch\n * the assistant's response.\n * @param message The message to append\n */\n append: (message: Message, options?: AppendMessageOptions) => Promise<void>;\n /**\n * Reload the last AI chat response for the given chat history. If the last\n * message isn't from the assistant, it will request the API to generate a\n * new response.\n */\n reload: (messageId: string) => Promise<void>;\n /**\n * Abort the current request immediately, keep the generated tokens if any.\n */\n stop: () => void;\n\n /**\n * Run the chat completion.\n */\n runChatCompletion: () => Promise<Message[]>;\n};\n\nexport interface AppendMessageOptions {\n /**\n * Whether to run the chat completion after appending the message. Defaults to `true`.\n */\n followUp?: boolean;\n /**\n * Whether to clear the suggestions after appending the message. Defaults to `true`.\n */\n clearSuggestions?: boolean;\n}\n\nexport function useChat(options: UseChatOptions): UseChatHelpers {\n const {\n messages,\n setMessages,\n makeSystemMessageCallback,\n copilotConfig,\n setIsLoading,\n initialMessages,\n isLoading,\n actions,\n onFunctionCall,\n onCoAgentStateRender,\n setCoagentStatesWithRef,\n coagentStatesRef,\n agentSession,\n setAgentSession,\n threadId,\n setThreadId,\n runId,\n setRunId,\n chatAbortControllerRef,\n agentLock,\n extensions,\n setExtensions,\n langGraphInterruptAction,\n setLangGraphInterruptAction,\n disableSystemMessage = false,\n } = options;\n const runChatCompletionRef = useRef<(previousMessages: Message[]) => Promise<Message[]>>();\n const addErrorToast = useErrorToast();\n const { setBannerError } = useToast();\n\n // Get onError from context since it's not part of copilotConfig\n const { onError, showDevConsole, getAllContext } = useCopilotContext();\n\n const copilotReadableContext = getAllContext();\n\n const context = useMemo(\n () =>\n copilotReadableContext.map((contextItem) => {\n const [description, ...valueParts] = contextItem.value.split(\":\");\n return {\n description: description.trim(),\n value: valueParts.join(\":\").trim(),\n };\n }),\n [copilotReadableContext],\n );\n\n // Add tracing functionality to use-chat\n const traceUIError = async (error: CopilotKitError, originalError?: any) => {\n try {\n const traceEvent = {\n type: \"error\" as const,\n timestamp: Date.now(),\n context: {\n source: \"ui\" as const,\n request: {\n operation: \"useChatCompletion\",\n url: copilotConfig.chatApiEndpoint,\n startTime: Date.now(),\n },\n technical: {\n environment: \"browser\",\n userAgent: typeof navigator !== \"undefined\" ? navigator.userAgent : undefined,\n stackTrace: originalError instanceof Error ? originalError.stack : undefined,\n },\n },\n error,\n };\n\n await onError(traceEvent);\n } catch (traceError) {\n console.error(\"Error in use-chat onError handler:\", traceError);\n }\n };\n // We need to keep a ref of coagent states and session because of renderAndWait - making sure\n // the latest state is sent to the API\n // This is a workaround and needs to be addressed in the future\n const agentSessionRef = useRef<AgentSession | null>(agentSession);\n agentSessionRef.current = agentSession;\n\n const runIdRef = useRef<string | null>(runId);\n runIdRef.current = runId;\n const extensionsRef = useRef<ExtensionsInput>(extensions);\n extensionsRef.current = extensions;\n\n const publicApiKey = copilotConfig.publicApiKey;\n\n const headers = {\n ...(copilotConfig.headers || {}),\n ...(publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {}),\n };\n\n const runtimeClient = useCopilotRuntimeClient({\n url: copilotConfig.chatApiEndpoint,\n publicApiKey: copilotConfig.publicApiKey,\n headers,\n credentials: copilotConfig.credentials,\n showDevConsole,\n onError,\n });\n\n const pendingAppendsRef = useRef<{ message: Message; followUp: boolean }[]>([]);\n\n const runChatCompletion = useAsyncCallback(\n async (previousMessages: Message[]): Promise<Message[]> => {\n setIsLoading(true);\n const interruptEvent = langGraphInterruptAction?.event;\n // In case an interrupt event exist and valid but has no response yet, we cannot process further messages to an agent\n if (\n interruptEvent?.name === MetaEventName.LangGraphInterruptEvent &&\n interruptEvent?.value &&\n !interruptEvent?.response &&\n agentSessionRef.current\n ) {\n addErrorToast([\n new Error(\n \"A message was sent while interrupt is active. This will cause failure on the agent side\",\n ),\n ]);\n }\n\n // this message is just a placeholder. It will disappear once the first real message\n // is received\n let newMessages: Message[] = [\n new TextMessage({\n content: \"\",\n role: Role.Assistant,\n }),\n ];\n\n chatAbortControllerRef.current = new AbortController();\n\n setMessages([...previousMessages, ...newMessages]);\n\n const messagesWithContext = disableSystemMessage\n ? [...(initialMessages || []), ...previousMessages]\n : [makeSystemMessageCallback(), ...(initialMessages || []), ...previousMessages];\n\n // ----- Set mcpServers in properties -----\n // Create a copy of properties to avoid modifying the original object\n const finalProperties = { ...(copilotConfig.properties || {}) };\n\n // Look for mcpServers in either direct property or properties\n let mcpServersToUse = null;\n\n // First check direct mcpServers property\n if (\n copilotConfig.mcpServers &&\n Array.isArray(copilotConfig.mcpServers) &&\n copilotConfig.mcpServers.length > 0\n ) {\n mcpServersToUse = copilotConfig.mcpServers;\n }\n // Then check mcpServers in properties\n else if (\n copilotConfig.properties?.mcpServers &&\n Array.isArray(copilotConfig.properties.mcpServers) &&\n copilotConfig.properties.mcpServers.length > 0\n ) {\n mcpServersToUse = copilotConfig.properties.mcpServers;\n }\n\n // Apply the mcpServers to properties if found\n if (mcpServersToUse) {\n // Set in finalProperties\n finalProperties.mcpServers = mcpServersToUse;\n\n // Also set in copilotConfig directly for future use\n copilotConfig.mcpServers = mcpServersToUse;\n }\n // -------------------------------------------------------------\n\n const isAgentRun = agentSessionRef.current !== null;\n\n const stream = runtimeClient.asStream(\n runtimeClient.generateCopilotResponse({\n data: {\n frontend: {\n actions: processActionsForRuntimeRequest(actions),\n url: window.location.href,\n },\n threadId: threadId,\n runId: runIdRef.current,\n extensions: extensionsRef.current,\n metaEvents: composeAndFlushMetaEventsInput([langGraphInterruptAction?.event]),\n messages: convertMessagesToGqlInput(filterAgentStateMessages(messagesWithContext)),\n ...(copilotConfig.cloud\n ? {\n cloud: {\n ...(copilotConfig.cloud.guardrails?.input?.restrictToTopic?.enabled\n ? {\n guardrails: {\n inputValidationRules: {\n allowList:\n copilotConfig.cloud.guardrails.input.restrictToTopic.validTopics,\n denyList:\n copilotConfig.cloud.guardrails.input.restrictToTopic.invalidTopics,\n },\n },\n }\n : {}),\n },\n }\n : {}),\n metadata: {\n requestType: CopilotRequestType.Chat,\n },\n ...(agentSessionRef.current\n ? {\n agentSession: agentSessionRef.current,\n }\n : {}),\n agentStates: Object.values(coagentStatesRef.current!).map((state) => {\n const stateObject: AgentStateInput = {\n agentName: state.name,\n state: JSON.stringify(state.state),\n };\n\n if (state.config !== undefined) {\n stateObject.config = JSON.stringify(state.config);\n }\n\n return stateObject;\n }),\n forwardedParameters: options.forwardedParameters || {},\n context,\n },\n properties: finalProperties,\n signal: chatAbortControllerRef.current?.signal,\n }),\n );\n\n const guardrailsEnabled =\n copilotConfig.cloud?.guardrails?.input?.restrictToTopic.enabled || false;\n\n const reader = stream.getReader();\n\n let executedCoAgentStateRenders: string[] = [];\n let followUp: FrontendAction[\"followUp\"] = undefined;\n\n let messages: Message[] = [];\n let syncedMessages: Message[] = [];\n let interruptMessages: Message[] = [];\n\n try {\n while (true) {\n let done, value;\n\n try {\n const readResult = await reader.read();\n done = readResult.done;\n value = readResult.value;\n } catch (readError) {\n break;\n }\n\n if (done) {\n if (chatAbortControllerRef.current.signal.aborted) {\n return [];\n }\n break;\n }\n\n if (!value?.generateCopilotResponse) {\n continue;\n }\n\n runIdRef.current = value.generateCopilotResponse.runId || null;\n\n // in the output, graphql inserts __typename, which leads to an error when sending it along\n // as input to the next request.\n extensionsRef.current = CopilotRuntimeClient.removeGraphQLTypename(\n value.generateCopilotResponse.extensions || {},\n );\n\n // setThreadId(threadIdRef.current);\n setRunId(runIdRef.current);\n setExtensions(extensionsRef.current);\n let rawMessagesResponse = value.generateCopilotResponse.messages;\n\n const metaEvents: MetaEvent[] | undefined =\n value.generateCopilotResponse?.metaEvents ?? [];\n (metaEvents ?? []).forEach((ev) => {\n if (ev.name === MetaEventName.LangGraphInterruptEvent) {\n let eventValue = langGraphInterruptEvent(ev as LangGraphInterruptEvent).value;\n eventValue = parseJson(eventValue, eventValue);\n setLangGraphInterruptAction(threadId, {\n event: {\n ...langGraphInterruptEvent(ev as LangGraphInterruptEvent),\n value: eventValue,\n },\n });\n }\n if (ev.name === MetaEventName.CopilotKitLangGraphInterruptEvent) {\n const data = (ev as CopilotKitLangGraphInterruptEvent).data;\n\n // @ts-expect-error -- same type of messages\n rawMessagesResponse = [...rawMessagesResponse, ...data.messages];\n interruptMessages = convertGqlOutputToMessages(\n // @ts-ignore\n filterAdjacentAgentStateMessages(data.messages),\n );\n }\n });\n\n messages = convertGqlOutputToMessages(\n filterAdjacentAgentStateMessages(rawMessagesResponse),\n );\n\n newMessages = [];\n\n // Handle error statuses BEFORE checking if there are messages\n // (errors can come in chunks with no messages)\n\n // request failed, display error message and quit\n if (\n value.generateCopilotResponse.status?.__typename === \"FailedResponseStatus\" &&\n value.generateCopilotResponse.status.reason === \"GUARDRAILS_VALIDATION_FAILED\"\n ) {\n const guardrailsReason =\n value.generateCopilotResponse.status.details?.guardrailsReason || \"\";\n\n newMessages = [\n new TextMessage({\n role: MessageRole.Assistant,\n content: guardrailsReason,\n }),\n ];\n\n // Trace guardrails validation failure\n const guardrailsError = new CopilotKitError({\n message: `Guardrails validation failed: ${guardrailsReason}`,\n code: CopilotKitErrorCode.MISUSE,\n });\n await traceUIError(guardrailsError, {\n statusReason: value.generateCopilotResponse.status.reason,\n statusDetails: value.generateCopilotResponse.status.details,\n });\n // TODO: if onError & renderError should work without key, insert here\n\n setMessages([...previousMessages, ...newMessages]);\n break;\n }\n\n // Handle UNKNOWN_ERROR failures (like authentication errors) by routing to banner error system\n if (\n value.generateCopilotResponse.status?.__typename === \"FailedResponseStatus\" &&\n value.generateCopilotResponse.status.reason === \"UNKNOWN_ERROR\"\n ) {\n const errorMessage =\n value.generateCopilotResponse.status.details?.description ||\n \"An unknown error occurred\";\n\n // Try to extract original error information from the response details\n const statusDetails = value.generateCopilotResponse.status.details;\n const originalError = statusDetails?.originalError || statusDetails?.error;\n\n // Extract structured error information if available (prioritize top-level over extensions)\n const originalCode = originalError?.code || originalError?.extensions?.code;\n const originalSeverity = originalError?.severity || originalError?.extensions?.severity;\n const originalVisibility =\n originalError?.visibility || originalError?.extensions?.visibility;\n\n // Use the original error code if available, otherwise default to NETWORK_ERROR\n let errorCode = CopilotKitErrorCode.NETWORK_ERROR;\n if (originalCode && Object.values(CopilotKitErrorCode).includes(originalCode)) {\n errorCode = originalCode;\n }\n\n // Create a structured CopilotKitError preserving original error information\n const structuredError = new CopilotKitError({\n message: errorMessage,\n code: errorCode,\n severity: originalSeverity,\n visibility: originalVisibility,\n });\n\n // Display the error in the banner\n setBannerError(structuredError);\n\n // Trace the error for debugging/observability\n await traceUIError(structuredError, {\n statusReason: value.generateCopilotResponse.status.reason,\n statusDetails: value.generateCopilotResponse.status.details,\n originalErrorCode: originalCode,\n preservedStructure: !!originalCode,\n });\n // TODO: if onError & renderError should work without key, insert here\n\n // Stop processing and break from the loop\n setIsLoading(false);\n throw new Error(structuredError.message);\n }\n\n // add messages to the chat\n else if (messages.length > 0) {\n newMessages = [...messages];\n\n for (const message of messages) {\n // execute onCoAgentStateRender handler\n if (\n message.isAgentStateMessage() &&\n !message.active &&\n !executedCoAgentStateRenders.includes(message.id) &&\n onCoAgentStateRender\n ) {\n // Do not execute a coagent action if guardrails are enabled but the status is not known\n if (guardrailsEnabled && value.generateCopilotResponse.status === undefined) {\n break;\n }\n // execute coagent action\n await onCoAgentStateRender({\n name: message.agentName,\n nodeName: message.nodeName,\n state: message.state,\n });\n executedCoAgentStateRenders.push(message.id);\n }\n }\n\n const lastAgentStateMessage = [...messages]\n .reverse()\n .find((message) => message.isAgentStateMessage());\n\n if (lastAgentStateMessage) {\n if (\n lastAgentStateMessage.state.messages &&\n lastAgentStateMessage.state.messages.length > 0\n ) {\n syncedMessages = loadMessagesFromJsonRepresentation(\n lastAgentStateMessage.state.messages,\n );\n }\n setCoagentStatesWithRef((prevAgentStates) => ({\n ...prevAgentStates,\n [lastAgentStateMessage.agentName]: {\n name: lastAgentStateMessage.agentName,\n state: lastAgentStateMessage.state,\n running: lastAgentStateMessage.running,\n active: lastAgentStateMessage.active,\n threadId: lastAgentStateMessage.threadId,\n nodeName: lastAgentStateMessage.nodeName,\n runId: lastAgentStateMessage.runId,\n // Preserve existing config from previous state\n config: prevAgentStates[lastAgentStateMessage.agentName]?.config,\n },\n }));\n if (lastAgentStateMessage.running) {\n setAgentSession({\n threadId: lastAgentStateMessage.threadId,\n agentName: lastAgentStateMessage.agentName,\n nodeName: lastAgentStateMessage.nodeName,\n });\n } else {\n if (agentLock) {\n setAgentSession({\n threadId: randomId(),\n agentName: agentLock,\n nodeName: undefined,\n });\n } else {\n setAgentSession(null);\n }\n }\n }\n }\n\n if (newMessages.length > 0) {\n // Update message state\n setMessages([...previousMessages, ...newMessages]);\n }\n }\n let finalMessages = constructFinalMessages(\n [...syncedMessages, ...interruptMessages],\n previousMessages,\n newMessages,\n );\n\n let didExecuteAction = false;\n\n // ----- Helper function to execute an action and manage its lifecycle -----\n const executeActionFromMessage = async (\n currentAction: FrontendAction<any>,\n actionMessage: ActionExecutionMessage,\n ) => {\n const isInterruptAction = interruptMessages.find((m) => m.id === actionMessage.id);\n // Determine follow-up behavior: use action's specific setting if defined, otherwise default based on interrupt status.\n followUp = currentAction?.followUp ?? !isInterruptAction;\n\n // Call _setActivatingMessageId before executing the action for HITL correlation\n if ((currentAction as any)?._setActivatingMessageId) {\n (currentAction as any)._setActivatingMessageId(actionMessage.id);\n }\n\n const resultMessage = await executeAction({\n onFunctionCall: onFunctionCall!,\n message: actionMessage,\n chatAbortControllerRef,\n onError: (error: Error) => {\n addErrorToast([error]);\n // console.error is kept here as it's a genuine error in action execution\n console.error(`Failed to execute action ${actionMessage.name}: ${error}`);\n },\n setMessages,\n getFinalMessages: () => finalMessages,\n isRenderAndWait: (currentAction as any)?._isRenderAndWait || false,\n });\n didExecuteAction = true;\n const messageIndex = finalMessages.findIndex((msg) => msg.id === actionMessage.id);\n finalMessages.splice(messageIndex + 1, 0, resultMessage);\n\n // If the executed action was a renderAndWaitForResponse type, update messages immediately\n // to reflect its completion in the UI, making it interactive promptly.\n if ((currentAction as any)?._isRenderAndWait) {\n const messagesForImmediateUpdate = [...finalMessages];\n flushSync(() => {\n setMessages(messagesForImmediateUpdate);\n });\n }\n\n // Clear _setActivatingMessageId after the action is done\n if ((currentAction as any)?._setActivatingMessageId) {\n (currentAction as any)._setActivatingMessageId(null);\n }\n\n return resultMessage;\n };\n // ----------------------------------------------------------------------\n\n // execute regular action executions that are specific to the frontend (last actions)\n if (onFunctionCall) {\n // Find consecutive action execution messages at the end\n const lastMessages = [];\n\n for (let i = finalMessages.length - 1; i >= 0; i--) {\n const message = finalMessages[i];\n if (\n (message.isActionExecutionMessage() || message.isResultMessage()) &&\n message.status.code !== MessageStatusCode.Pending\n ) {\n lastMessages.unshift(message);\n } else if (!message.isAgentStateMessage()) {\n break;\n }\n }\n\n for (const message of lastMessages) {\n // We update the message state before calling the handler so that the render\n // function can be called with `executing` state\n setMessages(finalMessages);\n\n const action = actions.find(\n (action) => action.name === (message as ActionExecutionMessage).name,\n );\n if (action && action.available === \"frontend\") {\n // never execute frontend actions\n continue;\n }\n const currentResultMessagePairedFeAction = message.isResultMessage()\n ? getPairedFeAction(actions, message)\n : null;\n\n // execution message which has an action registered with the hook (remote availability):\n // execute that action first, and then the \"paired FE action\"\n if (action && message.isActionExecutionMessage()) {\n // For HITL actions, check if they've already been processed to avoid redundant handler calls.\n const pairedFeAction = getPairedFeAction(actions, message);\n const alreadyProcessed =\n !pairedFeAction &&\n finalMessages.some(\n (fm) => fm.isResultMessage() && fm.actionExecutionId === message.id,\n );\n\n if (alreadyProcessed) {\n // Skip re-execution if already processed\n } else {\n // Call the single, externally defined executeActionFromMessage\n const resultMessage = await executeActionFromMessage(\n action,\n message as ActionExecutionMessage,\n );\n const pairedFeAction = getPairedFeAction(actions, resultMessage);\n\n if (pairedFeAction) {\n const newExecutionMessage = new ActionExecutionMessage({\n name: pairedFeAction.name,\n arguments: parseJson(resultMessage.result, resultMessage.result),\n status: message.status,\n createdAt: message.createdAt,\n parentMessageId: message.parentMessageId,\n });\n // Call the single, externally defined executeActionFromMessage\n await executeActionFromMessage(pairedFeAction, newExecutionMessage);\n }\n }\n } else if (message.isResultMessage() && currentResultMessagePairedFeAction) {\n // Actions which are set up in runtime actions array: Grab the result, executed paired FE action with it as args.\n const newExecutionMessage = new ActionExecutionMessage({\n name: currentResultMessagePairedFeAction.name,\n arguments: parseJson(message.result, message.result),\n status: message.status,\n createdAt: message.createdAt,\n });\n finalMessages.push(newExecutionMessage);\n // Call the single, externally defined executeActionFromMessage\n await executeActionFromMessage(\n currentResultMessagePairedFeAction,\n newExecutionMessage,\n );\n }\n }\n\n setMessages(finalMessages);\n }\n\n // Conditionally run chat completion again if followUp is not explicitly false\n // and an action was executed or the last message is a server-side result (for non-agent runs).\n if (\n followUp !== false &&\n (didExecuteAction ||\n // the last message is a server side result\n (!isAgentRun &&\n finalMessages.length &&\n finalMessages[finalMessages.length - 1].isResultMessage())) &&\n // the user did not stop generation\n !chatAbortControllerRef.current?.signal.aborted\n ) {\n // run the completion again and return the result\n\n // wait for next tick to make sure all the react state updates\n // - tried using react-dom's flushSync, but it did not work\n await new Promise((resolve) => setTimeout(resolve, 10));\n\n return await runChatCompletionRef.current!(finalMessages);\n } else if (chatAbortControllerRef.current?.signal.aborted) {\n // filter out all the action execution messages that do not have a consecutive matching result message\n const repairedMessages = finalMessages.filter((message, actionExecutionIndex) => {\n if (message.isActionExecutionMessage()) {\n return finalMessages.find(\n (msg, resultIndex) =>\n msg.isResultMessage() &&\n msg.actionExecutionId === message.id &&\n resultIndex === actionExecutionIndex + 1,\n );\n }\n return true;\n });\n const repairedMessageIds = repairedMessages.map((message) => message.id);\n setMessages(repairedMessages);\n\n // LangGraph needs two pieces of information to continue execution:\n // 1. The threadId\n // 2. The nodeName it came from\n // When stopping the agent, we don't know the nodeName the agent would have ended with\n // Therefore, we set the nodeName to the most reasonable thing we can guess, which\n // is \"__end__\"\n if (agentSessionRef.current?.nodeName) {\n setAgentSession({\n threadId: agentSessionRef.current.threadId,\n agentName: agentSessionRef.current.agentName,\n nodeName: \"__end__\",\n });\n }\n // only return new messages that were not filtered out\n return newMessages.filter((message) => repairedMessageIds.includes(message.id));\n } else {\n return newMessages.slice();\n }\n } finally {\n setIsLoading(false);\n }\n },\n [\n messages,\n setMessages,\n makeSystemMessageCallback,\n copilotConfig,\n setIsLoading,\n initialMessages,\n isLoading,\n actions,\n onFunctionCall,\n onCoAgentStateRender,\n setCoagentStatesWithRef,\n coagentStatesRef,\n agentSession,\n setAgentSession,\n disableSystemMessage,\n context,\n ],\n );\n\n runChatCompletionRef.current = runChatCompletion;\n\n const runChatCompletionAndHandleFunctionCall = useAsyncCallback(\n async (messages: Message[]): Promise<void> => {\n await runChatCompletionRef.current!(messages);\n },\n [messages],\n );\n\n useEffect(() => {\n if (!isLoading && pendingAppendsRef.current.length > 0) {\n const pending = pendingAppendsRef.current.splice(0);\n const followUp = pending.some((p) => p.followUp);\n const newMessages = [...messages, ...pending.map((p) => p.message)];\n setMessages(newMessages);\n if (followUp) {\n runChatCompletionAndHandleFunctionCall(newMessages);\n }\n }\n }, [isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]);\n\n // Go over all events and see that they include data that should be returned to the agent\n const composeAndFlushMetaEventsInput = useCallback(\n (metaEvents: (MetaEvent | undefined | null)[]) => {\n return metaEvents.reduce((acc: MetaEventInput[], event) => {\n if (!event) return acc;\n\n switch (event.name) {\n case MetaEventName.LangGraphInterruptEvent:\n if (event.response) {\n // Flush interrupt event from state\n setLangGraphInterruptAction(threadId, null);\n const value = (event as LangGraphInterruptEvent).value;\n return [\n ...acc,\n {\n name: event.name,\n value: typeof value === \"string\" ? value : JSON.stringify(value),\n response:\n typeof event.response === \"string\"\n ? event.response\n : JSON.stringify(event.response),\n },\n ];\n }\n return acc;\n default:\n return acc;\n }\n }, []);\n },\n [setLangGraphInterruptAction],\n );\n\n const append = useAsyncCallback(\n async (message: Message, options?: AppendMessageOptions): Promise<void> => {\n const followUp = options?.followUp ?? true;\n if (isLoading) {\n pendingAppendsRef.current.push({ message, followUp });\n return;\n }\n\n const newMessages = [...messages, message];\n setMessages(newMessages);\n if (followUp) {\n return runChatCompletionAndHandleFunctionCall(newMessages);\n }\n },\n [isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall],\n );\n\n const reload = useAsyncCallback(\n async (reloadMessageId: string): Promise<void> => {\n if (isLoading || messages.length === 0) {\n return;\n }\n\n const reloadMessageIndex = messages.findIndex((msg) => msg.id === reloadMessageId);\n if (reloadMessageIndex === -1) {\n console.warn(`Message with id ${reloadMessageId} not found`);\n return;\n }\n\n // @ts-expect-error -- message has role\n const reloadMessageRole = messages[reloadMessageIndex].role;\n if (reloadMessageRole !== MessageRole.Assistant) {\n console.warn(`Regenerate cannot be performed on ${reloadMessageRole} role`);\n return;\n }\n let historyCutoff: Message[] = [messages[0]];\n\n if (messages.length > 2 && reloadMessageIndex !== 0) {\n // message to regenerate from is now first.\n // Work backwards to find the first the closest user message\n const lastUserMessageBeforeRegenerate = messages\n .slice(0, reloadMessageIndex)\n .reverse()\n .find(\n (msg) =>\n // @ts-expect-error -- message has role\n msg.role === MessageRole.User,\n );\n const indexOfLastUserMessageBeforeRegenerate = messages.findIndex(\n (msg) => msg.id === lastUserMessageBeforeRegenerate!.id,\n );\n\n // Include the user message, remove everything after it\n historyCutoff = messages.slice(0, indexOfLastUserMessageBeforeRegenerate + 1);\n } else if (messages.length > 2 && reloadMessageIndex === 0) {\n historyCutoff = [messages[0], messages[1]];\n }\n\n setMessages(historyCutoff);\n\n return runChatCompletionAndHandleFunctionCall(historyCutoff);\n },\n [isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall],\n );\n\n const stop = (): void => {\n chatAbortControllerRef.current?.abort(\"Stop was called\");\n };\n\n return {\n append,\n reload,\n stop,\n runChatCompletion: () => runChatCompletionRef.current!(messages),\n };\n}\n\nfunction constructFinalMessages(\n syncedMessages: Message[],\n previousMessages: Message[],\n newMessages: Message[],\n): Message[] {\n const finalMessages =\n syncedMessages.length > 0 ? [...syncedMessages] : [...previousMessages, ...newMessages];\n\n if (syncedMessages.length > 0) {\n const messagesWithAgentState = [...previousMessages, ...newMessages];\n\n let previousMessageId: string | undefined = undefined;\n\n for (const message of messagesWithAgentState) {\n if (message.isAgentStateMessage()) {\n // insert this message into finalMessages after the position of previousMessageId\n const index = finalMessages.findIndex((msg) => msg.id === previousMessageId);\n if (index !== -1) {\n finalMessages.splice(index + 1, 0, message);\n }\n }\n\n previousMessageId = message.id;\n }\n }\n\n return finalMessages;\n}\n\nasync function executeAction({\n onFunctionCall,\n message,\n chatAbortControllerRef,\n onError,\n setMessages,\n getFinalMessages,\n isRenderAndWait,\n}: {\n onFunctionCall: FunctionCallHandler;\n message: ActionExecutionMessage;\n chatAbortControllerRef: React.MutableRefObject<AbortController | null>;\n onError: (error: Error) => void;\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\n getFinalMessages: () => Message[];\n isRenderAndWait: boolean;\n}) {\n let result: any;\n let error: Error | null = null;\n\n const currentMessagesForHandler = getFinalMessages();\n\n // The handler (onFunctionCall) runs its synchronous part here, potentially setting up\n // renderAndWaitRef.current for HITL actions via useCopilotAction's transformed handler.\n const handlerReturnedPromise = onFunctionCall({\n messages: currentMessagesForHandler,\n name: message.name,\n args: message.arguments,\n });\n\n // For HITL actions, call flushSync immediately after their handler has set up the promise\n // and before awaiting the promise. This ensures the UI updates to an interactive state.\n if (isRenderAndWait) {\n const currentMessagesForRender = getFinalMessages();\n flushSync(() => {\n setMessages([...currentMessagesForRender]);\n });\n }\n\n try {\n result = await Promise.race([\n handlerReturnedPromise, // Await the promise returned by the handler\n new Promise((resolve) =>\n chatAbortControllerRef.current?.signal.addEventListener(\"abort\", () =>\n resolve(\"Operation was aborted by the user\"),\n ),\n ),\n // if the user stopped generation, we also abort consecutive actions\n new Promise((resolve) => {\n if (chatAbortControllerRef.current?.signal.aborted) {\n resolve(\"Operation was aborted by the user\");\n }\n }),\n ]);\n } catch (e) {\n onError(e as Error);\n }\n return new ResultMessage({\n id: \"result-\" + message.id,\n result: ResultMessage.encodeResult(\n error\n ? {\n content: result,\n error: JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error))),\n }\n : result,\n ),\n actionExecutionId: message.id,\n actionName: message.name,\n });\n}\n\nfunction getPairedFeAction(\n actions: FrontendAction<any>[],\n message: ActionExecutionMessage | ResultMessage,\n) {\n let actionName = null;\n if (message.isActionExecutionMessage()) {\n actionName = message.name;\n } else if (message.isResultMessage()) {\n actionName = message.actionName;\n }\n return actions.find(\n (action) =>\n (action.name === actionName && action.available === \"frontend\") ||\n action.pairedAction === actionName,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAgB,aAAa,WAAW,SAAS,cAAc;AAC/D,SAAS,iBAAiB;AAC1B;AAAA,EAEE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EAEA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OAKK;AAqKA,SAAS,QAAQ,SAAyC;AAC/D,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,uBAAuB;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E/C;AAAA;AAAA,QAEA,IAAI,QAAQ,CAAC,YAAY;AA9kC/B;AA+kCQ,eAAI,4BAAuB,YAAvB,mBAAgC,OAAO,SAAS;AAClD,oBAAQ,mCAAmC;AAAA,UAC7C;AAAA,QACF,CAAC;AAAA,MACH,CAAC;AAAA,IACH,SAAS,GAAP;AACA,cAAQ,CAAU;AAAA,IACpB;AACA,WAAO,IAAI,cAAc;AAAA,MACvB,IAAI,YAAY,QAAQ;AAAA,MACxB,QAAQ,cAAc;AAAA,QACpB,QACI;AAAA,UACE,SAAS;AAAA,UACT,OAAO,KAAK,MAAM,KAAK,UAAU,OAAO,OAAO,oBAAoB,KAAK,CAAC,CAAC;AAAA,QAC5E,IACA;AAAA,MACN;AAAA,MACA,mBAAmB,QAAQ;AAAA,MAC3B,YAAY,QAAQ;AAAA,IACtB,CAAC;AAAA,EACH;AAAA;AAEA,SAAS,kBACP,SACA,SACA;AACA,MAAI,aAAa;AACjB,MAAI,QAAQ,yBAAyB,GAAG;AACtC,iBAAa,QAAQ;AAAA,EACvB,WAAW,QAAQ,gBAAgB,GAAG;AACpC,iBAAa,QAAQ;AAAA,EACvB;AACA,SAAO,QAAQ;AAAA,IACb,CAAC,WACE,OAAO,SAAS,cAAc,OAAO,cAAc,cACpD,OAAO,iBAAiB;AAAA,EAC5B;AACF;","names":["messages","_a","action","pairedFeAction","options"]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  CopilotContext
3
- } from "./chunk-YHT6CWIY.mjs";
3
+ } from "./chunk-EUX2P2E7.mjs";
4
4
  import {
5
5
  useToast
6
6
  } from "./chunk-EFL5OBKN.mjs";
@@ -85,4 +85,4 @@ function useCoAgentStateRender(action, dependencies) {
85
85
  export {
86
86
  useCoAgentStateRender
87
87
  };
88
- //# sourceMappingURL=chunk-CLQLVMW4.mjs.map
88
+ //# sourceMappingURL=chunk-3WUDRJTT.mjs.map
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  useCopilotChat
3
- } from "./chunk-FCRODLLL.mjs";
3
+ } from "./chunk-HYJUBYMU.mjs";
4
4
  import {
5
5
  useMessagesTap
6
- } from "./chunk-MY2BUA6F.mjs";
6
+ } from "./chunk-M37URBJS.mjs";
7
7
  import {
8
8
  useAsyncCallback
9
9
  } from "./chunk-N4WEHORG.mjs";
@@ -12,7 +12,7 @@ import {
12
12
  } from "./chunk-Q3MCVRO3.mjs";
13
13
  import {
14
14
  useCopilotContext
15
- } from "./chunk-YHT6CWIY.mjs";
15
+ } from "./chunk-EUX2P2E7.mjs";
16
16
  import {
17
17
  useToast
18
18
  } from "./chunk-EFL5OBKN.mjs";
@@ -236,4 +236,4 @@ export {
236
236
  stopAgent,
237
237
  runAgent
238
238
  };
239
- //# sourceMappingURL=chunk-AGP7SAEE.mjs.map
239
+ //# sourceMappingURL=chunk-7LTRT3IV.mjs.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useCopilotContext
3
- } from "./chunk-YHT6CWIY.mjs";
3
+ } from "./chunk-EUX2P2E7.mjs";
4
4
 
5
5
  // src/hooks/use-make-copilot-document-readable.ts
6
6
  import { useEffect, useRef } from "react";
@@ -20,4 +20,4 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
20
20
  export {
21
21
  useMakeCopilotDocumentReadable
22
22
  };
23
- //# sourceMappingURL=chunk-CXDK6XA5.mjs.map
23
+ //# sourceMappingURL=chunk-BBUQMG45.mjs.map
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  DeveloperConsoleModal
3
- } from "./chunk-23SOG4FI.mjs";
3
+ } from "./chunk-TUTNHDM3.mjs";
4
4
  import {
5
5
  CopilotKitIcon
6
6
  } from "./chunk-PIF5KJYI.mjs";
7
7
  import {
8
8
  useCopilotContext
9
- } from "./chunk-YHT6CWIY.mjs";
9
+ } from "./chunk-EUX2P2E7.mjs";
10
10
 
11
11
  // src/components/dev-console/console-trigger.tsx
12
12
  import { useState, useEffect, useRef } from "react";
@@ -228,4 +228,4 @@ function ConsoleTrigger({ position = "bottom-right" }) {
228
228
  export {
229
229
  ConsoleTrigger
230
230
  };
231
- //# sourceMappingURL=chunk-G2GQX4FI.mjs.map
231
+ //# sourceMappingURL=chunk-CUWOXXM5.mjs.map
@@ -74,8 +74,10 @@ var emptyCopilotContext = {
74
74
  setExtensions: () => {
75
75
  },
76
76
  langGraphInterruptAction: null,
77
- setLangGraphInterruptAction: () => null,
78
- removeLangGraphInterruptAction: () => null,
77
+ setLangGraphInterruptAction: () => {
78
+ },
79
+ removeLangGraphInterruptAction: () => {
80
+ },
79
81
  onError: () => {
80
82
  },
81
83
  bannerError: null,
@@ -103,4 +105,4 @@ export {
103
105
  CopilotContext,
104
106
  useCopilotContext
105
107
  };
106
- //# sourceMappingURL=chunk-YHT6CWIY.mjs.map
108
+ //# sourceMappingURL=chunk-EUX2P2E7.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/context/copilot-context.tsx"],"sourcesContent":["import {\n CopilotCloudConfig,\n FunctionCallHandler,\n CopilotErrorHandler,\n CopilotKitError,\n} from \"@copilotkit/shared\";\nimport {\n ActionRenderProps,\n CatchAllActionRenderProps,\n FrontendAction,\n} from \"../types/frontend-action\";\nimport React from \"react\";\nimport { TreeNodeId, Tree } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\nimport { CopilotChatSuggestionConfiguration } from \"../types/chat-suggestion-configuration\";\nimport { CoAgentStateRender, CoAgentStateRenderProps } from \"../types/coagent-action\";\nimport { CoagentState } from \"../types/coagent-state\";\nimport {\n CopilotRuntimeClient,\n ExtensionsInput,\n ForwardedParametersInput,\n} from \"@copilotkit/runtime-client-gql\";\nimport { Agent } from \"@copilotkit/runtime-client-gql\";\nimport {\n LangGraphInterruptAction,\n LangGraphInterruptActionSetter,\n} from \"../types/interrupt-action\";\nimport { SuggestionItem } from \"../utils/suggestions\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The public API key for Copilot Cloud.\n */\n publicApiKey?: string;\n\n /**\n * The configuration for Copilot Cloud.\n */\n cloud?: CopilotCloudConfig;\n\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the Copilot transcribe audio service.\n */\n transcribeAudioUrl?: string;\n\n /**\n * The endpoint for the Copilot text to speech service.\n */\n textToSpeechUrl?: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Custom properties to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n properties?: Record<string, any>;\n\n /**\n * Indicates whether the user agent should send or receive cookies from the other domain\n * in the case of cross-origin requests.\n */\n credentials?: RequestCredentials;\n\n /**\n * Optional configuration for connecting to Model Context Protocol (MCP) servers.\n * This is typically derived from the CopilotKitProps and used internally.\n * @experimental\n */\n mcpServers?: Array<{ endpoint: string; apiKey?: string }>;\n}\n\nexport type InChatRenderFunction<TProps = ActionRenderProps<any> | CatchAllActionRenderProps<any>> =\n (props: TProps) => string | JSX.Element;\nexport type CoagentInChatRenderFunction = (\n props: CoAgentStateRenderProps<any>,\n) => string | JSX.Element | undefined | null;\n\nexport interface ChatComponentsCache {\n actions: Record<string, InChatRenderFunction | string>;\n coAgentStateRenders: Record<string, CoagentInChatRenderFunction | string>;\n}\n\nexport interface AgentSession {\n agentName: string;\n threadId?: string;\n nodeName?: string;\n}\n\nexport interface AuthState {\n status: \"authenticated\" | \"unauthenticated\";\n authHeaders: Record<string, string>;\n userId?: string;\n metadata?: Record<string, any>;\n}\n\nexport type ActionName = string;\nexport type ContextTree = Tree;\n\nexport interface CopilotContextParams {\n // function-calling\n actions: Record<string, FrontendAction<any>>;\n setAction: (id: string, action: FrontendAction<any>) => void;\n removeAction: (id: string) => void;\n\n // coagent actions\n coAgentStateRenders: Record<string, CoAgentStateRender<any>>;\n setCoAgentStateRender: (id: string, stateRender: CoAgentStateRender<any>) => void;\n removeCoAgentStateRender: (id: string) => void;\n\n chatComponentsCache: React.RefObject<ChatComponentsCache>;\n\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => FunctionCallHandler;\n\n // text context\n addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n getAllContext: () => Tree;\n getContextString: (documents: DocumentPointer[], categories: string[]) => string;\n\n // document context\n addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n getDocumentsContext: (categories: string[]) => DocumentPointer[];\n\n isLoading: boolean;\n setIsLoading: React.Dispatch<React.SetStateAction<boolean>>;\n\n chatSuggestionConfiguration: { [key: string]: CopilotChatSuggestionConfiguration };\n addChatSuggestionConfiguration: (\n id: string,\n suggestion: CopilotChatSuggestionConfiguration,\n ) => void;\n removeChatSuggestionConfiguration: (id: string) => void;\n\n chatInstructions: string;\n setChatInstructions: React.Dispatch<React.SetStateAction<string>>;\n\n additionalInstructions?: string[];\n setAdditionalInstructions: React.Dispatch<React.SetStateAction<string[]>>;\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n\n showDevConsole: boolean;\n\n // agents\n coagentStates: Record<string, CoagentState>;\n setCoagentStates: React.Dispatch<React.SetStateAction<Record<string, CoagentState>>>;\n coagentStatesRef: React.RefObject<Record<string, CoagentState>>;\n setCoagentStatesWithRef: (\n value:\n | Record<string, CoagentState>\n | ((prev: Record<string, CoagentState>) => Record<string, CoagentState>),\n ) => void;\n\n agentSession: AgentSession | null;\n setAgentSession: React.Dispatch<React.SetStateAction<AgentSession | null>>;\n\n agentLock: string | null;\n\n threadId: string;\n setThreadId: React.Dispatch<React.SetStateAction<string>>;\n\n runId: string | null;\n setRunId: React.Dispatch<React.SetStateAction<string | null>>;\n\n // The chat abort controller can be used to stop generation globally,\n // i.e. when using `stop()` from `useChat`\n chatAbortControllerRef: React.MutableRefObject<AbortController | null>;\n\n // runtime\n runtimeClient: CopilotRuntimeClient;\n\n /**\n * The forwarded parameters to use for the task.\n */\n forwardedParameters?: Partial<Pick<ForwardedParametersInput, \"temperature\">>;\n availableAgents: Agent[];\n\n /**\n * The auth states for the CopilotKit.\n */\n authStates_c?: Record<ActionName, AuthState>;\n setAuthStates_c?: React.Dispatch<React.SetStateAction<Record<ActionName, AuthState>>>;\n\n /**\n * The auth config for the CopilotKit.\n */\n authConfig_c?: {\n SignInComponent: React.ComponentType<{\n onSignInComplete: (authState: AuthState) => void;\n }>;\n };\n\n extensions: ExtensionsInput;\n setExtensions: React.Dispatch<React.SetStateAction<ExtensionsInput>>;\n langGraphInterruptAction: LangGraphInterruptAction | null;\n setLangGraphInterruptAction: LangGraphInterruptActionSetter;\n removeLangGraphInterruptAction: () => void;\n\n /**\n * Optional trace handler for comprehensive debugging and observability.\n */\n onError: CopilotErrorHandler;\n\n // banner error state\n bannerError: CopilotKitError | null;\n setBannerError: React.Dispatch<React.SetStateAction<CopilotKitError | null>>;\n // Internal error handlers\n // These are used to handle errors that occur during the execution of the chat.\n // They are not intended for use by the developer. A component can register itself an error listener to be activated somewhere else as needed\n internalErrorHandlers: Record<string, CopilotErrorHandler>;\n setInternalErrorHandler: (handler: Record<string, CopilotErrorHandler>) => void;\n removeInternalErrorHandler: (id: string) => void;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n actions: {},\n setAction: () => {},\n removeAction: () => {},\n\n coAgentStateRenders: {},\n setCoAgentStateRender: () => {},\n removeCoAgentStateRender: () => {},\n\n chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n getAllContext: () => [],\n\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n\n isLoading: false,\n setIsLoading: () => returnAndThrowInDebug(false),\n\n chatInstructions: \"\",\n setChatInstructions: () => returnAndThrowInDebug(\"\"),\n\n additionalInstructions: [],\n setAdditionalInstructions: () => returnAndThrowInDebug([]),\n\n getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n runtimeClient: {} as any,\n\n copilotApiConfig: new (class implements CopilotApiConfig {\n get chatApiEndpoint(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n\n chatSuggestionConfiguration: {},\n addChatSuggestionConfiguration: () => {},\n removeChatSuggestionConfiguration: () => {},\n showDevConsole: false,\n coagentStates: {},\n setCoagentStates: () => {},\n coagentStatesRef: { current: {} },\n setCoagentStatesWithRef: () => {},\n agentSession: null,\n setAgentSession: () => {},\n forwardedParameters: {},\n agentLock: null,\n threadId: \"\",\n setThreadId: () => {},\n runId: null,\n setRunId: () => {},\n chatAbortControllerRef: { current: null },\n availableAgents: [],\n extensions: {},\n setExtensions: () => {},\n langGraphInterruptAction: null,\n setLangGraphInterruptAction: () => null,\n removeLangGraphInterruptAction: () => null,\n onError: () => {},\n bannerError: null,\n setBannerError: () => {},\n internalErrorHandlers: {},\n setInternalErrorHandler: () => {},\n removeInternalErrorHandler: () => {},\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n const context = React.useContext(CopilotContext);\n if (context === emptyCopilotContext) {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n return context;\n}\n\nfunction returnAndThrowInDebug<T>(_value: T): T {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n}\n"],"mappings":";;;;;AAWA,OAAO,WAAW;AAwOlB,IAAM,sBAA4C;AAAA,EAChD,SAAS,CAAC;AAAA,EACV,WAAW,MAAM;AAAA,EAAC;AAAA,EA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AC,EAAE;AAAA,EAChC,yBAAyB,MAAM;AAAA,EAAC;AAAA,EAChC,cAAc;AAAA,EACd,iBAAiB,MAAM;AAAA,EAAC;AAAA,EACxB,qBAAqB,CAAC;AAAA,EACtB,WAAW;AAAA,EACX,UAAU;AAAA,EACV,aAAa,MAAM;AAAA,EAAC;AAAA,EACpB,OAAO;AAAA,EACP,UAAU,MAAM;AAAA,EAAC;AAAA,EACjB,wBAAwB,EAAE,SAAS,KAAK;AAAA,EACxC,iBAAiB,CAAC;AAAA,EAClB,YAAY,CAAC;AAAA,EACb,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,0BAA0B;AAAA,EAC1B,6BAA6B,MAAM;AAAA,EACnC,gCAAgC,MAAM;AAAA,EACtC,SAAS,MAAM;AAAA,EAAC;AAAA,EAChB,aAAa;AAAA,EACb,gBAAgB,MAAM;AAAA,EAAC;AAAA,EACvB,uBAAuB,CAAC;AAAA,EACxB,yBAAyB,MAAM;AAAA,EAAC;AAAA,EAChC,4BAA4B,MAAM;AAAA,EAAC;AACrC;AAEO,IAAM,iBAAiB,MAAM,cAAoC,mBAAmB;AAEpF,SAAS,oBAA0C;AACxD,QAAM,UAAU,MAAM,WAAW,cAAc;AAC/C,MAAI,YAAY,qBAAqB;AACnC,UAAM,IAAI,MAAM,uEAAuE;AAAA,EACzF;AACA,SAAO;AACT;AAEA,SAAS,sBAAyB,QAAc;AAC9C,QAAM,IAAI,MAAM,uEAAuE;AACzF;","names":[]}
1
+ {"version":3,"sources":["../src/context/copilot-context.tsx"],"sourcesContent":["import {\n CopilotCloudConfig,\n FunctionCallHandler,\n CopilotErrorHandler,\n CopilotKitError,\n} from \"@copilotkit/shared\";\nimport {\n ActionRenderProps,\n CatchAllActionRenderProps,\n FrontendAction,\n} from \"../types/frontend-action\";\nimport React from \"react\";\nimport { TreeNodeId, Tree } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\nimport { CopilotChatSuggestionConfiguration } from \"../types/chat-suggestion-configuration\";\nimport { CoAgentStateRender, CoAgentStateRenderProps } from \"../types/coagent-action\";\nimport { CoagentState } from \"../types/coagent-state\";\nimport {\n CopilotRuntimeClient,\n ExtensionsInput,\n ForwardedParametersInput,\n} from \"@copilotkit/runtime-client-gql\";\nimport { Agent } from \"@copilotkit/runtime-client-gql\";\nimport {\n LangGraphInterruptAction,\n LangGraphInterruptActionSetter,\n} from \"../types/interrupt-action\";\nimport { SuggestionItem } from \"../utils/suggestions\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The public API key for Copilot Cloud.\n */\n publicApiKey?: string;\n\n /**\n * The configuration for Copilot Cloud.\n */\n cloud?: CopilotCloudConfig;\n\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the Copilot transcribe audio service.\n */\n transcribeAudioUrl?: string;\n\n /**\n * The endpoint for the Copilot text to speech service.\n */\n textToSpeechUrl?: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Custom properties to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n properties?: Record<string, any>;\n\n /**\n * Indicates whether the user agent should send or receive cookies from the other domain\n * in the case of cross-origin requests.\n */\n credentials?: RequestCredentials;\n\n /**\n * Optional configuration for connecting to Model Context Protocol (MCP) servers.\n * This is typically derived from the CopilotKitProps and used internally.\n * @experimental\n */\n mcpServers?: Array<{ endpoint: string; apiKey?: string }>;\n}\n\nexport type InChatRenderFunction<TProps = ActionRenderProps<any> | CatchAllActionRenderProps<any>> =\n (props: TProps) => string | JSX.Element;\nexport type CoagentInChatRenderFunction = (\n props: CoAgentStateRenderProps<any>,\n) => string | JSX.Element | undefined | null;\n\nexport interface ChatComponentsCache {\n actions: Record<string, InChatRenderFunction | string>;\n coAgentStateRenders: Record<string, CoagentInChatRenderFunction | string>;\n}\n\nexport interface AgentSession {\n agentName: string;\n threadId?: string;\n nodeName?: string;\n}\n\nexport interface AuthState {\n status: \"authenticated\" | \"unauthenticated\";\n authHeaders: Record<string, string>;\n userId?: string;\n metadata?: Record<string, any>;\n}\n\nexport type ActionName = string;\nexport type ContextTree = Tree;\n\nexport interface CopilotContextParams {\n // function-calling\n actions: Record<string, FrontendAction<any>>;\n setAction: (id: string, action: FrontendAction<any>) => void;\n removeAction: (id: string) => void;\n\n // coagent actions\n coAgentStateRenders: Record<string, CoAgentStateRender<any>>;\n setCoAgentStateRender: (id: string, stateRender: CoAgentStateRender<any>) => void;\n removeCoAgentStateRender: (id: string) => void;\n\n chatComponentsCache: React.RefObject<ChatComponentsCache>;\n\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => FunctionCallHandler;\n\n // text context\n addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n getAllContext: () => Tree;\n getContextString: (documents: DocumentPointer[], categories: string[]) => string;\n\n // document context\n addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n getDocumentsContext: (categories: string[]) => DocumentPointer[];\n\n isLoading: boolean;\n setIsLoading: React.Dispatch<React.SetStateAction<boolean>>;\n\n chatSuggestionConfiguration: { [key: string]: CopilotChatSuggestionConfiguration };\n addChatSuggestionConfiguration: (\n id: string,\n suggestion: CopilotChatSuggestionConfiguration,\n ) => void;\n removeChatSuggestionConfiguration: (id: string) => void;\n\n chatInstructions: string;\n setChatInstructions: React.Dispatch<React.SetStateAction<string>>;\n\n additionalInstructions?: string[];\n setAdditionalInstructions: React.Dispatch<React.SetStateAction<string[]>>;\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n\n showDevConsole: boolean;\n\n // agents\n coagentStates: Record<string, CoagentState>;\n setCoagentStates: React.Dispatch<React.SetStateAction<Record<string, CoagentState>>>;\n coagentStatesRef: React.RefObject<Record<string, CoagentState>>;\n setCoagentStatesWithRef: (\n value:\n | Record<string, CoagentState>\n | ((prev: Record<string, CoagentState>) => Record<string, CoagentState>),\n ) => void;\n\n agentSession: AgentSession | null;\n setAgentSession: React.Dispatch<React.SetStateAction<AgentSession | null>>;\n\n agentLock: string | null;\n\n threadId: string;\n setThreadId: React.Dispatch<React.SetStateAction<string>>;\n\n runId: string | null;\n setRunId: React.Dispatch<React.SetStateAction<string | null>>;\n\n // The chat abort controller can be used to stop generation globally,\n // i.e. when using `stop()` from `useChat`\n chatAbortControllerRef: React.MutableRefObject<AbortController | null>;\n\n // runtime\n runtimeClient: CopilotRuntimeClient;\n\n /**\n * The forwarded parameters to use for the task.\n */\n forwardedParameters?: Partial<Pick<ForwardedParametersInput, \"temperature\">>;\n availableAgents: Agent[];\n\n /**\n * The auth states for the CopilotKit.\n */\n authStates_c?: Record<ActionName, AuthState>;\n setAuthStates_c?: React.Dispatch<React.SetStateAction<Record<ActionName, AuthState>>>;\n\n /**\n * The auth config for the CopilotKit.\n */\n authConfig_c?: {\n SignInComponent: React.ComponentType<{\n onSignInComplete: (authState: AuthState) => void;\n }>;\n };\n\n extensions: ExtensionsInput;\n setExtensions: React.Dispatch<React.SetStateAction<ExtensionsInput>>;\n langGraphInterruptAction: LangGraphInterruptAction | null;\n setLangGraphInterruptAction: LangGraphInterruptActionSetter;\n removeLangGraphInterruptAction: (threadId: string) => void;\n\n /**\n * Optional trace handler for comprehensive debugging and observability.\n */\n onError: CopilotErrorHandler;\n\n // banner error state\n bannerError: CopilotKitError | null;\n setBannerError: React.Dispatch<React.SetStateAction<CopilotKitError | null>>;\n // Internal error handlers\n // These are used to handle errors that occur during the execution of the chat.\n // They are not intended for use by the developer. A component can register itself an error listener to be activated somewhere else as needed\n internalErrorHandlers: Record<string, CopilotErrorHandler>;\n setInternalErrorHandler: (handler: Record<string, CopilotErrorHandler>) => void;\n removeInternalErrorHandler: (id: string) => void;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n actions: {},\n setAction: () => {},\n removeAction: () => {},\n\n coAgentStateRenders: {},\n setCoAgentStateRender: () => {},\n removeCoAgentStateRender: () => {},\n\n chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n getAllContext: () => [],\n\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n\n isLoading: false,\n setIsLoading: () => returnAndThrowInDebug(false),\n\n chatInstructions: \"\",\n setChatInstructions: () => returnAndThrowInDebug(\"\"),\n\n additionalInstructions: [],\n setAdditionalInstructions: () => returnAndThrowInDebug([]),\n\n getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n runtimeClient: {} as any,\n\n copilotApiConfig: new (class implements CopilotApiConfig {\n get chatApiEndpoint(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n\n chatSuggestionConfiguration: {},\n addChatSuggestionConfiguration: () => {},\n removeChatSuggestionConfiguration: () => {},\n showDevConsole: false,\n coagentStates: {},\n setCoagentStates: () => {},\n coagentStatesRef: { current: {} },\n setCoagentStatesWithRef: () => {},\n agentSession: null,\n setAgentSession: () => {},\n forwardedParameters: {},\n agentLock: null,\n threadId: \"\",\n setThreadId: () => {},\n runId: null,\n setRunId: () => {},\n chatAbortControllerRef: { current: null },\n availableAgents: [],\n extensions: {},\n setExtensions: () => {},\n langGraphInterruptAction: null,\n setLangGraphInterruptAction: () => {},\n removeLangGraphInterruptAction: () => {},\n onError: () => {},\n bannerError: null,\n setBannerError: () => {},\n internalErrorHandlers: {},\n setInternalErrorHandler: () => {},\n removeInternalErrorHandler: () => {},\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n const context = React.useContext(CopilotContext);\n if (context === emptyCopilotContext) {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n return context;\n}\n\nfunction returnAndThrowInDebug<T>(_value: T): T {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n}\n"],"mappings":";;;;;AAWA,OAAO,WAAW;AAwOlB,IAAM,sBAA4C;AAAA,EAChD,SAAS,CAAC;AAAA,EACV,WAAW,MAAM;AAAA,EAAC;AAAA,EAClB,cAAc,MAAM;AAAA,EAAC;AAAA,EAErB,qBAAqB,CAAC;AAAA,EACtB,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAC9B,0BAA0B,MAAM;AAAA,EAAC;AAAA,EAEjC,qBAAqB,EAAE,SAAS,EAAE,SAAS,CAAC,GAAG,qBAAqB,CAAC,EAAE,EAAE;AAAA,EACzE,kBAAkB,CAAC,WAA8B,eAC/C,sBAAsB,EAAE;AAAA,EAC1B,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,eAAe,MAAM,CAAC;AAAA,EAEtB,wBAAwB,MAAM,sBAAsB,MAAY;AAAA,EAAC,EAAC;AAAA,EAElE,WAAW;AAAA,EACX,cAAc,MAAM,sBAAsB,KAAK;AAAA,EAE/C,kBAAkB;AAAA,EAClB,qBAAqB,MAAM,sBAAsB,EAAE;AAAA,EAEnD,wBAAwB,CAAC;AAAA,EACzB,2BAA2B,MAAM,sBAAsB,CAAC,CAAC;AAAA,EAEzD,qBAAqB,CAAC,eAAyB,sBAAsB,CAAC,CAAC;AAAA,EACvE,oBAAoB,MAAM,sBAAsB,EAAE;AAAA,EAClD,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAC9B,eAAe,CAAC;AAAA,EAEhB,kBAAkB,IAAK,MAAkC;AAAA,IACvD,IAAI,kBAA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E;AAAA,EACzF;AACA,SAAO;AACT;AAEA,SAAS,sBAAyB,QAAc;AAC9C,QAAM,IAAI,MAAM,uEAAuE;AACzF;","names":[]}
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  useCopilotAction
3
- } from "./chunk-AR7HJPGU.mjs";
3
+ } from "./chunk-HI6SPUOX.mjs";
4
4
  import {
5
5
  useCopilotContext
6
- } from "./chunk-YHT6CWIY.mjs";
6
+ } from "./chunk-EUX2P2E7.mjs";
7
7
  import {
8
8
  __spreadProps,
9
9
  __spreadValues
@@ -56,4 +56,4 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
56
56
  export {
57
57
  useCopilotAuthenticatedAction_c
58
58
  };
59
- //# sourceMappingURL=chunk-4JBVPOHK.mjs.map
59
+ //# sourceMappingURL=chunk-GIGUZ2OK.mjs.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useCopilotContext
3
- } from "./chunk-YHT6CWIY.mjs";
3
+ } from "./chunk-EUX2P2E7.mjs";
4
4
 
5
5
  // src/hooks/use-copilot-readable.ts
6
6
  import { useEffect, useRef } from "react";
@@ -34,4 +34,4 @@ function useCopilotReadable({
34
34
  export {
35
35
  useCopilotReadable
36
36
  };
37
- //# sourceMappingURL=chunk-36FJAVOF.mjs.map
37
+ //# sourceMappingURL=chunk-HDOG2RTM.mjs.map
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-N4WEHORG.mjs";
4
4
  import {
5
5
  useCopilotContext
6
- } from "./chunk-YHT6CWIY.mjs";
6
+ } from "./chunk-EUX2P2E7.mjs";
7
7
  import {
8
8
  useToast
9
9
  } from "./chunk-EFL5OBKN.mjs";
@@ -139,4 +139,4 @@ function isFrontendAction(action) {
139
139
  export {
140
140
  useCopilotAction
141
141
  };
142
- //# sourceMappingURL=chunk-AR7HJPGU.mjs.map
142
+ //# sourceMappingURL=chunk-HI6SPUOX.mjs.map
@@ -1,22 +1,22 @@
1
1
  import {
2
2
  useLangGraphInterruptRender
3
- } from "./chunk-QF3Q5LUN.mjs";
3
+ } from "./chunk-ZVOLWJCY.mjs";
4
4
  import {
5
5
  defaultCopilotContextCategories,
6
6
  reloadSuggestions
7
- } from "./chunk-7LZXD5RJ.mjs";
7
+ } from "./chunk-ITDKIB5E.mjs";
8
8
  import {
9
9
  useCopilotMessagesContext
10
10
  } from "./chunk-ZLQVRPDS.mjs";
11
11
  import {
12
12
  useChat
13
- } from "./chunk-6INCKUL6.mjs";
13
+ } from "./chunk-3N4MVKFZ.mjs";
14
14
  import {
15
15
  useAsyncCallback
16
16
  } from "./chunk-N4WEHORG.mjs";
17
17
  import {
18
18
  useCopilotContext
19
- } from "./chunk-YHT6CWIY.mjs";
19
+ } from "./chunk-EUX2P2E7.mjs";
20
20
  import {
21
21
  __async,
22
22
  __spreadProps,
@@ -329,4 +329,4 @@ export {
329
329
  useCopilotChat,
330
330
  defaultSystemMessage
331
331
  };
332
- //# sourceMappingURL=chunk-FCRODLLL.mjs.map
332
+ //# sourceMappingURL=chunk-HYJUBYMU.mjs.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defaultCopilotContextCategories
3
- } from "./chunk-7LZXD5RJ.mjs";
3
+ } from "./chunk-ITDKIB5E.mjs";
4
4
  import {
5
5
  processActionsForRuntimeRequest
6
6
  } from "./chunk-4CEQJ2X6.mjs";
@@ -117,4 +117,4 @@ ${instructions}
117
117
  export {
118
118
  CopilotTask
119
119
  };
120
- //# sourceMappingURL=chunk-7D4OASUM.mjs.map
120
+ //# sourceMappingURL=chunk-IHV5PTID.mjs.map