@copilotkit/react-core 0.0.0-mme-load-agent-state-20250117154700

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 +2017 -0
  2. package/README.md +48 -0
  3. package/dist/chunk-4IYWTPBR.mjs +61 -0
  4. package/dist/chunk-4IYWTPBR.mjs.map +1 -0
  5. package/dist/chunk-5FHSUKQL.mjs +70 -0
  6. package/dist/chunk-5FHSUKQL.mjs.map +1 -0
  7. package/dist/chunk-6BQVZFNO.mjs +35 -0
  8. package/dist/chunk-6BQVZFNO.mjs.map +1 -0
  9. package/dist/chunk-6U3UH3KO.mjs +140 -0
  10. package/dist/chunk-6U3UH3KO.mjs.map +1 -0
  11. package/dist/chunk-BHRJWCZT.mjs +423 -0
  12. package/dist/chunk-BHRJWCZT.mjs.map +1 -0
  13. package/dist/chunk-DCTJZ742.mjs +22 -0
  14. package/dist/chunk-DCTJZ742.mjs.map +1 -0
  15. package/dist/chunk-EFZPSZWO.mjs +1 -0
  16. package/dist/chunk-EFZPSZWO.mjs.map +1 -0
  17. package/dist/chunk-IFBUUIU7.mjs +53 -0
  18. package/dist/chunk-IFBUUIU7.mjs.map +1 -0
  19. package/dist/chunk-IJJTXITZ.mjs +59 -0
  20. package/dist/chunk-IJJTXITZ.mjs.map +1 -0
  21. package/dist/chunk-IPTELVUL.mjs +221 -0
  22. package/dist/chunk-IPTELVUL.mjs.map +1 -0
  23. package/dist/chunk-J6UBNKIR.mjs +23 -0
  24. package/dist/chunk-J6UBNKIR.mjs.map +1 -0
  25. package/dist/chunk-JFMOYUAX.mjs +120 -0
  26. package/dist/chunk-JFMOYUAX.mjs.map +1 -0
  27. package/dist/chunk-LNI2Z45S.mjs +242 -0
  28. package/dist/chunk-LNI2Z45S.mjs.map +1 -0
  29. package/dist/chunk-LUGEI4YQ.mjs +1 -0
  30. package/dist/chunk-LUGEI4YQ.mjs.map +1 -0
  31. package/dist/chunk-MLAS4QUR.mjs +18 -0
  32. package/dist/chunk-MLAS4QUR.mjs.map +1 -0
  33. package/dist/chunk-N37EFAUX.mjs +28 -0
  34. package/dist/chunk-N37EFAUX.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-U6JOA64X.mjs +107 -0
  42. package/dist/chunk-U6JOA64X.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-VRQFYEQF.mjs +181 -0
  46. package/dist/chunk-VRQFYEQF.mjs.map +1 -0
  47. package/dist/chunk-WZZEEFIX.mjs +500 -0
  48. package/dist/chunk-WZZEEFIX.mjs.map +1 -0
  49. package/dist/chunk-XERJQUHA.mjs +31 -0
  50. package/dist/chunk-XERJQUHA.mjs.map +1 -0
  51. package/dist/chunk-YPSGKPDA.mjs +1 -0
  52. package/dist/chunk-YPSGKPDA.mjs.map +1 -0
  53. package/dist/chunk-YVQNSJ4Z.mjs +90 -0
  54. package/dist/chunk-YVQNSJ4Z.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 +203 -0
  57. package/dist/components/copilot-provider/copilot-messages.js.map +1 -0
  58. package/dist/components/copilot-provider/copilot-messages.mjs +10 -0
  59. package/dist/components/copilot-provider/copilot-messages.mjs.map +1 -0
  60. package/dist/components/copilot-provider/copilotkit-props.d.ts +97 -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 +1037 -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 +1037 -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 +1037 -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 +144 -0
  101. package/dist/context/copilot-context.js +141 -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 +164 -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 +1350 -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 +138 -0
  121. package/dist/hooks/use-chat.js +628 -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 +198 -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 +1111 -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 +372 -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 +421 -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 +957 -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 +161 -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 +156 -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 +2308 -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 +45 -0
  253. package/src/components/copilot-provider/copilotkit-props.tsx +102 -0
  254. package/src/components/copilot-provider/copilotkit.tsx +427 -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 +280 -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 +682 -0
  266. package/src/hooks/use-coagent-state-render.ts +118 -0
  267. package/src/hooks/use-coagent.ts +394 -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 +310 -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,628 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __spreadValues = (a, b) => {
12
+ for (var prop in b || (b = {}))
13
+ if (__hasOwnProp.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
15
+ if (__getOwnPropSymbols)
16
+ for (var prop of __getOwnPropSymbols(b)) {
17
+ if (__propIsEnum.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ }
20
+ return a;
21
+ };
22
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
+ var __export = (target, all) => {
24
+ for (var name in all)
25
+ __defProp(target, name, { get: all[name], enumerable: true });
26
+ };
27
+ var __copyProps = (to, from, except, desc) => {
28
+ if (from && typeof from === "object" || typeof from === "function") {
29
+ for (let key of __getOwnPropNames(from))
30
+ if (!__hasOwnProp.call(to, key) && key !== except)
31
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
32
+ }
33
+ return to;
34
+ };
35
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
+ var __async = (__this, __arguments, generator) => {
37
+ return new Promise((resolve, reject) => {
38
+ var fulfilled = (value) => {
39
+ try {
40
+ step(generator.next(value));
41
+ } catch (e) {
42
+ reject(e);
43
+ }
44
+ };
45
+ var rejected = (value) => {
46
+ try {
47
+ step(generator.throw(value));
48
+ } catch (e) {
49
+ reject(e);
50
+ }
51
+ };
52
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
53
+ step((generator = generator.apply(__this, __arguments)).next());
54
+ });
55
+ };
56
+
57
+ // src/hooks/use-chat.ts
58
+ var use_chat_exports = {};
59
+ __export(use_chat_exports, {
60
+ useChat: () => useChat
61
+ });
62
+ module.exports = __toCommonJS(use_chat_exports);
63
+ var import_react4 = require("react");
64
+ var import_shared2 = require("@copilotkit/shared");
65
+ var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
66
+
67
+ // src/types/frontend-action.ts
68
+ var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
69
+ var import_shared = require("@copilotkit/shared");
70
+ function processActionsForRuntimeRequest(actions) {
71
+ const filteredActions = actions.filter(
72
+ (action) => action.available !== import_runtime_client_gql.ActionInputAvailability.Disabled && action.disabled !== true && action.name !== "*"
73
+ ).map((action) => {
74
+ let available = import_runtime_client_gql.ActionInputAvailability.Enabled;
75
+ if (action.disabled) {
76
+ available = import_runtime_client_gql.ActionInputAvailability.Disabled;
77
+ } else if (action.available === "disabled") {
78
+ available = import_runtime_client_gql.ActionInputAvailability.Disabled;
79
+ } else if (action.available === "remote") {
80
+ available = import_runtime_client_gql.ActionInputAvailability.Remote;
81
+ }
82
+ return {
83
+ name: action.name,
84
+ description: action.description || "",
85
+ jsonSchema: JSON.stringify((0, import_shared.actionParametersToJsonSchema)(action.parameters || [])),
86
+ available
87
+ };
88
+ });
89
+ return filteredActions;
90
+ }
91
+
92
+ // src/hooks/use-copilot-runtime-client.ts
93
+ var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
94
+
95
+ // src/components/toast/toast-provider.tsx
96
+ var import_react2 = require("react");
97
+
98
+ // src/components/error-boundary/error-utils.tsx
99
+ var import_react = require("react");
100
+
101
+ // src/components/toast/exclamation-mark-icon.tsx
102
+ var import_jsx_runtime = require("react/jsx-runtime");
103
+ var ExclamationMarkIcon = ({
104
+ className,
105
+ style
106
+ }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
107
+ "svg",
108
+ {
109
+ xmlns: "http://www.w3.org/2000/svg",
110
+ width: "24",
111
+ height: "24",
112
+ viewBox: "0 0 24 24",
113
+ fill: "none",
114
+ stroke: "currentColor",
115
+ strokeWidth: "2",
116
+ strokeLinecap: "round",
117
+ strokeLinejoin: "round",
118
+ className: `lucide lucide-circle-alert ${className ? className : ""}`,
119
+ style,
120
+ children: [
121
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
122
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "12", x2: "12", y1: "8", y2: "12" }),
123
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "12", x2: "12.01", y1: "16", y2: "16" })
124
+ ]
125
+ }
126
+ );
127
+
128
+ // src/components/error-boundary/error-utils.tsx
129
+ var import_jsx_runtime2 = require("react/jsx-runtime");
130
+ function ErrorToast({ errors }) {
131
+ const errorsToRender = errors.map((error, idx) => {
132
+ var _a, _b, _c;
133
+ const message = "extensions" in error ? (_b = (_a = error.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message : error.message;
134
+ const code = "extensions" in error ? (_c = error.extensions) == null ? void 0 : _c.code : null;
135
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
136
+ "div",
137
+ {
138
+ style: {
139
+ marginTop: idx === 0 ? 0 : 10,
140
+ marginBottom: 14
141
+ },
142
+ children: [
143
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
144
+ code && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
145
+ "div",
146
+ {
147
+ style: {
148
+ fontWeight: "600",
149
+ marginBottom: 4
150
+ },
151
+ children: [
152
+ "Copilot Cloud Error:",
153
+ " ",
154
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
155
+ ]
156
+ }
157
+ ),
158
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { children: message })
159
+ ]
160
+ },
161
+ idx
162
+ );
163
+ });
164
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
165
+ "div",
166
+ {
167
+ style: {
168
+ fontSize: "13px",
169
+ maxWidth: "600px"
170
+ },
171
+ children: [
172
+ errorsToRender,
173
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: { fontSize: "11px", opacity: 0.75 }, children: "NOTE: This error only displays during local development." })
174
+ ]
175
+ }
176
+ );
177
+ }
178
+ function useErrorToast() {
179
+ const { addToast } = useToast();
180
+ return (0, import_react.useCallback)(
181
+ (error) => {
182
+ const errorId = error.map((err) => {
183
+ var _a, _b;
184
+ const message = "extensions" in err ? ((_b = (_a = err.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message) || err.message : err.message;
185
+ const stack = err.stack || "";
186
+ return btoa(message + stack).slice(0, 32);
187
+ }).join("|");
188
+ addToast({
189
+ type: "error",
190
+ id: errorId,
191
+ // Toast libraries typically dedupe by id
192
+ message: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ErrorToast, { errors: error })
193
+ });
194
+ },
195
+ [addToast]
196
+ );
197
+ }
198
+ function useAsyncCallback(callback, deps) {
199
+ const addErrorToast = useErrorToast();
200
+ return (0, import_react.useCallback)((...args) => __async(this, null, function* () {
201
+ try {
202
+ return yield callback(...args);
203
+ } catch (error) {
204
+ console.error("Error in async callback:", error);
205
+ addErrorToast([error]);
206
+ throw error;
207
+ }
208
+ }), deps);
209
+ }
210
+
211
+ // src/components/toast/toast-provider.tsx
212
+ var import_jsx_runtime3 = require("react/jsx-runtime");
213
+ var ToastContext = (0, import_react2.createContext)(void 0);
214
+ function useToast() {
215
+ const context = (0, import_react2.useContext)(ToastContext);
216
+ if (!context) {
217
+ throw new Error("useToast must be used within a ToastProvider");
218
+ }
219
+ return context;
220
+ }
221
+
222
+ // src/hooks/use-copilot-runtime-client.ts
223
+ var import_react3 = require("react");
224
+ var useCopilotRuntimeClient = (options) => {
225
+ const { addGraphQLErrorsToast } = useToast();
226
+ const addErrorToast = useErrorToast();
227
+ const runtimeClient = (0, import_react3.useMemo)(() => {
228
+ return new import_runtime_client_gql2.CopilotRuntimeClient(__spreadProps(__spreadValues({}, options), {
229
+ handleGQLErrors: (error) => {
230
+ if (error.graphQLErrors.length) {
231
+ addGraphQLErrorsToast(error.graphQLErrors);
232
+ } else {
233
+ addErrorToast([error]);
234
+ }
235
+ }
236
+ }));
237
+ }, [options, addGraphQLErrorsToast]);
238
+ return runtimeClient;
239
+ };
240
+
241
+ // src/hooks/use-chat.ts
242
+ function useChat(options) {
243
+ const {
244
+ messages,
245
+ setMessages,
246
+ makeSystemMessageCallback,
247
+ copilotConfig,
248
+ setIsLoading,
249
+ initialMessages,
250
+ isLoading,
251
+ actions,
252
+ onFunctionCall,
253
+ onCoAgentStateRender,
254
+ setCoagentStatesWithRef,
255
+ coagentStatesRef,
256
+ agentSession,
257
+ setAgentSession,
258
+ threadId,
259
+ setThreadId,
260
+ runId,
261
+ setRunId,
262
+ chatAbortControllerRef,
263
+ agentLock,
264
+ extensions,
265
+ setExtensions
266
+ } = options;
267
+ const runChatCompletionRef = (0, import_react4.useRef)();
268
+ const addErrorToast = useErrorToast();
269
+ const agentSessionRef = (0, import_react4.useRef)(agentSession);
270
+ agentSessionRef.current = agentSession;
271
+ const runIdRef = (0, import_react4.useRef)(runId);
272
+ runIdRef.current = runId;
273
+ const extensionsRef = (0, import_react4.useRef)(extensions);
274
+ extensionsRef.current = extensions;
275
+ const publicApiKey = copilotConfig.publicApiKey;
276
+ const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared2.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
277
+ const runtimeClient = useCopilotRuntimeClient({
278
+ url: copilotConfig.chatApiEndpoint,
279
+ publicApiKey: copilotConfig.publicApiKey,
280
+ headers,
281
+ credentials: copilotConfig.credentials
282
+ });
283
+ const runChatCompletion = useAsyncCallback(
284
+ (previousMessages) => __async(this, null, function* () {
285
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
286
+ setIsLoading(true);
287
+ let newMessages = [
288
+ new import_runtime_client_gql3.TextMessage({
289
+ content: "",
290
+ role: import_runtime_client_gql3.Role.Assistant
291
+ })
292
+ ];
293
+ chatAbortControllerRef.current = new AbortController();
294
+ setMessages([...previousMessages, ...newMessages]);
295
+ const systemMessage = makeSystemMessageCallback();
296
+ const messagesWithContext = [systemMessage, ...initialMessages || [], ...previousMessages];
297
+ const isAgentRun = agentSessionRef.current !== null;
298
+ const stream = runtimeClient.asStream(
299
+ runtimeClient.generateCopilotResponse({
300
+ data: __spreadProps(__spreadValues(__spreadProps(__spreadValues({
301
+ frontend: {
302
+ actions: processActionsForRuntimeRequest(actions),
303
+ url: window.location.href
304
+ },
305
+ threadId,
306
+ runId: runIdRef.current,
307
+ extensions: extensionsRef.current,
308
+ messages: (0, import_runtime_client_gql3.convertMessagesToGqlInput)((0, import_runtime_client_gql3.filterAgentStateMessages)(messagesWithContext))
309
+ }, copilotConfig.cloud ? {
310
+ cloud: __spreadValues({}, ((_c = (_b = (_a = copilotConfig.cloud.guardrails) == null ? void 0 : _a.input) == null ? void 0 : _b.restrictToTopic) == null ? void 0 : _c.enabled) ? {
311
+ guardrails: {
312
+ inputValidationRules: {
313
+ allowList: copilotConfig.cloud.guardrails.input.restrictToTopic.validTopics,
314
+ denyList: copilotConfig.cloud.guardrails.input.restrictToTopic.invalidTopics
315
+ }
316
+ }
317
+ } : {})
318
+ } : {}), {
319
+ metadata: {
320
+ requestType: import_runtime_client_gql3.CopilotRequestType.Chat
321
+ }
322
+ }), agentSessionRef.current ? {
323
+ agentSession: agentSessionRef.current
324
+ } : {}), {
325
+ agentStates: Object.values(coagentStatesRef.current).map((state) => ({
326
+ agentName: state.name,
327
+ state: JSON.stringify(state.state)
328
+ })),
329
+ forwardedParameters: options.forwardedParameters || {}
330
+ }),
331
+ properties: copilotConfig.properties,
332
+ signal: (_d = chatAbortControllerRef.current) == null ? void 0 : _d.signal
333
+ })
334
+ );
335
+ const guardrailsEnabled = ((_g = (_f = (_e = copilotConfig.cloud) == null ? void 0 : _e.guardrails) == null ? void 0 : _f.input) == null ? void 0 : _g.restrictToTopic.enabled) || false;
336
+ const reader = stream.getReader();
337
+ let executedCoAgentStateRenders = [];
338
+ let followUp = void 0;
339
+ let messages2 = [];
340
+ let syncedMessages = [];
341
+ try {
342
+ while (true) {
343
+ let done, value;
344
+ try {
345
+ const readResult = yield reader.read();
346
+ done = readResult.done;
347
+ value = readResult.value;
348
+ } catch (readError) {
349
+ break;
350
+ }
351
+ if (done) {
352
+ if (chatAbortControllerRef.current.signal.aborted) {
353
+ return [];
354
+ }
355
+ break;
356
+ }
357
+ if (!(value == null ? void 0 : value.generateCopilotResponse)) {
358
+ continue;
359
+ }
360
+ runIdRef.current = value.generateCopilotResponse.runId || null;
361
+ extensionsRef.current = import_runtime_client_gql3.CopilotRuntimeClient.removeGraphQLTypename(
362
+ value.generateCopilotResponse.extensions || {}
363
+ );
364
+ setRunId(runIdRef.current);
365
+ setExtensions(extensionsRef.current);
366
+ messages2 = (0, import_runtime_client_gql3.convertGqlOutputToMessages)(
367
+ (0, import_runtime_client_gql3.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
368
+ );
369
+ if (messages2.length === 0) {
370
+ continue;
371
+ }
372
+ newMessages = [];
373
+ if (((_h = value.generateCopilotResponse.status) == null ? void 0 : _h.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
374
+ newMessages = [
375
+ new import_runtime_client_gql3.TextMessage({
376
+ role: import_runtime_client_gql3.MessageRole.Assistant,
377
+ content: ((_i = value.generateCopilotResponse.status.details) == null ? void 0 : _i.guardrailsReason) || ""
378
+ })
379
+ ];
380
+ setMessages([...previousMessages, ...newMessages]);
381
+ break;
382
+ } else {
383
+ newMessages = [...messages2];
384
+ for (const message of messages2) {
385
+ if (message.isAgentStateMessage() && !message.active && !executedCoAgentStateRenders.includes(message.id) && onCoAgentStateRender) {
386
+ if (guardrailsEnabled && value.generateCopilotResponse.status === void 0) {
387
+ break;
388
+ }
389
+ yield onCoAgentStateRender({
390
+ name: message.agentName,
391
+ nodeName: message.nodeName,
392
+ state: message.state
393
+ });
394
+ executedCoAgentStateRenders.push(message.id);
395
+ }
396
+ }
397
+ const lastAgentStateMessage = [...messages2].reverse().find((message) => message.isAgentStateMessage());
398
+ if (lastAgentStateMessage) {
399
+ if (lastAgentStateMessage.state.messages && lastAgentStateMessage.state.messages.length > 0) {
400
+ syncedMessages = (0, import_runtime_client_gql3.loadMessagesFromJsonRepresentation)(
401
+ lastAgentStateMessage.state.messages
402
+ );
403
+ }
404
+ setCoagentStatesWithRef((prevAgentStates) => __spreadProps(__spreadValues({}, prevAgentStates), {
405
+ [lastAgentStateMessage.agentName]: {
406
+ name: lastAgentStateMessage.agentName,
407
+ state: lastAgentStateMessage.state,
408
+ running: lastAgentStateMessage.running,
409
+ active: lastAgentStateMessage.active,
410
+ threadId: lastAgentStateMessage.threadId,
411
+ nodeName: lastAgentStateMessage.nodeName,
412
+ runId: lastAgentStateMessage.runId
413
+ }
414
+ }));
415
+ if (lastAgentStateMessage.running) {
416
+ setAgentSession({
417
+ threadId: lastAgentStateMessage.threadId,
418
+ agentName: lastAgentStateMessage.agentName,
419
+ nodeName: lastAgentStateMessage.nodeName
420
+ });
421
+ } else {
422
+ if (agentLock) {
423
+ setAgentSession({
424
+ threadId: (0, import_shared2.randomId)(),
425
+ agentName: agentLock,
426
+ nodeName: void 0
427
+ });
428
+ } else {
429
+ setAgentSession(null);
430
+ }
431
+ }
432
+ }
433
+ }
434
+ if (newMessages.length > 0) {
435
+ setMessages([...previousMessages, ...newMessages]);
436
+ }
437
+ }
438
+ const finalMessages = constructFinalMessages(syncedMessages, previousMessages, newMessages);
439
+ let didExecuteAction = false;
440
+ if (onFunctionCall) {
441
+ const lastMessages = [];
442
+ for (let i = finalMessages.length - 1; i >= 0; i--) {
443
+ const message = finalMessages[i];
444
+ if (message.isActionExecutionMessage() && message.status.code !== import_runtime_client_gql3.MessageStatusCode.Pending) {
445
+ lastMessages.unshift(message);
446
+ } else {
447
+ break;
448
+ }
449
+ }
450
+ for (const message of lastMessages) {
451
+ setMessages(finalMessages);
452
+ const action = actions.find((action2) => action2.name === message.name);
453
+ if (action) {
454
+ followUp = action.followUp;
455
+ let result;
456
+ let error = null;
457
+ try {
458
+ result = yield Promise.race([
459
+ onFunctionCall({
460
+ messages: previousMessages,
461
+ name: message.name,
462
+ args: message.arguments
463
+ }),
464
+ new Promise(
465
+ (resolve) => {
466
+ var _a2;
467
+ return (_a2 = chatAbortControllerRef.current) == null ? void 0 : _a2.signal.addEventListener(
468
+ "abort",
469
+ () => resolve("Operation was aborted by the user")
470
+ );
471
+ }
472
+ ),
473
+ // if the user stopped generation, we also abort consecutive actions
474
+ new Promise((resolve) => {
475
+ var _a2;
476
+ if ((_a2 = chatAbortControllerRef.current) == null ? void 0 : _a2.signal.aborted) {
477
+ resolve("Operation was aborted by the user");
478
+ }
479
+ })
480
+ ]);
481
+ } catch (e) {
482
+ error = e;
483
+ addErrorToast([error]);
484
+ result = `Failed to execute action ${message.name}. ${error.message}`;
485
+ console.error(`Failed to execute action ${message.name}: ${error}`);
486
+ }
487
+ didExecuteAction = true;
488
+ const messageIndex = finalMessages.findIndex((msg) => msg.id === message.id);
489
+ finalMessages.splice(
490
+ messageIndex + 1,
491
+ 0,
492
+ new import_runtime_client_gql3.ResultMessage({
493
+ id: "result-" + message.id,
494
+ result: import_runtime_client_gql3.ResultMessage.encodeResult(
495
+ error ? {
496
+ content: result,
497
+ error: JSON.parse(
498
+ JSON.stringify(error, Object.getOwnPropertyNames(error))
499
+ )
500
+ } : result
501
+ ),
502
+ actionExecutionId: message.id,
503
+ actionName: message.name
504
+ })
505
+ );
506
+ }
507
+ }
508
+ setMessages(finalMessages);
509
+ }
510
+ if (
511
+ // if followUp is not explicitly false
512
+ followUp !== false && // and we executed an action
513
+ (didExecuteAction || // the last message is a server side result
514
+ !isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
515
+ !((_j = chatAbortControllerRef.current) == null ? void 0 : _j.signal.aborted)
516
+ ) {
517
+ yield new Promise((resolve) => setTimeout(resolve, 10));
518
+ return yield runChatCompletionRef.current(finalMessages);
519
+ } else if ((_k = chatAbortControllerRef.current) == null ? void 0 : _k.signal.aborted) {
520
+ const repairedMessages = finalMessages.filter((message, actionExecutionIndex) => {
521
+ if (message.isActionExecutionMessage()) {
522
+ return finalMessages.find(
523
+ (msg, resultIndex) => msg.isResultMessage() && msg.actionExecutionId === message.id && resultIndex === actionExecutionIndex + 1
524
+ );
525
+ }
526
+ return true;
527
+ });
528
+ const repairedMessageIds = repairedMessages.map((message) => message.id);
529
+ setMessages(repairedMessages);
530
+ if ((_l = agentSessionRef.current) == null ? void 0 : _l.nodeName) {
531
+ setAgentSession({
532
+ threadId: agentSessionRef.current.threadId,
533
+ agentName: agentSessionRef.current.agentName,
534
+ nodeName: "__end__"
535
+ });
536
+ }
537
+ return newMessages.filter((message) => repairedMessageIds.includes(message.id));
538
+ } else {
539
+ return newMessages.slice();
540
+ }
541
+ } finally {
542
+ setIsLoading(false);
543
+ }
544
+ }),
545
+ [
546
+ messages,
547
+ setMessages,
548
+ makeSystemMessageCallback,
549
+ copilotConfig,
550
+ setIsLoading,
551
+ initialMessages,
552
+ isLoading,
553
+ actions,
554
+ onFunctionCall,
555
+ onCoAgentStateRender,
556
+ setCoagentStatesWithRef,
557
+ coagentStatesRef,
558
+ agentSession,
559
+ setAgentSession
560
+ ]
561
+ );
562
+ runChatCompletionRef.current = runChatCompletion;
563
+ const runChatCompletionAndHandleFunctionCall = useAsyncCallback(
564
+ (messages2) => __async(this, null, function* () {
565
+ yield runChatCompletionRef.current(messages2);
566
+ }),
567
+ [messages]
568
+ );
569
+ const append = useAsyncCallback(
570
+ (message, options2) => __async(this, null, function* () {
571
+ var _a;
572
+ if (isLoading) {
573
+ return;
574
+ }
575
+ const newMessages = [...messages, message];
576
+ setMessages(newMessages);
577
+ const followUp = (_a = options2 == null ? void 0 : options2.followUp) != null ? _a : true;
578
+ if (followUp) {
579
+ return runChatCompletionAndHandleFunctionCall(newMessages);
580
+ }
581
+ }),
582
+ [isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]
583
+ );
584
+ const reload = useAsyncCallback(() => __async(this, null, function* () {
585
+ if (isLoading || messages.length === 0) {
586
+ return;
587
+ }
588
+ let newMessages = [...messages];
589
+ const lastMessage = messages[messages.length - 1];
590
+ if (lastMessage.isTextMessage() && lastMessage.role === "assistant") {
591
+ newMessages = newMessages.slice(0, -1);
592
+ }
593
+ setMessages(newMessages);
594
+ return runChatCompletionAndHandleFunctionCall(newMessages);
595
+ }), [isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]);
596
+ const stop = () => {
597
+ var _a;
598
+ (_a = chatAbortControllerRef.current) == null ? void 0 : _a.abort("Stop was called");
599
+ };
600
+ return {
601
+ append,
602
+ reload,
603
+ stop,
604
+ runChatCompletion: () => runChatCompletionRef.current(messages)
605
+ };
606
+ }
607
+ function constructFinalMessages(syncedMessages, previousMessages, newMessages) {
608
+ const finalMessages = syncedMessages.length > 0 ? [...syncedMessages] : [...previousMessages, ...newMessages];
609
+ if (syncedMessages.length > 0) {
610
+ const messagesWithAgentState = [...previousMessages, ...newMessages];
611
+ let previousMessageId = void 0;
612
+ for (const message of messagesWithAgentState) {
613
+ if (message.isAgentStateMessage()) {
614
+ const index = finalMessages.findIndex((msg) => msg.id === previousMessageId);
615
+ if (index !== -1) {
616
+ finalMessages.splice(index + 1, 0, message);
617
+ }
618
+ }
619
+ previousMessageId = message.id;
620
+ }
621
+ }
622
+ return finalMessages;
623
+ }
624
+ // Annotate the CommonJS export names for ESM import in node:
625
+ 0 && (module.exports = {
626
+ useChat
627
+ });
628
+ //# sourceMappingURL=use-chat.js.map