@copilotkit/react-core 1.5.0-tyler-reset-chat.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/CHANGELOG.md +158 -4
  2. package/README.md +2 -0
  3. package/dist/{chunk-3AYELZJS.mjs → chunk-35EN6BG4.mjs} +2 -2
  4. package/dist/{chunk-3AYELZJS.mjs.map → chunk-35EN6BG4.mjs.map} +1 -1
  5. package/dist/{chunk-SEPYQHH7.mjs → chunk-42N5VKIX.mjs} +34 -28
  6. package/dist/chunk-42N5VKIX.mjs.map +1 -0
  7. package/dist/{chunk-USL3EHJB.mjs → chunk-5FYKUKG3.mjs} +2 -2
  8. package/dist/{chunk-ODN4H66E.mjs → chunk-7LRDVJH5.mjs} +6 -2
  9. package/dist/chunk-7LRDVJH5.mjs.map +1 -0
  10. package/dist/{chunk-CZMEZR6F.mjs → chunk-BT6WK2JZ.mjs} +34 -19
  11. package/dist/chunk-BT6WK2JZ.mjs.map +1 -0
  12. package/dist/{chunk-3R4J2TPH.mjs → chunk-EUU6NNYU.mjs} +29 -13
  13. package/dist/chunk-EUU6NNYU.mjs.map +1 -0
  14. package/dist/chunk-QCUP6HLK.mjs +37 -0
  15. package/dist/chunk-QCUP6HLK.mjs.map +1 -0
  16. package/dist/chunk-QTDCEDOC.mjs +392 -0
  17. package/dist/chunk-QTDCEDOC.mjs.map +1 -0
  18. package/dist/{chunk-JR55I3FL.mjs → chunk-QX6V774L.mjs} +6 -8
  19. package/dist/chunk-QX6V774L.mjs.map +1 -0
  20. package/dist/{chunk-2KCEHGSI.mjs → chunk-SFPANIOY.mjs} +99 -49
  21. package/dist/chunk-SFPANIOY.mjs.map +1 -0
  22. package/dist/{chunk-2JP64U3A.mjs → chunk-TQN3EZWQ.mjs} +4 -1
  23. package/dist/chunk-TQN3EZWQ.mjs.map +1 -0
  24. package/dist/{chunk-XUPO37VH.mjs → chunk-V3PFWGIY.mjs} +2 -2
  25. package/dist/{chunk-6QKA3SNN.mjs → chunk-VMP6JWBB.mjs} +21 -5
  26. package/dist/chunk-VMP6JWBB.mjs.map +1 -0
  27. package/dist/chunk-XERJQUHA.mjs +31 -0
  28. package/dist/chunk-XERJQUHA.mjs.map +1 -0
  29. package/dist/components/copilot-provider/copilotkit.js +173 -92
  30. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  31. package/dist/components/copilot-provider/copilotkit.mjs +5 -4
  32. package/dist/components/copilot-provider/index.js +173 -92
  33. package/dist/components/copilot-provider/index.js.map +1 -1
  34. package/dist/components/copilot-provider/index.mjs +5 -4
  35. package/dist/components/error-boundary/error-boundary.d.ts +22 -0
  36. package/dist/components/error-boundary/error-boundary.js +183 -0
  37. package/dist/components/error-boundary/error-boundary.js.map +1 -0
  38. package/dist/components/error-boundary/error-boundary.mjs +12 -0
  39. package/dist/components/error-boundary/error-boundary.mjs.map +1 -0
  40. package/dist/components/error-boundary/error-utils.d.ts +11 -0
  41. package/dist/components/error-boundary/error-utils.js +177 -0
  42. package/dist/components/error-boundary/error-utils.js.map +1 -0
  43. package/dist/components/error-boundary/error-utils.mjs +13 -0
  44. package/dist/components/error-boundary/error-utils.mjs.map +1 -0
  45. package/dist/components/index.js +173 -92
  46. package/dist/components/index.js.map +1 -1
  47. package/dist/components/index.mjs +5 -4
  48. package/dist/components/toast/toast-provider.d.ts +2 -1
  49. package/dist/components/toast/toast-provider.js +76 -62
  50. package/dist/components/toast/toast-provider.js.map +1 -1
  51. package/dist/components/toast/toast-provider.mjs +1 -1
  52. package/dist/context/copilot-context.d.ts +4 -2
  53. package/dist/context/copilot-context.js +3 -0
  54. package/dist/context/copilot-context.js.map +1 -1
  55. package/dist/context/copilot-context.mjs +1 -1
  56. package/dist/context/index.d.ts +1 -1
  57. package/dist/context/index.js +3 -0
  58. package/dist/context/index.js.map +1 -1
  59. package/dist/context/index.mjs +1 -1
  60. package/dist/hooks/index.js +554 -308
  61. package/dist/hooks/index.js.map +1 -1
  62. package/dist/hooks/index.mjs +13 -11
  63. package/dist/hooks/use-chat.d.ts +6 -2
  64. package/dist/hooks/use-chat.js +434 -219
  65. package/dist/hooks/use-chat.js.map +1 -1
  66. package/dist/hooks/use-chat.mjs +4 -3
  67. package/dist/hooks/use-coagent-state-render.d.ts +2 -2
  68. package/dist/hooks/use-coagent-state-render.js +3 -0
  69. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  70. package/dist/hooks/use-coagent-state-render.mjs +2 -2
  71. package/dist/hooks/use-coagent.d.ts +1 -1
  72. package/dist/hooks/use-coagent.js +510 -277
  73. package/dist/hooks/use-coagent.js.map +1 -1
  74. package/dist/hooks/use-coagent.mjs +9 -7
  75. package/dist/hooks/use-copilot-action.d.ts +12 -2
  76. package/dist/hooks/use-copilot-action.js +157 -16
  77. package/dist/hooks/use-copilot-action.js.map +1 -1
  78. package/dist/hooks/use-copilot-action.mjs +4 -2
  79. package/dist/hooks/use-copilot-chat.d.ts +1 -0
  80. package/dist/hooks/use-copilot-chat.js +483 -253
  81. package/dist/hooks/use-copilot-chat.js.map +1 -1
  82. package/dist/hooks/use-copilot-chat.mjs +8 -6
  83. package/dist/hooks/use-copilot-readable.js +3 -0
  84. package/dist/hooks/use-copilot-readable.js.map +1 -1
  85. package/dist/hooks/use-copilot-readable.mjs +2 -2
  86. package/dist/hooks/use-copilot-runtime-client.js +110 -4
  87. package/dist/hooks/use-copilot-runtime-client.js.map +1 -1
  88. package/dist/hooks/use-copilot-runtime-client.mjs +2 -2
  89. package/dist/hooks/use-make-copilot-document-readable.js +3 -0
  90. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  91. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  92. package/dist/index.d.ts +1 -1
  93. package/dist/index.js +616 -401
  94. package/dist/index.js.map +1 -1
  95. package/dist/index.mjs +14 -12
  96. package/dist/lib/copilot-task.d.ts +1 -1
  97. package/dist/lib/copilot-task.js +33 -13
  98. package/dist/lib/copilot-task.js.map +1 -1
  99. package/dist/lib/copilot-task.mjs +7 -5
  100. package/dist/lib/index.d.ts +1 -1
  101. package/dist/lib/index.js +33 -13
  102. package/dist/lib/index.js.map +1 -1
  103. package/dist/lib/index.mjs +7 -5
  104. package/dist/types/frontend-action.d.ts +21 -2
  105. package/dist/types/frontend-action.js +34 -0
  106. package/dist/types/frontend-action.js.map +1 -1
  107. package/dist/types/frontend-action.mjs +7 -0
  108. package/dist/types/index.d.ts +2 -1
  109. package/dist/types/index.js.map +1 -1
  110. package/dist/utils/extract.js.map +1 -1
  111. package/dist/utils/extract.mjs +5 -4
  112. package/dist/utils/index.js.map +1 -1
  113. package/dist/utils/index.mjs +5 -4
  114. package/package.json +5 -5
  115. package/src/components/copilot-provider/copilotkit.tsx +22 -1
  116. package/src/components/error-boundary/error-boundary.tsx +42 -0
  117. package/src/components/error-boundary/error-utils.tsx +95 -0
  118. package/src/components/toast/toast-provider.tsx +10 -49
  119. package/src/context/copilot-context.tsx +17 -2
  120. package/src/hooks/use-chat.ts +375 -279
  121. package/src/hooks/use-coagent-state-render.ts +2 -2
  122. package/src/hooks/use-coagent.ts +34 -28
  123. package/src/hooks/use-copilot-action.ts +50 -15
  124. package/src/hooks/use-copilot-chat.ts +28 -14
  125. package/src/hooks/use-copilot-runtime-client.ts +4 -0
  126. package/src/lib/copilot-task.ts +2 -8
  127. package/src/types/frontend-action.ts +55 -2
  128. package/src/types/index.ts +5 -1
  129. package/dist/chunk-2JP64U3A.mjs.map +0 -1
  130. package/dist/chunk-2KCEHGSI.mjs.map +0 -1
  131. package/dist/chunk-3R4J2TPH.mjs.map +0 -1
  132. package/dist/chunk-6EN7J4V2.mjs +0 -317
  133. package/dist/chunk-6EN7J4V2.mjs.map +0 -1
  134. package/dist/chunk-6QKA3SNN.mjs.map +0 -1
  135. package/dist/chunk-CZMEZR6F.mjs.map +0 -1
  136. package/dist/chunk-JR55I3FL.mjs.map +0 -1
  137. package/dist/chunk-ODN4H66E.mjs.map +0 -1
  138. package/dist/chunk-SEPYQHH7.mjs.map +0 -1
  139. /package/dist/{chunk-USL3EHJB.mjs.map → chunk-5FYKUKG3.mjs.map} +0 -0
  140. /package/dist/{chunk-XUPO37VH.mjs.map → chunk-V3PFWGIY.mjs.map} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,16 +1,170 @@
1
1
  # ui
2
2
 
3
- ## 1.5.0-tyler-reset-chat.0
3
+ ## 1.5.0
4
4
 
5
5
  ### Minor Changes
6
6
 
7
- - Merging Markus' reset fixes with main + a new change for stopping an agent during execution of FE actions
7
+ - 1b47092: Synchronize LangGraph messages with CopilotKit
8
8
 
9
9
  ### Patch Changes
10
10
 
11
+ - 00e9488: - fix: wait for renderAndWaitForResponse handler to be ready before rendering
12
+ - 1b47092: CoAgents v0.3 prerelease
13
+ - Updated dependencies [1b47092]
14
+ - Updated dependencies [1b47092]
15
+ - @copilotkit/runtime-client-gql@1.5.0
16
+ - @copilotkit/shared@1.5.0
17
+
18
+ ## 1.5.0-coagents-v0-3.0
19
+
20
+ ### Minor Changes
21
+
22
+ - Synchronize LangGraph messages with CopilotKit
23
+
24
+ ### Patch Changes
25
+
26
+ - e66bce4: CoAgents v0.3 prerelease
27
+ - Updated dependencies
28
+ - Updated dependencies [e66bce4]
29
+ - @copilotkit/runtime-client-gql@1.5.0-coagents-v0-3.0
30
+ - @copilotkit/shared@1.5.0-coagents-v0-3.0
31
+
32
+ ## 1.4.8
33
+
34
+ ### Patch Changes
35
+
36
+ - - Better error handling
37
+ - Introduce new "EmptyLLMAdapter" for when using CoAgents
38
+ - Improve dev console help options
39
+ - Allow CopilotKit remote endpoint without agents
40
+ - Updated dependencies
41
+ - @copilotkit/runtime-client-gql@1.4.8
42
+ - @copilotkit/shared@1.4.8
43
+
44
+ ## 1.4.8-next.0
45
+
46
+ ### Patch Changes
47
+
48
+ - @copilotkit/runtime-client-gql@1.4.8-next.0
49
+ - @copilotkit/shared@1.4.8-next.0
50
+
51
+ ## 1.4.7
52
+
53
+ ### Patch Changes
54
+
55
+ - Fix broken build script before release
56
+ - Updated dependencies
57
+ - @copilotkit/runtime-client-gql@1.4.7
58
+ - @copilotkit/shared@1.4.7
59
+
60
+ ## 1.4.6
61
+
62
+ ### Patch Changes
63
+
64
+ - .
65
+
66
+ ## 1.4.5
67
+
68
+ ### Patch Changes
69
+
70
+ - testing release workflow
71
+ - Updated dependencies
72
+ - @copilotkit/runtime-client-gql@1.4.5
73
+ - @copilotkit/shared@1.4.5
74
+
75
+ ## 1.4.5-next.0
76
+
77
+ ### Patch Changes
78
+
79
+ - testing release workflow
80
+ - Updated dependencies
81
+ - @copilotkit/runtime-client-gql@1.4.5-next.0
82
+ - @copilotkit/shared@1.4.5-next.0
83
+
84
+ ## 1.4.4
85
+
86
+ ### Patch Changes
87
+
88
+ - e35e6ad: - test
89
+ - update config.json
90
+ - Merge remote-tracking branch 'origin/main' into feat/test-changeset-bot-1
91
+ - test
92
+ - test
93
+ - @copilotkit/runtime-client-gql@1.4.4
94
+ - @copilotkit/shared@1.4.4
95
+
96
+ ## 1.4.4-next.4
97
+
98
+ ### Patch Changes
99
+
100
+ - @copilotkit/runtime-client-gql@1.4.4-next.4
101
+ - @copilotkit/shared@1.4.4-next.4
102
+
103
+ ## 1.4.4-next.3
104
+
105
+ ### Patch Changes
106
+
107
+ - @copilotkit/runtime-client-gql@1.4.4-next.3
108
+ - @copilotkit/shared@1.4.4-next.3
109
+
110
+ ## 1.4.4-next.2
111
+
112
+ ### Patch Changes
113
+
114
+ - @copilotkit/runtime-client-gql@1.4.4-next.2
115
+ - @copilotkit/shared@1.4.4-next.2
116
+
117
+ ## 1.4.4-next.1
118
+
119
+ ### Patch Changes
120
+
121
+ - @copilotkit/runtime-client-gql@1.4.4-next.1
122
+ - @copilotkit/shared@1.4.4-next.1
123
+
124
+ ## 1.4.4-next.0
125
+
126
+ ### Patch Changes
127
+
128
+ - e35e6ad: - test
129
+ - update config.json
130
+ - Merge remote-tracking branch 'origin/main' into feat/test-changeset-bot-1
131
+ - test
132
+ - test
133
+ - @copilotkit/runtime-client-gql@1.4.4-next.0
134
+ - @copilotkit/shared@1.4.4-next.0
135
+
136
+ ## 1.4.3
137
+
138
+ ### Patch Changes
139
+
140
+ - c296282: - Better error surfacing when using LangGraph Platform streaming
141
+ - Ensure state is immediately set without using flushSync
142
+ - - Better error surfacing when using LangGraph Platform streaming
143
+ - Ensure state is immediately set without using flushSync
144
+ - Updated dependencies [c296282]
145
+ - Updated dependencies
146
+ - @copilotkit/runtime-client-gql@1.4.3
147
+ - @copilotkit/shared@1.4.3
148
+
149
+ ## 1.4.3-pre.0
150
+
151
+ ### Patch Changes
152
+
153
+ - - Better error surfacing when using LangGraph Platform streaming
154
+ - Ensure state is immediately set without using flushSync
155
+ - Updated dependencies
156
+ - @copilotkit/runtime-client-gql@1.4.3-pre.0
157
+ - @copilotkit/shared@1.4.3-pre.0
158
+
159
+ ## 1.4.2
160
+
161
+ ### Patch Changes
162
+
163
+ - - Make sure agent state is set immediately (#1077)
164
+ - Support running an agent without messages (#1075)
11
165
  - Updated dependencies
12
- - @copilotkit/runtime-client-gql@1.5.0-tyler-reset-chat.0
13
- - @copilotkit/shared@1.5.0-tyler-reset-chat.0
166
+ - @copilotkit/runtime-client-gql@1.4.2
167
+ - @copilotkit/shared@1.4.2
14
168
 
15
169
  ## 1.4.1
16
170
 
package/README.md CHANGED
@@ -12,6 +12,8 @@
12
12
 
13
13
  <br/>
14
14
 
15
+ <!-- -->
16
+
15
17
  <div align="center">
16
18
  <a href="https://www.npmjs.com/package/@copilotkit/react-core" target="_blank">
17
19
  <img src="https://img.shields.io/npm/v/%40copilotkit%2Freact-core?logo=npm&logoColor=%23FFFFFF&label=Version&color=%236963ff" alt="NPM">
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  CopilotContext
3
- } from "./chunk-2JP64U3A.mjs";
3
+ } from "./chunk-TQN3EZWQ.mjs";
4
4
 
5
5
  // src/hooks/use-coagent-state-render.ts
6
6
  import { useRef, useContext, useEffect } from "react";
@@ -46,4 +46,4 @@ function useCoAgentStateRender(action, dependencies) {
46
46
  export {
47
47
  useCoAgentStateRender
48
48
  };
49
- //# sourceMappingURL=chunk-3AYELZJS.mjs.map
49
+ //# sourceMappingURL=chunk-35EN6BG4.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hooks/use-coagent-state-render.ts"],"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\";\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 } = useContext(CopilotContext);\n const idRef = useRef<string>(randomId());\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"],"mappings":";;;;;AAgDA,SAAS,QAAQ,YAAY,iBAAiB;AAE9C,SAAS,gBAAgB;AAclB,SAAS,sBACd,QACA,cACM;AACN,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,cAAc;AAC7B,QAAM,QAAQ,OAAe,SAAS,CAAC;AAEvC,QAAM,MAAM,GAAG,OAAO,QAAQ,OAAO,YAAY;AAEjD,MAAI,iBAAiB,QAAW;AAC9B,QAAI,oBAAoB,MAAM,OAAO,GAAG;AACtC,0BAAoB,MAAM,OAAO,EAAE,UAAU,OAAO;AACpD,UAAI,OAAO,OAAO,WAAW,YAAY;AACvC,YAAI,oBAAoB,YAAY,MAAM;AACxC,8BAAoB,QAAQ,oBAAoB,GAAG,IAAI,OAAO;AAAA,QAChE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,YAAU,MAAM;AACd,0BAAsB,MAAM,SAAS,MAAa;AAClD,QAAI,oBAAoB,YAAY,QAAQ,OAAO,WAAW,QAAW;AACvE,0BAAoB,QAAQ,oBAAoB,GAAG,IAAI,OAAO;AAAA,IAChE;AACA,WAAO,MAAM;AACX,+BAAyB,MAAM,OAAO;AAAA,IACxC;AAAA,EACF,GAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA,OAAO;AAAA;AAAA,IAEP,OAAO,OAAO,WAAW,WAAW,OAAO,SAAS;AAAA;AAAA,IAEpD,GAAI,gBAAgB,CAAC;AAAA,EACvB,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../src/hooks/use-coagent-state-render.ts"],"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\";\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 } = useContext(CopilotContext);\n const idRef = useRef<string>(randomId());\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"],"mappings":";;;;;AAgDA,SAAS,QAAQ,YAAY,iBAAiB;AAE9C,SAAS,gBAAgB;AAclB,SAAS,sBACd,QACA,cACM;AACN,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,cAAc;AAC7B,QAAM,QAAQ,OAAe,SAAS,CAAC;AAEvC,QAAM,MAAM,GAAG,OAAO,QAAQ,OAAO,YAAY;AAEjD,MAAI,iBAAiB,QAAW;AAC9B,QAAI,oBAAoB,MAAM,OAAO,GAAG;AACtC,0BAAoB,MAAM,OAAO,EAAE,UAAU,OAAO;AACpD,UAAI,OAAO,OAAO,WAAW,YAAY;AACvC,YAAI,oBAAoB,YAAY,MAAM;AACxC,8BAAoB,QAAQ,oBAAoB,GAAG,IAAI,OAAO;AAAA,QAChE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,YAAU,MAAM;AACd,0BAAsB,MAAM,SAAS,MAAa;AAClD,QAAI,oBAAoB,YAAY,QAAQ,OAAO,WAAW,QAAW;AACvE,0BAAoB,QAAQ,oBAAoB,GAAG,IAAI,OAAO;AAAA,IAChE;AACA,WAAO,MAAM;AACX,+BAAyB,MAAM,OAAO;AAAA,IACxC;AAAA,EACF,GAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA,OAAO;AAAA;AAAA,IAEP,OAAO,OAAO,WAAW,WAAW,OAAO,SAAS;AAAA;AAAA,IAEpD,GAAI,gBAAgB,CAAC;AAAA,EACvB,CAAC;AACH;","names":[]}
@@ -1,12 +1,15 @@
1
1
  import {
2
2
  useCopilotChat
3
- } from "./chunk-CZMEZR6F.mjs";
3
+ } from "./chunk-BT6WK2JZ.mjs";
4
4
  import {
5
5
  useCopilotMessagesContext
6
6
  } from "./chunk-DCTJZ742.mjs";
7
+ import {
8
+ useAsyncCallback
9
+ } from "./chunk-SFPANIOY.mjs";
7
10
  import {
8
11
  useCopilotContext
9
- } from "./chunk-2JP64U3A.mjs";
12
+ } from "./chunk-TQN3EZWQ.mjs";
10
13
  import {
11
14
  __async,
12
15
  __spreadProps,
@@ -26,8 +29,8 @@ function useCoAgent(options) {
26
29
  const generalContext = useCopilotContext();
27
30
  const messagesContext = useCopilotMessagesContext();
28
31
  const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
29
- const { coagentStates, setCoagentStates } = context;
30
- const { appendMessage } = useCopilotChat();
32
+ const { coagentStates, coagentStatesRef, setCoagentStatesWithRef } = context;
33
+ const { appendMessage, runChatCompletion } = useCopilotChat();
31
34
  const getCoagentState = (coagentStates2, name2) => {
32
35
  if (coagentStates2[name2]) {
33
36
  return coagentStates2[name2];
@@ -44,15 +47,13 @@ function useCoAgent(options) {
44
47
  }
45
48
  };
46
49
  const setState = (newState) => {
47
- setCoagentStates((prevAgentStates) => {
48
- let coagentState2 = getCoagentState(prevAgentStates, name);
49
- const updatedState = typeof newState === "function" ? newState(coagentState2.state) : newState;
50
- return __spreadProps(__spreadValues({}, prevAgentStates), {
51
- [name]: __spreadProps(__spreadValues({}, coagentState2), {
52
- state: updatedState
53
- })
54
- });
55
- });
50
+ let coagentState2 = getCoagentState(coagentStatesRef.current || {}, name);
51
+ const updatedState = typeof newState === "function" ? newState(coagentState2.state) : newState;
52
+ setCoagentStatesWithRef(__spreadProps(__spreadValues({}, coagentStatesRef.current), {
53
+ [name]: __spreadProps(__spreadValues({}, coagentState2), {
54
+ state: updatedState
55
+ })
56
+ }));
56
57
  };
57
58
  const coagentState = getCoagentState(coagentStates, name);
58
59
  const state = isExternalStateManagement(options) ? options.state : coagentState.state;
@@ -65,23 +66,24 @@ function useCoAgent(options) {
65
66
  }, [
66
67
  isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0,
67
68
  // reset initialstate on reset
68
- coagentStates === void 0
69
+ coagentStates[name] === void 0
69
70
  ]);
71
+ const runAgentCallback = useAsyncCallback(
72
+ (hint) => __async(this, null, function* () {
73
+ yield runAgent(name, context, appendMessage, runChatCompletion, hint);
74
+ }),
75
+ [name, context, appendMessage, runChatCompletion]
76
+ );
70
77
  return {
71
78
  name,
72
79
  nodeName: coagentState.nodeName,
73
- state,
74
- setState,
80
+ threadId: coagentState.threadId,
75
81
  running: coagentState.running,
76
- start: () => {
77
- startAgent(name, context);
78
- },
79
- stop: () => {
80
- stopAgent(name, context);
81
- },
82
- run: (hint) => {
83
- return runAgent(name, context, appendMessage, hint);
84
- }
82
+ state: coagentState.state,
83
+ setState: isExternalStateManagement(options) ? options.setState : setState,
84
+ start: () => startAgent(name, context),
85
+ stop: () => stopAgent(name, context),
86
+ run: runAgentCallback
85
87
  };
86
88
  }
87
89
  function startAgent(name, context) {
@@ -109,7 +111,7 @@ function stopAgent(name, context) {
109
111
  console.warn(`No agent session found for ${name}`);
110
112
  }
111
113
  }
112
- function runAgent(name, context, appendMessage, hint) {
114
+ function runAgent(name, context, appendMessage, runChatCompletion, hint) {
113
115
  return __async(this, null, function* () {
114
116
  var _a, _b;
115
117
  const { agentSession, setAgentSession } = context;
@@ -125,12 +127,16 @@ function runAgent(name, context, appendMessage, hint) {
125
127
  previousState = message.state;
126
128
  }
127
129
  }
128
- let state = ((_b = (_a = context.coagentStates) == null ? void 0 : _a[name]) == null ? void 0 : _b.state) || {};
130
+ let state = ((_b = (_a = context.coagentStatesRef.current) == null ? void 0 : _a[name]) == null ? void 0 : _b.state) || {};
129
131
  if (hint) {
130
132
  const hintMessage = hint({ previousState, currentState: state });
131
133
  if (hintMessage) {
132
134
  yield appendMessage(hintMessage);
135
+ } else {
136
+ yield runChatCompletion();
133
137
  }
138
+ } else {
139
+ yield runChatCompletion();
134
140
  }
135
141
  });
136
142
  }
@@ -141,4 +147,4 @@ export {
141
147
  stopAgent,
142
148
  runAgent
143
149
  };
144
- //# sourceMappingURL=chunk-SEPYQHH7.mjs.map
150
+ //# sourceMappingURL=chunk-42N5VKIX.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-coagent.ts"],"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\">[getting started guide](/coagents/quickstart)</span>.\n * </Callout>\n * <Frame className=\"my-12\">\n * <img\n * src=\"/images/coagents/SharedStateCoAgents.gif\"\n * alt=\"CoAgents demonstration\"\n * className=\"w-auto\"\n * />\n * </Frame>\n *\n * This hook is used to integrate an agent into your application. With its use, you can\n * render and update the state of an agent, allowing for a dynamic and interactive experience.\n * We call these shared state experiences agentic copilots, or CoAgents for short.\n *\n * ## Usage\n *\n * ### Simple Usage\n *\n * ```tsx\n * import { useCoAgent } from \"@copilotkit/react-core\";\n *\n * type AgentState = {\n * count: number;\n * }\n *\n * const agent = useCoAgent<AgentState>({\n * name: \"my-agent\",\n * initialState: {\n * count: 0,\n * },\n * });\n *\n * ```\n *\n * `useCoAgent` returns an object with the following properties:\n *\n * ```tsx\n * const {\n * name, // The name of the agent currently being used.\n * nodeName, // The name of the current LangGraph node.\n * state, // The current state of the agent.\n * setState, // A function to update the state of the agent.\n * running, // A boolean indicating if the agent is currently running.\n * start, // A function to start the agent.\n * stop, // A function to stop the agent.\n * run, // A function to re-run the agent. Takes a HintFunction to inform the agent why it is being re-run.\n * } = agent;\n * ```\n *\n * Finally we can leverage these properties to create reactive experiences with the agent!\n *\n * ```tsx\n * const { state, setState } = useCoAgent<AgentState>({\n * name: \"my-agent\",\n * initialState: {\n * count: 0,\n * },\n * });\n *\n * return (\n * <div>\n * <p>Count: {state.count}</p>\n * <button onClick={() => setState({ count: state.count + 1 })}>Increment</button>\n * </div>\n * );\n * ```\n *\n * This reactivity is bidirectional, meaning that changes to the state from the agent will be reflected in the UI and vice versa.\n *\n * ## Parameters\n * <PropertyReference name=\"options\" type=\"UseCoagentOptions<T>\" required>\n * The options to use when creating the coagent.\n * <PropertyReference name=\"name\" type=\"string\" required>\n * The name of the agent to use.\n * </PropertyReference>\n * <PropertyReference name=\"initialState\" type=\"T | any\">\n * The initial state of the agent.\n * </PropertyReference>\n * <PropertyReference name=\"state\" type=\"T | any\">\n * State to manage externally if you are using this hook with external state management.\n * </PropertyReference>\n * <PropertyReference name=\"setState\" type=\"(newState: T | ((prevState: T | undefined) => T)) => void\">\n * A function to update the state of the agent if you are using this hook with external state management.\n * </PropertyReference>\n * </PropertyReference>\n */\n\nimport { useEffect } from \"react\";\nimport {\n CopilotContextParams,\n CopilotMessagesContextParams,\n useCopilotContext,\n useCopilotMessagesContext,\n} from \"../context\";\nimport { CoagentState } from \"../types/coagent-state\";\nimport { useCopilotChat } from \"./use-copilot-chat\";\nimport { Message } from \"@copilotkit/runtime-client-gql\";\nimport { flushSync } from \"react-dom\";\nimport { useAsyncCallback } from \"../components/error-boundary/error-utils\";\n\ninterface WithInternalStateManagementAndInitial<T> {\n /**\n * The name of the agent being used.\n */\n name: string;\n /**\n * The initial state of the agent.\n */\n initialState: T;\n}\n\ninterface WithInternalStateManagement {\n /**\n * The name of the agent being used.\n */\n name: string;\n /**\n * Optional initialState with default type any\n */\n initialState?: any;\n}\n\ninterface WithExternalStateManagement<T> {\n /**\n * The name of the agent being used.\n */\n name: string;\n /**\n * The current state of the agent.\n */\n state: T;\n /**\n * A function to update the state of the agent.\n */\n setState: (newState: T | ((prevState: T | undefined) => T)) => void;\n}\n\ntype UseCoagentOptions<T> =\n | WithInternalStateManagementAndInitial<T>\n | WithInternalStateManagement\n | WithExternalStateManagement<T>;\n\nexport interface UseCoagentReturnType<T> {\n /**\n * The name of the agent being used.\n */\n name: string;\n /**\n * The name of the current LangGraph node.\n */\n nodeName?: string;\n /**\n * The ID of the thread the agent is running in.\n */\n threadId?: string;\n /**\n * A boolean indicating if the agent is currently running.\n */\n running: boolean;\n /**\n * The current state of the agent.\n */\n state: T;\n /**\n * A function to update the state of the agent.\n */\n setState: (newState: T | ((prevState: T | undefined) => T)) => void;\n /**\n * A function to start the agent.\n */\n start: () => void;\n /**\n * A function to stop the agent.\n */\n stop: () => void;\n /**\n * A function to re-run the agent. The hint function can be used to provide a hint to the agent\n * about why it is being re-run again.\n */\n run: (hint?: HintFunction) => Promise<void>;\n}\n\nexport interface HintFunctionParams {\n /**\n * The previous state of the agent.\n */\n previousState: any;\n /**\n * The current state of the agent.\n */\n currentState: any;\n}\n\nexport type HintFunction = (params: HintFunctionParams) => Message | undefined;\n\n/**\n * This hook is used to integrate an agent into your application. With its use, you can\n * render and update the state of the agent, allowing for a dynamic and interactive experience.\n * We call these shared state experiences \"agentic copilots\". To get started using agentic copilots, which\n * we refer to as CoAgents, checkout the documentation at https://docs.copilotkit.ai/coagents/quickstart.\n */\nexport function useCoAgent<T = any>(options: UseCoagentOptions<T>): UseCoagentReturnType<T> {\n const isExternalStateManagement = (\n options: UseCoagentOptions<T>,\n ): options is WithExternalStateManagement<T> => {\n return \"state\" in options && \"setState\" in options;\n };\n\n const { name } = options;\n\n const isInternalStateManagementWithInitial = (\n options: UseCoagentOptions<T>,\n ): options is WithInternalStateManagementAndInitial<T> => {\n return \"initialState\" in options;\n };\n\n const generalContext = useCopilotContext();\n const messagesContext = useCopilotMessagesContext();\n const context = { ...generalContext, ...messagesContext };\n const { coagentStates, coagentStatesRef, setCoagentStatesWithRef } = context;\n const { appendMessage, runChatCompletion } = useCopilotChat();\n\n const getCoagentState = (coagentStates: Record<string, CoagentState>, name: string) => {\n if (coagentStates[name]) {\n return coagentStates[name];\n } else {\n return {\n name,\n state: isInternalStateManagementWithInitial(options) ? options.initialState : {},\n running: false,\n active: false,\n threadId: undefined,\n nodeName: undefined,\n runId: undefined,\n };\n }\n };\n\n // if we manage state internally, we need to provide a function to set the state\n const setState = (newState: T | ((prevState: T | undefined) => T)) => {\n let coagentState: CoagentState = getCoagentState(coagentStatesRef.current || {}, name);\n const updatedState =\n typeof newState === \"function\" ? (newState as Function)(coagentState.state) : newState;\n\n setCoagentStatesWithRef({\n ...coagentStatesRef.current,\n [name]: {\n ...coagentState,\n state: updatedState,\n },\n });\n };\n\n const coagentState = getCoagentState(coagentStates, name);\n\n const state = isExternalStateManagement(options) ? options.state : coagentState.state;\n\n // Sync internal state with external state if state management is external\n useEffect(() => {\n if (isExternalStateManagement(options)) {\n setState(options.state);\n } else if (coagentStates[name] === undefined) {\n setState(options.initialState === undefined ? {} : options.initialState);\n }\n }, [\n isExternalStateManagement(options) ? JSON.stringify(options.state) : undefined,\n // reset initialstate on reset\n coagentStates[name] === undefined,\n ]);\n\n const runAgentCallback = useAsyncCallback(\n async (hint?: HintFunction) => {\n await runAgent(name, context, appendMessage, runChatCompletion, hint);\n },\n [name, context, appendMessage, runChatCompletion],\n );\n\n // Return the state and setState function\n return {\n name,\n nodeName: coagentState.nodeName,\n threadId: coagentState.threadId,\n running: coagentState.running,\n state: coagentState.state,\n setState: isExternalStateManagement(options) ? options.setState : setState,\n start: () => startAgent(name, context),\n stop: () => stopAgent(name, context),\n run: runAgentCallback,\n };\n}\n\nexport function startAgent(name: string, context: CopilotContextParams) {\n const { setAgentSession } = context;\n setAgentSession({\n agentName: name,\n });\n}\n\nexport function stopAgent(name: string, context: CopilotContextParams) {\n const { agentSession, setAgentSession } = context;\n if (agentSession && agentSession.agentName === name) {\n setAgentSession(null);\n context.setCoagentStates((prevAgentStates) => {\n return {\n ...prevAgentStates,\n [name]: {\n ...prevAgentStates[name],\n running: false,\n active: false,\n threadId: undefined,\n nodeName: undefined,\n runId: undefined,\n },\n };\n });\n } else {\n console.warn(`No agent session found for ${name}`);\n }\n}\n\nexport async function runAgent(\n name: string,\n context: CopilotContextParams & CopilotMessagesContextParams,\n appendMessage: (message: Message) => Promise<void>,\n runChatCompletion: () => Promise<Message[]>,\n hint?: HintFunction,\n) {\n const { agentSession, setAgentSession } = context;\n if (!agentSession || agentSession.agentName !== name) {\n setAgentSession({\n agentName: name,\n });\n }\n\n let previousState: any = null;\n for (let i = context.messages.length - 1; i >= 0; i--) {\n const message = context.messages[i];\n if (message.isAgentStateMessage() && message.agentName === name) {\n previousState = message.state;\n }\n }\n\n let state = context.coagentStatesRef.current?.[name]?.state || {};\n\n if (hint) {\n const hintMessage = hint({ previousState, currentState: state });\n if (hintMessage) {\n await appendMessage(hintMessage);\n } else {\n await runChatCompletion();\n }\n } else {\n await runChatCompletion();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA0FA,SAAS,iBAAiB;AAkHnB,SAAS,WAAoB,SAAwD;AAC1F,QAAM,4BAA4B,CAChCA,aAC8C;AAC9C,WAAO,WAAWA,YAAW,cAAcA;AAAA,EAC7C;AAEA,QAAM,EAAE,KAAK,IAAI;AAEjB,QAAM,uCAAuC,CAC3CA,aACwD;AACxD,WAAO,kBAAkBA;AAAA,EAC3B;AAEA,QAAM,iBAAiB,kBAAkB;AACzC,QAAM,kBAAkB,0BAA0B;AAClD,QAAM,UAAU,kCAAK,iBAAmB;AACxC,QAAM,EAAE,eAAe,kBAAkB,wBAAwB,IAAI;AACrE,QAAM,EAAE,eAAe,kBAAkB,IAAI,eAAe;AAE5D,QAAM,kBAAkB,CAACC,gBAA6CC,UAAiB;AACrF,QAAID,eAAcC,KAAI,GAAG;AACvB,aAAOD,eAAcC,KAAI;AAAA,IAC3B,OAAO;AACL,aAAO;AAAA,QACL,MAAAA;AAAA,QACA,OAAO,qCAAqC,OAAO,IAAI,QAAQ,eAAe,CAAC;AAAA,QAC/E,SAAS;AAAA,QACT,QAAQ;AAAA,QACR,UAAU;AAAA,QACV,UAAU;AAAA,QACV,OAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AAGA,QAAM,WAAW,CAAC,aAAoD;AACpE,QAAIC,gBAA6B,gBAAgB,iBAAiB,WAAW,CAAC,GAAG,IAAI;AACrF,UAAM,eACJ,OAAO,aAAa,aAAc,SAAsBA,cAAa,KAAK,IAAI;AAEhF,4BAAwB,iCACnB,iBAAiB,UADE;AAAA,MAEtB,CAAC,IAAI,GAAG,iCACHA,gBADG;AAAA,QAEN,OAAO;AAAA,MACT;AAAA,IACF,EAAC;AAAA,EACH;AAEA,QAAM,eAAe,gBAAgB,eAAe,IAAI;AAExD,QAAM,QAAQ,0BAA0B,OAAO,IAAI,QAAQ,QAAQ,aA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AAAA,QACT;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,OAAO;AACL,YAAQ,KAAK,8BAA8B,MAAM;AAAA,EACnD;AACF;AAEA,SAAsB,SACpB,MACA,SACA,eACA,mBACA,MACA;AAAA;AAzUF;AA0UE,UAAM,EAAE,cAAc,gBAAgB,IAAI;AAC1C,QAAI,CAAC,gBAAgB,aAAa,cAAc,MAAM;AACpD,sBAAgB;AAAA,QACd,WAAW;AAAA,MACb,CAAC;AAAA,IACH;AAEA,QAAI,gBAAqB;AACzB,aAAS,IAAI,QAAQ,SAAS,SAAS,GAAG,KAAK,GAAG,KAAK;AACrD,YAAM,UAAU,QAAQ,SAAS,CAAC;AAClC,UAAI,QAAQ,oBAAoB,KAAK,QAAQ,cAAc,MAAM;AAC/D,wBAAgB,QAAQ;AAAA,MAC1B;AAAA,IACF;AAEA,QAAI,UAAQ,mBAAQ,iBAAiB,YAAzB,mBAAmC,UAAnC,mBAA0C,UAAS,CAAC;AAEhE,QAAI,MAAM;AACR,YAAM,cAAc,KAAK,EAAE,eAAe,cAAc,MAAM,CAAC;AAC/D,UAAI,aAAa;AACf,cAAM,cAAc,WAAW;AAAA,MACjC,OAAO;AACL,cAAM,kBAAkB;AAAA,MAC1B;AAAA,IACF,OAAO;AACL,YAAM,kBAAkB;AAAA,IAC1B;AAAA,EACF;AAAA;","names":["options","coagentStates","name","coagentState"]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useCopilotContext
3
- } from "./chunk-2JP64U3A.mjs";
3
+ } from "./chunk-TQN3EZWQ.mjs";
4
4
 
5
5
  // src/hooks/use-copilot-readable.ts
6
6
  import { useEffect, useRef } from "react";
@@ -25,4 +25,4 @@ function useCopilotReadable({ description, value, parentId, categories, convert
25
25
  export {
26
26
  useCopilotReadable
27
27
  };
28
- //# sourceMappingURL=chunk-USL3EHJB.mjs.map
28
+ //# sourceMappingURL=chunk-5FYKUKG3.mjs.map
@@ -1,6 +1,7 @@
1
1
  import {
2
+ useErrorToast,
2
3
  useToast
3
- } from "./chunk-2KCEHGSI.mjs";
4
+ } from "./chunk-SFPANIOY.mjs";
4
5
  import {
5
6
  __spreadProps,
6
7
  __spreadValues
@@ -13,11 +14,14 @@ import {
13
14
  import { useMemo } from "react";
14
15
  var useCopilotRuntimeClient = (options) => {
15
16
  const { addGraphQLErrorsToast } = useToast();
17
+ const addErrorToast = useErrorToast();
16
18
  const runtimeClient = useMemo(() => {
17
19
  return new CopilotRuntimeClient(__spreadProps(__spreadValues({}, options), {
18
20
  handleGQLErrors: (error) => {
19
21
  if (error.graphQLErrors.length) {
20
22
  addGraphQLErrorsToast(error.graphQLErrors);
23
+ } else {
24
+ addErrorToast([error]);
21
25
  }
22
26
  }
23
27
  }));
@@ -28,4 +32,4 @@ var useCopilotRuntimeClient = (options) => {
28
32
  export {
29
33
  useCopilotRuntimeClient
30
34
  };
31
- //# sourceMappingURL=chunk-ODN4H66E.mjs.map
35
+ //# sourceMappingURL=chunk-7LRDVJH5.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-copilot-runtime-client.ts"],"sourcesContent":["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"],"mappings":";;;;;;;;;;AAAA;AAAA,EACE;AAAA,OAGK;AAEP,SAAS,eAAe;AAGjB,IAAM,0BAA0B,CAAC,YAAyC;AAC/E,QAAM,EAAE,sBAAsB,IAAI,SAAS;AAC3C,QAAM,gBAAgB,cAAc;AAEpC,QAAM,gBAAgB,QAAQ,MAAM;AAClC,WAAO,IAAI,qBAAqB,iCAC3B,UAD2B;AAAA,MAE9B,iBAAiB,CAAC,UAAU;AAC1B,YAAK,MAAc,cAAc,QAAQ;AACvC,gCAAuB,MAAc,aAA+B;AAAA,QACtE,OAAO;AACL,wBAAc,CAAC,KAAK,CAAC;AAAA,QACvB;AAAA,MACF;AAAA,IACF,EAAC;AAAA,EACH,GAAG,CAAC,SAAS,qBAAqB,CAAC;AAEnC,SAAO;AACT;","names":[]}
@@ -1,15 +1,18 @@
1
1
  import {
2
2
  defaultCopilotContextCategories
3
- } from "./chunk-6QKA3SNN.mjs";
3
+ } from "./chunk-VMP6JWBB.mjs";
4
4
  import {
5
5
  useCopilotMessagesContext
6
6
  } from "./chunk-DCTJZ742.mjs";
7
7
  import {
8
8
  useChat
9
- } from "./chunk-6EN7J4V2.mjs";
9
+ } from "./chunk-QTDCEDOC.mjs";
10
+ import {
11
+ useAsyncCallback
12
+ } from "./chunk-SFPANIOY.mjs";
10
13
  import {
11
14
  useCopilotContext
12
- } from "./chunk-2JP64U3A.mjs";
15
+ } from "./chunk-TQN3EZWQ.mjs";
13
16
  import {
14
17
  __async,
15
18
  __objRest,
@@ -34,8 +37,8 @@ function useCopilotChat(_a = {}) {
34
37
  setIsLoading,
35
38
  chatInstructions,
36
39
  actions,
37
- coagentStates,
38
- setCoagentStates,
40
+ coagentStatesRef,
41
+ setCoagentStatesWithRef,
39
42
  coAgentStateRenders,
40
43
  agentSession,
41
44
  setAgentSession,
@@ -62,7 +65,7 @@ function useCopilotChat(_a = {}) {
62
65
  role: Role.System
63
66
  });
64
67
  }, [getContextString, makeSystemMessage, chatInstructions]);
65
- const onCoAgentStateRender = useCallback(
68
+ const onCoAgentStateRender = useAsyncCallback(
66
69
  (args) => __async(this, null, function* () {
67
70
  var _a2;
68
71
  const { name, nodeName, state } = args;
@@ -80,7 +83,7 @@ function useCopilotChat(_a = {}) {
80
83
  }),
81
84
  [coAgentStateRenders]
82
85
  );
83
- const { append, reload, stop } = useChat(__spreadProps(__spreadValues({}, options), {
86
+ const { append, reload, stop, runChatCompletion } = useChat(__spreadProps(__spreadValues({}, options), {
84
87
  actions: Object.values(actions),
85
88
  copilotConfig: copilotApiConfig,
86
89
  initialMessages: options.initialMessages || [],
@@ -91,8 +94,8 @@ function useCopilotChat(_a = {}) {
91
94
  makeSystemMessageCallback,
92
95
  isLoading,
93
96
  setIsLoading,
94
- coagentStates,
95
- setCoagentStates,
97
+ coagentStatesRef,
98
+ setCoagentStatesWithRef,
96
99
  agentSession,
97
100
  setAgentSession,
98
101
  threadId,
@@ -102,16 +105,16 @@ function useCopilotChat(_a = {}) {
102
105
  chatAbortControllerRef
103
106
  }));
104
107
  const latestAppend = useUpdatedRef(append);
105
- const latestAppendFunc = useCallback(
106
- (message) => {
107
- return latestAppend.current(message);
108
- },
108
+ const latestAppendFunc = useAsyncCallback(
109
+ (message) => __async(this, null, function* () {
110
+ return yield latestAppend.current(message);
111
+ }),
109
112
  [latestAppend]
110
113
  );
111
114
  const latestReload = useUpdatedRef(reload);
112
- const latestReloadFunc = useCallback(() => {
113
- return latestReload.current();
114
- }, [latestReload]);
115
+ const latestReloadFunc = useAsyncCallback(() => __async(this, null, function* () {
116
+ return yield latestReload.current();
117
+ }), [latestReload]);
115
118
  const latestStop = useUpdatedRef(stop);
116
119
  const latestStopFunc = useCallback(() => {
117
120
  return latestStop.current();
@@ -130,12 +133,16 @@ function useCopilotChat(_a = {}) {
130
133
  },
131
134
  [latestSetMessages]
132
135
  );
136
+ const latestRunChatCompletion = useUpdatedRef(runChatCompletion);
137
+ const latestRunChatCompletionFunc = useAsyncCallback(() => __async(this, null, function* () {
138
+ return yield latestRunChatCompletion.current();
139
+ }), [latestRunChatCompletion]);
133
140
  const reset = useCallback(() => {
134
141
  latestStopFunc();
135
142
  setMessages([]);
136
143
  setThreadId(null);
137
144
  setRunId(null);
138
- setCoagentStates({});
145
+ setCoagentStatesWithRef({});
139
146
  let initialAgentSession = null;
140
147
  if (agentLock) {
141
148
  initialAgentSession = {
@@ -143,7 +150,14 @@ function useCopilotChat(_a = {}) {
143
150
  };
144
151
  }
145
152
  setAgentSession(initialAgentSession);
146
- }, [latestStopFunc, setMessages, setThreadId, setCoagentStates, setAgentSession, agentLock]);
153
+ }, [
154
+ latestStopFunc,
155
+ setMessages,
156
+ setThreadId,
157
+ setCoagentStatesWithRef,
158
+ setAgentSession,
159
+ agentLock
160
+ ]);
147
161
  const latestReset = useUpdatedRef(reset);
148
162
  const latestResetFunc = useCallback(() => {
149
163
  return latestReset.current();
@@ -156,6 +170,7 @@ function useCopilotChat(_a = {}) {
156
170
  stopGeneration: latestStopFunc,
157
171
  reset: latestResetFunc,
158
172
  deleteMessage: latestDeleteFunc,
173
+ runChatCompletion: latestRunChatCompletionFunc,
159
174
  isLoading
160
175
  };
161
176
  }
@@ -194,4 +209,4 @@ export {
194
209
  useCopilotChat,
195
210
  defaultSystemMessage
196
211
  };
197
- //# sourceMappingURL=chunk-CZMEZR6F.mjs.map
212
+ //# sourceMappingURL=chunk-BT6WK2JZ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-copilot-chat.ts"],"sourcesContent":["/**\n * `useCopilotChat` is a React hook that lets you directly interact with the\n * Copilot instance. Use to implement a fully custom UI (headless UI) or to\n * programmatically interact with the Copilot instance managed by the default\n * UI.\n *\n * ## Usage\n *\n * ### Simple Usage\n *\n * ```tsx\n * import { useCopilotChat } from \"@copilotkit/react-core\";\n * import { Role, TextMessage } from \"@copilotkit/runtime-client-gql\";\n *\n * export function YourComponent() {\n * const { appendMessage } = useCopilotChat();\n *\n * appendMessage(\n * new TextMessage({\n * content: \"Hello World\",\n * role: Role.User,\n * }),\n * );\n * }\n * ```\n *\n * `useCopilotChat` returns an object with the following properties:\n *\n * ```tsx\n * const {\n * visibleMessages, // An array of messages that are currently visible in the chat.\n * appendMessage, // A function to append a message to the chat.\n * setMessages, // A function to set the messages in the chat.\n * deleteMessage, // A function to delete a message from the chat.\n * reloadMessages, // A function to reload the messages from the API.\n * stopGeneration, // A function to stop the generation of the next message.\n * isLoading, // A boolean indicating if the chat is loading.\n * } = useCopilotChat();\n * ```\n */\nimport { useRef, useEffect, useCallback } from \"react\";\nimport { AgentSession, useCopilotContext } from \"../context/copilot-context\";\nimport { Message, Role, TextMessage } from \"@copilotkit/runtime-client-gql\";\nimport { SystemMessageFunction } from \"../types\";\nimport { useChat } from \"./use-chat\";\nimport { defaultCopilotContextCategories } from \"../components\";\nimport { MessageStatusCode } from \"@copilotkit/runtime-client-gql\";\nimport { CoAgentStateRenderHandlerArguments } from \"@copilotkit/shared\";\nimport { useCopilotMessagesContext } from \"../context\";\nimport { useAsyncCallback } from \"../components/error-boundary/error-utils\";\n\nexport interface UseCopilotChatOptions {\n /**\n * A unique identifier for the chat. If not provided, a random one will be\n * generated. When provided, the `useChat` hook with the same `id` will\n * have shared states across components.\n */\n id?: string;\n\n /**\n * HTTP headers to be sent with the API request.\n */\n headers?: Record<string, string> | Headers;\n /**\n * System messages of the chat. Defaults to an empty array.\n */\n initialMessages?: Message[];\n\n /**\n * A function to generate the system message. Defaults to `defaultSystemMessage`.\n */\n makeSystemMessage?: SystemMessageFunction;\n}\n\nexport interface UseCopilotChatReturn {\n visibleMessages: Message[];\n appendMessage: (message: Message) => Promise<void>;\n setMessages: (messages: Message[]) => void;\n deleteMessage: (messageId: string) => void;\n reloadMessages: () => Promise<void>;\n stopGeneration: () => void;\n reset: () => void;\n isLoading: boolean;\n runChatCompletion: () => Promise<Message[]>;\n}\n\nexport function useCopilotChat({\n makeSystemMessage,\n ...options\n}: UseCopilotChatOptions = {}): UseCopilotChatReturn {\n const {\n getContextString,\n getFunctionCallHandler,\n copilotApiConfig,\n isLoading,\n setIsLoading,\n chatInstructions,\n actions,\n coagentStatesRef,\n setCoagentStatesWithRef,\n coAgentStateRenders,\n agentSession,\n setAgentSession,\n agentLock,\n threadId,\n setThreadId,\n runId,\n setRunId,\n chatAbortControllerRef,\n } = useCopilotContext();\n const { messages, setMessages } = useCopilotMessagesContext();\n\n // We need to ensure that makeSystemMessageCallback always uses the latest\n // useCopilotReadable data.\n const latestGetContextString = useUpdatedRef(getContextString);\n const deleteMessage = useCallback(\n (messageId: string) => {\n setMessages((prev) => prev.filter((message) => message.id !== messageId));\n },\n [setMessages],\n );\n\n const makeSystemMessageCallback = useCallback(() => {\n const systemMessageMaker = makeSystemMessage || defaultSystemMessage;\n // this always gets the latest context string\n const contextString = latestGetContextString.current([], defaultCopilotContextCategories); // TODO: make the context categories configurable\n\n return new TextMessage({\n content: systemMessageMaker(contextString, chatInstructions),\n role: Role.System,\n });\n }, [getContextString, makeSystemMessage, chatInstructions]);\n\n const onCoAgentStateRender = useAsyncCallback(\n async (args: CoAgentStateRenderHandlerArguments) => {\n const { name, nodeName, state } = args;\n let action = Object.values(coAgentStateRenders).find(\n (action) => action.name === name && action.nodeName === nodeName,\n );\n if (!action) {\n action = Object.values(coAgentStateRenders).find(\n (action) => action.name === name && !action.nodeName,\n );\n }\n if (action) {\n await action.handler?.({ state, nodeName });\n }\n },\n [coAgentStateRenders],\n );\n\n const { append, reload, stop, runChatCompletion } = useChat({\n ...options,\n actions: Object.values(actions),\n copilotConfig: copilotApiConfig,\n initialMessages: options.initialMessages || [],\n onFunctionCall: getFunctionCallHandler(),\n onCoAgentStateRender,\n messages,\n setMessages,\n makeSystemMessageCallback,\n isLoading,\n setIsLoading,\n coagentStatesRef,\n setCoagentStatesWithRef,\n agentSession,\n setAgentSession,\n threadId,\n setThreadId,\n runId,\n setRunId,\n chatAbortControllerRef,\n });\n\n // this is a workaround born out of a bug that Athena incessantly ran into.\n // We could not find the origin of the bug, however, it was clear that an outdated version of the append function was being used somehow --\n // it referenced the old state of the messages array, and not the latest one.\n //\n // We want to make copilotkit as abuse-proof as possible, so we are adding this workaround to ensure that the latest version of the append function is always used.\n //\n // How does this work?\n // we store the relevant function in a ref that is always up-to-date, and then we use that ref in the callback.\n const latestAppend = useUpdatedRef(append);\n const latestAppendFunc = useAsyncCallback(\n async (message: Message) => {\n return await latestAppend.current(message);\n },\n [latestAppend],\n );\n\n const latestReload = useUpdatedRef(reload);\n const latestReloadFunc = useAsyncCallback(async () => {\n return await latestReload.current();\n }, [latestReload]);\n\n const latestStop = useUpdatedRef(stop);\n const latestStopFunc = useCallback(() => {\n return latestStop.current();\n }, [latestStop]);\n\n const latestDelete = useUpdatedRef(deleteMessage);\n const latestDeleteFunc = useCallback(\n (messageId: string) => {\n return latestDelete.current(messageId);\n },\n [latestDelete],\n );\n\n const latestSetMessages = useUpdatedRef(setMessages);\n const latestSetMessagesFunc = useCallback(\n (messages: Message[]) => {\n return latestSetMessages.current(messages);\n },\n [latestSetMessages],\n );\n\n const latestRunChatCompletion = useUpdatedRef(runChatCompletion);\n const latestRunChatCompletionFunc = useAsyncCallback(async () => {\n return await latestRunChatCompletion.current!();\n }, [latestRunChatCompletion]);\n\n const reset = useCallback(() => {\n latestStopFunc();\n setMessages([]);\n setThreadId(null);\n setRunId(null);\n setCoagentStatesWithRef({});\n let initialAgentSession: AgentSession | null = null;\n if (agentLock) {\n initialAgentSession = {\n agentName: agentLock,\n };\n }\n setAgentSession(initialAgentSession);\n }, [\n latestStopFunc,\n setMessages,\n setThreadId,\n setCoagentStatesWithRef,\n setAgentSession,\n agentLock,\n ]);\n\n const latestReset = useUpdatedRef(reset);\n const latestResetFunc = useCallback(() => {\n return latestReset.current();\n }, [latestReset]);\n\n return {\n visibleMessages: messages,\n appendMessage: latestAppendFunc,\n setMessages: latestSetMessagesFunc,\n reloadMessages: latestReloadFunc,\n stopGeneration: latestStopFunc,\n reset: latestResetFunc,\n deleteMessage: latestDeleteFunc,\n runChatCompletion: latestRunChatCompletionFunc,\n isLoading,\n };\n}\n\n// store `value` in a ref and update\n// it whenever it changes.\nfunction useUpdatedRef<T>(value: T) {\n const ref = useRef(value);\n\n useEffect(() => {\n ref.current = value;\n }, [value]);\n\n return ref;\n}\n\nexport function defaultSystemMessage(\n contextString: string,\n additionalInstructions?: string,\n): string {\n return (\n `\nPlease act as an efficient, competent, conscientious, and industrious professional assistant.\n\nHelp the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.\nAlways be polite and respectful, and prefer brevity over verbosity.\n\nThe user has provided you with the following context:\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n\nThey have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information.\n\nPlease assist them as best you can.\n\nYou can ask them for clarifying questions if needed, but don't be annoying about it. If you can reasonably 'fill in the blanks' yourself, do so.\n\nIf you would like to call a function, call it without saying anything else.\n` + (additionalInstructions ? `\\n\\n${additionalInstructions}` : \"\")\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAwCA,SAAS,QAAQ,WAAW,mBAAmB;AAE/C,SAAkB,MAAM,mBAAmB;AA4CpC,SAAS,eAAe,KAGJ,CAAC,GAAyB;AAHtB,eAC7B;AAAA;AAAA,EAvFF,IAsF+B,IAE1B,oBAF0B,IAE1B;AAAA,IADH;AAAA;AAGA,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,kBAAkB;AACtB,QAAM,EAAE,UAAU,YAAY,IAAI,0BAA0B;AAI5D,QAAM,yBAAyB,cAAc,gBAAgB;AAC7D,QAAM,gBAAgB;AAAA,IACpB,CAAC,cAAsB;AACrB,kBAAY,CAAC,SAAS,KAAK,OAAO,CAAC,YAAY,QAAQ,OAAO,SAAS,CAAC;AAAA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