@copilotkit/react-core 1.9.2-next.9 → 1.9.3-next.0

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 (147) hide show
  1. package/CHANGELOG.md +191 -0
  2. package/dist/{chunk-ERXWDCY6.mjs → chunk-36MGCCPZ.mjs} +2 -2
  3. package/dist/{chunk-UBNRUXEK.mjs → chunk-5BSUSFHM.mjs} +2 -2
  4. package/dist/{chunk-G7LYGERN.mjs → chunk-6ZLSC4KB.mjs} +124 -73
  5. package/dist/chunk-6ZLSC4KB.mjs.map +1 -0
  6. package/dist/{chunk-JDEWNLNP.mjs → chunk-BSAVFYRQ.mjs} +11 -11
  7. package/dist/{chunk-JDEWNLNP.mjs.map → chunk-BSAVFYRQ.mjs.map} +1 -1
  8. package/dist/{chunk-JPMIAGI6.mjs → chunk-BVK7PLK6.mjs} +2 -2
  9. package/dist/{chunk-FXK6RQIN.mjs → chunk-CUAFWKTQ.mjs} +4 -4
  10. package/dist/{chunk-XFOTNHYA.mjs → chunk-DKZTPL66.mjs} +2 -2
  11. package/dist/{chunk-XFOTNHYA.mjs.map → chunk-DKZTPL66.mjs.map} +1 -1
  12. package/dist/{chunk-EF5BNM34.mjs → chunk-FN3UA2ZE.mjs} +3 -3
  13. package/dist/{chunk-EXU7GWLC.mjs → chunk-GEE5AMYL.mjs} +9 -9
  14. package/dist/{chunk-WOGURSAL.mjs → chunk-GIMSRCVW.mjs} +64 -23
  15. package/dist/chunk-GIMSRCVW.mjs.map +1 -0
  16. package/dist/{chunk-55QZ2SVJ.mjs → chunk-JWAXDYOW.mjs} +8 -8
  17. package/dist/chunk-JWAXDYOW.mjs.map +1 -0
  18. package/dist/{chunk-3YHYWAHK.mjs → chunk-KIXKBJUV.mjs} +2 -2
  19. package/dist/{chunk-ADIITPD2.mjs → chunk-KLENTCQV.mjs} +34 -8
  20. package/dist/{chunk-ADIITPD2.mjs.map → chunk-KLENTCQV.mjs.map} +1 -1
  21. package/dist/{chunk-OF4SZTLL.mjs → chunk-NGQN3JRJ.mjs} +3 -3
  22. package/dist/{chunk-NQVCZQ5T.mjs → chunk-NJA5ZLAZ.mjs} +27 -8
  23. package/dist/chunk-NJA5ZLAZ.mjs.map +1 -0
  24. package/dist/{chunk-SJJNFYGQ.mjs → chunk-SGF6C7I6.mjs} +4 -4
  25. package/dist/{chunk-CMQV4XNY.mjs → chunk-VDADWRS3.mjs} +2 -2
  26. package/dist/components/copilot-provider/copilot-messages.js +7 -7
  27. package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
  28. package/dist/components/copilot-provider/copilot-messages.mjs +3 -3
  29. package/dist/components/copilot-provider/copilotkit-props.d.ts +14 -9
  30. package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
  31. package/dist/components/copilot-provider/copilotkit.d.ts +1 -1
  32. package/dist/components/copilot-provider/copilotkit.js +70 -29
  33. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  34. package/dist/components/copilot-provider/copilotkit.mjs +9 -9
  35. package/dist/components/copilot-provider/index.d.ts +1 -1
  36. package/dist/components/copilot-provider/index.js +70 -29
  37. package/dist/components/copilot-provider/index.js.map +1 -1
  38. package/dist/components/copilot-provider/index.mjs +9 -9
  39. package/dist/components/error-boundary/error-boundary.mjs +2 -2
  40. package/dist/components/index.d.ts +1 -1
  41. package/dist/components/index.js +70 -29
  42. package/dist/components/index.js.map +1 -1
  43. package/dist/components/index.mjs +9 -9
  44. package/dist/context/copilot-context.d.ts +1 -1
  45. package/dist/context/copilot-context.js +1 -1
  46. package/dist/context/copilot-context.js.map +1 -1
  47. package/dist/context/copilot-context.mjs +1 -1
  48. package/dist/context/index.d.ts +1 -1
  49. package/dist/context/index.js +1 -1
  50. package/dist/context/index.js.map +1 -1
  51. package/dist/context/index.mjs +4 -4
  52. package/dist/{copilot-context-3da805ab.d.ts → copilot-context-3ab4fdf5.d.ts} +3 -3
  53. package/dist/hooks/index.d.ts +1 -1
  54. package/dist/hooks/index.js +179 -83
  55. package/dist/hooks/index.js.map +1 -1
  56. package/dist/hooks/index.mjs +23 -23
  57. package/dist/hooks/use-chat.d.ts +1 -1
  58. package/dist/hooks/use-chat.js +220 -169
  59. package/dist/hooks/use-chat.js.map +1 -1
  60. package/dist/hooks/use-chat.mjs +4 -4
  61. package/dist/hooks/use-coagent-state-render.js +1 -1
  62. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  63. package/dist/hooks/use-coagent-state-render.mjs +2 -2
  64. package/dist/hooks/use-coagent.d.ts +1 -1
  65. package/dist/hooks/use-coagent.js +154 -77
  66. package/dist/hooks/use-coagent.js.map +1 -1
  67. package/dist/hooks/use-coagent.mjs +14 -14
  68. package/dist/hooks/use-copilot-action.js +26 -7
  69. package/dist/hooks/use-copilot-action.js.map +1 -1
  70. package/dist/hooks/use-copilot-action.mjs +2 -2
  71. package/dist/hooks/use-copilot-additional-instructions.js +1 -1
  72. package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
  73. package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
  74. package/dist/hooks/use-copilot-authenticated-action.js +26 -7
  75. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
  76. package/dist/hooks/use-copilot-authenticated-action.mjs +3 -3
  77. package/dist/hooks/use-copilot-chat.d.ts +1 -1
  78. package/dist/hooks/use-copilot-chat.js +128 -77
  79. package/dist/hooks/use-copilot-chat.js.map +1 -1
  80. package/dist/hooks/use-copilot-chat.mjs +13 -13
  81. package/dist/hooks/use-copilot-readable.js +1 -1
  82. package/dist/hooks/use-copilot-readable.js.map +1 -1
  83. package/dist/hooks/use-copilot-readable.mjs +2 -2
  84. package/dist/hooks/use-copilot-runtime-client.d.ts +2 -2
  85. package/dist/hooks/use-copilot-runtime-client.js +7 -7
  86. package/dist/hooks/use-copilot-runtime-client.js.map +1 -1
  87. package/dist/hooks/use-copilot-runtime-client.mjs +1 -1
  88. package/dist/hooks/use-langgraph-interrupt-render.js +1 -1
  89. package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
  90. package/dist/hooks/use-langgraph-interrupt-render.mjs +2 -2
  91. package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
  92. package/dist/hooks/use-langgraph-interrupt.js +128 -77
  93. package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
  94. package/dist/hooks/use-langgraph-interrupt.mjs +14 -14
  95. package/dist/hooks/use-make-copilot-document-readable.js +1 -1
  96. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  97. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  98. package/dist/index.d.ts +1 -1
  99. package/dist/index.js +240 -103
  100. package/dist/index.js.map +1 -1
  101. package/dist/index.mjs +27 -27
  102. package/dist/lib/copilot-task.d.ts +1 -1
  103. package/dist/lib/copilot-task.js.map +1 -1
  104. package/dist/lib/copilot-task.mjs +11 -11
  105. package/dist/lib/index.d.ts +1 -1
  106. package/dist/lib/index.js.map +1 -1
  107. package/dist/lib/index.mjs +11 -11
  108. package/dist/setupTests.d.ts +2 -0
  109. package/dist/setupTests.js +26 -0
  110. package/dist/setupTests.js.map +1 -0
  111. package/dist/setupTests.mjs +24 -0
  112. package/dist/setupTests.mjs.map +1 -0
  113. package/dist/types/interrupt-action.d.ts +1 -1
  114. package/dist/utils/extract.d.ts +1 -1
  115. package/dist/utils/extract.js.map +1 -1
  116. package/dist/utils/extract.mjs +9 -9
  117. package/dist/utils/index.d.ts +1 -1
  118. package/dist/utils/index.js.map +1 -1
  119. package/dist/utils/index.mjs +10 -10
  120. package/jest.config.js +4 -0
  121. package/package.json +6 -3
  122. package/src/components/copilot-provider/__tests__/{copilotkit-trace.test.tsx → copilotkit-error.test.tsx} +17 -17
  123. package/src/components/copilot-provider/copilot-messages.tsx +7 -7
  124. package/src/components/copilot-provider/copilotkit-props.tsx +13 -8
  125. package/src/components/copilot-provider/copilotkit.tsx +61 -19
  126. package/src/context/copilot-context.tsx +4 -4
  127. package/src/hooks/__tests__/use-coagent-config.test.ts +284 -0
  128. package/src/hooks/use-chat.ts +149 -61
  129. package/src/hooks/use-coagent.ts +36 -0
  130. package/src/hooks/use-copilot-action.ts +51 -9
  131. package/src/hooks/use-copilot-runtime-client.ts +11 -12
  132. package/src/setupTests.ts +26 -0
  133. package/tsconfig.json +5 -2
  134. package/dist/chunk-55QZ2SVJ.mjs.map +0 -1
  135. package/dist/chunk-G7LYGERN.mjs.map +0 -1
  136. package/dist/chunk-NQVCZQ5T.mjs.map +0 -1
  137. package/dist/chunk-WOGURSAL.mjs.map +0 -1
  138. /package/dist/{chunk-ERXWDCY6.mjs.map → chunk-36MGCCPZ.mjs.map} +0 -0
  139. /package/dist/{chunk-UBNRUXEK.mjs.map → chunk-5BSUSFHM.mjs.map} +0 -0
  140. /package/dist/{chunk-JPMIAGI6.mjs.map → chunk-BVK7PLK6.mjs.map} +0 -0
  141. /package/dist/{chunk-FXK6RQIN.mjs.map → chunk-CUAFWKTQ.mjs.map} +0 -0
  142. /package/dist/{chunk-EF5BNM34.mjs.map → chunk-FN3UA2ZE.mjs.map} +0 -0
  143. /package/dist/{chunk-EXU7GWLC.mjs.map → chunk-GEE5AMYL.mjs.map} +0 -0
  144. /package/dist/{chunk-3YHYWAHK.mjs.map → chunk-KIXKBJUV.mjs.map} +0 -0
  145. /package/dist/{chunk-OF4SZTLL.mjs.map → chunk-NGQN3JRJ.mjs.map} +0 -0
  146. /package/dist/{chunk-SJJNFYGQ.mjs.map → chunk-SGF6C7I6.mjs.map} +0 -0
  147. /package/dist/{chunk-CMQV4XNY.mjs.map → chunk-VDADWRS3.mjs.map} +0 -0
@@ -1,7 +1,7 @@
1
1
  import { ForwardedParametersInput } from '@copilotkit/runtime-client-gql';
2
2
  import { ReactNode } from 'react';
3
- import { f as AuthState } from '../../copilot-context-3da805ab.js';
4
- import { CopilotTraceHandler } from '@copilotkit/shared';
3
+ import { f as AuthState } from '../../copilot-context-3ab4fdf5.js';
4
+ import { CopilotErrorHandler } from '@copilotkit/shared';
5
5
  import '../../types/frontend-action.js';
6
6
  import '../../hooks/use-tree.js';
7
7
  import '../../types/document-pointer.js';
@@ -63,11 +63,16 @@ interface CopilotKitProps {
63
63
  */
64
64
  children: ReactNode;
65
65
  /**
66
- * Custom properties to be sent with the request
66
+ * Custom properties to be sent with the request.
67
+ * Can include threadMetadata for thread creation.
67
68
  * For example:
68
69
  * ```js
69
70
  * {
70
71
  * 'user_id': 'users_id',
72
+ * threadMetadata: {
73
+ * 'account_id': '123',
74
+ * 'user_type': 'premium'
75
+ * }
71
76
  * }
72
77
  * ```
73
78
  */
@@ -108,24 +113,24 @@ interface CopilotKitProps {
108
113
  */
109
114
  threadId?: string;
110
115
  /**
111
- * Optional trace handler for comprehensive debugging and observability.
116
+ * Optional error handler for comprehensive debugging and observability.
112
117
  *
113
- * **Requires publicApiKey**: Tracing only works when publicApiKey is provided.
118
+ * **Requires publicApiKey**: Error handling only works when publicApiKey is provided.
114
119
  * This is a premium CopilotKit Cloud feature.
115
120
  *
116
- * @param traceEvent - Structured trace event with rich debugging context
121
+ * @param errorEvent - Structured error event with rich debugging context
117
122
  *
118
123
  * @example
119
124
  * ```typescript
120
125
  * <CopilotKit
121
126
  * publicApiKey="ck_pub_your_key"
122
- * onTrace={(traceEvent) => {
123
- * debugDashboard.capture(traceEvent);
127
+ * onError={(errorEvent) => {
128
+ * debugDashboard.capture(errorEvent);
124
129
  * }}
125
130
  * >
126
131
  * ```
127
132
  */
128
- onTrace?: CopilotTraceHandler;
133
+ onError?: CopilotErrorHandler;
129
134
  }
130
135
 
131
136
  export { CopilotKitProps };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/copilot-provider/copilotkit-props.tsx"],"sourcesContent":["import { ForwardedParametersInput } from \"@copilotkit/runtime-client-gql\";\nimport { ReactNode } from \"react\";\nimport { AuthState } from \"../../context/copilot-context\";\nimport { CopilotTraceHandler } from \"@copilotkit/shared\";\n/**\n * Props for CopilotKit.\n */\n\nexport interface CopilotKitProps {\n /**\n * Your Copilot Cloud API key. Don't have it yet? Go to https://cloud.copilotkit.ai and get one for free.\n */\n publicApiKey?: string;\n\n /**\n * Restrict input to a specific topic.\n * @deprecated Use `guardrails_c` instead to control input restrictions\n */\n cloudRestrictToTopic?: {\n validTopics?: string[];\n invalidTopics?: string[];\n };\n\n /**\n * Restrict input to specific topics using guardrails.\n * @remarks\n *\n * This feature is only available when using CopilotKit's hosted cloud service. To use this feature, sign up at https://cloud.copilotkit.ai to get your publicApiKey. The feature allows restricting chat conversations to specific topics.\n */\n guardrails_c?: {\n validTopics?: string[];\n invalidTopics?: string[];\n };\n\n /**\n * The endpoint for the Copilot Runtime instance. [Click here for more information](/concepts/copilot-runtime).\n */\n runtimeUrl?: 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 *\n * For example:\n * ```json\n * {\n * \"Authorization\": \"Bearer X\"\n * }\n * ```\n */\n headers?: Record<string, string>;\n\n /**\n * The children to be rendered within the CopilotKit.\n */\n children: ReactNode;\n\n /**\n * Custom properties to be sent with the request\n * For example:\n * ```js\n * {\n * 'user_id': 'users_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 * Whether to show the dev console.\n *\n * Set to `true` to show error banners and toasts, `false` to hide all error UI.\n * Defaults to `false` for production safety.\n */\n showDevConsole?: boolean;\n\n /**\n * The name of the agent to use.\n */\n agent?: string;\n\n /**\n * The forwarded parameters to use for the task.\n */\n forwardedParameters?: Pick<ForwardedParametersInput, \"temperature\">;\n\n /**\n * The auth config to use for the CopilotKit.\n * @remarks\n *\n * This feature is only available when using CopilotKit's hosted cloud service. To use this feature, sign up at https://cloud.copilotkit.ai to get your publicApiKey. The feature allows restricting chat conversations to specific topics.\n */\n authConfig_c?: {\n SignInComponent: React.ComponentType<{\n onSignInComplete: (authState: AuthState) => void;\n }>;\n };\n\n /**\n * The thread id to use for the CopilotKit.\n */\n threadId?: string;\n\n /**\n * Optional trace handler for comprehensive debugging and observability.\n *\n * **Requires publicApiKey**: Tracing only works when publicApiKey is provided.\n * This is a premium CopilotKit Cloud feature.\n *\n * @param traceEvent - Structured trace event with rich debugging context\n *\n * @example\n * ```typescript\n * <CopilotKit\n * publicApiKey=\"ck_pub_your_key\"\n * onTrace={(traceEvent) => {\n * debugDashboard.capture(traceEvent);\n * }}\n * >\n * ```\n */\n onTrace?: CopilotTraceHandler;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../../src/components/copilot-provider/copilotkit-props.tsx"],"sourcesContent":["import { ForwardedParametersInput } from \"@copilotkit/runtime-client-gql\";\nimport { ReactNode } from \"react\";\nimport { AuthState } from \"../../context/copilot-context\";\nimport { CopilotErrorHandler } from \"@copilotkit/shared\";\n/**\n * Props for CopilotKit.\n */\n\nexport interface CopilotKitProps {\n /**\n * Your Copilot Cloud API key. Don't have it yet? Go to https://cloud.copilotkit.ai and get one for free.\n */\n publicApiKey?: string;\n\n /**\n * Restrict input to a specific topic.\n * @deprecated Use `guardrails_c` instead to control input restrictions\n */\n cloudRestrictToTopic?: {\n validTopics?: string[];\n invalidTopics?: string[];\n };\n\n /**\n * Restrict input to specific topics using guardrails.\n * @remarks\n *\n * This feature is only available when using CopilotKit's hosted cloud service. To use this feature, sign up at https://cloud.copilotkit.ai to get your publicApiKey. The feature allows restricting chat conversations to specific topics.\n */\n guardrails_c?: {\n validTopics?: string[];\n invalidTopics?: string[];\n };\n\n /**\n * The endpoint for the Copilot Runtime instance. [Click here for more information](/concepts/copilot-runtime).\n */\n runtimeUrl?: 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 *\n * For example:\n * ```json\n * {\n * \"Authorization\": \"Bearer X\"\n * }\n * ```\n */\n headers?: Record<string, string>;\n\n /**\n * The children to be rendered within the CopilotKit.\n */\n children: ReactNode;\n\n /**\n * Custom properties to be sent with the request.\n * Can include threadMetadata for thread creation.\n * For example:\n * ```js\n * {\n * 'user_id': 'users_id',\n * threadMetadata: {\n * 'account_id': '123',\n * 'user_type': 'premium'\n * }\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 * Whether to show the dev console.\n *\n * Set to `true` to show error banners and toasts, `false` to hide all error UI.\n * Defaults to `false` for production safety.\n */\n showDevConsole?: boolean;\n\n /**\n * The name of the agent to use.\n */\n agent?: string;\n\n /**\n * The forwarded parameters to use for the task.\n */\n forwardedParameters?: Pick<ForwardedParametersInput, \"temperature\">;\n\n /**\n * The auth config to use for the CopilotKit.\n * @remarks\n *\n * This feature is only available when using CopilotKit's hosted cloud service. To use this feature, sign up at https://cloud.copilotkit.ai to get your publicApiKey. The feature allows restricting chat conversations to specific topics.\n */\n authConfig_c?: {\n SignInComponent: React.ComponentType<{\n onSignInComplete: (authState: AuthState) => void;\n }>;\n };\n\n /**\n * The thread id to use for the CopilotKit.\n */\n threadId?: string;\n\n /**\n * Optional error handler for comprehensive debugging and observability.\n *\n * **Requires publicApiKey**: Error handling only works when publicApiKey is provided.\n * This is a premium CopilotKit Cloud feature.\n *\n * @param errorEvent - Structured error event with rich debugging context\n *\n * @example\n * ```typescript\n * <CopilotKit\n * publicApiKey=\"ck_pub_your_key\"\n * onError={(errorEvent) => {\n * debugDashboard.capture(errorEvent);\n * }}\n * >\n * ```\n */\n onError?: CopilotErrorHandler;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -2,7 +2,7 @@ import { CopilotKitProps } from './copilotkit-props.js';
2
2
  import * as react_jsx_runtime from 'react/jsx-runtime';
3
3
  import '@copilotkit/runtime-client-gql';
4
4
  import 'react';
5
- import '../../copilot-context-3da805ab.js';
5
+ import '../../copilot-context-3ab4fdf5.js';
6
6
  import '@copilotkit/shared';
7
7
  import '../../types/frontend-action.js';
8
8
  import '../../hooks/use-tree.js';
@@ -161,7 +161,7 @@ var emptyCopilotContext = {
161
161
  langGraphInterruptAction: null,
162
162
  setLangGraphInterruptAction: () => null,
163
163
  removeLangGraphInterruptAction: () => null,
164
- onTrace: void 0
164
+ onError: void 0
165
165
  };
166
166
  var CopilotContext = import_react.default.createContext(emptyCopilotContext);
167
167
  function useCopilotContext() {
@@ -706,11 +706,11 @@ function CopilotMessages({ children }) {
706
706
  const lastLoadedThreadId = (0, import_react6.useRef)();
707
707
  const lastLoadedAgentName = (0, import_react6.useRef)();
708
708
  const lastLoadedMessages = (0, import_react6.useRef)();
709
- const { threadId, agentSession, runtimeClient, showDevConsole, onTrace, copilotApiConfig } = useCopilotContext();
709
+ const { threadId, agentSession, runtimeClient, showDevConsole, onError, copilotApiConfig } = useCopilotContext();
710
710
  const { setBannerError } = useToast();
711
711
  const traceUIError = (0, import_react6.useCallback)(
712
712
  (error, originalError) => __async(this, null, function* () {
713
- if (!onTrace || !copilotApiConfig.publicApiKey)
713
+ if (!onError || !copilotApiConfig.publicApiKey)
714
714
  return;
715
715
  try {
716
716
  const traceEvent = {
@@ -731,12 +731,12 @@ function CopilotMessages({ children }) {
731
731
  },
732
732
  error
733
733
  };
734
- yield onTrace(traceEvent);
734
+ yield onError(traceEvent);
735
735
  } catch (traceError) {
736
- console.error("Error in CopilotMessages onTrace handler:", traceError);
736
+ console.error("Error in CopilotMessages onError handler:", traceError);
737
737
  }
738
738
  }),
739
- [onTrace, copilotApiConfig.publicApiKey, copilotApiConfig.chatApiEndpoint]
739
+ [onError, copilotApiConfig.publicApiKey, copilotApiConfig.chatApiEndpoint]
740
740
  );
741
741
  const createStructuredError2 = (gqlError) => {
742
742
  const extensions = gqlError.extensions;
@@ -841,7 +841,7 @@ function CopilotMessages({ children }) {
841
841
  }
842
842
  });
843
843
  void fetchMessages();
844
- }, [threadId, agentSession == null ? void 0 : agentSession.agentName, runtimeClient]);
844
+ }, [threadId, agentSession == null ? void 0 : agentSession.agentName]);
845
845
  const memoizedChildren = (0, import_react6.useMemo)(() => children, [children]);
846
846
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
847
847
  CopilotMessagesContext.Provider,
@@ -861,13 +861,13 @@ var import_react7 = require("react");
861
861
  var import_shared5 = require("@copilotkit/shared");
862
862
  var useCopilotRuntimeClient = (options) => {
863
863
  const { setBannerError } = useToast();
864
- const _a = options, { showDevConsole, onTrace } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onTrace"]);
864
+ const _a = options, { showDevConsole, onError } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onError"]);
865
865
  const lastStructuredErrorRef = (0, import_react7.useRef)(null);
866
866
  const traceUIError = (error, originalError) => __async(void 0, null, function* () {
867
- if (!onTrace || !runtimeOptions.publicApiKey)
867
+ if (!onError || !runtimeOptions.publicApiKey)
868
868
  return;
869
869
  try {
870
- const traceEvent = {
870
+ const errorEvent = {
871
871
  type: "error",
872
872
  timestamp: Date.now(),
873
873
  context: {
@@ -885,9 +885,9 @@ var useCopilotRuntimeClient = (options) => {
885
885
  },
886
886
  error
887
887
  };
888
- yield onTrace(traceEvent);
889
- } catch (traceError) {
890
- console.error("Error in onTrace handler:", traceError);
888
+ yield onError(errorEvent);
889
+ } catch (error2) {
890
+ console.error("Error in onError handler:", error2);
891
891
  }
892
892
  });
893
893
  const runtimeClient = (0, import_react7.useMemo)(() => {
@@ -951,7 +951,7 @@ var useCopilotRuntimeClient = (options) => {
951
951
  setBannerError(warningError);
952
952
  }
953
953
  }));
954
- }, [runtimeOptions, setBannerError, showDevConsole, onTrace]);
954
+ }, [runtimeOptions, setBannerError, showDevConsole, onError]);
955
955
  return runtimeClient;
956
956
  };
957
957
  function createStructuredError(gqlError) {
@@ -1721,18 +1721,24 @@ ${nonDocumentStrings}`;
1721
1721
  headers,
1722
1722
  credentials: copilotApiConfig.credentials,
1723
1723
  showDevConsole: (_b = props.showDevConsole) != null ? _b : false,
1724
- onTrace: props.onTrace
1724
+ onError: props.onError
1725
1725
  });
1726
1726
  const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react10.useState)({});
1727
- const addChatSuggestionConfiguration = (id, suggestion) => {
1728
- setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
1729
- };
1730
- const removeChatSuggestionConfiguration = (id) => {
1731
- setChatSuggestionConfiguration((prev) => {
1732
- const _a2 = prev, { [id]: _ } = _a2, rest = __objRest(_a2, [__restKey(id)]);
1733
- return rest;
1734
- });
1735
- };
1727
+ const addChatSuggestionConfiguration = (0, import_react10.useCallback)(
1728
+ (id, suggestion) => {
1729
+ setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
1730
+ },
1731
+ [setChatSuggestionConfiguration]
1732
+ );
1733
+ const removeChatSuggestionConfiguration = (0, import_react10.useCallback)(
1734
+ (id) => {
1735
+ setChatSuggestionConfiguration((prev) => {
1736
+ const _a2 = prev, { [id]: _ } = _a2, rest = __objRest(_a2, [__restKey(id)]);
1737
+ return rest;
1738
+ });
1739
+ },
1740
+ [setChatSuggestionConfiguration]
1741
+ );
1736
1742
  const [availableAgents, setAvailableAgents] = (0, import_react10.useState)([]);
1737
1743
  const [coagentStates, setCoagentStates] = (0, import_react10.useState)({});
1738
1744
  const coagentStatesRef = (0, import_react10.useRef)({});
@@ -1812,6 +1818,41 @@ ${nonDocumentStrings}`;
1812
1818
  setLangGraphInterruptAction(null);
1813
1819
  }, []);
1814
1820
  const memoizedChildren = (0, import_react10.useMemo)(() => children, [children]);
1821
+ const agentLock = (0, import_react10.useMemo)(() => {
1822
+ var _a2;
1823
+ return (_a2 = props.agent) != null ? _a2 : null;
1824
+ }, [props.agent]);
1825
+ const forwardedParameters = (0, import_react10.useMemo)(
1826
+ () => {
1827
+ var _a2;
1828
+ return (_a2 = props.forwardedParameters) != null ? _a2 : {};
1829
+ },
1830
+ [props.forwardedParameters]
1831
+ );
1832
+ const updateExtensions = (0, import_react10.useCallback)(
1833
+ (newExtensions) => {
1834
+ setExtensions((prev) => {
1835
+ const resolved = typeof newExtensions === "function" ? newExtensions(prev) : newExtensions;
1836
+ const isSameLength = Object.keys(resolved).length === Object.keys(prev).length;
1837
+ const isEqual = isSameLength && // @ts-ignore
1838
+ Object.entries(resolved).every(([key, value]) => prev[key] === value);
1839
+ return isEqual ? prev : resolved;
1840
+ });
1841
+ },
1842
+ [setExtensions]
1843
+ );
1844
+ const updateAuthStates = (0, import_react10.useCallback)(
1845
+ (newAuthStates) => {
1846
+ setAuthStates((prev) => {
1847
+ const resolved = typeof newAuthStates === "function" ? newAuthStates(prev) : newAuthStates;
1848
+ const isSameLength = Object.keys(resolved).length === Object.keys(prev).length;
1849
+ const isEqual = isSameLength && // @ts-ignore
1850
+ Object.entries(resolved).every(([key, value]) => prev[key] === value);
1851
+ return isEqual ? prev : resolved;
1852
+ });
1853
+ },
1854
+ [setAuthStates]
1855
+ );
1815
1856
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1816
1857
  CopilotContext.Provider,
1817
1858
  {
@@ -1849,8 +1890,8 @@ ${nonDocumentStrings}`;
1849
1890
  agentSession,
1850
1891
  setAgentSession,
1851
1892
  runtimeClient,
1852
- forwardedParameters: props.forwardedParameters || {},
1853
- agentLock: props.agent || null,
1893
+ forwardedParameters,
1894
+ agentLock,
1854
1895
  threadId: internalThreadId,
1855
1896
  setThreadId,
1856
1897
  runId,
@@ -1859,13 +1900,13 @@ ${nonDocumentStrings}`;
1859
1900
  availableAgents,
1860
1901
  authConfig_c: props.authConfig_c,
1861
1902
  authStates_c: authStates,
1862
- setAuthStates_c: setAuthStates,
1903
+ setAuthStates_c: updateAuthStates,
1863
1904
  extensions,
1864
- setExtensions,
1905
+ setExtensions: updateExtensions,
1865
1906
  langGraphInterruptAction,
1866
1907
  setLangGraphInterruptAction,
1867
1908
  removeLangGraphInterruptAction,
1868
- onTrace: props.onTrace
1909
+ onError: props.onError
1869
1910
  },
1870
1911
  children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CopilotMessages, { children: memoizedChildren })
1871
1912
  }