@copilotkit/shared 0.0.0-0.0.0-max-changeset-10101010101010-20260109191632
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/CHANGELOG.md +1800 -0
- package/LICENSE +21 -0
- package/README.md +141 -0
- package/dist/chunk-2OJ5OJ2D.mjs +1 -0
- package/dist/chunk-2OJ5OJ2D.mjs.map +1 -0
- package/dist/chunk-5YXKLIUO.mjs +38 -0
- package/dist/chunk-5YXKLIUO.mjs.map +1 -0
- package/dist/chunk-64DYJ27R.mjs +201 -0
- package/dist/chunk-64DYJ27R.mjs.map +1 -0
- package/dist/chunk-6QGXWNS5.mjs +34 -0
- package/dist/chunk-6QGXWNS5.mjs.map +1 -0
- package/dist/chunk-6W2UEO2M.mjs +94 -0
- package/dist/chunk-6W2UEO2M.mjs.map +1 -0
- package/dist/chunk-BOKE4OKY.mjs +41 -0
- package/dist/chunk-BOKE4OKY.mjs.map +1 -0
- package/dist/chunk-FCCOSO5L.mjs +1 -0
- package/dist/chunk-FCCOSO5L.mjs.map +1 -0
- package/dist/chunk-GYZIHHE6.mjs +13 -0
- package/dist/chunk-GYZIHHE6.mjs.map +1 -0
- package/dist/chunk-IAFBVORQ.mjs +1 -0
- package/dist/chunk-IAFBVORQ.mjs.map +1 -0
- package/dist/chunk-MSUB6DGR.mjs +1 -0
- package/dist/chunk-MSUB6DGR.mjs.map +1 -0
- package/dist/chunk-N5EP5OD5.mjs +1 -0
- package/dist/chunk-N5EP5OD5.mjs.map +1 -0
- package/dist/chunk-NAFEBKSO.mjs +1 -0
- package/dist/chunk-NAFEBKSO.mjs.map +1 -0
- package/dist/chunk-NBLG4PC5.mjs +426 -0
- package/dist/chunk-NBLG4PC5.mjs.map +1 -0
- package/dist/chunk-P7STFMPO.mjs +1 -0
- package/dist/chunk-P7STFMPO.mjs.map +1 -0
- package/dist/chunk-PL5WNHFZ.mjs +50 -0
- package/dist/chunk-PL5WNHFZ.mjs.map +1 -0
- package/dist/chunk-UYARLQNA.mjs +1 -0
- package/dist/chunk-UYARLQNA.mjs.map +1 -0
- package/dist/chunk-WUPFNPXO.mjs +107 -0
- package/dist/chunk-WUPFNPXO.mjs.map +1 -0
- package/dist/chunk-XEMZTHQZ.mjs +67 -0
- package/dist/chunk-XEMZTHQZ.mjs.map +1 -0
- package/dist/chunk-XTHC46M2.mjs +1 -0
- package/dist/chunk-XTHC46M2.mjs.map +1 -0
- package/dist/constants/index.d.ts +6 -0
- package/dist/constants/index.js +40 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/constants/index.mjs +13 -0
- package/dist/constants/index.mjs.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +1098 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +124 -0
- package/dist/index.mjs.map +1 -0
- package/dist/telemetry/events.d.ts +45 -0
- package/dist/telemetry/events.js +19 -0
- package/dist/telemetry/events.js.map +1 -0
- package/dist/telemetry/events.mjs +1 -0
- package/dist/telemetry/events.mjs.map +1 -0
- package/dist/telemetry/index.d.ts +3 -0
- package/dist/telemetry/index.js +188 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/telemetry/index.mjs +12 -0
- package/dist/telemetry/index.mjs.map +1 -0
- package/dist/telemetry/scarf-client.d.ts +7 -0
- package/dist/telemetry/scarf-client.js +59 -0
- package/dist/telemetry/scarf-client.js.map +1 -0
- package/dist/telemetry/scarf-client.mjs +7 -0
- package/dist/telemetry/scarf-client.mjs.map +1 -0
- package/dist/telemetry/security-check.d.ts +2 -0
- package/dist/telemetry/security-check.js +2 -0
- package/dist/telemetry/security-check.js.map +1 -0
- package/dist/telemetry/security-check.mjs +1 -0
- package/dist/telemetry/security-check.mjs.map +1 -0
- package/dist/telemetry/telemetry-client.d.ts +40 -0
- package/dist/telemetry/telemetry-client.js +186 -0
- package/dist/telemetry/telemetry-client.js.map +1 -0
- package/dist/telemetry/telemetry-client.mjs +11 -0
- package/dist/telemetry/telemetry-client.mjs.map +1 -0
- package/dist/telemetry/utils.d.ts +8 -0
- package/dist/telemetry/utils.js +69 -0
- package/dist/telemetry/utils.js.map +1 -0
- package/dist/telemetry/utils.mjs +9 -0
- package/dist/telemetry/utils.mjs.map +1 -0
- package/dist/types/action.d.ts +59 -0
- package/dist/types/action.js +19 -0
- package/dist/types/action.js.map +1 -0
- package/dist/types/action.mjs +2 -0
- package/dist/types/action.mjs.map +1 -0
- package/dist/types/copilot-cloud-config.d.ts +13 -0
- package/dist/types/copilot-cloud-config.js +19 -0
- package/dist/types/copilot-cloud-config.js.map +1 -0
- package/dist/types/copilot-cloud-config.mjs +2 -0
- package/dist/types/copilot-cloud-config.mjs.map +1 -0
- package/dist/types/error.d.ts +55 -0
- package/dist/types/error.js +19 -0
- package/dist/types/error.js.map +1 -0
- package/dist/types/error.mjs +2 -0
- package/dist/types/error.mjs.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.js +19 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +8 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/types/message.d.ts +26 -0
- package/dist/types/message.js +19 -0
- package/dist/types/message.js.map +1 -0
- package/dist/types/message.mjs +2 -0
- package/dist/types/message.mjs.map +1 -0
- package/dist/types/openai-assistant.d.ts +53 -0
- package/dist/types/openai-assistant.js +19 -0
- package/dist/types/openai-assistant.js.map +1 -0
- package/dist/types/openai-assistant.mjs +2 -0
- package/dist/types/openai-assistant.mjs.map +1 -0
- package/dist/types/utility.d.ts +6 -0
- package/dist/types/utility.js +19 -0
- package/dist/types/utility.js.map +1 -0
- package/dist/types/utility.mjs +2 -0
- package/dist/types/utility.mjs.map +1 -0
- package/dist/utils/conditions.d.ts +26 -0
- package/dist/utils/conditions.js +74 -0
- package/dist/utils/conditions.js.map +1 -0
- package/dist/utils/conditions.mjs +7 -0
- package/dist/utils/conditions.mjs.map +1 -0
- package/dist/utils/console-styling.d.ts +84 -0
- package/dist/utils/console-styling.js +123 -0
- package/dist/utils/console-styling.js.map +1 -0
- package/dist/utils/console-styling.mjs +17 -0
- package/dist/utils/console-styling.mjs.map +1 -0
- package/dist/utils/errors.d.ts +280 -0
- package/dist/utils/errors.js +443 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/errors.mjs +65 -0
- package/dist/utils/errors.mjs.map +1 -0
- package/dist/utils/index.d.ts +32 -0
- package/dist/utils/index.js +927 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +108 -0
- package/dist/utils/index.mjs.map +1 -0
- package/dist/utils/json-schema.d.ts +34 -0
- package/dist/utils/json-schema.js +228 -0
- package/dist/utils/json-schema.js.map +1 -0
- package/dist/utils/json-schema.mjs +13 -0
- package/dist/utils/json-schema.mjs.map +1 -0
- package/dist/utils/random-id.d.ts +6 -0
- package/dist/utils/random-id.js +68 -0
- package/dist/utils/random-id.js.map +1 -0
- package/dist/utils/random-id.mjs +13 -0
- package/dist/utils/random-id.mjs.map +1 -0
- package/dist/utils/requests.d.ts +10 -0
- package/dist/utils/requests.js +91 -0
- package/dist/utils/requests.js.map +1 -0
- package/dist/utils/requests.mjs +7 -0
- package/dist/utils/requests.mjs.map +1 -0
- package/dist/utils/types.d.ts +20 -0
- package/dist/utils/types.js +19 -0
- package/dist/utils/types.js.map +1 -0
- package/dist/utils/types.mjs +2 -0
- package/dist/utils/types.mjs.map +1 -0
- package/jest.config.js +5 -0
- package/package.json +68 -0
- package/src/constants/index.ts +4 -0
- package/src/index.ts +7 -0
- package/src/telemetry/events.ts +41 -0
- package/src/telemetry/index.ts +1 -0
- package/src/telemetry/scarf-client.ts +39 -0
- package/src/telemetry/security-check.ts +0 -0
- package/src/telemetry/telemetry-client.ts +142 -0
- package/src/telemetry/utils.ts +39 -0
- package/src/types/action.ts +129 -0
- package/src/types/copilot-cloud-config.ts +11 -0
- package/src/types/error.ts +70 -0
- package/src/types/index.ts +6 -0
- package/src/types/message.ts +37 -0
- package/src/types/openai-assistant.ts +62 -0
- package/src/types/utility.ts +2 -0
- package/src/utils/conditions.ts +98 -0
- package/src/utils/console-styling.ts +124 -0
- package/src/utils/errors.ts +525 -0
- package/src/utils/index.ts +49 -0
- package/src/utils/json-schema.test.ts +383 -0
- package/src/utils/json-schema.ts +258 -0
- package/src/utils/random-id.ts +42 -0
- package/src/utils/requests.ts +77 -0
- package/src/utils/types.ts +22 -0
- package/tsconfig.json +9 -0
- package/tsup.config.ts +11 -0
- package/typedoc.json +4 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import {
|
|
2
|
+
scarf_client_default
|
|
3
|
+
} from "./chunk-5YXKLIUO.mjs";
|
|
4
|
+
import {
|
|
5
|
+
flattenObject
|
|
6
|
+
} from "./chunk-6QGXWNS5.mjs";
|
|
7
|
+
|
|
8
|
+
// src/telemetry/telemetry-client.ts
|
|
9
|
+
import { Analytics } from "@segment/analytics-node";
|
|
10
|
+
import { v4 as uuidv4 } from "uuid";
|
|
11
|
+
function isTelemetryDisabled() {
|
|
12
|
+
return process.env.COPILOTKIT_TELEMETRY_DISABLED === "true" || process.env.COPILOTKIT_TELEMETRY_DISABLED === "1" || process.env.DO_NOT_TRACK === "true" || process.env.DO_NOT_TRACK === "1";
|
|
13
|
+
}
|
|
14
|
+
var TelemetryClient = class {
|
|
15
|
+
constructor({
|
|
16
|
+
packageName,
|
|
17
|
+
packageVersion,
|
|
18
|
+
telemetryDisabled,
|
|
19
|
+
telemetryBaseUrl,
|
|
20
|
+
sampleRate
|
|
21
|
+
}) {
|
|
22
|
+
this.globalProperties = {};
|
|
23
|
+
this.cloudConfiguration = null;
|
|
24
|
+
this.telemetryDisabled = false;
|
|
25
|
+
this.sampleRate = 0.05;
|
|
26
|
+
this.anonymousId = `anon_${uuidv4()}`;
|
|
27
|
+
this.packageName = packageName;
|
|
28
|
+
this.packageVersion = packageVersion;
|
|
29
|
+
this.telemetryDisabled = telemetryDisabled || isTelemetryDisabled();
|
|
30
|
+
if (this.telemetryDisabled) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
this.setSampleRate(sampleRate);
|
|
34
|
+
const writeKey = process.env.COPILOTKIT_SEGMENT_WRITE_KEY || "n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja";
|
|
35
|
+
this.segment = new Analytics({
|
|
36
|
+
writeKey
|
|
37
|
+
});
|
|
38
|
+
this.setGlobalProperties({
|
|
39
|
+
"copilotkit.package.name": packageName,
|
|
40
|
+
"copilotkit.package.version": packageVersion
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
shouldSendEvent() {
|
|
44
|
+
const randomNumber = Math.random();
|
|
45
|
+
return randomNumber < this.sampleRate;
|
|
46
|
+
}
|
|
47
|
+
async capture(event, properties) {
|
|
48
|
+
if (!this.shouldSendEvent() || !this.segment) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const flattenedProperties = flattenObject(properties);
|
|
52
|
+
const propertiesWithGlobal = {
|
|
53
|
+
...this.globalProperties,
|
|
54
|
+
...flattenedProperties
|
|
55
|
+
};
|
|
56
|
+
const orderedPropertiesWithGlobal = Object.keys(propertiesWithGlobal).sort().reduce(
|
|
57
|
+
(obj, key) => {
|
|
58
|
+
obj[key] = propertiesWithGlobal[key];
|
|
59
|
+
return obj;
|
|
60
|
+
},
|
|
61
|
+
{}
|
|
62
|
+
);
|
|
63
|
+
this.segment.track({
|
|
64
|
+
anonymousId: this.anonymousId,
|
|
65
|
+
event,
|
|
66
|
+
properties: { ...orderedPropertiesWithGlobal }
|
|
67
|
+
});
|
|
68
|
+
await scarf_client_default.logEvent({
|
|
69
|
+
event
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
setGlobalProperties(properties) {
|
|
73
|
+
const flattenedProperties = flattenObject(properties);
|
|
74
|
+
this.globalProperties = { ...this.globalProperties, ...flattenedProperties };
|
|
75
|
+
}
|
|
76
|
+
setCloudConfiguration(properties) {
|
|
77
|
+
this.cloudConfiguration = properties;
|
|
78
|
+
this.setGlobalProperties({
|
|
79
|
+
cloud: {
|
|
80
|
+
publicApiKey: properties.publicApiKey,
|
|
81
|
+
baseUrl: properties.baseUrl
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
setSampleRate(sampleRate) {
|
|
86
|
+
let _sampleRate;
|
|
87
|
+
_sampleRate = sampleRate ?? 0.05;
|
|
88
|
+
if (process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE) {
|
|
89
|
+
_sampleRate = parseFloat(process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE);
|
|
90
|
+
}
|
|
91
|
+
if (_sampleRate < 0 || _sampleRate > 1) {
|
|
92
|
+
throw new Error("Sample rate must be between 0 and 1");
|
|
93
|
+
}
|
|
94
|
+
this.sampleRate = _sampleRate;
|
|
95
|
+
this.setGlobalProperties({
|
|
96
|
+
sampleRate: this.sampleRate,
|
|
97
|
+
sampleRateAdjustmentFactor: 1 - this.sampleRate,
|
|
98
|
+
sampleWeight: 1 / this.sampleRate
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export {
|
|
104
|
+
isTelemetryDisabled,
|
|
105
|
+
TelemetryClient
|
|
106
|
+
};
|
|
107
|
+
//# sourceMappingURL=chunk-WUPFNPXO.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/telemetry/telemetry-client.ts"],"sourcesContent":["import { Analytics } from \"@segment/analytics-node\";\nimport { AnalyticsEvents } from \"./events\";\nimport { flattenObject } from \"./utils\";\nimport { v4 as uuidv4 } from \"uuid\";\nimport scarfClient from \"./scarf-client\";\n\n/**\n * Checks if telemetry is disabled via environment variables.\n * Users can opt out by setting:\n * - COPILOTKIT_TELEMETRY_DISABLED=true or COPILOTKIT_TELEMETRY_DISABLED=1\n * - DO_NOT_TRACK=true or DO_NOT_TRACK=1\n */\nexport function isTelemetryDisabled(): boolean {\n return (\n (process.env as Record<string, string | undefined>).COPILOTKIT_TELEMETRY_DISABLED === \"true\" ||\n (process.env as Record<string, string | undefined>).COPILOTKIT_TELEMETRY_DISABLED === \"1\" ||\n (process.env as Record<string, string | undefined>).DO_NOT_TRACK === \"true\" ||\n (process.env as Record<string, string | undefined>).DO_NOT_TRACK === \"1\"\n );\n}\n\nexport class TelemetryClient {\n segment: Analytics | undefined;\n globalProperties: Record<string, any> = {};\n cloudConfiguration: { publicApiKey: string; baseUrl: string } | null = null;\n packageName: string;\n packageVersion: string;\n private telemetryDisabled: boolean = false;\n private sampleRate: number = 0.05;\n private anonymousId = `anon_${uuidv4()}`;\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 = telemetryDisabled || isTelemetryDisabled();\n\n if (this.telemetryDisabled) {\n return;\n }\n\n this.setSampleRate(sampleRate);\n\n // eslint-disable-next-line\n const writeKey = process.env.COPILOTKIT_SEGMENT_WRITE_KEY || \"n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja\";\n\n this.segment = new Analytics({\n writeKey,\n });\n\n this.setGlobalProperties({\n \"copilotkit.package.name\": packageName,\n \"copilotkit.package.version\": packageVersion,\n });\n }\n\n private shouldSendEvent() {\n const randomNumber = Math.random();\n return randomNumber < this.sampleRate;\n }\n\n async capture<K extends keyof AnalyticsEvents>(event: K, properties: AnalyticsEvents[K]) {\n 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 await scarfClient.logEvent({\n event,\n });\n }\n\n setGlobalProperties(properties: Record<string, any>) {\n const flattenedProperties = flattenObject(properties);\n this.globalProperties = { ...this.globalProperties, ...flattenedProperties };\n }\n\n setCloudConfiguration(properties: { publicApiKey: string; baseUrl: string }) {\n this.cloudConfiguration = properties;\n\n this.setGlobalProperties({\n cloud: {\n publicApiKey: properties.publicApiKey,\n baseUrl: properties.baseUrl,\n },\n });\n }\n\n private setSampleRate(sampleRate: number | undefined) {\n let _sampleRate: number;\n\n _sampleRate = sampleRate ?? 0.05;\n\n // eslint-disable-next-line\n if (process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE) {\n // eslint-disable-next-line\n _sampleRate = parseFloat(process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE);\n }\n\n if (_sampleRate < 0 || _sampleRate > 1) {\n throw new Error(\"Sample rate must be between 0 and 1\");\n }\n\n this.sampleRate = _sampleRate;\n this.setGlobalProperties({\n sampleRate: this.sampleRate,\n sampleRateAdjustmentFactor: 1 - this.sampleRate,\n sampleWeight: 1 / this.sampleRate,\n });\n }\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,iBAAiB;AAG1B,SAAS,MAAM,cAAc;AAStB,SAAS,sBAA+B;AAC7C,SACG,QAAQ,IAA2C,kCAAkC,UACrF,QAAQ,IAA2C,kCAAkC,OACrF,QAAQ,IAA2C,iBAAiB,UACpE,QAAQ,IAA2C,iBAAiB;AAEzE;AAEO,IAAM,kBAAN,MAAsB;AAAA,EAU3B,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAMG;AApBH,4BAAwC,CAAC;AACzC,8BAAuE;AAGvE,SAAQ,oBAA6B;AACrC,SAAQ,aAAqB;AAC7B,SAAQ,cAAc,QAAQ,OAAO;AAenC,SAAK,cAAc;AACnB,SAAK,iBAAiB;AACtB,SAAK,oBAAoB,qBAAqB,oBAAoB;AAElE,QAAI,KAAK,mBAAmB;AAC1B;AAAA,IACF;AAEA,SAAK,cAAc,UAAU;AAG7B,UAAM,WAAW,QAAQ,IAAI,gCAAgC;AAE7D,SAAK,UAAU,IAAI,UAAU;AAAA,MAC3B;AAAA,IACF,CAAC;AAED,SAAK,oBAAoB;AAAA,MACvB,2BAA2B;AAAA,MAC3B,8BAA8B;AAAA,IAChC,CAAC;AAAA,EACH;AAAA,EAEQ,kBAAkB;AACxB,UAAM,eAAe,KAAK,OAAO;AACjC,WAAO,eAAe,KAAK;AAAA,EAC7B;AAAA,EAEA,MAAM,QAAyC,OAAU,YAAgC;AACvF,QAAI,CAAC,KAAK,gBAAgB,KAAK,CAAC,KAAK,SAAS;AAC5C;AAAA,IACF;AAEA,UAAM,sBAAsB,cAAc,UAAU;AACpD,UAAM,uBAAuB;AAAA,MAC3B,GAAG,KAAK;AAAA,MACR,GAAG;AAAA,IACL;AACA,UAAM,8BAA8B,OAAO,KAAK,oBAAoB,EACjE,KAAK,EACL;AAAA,MACC,CAAC,KAAK,QAAQ;AACZ,YAAI,GAAG,IAAI,qBAAqB,GAAG;AACnC,eAAO;AAAA,MACT;AAAA,MACA,CAAC;AAAA,IACH;AAEF,SAAK,QAAQ,MAAM;AAAA,MACjB,aAAa,KAAK;AAAA,MAClB;AAAA,MACA,YAAY,EAAE,GAAG,4BAA4B;AAAA,IAC/C,CAAC;AAED,UAAM,qBAAY,SAAS;AAAA,MACzB;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEA,oBAAoB,YAAiC;AACnD,UAAM,sBAAsB,cAAc,UAAU;AACpD,SAAK,mBAAmB,EAAE,GAAG,KAAK,kBAAkB,GAAG,oBAAoB;AAAA,EAC7E;AAAA,EAEA,sBAAsB,YAAuD;AAC3E,SAAK,qBAAqB;AAE1B,SAAK,oBAAoB;AAAA,MACvB,OAAO;AAAA,QACL,cAAc,WAAW;AAAA,QACzB,SAAS,WAAW;AAAA,MACtB;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEQ,cAAc,YAAgC;AACpD,QAAI;AAEJ,kBAAc,cAAc;AAG5B,QAAI,QAAQ,IAAI,kCAAkC;AAEhD,oBAAc,WAAW,QAAQ,IAAI,gCAAgC;AAAA,IACvE;AAEA,QAAI,cAAc,KAAK,cAAc,GAAG;AACtC,YAAM,IAAI,MAAM,qCAAqC;AAAA,IACvD;AAEA,SAAK,aAAa;AAClB,SAAK,oBAAoB;AAAA,MACvB,YAAY,KAAK;AAAA,MACjB,4BAA4B,IAAI,KAAK;AAAA,MACrC,cAAc,IAAI,KAAK;AAAA,IACzB,CAAC;AAAA,EACH;AACF;","names":[]}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// src/utils/requests.ts
|
|
2
|
+
async function readBody(r) {
|
|
3
|
+
const method = "method" in r ? r.method.toUpperCase() : void 0;
|
|
4
|
+
if (method === "GET" || method === "HEAD") {
|
|
5
|
+
return void 0;
|
|
6
|
+
}
|
|
7
|
+
if (!("body" in r) || r.body == null) {
|
|
8
|
+
return void 0;
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
return await r.clone().json();
|
|
12
|
+
} catch {
|
|
13
|
+
try {
|
|
14
|
+
const text = await r.clone().text();
|
|
15
|
+
const trimmed = text.trim();
|
|
16
|
+
if (trimmed.length === 0)
|
|
17
|
+
return text;
|
|
18
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
19
|
+
try {
|
|
20
|
+
return JSON.parse(trimmed);
|
|
21
|
+
} catch {
|
|
22
|
+
return text;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return text;
|
|
26
|
+
} catch {
|
|
27
|
+
try {
|
|
28
|
+
const c = r.clone();
|
|
29
|
+
const stream = c.body ?? null;
|
|
30
|
+
if (!stream)
|
|
31
|
+
return void 0;
|
|
32
|
+
const reader = stream.getReader();
|
|
33
|
+
const decoder = new TextDecoder();
|
|
34
|
+
let out = "";
|
|
35
|
+
while (true) {
|
|
36
|
+
const { done, value } = await reader.read();
|
|
37
|
+
if (done)
|
|
38
|
+
break;
|
|
39
|
+
if (typeof value === "string") {
|
|
40
|
+
out += value;
|
|
41
|
+
} else {
|
|
42
|
+
out += decoder.decode(value, { stream: true });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
out += decoder.decode();
|
|
46
|
+
const trimmed = out.trim();
|
|
47
|
+
if (trimmed.length === 0)
|
|
48
|
+
return out;
|
|
49
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
50
|
+
try {
|
|
51
|
+
return JSON.parse(trimmed);
|
|
52
|
+
} catch {
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
} catch {
|
|
58
|
+
return void 0;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export {
|
|
65
|
+
readBody
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=chunk-XEMZTHQZ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/requests.ts"],"sourcesContent":["/**\n * Safely read a Response/Request body with sensible defaults:\n * - clones the response/request to avoid consuming the original response/request\n * - Skips GET/HEAD\n * - Tries JSON first regardless of content-type\n * - Falls back to text and optionally parses when it \"looks\" like JSON\n */\nexport async function readBody<T extends Response | Request>(r: T): Promise<unknown> {\n // skip GET/HEAD requests (unchanged)\n const method = \"method\" in r ? r.method.toUpperCase() : undefined;\n if (method === \"GET\" || method === \"HEAD\") {\n return undefined;\n }\n\n // no body at all → undefined (unchanged)\n if (!(\"body\" in r) || r.body == null) {\n return undefined;\n }\n\n // 1) try JSON (unchanged)\n try {\n return await r.clone().json();\n } catch {\n // 2) try text (unchanged + your whitespace/JSON-heuristic)\n try {\n const text = await r.clone().text();\n const trimmed = text.trim();\n\n if (trimmed.length === 0) return text;\n\n if (trimmed.startsWith(\"{\") || trimmed.startsWith(\"[\")) {\n try {\n return JSON.parse(trimmed);\n } catch {\n return text;\n }\n }\n return text;\n } catch {\n // 3) FINAL FALLBACK: manual read that accepts string or bytes\n try {\n const c = r.clone();\n const stream: ReadableStream | null = c.body ?? null;\n if (!stream) return undefined;\n\n const reader = stream.getReader();\n const decoder = new TextDecoder();\n let out = \"\";\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n if (typeof value === \"string\") {\n out += value; // accept string chunks\n } else {\n out += decoder.decode(value, { stream: true }); // bytes\n }\n }\n out += decoder.decode(); // flush\n\n const trimmed = out.trim();\n if (trimmed.length === 0) return out;\n\n if (trimmed.startsWith(\"{\") || trimmed.startsWith(\"[\")) {\n try {\n return JSON.parse(trimmed);\n } catch {\n return out;\n }\n }\n return out;\n } catch {\n return undefined; // same \"give up\" behavior you had\n }\n }\n }\n}\n"],"mappings":";AAOA,eAAsB,SAAuC,GAAwB;AAEnF,QAAM,SAAS,YAAY,IAAI,EAAE,OAAO,YAAY,IAAI;AACxD,MAAI,WAAW,SAAS,WAAW,QAAQ;AACzC,WAAO;AAAA,EACT;AAGA,MAAI,EAAE,UAAU,MAAM,EAAE,QAAQ,MAAM;AACpC,WAAO;AAAA,EACT;AAGA,MAAI;AACF,WAAO,MAAM,EAAE,MAAM,EAAE,KAAK;AAAA,EAC9B,QAAE;AAEA,QAAI;AACF,YAAM,OAAO,MAAM,EAAE,MAAM,EAAE,KAAK;AAClC,YAAM,UAAU,KAAK,KAAK;AAE1B,UAAI,QAAQ,WAAW;AAAG,eAAO;AAEjC,UAAI,QAAQ,WAAW,GAAG,KAAK,QAAQ,WAAW,GAAG,GAAG;AACtD,YAAI;AACF,iBAAO,KAAK,MAAM,OAAO;AAAA,QAC3B,QAAE;AACA,iBAAO;AAAA,QACT;AAAA,MACF;AACA,aAAO;AAAA,IACT,QAAE;AAEA,UAAI;AACF,cAAM,IAAI,EAAE,MAAM;AAClB,cAAM,SAAgC,EAAE,QAAQ;AAChD,YAAI,CAAC;AAAQ,iBAAO;AAEpB,cAAM,SAAS,OAAO,UAAU;AAChC,cAAM,UAAU,IAAI,YAAY;AAChC,YAAI,MAAM;AAEV,eAAO,MAAM;AACX,gBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,cAAI;AAAM;AACV,cAAI,OAAO,UAAU,UAAU;AAC7B,mBAAO;AAAA,UACT,OAAO;AACL,mBAAO,QAAQ,OAAO,OAAO,EAAE,QAAQ,KAAK,CAAC;AAAA,UAC/C;AAAA,QACF;AACA,eAAO,QAAQ,OAAO;AAEtB,cAAM,UAAU,IAAI,KAAK;AACzB,YAAI,QAAQ,WAAW;AAAG,iBAAO;AAEjC,YAAI,QAAQ,WAAW,GAAG,KAAK,QAAQ,WAAW,GAAG,GAAG;AACtD,cAAI;AACF,mBAAO,KAAK,MAAM,OAAO;AAAA,UAC3B,QAAE;AACA,mBAAO;AAAA,UACT;AAAA,QACF;AACA,eAAO;AAAA,MACT,QAAE;AACA,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-XTHC46M2.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
declare const COPILOT_CLOUD_API_URL = "https://api.cloud.copilotkit.ai";
|
|
2
|
+
declare const COPILOT_CLOUD_VERSION = "v1";
|
|
3
|
+
declare const COPILOT_CLOUD_CHAT_URL = "https://api.cloud.copilotkit.ai/copilotkit/v1";
|
|
4
|
+
declare const COPILOT_CLOUD_PUBLIC_API_KEY_HEADER = "X-CopilotCloud-Public-Api-Key";
|
|
5
|
+
|
|
6
|
+
export { COPILOT_CLOUD_API_URL, COPILOT_CLOUD_CHAT_URL, COPILOT_CLOUD_PUBLIC_API_KEY_HEADER, COPILOT_CLOUD_VERSION };
|
|
@@ -0,0 +1,40 @@
|
|
|
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/constants/index.ts
|
|
21
|
+
var constants_exports = {};
|
|
22
|
+
__export(constants_exports, {
|
|
23
|
+
COPILOT_CLOUD_API_URL: () => COPILOT_CLOUD_API_URL,
|
|
24
|
+
COPILOT_CLOUD_CHAT_URL: () => COPILOT_CLOUD_CHAT_URL,
|
|
25
|
+
COPILOT_CLOUD_PUBLIC_API_KEY_HEADER: () => COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,
|
|
26
|
+
COPILOT_CLOUD_VERSION: () => COPILOT_CLOUD_VERSION
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(constants_exports);
|
|
29
|
+
var COPILOT_CLOUD_API_URL = "https://api.cloud.copilotkit.ai";
|
|
30
|
+
var COPILOT_CLOUD_VERSION = "v1";
|
|
31
|
+
var COPILOT_CLOUD_CHAT_URL = `${COPILOT_CLOUD_API_URL}/copilotkit/${COPILOT_CLOUD_VERSION}`;
|
|
32
|
+
var COPILOT_CLOUD_PUBLIC_API_KEY_HEADER = "X-CopilotCloud-Public-Api-Key";
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
35
|
+
COPILOT_CLOUD_API_URL,
|
|
36
|
+
COPILOT_CLOUD_CHAT_URL,
|
|
37
|
+
COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,
|
|
38
|
+
COPILOT_CLOUD_VERSION
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/constants/index.ts"],"sourcesContent":["export const COPILOT_CLOUD_API_URL = \"https://api.cloud.copilotkit.ai\";\nexport const COPILOT_CLOUD_VERSION = \"v1\";\nexport const COPILOT_CLOUD_CHAT_URL = `${COPILOT_CLOUD_API_URL}/copilotkit/${COPILOT_CLOUD_VERSION}`;\nexport const COPILOT_CLOUD_PUBLIC_API_KEY_HEADER = \"X-CopilotCloud-Public-Api-Key\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,IAAM,wBAAwB;AAC9B,IAAM,wBAAwB;AAC9B,IAAM,yBAAyB,GAAG,oCAAoC;AACtE,IAAM,sCAAsC;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
COPILOT_CLOUD_API_URL,
|
|
3
|
+
COPILOT_CLOUD_CHAT_URL,
|
|
4
|
+
COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,
|
|
5
|
+
COPILOT_CLOUD_VERSION
|
|
6
|
+
} from "../chunk-GYZIHHE6.mjs";
|
|
7
|
+
export {
|
|
8
|
+
COPILOT_CLOUD_API_URL,
|
|
9
|
+
COPILOT_CLOUD_CHAT_URL,
|
|
10
|
+
COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,
|
|
11
|
+
COPILOT_CLOUD_VERSION
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export { AssistantMessage, CoAgentStateRenderHandler, CoAgentStateRenderHandlerArguments, FunctionCallHandler, FunctionCallHandlerArguments, FunctionDefinition, JSONValue, ToolDefinition } from './types/openai-assistant.js';
|
|
2
|
+
export { Action, MappedParameterTypes, Parameter } from './types/action.js';
|
|
3
|
+
export { CopilotCloudConfig } from './types/copilot-cloud-config.js';
|
|
4
|
+
export { PartialBy, RequiredBy } from './types/utility.js';
|
|
5
|
+
export { CopilotErrorEvent, CopilotErrorHandler, CopilotRequestContext } from './types/error.js';
|
|
6
|
+
export { AIMessage, ActivityMessage, DeveloperMessage, ImageData, Message, Role, SystemMessage, ToolCall, ToolResult, UserMessage } from './types/message.js';
|
|
7
|
+
export { isMacOS, parseJson, tryMap } from './utils/index.js';
|
|
8
|
+
export { COPILOT_CLOUD_API_URL, COPILOT_CLOUD_CHAT_URL, COPILOT_CLOUD_PUBLIC_API_KEY_HEADER, COPILOT_CLOUD_VERSION } from './constants/index.js';
|
|
9
|
+
export { TelemetryClient, isTelemetryDisabled } from './telemetry/telemetry-client.js';
|
|
10
|
+
export { BaseCondition, ComparisonCondition, ComparisonRule, Condition, ExistenceCondition, ExistenceRule, LogicalCondition, LogicalRule, Rule, executeConditions } from './utils/conditions.js';
|
|
11
|
+
export { ConsoleColors, ConsoleStyles, logCopilotKitPlatformMessage, logStyled, publicApiKeyRequired, styledConsole } from './utils/console-styling.js';
|
|
12
|
+
export { BANNER_ERROR_NAMES, COPILOT_CLOUD_ERROR_NAMES, ConfigurationError, CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitLowLevelError, CopilotKitMisuseError, CopilotKitRemoteEndpointDiscoveryError, CopilotKitVersionMismatchError, ERROR_CONFIG, ERROR_NAMES, ErrorVisibility, MissingPublicApiKeyError, ResolvedCopilotKitError, Severity, UpgradeRequiredError, ensureStructuredError, getPossibleVersionMismatch, isStructuredCopilotKitError } from './utils/errors.js';
|
|
13
|
+
export { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema, convertJsonSchemaToZodSchema, getZodParameters, jsonSchemaToActionParameters } from './utils/json-schema.js';
|
|
14
|
+
export { AgentDescription, MaybePromise, NonEmptyRecord, RuntimeInfo } from './utils/types.js';
|
|
15
|
+
export { dataToUUID, isValidUUID, randomId, randomUUID } from './utils/random-id.js';
|
|
16
|
+
export { readBody } from './utils/requests.js';
|
|
17
|
+
import '@ag-ui/core';
|
|
18
|
+
import '@segment/analytics-node';
|
|
19
|
+
import './telemetry/events.js';
|
|
20
|
+
import 'graphql';
|
|
21
|
+
import 'zod';
|
|
22
|
+
|
|
23
|
+
declare const COPILOTKIT_VERSION: string;
|
|
24
|
+
|
|
25
|
+
export { COPILOTKIT_VERSION };
|