@copilotkit/shared 1.51.4 → 1.51.5-next.1

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 (256) hide show
  1. package/CHANGELOG.md +8 -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.cts +31 -0
  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 +17 -15
  131. package/src/types/message.ts +3 -1
  132. package/tsdown.config.ts +36 -0
  133. package/vitest.config.mjs +11 -0
  134. package/dist/chunk-2OJ5OJ2D.mjs +0 -1
  135. package/dist/chunk-2OJ5OJ2D.mjs.map +0 -1
  136. package/dist/chunk-3DK3UMRW.mjs +0 -217
  137. package/dist/chunk-3DK3UMRW.mjs.map +0 -1
  138. package/dist/chunk-6BE7PM2Q.mjs +0 -110
  139. package/dist/chunk-6BE7PM2Q.mjs.map +0 -1
  140. package/dist/chunk-BVVLGLFE.mjs +0 -435
  141. package/dist/chunk-BVVLGLFE.mjs.map +0 -1
  142. package/dist/chunk-FCCOSO5L.mjs +0 -1
  143. package/dist/chunk-FCCOSO5L.mjs.map +0 -1
  144. package/dist/chunk-GS5BLXSZ.mjs +0 -41
  145. package/dist/chunk-GS5BLXSZ.mjs.map +0 -1
  146. package/dist/chunk-HFJ7Q6KR.mjs +0 -38
  147. package/dist/chunk-HFJ7Q6KR.mjs.map +0 -1
  148. package/dist/chunk-IAFBVORQ.mjs +0 -1
  149. package/dist/chunk-IAFBVORQ.mjs.map +0 -1
  150. package/dist/chunk-M2RJI5BZ.mjs +0 -94
  151. package/dist/chunk-M2RJI5BZ.mjs.map +0 -1
  152. package/dist/chunk-MSUB6DGR.mjs +0 -1
  153. package/dist/chunk-MSUB6DGR.mjs.map +0 -1
  154. package/dist/chunk-N5EP5OD5.mjs +0 -1
  155. package/dist/chunk-N5EP5OD5.mjs.map +0 -1
  156. package/dist/chunk-NAFEBKSO.mjs +0 -1
  157. package/dist/chunk-NAFEBKSO.mjs.map +0 -1
  158. package/dist/chunk-P7STFMPO.mjs +0 -1
  159. package/dist/chunk-P7STFMPO.mjs.map +0 -1
  160. package/dist/chunk-UYARLQNA.mjs +0 -1
  161. package/dist/chunk-UYARLQNA.mjs.map +0 -1
  162. package/dist/chunk-V7BSERGI.mjs +0 -62
  163. package/dist/chunk-V7BSERGI.mjs.map +0 -1
  164. package/dist/chunk-WAZHII6M.mjs +0 -67
  165. package/dist/chunk-WAZHII6M.mjs.map +0 -1
  166. package/dist/chunk-XTHC46M2.mjs +0 -1
  167. package/dist/chunk-XTHC46M2.mjs.map +0 -1
  168. package/dist/chunk-ZIC6V6S5.mjs +0 -13
  169. package/dist/chunk-ZIC6V6S5.mjs.map +0 -1
  170. package/dist/chunk-ZUE2VR7D.mjs +0 -38
  171. package/dist/chunk-ZUE2VR7D.mjs.map +0 -1
  172. package/dist/constants/index.js +0 -40
  173. package/dist/constants/index.js.map +0 -1
  174. package/dist/index.d.ts +0 -25
  175. package/dist/index.js +0 -1138
  176. package/dist/index.js.map +0 -1
  177. package/dist/telemetry/events.d.ts +0 -45
  178. package/dist/telemetry/events.js +0 -19
  179. package/dist/telemetry/events.js.map +0 -1
  180. package/dist/telemetry/events.mjs +0 -1
  181. package/dist/telemetry/events.mjs.map +0 -1
  182. package/dist/telemetry/index.d.ts +0 -3
  183. package/dist/telemetry/index.js +0 -191
  184. package/dist/telemetry/index.js.map +0 -1
  185. package/dist/telemetry/index.mjs +0 -12
  186. package/dist/telemetry/index.mjs.map +0 -1
  187. package/dist/telemetry/scarf-client.d.ts +0 -7
  188. package/dist/telemetry/scarf-client.js +0 -59
  189. package/dist/telemetry/scarf-client.js.map +0 -1
  190. package/dist/telemetry/security-check.d.ts +0 -2
  191. package/dist/telemetry/security-check.js +0 -2
  192. package/dist/telemetry/security-check.js.map +0 -1
  193. package/dist/telemetry/security-check.mjs +0 -1
  194. package/dist/telemetry/security-check.mjs.map +0 -1
  195. package/dist/telemetry/telemetry-client.d.ts +0 -40
  196. package/dist/telemetry/telemetry-client.js +0 -189
  197. package/dist/telemetry/telemetry-client.js.map +0 -1
  198. package/dist/telemetry/utils.d.ts +0 -8
  199. package/dist/telemetry/utils.js +0 -73
  200. package/dist/telemetry/utils.js.map +0 -1
  201. package/dist/types/action.js +0 -19
  202. package/dist/types/action.js.map +0 -1
  203. package/dist/types/action.mjs +0 -2
  204. package/dist/types/action.mjs.map +0 -1
  205. package/dist/types/copilot-cloud-config.d.ts +0 -13
  206. package/dist/types/copilot-cloud-config.js +0 -19
  207. package/dist/types/copilot-cloud-config.js.map +0 -1
  208. package/dist/types/copilot-cloud-config.mjs +0 -2
  209. package/dist/types/copilot-cloud-config.mjs.map +0 -1
  210. package/dist/types/error.d.ts +0 -55
  211. package/dist/types/error.js +0 -19
  212. package/dist/types/error.js.map +0 -1
  213. package/dist/types/error.mjs +0 -2
  214. package/dist/types/error.mjs.map +0 -1
  215. package/dist/types/index.d.ts +0 -7
  216. package/dist/types/index.js +0 -19
  217. package/dist/types/index.js.map +0 -1
  218. package/dist/types/index.mjs +0 -8
  219. package/dist/types/index.mjs.map +0 -1
  220. package/dist/types/message.d.ts +0 -28
  221. package/dist/types/message.js +0 -19
  222. package/dist/types/message.js.map +0 -1
  223. package/dist/types/message.mjs +0 -2
  224. package/dist/types/message.mjs.map +0 -1
  225. package/dist/types/openai-assistant.d.ts +0 -53
  226. package/dist/types/openai-assistant.js +0 -19
  227. package/dist/types/openai-assistant.js.map +0 -1
  228. package/dist/types/openai-assistant.mjs +0 -2
  229. package/dist/types/openai-assistant.mjs.map +0 -1
  230. package/dist/types/utility.d.ts +0 -6
  231. package/dist/types/utility.js +0 -19
  232. package/dist/types/utility.js.map +0 -1
  233. package/dist/types/utility.mjs +0 -2
  234. package/dist/types/utility.mjs.map +0 -1
  235. package/dist/utils/conditions.js +0 -86
  236. package/dist/utils/conditions.js.map +0 -1
  237. package/dist/utils/console-styling.d.ts +0 -84
  238. package/dist/utils/console-styling.js +0 -123
  239. package/dist/utils/console-styling.js.map +0 -1
  240. package/dist/utils/errors.js +0 -452
  241. package/dist/utils/errors.js.map +0 -1
  242. package/dist/utils/index.js +0 -964
  243. package/dist/utils/index.js.map +0 -1
  244. package/dist/utils/json-schema.js +0 -244
  245. package/dist/utils/json-schema.js.map +0 -1
  246. package/dist/utils/random-id.js +0 -68
  247. package/dist/utils/random-id.js.map +0 -1
  248. package/dist/utils/requests.js +0 -91
  249. package/dist/utils/requests.js.map +0 -1
  250. package/dist/utils/types.js +0 -19
  251. package/dist/utils/types.js.map +0 -1
  252. package/dist/utils/types.mjs +0 -2
  253. package/dist/utils/types.mjs.map +0 -1
  254. package/jest.config.js +0 -5
  255. package/rollup.config.mjs +0 -54
  256. package/tsup.config.ts +0 -15
package/dist/index.js DELETED
@@ -1,1138 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
33
- BANNER_ERROR_NAMES: () => BANNER_ERROR_NAMES,
34
- COPILOTKIT_VERSION: () => COPILOTKIT_VERSION,
35
- COPILOT_CLOUD_API_URL: () => COPILOT_CLOUD_API_URL,
36
- COPILOT_CLOUD_CHAT_URL: () => COPILOT_CLOUD_CHAT_URL,
37
- COPILOT_CLOUD_ERROR_NAMES: () => COPILOT_CLOUD_ERROR_NAMES,
38
- COPILOT_CLOUD_PUBLIC_API_KEY_HEADER: () => COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,
39
- COPILOT_CLOUD_VERSION: () => COPILOT_CLOUD_VERSION,
40
- ConfigurationError: () => ConfigurationError,
41
- ConsoleColors: () => ConsoleColors,
42
- ConsoleStyles: () => ConsoleStyles,
43
- CopilotKitAgentDiscoveryError: () => CopilotKitAgentDiscoveryError,
44
- CopilotKitApiDiscoveryError: () => CopilotKitApiDiscoveryError,
45
- CopilotKitError: () => CopilotKitError,
46
- CopilotKitErrorCode: () => CopilotKitErrorCode,
47
- CopilotKitLowLevelError: () => CopilotKitLowLevelError,
48
- CopilotKitMisuseError: () => CopilotKitMisuseError,
49
- CopilotKitRemoteEndpointDiscoveryError: () => CopilotKitRemoteEndpointDiscoveryError,
50
- CopilotKitVersionMismatchError: () => CopilotKitVersionMismatchError,
51
- ERROR_CONFIG: () => ERROR_CONFIG,
52
- ERROR_NAMES: () => ERROR_NAMES,
53
- ErrorVisibility: () => ErrorVisibility,
54
- MissingPublicApiKeyError: () => MissingPublicApiKeyError,
55
- ResolvedCopilotKitError: () => ResolvedCopilotKitError,
56
- Severity: () => Severity,
57
- TelemetryClient: () => TelemetryClient,
58
- UpgradeRequiredError: () => UpgradeRequiredError,
59
- actionParametersToJsonSchema: () => actionParametersToJsonSchema,
60
- convertJsonSchemaToZodSchema: () => convertJsonSchemaToZodSchema,
61
- dataToUUID: () => dataToUUID,
62
- ensureStructuredError: () => ensureStructuredError,
63
- executeConditions: () => executeConditions,
64
- getPossibleVersionMismatch: () => getPossibleVersionMismatch,
65
- getZodParameters: () => getZodParameters,
66
- isMacOS: () => isMacOS,
67
- isStructuredCopilotKitError: () => isStructuredCopilotKitError,
68
- isTelemetryDisabled: () => isTelemetryDisabled,
69
- isValidUUID: () => isValidUUID,
70
- jsonSchemaToActionParameters: () => jsonSchemaToActionParameters,
71
- logCopilotKitPlatformMessage: () => logCopilotKitPlatformMessage,
72
- logStyled: () => logStyled,
73
- parseJson: () => parseJson,
74
- publicApiKeyRequired: () => publicApiKeyRequired,
75
- randomId: () => randomId,
76
- randomUUID: () => randomUUID,
77
- readBody: () => readBody,
78
- styledConsole: () => styledConsole,
79
- tryMap: () => tryMap
80
- });
81
- module.exports = __toCommonJS(src_exports);
82
-
83
- // src/utils/conditions.ts
84
- function executeConditions({
85
- conditions,
86
- value
87
- }) {
88
- if (!(conditions == null ? void 0 : conditions.length))
89
- return true;
90
- return conditions.every((condition) => executeCondition(condition, value));
91
- }
92
- function executeCondition(condition, value) {
93
- const targetValue = condition.path ? getValueFromPath(value, condition.path) : value;
94
- switch (condition.rule) {
95
- case "AND":
96
- return condition.conditions.every(
97
- (c) => executeCondition(c, value)
98
- );
99
- case "OR":
100
- return condition.conditions.some(
101
- (c) => executeCondition(c, value)
102
- );
103
- case "NOT":
104
- return !condition.conditions.every(
105
- (c) => executeCondition(c, value)
106
- );
107
- case "EQUALS":
108
- return targetValue === condition.value;
109
- case "NOT_EQUALS":
110
- return targetValue !== condition.value;
111
- case "GREATER_THAN":
112
- return targetValue > condition.value;
113
- case "LESS_THAN":
114
- return targetValue < condition.value;
115
- case "CONTAINS":
116
- return Array.isArray(targetValue) && targetValue.includes(condition.value);
117
- case "NOT_CONTAINS":
118
- return Array.isArray(targetValue) && !targetValue.includes(condition.value);
119
- case "MATCHES":
120
- return new RegExp(condition.value).test(
121
- String(targetValue)
122
- );
123
- case "STARTS_WITH":
124
- return String(targetValue).startsWith(
125
- condition.value
126
- );
127
- case "ENDS_WITH":
128
- return String(targetValue).endsWith(
129
- condition.value
130
- );
131
- case "EXISTS":
132
- return targetValue !== void 0 && targetValue !== null;
133
- case "NOT_EXISTS":
134
- return targetValue === void 0 || targetValue === null;
135
- }
136
- }
137
- function getValueFromPath(obj, path) {
138
- return path.split(".").reduce((acc, part) => acc == null ? void 0 : acc[part], obj);
139
- }
140
-
141
- // src/utils/console-styling.ts
142
- var ConsoleColors = {
143
- /** Primary brand blue - for titles and links */
144
- primary: "#007acc",
145
- /** Success green - for positive messaging */
146
- success: "#22c55e",
147
- /** Purple - for feature highlights */
148
- feature: "#a855f7",
149
- /** Red - for calls-to-action */
150
- cta: "#ef4444",
151
- /** Cyan - for closing statements */
152
- info: "#06b6d4",
153
- /** Inherit console default - for body text */
154
- inherit: "inherit",
155
- /** Warning style */
156
- warning: "#f59e0b"
157
- };
158
- var ConsoleStyles = {
159
- /** Large header style */
160
- header: `color: ${ConsoleColors.warning}; font-weight: bold; font-size: 16px;`,
161
- /** Section header style */
162
- section: `color: ${ConsoleColors.success}; font-weight: bold;`,
163
- /** Feature highlight style */
164
- highlight: `color: ${ConsoleColors.feature}; font-weight: bold;`,
165
- /** Call-to-action style */
166
- cta: `color: ${ConsoleColors.success}; font-weight: bold;`,
167
- /** Info style */
168
- info: `color: ${ConsoleColors.info}; font-weight: bold;`,
169
- /** Link style */
170
- link: `color: ${ConsoleColors.primary}; text-decoration: underline;`,
171
- /** Body text - inherits console theme */
172
- body: `color: ${ConsoleColors.inherit};`,
173
- /** Warning style */
174
- warning: `color: ${ConsoleColors.cta}; font-weight: bold;`
175
- };
176
- function logCopilotKitPlatformMessage() {
177
- console.log(
178
- `%cCopilotKit Warning%c
179
-
180
- useCopilotChatHeadless_c provides full compatibility with CopilotKit's newly released Headless UI feature set. To enable this premium feature, add your public license key, available for free at:
181
-
182
- %chttps://cloud.copilotkit.ai%c
183
-
184
- Alternatively, useCopilotChat is available for basic programmatic control, and does not require an API key.
185
-
186
- To learn more about premium features, read the documentation here:
187
-
188
- %chttps://docs.copilotkit.ai/premium%c`,
189
- ConsoleStyles.header,
190
- ConsoleStyles.body,
191
- ConsoleStyles.cta,
192
- ConsoleStyles.body,
193
- ConsoleStyles.link,
194
- ConsoleStyles.body
195
- );
196
- }
197
- function publicApiKeyRequired(feature) {
198
- console.log(
199
- `
200
- %cCopilotKit Warning%c
201
-
202
- In order to use ${feature}, you need to add your CopilotKit API key, available for free at https://cloud.copilotkit.ai.
203
- `.trim(),
204
- ConsoleStyles.header,
205
- ConsoleStyles.body
206
- );
207
- }
208
- function logStyled(template, styles) {
209
- console.log(template, ...styles);
210
- }
211
- var styledConsole = {
212
- /** Log a success message */
213
- success: (message) => logStyled(`%c\u2705 ${message}`, [ConsoleStyles.section]),
214
- /** Log an info message */
215
- info: (message) => logStyled(`%c\u2139\uFE0F ${message}`, [ConsoleStyles.info]),
216
- /** Log a feature highlight */
217
- feature: (message) => logStyled(`%c\u2728 ${message}`, [ConsoleStyles.highlight]),
218
- /** Log a call-to-action */
219
- cta: (message) => logStyled(`%c\u{1F680} ${message}`, [ConsoleStyles.cta]),
220
- /** Log the CopilotKit platform promotion */
221
- logCopilotKitPlatformMessage,
222
- /** Log a `publicApiKeyRequired` warning */
223
- publicApiKeyRequired
224
- };
225
-
226
- // src/utils/errors.ts
227
- var import_graphql = require("graphql");
228
- var Severity = /* @__PURE__ */ ((Severity2) => {
229
- Severity2["CRITICAL"] = "critical";
230
- Severity2["WARNING"] = "warning";
231
- Severity2["INFO"] = "info";
232
- return Severity2;
233
- })(Severity || {});
234
- var ErrorVisibility = /* @__PURE__ */ ((ErrorVisibility2) => {
235
- ErrorVisibility2["BANNER"] = "banner";
236
- ErrorVisibility2["TOAST"] = "toast";
237
- ErrorVisibility2["SILENT"] = "silent";
238
- ErrorVisibility2["DEV_ONLY"] = "dev_only";
239
- return ErrorVisibility2;
240
- })(ErrorVisibility || {});
241
- var ERROR_NAMES = {
242
- COPILOT_ERROR: "CopilotError",
243
- COPILOT_API_DISCOVERY_ERROR: "CopilotApiDiscoveryError",
244
- COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR: "CopilotKitRemoteEndpointDiscoveryError",
245
- COPILOT_KIT_AGENT_DISCOVERY_ERROR: "CopilotKitAgentDiscoveryError",
246
- COPILOT_KIT_LOW_LEVEL_ERROR: "CopilotKitLowLevelError",
247
- COPILOT_KIT_VERSION_MISMATCH_ERROR: "CopilotKitVersionMismatchError",
248
- RESOLVED_COPILOT_KIT_ERROR: "ResolvedCopilotKitError",
249
- CONFIGURATION_ERROR: "ConfigurationError",
250
- MISSING_PUBLIC_API_KEY_ERROR: "MissingPublicApiKeyError",
251
- UPGRADE_REQUIRED_ERROR: "UpgradeRequiredError"
252
- };
253
- var BANNER_ERROR_NAMES = [
254
- ERROR_NAMES.CONFIGURATION_ERROR,
255
- ERROR_NAMES.MISSING_PUBLIC_API_KEY_ERROR,
256
- ERROR_NAMES.UPGRADE_REQUIRED_ERROR,
257
- ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR,
258
- ERROR_NAMES.COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR,
259
- ERROR_NAMES.COPILOT_KIT_AGENT_DISCOVERY_ERROR
260
- ];
261
- var COPILOT_CLOUD_ERROR_NAMES = BANNER_ERROR_NAMES;
262
- var CopilotKitErrorCode = /* @__PURE__ */ ((CopilotKitErrorCode2) => {
263
- CopilotKitErrorCode2["NETWORK_ERROR"] = "NETWORK_ERROR";
264
- CopilotKitErrorCode2["NOT_FOUND"] = "NOT_FOUND";
265
- CopilotKitErrorCode2["AGENT_NOT_FOUND"] = "AGENT_NOT_FOUND";
266
- CopilotKitErrorCode2["API_NOT_FOUND"] = "API_NOT_FOUND";
267
- CopilotKitErrorCode2["REMOTE_ENDPOINT_NOT_FOUND"] = "REMOTE_ENDPOINT_NOT_FOUND";
268
- CopilotKitErrorCode2["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
269
- CopilotKitErrorCode2["MISUSE"] = "MISUSE";
270
- CopilotKitErrorCode2["UNKNOWN"] = "UNKNOWN";
271
- CopilotKitErrorCode2["VERSION_MISMATCH"] = "VERSION_MISMATCH";
272
- CopilotKitErrorCode2["CONFIGURATION_ERROR"] = "CONFIGURATION_ERROR";
273
- CopilotKitErrorCode2["MISSING_PUBLIC_API_KEY_ERROR"] = "MISSING_PUBLIC_API_KEY_ERROR";
274
- CopilotKitErrorCode2["UPGRADE_REQUIRED_ERROR"] = "UPGRADE_REQUIRED_ERROR";
275
- return CopilotKitErrorCode2;
276
- })(CopilotKitErrorCode || {});
277
- var BASE_URL = "https://docs.copilotkit.ai";
278
- var getSeeMoreMarkdown = (link) => `See more: [${link}](${link})`;
279
- var ERROR_CONFIG = {
280
- ["NETWORK_ERROR" /* NETWORK_ERROR */]: {
281
- statusCode: 503,
282
- troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-a-network-errors--api-not-found`,
283
- visibility: "banner" /* BANNER */,
284
- severity: "critical" /* CRITICAL */
285
- },
286
- ["NOT_FOUND" /* NOT_FOUND */]: {
287
- statusCode: 404,
288
- troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-a-network-errors--api-not-found`,
289
- visibility: "banner" /* BANNER */,
290
- severity: "critical" /* CRITICAL */
291
- },
292
- ["AGENT_NOT_FOUND" /* AGENT_NOT_FOUND */]: {
293
- statusCode: 500,
294
- troubleshootingUrl: `${BASE_URL}/coagents/troubleshooting/common-issues#i-am-getting-agent-not-found-error`,
295
- visibility: "banner" /* BANNER */,
296
- severity: "critical" /* CRITICAL */
297
- },
298
- ["API_NOT_FOUND" /* API_NOT_FOUND */]: {
299
- statusCode: 404,
300
- troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-a-network-errors--api-not-found`,
301
- visibility: "banner" /* BANNER */,
302
- severity: "critical" /* CRITICAL */
303
- },
304
- ["REMOTE_ENDPOINT_NOT_FOUND" /* REMOTE_ENDPOINT_NOT_FOUND */]: {
305
- statusCode: 404,
306
- troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#i-am-getting-copilotkits-remote-endpoint-not-found-error`,
307
- visibility: "banner" /* BANNER */,
308
- severity: "critical" /* CRITICAL */
309
- },
310
- ["AUTHENTICATION_ERROR" /* AUTHENTICATION_ERROR */]: {
311
- statusCode: 401,
312
- troubleshootingUrl: `${BASE_URL}/troubleshooting/common-issues#authentication-errors`,
313
- visibility: "banner" /* BANNER */,
314
- severity: "critical" /* CRITICAL */
315
- },
316
- ["MISUSE" /* MISUSE */]: {
317
- statusCode: 400,
318
- troubleshootingUrl: null,
319
- visibility: "dev_only" /* DEV_ONLY */,
320
- severity: "warning" /* WARNING */
321
- },
322
- ["UNKNOWN" /* UNKNOWN */]: {
323
- statusCode: 500,
324
- visibility: "toast" /* TOAST */,
325
- severity: "critical" /* CRITICAL */
326
- },
327
- ["CONFIGURATION_ERROR" /* CONFIGURATION_ERROR */]: {
328
- statusCode: 400,
329
- troubleshootingUrl: null,
330
- severity: "warning" /* WARNING */,
331
- visibility: "banner" /* BANNER */
332
- },
333
- ["MISSING_PUBLIC_API_KEY_ERROR" /* MISSING_PUBLIC_API_KEY_ERROR */]: {
334
- statusCode: 400,
335
- troubleshootingUrl: null,
336
- severity: "critical" /* CRITICAL */,
337
- visibility: "banner" /* BANNER */
338
- },
339
- ["UPGRADE_REQUIRED_ERROR" /* UPGRADE_REQUIRED_ERROR */]: {
340
- statusCode: 402,
341
- troubleshootingUrl: null,
342
- severity: "warning" /* WARNING */,
343
- visibility: "banner" /* BANNER */
344
- },
345
- ["VERSION_MISMATCH" /* VERSION_MISMATCH */]: {
346
- statusCode: 400,
347
- troubleshootingUrl: null,
348
- visibility: "dev_only" /* DEV_ONLY */,
349
- severity: "info" /* INFO */
350
- }
351
- };
352
- var CopilotKitError = class extends import_graphql.GraphQLError {
353
- constructor({
354
- message = "Unknown error occurred",
355
- code,
356
- severity,
357
- visibility
358
- }) {
359
- const name = ERROR_NAMES.COPILOT_ERROR;
360
- const config = ERROR_CONFIG[code];
361
- const { statusCode } = config;
362
- const resolvedVisibility = visibility ?? config.visibility ?? "toast" /* TOAST */;
363
- const resolvedSeverity = severity ?? ("severity" in config ? config.severity : void 0);
364
- super(message, {
365
- extensions: {
366
- name,
367
- statusCode,
368
- code,
369
- visibility: resolvedVisibility,
370
- severity: resolvedSeverity,
371
- troubleshootingUrl: "troubleshootingUrl" in config ? config.troubleshootingUrl : null,
372
- originalError: {
373
- message,
374
- stack: new Error().stack
375
- }
376
- }
377
- });
378
- this.code = code;
379
- this.name = name;
380
- this.statusCode = statusCode;
381
- this.severity = resolvedSeverity;
382
- this.visibility = resolvedVisibility;
383
- }
384
- };
385
- var CopilotKitMisuseError = class extends CopilotKitError {
386
- constructor({
387
- message,
388
- code = "MISUSE" /* MISUSE */
389
- }) {
390
- const docsLink = "troubleshootingUrl" in ERROR_CONFIG[code] && ERROR_CONFIG[code].troubleshootingUrl ? getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl) : null;
391
- const finalMessage = docsLink ? `${message}.
392
-
393
- ${docsLink}` : message;
394
- super({ message: finalMessage, code });
395
- this.name = ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR;
396
- }
397
- };
398
- var getVersionMismatchErrorMessage = ({
399
- reactCoreVersion,
400
- runtimeVersion,
401
- runtimeClientGqlVersion
402
- }) => `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.`;
403
- var CopilotKitVersionMismatchError = class extends CopilotKitError {
404
- constructor({
405
- reactCoreVersion,
406
- runtimeVersion,
407
- runtimeClientGqlVersion
408
- }) {
409
- const code = "VERSION_MISMATCH" /* VERSION_MISMATCH */;
410
- super({
411
- message: getVersionMismatchErrorMessage({
412
- reactCoreVersion,
413
- runtimeVersion,
414
- runtimeClientGqlVersion
415
- }),
416
- code
417
- });
418
- this.name = ERROR_NAMES.COPILOT_KIT_VERSION_MISMATCH_ERROR;
419
- }
420
- };
421
- var CopilotKitApiDiscoveryError = class extends CopilotKitError {
422
- constructor(params = {}) {
423
- const url = params.url ?? "";
424
- let operationSuffix = "";
425
- if (url == null ? void 0 : url.includes("/info"))
426
- operationSuffix = `when fetching CopilotKit info`;
427
- else if (url.includes("/actions/execute"))
428
- operationSuffix = `when attempting to execute actions.`;
429
- else if (url.includes("/agents/state"))
430
- operationSuffix = `when attempting to get agent state.`;
431
- else if (url.includes("/agents/execute"))
432
- operationSuffix = `when attempting to execute agent(s).`;
433
- const message = params.message ?? (params.url ? `Failed to find CopilotKit API endpoint at url ${params.url} ${operationSuffix}` : `Failed to find CopilotKit API endpoint.`);
434
- const code = params.code ?? "API_NOT_FOUND" /* API_NOT_FOUND */;
435
- const errorMessage = `${message}.
436
-
437
- ${getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl)}`;
438
- super({ message: errorMessage, code });
439
- this.name = ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR;
440
- }
441
- };
442
- var CopilotKitRemoteEndpointDiscoveryError = class extends CopilotKitApiDiscoveryError {
443
- constructor(params) {
444
- const message = (params == null ? void 0 : params.message) ?? ((params == null ? void 0 : params.url) ? `Failed to find or contact remote endpoint at url ${params.url}` : "Failed to find or contact remote endpoint");
445
- const code = "REMOTE_ENDPOINT_NOT_FOUND" /* REMOTE_ENDPOINT_NOT_FOUND */;
446
- super({ message, code });
447
- this.name = ERROR_NAMES.COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR;
448
- }
449
- };
450
- var CopilotKitAgentDiscoveryError = class extends CopilotKitError {
451
- constructor(params) {
452
- const { agentName, availableAgents } = params;
453
- const code = "AGENT_NOT_FOUND" /* AGENT_NOT_FOUND */;
454
- const seeMore = getSeeMoreMarkdown(ERROR_CONFIG[code].troubleshootingUrl);
455
- let message;
456
- if (availableAgents.length) {
457
- const agentList = availableAgents.map((agent) => agent.name).join(", ");
458
- if (agentName) {
459
- 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.
460
-
461
- ${seeMore}`;
462
- } else {
463
- 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.
464
-
465
- ${seeMore}`;
466
- }
467
- } else {
468
- message = `${agentName ? `Agent '${agentName}'` : "The requested agent"} was not found. Please set up at least one agent before proceeding. ${seeMore}`;
469
- }
470
- super({ message, code });
471
- this.name = ERROR_NAMES.COPILOT_KIT_AGENT_DISCOVERY_ERROR;
472
- }
473
- };
474
- var CopilotKitLowLevelError = class extends CopilotKitError {
475
- constructor({
476
- error,
477
- url,
478
- message
479
- }) {
480
- let code = "NETWORK_ERROR" /* NETWORK_ERROR */;
481
- const errorCode = error.code;
482
- const errorMessage = message ?? resolveLowLevelErrorMessage({ errorCode, url });
483
- super({ message: errorMessage, code });
484
- this.name = ERROR_NAMES.COPILOT_KIT_LOW_LEVEL_ERROR;
485
- }
486
- };
487
- var ResolvedCopilotKitError = class extends CopilotKitError {
488
- constructor({
489
- status,
490
- message,
491
- code,
492
- isRemoteEndpoint,
493
- url
494
- }) {
495
- let resolvedCode = code;
496
- if (!resolvedCode) {
497
- switch (status) {
498
- case 400:
499
- throw new CopilotKitApiDiscoveryError({ message, url });
500
- case 404:
501
- throw isRemoteEndpoint ? new CopilotKitRemoteEndpointDiscoveryError({ message, url }) : new CopilotKitApiDiscoveryError({ message, url });
502
- default:
503
- resolvedCode = "UNKNOWN" /* UNKNOWN */;
504
- break;
505
- }
506
- }
507
- super({ message, code: resolvedCode });
508
- this.name = ERROR_NAMES.RESOLVED_COPILOT_KIT_ERROR;
509
- }
510
- };
511
- var ConfigurationError = class extends CopilotKitError {
512
- constructor(message) {
513
- super({ message, code: "CONFIGURATION_ERROR" /* CONFIGURATION_ERROR */ });
514
- this.name = ERROR_NAMES.CONFIGURATION_ERROR;
515
- this.severity = "warning" /* WARNING */;
516
- }
517
- };
518
- var MissingPublicApiKeyError = class extends ConfigurationError {
519
- constructor(message) {
520
- super(message);
521
- this.name = ERROR_NAMES.MISSING_PUBLIC_API_KEY_ERROR;
522
- this.severity = "critical" /* CRITICAL */;
523
- }
524
- };
525
- var UpgradeRequiredError = class extends ConfigurationError {
526
- constructor(message) {
527
- super(message);
528
- this.name = ERROR_NAMES.UPGRADE_REQUIRED_ERROR;
529
- this.severity = "warning" /* WARNING */;
530
- }
531
- };
532
- function isStructuredCopilotKitError(error) {
533
- var _a;
534
- return error instanceof CopilotKitError || error instanceof CopilotKitLowLevelError || (error == null ? void 0 : error.name) && error.name.includes("CopilotKit") || ((_a = error == null ? void 0 : error.extensions) == null ? void 0 : _a.code) !== void 0;
535
- }
536
- function ensureStructuredError(error, converter) {
537
- return isStructuredCopilotKitError(error) ? error : converter(error);
538
- }
539
- async function getPossibleVersionMismatch({
540
- runtimeVersion,
541
- runtimeClientGqlVersion
542
- }) {
543
- if (!runtimeVersion || runtimeVersion === "" || !runtimeClientGqlVersion)
544
- return;
545
- if (COPILOTKIT_VERSION !== runtimeVersion || COPILOTKIT_VERSION !== runtimeClientGqlVersion || runtimeVersion !== runtimeClientGqlVersion) {
546
- return {
547
- runtimeVersion,
548
- runtimeClientGqlVersion,
549
- reactCoreVersion: COPILOTKIT_VERSION,
550
- message: getVersionMismatchErrorMessage({
551
- runtimeVersion,
552
- runtimeClientGqlVersion,
553
- reactCoreVersion: COPILOTKIT_VERSION
554
- })
555
- };
556
- }
557
- return;
558
- }
559
- var resolveLowLevelErrorMessage = ({
560
- errorCode,
561
- url
562
- }) => {
563
- const troubleshootingLink = ERROR_CONFIG["NETWORK_ERROR" /* NETWORK_ERROR */].troubleshootingUrl;
564
- const genericMessage = (description = `Failed to fetch from url ${url}.`) => `${description}.
565
-
566
- Possible reasons:
567
- - -The server may have an error preventing it from returning a response (Check the server logs for more info).
568
- - -The server might be down or unreachable
569
- - -There might be a network issue (e.g., DNS failure, connection timeout)
570
- - -The URL might be incorrect
571
- - -The server is not running on the specified port
572
-
573
- ${getSeeMoreMarkdown(troubleshootingLink)}`;
574
- if (url.includes("/info"))
575
- return genericMessage(
576
- `Failed to fetch CopilotKit agents/action information from url ${url}.`
577
- );
578
- if (url.includes("/actions/execute"))
579
- return genericMessage(`Fetch call to ${url} to execute actions failed.`);
580
- if (url.includes("/agents/state"))
581
- return genericMessage(`Fetch call to ${url} to get agent state failed.`);
582
- if (url.includes("/agents/execute"))
583
- return genericMessage(`Fetch call to ${url} to execute agent(s) failed.`);
584
- switch (errorCode) {
585
- case "ECONNREFUSED":
586
- return `Connection to ${url} was refused. Ensure the server is running and accessible.
587
-
588
- ${getSeeMoreMarkdown(troubleshootingLink)}`;
589
- case "ENOTFOUND":
590
- return `The server on ${url} could not be found. Check the URL or your network configuration.
591
-
592
- ${getSeeMoreMarkdown(ERROR_CONFIG["NOT_FOUND" /* NOT_FOUND */].troubleshootingUrl)}`;
593
- case "ETIMEDOUT":
594
- return `The connection to ${url} timed out. The server might be overloaded or taking too long to respond.
595
-
596
- ${getSeeMoreMarkdown(troubleshootingLink)}`;
597
- default:
598
- return;
599
- }
600
- };
601
-
602
- // src/utils/json-schema.ts
603
- var import_zod = require("zod");
604
- function actionParametersToJsonSchema(actionParameters) {
605
- let parameters = {};
606
- for (let parameter of actionParameters || []) {
607
- parameters[parameter.name] = convertAttribute(parameter);
608
- }
609
- let requiredParameterNames = [];
610
- for (let arg of actionParameters || []) {
611
- if (arg.required !== false) {
612
- requiredParameterNames.push(arg.name);
613
- }
614
- }
615
- return {
616
- type: "object",
617
- properties: parameters,
618
- required: requiredParameterNames
619
- };
620
- }
621
- function jsonSchemaToActionParameters(jsonSchema) {
622
- if (jsonSchema.type !== "object" || !jsonSchema.properties) {
623
- return [];
624
- }
625
- const parameters = [];
626
- const requiredFields = jsonSchema.required || [];
627
- for (const [name, schema] of Object.entries(jsonSchema.properties)) {
628
- const parameter = convertJsonSchemaToParameter(
629
- name,
630
- schema,
631
- requiredFields.includes(name)
632
- );
633
- parameters.push(parameter);
634
- }
635
- return parameters;
636
- }
637
- function convertJsonSchemaToParameter(name, schema, isRequired) {
638
- const baseParameter = {
639
- name,
640
- description: schema.description
641
- };
642
- if (!isRequired) {
643
- baseParameter.required = false;
644
- }
645
- switch (schema.type) {
646
- case "string":
647
- return {
648
- ...baseParameter,
649
- type: "string",
650
- ...schema.enum && { enum: schema.enum }
651
- };
652
- case "number":
653
- case "boolean":
654
- return {
655
- ...baseParameter,
656
- type: schema.type
657
- };
658
- case "object":
659
- if (schema.properties) {
660
- const attributes = [];
661
- const requiredFields = schema.required || [];
662
- for (const [propName, propSchema] of Object.entries(
663
- schema.properties
664
- )) {
665
- attributes.push(
666
- convertJsonSchemaToParameter(
667
- propName,
668
- propSchema,
669
- requiredFields.includes(propName)
670
- )
671
- );
672
- }
673
- return {
674
- ...baseParameter,
675
- type: "object",
676
- attributes
677
- };
678
- }
679
- return {
680
- ...baseParameter,
681
- type: "object"
682
- };
683
- case "array":
684
- if (schema.items.type === "object" && "properties" in schema.items) {
685
- const attributes = [];
686
- const requiredFields = schema.items.required || [];
687
- for (const [propName, propSchema] of Object.entries(
688
- schema.items.properties || {}
689
- )) {
690
- attributes.push(
691
- convertJsonSchemaToParameter(
692
- propName,
693
- propSchema,
694
- requiredFields.includes(propName)
695
- )
696
- );
697
- }
698
- return {
699
- ...baseParameter,
700
- type: "object[]",
701
- attributes
702
- };
703
- } else if (schema.items.type === "array") {
704
- throw new Error("Nested arrays are not supported");
705
- } else {
706
- return {
707
- ...baseParameter,
708
- type: `${schema.items.type}[]`
709
- };
710
- }
711
- default:
712
- return {
713
- ...baseParameter,
714
- type: "string"
715
- };
716
- }
717
- }
718
- function convertAttribute(attribute) {
719
- var _a, _b, _c;
720
- switch (attribute.type) {
721
- case "string":
722
- return {
723
- type: "string",
724
- description: attribute.description,
725
- ...attribute.enum && { enum: attribute.enum }
726
- };
727
- case "number":
728
- case "boolean":
729
- return {
730
- type: attribute.type,
731
- description: attribute.description
732
- };
733
- case "object":
734
- case "object[]":
735
- const properties = (_a = attribute.attributes) == null ? void 0 : _a.reduce(
736
- (acc, attr) => {
737
- acc[attr.name] = convertAttribute(attr);
738
- return acc;
739
- },
740
- {}
741
- );
742
- const required = (_b = attribute.attributes) == null ? void 0 : _b.filter((attr) => attr.required !== false).map((attr) => attr.name);
743
- if (attribute.type === "object[]") {
744
- return {
745
- type: "array",
746
- items: {
747
- type: "object",
748
- ...properties && { properties },
749
- ...required && required.length > 0 && { required }
750
- },
751
- description: attribute.description
752
- };
753
- }
754
- return {
755
- type: "object",
756
- description: attribute.description,
757
- ...properties && { properties },
758
- ...required && required.length > 0 && { required }
759
- };
760
- default:
761
- if ((_c = attribute.type) == null ? void 0 : _c.endsWith("[]")) {
762
- const itemType = attribute.type.slice(0, -2);
763
- return {
764
- type: "array",
765
- items: { type: itemType },
766
- description: attribute.description
767
- };
768
- }
769
- return {
770
- type: "string",
771
- description: attribute.description
772
- };
773
- }
774
- }
775
- function convertJsonSchemaToZodSchema(jsonSchema, required) {
776
- if (jsonSchema.type === "object") {
777
- const spec = {};
778
- if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) {
779
- return !required ? import_zod.z.object(spec).optional() : import_zod.z.object(spec);
780
- }
781
- for (const [key, value] of Object.entries(jsonSchema.properties)) {
782
- spec[key] = convertJsonSchemaToZodSchema(
783
- value,
784
- jsonSchema.required ? jsonSchema.required.includes(key) : false
785
- );
786
- }
787
- let schema = import_zod.z.object(spec).describe(jsonSchema.description);
788
- return required ? schema : schema.optional();
789
- } else if (jsonSchema.type === "string") {
790
- let schema = import_zod.z.string().describe(jsonSchema.description);
791
- return required ? schema : schema.optional();
792
- } else if (jsonSchema.type === "number") {
793
- let schema = import_zod.z.number().describe(jsonSchema.description);
794
- return required ? schema : schema.optional();
795
- } else if (jsonSchema.type === "boolean") {
796
- let schema = import_zod.z.boolean().describe(jsonSchema.description);
797
- return required ? schema : schema.optional();
798
- } else if (jsonSchema.type === "array") {
799
- let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, true);
800
- let schema = import_zod.z.array(itemSchema).describe(jsonSchema.description);
801
- return required ? schema : schema.optional();
802
- }
803
- throw new Error("Invalid JSON schema");
804
- }
805
- function getZodParameters(parameters) {
806
- if (!parameters)
807
- return import_zod.z.object({});
808
- const jsonParams = actionParametersToJsonSchema(parameters);
809
- return convertJsonSchemaToZodSchema(jsonParams, true);
810
- }
811
-
812
- // src/utils/random-id.ts
813
- var import_uuid = require("uuid");
814
- function randomId() {
815
- return "ck-" + (0, import_uuid.v4)();
816
- }
817
- function randomUUID() {
818
- return (0, import_uuid.v4)();
819
- }
820
- function toSerializable(value) {
821
- if (typeof value === "function") {
822
- return value.toString();
823
- }
824
- if (Array.isArray(value)) {
825
- return value.map(toSerializable);
826
- }
827
- if (value !== null && typeof value === "object") {
828
- const result = {};
829
- for (const key of Object.keys(value)) {
830
- result[key] = toSerializable(value[key]);
831
- }
832
- return result;
833
- }
834
- return value;
835
- }
836
- function dataToUUID(input, namespace) {
837
- const BASE_NAMESPACE = "e4b01160-ff74-4c6e-9b27-d53cd930fe8e";
838
- const boundNamespace = namespace ? (0, import_uuid.v5)(namespace, BASE_NAMESPACE) : BASE_NAMESPACE;
839
- const stringInput = typeof input === "string" ? input : JSON.stringify(toSerializable(input));
840
- return (0, import_uuid.v5)(stringInput, boundNamespace);
841
- }
842
- function isValidUUID(uuid) {
843
- return (0, import_uuid.validate)(uuid);
844
- }
845
-
846
- // src/utils/requests.ts
847
- async function readBody(r) {
848
- const method = "method" in r ? r.method.toUpperCase() : void 0;
849
- if (method === "GET" || method === "HEAD") {
850
- return void 0;
851
- }
852
- if (!("body" in r) || r.body == null) {
853
- return void 0;
854
- }
855
- try {
856
- return await r.clone().json();
857
- } catch {
858
- try {
859
- const text = await r.clone().text();
860
- const trimmed = text.trim();
861
- if (trimmed.length === 0)
862
- return text;
863
- if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
864
- try {
865
- return JSON.parse(trimmed);
866
- } catch {
867
- return text;
868
- }
869
- }
870
- return text;
871
- } catch {
872
- try {
873
- const c = r.clone();
874
- const stream = c.body ?? null;
875
- if (!stream)
876
- return void 0;
877
- const reader = stream.getReader();
878
- const decoder = new TextDecoder();
879
- let out = "";
880
- while (true) {
881
- const { done, value } = await reader.read();
882
- if (done)
883
- break;
884
- if (typeof value === "string") {
885
- out += value;
886
- } else {
887
- out += decoder.decode(value, { stream: true });
888
- }
889
- }
890
- out += decoder.decode();
891
- const trimmed = out.trim();
892
- if (trimmed.length === 0)
893
- return out;
894
- if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
895
- try {
896
- return JSON.parse(trimmed);
897
- } catch {
898
- return out;
899
- }
900
- }
901
- return out;
902
- } catch {
903
- return void 0;
904
- }
905
- }
906
- }
907
- }
908
-
909
- // src/utils/index.ts
910
- function parseJson(json, fallback = "unset") {
911
- try {
912
- return JSON.parse(json);
913
- } catch (e) {
914
- return fallback === "unset" ? null : fallback;
915
- }
916
- }
917
- function tryMap(items, callback) {
918
- return items.reduce((acc, item, index, array) => {
919
- try {
920
- acc.push(callback(item, index, array));
921
- } catch (error) {
922
- console.error(error);
923
- }
924
- return acc;
925
- }, []);
926
- }
927
- function isMacOS() {
928
- return /Mac|iMac|Macintosh/i.test(navigator.userAgent);
929
- }
930
-
931
- // src/constants/index.ts
932
- var COPILOT_CLOUD_API_URL = "https://api.cloud.copilotkit.ai";
933
- var COPILOT_CLOUD_VERSION = "v1";
934
- var COPILOT_CLOUD_CHAT_URL = `${COPILOT_CLOUD_API_URL}/copilotkit/${COPILOT_CLOUD_VERSION}`;
935
- var COPILOT_CLOUD_PUBLIC_API_KEY_HEADER = "X-CopilotCloud-Public-Api-Key";
936
-
937
- // src/telemetry/telemetry-client.ts
938
- var import_analytics_node = require("@segment/analytics-node");
939
-
940
- // src/telemetry/utils.ts
941
- var import_chalk = __toESM(require("chalk"));
942
- function flattenObject(obj, parentKey = "", res = {}) {
943
- for (let key in obj) {
944
- const propName = parentKey ? `${parentKey}.${key}` : key;
945
- if (typeof obj[key] === "object" && obj[key] !== null) {
946
- flattenObject(obj[key], propName, res);
947
- } else {
948
- res[propName] = obj[key];
949
- }
950
- }
951
- return res;
952
- }
953
-
954
- // src/telemetry/telemetry-client.ts
955
- var import_uuid2 = require("uuid");
956
-
957
- // package.json
958
- var version = "1.51.4";
959
-
960
- // src/telemetry/scarf-client.ts
961
- var SCARF_BASE_URL = `https://copilotkit.gateway.scarf.sh/${version}`;
962
- var ScarfClient = class {
963
- constructor() {
964
- }
965
- async logEvent(properties) {
966
- try {
967
- const controller = new AbortController();
968
- const timeoutId = setTimeout(() => controller.abort(), 3e3);
969
- const queryParams = new URLSearchParams();
970
- Object.entries(properties).forEach(([key, value]) => {
971
- if (value !== null && value !== void 0) {
972
- queryParams.append(key, String(value));
973
- }
974
- });
975
- const url = `${SCARF_BASE_URL}?${queryParams.toString()}`;
976
- const response = await fetch(url, {
977
- method: "GET",
978
- signal: controller.signal
979
- });
980
- clearTimeout(timeoutId);
981
- if (!response.ok) {
982
- throw new Error(`HTTP error! status: ${response.status}`);
983
- }
984
- } catch {
985
- }
986
- }
987
- };
988
- var scarf_client_default = new ScarfClient();
989
-
990
- // src/telemetry/telemetry-client.ts
991
- function isTelemetryDisabled() {
992
- return process.env.COPILOTKIT_TELEMETRY_DISABLED === "true" || process.env.COPILOTKIT_TELEMETRY_DISABLED === "1" || process.env.DO_NOT_TRACK === "true" || process.env.DO_NOT_TRACK === "1";
993
- }
994
- var TelemetryClient = class {
995
- constructor({
996
- packageName,
997
- packageVersion,
998
- telemetryDisabled,
999
- telemetryBaseUrl,
1000
- sampleRate
1001
- }) {
1002
- this.globalProperties = {};
1003
- this.cloudConfiguration = null;
1004
- this.telemetryDisabled = false;
1005
- this.sampleRate = 0.05;
1006
- this.anonymousId = `anon_${(0, import_uuid2.v4)()}`;
1007
- this.packageName = packageName;
1008
- this.packageVersion = packageVersion;
1009
- this.telemetryDisabled = telemetryDisabled || isTelemetryDisabled();
1010
- if (this.telemetryDisabled) {
1011
- return;
1012
- }
1013
- this.setSampleRate(sampleRate);
1014
- const writeKey = process.env.COPILOTKIT_SEGMENT_WRITE_KEY || "n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja";
1015
- this.segment = new import_analytics_node.Analytics({
1016
- writeKey
1017
- });
1018
- this.setGlobalProperties({
1019
- "copilotkit.package.name": packageName,
1020
- "copilotkit.package.version": packageVersion
1021
- });
1022
- }
1023
- shouldSendEvent() {
1024
- const randomNumber = Math.random();
1025
- return randomNumber < this.sampleRate;
1026
- }
1027
- async capture(event, properties) {
1028
- if (!this.shouldSendEvent() || !this.segment) {
1029
- return;
1030
- }
1031
- const flattenedProperties = flattenObject(properties);
1032
- const propertiesWithGlobal = {
1033
- ...this.globalProperties,
1034
- ...flattenedProperties
1035
- };
1036
- const orderedPropertiesWithGlobal = Object.keys(propertiesWithGlobal).sort().reduce(
1037
- (obj, key) => {
1038
- obj[key] = propertiesWithGlobal[key];
1039
- return obj;
1040
- },
1041
- {}
1042
- );
1043
- this.segment.track({
1044
- anonymousId: this.anonymousId,
1045
- event,
1046
- properties: { ...orderedPropertiesWithGlobal }
1047
- });
1048
- await scarf_client_default.logEvent({
1049
- event
1050
- });
1051
- }
1052
- setGlobalProperties(properties) {
1053
- const flattenedProperties = flattenObject(properties);
1054
- this.globalProperties = {
1055
- ...this.globalProperties,
1056
- ...flattenedProperties
1057
- };
1058
- }
1059
- setCloudConfiguration(properties) {
1060
- this.cloudConfiguration = properties;
1061
- this.setGlobalProperties({
1062
- cloud: {
1063
- publicApiKey: properties.publicApiKey,
1064
- baseUrl: properties.baseUrl
1065
- }
1066
- });
1067
- }
1068
- setSampleRate(sampleRate) {
1069
- let _sampleRate;
1070
- _sampleRate = sampleRate ?? 0.05;
1071
- if (process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE) {
1072
- _sampleRate = parseFloat(process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE);
1073
- }
1074
- if (_sampleRate < 0 || _sampleRate > 1) {
1075
- throw new Error("Sample rate must be between 0 and 1");
1076
- }
1077
- this.sampleRate = _sampleRate;
1078
- this.setGlobalProperties({
1079
- sampleRate: this.sampleRate,
1080
- sampleRateAdjustmentFactor: 1 - this.sampleRate,
1081
- sampleWeight: 1 / this.sampleRate
1082
- });
1083
- }
1084
- };
1085
-
1086
- // src/index.ts
1087
- var COPILOTKIT_VERSION = version;
1088
- // Annotate the CommonJS export names for ESM import in node:
1089
- 0 && (module.exports = {
1090
- BANNER_ERROR_NAMES,
1091
- COPILOTKIT_VERSION,
1092
- COPILOT_CLOUD_API_URL,
1093
- COPILOT_CLOUD_CHAT_URL,
1094
- COPILOT_CLOUD_ERROR_NAMES,
1095
- COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,
1096
- COPILOT_CLOUD_VERSION,
1097
- ConfigurationError,
1098
- ConsoleColors,
1099
- ConsoleStyles,
1100
- CopilotKitAgentDiscoveryError,
1101
- CopilotKitApiDiscoveryError,
1102
- CopilotKitError,
1103
- CopilotKitErrorCode,
1104
- CopilotKitLowLevelError,
1105
- CopilotKitMisuseError,
1106
- CopilotKitRemoteEndpointDiscoveryError,
1107
- CopilotKitVersionMismatchError,
1108
- ERROR_CONFIG,
1109
- ERROR_NAMES,
1110
- ErrorVisibility,
1111
- MissingPublicApiKeyError,
1112
- ResolvedCopilotKitError,
1113
- Severity,
1114
- TelemetryClient,
1115
- UpgradeRequiredError,
1116
- actionParametersToJsonSchema,
1117
- convertJsonSchemaToZodSchema,
1118
- dataToUUID,
1119
- ensureStructuredError,
1120
- executeConditions,
1121
- getPossibleVersionMismatch,
1122
- getZodParameters,
1123
- isMacOS,
1124
- isStructuredCopilotKitError,
1125
- isTelemetryDisabled,
1126
- isValidUUID,
1127
- jsonSchemaToActionParameters,
1128
- logCopilotKitPlatformMessage,
1129
- logStyled,
1130
- parseJson,
1131
- publicApiKeyRequired,
1132
- randomId,
1133
- randomUUID,
1134
- readBody,
1135
- styledConsole,
1136
- tryMap
1137
- });
1138
- //# sourceMappingURL=index.js.map