@copilotkit/shared 1.0.5 → 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.
- package/.turbo/turbo-build.log +13 -13
- package/CHANGELOG.md +13 -0
- package/dist/{chunk-MS46SBZ7.mjs → chunk-HTOI6HYR.mjs} +7 -22
- package/dist/chunk-HTOI6HYR.mjs.map +1 -0
- package/dist/index.js +5 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/telemetry/index.js +5 -34
- package/dist/telemetry/index.js.map +1 -1
- package/dist/telemetry/index.mjs +1 -1
- package/dist/telemetry/telemetry-client.d.ts +0 -2
- package/dist/telemetry/telemetry-client.js +5 -34
- package/dist/telemetry/telemetry-client.js.map +1 -1
- package/dist/telemetry/telemetry-client.mjs +1 -1
- package/package.json +3 -3
- package/src/telemetry/telemetry-client.ts +7 -30
- package/dist/chunk-MS46SBZ7.mjs.map +0 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @copilotkit/shared@1.0.
|
|
2
|
+
> @copilotkit/shared@1.0.7 build /home/runner/work/CopilotKit/CopilotKit/CopilotKit/packages/shared
|
|
3
3
|
> tsup --clean
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m 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
|
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
[34mESM[39m Build start
|
|
12
12
|
[34mCJS[39m Build start
|
|
13
13
|
[32mCJS[39m [1mdist/utils/index.js [22m[32m3.37 KB[39m
|
|
14
|
-
[32mCJS[39m [1mdist/index.js [22m[
|
|
14
|
+
[32mCJS[39m [1mdist/index.js [22m[32m7.96 KB[39m
|
|
15
15
|
[32mCJS[39m [1mdist/constants/index.js [22m[32m1.64 KB[39m
|
|
16
16
|
[32mCJS[39m [1mdist/telemetry/events.js [22m[32m805.00 B[39m
|
|
17
|
-
[32mCJS[39m [1mdist/telemetry/index.js [22m[
|
|
17
|
+
[32mCJS[39m [1mdist/telemetry/index.js [22m[32m5.01 KB[39m
|
|
18
18
|
[32mCJS[39m [1mdist/telemetry/security-check.js [22m[32m56.00 B[39m
|
|
19
|
-
[32mCJS[39m [1mdist/telemetry/telemetry-client.js [22m[
|
|
19
|
+
[32mCJS[39m [1mdist/telemetry/telemetry-client.js [22m[32m5.01 KB[39m
|
|
20
20
|
[32mCJS[39m [1mdist/telemetry/utils.js [22m[32m3.14 KB[39m
|
|
21
21
|
[32mCJS[39m [1mdist/types/action.js [22m[32m801.00 B[39m
|
|
22
22
|
[32mCJS[39m [1mdist/types/copilot-cloud-config.js [22m[32m857.00 B[39m
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
[32mCJS[39m [1mdist/utils/json-schema.js [22m[32m3.23 KB[39m
|
|
26
26
|
[32mCJS[39m [1mdist/utils/random-id.js [22m[32m1.15 KB[39m
|
|
27
27
|
[32mCJS[39m [1mdist/utils/index.js.map [22m[32m5.02 KB[39m
|
|
28
|
-
[32mCJS[39m [1mdist/index.js.map [22m[
|
|
28
|
+
[32mCJS[39m [1mdist/index.js.map [22m[32m12.48 KB[39m
|
|
29
29
|
[32mCJS[39m [1mdist/constants/index.js.map [22m[32m551.00 B[39m
|
|
30
30
|
[32mCJS[39m [1mdist/telemetry/events.js.map [22m[32m330.00 B[39m
|
|
31
|
-
[32mCJS[39m [1mdist/telemetry/index.js.map [22m[
|
|
31
|
+
[32mCJS[39m [1mdist/telemetry/index.js.map [22m[32m7.18 KB[39m
|
|
32
32
|
[32mCJS[39m [1mdist/telemetry/security-check.js.map [22m[32m71.00 B[39m
|
|
33
|
-
[32mCJS[39m [1mdist/telemetry/telemetry-client.js.map [22m[
|
|
33
|
+
[32mCJS[39m [1mdist/telemetry/telemetry-client.js.map [22m[32m7.10 KB[39m
|
|
34
34
|
[32mCJS[39m [1mdist/telemetry/utils.js.map [22m[32m2.00 KB[39m
|
|
35
35
|
[32mCJS[39m [1mdist/types/action.js.map [22m[32m4.84 KB[39m
|
|
36
36
|
[32mCJS[39m [1mdist/types/copilot-cloud-config.js.map [22m[32m356.00 B[39m
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
[32mCJS[39m [1mdist/types/openai-assistant.js.map [22m[32m1.53 KB[39m
|
|
39
39
|
[32mCJS[39m [1mdist/utils/json-schema.js.map [22m[32m4.75 KB[39m
|
|
40
40
|
[32mCJS[39m [1mdist/utils/random-id.js.map [22m[32m285.00 B[39m
|
|
41
|
-
[32mCJS[39m ⚡️ Build success in
|
|
41
|
+
[32mCJS[39m ⚡️ Build success in 130ms
|
|
42
42
|
[32mESM[39m [1mdist/index.mjs [22m[32m774.00 B[39m
|
|
43
43
|
[32mESM[39m [1mdist/constants/index.mjs [22m[32m315.00 B[39m
|
|
44
44
|
[32mESM[39m [1mdist/telemetry/events.mjs [22m[32m35.00 B[39m
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
[32mESM[39m [1mdist/chunk-P7STFMPO.mjs [22m[32m43.00 B[39m
|
|
55
55
|
[32mESM[39m [1mdist/telemetry/security-check.mjs [22m[32m43.00 B[39m
|
|
56
56
|
[32mESM[39m [1mdist/telemetry/telemetry-client.mjs [22m[32m166.00 B[39m
|
|
57
|
-
[32mESM[39m [1mdist/chunk-
|
|
57
|
+
[32mESM[39m [1mdist/chunk-HTOI6HYR.mjs [22m[32m2.98 KB[39m
|
|
58
58
|
[32mESM[39m [1mdist/telemetry/utils.mjs [22m[32m165.00 B[39m
|
|
59
59
|
[32mESM[39m [1mdist/chunk-6QGXWNS5.mjs [22m[32m1.41 KB[39m
|
|
60
60
|
[32mESM[39m [1mdist/chunk-NAFEBKSO.mjs [22m[32m43.00 B[39m
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
[32mESM[39m [1mdist/chunk-P7STFMPO.mjs.map [22m[32m71.00 B[39m
|
|
80
80
|
[32mESM[39m [1mdist/telemetry/security-check.mjs.map [22m[32m71.00 B[39m
|
|
81
81
|
[32mESM[39m [1mdist/telemetry/telemetry-client.mjs.map [22m[32m71.00 B[39m
|
|
82
|
-
[32mESM[39m [1mdist/chunk-
|
|
82
|
+
[32mESM[39m [1mdist/chunk-HTOI6HYR.mjs.map [22m[32m5.61 KB[39m
|
|
83
83
|
[32mESM[39m [1mdist/telemetry/utils.mjs.map [22m[32m71.00 B[39m
|
|
84
84
|
[32mESM[39m [1mdist/chunk-6QGXWNS5.mjs.map [22m[32m1.90 KB[39m
|
|
85
85
|
[32mESM[39m [1mdist/chunk-NAFEBKSO.mjs.map [22m[32m71.00 B[39m
|
|
@@ -89,9 +89,9 @@
|
|
|
89
89
|
[32mESM[39m [1mdist/utils/index.mjs.map [22m[32m71.00 B[39m
|
|
90
90
|
[32mESM[39m [1mdist/utils/json-schema.mjs.map [22m[32m71.00 B[39m
|
|
91
91
|
[32mESM[39m [1mdist/utils/random-id.mjs.map [22m[32m71.00 B[39m
|
|
92
|
-
[32mESM[39m ⚡️ Build success in
|
|
92
|
+
[32mESM[39m ⚡️ Build success in 139ms
|
|
93
93
|
[34mDTS[39m Build start
|
|
94
|
-
[32mDTS[39m ⚡️ Build success in
|
|
94
|
+
[32mDTS[39m ⚡️ Build success in 5719ms
|
|
95
95
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m810.00 B[39m
|
|
96
96
|
[32mDTS[39m [1mdist/types/openai-assistant.d.ts [22m[32m1.47 KB[39m
|
|
97
97
|
[32mDTS[39m [1mdist/types/action.d.ts [22m[32m2.24 KB[39m
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
[32mDTS[39m [1mdist/utils/json-schema.d.ts [22m[32m884.00 B[39m
|
|
100
100
|
[32mDTS[39m [1mdist/utils/random-id.d.ts [22m[32m59.00 B[39m
|
|
101
101
|
[32mDTS[39m [1mdist/constants/index.d.ts [22m[32m397.00 B[39m
|
|
102
|
-
[32mDTS[39m [1mdist/telemetry/telemetry-client.d.ts [22m[32m1.
|
|
102
|
+
[32mDTS[39m [1mdist/telemetry/telemetry-client.d.ts [22m[32m1.05 KB[39m
|
|
103
103
|
[32mDTS[39m [1mdist/telemetry/events.d.ts [22m[32m223.00 B[39m
|
|
104
104
|
[32mDTS[39m [1mdist/telemetry/index.d.ts [22m[32m113.00 B[39m
|
|
105
105
|
[32mDTS[39m [1mdist/telemetry/security-check.d.ts [22m[32m12.00 B[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @copilotkit/shared
|
|
2
2
|
|
|
3
|
+
## 1.0.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Add \_copilotkit internal properties to runtime
|
|
8
|
+
|
|
9
|
+
## 1.0.6
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- - Proactively prevent race conditions
|
|
14
|
+
- Improve token counting performance
|
|
15
|
+
|
|
3
16
|
## 1.0.5
|
|
4
17
|
|
|
5
18
|
### 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
|
-
|
|
28
|
+
const writeKey = process.env.COPILOTKIT_SEGMENT_WRITE_KEY || "n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja";
|
|
29
|
+
console.log("writeKey", writeKey);
|
|
30
30
|
this.segment = new Analytics({
|
|
31
|
-
|
|
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-
|
|
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\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,EAU3B,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;A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,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
|
-
|
|
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
|
-
|
|
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,6BAA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/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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AAc;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.mjs
CHANGED
package/dist/telemetry/index.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
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":";;;;;;;;;;;;;;;;;;;;;;;;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.mjs
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
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,QAAI,KAAK,mBAAmB;AAC1B;AAAA,IACF;AAEA,SAAK,cAAc,UAAU;AAG7B,UAAM,WAAW,QAAQ,IAAI,gCAAgC;AAE7D,YAAQ,IAAI,YAAY,QAAQ;AAEhC,SAAK,UAAU,IAAI,gCAAU;AAAA,MAC3B;AAAA,IACF,CAAC;AAED,SAAK,oBAAoB;AAAA,MACvB,2BAA2B;AAAA,MAC3B,8BAA8B;AAAA,IAChC,CAAC;AAAA,EACH;AAAA,EAEQ,kBAAkB;AACxB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AAY,KAAK;AAAA,MACjB,4BAA4B,IAAI,KAAK;AAAA,IACvC,CAAC;AAAA,EACH;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public"
|
|
11
11
|
},
|
|
12
|
-
"version": "1.0.
|
|
12
|
+
"version": "1.0.7",
|
|
13
13
|
"sideEffects": false,
|
|
14
14
|
"main": "./dist/index.js",
|
|
15
15
|
"module": "./dist/index.mjs",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"ts-jest": "^29.1.1",
|
|
30
30
|
"tsup": "^6.7.0",
|
|
31
31
|
"typescript": "^5.2.3",
|
|
32
|
-
"eslint-config-custom": "1.0.
|
|
33
|
-
"tsconfig": "1.0.
|
|
32
|
+
"eslint-config-custom": "1.0.2",
|
|
33
|
+
"tsconfig": "1.0.2"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@segment/analytics-node": "^2.1.2",
|
|
@@ -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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
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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