@copilotkit/shared 0.0.0-fix-debug-infosys-20251107162427 → 0.0.0-fix-restore-handle-method-node-http-20251222114321
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 +129 -1
- package/dist/{chunk-RFXI5UPJ.mjs → chunk-4KTOMF4X.mjs} +2 -2
- package/dist/{chunk-RFXI5UPJ.mjs.map → chunk-4KTOMF4X.mjs.map} +1 -1
- package/dist/{chunk-XLQ2EIPH.mjs → chunk-4MW543GA.mjs} +2 -2
- package/dist/{chunk-XLQ2EIPH.mjs.map → chunk-4MW543GA.mjs.map} +1 -1
- package/dist/{chunk-2KQ6HEWZ.mjs → chunk-64DYJ27R.mjs} +9 -2
- package/dist/{chunk-2KQ6HEWZ.mjs.map → chunk-64DYJ27R.mjs.map} +1 -1
- package/dist/chunk-BOKE4OKY.mjs +41 -0
- package/dist/chunk-BOKE4OKY.mjs.map +1 -0
- package/dist/{chunk-7HYFTWJY.mjs → chunk-OX5WDDTA.mjs} +7 -3
- package/dist/chunk-OX5WDDTA.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/index.d.ts +5 -3
- package/dist/index.js +98 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -6
- package/dist/telemetry/index.d.ts +1 -1
- package/dist/telemetry/index.js +9 -4
- package/dist/telemetry/index.js.map +1 -1
- package/dist/telemetry/index.mjs +6 -4
- package/dist/telemetry/scarf-client.js +1 -1
- package/dist/telemetry/scarf-client.js.map +1 -1
- package/dist/telemetry/scarf-client.mjs +1 -1
- package/dist/telemetry/telemetry-client.d.ts +8 -1
- package/dist/telemetry/telemetry-client.js +9 -4
- package/dist/telemetry/telemetry-client.js.map +1 -1
- package/dist/telemetry/telemetry-client.mjs +6 -4
- package/dist/types/index.d.ts +1 -1
- package/dist/types/message.d.ts +3 -2
- package/dist/types/message.js.map +1 -1
- package/dist/utils/errors.js +1 -1
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/errors.mjs +7 -5
- package/dist/utils/index.d.ts +3 -1
- package/dist/utils/index.js +92 -2
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +12 -5
- package/dist/utils/json-schema.d.ts +2 -1
- package/dist/utils/json-schema.js +8 -0
- package/dist/utils/json-schema.js.map +1 -1
- package/dist/utils/json-schema.mjs +3 -1
- package/dist/utils/random-id.d.ts +1 -1
- package/dist/utils/random-id.js +18 -1
- package/dist/utils/random-id.js.map +1 -1
- package/dist/utils/random-id.mjs +1 -1
- 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/package.json +4 -4
- package/src/telemetry/telemetry-client.ts +16 -6
- package/src/types/message.ts +8 -1
- package/src/utils/index.ts +2 -0
- package/src/utils/json-schema.ts +6 -0
- package/src/utils/random-id.ts +24 -2
- package/src/utils/requests.ts +77 -0
- package/src/utils/types.ts +22 -0
- package/dist/chunk-7HYFTWJY.mjs.map +0 -1
- package/dist/chunk-VNNKZIFB.mjs +0 -24
- package/dist/chunk-VNNKZIFB.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/random-id.ts"],"sourcesContent":["import { v4 as uuidv4, validate, v5 as uuidv5 } from \"uuid\";\n\nexport function randomId() {\n return \"ck-\" + uuidv4();\n}\n\nexport function randomUUID() {\n return uuidv4();\n}\n\nexport function dataToUUID(input: string, namespace?: string): string {\n const BASE_NAMESPACE = \"e4b01160-ff74-4c6e-9b27-d53cd930fe8e\";\n // Since namespace needs to be a uuid, we are creating a uuid for it.\n const boundNamespace = namespace ? uuidv5(namespace, BASE_NAMESPACE) : BASE_NAMESPACE;\n return uuidv5(
|
|
1
|
+
{"version":3,"sources":["../../src/utils/random-id.ts"],"sourcesContent":["import { v4 as uuidv4, validate, v5 as uuidv5 } from \"uuid\";\n\nexport function randomId() {\n return \"ck-\" + uuidv4();\n}\n\nexport function randomUUID() {\n return uuidv4();\n}\n\n/**\n * Recursively converts an object to a serializable form by converting functions to their string representation.\n */\nfunction toSerializable(value: unknown): unknown {\n if (typeof value === \"function\") {\n return value.toString();\n }\n if (Array.isArray(value)) {\n return value.map(toSerializable);\n }\n if (value !== null && typeof value === \"object\") {\n const result: Record<string, unknown> = {};\n for (const key of Object.keys(value)) {\n result[key] = toSerializable((value as Record<string, unknown>)[key]);\n }\n return result;\n }\n return value;\n}\n\nexport function dataToUUID(input: string | object, namespace?: string): string {\n const BASE_NAMESPACE = \"e4b01160-ff74-4c6e-9b27-d53cd930fe8e\";\n // Since namespace needs to be a uuid, we are creating a uuid for it.\n const boundNamespace = namespace ? uuidv5(namespace, BASE_NAMESPACE) : BASE_NAMESPACE;\n\n const stringInput = typeof input === \"string\" ? input : JSON.stringify(toSerializable(input));\n return uuidv5(stringInput, boundNamespace);\n}\n\nexport function isValidUUID(uuid: string) {\n return validate(uuid);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAqD;AAE9C,SAAS,WAAW;AACzB,SAAO,YAAQ,YAAAA,IAAO;AACxB;AAEO,SAAS,aAAa;AAC3B,aAAO,YAAAA,IAAO;AAChB;AAKA,SAAS,eAAe,OAAyB;AAC/C,MAAI,OAAO,UAAU,YAAY;AAC/B,WAAO,MAAM,SAAS;AAAA,EACxB;AACA,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAO,MAAM,IAAI,cAAc;AAAA,EACjC;AACA,MAAI,UAAU,QAAQ,OAAO,UAAU,UAAU;AAC/C,UAAM,SAAkC,CAAC;AACzC,eAAW,OAAO,OAAO,KAAK,KAAK,GAAG;AACpC,aAAO,GAAG,IAAI,eAAgB,MAAkC,GAAG,CAAC;AAAA,IACtE;AACA,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEO,SAAS,WAAW,OAAwB,WAA4B;AAC7E,QAAM,iBAAiB;AAEvB,QAAM,iBAAiB,gBAAY,YAAAC,IAAO,WAAW,cAAc,IAAI;AAEvE,QAAM,cAAc,OAAO,UAAU,WAAW,QAAQ,KAAK,UAAU,eAAe,KAAK,CAAC;AAC5F,aAAO,YAAAA,IAAO,aAAa,cAAc;AAC3C;AAEO,SAAS,YAAY,MAAc;AACxC,aAAO,sBAAS,IAAI;AACtB;","names":["uuidv4","uuidv5"]}
|
package/dist/utils/random-id.mjs
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safely read a Response/Request body with sensible defaults:
|
|
3
|
+
* - clones the response/request to avoid consuming the original response/request
|
|
4
|
+
* - Skips GET/HEAD
|
|
5
|
+
* - Tries JSON first regardless of content-type
|
|
6
|
+
* - Falls back to text and optionally parses when it "looks" like JSON
|
|
7
|
+
*/
|
|
8
|
+
declare function readBody<T extends Response | Request>(r: T): Promise<unknown>;
|
|
9
|
+
|
|
10
|
+
export { readBody };
|
|
@@ -0,0 +1,91 @@
|
|
|
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/requests.ts
|
|
21
|
+
var requests_exports = {};
|
|
22
|
+
__export(requests_exports, {
|
|
23
|
+
readBody: () => readBody
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(requests_exports);
|
|
26
|
+
async function readBody(r) {
|
|
27
|
+
const method = "method" in r ? r.method.toUpperCase() : void 0;
|
|
28
|
+
if (method === "GET" || method === "HEAD") {
|
|
29
|
+
return void 0;
|
|
30
|
+
}
|
|
31
|
+
if (!("body" in r) || r.body == null) {
|
|
32
|
+
return void 0;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
return await r.clone().json();
|
|
36
|
+
} catch {
|
|
37
|
+
try {
|
|
38
|
+
const text = await r.clone().text();
|
|
39
|
+
const trimmed = text.trim();
|
|
40
|
+
if (trimmed.length === 0)
|
|
41
|
+
return text;
|
|
42
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
43
|
+
try {
|
|
44
|
+
return JSON.parse(trimmed);
|
|
45
|
+
} catch {
|
|
46
|
+
return text;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return text;
|
|
50
|
+
} catch {
|
|
51
|
+
try {
|
|
52
|
+
const c = r.clone();
|
|
53
|
+
const stream = c.body ?? null;
|
|
54
|
+
if (!stream)
|
|
55
|
+
return void 0;
|
|
56
|
+
const reader = stream.getReader();
|
|
57
|
+
const decoder = new TextDecoder();
|
|
58
|
+
let out = "";
|
|
59
|
+
while (true) {
|
|
60
|
+
const { done, value } = await reader.read();
|
|
61
|
+
if (done)
|
|
62
|
+
break;
|
|
63
|
+
if (typeof value === "string") {
|
|
64
|
+
out += value;
|
|
65
|
+
} else {
|
|
66
|
+
out += decoder.decode(value, { stream: true });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
out += decoder.decode();
|
|
70
|
+
const trimmed = out.trim();
|
|
71
|
+
if (trimmed.length === 0)
|
|
72
|
+
return out;
|
|
73
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
74
|
+
try {
|
|
75
|
+
return JSON.parse(trimmed);
|
|
76
|
+
} catch {
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return out;
|
|
81
|
+
} catch {
|
|
82
|
+
return void 0;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
88
|
+
0 && (module.exports = {
|
|
89
|
+
readBody
|
|
90
|
+
});
|
|
91
|
+
//# sourceMappingURL=requests.js.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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;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
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type MaybePromise<T> = T | PromiseLike<T>;
|
|
2
|
+
/**
|
|
3
|
+
* More specific utility for records with at least one key
|
|
4
|
+
*/
|
|
5
|
+
type NonEmptyRecord<T> = T extends Record<string, unknown> ? (keyof T extends never ? never : T) : never;
|
|
6
|
+
/**
|
|
7
|
+
* Type representing an agent's basic information
|
|
8
|
+
*/
|
|
9
|
+
interface AgentDescription {
|
|
10
|
+
name: string;
|
|
11
|
+
className: string;
|
|
12
|
+
description: string;
|
|
13
|
+
}
|
|
14
|
+
interface RuntimeInfo {
|
|
15
|
+
version: string;
|
|
16
|
+
agents: Record<string, AgentDescription>;
|
|
17
|
+
audioFileTranscriptionEnabled: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { AgentDescription, MaybePromise, NonEmptyRecord, RuntimeInfo };
|
|
@@ -0,0 +1,19 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/utils/types.ts
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
|
19
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/types.ts"],"sourcesContent":["export type MaybePromise<T> = T | PromiseLike<T>;\n\n/**\n * More specific utility for records with at least one key\n */\nexport type NonEmptyRecord<T> =\n T extends Record<string, unknown> ? (keyof T extends never ? never : T) : never;\n\n/**\n * Type representing an agent's basic information\n */\nexport interface AgentDescription {\n name: string;\n className: string;\n description: string;\n}\n\nexport interface RuntimeInfo {\n version: string;\n agents: Record<string, AgentDescription>;\n audioFileTranscriptionEnabled: boolean;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -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": "0.0.0-fix-
|
|
12
|
+
"version": "0.0.0-fix-restore-handle-method-node-http-20251222114321",
|
|
13
13
|
"sideEffects": false,
|
|
14
14
|
"main": "./dist/index.js",
|
|
15
15
|
"module": "./dist/index.mjs",
|
|
@@ -30,17 +30,17 @@
|
|
|
30
30
|
"ts-jest": "^29.1.1",
|
|
31
31
|
"tsup": "^6.7.0",
|
|
32
32
|
"typescript": "^5.2.3",
|
|
33
|
+
"zod-to-json-schema": "^3.23.5",
|
|
33
34
|
"eslint-config-custom": "1.4.6",
|
|
34
35
|
"tsconfig": "1.4.6"
|
|
35
36
|
},
|
|
36
37
|
"dependencies": {
|
|
37
|
-
"@ag-ui/core": "^0.0.
|
|
38
|
+
"@ag-ui/core": "^0.0.42",
|
|
38
39
|
"@segment/analytics-node": "^2.1.2",
|
|
39
40
|
"chalk": "4.1.2",
|
|
40
41
|
"graphql": "^16.8.1",
|
|
41
42
|
"uuid": "^10.0.0",
|
|
42
|
-
"zod": "^3.23.3"
|
|
43
|
-
"zod-to-json-schema": "^3.23.5"
|
|
43
|
+
"zod": "^3.23.3"
|
|
44
44
|
},
|
|
45
45
|
"keywords": [
|
|
46
46
|
"copilotkit",
|
|
@@ -4,6 +4,21 @@ import { flattenObject } from "./utils";
|
|
|
4
4
|
import { v4 as uuidv4 } from "uuid";
|
|
5
5
|
import scarfClient from "./scarf-client";
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Checks if telemetry is disabled via environment variables.
|
|
9
|
+
* Users can opt out by setting:
|
|
10
|
+
* - COPILOTKIT_TELEMETRY_DISABLED=true or COPILOTKIT_TELEMETRY_DISABLED=1
|
|
11
|
+
* - DO_NOT_TRACK=true or DO_NOT_TRACK=1
|
|
12
|
+
*/
|
|
13
|
+
export function isTelemetryDisabled(): boolean {
|
|
14
|
+
return (
|
|
15
|
+
(process.env as Record<string, string | undefined>).COPILOTKIT_TELEMETRY_DISABLED === "true" ||
|
|
16
|
+
(process.env as Record<string, string | undefined>).COPILOTKIT_TELEMETRY_DISABLED === "1" ||
|
|
17
|
+
(process.env as Record<string, string | undefined>).DO_NOT_TRACK === "true" ||
|
|
18
|
+
(process.env as Record<string, string | undefined>).DO_NOT_TRACK === "1"
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
7
22
|
export class TelemetryClient {
|
|
8
23
|
segment: Analytics | undefined;
|
|
9
24
|
globalProperties: Record<string, any> = {};
|
|
@@ -29,12 +44,7 @@ export class TelemetryClient {
|
|
|
29
44
|
}) {
|
|
30
45
|
this.packageName = packageName;
|
|
31
46
|
this.packageVersion = packageVersion;
|
|
32
|
-
this.telemetryDisabled =
|
|
33
|
-
telemetryDisabled ||
|
|
34
|
-
(process.env as any).COPILOTKIT_TELEMETRY_DISABLED === "true" ||
|
|
35
|
-
(process.env as any).COPILOTKIT_TELEMETRY_DISABLED === "1" ||
|
|
36
|
-
(process.env as any).DO_NOT_TRACK === "true" ||
|
|
37
|
-
(process.env as any).DO_NOT_TRACK === "1";
|
|
47
|
+
this.telemetryDisabled = telemetryDisabled || isTelemetryDisabled();
|
|
38
48
|
|
|
39
49
|
if (this.telemetryDisabled) {
|
|
40
50
|
return;
|
package/src/types/message.ts
CHANGED
|
@@ -10,6 +10,7 @@ export type Role = agui.Role;
|
|
|
10
10
|
export type SystemMessage = agui.SystemMessage;
|
|
11
11
|
export type DeveloperMessage = agui.DeveloperMessage;
|
|
12
12
|
export type ToolCall = agui.ToolCall;
|
|
13
|
+
export type ActivityMessage = agui.ActivityMessage;
|
|
13
14
|
|
|
14
15
|
// Extended message types
|
|
15
16
|
export type ToolResult = agui.ToolMessage & {
|
|
@@ -27,4 +28,10 @@ export type UserMessage = agui.UserMessage & {
|
|
|
27
28
|
image?: ImageData;
|
|
28
29
|
};
|
|
29
30
|
|
|
30
|
-
export type Message =
|
|
31
|
+
export type Message =
|
|
32
|
+
| AIMessage
|
|
33
|
+
| ToolResult
|
|
34
|
+
| UserMessage
|
|
35
|
+
| SystemMessage
|
|
36
|
+
| DeveloperMessage
|
|
37
|
+
| ActivityMessage;
|
package/src/utils/index.ts
CHANGED
|
@@ -2,7 +2,9 @@ export * from "./conditions";
|
|
|
2
2
|
export * from "./console-styling";
|
|
3
3
|
export * from "./errors";
|
|
4
4
|
export * from "./json-schema";
|
|
5
|
+
export * from "./types";
|
|
5
6
|
export * from "./random-id";
|
|
7
|
+
export * from "./requests";
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Safely parses a JSON string into an object
|
package/src/utils/json-schema.ts
CHANGED
|
@@ -250,3 +250,9 @@ export function convertJsonSchemaToZodSchema(jsonSchema: any, required: boolean)
|
|
|
250
250
|
}
|
|
251
251
|
throw new Error("Invalid JSON schema");
|
|
252
252
|
}
|
|
253
|
+
|
|
254
|
+
export function getZodParameters<T extends [] | Parameter[] | undefined>(parameters: T): any {
|
|
255
|
+
if (!parameters) return z.object({});
|
|
256
|
+
const jsonParams = actionParametersToJsonSchema(parameters);
|
|
257
|
+
return convertJsonSchemaToZodSchema(jsonParams, true);
|
|
258
|
+
}
|
package/src/utils/random-id.ts
CHANGED
|
@@ -8,11 +8,33 @@ export function randomUUID() {
|
|
|
8
8
|
return uuidv4();
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Recursively converts an object to a serializable form by converting functions to their string representation.
|
|
13
|
+
*/
|
|
14
|
+
function toSerializable(value: unknown): unknown {
|
|
15
|
+
if (typeof value === "function") {
|
|
16
|
+
return value.toString();
|
|
17
|
+
}
|
|
18
|
+
if (Array.isArray(value)) {
|
|
19
|
+
return value.map(toSerializable);
|
|
20
|
+
}
|
|
21
|
+
if (value !== null && typeof value === "object") {
|
|
22
|
+
const result: Record<string, unknown> = {};
|
|
23
|
+
for (const key of Object.keys(value)) {
|
|
24
|
+
result[key] = toSerializable((value as Record<string, unknown>)[key]);
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function dataToUUID(input: string | object, namespace?: string): string {
|
|
12
32
|
const BASE_NAMESPACE = "e4b01160-ff74-4c6e-9b27-d53cd930fe8e";
|
|
13
33
|
// Since namespace needs to be a uuid, we are creating a uuid for it.
|
|
14
34
|
const boundNamespace = namespace ? uuidv5(namespace, BASE_NAMESPACE) : BASE_NAMESPACE;
|
|
15
|
-
|
|
35
|
+
|
|
36
|
+
const stringInput = typeof input === "string" ? input : JSON.stringify(toSerializable(input));
|
|
37
|
+
return uuidv5(stringInput, boundNamespace);
|
|
16
38
|
}
|
|
17
39
|
|
|
18
40
|
export function isValidUUID(uuid: string) {
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safely read a Response/Request body with sensible defaults:
|
|
3
|
+
* - clones the response/request to avoid consuming the original response/request
|
|
4
|
+
* - Skips GET/HEAD
|
|
5
|
+
* - Tries JSON first regardless of content-type
|
|
6
|
+
* - Falls back to text and optionally parses when it "looks" like JSON
|
|
7
|
+
*/
|
|
8
|
+
export async function readBody<T extends Response | Request>(r: T): Promise<unknown> {
|
|
9
|
+
// skip GET/HEAD requests (unchanged)
|
|
10
|
+
const method = "method" in r ? r.method.toUpperCase() : undefined;
|
|
11
|
+
if (method === "GET" || method === "HEAD") {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// no body at all → undefined (unchanged)
|
|
16
|
+
if (!("body" in r) || r.body == null) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// 1) try JSON (unchanged)
|
|
21
|
+
try {
|
|
22
|
+
return await r.clone().json();
|
|
23
|
+
} catch {
|
|
24
|
+
// 2) try text (unchanged + your whitespace/JSON-heuristic)
|
|
25
|
+
try {
|
|
26
|
+
const text = await r.clone().text();
|
|
27
|
+
const trimmed = text.trim();
|
|
28
|
+
|
|
29
|
+
if (trimmed.length === 0) return text;
|
|
30
|
+
|
|
31
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
32
|
+
try {
|
|
33
|
+
return JSON.parse(trimmed);
|
|
34
|
+
} catch {
|
|
35
|
+
return text;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return text;
|
|
39
|
+
} catch {
|
|
40
|
+
// 3) FINAL FALLBACK: manual read that accepts string or bytes
|
|
41
|
+
try {
|
|
42
|
+
const c = r.clone();
|
|
43
|
+
const stream: ReadableStream | null = c.body ?? null;
|
|
44
|
+
if (!stream) return undefined;
|
|
45
|
+
|
|
46
|
+
const reader = stream.getReader();
|
|
47
|
+
const decoder = new TextDecoder();
|
|
48
|
+
let out = "";
|
|
49
|
+
|
|
50
|
+
while (true) {
|
|
51
|
+
const { done, value } = await reader.read();
|
|
52
|
+
if (done) break;
|
|
53
|
+
if (typeof value === "string") {
|
|
54
|
+
out += value; // accept string chunks
|
|
55
|
+
} else {
|
|
56
|
+
out += decoder.decode(value, { stream: true }); // bytes
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
out += decoder.decode(); // flush
|
|
60
|
+
|
|
61
|
+
const trimmed = out.trim();
|
|
62
|
+
if (trimmed.length === 0) return out;
|
|
63
|
+
|
|
64
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
65
|
+
try {
|
|
66
|
+
return JSON.parse(trimmed);
|
|
67
|
+
} catch {
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return out;
|
|
72
|
+
} catch {
|
|
73
|
+
return undefined; // same "give up" behavior you had
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type MaybePromise<T> = T | PromiseLike<T>;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* More specific utility for records with at least one key
|
|
5
|
+
*/
|
|
6
|
+
export type NonEmptyRecord<T> =
|
|
7
|
+
T extends Record<string, unknown> ? (keyof T extends never ? never : T) : never;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Type representing an agent's basic information
|
|
11
|
+
*/
|
|
12
|
+
export interface AgentDescription {
|
|
13
|
+
name: string;
|
|
14
|
+
className: string;
|
|
15
|
+
description: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface RuntimeInfo {
|
|
19
|
+
version: string;
|
|
20
|
+
agents: Record<string, AgentDescription>;
|
|
21
|
+
audioFileTranscriptionEnabled: boolean;
|
|
22
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
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\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 =\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 // 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;AAGtB,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,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;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":[]}
|
package/dist/chunk-VNNKZIFB.mjs
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// src/utils/random-id.ts
|
|
2
|
-
import { v4 as uuidv4, validate, v5 as uuidv5 } from "uuid";
|
|
3
|
-
function randomId() {
|
|
4
|
-
return "ck-" + uuidv4();
|
|
5
|
-
}
|
|
6
|
-
function randomUUID() {
|
|
7
|
-
return uuidv4();
|
|
8
|
-
}
|
|
9
|
-
function dataToUUID(input, namespace) {
|
|
10
|
-
const BASE_NAMESPACE = "e4b01160-ff74-4c6e-9b27-d53cd930fe8e";
|
|
11
|
-
const boundNamespace = namespace ? uuidv5(namespace, BASE_NAMESPACE) : BASE_NAMESPACE;
|
|
12
|
-
return uuidv5(input, boundNamespace);
|
|
13
|
-
}
|
|
14
|
-
function isValidUUID(uuid) {
|
|
15
|
-
return validate(uuid);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export {
|
|
19
|
-
randomId,
|
|
20
|
-
randomUUID,
|
|
21
|
-
dataToUUID,
|
|
22
|
-
isValidUUID
|
|
23
|
-
};
|
|
24
|
-
//# sourceMappingURL=chunk-VNNKZIFB.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/random-id.ts"],"sourcesContent":["import { v4 as uuidv4, validate, v5 as uuidv5 } from \"uuid\";\n\nexport function randomId() {\n return \"ck-\" + uuidv4();\n}\n\nexport function randomUUID() {\n return uuidv4();\n}\n\nexport function dataToUUID(input: string, namespace?: string): string {\n const BASE_NAMESPACE = \"e4b01160-ff74-4c6e-9b27-d53cd930fe8e\";\n // Since namespace needs to be a uuid, we are creating a uuid for it.\n const boundNamespace = namespace ? uuidv5(namespace, BASE_NAMESPACE) : BASE_NAMESPACE;\n return uuidv5(input, boundNamespace);\n}\n\nexport function isValidUUID(uuid: string) {\n return validate(uuid);\n}\n"],"mappings":";AAAA,SAAS,MAAM,QAAQ,UAAU,MAAM,cAAc;AAE9C,SAAS,WAAW;AACzB,SAAO,QAAQ,OAAO;AACxB;AAEO,SAAS,aAAa;AAC3B,SAAO,OAAO;AAChB;AAEO,SAAS,WAAW,OAAe,WAA4B;AACpE,QAAM,iBAAiB;AAEvB,QAAM,iBAAiB,YAAY,OAAO,WAAW,cAAc,IAAI;AACvE,SAAO,OAAO,OAAO,cAAc;AACrC;AAEO,SAAS,YAAY,MAAc;AACxC,SAAO,SAAS,IAAI;AACtB;","names":[]}
|