@copilotkit/shared 0.0.0-0.0.0-max-changeset-10101010101010-20260109191632

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 (185) hide show
  1. package/CHANGELOG.md +1800 -0
  2. package/LICENSE +21 -0
  3. package/README.md +141 -0
  4. package/dist/chunk-2OJ5OJ2D.mjs +1 -0
  5. package/dist/chunk-2OJ5OJ2D.mjs.map +1 -0
  6. package/dist/chunk-5YXKLIUO.mjs +38 -0
  7. package/dist/chunk-5YXKLIUO.mjs.map +1 -0
  8. package/dist/chunk-64DYJ27R.mjs +201 -0
  9. package/dist/chunk-64DYJ27R.mjs.map +1 -0
  10. package/dist/chunk-6QGXWNS5.mjs +34 -0
  11. package/dist/chunk-6QGXWNS5.mjs.map +1 -0
  12. package/dist/chunk-6W2UEO2M.mjs +94 -0
  13. package/dist/chunk-6W2UEO2M.mjs.map +1 -0
  14. package/dist/chunk-BOKE4OKY.mjs +41 -0
  15. package/dist/chunk-BOKE4OKY.mjs.map +1 -0
  16. package/dist/chunk-FCCOSO5L.mjs +1 -0
  17. package/dist/chunk-FCCOSO5L.mjs.map +1 -0
  18. package/dist/chunk-GYZIHHE6.mjs +13 -0
  19. package/dist/chunk-GYZIHHE6.mjs.map +1 -0
  20. package/dist/chunk-IAFBVORQ.mjs +1 -0
  21. package/dist/chunk-IAFBVORQ.mjs.map +1 -0
  22. package/dist/chunk-MSUB6DGR.mjs +1 -0
  23. package/dist/chunk-MSUB6DGR.mjs.map +1 -0
  24. package/dist/chunk-N5EP5OD5.mjs +1 -0
  25. package/dist/chunk-N5EP5OD5.mjs.map +1 -0
  26. package/dist/chunk-NAFEBKSO.mjs +1 -0
  27. package/dist/chunk-NAFEBKSO.mjs.map +1 -0
  28. package/dist/chunk-NBLG4PC5.mjs +426 -0
  29. package/dist/chunk-NBLG4PC5.mjs.map +1 -0
  30. package/dist/chunk-P7STFMPO.mjs +1 -0
  31. package/dist/chunk-P7STFMPO.mjs.map +1 -0
  32. package/dist/chunk-PL5WNHFZ.mjs +50 -0
  33. package/dist/chunk-PL5WNHFZ.mjs.map +1 -0
  34. package/dist/chunk-UYARLQNA.mjs +1 -0
  35. package/dist/chunk-UYARLQNA.mjs.map +1 -0
  36. package/dist/chunk-WUPFNPXO.mjs +107 -0
  37. package/dist/chunk-WUPFNPXO.mjs.map +1 -0
  38. package/dist/chunk-XEMZTHQZ.mjs +67 -0
  39. package/dist/chunk-XEMZTHQZ.mjs.map +1 -0
  40. package/dist/chunk-XTHC46M2.mjs +1 -0
  41. package/dist/chunk-XTHC46M2.mjs.map +1 -0
  42. package/dist/constants/index.d.ts +6 -0
  43. package/dist/constants/index.js +40 -0
  44. package/dist/constants/index.js.map +1 -0
  45. package/dist/constants/index.mjs +13 -0
  46. package/dist/constants/index.mjs.map +1 -0
  47. package/dist/index.d.ts +25 -0
  48. package/dist/index.js +1098 -0
  49. package/dist/index.js.map +1 -0
  50. package/dist/index.mjs +124 -0
  51. package/dist/index.mjs.map +1 -0
  52. package/dist/telemetry/events.d.ts +45 -0
  53. package/dist/telemetry/events.js +19 -0
  54. package/dist/telemetry/events.js.map +1 -0
  55. package/dist/telemetry/events.mjs +1 -0
  56. package/dist/telemetry/events.mjs.map +1 -0
  57. package/dist/telemetry/index.d.ts +3 -0
  58. package/dist/telemetry/index.js +188 -0
  59. package/dist/telemetry/index.js.map +1 -0
  60. package/dist/telemetry/index.mjs +12 -0
  61. package/dist/telemetry/index.mjs.map +1 -0
  62. package/dist/telemetry/scarf-client.d.ts +7 -0
  63. package/dist/telemetry/scarf-client.js +59 -0
  64. package/dist/telemetry/scarf-client.js.map +1 -0
  65. package/dist/telemetry/scarf-client.mjs +7 -0
  66. package/dist/telemetry/scarf-client.mjs.map +1 -0
  67. package/dist/telemetry/security-check.d.ts +2 -0
  68. package/dist/telemetry/security-check.js +2 -0
  69. package/dist/telemetry/security-check.js.map +1 -0
  70. package/dist/telemetry/security-check.mjs +1 -0
  71. package/dist/telemetry/security-check.mjs.map +1 -0
  72. package/dist/telemetry/telemetry-client.d.ts +40 -0
  73. package/dist/telemetry/telemetry-client.js +186 -0
  74. package/dist/telemetry/telemetry-client.js.map +1 -0
  75. package/dist/telemetry/telemetry-client.mjs +11 -0
  76. package/dist/telemetry/telemetry-client.mjs.map +1 -0
  77. package/dist/telemetry/utils.d.ts +8 -0
  78. package/dist/telemetry/utils.js +69 -0
  79. package/dist/telemetry/utils.js.map +1 -0
  80. package/dist/telemetry/utils.mjs +9 -0
  81. package/dist/telemetry/utils.mjs.map +1 -0
  82. package/dist/types/action.d.ts +59 -0
  83. package/dist/types/action.js +19 -0
  84. package/dist/types/action.js.map +1 -0
  85. package/dist/types/action.mjs +2 -0
  86. package/dist/types/action.mjs.map +1 -0
  87. package/dist/types/copilot-cloud-config.d.ts +13 -0
  88. package/dist/types/copilot-cloud-config.js +19 -0
  89. package/dist/types/copilot-cloud-config.js.map +1 -0
  90. package/dist/types/copilot-cloud-config.mjs +2 -0
  91. package/dist/types/copilot-cloud-config.mjs.map +1 -0
  92. package/dist/types/error.d.ts +55 -0
  93. package/dist/types/error.js +19 -0
  94. package/dist/types/error.js.map +1 -0
  95. package/dist/types/error.mjs +2 -0
  96. package/dist/types/error.mjs.map +1 -0
  97. package/dist/types/index.d.ts +7 -0
  98. package/dist/types/index.js +19 -0
  99. package/dist/types/index.js.map +1 -0
  100. package/dist/types/index.mjs +8 -0
  101. package/dist/types/index.mjs.map +1 -0
  102. package/dist/types/message.d.ts +26 -0
  103. package/dist/types/message.js +19 -0
  104. package/dist/types/message.js.map +1 -0
  105. package/dist/types/message.mjs +2 -0
  106. package/dist/types/message.mjs.map +1 -0
  107. package/dist/types/openai-assistant.d.ts +53 -0
  108. package/dist/types/openai-assistant.js +19 -0
  109. package/dist/types/openai-assistant.js.map +1 -0
  110. package/dist/types/openai-assistant.mjs +2 -0
  111. package/dist/types/openai-assistant.mjs.map +1 -0
  112. package/dist/types/utility.d.ts +6 -0
  113. package/dist/types/utility.js +19 -0
  114. package/dist/types/utility.js.map +1 -0
  115. package/dist/types/utility.mjs +2 -0
  116. package/dist/types/utility.mjs.map +1 -0
  117. package/dist/utils/conditions.d.ts +26 -0
  118. package/dist/utils/conditions.js +74 -0
  119. package/dist/utils/conditions.js.map +1 -0
  120. package/dist/utils/conditions.mjs +7 -0
  121. package/dist/utils/conditions.mjs.map +1 -0
  122. package/dist/utils/console-styling.d.ts +84 -0
  123. package/dist/utils/console-styling.js +123 -0
  124. package/dist/utils/console-styling.js.map +1 -0
  125. package/dist/utils/console-styling.mjs +17 -0
  126. package/dist/utils/console-styling.mjs.map +1 -0
  127. package/dist/utils/errors.d.ts +280 -0
  128. package/dist/utils/errors.js +443 -0
  129. package/dist/utils/errors.js.map +1 -0
  130. package/dist/utils/errors.mjs +65 -0
  131. package/dist/utils/errors.mjs.map +1 -0
  132. package/dist/utils/index.d.ts +32 -0
  133. package/dist/utils/index.js +927 -0
  134. package/dist/utils/index.js.map +1 -0
  135. package/dist/utils/index.mjs +108 -0
  136. package/dist/utils/index.mjs.map +1 -0
  137. package/dist/utils/json-schema.d.ts +34 -0
  138. package/dist/utils/json-schema.js +228 -0
  139. package/dist/utils/json-schema.js.map +1 -0
  140. package/dist/utils/json-schema.mjs +13 -0
  141. package/dist/utils/json-schema.mjs.map +1 -0
  142. package/dist/utils/random-id.d.ts +6 -0
  143. package/dist/utils/random-id.js +68 -0
  144. package/dist/utils/random-id.js.map +1 -0
  145. package/dist/utils/random-id.mjs +13 -0
  146. package/dist/utils/random-id.mjs.map +1 -0
  147. package/dist/utils/requests.d.ts +10 -0
  148. package/dist/utils/requests.js +91 -0
  149. package/dist/utils/requests.js.map +1 -0
  150. package/dist/utils/requests.mjs +7 -0
  151. package/dist/utils/requests.mjs.map +1 -0
  152. package/dist/utils/types.d.ts +20 -0
  153. package/dist/utils/types.js +19 -0
  154. package/dist/utils/types.js.map +1 -0
  155. package/dist/utils/types.mjs +2 -0
  156. package/dist/utils/types.mjs.map +1 -0
  157. package/jest.config.js +5 -0
  158. package/package.json +68 -0
  159. package/src/constants/index.ts +4 -0
  160. package/src/index.ts +7 -0
  161. package/src/telemetry/events.ts +41 -0
  162. package/src/telemetry/index.ts +1 -0
  163. package/src/telemetry/scarf-client.ts +39 -0
  164. package/src/telemetry/security-check.ts +0 -0
  165. package/src/telemetry/telemetry-client.ts +142 -0
  166. package/src/telemetry/utils.ts +39 -0
  167. package/src/types/action.ts +129 -0
  168. package/src/types/copilot-cloud-config.ts +11 -0
  169. package/src/types/error.ts +70 -0
  170. package/src/types/index.ts +6 -0
  171. package/src/types/message.ts +37 -0
  172. package/src/types/openai-assistant.ts +62 -0
  173. package/src/types/utility.ts +2 -0
  174. package/src/utils/conditions.ts +98 -0
  175. package/src/utils/console-styling.ts +124 -0
  176. package/src/utils/errors.ts +525 -0
  177. package/src/utils/index.ts +49 -0
  178. package/src/utils/json-schema.test.ts +383 -0
  179. package/src/utils/json-schema.ts +258 -0
  180. package/src/utils/random-id.ts +42 -0
  181. package/src/utils/requests.ts +77 -0
  182. package/src/utils/types.ts +22 -0
  183. package/tsconfig.json +9 -0
  184. package/tsup.config.ts +11 -0
  185. package/typedoc.json +4 -0
@@ -0,0 +1,13 @@
1
+ import {
2
+ dataToUUID,
3
+ isValidUUID,
4
+ randomId,
5
+ randomUUID
6
+ } from "../chunk-BOKE4OKY.mjs";
7
+ export {
8
+ dataToUUID,
9
+ isValidUUID,
10
+ randomId,
11
+ randomUUID
12
+ };
13
+ //# sourceMappingURL=random-id.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Safely read a Response/Request body with sensible defaults:
3
+ * - clones the response/request to avoid consuming the original response/request
4
+ * - Skips GET/HEAD
5
+ * - Tries JSON first regardless of content-type
6
+ * - Falls back to text and optionally parses when it "looks" like JSON
7
+ */
8
+ declare function readBody<T extends Response | Request>(r: T): Promise<unknown>;
9
+
10
+ export { readBody };
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/utils/requests.ts
21
+ var requests_exports = {};
22
+ __export(requests_exports, {
23
+ readBody: () => readBody
24
+ });
25
+ module.exports = __toCommonJS(requests_exports);
26
+ async function readBody(r) {
27
+ const method = "method" in r ? r.method.toUpperCase() : void 0;
28
+ if (method === "GET" || method === "HEAD") {
29
+ return void 0;
30
+ }
31
+ if (!("body" in r) || r.body == null) {
32
+ return void 0;
33
+ }
34
+ try {
35
+ return await r.clone().json();
36
+ } catch {
37
+ try {
38
+ const text = await r.clone().text();
39
+ const trimmed = text.trim();
40
+ if (trimmed.length === 0)
41
+ return text;
42
+ if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
43
+ try {
44
+ return JSON.parse(trimmed);
45
+ } catch {
46
+ return text;
47
+ }
48
+ }
49
+ return text;
50
+ } catch {
51
+ try {
52
+ const c = r.clone();
53
+ const stream = c.body ?? null;
54
+ if (!stream)
55
+ return void 0;
56
+ const reader = stream.getReader();
57
+ const decoder = new TextDecoder();
58
+ let out = "";
59
+ while (true) {
60
+ const { done, value } = await reader.read();
61
+ if (done)
62
+ break;
63
+ if (typeof value === "string") {
64
+ out += value;
65
+ } else {
66
+ out += decoder.decode(value, { stream: true });
67
+ }
68
+ }
69
+ out += decoder.decode();
70
+ const trimmed = out.trim();
71
+ if (trimmed.length === 0)
72
+ return out;
73
+ if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
74
+ try {
75
+ return JSON.parse(trimmed);
76
+ } catch {
77
+ return out;
78
+ }
79
+ }
80
+ return out;
81
+ } catch {
82
+ return void 0;
83
+ }
84
+ }
85
+ }
86
+ }
87
+ // Annotate the CommonJS export names for ESM import in node:
88
+ 0 && (module.exports = {
89
+ readBody
90
+ });
91
+ //# sourceMappingURL=requests.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/requests.ts"],"sourcesContent":["/**\n * Safely read a Response/Request body with sensible defaults:\n * - clones the response/request to avoid consuming the original response/request\n * - Skips GET/HEAD\n * - Tries JSON first regardless of content-type\n * - Falls back to text and optionally parses when it \"looks\" like JSON\n */\nexport async function readBody<T extends Response | Request>(r: T): Promise<unknown> {\n // skip GET/HEAD requests (unchanged)\n const method = \"method\" in r ? r.method.toUpperCase() : undefined;\n if (method === \"GET\" || method === \"HEAD\") {\n return undefined;\n }\n\n // no body at all → undefined (unchanged)\n if (!(\"body\" in r) || r.body == null) {\n return undefined;\n }\n\n // 1) try JSON (unchanged)\n try {\n return await r.clone().json();\n } catch {\n // 2) try text (unchanged + your whitespace/JSON-heuristic)\n try {\n const text = await r.clone().text();\n const trimmed = text.trim();\n\n if (trimmed.length === 0) return text;\n\n if (trimmed.startsWith(\"{\") || trimmed.startsWith(\"[\")) {\n try {\n return JSON.parse(trimmed);\n } catch {\n return text;\n }\n }\n return text;\n } catch {\n // 3) FINAL FALLBACK: manual read that accepts string or bytes\n try {\n const c = r.clone();\n const stream: ReadableStream | null = c.body ?? null;\n if (!stream) return undefined;\n\n const reader = stream.getReader();\n const decoder = new TextDecoder();\n let out = \"\";\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n if (typeof value === \"string\") {\n out += value; // accept string chunks\n } else {\n out += decoder.decode(value, { stream: true }); // bytes\n }\n }\n out += decoder.decode(); // flush\n\n const trimmed = out.trim();\n if (trimmed.length === 0) return out;\n\n if (trimmed.startsWith(\"{\") || trimmed.startsWith(\"[\")) {\n try {\n return JSON.parse(trimmed);\n } catch {\n return out;\n }\n }\n return out;\n } catch {\n return undefined; // same \"give up\" behavior you had\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,eAAsB,SAAuC,GAAwB;AAEnF,QAAM,SAAS,YAAY,IAAI,EAAE,OAAO,YAAY,IAAI;AACxD,MAAI,WAAW,SAAS,WAAW,QAAQ;AACzC,WAAO;AAAA,EACT;AAGA,MAAI,EAAE,UAAU,MAAM,EAAE,QAAQ,MAAM;AACpC,WAAO;AAAA,EACT;AAGA,MAAI;AACF,WAAO,MAAM,EAAE,MAAM,EAAE,KAAK;AAAA,EAC9B,QAAE;AAEA,QAAI;AACF,YAAM,OAAO,MAAM,EAAE,MAAM,EAAE,KAAK;AAClC,YAAM,UAAU,KAAK,KAAK;AAE1B,UAAI,QAAQ,WAAW;AAAG,eAAO;AAEjC,UAAI,QAAQ,WAAW,GAAG,KAAK,QAAQ,WAAW,GAAG,GAAG;AACtD,YAAI;AACF,iBAAO,KAAK,MAAM,OAAO;AAAA,QAC3B,QAAE;AACA,iBAAO;AAAA,QACT;AAAA,MACF;AACA,aAAO;AAAA,IACT,QAAE;AAEA,UAAI;AACF,cAAM,IAAI,EAAE,MAAM;AAClB,cAAM,SAAgC,EAAE,QAAQ;AAChD,YAAI,CAAC;AAAQ,iBAAO;AAEpB,cAAM,SAAS,OAAO,UAAU;AAChC,cAAM,UAAU,IAAI,YAAY;AAChC,YAAI,MAAM;AAEV,eAAO,MAAM;AACX,gBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,cAAI;AAAM;AACV,cAAI,OAAO,UAAU,UAAU;AAC7B,mBAAO;AAAA,UACT,OAAO;AACL,mBAAO,QAAQ,OAAO,OAAO,EAAE,QAAQ,KAAK,CAAC;AAAA,UAC/C;AAAA,QACF;AACA,eAAO,QAAQ,OAAO;AAEtB,cAAM,UAAU,IAAI,KAAK;AACzB,YAAI,QAAQ,WAAW;AAAG,iBAAO;AAEjC,YAAI,QAAQ,WAAW,GAAG,KAAK,QAAQ,WAAW,GAAG,GAAG;AACtD,cAAI;AACF,mBAAO,KAAK,MAAM,OAAO;AAAA,UAC3B,QAAE;AACA,mBAAO;AAAA,UACT;AAAA,QACF;AACA,eAAO;AAAA,MACT,QAAE;AACA,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,7 @@
1
+ import {
2
+ readBody
3
+ } from "../chunk-XEMZTHQZ.mjs";
4
+ export {
5
+ readBody
6
+ };
7
+ //# sourceMappingURL=requests.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,20 @@
1
+ type MaybePromise<T> = T | PromiseLike<T>;
2
+ /**
3
+ * More specific utility for records with at least one key
4
+ */
5
+ type NonEmptyRecord<T> = T extends Record<string, unknown> ? (keyof T extends never ? never : T) : never;
6
+ /**
7
+ * Type representing an agent's basic information
8
+ */
9
+ interface AgentDescription {
10
+ name: string;
11
+ className: string;
12
+ description: string;
13
+ }
14
+ interface RuntimeInfo {
15
+ version: string;
16
+ agents: Record<string, AgentDescription>;
17
+ audioFileTranscriptionEnabled: boolean;
18
+ }
19
+
20
+ export { AgentDescription, MaybePromise, NonEmptyRecord, RuntimeInfo };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/utils/types.ts
17
+ var types_exports = {};
18
+ module.exports = __toCommonJS(types_exports);
19
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/types.ts"],"sourcesContent":["export type MaybePromise<T> = T | PromiseLike<T>;\n\n/**\n * More specific utility for records with at least one key\n */\nexport type NonEmptyRecord<T> =\n T extends Record<string, unknown> ? (keyof T extends never ? never : T) : never;\n\n/**\n * Type representing an agent's basic information\n */\nexport interface AgentDescription {\n name: string;\n className: string;\n description: string;\n}\n\nexport interface RuntimeInfo {\n version: string;\n agents: Record<string, AgentDescription>;\n audioFileTranscriptionEnabled: boolean;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -0,0 +1,2 @@
1
+ import "../chunk-XTHC46M2.mjs";
2
+ //# sourceMappingURL=types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/jest.config.js ADDED
@@ -0,0 +1,5 @@
1
+ /** @type {import('ts-jest').JestConfigWithTsJest} */
2
+ module.exports = {
3
+ preset: 'ts-jest',
4
+ testEnvironment: 'node',
5
+ };
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@copilotkit/shared",
3
+ "private": false,
4
+ "homepage": "https://github.com/CopilotKit/CopilotKit",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/CopilotKit/CopilotKit.git"
8
+ },
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "version": "0.0.0-0.0.0-max-changeset-10101010101010-20260109191632",
13
+ "sideEffects": false,
14
+ "main": "./dist/index.js",
15
+ "module": "./dist/index.mjs",
16
+ "exports": {
17
+ ".": {
18
+ "import": "./dist/index.mjs",
19
+ "require": "./dist/index.js",
20
+ "types": "./dist/index.d.ts"
21
+ }
22
+ },
23
+ "types": "./dist/index.d.ts",
24
+ "license": "MIT",
25
+ "devDependencies": {
26
+ "@types/jest": "^29.5.4",
27
+ "@types/uuid": "^10.0.0",
28
+ "eslint": "^8.56.0",
29
+ "jest": "^29.6.4",
30
+ "ts-jest": "^29.1.1",
31
+ "tsup": "^6.7.0",
32
+ "typescript": "^5.2.3",
33
+ "zod-to-json-schema": "^3.23.5",
34
+ "eslint-config-custom": "1.4.6",
35
+ "tsconfig": "1.4.6"
36
+ },
37
+ "dependencies": {
38
+ "@segment/analytics-node": "^2.1.2",
39
+ "chalk": "4.1.2",
40
+ "graphql": "^16.8.1",
41
+ "uuid": "^10.0.0",
42
+ "zod": "^3.23.3"
43
+ },
44
+ "peerDependencies": {
45
+ "@ag-ui/core": "^0.0.42"
46
+ },
47
+ "keywords": [
48
+ "copilotkit",
49
+ "copilot",
50
+ "react",
51
+ "nextjs",
52
+ "nodejs",
53
+ "ai",
54
+ "assistant",
55
+ "javascript",
56
+ "automation",
57
+ "textarea"
58
+ ],
59
+ "scripts": {
60
+ "build": "tsup --clean",
61
+ "dev": "tsup --watch --no-splitting",
62
+ "test": "jest --passWithNoTests",
63
+ "check-types": "tsc --noEmit",
64
+ "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist && rm -rf .next",
65
+ "link:global": "pnpm link --global",
66
+ "unlink:global": "pnpm unlink --global"
67
+ }
68
+ }
@@ -0,0 +1,4 @@
1
+ export const COPILOT_CLOUD_API_URL = "https://api.cloud.copilotkit.ai";
2
+ export const COPILOT_CLOUD_VERSION = "v1";
3
+ export const COPILOT_CLOUD_CHAT_URL = `${COPILOT_CLOUD_API_URL}/copilotkit/${COPILOT_CLOUD_VERSION}`;
4
+ export const COPILOT_CLOUD_PUBLIC_API_KEY_HEADER = "X-CopilotCloud-Public-Api-Key";
package/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ export * from "./types";
2
+ export * from "./utils";
3
+ export * from "./constants";
4
+ export * from "./telemetry";
5
+
6
+ import * as packageJson from "../package.json";
7
+ export const COPILOTKIT_VERSION = packageJson.version;
@@ -0,0 +1,41 @@
1
+ export type AnalyticsEvents = {
2
+ "oss.runtime.instance_created": RuntimeInstanceCreatedInfo;
3
+ "oss.runtime.copilot_request_created": {
4
+ "cloud.guardrails.enabled": boolean;
5
+ requestType: string;
6
+ "cloud.api_key_provided": boolean;
7
+ "cloud.public_api_key"?: string;
8
+ "cloud.base_url"?: string;
9
+ };
10
+ "oss.runtime.server_action_executed": {};
11
+ "oss.runtime.remote_action_executed": RemoteActionExecutionInfo;
12
+ "oss.runtime.agent_execution_stream_started": { hashedLgcKey?: string };
13
+ "oss.runtime.agent_execution_stream_ended": AgentExecutionResponseInfo;
14
+ "oss.runtime.agent_execution_stream_errored": { hashedLgcKey?: string; error?: string };
15
+ };
16
+
17
+ export interface RuntimeInstanceCreatedInfo {
18
+ actionsAmount: number;
19
+ endpointTypes: string[];
20
+ hashedLgcKey?: string;
21
+ endpointsAmount: number;
22
+ agentsAmount?: number | null;
23
+ "cloud.api_key_provided": boolean;
24
+ "cloud.public_api_key"?: string;
25
+ "cloud.base_url"?: string;
26
+ }
27
+
28
+ export interface RemoteActionExecutionInfo {
29
+ agentExecution: boolean;
30
+ type: "self-hosted" | "langgraph-platform";
31
+ agentsAmount?: number | null;
32
+ hashedLgcKey?: string;
33
+ }
34
+
35
+ export interface AgentExecutionResponseInfo {
36
+ provider?: string;
37
+ model?: string;
38
+ langGraphHost?: string;
39
+ langGraphVersion?: string;
40
+ hashedLgcKey?: string;
41
+ }
@@ -0,0 +1 @@
1
+ export * from "./telemetry-client";
@@ -0,0 +1,39 @@
1
+ import * as packageJson from "../../package.json";
2
+
3
+ const SCARF_BASE_URL = `https://copilotkit.gateway.scarf.sh/${packageJson.version}`;
4
+
5
+ class ScarfClient {
6
+ constructor() {}
7
+
8
+ async logEvent(properties: Record<string, any>): Promise<void> {
9
+ try {
10
+ const controller = new AbortController();
11
+ const timeoutId = setTimeout(() => controller.abort(), 3000);
12
+
13
+ const queryParams = new URLSearchParams();
14
+
15
+ Object.entries(properties).forEach(([key, value]) => {
16
+ if (value !== null && value !== undefined) {
17
+ queryParams.append(key, String(value));
18
+ }
19
+ });
20
+
21
+ const url = `${SCARF_BASE_URL}?${queryParams.toString()}`;
22
+
23
+ const response = await fetch(url, {
24
+ method: "GET",
25
+ signal: controller.signal,
26
+ });
27
+
28
+ clearTimeout(timeoutId);
29
+
30
+ if (!response.ok) {
31
+ throw new Error(`HTTP error! status: ${response.status}`);
32
+ }
33
+ } catch {
34
+ // Silently fail - telemetry should not break the application
35
+ }
36
+ }
37
+ }
38
+
39
+ export default new ScarfClient();
File without changes
@@ -0,0 +1,142 @@
1
+ import { Analytics } from "@segment/analytics-node";
2
+ import { AnalyticsEvents } from "./events";
3
+ import { flattenObject } from "./utils";
4
+ import { v4 as uuidv4 } from "uuid";
5
+ import scarfClient from "./scarf-client";
6
+
7
+ /**
8
+ * Checks if telemetry is disabled via environment variables.
9
+ * Users can opt out by setting:
10
+ * - COPILOTKIT_TELEMETRY_DISABLED=true or COPILOTKIT_TELEMETRY_DISABLED=1
11
+ * - DO_NOT_TRACK=true or DO_NOT_TRACK=1
12
+ */
13
+ export function isTelemetryDisabled(): boolean {
14
+ return (
15
+ (process.env as Record<string, string | undefined>).COPILOTKIT_TELEMETRY_DISABLED === "true" ||
16
+ (process.env as Record<string, string | undefined>).COPILOTKIT_TELEMETRY_DISABLED === "1" ||
17
+ (process.env as Record<string, string | undefined>).DO_NOT_TRACK === "true" ||
18
+ (process.env as Record<string, string | undefined>).DO_NOT_TRACK === "1"
19
+ );
20
+ }
21
+
22
+ export class TelemetryClient {
23
+ segment: Analytics | undefined;
24
+ globalProperties: Record<string, any> = {};
25
+ cloudConfiguration: { publicApiKey: string; baseUrl: string } | null = null;
26
+ packageName: string;
27
+ packageVersion: string;
28
+ private telemetryDisabled: boolean = false;
29
+ private sampleRate: number = 0.05;
30
+ private anonymousId = `anon_${uuidv4()}`;
31
+
32
+ constructor({
33
+ packageName,
34
+ packageVersion,
35
+ telemetryDisabled,
36
+ telemetryBaseUrl,
37
+ sampleRate,
38
+ }: {
39
+ packageName: string;
40
+ packageVersion: string;
41
+ telemetryDisabled?: boolean;
42
+ telemetryBaseUrl?: string;
43
+ sampleRate?: number;
44
+ }) {
45
+ this.packageName = packageName;
46
+ this.packageVersion = packageVersion;
47
+ this.telemetryDisabled = telemetryDisabled || isTelemetryDisabled();
48
+
49
+ if (this.telemetryDisabled) {
50
+ return;
51
+ }
52
+
53
+ this.setSampleRate(sampleRate);
54
+
55
+ // eslint-disable-next-line
56
+ const writeKey = process.env.COPILOTKIT_SEGMENT_WRITE_KEY || "n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja";
57
+
58
+ this.segment = new Analytics({
59
+ writeKey,
60
+ });
61
+
62
+ this.setGlobalProperties({
63
+ "copilotkit.package.name": packageName,
64
+ "copilotkit.package.version": packageVersion,
65
+ });
66
+ }
67
+
68
+ private shouldSendEvent() {
69
+ const randomNumber = Math.random();
70
+ return randomNumber < this.sampleRate;
71
+ }
72
+
73
+ async capture<K extends keyof AnalyticsEvents>(event: K, properties: AnalyticsEvents[K]) {
74
+ if (!this.shouldSendEvent() || !this.segment) {
75
+ return;
76
+ }
77
+
78
+ const flattenedProperties = flattenObject(properties);
79
+ const propertiesWithGlobal = {
80
+ ...this.globalProperties,
81
+ ...flattenedProperties,
82
+ };
83
+ const orderedPropertiesWithGlobal = Object.keys(propertiesWithGlobal)
84
+ .sort()
85
+ .reduce(
86
+ (obj, key) => {
87
+ obj[key] = propertiesWithGlobal[key];
88
+ return obj;
89
+ },
90
+ {} as Record<string, any>,
91
+ );
92
+
93
+ this.segment.track({
94
+ anonymousId: this.anonymousId,
95
+ event,
96
+ properties: { ...orderedPropertiesWithGlobal },
97
+ });
98
+
99
+ await scarfClient.logEvent({
100
+ event,
101
+ });
102
+ }
103
+
104
+ setGlobalProperties(properties: Record<string, any>) {
105
+ const flattenedProperties = flattenObject(properties);
106
+ this.globalProperties = { ...this.globalProperties, ...flattenedProperties };
107
+ }
108
+
109
+ setCloudConfiguration(properties: { publicApiKey: string; baseUrl: string }) {
110
+ this.cloudConfiguration = properties;
111
+
112
+ this.setGlobalProperties({
113
+ cloud: {
114
+ publicApiKey: properties.publicApiKey,
115
+ baseUrl: properties.baseUrl,
116
+ },
117
+ });
118
+ }
119
+
120
+ private setSampleRate(sampleRate: number | undefined) {
121
+ let _sampleRate: number;
122
+
123
+ _sampleRate = sampleRate ?? 0.05;
124
+
125
+ // eslint-disable-next-line
126
+ if (process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE) {
127
+ // eslint-disable-next-line
128
+ _sampleRate = parseFloat(process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE);
129
+ }
130
+
131
+ if (_sampleRate < 0 || _sampleRate > 1) {
132
+ throw new Error("Sample rate must be between 0 and 1");
133
+ }
134
+
135
+ this.sampleRate = _sampleRate;
136
+ this.setGlobalProperties({
137
+ sampleRate: this.sampleRate,
138
+ sampleRateAdjustmentFactor: 1 - this.sampleRate,
139
+ sampleWeight: 1 / this.sampleRate,
140
+ });
141
+ }
142
+ }
@@ -0,0 +1,39 @@
1
+ import chalk from "chalk";
2
+
3
+ export function flattenObject(
4
+ obj: Record<string, any>,
5
+ parentKey = "",
6
+ res: Record<string, any> = {},
7
+ ): Record<string, any> {
8
+ for (let key in obj) {
9
+ const propName = parentKey ? `${parentKey}.${key}` : key;
10
+ if (typeof obj[key] === "object" && obj[key] !== null) {
11
+ flattenObject(obj[key], propName, res);
12
+ } else {
13
+ res[propName] = obj[key];
14
+ }
15
+ }
16
+ return res;
17
+ }
18
+
19
+ export function printSecurityNotice(advisory: {
20
+ advisory: string | null;
21
+ message: string;
22
+ severity: "low" | "medium" | "high" | "none";
23
+ }) {
24
+ const severityColor =
25
+ {
26
+ low: chalk.blue,
27
+ medium: chalk.yellow,
28
+ high: chalk.red,
29
+ }[advisory.severity.toLowerCase()] || chalk.white;
30
+
31
+ console.log();
32
+ console.log(`━━━━━━━━━━━━━━━━━━ ${chalk.bold(`CopilotKit`)} ━━━━━━━━━━━━━━━━━━`);
33
+ console.log();
34
+ console.log(`${chalk.bold(`Severity: ${severityColor(advisory.severity.toUpperCase())}`)}`);
35
+ console.log();
36
+ console.log(`${chalk.bold(advisory.message)}`);
37
+ console.log();
38
+ console.log(`━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`);
39
+ }