@copilotkit/shared 1.0.0-beta.1 → 1.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/.turbo/turbo-build.log +31 -45
  2. package/CHANGELOG.md +6 -0
  3. package/dist/{chunk-3VA36BKL.mjs → chunk-2WEXXBTK.mjs} +1 -4
  4. package/dist/chunk-2WEXXBTK.mjs.map +1 -0
  5. package/dist/{chunk-2VLE6D3W.mjs → chunk-3AJ2GKWG.mjs} +2 -2
  6. package/dist/chunk-3AJ2GKWG.mjs.map +1 -0
  7. package/dist/chunk-DE5K76I2.mjs +1 -0
  8. package/dist/chunk-YJLRG5U3.mjs +1 -0
  9. package/dist/constants/index.d.ts +1 -1
  10. package/dist/constants/index.js +1 -1
  11. package/dist/constants/index.js.map +1 -1
  12. package/dist/constants/index.mjs +1 -1
  13. package/dist/index.d.ts +0 -2
  14. package/dist/index.js +6 -172
  15. package/dist/index.js.map +1 -1
  16. package/dist/index.mjs +5 -14
  17. package/dist/telemetry/index.js +0 -3
  18. package/dist/telemetry/index.js.map +1 -1
  19. package/dist/telemetry/index.mjs +1 -1
  20. package/dist/telemetry/telemetry-client.js +0 -3
  21. package/dist/telemetry/telemetry-client.js.map +1 -1
  22. package/dist/telemetry/telemetry-client.mjs +1 -1
  23. package/dist/types/index.d.ts +0 -1
  24. package/dist/types/index.js.map +1 -1
  25. package/dist/types/index.mjs +1 -2
  26. package/dist/utils/index.d.ts +0 -3
  27. package/dist/utils/index.js +5 -168
  28. package/dist/utils/index.js.map +1 -1
  29. package/dist/utils/index.mjs +2 -10
  30. package/package.json +1 -1
  31. package/src/constants/index.ts +1 -1
  32. package/src/telemetry/telemetry-client.ts +0 -5
  33. package/src/types/index.ts +0 -1
  34. package/src/utils/index.ts +0 -1
  35. package/dist/chunk-2VLE6D3W.mjs.map +0 -1
  36. package/dist/chunk-3VA36BKL.mjs.map +0 -1
  37. package/dist/chunk-BANDZXMP.mjs +0 -1
  38. package/dist/chunk-CYDWEPFL.mjs +0 -1
  39. package/dist/chunk-S4HGLK2E.mjs +0 -163
  40. package/dist/chunk-S4HGLK2E.mjs.map +0 -1
  41. package/dist/chunk-YBHX4Y25.mjs +0 -1
  42. package/dist/chunk-YBHX4Y25.mjs.map +0 -1
  43. package/dist/types/annotated-function.d.ts +0 -24
  44. package/dist/types/annotated-function.js +0 -19
  45. package/dist/types/annotated-function.js.map +0 -1
  46. package/dist/types/annotated-function.mjs +0 -2
  47. package/dist/types/annotated-function.mjs.map +0 -1
  48. package/dist/utils/annotated-function.d.ts +0 -9
  49. package/dist/utils/annotated-function.js +0 -189
  50. package/dist/utils/annotated-function.js.map +0 -1
  51. package/dist/utils/annotated-function.mjs +0 -11
  52. package/dist/utils/annotated-function.mjs.map +0 -1
  53. package/src/types/annotated-function.ts +0 -27
  54. package/src/utils/annotated-function.ts +0 -179
  55. /package/dist/{chunk-BANDZXMP.mjs.map → chunk-DE5K76I2.mjs.map} +0 -0
  56. /package/dist/{chunk-CYDWEPFL.mjs.map → chunk-YJLRG5U3.mjs.map} +0 -0
@@ -1,8 +1,8 @@
1
1
 
2
- > @copilotkit/shared@1.0.0-beta.1 build /home/runner/work/CopilotKit/CopilotKit/CopilotKit/packages/shared
2
+ > @copilotkit/shared@1.0.0-beta.2 build /home/runner/work/CopilotKit/CopilotKit/CopilotKit/packages/shared
3
3
  > tsup --clean
4
4
 
5
- CLI Building entry: src/index.ts, src/constants/index.ts, src/telemetry/events.ts, src/telemetry/index.ts, src/telemetry/security-check.ts, src/telemetry/telemetry-client.ts, src/telemetry/utils.ts, src/types/action.ts, src/types/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
+ CLI Building entry: src/index.ts, src/constants/index.ts, src/telemetry/events.ts, src/telemetry/index.ts, src/telemetry/security-check.ts, src/telemetry/telemetry-client.ts, src/telemetry/utils.ts, src/types/action.ts, src/types/copilot-cloud-config.ts, src/types/index.ts, src/types/openai-assistant.ts, src/utils/index.ts, src/utils/json-schema.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
7
  CLI tsup v6.7.0
8
8
  CLI Using tsup config: /home/runner/work/CopilotKit/CopilotKit/CopilotKit/packages/shared/tsup.config.ts
@@ -10,106 +10,92 @@
10
10
  CLI Cleaning output folder
11
11
  ESM Build start
12
12
  CJS Build start
13
- CJS dist/utils/annotated-function.js 5.84 KB
14
- CJS dist/index.js 14.35 KB
15
- CJS dist/constants/index.js 1.65 KB
13
+ CJS dist/utils/index.js 3.23 KB
14
+ CJS dist/index.js 9.45 KB
15
+ CJS dist/constants/index.js 1.64 KB
16
16
  CJS dist/telemetry/events.js 805.00 B
17
- CJS dist/telemetry/index.js 6.72 KB
17
+ CJS dist/telemetry/index.js 6.63 KB
18
18
  CJS dist/telemetry/security-check.js 56.00 B
19
- CJS dist/telemetry/telemetry-client.js 6.73 KB
19
+ CJS dist/telemetry/telemetry-client.js 6.63 KB
20
20
  CJS dist/telemetry/utils.js 3.14 KB
21
21
  CJS dist/types/action.js 801.00 B
22
- CJS dist/types/annotated-function.js 849.00 B
23
22
  CJS dist/types/copilot-cloud-config.js 857.00 B
24
23
  CJS dist/types/index.js 797.00 B
25
24
  CJS dist/types/openai-assistant.js 841.00 B
26
- CJS dist/utils/index.js 8.03 KB
27
25
  CJS dist/utils/json-schema.js 3.23 KB
28
- CJS dist/utils/annotated-function.js.map 8.45 KB
29
- CJS dist/index.js.map 22.36 KB
30
- CJS dist/constants/index.js.map 564.00 B
26
+ CJS dist/utils/index.js.map 4.82 KB
27
+ CJS dist/index.js.map 13.75 KB
28
+ CJS dist/constants/index.js.map 551.00 B
31
29
  CJS dist/telemetry/events.js.map 330.00 B
32
- CJS dist/telemetry/index.js.map 8.84 KB
30
+ CJS dist/telemetry/index.js.map 8.61 KB
33
31
  CJS dist/telemetry/security-check.js.map 71.00 B
34
- CJS dist/telemetry/telemetry-client.js.map 8.77 KB
32
+ CJS dist/telemetry/telemetry-client.js.map 8.54 KB
35
33
  CJS dist/telemetry/utils.js.map 2.00 KB
36
34
  CJS dist/types/action.js.map 4.84 KB
37
- CJS dist/types/annotated-function.js.map 871.00 B
38
35
  CJS dist/types/copilot-cloud-config.js.map 356.00 B
39
- CJS dist/types/index.js.map 277.00 B
36
+ CJS dist/types/index.js.map 236.00 B
40
37
  CJS dist/types/openai-assistant.js.map 1.53 KB
41
- CJS dist/utils/index.js.map 13.23 KB
42
38
  CJS dist/utils/json-schema.js.map 4.75 KB
43
- CJS ⚡️ Build success in 112ms
44
- ESM dist/index.mjs 997.00 B
39
+ CJS ⚡️ Build success in 104ms
40
+ ESM dist/index.mjs 711.00 B
45
41
  ESM dist/constants/index.mjs 315.00 B
46
42
  ESM dist/telemetry/events.mjs 35.00 B
47
43
  ESM dist/types/action.mjs 67.00 B
48
- ESM dist/chunk-BANDZXMP.mjs 43.00 B
49
- ESM dist/chunk-YBHX4Y25.mjs 43.00 B
44
+ ESM dist/chunk-DE5K76I2.mjs 43.00 B
50
45
  ESM dist/chunk-MSUB6DGR.mjs 43.00 B
51
46
  ESM dist/chunk-IAFBVORQ.mjs 43.00 B
52
- ESM dist/chunk-CYDWEPFL.mjs 43.00 B
53
- ESM dist/chunk-S4HGLK2E.mjs 4.62 KB
47
+ ESM dist/chunk-YJLRG5U3.mjs 43.00 B
54
48
  ESM dist/chunk-CIPF7PMC.mjs 2.20 KB
55
- ESM dist/chunk-2VLE6D3W.mjs 468.00 B
49
+ ESM dist/chunk-3AJ2GKWG.mjs 455.00 B
56
50
  ESM dist/telemetry/index.mjs 187.00 B
57
51
  ESM dist/chunk-P7STFMPO.mjs 43.00 B
58
52
  ESM dist/telemetry/security-check.mjs 43.00 B
59
53
  ESM dist/telemetry/telemetry-client.mjs 166.00 B
60
- ESM dist/chunk-3VA36BKL.mjs 3.67 KB
54
+ ESM dist/chunk-2WEXXBTK.mjs 3.58 KB
61
55
  ESM dist/telemetry/utils.mjs 165.00 B
62
56
  ESM dist/chunk-6QGXWNS5.mjs 1.41 KB
63
57
  ESM dist/chunk-NAFEBKSO.mjs 43.00 B
64
- ESM dist/types/annotated-function.mjs 79.00 B
65
58
  ESM dist/types/copilot-cloud-config.mjs 81.00 B
66
- ESM dist/types/index.mjs 194.00 B
59
+ ESM dist/types/index.mjs 162.00 B
67
60
  ESM dist/types/openai-assistant.mjs 77.00 B
68
- ESM dist/utils/annotated-function.mjs 314.00 B
69
- ESM dist/utils/index.mjs 437.00 B
61
+ ESM dist/utils/index.mjs 181.00 B
70
62
  ESM dist/utils/json-schema.mjs 155.00 B
71
63
  ESM dist/index.mjs.map 71.00 B
72
64
  ESM dist/constants/index.mjs.map 71.00 B
73
65
  ESM dist/telemetry/events.mjs.map 71.00 B
74
66
  ESM dist/types/action.mjs.map 71.00 B
75
- ESM dist/chunk-BANDZXMP.mjs.map 71.00 B
76
- ESM dist/chunk-YBHX4Y25.mjs.map 71.00 B
67
+ ESM dist/chunk-DE5K76I2.mjs.map 71.00 B
77
68
  ESM dist/chunk-MSUB6DGR.mjs.map 71.00 B
78
69
  ESM dist/chunk-IAFBVORQ.mjs.map 71.00 B
79
- ESM dist/chunk-CYDWEPFL.mjs.map 71.00 B
80
- ESM dist/chunk-S4HGLK2E.mjs.map 8.40 KB
70
+ ESM dist/chunk-YJLRG5U3.mjs.map 71.00 B
81
71
  ESM dist/chunk-CIPF7PMC.mjs.map 4.71 KB
82
- ESM dist/chunk-2VLE6D3W.mjs.map 502.00 B
72
+ ESM dist/chunk-3AJ2GKWG.mjs.map 489.00 B
83
73
  ESM dist/telemetry/index.mjs.map 71.00 B
84
74
  ESM dist/chunk-P7STFMPO.mjs.map 71.00 B
85
75
  ESM dist/telemetry/security-check.mjs.map 71.00 B
86
76
  ESM dist/telemetry/telemetry-client.mjs.map 71.00 B
87
- ESM dist/chunk-3VA36BKL.mjs.map 6.84 KB
77
+ ESM dist/chunk-2WEXXBTK.mjs.map 6.61 KB
88
78
  ESM dist/telemetry/utils.mjs.map 71.00 B
89
79
  ESM dist/chunk-6QGXWNS5.mjs.map 1.90 KB
90
80
  ESM dist/chunk-NAFEBKSO.mjs.map 71.00 B
91
- ESM dist/types/annotated-function.mjs.map 71.00 B
92
81
  ESM dist/types/copilot-cloud-config.mjs.map 71.00 B
93
82
  ESM dist/types/index.mjs.map 71.00 B
94
83
  ESM dist/types/openai-assistant.mjs.map 71.00 B
95
- ESM dist/utils/annotated-function.mjs.map 71.00 B
96
84
  ESM dist/utils/index.mjs.map 71.00 B
97
85
  ESM dist/utils/json-schema.mjs.map 71.00 B
98
- ESM ⚡️ Build success in 128ms
86
+ ESM ⚡️ Build success in 123ms
99
87
  DTS Build start
100
- DTS ⚡️ Build success in 4913ms
101
- DTS dist/index.d.ts 1.03 KB
88
+ DTS ⚡️ Build success in 5474ms
89
+ DTS dist/index.d.ts 750.00 B
102
90
  DTS dist/types/openai-assistant.d.ts 1.47 KB
103
- DTS dist/types/annotated-function.d.ts 766.00 B
104
91
  DTS dist/types/action.d.ts 2.24 KB
105
92
  DTS dist/types/copilot-cloud-config.d.ts 278.00 B
106
- DTS dist/utils/annotated-function.d.ts 600.00 B
107
93
  DTS dist/utils/json-schema.d.ts 884.00 B
108
- DTS dist/constants/index.d.ts 410.00 B
94
+ DTS dist/constants/index.d.ts 397.00 B
109
95
  DTS dist/telemetry/telemetry-client.d.ts 1.16 KB
110
96
  DTS dist/telemetry/events.d.ts 223.00 B
111
97
  DTS dist/telemetry/index.d.ts 102.00 B
112
98
  DTS dist/telemetry/security-check.d.ts 12.00 B
113
99
  DTS dist/telemetry/utils.d.ts 333.00 B
114
- DTS dist/types/index.d.ts 444.00 B
115
- DTS dist/utils/index.d.ts 420.00 B
100
+ DTS dist/types/index.d.ts 291.00 B
101
+ DTS dist/utils/index.d.ts 196.00 B
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @copilotkit/shared
2
2
 
3
+ ## 1.0.0-beta.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Set default Copilot Cloud runtime URL to versioned URL (v1)
8
+
3
9
  ## 1.0.0-beta.1
4
10
 
5
11
  ### Patch Changes
@@ -34,9 +34,6 @@ var TelemetryClient = class {
34
34
  "copilotkit.package.name": packageName,
35
35
  "copilotkit.package.version": packageVersion
36
36
  });
37
- if (typeof globalThis.navigator !== "undefined") {
38
- globalThis.navigator = {};
39
- }
40
37
  }
41
38
  shouldSendEvent() {
42
39
  if (!this.telemetryBaseUrl) {
@@ -119,4 +116,4 @@ var TelemetryClient = class {
119
116
  export {
120
117
  TelemetryClient
121
118
  };
122
- //# sourceMappingURL=chunk-3VA36BKL.mjs.map
119
+ //# sourceMappingURL=chunk-2WEXXBTK.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\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,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;AAE7B,SAAK,mBACH,oBACC,QAAQ,IAAY,iCACrB;AAEF,SAAK,UAAU,IAAI,QAAQ,gBAAgB,SAAS;AAAA,MAClD,MAAM,GAAG,KAAK;AAAA,IAChB,CAAC;AAED,SAAK,oBAAoB;AAAA,MACvB,2BAA2B;AAAA,MAC3B,8BAA8B;AAAA,IAChC,CAAC;AAAA,EACH;AAAA,EAEQ,kBAAkB;AACxB,QAAI,CAAC,KAAK,kBAA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AEA,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":[]}
@@ -1,7 +1,7 @@
1
1
  // src/constants/index.ts
2
2
  var COPILOT_CLOUD_API_URL = "https://api.copilotkit.ai";
3
3
  var COPILOT_CLOUD_VERSION = "v1";
4
- var COPILOT_CLOUD_CHAT_URL = `${COPILOT_CLOUD_API_URL}/${COPILOT_CLOUD_VERSION}/copilotkit/runtime/chat`;
4
+ var COPILOT_CLOUD_CHAT_URL = `${COPILOT_CLOUD_API_URL}/copilotkit/${COPILOT_CLOUD_VERSION}`;
5
5
  var COPILOT_CLOUD_PUBLIC_API_KEY_HEADER = "X-CopilotCloud-Public-Api-Key";
6
6
 
7
7
  export {
@@ -10,4 +10,4 @@ export {
10
10
  COPILOT_CLOUD_CHAT_URL,
11
11
  COPILOT_CLOUD_PUBLIC_API_KEY_HEADER
12
12
  };
13
- //# sourceMappingURL=chunk-2VLE6D3W.mjs.map
13
+ //# sourceMappingURL=chunk-3AJ2GKWG.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/constants/index.ts"],"sourcesContent":["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"],"mappings":";AAAO,IAAM,wBAAwB;AAC9B,IAAM,wBAAwB;AAC9B,IAAM,yBAAyB,GAAG,oCAAoC;AACtE,IAAM,sCAAsC;","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-DE5K76I2.mjs.map
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-YJLRG5U3.mjs.map
@@ -1,6 +1,6 @@
1
1
  declare const COPILOT_CLOUD_API_URL = "https://api.copilotkit.ai";
2
2
  declare const COPILOT_CLOUD_VERSION = "v1";
3
- declare const COPILOT_CLOUD_CHAT_URL = "https://api.copilotkit.ai/v1/copilotkit/runtime/chat";
3
+ declare const COPILOT_CLOUD_CHAT_URL = "https://api.copilotkit.ai/copilotkit/v1";
4
4
  declare const COPILOT_CLOUD_PUBLIC_API_KEY_HEADER = "X-CopilotCloud-Public-Api-Key";
5
5
 
6
6
  export { COPILOT_CLOUD_API_URL, COPILOT_CLOUD_CHAT_URL, COPILOT_CLOUD_PUBLIC_API_KEY_HEADER, COPILOT_CLOUD_VERSION };
@@ -28,7 +28,7 @@ __export(constants_exports, {
28
28
  module.exports = __toCommonJS(constants_exports);
29
29
  var COPILOT_CLOUD_API_URL = "https://api.copilotkit.ai";
30
30
  var COPILOT_CLOUD_VERSION = "v1";
31
- var COPILOT_CLOUD_CHAT_URL = `${COPILOT_CLOUD_API_URL}/${COPILOT_CLOUD_VERSION}/copilotkit/runtime/chat`;
31
+ var COPILOT_CLOUD_CHAT_URL = `${COPILOT_CLOUD_API_URL}/copilotkit/${COPILOT_CLOUD_VERSION}`;
32
32
  var COPILOT_CLOUD_PUBLIC_API_KEY_HEADER = "X-CopilotCloud-Public-Api-Key";
33
33
  // Annotate the CommonJS export names for ESM import in node:
34
34
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/constants/index.ts"],"sourcesContent":["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;AAAO,IAAM,wBAAwB;AAC9B,IAAM,wBAAwB;AAC9B,IAAM,yBAAyB,GAAG,yBAAyB;AAC3D,IAAM,sCAAsC;","names":[]}
1
+ {"version":3,"sources":["../../src/constants/index.ts"],"sourcesContent":["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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,IAAM,wBAAwB;AAC9B,IAAM,wBAAwB;AAC9B,IAAM,yBAAyB,GAAG,oCAAoC;AACtE,IAAM,sCAAsC;","names":[]}
@@ -3,7 +3,7 @@ import {
3
3
  COPILOT_CLOUD_CHAT_URL,
4
4
  COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,
5
5
  COPILOT_CLOUD_VERSION
6
- } from "../chunk-2VLE6D3W.mjs";
6
+ } from "../chunk-3AJ2GKWG.mjs";
7
7
  export {
8
8
  COPILOT_CLOUD_API_URL,
9
9
  COPILOT_CLOUD_CHAT_URL,
package/dist/index.d.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  export { AssistantMessage, FunctionCallHandler, FunctionCallHandlerArguments, FunctionDefinition, JSONValue, ToolDefinition } from './types/openai-assistant.js';
2
- export { AnnotatedFunction, AnnotatedFunctionArgument, AnnotatedFunctionArrayArgument, AnnotatedFunctionSimpleArgument } from './types/annotated-function.js';
3
2
  export { Action, MappedParameterTypes, Parameter } from './types/action.js';
4
3
  export { CopilotCloudConfig } from './types/copilot-cloud-config.js';
5
- export { actionToChatCompletionFunction, annotatedFunctionToAction, annotatedFunctionToChatCompletionFunction } from './utils/annotated-function.js';
6
4
  export { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema } from './utils/json-schema.js';
7
5
  export { COPILOT_CLOUD_API_URL, COPILOT_CLOUD_CHAT_URL, COPILOT_CLOUD_PUBLIC_API_KEY_HEADER, COPILOT_CLOUD_VERSION } from './constants/index.js';
8
6
  export { TelemetryClient } from './telemetry/telemetry-client.js';
package/dist/index.js CHANGED
@@ -35,175 +35,15 @@ __export(src_exports, {
35
35
  COPILOT_CLOUD_PUBLIC_API_KEY_HEADER: () => COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,
36
36
  COPILOT_CLOUD_VERSION: () => COPILOT_CLOUD_VERSION,
37
37
  TelemetryClient: () => TelemetryClient,
38
- actionParametersToJsonSchema: () => actionParametersToJsonSchema,
39
- actionToChatCompletionFunction: () => actionToChatCompletionFunction,
40
- annotatedFunctionToAction: () => annotatedFunctionToAction,
41
- annotatedFunctionToChatCompletionFunction: () => annotatedFunctionToChatCompletionFunction
38
+ actionParametersToJsonSchema: () => actionParametersToJsonSchema
42
39
  });
43
40
  module.exports = __toCommonJS(src_exports);
44
41
 
45
- // src/utils/annotated-function.ts
46
- function annotatedFunctionToChatCompletionFunction(annotatedFunction) {
47
- let parameters = {};
48
- for (let arg of annotatedFunction.argumentAnnotations) {
49
- let { name, required, ...forwardedArgs } = arg;
50
- parameters[arg.name] = forwardedArgs;
51
- }
52
- let requiredParameterNames = [];
53
- for (let arg of annotatedFunction.argumentAnnotations) {
54
- if (arg.required) {
55
- requiredParameterNames.push(arg.name);
56
- }
57
- }
58
- let chatCompletionFunction = {
59
- type: "function",
60
- function: {
61
- name: annotatedFunction.name,
62
- description: annotatedFunction.description,
63
- parameters: {
64
- type: "object",
65
- properties: parameters,
66
- required: requiredParameterNames
67
- }
68
- }
69
- };
70
- return chatCompletionFunction;
71
- }
72
- function convertAttribute(attribute) {
73
- var _a, _b, _c;
74
- switch (attribute.type) {
75
- case "string":
76
- return {
77
- type: "string",
78
- description: attribute.description,
79
- ...attribute.enum && { enum: attribute.enum }
80
- };
81
- case "number":
82
- case "boolean":
83
- return {
84
- type: attribute.type,
85
- description: attribute.description
86
- };
87
- case "object":
88
- case "object[]":
89
- const properties = (_a = attribute.attributes) == null ? void 0 : _a.reduce(
90
- (acc, attr) => {
91
- acc[attr.name] = convertAttribute(attr);
92
- return acc;
93
- },
94
- {}
95
- );
96
- const required = (_b = attribute.attributes) == null ? void 0 : _b.filter((attr) => attr.required !== false).map((attr) => attr.name);
97
- if (attribute.type === "object[]") {
98
- return {
99
- type: "array",
100
- items: {
101
- type: "object",
102
- ...properties && { properties },
103
- ...required && required.length > 0 && { required }
104
- },
105
- description: attribute.description
106
- };
107
- }
108
- return {
109
- type: "object",
110
- description: attribute.description,
111
- ...properties && { properties },
112
- ...required && required.length > 0 && { required }
113
- };
114
- default:
115
- if ((_c = attribute.type) == null ? void 0 : _c.endsWith("[]")) {
116
- const itemType = attribute.type.slice(0, -2);
117
- return {
118
- type: "array",
119
- items: { type: itemType },
120
- description: attribute.description
121
- };
122
- }
123
- return {
124
- type: "string",
125
- description: attribute.description
126
- };
127
- }
128
- }
129
- function actionToChatCompletionFunction(action) {
130
- let parameters = {};
131
- for (let parameter of action.parameters || []) {
132
- parameters[parameter.name] = convertAttribute(parameter);
133
- }
134
- let requiredParameterNames = [];
135
- for (let arg of action.parameters || []) {
136
- if (arg.required !== false) {
137
- requiredParameterNames.push(arg.name);
138
- }
139
- }
140
- let chatCompletionFunction = {
141
- type: "function",
142
- function: {
143
- name: action.name,
144
- ...action.description && { description: action.description },
145
- parameters: {
146
- type: "object",
147
- properties: parameters,
148
- required: requiredParameterNames
149
- }
150
- }
151
- };
152
- return chatCompletionFunction;
153
- }
154
- function annotatedFunctionToAction(annotatedFunction) {
155
- const parameters = annotatedFunction.argumentAnnotations.map((annotation) => {
156
- switch (annotation.type) {
157
- case "string":
158
- case "number":
159
- case "boolean":
160
- case "object":
161
- return {
162
- name: annotation.name,
163
- description: annotation.description,
164
- type: annotation.type,
165
- required: annotation.required
166
- };
167
- case "array":
168
- let type;
169
- if (annotation.items.type === "string") {
170
- type = "string[]";
171
- } else if (annotation.items.type === "number") {
172
- type = "number[]";
173
- } else if (annotation.items.type === "boolean") {
174
- type = "boolean[]";
175
- } else if (annotation.items.type === "object") {
176
- type = "object[]";
177
- } else {
178
- type = "string[]";
179
- }
180
- return {
181
- name: annotation.name,
182
- description: annotation.description,
183
- type,
184
- required: annotation.required
185
- };
186
- }
187
- });
188
- return {
189
- name: annotatedFunction.name,
190
- description: annotatedFunction.description,
191
- parameters,
192
- handler: (args) => {
193
- const paramsInCorrectOrder = [];
194
- for (let arg of annotatedFunction.argumentAnnotations) {
195
- paramsInCorrectOrder.push(args[arg.name]);
196
- }
197
- return annotatedFunction.implementation(...paramsInCorrectOrder);
198
- }
199
- };
200
- }
201
-
202
42
  // src/utils/json-schema.ts
203
43
  function actionParametersToJsonSchema(actionParameters) {
204
44
  let parameters = {};
205
45
  for (let parameter of actionParameters || []) {
206
- parameters[parameter.name] = convertAttribute2(parameter);
46
+ parameters[parameter.name] = convertAttribute(parameter);
207
47
  }
208
48
  let requiredParameterNames = [];
209
49
  for (let arg of actionParameters || []) {
@@ -217,7 +57,7 @@ function actionParametersToJsonSchema(actionParameters) {
217
57
  required: requiredParameterNames
218
58
  };
219
59
  }
220
- function convertAttribute2(attribute) {
60
+ function convertAttribute(attribute) {
221
61
  var _a, _b, _c;
222
62
  switch (attribute.type) {
223
63
  case "string":
@@ -236,7 +76,7 @@ function convertAttribute2(attribute) {
236
76
  case "object[]":
237
77
  const properties = (_a = attribute.attributes) == null ? void 0 : _a.reduce(
238
78
  (acc, attr) => {
239
- acc[attr.name] = convertAttribute2(attr);
79
+ acc[attr.name] = convertAttribute(attr);
240
80
  return acc;
241
81
  },
242
82
  {}
@@ -278,7 +118,7 @@ function convertAttribute2(attribute) {
278
118
  // src/constants/index.ts
279
119
  var COPILOT_CLOUD_API_URL = "https://api.copilotkit.ai";
280
120
  var COPILOT_CLOUD_VERSION = "v1";
281
- var COPILOT_CLOUD_CHAT_URL = `${COPILOT_CLOUD_API_URL}/${COPILOT_CLOUD_VERSION}/copilotkit/runtime/chat`;
121
+ var COPILOT_CLOUD_CHAT_URL = `${COPILOT_CLOUD_API_URL}/copilotkit/${COPILOT_CLOUD_VERSION}`;
282
122
  var COPILOT_CLOUD_PUBLIC_API_KEY_HEADER = "X-CopilotCloud-Public-Api-Key";
283
123
 
284
124
  // src/telemetry/telemetry-client.ts
@@ -343,9 +183,6 @@ var TelemetryClient = class {
343
183
  "copilotkit.package.name": packageName,
344
184
  "copilotkit.package.version": packageVersion
345
185
  });
346
- if (typeof globalThis.navigator !== "undefined") {
347
- globalThis.navigator = {};
348
- }
349
186
  }
350
187
  shouldSendEvent() {
351
188
  if (!this.telemetryBaseUrl) {
@@ -431,9 +268,6 @@ var TelemetryClient = class {
431
268
  COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,
432
269
  COPILOT_CLOUD_VERSION,
433
270
  TelemetryClient,
434
- actionParametersToJsonSchema,
435
- actionToChatCompletionFunction,
436
- annotatedFunctionToAction,
437
- annotatedFunctionToChatCompletionFunction
271
+ actionParametersToJsonSchema
438
272
  });
439
273
  //# sourceMappingURL=index.js.map
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","../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;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,MACvB,YAAY,KAAK;AAAA,MACjB,4BAA4B,IAAI,KAAK;AAAA,IACvC,CAAC;AAAA,EACH;AACF;","names":["convertAttribute","chalk"]}
1
+ {"version":3,"sources":["../src/index.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 { 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}/copilotkit/${COPILOT_CLOUD_VERSION}`;\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\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;;;ACsCO,SAAS,6BAA6B,kBAA2C;AAEtF,MAAI,aAAqC,CAAC;AAC1C,WAAS,aAAa,oBAAoB,CAAC,GAAG;AAC5C,eAAW,UAAU,IAAI,IAAI,iBAAiB,SAAS;AAAA,EACzD;AAEA,MAAI,yBAAmC,CAAC;AACxC,WAAS,OAAO,oBAAoB,CAAC,GAAG;AACtC,QAAI,IAAI,aAAa,OAAO;AAC1B,6BAAuB,KAAK,IAAI,IAAI;AAAA,IACtC;AAAA,EACF;AAGA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,UAAU;AAAA,EACZ;AACF;AAEA,SAAS,iBAAiB,WAAkC;AA5D5D;AA6DE,UAAQ,UAAU,MAAM;AAAA,IACtB,KAAK;AACH,aAAO;AAAA,QACL,MAAM;AAAA,QACN,aAAa,UAAU;AAAA,QACvB,GAAI,UAAU,QAAQ,EAAE,MAAM,UAAU,KAAK;AAAA,MAC/C;AAAA,IACF,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,QACL,MAAM,UAAU;AAAA,QAChB,aAAa,UAAU;AAAA,MACzB;AAAA,IACF,KAAK;AAAA,IACL,KAAK;AACH,YAAM,cAAa,eAAU,eAAV,mBAAsB;AAAA,QACvC,CAAC,KAAK,SAAS;AACb,cAAI,KAAK,IAAI,IAAI,iBAAiB,IAAI;AACtC,iBAAO;AAAA,QACT;AAAA,QACA,CAAC;AAAA;AAEH,YAAM,YAAW,eAAU,eAAV,mBACb,OAAO,CAAC,SAAS,KAAK,aAAa,OACpC,IAAI,CAAC,SAAS,KAAK;AACtB,UAAI,UAAU,SAAS,YAAY;AACjC,eAAO;AAAA,UACL,MAAM;AAAA,UACN,OAAO;AAAA,YAC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AAS,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":["chalk"]}
package/dist/index.mjs CHANGED
@@ -1,13 +1,7 @@
1
- import "./chunk-BANDZXMP.mjs";
2
- import "./chunk-YBHX4Y25.mjs";
1
+ import "./chunk-DE5K76I2.mjs";
3
2
  import "./chunk-MSUB6DGR.mjs";
4
3
  import "./chunk-IAFBVORQ.mjs";
5
- import "./chunk-CYDWEPFL.mjs";
6
- import {
7
- actionToChatCompletionFunction,
8
- annotatedFunctionToAction,
9
- annotatedFunctionToChatCompletionFunction
10
- } from "./chunk-S4HGLK2E.mjs";
4
+ import "./chunk-YJLRG5U3.mjs";
11
5
  import {
12
6
  actionParametersToJsonSchema
13
7
  } from "./chunk-CIPF7PMC.mjs";
@@ -16,11 +10,11 @@ import {
16
10
  COPILOT_CLOUD_CHAT_URL,
17
11
  COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,
18
12
  COPILOT_CLOUD_VERSION
19
- } from "./chunk-2VLE6D3W.mjs";
13
+ } from "./chunk-3AJ2GKWG.mjs";
20
14
  import "./chunk-P7STFMPO.mjs";
21
15
  import {
22
16
  TelemetryClient
23
- } from "./chunk-3VA36BKL.mjs";
17
+ } from "./chunk-2WEXXBTK.mjs";
24
18
  import "./chunk-6QGXWNS5.mjs";
25
19
  import "./chunk-NAFEBKSO.mjs";
26
20
  export {
@@ -29,9 +23,6 @@ export {
29
23
  COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,
30
24
  COPILOT_CLOUD_VERSION,
31
25
  TelemetryClient,
32
- actionParametersToJsonSchema,
33
- actionToChatCompletionFunction,
34
- annotatedFunctionToAction,
35
- annotatedFunctionToChatCompletionFunction
26
+ actionParametersToJsonSchema
36
27
  };
37
28
  //# sourceMappingURL=index.mjs.map
@@ -96,9 +96,6 @@ var TelemetryClient = class {
96
96
  "copilotkit.package.name": packageName,
97
97
  "copilotkit.package.version": packageVersion
98
98
  });
99
- if (typeof globalThis.navigator !== "undefined") {
100
- globalThis.navigator = {};
101
- }
102
99
  }
103
100
  shouldSendEvent() {
104
101
  if (!this.telemetryBaseUrl) {