@copilotkit/shared 1.0.0-beta.0 → 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +56 -25
- package/CHANGELOG.md +6 -0
- package/dist/chunk-3VA36BKL.mjs +122 -0
- package/dist/chunk-3VA36BKL.mjs.map +1 -0
- package/dist/chunk-6QGXWNS5.mjs +34 -0
- package/dist/chunk-6QGXWNS5.mjs.map +1 -0
- package/dist/chunk-P7STFMPO.mjs +1 -0
- package/dist/chunk-P7STFMPO.mjs.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +156 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -9
- package/dist/telemetry/events.d.ts +9 -0
- package/dist/telemetry/events.js +19 -0
- package/dist/telemetry/events.js.map +1 -0
- package/dist/telemetry/events.mjs +1 -0
- package/dist/telemetry/events.mjs.map +1 -0
- package/dist/telemetry/index.d.ts +3 -0
- package/dist/telemetry/index.js +184 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/telemetry/index.mjs +9 -0
- package/dist/telemetry/index.mjs.map +1 -0
- package/dist/telemetry/security-check.d.ts +2 -0
- package/dist/telemetry/security-check.js +2 -0
- package/dist/telemetry/security-check.js.map +1 -0
- package/dist/telemetry/security-check.mjs +1 -0
- package/dist/telemetry/security-check.mjs.map +1 -0
- package/dist/telemetry/telemetry-client.d.ts +36 -0
- package/dist/telemetry/telemetry-client.js +182 -0
- package/dist/telemetry/telemetry-client.js.map +1 -0
- package/dist/telemetry/telemetry-client.mjs +8 -0
- package/dist/telemetry/telemetry-client.mjs.map +1 -0
- package/dist/telemetry/utils.d.ts +8 -0
- package/dist/telemetry/utils.js +69 -0
- package/dist/telemetry/utils.js.map +1 -0
- package/dist/telemetry/utils.mjs +9 -0
- package/dist/telemetry/utils.mjs.map +1 -0
- package/dist/types/index.mjs +1 -1
- package/dist/utils/index.mjs +3 -3
- package/package.json +5 -3
- package/src/index.ts +1 -0
- package/src/telemetry/events.ts +7 -0
- package/src/telemetry/index.ts +1 -0
- package/src/telemetry/security-check.ts +0 -0
- package/src/telemetry/telemetry-client.ts +164 -0
- package/src/telemetry/utils.ts +39 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
|
-
> @copilotkit/shared@1.0.0-beta.
|
|
2
|
+
> @copilotkit/shared@1.0.0-beta.1 build /home/runner/work/CopilotKit/CopilotKit/CopilotKit/packages/shared
|
|
3
3
|
> tsup --clean
|
|
4
4
|
|
|
5
|
-
[34mCLI[39m Building entry: src/index.ts, src/constants/index.ts, src/types/action.ts, src/types/annotated-function.ts, src/types/copilot-cloud-config.ts, src/types/index.ts, src/types/openai-assistant.ts, src/utils/annotated-function.ts, src/utils/index.ts, src/utils/json-schema.ts
|
|
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/annotated-function.ts, src/types/copilot-cloud-config.ts, src/types/index.ts, src/types/openai-assistant.ts, src/utils/annotated-function.ts, src/utils/index.ts, src/utils/json-schema.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v6.7.0
|
|
8
8
|
[34mCLI[39m Using tsup config: /home/runner/work/CopilotKit/CopilotKit/CopilotKit/packages/shared/tsup.config.ts
|
|
@@ -10,69 +10,95 @@
|
|
|
10
10
|
[34mCLI[39m Cleaning output folder
|
|
11
11
|
[34mESM[39m Build start
|
|
12
12
|
[34mCJS[39m Build start
|
|
13
|
-
[32mCJS[39m [1mdist/
|
|
13
|
+
[32mCJS[39m [1mdist/utils/annotated-function.js [22m[32m5.84 KB[39m
|
|
14
|
+
[32mCJS[39m [1mdist/index.js [22m[32m14.35 KB[39m
|
|
14
15
|
[32mCJS[39m [1mdist/constants/index.js [22m[32m1.65 KB[39m
|
|
16
|
+
[32mCJS[39m [1mdist/telemetry/events.js [22m[32m805.00 B[39m
|
|
17
|
+
[32mCJS[39m [1mdist/telemetry/index.js [22m[32m6.72 KB[39m
|
|
18
|
+
[32mCJS[39m [1mdist/telemetry/security-check.js [22m[32m56.00 B[39m
|
|
19
|
+
[32mCJS[39m [1mdist/telemetry/telemetry-client.js [22m[32m6.73 KB[39m
|
|
20
|
+
[32mCJS[39m [1mdist/telemetry/utils.js [22m[32m3.14 KB[39m
|
|
15
21
|
[32mCJS[39m [1mdist/types/action.js [22m[32m801.00 B[39m
|
|
16
22
|
[32mCJS[39m [1mdist/types/annotated-function.js [22m[32m849.00 B[39m
|
|
17
23
|
[32mCJS[39m [1mdist/types/copilot-cloud-config.js [22m[32m857.00 B[39m
|
|
18
24
|
[32mCJS[39m [1mdist/types/index.js [22m[32m797.00 B[39m
|
|
19
25
|
[32mCJS[39m [1mdist/types/openai-assistant.js [22m[32m841.00 B[39m
|
|
20
|
-
[32mCJS[39m [1mdist/utils/annotated-function.js [22m[32m5.84 KB[39m
|
|
21
26
|
[32mCJS[39m [1mdist/utils/index.js [22m[32m8.03 KB[39m
|
|
22
27
|
[32mCJS[39m [1mdist/utils/json-schema.js [22m[32m3.23 KB[39m
|
|
23
|
-
[32mCJS[39m [1mdist/
|
|
28
|
+
[32mCJS[39m [1mdist/utils/annotated-function.js.map [22m[32m8.45 KB[39m
|
|
29
|
+
[32mCJS[39m [1mdist/index.js.map [22m[32m22.36 KB[39m
|
|
24
30
|
[32mCJS[39m [1mdist/constants/index.js.map [22m[32m564.00 B[39m
|
|
31
|
+
[32mCJS[39m [1mdist/telemetry/events.js.map [22m[32m330.00 B[39m
|
|
32
|
+
[32mCJS[39m [1mdist/telemetry/index.js.map [22m[32m8.84 KB[39m
|
|
33
|
+
[32mCJS[39m [1mdist/telemetry/security-check.js.map [22m[32m71.00 B[39m
|
|
34
|
+
[32mCJS[39m [1mdist/telemetry/telemetry-client.js.map [22m[32m8.77 KB[39m
|
|
35
|
+
[32mCJS[39m [1mdist/telemetry/utils.js.map [22m[32m2.00 KB[39m
|
|
25
36
|
[32mCJS[39m [1mdist/types/action.js.map [22m[32m4.84 KB[39m
|
|
26
37
|
[32mCJS[39m [1mdist/types/annotated-function.js.map [22m[32m871.00 B[39m
|
|
27
38
|
[32mCJS[39m [1mdist/types/copilot-cloud-config.js.map [22m[32m356.00 B[39m
|
|
28
39
|
[32mCJS[39m [1mdist/types/index.js.map [22m[32m277.00 B[39m
|
|
29
40
|
[32mCJS[39m [1mdist/types/openai-assistant.js.map [22m[32m1.53 KB[39m
|
|
30
|
-
[32mCJS[39m [1mdist/utils/annotated-function.js.map [22m[32m8.45 KB[39m
|
|
31
41
|
[32mCJS[39m [1mdist/utils/index.js.map [22m[32m13.23 KB[39m
|
|
32
42
|
[32mCJS[39m [1mdist/utils/json-schema.js.map [22m[32m4.75 KB[39m
|
|
33
|
-
[32mCJS[39m ⚡️ Build success in
|
|
34
|
-
[32mESM[39m [1mdist/index.mjs [22m[
|
|
43
|
+
[32mCJS[39m ⚡️ Build success in 112ms
|
|
44
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m997.00 B[39m
|
|
35
45
|
[32mESM[39m [1mdist/constants/index.mjs [22m[32m315.00 B[39m
|
|
46
|
+
[32mESM[39m [1mdist/telemetry/events.mjs [22m[32m35.00 B[39m
|
|
36
47
|
[32mESM[39m [1mdist/types/action.mjs [22m[32m67.00 B[39m
|
|
37
|
-
[32mESM[39m [1mdist/
|
|
48
|
+
[32mESM[39m [1mdist/chunk-BANDZXMP.mjs [22m[32m43.00 B[39m
|
|
49
|
+
[32mESM[39m [1mdist/chunk-YBHX4Y25.mjs [22m[32m43.00 B[39m
|
|
50
|
+
[32mESM[39m [1mdist/chunk-MSUB6DGR.mjs [22m[32m43.00 B[39m
|
|
51
|
+
[32mESM[39m [1mdist/chunk-IAFBVORQ.mjs [22m[32m43.00 B[39m
|
|
38
52
|
[32mESM[39m [1mdist/chunk-CYDWEPFL.mjs [22m[32m43.00 B[39m
|
|
53
|
+
[32mESM[39m [1mdist/chunk-S4HGLK2E.mjs [22m[32m4.62 KB[39m
|
|
39
54
|
[32mESM[39m [1mdist/chunk-CIPF7PMC.mjs [22m[32m2.20 KB[39m
|
|
40
55
|
[32mESM[39m [1mdist/chunk-2VLE6D3W.mjs [22m[32m468.00 B[39m
|
|
56
|
+
[32mESM[39m [1mdist/telemetry/index.mjs [22m[32m187.00 B[39m
|
|
57
|
+
[32mESM[39m [1mdist/chunk-P7STFMPO.mjs [22m[32m43.00 B[39m
|
|
58
|
+
[32mESM[39m [1mdist/telemetry/security-check.mjs [22m[32m43.00 B[39m
|
|
59
|
+
[32mESM[39m [1mdist/telemetry/telemetry-client.mjs [22m[32m166.00 B[39m
|
|
60
|
+
[32mESM[39m [1mdist/chunk-3VA36BKL.mjs [22m[32m3.67 KB[39m
|
|
61
|
+
[32mESM[39m [1mdist/telemetry/utils.mjs [22m[32m165.00 B[39m
|
|
62
|
+
[32mESM[39m [1mdist/chunk-6QGXWNS5.mjs [22m[32m1.41 KB[39m
|
|
63
|
+
[32mESM[39m [1mdist/chunk-NAFEBKSO.mjs [22m[32m43.00 B[39m
|
|
41
64
|
[32mESM[39m [1mdist/types/annotated-function.mjs [22m[32m79.00 B[39m
|
|
42
65
|
[32mESM[39m [1mdist/types/copilot-cloud-config.mjs [22m[32m81.00 B[39m
|
|
43
66
|
[32mESM[39m [1mdist/types/index.mjs [22m[32m194.00 B[39m
|
|
44
|
-
[32mESM[39m [1mdist/chunk-BANDZXMP.mjs [22m[32m43.00 B[39m
|
|
45
|
-
[32mESM[39m [1mdist/chunk-NAFEBKSO.mjs [22m[32m43.00 B[39m
|
|
46
|
-
[32mESM[39m [1mdist/chunk-YBHX4Y25.mjs [22m[32m43.00 B[39m
|
|
47
|
-
[32mESM[39m [1mdist/chunk-MSUB6DGR.mjs [22m[32m43.00 B[39m
|
|
48
67
|
[32mESM[39m [1mdist/types/openai-assistant.mjs [22m[32m77.00 B[39m
|
|
49
|
-
[32mESM[39m [1mdist/
|
|
50
|
-
[32mESM[39m [1mdist/chunk-S4HGLK2E.mjs [22m[32m4.62 KB[39m
|
|
68
|
+
[32mESM[39m [1mdist/utils/annotated-function.mjs [22m[32m314.00 B[39m
|
|
51
69
|
[32mESM[39m [1mdist/utils/index.mjs [22m[32m437.00 B[39m
|
|
52
70
|
[32mESM[39m [1mdist/utils/json-schema.mjs [22m[32m155.00 B[39m
|
|
53
71
|
[32mESM[39m [1mdist/index.mjs.map [22m[32m71.00 B[39m
|
|
54
72
|
[32mESM[39m [1mdist/constants/index.mjs.map [22m[32m71.00 B[39m
|
|
73
|
+
[32mESM[39m [1mdist/telemetry/events.mjs.map [22m[32m71.00 B[39m
|
|
55
74
|
[32mESM[39m [1mdist/types/action.mjs.map [22m[32m71.00 B[39m
|
|
56
|
-
[32mESM[39m [1mdist/
|
|
75
|
+
[32mESM[39m [1mdist/chunk-BANDZXMP.mjs.map [22m[32m71.00 B[39m
|
|
76
|
+
[32mESM[39m [1mdist/chunk-YBHX4Y25.mjs.map [22m[32m71.00 B[39m
|
|
77
|
+
[32mESM[39m [1mdist/chunk-MSUB6DGR.mjs.map [22m[32m71.00 B[39m
|
|
78
|
+
[32mESM[39m [1mdist/chunk-IAFBVORQ.mjs.map [22m[32m71.00 B[39m
|
|
57
79
|
[32mESM[39m [1mdist/chunk-CYDWEPFL.mjs.map [22m[32m71.00 B[39m
|
|
80
|
+
[32mESM[39m [1mdist/chunk-S4HGLK2E.mjs.map [22m[32m8.40 KB[39m
|
|
58
81
|
[32mESM[39m [1mdist/chunk-CIPF7PMC.mjs.map [22m[32m4.71 KB[39m
|
|
59
82
|
[32mESM[39m [1mdist/chunk-2VLE6D3W.mjs.map [22m[32m502.00 B[39m
|
|
83
|
+
[32mESM[39m [1mdist/telemetry/index.mjs.map [22m[32m71.00 B[39m
|
|
84
|
+
[32mESM[39m [1mdist/chunk-P7STFMPO.mjs.map [22m[32m71.00 B[39m
|
|
85
|
+
[32mESM[39m [1mdist/telemetry/security-check.mjs.map [22m[32m71.00 B[39m
|
|
86
|
+
[32mESM[39m [1mdist/telemetry/telemetry-client.mjs.map [22m[32m71.00 B[39m
|
|
87
|
+
[32mESM[39m [1mdist/chunk-3VA36BKL.mjs.map [22m[32m6.84 KB[39m
|
|
88
|
+
[32mESM[39m [1mdist/telemetry/utils.mjs.map [22m[32m71.00 B[39m
|
|
89
|
+
[32mESM[39m [1mdist/chunk-6QGXWNS5.mjs.map [22m[32m1.90 KB[39m
|
|
90
|
+
[32mESM[39m [1mdist/chunk-NAFEBKSO.mjs.map [22m[32m71.00 B[39m
|
|
60
91
|
[32mESM[39m [1mdist/types/annotated-function.mjs.map [22m[32m71.00 B[39m
|
|
61
92
|
[32mESM[39m [1mdist/types/copilot-cloud-config.mjs.map [22m[32m71.00 B[39m
|
|
62
93
|
[32mESM[39m [1mdist/types/index.mjs.map [22m[32m71.00 B[39m
|
|
63
|
-
[32mESM[39m [1mdist/chunk-BANDZXMP.mjs.map [22m[32m71.00 B[39m
|
|
64
|
-
[32mESM[39m [1mdist/chunk-NAFEBKSO.mjs.map [22m[32m71.00 B[39m
|
|
65
|
-
[32mESM[39m [1mdist/chunk-YBHX4Y25.mjs.map [22m[32m71.00 B[39m
|
|
66
|
-
[32mESM[39m [1mdist/chunk-MSUB6DGR.mjs.map [22m[32m71.00 B[39m
|
|
67
94
|
[32mESM[39m [1mdist/types/openai-assistant.mjs.map [22m[32m71.00 B[39m
|
|
68
|
-
[32mESM[39m [1mdist/
|
|
69
|
-
[32mESM[39m [1mdist/chunk-S4HGLK2E.mjs.map [22m[32m8.40 KB[39m
|
|
95
|
+
[32mESM[39m [1mdist/utils/annotated-function.mjs.map [22m[32m71.00 B[39m
|
|
70
96
|
[32mESM[39m [1mdist/utils/index.mjs.map [22m[32m71.00 B[39m
|
|
71
97
|
[32mESM[39m [1mdist/utils/json-schema.mjs.map [22m[32m71.00 B[39m
|
|
72
|
-
[32mESM[39m ⚡️ Build success in
|
|
98
|
+
[32mESM[39m ⚡️ Build success in 128ms
|
|
73
99
|
[34mDTS[39m Build start
|
|
74
|
-
[32mDTS[39m ⚡️ Build success in
|
|
75
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
100
|
+
[32mDTS[39m ⚡️ Build success in 4913ms
|
|
101
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m1.03 KB[39m
|
|
76
102
|
[32mDTS[39m [1mdist/types/openai-assistant.d.ts [22m[32m1.47 KB[39m
|
|
77
103
|
[32mDTS[39m [1mdist/types/annotated-function.d.ts [22m[32m766.00 B[39m
|
|
78
104
|
[32mDTS[39m [1mdist/types/action.d.ts [22m[32m2.24 KB[39m
|
|
@@ -80,5 +106,10 @@
|
|
|
80
106
|
[32mDTS[39m [1mdist/utils/annotated-function.d.ts [22m[32m600.00 B[39m
|
|
81
107
|
[32mDTS[39m [1mdist/utils/json-schema.d.ts [22m[32m884.00 B[39m
|
|
82
108
|
[32mDTS[39m [1mdist/constants/index.d.ts [22m[32m410.00 B[39m
|
|
109
|
+
[32mDTS[39m [1mdist/telemetry/telemetry-client.d.ts [22m[32m1.16 KB[39m
|
|
110
|
+
[32mDTS[39m [1mdist/telemetry/events.d.ts [22m[32m223.00 B[39m
|
|
111
|
+
[32mDTS[39m [1mdist/telemetry/index.d.ts [22m[32m102.00 B[39m
|
|
112
|
+
[32mDTS[39m [1mdist/telemetry/security-check.d.ts [22m[32m12.00 B[39m
|
|
113
|
+
[32mDTS[39m [1mdist/telemetry/utils.d.ts [22m[32m333.00 B[39m
|
|
83
114
|
[32mDTS[39m [1mdist/types/index.d.ts [22m[32m444.00 B[39m
|
|
84
115
|
[32mDTS[39m [1mdist/utils/index.d.ts [22m[32m420.00 B[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {
|
|
2
|
+
flattenObject,
|
|
3
|
+
printSecurityNotice
|
|
4
|
+
} from "./chunk-6QGXWNS5.mjs";
|
|
5
|
+
|
|
6
|
+
// src/telemetry/telemetry-client.ts
|
|
7
|
+
import { PostHog } from "posthog-node";
|
|
8
|
+
import { randomUUID } from "crypto";
|
|
9
|
+
var TelemetryClient = class {
|
|
10
|
+
constructor({
|
|
11
|
+
packageName,
|
|
12
|
+
packageVersion,
|
|
13
|
+
telemetryDisabled,
|
|
14
|
+
telemetryBaseUrl,
|
|
15
|
+
posthogToken,
|
|
16
|
+
sampleRate
|
|
17
|
+
}) {
|
|
18
|
+
this.globalProperties = {};
|
|
19
|
+
this.cloudConfiguration = null;
|
|
20
|
+
this.telemetryDisabled = false;
|
|
21
|
+
this.sampleRate = 0.05;
|
|
22
|
+
this.packageName = packageName;
|
|
23
|
+
this.packageVersion = packageVersion;
|
|
24
|
+
this.telemetryDisabled = telemetryDisabled || process.env.COPILOTKIT_TELEMETRY_DISABLED === "true" || process.env.COPILOTKIT_TELEMETRY_DISABLED === "1" || process.env.DO_NOT_TRACK === "true" || process.env.DO_NOT_TRACK === "1";
|
|
25
|
+
if (this.telemetryDisabled) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
this.setSampleRate(sampleRate);
|
|
29
|
+
this.telemetryBaseUrl = telemetryBaseUrl || process.env.COPILOTKIT_TELEMETRY_BASE_URL || "https://telemetry.copilotkit.ai";
|
|
30
|
+
this.posthog = new PostHog(posthogToken || "token", {
|
|
31
|
+
host: `${this.telemetryBaseUrl}/telemetry/ingest`
|
|
32
|
+
});
|
|
33
|
+
this.setGlobalProperties({
|
|
34
|
+
"copilotkit.package.name": packageName,
|
|
35
|
+
"copilotkit.package.version": packageVersion
|
|
36
|
+
});
|
|
37
|
+
if (typeof globalThis.navigator !== "undefined") {
|
|
38
|
+
globalThis.navigator = {};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
shouldSendEvent() {
|
|
42
|
+
if (!this.telemetryBaseUrl) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
const randomNumber = Math.random();
|
|
46
|
+
return randomNumber < this.sampleRate;
|
|
47
|
+
}
|
|
48
|
+
async capture(event, properties) {
|
|
49
|
+
if (!this.shouldSendEvent() || !this.posthog) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const flattenedProperties = flattenObject(properties);
|
|
53
|
+
const propertiesWithGlobal = {
|
|
54
|
+
...this.globalProperties,
|
|
55
|
+
...flattenedProperties
|
|
56
|
+
};
|
|
57
|
+
const orderedPropertiesWithGlobal = Object.keys(propertiesWithGlobal).sort().reduce(
|
|
58
|
+
(obj, key) => {
|
|
59
|
+
obj[key] = propertiesWithGlobal[key];
|
|
60
|
+
return obj;
|
|
61
|
+
},
|
|
62
|
+
{}
|
|
63
|
+
);
|
|
64
|
+
this.posthog.capture({
|
|
65
|
+
distinctId: randomUUID(),
|
|
66
|
+
event,
|
|
67
|
+
properties: { ...orderedPropertiesWithGlobal }
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
async checkForUpdates() {
|
|
71
|
+
const url = `${this.telemetryBaseUrl}/check-for-updates?packageName=${this.packageName}&packageVersion=${this.packageVersion}`;
|
|
72
|
+
const response = await fetch(url);
|
|
73
|
+
if (!response.ok) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const result = await response.json();
|
|
77
|
+
const { advisory, severity } = result;
|
|
78
|
+
if (!advisory && (severity === "low" || severity === "none")) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
printSecurityNotice(result);
|
|
82
|
+
}
|
|
83
|
+
setTelemetryBaseUrl(url) {
|
|
84
|
+
this.telemetryBaseUrl = url;
|
|
85
|
+
if (this.posthog) {
|
|
86
|
+
this.posthog.host = `${url}/telemetry/ingest`;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
setGlobalProperties(properties) {
|
|
90
|
+
const flattenedProperties = flattenObject(properties);
|
|
91
|
+
this.globalProperties = { ...this.globalProperties, ...flattenedProperties };
|
|
92
|
+
}
|
|
93
|
+
setCloudConfiguration(properties) {
|
|
94
|
+
this.cloudConfiguration = properties;
|
|
95
|
+
this.setGlobalProperties({
|
|
96
|
+
cloud: {
|
|
97
|
+
publicApiKey: properties.publicApiKey,
|
|
98
|
+
baseUrl: properties.baseUrl
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
setSampleRate(sampleRate) {
|
|
103
|
+
let _sampleRate;
|
|
104
|
+
_sampleRate = sampleRate ?? 0.05;
|
|
105
|
+
if (process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE) {
|
|
106
|
+
_sampleRate = parseFloat(process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE);
|
|
107
|
+
}
|
|
108
|
+
if (_sampleRate < 0 || _sampleRate > 1) {
|
|
109
|
+
throw new Error("Sample rate must be between 0 and 1");
|
|
110
|
+
}
|
|
111
|
+
this.sampleRate = _sampleRate;
|
|
112
|
+
this.setGlobalProperties({
|
|
113
|
+
sampleRate: this.sampleRate,
|
|
114
|
+
sampleRateAdjustmentFactor: 1 - this.sampleRate
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export {
|
|
120
|
+
TelemetryClient
|
|
121
|
+
};
|
|
122
|
+
//# sourceMappingURL=chunk-3VA36BKL.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/telemetry/telemetry-client.ts"],"sourcesContent":["import { PostHog } from \"posthog-node\";\nimport { AnalyticsEvents } from \"./events\";\nimport { flattenObject, printSecurityNotice } from \"./utils\";\nimport { randomUUID } from \"crypto\";\n\nexport class TelemetryClient {\n posthog: PostHog | 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\n constructor({\n packageName,\n packageVersion,\n telemetryDisabled,\n telemetryBaseUrl,\n posthogToken,\n sampleRate,\n }: {\n packageName: string;\n packageVersion: string;\n telemetryDisabled?: boolean;\n telemetryBaseUrl?: string;\n posthogToken?: 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.posthog = new PostHog(posthogToken || \"token\", {\n host: `${this.telemetryBaseUrl}/telemetry/ingest`,\n });\n\n this.setGlobalProperties({\n \"copilotkit.package.name\": packageName,\n \"copilotkit.package.version\": packageVersion,\n });\n\n // Eliminates a PostHog error on Next.js\n if (typeof (globalThis as any).navigator !== \"undefined\") {\n (globalThis as any).navigator = {};\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.posthog) {\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.posthog.capture({\n distinctId: randomUUID(),\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 setTelemetryBaseUrl(url: string) {\n this.telemetryBaseUrl = url;\n\n if (this.posthog) {\n this.posthog.host = `${url}/telemetry/ingest`;\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 if (process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE) {\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,eAAe;AAGxB,SAAS,kBAAkB;AAEpB,IAAM,kBAAN,MAAsB;AAAA,EAU3B,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAOG;AAtBH,4BAAwC,CAAC;AACzC,8BAAuE;AAGvE,SAAQ,oBAA6B;AAErC,SAAQ,aAAqB;AAiB3B,SAAK,cAAc;AACnB,SAAK,iBAAiB;AACtB,SAAK,oBACH,qBACC,QAAQ,IA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AE9G,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,KAAa;AAC/B,SAAK,mBAAmB;AAExB,QAAI,KAAK,SAAS;AAChB,WAAK,QAAQ,OAAO,GAAG;AAAA,IACzB;AAAA,EACF;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;AAE5B,QAAI,QAAQ,IAAI,kCAAkC;AAChD,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":[]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// src/telemetry/utils.ts
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
function flattenObject(obj, parentKey = "", res = {}) {
|
|
4
|
+
for (let key in obj) {
|
|
5
|
+
const propName = parentKey ? `${parentKey}.${key}` : key;
|
|
6
|
+
if (typeof obj[key] === "object" && obj[key] !== null) {
|
|
7
|
+
flattenObject(obj[key], propName, res);
|
|
8
|
+
} else {
|
|
9
|
+
res[propName] = obj[key];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return res;
|
|
13
|
+
}
|
|
14
|
+
function printSecurityNotice(advisory) {
|
|
15
|
+
const severityColor = {
|
|
16
|
+
low: chalk.blue,
|
|
17
|
+
medium: chalk.yellow,
|
|
18
|
+
high: chalk.red
|
|
19
|
+
}[advisory.severity.toLowerCase()] || chalk.white;
|
|
20
|
+
console.log();
|
|
21
|
+
console.log(`\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 ${chalk.bold(`CopilotKit`)} \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501`);
|
|
22
|
+
console.log();
|
|
23
|
+
console.log(`${chalk.bold(`Severity: ${severityColor(advisory.severity.toUpperCase())}`)}`);
|
|
24
|
+
console.log();
|
|
25
|
+
console.log(`${chalk.bold(advisory.message)}`);
|
|
26
|
+
console.log();
|
|
27
|
+
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`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
flattenObject,
|
|
32
|
+
printSecurityNotice
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=chunk-6QGXWNS5.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/telemetry/utils.ts"],"sourcesContent":["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,OAAO,WAAW;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,MAAM;AAAA,IACX,QAAQ,MAAM;AAAA,IACd,MAAM,MAAM;AAAA,EACd,EAAE,SAAS,SAAS,YAAY,CAAC,KAAK,MAAM;AAE9C,UAAQ,IAAI;AACZ,UAAQ,IAAI,gHAAsB,MAAM,KAAK,YAAY,gHAAsB;AAC/E,UAAQ,IAAI;AACZ,UAAQ,IAAI,GAAG,MAAM,KAAK,aAAa,cAAc,SAAS,SAAS,YAAY,CAAC,GAAG,GAAG;AAC1F,UAAQ,IAAI;AACZ,UAAQ,IAAI,GAAG,MAAM,KAAK,SAAS,OAAO,GAAG;AAC7C,UAAQ,IAAI;AACZ,UAAQ,IAAI,kSAAkD;AAChE;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-P7STFMPO.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,3 +5,6 @@ export { CopilotCloudConfig } from './types/copilot-cloud-config.js';
|
|
|
5
5
|
export { actionToChatCompletionFunction, annotatedFunctionToAction, annotatedFunctionToChatCompletionFunction } from './utils/annotated-function.js';
|
|
6
6
|
export { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema } from './utils/json-schema.js';
|
|
7
7
|
export { COPILOT_CLOUD_API_URL, COPILOT_CLOUD_CHAT_URL, COPILOT_CLOUD_PUBLIC_API_KEY_HEADER, COPILOT_CLOUD_VERSION } from './constants/index.js';
|
|
8
|
+
export { TelemetryClient } from './telemetry/telemetry-client.js';
|
|
9
|
+
import 'posthog-node';
|
|
10
|
+
import './telemetry/events.js';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -24,6 +34,7 @@ __export(src_exports, {
|
|
|
24
34
|
COPILOT_CLOUD_CHAT_URL: () => COPILOT_CLOUD_CHAT_URL,
|
|
25
35
|
COPILOT_CLOUD_PUBLIC_API_KEY_HEADER: () => COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,
|
|
26
36
|
COPILOT_CLOUD_VERSION: () => COPILOT_CLOUD_VERSION,
|
|
37
|
+
TelemetryClient: () => TelemetryClient,
|
|
27
38
|
actionParametersToJsonSchema: () => actionParametersToJsonSchema,
|
|
28
39
|
actionToChatCompletionFunction: () => actionToChatCompletionFunction,
|
|
29
40
|
annotatedFunctionToAction: () => annotatedFunctionToAction,
|
|
@@ -269,12 +280,157 @@ var COPILOT_CLOUD_API_URL = "https://api.copilotkit.ai";
|
|
|
269
280
|
var COPILOT_CLOUD_VERSION = "v1";
|
|
270
281
|
var COPILOT_CLOUD_CHAT_URL = `${COPILOT_CLOUD_API_URL}/${COPILOT_CLOUD_VERSION}/copilotkit/runtime/chat`;
|
|
271
282
|
var COPILOT_CLOUD_PUBLIC_API_KEY_HEADER = "X-CopilotCloud-Public-Api-Key";
|
|
283
|
+
|
|
284
|
+
// src/telemetry/telemetry-client.ts
|
|
285
|
+
var import_posthog_node = require("posthog-node");
|
|
286
|
+
|
|
287
|
+
// src/telemetry/utils.ts
|
|
288
|
+
var import_chalk = __toESM(require("chalk"));
|
|
289
|
+
function flattenObject(obj, parentKey = "", res = {}) {
|
|
290
|
+
for (let key in obj) {
|
|
291
|
+
const propName = parentKey ? `${parentKey}.${key}` : key;
|
|
292
|
+
if (typeof obj[key] === "object" && obj[key] !== null) {
|
|
293
|
+
flattenObject(obj[key], propName, res);
|
|
294
|
+
} else {
|
|
295
|
+
res[propName] = obj[key];
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return res;
|
|
299
|
+
}
|
|
300
|
+
function printSecurityNotice(advisory) {
|
|
301
|
+
const severityColor = {
|
|
302
|
+
low: import_chalk.default.blue,
|
|
303
|
+
medium: import_chalk.default.yellow,
|
|
304
|
+
high: import_chalk.default.red
|
|
305
|
+
}[advisory.severity.toLowerCase()] || import_chalk.default.white;
|
|
306
|
+
console.log();
|
|
307
|
+
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`);
|
|
308
|
+
console.log();
|
|
309
|
+
console.log(`${import_chalk.default.bold(`Severity: ${severityColor(advisory.severity.toUpperCase())}`)}`);
|
|
310
|
+
console.log();
|
|
311
|
+
console.log(`${import_chalk.default.bold(advisory.message)}`);
|
|
312
|
+
console.log();
|
|
313
|
+
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`);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// src/telemetry/telemetry-client.ts
|
|
317
|
+
var import_crypto = require("crypto");
|
|
318
|
+
var TelemetryClient = class {
|
|
319
|
+
constructor({
|
|
320
|
+
packageName,
|
|
321
|
+
packageVersion,
|
|
322
|
+
telemetryDisabled,
|
|
323
|
+
telemetryBaseUrl,
|
|
324
|
+
posthogToken,
|
|
325
|
+
sampleRate
|
|
326
|
+
}) {
|
|
327
|
+
this.globalProperties = {};
|
|
328
|
+
this.cloudConfiguration = null;
|
|
329
|
+
this.telemetryDisabled = false;
|
|
330
|
+
this.sampleRate = 0.05;
|
|
331
|
+
this.packageName = packageName;
|
|
332
|
+
this.packageVersion = packageVersion;
|
|
333
|
+
this.telemetryDisabled = telemetryDisabled || process.env.COPILOTKIT_TELEMETRY_DISABLED === "true" || process.env.COPILOTKIT_TELEMETRY_DISABLED === "1" || process.env.DO_NOT_TRACK === "true" || process.env.DO_NOT_TRACK === "1";
|
|
334
|
+
if (this.telemetryDisabled) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
this.setSampleRate(sampleRate);
|
|
338
|
+
this.telemetryBaseUrl = telemetryBaseUrl || process.env.COPILOTKIT_TELEMETRY_BASE_URL || "https://telemetry.copilotkit.ai";
|
|
339
|
+
this.posthog = new import_posthog_node.PostHog(posthogToken || "token", {
|
|
340
|
+
host: `${this.telemetryBaseUrl}/telemetry/ingest`
|
|
341
|
+
});
|
|
342
|
+
this.setGlobalProperties({
|
|
343
|
+
"copilotkit.package.name": packageName,
|
|
344
|
+
"copilotkit.package.version": packageVersion
|
|
345
|
+
});
|
|
346
|
+
if (typeof globalThis.navigator !== "undefined") {
|
|
347
|
+
globalThis.navigator = {};
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
shouldSendEvent() {
|
|
351
|
+
if (!this.telemetryBaseUrl) {
|
|
352
|
+
return false;
|
|
353
|
+
}
|
|
354
|
+
const randomNumber = Math.random();
|
|
355
|
+
return randomNumber < this.sampleRate;
|
|
356
|
+
}
|
|
357
|
+
async capture(event, properties) {
|
|
358
|
+
if (!this.shouldSendEvent() || !this.posthog) {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
const flattenedProperties = flattenObject(properties);
|
|
362
|
+
const propertiesWithGlobal = {
|
|
363
|
+
...this.globalProperties,
|
|
364
|
+
...flattenedProperties
|
|
365
|
+
};
|
|
366
|
+
const orderedPropertiesWithGlobal = Object.keys(propertiesWithGlobal).sort().reduce(
|
|
367
|
+
(obj, key) => {
|
|
368
|
+
obj[key] = propertiesWithGlobal[key];
|
|
369
|
+
return obj;
|
|
370
|
+
},
|
|
371
|
+
{}
|
|
372
|
+
);
|
|
373
|
+
this.posthog.capture({
|
|
374
|
+
distinctId: (0, import_crypto.randomUUID)(),
|
|
375
|
+
event,
|
|
376
|
+
properties: { ...orderedPropertiesWithGlobal }
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
async checkForUpdates() {
|
|
380
|
+
const url = `${this.telemetryBaseUrl}/check-for-updates?packageName=${this.packageName}&packageVersion=${this.packageVersion}`;
|
|
381
|
+
const response = await fetch(url);
|
|
382
|
+
if (!response.ok) {
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
const result = await response.json();
|
|
386
|
+
const { advisory, severity } = result;
|
|
387
|
+
if (!advisory && (severity === "low" || severity === "none")) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
printSecurityNotice(result);
|
|
391
|
+
}
|
|
392
|
+
setTelemetryBaseUrl(url) {
|
|
393
|
+
this.telemetryBaseUrl = url;
|
|
394
|
+
if (this.posthog) {
|
|
395
|
+
this.posthog.host = `${url}/telemetry/ingest`;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
setGlobalProperties(properties) {
|
|
399
|
+
const flattenedProperties = flattenObject(properties);
|
|
400
|
+
this.globalProperties = { ...this.globalProperties, ...flattenedProperties };
|
|
401
|
+
}
|
|
402
|
+
setCloudConfiguration(properties) {
|
|
403
|
+
this.cloudConfiguration = properties;
|
|
404
|
+
this.setGlobalProperties({
|
|
405
|
+
cloud: {
|
|
406
|
+
publicApiKey: properties.publicApiKey,
|
|
407
|
+
baseUrl: properties.baseUrl
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
setSampleRate(sampleRate) {
|
|
412
|
+
let _sampleRate;
|
|
413
|
+
_sampleRate = sampleRate ?? 0.05;
|
|
414
|
+
if (process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE) {
|
|
415
|
+
_sampleRate = parseFloat(process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE);
|
|
416
|
+
}
|
|
417
|
+
if (_sampleRate < 0 || _sampleRate > 1) {
|
|
418
|
+
throw new Error("Sample rate must be between 0 and 1");
|
|
419
|
+
}
|
|
420
|
+
this.sampleRate = _sampleRate;
|
|
421
|
+
this.setGlobalProperties({
|
|
422
|
+
sampleRate: this.sampleRate,
|
|
423
|
+
sampleRateAdjustmentFactor: 1 - this.sampleRate
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
};
|
|
272
427
|
// Annotate the CommonJS export names for ESM import in node:
|
|
273
428
|
0 && (module.exports = {
|
|
274
429
|
COPILOT_CLOUD_API_URL,
|
|
275
430
|
COPILOT_CLOUD_CHAT_URL,
|
|
276
431
|
COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,
|
|
277
432
|
COPILOT_CLOUD_VERSION,
|
|
433
|
+
TelemetryClient,
|
|
278
434
|
actionParametersToJsonSchema,
|
|
279
435
|
actionToChatCompletionFunction,
|
|
280
436
|
annotatedFunctionToAction,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/utils/annotated-function.ts","../src/utils/json-schema.ts","../src/constants/index.ts"],"sourcesContent":["export * from \"./types\";\nexport * from \"./utils\";\nexport * from \"./constants\";\n","import { Action, AnnotatedFunction, ToolDefinition, Parameter } from \"../types\";\n\nexport function annotatedFunctionToChatCompletionFunction(\n annotatedFunction: AnnotatedFunction<any[]>,\n): ToolDefinition {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let arg of annotatedFunction.argumentAnnotations) {\n // isolate the args we should forward inline\n let { name, required, ...forwardedArgs } = arg;\n parameters[arg.name] = forwardedArgs;\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of annotatedFunction.argumentAnnotations) {\n if (arg.required) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n let chatCompletionFunction: ToolDefinition = {\n type: \"function\",\n function: {\n name: annotatedFunction.name,\n description: annotatedFunction.description,\n parameters: {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n },\n },\n };\n\n return chatCompletionFunction;\n}\n\nfunction convertAttribute(attribute: Parameter): any {\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 },\n description: attribute.description,\n };\n }\n // Fallback for undefined type or any other unexpected type\n return {\n type: \"string\",\n description: attribute.description,\n };\n }\n}\n\nexport function actionToChatCompletionFunction(action: Action<any>): ToolDefinition {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let parameter of action.parameters || []) {\n parameters[parameter.name] = convertAttribute(parameter);\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of action.parameters || []) {\n if (arg.required !== false) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n let chatCompletionFunction: ToolDefinition = {\n type: \"function\",\n function: {\n name: action.name,\n ...(action.description && { description: action.description }),\n parameters: {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n },\n },\n };\n\n return chatCompletionFunction;\n}\n\nexport function annotatedFunctionToAction(\n annotatedFunction: AnnotatedFunction<any[]>,\n): Action<any> {\n const parameters: Parameter[] = annotatedFunction.argumentAnnotations.map((annotation) => {\n switch (annotation.type) {\n case \"string\":\n case \"number\":\n case \"boolean\":\n case \"object\":\n return {\n name: annotation.name,\n description: annotation.description,\n type: annotation.type,\n required: annotation.required,\n };\n case \"array\":\n let type;\n if (annotation.items.type === \"string\") {\n type = \"string[]\";\n } else if (annotation.items.type === \"number\") {\n type = \"number[]\";\n } else if (annotation.items.type === \"boolean\") {\n type = \"boolean[]\";\n } else if (annotation.items.type === \"object\") {\n type = \"object[]\";\n } else {\n type = \"string[]\";\n }\n return {\n name: annotation.name,\n description: annotation.description,\n type: type as any,\n required: annotation.required,\n };\n }\n });\n\n return {\n name: annotatedFunction.name,\n description: annotatedFunction.description,\n parameters: parameters,\n handler: (args) => {\n const paramsInCorrectOrder: any[] = [];\n for (let arg of annotatedFunction.argumentAnnotations) {\n paramsInCorrectOrder.push(args[arg.name]);\n }\n return annotatedFunction.implementation(...paramsInCorrectOrder);\n },\n };\n}\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 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}/${COPILOT_CLOUD_VERSION}/copilotkit/runtime/chat`;\nexport const COPILOT_CLOUD_PUBLIC_API_KEY_HEADER = \"X-CopilotCloud-Public-Api-Key\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,SAAS,0CACd,mBACgB;AAEhB,MAAI,aAAqC,CAAC;AAC1C,WAAS,OAAO,kBAAkB,qBAAqB;AAErD,QAAI,EAAE,MAAM,UAAU,GAAG,cAAc,IAAI;AAC3C,eAAW,IAAI,IAAI,IAAI;AAAA,EACzB;AAEA,MAAI,yBAAmC,CAAC;AACxC,WAAS,OAAO,kBAAkB,qBAAqB;AACrD,QAAI,IAAI,UAAU;AAChB,6BAAuB,KAAK,IAAI,IAAI;AAAA,IACtC;AAAA,EACF;AAGA,MAAI,yBAAyC;AAAA,IAC3C,MAAM;AAAA,IACN,UAAU;AAAA,MACR,MAAM,kBAAkB;AAAA,MACxB,aAAa,kBAAkB;AAAA,MAC/B,YAAY;AAAA,QACV,MAAM;AAAA,QACN,YAAY;AAAA,QACZ,UAAU;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEA,SAAS,iBAAiB,WAA2B;AArCrD;AAsCE,UAAQ,UAAU,MAAM;AAAA,IACtB,KAAK;AACH,aAAO;AAAA,QACL,MAAM;AAAA,QACN,aAAa,UAAU;AAAA,QACvB,GAAI,UAAU,Q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AACjC,eAAO;AAAA,UACL,MAAM;AAAA,UACN,OAAO;AAAA,YACL,MAAM;AAAA,YACN,GAAI,cAAc,EAAE,WAAW;AAAA,YAC/B,GAAI,YAAY,SAAS,SAAS,KAAK,EAAE,SAAS;AAAA,UACpD;AAAA,UACA,aAAa,UAAU;AAAA,QACzB;AAAA,MACF;AACA,aAAO;AAAA,QACL,MAAM;AAAA,QACN,aAAa,UAAU;AAAA,QACvB,GAAI,cAAc,EAAE,WAAW;AAAA,QAC/B,GAAI,YAAY,SAAS,SAAS,KAAK,EAAE,SAAS;AAAA,MACpD;AAAA,IACF;AAEE,WAAI,eAAU,SAAV,mBAAgB,SAAS,OAAO;AAClC,cAAM,WAAW,UAAU,KAAK,MAAM,GAAG,EAAE;AAC3C,eAAO;AAAA,UACL,MAAM;AAAA,UACN,OAAO,EAAE,MAAM,SAAgB;AAAA,UAC/B,aAAa,UAAU;AAAA,QACzB;AAAA,MACF;AAEA,aAAO;AAAA,QACL,MAAM;AAAA,QACN,aAAa,UAAU;AAAA,MACzB;AAAA,EACJ;AACF;;;ACvHO,IAAM,wBAAwB;AAC9B,IAAM,wBAAwB;AAC9B,IAAM,yBAAyB,GAAG,yBAAyB;AAC3D,IAAM,sCAAsC;","names":["convertAttribute"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/utils/annotated-function.ts","../src/utils/json-schema.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 { Action, AnnotatedFunction, ToolDefinition, Parameter } from \"../types\";\n\nexport function annotatedFunctionToChatCompletionFunction(\n annotatedFunction: AnnotatedFunction<any[]>,\n): ToolDefinition {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let arg of annotatedFunction.argumentAnnotations) {\n // isolate the args we should forward inline\n let { name, required, ...forwardedArgs } = arg;\n parameters[arg.name] = forwardedArgs;\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of annotatedFunction.argumentAnnotations) {\n if (arg.required) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n let chatCompletionFunction: ToolDefinition = {\n type: \"function\",\n function: {\n name: annotatedFunction.name,\n description: annotatedFunction.description,\n parameters: {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n },\n },\n };\n\n return chatCompletionFunction;\n}\n\nfunction convertAttribute(attribute: Parameter): any {\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 },\n description: attribute.description,\n };\n }\n // Fallback for undefined type or any other unexpected type\n return {\n type: \"string\",\n description: attribute.description,\n };\n }\n}\n\nexport function actionToChatCompletionFunction(action: Action<any>): ToolDefinition {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let parameter of action.parameters || []) {\n parameters[parameter.name] = convertAttribute(parameter);\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of action.parameters || []) {\n if (arg.required !== false) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n let chatCompletionFunction: ToolDefinition = {\n type: \"function\",\n function: {\n name: action.name,\n ...(action.description && { description: action.description }),\n parameters: {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n },\n },\n };\n\n return chatCompletionFunction;\n}\n\nexport function annotatedFunctionToAction(\n annotatedFunction: AnnotatedFunction<any[]>,\n): Action<any> {\n const parameters: Parameter[] = annotatedFunction.argumentAnnotations.map((annotation) => {\n switch (annotation.type) {\n case \"string\":\n case \"number\":\n case \"boolean\":\n case \"object\":\n return {\n name: annotation.name,\n description: annotation.description,\n type: annotation.type,\n required: annotation.required,\n };\n case \"array\":\n let type;\n if (annotation.items.type === \"string\") {\n type = \"string[]\";\n } else if (annotation.items.type === \"number\") {\n type = \"number[]\";\n } else if (annotation.items.type === \"boolean\") {\n type = \"boolean[]\";\n } else if (annotation.items.type === \"object\") {\n type = \"object[]\";\n } else {\n type = \"string[]\";\n }\n return {\n name: annotation.name,\n description: annotation.description,\n type: type as any,\n required: annotation.required,\n };\n }\n });\n\n return {\n name: annotatedFunction.name,\n description: annotatedFunction.description,\n parameters: parameters,\n handler: (args) => {\n const paramsInCorrectOrder: any[] = [];\n for (let arg of annotatedFunction.argumentAnnotations) {\n paramsInCorrectOrder.push(args[arg.name]);\n }\n return annotatedFunction.implementation(...paramsInCorrectOrder);\n },\n };\n}\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 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}/${COPILOT_CLOUD_VERSION}/copilotkit/runtime/chat`;\nexport const COPILOT_CLOUD_PUBLIC_API_KEY_HEADER = \"X-CopilotCloud-Public-Api-Key\";\n","import { PostHog } from \"posthog-node\";\nimport { AnalyticsEvents } from \"./events\";\nimport { flattenObject, printSecurityNotice } from \"./utils\";\nimport { randomUUID } from \"crypto\";\n\nexport class TelemetryClient {\n posthog: PostHog | 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\n constructor({\n packageName,\n packageVersion,\n telemetryDisabled,\n telemetryBaseUrl,\n posthogToken,\n sampleRate,\n }: {\n packageName: string;\n packageVersion: string;\n telemetryDisabled?: boolean;\n telemetryBaseUrl?: string;\n posthogToken?: 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.posthog = new PostHog(posthogToken || \"token\", {\n host: `${this.telemetryBaseUrl}/telemetry/ingest`,\n });\n\n this.setGlobalProperties({\n \"copilotkit.package.name\": packageName,\n \"copilotkit.package.version\": packageVersion,\n });\n\n // Eliminates a PostHog error on Next.js\n if (typeof (globalThis as any).navigator !== \"undefined\") {\n (globalThis as any).navigator = {};\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.posthog) {\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.posthog.capture({\n distinctId: randomUUID(),\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 setTelemetryBaseUrl(url: string) {\n this.telemetryBaseUrl = url;\n\n if (this.posthog) {\n this.posthog.host = `${url}/telemetry/ingest`;\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 if (process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE) {\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;AAAA;AAAA;;;ACEO,SAAS,0CACd,mBACgB;AAEhB,MAAI,aAAqC,CAAC;AAC1C,WAAS,OAAO,kBAAkB,qBAAqB;AAErD,QAAI,EAAE,MAAM,UAAU,GAAG,cAAc,IAAI;AAC3C,eAAW,IAAI,IAAI,IAAI;AAAA,EACzB;AAEA,MAAI,yBAAmC,CAAC;AACxC,WAAS,OAAO,kBAAkB,qBAAqB;AACrD,QAAI,IAAI,UAAU;AAChB,6BAAuB,KAAK,IAAI,IAAI;AAAA,IACtC;AAAA,EACF;AAGA,MAAI,yBAAyC;AAAA,IAC3C,MAAM;AAAA,I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