@copilotkit/shared 1.0.0-beta.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +47 -61
- package/CHANGELOG.md +31 -0
- package/dist/{chunk-3VA36BKL.mjs → chunk-2WEXXBTK.mjs} +1 -4
- package/dist/chunk-2WEXXBTK.mjs.map +1 -0
- package/dist/{chunk-2VLE6D3W.mjs → chunk-3AJ2GKWG.mjs} +2 -2
- package/dist/chunk-3AJ2GKWG.mjs.map +1 -0
- package/dist/chunk-DE5K76I2.mjs +1 -0
- package/dist/chunk-YJLRG5U3.mjs +1 -0
- package/dist/constants/index.d.ts +1 -1
- package/dist/constants/index.js +1 -1
- package/dist/constants/index.js.map +1 -1
- package/dist/constants/index.mjs +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +6 -172
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -14
- package/dist/telemetry/index.js +0 -3
- package/dist/telemetry/index.js.map +1 -1
- package/dist/telemetry/index.mjs +1 -1
- package/dist/telemetry/telemetry-client.js +0 -3
- package/dist/telemetry/telemetry-client.js.map +1 -1
- package/dist/telemetry/telemetry-client.mjs +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs +1 -2
- package/dist/utils/index.d.ts +0 -3
- package/dist/utils/index.js +5 -168
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +2 -10
- package/package.json +3 -3
- package/src/constants/index.ts +1 -1
- package/src/telemetry/telemetry-client.ts +0 -5
- package/src/types/index.ts +0 -1
- package/src/utils/index.ts +0 -1
- package/dist/chunk-2VLE6D3W.mjs.map +0 -1
- package/dist/chunk-3VA36BKL.mjs.map +0 -1
- package/dist/chunk-BANDZXMP.mjs +0 -1
- package/dist/chunk-CYDWEPFL.mjs +0 -1
- package/dist/chunk-S4HGLK2E.mjs +0 -163
- package/dist/chunk-S4HGLK2E.mjs.map +0 -1
- package/dist/chunk-YBHX4Y25.mjs +0 -1
- package/dist/chunk-YBHX4Y25.mjs.map +0 -1
- package/dist/types/annotated-function.d.ts +0 -24
- package/dist/types/annotated-function.js +0 -19
- package/dist/types/annotated-function.js.map +0 -1
- package/dist/types/annotated-function.mjs +0 -2
- package/dist/types/annotated-function.mjs.map +0 -1
- package/dist/utils/annotated-function.d.ts +0 -9
- package/dist/utils/annotated-function.js +0 -189
- package/dist/utils/annotated-function.js.map +0 -1
- package/dist/utils/annotated-function.mjs +0 -11
- package/dist/utils/annotated-function.mjs.map +0 -1
- package/src/types/annotated-function.ts +0 -27
- package/src/utils/annotated-function.ts +0 -179
- /package/dist/{chunk-BANDZXMP.mjs.map → chunk-DE5K76I2.mjs.map} +0 -0
- /package/dist/{chunk-CYDWEPFL.mjs.map → chunk-YJLRG5U3.mjs.map} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import "./chunk-
|
|
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-
|
|
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-
|
|
13
|
+
} from "./chunk-3AJ2GKWG.mjs";
|
|
20
14
|
import "./chunk-P7STFMPO.mjs";
|
|
21
15
|
import {
|
|
22
16
|
TelemetryClient
|
|
23
|
-
} from "./chunk-
|
|
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
|
package/dist/telemetry/index.js
CHANGED
|
@@ -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) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/telemetry/index.ts","../../src/telemetry/telemetry-client.ts","../../src/telemetry/utils.ts"],"sourcesContent":["export * from \"./telemetry-client\";\n","import { 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
|
|
1
|
+
{"version":3,"sources":["../../src/telemetry/index.ts","../../src/telemetry/telemetry-client.ts","../../src/telemetry/utils.ts"],"sourcesContent":["export * from \"./telemetry-client\";\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;;;ACAA,0BAAwB;;;ACAxB,mBAAkB;AAEX,SAAS,cACd,KACA,YAAY,IACZ,MAA2B,CAAC,GACP;AACrB,WAAS,OAAO,KAAK;AACnB,UAAM,WAAW,YAAY,GAAG,aAAa,QAAQ;AACrD,QAAI,OAAO,IAAI,GAAG,MAAM,YAAY,IAAI,GAAG,MAAM,MAAM;AACrD,oBAAc,IAAI,GAAG,GAAG,UAAU,GAAG;AAAA,IACvC,OAAO;AACL,UAAI,QAAQ,IAAI,IAAI,GAAG;AAAA,IACzB;AAAA,EACF;AACA,SAAO;AACT;AAEO,SAAS,oBAAoB,UAIjC;AACD,QAAM,gBACJ;AAAA,IACE,KAAK,aAAAA,QAAM;AAAA,IACX,QAAQ,aAAAA,QAAM;AAAA,IACd,MAAM,aAAAA,QAAM;AAAA,EACd,EAAE,SAAS,SAAS,YAAY,CAAC,KAAK,aAAAA,QAAM;AAE9C,UAAQ,IAAI;AACZ,UAAQ,IAAI,gHAAsB,aAAAA,QAAM,KAAK,YAAY,gHAAsB;AAC/E,UAAQ,IAAI;AACZ,UAAQ,IAAI,GAAG,aAAAA,QAAM,KAAK,aAAa,cAAc,SAAS,SAAS,YAAY,CAAC,GAAG,GAAG;AAC1F,UAAQ,IAAI;AACZ,UAAQ,IAAI,GAAG,aAAAA,QAAM,KAAK,SAAS,OAAO,GAAG;AAC7C,UAAQ,IAAI;AACZ,UAAQ,IAAI,kSAAkD;AAChE;;;ADnCA,oBAA2B;AAEpB,IAAM,kBAAN,MAA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names":["chalk"]}
|
package/dist/telemetry/index.mjs
CHANGED
|
@@ -94,9 +94,6 @@ var TelemetryClient = class {
|
|
|
94
94
|
"copilotkit.package.name": packageName,
|
|
95
95
|
"copilotkit.package.version": packageVersion
|
|
96
96
|
});
|
|
97
|
-
if (typeof globalThis.navigator !== "undefined") {
|
|
98
|
-
globalThis.navigator = {};
|
|
99
|
-
}
|
|
100
97
|
}
|
|
101
98
|
shouldSendEvent() {
|
|
102
99
|
if (!this.telemetryBaseUrl) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/telemetry/telemetry-client.ts","../../src/telemetry/utils.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
|
|
1
|
+
{"version":3,"sources":["../../src/telemetry/telemetry-client.ts","../../src/telemetry/utils.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","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,0BAAwB;;;ACAxB,mBAAkB;AAEX,SAAS,cACd,KACA,YAAY,IACZ,MAA2B,CAAC,GACP;AACrB,WAAS,OAAO,KAAK;AACnB,UAAM,WAAW,YAAY,GAAG,aAAa,QAAQ;AACrD,QAAI,OAAO,IAAI,GAAG,MAAM,YAAY,IAAI,GAAG,MAAM,MAAM;AACrD,oBAAc,IAAI,GAAG,GAAG,UAAU,GAAG;AAAA,IACvC,OAAO;AACL,UAAI,QAAQ,IAAI,IAAI,GAAG;AAAA,IACzB;AAAA,EAC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B,EAAE,GAAG,KAAK,kBAAkB,GAAG,oBAAoB;AAAA,EAC7E;AAAA,EAEA,sBAAsB,YAAuD;AAC3E,SAAK,qBAAqB;AAE1B,SAAK,oBAAoB;AAAA,MACvB,OAAO;AAAA,QACL,cAAc,WAAW;AAAA,QACzB,SAAS,WAAW;AAAA,MACtB;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEQ,cAAc,YAAgC;AACpD,QAAI;AAEJ,kBAAc,cAAc;AAE5B,QAAI,QAAQ,IAAI,kCAAkC;AAChD,oBAAc,WAAW,QAAQ,IAAI,gCAAgC;AAAA,IACvE;AAEA,QAAI,cAAc,KAAK,cAAc,GAAG;AACtC,YAAM,IAAI,MAAM,qCAAqC;AAAA,IACvD;AAEA,SAAK,aAAa;AAClB,SAAK,oBAAoB;AAAA,MACvB,YAAY,KAAK;AAAA,MACjB,4BAA4B,IAAI,KAAK;AAAA,IACvC,CAAC;AAAA,EACH;AACF;","names":["chalk"]}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export { AssistantMessage, FunctionCallHandler, FunctionCallHandlerArguments, FunctionDefinition, JSONValue, ToolDefinition } from './openai-assistant.js';
|
|
2
|
-
export { AnnotatedFunction, AnnotatedFunctionArgument, AnnotatedFunctionArrayArgument, AnnotatedFunctionSimpleArgument } from './annotated-function.js';
|
|
3
2
|
export { Action, MappedParameterTypes, Parameter } from './action.js';
|
|
4
3
|
export { CopilotCloudConfig } from './copilot-cloud-config.js';
|
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/index.ts"],"sourcesContent":["export * from \"./openai-assistant\";\nexport * from \"./
|
|
1
|
+
{"version":3,"sources":["../../src/types/index.ts"],"sourcesContent":["export * from \"./openai-assistant\";\nexport * from \"./action\";\nexport * from \"./copilot-cloud-config\";\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
package/dist/types/index.mjs
CHANGED
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
export { actionToChatCompletionFunction, annotatedFunctionToAction, annotatedFunctionToChatCompletionFunction } from './annotated-function.js';
|
|
2
1
|
export { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema } from './json-schema.js';
|
|
3
|
-
import '../types/openai-assistant.js';
|
|
4
|
-
import '../types/annotated-function.js';
|
|
5
2
|
import '../types/action.js';
|
package/dist/utils/index.js
CHANGED
|
@@ -20,175 +20,15 @@ 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
|
|
24
|
-
actionToChatCompletionFunction: () => actionToChatCompletionFunction,
|
|
25
|
-
annotatedFunctionToAction: () => annotatedFunctionToAction,
|
|
26
|
-
annotatedFunctionToChatCompletionFunction: () => annotatedFunctionToChatCompletionFunction
|
|
23
|
+
actionParametersToJsonSchema: () => actionParametersToJsonSchema
|
|
27
24
|
});
|
|
28
25
|
module.exports = __toCommonJS(utils_exports);
|
|
29
26
|
|
|
30
|
-
// src/utils/annotated-function.ts
|
|
31
|
-
function annotatedFunctionToChatCompletionFunction(annotatedFunction) {
|
|
32
|
-
let parameters = {};
|
|
33
|
-
for (let arg of annotatedFunction.argumentAnnotations) {
|
|
34
|
-
let { name, required, ...forwardedArgs } = arg;
|
|
35
|
-
parameters[arg.name] = forwardedArgs;
|
|
36
|
-
}
|
|
37
|
-
let requiredParameterNames = [];
|
|
38
|
-
for (let arg of annotatedFunction.argumentAnnotations) {
|
|
39
|
-
if (arg.required) {
|
|
40
|
-
requiredParameterNames.push(arg.name);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
let chatCompletionFunction = {
|
|
44
|
-
type: "function",
|
|
45
|
-
function: {
|
|
46
|
-
name: annotatedFunction.name,
|
|
47
|
-
description: annotatedFunction.description,
|
|
48
|
-
parameters: {
|
|
49
|
-
type: "object",
|
|
50
|
-
properties: parameters,
|
|
51
|
-
required: requiredParameterNames
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
return chatCompletionFunction;
|
|
56
|
-
}
|
|
57
|
-
function convertAttribute(attribute) {
|
|
58
|
-
var _a, _b, _c;
|
|
59
|
-
switch (attribute.type) {
|
|
60
|
-
case "string":
|
|
61
|
-
return {
|
|
62
|
-
type: "string",
|
|
63
|
-
description: attribute.description,
|
|
64
|
-
...attribute.enum && { enum: attribute.enum }
|
|
65
|
-
};
|
|
66
|
-
case "number":
|
|
67
|
-
case "boolean":
|
|
68
|
-
return {
|
|
69
|
-
type: attribute.type,
|
|
70
|
-
description: attribute.description
|
|
71
|
-
};
|
|
72
|
-
case "object":
|
|
73
|
-
case "object[]":
|
|
74
|
-
const properties = (_a = attribute.attributes) == null ? void 0 : _a.reduce(
|
|
75
|
-
(acc, attr) => {
|
|
76
|
-
acc[attr.name] = convertAttribute(attr);
|
|
77
|
-
return acc;
|
|
78
|
-
},
|
|
79
|
-
{}
|
|
80
|
-
);
|
|
81
|
-
const required = (_b = attribute.attributes) == null ? void 0 : _b.filter((attr) => attr.required !== false).map((attr) => attr.name);
|
|
82
|
-
if (attribute.type === "object[]") {
|
|
83
|
-
return {
|
|
84
|
-
type: "array",
|
|
85
|
-
items: {
|
|
86
|
-
type: "object",
|
|
87
|
-
...properties && { properties },
|
|
88
|
-
...required && required.length > 0 && { required }
|
|
89
|
-
},
|
|
90
|
-
description: attribute.description
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
return {
|
|
94
|
-
type: "object",
|
|
95
|
-
description: attribute.description,
|
|
96
|
-
...properties && { properties },
|
|
97
|
-
...required && required.length > 0 && { required }
|
|
98
|
-
};
|
|
99
|
-
default:
|
|
100
|
-
if ((_c = attribute.type) == null ? void 0 : _c.endsWith("[]")) {
|
|
101
|
-
const itemType = attribute.type.slice(0, -2);
|
|
102
|
-
return {
|
|
103
|
-
type: "array",
|
|
104
|
-
items: { type: itemType },
|
|
105
|
-
description: attribute.description
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
return {
|
|
109
|
-
type: "string",
|
|
110
|
-
description: attribute.description
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
function actionToChatCompletionFunction(action) {
|
|
115
|
-
let parameters = {};
|
|
116
|
-
for (let parameter of action.parameters || []) {
|
|
117
|
-
parameters[parameter.name] = convertAttribute(parameter);
|
|
118
|
-
}
|
|
119
|
-
let requiredParameterNames = [];
|
|
120
|
-
for (let arg of action.parameters || []) {
|
|
121
|
-
if (arg.required !== false) {
|
|
122
|
-
requiredParameterNames.push(arg.name);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
let chatCompletionFunction = {
|
|
126
|
-
type: "function",
|
|
127
|
-
function: {
|
|
128
|
-
name: action.name,
|
|
129
|
-
...action.description && { description: action.description },
|
|
130
|
-
parameters: {
|
|
131
|
-
type: "object",
|
|
132
|
-
properties: parameters,
|
|
133
|
-
required: requiredParameterNames
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
return chatCompletionFunction;
|
|
138
|
-
}
|
|
139
|
-
function annotatedFunctionToAction(annotatedFunction) {
|
|
140
|
-
const parameters = annotatedFunction.argumentAnnotations.map((annotation) => {
|
|
141
|
-
switch (annotation.type) {
|
|
142
|
-
case "string":
|
|
143
|
-
case "number":
|
|
144
|
-
case "boolean":
|
|
145
|
-
case "object":
|
|
146
|
-
return {
|
|
147
|
-
name: annotation.name,
|
|
148
|
-
description: annotation.description,
|
|
149
|
-
type: annotation.type,
|
|
150
|
-
required: annotation.required
|
|
151
|
-
};
|
|
152
|
-
case "array":
|
|
153
|
-
let type;
|
|
154
|
-
if (annotation.items.type === "string") {
|
|
155
|
-
type = "string[]";
|
|
156
|
-
} else if (annotation.items.type === "number") {
|
|
157
|
-
type = "number[]";
|
|
158
|
-
} else if (annotation.items.type === "boolean") {
|
|
159
|
-
type = "boolean[]";
|
|
160
|
-
} else if (annotation.items.type === "object") {
|
|
161
|
-
type = "object[]";
|
|
162
|
-
} else {
|
|
163
|
-
type = "string[]";
|
|
164
|
-
}
|
|
165
|
-
return {
|
|
166
|
-
name: annotation.name,
|
|
167
|
-
description: annotation.description,
|
|
168
|
-
type,
|
|
169
|
-
required: annotation.required
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
return {
|
|
174
|
-
name: annotatedFunction.name,
|
|
175
|
-
description: annotatedFunction.description,
|
|
176
|
-
parameters,
|
|
177
|
-
handler: (args) => {
|
|
178
|
-
const paramsInCorrectOrder = [];
|
|
179
|
-
for (let arg of annotatedFunction.argumentAnnotations) {
|
|
180
|
-
paramsInCorrectOrder.push(args[arg.name]);
|
|
181
|
-
}
|
|
182
|
-
return annotatedFunction.implementation(...paramsInCorrectOrder);
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
|
|
187
27
|
// src/utils/json-schema.ts
|
|
188
28
|
function actionParametersToJsonSchema(actionParameters) {
|
|
189
29
|
let parameters = {};
|
|
190
30
|
for (let parameter of actionParameters || []) {
|
|
191
|
-
parameters[parameter.name] =
|
|
31
|
+
parameters[parameter.name] = convertAttribute(parameter);
|
|
192
32
|
}
|
|
193
33
|
let requiredParameterNames = [];
|
|
194
34
|
for (let arg of actionParameters || []) {
|
|
@@ -202,7 +42,7 @@ function actionParametersToJsonSchema(actionParameters) {
|
|
|
202
42
|
required: requiredParameterNames
|
|
203
43
|
};
|
|
204
44
|
}
|
|
205
|
-
function
|
|
45
|
+
function convertAttribute(attribute) {
|
|
206
46
|
var _a, _b, _c;
|
|
207
47
|
switch (attribute.type) {
|
|
208
48
|
case "string":
|
|
@@ -221,7 +61,7 @@ function convertAttribute2(attribute) {
|
|
|
221
61
|
case "object[]":
|
|
222
62
|
const properties = (_a = attribute.attributes) == null ? void 0 : _a.reduce(
|
|
223
63
|
(acc, attr) => {
|
|
224
|
-
acc[attr.name] =
|
|
64
|
+
acc[attr.name] = convertAttribute(attr);
|
|
225
65
|
return acc;
|
|
226
66
|
},
|
|
227
67
|
{}
|
|
@@ -261,9 +101,6 @@ function convertAttribute2(attribute) {
|
|
|
261
101
|
}
|
|
262
102
|
// Annotate the CommonJS export names for ESM import in node:
|
|
263
103
|
0 && (module.exports = {
|
|
264
|
-
actionParametersToJsonSchema
|
|
265
|
-
actionToChatCompletionFunction,
|
|
266
|
-
annotatedFunctionToAction,
|
|
267
|
-
annotatedFunctionToChatCompletionFunction
|
|
104
|
+
actionParametersToJsonSchema
|
|
268
105
|
});
|
|
269
106
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/index.ts","../../src/utils/annotated-function.ts","../../src/utils/json-schema.ts"],"sourcesContent":["export * from \"./annotated-function\";\nexport * from \"./json-schema\";\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,SAAS,0CACd,mBACgB;AAEhB,MAAI,aAAqC,CAAC;AAC1C,WAAS,OAAO,kBAAkB,qBAAqB;AAErD,QAAI,EAAE,MAAM,UAAU,GAAG,cAAc,IAAI;AAC3C,eAAW,IAAI,IAAI,IAAI;AAAA,EACzB;AAEA,MAAI,yBAAmC,CAAC;AACxC,WAAS,OAAO,kBAAkB,qBAAqB;AACrD,QAAI,IAAI,UAAU;AAChB,6BAAuB,KAAK,IAAI,IAAI;AAAA,IACtC;AAAA,EACF;AAGA,MAAI,yBAAyC;AAAA,IAC3C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AA,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,IAAIA,kBAAiB,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,YACL,MAAM;AAAA,YACN,GAAI,cAAc,EAAE,WAAW;AAAA,YAC/B,GAAI,YAAY,SAAS,SAAS,KAAK,EAAE,SAAS;AAAA,UACpD;AAAA,UACA,aAAa,UAAU;AAAA,QACzB;AAAA,MACF;AACA,aAAO;AAAA,QACL,MAAM;AAAA,QACN,aAAa,UAAU;AAAA,QACvB,GAAI,cAAc,EAAE,WAAW;AAAA,QAC/B,GAAI,YAAY,SAAS,SAAS,KAAK,EAAE,SAAS;AAAA,MACpD;AAAA,IACF;AAEE,WAAI,eAAU,SAAV,mBAAgB,SAAS,OAAO;AAClC,cAAM,WAAW,UAAU,KAAK,MAAM,GAAG,EAAE;AAC3C,eAAO;AAAA,UACL,MAAM;AAAA,UACN,OAAO,EAAE,MAAM,SAAgB;AAAA,UAC/B,aAAa,UAAU;AAAA,QACzB;AAAA,MACF;AAEA,aAAO;AAAA,QACL,MAAM;AAAA,QACN,aAAa,UAAU;AAAA,MACzB;AAAA,EACJ;AACF;","names":["convertAttribute"]}
|
|
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,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,YACL,MAAM;AAAA,YACN,GAAI,cAAc,EAAE,WAAW;AAAA,YAC/B,GAAI,YAAY,SAAS,SAAS,KAAK,EAAE,SAAS;AAAA,UACpD;AAAA,UACA,aAAa,UAAU;AAAA,QACzB;AAAA,MACF;AACA,aAAO;AAAA,QACL,MAAM;AAAA,QACN,aAAa,UAAU;AAAA,QACvB,GAAI,cAAc,EAAE,WAAW;AAAA,QAC/B,GAAI,YAAY,SAAS,SAAS,KAAK,EAAE,SAAS;AAAA,MACpD;AAAA,IACF;AAEE,WAAI,eAAU,SAAV,mBAAgB,SAAS,OAAO;AAClC,cAAM,WAAW,UAAU,KAAK,MAAM,GAAG,EAAE;AAC3C,eAAO;AAAA,UACL,MAAM;AAAA,UACN,OAAO,EAAE,MAAM,SAAgB;AAAA,UAC/B,aAAa,UAAU;AAAA,QACzB;AAAA,MACF;AAEA,aAAO;AAAA,QACL,MAAM;AAAA,QACN,aAAa,UAAU;AAAA,MACzB;AAAA,EACJ;AACF;","names":[]}
|
package/dist/utils/index.mjs
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
import "../chunk-
|
|
2
|
-
import {
|
|
3
|
-
actionToChatCompletionFunction,
|
|
4
|
-
annotatedFunctionToAction,
|
|
5
|
-
annotatedFunctionToChatCompletionFunction
|
|
6
|
-
} from "../chunk-S4HGLK2E.mjs";
|
|
1
|
+
import "../chunk-YJLRG5U3.mjs";
|
|
7
2
|
import {
|
|
8
3
|
actionParametersToJsonSchema
|
|
9
4
|
} from "../chunk-CIPF7PMC.mjs";
|
|
10
5
|
export {
|
|
11
|
-
actionParametersToJsonSchema
|
|
12
|
-
actionToChatCompletionFunction,
|
|
13
|
-
annotatedFunctionToAction,
|
|
14
|
-
annotatedFunctionToChatCompletionFunction
|
|
6
|
+
actionParametersToJsonSchema
|
|
15
7
|
};
|
|
16
8
|
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.0.0
|
|
7
|
+
"version": "1.0.0",
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"main": "./dist/index.js",
|
|
10
10
|
"module": "./dist/index.mjs",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"ts-jest": "^29.1.1",
|
|
25
25
|
"tsup": "^6.7.0",
|
|
26
26
|
"typescript": "^5.2.3",
|
|
27
|
-
"eslint-config-custom": "1.0.0
|
|
28
|
-
"tsconfig": "1.0.0
|
|
27
|
+
"eslint-config-custom": "1.0.0",
|
|
28
|
+
"tsconfig": "1.0.0"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"chalk": "4.1.2",
|
package/src/constants/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export const COPILOT_CLOUD_API_URL = "https://api.copilotkit.ai";
|
|
2
2
|
export const COPILOT_CLOUD_VERSION = "v1";
|
|
3
|
-
export const COPILOT_CLOUD_CHAT_URL = `${COPILOT_CLOUD_API_URL}/${COPILOT_CLOUD_VERSION}
|
|
3
|
+
export const COPILOT_CLOUD_CHAT_URL = `${COPILOT_CLOUD_API_URL}/copilotkit/${COPILOT_CLOUD_VERSION}`;
|
|
4
4
|
export const COPILOT_CLOUD_PUBLIC_API_KEY_HEADER = "X-CopilotCloud-Public-Api-Key";
|
|
@@ -56,11 +56,6 @@ export class TelemetryClient {
|
|
|
56
56
|
"copilotkit.package.name": packageName,
|
|
57
57
|
"copilotkit.package.version": packageVersion,
|
|
58
58
|
});
|
|
59
|
-
|
|
60
|
-
// Eliminates a PostHog error on Next.js
|
|
61
|
-
if (typeof (globalThis as any).navigator !== "undefined") {
|
|
62
|
-
(globalThis as any).navigator = {};
|
|
63
|
-
}
|
|
64
59
|
}
|
|
65
60
|
|
|
66
61
|
private shouldSendEvent() {
|
package/src/types/index.ts
CHANGED
package/src/utils/index.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
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":";AAAO,IAAM,wBAAwB;AAC9B,IAAM,wBAAwB;AAC9B,IAAM,yBAAyB,GAAG,yBAAyB;AAC3D,IAAM,sCAAsC;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/telemetry/telemetry-client.ts"],"sourcesContent":["import { PostHog } from \"posthog-node\";\nimport { AnalyticsEvents } from \"./events\";\nimport { flattenObject, printSecurityNotice } from \"./utils\";\nimport { randomUUID } from \"crypto\";\n\nexport class TelemetryClient {\n posthog: PostHog | undefined;\n globalProperties: Record<string, any> = {};\n cloudConfiguration: { publicApiKey: string; baseUrl: string } | null = null;\n packageName: string;\n packageVersion: string;\n private telemetryDisabled: boolean = false;\n private telemetryBaseUrl: string | undefined;\n private sampleRate: number = 0.05;\n\n constructor({\n packageName,\n packageVersion,\n telemetryDisabled,\n telemetryBaseUrl,\n posthogToken,\n sampleRate,\n }: {\n packageName: string;\n packageVersion: string;\n telemetryDisabled?: boolean;\n telemetryBaseUrl?: string;\n posthogToken?: string;\n sampleRate?: number;\n }) {\n this.packageName = packageName;\n this.packageVersion = packageVersion;\n this.telemetryDisabled =\n telemetryDisabled ||\n (process.env as any).COPILOTKIT_TELEMETRY_DISABLED === \"true\" ||\n (process.env as any).COPILOTKIT_TELEMETRY_DISABLED === \"1\" ||\n (process.env as any).DO_NOT_TRACK === \"true\" ||\n (process.env as any).DO_NOT_TRACK === \"1\";\n\n if (this.telemetryDisabled) {\n return;\n }\n\n this.setSampleRate(sampleRate);\n\n this.telemetryBaseUrl =\n telemetryBaseUrl ||\n (process.env as any).COPILOTKIT_TELEMETRY_BASE_URL ||\n \"https://telemetry.copilotkit.ai\";\n\n this.posthog = new PostHog(posthogToken || \"token\", {\n host: `${this.telemetryBaseUrl}/telemetry/ingest`,\n });\n\n this.setGlobalProperties({\n \"copilotkit.package.name\": packageName,\n \"copilotkit.package.version\": packageVersion,\n });\n\n // Eliminates a PostHog error on Next.js\n if (typeof (globalThis as any).navigator !== \"undefined\") {\n (globalThis as any).navigator = {};\n }\n }\n\n private shouldSendEvent() {\n if (!this.telemetryBaseUrl) {\n return false;\n }\n\n const randomNumber = Math.random();\n return randomNumber < this.sampleRate;\n }\n\n async capture<K extends keyof AnalyticsEvents>(event: K, properties: AnalyticsEvents[K]) {\n if (!this.shouldSendEvent() || !this.posthog) {\n return;\n }\n\n const flattenedProperties = flattenObject(properties);\n const propertiesWithGlobal = {\n ...this.globalProperties,\n ...flattenedProperties,\n };\n const orderedPropertiesWithGlobal = Object.keys(propertiesWithGlobal)\n .sort()\n .reduce(\n (obj, key) => {\n obj[key] = propertiesWithGlobal[key];\n return obj;\n },\n {} as Record<string, any>,\n );\n\n this.posthog.capture({\n distinctId: randomUUID(),\n event,\n properties: { ...orderedPropertiesWithGlobal },\n });\n }\n\n async checkForUpdates() {\n const url = `${this.telemetryBaseUrl}/check-for-updates?packageName=${this.packageName}&packageVersion=${this.packageVersion}`;\n\n const response = await fetch(url);\n\n if (!response.ok) {\n return;\n }\n\n const result = await response.json();\n const { advisory, severity } = result;\n\n if (!advisory && (severity === \"low\" || severity === \"none\")) {\n return;\n }\n\n printSecurityNotice(result);\n }\n\n setTelemetryBaseUrl(url: string) {\n this.telemetryBaseUrl = url;\n\n if (this.posthog) {\n this.posthog.host = `${url}/telemetry/ingest`;\n }\n }\n\n setGlobalProperties(properties: Record<string, any>) {\n const flattenedProperties = flattenObject(properties);\n this.globalProperties = { ...this.globalProperties, ...flattenedProperties };\n }\n\n setCloudConfiguration(properties: { publicApiKey: string; baseUrl: string }) {\n this.cloudConfiguration = properties;\n\n this.setGlobalProperties({\n cloud: {\n publicApiKey: properties.publicApiKey,\n baseUrl: properties.baseUrl,\n },\n });\n }\n\n private setSampleRate(sampleRate: number | undefined) {\n let _sampleRate: number;\n\n _sampleRate = sampleRate ?? 0.05;\n\n if (process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE) {\n _sampleRate = parseFloat(process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE);\n }\n\n if (_sampleRate < 0 || _sampleRate > 1) {\n throw new Error(\"Sample rate must be between 0 and 1\");\n }\n\n this.sampleRate = _sampleRate;\n this.setGlobalProperties({\n sampleRate: this.sampleRate,\n sampleRateAdjustmentFactor: 1 - this.sampleRate,\n });\n }\n}\n"],"mappings":";;;;;;AAAA,SAAS,eAAe;AAGxB,SAAS,kBAAkB;AAEpB,IAAM,kBAAN,MAAsB;AAAA,EAU3B,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAOG;AAtBH,4BAAwC,CAAC;AACzC,8BAAuE;AAGvE,SAAQ,oBAA6B;AAErC,SAAQ,aAAqB;AAiB3B,SAAK,cAAc;AACnB,SAAK,iBAAiB;AACtB,SAAK,oBACH,qBACC,QAAQ,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;AAGD,QAAI,OAAQ,WAAmB,cAAc,aAAa;AAC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