@copilotkit/shared 1.51.5-next.0 → 1.51.5-next.2

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 (254) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  3. package/dist/constants/index.cjs +13 -0
  4. package/dist/constants/index.cjs.map +1 -0
  5. package/dist/constants/{index.d.ts → index.d.cts} +3 -1
  6. package/dist/constants/index.d.cts.map +1 -0
  7. package/dist/constants/index.d.mts +8 -0
  8. package/dist/constants/index.d.mts.map +1 -0
  9. package/dist/constants/index.mjs +8 -12
  10. package/dist/constants/index.mjs.map +1 -1
  11. package/dist/index.cjs +64 -0
  12. package/dist/index.cjs.map +1 -0
  13. package/dist/index.d.cts +22 -0
  14. package/dist/index.d.cts.map +1 -0
  15. package/dist/index.d.mts +23 -0
  16. package/dist/index.d.mts.map +1 -0
  17. package/dist/index.mjs +16 -123
  18. package/dist/index.mjs.map +1 -1
  19. package/dist/index.umd.js +1017 -2
  20. package/dist/index.umd.js.map +1 -1
  21. package/dist/package.cjs +12 -0
  22. package/dist/package.cjs.map +1 -0
  23. package/dist/package.mjs +6 -0
  24. package/dist/package.mjs.map +1 -0
  25. package/dist/telemetry/events.d.cts +47 -0
  26. package/dist/telemetry/events.d.cts.map +1 -0
  27. package/dist/telemetry/events.d.mts +47 -0
  28. package/dist/telemetry/events.d.mts.map +1 -0
  29. package/dist/telemetry/index.d.mts +1 -0
  30. package/dist/telemetry/scarf-client.cjs +29 -0
  31. package/dist/telemetry/scarf-client.cjs.map +1 -0
  32. package/dist/telemetry/scarf-client.mjs +27 -5
  33. package/dist/telemetry/scarf-client.mjs.map +1 -1
  34. package/dist/telemetry/telemetry-client.cjs +87 -0
  35. package/dist/telemetry/telemetry-client.cjs.map +1 -0
  36. package/dist/telemetry/telemetry-client.d.cts +48 -0
  37. package/dist/telemetry/telemetry-client.d.cts.map +1 -0
  38. package/dist/telemetry/telemetry-client.d.mts +48 -0
  39. package/dist/telemetry/telemetry-client.d.mts.map +1 -0
  40. package/dist/telemetry/telemetry-client.mjs +83 -9
  41. package/dist/telemetry/telemetry-client.mjs.map +1 -1
  42. package/dist/telemetry/utils.cjs +16 -0
  43. package/dist/telemetry/utils.cjs.map +1 -0
  44. package/dist/telemetry/utils.mjs +14 -8
  45. package/dist/telemetry/utils.mjs.map +1 -1
  46. package/dist/types/{action.d.ts → action.d.cts} +32 -32
  47. package/dist/types/action.d.cts.map +1 -0
  48. package/dist/types/action.d.mts +59 -0
  49. package/dist/types/action.d.mts.map +1 -0
  50. package/dist/types/copilot-cloud-config.d.cts +15 -0
  51. package/dist/types/copilot-cloud-config.d.cts.map +1 -0
  52. package/dist/types/copilot-cloud-config.d.mts +15 -0
  53. package/dist/types/copilot-cloud-config.d.mts.map +1 -0
  54. package/dist/types/error.d.cts +57 -0
  55. package/dist/types/error.d.cts.map +1 -0
  56. package/dist/types/error.d.mts +57 -0
  57. package/dist/types/error.d.mts.map +1 -0
  58. package/dist/types/{message.d.ts → message.d.cts} +14 -12
  59. package/dist/types/message.d.cts.map +1 -0
  60. package/dist/types/message.d.mts +31 -0
  61. package/dist/types/message.d.mts.map +1 -0
  62. package/dist/types/openai-assistant.d.cts +55 -0
  63. package/dist/types/openai-assistant.d.cts.map +1 -0
  64. package/dist/types/openai-assistant.d.mts +55 -0
  65. package/dist/types/openai-assistant.d.mts.map +1 -0
  66. package/dist/types/utility.d.cts +6 -0
  67. package/dist/types/utility.d.cts.map +1 -0
  68. package/dist/types/utility.d.mts +6 -0
  69. package/dist/types/utility.d.mts.map +1 -0
  70. package/dist/utils/conditions.cjs +32 -0
  71. package/dist/utils/conditions.cjs.map +1 -0
  72. package/dist/utils/{conditions.d.ts → conditions.d.cts} +16 -11
  73. package/dist/utils/conditions.d.cts.map +1 -0
  74. package/dist/utils/conditions.d.mts +31 -0
  75. package/dist/utils/conditions.d.mts.map +1 -0
  76. package/dist/utils/conditions.mjs +30 -6
  77. package/dist/utils/conditions.mjs.map +1 -1
  78. package/dist/utils/console-styling.cjs +91 -0
  79. package/dist/utils/console-styling.cjs.map +1 -0
  80. package/dist/utils/console-styling.d.cts +65 -0
  81. package/dist/utils/console-styling.d.cts.map +1 -0
  82. package/dist/utils/console-styling.d.mts +65 -0
  83. package/dist/utils/console-styling.d.mts.map +1 -0
  84. package/dist/utils/console-styling.mjs +83 -15
  85. package/dist/utils/console-styling.mjs.map +1 -1
  86. package/dist/utils/errors.cjs +439 -0
  87. package/dist/utils/errors.cjs.map +1 -0
  88. package/dist/utils/{errors.d.ts → errors.d.cts} +188 -156
  89. package/dist/utils/errors.d.cts.map +1 -0
  90. package/dist/utils/errors.d.mts +312 -0
  91. package/dist/utils/errors.d.mts.map +1 -0
  92. package/dist/utils/errors.mjs +416 -63
  93. package/dist/utils/errors.mjs.map +1 -1
  94. package/dist/utils/index.cjs +50 -0
  95. package/dist/utils/index.cjs.map +1 -0
  96. package/dist/utils/{index.d.ts → index.d.cts} +10 -11
  97. package/dist/utils/index.d.cts.map +1 -0
  98. package/dist/utils/index.d.mts +31 -0
  99. package/dist/utils/index.d.mts.map +1 -0
  100. package/dist/utils/index.mjs +47 -107
  101. package/dist/utils/index.mjs.map +1 -1
  102. package/dist/utils/json-schema.cjs +157 -0
  103. package/dist/utils/json-schema.cjs.map +1 -0
  104. package/dist/utils/{json-schema.d.ts → json-schema.d.cts} +19 -17
  105. package/dist/utils/json-schema.d.cts.map +1 -0
  106. package/dist/utils/json-schema.d.mts +36 -0
  107. package/dist/utils/json-schema.d.mts.map +1 -0
  108. package/dist/utils/json-schema.mjs +152 -12
  109. package/dist/utils/json-schema.mjs.map +1 -1
  110. package/dist/utils/random-id.cjs +38 -0
  111. package/dist/utils/random-id.cjs.map +1 -0
  112. package/dist/utils/{random-id.d.ts → random-id.d.cts} +3 -1
  113. package/dist/utils/random-id.d.cts.map +1 -0
  114. package/dist/utils/random-id.d.mts +8 -0
  115. package/dist/utils/random-id.d.mts.map +1 -0
  116. package/dist/utils/random-id.mjs +33 -12
  117. package/dist/utils/random-id.mjs.map +1 -1
  118. package/dist/utils/requests.cjs +58 -0
  119. package/dist/utils/requests.cjs.map +1 -0
  120. package/dist/utils/{requests.d.ts → requests.d.cts} +3 -1
  121. package/dist/utils/requests.d.cts.map +1 -0
  122. package/dist/utils/requests.d.mts +12 -0
  123. package/dist/utils/requests.d.mts.map +1 -0
  124. package/dist/utils/requests.mjs +56 -6
  125. package/dist/utils/requests.mjs.map +1 -1
  126. package/dist/utils/{types.d.ts → types.d.cts} +9 -7
  127. package/dist/utils/types.d.cts.map +1 -0
  128. package/dist/utils/types.d.mts +22 -0
  129. package/dist/utils/types.d.mts.map +1 -0
  130. package/package.json +16 -14
  131. package/tsdown.config.ts +36 -0
  132. package/vitest.config.mjs +11 -0
  133. package/dist/chunk-2OJ5OJ2D.mjs +0 -1
  134. package/dist/chunk-2OJ5OJ2D.mjs.map +0 -1
  135. package/dist/chunk-3DK3UMRW.mjs +0 -217
  136. package/dist/chunk-3DK3UMRW.mjs.map +0 -1
  137. package/dist/chunk-7KOT4KP4.mjs +0 -435
  138. package/dist/chunk-7KOT4KP4.mjs.map +0 -1
  139. package/dist/chunk-DE5XAMMI.mjs +0 -110
  140. package/dist/chunk-DE5XAMMI.mjs.map +0 -1
  141. package/dist/chunk-FCCOSO5L.mjs +0 -1
  142. package/dist/chunk-FCCOSO5L.mjs.map +0 -1
  143. package/dist/chunk-GS5BLXSZ.mjs +0 -41
  144. package/dist/chunk-GS5BLXSZ.mjs.map +0 -1
  145. package/dist/chunk-IAFBVORQ.mjs +0 -1
  146. package/dist/chunk-IAFBVORQ.mjs.map +0 -1
  147. package/dist/chunk-M2RJI5BZ.mjs +0 -94
  148. package/dist/chunk-M2RJI5BZ.mjs.map +0 -1
  149. package/dist/chunk-MSUB6DGR.mjs +0 -1
  150. package/dist/chunk-MSUB6DGR.mjs.map +0 -1
  151. package/dist/chunk-N5EP5OD5.mjs +0 -1
  152. package/dist/chunk-N5EP5OD5.mjs.map +0 -1
  153. package/dist/chunk-NAFEBKSO.mjs +0 -1
  154. package/dist/chunk-NAFEBKSO.mjs.map +0 -1
  155. package/dist/chunk-P7STFMPO.mjs +0 -1
  156. package/dist/chunk-P7STFMPO.mjs.map +0 -1
  157. package/dist/chunk-UYARLQNA.mjs +0 -1
  158. package/dist/chunk-UYARLQNA.mjs.map +0 -1
  159. package/dist/chunk-V7BSERGI.mjs +0 -62
  160. package/dist/chunk-V7BSERGI.mjs.map +0 -1
  161. package/dist/chunk-WAZHII6M.mjs +0 -67
  162. package/dist/chunk-WAZHII6M.mjs.map +0 -1
  163. package/dist/chunk-XTHC46M2.mjs +0 -1
  164. package/dist/chunk-XTHC46M2.mjs.map +0 -1
  165. package/dist/chunk-ZI7ZVRL3.mjs +0 -38
  166. package/dist/chunk-ZI7ZVRL3.mjs.map +0 -1
  167. package/dist/chunk-ZIC6V6S5.mjs +0 -13
  168. package/dist/chunk-ZIC6V6S5.mjs.map +0 -1
  169. package/dist/chunk-ZUE2VR7D.mjs +0 -38
  170. package/dist/chunk-ZUE2VR7D.mjs.map +0 -1
  171. package/dist/constants/index.js +0 -40
  172. package/dist/constants/index.js.map +0 -1
  173. package/dist/index.d.ts +0 -25
  174. package/dist/index.js +0 -1138
  175. package/dist/index.js.map +0 -1
  176. package/dist/telemetry/events.d.ts +0 -45
  177. package/dist/telemetry/events.js +0 -19
  178. package/dist/telemetry/events.js.map +0 -1
  179. package/dist/telemetry/events.mjs +0 -1
  180. package/dist/telemetry/events.mjs.map +0 -1
  181. package/dist/telemetry/index.d.ts +0 -3
  182. package/dist/telemetry/index.js +0 -191
  183. package/dist/telemetry/index.js.map +0 -1
  184. package/dist/telemetry/index.mjs +0 -12
  185. package/dist/telemetry/index.mjs.map +0 -1
  186. package/dist/telemetry/scarf-client.d.ts +0 -7
  187. package/dist/telemetry/scarf-client.js +0 -59
  188. package/dist/telemetry/scarf-client.js.map +0 -1
  189. package/dist/telemetry/security-check.d.ts +0 -2
  190. package/dist/telemetry/security-check.js +0 -2
  191. package/dist/telemetry/security-check.js.map +0 -1
  192. package/dist/telemetry/security-check.mjs +0 -1
  193. package/dist/telemetry/security-check.mjs.map +0 -1
  194. package/dist/telemetry/telemetry-client.d.ts +0 -40
  195. package/dist/telemetry/telemetry-client.js +0 -189
  196. package/dist/telemetry/telemetry-client.js.map +0 -1
  197. package/dist/telemetry/utils.d.ts +0 -8
  198. package/dist/telemetry/utils.js +0 -73
  199. package/dist/telemetry/utils.js.map +0 -1
  200. package/dist/types/action.js +0 -19
  201. package/dist/types/action.js.map +0 -1
  202. package/dist/types/action.mjs +0 -2
  203. package/dist/types/action.mjs.map +0 -1
  204. package/dist/types/copilot-cloud-config.d.ts +0 -13
  205. package/dist/types/copilot-cloud-config.js +0 -19
  206. package/dist/types/copilot-cloud-config.js.map +0 -1
  207. package/dist/types/copilot-cloud-config.mjs +0 -2
  208. package/dist/types/copilot-cloud-config.mjs.map +0 -1
  209. package/dist/types/error.d.ts +0 -55
  210. package/dist/types/error.js +0 -19
  211. package/dist/types/error.js.map +0 -1
  212. package/dist/types/error.mjs +0 -2
  213. package/dist/types/error.mjs.map +0 -1
  214. package/dist/types/index.d.ts +0 -7
  215. package/dist/types/index.js +0 -19
  216. package/dist/types/index.js.map +0 -1
  217. package/dist/types/index.mjs +0 -8
  218. package/dist/types/index.mjs.map +0 -1
  219. package/dist/types/message.js +0 -19
  220. package/dist/types/message.js.map +0 -1
  221. package/dist/types/message.mjs +0 -2
  222. package/dist/types/message.mjs.map +0 -1
  223. package/dist/types/openai-assistant.d.ts +0 -53
  224. package/dist/types/openai-assistant.js +0 -19
  225. package/dist/types/openai-assistant.js.map +0 -1
  226. package/dist/types/openai-assistant.mjs +0 -2
  227. package/dist/types/openai-assistant.mjs.map +0 -1
  228. package/dist/types/utility.d.ts +0 -6
  229. package/dist/types/utility.js +0 -19
  230. package/dist/types/utility.js.map +0 -1
  231. package/dist/types/utility.mjs +0 -2
  232. package/dist/types/utility.mjs.map +0 -1
  233. package/dist/utils/conditions.js +0 -86
  234. package/dist/utils/conditions.js.map +0 -1
  235. package/dist/utils/console-styling.d.ts +0 -84
  236. package/dist/utils/console-styling.js +0 -123
  237. package/dist/utils/console-styling.js.map +0 -1
  238. package/dist/utils/errors.js +0 -452
  239. package/dist/utils/errors.js.map +0 -1
  240. package/dist/utils/index.js +0 -964
  241. package/dist/utils/index.js.map +0 -1
  242. package/dist/utils/json-schema.js +0 -244
  243. package/dist/utils/json-schema.js.map +0 -1
  244. package/dist/utils/random-id.js +0 -68
  245. package/dist/utils/random-id.js.map +0 -1
  246. package/dist/utils/requests.js +0 -91
  247. package/dist/utils/requests.js.map +0 -1
  248. package/dist/utils/types.js +0 -19
  249. package/dist/utils/types.js.map +0 -1
  250. package/dist/utils/types.mjs +0 -2
  251. package/dist/utils/types.mjs.map +0 -1
  252. package/jest.config.js +0 -5
  253. package/rollup.config.mjs +0 -54
  254. package/tsup.config.ts +0 -15
@@ -1,65 +1,418 @@
1
- import {
2
- BANNER_ERROR_NAMES,
3
- COPILOT_CLOUD_ERROR_NAMES,
4
- ConfigurationError,
5
- CopilotKitAgentDiscoveryError,
6
- CopilotKitApiDiscoveryError,
7
- CopilotKitError,
8
- CopilotKitErrorCode,
9
- CopilotKitLowLevelError,
10
- CopilotKitMisuseError,
11
- CopilotKitRemoteEndpointDiscoveryError,
12
- CopilotKitVersionMismatchError,
13
- ERROR_CONFIG,
14
- ERROR_NAMES,
15
- ErrorVisibility,
16
- MissingPublicApiKeyError,
17
- ResolvedCopilotKitError,
18
- Severity,
19
- UpgradeRequiredError,
20
- ensureStructuredError,
21
- getPossibleVersionMismatch,
22
- isStructuredCopilotKitError
23
- } from "../chunk-7KOT4KP4.mjs";
24
- import "../chunk-N5EP5OD5.mjs";
25
- import "../chunk-NAFEBKSO.mjs";
26
- import "../chunk-MSUB6DGR.mjs";
27
- import "../chunk-2OJ5OJ2D.mjs";
28
- import "../chunk-UYARLQNA.mjs";
29
- import "../chunk-IAFBVORQ.mjs";
30
- import "../chunk-FCCOSO5L.mjs";
31
- import "../chunk-V7BSERGI.mjs";
32
- import "../chunk-M2RJI5BZ.mjs";
33
- import "../chunk-3DK3UMRW.mjs";
34
- import "../chunk-GS5BLXSZ.mjs";
35
- import "../chunk-WAZHII6M.mjs";
36
- import "../chunk-XTHC46M2.mjs";
37
- import "../chunk-ZIC6V6S5.mjs";
38
- import "../chunk-P7STFMPO.mjs";
39
- import "../chunk-DE5XAMMI.mjs";
40
- import "../chunk-ZI7ZVRL3.mjs";
41
- import "../chunk-ZUE2VR7D.mjs";
42
- export {
43
- BANNER_ERROR_NAMES,
44
- COPILOT_CLOUD_ERROR_NAMES,
45
- ConfigurationError,
46
- CopilotKitAgentDiscoveryError,
47
- CopilotKitApiDiscoveryError,
48
- CopilotKitError,
49
- CopilotKitErrorCode,
50
- CopilotKitLowLevelError,
51
- CopilotKitMisuseError,
52
- CopilotKitRemoteEndpointDiscoveryError,
53
- CopilotKitVersionMismatchError,
54
- ERROR_CONFIG,
55
- ERROR_NAMES,
56
- ErrorVisibility,
57
- MissingPublicApiKeyError,
58
- ResolvedCopilotKitError,
59
- Severity,
60
- UpgradeRequiredError,
61
- ensureStructuredError,
62
- getPossibleVersionMismatch,
63
- isStructuredCopilotKitError
1
+ import { COPILOTKIT_VERSION } from "../index.mjs";
2
+ import { GraphQLError } from "graphql";
3
+
4
+ //#region src/utils/errors.ts
5
+ let Severity = /* @__PURE__ */ function(Severity) {
6
+ Severity["CRITICAL"] = "critical";
7
+ Severity["WARNING"] = "warning";
8
+ Severity["INFO"] = "info";
9
+ return Severity;
10
+ }({});
11
+ let ErrorVisibility = /* @__PURE__ */ function(ErrorVisibility) {
12
+ ErrorVisibility["BANNER"] = "banner";
13
+ ErrorVisibility["TOAST"] = "toast";
14
+ ErrorVisibility["SILENT"] = "silent";
15
+ ErrorVisibility["DEV_ONLY"] = "dev_only";
16
+ return ErrorVisibility;
17
+ }({});
18
+ const ERROR_NAMES = {
19
+ COPILOT_ERROR: "CopilotError",
20
+ COPILOT_API_DISCOVERY_ERROR: "CopilotApiDiscoveryError",
21
+ COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR: "CopilotKitRemoteEndpointDiscoveryError",
22
+ COPILOT_KIT_AGENT_DISCOVERY_ERROR: "CopilotKitAgentDiscoveryError",
23
+ COPILOT_KIT_LOW_LEVEL_ERROR: "CopilotKitLowLevelError",
24
+ COPILOT_KIT_VERSION_MISMATCH_ERROR: "CopilotKitVersionMismatchError",
25
+ RESOLVED_COPILOT_KIT_ERROR: "ResolvedCopilotKitError",
26
+ CONFIGURATION_ERROR: "ConfigurationError",
27
+ MISSING_PUBLIC_API_KEY_ERROR: "MissingPublicApiKeyError",
28
+ UPGRADE_REQUIRED_ERROR: "UpgradeRequiredError"
64
29
  };
30
+ const BANNER_ERROR_NAMES = [
31
+ ERROR_NAMES.CONFIGURATION_ERROR,
32
+ ERROR_NAMES.MISSING_PUBLIC_API_KEY_ERROR,
33
+ ERROR_NAMES.UPGRADE_REQUIRED_ERROR,
34
+ ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR,
35
+ ERROR_NAMES.COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR,
36
+ ERROR_NAMES.COPILOT_KIT_AGENT_DISCOVERY_ERROR
37
+ ];
38
+ const COPILOT_CLOUD_ERROR_NAMES = BANNER_ERROR_NAMES;
39
+ let CopilotKitErrorCode = /* @__PURE__ */ function(CopilotKitErrorCode) {
40
+ CopilotKitErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR";
41
+ CopilotKitErrorCode["NOT_FOUND"] = "NOT_FOUND";
42
+ CopilotKitErrorCode["AGENT_NOT_FOUND"] = "AGENT_NOT_FOUND";
43
+ CopilotKitErrorCode["API_NOT_FOUND"] = "API_NOT_FOUND";
44
+ CopilotKitErrorCode["REMOTE_ENDPOINT_NOT_FOUND"] = "REMOTE_ENDPOINT_NOT_FOUND";
45
+ CopilotKitErrorCode["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
46
+ CopilotKitErrorCode["MISUSE"] = "MISUSE";
47
+ CopilotKitErrorCode["UNKNOWN"] = "UNKNOWN";
48
+ CopilotKitErrorCode["VERSION_MISMATCH"] = "VERSION_MISMATCH";
49
+ CopilotKitErrorCode["CONFIGURATION_ERROR"] = "CONFIGURATION_ERROR";
50
+ CopilotKitErrorCode["MISSING_PUBLIC_API_KEY_ERROR"] = "MISSING_PUBLIC_API_KEY_ERROR";
51
+ CopilotKitErrorCode["UPGRADE_REQUIRED_ERROR"] = "UPGRADE_REQUIRED_ERROR";
52
+ return CopilotKitErrorCode;
53
+ }({});
54
+ const BASE_URL = "https://docs.copilotkit.ai";
55
+ const getSeeMoreMarkdown = (link) => `See more: [${link}](${link})`;
56
+ const ERROR_CONFIG = {
57
+ [CopilotKitErrorCode.NETWORK_ERROR]: {
58
+ statusCode: 503,
59
+ troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-a-network-errors--api-not-found`,
60
+ visibility: ErrorVisibility.BANNER,
61
+ severity: Severity.CRITICAL
62
+ },
63
+ [CopilotKitErrorCode.NOT_FOUND]: {
64
+ statusCode: 404,
65
+ troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-a-network-errors--api-not-found`,
66
+ visibility: ErrorVisibility.BANNER,
67
+ severity: Severity.CRITICAL
68
+ },
69
+ [CopilotKitErrorCode.AGENT_NOT_FOUND]: {
70
+ statusCode: 500,
71
+ troubleshootingUrl: `${BASE_URL}/coagents/troubleshooting/common-issues#i-am-getting-agent-not-found-error`,
72
+ visibility: ErrorVisibility.BANNER,
73
+ severity: Severity.CRITICAL
74
+ },
75
+ [CopilotKitErrorCode.API_NOT_FOUND]: {
76
+ statusCode: 404,
77
+ troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-a-network-errors--api-not-found`,
78
+ visibility: ErrorVisibility.BANNER,
79
+ severity: Severity.CRITICAL
80
+ },
81
+ [CopilotKitErrorCode.REMOTE_ENDPOINT_NOT_FOUND]: {
82
+ statusCode: 404,
83
+ troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-copilotkits-remote-endpoint-not-found-error`,
84
+ visibility: ErrorVisibility.BANNER,
85
+ severity: Severity.CRITICAL
86
+ },
87
+ [CopilotKitErrorCode.AUTHENTICATION_ERROR]: {
88
+ statusCode: 401,
89
+ troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#authentication-errors`,
90
+ visibility: ErrorVisibility.BANNER,
91
+ severity: Severity.CRITICAL
92
+ },
93
+ [CopilotKitErrorCode.MISUSE]: {
94
+ statusCode: 400,
95
+ troubleshootingUrl: null,
96
+ visibility: ErrorVisibility.DEV_ONLY,
97
+ severity: Severity.WARNING
98
+ },
99
+ [CopilotKitErrorCode.UNKNOWN]: {
100
+ statusCode: 500,
101
+ visibility: ErrorVisibility.TOAST,
102
+ severity: Severity.CRITICAL
103
+ },
104
+ [CopilotKitErrorCode.CONFIGURATION_ERROR]: {
105
+ statusCode: 400,
106
+ troubleshootingUrl: null,
107
+ severity: Severity.WARNING,
108
+ visibility: ErrorVisibility.BANNER
109
+ },
110
+ [CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR]: {
111
+ statusCode: 400,
112
+ troubleshootingUrl: null,
113
+ severity: Severity.CRITICAL,
114
+ visibility: ErrorVisibility.BANNER
115
+ },
116
+ [CopilotKitErrorCode.UPGRADE_REQUIRED_ERROR]: {
117
+ statusCode: 402,
118
+ troubleshootingUrl: null,
119
+ severity: Severity.WARNING,
120
+ visibility: ErrorVisibility.BANNER
121
+ },
122
+ [CopilotKitErrorCode.VERSION_MISMATCH]: {
123
+ statusCode: 400,
124
+ troubleshootingUrl: null,
125
+ visibility: ErrorVisibility.DEV_ONLY,
126
+ severity: Severity.INFO
127
+ }
128
+ };
129
+ var CopilotKitError = class extends GraphQLError {
130
+ constructor({ message = "Unknown error occurred", code, severity, visibility }) {
131
+ const name = ERROR_NAMES.COPILOT_ERROR;
132
+ const config = ERROR_CONFIG[code];
133
+ const { statusCode } = config;
134
+ const resolvedVisibility = visibility ?? config.visibility ?? ErrorVisibility.TOAST;
135
+ const resolvedSeverity = severity ?? ("severity" in config ? config.severity : void 0);
136
+ super(message, { extensions: {
137
+ name,
138
+ statusCode,
139
+ code,
140
+ visibility: resolvedVisibility,
141
+ severity: resolvedSeverity,
142
+ troubleshootingUrl: "troubleshootingUrl" in config ? config.troubleshootingUrl : null,
143
+ originalError: {
144
+ message,
145
+ stack: (/* @__PURE__ */ new Error()).stack
146
+ }
147
+ } });
148
+ this.code = code;
149
+ this.name = name;
150
+ this.statusCode = statusCode;
151
+ this.severity = resolvedSeverity;
152
+ this.visibility = resolvedVisibility;
153
+ }
154
+ };
155
+ /**
156
+ * Error thrown when we can identify wrong usage of our components.
157
+ * This helps us notify the developer before real errors can happen
158
+ *
159
+ * @extends CopilotKitError
160
+ */
161
+ var CopilotKitMisuseError = class extends CopilotKitError {
162
+ constructor({ message, code = CopilotKitErrorCode.MISUSE }) {
163
+ const docsLink = "troubleshootingUrl" in ERROR_CONFIG[code] && ERROR_CONFIG[code].troubleshootingUrl ? getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl) : null;
164
+ const finalMessage = docsLink ? `${message}.\n\n${docsLink}` : message;
165
+ super({
166
+ message: finalMessage,
167
+ code
168
+ });
169
+ this.name = ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR;
170
+ }
171
+ };
172
+ const getVersionMismatchErrorMessage = ({ reactCoreVersion, runtimeVersion, runtimeClientGqlVersion }) => `Version mismatch detected: @copilotkit/runtime@${runtimeVersion ?? ""} is not compatible with @copilotkit/react-core@${reactCoreVersion} and @copilotkit/runtime-client-gql@${runtimeClientGqlVersion}. Please ensure all installed copilotkit packages are on the same version.`;
173
+ /**
174
+ * Error thrown when CPK versions does not match
175
+ *
176
+ * @extends CopilotKitError
177
+ */
178
+ var CopilotKitVersionMismatchError = class extends CopilotKitError {
179
+ constructor({ reactCoreVersion, runtimeVersion, runtimeClientGqlVersion }) {
180
+ const code = CopilotKitErrorCode.VERSION_MISMATCH;
181
+ super({
182
+ message: getVersionMismatchErrorMessage({
183
+ reactCoreVersion,
184
+ runtimeVersion,
185
+ runtimeClientGqlVersion
186
+ }),
187
+ code
188
+ });
189
+ this.name = ERROR_NAMES.COPILOT_KIT_VERSION_MISMATCH_ERROR;
190
+ }
191
+ };
192
+ /**
193
+ * Error thrown when the CopilotKit API endpoint cannot be discovered or accessed.
194
+ * This typically occurs when:
195
+ * - The API endpoint URL is invalid or misconfigured
196
+ * - The API service is not running at the expected location
197
+ * - There are network/firewall issues preventing access
198
+ *
199
+ * @extends CopilotKitError
200
+ */
201
+ var CopilotKitApiDiscoveryError = class extends CopilotKitError {
202
+ constructor(params = {}) {
203
+ const url = params.url ?? "";
204
+ let operationSuffix = "";
205
+ if (url?.includes("/info")) operationSuffix = `when fetching CopilotKit info`;
206
+ else if (url.includes("/actions/execute")) operationSuffix = `when attempting to execute actions.`;
207
+ else if (url.includes("/agents/state")) operationSuffix = `when attempting to get agent state.`;
208
+ else if (url.includes("/agents/execute")) operationSuffix = `when attempting to execute agent(s).`;
209
+ const message = params.message ?? (params.url ? `Failed to find CopilotKit API endpoint at url ${params.url} ${operationSuffix}` : `Failed to find CopilotKit API endpoint.`);
210
+ const code = params.code ?? CopilotKitErrorCode.API_NOT_FOUND;
211
+ const errorMessage = `${message}.\n\n${getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl)}`;
212
+ super({
213
+ message: errorMessage,
214
+ code
215
+ });
216
+ this.name = ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR;
217
+ }
218
+ };
219
+ /**
220
+ * This error is used for endpoints specified in runtime's remote endpoints. If they cannot be contacted
221
+ * This typically occurs when:
222
+ * - The API endpoint URL is invalid or misconfigured
223
+ * - The API service is not running at the expected location
224
+ *
225
+ * @extends CopilotKitApiDiscoveryError
226
+ */
227
+ var CopilotKitRemoteEndpointDiscoveryError = class extends CopilotKitApiDiscoveryError {
228
+ constructor(params) {
229
+ const message = params?.message ?? (params?.url ? `Failed to find or contact remote endpoint at url ${params.url}` : "Failed to find or contact remote endpoint");
230
+ const code = CopilotKitErrorCode.REMOTE_ENDPOINT_NOT_FOUND;
231
+ super({
232
+ message,
233
+ code
234
+ });
235
+ this.name = ERROR_NAMES.COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR;
236
+ }
237
+ };
238
+ /**
239
+ * Error thrown when a LangGraph agent cannot be found or accessed.
240
+ * This typically occurs when:
241
+ * - The specified agent name does not exist in the deployment
242
+ * - The agent configuration is invalid or missing
243
+ * - The agent service is not properly deployed or initialized
244
+ *
245
+ * @extends CopilotKitError
246
+ */
247
+ var CopilotKitAgentDiscoveryError = class extends CopilotKitError {
248
+ constructor(params) {
249
+ const { agentName, availableAgents } = params;
250
+ const code = CopilotKitErrorCode.AGENT_NOT_FOUND;
251
+ const seeMore = getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl);
252
+ let message;
253
+ if (availableAgents.length) {
254
+ const agentList = availableAgents.map((agent) => agent.name).join(", ");
255
+ if (agentName) message = `Agent '${agentName}' was not found. Available agents are: ${agentList}. Please verify the agent name in your configuration and ensure it matches one of the available agents.\n\n${seeMore}`;
256
+ else message = `The requested agent was not found. Available agents are: ${agentList}. Please verify the agent name in your configuration and ensure it matches one of the available agents.\n\n${seeMore}`;
257
+ } else message = `${agentName ? `Agent '${agentName}'` : "The requested agent"} was not found. Please set up at least one agent before proceeding. ${seeMore}`;
258
+ super({
259
+ message,
260
+ code
261
+ });
262
+ this.name = ERROR_NAMES.COPILOT_KIT_AGENT_DISCOVERY_ERROR;
263
+ }
264
+ };
265
+ /**
266
+ * Handles low-level networking errors that occur before a request reaches the server.
267
+ * These errors arise from issues in the underlying communication infrastructure rather than
268
+ * application-level logic or server responses. Typically used to handle "fetch failed" errors
269
+ * where no HTTP status code is available.
270
+ *
271
+ * Common scenarios include:
272
+ * - Connection failures (ECONNREFUSED) when server is down/unreachable
273
+ * - DNS resolution failures (ENOTFOUND) when domain can't be resolved
274
+ * - Timeouts (ETIMEDOUT) when request takes too long
275
+ * - Protocol/transport layer errors like SSL/TLS issues
276
+ */
277
+ var CopilotKitLowLevelError = class extends CopilotKitError {
278
+ constructor({ error, url, message }) {
279
+ let code = CopilotKitErrorCode.NETWORK_ERROR;
280
+ const errorCode = error.code;
281
+ const errorMessage = message ?? resolveLowLevelErrorMessage({
282
+ errorCode,
283
+ url
284
+ });
285
+ super({
286
+ message: errorMessage,
287
+ code
288
+ });
289
+ this.name = ERROR_NAMES.COPILOT_KIT_LOW_LEVEL_ERROR;
290
+ }
291
+ };
292
+ /**
293
+ * Generic catch-all error handler for HTTP responses from the CopilotKit API where a status code is available.
294
+ * Used when we receive an HTTP error status and wish to handle broad range of them
295
+ *
296
+ * This differs from CopilotKitLowLevelError in that:
297
+ * - ResolvedCopilotKitError: Server was reached and returned an HTTP status
298
+ * - CopilotKitLowLevelError: Error occurred before reaching server (e.g. network failure)
299
+ *
300
+ * @param status - The HTTP status code received from the API response
301
+ * @param message - Optional error message to include
302
+ * @param code - Optional specific CopilotKitErrorCode to override default behavior
303
+ *
304
+ * Default behavior:
305
+ * - 400 Bad Request: Maps to CopilotKitApiDiscoveryError
306
+ * - All other status codes: Maps to UNKNOWN error code if no specific code provided
307
+ */
308
+ var ResolvedCopilotKitError = class extends CopilotKitError {
309
+ constructor({ status, message, code, isRemoteEndpoint, url }) {
310
+ let resolvedCode = code;
311
+ if (!resolvedCode) switch (status) {
312
+ case 400: throw new CopilotKitApiDiscoveryError({
313
+ message,
314
+ url
315
+ });
316
+ case 404: throw isRemoteEndpoint ? new CopilotKitRemoteEndpointDiscoveryError({
317
+ message,
318
+ url
319
+ }) : new CopilotKitApiDiscoveryError({
320
+ message,
321
+ url
322
+ });
323
+ default:
324
+ resolvedCode = CopilotKitErrorCode.UNKNOWN;
325
+ break;
326
+ }
327
+ super({
328
+ message,
329
+ code: resolvedCode
330
+ });
331
+ this.name = ERROR_NAMES.RESOLVED_COPILOT_KIT_ERROR;
332
+ }
333
+ };
334
+ var ConfigurationError = class extends CopilotKitError {
335
+ constructor(message) {
336
+ super({
337
+ message,
338
+ code: CopilotKitErrorCode.CONFIGURATION_ERROR
339
+ });
340
+ this.name = ERROR_NAMES.CONFIGURATION_ERROR;
341
+ this.severity = Severity.WARNING;
342
+ }
343
+ };
344
+ var MissingPublicApiKeyError = class extends ConfigurationError {
345
+ constructor(message) {
346
+ super(message);
347
+ this.name = ERROR_NAMES.MISSING_PUBLIC_API_KEY_ERROR;
348
+ this.severity = Severity.CRITICAL;
349
+ }
350
+ };
351
+ var UpgradeRequiredError = class extends ConfigurationError {
352
+ constructor(message) {
353
+ super(message);
354
+ this.name = ERROR_NAMES.UPGRADE_REQUIRED_ERROR;
355
+ this.severity = Severity.WARNING;
356
+ }
357
+ };
358
+ /**
359
+ * Checks if an error is already a structured CopilotKit error.
360
+ * This utility centralizes the logic for detecting structured errors across the codebase.
361
+ *
362
+ * @param error - The error to check
363
+ * @returns true if the error is already structured, false otherwise
364
+ */
365
+ function isStructuredCopilotKitError(error) {
366
+ return error instanceof CopilotKitError || error instanceof CopilotKitLowLevelError || error?.name && error.name.includes("CopilotKit") || error?.extensions?.code !== void 0;
367
+ }
368
+ /**
369
+ * Returns the error as-is if it's already structured, otherwise converts it using the provided converter function.
370
+ * This utility centralizes the pattern of preserving structured errors while converting unstructured ones.
371
+ *
372
+ * @param error - The error to process
373
+ * @param converter - Function to convert unstructured errors to structured ones
374
+ * @returns The structured error
375
+ */
376
+ function ensureStructuredError(error, converter) {
377
+ return isStructuredCopilotKitError(error) ? error : converter(error);
378
+ }
379
+ async function getPossibleVersionMismatch({ runtimeVersion, runtimeClientGqlVersion }) {
380
+ if (!runtimeVersion || runtimeVersion === "" || !runtimeClientGqlVersion) return;
381
+ if (COPILOTKIT_VERSION !== runtimeVersion || COPILOTKIT_VERSION !== runtimeClientGqlVersion || runtimeVersion !== runtimeClientGqlVersion) return {
382
+ runtimeVersion,
383
+ runtimeClientGqlVersion,
384
+ reactCoreVersion: COPILOTKIT_VERSION,
385
+ message: getVersionMismatchErrorMessage({
386
+ runtimeVersion,
387
+ runtimeClientGqlVersion,
388
+ reactCoreVersion: COPILOTKIT_VERSION
389
+ })
390
+ };
391
+ }
392
+ const resolveLowLevelErrorMessage = ({ errorCode, url }) => {
393
+ const troubleshootingLink = ERROR_CONFIG[CopilotKitErrorCode.NETWORK_ERROR].troubleshootingUrl;
394
+ const genericMessage = (description = `Failed to fetch from url ${url}.`) => `${description}.
395
+
396
+ Possible reasons:
397
+ - -The server may have an error preventing it from returning a response (Check the server logs for more info).
398
+ - -The server might be down or unreachable
399
+ - -There might be a network issue (e.g., DNS failure, connection timeout)
400
+ - -The URL might be incorrect
401
+ - -The server is not running on the specified port
402
+
403
+ ${getSeeMoreMarkdown(troubleshootingLink)}`;
404
+ if (url.includes("/info")) return genericMessage(`Failed to fetch CopilotKit agents/action information from url ${url}.`);
405
+ if (url.includes("/actions/execute")) return genericMessage(`Fetch call to ${url} to execute actions failed.`);
406
+ if (url.includes("/agents/state")) return genericMessage(`Fetch call to ${url} to get agent state failed.`);
407
+ if (url.includes("/agents/execute")) return genericMessage(`Fetch call to ${url} to execute agent(s) failed.`);
408
+ switch (errorCode) {
409
+ case "ECONNREFUSED": return `Connection to ${url} was refused. Ensure the server is running and accessible.\n\n${getSeeMoreMarkdown(troubleshootingLink)}`;
410
+ case "ENOTFOUND": return `The server on ${url} could not be found. Check the URL or your network configuration.\n\n${getSeeMoreMarkdown(ERROR_CONFIG[CopilotKitErrorCode.NOT_FOUND].troubleshootingUrl)}`;
411
+ case "ETIMEDOUT": return `The connection to ${url} timed out. The server might be overloaded or taking too long to respond.\n\n${getSeeMoreMarkdown(troubleshootingLink)}`;
412
+ default: return;
413
+ }
414
+ };
415
+
416
+ //#endregion
417
+ export { BANNER_ERROR_NAMES, COPILOT_CLOUD_ERROR_NAMES, ConfigurationError, CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitLowLevelError, CopilotKitMisuseError, CopilotKitRemoteEndpointDiscoveryError, CopilotKitVersionMismatchError, ERROR_CONFIG, ERROR_NAMES, ErrorVisibility, MissingPublicApiKeyError, ResolvedCopilotKitError, Severity, UpgradeRequiredError, ensureStructuredError, getPossibleVersionMismatch, isStructuredCopilotKitError };
65
418
  //# sourceMappingURL=errors.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"file":"errors.mjs","names":[],"sources":["../../src/utils/errors.ts"],"sourcesContent":["import { GraphQLError } from \"graphql\";\nimport { COPILOTKIT_VERSION } from \"../index\";\n\nexport enum Severity {\n CRITICAL = \"critical\", // Critical errors that block core functionality\n WARNING = \"warning\", // Configuration/setup issues that need attention\n INFO = \"info\", // General errors and network issues\n}\n\nexport enum ErrorVisibility {\n BANNER = \"banner\", // Critical errors shown as fixed banners\n TOAST = \"toast\", // Regular errors shown as dismissible toasts\n SILENT = \"silent\", // Errors logged but not shown to user\n DEV_ONLY = \"dev_only\", // Errors only shown in development mode\n}\n\nexport const ERROR_NAMES = {\n COPILOT_ERROR: \"CopilotError\",\n COPILOT_API_DISCOVERY_ERROR: \"CopilotApiDiscoveryError\",\n COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR:\n \"CopilotKitRemoteEndpointDiscoveryError\",\n COPILOT_KIT_AGENT_DISCOVERY_ERROR: \"CopilotKitAgentDiscoveryError\",\n COPILOT_KIT_LOW_LEVEL_ERROR: \"CopilotKitLowLevelError\",\n COPILOT_KIT_VERSION_MISMATCH_ERROR: \"CopilotKitVersionMismatchError\",\n RESOLVED_COPILOT_KIT_ERROR: \"ResolvedCopilotKitError\",\n CONFIGURATION_ERROR: \"ConfigurationError\",\n MISSING_PUBLIC_API_KEY_ERROR: \"MissingPublicApiKeyError\",\n UPGRADE_REQUIRED_ERROR: \"UpgradeRequiredError\",\n} as const;\n\n// Banner errors - critical configuration/discovery issues\nexport const BANNER_ERROR_NAMES = [\n ERROR_NAMES.CONFIGURATION_ERROR,\n ERROR_NAMES.MISSING_PUBLIC_API_KEY_ERROR,\n ERROR_NAMES.UPGRADE_REQUIRED_ERROR,\n ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR,\n ERROR_NAMES.COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR,\n ERROR_NAMES.COPILOT_KIT_AGENT_DISCOVERY_ERROR,\n];\n\n// Legacy cloud error names for backward compatibility\nexport const COPILOT_CLOUD_ERROR_NAMES = BANNER_ERROR_NAMES;\n\nexport enum CopilotKitErrorCode {\n NETWORK_ERROR = \"NETWORK_ERROR\",\n NOT_FOUND = \"NOT_FOUND\",\n AGENT_NOT_FOUND = \"AGENT_NOT_FOUND\",\n API_NOT_FOUND = \"API_NOT_FOUND\",\n REMOTE_ENDPOINT_NOT_FOUND = \"REMOTE_ENDPOINT_NOT_FOUND\",\n AUTHENTICATION_ERROR = \"AUTHENTICATION_ERROR\",\n MISUSE = \"MISUSE\",\n UNKNOWN = \"UNKNOWN\",\n VERSION_MISMATCH = \"VERSION_MISMATCH\",\n CONFIGURATION_ERROR = \"CONFIGURATION_ERROR\",\n MISSING_PUBLIC_API_KEY_ERROR = \"MISSING_PUBLIC_API_KEY_ERROR\",\n UPGRADE_REQUIRED_ERROR = \"UPGRADE_REQUIRED_ERROR\",\n}\n\nconst BASE_URL = \"https://docs.copilotkit.ai\";\n\nconst getSeeMoreMarkdown = (link: string) => `See more: [${link}](${link})`;\n\nexport const ERROR_CONFIG = {\n [CopilotKitErrorCode.NETWORK_ERROR]: {\n statusCode: 503,\n troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-a-network-errors--api-not-found`,\n visibility: ErrorVisibility.BANNER,\n severity: Severity.CRITICAL,\n },\n [CopilotKitErrorCode.NOT_FOUND]: {\n statusCode: 404,\n troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-a-network-errors--api-not-found`,\n visibility: ErrorVisibility.BANNER,\n severity: Severity.CRITICAL,\n },\n [CopilotKitErrorCode.AGENT_NOT_FOUND]: {\n statusCode: 500,\n troubleshootingUrl: `${BASE_URL}/coagents/troubleshooting/common-issues#i-am-getting-agent-not-found-error`,\n visibility: ErrorVisibility.BANNER,\n severity: Severity.CRITICAL,\n },\n [CopilotKitErrorCode.API_NOT_FOUND]: {\n statusCode: 404,\n troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-a-network-errors--api-not-found`,\n visibility: ErrorVisibility.BANNER,\n severity: Severity.CRITICAL,\n },\n [CopilotKitErrorCode.REMOTE_ENDPOINT_NOT_FOUND]: {\n statusCode: 404,\n troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-copilotkits-remote-endpoint-not-found-error`,\n visibility: ErrorVisibility.BANNER,\n severity: Severity.CRITICAL,\n },\n [CopilotKitErrorCode.AUTHENTICATION_ERROR]: {\n statusCode: 401,\n troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#authentication-errors`,\n visibility: ErrorVisibility.BANNER,\n severity: Severity.CRITICAL,\n },\n [CopilotKitErrorCode.MISUSE]: {\n statusCode: 400,\n troubleshootingUrl: null,\n visibility: ErrorVisibility.DEV_ONLY,\n severity: Severity.WARNING,\n },\n [CopilotKitErrorCode.UNKNOWN]: {\n statusCode: 500,\n visibility: ErrorVisibility.TOAST,\n severity: Severity.CRITICAL,\n },\n [CopilotKitErrorCode.CONFIGURATION_ERROR]: {\n statusCode: 400,\n troubleshootingUrl: null,\n severity: Severity.WARNING,\n visibility: ErrorVisibility.BANNER,\n },\n [CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR]: {\n statusCode: 400,\n troubleshootingUrl: null,\n severity: Severity.CRITICAL,\n visibility: ErrorVisibility.BANNER,\n },\n [CopilotKitErrorCode.UPGRADE_REQUIRED_ERROR]: {\n statusCode: 402,\n troubleshootingUrl: null,\n severity: Severity.WARNING,\n visibility: ErrorVisibility.BANNER,\n },\n [CopilotKitErrorCode.VERSION_MISMATCH]: {\n statusCode: 400,\n troubleshootingUrl: null,\n visibility: ErrorVisibility.DEV_ONLY,\n severity: Severity.INFO,\n },\n};\n\nexport class CopilotKitError extends GraphQLError {\n code: CopilotKitErrorCode;\n statusCode: number;\n severity?: Severity;\n visibility: ErrorVisibility;\n\n constructor({\n message = \"Unknown error occurred\",\n code,\n severity,\n visibility,\n }: {\n message?: string;\n code: CopilotKitErrorCode;\n severity?: Severity;\n visibility?: ErrorVisibility;\n }) {\n const name = ERROR_NAMES.COPILOT_ERROR;\n const config = ERROR_CONFIG[code];\n const { statusCode } = config;\n const resolvedVisibility =\n visibility ?? config.visibility ?? ErrorVisibility.TOAST;\n const resolvedSeverity =\n severity ?? (\"severity\" in config ? config.severity : undefined);\n\n super(message, {\n extensions: {\n name,\n statusCode,\n code,\n visibility: resolvedVisibility,\n severity: resolvedSeverity,\n troubleshootingUrl:\n \"troubleshootingUrl\" in config ? config.troubleshootingUrl : null,\n originalError: {\n message,\n stack: new Error().stack,\n },\n },\n });\n\n this.code = code;\n this.name = name;\n this.statusCode = statusCode;\n this.severity = resolvedSeverity;\n this.visibility = resolvedVisibility;\n }\n}\n\n/**\n * Error thrown when we can identify wrong usage of our components.\n * This helps us notify the developer before real errors can happen\n *\n * @extends CopilotKitError\n */\nexport class CopilotKitMisuseError extends CopilotKitError {\n constructor({\n message,\n code = CopilotKitErrorCode.MISUSE,\n }: {\n message: string;\n code?: CopilotKitErrorCode;\n }) {\n const docsLink =\n \"troubleshootingUrl\" in ERROR_CONFIG[code] &&\n ERROR_CONFIG[code].troubleshootingUrl\n ? getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl as string)\n : null;\n const finalMessage = docsLink ? `${message}.\\n\\n${docsLink}` : message;\n super({ message: finalMessage, code });\n this.name = ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR;\n }\n}\n\nconst getVersionMismatchErrorMessage = ({\n reactCoreVersion,\n runtimeVersion,\n runtimeClientGqlVersion,\n}: VersionMismatchResponse) =>\n `Version mismatch detected: @copilotkit/runtime@${runtimeVersion ?? \"\"} is not compatible with @copilotkit/react-core@${reactCoreVersion} and @copilotkit/runtime-client-gql@${runtimeClientGqlVersion}. Please ensure all installed copilotkit packages are on the same version.`;\n/**\n * Error thrown when CPK versions does not match\n *\n * @extends CopilotKitError\n */\nexport class CopilotKitVersionMismatchError extends CopilotKitError {\n constructor({\n reactCoreVersion,\n runtimeVersion,\n runtimeClientGqlVersion,\n }: VersionMismatchResponse) {\n const code = CopilotKitErrorCode.VERSION_MISMATCH;\n super({\n message: getVersionMismatchErrorMessage({\n reactCoreVersion,\n runtimeVersion,\n runtimeClientGqlVersion,\n }),\n code,\n });\n this.name = ERROR_NAMES.COPILOT_KIT_VERSION_MISMATCH_ERROR;\n }\n}\n\n/**\n * Error thrown when the CopilotKit API endpoint cannot be discovered or accessed.\n * This typically occurs when:\n * - The API endpoint URL is invalid or misconfigured\n * - The API service is not running at the expected location\n * - There are network/firewall issues preventing access\n *\n * @extends CopilotKitError\n */\nexport class CopilotKitApiDiscoveryError extends CopilotKitError {\n constructor(\n params: {\n message?: string;\n code?:\n | CopilotKitErrorCode.API_NOT_FOUND\n | CopilotKitErrorCode.REMOTE_ENDPOINT_NOT_FOUND;\n url?: string;\n } = {},\n ) {\n const url = params.url ?? \"\";\n let operationSuffix = \"\";\n if (url?.includes(\"/info\"))\n operationSuffix = `when fetching CopilotKit info`;\n else if (url.includes(\"/actions/execute\"))\n operationSuffix = `when attempting to execute actions.`;\n else if (url.includes(\"/agents/state\"))\n operationSuffix = `when attempting to get agent state.`;\n else if (url.includes(\"/agents/execute\"))\n operationSuffix = `when attempting to execute agent(s).`;\n const message =\n params.message ??\n (params.url\n ? `Failed to find CopilotKit API endpoint at url ${params.url} ${operationSuffix}`\n : `Failed to find CopilotKit API endpoint.`);\n const code = params.code ?? CopilotKitErrorCode.API_NOT_FOUND;\n const errorMessage = `${message}.\\n\\n${getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl)}`;\n super({ message: errorMessage, code });\n this.name = ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR;\n }\n}\n\n/**\n * This error is used for endpoints specified in runtime's remote endpoints. If they cannot be contacted\n * This typically occurs when:\n * - The API endpoint URL is invalid or misconfigured\n * - The API service is not running at the expected location\n *\n * @extends CopilotKitApiDiscoveryError\n */\nexport class CopilotKitRemoteEndpointDiscoveryError extends CopilotKitApiDiscoveryError {\n constructor(params?: { message?: string; url?: string }) {\n const message =\n params?.message ??\n (params?.url\n ? `Failed to find or contact remote endpoint at url ${params.url}`\n : \"Failed to find or contact remote endpoint\");\n const code = CopilotKitErrorCode.REMOTE_ENDPOINT_NOT_FOUND;\n super({ message, code });\n this.name = ERROR_NAMES.COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR;\n }\n}\n\n/**\n * Error thrown when a LangGraph agent cannot be found or accessed.\n * This typically occurs when:\n * - The specified agent name does not exist in the deployment\n * - The agent configuration is invalid or missing\n * - The agent service is not properly deployed or initialized\n *\n * @extends CopilotKitError\n */\nexport class CopilotKitAgentDiscoveryError extends CopilotKitError {\n constructor(params: {\n agentName?: string;\n availableAgents: { name: string; id: string }[];\n }) {\n const { agentName, availableAgents } = params;\n const code = CopilotKitErrorCode.AGENT_NOT_FOUND;\n\n const seeMore = getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl);\n let message;\n\n if (availableAgents.length) {\n const agentList = availableAgents.map((agent) => agent.name).join(\", \");\n\n if (agentName) {\n message = `Agent '${agentName}' was not found. Available agents are: ${agentList}. Please verify the agent name in your configuration and ensure it matches one of the available agents.\\n\\n${seeMore}`;\n } else {\n message = `The requested agent was not found. Available agents are: ${agentList}. Please verify the agent name in your configuration and ensure it matches one of the available agents.\\n\\n${seeMore}`;\n }\n } else {\n message = `${agentName ? `Agent '${agentName}'` : \"The requested agent\"} was not found. Please set up at least one agent before proceeding. ${seeMore}`;\n }\n\n super({ message, code });\n this.name = ERROR_NAMES.COPILOT_KIT_AGENT_DISCOVERY_ERROR;\n }\n}\n\n/**\n * Handles low-level networking errors that occur before a request reaches the server.\n * These errors arise from issues in the underlying communication infrastructure rather than\n * application-level logic or server responses. Typically used to handle \"fetch failed\" errors\n * where no HTTP status code is available.\n *\n * Common scenarios include:\n * - Connection failures (ECONNREFUSED) when server is down/unreachable\n * - DNS resolution failures (ENOTFOUND) when domain can't be resolved\n * - Timeouts (ETIMEDOUT) when request takes too long\n * - Protocol/transport layer errors like SSL/TLS issues\n */\nexport class CopilotKitLowLevelError extends CopilotKitError {\n constructor({\n error,\n url,\n message,\n }: {\n error: Error;\n url: string;\n message?: string;\n }) {\n let code = CopilotKitErrorCode.NETWORK_ERROR;\n\n // @ts-expect-error -- code may exist\n const errorCode = error.code as string;\n const errorMessage =\n message ?? resolveLowLevelErrorMessage({ errorCode, url });\n\n super({ message: errorMessage, code });\n\n this.name = ERROR_NAMES.COPILOT_KIT_LOW_LEVEL_ERROR;\n }\n}\n\n/**\n * Generic catch-all error handler for HTTP responses from the CopilotKit API where a status code is available.\n * Used when we receive an HTTP error status and wish to handle broad range of them\n *\n * This differs from CopilotKitLowLevelError in that:\n * - ResolvedCopilotKitError: Server was reached and returned an HTTP status\n * - CopilotKitLowLevelError: Error occurred before reaching server (e.g. network failure)\n *\n * @param status - The HTTP status code received from the API response\n * @param message - Optional error message to include\n * @param code - Optional specific CopilotKitErrorCode to override default behavior\n *\n * Default behavior:\n * - 400 Bad Request: Maps to CopilotKitApiDiscoveryError\n * - All other status codes: Maps to UNKNOWN error code if no specific code provided\n */\nexport class ResolvedCopilotKitError extends CopilotKitError {\n constructor({\n status,\n message,\n code,\n isRemoteEndpoint,\n url,\n }: {\n status: number;\n message?: string;\n code?: CopilotKitErrorCode;\n isRemoteEndpoint?: boolean;\n url?: string;\n }) {\n let resolvedCode = code;\n if (!resolvedCode) {\n switch (status) {\n case 400:\n throw new CopilotKitApiDiscoveryError({ message, url });\n case 404:\n throw isRemoteEndpoint\n ? new CopilotKitRemoteEndpointDiscoveryError({ message, url })\n : new CopilotKitApiDiscoveryError({ message, url });\n default:\n resolvedCode = CopilotKitErrorCode.UNKNOWN;\n break;\n }\n }\n\n super({ message, code: resolvedCode });\n this.name = ERROR_NAMES.RESOLVED_COPILOT_KIT_ERROR;\n }\n}\n\nexport class ConfigurationError extends CopilotKitError {\n constructor(message: string) {\n super({ message, code: CopilotKitErrorCode.CONFIGURATION_ERROR });\n this.name = ERROR_NAMES.CONFIGURATION_ERROR;\n this.severity = Severity.WARNING;\n }\n}\n\nexport class MissingPublicApiKeyError extends ConfigurationError {\n constructor(message: string) {\n super(message);\n this.name = ERROR_NAMES.MISSING_PUBLIC_API_KEY_ERROR;\n this.severity = Severity.CRITICAL;\n }\n}\n\nexport class UpgradeRequiredError extends ConfigurationError {\n constructor(message: string) {\n super(message);\n this.name = ERROR_NAMES.UPGRADE_REQUIRED_ERROR;\n this.severity = Severity.WARNING;\n }\n}\n\n/**\n * Checks if an error is already a structured CopilotKit error.\n * This utility centralizes the logic for detecting structured errors across the codebase.\n *\n * @param error - The error to check\n * @returns true if the error is already structured, false otherwise\n */\nexport function isStructuredCopilotKitError(error: any): boolean {\n return (\n error instanceof CopilotKitError ||\n error instanceof CopilotKitLowLevelError ||\n (error?.name && error.name.includes(\"CopilotKit\")) ||\n error?.extensions?.code !== undefined // Check if it has our structured error properties\n );\n}\n\n/**\n * Returns the error as-is if it's already structured, otherwise converts it using the provided converter function.\n * This utility centralizes the pattern of preserving structured errors while converting unstructured ones.\n *\n * @param error - The error to process\n * @param converter - Function to convert unstructured errors to structured ones\n * @returns The structured error\n */\nexport function ensureStructuredError<T extends CopilotKitError>(\n error: any,\n converter: (error: any) => T,\n): T | any {\n return isStructuredCopilotKitError(error) ? error : converter(error);\n}\n\ninterface VersionMismatchResponse {\n runtimeVersion?: string;\n runtimeClientGqlVersion: string;\n reactCoreVersion: string;\n}\n\nexport async function getPossibleVersionMismatch({\n runtimeVersion,\n runtimeClientGqlVersion,\n}: {\n runtimeVersion?: string;\n runtimeClientGqlVersion: string;\n}) {\n if (!runtimeVersion || runtimeVersion === \"\" || !runtimeClientGqlVersion)\n return;\n if (\n COPILOTKIT_VERSION !== runtimeVersion ||\n COPILOTKIT_VERSION !== runtimeClientGqlVersion ||\n runtimeVersion !== runtimeClientGqlVersion\n ) {\n return {\n runtimeVersion,\n runtimeClientGqlVersion,\n reactCoreVersion: COPILOTKIT_VERSION,\n message: getVersionMismatchErrorMessage({\n runtimeVersion,\n runtimeClientGqlVersion,\n reactCoreVersion: COPILOTKIT_VERSION,\n }),\n };\n }\n\n return;\n}\n\nconst resolveLowLevelErrorMessage = ({\n errorCode,\n url,\n}: {\n errorCode?: string;\n url: string;\n}) => {\n const troubleshootingLink =\n ERROR_CONFIG[CopilotKitErrorCode.NETWORK_ERROR].troubleshootingUrl;\n const genericMessage = (\n description = `Failed to fetch from url ${url}.`,\n ) => `${description}.\n\nPossible reasons:\n- -The server may have an error preventing it from returning a response (Check the server logs for more info).\n- -The server might be down or unreachable\n- -There might be a network issue (e.g., DNS failure, connection timeout) \n- -The URL might be incorrect\n- -The server is not running on the specified port\n\n${getSeeMoreMarkdown(troubleshootingLink)}`;\n\n if (url.includes(\"/info\"))\n return genericMessage(\n `Failed to fetch CopilotKit agents/action information from url ${url}.`,\n );\n if (url.includes(\"/actions/execute\"))\n return genericMessage(`Fetch call to ${url} to execute actions failed.`);\n if (url.includes(\"/agents/state\"))\n return genericMessage(`Fetch call to ${url} to get agent state failed.`);\n if (url.includes(\"/agents/execute\"))\n return genericMessage(`Fetch call to ${url} to execute agent(s) failed.`);\n\n switch (errorCode) {\n case \"ECONNREFUSED\":\n return `Connection to ${url} was refused. Ensure the server is running and accessible.\\n\\n${getSeeMoreMarkdown(troubleshootingLink)}`;\n case \"ENOTFOUND\":\n return `The server on ${url} could not be found. Check the URL or your network configuration.\\n\\n${getSeeMoreMarkdown(ERROR_CONFIG[CopilotKitErrorCode.NOT_FOUND].troubleshootingUrl)}`;\n case \"ETIMEDOUT\":\n return `The connection to ${url} timed out. The server might be overloaded or taking too long to respond.\\n\\n${getSeeMoreMarkdown(troubleshootingLink)}`;\n default:\n return;\n }\n};\n"],"mappings":";;;;AAGA,IAAY,8CAAL;AACL;AACA;AACA;;;AAGF,IAAY,4DAAL;AACL;AACA;AACA;AACA;;;AAGF,MAAa,cAAc;CACzB,eAAe;CACf,6BAA6B;CAC7B,yCACE;CACF,mCAAmC;CACnC,6BAA6B;CAC7B,oCAAoC;CACpC,4BAA4B;CAC5B,qBAAqB;CACrB,8BAA8B;CAC9B,wBAAwB;CACzB;AAGD,MAAa,qBAAqB;CAChC,YAAY;CACZ,YAAY;CACZ,YAAY;CACZ,YAAY;CACZ,YAAY;CACZ,YAAY;CACb;AAGD,MAAa,4BAA4B;AAEzC,IAAY,oEAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAGF,MAAM,WAAW;AAEjB,MAAM,sBAAsB,SAAiB,cAAc,KAAK,IAAI,KAAK;AAEzE,MAAa,eAAe;EACzB,oBAAoB,gBAAgB;EACnC,YAAY;EACZ,oBAAoB,GAAG,SAAS;EAChC,YAAY,gBAAgB;EAC5B,UAAU,SAAS;EACpB;EACA,oBAAoB,YAAY;EAC/B,YAAY;EACZ,oBAAoB,GAAG,SAAS;EAChC,YAAY,gBAAgB;EAC5B,UAAU,SAAS;EACpB;EACA,oBAAoB,kBAAkB;EACrC,YAAY;EACZ,oBAAoB,GAAG,SAAS;EAChC,YAAY,gBAAgB;EAC5B,UAAU,SAAS;EACpB;EACA,oBAAoB,gBAAgB;EACnC,YAAY;EACZ,oBAAoB,GAAG,SAAS;EAChC,YAAY,gBAAgB;EAC5B,UAAU,SAAS;EACpB;EACA,oBAAoB,4BAA4B;EAC/C,YAAY;EACZ,oBAAoB,GAAG,S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S,mBAAmB,CAClC,QAAO,eAAe,iBAAiB,IAAI,6BAA6B;AAC1E,KAAI,IAAI,SAAS,gBAAgB,CAC/B,QAAO,eAAe,iBAAiB,IAAI,6BAA6B;AAC1E,KAAI,IAAI,SAAS,kBAAkB,CACjC,QAAO,eAAe,iBAAiB,IAAI,8BAA8B;AAE3E,SAAQ,WAAR;EACE,KAAK,eACH,QAAO,iBAAiB,IAAI,gEAAgE,mBAAmB,oBAAoB;EACrI,KAAK,YACH,QAAO,iBAAiB,IAAI,uEAAuE,mBAAmB,aAAa,oBAAoB,WAAW,mBAAmB;EACvL,KAAK,YACH,QAAO,qBAAqB,IAAI,+EAA+E,mBAAmB,oBAAoB;EACxJ,QACE"}
@@ -0,0 +1,50 @@
1
+ const require_conditions = require('./conditions.cjs');
2
+ const require_console_styling = require('./console-styling.cjs');
3
+ const require_errors = require('./errors.cjs');
4
+ const require_json_schema = require('./json-schema.cjs');
5
+ const require_random_id = require('./random-id.cjs');
6
+ const require_requests = require('./requests.cjs');
7
+
8
+ //#region src/utils/index.ts
9
+ /**
10
+ * Safely parses a JSON string into an object
11
+ * @param json The JSON string to parse
12
+ * @param fallback Optional fallback value to return if parsing fails. If not provided or set to "unset", returns null
13
+ * @returns The parsed JSON object, or the fallback value (or null) if parsing fails
14
+ */
15
+ function parseJson(json, fallback = "unset") {
16
+ try {
17
+ return JSON.parse(json);
18
+ } catch (e) {
19
+ return fallback === "unset" ? null : fallback;
20
+ }
21
+ }
22
+ /**
23
+ * Maps an array of items to a new array, skipping items that throw errors during mapping
24
+ * @param items The array to map
25
+ * @param callback The mapping function to apply to each item
26
+ * @returns A new array containing only the successfully mapped items
27
+ */
28
+ function tryMap(items, callback) {
29
+ return items.reduce((acc, item, index, array) => {
30
+ try {
31
+ acc.push(callback(item, index, array));
32
+ } catch (error) {
33
+ console.error(error);
34
+ }
35
+ return acc;
36
+ }, []);
37
+ }
38
+ /**
39
+ * Checks if the current environment is macOS
40
+ * @returns {boolean} True if running on macOS, false otherwise
41
+ */
42
+ function isMacOS() {
43
+ return /Mac|iMac|Macintosh/i.test(navigator.userAgent);
44
+ }
45
+
46
+ //#endregion
47
+ exports.isMacOS = isMacOS;
48
+ exports.parseJson = parseJson;
49
+ exports.tryMap = tryMap;
50
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../../src/utils/index.ts"],"sourcesContent":["export * from \"./conditions\";\nexport * from \"./console-styling\";\nexport * from \"./errors\";\nexport * from \"./json-schema\";\nexport * from \"./types\";\nexport * from \"./random-id\";\nexport * from \"./requests\";\n\n/**\n * Safely parses a JSON string into an object\n * @param json The JSON string to parse\n * @param fallback Optional fallback value to return if parsing fails. If not provided or set to \"unset\", returns null\n * @returns The parsed JSON object, or the fallback value (or null) if parsing fails\n */\nexport function parseJson(json: string, fallback: any = \"unset\") {\n try {\n return JSON.parse(json);\n } catch (e) {\n return fallback === \"unset\" ? null : fallback;\n }\n}\n\n/**\n * Maps an array of items to a new array, skipping items that throw errors during mapping\n * @param items The array to map\n * @param callback The mapping function to apply to each item\n * @returns A new array containing only the successfully mapped items\n */\nexport function tryMap<TItem, TMapped>(\n items: TItem[],\n callback: (item: TItem, index: number, array: TItem[]) => TMapped,\n): TMapped[] {\n return items.reduce<TMapped[]>((acc, item, index, array) => {\n try {\n acc.push(callback(item, index, array));\n } catch (error) {\n console.error(error);\n }\n return acc;\n }, []);\n}\n\n/**\n * Checks if the current environment is macOS\n * @returns {boolean} True if running on macOS, false otherwise\n */\nexport function isMacOS(): boolean {\n return /Mac|iMac|Macintosh/i.test(navigator.userAgent);\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,SAAgB,UAAU,MAAc,WAAgB,SAAS;AAC/D,KAAI;AACF,SAAO,KAAK,MAAM,KAAK;UAChB,GAAG;AACV,SAAO,aAAa,UAAU,OAAO;;;;;;;;;AAUzC,SAAgB,OACd,OACA,UACW;AACX,QAAO,MAAM,QAAmB,KAAK,MAAM,OAAO,UAAU;AAC1D,MAAI;AACF,OAAI,KAAK,SAAS,MAAM,OAAO,MAAM,CAAC;WAC/B,OAAO;AACd,WAAQ,MAAM,MAAM;;AAEtB,SAAO;IACN,EAAE,CAAC;;;;;;AAOR,SAAgB,UAAmB;AACjC,QAAO,sBAAsB,KAAK,UAAU,UAAU"}
@@ -1,14 +1,12 @@
1
- export { BaseCondition, ComparisonCondition, ComparisonRule, Condition, ExistenceCondition, ExistenceRule, LogicalCondition, LogicalRule, Rule, executeConditions } from './conditions.js';
2
- export { ConsoleColors, ConsoleStyles, logCopilotKitPlatformMessage, logStyled, publicApiKeyRequired, styledConsole } from './console-styling.js';
3
- export { BANNER_ERROR_NAMES, COPILOT_CLOUD_ERROR_NAMES, ConfigurationError, CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitLowLevelError, CopilotKitMisuseError, CopilotKitRemoteEndpointDiscoveryError, CopilotKitVersionMismatchError, ERROR_CONFIG, ERROR_NAMES, ErrorVisibility, MissingPublicApiKeyError, ResolvedCopilotKitError, Severity, UpgradeRequiredError, ensureStructuredError, getPossibleVersionMismatch, isStructuredCopilotKitError } from './errors.js';
4
- export { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema, convertJsonSchemaToZodSchema, getZodParameters, jsonSchemaToActionParameters } from './json-schema.js';
5
- export { AgentDescription, MaybePromise, NonEmptyRecord, RuntimeInfo } from './types.js';
6
- export { dataToUUID, isValidUUID, randomId, randomUUID } from './random-id.js';
7
- export { readBody } from './requests.js';
8
- import 'graphql';
9
- import 'zod';
10
- import '../types/action.js';
1
+ import { BaseCondition, ComparisonCondition, ComparisonRule, Condition, ExistenceCondition, ExistenceRule, LogicalCondition, LogicalRule, Rule, executeConditions } from "./conditions.cjs";
2
+ import { ConsoleColors, ConsoleStyles, logCopilotKitPlatformMessage, logStyled, publicApiKeyRequired, styledConsole } from "./console-styling.cjs";
3
+ import { BANNER_ERROR_NAMES, COPILOT_CLOUD_ERROR_NAMES, ConfigurationError, CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitLowLevelError, CopilotKitMisuseError, CopilotKitRemoteEndpointDiscoveryError, CopilotKitVersionMismatchError, ERROR_CONFIG, ERROR_NAMES, ErrorVisibility, MissingPublicApiKeyError, ResolvedCopilotKitError, Severity, UpgradeRequiredError, ensureStructuredError, getPossibleVersionMismatch, isStructuredCopilotKitError } from "./errors.cjs";
4
+ import { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema, convertJsonSchemaToZodSchema, getZodParameters, jsonSchemaToActionParameters } from "./json-schema.cjs";
5
+ import { AgentDescription, MaybePromise, NonEmptyRecord, RuntimeInfo } from "./types.cjs";
6
+ import { dataToUUID, isValidUUID, randomId, randomUUID } from "./random-id.cjs";
7
+ import { readBody } from "./requests.cjs";
11
8
 
9
+ //#region src/utils/index.d.ts
12
10
  /**
13
11
  * Safely parses a JSON string into an object
14
12
  * @param json The JSON string to parse
@@ -28,5 +26,6 @@ declare function tryMap<TItem, TMapped>(items: TItem[], callback: (item: TItem,
28
26
  * @returns {boolean} True if running on macOS, false otherwise
29
27
  */
30
28
  declare function isMacOS(): boolean;
31
-
29
+ //#endregion
32
30
  export { isMacOS, parseJson, tryMap };
31
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/utils/index.ts"],"mappings":";;;;;;;;;;;AAcA;;;;iBAAgB,SAAA,CAAU,IAAA,UAAc,QAAA;AAcxC;;;;;;AAAA,iBAAgB,MAAA,gBAAA,CACd,KAAA,EAAO,KAAA,IACP,QAAA,GAAW,IAAA,EAAM,KAAA,EAAO,KAAA,UAAe,KAAA,EAAO,KAAA,OAAY,OAAA,GACzD,OAAA;;;;;iBAea,OAAA,CAAA"}