@copilotkit/shared 0.0.0-feat-dynamic-copilotcloud-qa-20250117190454

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/CHANGELOG.md +978 -0
  2. package/README.md +46 -0
  3. package/dist/chunk-6QGXWNS5.mjs +34 -0
  4. package/dist/chunk-6QGXWNS5.mjs.map +1 -0
  5. package/dist/chunk-BANDZXMP.mjs +1 -0
  6. package/dist/chunk-BANDZXMP.mjs.map +1 -0
  7. package/dist/chunk-CYDWEPFL.mjs +1 -0
  8. package/dist/chunk-CYDWEPFL.mjs.map +1 -0
  9. package/dist/chunk-FCCOSO5L.mjs +1 -0
  10. package/dist/chunk-FCCOSO5L.mjs.map +1 -0
  11. package/dist/chunk-GYZIHHE6.mjs +13 -0
  12. package/dist/chunk-GYZIHHE6.mjs.map +1 -0
  13. package/dist/chunk-IAFBVORQ.mjs +1 -0
  14. package/dist/chunk-IAFBVORQ.mjs.map +1 -0
  15. package/dist/chunk-JP2M4U4G.mjs +112 -0
  16. package/dist/chunk-JP2M4U4G.mjs.map +1 -0
  17. package/dist/chunk-MSUB6DGR.mjs +1 -0
  18. package/dist/chunk-MSUB6DGR.mjs.map +1 -0
  19. package/dist/chunk-NAFEBKSO.mjs +1 -0
  20. package/dist/chunk-NAFEBKSO.mjs.map +1 -0
  21. package/dist/chunk-P7STFMPO.mjs +1 -0
  22. package/dist/chunk-P7STFMPO.mjs.map +1 -0
  23. package/dist/chunk-QFITLWYZ.mjs +96 -0
  24. package/dist/chunk-QFITLWYZ.mjs.map +1 -0
  25. package/dist/chunk-RIPX6APP.mjs +10 -0
  26. package/dist/chunk-RIPX6APP.mjs.map +1 -0
  27. package/dist/constants/index.d.ts +6 -0
  28. package/dist/constants/index.js +40 -0
  29. package/dist/constants/index.js.map +1 -0
  30. package/dist/constants/index.mjs +13 -0
  31. package/dist/constants/index.mjs.map +1 -0
  32. package/dist/index.d.ts +15 -0
  33. package/dist/index.js +285 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/index.mjs +42 -0
  36. package/dist/index.mjs.map +1 -0
  37. package/dist/telemetry/events.d.ts +39 -0
  38. package/dist/telemetry/events.js +19 -0
  39. package/dist/telemetry/events.js.map +1 -0
  40. package/dist/telemetry/events.mjs +1 -0
  41. package/dist/telemetry/events.mjs.map +1 -0
  42. package/dist/telemetry/index.d.ts +3 -0
  43. package/dist/telemetry/index.js +144 -0
  44. package/dist/telemetry/index.js.map +1 -0
  45. package/dist/telemetry/index.mjs +9 -0
  46. package/dist/telemetry/index.mjs.map +1 -0
  47. package/dist/telemetry/security-check.d.ts +2 -0
  48. package/dist/telemetry/security-check.js +2 -0
  49. package/dist/telemetry/security-check.js.map +1 -0
  50. package/dist/telemetry/security-check.mjs +1 -0
  51. package/dist/telemetry/security-check.mjs.map +1 -0
  52. package/dist/telemetry/telemetry-client.d.ts +33 -0
  53. package/dist/telemetry/telemetry-client.js +142 -0
  54. package/dist/telemetry/telemetry-client.js.map +1 -0
  55. package/dist/telemetry/telemetry-client.mjs +8 -0
  56. package/dist/telemetry/telemetry-client.mjs.map +1 -0
  57. package/dist/telemetry/utils.d.ts +8 -0
  58. package/dist/telemetry/utils.js +69 -0
  59. package/dist/telemetry/utils.js.map +1 -0
  60. package/dist/telemetry/utils.mjs +9 -0
  61. package/dist/telemetry/utils.mjs.map +1 -0
  62. package/dist/types/action.d.ts +58 -0
  63. package/dist/types/action.js +19 -0
  64. package/dist/types/action.js.map +1 -0
  65. package/dist/types/action.mjs +2 -0
  66. package/dist/types/action.mjs.map +1 -0
  67. package/dist/types/copilot-cloud-config.d.ts +13 -0
  68. package/dist/types/copilot-cloud-config.js +19 -0
  69. package/dist/types/copilot-cloud-config.js.map +1 -0
  70. package/dist/types/copilot-cloud-config.mjs +2 -0
  71. package/dist/types/copilot-cloud-config.mjs.map +1 -0
  72. package/dist/types/index.d.ts +4 -0
  73. package/dist/types/index.js +19 -0
  74. package/dist/types/index.js.map +1 -0
  75. package/dist/types/index.mjs +6 -0
  76. package/dist/types/index.mjs.map +1 -0
  77. package/dist/types/openai-assistant.d.ts +53 -0
  78. package/dist/types/openai-assistant.js +19 -0
  79. package/dist/types/openai-assistant.js.map +1 -0
  80. package/dist/types/openai-assistant.mjs +2 -0
  81. package/dist/types/openai-assistant.mjs.map +1 -0
  82. package/dist/types/utility.d.ts +3 -0
  83. package/dist/types/utility.js +19 -0
  84. package/dist/types/utility.js.map +1 -0
  85. package/dist/types/utility.mjs +2 -0
  86. package/dist/types/utility.mjs.map +1 -0
  87. package/dist/utils/index.d.ts +4 -0
  88. package/dist/utils/index.js +147 -0
  89. package/dist/utils/index.js.map +1 -0
  90. package/dist/utils/index.mjs +14 -0
  91. package/dist/utils/index.mjs.map +1 -0
  92. package/dist/utils/json-schema.d.ts +32 -0
  93. package/dist/utils/json-schema.js +137 -0
  94. package/dist/utils/json-schema.js.map +1 -0
  95. package/dist/utils/json-schema.mjs +9 -0
  96. package/dist/utils/json-schema.mjs.map +1 -0
  97. package/dist/utils/json-schema.test.d.ts +2 -0
  98. package/dist/utils/json-schema.test.js +173 -0
  99. package/dist/utils/json-schema.test.js.map +1 -0
  100. package/dist/utils/json-schema.test.mjs +140 -0
  101. package/dist/utils/json-schema.test.mjs.map +1 -0
  102. package/dist/utils/random-id.d.ts +3 -0
  103. package/dist/utils/random-id.js +34 -0
  104. package/dist/utils/random-id.js.map +1 -0
  105. package/dist/utils/random-id.mjs +7 -0
  106. package/dist/utils/random-id.mjs.map +1 -0
  107. package/jest.config.js +5 -0
  108. package/package.json +64 -0
  109. package/src/constants/index.ts +4 -0
  110. package/src/index.ts +7 -0
  111. package/src/telemetry/events.ts +35 -0
  112. package/src/telemetry/index.ts +1 -0
  113. package/src/telemetry/security-check.ts +0 -0
  114. package/src/telemetry/telemetry-client.ts +126 -0
  115. package/src/telemetry/utils.ts +39 -0
  116. package/src/types/action.ts +128 -0
  117. package/src/types/copilot-cloud-config.ts +11 -0
  118. package/src/types/index.ts +4 -0
  119. package/src/types/openai-assistant.ts +62 -0
  120. package/src/types/utility.ts +1 -0
  121. package/src/utils/index.ts +2 -0
  122. package/src/utils/json-schema.test.ts +169 -0
  123. package/src/utils/json-schema.ts +154 -0
  124. package/src/utils/random-id.ts +5 -0
  125. package/tsconfig.json +9 -0
  126. package/tsup.config.ts +16 -0
  127. package/typedoc.json +4 -0
@@ -0,0 +1,140 @@
1
+ import {
2
+ convertJsonSchemaToZodSchema
3
+ } from "../chunk-JP2M4U4G.mjs";
4
+
5
+ // src/utils/json-schema.test.ts
6
+ import { z } from "zod";
7
+ import { zodToJsonSchema } from "zod-to-json-schema";
8
+ describe("convertJsonSchemaToZodSchema", () => {
9
+ it("should convert a simple JSON schema to a Zod schema", () => {
10
+ const jsonSchema = {
11
+ type: "object",
12
+ properties: {
13
+ name: { type: "string" },
14
+ age: { type: "number" }
15
+ },
16
+ required: ["name", "age"]
17
+ };
18
+ const expectedSchema = z.object({
19
+ name: z.string(),
20
+ age: z.number()
21
+ });
22
+ const result = convertJsonSchemaToZodSchema(jsonSchema, true);
23
+ const resultSchemaJson = zodToJsonSchema(result);
24
+ const expectedSchemaJson = zodToJsonSchema(expectedSchema);
25
+ expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
26
+ });
27
+ it("should convert a JSON schema with nested objects to a Zod schema", () => {
28
+ const jsonSchema = {
29
+ type: "object",
30
+ properties: {
31
+ name: { type: "string" },
32
+ address: {
33
+ type: "object",
34
+ properties: {
35
+ street: { type: "string" },
36
+ city: { type: "string" }
37
+ },
38
+ required: ["street", "city"]
39
+ }
40
+ },
41
+ required: ["name", "address"]
42
+ };
43
+ const expectedSchema = z.object({
44
+ name: z.string(),
45
+ address: z.object({
46
+ street: z.string(),
47
+ city: z.string()
48
+ })
49
+ });
50
+ const result = convertJsonSchemaToZodSchema(jsonSchema, true);
51
+ const resultSchemaJson = zodToJsonSchema(result);
52
+ const expectedSchemaJson = zodToJsonSchema(expectedSchema);
53
+ expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
54
+ });
55
+ it("should convert a JSON schema with arrays to a Zod schema", () => {
56
+ const jsonSchema = {
57
+ type: "object",
58
+ properties: {
59
+ names: {
60
+ type: "array",
61
+ items: { type: "string" }
62
+ }
63
+ },
64
+ required: ["names"]
65
+ };
66
+ const expectedSchema = z.object({
67
+ names: z.array(z.string())
68
+ });
69
+ const result = convertJsonSchemaToZodSchema(jsonSchema, true);
70
+ const resultSchemaJson = zodToJsonSchema(result);
71
+ const expectedSchemaJson = zodToJsonSchema(expectedSchema);
72
+ expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
73
+ });
74
+ it("should convert a JSON schema with optional properties to a Zod schema", () => {
75
+ const jsonSchema = {
76
+ type: "object",
77
+ properties: {
78
+ name: { type: "string" },
79
+ age: { type: "number", required: false }
80
+ }
81
+ };
82
+ const expectedSchema = z.object({
83
+ name: z.string().optional(),
84
+ age: z.number().optional()
85
+ }).optional();
86
+ const result = convertJsonSchemaToZodSchema(jsonSchema, false);
87
+ console.log(convertJsonSchemaToZodSchema(jsonSchema, false));
88
+ const resultSchemaJson = zodToJsonSchema(result);
89
+ const expectedSchemaJson = zodToJsonSchema(expectedSchema);
90
+ expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
91
+ });
92
+ it("should convert a JSON schema with different types to a Zod schema", () => {
93
+ const jsonSchema = {
94
+ type: "object",
95
+ properties: {
96
+ name: { type: "string" },
97
+ age: { type: "number" },
98
+ isAdmin: { type: "boolean" }
99
+ },
100
+ required: ["name", "age", "isAdmin"]
101
+ };
102
+ const expectedSchema = z.object({
103
+ name: z.string(),
104
+ age: z.number(),
105
+ isAdmin: z.boolean()
106
+ });
107
+ const result = convertJsonSchemaToZodSchema(jsonSchema, true);
108
+ const resultSchemaJson = zodToJsonSchema(result);
109
+ const expectedSchemaJson = zodToJsonSchema(expectedSchema);
110
+ expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
111
+ });
112
+ it("should handle edge case where JSON schema has no properties", () => {
113
+ const jsonSchema = {
114
+ type: "object"
115
+ };
116
+ const expectedSchema = z.object({});
117
+ const result = convertJsonSchemaToZodSchema(jsonSchema, true);
118
+ const resultSchemaJson = zodToJsonSchema(result);
119
+ const expectedSchemaJson = zodToJsonSchema(expectedSchema);
120
+ expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
121
+ });
122
+ it("should handle edge case where JSON schema has no required properties", () => {
123
+ const jsonSchema = {
124
+ type: "object",
125
+ properties: {
126
+ name: { type: "string" },
127
+ age: { type: "number" }
128
+ }
129
+ };
130
+ const expectedSchema = z.object({
131
+ name: z.string().optional(),
132
+ age: z.number().optional()
133
+ }).optional();
134
+ const result = convertJsonSchemaToZodSchema(jsonSchema, false);
135
+ const resultSchemaJson = zodToJsonSchema(result);
136
+ const expectedSchemaJson = zodToJsonSchema(expectedSchema);
137
+ expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
138
+ });
139
+ });
140
+ //# sourceMappingURL=json-schema.test.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/json-schema.test.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { convertJsonSchemaToZodSchema } from \"../utils/json-schema\";\nimport { zodToJsonSchema } from \"zod-to-json-schema\";\n\ndescribe(\"convertJsonSchemaToZodSchema\", () => {\n it(\"should convert a simple JSON schema to a Zod schema\", () => {\n const jsonSchema = {\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n age: { type: \"number\" },\n },\n required: [\"name\", \"age\"],\n };\n\n const expectedSchema = z.object({\n name: z.string(),\n age: z.number(),\n });\n\n const result = convertJsonSchemaToZodSchema(jsonSchema, true);\n const resultSchemaJson = zodToJsonSchema(result);\n const expectedSchemaJson = zodToJsonSchema(expectedSchema);\n\n expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);\n });\n\n it(\"should convert a JSON schema with nested objects to a Zod schema\", () => {\n const jsonSchema = {\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n address: {\n type: \"object\",\n properties: {\n street: { type: \"string\" },\n city: { type: \"string\" },\n },\n required: [\"street\", \"city\"],\n },\n },\n required: [\"name\", \"address\"],\n };\n\n const expectedSchema = z.object({\n name: z.string(),\n address: z.object({\n street: z.string(),\n city: z.string(),\n }),\n });\n\n const result = convertJsonSchemaToZodSchema(jsonSchema, true);\n const resultSchemaJson = zodToJsonSchema(result);\n const expectedSchemaJson = zodToJsonSchema(expectedSchema);\n\n expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);\n });\n\n it(\"should convert a JSON schema with arrays to a Zod schema\", () => {\n const jsonSchema = {\n type: \"object\",\n properties: {\n names: {\n type: \"array\",\n items: { type: \"string\" },\n },\n },\n required: [\"names\"],\n };\n\n const expectedSchema = z.object({\n names: z.array(z.string()),\n });\n\n const result = convertJsonSchemaToZodSchema(jsonSchema, true);\n const resultSchemaJson = zodToJsonSchema(result);\n const expectedSchemaJson = zodToJsonSchema(expectedSchema);\n\n expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);\n });\n\n it(\"should convert a JSON schema with optional properties to a Zod schema\", () => {\n const jsonSchema = {\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n age: { type: \"number\", required: false },\n },\n };\n\n const expectedSchema = z\n .object({\n name: z.string().optional(),\n age: z.number().optional(),\n })\n .optional();\n\n const result = convertJsonSchemaToZodSchema(jsonSchema, false);\n\n console.log(convertJsonSchemaToZodSchema(jsonSchema, false));\n\n const resultSchemaJson = zodToJsonSchema(result);\n const expectedSchemaJson = zodToJsonSchema(expectedSchema);\n\n expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);\n });\n\n it(\"should convert a JSON schema with different types to a Zod schema\", () => {\n const jsonSchema = {\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n age: { type: \"number\" },\n isAdmin: { type: \"boolean\" },\n },\n required: [\"name\", \"age\", \"isAdmin\"],\n };\n\n const expectedSchema = z.object({\n name: z.string(),\n age: z.number(),\n isAdmin: z.boolean(),\n });\n\n const result = convertJsonSchemaToZodSchema(jsonSchema, true);\n const resultSchemaJson = zodToJsonSchema(result);\n const expectedSchemaJson = zodToJsonSchema(expectedSchema);\n\n expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);\n });\n\n it(\"should handle edge case where JSON schema has no properties\", () => {\n const jsonSchema = {\n type: \"object\",\n };\n\n const expectedSchema = z.object({});\n\n const result = convertJsonSchemaToZodSchema(jsonSchema, true);\n const resultSchemaJson = zodToJsonSchema(result);\n const expectedSchemaJson = zodToJsonSchema(expectedSchema);\n\n expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);\n });\n\n it(\"should handle edge case where JSON schema has no required properties\", () => {\n const jsonSchema = {\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n age: { type: \"number\" },\n },\n };\n\n const expectedSchema = z\n .object({\n name: z.string().optional(),\n age: z.number().optional(),\n })\n .optional();\n\n const result = convertJsonSchemaToZodSchema(jsonSchema, false);\n const resultSchemaJson = zodToJsonSchema(result);\n const expectedSchemaJson = zodToJsonSchema(expectedSchema);\n\n expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);\n });\n});\n"],"mappings":";;;;;AAAA,SAAS,SAAS;AAElB,SAAS,uBAAuB;AAEhC,SAAS,gCAAgC,MAAM;AAC7C,KAAG,uDAAuD,MAAM;AAC9D,UAAM,aAAa;AAAA,MACjB,MAAM;AAAA,MACN,YAAY;AAAA,QACV,MAAM,EAAE,MAAM,SAAS;AAAA,QACvB,KAAK,EAAE,MAAM,SAAS;AAAA,MACxB;AAAA,MACA,UAAU,CAAC,QAAQ,KAAK;AAAA,IAC1B;AAEA,UAAM,iBAAiB,EAAE,OAAO;AAAA,MAC9B,MAAM,EAAE,OAAO;AAAA,MACf,KAAK,EAAE,OAAO;AAAA,IAChB,CAAC;AAED,UAAM,SAAS,6BAA6B,YAAY,IAAI;AAC5D,UAAM,mBAAmB,gBAAgB,MAAM;AAC/C,UAAM,qBAAqB,gBAAgB,cAAc;AAEzD,WAAO,gBAAgB,EAAE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CAAC;AAElC,UAAM,SAAS,6BAA6B,YAAY,IAAI;AAC5D,UAAM,mBAAmB,gBAAgB,MAAM;AAC/C,UAAM,qBAAqB,gBAAgB,cAAc;AAEzD,WAAO,gBAAgB,EAAE,cAAc,kBAAkB;AAAA,EAC3D,CAAC;AAED,KAAG,wEAAwE,MAAM;AAC/E,UAAM,aAAa;AAAA,MACjB,MAAM;AAAA,MACN,YAAY;AAAA,QACV,MAAM,EAAE,MAAM,SAAS;AAAA,QACvB,KAAK,EAAE,MAAM,SAAS;AAAA,MACxB;AAAA,IACF;AAEA,UAAM,iBAAiB,EACpB,OAAO;AAAA,MACN,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,MAC1B,KAAK,EAAE,OAAO,EAAE,SAAS;AAAA,IAC3B,CAAC,EACA,SAAS;AAEZ,UAAM,SAAS,6BAA6B,YAAY,KAAK;AAC7D,UAAM,mBAAmB,gBAAgB,MAAM;AAC/C,UAAM,qBAAqB,gBAAgB,cAAc;AAEzD,WAAO,gBAAgB,EAAE,cAAc,kBAAkB;AAAA,EAC3D,CAAC;AACH,CAAC;","names":[]}
@@ -0,0 +1,3 @@
1
+ declare function randomId(): string;
2
+
3
+ export { randomId };
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/utils/random-id.ts
21
+ var random_id_exports = {};
22
+ __export(random_id_exports, {
23
+ randomId: () => randomId
24
+ });
25
+ module.exports = __toCommonJS(random_id_exports);
26
+ var import_uuid = require("uuid");
27
+ function randomId() {
28
+ return "ck-" + (0, import_uuid.v4)();
29
+ }
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ randomId
33
+ });
34
+ //# sourceMappingURL=random-id.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/random-id.ts"],"sourcesContent":["import { v4 as uuidv4 } from \"uuid\";\n\nexport function randomId() {\n return \"ck-\" + uuidv4();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;AAEtB,SAAS,WAAW;AACzB,SAAO,YAAQ,YAAAA,IAAO;AACxB;","names":["uuidv4"]}
@@ -0,0 +1,7 @@
1
+ import {
2
+ randomId
3
+ } from "../chunk-RIPX6APP.mjs";
4
+ export {
5
+ randomId
6
+ };
7
+ //# sourceMappingURL=random-id.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/jest.config.js ADDED
@@ -0,0 +1,5 @@
1
+ /** @type {import('ts-jest').JestConfigWithTsJest} */
2
+ module.exports = {
3
+ preset: 'ts-jest',
4
+ testEnvironment: 'node',
5
+ };
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@copilotkit/shared",
3
+ "private": false,
4
+ "homepage": "https://github.com/CopilotKit/CopilotKit",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/CopilotKit/CopilotKit.git"
8
+ },
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "version": "0.0.0-feat-dynamic-copilotcloud-qa-20250117190454",
13
+ "sideEffects": false,
14
+ "main": "./dist/index.js",
15
+ "module": "./dist/index.mjs",
16
+ "exports": {
17
+ ".": {
18
+ "import": "./dist/index.mjs",
19
+ "require": "./dist/index.js",
20
+ "types": "./dist/index.d.ts"
21
+ }
22
+ },
23
+ "types": "./dist/index.d.ts",
24
+ "license": "MIT",
25
+ "devDependencies": {
26
+ "@types/jest": "^29.5.4",
27
+ "@types/uuid": "^10.0.0",
28
+ "eslint": "^8.56.0",
29
+ "jest": "^29.6.4",
30
+ "ts-jest": "^29.1.1",
31
+ "tsup": "^6.7.0",
32
+ "typescript": "^5.2.3",
33
+ "eslint-config-custom": "1.4.6",
34
+ "tsconfig": "1.4.6"
35
+ },
36
+ "dependencies": {
37
+ "@segment/analytics-node": "^2.1.2",
38
+ "chalk": "4.1.2",
39
+ "uuid": "^10.0.0",
40
+ "zod": "^3.23.3",
41
+ "zod-to-json-schema": "^3.23.5"
42
+ },
43
+ "keywords": [
44
+ "copilotkit",
45
+ "copilot",
46
+ "react",
47
+ "nextjs",
48
+ "nodejs",
49
+ "ai",
50
+ "assistant",
51
+ "javascript",
52
+ "automation",
53
+ "textarea"
54
+ ],
55
+ "scripts": {
56
+ "build": "tsup --clean",
57
+ "dev": "tsup --watch --no-splitting",
58
+ "test": "jest --passWithNoTests",
59
+ "check-types": "tsc --noEmit",
60
+ "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist && rm -rf .next",
61
+ "link:global": "pnpm link --global",
62
+ "unlink:global": "pnpm unlink --global"
63
+ }
64
+ }
@@ -0,0 +1,4 @@
1
+ export const COPILOT_CLOUD_API_URL = "https://api.cloud.copilotkit.ai";
2
+ export const COPILOT_CLOUD_VERSION = "v1";
3
+ export const COPILOT_CLOUD_CHAT_URL = `${COPILOT_CLOUD_API_URL}/copilotkit/${COPILOT_CLOUD_VERSION}`;
4
+ export const COPILOT_CLOUD_PUBLIC_API_KEY_HEADER = "X-CopilotCloud-Public-Api-Key";
package/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ export * from "./types";
2
+ export * from "./utils";
3
+ export * from "./constants";
4
+ export * from "./telemetry";
5
+
6
+ import * as packageJson from "../package.json";
7
+ export const COPILOTKIT_VERSION = packageJson.version;
@@ -0,0 +1,35 @@
1
+ export type AnalyticsEvents = {
2
+ "oss.runtime.instance_created": RuntimeInstanceCreatedInfo;
3
+ "oss.runtime.copilot_request_created": {
4
+ "cloud.guardrails.enabled": boolean;
5
+ requestType: string;
6
+ };
7
+ "oss.runtime.server_action_executed": {};
8
+ "oss.runtime.remote_action_executed": RemoteActionExecutionInfo;
9
+ "oss.runtime.agent_execution_stream_started": { hashedLgcKey?: string };
10
+ "oss.runtime.agent_execution_stream_ended": AgentExecutionResponseInfo;
11
+ "oss.runtime.agent_execution_stream_errored": { hashedLgcKey?: string; error?: string };
12
+ };
13
+
14
+ export interface RuntimeInstanceCreatedInfo {
15
+ actionsAmount: number;
16
+ endpointTypes: string[];
17
+ hashedLgcKey?: string;
18
+ endpointsAmount: number;
19
+ agentsAmount?: number | null;
20
+ }
21
+
22
+ export interface RemoteActionExecutionInfo {
23
+ agentExecution: boolean;
24
+ type: "self-hosted" | "langgraph-platform";
25
+ agentsAmount?: number | null;
26
+ hashedLgcKey?: string;
27
+ }
28
+
29
+ export interface AgentExecutionResponseInfo {
30
+ provider?: string;
31
+ model?: string;
32
+ langGraphHost?: string;
33
+ langGraphVersion?: string;
34
+ hashedLgcKey?: string;
35
+ }
@@ -0,0 +1 @@
1
+ export * from "./telemetry-client";
File without changes
@@ -0,0 +1,126 @@
1
+ import { Analytics } from "@segment/analytics-node";
2
+ import { AnalyticsEvents } from "./events";
3
+ import { flattenObject, printSecurityNotice } from "./utils";
4
+ import { v4 as uuidv4 } from "uuid";
5
+
6
+ export class TelemetryClient {
7
+ segment: Analytics | undefined;
8
+ globalProperties: Record<string, any> = {};
9
+ cloudConfiguration: { publicApiKey: string; baseUrl: string } | null = null;
10
+ packageName: string;
11
+ packageVersion: string;
12
+ private telemetryDisabled: boolean = false;
13
+ private sampleRate: number = 0.05;
14
+ private anonymousId = `anon_${uuidv4()}`;
15
+
16
+ constructor({
17
+ packageName,
18
+ packageVersion,
19
+ telemetryDisabled,
20
+ telemetryBaseUrl,
21
+ sampleRate,
22
+ }: {
23
+ packageName: string;
24
+ packageVersion: string;
25
+ telemetryDisabled?: boolean;
26
+ telemetryBaseUrl?: string;
27
+ sampleRate?: number;
28
+ }) {
29
+ this.packageName = packageName;
30
+ this.packageVersion = packageVersion;
31
+ this.telemetryDisabled =
32
+ telemetryDisabled ||
33
+ (process.env as any).COPILOTKIT_TELEMETRY_DISABLED === "true" ||
34
+ (process.env as any).COPILOTKIT_TELEMETRY_DISABLED === "1" ||
35
+ (process.env as any).DO_NOT_TRACK === "true" ||
36
+ (process.env as any).DO_NOT_TRACK === "1";
37
+
38
+ if (this.telemetryDisabled) {
39
+ return;
40
+ }
41
+
42
+ this.setSampleRate(sampleRate);
43
+
44
+ // eslint-disable-next-line
45
+ const writeKey = process.env.COPILOTKIT_SEGMENT_WRITE_KEY || "n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja";
46
+
47
+ this.segment = new Analytics({
48
+ writeKey,
49
+ });
50
+
51
+ this.setGlobalProperties({
52
+ "copilotkit.package.name": packageName,
53
+ "copilotkit.package.version": packageVersion,
54
+ });
55
+ }
56
+
57
+ private shouldSendEvent() {
58
+ const randomNumber = Math.random();
59
+ return randomNumber < this.sampleRate;
60
+ }
61
+
62
+ async capture<K extends keyof AnalyticsEvents>(event: K, properties: AnalyticsEvents[K]) {
63
+ if (!this.shouldSendEvent() || !this.segment) {
64
+ return;
65
+ }
66
+
67
+ const flattenedProperties = flattenObject(properties);
68
+ const propertiesWithGlobal = {
69
+ ...this.globalProperties,
70
+ ...flattenedProperties,
71
+ };
72
+ const orderedPropertiesWithGlobal = Object.keys(propertiesWithGlobal)
73
+ .sort()
74
+ .reduce(
75
+ (obj, key) => {
76
+ obj[key] = propertiesWithGlobal[key];
77
+ return obj;
78
+ },
79
+ {} as Record<string, any>,
80
+ );
81
+
82
+ this.segment.track({
83
+ anonymousId: this.anonymousId,
84
+ event,
85
+ properties: { ...orderedPropertiesWithGlobal },
86
+ });
87
+ }
88
+
89
+ setGlobalProperties(properties: Record<string, any>) {
90
+ const flattenedProperties = flattenObject(properties);
91
+ this.globalProperties = { ...this.globalProperties, ...flattenedProperties };
92
+ }
93
+
94
+ setCloudConfiguration(properties: { publicApiKey: string; baseUrl: string }) {
95
+ this.cloudConfiguration = properties;
96
+
97
+ this.setGlobalProperties({
98
+ cloud: {
99
+ publicApiKey: properties.publicApiKey,
100
+ baseUrl: properties.baseUrl,
101
+ },
102
+ });
103
+ }
104
+
105
+ private setSampleRate(sampleRate: number | undefined) {
106
+ let _sampleRate: number;
107
+
108
+ _sampleRate = sampleRate ?? 0.05;
109
+
110
+ // eslint-disable-next-line
111
+ if (process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE) {
112
+ // eslint-disable-next-line
113
+ _sampleRate = parseFloat(process.env.COPILOTKIT_TELEMETRY_SAMPLE_RATE);
114
+ }
115
+
116
+ if (_sampleRate < 0 || _sampleRate > 1) {
117
+ throw new Error("Sample rate must be between 0 and 1");
118
+ }
119
+
120
+ this.sampleRate = _sampleRate;
121
+ this.setGlobalProperties({
122
+ sampleRate: this.sampleRate,
123
+ sampleRateAdjustmentFactor: 1 - this.sampleRate,
124
+ });
125
+ }
126
+ }
@@ -0,0 +1,39 @@
1
+ import chalk from "chalk";
2
+
3
+ export function flattenObject(
4
+ obj: Record<string, any>,
5
+ parentKey = "",
6
+ res: Record<string, any> = {},
7
+ ): Record<string, any> {
8
+ for (let key in obj) {
9
+ const propName = parentKey ? `${parentKey}.${key}` : key;
10
+ if (typeof obj[key] === "object" && obj[key] !== null) {
11
+ flattenObject(obj[key], propName, res);
12
+ } else {
13
+ res[propName] = obj[key];
14
+ }
15
+ }
16
+ return res;
17
+ }
18
+
19
+ export function printSecurityNotice(advisory: {
20
+ advisory: string | null;
21
+ message: string;
22
+ severity: "low" | "medium" | "high" | "none";
23
+ }) {
24
+ const severityColor =
25
+ {
26
+ low: chalk.blue,
27
+ medium: chalk.yellow,
28
+ high: chalk.red,
29
+ }[advisory.severity.toLowerCase()] || chalk.white;
30
+
31
+ console.log();
32
+ console.log(`━━━━━━━━━━━━━━━━━━ ${chalk.bold(`CopilotKit`)} ━━━━━━━━━━━━━━━━━━`);
33
+ console.log();
34
+ console.log(`${chalk.bold(`Severity: ${severityColor(advisory.severity.toUpperCase())}`)}`);
35
+ console.log();
36
+ console.log(`${chalk.bold(advisory.message)}`);
37
+ console.log();
38
+ console.log(`━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`);
39
+ }
@@ -0,0 +1,128 @@
1
+ type TypeMap = {
2
+ string: string;
3
+ number: number;
4
+ boolean: boolean;
5
+ object: object;
6
+ "string[]": string[];
7
+ "number[]": number[];
8
+ "boolean[]": boolean[];
9
+ "object[]": object[];
10
+ };
11
+
12
+ type AbstractParameter = {
13
+ name: string;
14
+ type?: keyof TypeMap;
15
+ description?: string;
16
+ required?: boolean;
17
+ };
18
+
19
+ interface StringParameter extends AbstractParameter {
20
+ type: "string";
21
+ enum?: string[];
22
+ }
23
+
24
+ interface ObjectParameter extends AbstractParameter {
25
+ type: "object";
26
+ attributes?: Parameter[];
27
+ }
28
+
29
+ interface ObjectArrayParameter extends AbstractParameter {
30
+ type: "object[]";
31
+ attributes?: Parameter[];
32
+ }
33
+
34
+ type SpecialParameters = StringParameter | ObjectParameter | ObjectArrayParameter;
35
+ interface BaseParameter extends AbstractParameter {
36
+ type?: Exclude<AbstractParameter["type"], SpecialParameters["type"]>;
37
+ }
38
+
39
+ export type Parameter = BaseParameter | SpecialParameters;
40
+
41
+ type OptionalParameterType<P extends AbstractParameter> = P["required"] extends false
42
+ ? undefined
43
+ : never;
44
+
45
+ type StringParameterType<P> = P extends StringParameter
46
+ ? P extends { enum?: Array<infer E> }
47
+ ? E
48
+ : string
49
+ : never;
50
+
51
+ type ObjectParameterType<P> = P extends ObjectParameter
52
+ ? P extends { attributes?: infer Attributes extends Parameter[] }
53
+ ? MappedParameterTypes<Attributes>
54
+ : object
55
+ : never;
56
+
57
+ type ObjectArrayParameterType<P> = P extends ObjectArrayParameter
58
+ ? P extends { attributes?: infer Attributes extends Parameter[] }
59
+ ? MappedParameterTypes<Attributes>[]
60
+ : any[]
61
+ : never;
62
+
63
+ type MappedTypeOrString<T> = T extends keyof TypeMap ? TypeMap[T] : string;
64
+ type BaseParameterType<P extends AbstractParameter> = P extends { type: infer T }
65
+ ? T extends BaseParameter["type"]
66
+ ? MappedTypeOrString<T>
67
+ : never
68
+ : string;
69
+
70
+ export type MappedParameterTypes<T extends Parameter[] | [] = []> = T extends []
71
+ ? Record<string, any>
72
+ : {
73
+ [P in T[number] as P["name"]]:
74
+ | OptionalParameterType<P>
75
+ | StringParameterType<P>
76
+ | ObjectParameterType<P>
77
+ | ObjectArrayParameterType<P>
78
+ | BaseParameterType<P>;
79
+ };
80
+
81
+ export type Action<T extends Parameter[] | [] = []> = {
82
+ name: string;
83
+ description?: string;
84
+ parameters?: T;
85
+ handler?: T extends []
86
+ ? () => any | Promise<any>
87
+ : (args: MappedParameterTypes<T>) => any | Promise<any>;
88
+ };
89
+
90
+ // This is the original "ceiling is being raised" version of MappedParameterTypes.
91
+ //
92
+ // ceiling is being raised. cursor's copilot helped us write "superhuman code"
93
+ // for a critical feature. We can read this code, but VERY few engineers out
94
+ // there could write it from scratch.
95
+ // Took lots of convincing too. "come on, this must be possible, try harder".
96
+ // and obviously- done in parts.
97
+ //
98
+ // - https://twitter.com/ataiiam/status/1765089261374914957
99
+ // (Mar 5, 2024)
100
+ //
101
+ // export type MappedParameterTypes<T extends Parameter[]> = {
102
+ // // Check if the parameter has an 'enum' defined
103
+ // [P in T[number] as P["name"]]: P extends { enum: Array<infer E> }
104
+ // ? E extends string // Ensure the enum values are strings
105
+ // ? P["required"] extends false // Check if the parameter is optional
106
+ // ? E | undefined // If so, include 'undefined' in the type
107
+ // : E // Otherwise, use the enum type directly
108
+ // : never // This case should not occur since 'enum' implies string values
109
+ // : // Handle parameters defined as 'object' with specified attributes
110
+ // P extends { type: "object"; attributes: infer Attributes }
111
+ // ? Attributes extends Parameter[]
112
+ // ? MappedParameterTypes<Attributes> // Recursively map the attributes of the object
113
+ // : never // If 'attributes' is not an array of Parameters, this is invalid
114
+ // : // Handle parameters defined as 'object[]' without specified attributes
115
+ // P extends { type: "object[]"; attributes?: never }
116
+ // ? any[] // Default to 'any[]' for arrays of objects without specific attributes
117
+ // : // Handle parameters defined as 'object[]' with specified attributes
118
+ // P extends { type: "object[]"; attributes: infer Attributes }
119
+ // ? Attributes extends Parameter[]
120
+ // ? MappedParameterTypes<Attributes>[] // Recursively map each object in the array
121
+ // : any[] // Default to 'any[]' if attributes are not properly defined
122
+ // : // Handle all other parameter types
123
+ // P["required"] extends false
124
+ // ? // Include 'undefined' for optional parameters
125
+ // TypeMap[P["type"] extends keyof TypeMap ? P["type"] : "string"] | undefined
126
+ // : // Use the direct mapping from 'TypeMap' for the parameter's type
127
+ // TypeMap[P["type"] extends keyof TypeMap ? P["type"] : "string"];
128
+ // };
@@ -0,0 +1,11 @@
1
+ export interface CopilotCloudConfig {
2
+ guardrails: {
3
+ input: {
4
+ restrictToTopic: {
5
+ enabled: boolean;
6
+ validTopics: string[];
7
+ invalidTopics: string[];
8
+ };
9
+ };
10
+ };
11
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./openai-assistant";
2
+ export * from "./action";
3
+ export * from "./copilot-cloud-config";
4
+ export * from "./utility";