@copilotkit/react-core 1.5.9 → 1.5.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 (249) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/chunk-22XKTBPF.mjs +61 -0
  3. package/dist/chunk-22XKTBPF.mjs.map +1 -0
  4. package/dist/chunk-5FHSUKQL.mjs +70 -0
  5. package/dist/chunk-5FHSUKQL.mjs.map +1 -0
  6. package/dist/chunk-6BQVZFNO.mjs +35 -0
  7. package/dist/chunk-6BQVZFNO.mjs.map +1 -0
  8. package/dist/chunk-6U3UH3KO.mjs +140 -0
  9. package/dist/chunk-6U3UH3KO.mjs.map +1 -0
  10. package/dist/chunk-DCTJZ742.mjs +22 -0
  11. package/dist/chunk-DCTJZ742.mjs.map +1 -0
  12. package/dist/chunk-EFZPSZWO.mjs +1 -0
  13. package/dist/chunk-EFZPSZWO.mjs.map +1 -0
  14. package/dist/chunk-EWKJMQOF.mjs +107 -0
  15. package/dist/chunk-EWKJMQOF.mjs.map +1 -0
  16. package/dist/chunk-FQ53HQYZ.mjs +28 -0
  17. package/dist/chunk-FQ53HQYZ.mjs.map +1 -0
  18. package/dist/chunk-HIUT2NLX.mjs +23 -0
  19. package/dist/chunk-HIUT2NLX.mjs.map +1 -0
  20. package/dist/chunk-KXH7NSOV.mjs +215 -0
  21. package/dist/chunk-KXH7NSOV.mjs.map +1 -0
  22. package/dist/chunk-LHKIIAUQ.mjs +59 -0
  23. package/dist/chunk-LHKIIAUQ.mjs.map +1 -0
  24. package/dist/chunk-LNI2Z45S.mjs +242 -0
  25. package/dist/chunk-LNI2Z45S.mjs.map +1 -0
  26. package/dist/chunk-LUGEI4YQ.mjs +1 -0
  27. package/dist/chunk-LUGEI4YQ.mjs.map +1 -0
  28. package/dist/chunk-LZWH4OG5.mjs +482 -0
  29. package/dist/chunk-LZWH4OG5.mjs.map +1 -0
  30. package/dist/chunk-M2NT7NOO.mjs +120 -0
  31. package/dist/chunk-M2NT7NOO.mjs.map +1 -0
  32. package/dist/chunk-MLAS4QUR.mjs +18 -0
  33. package/dist/chunk-MLAS4QUR.mjs.map +1 -0
  34. package/dist/chunk-NR2BTA6Z.mjs +1 -0
  35. package/dist/chunk-NR2BTA6Z.mjs.map +1 -0
  36. package/dist/chunk-O7ARI5CV.mjs +31 -0
  37. package/dist/chunk-O7ARI5CV.mjs.map +1 -0
  38. package/dist/chunk-SKC7AJIV.mjs +61 -0
  39. package/dist/chunk-SKC7AJIV.mjs.map +1 -0
  40. package/dist/chunk-VGOFRULA.mjs +401 -0
  41. package/dist/chunk-VGOFRULA.mjs.map +1 -0
  42. package/dist/chunk-VNTDIJSG.mjs +37 -0
  43. package/dist/chunk-VNTDIJSG.mjs.map +1 -0
  44. package/dist/chunk-WXREY7UP.mjs +87 -0
  45. package/dist/chunk-WXREY7UP.mjs.map +1 -0
  46. package/dist/chunk-XERJQUHA.mjs +31 -0
  47. package/dist/chunk-XERJQUHA.mjs.map +1 -0
  48. package/dist/chunk-XXR4QFAQ.mjs +29 -0
  49. package/dist/chunk-XXR4QFAQ.mjs.map +1 -0
  50. package/dist/chunk-YMG27BON.mjs +160 -0
  51. package/dist/chunk-YMG27BON.mjs.map +1 -0
  52. package/dist/chunk-YPSGKPDA.mjs +1 -0
  53. package/dist/chunk-YPSGKPDA.mjs.map +1 -0
  54. package/dist/components/copilot-provider/copilot-messages.d.ts +16 -0
  55. package/dist/components/copilot-provider/copilot-messages.js +80 -0
  56. package/dist/components/copilot-provider/copilot-messages.js.map +1 -0
  57. package/dist/components/copilot-provider/copilot-messages.mjs +9 -0
  58. package/dist/components/copilot-provider/copilot-messages.mjs.map +1 -0
  59. package/dist/components/copilot-provider/copilotkit-props.d.ts +93 -0
  60. package/dist/components/copilot-provider/copilotkit-props.js +19 -0
  61. package/dist/components/copilot-provider/copilotkit-props.js.map +1 -0
  62. package/dist/components/copilot-provider/copilotkit-props.mjs +1 -0
  63. package/dist/components/copilot-provider/copilotkit-props.mjs.map +1 -0
  64. package/dist/components/copilot-provider/copilotkit.d.ts +18 -0
  65. package/dist/components/copilot-provider/copilotkit.js +990 -0
  66. package/dist/components/copilot-provider/copilotkit.js.map +1 -0
  67. package/dist/components/copilot-provider/copilotkit.mjs +22 -0
  68. package/dist/components/copilot-provider/copilotkit.mjs.map +1 -0
  69. package/dist/components/copilot-provider/index.d.ts +13 -0
  70. package/dist/components/copilot-provider/index.js +990 -0
  71. package/dist/components/copilot-provider/index.js.map +1 -0
  72. package/dist/components/copilot-provider/index.mjs +20 -0
  73. package/dist/components/copilot-provider/index.mjs.map +1 -0
  74. package/dist/components/error-boundary/error-boundary.d.ts +22 -0
  75. package/dist/components/error-boundary/error-boundary.js +183 -0
  76. package/dist/components/error-boundary/error-boundary.js.map +1 -0
  77. package/dist/components/error-boundary/error-boundary.mjs +12 -0
  78. package/dist/components/error-boundary/error-boundary.mjs.map +1 -0
  79. package/dist/components/error-boundary/error-utils.d.ts +11 -0
  80. package/dist/components/error-boundary/error-utils.js +177 -0
  81. package/dist/components/error-boundary/error-utils.js.map +1 -0
  82. package/dist/components/error-boundary/error-utils.mjs +13 -0
  83. package/dist/components/error-boundary/error-utils.mjs.map +1 -0
  84. package/dist/components/index.d.ts +13 -0
  85. package/dist/components/index.js +990 -0
  86. package/dist/components/index.js.map +1 -0
  87. package/dist/components/index.mjs +20 -0
  88. package/dist/components/index.mjs.map +1 -0
  89. package/dist/components/toast/exclamation-mark-icon.d.ts +9 -0
  90. package/dist/components/toast/exclamation-mark-icon.js +55 -0
  91. package/dist/components/toast/exclamation-mark-icon.js.map +1 -0
  92. package/dist/components/toast/exclamation-mark-icon.mjs +8 -0
  93. package/dist/components/toast/exclamation-mark-icon.mjs.map +1 -0
  94. package/dist/components/toast/toast-provider.d.ts +30 -0
  95. package/dist/components/toast/toast-provider.js +269 -0
  96. package/dist/components/toast/toast-provider.js.map +1 -0
  97. package/dist/components/toast/toast-provider.mjs +11 -0
  98. package/dist/components/toast/toast-provider.mjs.map +1 -0
  99. package/dist/context/copilot-context.d.ts +142 -0
  100. package/dist/context/copilot-context.js +138 -0
  101. package/dist/context/copilot-context.js.map +1 -0
  102. package/dist/context/copilot-context.mjs +10 -0
  103. package/dist/context/copilot-context.mjs.map +1 -0
  104. package/dist/context/copilot-messages-context.d.ts +15 -0
  105. package/dist/context/copilot-messages-context.js +57 -0
  106. package/dist/context/copilot-messages-context.js.map +1 -0
  107. package/dist/context/copilot-messages-context.mjs +10 -0
  108. package/dist/context/copilot-messages-context.mjs.map +1 -0
  109. package/dist/context/index.d.ts +11 -0
  110. package/dist/context/index.js +161 -0
  111. package/dist/context/index.js.map +1 -0
  112. package/dist/context/index.mjs +17 -0
  113. package/dist/context/index.mjs.map +1 -0
  114. package/dist/hooks/index.d.ts +21 -0
  115. package/dist/hooks/index.js +1303 -0
  116. package/dist/hooks/index.js.map +1 -0
  117. package/dist/hooks/index.mjs +56 -0
  118. package/dist/hooks/index.mjs.map +1 -0
  119. package/dist/hooks/use-chat.d.ts +124 -0
  120. package/dist/hooks/use-chat.js +608 -0
  121. package/dist/hooks/use-chat.js.map +1 -0
  122. package/dist/hooks/use-chat.mjs +12 -0
  123. package/dist/hooks/use-chat.mjs.map +1 -0
  124. package/dist/hooks/use-coagent-state-render.d.ts +60 -0
  125. package/dist/hooks/use-coagent-state-render.js +195 -0
  126. package/dist/hooks/use-coagent-state-render.js.map +1 -0
  127. package/dist/hooks/use-coagent-state-render.mjs +11 -0
  128. package/dist/hooks/use-coagent-state-render.mjs.map +1 -0
  129. package/dist/hooks/use-coagent.d.ts +199 -0
  130. package/dist/hooks/use-coagent.js +1064 -0
  131. package/dist/hooks/use-coagent.js.map +1 -0
  132. package/dist/hooks/use-coagent.mjs +29 -0
  133. package/dist/hooks/use-coagent.mjs.map +1 -0
  134. package/dist/hooks/use-copilot-action.d.ts +140 -0
  135. package/dist/hooks/use-copilot-action.js +369 -0
  136. package/dist/hooks/use-copilot-action.js.map +1 -0
  137. package/dist/hooks/use-copilot-action.mjs +11 -0
  138. package/dist/hooks/use-copilot-action.mjs.map +1 -0
  139. package/dist/hooks/use-copilot-authenticated-action.d.ts +8 -0
  140. package/dist/hooks/use-copilot-authenticated-action.js +418 -0
  141. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -0
  142. package/dist/hooks/use-copilot-authenticated-action.mjs +12 -0
  143. package/dist/hooks/use-copilot-authenticated-action.mjs.map +1 -0
  144. package/dist/hooks/use-copilot-chat.d.ts +38 -0
  145. package/dist/hooks/use-copilot-chat.js +928 -0
  146. package/dist/hooks/use-copilot-chat.js.map +1 -0
  147. package/dist/hooks/use-copilot-chat.mjs +24 -0
  148. package/dist/hooks/use-copilot-chat.mjs.map +1 -0
  149. package/dist/hooks/use-copilot-readable.d.ts +33 -0
  150. package/dist/hooks/use-copilot-readable.js +158 -0
  151. package/dist/hooks/use-copilot-readable.js.map +1 -0
  152. package/dist/hooks/use-copilot-readable.mjs +9 -0
  153. package/dist/hooks/use-copilot-readable.mjs.map +1 -0
  154. package/dist/hooks/use-copilot-runtime-client.d.ts +5 -0
  155. package/dist/hooks/use-copilot-runtime-client.js +182 -0
  156. package/dist/hooks/use-copilot-runtime-client.js.map +1 -0
  157. package/dist/hooks/use-copilot-runtime-client.mjs +10 -0
  158. package/dist/hooks/use-copilot-runtime-client.mjs.map +1 -0
  159. package/dist/hooks/use-flat-category-store.d.ts +9 -0
  160. package/dist/hooks/use-flat-category-store.js +90 -0
  161. package/dist/hooks/use-flat-category-store.js.map +1 -0
  162. package/dist/hooks/use-flat-category-store.mjs +8 -0
  163. package/dist/hooks/use-flat-category-store.mjs.map +1 -0
  164. package/dist/hooks/use-make-copilot-document-readable.d.ts +12 -0
  165. package/dist/hooks/use-make-copilot-document-readable.js +153 -0
  166. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -0
  167. package/dist/hooks/use-make-copilot-document-readable.mjs +9 -0
  168. package/dist/hooks/use-make-copilot-document-readable.mjs.map +1 -0
  169. package/dist/hooks/use-tree.d.ts +18 -0
  170. package/dist/hooks/use-tree.js +172 -0
  171. package/dist/hooks/use-tree.js.map +1 -0
  172. package/dist/hooks/use-tree.mjs +8 -0
  173. package/dist/hooks/use-tree.mjs.map +1 -0
  174. package/dist/index.d.ts +27 -0
  175. package/dist/index.js +2224 -0
  176. package/dist/index.js.map +1 -0
  177. package/dist/index.mjs +83 -0
  178. package/dist/index.mjs.map +1 -0
  179. package/dist/lib/copilot-task.d.ts +97 -0
  180. package/dist/lib/copilot-task.js +195 -0
  181. package/dist/lib/copilot-task.js.map +1 -0
  182. package/dist/lib/copilot-task.mjs +20 -0
  183. package/dist/lib/copilot-task.mjs.map +1 -0
  184. package/dist/lib/index.d.ts +11 -0
  185. package/dist/lib/index.js +197 -0
  186. package/dist/lib/index.js.map +1 -0
  187. package/dist/lib/index.mjs +21 -0
  188. package/dist/lib/index.mjs.map +1 -0
  189. package/dist/types/chat-suggestion-configuration.d.ts +22 -0
  190. package/dist/types/chat-suggestion-configuration.js +19 -0
  191. package/dist/types/chat-suggestion-configuration.js.map +1 -0
  192. package/dist/types/chat-suggestion-configuration.mjs +1 -0
  193. package/dist/types/chat-suggestion-configuration.mjs.map +1 -0
  194. package/dist/types/coagent-action.d.ts +29 -0
  195. package/dist/types/coagent-action.js +19 -0
  196. package/dist/types/coagent-action.js.map +1 -0
  197. package/dist/types/coagent-action.mjs +1 -0
  198. package/dist/types/coagent-action.mjs.map +1 -0
  199. package/dist/types/coagent-state.d.ts +11 -0
  200. package/dist/types/coagent-state.js +19 -0
  201. package/dist/types/coagent-state.js.map +1 -0
  202. package/dist/types/coagent-state.mjs +1 -0
  203. package/dist/types/coagent-state.mjs.map +1 -0
  204. package/dist/types/document-pointer.d.ts +9 -0
  205. package/dist/types/document-pointer.js +19 -0
  206. package/dist/types/document-pointer.js.map +1 -0
  207. package/dist/types/document-pointer.mjs +1 -0
  208. package/dist/types/document-pointer.mjs.map +1 -0
  209. package/dist/types/frontend-action.d.ts +126 -0
  210. package/dist/types/frontend-action.js +53 -0
  211. package/dist/types/frontend-action.js.map +1 -0
  212. package/dist/types/frontend-action.mjs +8 -0
  213. package/dist/types/frontend-action.mjs.map +1 -0
  214. package/dist/types/index.d.ts +7 -0
  215. package/dist/types/index.js +19 -0
  216. package/dist/types/index.js.map +1 -0
  217. package/dist/types/index.mjs +2 -0
  218. package/dist/types/index.mjs.map +1 -0
  219. package/dist/types/system-message.d.ts +3 -0
  220. package/dist/types/system-message.js +19 -0
  221. package/dist/types/system-message.js.map +1 -0
  222. package/dist/types/system-message.mjs +1 -0
  223. package/dist/types/system-message.mjs.map +1 -0
  224. package/dist/utils/dev-console.d.ts +3 -0
  225. package/dist/utils/dev-console.js +42 -0
  226. package/dist/utils/dev-console.js.map +1 -0
  227. package/dist/utils/dev-console.mjs +8 -0
  228. package/dist/utils/dev-console.mjs.map +1 -0
  229. package/dist/utils/extract.d.ts +43 -0
  230. package/dist/utils/extract.js +208 -0
  231. package/dist/utils/extract.js.map +1 -0
  232. package/dist/utils/extract.mjs +18 -0
  233. package/dist/utils/extract.mjs.map +1 -0
  234. package/dist/utils/index.d.ts +13 -0
  235. package/dist/utils/index.js +226 -0
  236. package/dist/utils/index.js.map +1 -0
  237. package/dist/utils/index.mjs +21 -0
  238. package/dist/utils/index.mjs.map +1 -0
  239. package/dist/utils/utils.d.ts +2 -0
  240. package/dist/utils/utils.js +19 -0
  241. package/dist/utils/utils.js.map +1 -0
  242. package/dist/utils/utils.mjs +1 -0
  243. package/dist/utils/utils.mjs.map +1 -0
  244. package/dist/utils/utils.test.d.ts +2 -0
  245. package/dist/utils/utils.test.js +9 -0
  246. package/dist/utils/utils.test.js.map +1 -0
  247. package/dist/utils/utils.test.mjs +7 -0
  248. package/dist/utils/utils.test.mjs.map +1 -0
  249. package/package.json +3 -3
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/use-chat.ts","../../src/types/frontend-action.ts","../../src/hooks/use-copilot-runtime-client.ts","../../src/components/toast/toast-provider.tsx","../../src/components/error-boundary/error-utils.tsx","../../src/components/toast/exclamation-mark-icon.tsx"],"sourcesContent":["import { useRef } from \"react\";\nimport {\n FunctionCallHandler,\n COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,\n CoAgentStateRenderHandler,\n randomId,\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} 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 } from \"../context/copilot-context\";\nimport { useCopilotRuntimeClient } from \"./use-copilot-runtime-client\";\nimport { useAsyncCallback } from \"../components/error-boundary/error-utils\";\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 | null;\n /**\n * set the current thread ID\n */\n setThreadId: (threadId: string | null) => 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\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) => 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: () => 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 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 } = options;\n const runChatCompletionRef = useRef<(previousMessages: Message[]) => Promise<Message[]>>();\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 const threadIdRef = useRef<string | null>(threadId);\n threadIdRef.current = threadId;\n const runIdRef = useRef<string | null>(runId);\n runIdRef.current = runId;\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 });\n\n const runChatCompletion = useAsyncCallback(\n async (previousMessages: Message[]): Promise<Message[]> => {\n setIsLoading(true);\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 systemMessage = makeSystemMessageCallback();\n\n const messagesWithContext = [systemMessage, ...(initialMessages || []), ...previousMessages];\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: threadIdRef.current,\n runId: runIdRef.current,\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 agentName: state.name,\n state: JSON.stringify(state.state),\n })),\n forwardedParameters: options.forwardedParameters || {},\n },\n properties: copilotConfig.properties,\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\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 threadIdRef.current = value.generateCopilotResponse.threadId || null;\n runIdRef.current = value.generateCopilotResponse.runId || null;\n\n setThreadId(threadIdRef.current);\n setRunId(runIdRef.current);\n\n messages = convertGqlOutputToMessages(\n filterAdjacentAgentStateMessages(value.generateCopilotResponse.messages),\n );\n\n if (messages.length === 0) {\n continue;\n }\n\n newMessages = [];\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 newMessages = [\n new TextMessage({\n role: MessageRole.Assistant,\n content: value.generateCopilotResponse.status.details?.guardrailsReason || \"\",\n }),\n ];\n setMessages([...previousMessages, ...newMessages]);\n break;\n }\n\n // add messages to the chat\n else {\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 },\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 const finalMessages = constructFinalMessages(syncedMessages, previousMessages, newMessages);\n\n let didExecuteAction = false;\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 for (let i = finalMessages.length - 1; i >= 0; i--) {\n const message = finalMessages[i];\n if (\n message.isActionExecutionMessage() &&\n message.status.code !== MessageStatusCode.Pending\n ) {\n lastMessages.unshift(message);\n } else {\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((action) => action.name === message.name);\n\n if (action) {\n followUp = action.followUp;\n let result: any;\n try {\n result = await Promise.race([\n onFunctionCall({\n messages: previousMessages,\n name: message.name,\n args: message.arguments,\n }),\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 result = `Failed to execute action ${message.name}`;\n console.error(`Failed to execute action ${message.name}: ${e}`);\n }\n didExecuteAction = true;\n const messageIndex = finalMessages.findIndex((msg) => msg.id === message.id);\n finalMessages.splice(\n messageIndex + 1,\n 0,\n new ResultMessage({\n id: \"result-\" + message.id,\n result: ResultMessage.encodeResult(result),\n actionExecutionId: message.id,\n actionName: message.name,\n }),\n );\n }\n }\n\n setMessages(finalMessages);\n }\n\n if (\n // if followUp is not explicitly false\n followUp !== false &&\n // and we executed an action\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 ],\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 const append = useAsyncCallback(\n async (message: Message): Promise<void> => {\n if (isLoading) {\n return;\n }\n\n const newMessages = [...messages, message];\n setMessages(newMessages);\n return runChatCompletionAndHandleFunctionCall(newMessages);\n },\n [isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall],\n );\n\n const reload = useAsyncCallback(async (): Promise<void> => {\n if (isLoading || messages.length === 0) {\n return;\n }\n let newMessages = [...messages];\n const lastMessage = messages[messages.length - 1];\n\n if (lastMessage.isTextMessage() && lastMessage.role === \"assistant\") {\n newMessages = newMessages.slice(0, -1);\n }\n\n setMessages(newMessages);\n\n return runChatCompletionAndHandleFunctionCall(newMessages);\n }, [isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]);\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","import { ActionInputAvailability } from \"@copilotkit/runtime-client-gql\";\nimport {\n Action,\n Parameter,\n MappedParameterTypes,\n actionParametersToJsonSchema,\n} from \"@copilotkit/shared\";\nimport React from \"react\";\n\ninterface InProgressState<T extends Parameter[] | [] = []> {\n status: \"inProgress\";\n args: Partial<MappedParameterTypes<T>>;\n result: undefined;\n}\n\ninterface ExecutingState<T extends Parameter[] | [] = []> {\n status: \"executing\";\n args: MappedParameterTypes<T>;\n result: undefined;\n}\n\ninterface CompleteState<T extends Parameter[] | [] = []> {\n status: \"complete\";\n args: MappedParameterTypes<T>;\n result: any;\n}\n\ninterface InProgressStateNoArgs<T extends Parameter[] | [] = []> {\n status: \"inProgress\";\n args: Partial<MappedParameterTypes<T>>;\n result: undefined;\n}\n\ninterface ExecutingStateNoArgs<T extends Parameter[] | [] = []> {\n status: \"executing\";\n args: MappedParameterTypes<T>;\n result: undefined;\n}\n\ninterface CompleteStateNoArgs<T extends Parameter[] | [] = []> {\n status: \"complete\";\n args: MappedParameterTypes<T>;\n result: any;\n}\n\ninterface InProgressStateWait<T extends Parameter[] | [] = []> {\n status: \"inProgress\";\n args: Partial<MappedParameterTypes<T>>;\n /** @deprecated use respond instead */\n handler: undefined;\n respond: undefined;\n result: undefined;\n}\n\ninterface ExecutingStateWait<T extends Parameter[] | [] = []> {\n status: \"executing\";\n args: MappedParameterTypes<T>;\n /** @deprecated use respond instead */\n handler: (result: any) => void;\n respond: (result: any) => void;\n result: undefined;\n}\n\ninterface CompleteStateWait<T extends Parameter[] | [] = []> {\n status: \"complete\";\n args: MappedParameterTypes<T>;\n /** @deprecated use respond instead */\n handler: undefined;\n respond: undefined;\n result: any;\n}\n\ninterface InProgressStateNoArgsWait<T extends Parameter[] | [] = []> {\n status: \"inProgress\";\n args: Partial<MappedParameterTypes<T>>;\n /** @deprecated use respond instead */\n handler: undefined;\n respond: undefined;\n result: undefined;\n}\n\ninterface ExecutingStateNoArgsWait<T extends Parameter[] | [] = []> {\n status: \"executing\";\n args: MappedParameterTypes<T>;\n /** @deprecated use respond instead */\n handler: (result: any) => void;\n respond: (result: any) => void;\n result: undefined;\n}\n\ninterface CompleteStateNoArgsWait<T extends Parameter[] | [] = []> {\n status: \"complete\";\n args: MappedParameterTypes<T>;\n /** @deprecated use respond instead */\n handler: undefined;\n respond: undefined;\n}\n\nexport type ActionRenderProps<T extends Parameter[] | [] = []> =\n | CompleteState<T>\n | ExecutingState<T>\n | InProgressState<T>;\n\nexport type ActionRenderPropsNoArgs<T extends Parameter[] | [] = []> =\n | CompleteStateNoArgs<T>\n | ExecutingStateNoArgs<T>\n | InProgressStateNoArgs<T>;\n\nexport type ActionRenderPropsWait<T extends Parameter[] | [] = []> =\n | CompleteStateWait<T>\n | ExecutingStateWait<T>\n | InProgressStateWait<T>;\n\nexport type ActionRenderPropsNoArgsWait<T extends Parameter[] | [] = []> =\n | CompleteStateNoArgsWait<T>\n | ExecutingStateNoArgsWait<T>\n | InProgressStateNoArgsWait<T>;\n\nexport type CatchAllActionRenderProps<T extends Parameter[] | [] = []> =\n | (CompleteState<T> & {\n name: string;\n })\n | (ExecutingState<T> & {\n name: string;\n })\n | (InProgressState<T> & {\n name: string;\n });\n\nexport type FrontendActionAvailability = \"disabled\" | \"enabled\" | \"remote\";\n\nexport type FrontendAction<\n T extends Parameter[] | [] = [],\n N extends string = string,\n> = Action<T> & {\n name: Exclude<N, \"*\">;\n /**\n * @deprecated Use `available` instead.\n */\n disabled?: boolean;\n available?: FrontendActionAvailability;\n followUp?: boolean;\n} & (\n | {\n render?:\n | string\n | (T extends []\n ? (props: ActionRenderPropsNoArgs<T>) => string | React.ReactElement\n : (props: ActionRenderProps<T>) => string | React.ReactElement);\n /** @deprecated use renderAndWaitForResponse instead */\n renderAndWait?: never;\n renderAndWaitForResponse?: never;\n }\n | {\n render?: never;\n /** @deprecated use renderAndWaitForResponse instead */\n renderAndWait?: T extends []\n ? (props: ActionRenderPropsNoArgsWait<T>) => React.ReactElement\n : (props: ActionRenderPropsWait<T>) => React.ReactElement;\n renderAndWaitForResponse?: T extends []\n ? (props: ActionRenderPropsNoArgsWait<T>) => React.ReactElement\n : (props: ActionRenderPropsWait<T>) => React.ReactElement;\n handler?: never;\n }\n );\n\nexport type CatchAllFrontendAction = {\n name: \"*\";\n render: (props: CatchAllActionRenderProps<any>) => React.ReactElement;\n};\n\nexport type RenderFunctionStatus = ActionRenderProps<any>[\"status\"];\n\nexport function processActionsForRuntimeRequest(actions: FrontendAction<any>[]) {\n const filteredActions = actions\n .filter(\n (action) =>\n action.available !== ActionInputAvailability.Disabled &&\n action.disabled !== true &&\n action.name !== \"*\",\n )\n .map((action) => {\n let available: ActionInputAvailability | undefined = ActionInputAvailability.Enabled;\n if (action.disabled) {\n available = ActionInputAvailability.Disabled;\n } else if (action.available === \"disabled\") {\n available = ActionInputAvailability.Disabled;\n } else if (action.available === \"remote\") {\n available = ActionInputAvailability.Remote;\n }\n return {\n name: action.name,\n description: action.description || \"\",\n jsonSchema: JSON.stringify(actionParametersToJsonSchema(action.parameters || [])),\n available,\n };\n });\n return filteredActions;\n}\n","import {\n CopilotRuntimeClient,\n CopilotRuntimeClientOptions,\n GraphQLError,\n} from \"@copilotkit/runtime-client-gql\";\nimport { useToast } from \"../components/toast/toast-provider\";\nimport { useMemo } from \"react\";\nimport { useErrorToast } from \"../components/error-boundary/error-utils\";\n\nexport const useCopilotRuntimeClient = (options: CopilotRuntimeClientOptions) => {\n const { addGraphQLErrorsToast } = useToast();\n const addErrorToast = useErrorToast();\n\n const runtimeClient = useMemo(() => {\n return new CopilotRuntimeClient({\n ...options,\n handleGQLErrors: (error) => {\n if ((error as any).graphQLErrors.length) {\n addGraphQLErrorsToast((error as any).graphQLErrors as GraphQLError[]);\n } else {\n addErrorToast([error]);\n }\n },\n });\n }, [options, addGraphQLErrorsToast]);\n\n return runtimeClient;\n};\n","import { GraphQLError } from \"@copilotkit/runtime-client-gql\";\nimport React, { createContext, useContext, useState, useCallback } from \"react\";\nimport { ErrorToast } from \"../error-boundary/error-utils\";\nimport { PartialBy } from \"@copilotkit/shared\";\n\ninterface Toast {\n id: string;\n message: string | React.ReactNode;\n type: \"info\" | \"success\" | \"warning\" | \"error\";\n duration?: number;\n}\n\ninterface ToastContextValue {\n toasts: Toast[];\n addToast: (toast: PartialBy<Toast, \"id\">) => void;\n addGraphQLErrorsToast: (errors: GraphQLError[]) => void;\n removeToast: (id: string) => void;\n enabled: boolean;\n}\n\nconst ToastContext = createContext<ToastContextValue | undefined>(undefined);\n\nexport function useToast() {\n const context = useContext(ToastContext);\n if (!context) {\n throw new Error(\"useToast must be used within a ToastProvider\");\n }\n return context;\n}\n\nexport function ToastProvider({\n enabled,\n children,\n}: {\n enabled: boolean;\n children: React.ReactNode;\n}) {\n const [toasts, setToasts] = useState<Toast[]>([]);\n const addToast = useCallback((toast: PartialBy<Toast, \"id\">) => {\n const id = toast.id ?? Math.random().toString(36).substring(2, 9);\n\n setToasts((currentToasts) => {\n if (currentToasts.find((toast) => toast.id === id)) return currentToasts;\n return [...currentToasts, { ...toast, id }];\n });\n\n if (toast.duration) {\n setTimeout(() => {\n removeToast(id);\n }, toast.duration);\n }\n }, []);\n\n const addGraphQLErrorsToast = useCallback((errors: GraphQLError[]) => {\n // We do not display these errors unless we are in dev mode.\n // if (!showDevConsole) {\n // return;\n // }\n\n addToast({\n type: \"error\",\n message: <ErrorToast errors={errors} />,\n });\n }, []);\n\n const removeToast = useCallback((id: string) => {\n setToasts((currentToasts) => currentToasts.filter((toast) => toast.id !== id));\n }, []);\n\n const value = {\n toasts,\n addToast,\n addGraphQLErrorsToast,\n removeToast,\n enabled,\n };\n\n return (\n <ToastContext.Provider value={value}>\n <div\n style={{\n position: \"fixed\",\n bottom: \"1rem\",\n left: \"50%\",\n transform: \"translateX(-50%)\",\n zIndex: 50,\n display: \"flex\",\n flexDirection: \"column\",\n gap: \"0.5rem\",\n }}\n >\n {toasts.length > 1 && (\n <div style={{ textAlign: \"right\" }}>\n <button\n onClick={() => setToasts([])}\n style={{\n padding: \"4px 8px\",\n fontSize: \"12px\",\n cursor: \"pointer\",\n background: \"white\",\n border: \"1px solid rgba(0,0,0,0.2)\",\n borderRadius: \"4px\",\n }}\n >\n Close All\n </button>\n </div>\n )}\n {toasts.map((toast) => (\n <Toast\n key={toast.id}\n message={toast.message}\n type={toast.type}\n onClose={() => removeToast(toast.id)}\n />\n ))}\n </div>\n {children}\n </ToastContext.Provider>\n );\n}\n\nfunction Toast({\n message,\n type = \"info\",\n onClose,\n}: {\n message: string | React.ReactNode;\n type: \"info\" | \"success\" | \"warning\" | \"error\";\n onClose: () => void;\n}) {\n const bgColors = {\n info: \"#3b82f6\",\n success: \"#22c55e\",\n warning: \"#eab308\",\n error: \"#ef4444\",\n };\n\n return (\n <div\n style={{\n backgroundColor: bgColors[type],\n color: \"white\",\n padding: \"0.5rem 1.5rem\",\n borderRadius: \"0.25rem\",\n boxShadow: \"0 2px 4px rgba(0,0,0,0.1)\",\n position: \"relative\",\n minWidth: \"200px\",\n }}\n >\n <div>{message}</div>\n <button\n onClick={onClose}\n style={{\n position: \"absolute\",\n top: \"0\",\n right: \"0\",\n background: \"none\",\n border: \"none\",\n color: \"white\",\n cursor: \"pointer\",\n padding: \"0.5rem\",\n fontSize: \"1rem\",\n }}\n >\n ✕\n </button>\n </div>\n );\n}\n","import React, { useCallback, useEffect } from \"react\";\nimport { GraphQLError } from \"@copilotkit/runtime-client-gql\";\nimport { useToast } from \"../toast/toast-provider\";\nimport { ExclamationMarkIcon } from \"../toast/exclamation-mark-icon\";\n\nexport function ErrorToast({ errors }: { errors: (Error | GraphQLError)[] }) {\n const errorsToRender = errors.map((error, idx) => {\n const message =\n \"extensions\" in error\n ? (error.extensions?.originalError as undefined | { message?: string })?.message\n : error.message;\n const code = \"extensions\" in error ? (error.extensions?.code as string) : null;\n\n return (\n <div\n key={idx}\n style={{\n marginTop: idx === 0 ? 0 : 10,\n marginBottom: 14,\n }}\n >\n <ExclamationMarkIcon style={{ marginBottom: 4 }} />\n\n {code && (\n <div\n style={{\n fontWeight: \"600\",\n marginBottom: 4,\n }}\n >\n Copilot Cloud Error:{\" \"}\n <span style={{ fontFamily: \"monospace\", fontWeight: \"normal\" }}>{code}</span>\n </div>\n )}\n <div>{message}</div>\n </div>\n );\n });\n return (\n <div\n style={{\n fontSize: \"13px\",\n maxWidth: \"600px\",\n }}\n >\n {errorsToRender}\n <div style={{ fontSize: \"11px\", opacity: 0.75 }}>\n NOTE: This error only displays during local development.\n </div>\n </div>\n );\n}\n\nexport function useErrorToast() {\n const { addToast } = useToast();\n\n return useCallback(\n (error: (Error | GraphQLError)[]) => {\n const errorId = error\n .map((err) => {\n const message =\n \"extensions\" in err\n ? (err.extensions?.originalError as any)?.message || err.message\n : err.message;\n const stack = err.stack || \"\";\n return btoa(message + stack).slice(0, 32); // Create hash from message + stack\n })\n .join(\"|\");\n\n addToast({\n type: \"error\",\n id: errorId, // Toast libraries typically dedupe by id\n message: <ErrorToast errors={error} />,\n });\n },\n [addToast],\n );\n}\n\nexport function useAsyncCallback<T extends (...args: any[]) => Promise<any>>(\n callback: T,\n deps: Parameters<typeof useCallback>[1],\n) {\n const addErrorToast = useErrorToast();\n return useCallback(async (...args: Parameters<T>) => {\n try {\n return await callback(...args);\n } catch (error) {\n console.error(\"Error in async callback:\", error);\n // @ts-ignore\n addErrorToast([error]);\n throw error;\n }\n }, deps);\n}\n","import React from \"react\";\n\nexport const ExclamationMarkIcon = ({\n className,\n style,\n}: {\n className?: string;\n style?: React.CSSProperties;\n}) => (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"24\"\n height=\"24\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className={`lucide lucide-circle-alert ${className ? className : \"\"}`}\n style={style}\n >\n <circle cx=\"12\" cy=\"12\" r=\"10\" />\n <line x1=\"12\" x2=\"12\" y1=\"8\" y2=\"12\" />\n <line x1=\"12\" x2=\"12.01\" y1=\"16\" y2=\"16\" />\n </svg>\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAAuB;AACvB,IAAAC,iBAKO;AACP,IAAAC,6BAcO;;;ACrBP,gCAAwC;AACxC,oBAKO;AAuKA,SAAS,gCAAgC,SAAgC;AAC9E,QAAM,kBAAkB,QACrB;AAAA,IACC,CAAC,WACC,OAAO,cAAc,kDAAwB,YAC7C,OAAO,aAAa,QACpB,OAAO,SAAS;AAAA,EACpB,EACC,IAAI,CAAC,WAAW;AACf,QAAI,YAAiD,kDAAwB;AAC7E,QAAI,OAAO,UAAU;AACnB,kBAAY,kDAAwB;AAAA,IACtC,WAAW,OAAO,cAAc,YAAY;AAC1C,kBAAY,kDAAwB;AAAA,IACtC,WAAW,OAAO,cAAc,UAAU;AACxC,kBAAY,kDAAwB;AAAA,IACtC;AACA,WAAO;AAAA,MACL,MAAM,OAAO;AAAA,MACb,aAAa,OAAO,eAAe;AAAA,MACnC,YAAY,KAAK,cAAU,4CAA6B,OAAO,cAAc,CAAC,CAAC,CAAC;AAAA,MAChF;AAAA,IACF;AAAA,EACF,CAAC;AACH,SAAO;AACT;;;ACtMA,IAAAC,6BAIO;;;ACHP,IAAAC,gBAAwE;;;ACDxE,mBAA8C;;;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AAG,EAAE;AAAA,IACvC;AAEA,gBAAY,WAAW;AAEvB,WAAO,uCAAuC,WAAW;AAAA,EAC3D,IAAG,CAAC,WAAW,UAAU,aAAa,sCAAsC,CAAC;AAE7E,QAAM,OAAO,MAAY;AAvlB3B;AAwlBI,iCAAuB,YAAvB,mBAAgC,MAAM;AAAA,EACxC;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,mBAAmB,MAAM,qBAAqB,QAAS,QAAQ;AAAA,EACjE;AACF;AAEA,SAAS,uBACP,gBACA,kBACA,aACW;AACX,QAAM,gBACJ,eAAe,SAAS,IAAI,CAAC,GAAG,cAAc,IAAI,CAAC,GAAG,kBAAkB,GAAG,WAAW;AAExF,MAAI,eAAe,SAAS,GAAG;AAC7B,UAAM,yBAAyB,CAAC,GAAG,kBAAkB,GAAG,WAAW;AAEnE,QAAI,oBAAwC;AAE5C,eAAW,WAAW,wBAAwB;AAC5C,UAAI,QAAQ,oBAAoB,GAAG;AAEjC,cAAM,QAAQ,cAAc,UAAU,CAAC,QAAQ,IAAI,OAAO,iBAAiB;AAC3E,YAAI,UAAU,IAAI;AAChB,wBAAc,OAAO,QAAQ,GAAG,GAAG,OAAO;AAAA,QAC5C;AAAA,MACF;AAEA,0BAAoB,QAAQ;AAAA,IAC9B;AAAA,EACF;AAEA,SAAO;AACT;","names":["import_react","import_shared","import_runtime_client_gql","import_runtime_client_gql","import_react","import_jsx_runtime","import_jsx_runtime","import_react","messages","action","_a"]}
@@ -0,0 +1,12 @@
1
+ import {
2
+ useChat
3
+ } from "../chunk-VGOFRULA.mjs";
4
+ import "../chunk-XERJQUHA.mjs";
5
+ import "../chunk-6BQVZFNO.mjs";
6
+ import "../chunk-LNI2Z45S.mjs";
7
+ import "../chunk-O7ARI5CV.mjs";
8
+ import "../chunk-SKC7AJIV.mjs";
9
+ export {
10
+ useChat
11
+ };
12
+ //# sourceMappingURL=use-chat.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,60 @@
1
+ import { CoAgentStateRender } from '../types/coagent-action.js';
2
+
3
+ /**
4
+ * <Callout type="info">
5
+ * Usage of this hook assumes some additional setup in your application, for more information
6
+ * on that see the CoAgents <span className="text-blue-500">[Agentic Generative UI documentation](/coagents/chat-ui/render-agent-state)</span>.
7
+ * </Callout>
8
+ *
9
+ * The useCoAgentStateRender hook allows you to render UI components or text based on a Agentic Copilot's state.
10
+ * This is particularly useful for showing intermediate state or progress during Agentic Copilot operations.
11
+ *
12
+ * ## Usage
13
+ *
14
+ * ### Simple Usage
15
+ *
16
+ * ```tsx
17
+ * import { useCoAgentStateRender } from "@copilotkit/react-core";
18
+ *
19
+ * type YourAgentState = {
20
+ * agent_state_property: string;
21
+ * }
22
+ *
23
+ * useCoAgentStateRender<YourAgentState>({
24
+ * name: "basic_agent",
25
+ * nodeName: "optionally_specify_a_specific_node",
26
+ * render: ({ status, state, nodeName }) => {
27
+ * return (
28
+ * <YourComponent
29
+ * agentStateProperty={state.agent_state_property}
30
+ * status={status}
31
+ * nodeName={nodeName}
32
+ * />
33
+ * );
34
+ * },
35
+ * });
36
+ * ```
37
+ *
38
+ * This allows for you to render UI components or text based on what is happening within the agent.
39
+ *
40
+ * ### Example
41
+ * A great example of this is in our Perplexity Clone where we render the progress of an agent's internet search as it is happening.
42
+ * You can play around with it below or learn how to build it with its [demo](/coagents/videos/perplexity-clone).
43
+ *
44
+ * <Callout type="info">
45
+ * This example is hosted on Vercel and may take a few seconds to load.
46
+ * </Callout>
47
+ *
48
+ * <iframe src="https://examples-coagents-ai-researcher-ui.vercel.app/" className="w-full rounded-lg border h-[700px] my-4" />
49
+ */
50
+
51
+ /**
52
+ * This hook is used to render agent state with custom UI components or text. This is particularly
53
+ * useful for showing intermediate state or progress during Agentic Copilot operations.
54
+ * To get started using rendering intermediate state through this hook, checkout the documentation.
55
+ *
56
+ * https://docs.copilotkit.ai/coagents/chat-ui/render-agent-state.
57
+ */
58
+ declare function useCoAgentStateRender<T = any>(action: CoAgentStateRender<T>, dependencies?: any[]): void;
59
+
60
+ export { useCoAgentStateRender };
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var __async = (__this, __arguments, generator) => {
30
+ return new Promise((resolve, reject) => {
31
+ var fulfilled = (value) => {
32
+ try {
33
+ step(generator.next(value));
34
+ } catch (e) {
35
+ reject(e);
36
+ }
37
+ };
38
+ var rejected = (value) => {
39
+ try {
40
+ step(generator.throw(value));
41
+ } catch (e) {
42
+ reject(e);
43
+ }
44
+ };
45
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
46
+ step((generator = generator.apply(__this, __arguments)).next());
47
+ });
48
+ };
49
+
50
+ // src/hooks/use-coagent-state-render.ts
51
+ var use_coagent_state_render_exports = {};
52
+ __export(use_coagent_state_render_exports, {
53
+ useCoAgentStateRender: () => useCoAgentStateRender
54
+ });
55
+ module.exports = __toCommonJS(use_coagent_state_render_exports);
56
+ var import_react3 = require("react");
57
+
58
+ // src/context/copilot-context.tsx
59
+ var import_react = __toESM(require("react"));
60
+ var emptyCopilotContext = {
61
+ actions: {},
62
+ setAction: () => {
63
+ },
64
+ removeAction: () => {
65
+ },
66
+ coAgentStateRenders: {},
67
+ setCoAgentStateRender: () => {
68
+ },
69
+ removeCoAgentStateRender: () => {
70
+ },
71
+ chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },
72
+ getContextString: (documents, categories) => returnAndThrowInDebug(""),
73
+ addContext: () => "",
74
+ removeContext: () => {
75
+ },
76
+ getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
77
+ })),
78
+ isLoading: false,
79
+ setIsLoading: () => returnAndThrowInDebug(false),
80
+ chatInstructions: "",
81
+ setChatInstructions: () => returnAndThrowInDebug(""),
82
+ getDocumentsContext: (categories) => returnAndThrowInDebug([]),
83
+ addDocumentContext: () => returnAndThrowInDebug(""),
84
+ removeDocumentContext: () => {
85
+ },
86
+ runtimeClient: {},
87
+ copilotApiConfig: new class {
88
+ get chatApiEndpoint() {
89
+ throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
90
+ }
91
+ get headers() {
92
+ return {};
93
+ }
94
+ get body() {
95
+ return {};
96
+ }
97
+ }(),
98
+ chatSuggestionConfiguration: {},
99
+ addChatSuggestionConfiguration: () => {
100
+ },
101
+ removeChatSuggestionConfiguration: () => {
102
+ },
103
+ showDevConsole: "auto",
104
+ coagentStates: {},
105
+ setCoagentStates: () => {
106
+ },
107
+ coagentStatesRef: { current: {} },
108
+ setCoagentStatesWithRef: () => {
109
+ },
110
+ agentSession: null,
111
+ setAgentSession: () => {
112
+ },
113
+ forwardedParameters: {},
114
+ agentLock: null,
115
+ threadId: null,
116
+ setThreadId: () => {
117
+ },
118
+ runId: null,
119
+ setRunId: () => {
120
+ },
121
+ chatAbortControllerRef: { current: null },
122
+ availableAgents: []
123
+ };
124
+ var CopilotContext = import_react.default.createContext(emptyCopilotContext);
125
+ function returnAndThrowInDebug(_value) {
126
+ throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
127
+ }
128
+
129
+ // src/hooks/use-coagent-state-render.ts
130
+ var import_shared = require("@copilotkit/shared");
131
+
132
+ // src/components/toast/toast-provider.tsx
133
+ var import_react2 = require("react");
134
+ var import_jsx_runtime = require("react/jsx-runtime");
135
+ var ToastContext = (0, import_react2.createContext)(void 0);
136
+ function useToast() {
137
+ const context = (0, import_react2.useContext)(ToastContext);
138
+ if (!context) {
139
+ throw new Error("useToast must be used within a ToastProvider");
140
+ }
141
+ return context;
142
+ }
143
+
144
+ // src/hooks/use-coagent-state-render.ts
145
+ function useCoAgentStateRender(action, dependencies) {
146
+ const {
147
+ setCoAgentStateRender,
148
+ removeCoAgentStateRender,
149
+ coAgentStateRenders,
150
+ chatComponentsCache,
151
+ availableAgents
152
+ } = (0, import_react3.useContext)(CopilotContext);
153
+ const idRef = (0, import_react3.useRef)((0, import_shared.randomId)());
154
+ const { addToast } = useToast();
155
+ (0, import_react3.useEffect)(() => {
156
+ if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === action.name)) {
157
+ const message = `(useCoAgentStateRender): Agent "${action.name}" not found. Make sure the agent exists and is properly configured.`;
158
+ console.warn(message);
159
+ addToast({ type: "warning", message });
160
+ }
161
+ }, [availableAgents]);
162
+ const key = `${action.name}-${action.nodeName || "global"}`;
163
+ if (dependencies === void 0) {
164
+ if (coAgentStateRenders[idRef.current]) {
165
+ coAgentStateRenders[idRef.current].handler = action.handler;
166
+ if (typeof action.render === "function") {
167
+ if (chatComponentsCache.current !== null) {
168
+ chatComponentsCache.current.coAgentStateRenders[key] = action.render;
169
+ }
170
+ }
171
+ }
172
+ }
173
+ (0, import_react3.useEffect)(() => {
174
+ setCoAgentStateRender(idRef.current, action);
175
+ if (chatComponentsCache.current !== null && action.render !== void 0) {
176
+ chatComponentsCache.current.coAgentStateRenders[key] = action.render;
177
+ }
178
+ return () => {
179
+ removeCoAgentStateRender(idRef.current);
180
+ };
181
+ }, [
182
+ setCoAgentStateRender,
183
+ removeCoAgentStateRender,
184
+ action.name,
185
+ // include render only if it's a string
186
+ typeof action.render === "string" ? action.render : void 0,
187
+ // dependencies set by the developer
188
+ ...dependencies || []
189
+ ]);
190
+ }
191
+ // Annotate the CommonJS export names for ESM import in node:
192
+ 0 && (module.exports = {
193
+ useCoAgentStateRender
194
+ });
195
+ //# sourceMappingURL=use-coagent-state-render.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/use-coagent-state-render.ts","../../src/context/copilot-context.tsx","../../src/components/toast/toast-provider.tsx"],"sourcesContent":["/**\n * <Callout type=\"info\">\n * Usage of this hook assumes some additional setup in your application, for more information\n * on that see the CoAgents <span className=\"text-blue-500\">[Agentic Generative UI documentation](/coagents/chat-ui/render-agent-state)</span>.\n * </Callout>\n *\n * The useCoAgentStateRender hook allows you to render UI components or text based on a Agentic Copilot's state.\n * This is particularly useful for showing intermediate state or progress during Agentic Copilot operations.\n *\n * ## Usage\n *\n * ### Simple Usage\n *\n * ```tsx\n * import { useCoAgentStateRender } from \"@copilotkit/react-core\";\n *\n * type YourAgentState = {\n * agent_state_property: string;\n * }\n *\n * useCoAgentStateRender<YourAgentState>({\n * name: \"basic_agent\",\n * nodeName: \"optionally_specify_a_specific_node\",\n * render: ({ status, state, nodeName }) => {\n * return (\n * <YourComponent\n * agentStateProperty={state.agent_state_property}\n * status={status}\n * nodeName={nodeName}\n * />\n * );\n * },\n * });\n * ```\n *\n * This allows for you to render UI components or text based on what is happening within the agent.\n *\n * ### Example\n * A great example of this is in our Perplexity Clone where we render the progress of an agent's internet search as it is happening.\n * You can play around with it below or learn how to build it with its [demo](/coagents/videos/perplexity-clone).\n *\n * <Callout type=\"info\">\n * This example is hosted on Vercel and may take a few seconds to load.\n * </Callout>\n *\n * <iframe src=\"https://examples-coagents-ai-researcher-ui.vercel.app/\" className=\"w-full rounded-lg border h-[700px] my-4\" />\n */\n\nimport { useRef, useContext, useEffect } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { randomId } from \"@copilotkit/shared\";\nimport { CoAgentStateRender } from \"../types/coagent-action\";\nimport { useToast } from \"../components/toast/toast-provider\";\n\n/**\n * This hook is used to render agent state with custom UI components or text. This is particularly\n * useful for showing intermediate state or progress during Agentic Copilot operations.\n * To get started using rendering intermediate state through this hook, checkout the documentation.\n *\n * https://docs.copilotkit.ai/coagents/chat-ui/render-agent-state.\n */\n\n// We implement useCoAgentStateRender dependency handling so that\n// the developer has the option to not provide any dependencies.\n// see useCopilotAction for more details about this approach.\nexport function useCoAgentStateRender<T = any>(\n action: CoAgentStateRender<T>,\n dependencies?: any[],\n): void {\n const {\n setCoAgentStateRender,\n removeCoAgentStateRender,\n coAgentStateRenders,\n chatComponentsCache,\n availableAgents,\n } = useContext(CopilotContext);\n const idRef = useRef<string>(randomId());\n const { addToast } = useToast();\n\n useEffect(() => {\n if (availableAgents?.length && !availableAgents.some((a) => a.name === action.name)) {\n const message = `(useCoAgentStateRender): Agent \"${action.name}\" not found. Make sure the agent exists and is properly configured.`;\n console.warn(message);\n addToast({ type: \"warning\", message });\n }\n }, [availableAgents]);\n\n const key = `${action.name}-${action.nodeName || \"global\"}`;\n\n if (dependencies === undefined) {\n if (coAgentStateRenders[idRef.current]) {\n coAgentStateRenders[idRef.current].handler = action.handler as any;\n if (typeof action.render === \"function\") {\n if (chatComponentsCache.current !== null) {\n chatComponentsCache.current.coAgentStateRenders[key] = action.render;\n }\n }\n }\n }\n\n useEffect(() => {\n setCoAgentStateRender(idRef.current, action as any);\n if (chatComponentsCache.current !== null && action.render !== undefined) {\n chatComponentsCache.current.coAgentStateRenders[key] = action.render;\n }\n return () => {\n removeCoAgentStateRender(idRef.current);\n };\n }, [\n setCoAgentStateRender,\n removeCoAgentStateRender,\n action.name,\n // include render only if it's a string\n typeof action.render === \"string\" ? action.render : undefined,\n // dependencies set by the developer\n ...(dependencies || []),\n ]);\n}\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 } 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 { CopilotRuntimeClient, ForwardedParametersInput } from \"@copilotkit/runtime-client-gql\";\nimport { Agent } from \"@copilotkit/runtime-client-gql\";\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\nexport type InChatRenderFunction = (\n props: ActionRenderProps<any> | CatchAllActionRenderProps<any>,\n) => 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;\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 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 // api endpoints\n copilotApiConfig: CopilotApiConfig;\n\n showDevConsole: boolean | \"auto\";\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 | null;\n setThreadId: React.Dispatch<React.SetStateAction<string | null>>;\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?: Record<ActionName, AuthState>;\n setAuthStates?: React.Dispatch<React.SetStateAction<Record<ActionName, AuthState>>>;\n\n /**\n * The auth config for the CopilotKit.\n */\n authConfig?: {\n SignInComponent: React.ComponentType<{\n onSignInComplete: (authState: AuthState) => void;\n }>;\n };\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\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n\n isLoading: false,\n setIsLoading: () => returnAndThrowInDebug(false),\n\n chatInstructions: \"\",\n setChatInstructions: () => 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: \"auto\",\n coagentStates: {},\n setCoagentStates: () => {},\n coagentStatesRef: { current: {} },\n setCoagentStatesWithRef: () => {},\n agentSession: null,\n setAgentSession: () => {},\n forwardedParameters: {},\n agentLock: null,\n threadId: null,\n setThreadId: () => {},\n runId: null,\n setRunId: () => {},\n chatAbortControllerRef: { current: null },\n availableAgents: [],\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","import { GraphQLError } from \"@copilotkit/runtime-client-gql\";\nimport React, { createContext, useContext, useState, useCallback } from \"react\";\nimport { ErrorToast } from \"../error-boundary/error-utils\";\nimport { PartialBy } from \"@copilotkit/shared\";\n\ninterface Toast {\n id: string;\n message: string | React.ReactNode;\n type: \"info\" | \"success\" | \"warning\" | \"error\";\n duration?: number;\n}\n\ninterface ToastContextValue {\n toasts: Toast[];\n addToast: (toast: PartialBy<Toast, \"id\">) => void;\n addGraphQLErrorsToast: (errors: GraphQLError[]) => void;\n removeToast: (id: string) => void;\n enabled: boolean;\n}\n\nconst ToastContext = createContext<ToastContextValue | undefined>(undefined);\n\nexport function useToast() {\n const context = useContext(ToastContext);\n if (!context) {\n throw new Error(\"useToast must be used within a ToastProvider\");\n }\n return context;\n}\n\nexport function ToastProvider({\n enabled,\n children,\n}: {\n enabled: boolean;\n children: React.ReactNode;\n}) {\n const [toasts, setToasts] = useState<Toast[]>([]);\n const addToast = useCallback((toast: PartialBy<Toast, \"id\">) => {\n const id = toast.id ?? Math.random().toString(36).substring(2, 9);\n\n setToasts((currentToasts) => {\n if (currentToasts.find((toast) => toast.id === id)) return currentToasts;\n return [...currentToasts, { ...toast, id }];\n });\n\n if (toast.duration) {\n setTimeout(() => {\n removeToast(id);\n }, toast.duration);\n }\n }, []);\n\n const addGraphQLErrorsToast = useCallback((errors: GraphQLError[]) => {\n // We do not display these errors unless we are in dev mode.\n // if (!showDevConsole) {\n // return;\n // }\n\n addToast({\n type: \"error\",\n message: <ErrorToast errors={errors} />,\n });\n }, []);\n\n const removeToast = useCallback((id: string) => {\n setToasts((currentToasts) => currentToasts.filter((toast) => toast.id !== id));\n }, []);\n\n const value = {\n toasts,\n addToast,\n addGraphQLErrorsToast,\n removeToast,\n enabled,\n };\n\n return (\n <ToastContext.Provider value={value}>\n <div\n style={{\n position: \"fixed\",\n bottom: \"1rem\",\n left: \"50%\",\n transform: \"translateX(-50%)\",\n zIndex: 50,\n display: \"flex\",\n flexDirection: \"column\",\n gap: \"0.5rem\",\n }}\n >\n {toasts.length > 1 && (\n <div style={{ textAlign: \"right\" }}>\n <button\n onClick={() => setToasts([])}\n style={{\n padding: \"4px 8px\",\n fontSize: \"12px\",\n cursor: \"pointer\",\n background: \"white\",\n border: \"1px solid rgba(0,0,0,0.2)\",\n borderRadius: \"4px\",\n }}\n >\n Close All\n </button>\n </div>\n )}\n {toasts.map((toast) => (\n <Toast\n key={toast.id}\n message={toast.message}\n type={toast.type}\n onClose={() => removeToast(toast.id)}\n />\n ))}\n </div>\n {children}\n </ToastContext.Provider>\n );\n}\n\nfunction Toast({\n message,\n type = \"info\",\n onClose,\n}: {\n message: string | React.ReactNode;\n type: \"info\" | \"success\" | \"warning\" | \"error\";\n onClose: () => void;\n}) {\n const bgColors = {\n info: \"#3b82f6\",\n success: \"#22c55e\",\n warning: \"#eab308\",\n error: \"#ef4444\",\n };\n\n return (\n <div\n style={{\n backgroundColor: bgColors[type],\n color: \"white\",\n padding: \"0.5rem 1.5rem\",\n borderRadius: \"0.25rem\",\n boxShadow: \"0 2px 4px rgba(0,0,0,0.1)\",\n position: \"relative\",\n minWidth: \"200px\",\n }}\n >\n <div>{message}</div>\n <button\n onClick={onClose}\n style={{\n position: \"absolute\",\n top: \"0\",\n right: \"0\",\n background: \"none\",\n border: \"none\",\n color: \"white\",\n cursor: \"pointer\",\n padding: \"0.5rem\",\n fontSize: \"1rem\",\n }}\n >\n ✕\n </button>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgDA,IAAAA,gBAA8C;;;AC1C9C,mBAAkB;AA+LlB,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,EAEtB,wBAAwB,MAAM,sBAAsB,MAAY;AAAA,EAAC,EAAC;AAAA,EAElE,WAAW;AAAA,EACX,cAAc,MA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,SAAS;AAAA;AAAA,IAEpD,GAAI,gBAAgB,CAAC;AAAA,EACvB,CAAC;AACH;","names":["import_react","React","import_react"]}
@@ -0,0 +1,11 @@
1
+ import {
2
+ useCoAgentStateRender
3
+ } from "../chunk-22XKTBPF.mjs";
4
+ import "../chunk-WXREY7UP.mjs";
5
+ import "../chunk-LNI2Z45S.mjs";
6
+ import "../chunk-O7ARI5CV.mjs";
7
+ import "../chunk-SKC7AJIV.mjs";
8
+ export {
9
+ useCoAgentStateRender
10
+ };
11
+ //# sourceMappingURL=use-coagent-state-render.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,199 @@
1
+ import { CopilotContextParams } from '../context/copilot-context.js';
2
+ import { CopilotMessagesContextParams } from '../context/copilot-messages-context.js';
3
+ import { Message } from '@copilotkit/runtime-client-gql';
4
+ import '@copilotkit/shared';
5
+ import '../types/frontend-action.js';
6
+ import 'react';
7
+ import './use-tree.js';
8
+ import '../types/document-pointer.js';
9
+ import '../types/chat-suggestion-configuration.js';
10
+ import '../types/coagent-action.js';
11
+ import '../types/coagent-state.js';
12
+
13
+ /**
14
+ * <Callout type="info">
15
+ * Usage of this hook assumes some additional setup in your application, for more information
16
+ * on that see the CoAgents <span className="text-blue-500">[getting started guide](/coagents/quickstart)</span>.
17
+ * </Callout>
18
+ * <Frame className="my-12">
19
+ * <img
20
+ * src="/images/coagents/SharedStateCoAgents.gif"
21
+ * alt="CoAgents demonstration"
22
+ * className="w-auto"
23
+ * />
24
+ * </Frame>
25
+ *
26
+ * This hook is used to integrate an agent into your application. With its use, you can
27
+ * render and update the state of an agent, allowing for a dynamic and interactive experience.
28
+ * We call these shared state experiences agentic copilots, or CoAgents for short.
29
+ *
30
+ * ## Usage
31
+ *
32
+ * ### Simple Usage
33
+ *
34
+ * ```tsx
35
+ * import { useCoAgent } from "@copilotkit/react-core";
36
+ *
37
+ * type AgentState = {
38
+ * count: number;
39
+ * }
40
+ *
41
+ * const agent = useCoAgent<AgentState>({
42
+ * name: "my-agent",
43
+ * initialState: {
44
+ * count: 0,
45
+ * },
46
+ * });
47
+ *
48
+ * ```
49
+ *
50
+ * `useCoAgent` returns an object with the following properties:
51
+ *
52
+ * ```tsx
53
+ * const {
54
+ * name, // The name of the agent currently being used.
55
+ * nodeName, // The name of the current LangGraph node.
56
+ * state, // The current state of the agent.
57
+ * setState, // A function to update the state of the agent.
58
+ * running, // A boolean indicating if the agent is currently running.
59
+ * start, // A function to start the agent.
60
+ * stop, // A function to stop the agent.
61
+ * run, // A function to re-run the agent. Takes a HintFunction to inform the agent why it is being re-run.
62
+ * } = agent;
63
+ * ```
64
+ *
65
+ * Finally we can leverage these properties to create reactive experiences with the agent!
66
+ *
67
+ * ```tsx
68
+ * const { state, setState } = useCoAgent<AgentState>({
69
+ * name: "my-agent",
70
+ * initialState: {
71
+ * count: 0,
72
+ * },
73
+ * });
74
+ *
75
+ * return (
76
+ * <div>
77
+ * <p>Count: {state.count}</p>
78
+ * <button onClick={() => setState({ count: state.count + 1 })}>Increment</button>
79
+ * </div>
80
+ * );
81
+ * ```
82
+ *
83
+ * This reactivity is bidirectional, meaning that changes to the state from the agent will be reflected in the UI and vice versa.
84
+ *
85
+ * ## Parameters
86
+ * <PropertyReference name="options" type="UseCoagentOptions<T>" required>
87
+ * The options to use when creating the coagent.
88
+ * <PropertyReference name="name" type="string" required>
89
+ * The name of the agent to use.
90
+ * </PropertyReference>
91
+ * <PropertyReference name="initialState" type="T | any">
92
+ * The initial state of the agent.
93
+ * </PropertyReference>
94
+ * <PropertyReference name="state" type="T | any">
95
+ * State to manage externally if you are using this hook with external state management.
96
+ * </PropertyReference>
97
+ * <PropertyReference name="setState" type="(newState: T | ((prevState: T | undefined) => T)) => void">
98
+ * A function to update the state of the agent if you are using this hook with external state management.
99
+ * </PropertyReference>
100
+ * </PropertyReference>
101
+ */
102
+
103
+ interface WithInternalStateManagementAndInitial<T> {
104
+ /**
105
+ * The name of the agent being used.
106
+ */
107
+ name: string;
108
+ /**
109
+ * The initial state of the agent.
110
+ */
111
+ initialState: T;
112
+ }
113
+ interface WithInternalStateManagement {
114
+ /**
115
+ * The name of the agent being used.
116
+ */
117
+ name: string;
118
+ /**
119
+ * Optional initialState with default type any
120
+ */
121
+ initialState?: any;
122
+ }
123
+ interface WithExternalStateManagement<T> {
124
+ /**
125
+ * The name of the agent being used.
126
+ */
127
+ name: string;
128
+ /**
129
+ * The current state of the agent.
130
+ */
131
+ state: T;
132
+ /**
133
+ * A function to update the state of the agent.
134
+ */
135
+ setState: (newState: T | ((prevState: T | undefined) => T)) => void;
136
+ }
137
+ type UseCoagentOptions<T> = WithInternalStateManagementAndInitial<T> | WithInternalStateManagement | WithExternalStateManagement<T>;
138
+ interface UseCoagentReturnType<T> {
139
+ /**
140
+ * The name of the agent being used.
141
+ */
142
+ name: string;
143
+ /**
144
+ * The name of the current LangGraph node.
145
+ */
146
+ nodeName?: string;
147
+ /**
148
+ * The ID of the thread the agent is running in.
149
+ */
150
+ threadId?: string;
151
+ /**
152
+ * A boolean indicating if the agent is currently running.
153
+ */
154
+ running: boolean;
155
+ /**
156
+ * The current state of the agent.
157
+ */
158
+ state: T;
159
+ /**
160
+ * A function to update the state of the agent.
161
+ */
162
+ setState: (newState: T | ((prevState: T | undefined) => T)) => void;
163
+ /**
164
+ * A function to start the agent.
165
+ */
166
+ start: () => void;
167
+ /**
168
+ * A function to stop the agent.
169
+ */
170
+ stop: () => void;
171
+ /**
172
+ * A function to re-run the agent. The hint function can be used to provide a hint to the agent
173
+ * about why it is being re-run again.
174
+ */
175
+ run: (hint?: HintFunction) => Promise<void>;
176
+ }
177
+ interface HintFunctionParams {
178
+ /**
179
+ * The previous state of the agent.
180
+ */
181
+ previousState: any;
182
+ /**
183
+ * The current state of the agent.
184
+ */
185
+ currentState: any;
186
+ }
187
+ type HintFunction = (params: HintFunctionParams) => Message | undefined;
188
+ /**
189
+ * This hook is used to integrate an agent into your application. With its use, you can
190
+ * render and update the state of the agent, allowing for a dynamic and interactive experience.
191
+ * We call these shared state experiences "agentic copilots". To get started using agentic copilots, which
192
+ * we refer to as CoAgents, checkout the documentation at https://docs.copilotkit.ai/coagents/quickstart.
193
+ */
194
+ declare function useCoAgent<T = any>(options: UseCoagentOptions<T>): UseCoagentReturnType<T>;
195
+ declare function startAgent(name: string, context: CopilotContextParams): void;
196
+ declare function stopAgent(name: string, context: CopilotContextParams): void;
197
+ declare function runAgent(name: string, context: CopilotContextParams & CopilotMessagesContextParams, appendMessage: (message: Message) => Promise<void>, runChatCompletion: () => Promise<Message[]>, hint?: HintFunction): Promise<void>;
198
+
199
+ export { HintFunction, HintFunctionParams, UseCoagentReturnType, runAgent, startAgent, stopAgent, useCoAgent };