@copilotkit/shared 1.0.6 → 1.0.7

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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @copilotkit/shared@1.0.6 build /home/runner/work/CopilotKit/CopilotKit/CopilotKit/packages/shared
2
+ > @copilotkit/shared@1.0.7 build /home/runner/work/CopilotKit/CopilotKit/CopilotKit/packages/shared
3
3
  > tsup --clean
4
4
 
5
5
  CLI Building entry: src/index.ts, src/constants/index.ts, src/telemetry/events.ts, src/telemetry/index.ts, src/telemetry/security-check.ts, src/telemetry/telemetry-client.ts, src/telemetry/utils.ts, src/types/action.ts, src/types/copilot-cloud-config.ts, src/types/index.ts, src/types/openai-assistant.ts, src/utils/index.ts, src/utils/json-schema.ts, src/utils/random-id.ts
@@ -10,88 +10,88 @@
10
10
  CLI Cleaning output folder
11
11
  ESM Build start
12
12
  CJS Build start
13
- CJS dist/index.js 9.53 KB
13
+ CJS dist/utils/index.js 3.37 KB
14
+ CJS dist/index.js 7.96 KB
14
15
  CJS dist/constants/index.js 1.64 KB
15
16
  CJS dist/telemetry/events.js 805.00 B
16
- CJS dist/types/action.js 801.00 B
17
- CJS dist/utils/index.js 3.37 KB
18
- CJS dist/telemetry/index.js 6.58 KB
17
+ CJS dist/telemetry/index.js 5.01 KB
19
18
  CJS dist/telemetry/security-check.js 56.00 B
20
- CJS dist/telemetry/telemetry-client.js 6.58 KB
19
+ CJS dist/telemetry/telemetry-client.js 5.01 KB
21
20
  CJS dist/telemetry/utils.js 3.14 KB
21
+ CJS dist/types/action.js 801.00 B
22
22
  CJS dist/types/copilot-cloud-config.js 857.00 B
23
23
  CJS dist/types/index.js 797.00 B
24
24
  CJS dist/types/openai-assistant.js 841.00 B
25
25
  CJS dist/utils/json-schema.js 3.23 KB
26
26
  CJS dist/utils/random-id.js 1.15 KB
27
- CJS dist/index.js.map 13.80 KB
27
+ CJS dist/utils/index.js.map 5.02 KB
28
+ CJS dist/index.js.map 12.48 KB
28
29
  CJS dist/constants/index.js.map 551.00 B
29
30
  CJS dist/telemetry/events.js.map 330.00 B
30
- CJS dist/types/action.js.map 4.84 KB
31
- CJS dist/utils/index.js.map 5.02 KB
32
- CJS dist/telemetry/index.js.map 8.49 KB
31
+ CJS dist/telemetry/index.js.map 7.18 KB
33
32
  CJS dist/telemetry/security-check.js.map 71.00 B
34
- CJS dist/telemetry/telemetry-client.js.map 8.42 KB
33
+ CJS dist/telemetry/telemetry-client.js.map 7.10 KB
35
34
  CJS dist/telemetry/utils.js.map 2.00 KB
35
+ CJS dist/types/action.js.map 4.84 KB
36
36
  CJS dist/types/copilot-cloud-config.js.map 356.00 B
37
37
  CJS dist/types/index.js.map 236.00 B
38
38
  CJS dist/types/openai-assistant.js.map 1.53 KB
39
39
  CJS dist/utils/json-schema.js.map 4.75 KB
40
40
  CJS dist/utils/random-id.js.map 285.00 B
41
- CJS ⚡️ Build success in 82ms
42
- ESM dist/types/copilot-cloud-config.mjs 81.00 B
43
- ESM dist/types/index.mjs 162.00 B
44
- ESM dist/types/openai-assistant.mjs 77.00 B
45
- ESM dist/utils/index.mjs 245.00 B
46
- ESM dist/utils/json-schema.mjs 155.00 B
47
- ESM dist/utils/random-id.mjs 113.00 B
41
+ CJS ⚡️ Build success in 130ms
48
42
  ESM dist/index.mjs 774.00 B
43
+ ESM dist/constants/index.mjs 315.00 B
44
+ ESM dist/telemetry/events.mjs 35.00 B
45
+ ESM dist/types/action.mjs 67.00 B
49
46
  ESM dist/chunk-DE5K76I2.mjs 43.00 B
50
47
  ESM dist/chunk-MSUB6DGR.mjs 43.00 B
51
48
  ESM dist/chunk-IAFBVORQ.mjs 43.00 B
52
49
  ESM dist/chunk-CYDWEPFL.mjs 43.00 B
53
50
  ESM dist/chunk-CIPF7PMC.mjs 2.20 KB
54
51
  ESM dist/chunk-6P6F44JQ.mjs 166.00 B
55
- ESM dist/constants/index.mjs 315.00 B
56
52
  ESM dist/chunk-3AJ2GKWG.mjs 455.00 B
57
- ESM dist/telemetry/events.mjs 35.00 B
58
53
  ESM dist/telemetry/index.mjs 187.00 B
59
54
  ESM dist/chunk-P7STFMPO.mjs 43.00 B
60
55
  ESM dist/telemetry/security-check.mjs 43.00 B
61
56
  ESM dist/telemetry/telemetry-client.mjs 166.00 B
62
- ESM dist/chunk-MS46SBZ7.mjs 3.52 KB
57
+ ESM dist/chunk-HTOI6HYR.mjs 2.98 KB
63
58
  ESM dist/telemetry/utils.mjs 165.00 B
64
59
  ESM dist/chunk-6QGXWNS5.mjs 1.41 KB
65
- ESM dist/types/action.mjs 67.00 B
66
60
  ESM dist/chunk-NAFEBKSO.mjs 43.00 B
67
- ESM dist/types/copilot-cloud-config.mjs.map 71.00 B
68
- ESM dist/types/index.mjs.map 71.00 B
69
- ESM dist/types/openai-assistant.mjs.map 71.00 B
70
- ESM dist/utils/index.mjs.map 71.00 B
71
- ESM dist/utils/json-schema.mjs.map 71.00 B
72
- ESM dist/utils/random-id.mjs.map 71.00 B
61
+ ESM dist/types/copilot-cloud-config.mjs 81.00 B
62
+ ESM dist/types/index.mjs 162.00 B
63
+ ESM dist/types/openai-assistant.mjs 77.00 B
64
+ ESM dist/utils/index.mjs 245.00 B
65
+ ESM dist/utils/json-schema.mjs 155.00 B
66
+ ESM dist/utils/random-id.mjs 113.00 B
73
67
  ESM dist/index.mjs.map 71.00 B
68
+ ESM dist/constants/index.mjs.map 71.00 B
69
+ ESM dist/telemetry/events.mjs.map 71.00 B
70
+ ESM dist/types/action.mjs.map 71.00 B
74
71
  ESM dist/chunk-DE5K76I2.mjs.map 71.00 B
75
72
  ESM dist/chunk-MSUB6DGR.mjs.map 71.00 B
76
73
  ESM dist/chunk-IAFBVORQ.mjs.map 71.00 B
77
74
  ESM dist/chunk-CYDWEPFL.mjs.map 71.00 B
78
75
  ESM dist/chunk-CIPF7PMC.mjs.map 4.71 KB
79
76
  ESM dist/chunk-6P6F44JQ.mjs.map 238.00 B
80
- ESM dist/constants/index.mjs.map 71.00 B
81
77
  ESM dist/chunk-3AJ2GKWG.mjs.map 489.00 B
82
- ESM dist/telemetry/events.mjs.map 71.00 B
83
78
  ESM dist/telemetry/index.mjs.map 71.00 B
84
79
  ESM dist/chunk-P7STFMPO.mjs.map 71.00 B
85
80
  ESM dist/telemetry/security-check.mjs.map 71.00 B
86
81
  ESM dist/telemetry/telemetry-client.mjs.map 71.00 B
87
- ESM dist/chunk-MS46SBZ7.mjs.map 6.50 KB
82
+ ESM dist/chunk-HTOI6HYR.mjs.map 5.61 KB
88
83
  ESM dist/telemetry/utils.mjs.map 71.00 B
89
84
  ESM dist/chunk-6QGXWNS5.mjs.map 1.90 KB
90
- ESM dist/types/action.mjs.map 71.00 B
91
85
  ESM dist/chunk-NAFEBKSO.mjs.map 71.00 B
92
- ESM ⚡️ Build success in 88ms
86
+ ESM dist/types/copilot-cloud-config.mjs.map 71.00 B
87
+ ESM dist/types/index.mjs.map 71.00 B
88
+ ESM dist/types/openai-assistant.mjs.map 71.00 B
89
+ ESM dist/utils/index.mjs.map 71.00 B
90
+ ESM dist/utils/json-schema.mjs.map 71.00 B
91
+ ESM dist/utils/random-id.mjs.map 71.00 B
92
+ ESM ⚡️ Build success in 139ms
93
93
  DTS Build start
94
- DTS ⚡️ Build success in 5043ms
94
+ DTS ⚡️ Build success in 5719ms
95
95
  DTS dist/index.d.ts 810.00 B
96
96
  DTS dist/types/openai-assistant.d.ts 1.47 KB
97
97
  DTS dist/types/action.d.ts 2.24 KB
@@ -99,7 +99,7 @@
99
99
  DTS dist/utils/json-schema.d.ts 884.00 B
100
100
  DTS dist/utils/random-id.d.ts 59.00 B
101
101
  DTS dist/constants/index.d.ts 397.00 B
102
- DTS dist/telemetry/telemetry-client.d.ts 1.12 KB
102
+ DTS dist/telemetry/telemetry-client.d.ts 1.05 KB
103
103
  DTS dist/telemetry/events.d.ts 223.00 B
104
104
  DTS dist/telemetry/index.d.ts 113.00 B
105
105
  DTS dist/telemetry/security-check.d.ts 12.00 B
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @copilotkit/shared
2
2
 
3
+ ## 1.0.7
4
+
5
+ ### Patch Changes
6
+
7
+ - Add \_copilotkit internal properties to runtime
8
+
3
9
  ## 1.0.6
4
10
 
5
11
  ### Patch Changes
@@ -1,6 +1,5 @@
1
1
  import {
2
- flattenObject,
3
- printSecurityNotice
2
+ flattenObject
4
3
  } from "./chunk-6QGXWNS5.mjs";
5
4
 
6
5
  // src/telemetry/telemetry-client.ts
@@ -26,10 +25,10 @@ var TelemetryClient = class {
26
25
  return;
27
26
  }
28
27
  this.setSampleRate(sampleRate);
29
- this.telemetryBaseUrl = telemetryBaseUrl || process.env.COPILOTKIT_TELEMETRY_BASE_URL || "https://telemetry.copilotkit.ai";
28
+ const writeKey = process.env.COPILOTKIT_SEGMENT_WRITE_KEY || "n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja";
29
+ console.log("writeKey", writeKey);
30
30
  this.segment = new Analytics({
31
- // eslint-disable-next-line
32
- writeKey: process.env.COPILOTKIT_SEGMENT_WRITE_KEY || "n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja"
31
+ writeKey
33
32
  });
34
33
  this.setGlobalProperties({
35
34
  "copilotkit.package.name": packageName,
@@ -37,16 +36,15 @@ var TelemetryClient = class {
37
36
  });
38
37
  }
39
38
  shouldSendEvent() {
40
- if (!this.telemetryBaseUrl) {
41
- return false;
42
- }
43
39
  const randomNumber = Math.random();
44
40
  return randomNumber < this.sampleRate;
45
41
  }
46
42
  async capture(event, properties) {
43
+ console.log("pre send event check");
47
44
  if (!this.shouldSendEvent() || !this.segment) {
48
45
  return;
49
46
  }
47
+ console.log("post send event check");
50
48
  const flattenedProperties = flattenObject(properties);
51
49
  const propertiesWithGlobal = {
52
50
  ...this.globalProperties,
@@ -65,19 +63,6 @@ var TelemetryClient = class {
65
63
  properties: { ...orderedPropertiesWithGlobal }
66
64
  });
67
65
  }
68
- async checkForUpdates() {
69
- const url = `${this.telemetryBaseUrl}/check-for-updates?packageName=${this.packageName}&packageVersion=${this.packageVersion}`;
70
- const response = await fetch(url);
71
- if (!response.ok) {
72
- return;
73
- }
74
- const result = await response.json();
75
- const { advisory, severity } = result;
76
- if (!advisory && (severity === "low" || severity === "none")) {
77
- return;
78
- }
79
- printSecurityNotice(result);
80
- }
81
66
  setGlobalProperties(properties) {
82
67
  const flattenedProperties = flattenObject(properties);
83
68
  this.globalProperties = { ...this.globalProperties, ...flattenedProperties };
@@ -111,4 +96,4 @@ var TelemetryClient = class {
111
96
  export {
112
97
  TelemetryClient
113
98
  };
114
- //# sourceMappingURL=chunk-MS46SBZ7.mjs.map
99
+ //# sourceMappingURL=chunk-HTOI6HYR.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/telemetry/telemetry-client.ts"],"sourcesContent":["import { Analytics } from \"@segment/analytics-node\";\nimport { AnalyticsEvents } from \"./events\";\nimport { flattenObject, printSecurityNotice } from \"./utils\";\nimport { randomUUID } from \"crypto\";\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_${randomUUID()}`;\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 console.log(\"writeKey\", writeKey);\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 console.log(\"pre send event check\");\n if (!this.shouldSendEvent() || !this.segment) {\n return;\n }\n console.log(\"post send event check\");\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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B,OAAO,KAAK,oBAAoB,EACjE,KAAK,EACL;AAAA,MACC,CAAC,KAAK,QAAQ;AACZ,YAAI,GAAG,IAAI,qBAAqB,GAAG;AACnC,eAAO;AAAA,MACT;AAAA,MACA,CAAC;AAAA,IACH;AAEF,SAAK,QAAQ,MAAM;AAAA,MACjB,aAAa,KAAK;AAAA,MAClB;AAAA,MACA,YAAY,EAAE,GAAG,4BAA4B;AAAA,IAC/C,CAAC;AAAA,EACH;AAAA,EAEA,oBAAoB,YAAiC;AACnD,UAAM,sBAAsB,cAAc,UAAU;AACpD,SAAK,mBAAmB,EAAE,GAAG,KAAK,kBAAkB,GAAG,oBAAoB;AAAA,EAC7E;AAAA,EAEA,sBAAsB,YAAuD;AAC3E,SAAK,qBAAqB;AAE1B,SAAK,oBAAoB;AAAA,MACvB,OAAO;AAAA,QACL,cAAc,WAAW;AAAA,QACzB,SAAS,WAAW;AAAA,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;","names":[]}
package/dist/index.js CHANGED
@@ -143,21 +143,6 @@ function flattenObject(obj, parentKey = "", res = {}) {
143
143
  }
144
144
  return res;
145
145
  }
146
- function printSecurityNotice(advisory) {
147
- const severityColor = {
148
- low: import_chalk.default.blue,
149
- medium: import_chalk.default.yellow,
150
- high: import_chalk.default.red
151
- }[advisory.severity.toLowerCase()] || import_chalk.default.white;
152
- console.log();
153
- console.log(`\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 ${import_chalk.default.bold(`CopilotKit`)} \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501`);
154
- console.log();
155
- console.log(`${import_chalk.default.bold(`Severity: ${severityColor(advisory.severity.toUpperCase())}`)}`);
156
- console.log();
157
- console.log(`${import_chalk.default.bold(advisory.message)}`);
158
- console.log();
159
- console.log(`\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501`);
160
- }
161
146
 
162
147
  // src/telemetry/telemetry-client.ts
163
148
  var import_crypto = require("crypto");
@@ -181,10 +166,10 @@ var TelemetryClient = class {
181
166
  return;
182
167
  }
183
168
  this.setSampleRate(sampleRate);
184
- this.telemetryBaseUrl = telemetryBaseUrl || process.env.COPILOTKIT_TELEMETRY_BASE_URL || "https://telemetry.copilotkit.ai";
169
+ const writeKey = process.env.COPILOTKIT_SEGMENT_WRITE_KEY || "n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja";
170
+ console.log("writeKey", writeKey);
185
171
  this.segment = new import_analytics_node.Analytics({
186
- // eslint-disable-next-line
187
- writeKey: process.env.COPILOTKIT_SEGMENT_WRITE_KEY || "n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja"
172
+ writeKey
188
173
  });
189
174
  this.setGlobalProperties({
190
175
  "copilotkit.package.name": packageName,
@@ -192,16 +177,15 @@ var TelemetryClient = class {
192
177
  });
193
178
  }
194
179
  shouldSendEvent() {
195
- if (!this.telemetryBaseUrl) {
196
- return false;
197
- }
198
180
  const randomNumber = Math.random();
199
181
  return randomNumber < this.sampleRate;
200
182
  }
201
183
  async capture(event, properties) {
184
+ console.log("pre send event check");
202
185
  if (!this.shouldSendEvent() || !this.segment) {
203
186
  return;
204
187
  }
188
+ console.log("post send event check");
205
189
  const flattenedProperties = flattenObject(properties);
206
190
  const propertiesWithGlobal = {
207
191
  ...this.globalProperties,
@@ -220,19 +204,6 @@ var TelemetryClient = class {
220
204
  properties: { ...orderedPropertiesWithGlobal }
221
205
  });
222
206
  }
223
- async checkForUpdates() {
224
- const url = `${this.telemetryBaseUrl}/check-for-updates?packageName=${this.packageName}&packageVersion=${this.packageVersion}`;
225
- const response = await fetch(url);
226
- if (!response.ok) {
227
- return;
228
- }
229
- const result = await response.json();
230
- const { advisory, severity } = result;
231
- if (!advisory && (severity === "low" || severity === "none")) {
232
- return;
233
- }
234
- printSecurityNotice(result);
235
- }
236
207
  setGlobalProperties(properties) {
237
208
  const flattenedProperties = flattenObject(properties);
238
209
  this.globalProperties = { ...this.globalProperties, ...flattenedProperties };
package/dist/index.js.map CHANGED
@@ -1 +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"],"sourcesContent":["export * from \"./types\";\nexport * from \"./utils\";\nexport * from \"./constants\";\nexport * from \"./telemetry\";\n","import { 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","export function randomId() {\n return \"ck-\" + globalThis.crypto.randomUUID();\n}\n","export const COPILOT_CLOUD_API_URL = \"https://api.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 { randomUUID } from \"crypto\";\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 telemetryBaseUrl: string | undefined;\n private sampleRate: number = 0.05;\n private anonymousId = `anon_${randomUUID()}`;\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 this.telemetryBaseUrl =\n telemetryBaseUrl ||\n (process.env as any).COPILOTKIT_TELEMETRY_BASE_URL ||\n \"https://telemetry.copilotkit.ai\";\n\n this.segment = new Analytics({\n // eslint-disable-next-line\n writeKey: process.env.COPILOTKIT_SEGMENT_WRITE_KEY || \"n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja\",\n });\n\n this.setGlobalProperties({\n \"copilotkit.package.name\": packageName,\n \"copilotkit.package.version\": packageVersion,\n });\n }\n\n private shouldSendEvent() {\n if (!this.telemetryBaseUrl) {\n return false;\n }\n\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 async checkForUpdates() {\n const url = `${this.telemetryBaseUrl}/check-for-updates?packageName=${this.packageName}&packageVersion=${this.packageVersion}`;\n\n const response = await fetch(url);\n\n if (!response.ok) {\n return;\n }\n\n const result = await response.json();\n const { advisory, severity } = result;\n\n if (!advisory && (severity === \"low\" || severity === \"none\")) {\n return;\n }\n\n printSecurityNotice(result);\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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACsCO,SAAS,6BAA6B,kBAA2C;AAEtF,MAAI,aAAqC,CAAC;AAC1C,WAAS,aAAa,oBAAoB,CAAC,GAAG;AAC5C,eAAW,UAAU,IAAI,IAAI,iBAAiB,SAAS;AAAA,EACzD;AAEA,MAAI,yBAAmC,CAAC;AACxC,WAAS,OAAO,oBAAoB,CAAC,GAAG;AACtC,QAAI,IAAI,aAAa,OAAO;AAC1B,6BAAuB,KAAK,IAAI,IAAI;AAAA,IACtC;AAAA,EACF;AAGA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,UAAU;AAAA,EACZ;AACF;AAEA,SAAS,iBAAiB,WAAkC;AA5D5D;AA6DE,UAAQ,UAAU,MAAM;AAAA,IACtB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AAG,KAAK,kDAAkD,KAAK,8BAA8B,KAAK;AAE9G,UAAM,WAAW,MAAM,MAAM,GAAG;AAEhC,QAAI,CAAC,SAAS,IAAI;AAChB;AAAA,IACF;AAEA,UAAM,SAAS,MAAM,SAAS,KAAK;AACnC,UAAM,EAAE,UAAU,SAAS,IAAI;AAE/B,QAAI,CAAC,aAAa,aAAa,SAAS,aAAa,SAAS;AAC5D;AAAA,IACF;AAEA,wBAAoB,MAAM;AAAA,EAC5B;AAAA,EAEA,oBAAoB,YAAiC;AACnD,UAAM,sBAAsB,cAAc,UAAU;AACpD,SAAK,mBAAmB,EAAE,GAAG,KAAK,kBAAkB,GAAG,oBAAoB;AAAA,EAC7E;AAAA,EAEA,sBAAsB,YAAuD;AAC3E,SAAK,qBAAqB;AAE1B,SAAK,oBAAoB;AAAA,MACvB,OAAO;AAAA,QACL,cAAc,WAAW;AAAA,QACzB,SAAS,WAAW;AAAA,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;","names":["chalk"]}
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"],"sourcesContent":["export * from \"./types\";\nexport * from \"./utils\";\nexport * from \"./constants\";\nexport * from \"./telemetry\";\n","import { 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","export function randomId() {\n return \"ck-\" + globalThis.crypto.randomUUID();\n}\n","export const COPILOT_CLOUD_API_URL = \"https://api.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 { randomUUID } from \"crypto\";\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_${randomUUID()}`;\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 console.log(\"writeKey\", writeKey);\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 console.log(\"pre send event check\");\n if (!this.shouldSendEvent() || !this.segment) {\n return;\n }\n console.log(\"post send event check\");\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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACsCO,SAAS,6BAA6B,kBAA2C;AAEtF,MAAI,aAAqC,CAAC;AAC1C,WAAS,aAAa,oBAAoB,CAAC,GAAG;AAC5C,eAAW,UAAU,IAAI,IAAI,iBAAiB,SAAS;AAAA,EACzD;AAEA,MAAI,yBAAmC,CAAC;AACxC,WAAS,OAAO,oBAAoB,CAAC,GAAG;AACtC,QAAI,IAAI,aAAa,OAAO;AAC1B,6BAAuB,KAAK,IAAI,IAAI;AAAA,IACtC;AAAA,EACF;AAGA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,UAAU;AAAA,EACZ;AACF;AAEA,SAAS,iBAAiB,WAAkC;AA5D5D;AA6DE,UAAQ,UAAU,MAAM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BAAoB;AAAA,MACvB,YAAY,KAAK;AAAA,MACjB,4BAA4B,IAAI,KAAK;AAAA,IACvC,CAAC;AAAA,EACH;AACF;","names":[]}
package/dist/index.mjs CHANGED
@@ -17,7 +17,7 @@ import {
17
17
  import "./chunk-P7STFMPO.mjs";
18
18
  import {
19
19
  TelemetryClient
20
- } from "./chunk-MS46SBZ7.mjs";
20
+ } from "./chunk-HTOI6HYR.mjs";
21
21
  import "./chunk-6QGXWNS5.mjs";
22
22
  import "./chunk-NAFEBKSO.mjs";
23
23
  export {
@@ -50,21 +50,6 @@ function flattenObject(obj, parentKey = "", res = {}) {
50
50
  }
51
51
  return res;
52
52
  }
53
- function printSecurityNotice(advisory) {
54
- const severityColor = {
55
- low: import_chalk.default.blue,
56
- medium: import_chalk.default.yellow,
57
- high: import_chalk.default.red
58
- }[advisory.severity.toLowerCase()] || import_chalk.default.white;
59
- console.log();
60
- console.log(`\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 ${import_chalk.default.bold(`CopilotKit`)} \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501`);
61
- console.log();
62
- console.log(`${import_chalk.default.bold(`Severity: ${severityColor(advisory.severity.toUpperCase())}`)}`);
63
- console.log();
64
- console.log(`${import_chalk.default.bold(advisory.message)}`);
65
- console.log();
66
- console.log(`\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501`);
67
- }
68
53
 
69
54
  // src/telemetry/telemetry-client.ts
70
55
  var import_crypto = require("crypto");
@@ -88,10 +73,10 @@ var TelemetryClient = class {
88
73
  return;
89
74
  }
90
75
  this.setSampleRate(sampleRate);
91
- this.telemetryBaseUrl = telemetryBaseUrl || process.env.COPILOTKIT_TELEMETRY_BASE_URL || "https://telemetry.copilotkit.ai";
76
+ const writeKey = process.env.COPILOTKIT_SEGMENT_WRITE_KEY || "n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja";
77
+ console.log("writeKey", writeKey);
92
78
  this.segment = new import_analytics_node.Analytics({
93
- // eslint-disable-next-line
94
- writeKey: process.env.COPILOTKIT_SEGMENT_WRITE_KEY || "n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja"
79
+ writeKey
95
80
  });
96
81
  this.setGlobalProperties({
97
82
  "copilotkit.package.name": packageName,
@@ -99,16 +84,15 @@ var TelemetryClient = class {
99
84
  });
100
85
  }
101
86
  shouldSendEvent() {
102
- if (!this.telemetryBaseUrl) {
103
- return false;
104
- }
105
87
  const randomNumber = Math.random();
106
88
  return randomNumber < this.sampleRate;
107
89
  }
108
90
  async capture(event, properties) {
91
+ console.log("pre send event check");
109
92
  if (!this.shouldSendEvent() || !this.segment) {
110
93
  return;
111
94
  }
95
+ console.log("post send event check");
112
96
  const flattenedProperties = flattenObject(properties);
113
97
  const propertiesWithGlobal = {
114
98
  ...this.globalProperties,
@@ -127,19 +111,6 @@ var TelemetryClient = class {
127
111
  properties: { ...orderedPropertiesWithGlobal }
128
112
  });
129
113
  }
130
- async checkForUpdates() {
131
- const url = `${this.telemetryBaseUrl}/check-for-updates?packageName=${this.packageName}&packageVersion=${this.packageVersion}`;
132
- const response = await fetch(url);
133
- if (!response.ok) {
134
- return;
135
- }
136
- const result = await response.json();
137
- const { advisory, severity } = result;
138
- if (!advisory && (severity === "low" || severity === "none")) {
139
- return;
140
- }
141
- printSecurityNotice(result);
142
- }
143
114
  setGlobalProperties(properties) {
144
115
  const flattenedProperties = flattenObject(properties);
145
116
  this.globalProperties = { ...this.globalProperties, ...flattenedProperties };
@@ -1 +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 { randomUUID } from \"crypto\";\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 telemetryBaseUrl: string | undefined;\n private sampleRate: number = 0.05;\n private anonymousId = `anon_${randomUUID()}`;\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 this.telemetryBaseUrl =\n telemetryBaseUrl ||\n (process.env as any).COPILOTKIT_TELEMETRY_BASE_URL ||\n \"https://telemetry.copilotkit.ai\";\n\n this.segment = new Analytics({\n // eslint-disable-next-line\n writeKey: process.env.COPILOTKIT_SEGMENT_WRITE_KEY || \"n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja\",\n });\n\n this.setGlobalProperties({\n \"copilotkit.package.name\": packageName,\n \"copilotkit.package.version\": packageVersion,\n });\n }\n\n private shouldSendEvent() {\n if (!this.telemetryBaseUrl) {\n return false;\n }\n\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 async checkForUpdates() {\n const url = `${this.telemetryBaseUrl}/check-for-updates?packageName=${this.packageName}&packageVersion=${this.packageVersion}`;\n\n const response = await fetch(url);\n\n if (!response.ok) {\n return;\n }\n\n const result = await response.json();\n const { advisory, severity } = result;\n\n if (!advisory && (severity === \"low\" || severity === \"none\")) {\n return;\n }\n\n printSecurityNotice(result);\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;AAEO,SAAS,oBAAoB,UAIjC;AACD,QAAM,gBACJ;AAAA,IACE,KAAK,aAAAA,QAAM;AAAA,IACX,QAAQ,aAAAA,QAAM;AAAA,IACd,MAAM,aAAAA,QAAM;A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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;","names":["chalk"]}
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 { randomUUID } from \"crypto\";\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_${randomUUID()}`;\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 console.log(\"writeKey\", writeKey);\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 console.log(\"pre send event check\");\n if (!this.shouldSendEvent() || !this.segment) {\n return;\n }\n console.log(\"post send event check\");\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,oBAA2B;AAEpB,IAAM,kBAAN,MAAsB;AAAA,EAU3B,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IAC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AG,4BAA4B;AAAA,IAC/C,CAAC;AAAA,EACH;AAAA,EAEA,oBAAoB,YAAiC;AACnD,UAAM,sBAAsB,cAAc,UAAU;AACpD,SAAK,mBAAmB,EAAE,GAAG,KAAK,kBAAkB,GAAG,oBAAoB;AAAA,EAC7E;AAAA,EAEA,sBAAsB,YAAuD;AAC3E,SAAK,qBAAqB;AAE1B,SAAK,oBAAoB;AAAA,MACvB,OAAO;AAAA,QACL,cAAc,WAAW;AAAA,QACzB,SAAS,WAAW;AAAA,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;","names":[]}
@@ -1,7 +1,7 @@
1
1
  import "../chunk-P7STFMPO.mjs";
2
2
  import {
3
3
  TelemetryClient
4
- } from "../chunk-MS46SBZ7.mjs";
4
+ } from "../chunk-HTOI6HYR.mjs";
5
5
  import "../chunk-6QGXWNS5.mjs";
6
6
  export {
7
7
  TelemetryClient
@@ -11,7 +11,6 @@ declare class TelemetryClient {
11
11
  packageName: string;
12
12
  packageVersion: string;
13
13
  private telemetryDisabled;
14
- private telemetryBaseUrl;
15
14
  private sampleRate;
16
15
  private anonymousId;
17
16
  constructor({ packageName, packageVersion, telemetryDisabled, telemetryBaseUrl, sampleRate, }: {
@@ -23,7 +22,6 @@ declare class TelemetryClient {
23
22
  });
24
23
  private shouldSendEvent;
25
24
  capture<K extends keyof AnalyticsEvents>(event: K, properties: AnalyticsEvents[K]): Promise<void>;
26
- checkForUpdates(): Promise<void>;
27
25
  setGlobalProperties(properties: Record<string, any>): void;
28
26
  setCloudConfiguration(properties: {
29
27
  publicApiKey: string;
@@ -48,21 +48,6 @@ function flattenObject(obj, parentKey = "", res = {}) {
48
48
  }
49
49
  return res;
50
50
  }
51
- function printSecurityNotice(advisory) {
52
- const severityColor = {
53
- low: import_chalk.default.blue,
54
- medium: import_chalk.default.yellow,
55
- high: import_chalk.default.red
56
- }[advisory.severity.toLowerCase()] || import_chalk.default.white;
57
- console.log();
58
- console.log(`\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 ${import_chalk.default.bold(`CopilotKit`)} \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501`);
59
- console.log();
60
- console.log(`${import_chalk.default.bold(`Severity: ${severityColor(advisory.severity.toUpperCase())}`)}`);
61
- console.log();
62
- console.log(`${import_chalk.default.bold(advisory.message)}`);
63
- console.log();
64
- console.log(`\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501`);
65
- }
66
51
 
67
52
  // src/telemetry/telemetry-client.ts
68
53
  var import_crypto = require("crypto");
@@ -86,10 +71,10 @@ var TelemetryClient = class {
86
71
  return;
87
72
  }
88
73
  this.setSampleRate(sampleRate);
89
- this.telemetryBaseUrl = telemetryBaseUrl || process.env.COPILOTKIT_TELEMETRY_BASE_URL || "https://telemetry.copilotkit.ai";
74
+ const writeKey = process.env.COPILOTKIT_SEGMENT_WRITE_KEY || "n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja";
75
+ console.log("writeKey", writeKey);
90
76
  this.segment = new import_analytics_node.Analytics({
91
- // eslint-disable-next-line
92
- writeKey: process.env.COPILOTKIT_SEGMENT_WRITE_KEY || "n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja"
77
+ writeKey
93
78
  });
94
79
  this.setGlobalProperties({
95
80
  "copilotkit.package.name": packageName,
@@ -97,16 +82,15 @@ var TelemetryClient = class {
97
82
  });
98
83
  }
99
84
  shouldSendEvent() {
100
- if (!this.telemetryBaseUrl) {
101
- return false;
102
- }
103
85
  const randomNumber = Math.random();
104
86
  return randomNumber < this.sampleRate;
105
87
  }
106
88
  async capture(event, properties) {
89
+ console.log("pre send event check");
107
90
  if (!this.shouldSendEvent() || !this.segment) {
108
91
  return;
109
92
  }
93
+ console.log("post send event check");
110
94
  const flattenedProperties = flattenObject(properties);
111
95
  const propertiesWithGlobal = {
112
96
  ...this.globalProperties,
@@ -125,19 +109,6 @@ var TelemetryClient = class {
125
109
  properties: { ...orderedPropertiesWithGlobal }
126
110
  });
127
111
  }
128
- async checkForUpdates() {
129
- const url = `${this.telemetryBaseUrl}/check-for-updates?packageName=${this.packageName}&packageVersion=${this.packageVersion}`;
130
- const response = await fetch(url);
131
- if (!response.ok) {
132
- return;
133
- }
134
- const result = await response.json();
135
- const { advisory, severity } = result;
136
- if (!advisory && (severity === "low" || severity === "none")) {
137
- return;
138
- }
139
- printSecurityNotice(result);
140
- }
141
112
  setGlobalProperties(properties) {
142
113
  const flattenedProperties = flattenObject(properties);
143
114
  this.globalProperties = { ...this.globalProperties, ...flattenedProperties };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/telemetry/telemetry-client.ts","../../src/telemetry/utils.ts"],"sourcesContent":["import { Analytics } from \"@segment/analytics-node\";\nimport { AnalyticsEvents } from \"./events\";\nimport { flattenObject, printSecurityNotice } from \"./utils\";\nimport { randomUUID } from \"crypto\";\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 telemetryBaseUrl: string | undefined;\n private sampleRate: number = 0.05;\n private anonymousId = `anon_${randomUUID()}`;\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 this.telemetryBaseUrl =\n telemetryBaseUrl ||\n (process.env as any).COPILOTKIT_TELEMETRY_BASE_URL ||\n \"https://telemetry.copilotkit.ai\";\n\n this.segment = new Analytics({\n // eslint-disable-next-line\n writeKey: process.env.COPILOTKIT_SEGMENT_WRITE_KEY || \"n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja\",\n });\n\n this.setGlobalProperties({\n \"copilotkit.package.name\": packageName,\n \"copilotkit.package.version\": packageVersion,\n });\n }\n\n private shouldSendEvent() {\n if (!this.telemetryBaseUrl) {\n return false;\n }\n\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 async checkForUpdates() {\n const url = `${this.telemetryBaseUrl}/check-for-updates?packageName=${this.packageName}&packageVersion=${this.packageVersion}`;\n\n const response = await fetch(url);\n\n if (!response.ok) {\n return;\n }\n\n const result = await response.json();\n const { advisory, severity } = result;\n\n if (!advisory && (severity === \"low\" || severity === \"none\")) {\n return;\n }\n\n printSecurityNotice(result);\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;AAAA,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;AAEO,SAAS,oBAAoB,UAIjC;AACD,QAAM,gBACJ;AAAA,IACE,KAAK,aAAAA,QAAM;AAAA,IACX,QAAQ,aAAAA,QAAM;AAAA,IACd,MAAM,aAAAA,QAAM;AAAA,EACd,EAAE,SAAS,SAAS,YAAY,CAAC,KAAK,aAAAA,QAAM;AAE9C,UAAQ,IAAI;AACZ,UAAQ,IAAI,gHAAsB,aAAAA,QAAM,KAAK,YAAY,gHAAsB;AAC/E,UAAQ,IAAI;AACZ,UAAQ,IAAI,GAAG,aAAAA,QAAM,KAAK,aAAa,cAAc,SAAS,SAAS,YAAY,CAAC,GAAG,GAAG;AAC1F,UAAQ,IAAI;AACZ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,IAAI,KAAK;AAAA,IACvC,CAAC;AAAA,EACH;AACF;","names":["chalk"]}
1
+ {"version":3,"sources":["../../src/telemetry/telemetry-client.ts","../../src/telemetry/utils.ts"],"sourcesContent":["import { Analytics } from \"@segment/analytics-node\";\nimport { AnalyticsEvents } from \"./events\";\nimport { flattenObject, printSecurityNotice } from \"./utils\";\nimport { randomUUID } from \"crypto\";\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_${randomUUID()}`;\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 console.log(\"writeKey\", writeKey);\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 console.log(\"pre send event check\");\n if (!this.shouldSendEvent() || !this.segment) {\n return;\n }\n console.log(\"post send event check\");\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;AAAA,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,oBAA2B;AAEpB,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,0BAAW;AAevC,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,Q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,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;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  TelemetryClient
3
- } from "../chunk-MS46SBZ7.mjs";
3
+ } from "../chunk-HTOI6HYR.mjs";
4
4
  import "../chunk-6QGXWNS5.mjs";
5
5
  export {
6
6
  TelemetryClient
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "publishConfig": {
10
10
  "access": "public"
11
11
  },
12
- "version": "1.0.6",
12
+ "version": "1.0.7",
13
13
  "sideEffects": false,
14
14
  "main": "./dist/index.js",
15
15
  "module": "./dist/index.mjs",
@@ -10,7 +10,6 @@ export class TelemetryClient {
10
10
  packageName: string;
11
11
  packageVersion: string;
12
12
  private telemetryDisabled: boolean = false;
13
- private telemetryBaseUrl: string | undefined;
14
13
  private sampleRate: number = 0.05;
15
14
  private anonymousId = `anon_${randomUUID()}`;
16
15
 
@@ -42,14 +41,13 @@ export class TelemetryClient {
42
41
 
43
42
  this.setSampleRate(sampleRate);
44
43
 
45
- this.telemetryBaseUrl =
46
- telemetryBaseUrl ||
47
- (process.env as any).COPILOTKIT_TELEMETRY_BASE_URL ||
48
- "https://telemetry.copilotkit.ai";
44
+ // eslint-disable-next-line
45
+ const writeKey = process.env.COPILOTKIT_SEGMENT_WRITE_KEY || "n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja";
46
+
47
+ console.log("writeKey", writeKey);
49
48
 
50
49
  this.segment = new Analytics({
51
- // eslint-disable-next-line
52
- writeKey: process.env.COPILOTKIT_SEGMENT_WRITE_KEY || "n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja",
50
+ writeKey,
53
51
  });
54
52
 
55
53
  this.setGlobalProperties({
@@ -59,18 +57,16 @@ export class TelemetryClient {
59
57
  }
60
58
 
61
59
  private shouldSendEvent() {
62
- if (!this.telemetryBaseUrl) {
63
- return false;
64
- }
65
-
66
60
  const randomNumber = Math.random();
67
61
  return randomNumber < this.sampleRate;
68
62
  }
69
63
 
70
64
  async capture<K extends keyof AnalyticsEvents>(event: K, properties: AnalyticsEvents[K]) {
65
+ console.log("pre send event check");
71
66
  if (!this.shouldSendEvent() || !this.segment) {
72
67
  return;
73
68
  }
69
+ console.log("post send event check");
74
70
 
75
71
  const flattenedProperties = flattenObject(properties);
76
72
  const propertiesWithGlobal = {
@@ -94,25 +90,6 @@ export class TelemetryClient {
94
90
  });
95
91
  }
96
92
 
97
- async checkForUpdates() {
98
- const url = `${this.telemetryBaseUrl}/check-for-updates?packageName=${this.packageName}&packageVersion=${this.packageVersion}`;
99
-
100
- const response = await fetch(url);
101
-
102
- if (!response.ok) {
103
- return;
104
- }
105
-
106
- const result = await response.json();
107
- const { advisory, severity } = result;
108
-
109
- if (!advisory && (severity === "low" || severity === "none")) {
110
- return;
111
- }
112
-
113
- printSecurityNotice(result);
114
- }
115
-
116
93
  setGlobalProperties(properties: Record<string, any>) {
117
94
  const flattenedProperties = flattenObject(properties);
118
95
  this.globalProperties = { ...this.globalProperties, ...flattenedProperties };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/telemetry/telemetry-client.ts"],"sourcesContent":["import { Analytics } from \"@segment/analytics-node\";\nimport { AnalyticsEvents } from \"./events\";\nimport { flattenObject, printSecurityNotice } from \"./utils\";\nimport { randomUUID } from \"crypto\";\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 telemetryBaseUrl: string | undefined;\n private sampleRate: number = 0.05;\n private anonymousId = `anon_${randomUUID()}`;\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 this.telemetryBaseUrl =\n telemetryBaseUrl ||\n (process.env as any).COPILOTKIT_TELEMETRY_BASE_URL ||\n \"https://telemetry.copilotkit.ai\";\n\n this.segment = new Analytics({\n // eslint-disable-next-line\n writeKey: process.env.COPILOTKIT_SEGMENT_WRITE_KEY || \"n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja\",\n });\n\n this.setGlobalProperties({\n \"copilotkit.package.name\": packageName,\n \"copilotkit.package.version\": packageVersion,\n });\n }\n\n private shouldSendEvent() {\n if (!this.telemetryBaseUrl) {\n return false;\n }\n\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 async checkForUpdates() {\n const url = `${this.telemetryBaseUrl}/check-for-updates?packageName=${this.packageName}&packageVersion=${this.packageVersion}`;\n\n const response = await fetch(url);\n\n if (!response.ok) {\n return;\n }\n\n const result = await response.json();\n const { advisory, severity } = result;\n\n if (!advisory && (severity === \"low\" || severity === \"none\")) {\n return;\n }\n\n printSecurityNotice(result);\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"],"mappings":";;;;;;AAAA,SAAS,iBAAiB;AAG1B,SAAS,kBAAkB;AAEpB,IAAM,kBAAN,MAAsB;AAAA,EAW3B,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAMG;AArBH,4BAAwC,CAAC;AACzC,8BAAuE;AAGvE,SAAQ,oBAA6B;AAErC,SAAQ,aAAqB;AAC7B,SAAQ,cAAc,QAAQ,WAAW;AA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