@copilotkit/react-core 1.9.2-next.2 → 1.9.2-next.21

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 (170) hide show
  1. package/CHANGELOG.md +162 -0
  2. package/dist/{chunk-UHQMV2CE.mjs → chunk-36MGCCPZ.mjs} +2 -2
  3. package/dist/{chunk-CCESTGAM.mjs → chunk-3OQM3NEK.mjs} +2 -2
  4. package/dist/{chunk-OUSWPVDT.mjs → chunk-4URMLOBR.mjs} +4 -4
  5. package/dist/chunk-57K2ZJ5F.mjs +348 -0
  6. package/dist/chunk-57K2ZJ5F.mjs.map +1 -0
  7. package/dist/{chunk-LZDDYZEY.mjs → chunk-5BSUSFHM.mjs} +2 -2
  8. package/dist/{chunk-C6F6EQNA.mjs → chunk-BVK7PLK6.mjs} +2 -2
  9. package/dist/{chunk-CMKIDDQL.mjs → chunk-DDIBJUWK.mjs} +11 -8
  10. package/dist/{chunk-CMKIDDQL.mjs.map → chunk-DDIBJUWK.mjs.map} +1 -1
  11. package/dist/{chunk-NNSXCFQO.mjs → chunk-DGON3GZX.mjs} +42 -8
  12. package/dist/chunk-DGON3GZX.mjs.map +1 -0
  13. package/dist/{chunk-6KGEF242.mjs → chunk-DKZTPL66.mjs} +3 -2
  14. package/dist/chunk-DKZTPL66.mjs.map +1 -0
  15. package/dist/{chunk-LDACFA2B.mjs → chunk-FN3UA2ZE.mjs} +3 -3
  16. package/dist/{chunk-RUY6MLHA.mjs → chunk-JWAXDYOW.mjs} +36 -6
  17. package/dist/chunk-JWAXDYOW.mjs.map +1 -0
  18. package/dist/{chunk-2FW7HH6W.mjs → chunk-KIXKBJUV.mjs} +3 -3
  19. package/dist/{chunk-MGIXEJWG.mjs → chunk-MTAJI7HV.mjs} +181 -68
  20. package/dist/chunk-MTAJI7HV.mjs.map +1 -0
  21. package/dist/{chunk-L6QAOAE4.mjs → chunk-N2M65NJ2.mjs} +69 -25
  22. package/dist/chunk-N2M65NJ2.mjs.map +1 -0
  23. package/dist/{chunk-T42PN5VN.mjs → chunk-NJA5ZLAZ.mjs} +29 -10
  24. package/dist/chunk-NJA5ZLAZ.mjs.map +1 -0
  25. package/dist/{chunk-4I7PLQF7.mjs → chunk-QKEH3O4S.mjs} +5 -5
  26. package/dist/{chunk-FRZZPPIV.mjs → chunk-RAQK4M64.mjs} +2 -2
  27. package/dist/{chunk-QQZLIEXK.mjs → chunk-SJJNFYGQ.mjs} +3 -3
  28. package/dist/{chunk-Q5D5XQFA.mjs → chunk-VDADWRS3.mjs} +2 -2
  29. package/dist/chunk-YAF2LATQ.mjs +310 -0
  30. package/dist/chunk-YAF2LATQ.mjs.map +1 -0
  31. package/dist/components/copilot-provider/copilot-messages.js +40 -5
  32. package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
  33. package/dist/components/copilot-provider/copilot-messages.mjs +3 -3
  34. package/dist/components/copilot-provider/copilotkit-props.d.ts +27 -3
  35. package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
  36. package/dist/components/copilot-provider/copilotkit.d.ts +1 -1
  37. package/dist/components/copilot-provider/copilotkit.js +385 -254
  38. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  39. package/dist/components/copilot-provider/copilotkit.mjs +10 -10
  40. package/dist/components/copilot-provider/index.d.ts +1 -1
  41. package/dist/components/copilot-provider/index.js +385 -254
  42. package/dist/components/copilot-provider/index.js.map +1 -1
  43. package/dist/components/copilot-provider/index.mjs +10 -10
  44. package/dist/components/error-boundary/error-boundary.js +135 -146
  45. package/dist/components/error-boundary/error-boundary.js.map +1 -1
  46. package/dist/components/error-boundary/error-boundary.mjs +4 -4
  47. package/dist/components/error-boundary/error-utils.js.map +1 -1
  48. package/dist/components/error-boundary/error-utils.mjs +2 -2
  49. package/dist/components/index.d.ts +1 -1
  50. package/dist/components/index.js +385 -254
  51. package/dist/components/index.js.map +1 -1
  52. package/dist/components/index.mjs +10 -10
  53. package/dist/components/toast/toast-provider.js +118 -85
  54. package/dist/components/toast/toast-provider.js.map +1 -1
  55. package/dist/components/toast/toast-provider.mjs +1 -1
  56. package/dist/components/usage-banner.js +135 -146
  57. package/dist/components/usage-banner.js.map +1 -1
  58. package/dist/components/usage-banner.mjs +1 -1
  59. package/dist/context/copilot-context.d.ts +1 -1
  60. package/dist/context/copilot-context.js +2 -1
  61. package/dist/context/copilot-context.js.map +1 -1
  62. package/dist/context/copilot-context.mjs +1 -1
  63. package/dist/context/index.d.ts +1 -1
  64. package/dist/context/index.js +2 -1
  65. package/dist/context/index.js.map +1 -1
  66. package/dist/context/index.mjs +1 -1
  67. package/dist/{copilot-context-f9b2b4c3.d.ts → copilot-context-3ab4fdf5.d.ts} +6 -2
  68. package/dist/hooks/index.d.ts +1 -1
  69. package/dist/hooks/index.js +232 -71
  70. package/dist/hooks/index.js.map +1 -1
  71. package/dist/hooks/index.mjs +32 -32
  72. package/dist/hooks/use-chat.d.ts +1 -1
  73. package/dist/hooks/use-chat.js +295 -156
  74. package/dist/hooks/use-chat.js.map +1 -1
  75. package/dist/hooks/use-chat.mjs +6 -6
  76. package/dist/hooks/use-coagent-state-render.js +2 -1
  77. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  78. package/dist/hooks/use-coagent-state-render.mjs +3 -3
  79. package/dist/hooks/use-coagent.d.ts +1 -1
  80. package/dist/hooks/use-coagent.js +207 -65
  81. package/dist/hooks/use-coagent.js.map +1 -1
  82. package/dist/hooks/use-coagent.mjs +14 -14
  83. package/dist/hooks/use-copilot-action.js +27 -7
  84. package/dist/hooks/use-copilot-action.js.map +1 -1
  85. package/dist/hooks/use-copilot-action.mjs +4 -4
  86. package/dist/hooks/use-copilot-additional-instructions.js +2 -1
  87. package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
  88. package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
  89. package/dist/hooks/use-copilot-authenticated-action.js +27 -7
  90. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
  91. package/dist/hooks/use-copilot-authenticated-action.mjs +5 -5
  92. package/dist/hooks/use-copilot-chat.d.ts +1 -1
  93. package/dist/hooks/use-copilot-chat.js +204 -65
  94. package/dist/hooks/use-copilot-chat.js.map +1 -1
  95. package/dist/hooks/use-copilot-chat.mjs +13 -13
  96. package/dist/hooks/use-copilot-readable.js +2 -1
  97. package/dist/hooks/use-copilot-readable.js.map +1 -1
  98. package/dist/hooks/use-copilot-readable.mjs +2 -2
  99. package/dist/hooks/use-copilot-runtime-client.d.ts +2 -0
  100. package/dist/hooks/use-copilot-runtime-client.js +52 -2
  101. package/dist/hooks/use-copilot-runtime-client.js.map +1 -1
  102. package/dist/hooks/use-copilot-runtime-client.mjs +2 -2
  103. package/dist/hooks/use-langgraph-interrupt-render.js +2 -1
  104. package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
  105. package/dist/hooks/use-langgraph-interrupt-render.mjs +2 -2
  106. package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
  107. package/dist/hooks/use-langgraph-interrupt.js +204 -65
  108. package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
  109. package/dist/hooks/use-langgraph-interrupt.mjs +14 -14
  110. package/dist/hooks/use-make-copilot-document-readable.js +2 -1
  111. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  112. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  113. package/dist/index.d.ts +1 -1
  114. package/dist/index.js +582 -321
  115. package/dist/index.js.map +1 -1
  116. package/dist/index.mjs +33 -33
  117. package/dist/lib/copilot-task.d.ts +1 -1
  118. package/dist/lib/copilot-task.js.map +1 -1
  119. package/dist/lib/copilot-task.mjs +11 -11
  120. package/dist/lib/index.d.ts +1 -1
  121. package/dist/lib/index.js.map +1 -1
  122. package/dist/lib/index.mjs +11 -11
  123. package/dist/types/interrupt-action.d.ts +1 -1
  124. package/dist/utils/extract.d.ts +1 -1
  125. package/dist/utils/extract.js.map +1 -1
  126. package/dist/utils/extract.mjs +10 -10
  127. package/dist/utils/index.d.ts +1 -1
  128. package/dist/utils/index.js.map +1 -1
  129. package/dist/utils/index.mjs +10 -10
  130. package/jest.config.js +7 -3
  131. package/package.json +4 -3
  132. package/src/components/copilot-provider/__tests__/copilotkit-error.test.tsx +75 -0
  133. package/src/components/copilot-provider/copilot-messages.tsx +47 -6
  134. package/src/components/copilot-provider/copilotkit-props.tsx +27 -1
  135. package/src/components/copilot-provider/copilotkit.tsx +64 -18
  136. package/src/components/toast/toast-provider.tsx +49 -24
  137. package/src/components/usage-banner.tsx +144 -147
  138. package/src/context/copilot-context.tsx +8 -2
  139. package/src/hooks/use-chat.ts +247 -61
  140. package/src/hooks/use-coagent.ts +5 -0
  141. package/src/hooks/use-copilot-action.ts +51 -9
  142. package/src/hooks/use-copilot-runtime-client.ts +41 -40
  143. package/tsconfig.json +4 -8
  144. package/tsup.config.ts +6 -6
  145. package/dist/chunk-6KGEF242.mjs.map +0 -1
  146. package/dist/chunk-HD2GE3DK.mjs +0 -359
  147. package/dist/chunk-HD2GE3DK.mjs.map +0 -1
  148. package/dist/chunk-L6QAOAE4.mjs.map +0 -1
  149. package/dist/chunk-MGIXEJWG.mjs.map +0 -1
  150. package/dist/chunk-NNSXCFQO.mjs.map +0 -1
  151. package/dist/chunk-RUY6MLHA.mjs.map +0 -1
  152. package/dist/chunk-T42PN5VN.mjs.map +0 -1
  153. package/dist/chunk-VRXANACV.mjs +0 -277
  154. package/dist/chunk-VRXANACV.mjs.map +0 -1
  155. package/dist/utils/utils.test.d.ts +0 -2
  156. package/dist/utils/utils.test.js +0 -9
  157. package/dist/utils/utils.test.js.map +0 -1
  158. package/dist/utils/utils.test.mjs +0 -7
  159. package/dist/utils/utils.test.mjs.map +0 -1
  160. /package/dist/{chunk-UHQMV2CE.mjs.map → chunk-36MGCCPZ.mjs.map} +0 -0
  161. /package/dist/{chunk-CCESTGAM.mjs.map → chunk-3OQM3NEK.mjs.map} +0 -0
  162. /package/dist/{chunk-OUSWPVDT.mjs.map → chunk-4URMLOBR.mjs.map} +0 -0
  163. /package/dist/{chunk-LZDDYZEY.mjs.map → chunk-5BSUSFHM.mjs.map} +0 -0
  164. /package/dist/{chunk-C6F6EQNA.mjs.map → chunk-BVK7PLK6.mjs.map} +0 -0
  165. /package/dist/{chunk-LDACFA2B.mjs.map → chunk-FN3UA2ZE.mjs.map} +0 -0
  166. /package/dist/{chunk-2FW7HH6W.mjs.map → chunk-KIXKBJUV.mjs.map} +0 -0
  167. /package/dist/{chunk-4I7PLQF7.mjs.map → chunk-QKEH3O4S.mjs.map} +0 -0
  168. /package/dist/{chunk-FRZZPPIV.mjs.map → chunk-RAQK4M64.mjs.map} +0 -0
  169. /package/dist/{chunk-QQZLIEXK.mjs.map → chunk-SJJNFYGQ.mjs.map} +0 -0
  170. /package/dist/{chunk-Q5D5XQFA.mjs.map → chunk-VDADWRS3.mjs.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/context/index.ts","../../src/context/copilot-context.tsx","../../src/context/copilot-messages-context.tsx"],"sourcesContent":["export { CopilotContext, useCopilotContext } from \"./copilot-context\";\nexport { CopilotMessagesContext, useCopilotMessagesContext } from \"./copilot-messages-context\";\nexport type {\n CopilotContextParams,\n CoagentInChatRenderFunction,\n CopilotApiConfig,\n} from \"./copilot-context\";\nexport type { CopilotMessagesContextParams } from \"./copilot-messages-context\";\n","import { CopilotCloudConfig, FunctionCallHandler } 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\";\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?: 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\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};\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","/**\n * An internal context to separate the messages state (which is constantly changing) from the rest of CopilotKit context\n */\n\nimport { Message } from \"@copilotkit/runtime-client-gql\";\nimport React from \"react\";\n\nexport interface CopilotMessagesContextParams {\n messages: Message[];\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\n}\n\nconst emptyCopilotContext: CopilotMessagesContextParams = {\n messages: [],\n setMessages: () => [],\n};\n\nexport const CopilotMessagesContext =\n React.createContext<CopilotMessagesContextParams>(emptyCopilotContext);\n\nexport function useCopilotMessagesContext(): CopilotMessagesContextParams {\n const context = React.useContext(CopilotMessagesContext);\n if (context === emptyCopilotContext) {\n throw new Error(\n \"A messages consuming component was not wrapped with `<CopilotMessages> {...} </CopilotMessages>`\",\n );\n }\n return context;\n}\n"],"mappings":"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","names":["React","import_react","emptyCopilotContext","React"]}
1
+ {"version":3,"sources":["../../src/context/index.ts","../../src/context/copilot-context.tsx","../../src/context/copilot-messages-context.tsx"],"sourcesContent":["export { CopilotContext, useCopilotContext } from \"./copilot-context\";\nexport { CopilotMessagesContext, useCopilotMessagesContext } from \"./copilot-messages-context\";\nexport type {\n CopilotContextParams,\n CoagentInChatRenderFunction,\n CopilotApiConfig,\n} from \"./copilot-context\";\nexport type { CopilotMessagesContextParams } from \"./copilot-messages-context\";\n","import { CopilotCloudConfig, FunctionCallHandler, CopilotErrorHandler } 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\";\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\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: undefined,\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","/**\n * An internal context to separate the messages state (which is constantly changing) from the rest of CopilotKit context\n */\n\nimport { Message } from \"@copilotkit/runtime-client-gql\";\nimport React from \"react\";\n\nexport interface CopilotMessagesContextParams {\n messages: Message[];\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\n}\n\nconst emptyCopilotContext: CopilotMessagesContextParams = {\n messages: [],\n setMessages: () => [],\n};\n\nexport const CopilotMessagesContext =\n React.createContext<CopilotMessagesContextParams>(emptyCopilotContext);\n\nexport function useCopilotMessagesContext(): CopilotMessagesContextParams {\n const context = React.useContext(CopilotMessagesContext);\n if (context === emptyCopilotContext) {\n throw new Error(\n \"A messages consuming component was not wrapped with `<CopilotMessages> {...} </CopilotMessages>`\",\n );\n }\n return context;\n}\n"],"mappings":"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","names":["React","import_react","emptyCopilotContext","React"]}
@@ -6,7 +6,7 @@ import {
6
6
  import {
7
7
  CopilotContext,
8
8
  useCopilotContext
9
- } from "../chunk-6KGEF242.mjs";
9
+ } from "../chunk-DKZTPL66.mjs";
10
10
  import "../chunk-SKC7AJIV.mjs";
11
11
  export {
12
12
  CopilotContext,
@@ -1,4 +1,4 @@
1
- import { CopilotCloudConfig, FunctionCallHandler } from '@copilotkit/shared';
1
+ import { CopilotCloudConfig, FunctionCallHandler, CopilotErrorHandler } from '@copilotkit/shared';
2
2
  import { ActionRenderProps, CatchAllActionRenderProps, FrontendAction } from './types/frontend-action.js';
3
3
  import React$1 from 'react';
4
4
  import { Tree, TreeNodeId } from './hooks/use-tree.js';
@@ -169,7 +169,7 @@ interface CopilotContextParams {
169
169
  /**
170
170
  * The forwarded parameters to use for the task.
171
171
  */
172
- forwardedParameters?: Pick<ForwardedParametersInput, "temperature">;
172
+ forwardedParameters?: Partial<Pick<ForwardedParametersInput, "temperature">>;
173
173
  availableAgents: Agent[];
174
174
  /**
175
175
  * The auth states for the CopilotKit.
@@ -189,6 +189,10 @@ interface CopilotContextParams {
189
189
  langGraphInterruptAction: LangGraphInterruptAction | null;
190
190
  setLangGraphInterruptAction: LangGraphInterruptActionSetter;
191
191
  removeLangGraphInterruptAction: () => void;
192
+ /**
193
+ * Optional trace handler for comprehensive debugging and observability.
194
+ */
195
+ onError?: CopilotErrorHandler;
192
196
  }
193
197
  declare const CopilotContext: React$1.Context<CopilotContextParams>;
194
198
  declare function useCopilotContext(): CopilotContextParams;
@@ -18,7 +18,7 @@ import '../types/frontend-action.js';
18
18
  import 'react';
19
19
  import '../types/coagent-action.js';
20
20
  import '../types/document-pointer.js';
21
- import '../copilot-context-f9b2b4c3.js';
21
+ import '../copilot-context-3ab4fdf5.js';
22
22
  import '../types/chat-suggestion-configuration.js';
23
23
  import '../types/coagent-state.js';
24
24
  import '../context/copilot-messages-context.js';
@@ -172,7 +172,8 @@ var emptyCopilotContext = {
172
172
  },
173
173
  langGraphInterruptAction: null,
174
174
  setLangGraphInterruptAction: () => null,
175
- removeLangGraphInterruptAction: () => null
175
+ removeLangGraphInterruptAction: () => null,
176
+ onError: void 0
176
177
  };
177
178
  var CopilotContext = import_react.default.createContext(emptyCopilotContext);
178
179
  function useCopilotContext() {
@@ -191,6 +192,7 @@ var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
191
192
 
192
193
  // src/hooks/use-chat.ts
193
194
  var import_react5 = require("react");
195
+ var import_react_dom = require("react-dom");
194
196
  var import_shared4 = require("@copilotkit/shared");
195
197
  var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
196
198
 
@@ -247,8 +249,35 @@ function shouldShowDevConsole(showDevConsole) {
247
249
  // src/hooks/use-copilot-runtime-client.ts
248
250
  var useCopilotRuntimeClient = (options) => {
249
251
  const { setBannerError } = useToast();
250
- const _a = options, { showDevConsole } = _a, runtimeOptions = __objRest(_a, ["showDevConsole"]);
252
+ const _a = options, { showDevConsole, onError } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onError"]);
251
253
  const lastStructuredErrorRef = (0, import_react3.useRef)(null);
254
+ const traceUIError = (error, originalError) => __async(void 0, null, function* () {
255
+ if (!onError || !runtimeOptions.publicApiKey)
256
+ return;
257
+ try {
258
+ const errorEvent = {
259
+ type: "error",
260
+ timestamp: Date.now(),
261
+ context: {
262
+ source: "ui",
263
+ request: {
264
+ operation: "runtimeClient",
265
+ url: runtimeOptions.url,
266
+ startTime: Date.now()
267
+ },
268
+ technical: {
269
+ environment: "browser",
270
+ userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
271
+ stackTrace: originalError instanceof Error ? originalError.stack : void 0
272
+ }
273
+ },
274
+ error
275
+ };
276
+ yield onError(errorEvent);
277
+ } catch (error2) {
278
+ console.error("Error in onError handler:", error2);
279
+ }
280
+ });
252
281
  const runtimeClient = (0, import_react3.useMemo)(() => {
253
282
  return new import_runtime_client_gql2.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
254
283
  handleGQLErrors: (error) => {
@@ -276,12 +305,14 @@ var useCopilotRuntimeClient = (options) => {
276
305
  const ckError = createStructuredError(gqlError);
277
306
  if (ckError) {
278
307
  setBannerError(ckError);
308
+ traceUIError(ckError, gqlError);
279
309
  } else {
280
310
  const fallbackError = new import_shared3.CopilotKitError({
281
311
  message: gqlError.message,
282
312
  code: import_shared3.CopilotKitErrorCode.UNKNOWN
283
313
  });
284
314
  setBannerError(fallbackError);
315
+ traceUIError(fallbackError, gqlError);
285
316
  }
286
317
  };
287
318
  graphQLErrors.forEach(routeError);
@@ -295,6 +326,7 @@ var useCopilotRuntimeClient = (options) => {
295
326
  code: import_shared3.CopilotKitErrorCode.UNKNOWN
296
327
  });
297
328
  setBannerError(fallbackError);
329
+ traceUIError(fallbackError, error);
298
330
  }
299
331
  }
300
332
  },
@@ -307,7 +339,7 @@ var useCopilotRuntimeClient = (options) => {
307
339
  setBannerError(warningError);
308
340
  }
309
341
  }));
310
- }, [runtimeOptions, setBannerError, showDevConsole]);
342
+ }, [runtimeOptions, setBannerError, showDevConsole, onError]);
311
343
  return runtimeClient;
312
344
  };
313
345
  function createStructuredError(gqlError) {
@@ -479,6 +511,35 @@ function useChat(options) {
479
511
  } = options;
480
512
  const runChatCompletionRef = (0, import_react5.useRef)();
481
513
  const addErrorToast = useErrorToast();
514
+ const { setBannerError } = useToast();
515
+ const { onError } = useCopilotContext();
516
+ const traceUIError = (error, originalError) => __async(this, null, function* () {
517
+ if (!onError || !(copilotConfig == null ? void 0 : copilotConfig.publicApiKey))
518
+ return;
519
+ try {
520
+ const traceEvent = {
521
+ type: "error",
522
+ timestamp: Date.now(),
523
+ context: {
524
+ source: "ui",
525
+ request: {
526
+ operation: "useChatCompletion",
527
+ url: copilotConfig.chatApiEndpoint,
528
+ startTime: Date.now()
529
+ },
530
+ technical: {
531
+ environment: "browser",
532
+ userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
533
+ stackTrace: originalError instanceof Error ? originalError.stack : void 0
534
+ }
535
+ },
536
+ error
537
+ };
538
+ yield onError(traceEvent);
539
+ } catch (traceError) {
540
+ console.error("Error in use-chat onError handler:", traceError);
541
+ }
542
+ });
482
543
  const agentSessionRef = (0, import_react5.useRef)(agentSession);
483
544
  agentSessionRef.current = agentSession;
484
545
  const runIdRef = (0, import_react5.useRef)(runId);
@@ -498,7 +559,7 @@ function useChat(options) {
498
559
  const pendingAppendsRef = (0, import_react5.useRef)([]);
499
560
  const runChatCompletion = useAsyncCallback(
500
561
  (previousMessages) => __async(this, null, function* () {
501
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
562
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
502
563
  setIsLoading(true);
503
564
  const interruptEvent = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event;
504
565
  if ((interruptEvent == null ? void 0 : interruptEvent.name) === import_runtime_client_gql3.MetaEventName.LangGraphInterruptEvent && (interruptEvent == null ? void 0 : interruptEvent.value) && !(interruptEvent == null ? void 0 : interruptEvent.response) && agentSessionRef.current) {
@@ -630,20 +691,53 @@ function useChat(options) {
630
691
  messages2 = (0, import_runtime_client_gql3.convertGqlOutputToMessages)(
631
692
  (0, import_runtime_client_gql3.filterAdjacentAgentStateMessages)(rawMessagesResponse)
632
693
  );
633
- if (messages2.length === 0) {
634
- continue;
635
- }
636
694
  newMessages = [];
637
695
  if (((_k = value.generateCopilotResponse.status) == null ? void 0 : _k.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
696
+ const guardrailsReason = ((_l = value.generateCopilotResponse.status.details) == null ? void 0 : _l.guardrailsReason) || "";
638
697
  newMessages = [
639
698
  new import_runtime_client_gql3.TextMessage({
640
699
  role: import_runtime_client_gql3.MessageRole.Assistant,
641
- content: ((_l = value.generateCopilotResponse.status.details) == null ? void 0 : _l.guardrailsReason) || ""
700
+ content: guardrailsReason
642
701
  })
643
702
  ];
703
+ const guardrailsError = new import_shared4.CopilotKitError({
704
+ message: `Guardrails validation failed: ${guardrailsReason}`,
705
+ code: import_shared4.CopilotKitErrorCode.MISUSE
706
+ });
707
+ yield traceUIError(guardrailsError, {
708
+ statusReason: value.generateCopilotResponse.status.reason,
709
+ statusDetails: value.generateCopilotResponse.status.details
710
+ });
644
711
  setMessages([...previousMessages, ...newMessages]);
645
712
  break;
646
- } else {
713
+ }
714
+ if (((_m = value.generateCopilotResponse.status) == null ? void 0 : _m.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "UNKNOWN_ERROR") {
715
+ const errorMessage = ((_n = value.generateCopilotResponse.status.details) == null ? void 0 : _n.description) || "An unknown error occurred";
716
+ const statusDetails = value.generateCopilotResponse.status.details;
717
+ const originalError = (statusDetails == null ? void 0 : statusDetails.originalError) || (statusDetails == null ? void 0 : statusDetails.error);
718
+ const originalCode = (originalError == null ? void 0 : originalError.code) || ((_o = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _o.code);
719
+ const originalSeverity = (originalError == null ? void 0 : originalError.severity) || ((_p = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _p.severity);
720
+ const originalVisibility = (originalError == null ? void 0 : originalError.visibility) || ((_q = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _q.visibility);
721
+ let errorCode = import_shared4.CopilotKitErrorCode.NETWORK_ERROR;
722
+ if (originalCode && Object.values(import_shared4.CopilotKitErrorCode).includes(originalCode)) {
723
+ errorCode = originalCode;
724
+ }
725
+ const structuredError = new import_shared4.CopilotKitError({
726
+ message: errorMessage,
727
+ code: errorCode,
728
+ severity: originalSeverity,
729
+ visibility: originalVisibility
730
+ });
731
+ setBannerError(structuredError);
732
+ yield traceUIError(structuredError, {
733
+ statusReason: value.generateCopilotResponse.status.reason,
734
+ statusDetails: value.generateCopilotResponse.status.details,
735
+ originalErrorCode: originalCode,
736
+ preservedStructure: !!originalCode
737
+ });
738
+ setIsLoading(false);
739
+ break;
740
+ } else if (messages2.length > 0) {
647
741
  newMessages = [...messages2];
648
742
  for (const message of messages2) {
649
743
  if (message.isAgentStateMessage() && !message.active && !executedCoAgentStateRenders.includes(message.id) && onCoAgentStateRender) {
@@ -705,6 +799,39 @@ function useChat(options) {
705
799
  newMessages
706
800
  );
707
801
  let didExecuteAction = false;
802
+ const executeActionFromMessage = (currentAction, actionMessage) => __async(this, null, function* () {
803
+ var _a2;
804
+ const isInterruptAction = interruptMessages.find((m) => m.id === actionMessage.id);
805
+ followUp = (_a2 = currentAction == null ? void 0 : currentAction.followUp) != null ? _a2 : !isInterruptAction;
806
+ if (currentAction == null ? void 0 : currentAction._setActivatingMessageId) {
807
+ currentAction._setActivatingMessageId(actionMessage.id);
808
+ }
809
+ const resultMessage = yield executeAction({
810
+ onFunctionCall,
811
+ message: actionMessage,
812
+ chatAbortControllerRef,
813
+ onError: (error) => {
814
+ addErrorToast([error]);
815
+ console.error(`Failed to execute action ${actionMessage.name}: ${error}`);
816
+ },
817
+ setMessages,
818
+ getFinalMessages: () => finalMessages,
819
+ isRenderAndWait: (currentAction == null ? void 0 : currentAction._isRenderAndWait) || false
820
+ });
821
+ didExecuteAction = true;
822
+ const messageIndex = finalMessages.findIndex((msg) => msg.id === actionMessage.id);
823
+ finalMessages.splice(messageIndex + 1, 0, resultMessage);
824
+ if (currentAction == null ? void 0 : currentAction._isRenderAndWait) {
825
+ const messagesForImmediateUpdate = [...finalMessages];
826
+ (0, import_react_dom.flushSync)(() => {
827
+ setMessages(messagesForImmediateUpdate);
828
+ });
829
+ }
830
+ if (currentAction == null ? void 0 : currentAction._setActivatingMessageId) {
831
+ currentAction._setActivatingMessageId(null);
832
+ }
833
+ return resultMessage;
834
+ });
708
835
  if (onFunctionCall) {
709
836
  const lastMessages = [];
710
837
  for (let i = finalMessages.length - 1; i >= 0; i--) {
@@ -721,37 +848,28 @@ function useChat(options) {
721
848
  (action2) => action2.name === message.name
722
849
  );
723
850
  const currentResultMessagePairedFeAction = message.isResultMessage() ? getPairedFeAction(actions, message) : null;
724
- const executeActionFromMessage = (action2, message2) => __async(this, null, function* () {
725
- var _a2;
726
- const isInterruptAction = interruptMessages.find((m) => m.id === message2.id);
727
- followUp = (_a2 = action2 == null ? void 0 : action2.followUp) != null ? _a2 : !isInterruptAction;
728
- const resultMessage = yield executeAction({
729
- onFunctionCall,
730
- previousMessages,
731
- message: message2,
732
- chatAbortControllerRef,
733
- onError: (error) => {
734
- addErrorToast([error]);
735
- console.error(`Failed to execute action ${message2.name}: ${error}`);
736
- }
737
- });
738
- didExecuteAction = true;
739
- const messageIndex = finalMessages.findIndex((msg) => msg.id === message2.id);
740
- finalMessages.splice(messageIndex + 1, 0, resultMessage);
741
- return resultMessage;
742
- });
743
851
  if (action && message.isActionExecutionMessage()) {
744
- const resultMessage = yield executeActionFromMessage(action, message);
745
- const pairedFeAction = getPairedFeAction(actions, resultMessage);
746
- if (pairedFeAction) {
747
- const newExecutionMessage = new import_runtime_client_gql3.ActionExecutionMessage({
748
- name: pairedFeAction.name,
749
- arguments: (0, import_shared4.parseJson)(resultMessage.result, resultMessage.result),
750
- status: message.status,
751
- createdAt: message.createdAt,
752
- parentMessageId: message.parentMessageId
753
- });
754
- yield executeActionFromMessage(pairedFeAction, newExecutionMessage);
852
+ const isRenderAndWaitAction = (action == null ? void 0 : action._isRenderAndWait) || false;
853
+ const alreadyProcessed = isRenderAndWaitAction && finalMessages.some(
854
+ (fm) => fm.isResultMessage() && fm.actionExecutionId === message.id
855
+ );
856
+ if (alreadyProcessed) {
857
+ } else {
858
+ const resultMessage = yield executeActionFromMessage(
859
+ action,
860
+ message
861
+ );
862
+ const pairedFeAction = getPairedFeAction(actions, resultMessage);
863
+ if (pairedFeAction) {
864
+ const newExecutionMessage = new import_runtime_client_gql3.ActionExecutionMessage({
865
+ name: pairedFeAction.name,
866
+ arguments: (0, import_shared4.parseJson)(resultMessage.result, resultMessage.result),
867
+ status: message.status,
868
+ createdAt: message.createdAt,
869
+ parentMessageId: message.parentMessageId
870
+ });
871
+ yield executeActionFromMessage(pairedFeAction, newExecutionMessage);
872
+ }
755
873
  }
756
874
  } else if (message.isResultMessage() && currentResultMessagePairedFeAction) {
757
875
  const newExecutionMessage = new import_runtime_client_gql3.ActionExecutionMessage({
@@ -769,16 +887,12 @@ function useChat(options) {
769
887
  }
770
888
  setMessages(finalMessages);
771
889
  }
772
- if (
773
- // if followUp is not explicitly false
774
- followUp !== false && // and we executed an action
775
- (didExecuteAction || // the last message is a server side result
776
- !isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
777
- !((_m = chatAbortControllerRef.current) == null ? void 0 : _m.signal.aborted)
778
- ) {
890
+ if (followUp !== false && (didExecuteAction || // the last message is a server side result
891
+ !isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
892
+ !((_r = chatAbortControllerRef.current) == null ? void 0 : _r.signal.aborted)) {
779
893
  yield new Promise((resolve) => setTimeout(resolve, 10));
780
894
  return yield runChatCompletionRef.current(finalMessages);
781
- } else if ((_n = chatAbortControllerRef.current) == null ? void 0 : _n.signal.aborted) {
895
+ } else if ((_s = chatAbortControllerRef.current) == null ? void 0 : _s.signal.aborted) {
782
896
  const repairedMessages = finalMessages.filter((message, actionExecutionIndex) => {
783
897
  if (message.isActionExecutionMessage()) {
784
898
  return finalMessages.find(
@@ -789,7 +903,7 @@ function useChat(options) {
789
903
  });
790
904
  const repairedMessageIds = repairedMessages.map((message) => message.id);
791
905
  setMessages(repairedMessages);
792
- if ((_o = agentSessionRef.current) == null ? void 0 : _o.nodeName) {
906
+ if ((_t = agentSessionRef.current) == null ? void 0 : _t.nodeName) {
793
907
  setAgentSession({
794
908
  threadId: agentSessionRef.current.threadId,
795
909
  agentName: agentSessionRef.current.agentName,
@@ -883,21 +997,35 @@ function useChat(options) {
883
997
  [isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]
884
998
  );
885
999
  const reload = useAsyncCallback(
886
- (messageId) => __async(this, null, function* () {
1000
+ (reloadMessageId) => __async(this, null, function* () {
887
1001
  if (isLoading || messages.length === 0) {
888
1002
  return;
889
1003
  }
890
- const index = messages.findIndex((msg) => msg.id === messageId);
891
- if (index === -1) {
892
- console.warn(`Message with id ${messageId} not found`);
1004
+ const reloadMessageIndex = messages.findIndex((msg) => msg.id === reloadMessageId);
1005
+ if (reloadMessageIndex === -1) {
1006
+ console.warn(`Message with id ${reloadMessageId} not found`);
1007
+ return;
1008
+ }
1009
+ const reloadMessageRole = messages[reloadMessageIndex].role;
1010
+ if (reloadMessageRole !== import_runtime_client_gql3.MessageRole.Assistant) {
1011
+ console.warn(`Regenerate cannot be performed on ${reloadMessageRole} role`);
893
1012
  return;
894
1013
  }
895
- let newMessages = messages.slice(0, index);
896
- if (newMessages.length > 0 && newMessages[newMessages.length - 1].isAgentStateMessage()) {
897
- newMessages = newMessages.slice(0, newMessages.length - 1);
1014
+ let historyCutoff = [];
1015
+ if (messages.length > 2) {
1016
+ const lastUserMessageBeforeRegenerate = messages.slice(0, reloadMessageIndex).reverse().find(
1017
+ (msg) => (
1018
+ // @ts-expect-error -- message has role
1019
+ msg.role === import_runtime_client_gql3.MessageRole.User
1020
+ )
1021
+ );
1022
+ const indexOfLastUserMessageBeforeRegenerate = messages.findIndex(
1023
+ (msg) => msg.id === lastUserMessageBeforeRegenerate.id
1024
+ );
1025
+ historyCutoff = messages.slice(0, indexOfLastUserMessageBeforeRegenerate + 1);
898
1026
  }
899
- setMessages(newMessages);
900
- return runChatCompletionAndHandleFunctionCall(newMessages);
1027
+ setMessages(historyCutoff);
1028
+ return runChatCompletionAndHandleFunctionCall(historyCutoff);
901
1029
  }),
902
1030
  [isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]
903
1031
  );
@@ -932,20 +1060,31 @@ function constructFinalMessages(syncedMessages, previousMessages, newMessages) {
932
1060
  function executeAction(_0) {
933
1061
  return __async(this, arguments, function* ({
934
1062
  onFunctionCall,
935
- previousMessages,
936
1063
  message,
937
1064
  chatAbortControllerRef,
938
- onError
1065
+ onError,
1066
+ setMessages,
1067
+ getFinalMessages,
1068
+ isRenderAndWait
939
1069
  }) {
940
1070
  let result;
941
1071
  let error = null;
1072
+ const currentMessagesForHandler = getFinalMessages();
1073
+ const handlerReturnedPromise = onFunctionCall({
1074
+ messages: currentMessagesForHandler,
1075
+ name: message.name,
1076
+ args: message.arguments
1077
+ });
1078
+ if (isRenderAndWait) {
1079
+ const currentMessagesForRender = getFinalMessages();
1080
+ (0, import_react_dom.flushSync)(() => {
1081
+ setMessages([...currentMessagesForRender]);
1082
+ });
1083
+ }
942
1084
  try {
943
1085
  result = yield Promise.race([
944
- onFunctionCall({
945
- messages: previousMessages,
946
- name: message.name,
947
- args: message.arguments
948
- }),
1086
+ handlerReturnedPromise,
1087
+ // Await the promise returned by the handler
949
1088
  new Promise(
950
1089
  (resolve) => {
951
1090
  var _a;
@@ -993,7 +1132,7 @@ function getPairedFeAction(actions, message) {
993
1132
 
994
1133
  // src/components/copilot-provider/copilotkit.tsx
995
1134
  var import_react7 = require("react");
996
- var import_react_dom = require("react-dom");
1135
+ var import_react_dom2 = require("react-dom");
997
1136
  var import_shared5 = require("@copilotkit/shared");
998
1137
 
999
1138
  // src/context/copilot-messages-context.tsx
@@ -1238,6 +1377,7 @@ function useCopilotAction(action, dependencies) {
1238
1377
  const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
1239
1378
  const idRef = (0, import_react9.useRef)((0, import_shared6.randomId)());
1240
1379
  const renderAndWaitRef = (0, import_react9.useRef)(null);
1380
+ const activatingMessageIdRef = (0, import_react9.useRef)(null);
1241
1381
  const { addToast } = useToast();
1242
1382
  action = __spreadValues({}, action);
1243
1383
  if (
@@ -1245,30 +1385,48 @@ function useCopilotAction(action, dependencies) {
1245
1385
  isFrontendAction(action) && // check if renderAndWaitForResponse is set
1246
1386
  (action.renderAndWait || action.renderAndWaitForResponse)
1247
1387
  ) {
1388
+ action._isRenderAndWait = true;
1248
1389
  const renderAndWait = action.renderAndWait || action.renderAndWaitForResponse;
1249
1390
  action.renderAndWait = void 0;
1250
1391
  action.renderAndWaitForResponse = void 0;
1392
+ action._setActivatingMessageId = (id) => {
1393
+ activatingMessageIdRef.current = id;
1394
+ };
1251
1395
  action.handler = useAsyncCallback(() => __async(this, null, function* () {
1396
+ const currentActivatingId = activatingMessageIdRef.current;
1252
1397
  let resolve;
1253
1398
  let reject;
1254
1399
  const promise = new Promise((resolvePromise, rejectPromise) => {
1255
1400
  resolve = resolvePromise;
1256
1401
  reject = rejectPromise;
1257
1402
  });
1258
- renderAndWaitRef.current = { promise, resolve, reject };
1259
- return yield promise;
1403
+ renderAndWaitRef.current = {
1404
+ promise,
1405
+ resolve,
1406
+ reject,
1407
+ messageId: currentActivatingId
1408
+ };
1409
+ const result = yield promise;
1410
+ return result;
1260
1411
  }), []);
1261
1412
  action.render = (props) => {
1413
+ const currentRenderMessageId = props.messageId;
1262
1414
  let status = props.status;
1263
- if (props.status === "executing" && !renderAndWaitRef.current) {
1264
- status = "inProgress";
1415
+ if (props.status === "executing") {
1416
+ if (!renderAndWaitRef.current || !renderAndWaitRef.current.promise) {
1417
+ status = "inProgress";
1418
+ } else if (renderAndWaitRef.current.messageId !== currentRenderMessageId && activatingMessageIdRef.current !== currentRenderMessageId) {
1419
+ status = "inProgress";
1420
+ }
1265
1421
  }
1266
1422
  const waitProps = {
1267
1423
  status,
1268
1424
  args: props.args,
1269
1425
  result: props.result,
1270
- handler: status === "executing" ? renderAndWaitRef.current.resolve : void 0,
1271
- respond: status === "executing" ? renderAndWaitRef.current.resolve : void 0
1426
+ // handler and respond should only be provided if this is the truly active instance
1427
+ // and its promise infrastructure is ready.
1428
+ handler: status === "executing" && renderAndWaitRef.current && renderAndWaitRef.current.messageId === currentRenderMessageId ? renderAndWaitRef.current.resolve : void 0,
1429
+ respond: status === "executing" && renderAndWaitRef.current && renderAndWaitRef.current.messageId === currentRenderMessageId ? renderAndWaitRef.current.resolve : void 0
1272
1430
  };
1273
1431
  const isNoArgsRenderWait = (_fn) => {
1274
1432
  var _a;
@@ -1511,6 +1669,9 @@ function useCoAgent(options) {
1511
1669
  threadId,
1512
1670
  agentName: name
1513
1671
  });
1672
+ if (result.error) {
1673
+ return;
1674
+ }
1514
1675
  const newState = (_b = (_a = result.data) == null ? void 0 : _a.loadAgentState) == null ? void 0 : _b.state;
1515
1676
  if (newState === lastLoadedState.current)
1516
1677
  return;