@copilotkit/shared 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
 
2
- > @copilotkit/shared@1.0.3 build /home/runner/work/CopilotKit/CopilotKit/CopilotKit/packages/shared
2
+ > @copilotkit/shared@1.0.4 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/copilot-cloud-config.ts, src/types/index.ts, src/types/openai-assistant.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, src/utils/random-id.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,15 +10,16 @@
10
10
  CLI Cleaning output folder
11
11
  ESM Build start
12
12
  CJS Build start
13
- ESM dist/index.mjs 711.00 B
13
+ ESM dist/index.mjs 774.00 B
14
14
  ESM dist/constants/index.mjs 315.00 B
15
15
  ESM dist/telemetry/events.mjs 35.00 B
16
16
  ESM dist/types/action.mjs 67.00 B
17
17
  ESM dist/chunk-DE5K76I2.mjs 43.00 B
18
18
  ESM dist/chunk-MSUB6DGR.mjs 43.00 B
19
19
  ESM dist/chunk-IAFBVORQ.mjs 43.00 B
20
- ESM dist/chunk-YJLRG5U3.mjs 43.00 B
20
+ ESM dist/chunk-CYDWEPFL.mjs 43.00 B
21
21
  ESM dist/chunk-CIPF7PMC.mjs 2.20 KB
22
+ ESM dist/chunk-6P6F44JQ.mjs 166.00 B
22
23
  ESM dist/chunk-3AJ2GKWG.mjs 455.00 B
23
24
  ESM dist/telemetry/index.mjs 187.00 B
24
25
  ESM dist/chunk-P7STFMPO.mjs 43.00 B
@@ -28,11 +29,12 @@
28
29
  ESM dist/telemetry/utils.mjs 165.00 B
29
30
  ESM dist/chunk-6QGXWNS5.mjs 1.41 KB
30
31
  ESM dist/chunk-NAFEBKSO.mjs 43.00 B
31
- ESM dist/utils/index.mjs 181.00 B
32
+ ESM dist/utils/index.mjs 245.00 B
32
33
  ESM dist/types/copilot-cloud-config.mjs 81.00 B
33
34
  ESM dist/types/index.mjs 162.00 B
34
35
  ESM dist/types/openai-assistant.mjs 77.00 B
35
36
  ESM dist/utils/json-schema.mjs 155.00 B
37
+ ESM dist/utils/random-id.mjs 113.00 B
36
38
  ESM dist/index.mjs.map 71.00 B
37
39
  ESM dist/constants/index.mjs.map 71.00 B
38
40
  ESM dist/telemetry/events.mjs.map 71.00 B
@@ -40,8 +42,9 @@
40
42
  ESM dist/chunk-DE5K76I2.mjs.map 71.00 B
41
43
  ESM dist/chunk-MSUB6DGR.mjs.map 71.00 B
42
44
  ESM dist/chunk-IAFBVORQ.mjs.map 71.00 B
43
- ESM dist/chunk-YJLRG5U3.mjs.map 71.00 B
45
+ ESM dist/chunk-CYDWEPFL.mjs.map 71.00 B
44
46
  ESM dist/chunk-CIPF7PMC.mjs.map 4.71 KB
47
+ ESM dist/chunk-6P6F44JQ.mjs.map 238.00 B
45
48
  ESM dist/chunk-3AJ2GKWG.mjs.map 489.00 B
46
49
  ESM dist/telemetry/index.mjs.map 71.00 B
47
50
  ESM dist/chunk-P7STFMPO.mjs.map 71.00 B
@@ -56,8 +59,9 @@
56
59
  ESM dist/types/index.mjs.map 71.00 B
57
60
  ESM dist/types/openai-assistant.mjs.map 71.00 B
58
61
  ESM dist/utils/json-schema.mjs.map 71.00 B
59
- ESM ⚡️ Build success in 84ms
60
- CJS dist/index.js 9.39 KB
62
+ ESM dist/utils/random-id.mjs.map 71.00 B
63
+ ESM ⚡️ Build success in 98ms
64
+ CJS dist/index.js 9.53 KB
61
65
  CJS dist/constants/index.js 1.64 KB
62
66
  CJS dist/telemetry/events.js 805.00 B
63
67
  CJS dist/telemetry/index.js 6.58 KB
@@ -68,9 +72,10 @@
68
72
  CJS dist/types/copilot-cloud-config.js 857.00 B
69
73
  CJS dist/types/index.js 797.00 B
70
74
  CJS dist/types/openai-assistant.js 841.00 B
71
- CJS dist/utils/index.js 3.23 KB
75
+ CJS dist/utils/index.js 3.37 KB
72
76
  CJS dist/utils/json-schema.js 3.23 KB
73
- CJS dist/index.js.map 13.63 KB
77
+ CJS dist/utils/random-id.js 1.15 KB
78
+ CJS dist/index.js.map 13.80 KB
74
79
  CJS dist/constants/index.js.map 551.00 B
75
80
  CJS dist/telemetry/events.js.map 330.00 B
76
81
  CJS dist/telemetry/index.js.map 8.49 KB
@@ -81,16 +86,18 @@
81
86
  CJS dist/types/copilot-cloud-config.js.map 356.00 B
82
87
  CJS dist/types/index.js.map 236.00 B
83
88
  CJS dist/types/openai-assistant.js.map 1.53 KB
84
- CJS dist/utils/index.js.map 4.82 KB
89
+ CJS dist/utils/index.js.map 5.02 KB
85
90
  CJS dist/utils/json-schema.js.map 4.75 KB
86
- CJS ⚡️ Build success in 107ms
91
+ CJS dist/utils/random-id.js.map 285.00 B
92
+ CJS ⚡️ Build success in 111ms
87
93
  DTS Build start
88
- DTS ⚡️ Build success in 5121ms
89
- DTS dist/index.d.ts 761.00 B
94
+ DTS ⚡️ Build success in 5224ms
95
+ DTS dist/index.d.ts 810.00 B
90
96
  DTS dist/types/openai-assistant.d.ts 1.47 KB
91
97
  DTS dist/types/action.d.ts 2.24 KB
92
98
  DTS dist/types/copilot-cloud-config.d.ts 278.00 B
93
99
  DTS dist/utils/json-schema.d.ts 884.00 B
100
+ DTS dist/utils/random-id.d.ts 59.00 B
94
101
  DTS dist/constants/index.d.ts 397.00 B
95
102
  DTS dist/telemetry/telemetry-client.d.ts 1.12 KB
96
103
  DTS dist/telemetry/events.d.ts 223.00 B
@@ -98,4 +105,4 @@
98
105
  DTS dist/telemetry/security-check.d.ts 12.00 B
99
106
  DTS dist/telemetry/utils.d.ts 333.00 B
100
107
  DTS dist/types/index.d.ts 291.00 B
101
- DTS dist/utils/index.d.ts 196.00 B
108
+ DTS dist/utils/index.d.ts 239.00 B
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @copilotkit/shared
2
2
 
3
+ ## 1.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Remove nanoid
8
+
3
9
  ## 1.0.3
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -41,7 +41,7 @@ in-app AI chatbots, AI agents, and AI Textareas.
41
41
  <img src="https://github.com/CopilotKit/CopilotKit/assets/131273140/a4a0fd04-6aee-4e02-9c3e-3f11d60b4e8b" alt="Read the Docs" height="30">
42
42
  </a>
43
43
  &nbsp;&middot;&nbsp;
44
- <a href="https://go.copilotkit.ai/kM4Lo86">
44
+ <a href="https://cloud.copilotkit.ai">
45
45
  <img src="https://github.com/CopilotKit/CopilotKit/assets/131273140/28ca62a8-cf93-4d3f-96b0-dc11bf89b734" alt="Try Copilot Cloud" height="30">
46
46
  </a>
47
47
  </p>
@@ -0,0 +1,9 @@
1
+ // src/utils/random-id.ts
2
+ function randomId() {
3
+ return "ck-" + globalThis.crypto.randomUUID();
4
+ }
5
+
6
+ export {
7
+ randomId
8
+ };
9
+ //# sourceMappingURL=chunk-6P6F44JQ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/random-id.ts"],"sourcesContent":["export function randomId() {\n return \"ck-\" + globalThis.crypto.randomUUID();\n}\n"],"mappings":";AAAO,SAAS,WAAW;AACzB,SAAO,QAAQ,WAAW,OAAO,WAAW;AAC9C;","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-CYDWEPFL.mjs.map
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export { AssistantMessage, FunctionCallHandler, FunctionCallHandlerArguments, Fu
2
2
  export { Action, MappedParameterTypes, Parameter } from './types/action.js';
3
3
  export { CopilotCloudConfig } from './types/copilot-cloud-config.js';
4
4
  export { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema } from './utils/json-schema.js';
5
+ export { randomId } from './utils/random-id.js';
5
6
  export { COPILOT_CLOUD_API_URL, COPILOT_CLOUD_CHAT_URL, COPILOT_CLOUD_PUBLIC_API_KEY_HEADER, COPILOT_CLOUD_VERSION } from './constants/index.js';
6
7
  export { TelemetryClient } from './telemetry/telemetry-client.js';
7
8
  import '@segment/analytics-node';
package/dist/index.js CHANGED
@@ -35,7 +35,8 @@ __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
38
+ actionParametersToJsonSchema: () => actionParametersToJsonSchema,
39
+ randomId: () => randomId
39
40
  });
40
41
  module.exports = __toCommonJS(src_exports);
41
42
 
@@ -115,6 +116,11 @@ function convertAttribute(attribute) {
115
116
  }
116
117
  }
117
118
 
119
+ // src/utils/random-id.ts
120
+ function randomId() {
121
+ return "ck-" + globalThis.crypto.randomUUID();
122
+ }
123
+
118
124
  // src/constants/index.ts
119
125
  var COPILOT_CLOUD_API_URL = "https://api.copilotkit.ai";
120
126
  var COPILOT_CLOUD_VERSION = "v1";
@@ -263,6 +269,7 @@ var TelemetryClient = class {
263
269
  COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,
264
270
  COPILOT_CLOUD_VERSION,
265
271
  TelemetryClient,
266
- actionParametersToJsonSchema
272
+ actionParametersToJsonSchema,
273
+ randomId
267
274
  });
268
275
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
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 { Analytics } from \"@segment/analytics-node\";\nimport { AnalyticsEvents } from \"./events\";\nimport { flattenObject, printSecurityNotice } from \"./utils\";\nimport { randomUUID } from \"crypto\";\n\nexport class TelemetryClient {\n segment: Analytics | undefined;\n globalProperties: Record<string, any> = {};\n cloudConfiguration: { publicApiKey: string; baseUrl: string } | null = null;\n packageName: string;\n packageVersion: string;\n private telemetryDisabled: boolean = false;\n private telemetryBaseUrl: string | undefined;\n private sampleRate: number = 0.05;\n private anonymousId = `anon_${randomUUID()}`;\n\n constructor({\n packageName,\n packageVersion,\n telemetryDisabled,\n telemetryBaseUrl,\n sampleRate,\n }: {\n packageName: string;\n packageVersion: string;\n telemetryDisabled?: boolean;\n telemetryBaseUrl?: string;\n sampleRate?: number;\n }) {\n this.packageName = packageName;\n this.packageVersion = packageVersion;\n this.telemetryDisabled =\n telemetryDisabled ||\n (process.env as any).COPILOTKIT_TELEMETRY_DISABLED === \"true\" ||\n (process.env as any).COPILOTKIT_TELEMETRY_DISABLED === \"1\" ||\n (process.env as any).DO_NOT_TRACK === \"true\" ||\n (process.env as any).DO_NOT_TRACK === \"1\";\n\n if (this.telemetryDisabled) {\n return;\n }\n\n this.setSampleRate(sampleRate);\n\n this.telemetryBaseUrl =\n telemetryBaseUrl ||\n (process.env as any).COPILOTKIT_TELEMETRY_BASE_URL ||\n \"https://telemetry.copilotkit.ai\";\n\n this.segment = new Analytics({\n // eslint-disable-next-line\n writeKey: process.env.COPILOTKIT_SEGMENT_WRITE_KEY || \"n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja\",\n });\n\n this.setGlobalProperties({\n \"copilotkit.package.name\": packageName,\n \"copilotkit.package.version\": packageVersion,\n });\n }\n\n private shouldSendEvent() {\n if (!this.telemetryBaseUrl) {\n return false;\n }\n\n const randomNumber = Math.random();\n return randomNumber < this.sampleRate;\n }\n\n async capture<K extends keyof AnalyticsEvents>(event: K, properties: AnalyticsEvents[K]) {\n if (!this.shouldSendEvent() || !this.segment) {\n return;\n }\n\n const flattenedProperties = flattenObject(properties);\n const propertiesWithGlobal = {\n ...this.globalProperties,\n ...flattenedProperties,\n };\n const orderedPropertiesWithGlobal = Object.keys(propertiesWithGlobal)\n .sort()\n .reduce(\n (obj, key) => {\n obj[key] = propertiesWithGlobal[key];\n return obj;\n },\n {} as Record<string, any>,\n );\n\n this.segment.track({\n anonymousId: this.anonymousId,\n event,\n properties: { ...orderedPropertiesWithGlobal },\n });\n }\n\n async checkForUpdates() {\n const url = `${this.telemetryBaseUrl}/check-for-updates?packageName=${this.packageName}&packageVersion=${this.packageVersion}`;\n\n const response = await fetch(url);\n\n if (!response.ok) {\n return;\n }\n\n const result = await response.json();\n const { advisory, severity } = result;\n\n if (!advisory && (severity === \"low\" || severity === \"none\")) {\n return;\n }\n\n printSecurityNotice(result);\n }\n\n setGlobalProperties(properties: Record<string, any>) {\n const flattenedProperties = flattenObject(properties);\n this.globalProperties = { ...this.globalProperties, ...flattenedProperties };\n }\n\n setCloudConfiguration(properties: { publicApiKey: string; baseUrl: string }) {\n this.cloudConfiguration = properties;\n\n this.setGlobalProperties({\n cloud: {\n publicApiKey: properties.publicApiKey,\n baseUrl: properties.baseUrl,\n },\n });\n }\n\n private setSampleRate(sampleRate: number | undefined) {\n let _sampleRate: number;\n\n _sampleRate = sampleRate ?? 0.05;\n\n // eslint-disable-next-line\n if (process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE) {\n // eslint-disable-next-line\n _sampleRate = parseFloat(process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE);\n }\n\n if (_sampleRate < 0 || _sampleRate > 1) {\n throw new Error(\"Sample rate must be between 0 and 1\");\n }\n\n this.sampleRate = _sampleRate;\n this.setGlobalProperties({\n sampleRate: this.sampleRate,\n sampleRateAdjustmentFactor: 1 - this.sampleRate,\n });\n }\n}\n","import chalk from \"chalk\";\n\nexport function flattenObject(\n obj: Record<string, any>,\n parentKey = \"\",\n res: Record<string, any> = {},\n): Record<string, any> {\n for (let key in obj) {\n const propName = parentKey ? `${parentKey}.${key}` : key;\n if (typeof obj[key] === \"object\" && obj[key] !== null) {\n flattenObject(obj[key], propName, res);\n } else {\n res[propName] = obj[key];\n }\n }\n return res;\n}\n\nexport function printSecurityNotice(advisory: {\n advisory: string | null;\n message: string;\n severity: \"low\" | \"medium\" | \"high\" | \"none\";\n}) {\n const severityColor =\n {\n low: chalk.blue,\n medium: chalk.yellow,\n high: chalk.red,\n }[advisory.severity.toLowerCase()] || chalk.white;\n\n console.log();\n console.log(`━━━━━━━━━━━━━━━━━━ ${chalk.bold(`CopilotKit`)} ━━━━━━━━━━━━━━━━━━`);\n console.log();\n console.log(`${chalk.bold(`Severity: ${severityColor(advisory.severity.toUpperCase())}`)}`);\n console.log();\n console.log(`${chalk.bold(advisory.message)}`);\n console.log();\n console.log(`━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;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,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,kBAAc,cAAc;AAG5B,QAAI,QAAQ,IAAI,kCAAkC;AAEhD,oBAAc,WAAW,QAAQ,IAAI,gCAAgC;AAAA,IACvE;AAEA,QAAI,cAAc,KAAK,cAAc,GAAG;AACtC,YAAM,IAAI,MAAM,qCAAqC;AAAA,IACvD;AAEA,SAAK,aAAa;AAClB,SAAK,oBAAoB;AAAA,MACvB,YAAY,KAAK;AAAA,MACjB,4BAA4B,IAAI,KAAK;AAAA,IACvC,CAAC;AAAA,EACH;AACF;","names":["chalk"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/utils/json-schema.ts","../src/utils/random-id.ts","../src/constants/index.ts","../src/telemetry/telemetry-client.ts","../src/telemetry/utils.ts"],"sourcesContent":["export * from \"./types\";\nexport * from \"./utils\";\nexport * from \"./constants\";\nexport * from \"./telemetry\";\n","import { Parameter } from \"../types\";\n\nexport type JSONSchemaString = {\n type: \"string\";\n description?: string;\n enum?: string[];\n};\n\nexport type JSONSchemaNumber = {\n type: \"number\";\n description?: string;\n};\n\nexport type JSONSchemaBoolean = {\n type: \"boolean\";\n description?: string;\n};\n\nexport type JSONSchemaObject = {\n type: \"object\";\n properties?: Record<string, JSONSchema>;\n required?: string[];\n description?: string;\n};\n\nexport type JSONSchemaArray = {\n type: \"array\";\n items: JSONSchema;\n description?: string;\n};\n\nexport type JSONSchema =\n | JSONSchemaString\n | JSONSchemaNumber\n | JSONSchemaBoolean\n | JSONSchemaObject\n | JSONSchemaArray;\n\nexport function actionParametersToJsonSchema(actionParameters: Parameter[]): JSONSchema {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let parameter of actionParameters || []) {\n parameters[parameter.name] = convertAttribute(parameter);\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of actionParameters || []) {\n if (arg.required !== false) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n return {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n };\n}\n\nfunction convertAttribute(attribute: Parameter): JSONSchema {\n switch (attribute.type) {\n case \"string\":\n return {\n type: \"string\",\n description: attribute.description,\n ...(attribute.enum && { enum: attribute.enum }),\n };\n case \"number\":\n case \"boolean\":\n return {\n type: attribute.type,\n description: attribute.description,\n };\n case \"object\":\n case \"object[]\":\n const properties = attribute.attributes?.reduce(\n (acc, attr) => {\n acc[attr.name] = convertAttribute(attr);\n return acc;\n },\n {} as Record<string, any>,\n );\n const required = attribute.attributes\n ?.filter((attr) => attr.required !== false)\n .map((attr) => attr.name);\n if (attribute.type === \"object[]\") {\n return {\n type: \"array\",\n items: {\n type: \"object\",\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n },\n description: attribute.description,\n };\n }\n return {\n type: \"object\",\n description: attribute.description,\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n };\n default:\n // Handle arrays of primitive types and undefined attribute.type\n if (attribute.type?.endsWith(\"[]\")) {\n const itemType = attribute.type.slice(0, -2);\n return {\n type: \"array\",\n items: { type: itemType as any },\n description: attribute.description,\n };\n }\n // Fallback for undefined type or any other unexpected type\n return {\n type: \"string\",\n description: attribute.description,\n };\n }\n}\n","export function randomId() {\n return \"ck-\" + globalThis.crypto.randomUUID();\n}\n","export const COPILOT_CLOUD_API_URL = \"https://api.copilotkit.ai\";\nexport const COPILOT_CLOUD_VERSION = \"v1\";\nexport const COPILOT_CLOUD_CHAT_URL = `${COPILOT_CLOUD_API_URL}/copilotkit/${COPILOT_CLOUD_VERSION}`;\nexport const COPILOT_CLOUD_PUBLIC_API_KEY_HEADER = \"X-CopilotCloud-Public-Api-Key\";\n","import { Analytics } from \"@segment/analytics-node\";\nimport { AnalyticsEvents } from \"./events\";\nimport { flattenObject, printSecurityNotice } from \"./utils\";\nimport { randomUUID } from \"crypto\";\n\nexport class TelemetryClient {\n segment: Analytics | undefined;\n globalProperties: Record<string, any> = {};\n cloudConfiguration: { publicApiKey: string; baseUrl: string } | null = null;\n packageName: string;\n packageVersion: string;\n private telemetryDisabled: boolean = false;\n private telemetryBaseUrl: string | undefined;\n private sampleRate: number = 0.05;\n private anonymousId = `anon_${randomUUID()}`;\n\n constructor({\n packageName,\n packageVersion,\n telemetryDisabled,\n telemetryBaseUrl,\n sampleRate,\n }: {\n packageName: string;\n packageVersion: string;\n telemetryDisabled?: boolean;\n telemetryBaseUrl?: string;\n sampleRate?: number;\n }) {\n this.packageName = packageName;\n this.packageVersion = packageVersion;\n this.telemetryDisabled =\n telemetryDisabled ||\n (process.env as any).COPILOTKIT_TELEMETRY_DISABLED === \"true\" ||\n (process.env as any).COPILOTKIT_TELEMETRY_DISABLED === \"1\" ||\n (process.env as any).DO_NOT_TRACK === \"true\" ||\n (process.env as any).DO_NOT_TRACK === \"1\";\n\n if (this.telemetryDisabled) {\n return;\n }\n\n this.setSampleRate(sampleRate);\n\n this.telemetryBaseUrl =\n telemetryBaseUrl ||\n (process.env as any).COPILOTKIT_TELEMETRY_BASE_URL ||\n \"https://telemetry.copilotkit.ai\";\n\n this.segment = new Analytics({\n // eslint-disable-next-line\n writeKey: process.env.COPILOTKIT_SEGMENT_WRITE_KEY || \"n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja\",\n });\n\n this.setGlobalProperties({\n \"copilotkit.package.name\": packageName,\n \"copilotkit.package.version\": packageVersion,\n });\n }\n\n private shouldSendEvent() {\n if (!this.telemetryBaseUrl) {\n return false;\n }\n\n const randomNumber = Math.random();\n return randomNumber < this.sampleRate;\n }\n\n async capture<K extends keyof AnalyticsEvents>(event: K, properties: AnalyticsEvents[K]) {\n if (!this.shouldSendEvent() || !this.segment) {\n return;\n }\n\n const flattenedProperties = flattenObject(properties);\n const propertiesWithGlobal = {\n ...this.globalProperties,\n ...flattenedProperties,\n };\n const orderedPropertiesWithGlobal = Object.keys(propertiesWithGlobal)\n .sort()\n .reduce(\n (obj, key) => {\n obj[key] = propertiesWithGlobal[key];\n return obj;\n },\n {} as Record<string, any>,\n );\n\n this.segment.track({\n anonymousId: this.anonymousId,\n event,\n properties: { ...orderedPropertiesWithGlobal },\n });\n }\n\n async checkForUpdates() {\n const url = `${this.telemetryBaseUrl}/check-for-updates?packageName=${this.packageName}&packageVersion=${this.packageVersion}`;\n\n const response = await fetch(url);\n\n if (!response.ok) {\n return;\n }\n\n const result = await response.json();\n const { advisory, severity } = result;\n\n if (!advisory && (severity === \"low\" || severity === \"none\")) {\n return;\n }\n\n printSecurityNotice(result);\n }\n\n setGlobalProperties(properties: Record<string, any>) {\n const flattenedProperties = flattenObject(properties);\n this.globalProperties = { ...this.globalProperties, ...flattenedProperties };\n }\n\n setCloudConfiguration(properties: { publicApiKey: string; baseUrl: string }) {\n this.cloudConfiguration = properties;\n\n this.setGlobalProperties({\n cloud: {\n publicApiKey: properties.publicApiKey,\n baseUrl: properties.baseUrl,\n },\n });\n }\n\n private setSampleRate(sampleRate: number | undefined) {\n let _sampleRate: number;\n\n _sampleRate = sampleRate ?? 0.05;\n\n // eslint-disable-next-line\n if (process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE) {\n // eslint-disable-next-line\n _sampleRate = parseFloat(process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE);\n }\n\n if (_sampleRate < 0 || _sampleRate > 1) {\n throw new Error(\"Sample rate must be between 0 and 1\");\n }\n\n this.sampleRate = _sampleRate;\n this.setGlobalProperties({\n sampleRate: this.sampleRate,\n sampleRateAdjustmentFactor: 1 - this.sampleRate,\n });\n }\n}\n","import chalk from \"chalk\";\n\nexport function flattenObject(\n obj: Record<string, any>,\n parentKey = \"\",\n res: Record<string, any> = {},\n): Record<string, any> {\n for (let key in obj) {\n const propName = parentKey ? `${parentKey}.${key}` : key;\n if (typeof obj[key] === \"object\" && obj[key] !== null) {\n flattenObject(obj[key], propName, res);\n } else {\n res[propName] = obj[key];\n }\n }\n return res;\n}\n\nexport function printSecurityNotice(advisory: {\n advisory: string | null;\n message: string;\n severity: \"low\" | \"medium\" | \"high\" | \"none\";\n}) {\n const severityColor =\n {\n low: chalk.blue,\n medium: chalk.yellow,\n high: chalk.red,\n }[advisory.severity.toLowerCase()] || chalk.white;\n\n console.log();\n console.log(`━━━━━━━━━━━━━━━━━━ ${chalk.bold(`CopilotKit`)} ━━━━━━━━━━━━━━━━━━`);\n console.log();\n console.log(`${chalk.bold(`Severity: ${severityColor(advisory.severity.toUpperCase())}`)}`);\n console.log();\n console.log(`${chalk.bold(advisory.message)}`);\n console.log();\n console.log(`━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACsCO,SAAS,6BAA6B,kBAA2C;AAEtF,MAAI,aAAqC,CAAC;AAC1C,WAAS,aAAa,oBAAoB,CAAC,GAAG;AAC5C,eAAW,UAAU,IAAI,IAAI,iBAAiB,SAAS;AAAA,EACzD;AAEA,MAAI,yBAAmC,CAAC;AACxC,WAAS,OAAO,oBAAoB,CAAC,GAAG;AACtC,QAAI,IAAI,aAAa,OAAO;AAC1B,6BAAuB,KAAK,IAAI,IAAI;AAAA,IACtC;AAAA,EACF;AAGA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,UAAU;AAAA,EACZ;AACF;AAEA,SAAS,iBAAiB,WAAkC;AA5D5D;AA6DE,UAAQ,UAAU,MAAM;AAAA,IACtB,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,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;AACnD,UAAM,sBAAsB,cAAc,UAAU;AACpD,SAAK,mBAAmB,EAAE,GAAG,KAAK,kBAAkB,GAAG,oBAAoB;AAAA,EAC7E;AAAA,EAEA,sBAAsB,YAAuD;AAC3E,SAAK,qBAAqB;AAE1B,SAAK,oBAAoB;AAAA,MACvB,OAAO;AAAA,QACL,cAAc,WAAW;AAAA,QACzB,SAAS,WAAW;AAAA,MACtB;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEQ,cAAc,YAAgC;AACpD,QAAI;AAEJ,kBAAc,cAAc;AAG5B,QAAI,QAAQ,IAAI,kCAAkC;AAEhD,oBAAc,WAAW,QAAQ,IAAI,gCAAgC;AAAA,IACvE;AAEA,QAAI,cAAc,KAAK,cAAc,GAAG;AACtC,YAAM,IAAI,MAAM,qCAAqC;AAAA,IACvD;AAEA,SAAK,aAAa;AAClB,SAAK,oBAAoB;AAAA,MACvB,YAAY,KAAK;AAAA,MACjB,4BAA4B,IAAI,KAAK;AAAA,IACvC,CAAC;AAAA,EACH;AACF;","names":["chalk"]}
package/dist/index.mjs CHANGED
@@ -1,10 +1,13 @@
1
1
  import "./chunk-DE5K76I2.mjs";
2
2
  import "./chunk-MSUB6DGR.mjs";
3
3
  import "./chunk-IAFBVORQ.mjs";
4
- import "./chunk-YJLRG5U3.mjs";
4
+ import "./chunk-CYDWEPFL.mjs";
5
5
  import {
6
6
  actionParametersToJsonSchema
7
7
  } from "./chunk-CIPF7PMC.mjs";
8
+ import {
9
+ randomId
10
+ } from "./chunk-6P6F44JQ.mjs";
8
11
  import {
9
12
  COPILOT_CLOUD_API_URL,
10
13
  COPILOT_CLOUD_CHAT_URL,
@@ -23,6 +26,7 @@ export {
23
26
  COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,
24
27
  COPILOT_CLOUD_VERSION,
25
28
  TelemetryClient,
26
- actionParametersToJsonSchema
29
+ actionParametersToJsonSchema,
30
+ randomId
27
31
  };
28
32
  //# sourceMappingURL=index.mjs.map
@@ -1,2 +1,3 @@
1
1
  export { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema } from './json-schema.js';
2
+ export { randomId } from './random-id.js';
2
3
  import '../types/action.js';
@@ -20,7 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/utils/index.ts
21
21
  var utils_exports = {};
22
22
  __export(utils_exports, {
23
- actionParametersToJsonSchema: () => actionParametersToJsonSchema
23
+ actionParametersToJsonSchema: () => actionParametersToJsonSchema,
24
+ randomId: () => randomId
24
25
  });
25
26
  module.exports = __toCommonJS(utils_exports);
26
27
 
@@ -99,8 +100,14 @@ function convertAttribute(attribute) {
99
100
  };
100
101
  }
101
102
  }
103
+
104
+ // src/utils/random-id.ts
105
+ function randomId() {
106
+ return "ck-" + globalThis.crypto.randomUUID();
107
+ }
102
108
  // Annotate the CommonJS export names for ESM import in node:
103
109
  0 && (module.exports = {
104
- actionParametersToJsonSchema
110
+ actionParametersToJsonSchema,
111
+ randomId
105
112
  });
106
113
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/index.ts","../../src/utils/json-schema.ts"],"sourcesContent":["export * from \"./json-schema\";\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"],"mappings":";;;;;;;;;;;;;;;;;;;;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,yBA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AAV,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;","names":[]}
1
+ {"version":3,"sources":["../../src/utils/index.ts","../../src/utils/json-schema.ts","../../src/utils/random-id.ts"],"sourcesContent":["export * from \"./json-schema\";\nexport * from \"./random-id\";\n","import { Parameter } from \"../types\";\n\nexport type JSONSchemaString = {\n type: \"string\";\n description?: string;\n enum?: string[];\n};\n\nexport type JSONSchemaNumber = {\n type: \"number\";\n description?: string;\n};\n\nexport type JSONSchemaBoolean = {\n type: \"boolean\";\n description?: string;\n};\n\nexport type JSONSchemaObject = {\n type: \"object\";\n properties?: Record<string, JSONSchema>;\n required?: string[];\n description?: string;\n};\n\nexport type JSONSchemaArray = {\n type: \"array\";\n items: JSONSchema;\n description?: string;\n};\n\nexport type JSONSchema =\n | JSONSchemaString\n | JSONSchemaNumber\n | JSONSchemaBoolean\n | JSONSchemaObject\n | JSONSchemaArray;\n\nexport function actionParametersToJsonSchema(actionParameters: Parameter[]): JSONSchema {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let parameter of actionParameters || []) {\n parameters[parameter.name] = convertAttribute(parameter);\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of actionParameters || []) {\n if (arg.required !== false) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n return {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n };\n}\n\nfunction convertAttribute(attribute: Parameter): JSONSchema {\n switch (attribute.type) {\n case \"string\":\n return {\n type: \"string\",\n description: attribute.description,\n ...(attribute.enum && { enum: attribute.enum }),\n };\n case \"number\":\n case \"boolean\":\n return {\n type: attribute.type,\n description: attribute.description,\n };\n case \"object\":\n case \"object[]\":\n const properties = attribute.attributes?.reduce(\n (acc, attr) => {\n acc[attr.name] = convertAttribute(attr);\n return acc;\n },\n {} as Record<string, any>,\n );\n const required = attribute.attributes\n ?.filter((attr) => attr.required !== false)\n .map((attr) => attr.name);\n if (attribute.type === \"object[]\") {\n return {\n type: \"array\",\n items: {\n type: \"object\",\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n },\n description: attribute.description,\n };\n }\n return {\n type: \"object\",\n description: attribute.description,\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n };\n default:\n // Handle arrays of primitive types and undefined attribute.type\n if (attribute.type?.endsWith(\"[]\")) {\n const itemType = attribute.type.slice(0, -2);\n return {\n type: \"array\",\n items: { type: itemType as any },\n description: attribute.description,\n };\n }\n // Fallback for undefined type or any other unexpected type\n return {\n type: \"string\",\n description: attribute.description,\n };\n }\n}\n","export function randomId() {\n return \"ck-\" + globalThis.crypto.randomUUID();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;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;A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,8 +1,12 @@
1
- import "../chunk-YJLRG5U3.mjs";
1
+ import "../chunk-CYDWEPFL.mjs";
2
2
  import {
3
3
  actionParametersToJsonSchema
4
4
  } from "../chunk-CIPF7PMC.mjs";
5
+ import {
6
+ randomId
7
+ } from "../chunk-6P6F44JQ.mjs";
5
8
  export {
6
- actionParametersToJsonSchema
9
+ actionParametersToJsonSchema,
10
+ randomId
7
11
  };
8
12
  //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,3 @@
1
+ declare function randomId(): string;
2
+
3
+ export { randomId };
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/utils/random-id.ts
21
+ var random_id_exports = {};
22
+ __export(random_id_exports, {
23
+ randomId: () => randomId
24
+ });
25
+ module.exports = __toCommonJS(random_id_exports);
26
+ function randomId() {
27
+ return "ck-" + globalThis.crypto.randomUUID();
28
+ }
29
+ // Annotate the CommonJS export names for ESM import in node:
30
+ 0 && (module.exports = {
31
+ randomId
32
+ });
33
+ //# sourceMappingURL=random-id.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/random-id.ts"],"sourcesContent":["export function randomId() {\n return \"ck-\" + globalThis.crypto.randomUUID();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,SAAS,WAAW;AACzB,SAAO,QAAQ,WAAW,OAAO,WAAW;AAC9C;","names":[]}
@@ -0,0 +1,7 @@
1
+ import {
2
+ randomId
3
+ } from "../chunk-6P6F44JQ.mjs";
4
+ export {
5
+ randomId
6
+ };
7
+ //# sourceMappingURL=random-id.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "publishConfig": {
10
10
  "access": "public"
11
11
  },
12
- "version": "1.0.3",
12
+ "version": "1.0.4",
13
13
  "sideEffects": false,
14
14
  "main": "./dist/index.js",
15
15
  "module": "./dist/index.mjs",
@@ -29,8 +29,8 @@
29
29
  "ts-jest": "^29.1.1",
30
30
  "tsup": "^6.7.0",
31
31
  "typescript": "^5.2.3",
32
- "eslint-config-custom": "1.0.0",
33
- "tsconfig": "1.0.0"
32
+ "eslint-config-custom": "1.0.1",
33
+ "tsconfig": "1.0.1"
34
34
  },
35
35
  "dependencies": {
36
36
  "@segment/analytics-node": "^2.1.2",
@@ -1 +1,2 @@
1
1
  export * from "./json-schema";
2
+ export * from "./random-id";
@@ -0,0 +1,3 @@
1
+ export function randomId() {
2
+ return "ck-" + globalThis.crypto.randomUUID();
3
+ }
@@ -1 +0,0 @@
1
- //# sourceMappingURL=chunk-YJLRG5U3.mjs.map