@copilotkit/react-core 0.0.0-feat-dynamic-copilotcloud-qa-20250117190454

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 (293) hide show
  1. package/CHANGELOG.md +2001 -0
  2. package/README.md +48 -0
  3. package/dist/chunk-22XKTBPF.mjs +61 -0
  4. package/dist/chunk-22XKTBPF.mjs.map +1 -0
  5. package/dist/chunk-2KT73RVG.mjs +482 -0
  6. package/dist/chunk-2KT73RVG.mjs.map +1 -0
  7. package/dist/chunk-4TDYSNUD.mjs +215 -0
  8. package/dist/chunk-4TDYSNUD.mjs.map +1 -0
  9. package/dist/chunk-5FHSUKQL.mjs +70 -0
  10. package/dist/chunk-5FHSUKQL.mjs.map +1 -0
  11. package/dist/chunk-6BQVZFNO.mjs +35 -0
  12. package/dist/chunk-6BQVZFNO.mjs.map +1 -0
  13. package/dist/chunk-6U3UH3KO.mjs +140 -0
  14. package/dist/chunk-6U3UH3KO.mjs.map +1 -0
  15. package/dist/chunk-DCTJZ742.mjs +22 -0
  16. package/dist/chunk-DCTJZ742.mjs.map +1 -0
  17. package/dist/chunk-EFZPSZWO.mjs +1 -0
  18. package/dist/chunk-EFZPSZWO.mjs.map +1 -0
  19. package/dist/chunk-EWKJMQOF.mjs +107 -0
  20. package/dist/chunk-EWKJMQOF.mjs.map +1 -0
  21. package/dist/chunk-FQ53HQYZ.mjs +28 -0
  22. package/dist/chunk-FQ53HQYZ.mjs.map +1 -0
  23. package/dist/chunk-HIUT2NLX.mjs +23 -0
  24. package/dist/chunk-HIUT2NLX.mjs.map +1 -0
  25. package/dist/chunk-KSPLXKSX.mjs +160 -0
  26. package/dist/chunk-KSPLXKSX.mjs.map +1 -0
  27. package/dist/chunk-LHKIIAUQ.mjs +59 -0
  28. package/dist/chunk-LHKIIAUQ.mjs.map +1 -0
  29. package/dist/chunk-LNI2Z45S.mjs +242 -0
  30. package/dist/chunk-LNI2Z45S.mjs.map +1 -0
  31. package/dist/chunk-LUGEI4YQ.mjs +1 -0
  32. package/dist/chunk-LUGEI4YQ.mjs.map +1 -0
  33. package/dist/chunk-MLAS4QUR.mjs +18 -0
  34. package/dist/chunk-MLAS4QUR.mjs.map +1 -0
  35. package/dist/chunk-NR2BTA6Z.mjs +1 -0
  36. package/dist/chunk-NR2BTA6Z.mjs.map +1 -0
  37. package/dist/chunk-O7ARI5CV.mjs +31 -0
  38. package/dist/chunk-O7ARI5CV.mjs.map +1 -0
  39. package/dist/chunk-SKC7AJIV.mjs +61 -0
  40. package/dist/chunk-SKC7AJIV.mjs.map +1 -0
  41. package/dist/chunk-U6JICUGO.mjs +405 -0
  42. package/dist/chunk-U6JICUGO.mjs.map +1 -0
  43. package/dist/chunk-VNTDIJSG.mjs +37 -0
  44. package/dist/chunk-VNTDIJSG.mjs.map +1 -0
  45. package/dist/chunk-WXREY7UP.mjs +87 -0
  46. package/dist/chunk-WXREY7UP.mjs.map +1 -0
  47. package/dist/chunk-XERJQUHA.mjs +31 -0
  48. package/dist/chunk-XERJQUHA.mjs.map +1 -0
  49. package/dist/chunk-XOQMISG3.mjs +120 -0
  50. package/dist/chunk-XOQMISG3.mjs.map +1 -0
  51. package/dist/chunk-XXR4QFAQ.mjs +29 -0
  52. package/dist/chunk-XXR4QFAQ.mjs.map +1 -0
  53. package/dist/chunk-YPSGKPDA.mjs +1 -0
  54. package/dist/chunk-YPSGKPDA.mjs.map +1 -0
  55. package/dist/components/copilot-provider/copilot-messages.d.ts +16 -0
  56. package/dist/components/copilot-provider/copilot-messages.js +80 -0
  57. package/dist/components/copilot-provider/copilot-messages.js.map +1 -0
  58. package/dist/components/copilot-provider/copilot-messages.mjs +9 -0
  59. package/dist/components/copilot-provider/copilot-messages.mjs.map +1 -0
  60. package/dist/components/copilot-provider/copilotkit-props.d.ts +93 -0
  61. package/dist/components/copilot-provider/copilotkit-props.js +19 -0
  62. package/dist/components/copilot-provider/copilotkit-props.js.map +1 -0
  63. package/dist/components/copilot-provider/copilotkit-props.mjs +1 -0
  64. package/dist/components/copilot-provider/copilotkit-props.mjs.map +1 -0
  65. package/dist/components/copilot-provider/copilotkit.d.ts +18 -0
  66. package/dist/components/copilot-provider/copilotkit.js +990 -0
  67. package/dist/components/copilot-provider/copilotkit.js.map +1 -0
  68. package/dist/components/copilot-provider/copilotkit.mjs +22 -0
  69. package/dist/components/copilot-provider/copilotkit.mjs.map +1 -0
  70. package/dist/components/copilot-provider/index.d.ts +13 -0
  71. package/dist/components/copilot-provider/index.js +990 -0
  72. package/dist/components/copilot-provider/index.js.map +1 -0
  73. package/dist/components/copilot-provider/index.mjs +20 -0
  74. package/dist/components/copilot-provider/index.mjs.map +1 -0
  75. package/dist/components/error-boundary/error-boundary.d.ts +22 -0
  76. package/dist/components/error-boundary/error-boundary.js +183 -0
  77. package/dist/components/error-boundary/error-boundary.js.map +1 -0
  78. package/dist/components/error-boundary/error-boundary.mjs +12 -0
  79. package/dist/components/error-boundary/error-boundary.mjs.map +1 -0
  80. package/dist/components/error-boundary/error-utils.d.ts +11 -0
  81. package/dist/components/error-boundary/error-utils.js +177 -0
  82. package/dist/components/error-boundary/error-utils.js.map +1 -0
  83. package/dist/components/error-boundary/error-utils.mjs +13 -0
  84. package/dist/components/error-boundary/error-utils.mjs.map +1 -0
  85. package/dist/components/index.d.ts +13 -0
  86. package/dist/components/index.js +990 -0
  87. package/dist/components/index.js.map +1 -0
  88. package/dist/components/index.mjs +20 -0
  89. package/dist/components/index.mjs.map +1 -0
  90. package/dist/components/toast/exclamation-mark-icon.d.ts +9 -0
  91. package/dist/components/toast/exclamation-mark-icon.js +55 -0
  92. package/dist/components/toast/exclamation-mark-icon.js.map +1 -0
  93. package/dist/components/toast/exclamation-mark-icon.mjs +8 -0
  94. package/dist/components/toast/exclamation-mark-icon.mjs.map +1 -0
  95. package/dist/components/toast/toast-provider.d.ts +30 -0
  96. package/dist/components/toast/toast-provider.js +269 -0
  97. package/dist/components/toast/toast-provider.js.map +1 -0
  98. package/dist/components/toast/toast-provider.mjs +11 -0
  99. package/dist/components/toast/toast-provider.mjs.map +1 -0
  100. package/dist/context/copilot-context.d.ts +142 -0
  101. package/dist/context/copilot-context.js +138 -0
  102. package/dist/context/copilot-context.js.map +1 -0
  103. package/dist/context/copilot-context.mjs +10 -0
  104. package/dist/context/copilot-context.mjs.map +1 -0
  105. package/dist/context/copilot-messages-context.d.ts +15 -0
  106. package/dist/context/copilot-messages-context.js +57 -0
  107. package/dist/context/copilot-messages-context.js.map +1 -0
  108. package/dist/context/copilot-messages-context.mjs +10 -0
  109. package/dist/context/copilot-messages-context.mjs.map +1 -0
  110. package/dist/context/index.d.ts +11 -0
  111. package/dist/context/index.js +161 -0
  112. package/dist/context/index.js.map +1 -0
  113. package/dist/context/index.mjs +17 -0
  114. package/dist/context/index.mjs.map +1 -0
  115. package/dist/hooks/index.d.ts +21 -0
  116. package/dist/hooks/index.js +1307 -0
  117. package/dist/hooks/index.js.map +1 -0
  118. package/dist/hooks/index.mjs +56 -0
  119. package/dist/hooks/index.mjs.map +1 -0
  120. package/dist/hooks/use-chat.d.ts +130 -0
  121. package/dist/hooks/use-chat.js +612 -0
  122. package/dist/hooks/use-chat.js.map +1 -0
  123. package/dist/hooks/use-chat.mjs +12 -0
  124. package/dist/hooks/use-chat.mjs.map +1 -0
  125. package/dist/hooks/use-coagent-state-render.d.ts +60 -0
  126. package/dist/hooks/use-coagent-state-render.js +195 -0
  127. package/dist/hooks/use-coagent-state-render.js.map +1 -0
  128. package/dist/hooks/use-coagent-state-render.mjs +11 -0
  129. package/dist/hooks/use-coagent-state-render.mjs.map +1 -0
  130. package/dist/hooks/use-coagent.d.ts +199 -0
  131. package/dist/hooks/use-coagent.js +1068 -0
  132. package/dist/hooks/use-coagent.js.map +1 -0
  133. package/dist/hooks/use-coagent.mjs +29 -0
  134. package/dist/hooks/use-coagent.mjs.map +1 -0
  135. package/dist/hooks/use-copilot-action.d.ts +140 -0
  136. package/dist/hooks/use-copilot-action.js +369 -0
  137. package/dist/hooks/use-copilot-action.js.map +1 -0
  138. package/dist/hooks/use-copilot-action.mjs +11 -0
  139. package/dist/hooks/use-copilot-action.mjs.map +1 -0
  140. package/dist/hooks/use-copilot-authenticated-action.d.ts +8 -0
  141. package/dist/hooks/use-copilot-authenticated-action.js +418 -0
  142. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -0
  143. package/dist/hooks/use-copilot-authenticated-action.mjs +12 -0
  144. package/dist/hooks/use-copilot-authenticated-action.mjs.map +1 -0
  145. package/dist/hooks/use-copilot-chat.d.ts +48 -0
  146. package/dist/hooks/use-copilot-chat.js +932 -0
  147. package/dist/hooks/use-copilot-chat.js.map +1 -0
  148. package/dist/hooks/use-copilot-chat.mjs +24 -0
  149. package/dist/hooks/use-copilot-chat.mjs.map +1 -0
  150. package/dist/hooks/use-copilot-readable.d.ts +33 -0
  151. package/dist/hooks/use-copilot-readable.js +158 -0
  152. package/dist/hooks/use-copilot-readable.js.map +1 -0
  153. package/dist/hooks/use-copilot-readable.mjs +9 -0
  154. package/dist/hooks/use-copilot-readable.mjs.map +1 -0
  155. package/dist/hooks/use-copilot-runtime-client.d.ts +5 -0
  156. package/dist/hooks/use-copilot-runtime-client.js +182 -0
  157. package/dist/hooks/use-copilot-runtime-client.js.map +1 -0
  158. package/dist/hooks/use-copilot-runtime-client.mjs +10 -0
  159. package/dist/hooks/use-copilot-runtime-client.mjs.map +1 -0
  160. package/dist/hooks/use-flat-category-store.d.ts +9 -0
  161. package/dist/hooks/use-flat-category-store.js +90 -0
  162. package/dist/hooks/use-flat-category-store.js.map +1 -0
  163. package/dist/hooks/use-flat-category-store.mjs +8 -0
  164. package/dist/hooks/use-flat-category-store.mjs.map +1 -0
  165. package/dist/hooks/use-make-copilot-document-readable.d.ts +12 -0
  166. package/dist/hooks/use-make-copilot-document-readable.js +153 -0
  167. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -0
  168. package/dist/hooks/use-make-copilot-document-readable.mjs +9 -0
  169. package/dist/hooks/use-make-copilot-document-readable.mjs.map +1 -0
  170. package/dist/hooks/use-tree.d.ts +18 -0
  171. package/dist/hooks/use-tree.js +172 -0
  172. package/dist/hooks/use-tree.js.map +1 -0
  173. package/dist/hooks/use-tree.mjs +8 -0
  174. package/dist/hooks/use-tree.mjs.map +1 -0
  175. package/dist/index.d.ts +27 -0
  176. package/dist/index.js +2228 -0
  177. package/dist/index.js.map +1 -0
  178. package/dist/index.mjs +83 -0
  179. package/dist/index.mjs.map +1 -0
  180. package/dist/lib/copilot-task.d.ts +97 -0
  181. package/dist/lib/copilot-task.js +195 -0
  182. package/dist/lib/copilot-task.js.map +1 -0
  183. package/dist/lib/copilot-task.mjs +20 -0
  184. package/dist/lib/copilot-task.mjs.map +1 -0
  185. package/dist/lib/index.d.ts +11 -0
  186. package/dist/lib/index.js +197 -0
  187. package/dist/lib/index.js.map +1 -0
  188. package/dist/lib/index.mjs +21 -0
  189. package/dist/lib/index.mjs.map +1 -0
  190. package/dist/types/chat-suggestion-configuration.d.ts +22 -0
  191. package/dist/types/chat-suggestion-configuration.js +19 -0
  192. package/dist/types/chat-suggestion-configuration.js.map +1 -0
  193. package/dist/types/chat-suggestion-configuration.mjs +1 -0
  194. package/dist/types/chat-suggestion-configuration.mjs.map +1 -0
  195. package/dist/types/coagent-action.d.ts +29 -0
  196. package/dist/types/coagent-action.js +19 -0
  197. package/dist/types/coagent-action.js.map +1 -0
  198. package/dist/types/coagent-action.mjs +1 -0
  199. package/dist/types/coagent-action.mjs.map +1 -0
  200. package/dist/types/coagent-state.d.ts +11 -0
  201. package/dist/types/coagent-state.js +19 -0
  202. package/dist/types/coagent-state.js.map +1 -0
  203. package/dist/types/coagent-state.mjs +1 -0
  204. package/dist/types/coagent-state.mjs.map +1 -0
  205. package/dist/types/document-pointer.d.ts +9 -0
  206. package/dist/types/document-pointer.js +19 -0
  207. package/dist/types/document-pointer.js.map +1 -0
  208. package/dist/types/document-pointer.mjs +1 -0
  209. package/dist/types/document-pointer.mjs.map +1 -0
  210. package/dist/types/frontend-action.d.ts +126 -0
  211. package/dist/types/frontend-action.js +53 -0
  212. package/dist/types/frontend-action.js.map +1 -0
  213. package/dist/types/frontend-action.mjs +8 -0
  214. package/dist/types/frontend-action.mjs.map +1 -0
  215. package/dist/types/index.d.ts +7 -0
  216. package/dist/types/index.js +19 -0
  217. package/dist/types/index.js.map +1 -0
  218. package/dist/types/index.mjs +2 -0
  219. package/dist/types/index.mjs.map +1 -0
  220. package/dist/types/system-message.d.ts +3 -0
  221. package/dist/types/system-message.js +19 -0
  222. package/dist/types/system-message.js.map +1 -0
  223. package/dist/types/system-message.mjs +1 -0
  224. package/dist/types/system-message.mjs.map +1 -0
  225. package/dist/utils/dev-console.d.ts +3 -0
  226. package/dist/utils/dev-console.js +42 -0
  227. package/dist/utils/dev-console.js.map +1 -0
  228. package/dist/utils/dev-console.mjs +8 -0
  229. package/dist/utils/dev-console.mjs.map +1 -0
  230. package/dist/utils/extract.d.ts +43 -0
  231. package/dist/utils/extract.js +208 -0
  232. package/dist/utils/extract.js.map +1 -0
  233. package/dist/utils/extract.mjs +18 -0
  234. package/dist/utils/extract.mjs.map +1 -0
  235. package/dist/utils/index.d.ts +13 -0
  236. package/dist/utils/index.js +226 -0
  237. package/dist/utils/index.js.map +1 -0
  238. package/dist/utils/index.mjs +21 -0
  239. package/dist/utils/index.mjs.map +1 -0
  240. package/dist/utils/utils.d.ts +2 -0
  241. package/dist/utils/utils.js +19 -0
  242. package/dist/utils/utils.js.map +1 -0
  243. package/dist/utils/utils.mjs +1 -0
  244. package/dist/utils/utils.mjs.map +1 -0
  245. package/dist/utils/utils.test.d.ts +2 -0
  246. package/dist/utils/utils.test.js +9 -0
  247. package/dist/utils/utils.test.js.map +1 -0
  248. package/dist/utils/utils.test.mjs +7 -0
  249. package/dist/utils/utils.test.mjs.map +1 -0
  250. package/jest.config.js +5 -0
  251. package/package.json +69 -0
  252. package/src/components/copilot-provider/copilot-messages.tsx +23 -0
  253. package/src/components/copilot-provider/copilotkit-props.tsx +97 -0
  254. package/src/components/copilot-provider/copilotkit.tsx +401 -0
  255. package/src/components/copilot-provider/index.ts +3 -0
  256. package/src/components/error-boundary/error-boundary.tsx +42 -0
  257. package/src/components/error-boundary/error-utils.tsx +95 -0
  258. package/src/components/index.ts +1 -0
  259. package/src/components/toast/exclamation-mark-icon.tsx +27 -0
  260. package/src/components/toast/toast-provider.tsx +170 -0
  261. package/src/context/copilot-context.tsx +271 -0
  262. package/src/context/copilot-messages-context.tsx +29 -0
  263. package/src/context/index.ts +8 -0
  264. package/src/hooks/index.ts +12 -0
  265. package/src/hooks/use-chat.ts +649 -0
  266. package/src/hooks/use-coagent-state-render.ts +118 -0
  267. package/src/hooks/use-coagent.ts +368 -0
  268. package/src/hooks/use-copilot-action.ts +289 -0
  269. package/src/hooks/use-copilot-authenticated-action.ts +60 -0
  270. package/src/hooks/use-copilot-chat.ts +304 -0
  271. package/src/hooks/use-copilot-readable.ts +123 -0
  272. package/src/hooks/use-copilot-runtime-client.ts +28 -0
  273. package/src/hooks/use-flat-category-store.ts +104 -0
  274. package/src/hooks/use-make-copilot-document-readable.ts +30 -0
  275. package/src/hooks/use-tree.ts +202 -0
  276. package/src/index.tsx +7 -0
  277. package/src/lib/copilot-task.ts +201 -0
  278. package/src/lib/index.ts +1 -0
  279. package/src/types/chat-suggestion-configuration.ts +23 -0
  280. package/src/types/coagent-action.ts +31 -0
  281. package/src/types/coagent-state.ts +9 -0
  282. package/src/types/document-pointer.ts +7 -0
  283. package/src/types/frontend-action.ts +199 -0
  284. package/src/types/index.ts +8 -0
  285. package/src/types/system-message.ts +4 -0
  286. package/src/utils/dev-console.ts +18 -0
  287. package/src/utils/extract.ts +215 -0
  288. package/src/utils/index.ts +2 -0
  289. package/src/utils/utils.test.ts +7 -0
  290. package/src/utils/utils.ts +1 -0
  291. package/tsconfig.json +12 -0
  292. package/tsup.config.ts +16 -0
  293. package/typedoc.json +4 -0
@@ -0,0 +1,7 @@
1
+ // src/utils/utils.test.ts
2
+ describe("emptyTest", () => {
3
+ it("should be truthy", () => {
4
+ expect(true).toBeTruthy();
5
+ });
6
+ });
7
+ //# sourceMappingURL=utils.test.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/utils.test.ts"],"sourcesContent":["import * as utils from \"./utils\";\n\ndescribe(\"emptyTest\", () => {\n it(\"should be truthy\", () => {\n expect(true).toBeTruthy();\n });\n});\n"],"mappings":";AAEA,SAAS,aAAa,MAAM;AAC1B,KAAG,oBAAoB,MAAM;AAC3B,WAAO,IAAI,EAAE,WAAW;AAAA,EAC1B,CAAC;AACH,CAAC;","names":[]}
package/jest.config.js ADDED
@@ -0,0 +1,5 @@
1
+ /** @type {import('ts-jest').JestConfigWithTsJest} */
2
+ module.exports = {
3
+ preset: 'ts-jest',
4
+ testEnvironment: 'node',
5
+ };
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@copilotkit/react-core",
3
+ "private": false,
4
+ "homepage": "https://github.com/CopilotKit/CopilotKit",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/CopilotKit/CopilotKit.git"
8
+ },
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "version": "0.0.0-feat-dynamic-copilotcloud-qa-20250117190454",
13
+ "sideEffects": false,
14
+ "main": "./dist/index.js",
15
+ "module": "./dist/index.mjs",
16
+ "exports": {
17
+ ".": {
18
+ "import": "./dist/index.mjs",
19
+ "require": "./dist/index.js",
20
+ "types": "./dist/index.d.ts"
21
+ }
22
+ },
23
+ "types": "./dist/index.d.ts",
24
+ "license": "MIT",
25
+ "peerDependencies": {
26
+ "react": "^18 || ^19 || ^19.0.0-rc",
27
+ "react-dom": "^18 || ^19 || ^19.0.0-rc"
28
+ },
29
+ "devDependencies": {
30
+ "@types/jest": "^29.5.4",
31
+ "@types/react": "^18.2.5",
32
+ "eslint": "^8.56.0",
33
+ "jest": "^29.6.4",
34
+ "react": "^18.2.0",
35
+ "ts-jest": "^29.1.1",
36
+ "tsup": "^6.7.0",
37
+ "typescript": "^5.2.3",
38
+ "@types/react-dom": "^18.2.4",
39
+ "eslint-config-custom": "1.4.6",
40
+ "tsconfig": "1.4.6"
41
+ },
42
+ "dependencies": {
43
+ "@scarf/scarf": "^1.3.0",
44
+ "untruncate-json": "^0.0.1",
45
+ "@copilotkit/runtime-client-gql": "0.0.0-feat-dynamic-copilotcloud-qa-20250117190454",
46
+ "@copilotkit/shared": "0.0.0-feat-dynamic-copilotcloud-qa-20250117190454"
47
+ },
48
+ "keywords": [
49
+ "copilotkit",
50
+ "copilot",
51
+ "react",
52
+ "nextjs",
53
+ "nodejs",
54
+ "ai",
55
+ "assistant",
56
+ "javascript",
57
+ "automation",
58
+ "textarea"
59
+ ],
60
+ "scripts": {
61
+ "build": "tsup --clean",
62
+ "dev": "tsup --watch",
63
+ "test": "jest",
64
+ "check-types": "tsc --noEmit",
65
+ "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist && rm -rf .next",
66
+ "link:global": "pnpm link --global",
67
+ "unlink:global": "pnpm unlink --global"
68
+ }
69
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * An internal context to separate the messages state (which is constantly changing) from the rest of CopilotKit context
3
+ */
4
+
5
+ import { useState } from "react";
6
+ import { CopilotMessagesContext } from "../../context/copilot-messages-context";
7
+ import { Message } from "@copilotkit/runtime-client-gql";
8
+ import { CopilotKitProps } from "./copilotkit-props";
9
+
10
+ export function CopilotMessages({ children, ...props }: CopilotKitProps) {
11
+ const [messages, setMessages] = useState<Message[]>([]);
12
+
13
+ return (
14
+ <CopilotMessagesContext.Provider
15
+ value={{
16
+ messages,
17
+ setMessages,
18
+ }}
19
+ >
20
+ {children}
21
+ </CopilotMessagesContext.Provider>
22
+ );
23
+ }
@@ -0,0 +1,97 @@
1
+ import { ForwardedParametersInput } from "@copilotkit/runtime-client-gql";
2
+ import { ReactNode } from "react";
3
+ import { AuthState } from "../../context/copilot-context";
4
+
5
+ /**
6
+ * Props for CopilotKit.
7
+ */
8
+
9
+ export interface CopilotKitProps {
10
+ /**
11
+ * Your Copilot Cloud API key. Don't have it yet? Go to https://cloud.copilotkit.ai and get one for free.
12
+ */
13
+ publicApiKey?: string;
14
+
15
+ /**
16
+ * Restrict input to a specific topic.
17
+ */
18
+ cloudRestrictToTopic?: {
19
+ validTopics?: string[];
20
+ invalidTopics?: string[];
21
+ };
22
+
23
+ /**
24
+ * The endpoint for the Copilot Runtime instance. [Click here for more information](/concepts/copilot-runtime).
25
+ */
26
+ runtimeUrl?: string;
27
+
28
+ /**
29
+ * The endpoint for the Copilot transcribe audio service.
30
+ */
31
+ transcribeAudioUrl?: string;
32
+
33
+ /**
34
+ * The endpoint for the Copilot text to speech service.
35
+ */
36
+ textToSpeechUrl?: string;
37
+
38
+ /**
39
+ * Additional headers to be sent with the request.
40
+ *
41
+ * For example:
42
+ * ```json
43
+ * {
44
+ * "Authorization": "Bearer X"
45
+ * }
46
+ * ```
47
+ */
48
+ headers?: Record<string, string>;
49
+
50
+ /**
51
+ * The children to be rendered within the CopilotKit.
52
+ */
53
+ children: ReactNode;
54
+
55
+ /**
56
+ * Custom properties to be sent with the request
57
+ * For example:
58
+ * ```js
59
+ * {
60
+ * 'user_id': 'users_id',
61
+ * }
62
+ * ```
63
+ */
64
+ properties?: Record<string, any>;
65
+
66
+ /**
67
+ * Indicates whether the user agent should send or receive cookies from the other domain
68
+ * in the case of cross-origin requests.
69
+ */
70
+ credentials?: RequestCredentials;
71
+
72
+ /**
73
+ * Whether to show the dev console.
74
+ *
75
+ * If set to "auto", the dev console will be show on localhost only.
76
+ */
77
+ showDevConsole?: boolean | "auto";
78
+
79
+ /**
80
+ * The name of the agent to use.
81
+ */
82
+ agent?: string;
83
+
84
+ /**
85
+ * The forwarded parameters to use for the task.
86
+ */
87
+ forwardedParameters?: Pick<ForwardedParametersInput, "temperature">;
88
+
89
+ /**
90
+ * The auth config to use for the CopilotKit.
91
+ */
92
+ authConfig?: {
93
+ SignInComponent: React.ComponentType<{
94
+ onSignInComplete: (authState: AuthState) => void;
95
+ }>;
96
+ };
97
+ }
@@ -0,0 +1,401 @@
1
+ /**
2
+ * This component will typically wrap your entire application (or a sub-tree of your application where you want to have a copilot). It provides the copilot context to all other components and hooks.
3
+ *
4
+ * ## Example
5
+ *
6
+ * You can find more information about self-hosting CopilotKit [here](/guides/self-hosting).
7
+ *
8
+ * ```tsx
9
+ * import { CopilotKit } from "@copilotkit/react-core";
10
+ *
11
+ * <CopilotKit runtimeUrl="<your-runtime-url>">
12
+ * // ... your app ...
13
+ * </CopilotKit>
14
+ * ```
15
+ */
16
+
17
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
18
+ import {
19
+ CopilotContext,
20
+ CopilotApiConfig,
21
+ ChatComponentsCache,
22
+ AgentSession,
23
+ AuthState,
24
+ } from "../../context/copilot-context";
25
+ import useTree from "../../hooks/use-tree";
26
+ import { CopilotChatSuggestionConfiguration, DocumentPointer } from "../../types";
27
+ import { flushSync } from "react-dom";
28
+ import {
29
+ COPILOT_CLOUD_CHAT_URL,
30
+ CopilotCloudConfig,
31
+ FunctionCallHandler,
32
+ COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,
33
+ } from "@copilotkit/shared";
34
+
35
+ import { FrontendAction } from "../../types/frontend-action";
36
+ import useFlatCategoryStore from "../../hooks/use-flat-category-store";
37
+ import { CopilotKitProps } from "./copilotkit-props";
38
+ import { CoAgentStateRender } from "../../types/coagent-action";
39
+ import { CoagentState } from "../../types/coagent-state";
40
+ import { CopilotMessages } from "./copilot-messages";
41
+ import { ToastProvider } from "../toast/toast-provider";
42
+ import { useCopilotRuntimeClient } from "../../hooks/use-copilot-runtime-client";
43
+ import { shouldShowDevConsole } from "../../utils";
44
+ import { CopilotErrorBoundary } from "../error-boundary/error-boundary";
45
+ import { Agent } from "@copilotkit/runtime-client-gql";
46
+
47
+ export function CopilotKit({ children, ...props }: CopilotKitProps) {
48
+ const showDevConsole = props.showDevConsole === undefined ? "auto" : props.showDevConsole;
49
+ const enabled = shouldShowDevConsole(showDevConsole);
50
+ return (
51
+ <ToastProvider enabled={enabled}>
52
+ <CopilotErrorBoundary>
53
+ <CopilotKitInternal {...props}>{children}</CopilotKitInternal>
54
+ </CopilotErrorBoundary>
55
+ </ToastProvider>
56
+ );
57
+ }
58
+
59
+ export function CopilotKitInternal({ children, ...props }: CopilotKitProps) {
60
+ // Compute all the functions and properties that we need to pass
61
+ // to the CopilotContext.
62
+
63
+ if (!props.runtimeUrl && !props.publicApiKey) {
64
+ throw new Error(
65
+ "Please provide either a runtimeUrl or a publicApiKey to the CopilotKit component.",
66
+ );
67
+ }
68
+
69
+ const chatApiEndpoint = props.runtimeUrl || COPILOT_CLOUD_CHAT_URL;
70
+
71
+ const [actions, setActions] = useState<Record<string, FrontendAction<any>>>({});
72
+ const [coAgentStateRenders, setCoAgentStateRenders] = useState<
73
+ Record<string, CoAgentStateRender<any>>
74
+ >({});
75
+ const chatComponentsCache = useRef<ChatComponentsCache>({
76
+ actions: {},
77
+ coAgentStateRenders: {},
78
+ });
79
+ const { addElement, removeElement, printTree } = useTree();
80
+ const [isLoading, setIsLoading] = useState(false);
81
+ const [chatInstructions, setChatInstructions] = useState("");
82
+ const [authStates, setAuthStates] = useState<Record<string, AuthState>>({});
83
+
84
+ const {
85
+ addElement: addDocument,
86
+ removeElement: removeDocument,
87
+ allElements: allDocuments,
88
+ } = useFlatCategoryStore<DocumentPointer>();
89
+
90
+ const setAction = useCallback((id: string, action: FrontendAction<any>) => {
91
+ setActions((prevPoints) => {
92
+ return {
93
+ ...prevPoints,
94
+ [id]: action,
95
+ };
96
+ });
97
+ }, []);
98
+
99
+ const removeAction = useCallback((id: string) => {
100
+ setActions((prevPoints) => {
101
+ const newPoints = { ...prevPoints };
102
+ delete newPoints[id];
103
+ return newPoints;
104
+ });
105
+ }, []);
106
+
107
+ const setCoAgentStateRender = useCallback((id: string, stateRender: CoAgentStateRender<any>) => {
108
+ setCoAgentStateRenders((prevPoints) => {
109
+ return {
110
+ ...prevPoints,
111
+ [id]: stateRender,
112
+ };
113
+ });
114
+ }, []);
115
+
116
+ const removeCoAgentStateRender = useCallback((id: string) => {
117
+ setCoAgentStateRenders((prevPoints) => {
118
+ const newPoints = { ...prevPoints };
119
+ delete newPoints[id];
120
+ return newPoints;
121
+ });
122
+ }, []);
123
+
124
+ const getContextString = useCallback(
125
+ (documents: DocumentPointer[], categories: string[]) => {
126
+ const documentsString = documents
127
+ .map((document) => {
128
+ return `${document.name} (${document.sourceApplication}):\n${document.getContents()}`;
129
+ })
130
+ .join("\n\n");
131
+
132
+ const nonDocumentStrings = printTree(categories);
133
+
134
+ return `${documentsString}\n\n${nonDocumentStrings}`;
135
+ },
136
+ [printTree],
137
+ );
138
+
139
+ const addContext = useCallback(
140
+ (
141
+ context: string,
142
+ parentId?: string,
143
+ categories: string[] = defaultCopilotContextCategories,
144
+ ) => {
145
+ return addElement(context, categories, parentId);
146
+ },
147
+ [addElement],
148
+ );
149
+
150
+ const removeContext = useCallback(
151
+ (id: string) => {
152
+ removeElement(id);
153
+ },
154
+ [removeElement],
155
+ );
156
+
157
+ const getFunctionCallHandler = useCallback(
158
+ (customEntryPoints?: Record<string, FrontendAction<any>>) => {
159
+ return entryPointsToFunctionCallHandler(Object.values(customEntryPoints || actions));
160
+ },
161
+ [actions],
162
+ );
163
+
164
+ const getDocumentsContext = useCallback(
165
+ (categories: string[]) => {
166
+ return allDocuments(categories);
167
+ },
168
+ [allDocuments],
169
+ );
170
+
171
+ const addDocumentContext = useCallback(
172
+ (documentPointer: DocumentPointer, categories: string[] = defaultCopilotContextCategories) => {
173
+ return addDocument(documentPointer, categories);
174
+ },
175
+ [addDocument],
176
+ );
177
+
178
+ const removeDocumentContext = useCallback(
179
+ (documentId: string) => {
180
+ removeDocument(documentId);
181
+ },
182
+ [removeDocument],
183
+ );
184
+
185
+ if (!props.publicApiKey) {
186
+ if (props.cloudRestrictToTopic) {
187
+ throw new Error(
188
+ "To use the cloudRestrictToTopic feature, please sign up at https://copilotkit.ai and provide a publicApiKey.",
189
+ );
190
+ }
191
+ }
192
+
193
+ // get the appropriate CopilotApiConfig from the props
194
+ const copilotApiConfig: CopilotApiConfig = useMemo(() => {
195
+ let cloud: CopilotCloudConfig | undefined = undefined;
196
+ if (props.publicApiKey) {
197
+ cloud = {
198
+ guardrails: {
199
+ input: {
200
+ restrictToTopic: {
201
+ enabled: props.cloudRestrictToTopic ? true : false,
202
+ validTopics: props.cloudRestrictToTopic?.validTopics || [],
203
+ invalidTopics: props.cloudRestrictToTopic?.invalidTopics || [],
204
+ },
205
+ },
206
+ },
207
+ };
208
+ }
209
+
210
+ return {
211
+ publicApiKey: props.publicApiKey,
212
+ ...(cloud ? { cloud } : {}),
213
+ chatApiEndpoint: chatApiEndpoint,
214
+ headers: props.headers || {},
215
+ properties: props.properties || {},
216
+ transcribeAudioUrl: props.transcribeAudioUrl,
217
+ textToSpeechUrl: props.textToSpeechUrl,
218
+ credentials: props.credentials,
219
+ };
220
+ }, [
221
+ props.publicApiKey,
222
+ props.headers,
223
+ props.properties,
224
+ props.transcribeAudioUrl,
225
+ props.textToSpeechUrl,
226
+ props.credentials,
227
+ props.cloudRestrictToTopic,
228
+ ]);
229
+
230
+ const headers = useMemo(() => {
231
+ const authHeaders = Object.values(authStates || {}).reduce((acc, state) => {
232
+ if (state.status === "authenticated" && state.authHeaders) {
233
+ return {
234
+ ...acc,
235
+ ...Object.entries(state.authHeaders).reduce(
236
+ (headers, [key, value]) => ({
237
+ ...headers,
238
+ [key.startsWith("X-Custom-") ? key : `X-Custom-${key}`]: value,
239
+ }),
240
+ {},
241
+ ),
242
+ };
243
+ }
244
+ return acc;
245
+ }, {});
246
+
247
+ return {
248
+ ...(copilotApiConfig.headers || {}),
249
+ ...(copilotApiConfig.publicApiKey
250
+ ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey }
251
+ : {}),
252
+ ...authHeaders,
253
+ };
254
+ }, [copilotApiConfig.headers, copilotApiConfig.publicApiKey, authStates]);
255
+
256
+ const runtimeClient = useCopilotRuntimeClient({
257
+ url: copilotApiConfig.chatApiEndpoint,
258
+ publicApiKey: copilotApiConfig.publicApiKey,
259
+ headers,
260
+ credentials: copilotApiConfig.credentials,
261
+ });
262
+
263
+ const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = useState<{
264
+ [key: string]: CopilotChatSuggestionConfiguration;
265
+ }>({});
266
+
267
+ const addChatSuggestionConfiguration = (
268
+ id: string,
269
+ suggestion: CopilotChatSuggestionConfiguration,
270
+ ) => {
271
+ setChatSuggestionConfiguration((prev) => ({ ...prev, [id]: suggestion }));
272
+ };
273
+
274
+ const removeChatSuggestionConfiguration = (id: string) => {
275
+ setChatSuggestionConfiguration((prev) => {
276
+ const { [id]: _, ...rest } = prev;
277
+ return rest;
278
+ });
279
+ };
280
+
281
+ const [availableAgents, setAvailableAgents] = useState<Agent[]>([]);
282
+ const [coagentStates, setCoagentStates] = useState<Record<string, CoagentState>>({});
283
+ const coagentStatesRef = useRef<Record<string, CoagentState>>({});
284
+ const setCoagentStatesWithRef = useCallback(
285
+ (
286
+ value:
287
+ | Record<string, CoagentState>
288
+ | ((prev: Record<string, CoagentState>) => Record<string, CoagentState>),
289
+ ) => {
290
+ const newValue = typeof value === "function" ? value(coagentStatesRef.current) : value;
291
+ coagentStatesRef.current = newValue;
292
+ setCoagentStates((prev) => {
293
+ return newValue;
294
+ });
295
+ },
296
+ [],
297
+ );
298
+
299
+ useEffect(() => {
300
+ const fetchData = async () => {
301
+ const result = await runtimeClient.availableAgents();
302
+ if (result.data?.availableAgents) {
303
+ setAvailableAgents(result.data.availableAgents.agents);
304
+ }
305
+ };
306
+ void fetchData();
307
+ }, []);
308
+
309
+ let initialAgentSession: AgentSession | null = null;
310
+ if (props.agent) {
311
+ initialAgentSession = {
312
+ agentName: props.agent,
313
+ };
314
+ }
315
+
316
+ const [agentSession, setAgentSession] = useState<AgentSession | null>(initialAgentSession);
317
+ const [threadId, setThreadId] = useState<string | null>(null);
318
+ const [runId, setRunId] = useState<string | null>(null);
319
+
320
+ const chatAbortControllerRef = useRef<AbortController | null>(null);
321
+
322
+ const showDevConsole = props.showDevConsole === undefined ? "auto" : props.showDevConsole;
323
+
324
+ return (
325
+ <CopilotContext.Provider
326
+ value={{
327
+ actions,
328
+ chatComponentsCache,
329
+ getFunctionCallHandler,
330
+ setAction,
331
+ removeAction,
332
+ coAgentStateRenders,
333
+ setCoAgentStateRender,
334
+ removeCoAgentStateRender,
335
+ getContextString,
336
+ addContext,
337
+ removeContext,
338
+ getDocumentsContext,
339
+ addDocumentContext,
340
+ removeDocumentContext,
341
+ copilotApiConfig: copilotApiConfig,
342
+ isLoading,
343
+ setIsLoading,
344
+ chatSuggestionConfiguration,
345
+ addChatSuggestionConfiguration,
346
+ removeChatSuggestionConfiguration,
347
+ chatInstructions,
348
+ setChatInstructions,
349
+ showDevConsole,
350
+ coagentStates,
351
+ setCoagentStates,
352
+ coagentStatesRef,
353
+ setCoagentStatesWithRef,
354
+ agentSession,
355
+ setAgentSession,
356
+ runtimeClient,
357
+ forwardedParameters: props.forwardedParameters || {},
358
+ agentLock: props.agent || null,
359
+ threadId,
360
+ setThreadId,
361
+ runId,
362
+ setRunId,
363
+ chatAbortControllerRef,
364
+ availableAgents,
365
+ authConfig: props.authConfig,
366
+ authStates,
367
+ setAuthStates,
368
+ }}
369
+ >
370
+ <CopilotMessages>{children}</CopilotMessages>
371
+ </CopilotContext.Provider>
372
+ );
373
+ }
374
+
375
+ export const defaultCopilotContextCategories = ["global"];
376
+
377
+ function entryPointsToFunctionCallHandler(actions: FrontendAction<any>[]): FunctionCallHandler {
378
+ return async ({ messages, name, args }) => {
379
+ let actionsByFunctionName: Record<string, FrontendAction<any>> = {};
380
+ for (let action of actions) {
381
+ actionsByFunctionName[action.name] = action;
382
+ }
383
+
384
+ const action = actionsByFunctionName[name];
385
+ let result: any = undefined;
386
+ if (action) {
387
+ await new Promise<void>((resolve, reject) => {
388
+ flushSync(async () => {
389
+ try {
390
+ result = await action.handler?.(args);
391
+ resolve();
392
+ } catch (error) {
393
+ reject(error);
394
+ }
395
+ });
396
+ });
397
+ await new Promise((resolve) => setTimeout(resolve, 20));
398
+ }
399
+ return result;
400
+ };
401
+ }
@@ -0,0 +1,3 @@
1
+ export { CopilotKit, defaultCopilotContextCategories } from "./copilotkit";
2
+
3
+ export type { CopilotKitProps } from "./copilotkit-props";
@@ -0,0 +1,42 @@
1
+ import React, { useEffect } from "react";
2
+ import { useErrorToast } from "./error-utils";
3
+
4
+ interface Props {
5
+ children: React.ReactNode;
6
+ }
7
+
8
+ interface State {
9
+ hasError: boolean;
10
+ error?: Error;
11
+ }
12
+
13
+ export class CopilotErrorBoundary extends React.Component<Props, State> {
14
+ constructor(props: Props) {
15
+ super(props);
16
+ this.state = { hasError: false };
17
+ }
18
+
19
+ static getDerivedStateFromError(error: Error): State {
20
+ return { hasError: true, error };
21
+ }
22
+
23
+ componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
24
+ console.error("CopilotKit Error:", error, errorInfo);
25
+ }
26
+
27
+ render() {
28
+ return <ErrorToast error={this.state.error}>{this.props.children}</ErrorToast>;
29
+ }
30
+ }
31
+
32
+ export function ErrorToast({ error, children }: { error?: Error; children: React.ReactNode }) {
33
+ const addErrorToast = useErrorToast();
34
+
35
+ useEffect(() => {
36
+ if (error) {
37
+ addErrorToast([error]);
38
+ }
39
+ }, [error, addErrorToast]);
40
+
41
+ return children;
42
+ }