@copilotkit/shared 0.0.0-mme-load-agent-state-20250117154700

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/CHANGELOG.md +982 -0
  2. package/README.md +46 -0
  3. package/dist/chunk-53DC2JUS.mjs +18 -0
  4. package/dist/chunk-53DC2JUS.mjs.map +1 -0
  5. package/dist/chunk-6QGXWNS5.mjs +34 -0
  6. package/dist/chunk-6QGXWNS5.mjs.map +1 -0
  7. package/dist/chunk-BANDZXMP.mjs +1 -0
  8. package/dist/chunk-BANDZXMP.mjs.map +1 -0
  9. package/dist/chunk-CYDWEPFL.mjs +1 -0
  10. package/dist/chunk-CYDWEPFL.mjs.map +1 -0
  11. package/dist/chunk-FCCOSO5L.mjs +1 -0
  12. package/dist/chunk-FCCOSO5L.mjs.map +1 -0
  13. package/dist/chunk-GYZIHHE6.mjs +13 -0
  14. package/dist/chunk-GYZIHHE6.mjs.map +1 -0
  15. package/dist/chunk-IAFBVORQ.mjs +1 -0
  16. package/dist/chunk-IAFBVORQ.mjs.map +1 -0
  17. package/dist/chunk-JP2M4U4G.mjs +112 -0
  18. package/dist/chunk-JP2M4U4G.mjs.map +1 -0
  19. package/dist/chunk-MSUB6DGR.mjs +1 -0
  20. package/dist/chunk-MSUB6DGR.mjs.map +1 -0
  21. package/dist/chunk-NAFEBKSO.mjs +1 -0
  22. package/dist/chunk-NAFEBKSO.mjs.map +1 -0
  23. package/dist/chunk-P7STFMPO.mjs +1 -0
  24. package/dist/chunk-P7STFMPO.mjs.map +1 -0
  25. package/dist/chunk-QFITLWYZ.mjs +96 -0
  26. package/dist/chunk-QFITLWYZ.mjs.map +1 -0
  27. package/dist/constants/index.d.ts +6 -0
  28. package/dist/constants/index.js +40 -0
  29. package/dist/constants/index.js.map +1 -0
  30. package/dist/constants/index.mjs +13 -0
  31. package/dist/constants/index.mjs.map +1 -0
  32. package/dist/index.d.ts +15 -0
  33. package/dist/index.js +295 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/index.mjs +46 -0
  36. package/dist/index.mjs.map +1 -0
  37. package/dist/telemetry/events.d.ts +39 -0
  38. package/dist/telemetry/events.js +19 -0
  39. package/dist/telemetry/events.js.map +1 -0
  40. package/dist/telemetry/events.mjs +1 -0
  41. package/dist/telemetry/events.mjs.map +1 -0
  42. package/dist/telemetry/index.d.ts +3 -0
  43. package/dist/telemetry/index.js +144 -0
  44. package/dist/telemetry/index.js.map +1 -0
  45. package/dist/telemetry/index.mjs +9 -0
  46. package/dist/telemetry/index.mjs.map +1 -0
  47. package/dist/telemetry/security-check.d.ts +2 -0
  48. package/dist/telemetry/security-check.js +2 -0
  49. package/dist/telemetry/security-check.js.map +1 -0
  50. package/dist/telemetry/security-check.mjs +1 -0
  51. package/dist/telemetry/security-check.mjs.map +1 -0
  52. package/dist/telemetry/telemetry-client.d.ts +33 -0
  53. package/dist/telemetry/telemetry-client.js +142 -0
  54. package/dist/telemetry/telemetry-client.js.map +1 -0
  55. package/dist/telemetry/telemetry-client.mjs +8 -0
  56. package/dist/telemetry/telemetry-client.mjs.map +1 -0
  57. package/dist/telemetry/utils.d.ts +8 -0
  58. package/dist/telemetry/utils.js +69 -0
  59. package/dist/telemetry/utils.js.map +1 -0
  60. package/dist/telemetry/utils.mjs +9 -0
  61. package/dist/telemetry/utils.mjs.map +1 -0
  62. package/dist/types/action.d.ts +58 -0
  63. package/dist/types/action.js +19 -0
  64. package/dist/types/action.js.map +1 -0
  65. package/dist/types/action.mjs +2 -0
  66. package/dist/types/action.mjs.map +1 -0
  67. package/dist/types/copilot-cloud-config.d.ts +13 -0
  68. package/dist/types/copilot-cloud-config.js +19 -0
  69. package/dist/types/copilot-cloud-config.js.map +1 -0
  70. package/dist/types/copilot-cloud-config.mjs +2 -0
  71. package/dist/types/copilot-cloud-config.mjs.map +1 -0
  72. package/dist/types/index.d.ts +4 -0
  73. package/dist/types/index.js +19 -0
  74. package/dist/types/index.js.map +1 -0
  75. package/dist/types/index.mjs +6 -0
  76. package/dist/types/index.mjs.map +1 -0
  77. package/dist/types/openai-assistant.d.ts +53 -0
  78. package/dist/types/openai-assistant.js +19 -0
  79. package/dist/types/openai-assistant.js.map +1 -0
  80. package/dist/types/openai-assistant.mjs +2 -0
  81. package/dist/types/openai-assistant.mjs.map +1 -0
  82. package/dist/types/utility.d.ts +3 -0
  83. package/dist/types/utility.js +19 -0
  84. package/dist/types/utility.js.map +1 -0
  85. package/dist/types/utility.mjs +2 -0
  86. package/dist/types/utility.mjs.map +1 -0
  87. package/dist/utils/index.d.ts +4 -0
  88. package/dist/utils/index.js +157 -0
  89. package/dist/utils/index.js.map +1 -0
  90. package/dist/utils/index.mjs +18 -0
  91. package/dist/utils/index.mjs.map +1 -0
  92. package/dist/utils/json-schema.d.ts +32 -0
  93. package/dist/utils/json-schema.js +137 -0
  94. package/dist/utils/json-schema.js.map +1 -0
  95. package/dist/utils/json-schema.mjs +9 -0
  96. package/dist/utils/json-schema.mjs.map +1 -0
  97. package/dist/utils/json-schema.test.d.ts +2 -0
  98. package/dist/utils/json-schema.test.js +173 -0
  99. package/dist/utils/json-schema.test.js.map +1 -0
  100. package/dist/utils/json-schema.test.mjs +140 -0
  101. package/dist/utils/json-schema.test.mjs.map +1 -0
  102. package/dist/utils/random-id.d.ts +5 -0
  103. package/dist/utils/random-id.js +44 -0
  104. package/dist/utils/random-id.js.map +1 -0
  105. package/dist/utils/random-id.mjs +11 -0
  106. package/dist/utils/random-id.mjs.map +1 -0
  107. package/jest.config.js +5 -0
  108. package/package.json +64 -0
  109. package/src/constants/index.ts +4 -0
  110. package/src/index.ts +7 -0
  111. package/src/telemetry/events.ts +35 -0
  112. package/src/telemetry/index.ts +1 -0
  113. package/src/telemetry/security-check.ts +0 -0
  114. package/src/telemetry/telemetry-client.ts +126 -0
  115. package/src/telemetry/utils.ts +39 -0
  116. package/src/types/action.ts +128 -0
  117. package/src/types/copilot-cloud-config.ts +11 -0
  118. package/src/types/index.ts +4 -0
  119. package/src/types/openai-assistant.ts +62 -0
  120. package/src/types/utility.ts +1 -0
  121. package/src/utils/index.ts +2 -0
  122. package/src/utils/json-schema.test.ts +169 -0
  123. package/src/utils/json-schema.ts +154 -0
  124. package/src/utils/random-id.ts +13 -0
  125. package/tsconfig.json +9 -0
  126. package/tsup.config.ts +16 -0
  127. package/typedoc.json +4 -0
package/dist/index.js ADDED
@@ -0,0 +1,295 @@
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
+ COPILOTKIT_VERSION: () => COPILOTKIT_VERSION,
34
+ COPILOT_CLOUD_API_URL: () => COPILOT_CLOUD_API_URL,
35
+ COPILOT_CLOUD_CHAT_URL: () => COPILOT_CLOUD_CHAT_URL,
36
+ COPILOT_CLOUD_PUBLIC_API_KEY_HEADER: () => COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,
37
+ COPILOT_CLOUD_VERSION: () => COPILOT_CLOUD_VERSION,
38
+ TelemetryClient: () => TelemetryClient,
39
+ actionParametersToJsonSchema: () => actionParametersToJsonSchema,
40
+ convertJsonSchemaToZodSchema: () => convertJsonSchemaToZodSchema,
41
+ isValidUUID: () => isValidUUID,
42
+ randomId: () => randomId,
43
+ randomUUID: () => randomUUID
44
+ });
45
+ module.exports = __toCommonJS(src_exports);
46
+
47
+ // src/utils/json-schema.ts
48
+ var import_zod = require("zod");
49
+ function actionParametersToJsonSchema(actionParameters) {
50
+ let parameters = {};
51
+ for (let parameter of actionParameters || []) {
52
+ parameters[parameter.name] = convertAttribute(parameter);
53
+ }
54
+ let requiredParameterNames = [];
55
+ for (let arg of actionParameters || []) {
56
+ if (arg.required !== false) {
57
+ requiredParameterNames.push(arg.name);
58
+ }
59
+ }
60
+ return {
61
+ type: "object",
62
+ properties: parameters,
63
+ required: requiredParameterNames
64
+ };
65
+ }
66
+ function convertAttribute(attribute) {
67
+ var _a, _b, _c;
68
+ switch (attribute.type) {
69
+ case "string":
70
+ return {
71
+ type: "string",
72
+ description: attribute.description,
73
+ ...attribute.enum && { enum: attribute.enum }
74
+ };
75
+ case "number":
76
+ case "boolean":
77
+ return {
78
+ type: attribute.type,
79
+ description: attribute.description
80
+ };
81
+ case "object":
82
+ case "object[]":
83
+ const properties = (_a = attribute.attributes) == null ? void 0 : _a.reduce(
84
+ (acc, attr) => {
85
+ acc[attr.name] = convertAttribute(attr);
86
+ return acc;
87
+ },
88
+ {}
89
+ );
90
+ const required = (_b = attribute.attributes) == null ? void 0 : _b.filter((attr) => attr.required !== false).map((attr) => attr.name);
91
+ if (attribute.type === "object[]") {
92
+ return {
93
+ type: "array",
94
+ items: {
95
+ type: "object",
96
+ ...properties && { properties },
97
+ ...required && required.length > 0 && { required }
98
+ },
99
+ description: attribute.description
100
+ };
101
+ }
102
+ return {
103
+ type: "object",
104
+ description: attribute.description,
105
+ ...properties && { properties },
106
+ ...required && required.length > 0 && { required }
107
+ };
108
+ default:
109
+ if ((_c = attribute.type) == null ? void 0 : _c.endsWith("[]")) {
110
+ const itemType = attribute.type.slice(0, -2);
111
+ return {
112
+ type: "array",
113
+ items: { type: itemType },
114
+ description: attribute.description
115
+ };
116
+ }
117
+ return {
118
+ type: "string",
119
+ description: attribute.description
120
+ };
121
+ }
122
+ }
123
+ function convertJsonSchemaToZodSchema(jsonSchema, required) {
124
+ if (jsonSchema.type === "object") {
125
+ const spec = {};
126
+ if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) {
127
+ return !required ? import_zod.z.object(spec).optional() : import_zod.z.object(spec);
128
+ }
129
+ for (const [key, value] of Object.entries(jsonSchema.properties)) {
130
+ spec[key] = convertJsonSchemaToZodSchema(
131
+ value,
132
+ jsonSchema.required ? jsonSchema.required.includes(key) : false
133
+ );
134
+ }
135
+ let schema = import_zod.z.object(spec).describe(jsonSchema.description);
136
+ return required ? schema : schema.optional();
137
+ } else if (jsonSchema.type === "string") {
138
+ let schema = import_zod.z.string().describe(jsonSchema.description);
139
+ return required ? schema : schema.optional();
140
+ } else if (jsonSchema.type === "number") {
141
+ let schema = import_zod.z.number().describe(jsonSchema.description);
142
+ return required ? schema : schema.optional();
143
+ } else if (jsonSchema.type === "boolean") {
144
+ let schema = import_zod.z.boolean().describe(jsonSchema.description);
145
+ return required ? schema : schema.optional();
146
+ } else if (jsonSchema.type === "array") {
147
+ let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, true);
148
+ let schema = import_zod.z.array(itemSchema).describe(jsonSchema.description);
149
+ return required ? schema : schema.optional();
150
+ }
151
+ throw new Error("Invalid JSON schema");
152
+ }
153
+
154
+ // src/utils/random-id.ts
155
+ var import_uuid = require("uuid");
156
+ function randomId() {
157
+ return "ck-" + (0, import_uuid.v4)();
158
+ }
159
+ function randomUUID() {
160
+ return (0, import_uuid.v4)();
161
+ }
162
+ function isValidUUID(uuid) {
163
+ return (0, import_uuid.validate)(uuid);
164
+ }
165
+
166
+ // src/constants/index.ts
167
+ var COPILOT_CLOUD_API_URL = "https://api.cloud.copilotkit.ai";
168
+ var COPILOT_CLOUD_VERSION = "v1";
169
+ var COPILOT_CLOUD_CHAT_URL = `${COPILOT_CLOUD_API_URL}/copilotkit/${COPILOT_CLOUD_VERSION}`;
170
+ var COPILOT_CLOUD_PUBLIC_API_KEY_HEADER = "X-CopilotCloud-Public-Api-Key";
171
+
172
+ // src/telemetry/telemetry-client.ts
173
+ var import_analytics_node = require("@segment/analytics-node");
174
+
175
+ // src/telemetry/utils.ts
176
+ var import_chalk = __toESM(require("chalk"));
177
+ function flattenObject(obj, parentKey = "", res = {}) {
178
+ for (let key in obj) {
179
+ const propName = parentKey ? `${parentKey}.${key}` : key;
180
+ if (typeof obj[key] === "object" && obj[key] !== null) {
181
+ flattenObject(obj[key], propName, res);
182
+ } else {
183
+ res[propName] = obj[key];
184
+ }
185
+ }
186
+ return res;
187
+ }
188
+
189
+ // src/telemetry/telemetry-client.ts
190
+ var import_uuid2 = require("uuid");
191
+ var TelemetryClient = class {
192
+ constructor({
193
+ packageName,
194
+ packageVersion,
195
+ telemetryDisabled,
196
+ telemetryBaseUrl,
197
+ sampleRate
198
+ }) {
199
+ this.globalProperties = {};
200
+ this.cloudConfiguration = null;
201
+ this.telemetryDisabled = false;
202
+ this.sampleRate = 0.05;
203
+ this.anonymousId = `anon_${(0, import_uuid2.v4)()}`;
204
+ this.packageName = packageName;
205
+ this.packageVersion = packageVersion;
206
+ this.telemetryDisabled = telemetryDisabled || process.env.COPILOTKIT_TELEMETRY_DISABLED === "true" || process.env.COPILOTKIT_TELEMETRY_DISABLED === "1" || process.env.DO_NOT_TRACK === "true" || process.env.DO_NOT_TRACK === "1";
207
+ if (this.telemetryDisabled) {
208
+ return;
209
+ }
210
+ this.setSampleRate(sampleRate);
211
+ const writeKey = process.env.COPILOTKIT_SEGMENT_WRITE_KEY || "n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja";
212
+ this.segment = new import_analytics_node.Analytics({
213
+ writeKey
214
+ });
215
+ this.setGlobalProperties({
216
+ "copilotkit.package.name": packageName,
217
+ "copilotkit.package.version": packageVersion
218
+ });
219
+ }
220
+ shouldSendEvent() {
221
+ const randomNumber = Math.random();
222
+ return randomNumber < this.sampleRate;
223
+ }
224
+ async capture(event, properties) {
225
+ if (!this.shouldSendEvent() || !this.segment) {
226
+ return;
227
+ }
228
+ const flattenedProperties = flattenObject(properties);
229
+ const propertiesWithGlobal = {
230
+ ...this.globalProperties,
231
+ ...flattenedProperties
232
+ };
233
+ const orderedPropertiesWithGlobal = Object.keys(propertiesWithGlobal).sort().reduce(
234
+ (obj, key) => {
235
+ obj[key] = propertiesWithGlobal[key];
236
+ return obj;
237
+ },
238
+ {}
239
+ );
240
+ this.segment.track({
241
+ anonymousId: this.anonymousId,
242
+ event,
243
+ properties: { ...orderedPropertiesWithGlobal }
244
+ });
245
+ }
246
+ setGlobalProperties(properties) {
247
+ const flattenedProperties = flattenObject(properties);
248
+ this.globalProperties = { ...this.globalProperties, ...flattenedProperties };
249
+ }
250
+ setCloudConfiguration(properties) {
251
+ this.cloudConfiguration = properties;
252
+ this.setGlobalProperties({
253
+ cloud: {
254
+ publicApiKey: properties.publicApiKey,
255
+ baseUrl: properties.baseUrl
256
+ }
257
+ });
258
+ }
259
+ setSampleRate(sampleRate) {
260
+ let _sampleRate;
261
+ _sampleRate = sampleRate ?? 0.05;
262
+ if (process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE) {
263
+ _sampleRate = parseFloat(process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE);
264
+ }
265
+ if (_sampleRate < 0 || _sampleRate > 1) {
266
+ throw new Error("Sample rate must be between 0 and 1");
267
+ }
268
+ this.sampleRate = _sampleRate;
269
+ this.setGlobalProperties({
270
+ sampleRate: this.sampleRate,
271
+ sampleRateAdjustmentFactor: 1 - this.sampleRate
272
+ });
273
+ }
274
+ };
275
+
276
+ // package.json
277
+ var version = "1.5.12-next.4";
278
+
279
+ // src/index.ts
280
+ var COPILOTKIT_VERSION = version;
281
+ // Annotate the CommonJS export names for ESM import in node:
282
+ 0 && (module.exports = {
283
+ COPILOTKIT_VERSION,
284
+ COPILOT_CLOUD_API_URL,
285
+ COPILOT_CLOUD_CHAT_URL,
286
+ COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,
287
+ COPILOT_CLOUD_VERSION,
288
+ TelemetryClient,
289
+ actionParametersToJsonSchema,
290
+ convertJsonSchemaToZodSchema,
291
+ isValidUUID,
292
+ randomId,
293
+ randomUUID
294
+ });
295
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/utils/json-schema.ts","../src/utils/random-id.ts","../src/constants/index.ts","../src/telemetry/telemetry-client.ts","../src/telemetry/utils.ts","../package.json"],"sourcesContent":["export * from \"./types\";\nexport * from \"./utils\";\nexport * from \"./constants\";\nexport * from \"./telemetry\";\n\nimport * as packageJson from \"../package.json\";\nexport const COPILOTKIT_VERSION = packageJson.version;\n","import { z } from \"zod\";\nimport { Parameter } from \"../types\";\n\nexport type JSONSchemaString = {\n type: \"string\";\n description?: string;\n enum?: string[];\n};\n\nexport type JSONSchemaNumber = {\n type: \"number\";\n description?: string;\n};\n\nexport type JSONSchemaBoolean = {\n type: \"boolean\";\n description?: string;\n};\n\nexport type JSONSchemaObject = {\n type: \"object\";\n properties?: Record<string, JSONSchema>;\n required?: string[];\n description?: string;\n};\n\nexport type JSONSchemaArray = {\n type: \"array\";\n items: JSONSchema;\n description?: string;\n};\n\nexport type JSONSchema =\n | JSONSchemaString\n | JSONSchemaNumber\n | JSONSchemaBoolean\n | JSONSchemaObject\n | JSONSchemaArray;\n\nexport function actionParametersToJsonSchema(actionParameters: Parameter[]): JSONSchema {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let parameter of actionParameters || []) {\n parameters[parameter.name] = convertAttribute(parameter);\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of actionParameters || []) {\n if (arg.required !== false) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n return {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n };\n}\n\nfunction convertAttribute(attribute: Parameter): JSONSchema {\n switch (attribute.type) {\n case \"string\":\n return {\n type: \"string\",\n description: attribute.description,\n ...(attribute.enum && { enum: attribute.enum }),\n };\n case \"number\":\n case \"boolean\":\n return {\n type: attribute.type,\n description: attribute.description,\n };\n case \"object\":\n case \"object[]\":\n const properties = attribute.attributes?.reduce(\n (acc, attr) => {\n acc[attr.name] = convertAttribute(attr);\n return acc;\n },\n {} as Record<string, any>,\n );\n const required = attribute.attributes\n ?.filter((attr) => attr.required !== false)\n .map((attr) => attr.name);\n if (attribute.type === \"object[]\") {\n return {\n type: \"array\",\n items: {\n type: \"object\",\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n },\n description: attribute.description,\n };\n }\n return {\n type: \"object\",\n description: attribute.description,\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n };\n default:\n // Handle arrays of primitive types and undefined attribute.type\n if (attribute.type?.endsWith(\"[]\")) {\n const itemType = attribute.type.slice(0, -2);\n return {\n type: \"array\",\n items: { type: itemType as any },\n description: attribute.description,\n };\n }\n // Fallback for undefined type or any other unexpected type\n return {\n type: \"string\",\n description: attribute.description,\n };\n }\n}\n\nexport function convertJsonSchemaToZodSchema(jsonSchema: any, required: boolean): z.ZodSchema {\n if (jsonSchema.type === \"object\") {\n const spec: { [key: string]: z.ZodSchema } = {};\n\n if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) {\n return !required ? z.object(spec).optional() : z.object(spec);\n }\n\n for (const [key, value] of Object.entries(jsonSchema.properties)) {\n spec[key] = convertJsonSchemaToZodSchema(\n value,\n jsonSchema.required ? jsonSchema.required.includes(key) : false,\n );\n }\n let schema = z.object(spec).describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"string\") {\n let schema = z.string().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"number\") {\n let schema = z.number().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"boolean\") {\n let schema = z.boolean().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"array\") {\n let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, true);\n let schema = z.array(itemSchema).describe(jsonSchema.description);\n return required ? schema : schema.optional();\n }\n throw new Error(\"Invalid JSON schema\");\n}\n","import { v4 as uuidv4, validate } from \"uuid\";\n\nexport function randomId() {\n return \"ck-\" + uuidv4();\n}\n\nexport function randomUUID() {\n return uuidv4();\n}\n\nexport function isValidUUID(uuid: string) {\n return validate(uuid);\n}\n","export const COPILOT_CLOUD_API_URL = \"https://api.cloud.copilotkit.ai\";\nexport const COPILOT_CLOUD_VERSION = \"v1\";\nexport const COPILOT_CLOUD_CHAT_URL = `${COPILOT_CLOUD_API_URL}/copilotkit/${COPILOT_CLOUD_VERSION}`;\nexport const COPILOT_CLOUD_PUBLIC_API_KEY_HEADER = \"X-CopilotCloud-Public-Api-Key\";\n","import { Analytics } from \"@segment/analytics-node\";\nimport { AnalyticsEvents } from \"./events\";\nimport { flattenObject, printSecurityNotice } from \"./utils\";\nimport { v4 as uuidv4 } from \"uuid\";\n\nexport class TelemetryClient {\n segment: Analytics | undefined;\n globalProperties: Record<string, any> = {};\n cloudConfiguration: { publicApiKey: string; baseUrl: string } | null = null;\n packageName: string;\n packageVersion: string;\n private telemetryDisabled: boolean = false;\n private sampleRate: number = 0.05;\n private anonymousId = `anon_${uuidv4()}`;\n\n constructor({\n packageName,\n packageVersion,\n telemetryDisabled,\n telemetryBaseUrl,\n sampleRate,\n }: {\n packageName: string;\n packageVersion: string;\n telemetryDisabled?: boolean;\n telemetryBaseUrl?: string;\n sampleRate?: number;\n }) {\n this.packageName = packageName;\n this.packageVersion = packageVersion;\n this.telemetryDisabled =\n telemetryDisabled ||\n (process.env as any).COPILOTKIT_TELEMETRY_DISABLED === \"true\" ||\n (process.env as any).COPILOTKIT_TELEMETRY_DISABLED === \"1\" ||\n (process.env as any).DO_NOT_TRACK === \"true\" ||\n (process.env as any).DO_NOT_TRACK === \"1\";\n\n if (this.telemetryDisabled) {\n return;\n }\n\n this.setSampleRate(sampleRate);\n\n // eslint-disable-next-line\n const writeKey = process.env.COPILOTKIT_SEGMENT_WRITE_KEY || \"n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja\";\n\n this.segment = new Analytics({\n writeKey,\n });\n\n this.setGlobalProperties({\n \"copilotkit.package.name\": packageName,\n \"copilotkit.package.version\": packageVersion,\n });\n }\n\n private shouldSendEvent() {\n const randomNumber = Math.random();\n return randomNumber < this.sampleRate;\n }\n\n async capture<K extends keyof AnalyticsEvents>(event: K, properties: AnalyticsEvents[K]) {\n if (!this.shouldSendEvent() || !this.segment) {\n return;\n }\n\n const flattenedProperties = flattenObject(properties);\n const propertiesWithGlobal = {\n ...this.globalProperties,\n ...flattenedProperties,\n };\n const orderedPropertiesWithGlobal = Object.keys(propertiesWithGlobal)\n .sort()\n .reduce(\n (obj, key) => {\n obj[key] = propertiesWithGlobal[key];\n return obj;\n },\n {} as Record<string, any>,\n );\n\n this.segment.track({\n anonymousId: this.anonymousId,\n event,\n properties: { ...orderedPropertiesWithGlobal },\n });\n }\n\n setGlobalProperties(properties: Record<string, any>) {\n const flattenedProperties = flattenObject(properties);\n this.globalProperties = { ...this.globalProperties, ...flattenedProperties };\n }\n\n setCloudConfiguration(properties: { publicApiKey: string; baseUrl: string }) {\n this.cloudConfiguration = properties;\n\n this.setGlobalProperties({\n cloud: {\n publicApiKey: properties.publicApiKey,\n baseUrl: properties.baseUrl,\n },\n });\n }\n\n private setSampleRate(sampleRate: number | undefined) {\n let _sampleRate: number;\n\n _sampleRate = sampleRate ?? 0.05;\n\n // eslint-disable-next-line\n if (process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE) {\n // eslint-disable-next-line\n _sampleRate = parseFloat(process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE);\n }\n\n if (_sampleRate < 0 || _sampleRate > 1) {\n throw new Error(\"Sample rate must be between 0 and 1\");\n }\n\n this.sampleRate = _sampleRate;\n this.setGlobalProperties({\n sampleRate: this.sampleRate,\n sampleRateAdjustmentFactor: 1 - this.sampleRate,\n });\n }\n}\n","import chalk from \"chalk\";\n\nexport function flattenObject(\n obj: Record<string, any>,\n parentKey = \"\",\n res: Record<string, any> = {},\n): Record<string, any> {\n for (let key in obj) {\n const propName = parentKey ? `${parentKey}.${key}` : key;\n if (typeof obj[key] === \"object\" && obj[key] !== null) {\n flattenObject(obj[key], propName, res);\n } else {\n res[propName] = obj[key];\n }\n }\n return res;\n}\n\nexport function printSecurityNotice(advisory: {\n advisory: string | null;\n message: string;\n severity: \"low\" | \"medium\" | \"high\" | \"none\";\n}) {\n const severityColor =\n {\n low: chalk.blue,\n medium: chalk.yellow,\n high: chalk.red,\n }[advisory.severity.toLowerCase()] || chalk.white;\n\n console.log();\n console.log(`━━━━━━━━━━━━━━━━━━ ${chalk.bold(`CopilotKit`)} ━━━━━━━━━━━━━━━━━━`);\n console.log();\n console.log(`${chalk.bold(`Severity: ${severityColor(advisory.severity.toUpperCase())}`)}`);\n console.log();\n console.log(`${chalk.bold(advisory.message)}`);\n console.log();\n console.log(`━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`);\n}\n","{\n \"name\": \"@copilotkit/shared\",\n \"private\": false,\n \"homepage\": \"https://github.com/CopilotKit/CopilotKit\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/CopilotKit/CopilotKit.git\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"version\": \"1.5.12-next.4\",\n \"sideEffects\": false,\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"exports\": {\n \".\": {\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\"\n }\n },\n \"types\": \"./dist/index.d.ts\",\n \"license\": \"MIT\",\n \"scripts\": {\n \"build\": \"tsup --clean\",\n \"dev\": \"tsup --watch --no-splitting\",\n \"test\": \"jest --passWithNoTests\",\n \"check-types\": \"tsc --noEmit\",\n \"clean\": \"rm -rf .turbo && rm -rf node_modules && rm -rf dist && rm -rf .next\",\n \"link:global\": \"pnpm link --global\",\n \"unlink:global\": \"pnpm unlink --global\"\n },\n \"devDependencies\": {\n \"@types/jest\": \"^29.5.4\",\n \"@types/uuid\": \"^10.0.0\",\n \"eslint\": \"^8.56.0\",\n \"eslint-config-custom\": \"workspace:*\",\n \"jest\": \"^29.6.4\",\n \"ts-jest\": \"^29.1.1\",\n \"tsconfig\": \"workspace:*\",\n \"tsup\": \"^6.7.0\",\n \"typescript\": \"^5.2.3\"\n },\n \"dependencies\": {\n \"@segment/analytics-node\": \"^2.1.2\",\n \"chalk\": \"4.1.2\",\n \"uuid\": \"^10.0.0\",\n \"zod\": \"^3.23.3\",\n \"zod-to-json-schema\": \"^3.23.5\"\n },\n \"keywords\": [\n \"copilotkit\",\n \"copilot\",\n \"react\",\n \"nextjs\",\n \"nodejs\",\n \"ai\",\n \"assistant\",\n \"javascript\",\n \"automation\",\n \"textarea\"\n ]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAAkB;AAuCX,SAAS,6BAA6B,kBAA2C;AAEtF,MAAI,aAAqC,CAAC;AAC1C,WAAS,aAAa,oBAAoB,CAAC,GAAG;AAC5C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AA,MACtB;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEQ,cAAc,YAAgC;AACpD,QAAI;AAEJ,kBAAc,cAAc;AAG5B,QAAI,QAAQ,IAAI,kCAAkC;AAEhD,oBAAc,WAAW,QAAQ,IAAI,gCAAgC;AAAA,IACvE;AAEA,QAAI,cAAc,KAAK,cAAc,GAAG;AACtC,YAAM,IAAI,MAAM,qCAAqC;AAAA,IACvD;AAEA,SAAK,aAAa;AAClB,SAAK,oBAAoB;AAAA,MACvB,YAAY,KAAK;AAAA,MACjB,4BAA4B,IAAI,KAAK;AAAA,IACvC,CAAC;AAAA,EACH;AACF;;;AElHE,cAAW;;;ANLN,IAAM,qBAAiC;","names":["uuidv4","import_uuid","uuidv4"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,46 @@
1
+ import "./chunk-BANDZXMP.mjs";
2
+ import "./chunk-MSUB6DGR.mjs";
3
+ import "./chunk-IAFBVORQ.mjs";
4
+ import "./chunk-FCCOSO5L.mjs";
5
+ import "./chunk-CYDWEPFL.mjs";
6
+ import {
7
+ actionParametersToJsonSchema,
8
+ convertJsonSchemaToZodSchema
9
+ } from "./chunk-JP2M4U4G.mjs";
10
+ import {
11
+ isValidUUID,
12
+ randomId,
13
+ randomUUID
14
+ } from "./chunk-53DC2JUS.mjs";
15
+ import {
16
+ COPILOT_CLOUD_API_URL,
17
+ COPILOT_CLOUD_CHAT_URL,
18
+ COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,
19
+ COPILOT_CLOUD_VERSION
20
+ } from "./chunk-GYZIHHE6.mjs";
21
+ import "./chunk-P7STFMPO.mjs";
22
+ import {
23
+ TelemetryClient
24
+ } from "./chunk-QFITLWYZ.mjs";
25
+ import "./chunk-6QGXWNS5.mjs";
26
+ import "./chunk-NAFEBKSO.mjs";
27
+
28
+ // package.json
29
+ var version = "1.5.12-next.4";
30
+
31
+ // src/index.ts
32
+ var COPILOTKIT_VERSION = version;
33
+ export {
34
+ COPILOTKIT_VERSION,
35
+ COPILOT_CLOUD_API_URL,
36
+ COPILOT_CLOUD_CHAT_URL,
37
+ COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,
38
+ COPILOT_CLOUD_VERSION,
39
+ TelemetryClient,
40
+ actionParametersToJsonSchema,
41
+ convertJsonSchemaToZodSchema,
42
+ isValidUUID,
43
+ randomId,
44
+ randomUUID
45
+ };
46
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../package.json","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@copilotkit/shared\",\n \"private\": false,\n \"homepage\": \"https://github.com/CopilotKit/CopilotKit\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/CopilotKit/CopilotKit.git\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"version\": \"1.5.12-next.4\",\n \"sideEffects\": false,\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"exports\": {\n \".\": {\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\"\n }\n },\n \"types\": \"./dist/index.d.ts\",\n \"license\": \"MIT\",\n \"scripts\": {\n \"build\": \"tsup --clean\",\n \"dev\": \"tsup --watch --no-splitting\",\n \"test\": \"jest --passWithNoTests\",\n \"check-types\": \"tsc --noEmit\",\n \"clean\": \"rm -rf .turbo && rm -rf node_modules && rm -rf dist && rm -rf .next\",\n \"link:global\": \"pnpm link --global\",\n \"unlink:global\": \"pnpm unlink --global\"\n },\n \"devDependencies\": {\n \"@types/jest\": \"^29.5.4\",\n \"@types/uuid\": \"^10.0.0\",\n \"eslint\": \"^8.56.0\",\n \"eslint-config-custom\": \"workspace:*\",\n \"jest\": \"^29.6.4\",\n \"ts-jest\": \"^29.1.1\",\n \"tsconfig\": \"workspace:*\",\n \"tsup\": \"^6.7.0\",\n \"typescript\": \"^5.2.3\"\n },\n \"dependencies\": {\n \"@segment/analytics-node\": \"^2.1.2\",\n \"chalk\": \"4.1.2\",\n \"uuid\": \"^10.0.0\",\n \"zod\": \"^3.23.3\",\n \"zod-to-json-schema\": \"^3.23.5\"\n },\n \"keywords\": [\n \"copilotkit\",\n \"copilot\",\n \"react\",\n \"nextjs\",\n \"nodejs\",\n \"ai\",\n \"assistant\",\n \"javascript\",\n \"automation\",\n \"textarea\"\n ]\n}\n","export * from \"./types\";\nexport * from \"./utils\";\nexport * from \"./constants\";\nexport * from \"./telemetry\";\n\nimport * as packageJson from \"../package.json\";\nexport const COPILOTKIT_VERSION = packageJson.version;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWE,cAAW;;;ACLN,IAAM,qBAAiC;","names":[]}
@@ -0,0 +1,39 @@
1
+ type AnalyticsEvents = {
2
+ "oss.runtime.instance_created": RuntimeInstanceCreatedInfo;
3
+ "oss.runtime.copilot_request_created": {
4
+ "cloud.guardrails.enabled": boolean;
5
+ requestType: string;
6
+ };
7
+ "oss.runtime.server_action_executed": {};
8
+ "oss.runtime.remote_action_executed": RemoteActionExecutionInfo;
9
+ "oss.runtime.agent_execution_stream_started": {
10
+ hashedLgcKey?: string;
11
+ };
12
+ "oss.runtime.agent_execution_stream_ended": AgentExecutionResponseInfo;
13
+ "oss.runtime.agent_execution_stream_errored": {
14
+ hashedLgcKey?: string;
15
+ error?: string;
16
+ };
17
+ };
18
+ interface RuntimeInstanceCreatedInfo {
19
+ actionsAmount: number;
20
+ endpointTypes: string[];
21
+ hashedLgcKey?: string;
22
+ endpointsAmount: number;
23
+ agentsAmount?: number | null;
24
+ }
25
+ interface RemoteActionExecutionInfo {
26
+ agentExecution: boolean;
27
+ type: "self-hosted" | "langgraph-platform";
28
+ agentsAmount?: number | null;
29
+ hashedLgcKey?: string;
30
+ }
31
+ interface AgentExecutionResponseInfo {
32
+ provider?: string;
33
+ model?: string;
34
+ langGraphHost?: string;
35
+ langGraphVersion?: string;
36
+ hashedLgcKey?: string;
37
+ }
38
+
39
+ export { AgentExecutionResponseInfo, AnalyticsEvents, RemoteActionExecutionInfo, RuntimeInstanceCreatedInfo };
@@ -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/telemetry/events.ts
17
+ var events_exports = {};
18
+ module.exports = __toCommonJS(events_exports);
19
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/telemetry/events.ts"],"sourcesContent":["export type AnalyticsEvents = {\n \"oss.runtime.instance_created\": RuntimeInstanceCreatedInfo;\n \"oss.runtime.copilot_request_created\": {\n \"cloud.guardrails.enabled\": boolean;\n requestType: string;\n };\n \"oss.runtime.server_action_executed\": {};\n \"oss.runtime.remote_action_executed\": RemoteActionExecutionInfo;\n \"oss.runtime.agent_execution_stream_started\": { hashedLgcKey?: string };\n \"oss.runtime.agent_execution_stream_ended\": AgentExecutionResponseInfo;\n \"oss.runtime.agent_execution_stream_errored\": { hashedLgcKey?: string; error?: string };\n};\n\nexport interface RuntimeInstanceCreatedInfo {\n actionsAmount: number;\n endpointTypes: string[];\n hashedLgcKey?: string;\n endpointsAmount: number;\n agentsAmount?: number | null;\n}\n\nexport interface RemoteActionExecutionInfo {\n agentExecution: boolean;\n type: \"self-hosted\" | \"langgraph-platform\";\n agentsAmount?: number | null;\n hashedLgcKey?: string;\n}\n\nexport interface AgentExecutionResponseInfo {\n provider?: string;\n model?: string;\n langGraphHost?: string;\n langGraphVersion?: string;\n hashedLgcKey?: string;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=events.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,3 @@
1
+ export { TelemetryClient } from './telemetry-client.js';
2
+ import '@segment/analytics-node';
3
+ import './events.js';
@@ -0,0 +1,144 @@
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/telemetry/index.ts
31
+ var telemetry_exports = {};
32
+ __export(telemetry_exports, {
33
+ TelemetryClient: () => TelemetryClient
34
+ });
35
+ module.exports = __toCommonJS(telemetry_exports);
36
+
37
+ // src/telemetry/telemetry-client.ts
38
+ var import_analytics_node = require("@segment/analytics-node");
39
+
40
+ // src/telemetry/utils.ts
41
+ var import_chalk = __toESM(require("chalk"));
42
+ function flattenObject(obj, parentKey = "", res = {}) {
43
+ for (let key in obj) {
44
+ const propName = parentKey ? `${parentKey}.${key}` : key;
45
+ if (typeof obj[key] === "object" && obj[key] !== null) {
46
+ flattenObject(obj[key], propName, res);
47
+ } else {
48
+ res[propName] = obj[key];
49
+ }
50
+ }
51
+ return res;
52
+ }
53
+
54
+ // src/telemetry/telemetry-client.ts
55
+ var import_uuid = require("uuid");
56
+ var TelemetryClient = class {
57
+ constructor({
58
+ packageName,
59
+ packageVersion,
60
+ telemetryDisabled,
61
+ telemetryBaseUrl,
62
+ sampleRate
63
+ }) {
64
+ this.globalProperties = {};
65
+ this.cloudConfiguration = null;
66
+ this.telemetryDisabled = false;
67
+ this.sampleRate = 0.05;
68
+ this.anonymousId = `anon_${(0, import_uuid.v4)()}`;
69
+ this.packageName = packageName;
70
+ this.packageVersion = packageVersion;
71
+ this.telemetryDisabled = telemetryDisabled || process.env.COPILOTKIT_TELEMETRY_DISABLED === "true" || process.env.COPILOTKIT_TELEMETRY_DISABLED === "1" || process.env.DO_NOT_TRACK === "true" || process.env.DO_NOT_TRACK === "1";
72
+ if (this.telemetryDisabled) {
73
+ return;
74
+ }
75
+ this.setSampleRate(sampleRate);
76
+ const writeKey = process.env.COPILOTKIT_SEGMENT_WRITE_KEY || "n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja";
77
+ this.segment = new import_analytics_node.Analytics({
78
+ writeKey
79
+ });
80
+ this.setGlobalProperties({
81
+ "copilotkit.package.name": packageName,
82
+ "copilotkit.package.version": packageVersion
83
+ });
84
+ }
85
+ shouldSendEvent() {
86
+ const randomNumber = Math.random();
87
+ return randomNumber < this.sampleRate;
88
+ }
89
+ async capture(event, properties) {
90
+ if (!this.shouldSendEvent() || !this.segment) {
91
+ return;
92
+ }
93
+ const flattenedProperties = flattenObject(properties);
94
+ const propertiesWithGlobal = {
95
+ ...this.globalProperties,
96
+ ...flattenedProperties
97
+ };
98
+ const orderedPropertiesWithGlobal = Object.keys(propertiesWithGlobal).sort().reduce(
99
+ (obj, key) => {
100
+ obj[key] = propertiesWithGlobal[key];
101
+ return obj;
102
+ },
103
+ {}
104
+ );
105
+ this.segment.track({
106
+ anonymousId: this.anonymousId,
107
+ event,
108
+ properties: { ...orderedPropertiesWithGlobal }
109
+ });
110
+ }
111
+ setGlobalProperties(properties) {
112
+ const flattenedProperties = flattenObject(properties);
113
+ this.globalProperties = { ...this.globalProperties, ...flattenedProperties };
114
+ }
115
+ setCloudConfiguration(properties) {
116
+ this.cloudConfiguration = properties;
117
+ this.setGlobalProperties({
118
+ cloud: {
119
+ publicApiKey: properties.publicApiKey,
120
+ baseUrl: properties.baseUrl
121
+ }
122
+ });
123
+ }
124
+ setSampleRate(sampleRate) {
125
+ let _sampleRate;
126
+ _sampleRate = sampleRate ?? 0.05;
127
+ if (process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE) {
128
+ _sampleRate = parseFloat(process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE);
129
+ }
130
+ if (_sampleRate < 0 || _sampleRate > 1) {
131
+ throw new Error("Sample rate must be between 0 and 1");
132
+ }
133
+ this.sampleRate = _sampleRate;
134
+ this.setGlobalProperties({
135
+ sampleRate: this.sampleRate,
136
+ sampleRateAdjustmentFactor: 1 - this.sampleRate
137
+ });
138
+ }
139
+ };
140
+ // Annotate the CommonJS export names for ESM import in node:
141
+ 0 && (module.exports = {
142
+ TelemetryClient
143
+ });
144
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/telemetry/index.ts","../../src/telemetry/telemetry-client.ts","../../src/telemetry/utils.ts"],"sourcesContent":["export * from \"./telemetry-client\";\n","import { Analytics } from \"@segment/analytics-node\";\nimport { AnalyticsEvents } from \"./events\";\nimport { flattenObject, printSecurityNotice } from \"./utils\";\nimport { v4 as uuidv4 } from \"uuid\";\n\nexport class TelemetryClient {\n segment: Analytics | undefined;\n globalProperties: Record<string, any> = {};\n cloudConfiguration: { publicApiKey: string; baseUrl: string } | null = null;\n packageName: string;\n packageVersion: string;\n private telemetryDisabled: boolean = false;\n private sampleRate: number = 0.05;\n private anonymousId = `anon_${uuidv4()}`;\n\n constructor({\n packageName,\n packageVersion,\n telemetryDisabled,\n telemetryBaseUrl,\n sampleRate,\n }: {\n packageName: string;\n packageVersion: string;\n telemetryDisabled?: boolean;\n telemetryBaseUrl?: string;\n sampleRate?: number;\n }) {\n this.packageName = packageName;\n this.packageVersion = packageVersion;\n this.telemetryDisabled =\n telemetryDisabled ||\n (process.env as any).COPILOTKIT_TELEMETRY_DISABLED === \"true\" ||\n (process.env as any).COPILOTKIT_TELEMETRY_DISABLED === \"1\" ||\n (process.env as any).DO_NOT_TRACK === \"true\" ||\n (process.env as any).DO_NOT_TRACK === \"1\";\n\n if (this.telemetryDisabled) {\n return;\n }\n\n this.setSampleRate(sampleRate);\n\n // eslint-disable-next-line\n const writeKey = process.env.COPILOTKIT_SEGMENT_WRITE_KEY || \"n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja\";\n\n this.segment = new Analytics({\n writeKey,\n });\n\n this.setGlobalProperties({\n \"copilotkit.package.name\": packageName,\n \"copilotkit.package.version\": packageVersion,\n });\n }\n\n private shouldSendEvent() {\n const randomNumber = Math.random();\n return randomNumber < this.sampleRate;\n }\n\n async capture<K extends keyof AnalyticsEvents>(event: K, properties: AnalyticsEvents[K]) {\n if (!this.shouldSendEvent() || !this.segment) {\n return;\n }\n\n const flattenedProperties = flattenObject(properties);\n const propertiesWithGlobal = {\n ...this.globalProperties,\n ...flattenedProperties,\n };\n const orderedPropertiesWithGlobal = Object.keys(propertiesWithGlobal)\n .sort()\n .reduce(\n (obj, key) => {\n obj[key] = propertiesWithGlobal[key];\n return obj;\n },\n {} as Record<string, any>,\n );\n\n this.segment.track({\n anonymousId: this.anonymousId,\n event,\n properties: { ...orderedPropertiesWithGlobal },\n });\n }\n\n setGlobalProperties(properties: Record<string, any>) {\n const flattenedProperties = flattenObject(properties);\n this.globalProperties = { ...this.globalProperties, ...flattenedProperties };\n }\n\n setCloudConfiguration(properties: { publicApiKey: string; baseUrl: string }) {\n this.cloudConfiguration = properties;\n\n this.setGlobalProperties({\n cloud: {\n publicApiKey: properties.publicApiKey,\n baseUrl: properties.baseUrl,\n },\n });\n }\n\n private setSampleRate(sampleRate: number | undefined) {\n let _sampleRate: number;\n\n _sampleRate = sampleRate ?? 0.05;\n\n // eslint-disable-next-line\n if (process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE) {\n // eslint-disable-next-line\n _sampleRate = parseFloat(process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE);\n }\n\n if (_sampleRate < 0 || _sampleRate > 1) {\n throw new Error(\"Sample rate must be between 0 and 1\");\n }\n\n this.sampleRate = _sampleRate;\n this.setGlobalProperties({\n sampleRate: this.sampleRate,\n sampleRateAdjustmentFactor: 1 - this.sampleRate,\n });\n }\n}\n","import chalk from \"chalk\";\n\nexport function flattenObject(\n obj: Record<string, any>,\n parentKey = \"\",\n res: Record<string, any> = {},\n): Record<string, any> {\n for (let key in obj) {\n const propName = parentKey ? `${parentKey}.${key}` : key;\n if (typeof obj[key] === \"object\" && obj[key] !== null) {\n flattenObject(obj[key], propName, res);\n } else {\n res[propName] = obj[key];\n }\n }\n return res;\n}\n\nexport function printSecurityNotice(advisory: {\n advisory: string | null;\n message: string;\n severity: \"low\" | \"medium\" | \"high\" | \"none\";\n}) {\n const severityColor =\n {\n low: chalk.blue,\n medium: chalk.yellow,\n high: chalk.red,\n }[advisory.severity.toLowerCase()] || chalk.white;\n\n console.log();\n console.log(`━━━━━━━━━━━━━━━━━━ ${chalk.bold(`CopilotKit`)} ━━━━━━━━━━━━━━━━━━`);\n console.log();\n console.log(`${chalk.bold(`Severity: ${severityColor(advisory.severity.toUpperCase())}`)}`);\n console.log();\n console.log(`${chalk.bold(advisory.message)}`);\n console.log();\n console.log(`━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,4BAA0B;;;ACA1B,mBAAkB;AAEX,SAAS,cACd,KACA,YAAY,IACZ,MAA2B,CAAC,GACP;AACrB,WAAS,OAAO,KAAK;AACnB,UAAM,WAAW,YAAY,GAAG,aAAa,QAAQ;AACrD,QAAI,OAAO,IAAI,GAAG,MAAM,YAAY,IAAI,GAAG,MAAM,MAAM;AACrD,oBAAc,IAAI,GAAG,GAAG,UAAU,GAAG;AAAA,IACvC,OAAO;AACL,UAAI,QAAQ,IAAI,IAAI,GAAG;AAAA,IACzB;AAAA,EACF;AACA,SAAO;AACT;;;ADbA,kBAA6B;AAEtB,IAAM,kBAAN,MAAsB;AAAA,EAU3B,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAMG;AApBH,4BAAwC,CAAC;AACzC,8BAAuE;AAGvE,SAAQ,oBAA6B;AACrC,SAAQ,aAAqB;AAC7B,SAAQ,cAAc,YAAQ,YAAAA,IAAO;AAenC,SAAK,cAAc;AACnB,SAAK,iBAAiB;AACtB,SAAK,oBACH,qBACC,QAAQ,IAAY,kCAAkC,UACtD,QAAQ,IAAY,kCAAkC,OACtD,QAAQ,IAAY,iBAAiB,UACrC,QAAQ,IAAY,iBAAiB;AAExC,QAAI,KAAK,mBAAmB;AAC1B;AAAA,IACF;AAEA,SAAK,cAAc,UAAU;AAG7B,UAAM,WAAW,QAAQ,IAAI,gCAAgC;AAE7D,SAAK,UAAU,IAAI,gCAAU;AAAA,MAC3B;AAAA,IACF,CAAC;AAED,SAAK,oBAAoB;AAAA,MACvB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ClB,SAAK,oBAAoB;AAAA,MACvB,YAAY,KAAK;AAAA,MACjB,4BAA4B,IAAI,KAAK;AAAA,IACvC,CAAC;AAAA,EACH;AACF;","names":["uuidv4"]}
@@ -0,0 +1,9 @@
1
+ import "../chunk-P7STFMPO.mjs";
2
+ import {
3
+ TelemetryClient
4
+ } from "../chunk-QFITLWYZ.mjs";
5
+ import "../chunk-6QGXWNS5.mjs";
6
+ export {
7
+ TelemetryClient
8
+ };
9
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=security-check.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=security-check.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}