@copilotkit/shared 2.0.0-rc.3 → 2.0.0-rc.31
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/README.md +3 -14
- package/dist/a2ui-envelope.cjs +2 -2
- package/dist/a2ui-envelope.cjs.map +1 -1
- package/dist/a2ui-envelope.d.cts +1 -1
- package/dist/a2ui-envelope.d.cts.map +1 -1
- package/dist/a2ui-envelope.d.mts +1 -1
- package/dist/a2ui-envelope.d.mts.map +1 -1
- package/dist/a2ui-envelope.mjs +2 -2
- package/dist/a2ui-envelope.mjs.map +1 -1
- package/dist/a2ui-prompts.cjs +21 -62
- package/dist/a2ui-prompts.cjs.map +1 -1
- package/dist/a2ui-prompts.d.cts +8 -1
- package/dist/a2ui-prompts.d.cts.map +1 -1
- package/dist/a2ui-prompts.d.mts +8 -1
- package/dist/a2ui-prompts.d.mts.map +1 -1
- package/dist/a2ui-prompts.mjs +22 -62
- package/dist/a2ui-prompts.mjs.map +1 -1
- package/dist/attachments/types.d.cts +1 -3
- package/dist/attachments/types.d.cts.map +1 -1
- package/dist/attachments/types.d.mts +1 -3
- package/dist/attachments/types.d.mts.map +1 -1
- package/dist/attachments/utils.cjs +16 -5
- package/dist/attachments/utils.cjs.map +1 -1
- package/dist/attachments/utils.d.cts +3 -1
- package/dist/attachments/utils.d.cts.map +1 -1
- package/dist/attachments/utils.d.mts +3 -1
- package/dist/attachments/utils.d.mts.map +1 -1
- package/dist/attachments/utils.mjs +16 -5
- package/dist/attachments/utils.mjs.map +1 -1
- package/dist/finalize-events.cjs +16 -0
- package/dist/finalize-events.cjs.map +1 -1
- package/dist/finalize-events.d.cts.map +1 -1
- package/dist/finalize-events.d.mts.map +1 -1
- package/dist/finalize-events.mjs +16 -0
- package/dist/finalize-events.mjs.map +1 -1
- package/dist/generative-ui/basic-functions.cjs +1 -1
- package/dist/generative-ui/basic-functions.cjs.map +1 -1
- package/dist/generative-ui/basic-functions.mjs +1 -1
- package/dist/generative-ui/basic-functions.mjs.map +1 -1
- package/dist/generative-ui/child-refs.cjs +3 -3
- package/dist/generative-ui/child-refs.cjs.map +1 -1
- package/dist/generative-ui/child-refs.d.cts.map +1 -1
- package/dist/generative-ui/child-refs.d.mts.map +1 -1
- package/dist/generative-ui/child-refs.mjs +3 -3
- package/dist/generative-ui/child-refs.mjs.map +1 -1
- package/dist/generative-ui/compact-schema.cjs +187 -0
- package/dist/generative-ui/compact-schema.cjs.map +1 -0
- package/dist/generative-ui/compact-schema.d.cts +55 -0
- package/dist/generative-ui/compact-schema.d.cts.map +1 -0
- package/dist/generative-ui/compact-schema.d.mts +55 -0
- package/dist/generative-ui/compact-schema.d.mts.map +1 -0
- package/dist/generative-ui/compact-schema.mjs +185 -0
- package/dist/generative-ui/compact-schema.mjs.map +1 -0
- package/dist/generative-ui/prompt-spec.cjs +225 -0
- package/dist/generative-ui/prompt-spec.cjs.map +1 -0
- package/dist/generative-ui/prompt-spec.d.cts +94 -0
- package/dist/generative-ui/prompt-spec.d.cts.map +1 -0
- package/dist/generative-ui/prompt-spec.d.mts +94 -0
- package/dist/generative-ui/prompt-spec.d.mts.map +1 -0
- package/dist/generative-ui/prompt-spec.mjs +220 -0
- package/dist/generative-ui/prompt-spec.mjs.map +1 -0
- package/dist/generative-ui/prompt.cjs +10 -36
- package/dist/generative-ui/prompt.cjs.map +1 -1
- package/dist/generative-ui/prompt.d.cts +2 -1
- package/dist/generative-ui/prompt.d.cts.map +1 -1
- package/dist/generative-ui/prompt.d.mts +2 -1
- package/dist/generative-ui/prompt.d.mts.map +1 -1
- package/dist/generative-ui/prompt.mjs +12 -38
- package/dist/generative-ui/prompt.mjs.map +1 -1
- package/dist/generative-ui/render-ui-args.cjs +1 -0
- package/dist/generative-ui/render-ui-args.cjs.map +1 -1
- package/dist/generative-ui/render-ui-args.d.cts.map +1 -1
- package/dist/generative-ui/render-ui-args.d.mts.map +1 -1
- package/dist/generative-ui/render-ui-args.mjs +1 -0
- package/dist/generative-ui/render-ui-args.mjs.map +1 -1
- package/dist/generative-ui/schema-render.cjs +242 -0
- package/dist/generative-ui/schema-render.cjs.map +1 -0
- package/dist/generative-ui/schema-render.d.cts +44 -0
- package/dist/generative-ui/schema-render.d.cts.map +1 -0
- package/dist/generative-ui/schema-render.d.mts +44 -0
- package/dist/generative-ui/schema-render.d.mts.map +1 -0
- package/dist/generative-ui/schema-render.mjs +239 -0
- package/dist/generative-ui/schema-render.mjs.map +1 -0
- package/dist/generative-ui/types.cjs +2 -2
- package/dist/generative-ui/types.cjs.map +1 -1
- package/dist/generative-ui/types.d.cts +7 -7
- package/dist/generative-ui/types.d.cts.map +1 -1
- package/dist/generative-ui/types.d.mts +7 -7
- package/dist/generative-ui/types.d.mts.map +1 -1
- package/dist/generative-ui/types.mjs +2 -2
- package/dist/generative-ui/types.mjs.map +1 -1
- package/dist/generative-ui/validate-operation.cjs +2 -2
- package/dist/generative-ui/validate-operation.cjs.map +1 -1
- package/dist/generative-ui/validate-operation.mjs +2 -2
- package/dist/generative-ui/validate-operation.mjs.map +1 -1
- package/dist/index.cjs +16 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -10
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +10 -10
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +9 -8
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +866 -455
- package/dist/index.umd.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/standard-schema.cjs +20 -7
- package/dist/standard-schema.cjs.map +1 -1
- package/dist/standard-schema.d.cts +15 -16
- package/dist/standard-schema.d.cts.map +1 -1
- package/dist/standard-schema.d.mts +15 -16
- package/dist/standard-schema.d.mts.map +1 -1
- package/dist/standard-schema.mjs +20 -8
- package/dist/standard-schema.mjs.map +1 -1
- package/dist/telemetry/lambda-client.cjs +1 -1
- package/dist/telemetry/lambda-client.cjs.map +1 -1
- package/dist/telemetry/lambda-client.d.cts.map +1 -1
- package/dist/telemetry/lambda-client.d.mts.map +1 -1
- package/dist/telemetry/lambda-client.mjs +1 -1
- package/dist/telemetry/lambda-client.mjs.map +1 -1
- package/dist/telemetry/telemetry-disabled.cjs +0 -5
- package/dist/telemetry/telemetry-disabled.cjs.map +1 -1
- package/dist/telemetry/telemetry-disabled.d.cts +0 -5
- package/dist/telemetry/telemetry-disabled.d.cts.map +1 -1
- package/dist/telemetry/telemetry-disabled.d.mts +0 -5
- package/dist/telemetry/telemetry-disabled.d.mts.map +1 -1
- package/dist/telemetry/telemetry-disabled.mjs +0 -5
- package/dist/telemetry/telemetry-disabled.mjs.map +1 -1
- package/dist/types/message.d.cts +1 -18
- package/dist/types/message.d.cts.map +1 -1
- package/dist/types/message.d.mts +1 -18
- package/dist/types/message.d.mts.map +1 -1
- package/dist/utils/errors.cjs +5 -42
- package/dist/utils/errors.cjs.map +1 -1
- package/dist/utils/errors.d.cts +16 -34
- package/dist/utils/errors.d.cts.map +1 -1
- package/dist/utils/errors.d.mts +16 -34
- package/dist/utils/errors.d.mts.map +1 -1
- package/dist/utils/errors.mjs +6 -41
- package/dist/utils/errors.mjs.map +1 -1
- package/dist/utils/index.cjs +0 -2
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +4 -6
- package/dist/utils/index.d.cts.map +1 -1
- package/dist/utils/index.d.mts +4 -6
- package/dist/utils/index.d.mts.map +1 -1
- package/dist/utils/index.mjs +4 -6
- package/dist/utils/index.mjs.map +1 -1
- package/dist/utils/inspector-visibility.cjs +25 -3
- package/dist/utils/inspector-visibility.cjs.map +1 -1
- package/dist/utils/inspector-visibility.d.cts +26 -3
- package/dist/utils/inspector-visibility.d.cts.map +1 -1
- package/dist/utils/inspector-visibility.d.mts +26 -3
- package/dist/utils/inspector-visibility.d.mts.map +1 -1
- package/dist/utils/inspector-visibility.mjs +25 -4
- package/dist/utils/inspector-visibility.mjs.map +1 -1
- package/dist/utils/json-schema.cjs +4 -79
- package/dist/utils/json-schema.cjs.map +1 -1
- package/dist/utils/json-schema.d.cts +1 -4
- package/dist/utils/json-schema.d.cts.map +1 -1
- package/dist/utils/json-schema.d.mts +1 -4
- package/dist/utils/json-schema.d.mts.map +1 -1
- package/dist/utils/json-schema.mjs +5 -78
- package/dist/utils/json-schema.mjs.map +1 -1
- package/dist/utils/random-id.cjs +13 -26
- package/dist/utils/random-id.cjs.map +1 -1
- package/dist/utils/random-id.d.cts +6 -3
- package/dist/utils/random-id.d.cts.map +1 -1
- package/dist/utils/random-id.d.mts +6 -3
- package/dist/utils/random-id.d.mts.map +1 -1
- package/dist/utils/random-id.mjs +14 -25
- package/dist/utils/random-id.mjs.map +1 -1
- package/package.json +10 -34
- package/scripts/verify-cjs-exports.cjs +1 -1
- package/src/__tests__/a2ui-envelope.test.ts +18 -13
- package/src/__tests__/a2ui-prompts.test.ts +47 -14
- package/src/__tests__/fixtures/prompt-goldens.json +354 -0
- package/src/__tests__/prompt-spec.test.ts +191 -0
- package/src/__tests__/root-entry-browser-safety.test.ts +5 -7
- package/src/__tests__/schema-render.test.ts +245 -0
- package/src/__tests__/standard-schema.test.ts +61 -101
- package/src/a2ui-envelope.ts +7 -6
- package/src/a2ui-prompts.ts +47 -96
- package/src/attachments/__tests__/utils.test.ts +22 -0
- package/src/attachments/types.ts +1 -3
- package/src/attachments/utils.ts +23 -5
- package/src/finalize-events.ts +16 -0
- package/src/generative-ui/__tests__/render-ui-args.test.ts +7 -7
- package/src/generative-ui/__tests__/validate-operation.test.ts +19 -13
- package/src/generative-ui/basic-functions.ts +1 -1
- package/src/generative-ui/child-refs.ts +5 -4
- package/src/generative-ui/compact-schema.ts +277 -0
- package/src/generative-ui/index.ts +3 -0
- package/src/generative-ui/prompt-spec.ts +335 -0
- package/src/generative-ui/prompt.ts +25 -75
- package/src/generative-ui/render-ui-args.ts +3 -0
- package/src/generative-ui/schema-render.ts +377 -0
- package/src/generative-ui/types.ts +10 -7
- package/src/generative-ui/validate-operation.ts +2 -2
- package/src/index.ts +3 -16
- package/src/standard-schema.ts +24 -27
- package/src/telemetry/lambda-client.ts +8 -3
- package/src/telemetry/model-host.test.ts +2 -5
- package/src/telemetry/telemetry-disabled.ts +0 -5
- package/src/types/message.ts +1 -19
- package/src/utils/__tests__/errors.test.ts +44 -0
- package/src/utils/__tests__/json-schema.test.ts +3 -479
- package/src/utils/__tests__/random-id.test.ts +37 -0
- package/src/utils/errors.ts +28 -85
- package/src/utils/index.ts +0 -2
- package/src/utils/inspector-visibility.test.ts +26 -0
- package/src/utils/inspector-visibility.ts +35 -3
- package/src/utils/json-schema.ts +5 -152
- package/src/utils/random-id.ts +17 -37
- package/tsconfig.json +3 -1
- package/tsdown.config.ts +2 -19
- package/dist/event-transforms/index.cjs +0 -15
- package/dist/event-transforms/index.d.cts +0 -4
- package/dist/event-transforms/index.d.mts +0 -4
- package/dist/event-transforms/index.mjs +0 -5
- package/dist/event-transforms/open-generative-ui-middleware.cjs +0 -286
- package/dist/event-transforms/open-generative-ui-middleware.cjs.map +0 -1
- package/dist/event-transforms/open-generative-ui-middleware.d.cts +0 -60
- package/dist/event-transforms/open-generative-ui-middleware.d.cts.map +0 -1
- package/dist/event-transforms/open-generative-ui-middleware.d.mts +0 -60
- package/dist/event-transforms/open-generative-ui-middleware.d.mts.map +0 -1
- package/dist/event-transforms/open-generative-ui-middleware.mjs +0 -283
- package/dist/event-transforms/open-generative-ui-middleware.mjs.map +0 -1
- package/dist/event-transforms/recorded-events.cjs +0 -59
- package/dist/event-transforms/recorded-events.cjs.map +0 -1
- package/dist/event-transforms/recorded-events.d.cts +0 -23
- package/dist/event-transforms/recorded-events.d.cts.map +0 -1
- package/dist/event-transforms/recorded-events.d.mts +0 -23
- package/dist/event-transforms/recorded-events.d.mts.map +0 -1
- package/dist/event-transforms/recorded-events.mjs +0 -58
- package/dist/event-transforms/recorded-events.mjs.map +0 -1
- package/dist/telemetry/events.d.cts +0 -72
- package/dist/telemetry/events.d.cts.map +0 -1
- package/dist/telemetry/events.d.mts +0 -72
- package/dist/telemetry/events.d.mts.map +0 -1
- package/dist/telemetry/index.cjs +0 -18
- package/dist/telemetry/index.d.cts +0 -5
- package/dist/telemetry/index.d.mts +0 -5
- package/dist/telemetry/index.mjs +0 -6
- package/dist/telemetry/telemetry-client.cjs +0 -165
- package/dist/telemetry/telemetry-client.cjs.map +0 -1
- package/dist/telemetry/telemetry-client.d.cts +0 -87
- package/dist/telemetry/telemetry-client.d.cts.map +0 -1
- package/dist/telemetry/telemetry-client.d.mts +0 -87
- package/dist/telemetry/telemetry-client.d.mts.map +0 -1
- package/dist/telemetry/telemetry-client.mjs +0 -164
- package/dist/telemetry/telemetry-client.mjs.map +0 -1
- package/dist/telemetry/utils.cjs +0 -14
- package/dist/telemetry/utils.cjs.map +0 -1
- package/dist/telemetry/utils.mjs +0 -13
- package/dist/telemetry/utils.mjs.map +0 -1
- package/dist/utils/conditions.cjs +0 -32
- package/dist/utils/conditions.cjs.map +0 -1
- package/dist/utils/conditions.d.cts +0 -31
- package/dist/utils/conditions.d.cts.map +0 -1
- package/dist/utils/conditions.d.mts +0 -31
- package/dist/utils/conditions.d.mts.map +0 -1
- package/dist/utils/conditions.mjs +0 -31
- package/dist/utils/conditions.mjs.map +0 -1
- package/dist/utils/console-styling.cjs +0 -91
- package/dist/utils/console-styling.cjs.map +0 -1
- package/dist/utils/console-styling.d.cts +0 -65
- package/dist/utils/console-styling.d.cts.map +0 -1
- package/dist/utils/console-styling.d.mts +0 -65
- package/dist/utils/console-styling.d.mts.map +0 -1
- package/dist/utils/console-styling.mjs +0 -85
- package/dist/utils/console-styling.mjs.map +0 -1
- package/src/__tests__/zod-regression.test.ts +0 -319
- package/src/event-transforms/index.ts +0 -5
- package/src/event-transforms/open-generative-ui-middleware.ts +0 -392
- package/src/event-transforms/recorded-events.test.ts +0 -166
- package/src/event-transforms/recorded-events.ts +0 -74
- package/src/telemetry/events.ts +0 -68
- package/src/telemetry/index.ts +0 -9
- package/src/telemetry/telemetry-blank-license-identity.test.ts +0 -128
- package/src/telemetry/telemetry-client.test.ts +0 -798
- package/src/telemetry/telemetry-client.ts +0 -328
- package/src/telemetry/utils.ts +0 -15
- package/src/utils/__tests__/conditions.test.ts +0 -161
- package/src/utils/conditions.ts +0 -116
- package/src/utils/console-styling.ts +0 -126
|
@@ -1,486 +1,10 @@
|
|
|
1
|
-
import { describe, it, expect
|
|
2
|
-
import {
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import type { JSONSchema } from "../json-schema";
|
|
3
3
|
import {
|
|
4
|
-
convertJsonSchemaToZodSchema,
|
|
5
4
|
actionParametersToJsonSchema,
|
|
6
5
|
jsonSchemaToActionParameters,
|
|
7
|
-
JSONSchema,
|
|
8
6
|
} from "../json-schema";
|
|
9
|
-
import {
|
|
10
|
-
import { Parameter } from "../../types";
|
|
11
|
-
|
|
12
|
-
describe("convertJsonSchemaToZodSchema", () => {
|
|
13
|
-
it("should convert a simple JSON schema to a Zod schema", () => {
|
|
14
|
-
const jsonSchema = {
|
|
15
|
-
type: "object",
|
|
16
|
-
properties: {
|
|
17
|
-
name: { type: "string" },
|
|
18
|
-
age: { type: "number" },
|
|
19
|
-
},
|
|
20
|
-
required: ["name", "age"],
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const expectedSchema = z.object({
|
|
24
|
-
name: z.string(),
|
|
25
|
-
age: z.number(),
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
29
|
-
const resultSchemaJson = zodToJsonSchema(result);
|
|
30
|
-
const expectedSchemaJson = zodToJsonSchema(expectedSchema);
|
|
31
|
-
|
|
32
|
-
expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("should convert a JSON schema with nested objects to a Zod schema", () => {
|
|
36
|
-
const jsonSchema = {
|
|
37
|
-
type: "object",
|
|
38
|
-
properties: {
|
|
39
|
-
name: { type: "string" },
|
|
40
|
-
address: {
|
|
41
|
-
type: "object",
|
|
42
|
-
properties: {
|
|
43
|
-
street: { type: "string" },
|
|
44
|
-
city: { type: "string" },
|
|
45
|
-
},
|
|
46
|
-
required: ["street", "city"],
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
required: ["name", "address"],
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const expectedSchema = z.object({
|
|
53
|
-
name: z.string(),
|
|
54
|
-
address: z.object({
|
|
55
|
-
street: z.string(),
|
|
56
|
-
city: z.string(),
|
|
57
|
-
}),
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
61
|
-
const resultSchemaJson = zodToJsonSchema(result);
|
|
62
|
-
const expectedSchemaJson = zodToJsonSchema(expectedSchema);
|
|
63
|
-
|
|
64
|
-
expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("should convert a JSON schema with arrays to a Zod schema", () => {
|
|
68
|
-
const jsonSchema = {
|
|
69
|
-
type: "object",
|
|
70
|
-
properties: {
|
|
71
|
-
names: {
|
|
72
|
-
type: "array",
|
|
73
|
-
items: { type: "string" },
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
required: ["names"],
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const expectedSchema = z.object({
|
|
80
|
-
names: z.array(z.string()),
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
84
|
-
const resultSchemaJson = zodToJsonSchema(result);
|
|
85
|
-
const expectedSchemaJson = zodToJsonSchema(expectedSchema);
|
|
86
|
-
|
|
87
|
-
expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it("should convert a JSON schema with optional properties to a Zod schema", () => {
|
|
91
|
-
const jsonSchema = {
|
|
92
|
-
type: "object",
|
|
93
|
-
properties: {
|
|
94
|
-
name: { type: "string" },
|
|
95
|
-
age: { type: "number", required: false },
|
|
96
|
-
},
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const expectedSchema = z
|
|
100
|
-
.object({
|
|
101
|
-
name: z.string().optional(),
|
|
102
|
-
age: z.number().optional(),
|
|
103
|
-
})
|
|
104
|
-
.optional();
|
|
105
|
-
|
|
106
|
-
const result = convertJsonSchemaToZodSchema(jsonSchema, false);
|
|
107
|
-
|
|
108
|
-
console.log(convertJsonSchemaToZodSchema(jsonSchema, false));
|
|
109
|
-
|
|
110
|
-
const resultSchemaJson = zodToJsonSchema(result);
|
|
111
|
-
const expectedSchemaJson = zodToJsonSchema(expectedSchema);
|
|
112
|
-
|
|
113
|
-
expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("should convert a JSON schema with different types to a Zod schema", () => {
|
|
117
|
-
const jsonSchema = {
|
|
118
|
-
type: "object",
|
|
119
|
-
properties: {
|
|
120
|
-
name: { type: "string" },
|
|
121
|
-
age: { type: "number" },
|
|
122
|
-
isAdmin: { type: "boolean" },
|
|
123
|
-
},
|
|
124
|
-
required: ["name", "age", "isAdmin"],
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
const expectedSchema = z.object({
|
|
128
|
-
name: z.string(),
|
|
129
|
-
age: z.number(),
|
|
130
|
-
isAdmin: z.boolean(),
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
134
|
-
const resultSchemaJson = zodToJsonSchema(result);
|
|
135
|
-
const expectedSchemaJson = zodToJsonSchema(expectedSchema);
|
|
136
|
-
|
|
137
|
-
expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it("should handle edge case where JSON schema has no properties", () => {
|
|
141
|
-
const jsonSchema = {
|
|
142
|
-
type: "object",
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
const expectedSchema = z.object({});
|
|
146
|
-
|
|
147
|
-
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
148
|
-
const resultSchemaJson = zodToJsonSchema(result);
|
|
149
|
-
const expectedSchemaJson = zodToJsonSchema(expectedSchema);
|
|
150
|
-
|
|
151
|
-
expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it("should preserve string enum constraints", () => {
|
|
155
|
-
const jsonSchema = {
|
|
156
|
-
type: "object",
|
|
157
|
-
properties: {
|
|
158
|
-
status: {
|
|
159
|
-
type: "string",
|
|
160
|
-
description: "The status",
|
|
161
|
-
enum: ["todo", "done"],
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
required: ["status"],
|
|
165
|
-
};
|
|
166
|
-
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
167
|
-
const statusSchema = (result as z.ZodObject<any>).shape.status;
|
|
168
|
-
expect(statusSchema._def.typeName).toBe("ZodEnum");
|
|
169
|
-
expect(statusSchema._def.values).toEqual(["todo", "done"]);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it("should handle null-union type ['string', 'null'] as nullable", () => {
|
|
173
|
-
const jsonSchema = {
|
|
174
|
-
type: "object",
|
|
175
|
-
properties: {
|
|
176
|
-
nickname: {
|
|
177
|
-
type: ["string", "null"],
|
|
178
|
-
description: "Optional nickname",
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
required: ["nickname"],
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
185
|
-
const shape = (result as z.ZodObject<any>).shape;
|
|
186
|
-
|
|
187
|
-
// The nickname field should accept both string and null
|
|
188
|
-
expect(shape.nickname.safeParse("hello").success).toBe(true);
|
|
189
|
-
expect(shape.nickname.safeParse(null).success).toBe(true);
|
|
190
|
-
expect(shape.nickname.safeParse(42).success).toBe(false);
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it("should handle null-union type ['number', 'null'] as nullable number", () => {
|
|
194
|
-
const jsonSchema = {
|
|
195
|
-
type: "object",
|
|
196
|
-
properties: {
|
|
197
|
-
score: {
|
|
198
|
-
type: ["number", "null"],
|
|
199
|
-
},
|
|
200
|
-
},
|
|
201
|
-
required: ["score"],
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
205
|
-
const shape = (result as z.ZodObject<any>).shape;
|
|
206
|
-
|
|
207
|
-
expect(shape.score.safeParse(42).success).toBe(true);
|
|
208
|
-
expect(shape.score.safeParse(null).success).toBe(true);
|
|
209
|
-
expect(shape.score.safeParse("hello").success).toBe(false);
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it("should handle edge case where JSON schema has no required properties", () => {
|
|
213
|
-
const jsonSchema = {
|
|
214
|
-
type: "object",
|
|
215
|
-
properties: {
|
|
216
|
-
name: { type: "string" },
|
|
217
|
-
age: { type: "number" },
|
|
218
|
-
},
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
const expectedSchema = z
|
|
222
|
-
.object({
|
|
223
|
-
name: z.string().optional(),
|
|
224
|
-
age: z.number().optional(),
|
|
225
|
-
})
|
|
226
|
-
.optional();
|
|
227
|
-
|
|
228
|
-
const result = convertJsonSchemaToZodSchema(jsonSchema, false);
|
|
229
|
-
const resultSchemaJson = zodToJsonSchema(result);
|
|
230
|
-
const expectedSchemaJson = zodToJsonSchema(expectedSchema);
|
|
231
|
-
|
|
232
|
-
expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
it("should resolve non-circular $ref definitions correctly", () => {
|
|
236
|
-
const jsonSchema = {
|
|
237
|
-
type: "object",
|
|
238
|
-
properties: {
|
|
239
|
-
address: { $ref: "#/$defs/Address" },
|
|
240
|
-
},
|
|
241
|
-
required: ["address"],
|
|
242
|
-
$defs: {
|
|
243
|
-
Address: {
|
|
244
|
-
type: "object",
|
|
245
|
-
properties: {
|
|
246
|
-
street: { type: "string", description: "Street name" },
|
|
247
|
-
city: { type: "string", description: "City name" },
|
|
248
|
-
},
|
|
249
|
-
required: ["street", "city"],
|
|
250
|
-
description: "A postal address",
|
|
251
|
-
},
|
|
252
|
-
},
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
256
|
-
const resultJson = zodToJsonSchema(result);
|
|
257
|
-
|
|
258
|
-
const expectedSchema = z.object({
|
|
259
|
-
address: z
|
|
260
|
-
.object({
|
|
261
|
-
street: z.string().describe("Street name"),
|
|
262
|
-
city: z.string().describe("City name"),
|
|
263
|
-
})
|
|
264
|
-
.describe("A postal address"),
|
|
265
|
-
});
|
|
266
|
-
const expectedJson = zodToJsonSchema(expectedSchema);
|
|
267
|
-
|
|
268
|
-
expect(resultJson).toStrictEqual(expectedJson);
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
it("should handle circular $ref without crashing and return z.any()", () => {
|
|
272
|
-
// A schema where Node references itself — this would cause infinite
|
|
273
|
-
// recursion without cycle detection.
|
|
274
|
-
const jsonSchema = {
|
|
275
|
-
type: "object",
|
|
276
|
-
properties: {
|
|
277
|
-
root: { $ref: "#/$defs/Node" },
|
|
278
|
-
},
|
|
279
|
-
required: ["root"],
|
|
280
|
-
$defs: {
|
|
281
|
-
Node: {
|
|
282
|
-
type: "object",
|
|
283
|
-
properties: {
|
|
284
|
-
value: { type: "string", description: "Node value" },
|
|
285
|
-
child: { $ref: "#/$defs/Node" },
|
|
286
|
-
},
|
|
287
|
-
required: ["value"],
|
|
288
|
-
description: "A tree node",
|
|
289
|
-
},
|
|
290
|
-
},
|
|
291
|
-
};
|
|
292
|
-
|
|
293
|
-
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
294
|
-
|
|
295
|
-
// Must not throw or hang
|
|
296
|
-
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
297
|
-
expect(result).toBeDefined();
|
|
298
|
-
|
|
299
|
-
// The circular ref should have produced a console.warn
|
|
300
|
-
expect(warnSpy).toHaveBeenCalledWith(
|
|
301
|
-
expect.stringContaining("Circular $ref detected"),
|
|
302
|
-
);
|
|
303
|
-
|
|
304
|
-
// The top-level shape should still have a "root" key that is an object
|
|
305
|
-
const shape = (result as z.ZodObject<any>).shape;
|
|
306
|
-
expect(shape.root).toBeDefined();
|
|
307
|
-
|
|
308
|
-
// Inside root, "value" should be a string and "child" should be z.any()
|
|
309
|
-
// (child is optional since it's not in required[], so unwrap ZodOptional)
|
|
310
|
-
const rootShape = (shape.root as z.ZodObject<any>).shape;
|
|
311
|
-
expect(rootShape.value._def.typeName).toBe("ZodString");
|
|
312
|
-
const childDef = rootShape.child._def;
|
|
313
|
-
if (childDef.typeName === "ZodOptional") {
|
|
314
|
-
expect(childDef.innerType._def.typeName).toBe("ZodAny");
|
|
315
|
-
} else {
|
|
316
|
-
expect(childDef.typeName).toBe("ZodAny");
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
warnSpy.mockRestore();
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
it("should resolve the same $ref used by multiple sibling properties", () => {
|
|
323
|
-
// Two properties reference the same $def — the visited set must NOT
|
|
324
|
-
// mark the second usage as circular.
|
|
325
|
-
const jsonSchema = {
|
|
326
|
-
type: "object",
|
|
327
|
-
properties: {
|
|
328
|
-
billing: { $ref: "#/$defs/Address" },
|
|
329
|
-
shipping: { $ref: "#/$defs/Address" },
|
|
330
|
-
},
|
|
331
|
-
required: ["billing", "shipping"],
|
|
332
|
-
$defs: {
|
|
333
|
-
Address: {
|
|
334
|
-
type: "object",
|
|
335
|
-
properties: {
|
|
336
|
-
street: { type: "string", description: "Street" },
|
|
337
|
-
city: { type: "string", description: "City" },
|
|
338
|
-
},
|
|
339
|
-
required: ["street", "city"],
|
|
340
|
-
description: "An address",
|
|
341
|
-
},
|
|
342
|
-
},
|
|
343
|
-
};
|
|
344
|
-
|
|
345
|
-
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
346
|
-
|
|
347
|
-
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
348
|
-
const shape = (result as z.ZodObject<any>).shape;
|
|
349
|
-
|
|
350
|
-
// Both should be fully resolved objects, NOT z.any()
|
|
351
|
-
expect(shape.billing._def.typeName).toBe("ZodObject");
|
|
352
|
-
expect(shape.shipping._def.typeName).toBe("ZodObject");
|
|
353
|
-
|
|
354
|
-
// No circular-ref warning should have been emitted
|
|
355
|
-
expect(warnSpy).not.toHaveBeenCalled();
|
|
356
|
-
|
|
357
|
-
warnSpy.mockRestore();
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
it("should resolve a shared $ref used in different branches of a $ref chain", () => {
|
|
361
|
-
// Wrapper -> Container (via $ref) which has two children both using $ref to Leaf.
|
|
362
|
-
// Without set cloning, the second Leaf ref in Container would be wrongly flagged
|
|
363
|
-
// as circular because the first Leaf resolution already added it to the set.
|
|
364
|
-
const jsonSchema = {
|
|
365
|
-
type: "object",
|
|
366
|
-
properties: {
|
|
367
|
-
wrapper: { $ref: "#/$defs/Container" },
|
|
368
|
-
},
|
|
369
|
-
required: ["wrapper"],
|
|
370
|
-
$defs: {
|
|
371
|
-
Container: {
|
|
372
|
-
type: "object",
|
|
373
|
-
properties: {
|
|
374
|
-
first: { $ref: "#/$defs/Leaf" },
|
|
375
|
-
second: { $ref: "#/$defs/Leaf" },
|
|
376
|
-
},
|
|
377
|
-
required: ["first", "second"],
|
|
378
|
-
description: "A container with two leaves",
|
|
379
|
-
},
|
|
380
|
-
Leaf: {
|
|
381
|
-
type: "object",
|
|
382
|
-
properties: {
|
|
383
|
-
label: { type: "string", description: "Leaf label" },
|
|
384
|
-
},
|
|
385
|
-
required: ["label"],
|
|
386
|
-
description: "A leaf node",
|
|
387
|
-
},
|
|
388
|
-
},
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
392
|
-
|
|
393
|
-
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
394
|
-
const wrapperShape = (
|
|
395
|
-
(result as z.ZodObject<any>).shape.wrapper as z.ZodObject<any>
|
|
396
|
-
).shape;
|
|
397
|
-
|
|
398
|
-
// Both first and second should be fully resolved Leaf objects
|
|
399
|
-
expect(wrapperShape.first._def.typeName).toBe("ZodObject");
|
|
400
|
-
expect(wrapperShape.second._def.typeName).toBe("ZodObject");
|
|
401
|
-
|
|
402
|
-
// No circular-ref warning should have been emitted
|
|
403
|
-
expect(warnSpy).not.toHaveBeenCalled();
|
|
404
|
-
|
|
405
|
-
warnSpy.mockRestore();
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
it("should handle anyOf with $ref variants", () => {
|
|
409
|
-
const jsonSchema = {
|
|
410
|
-
type: "object",
|
|
411
|
-
properties: {
|
|
412
|
-
pet: {
|
|
413
|
-
anyOf: [{ $ref: "#/$defs/Cat" }, { $ref: "#/$defs/Dog" }],
|
|
414
|
-
description: "A pet",
|
|
415
|
-
},
|
|
416
|
-
},
|
|
417
|
-
required: ["pet"],
|
|
418
|
-
$defs: {
|
|
419
|
-
Cat: {
|
|
420
|
-
type: "object",
|
|
421
|
-
properties: { meow: { type: "boolean" } },
|
|
422
|
-
required: ["meow"],
|
|
423
|
-
},
|
|
424
|
-
Dog: {
|
|
425
|
-
type: "object",
|
|
426
|
-
properties: { bark: { type: "boolean" } },
|
|
427
|
-
required: ["bark"],
|
|
428
|
-
},
|
|
429
|
-
},
|
|
430
|
-
};
|
|
431
|
-
|
|
432
|
-
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
433
|
-
expect(result).toBeDefined();
|
|
434
|
-
|
|
435
|
-
// Should produce a union inside the "pet" property
|
|
436
|
-
const petSchema = (result as z.ZodObject<any>).shape.pet;
|
|
437
|
-
expect(petSchema._def.typeName).toBe("ZodUnion");
|
|
438
|
-
});
|
|
439
|
-
|
|
440
|
-
it("should handle integer type as z.number()", () => {
|
|
441
|
-
const jsonSchema = {
|
|
442
|
-
type: "object",
|
|
443
|
-
properties: {
|
|
444
|
-
count: { type: "integer", description: "A count" },
|
|
445
|
-
},
|
|
446
|
-
required: ["count"],
|
|
447
|
-
};
|
|
448
|
-
|
|
449
|
-
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
450
|
-
const shape = (result as z.ZodObject<any>).shape;
|
|
451
|
-
expect(shape.count._def.typeName).toBe("ZodNumber");
|
|
452
|
-
});
|
|
453
|
-
|
|
454
|
-
it("should handle null type", () => {
|
|
455
|
-
const jsonSchema = {
|
|
456
|
-
type: "object",
|
|
457
|
-
properties: {
|
|
458
|
-
empty: { type: "null", description: "Always null" },
|
|
459
|
-
},
|
|
460
|
-
required: ["empty"],
|
|
461
|
-
};
|
|
462
|
-
|
|
463
|
-
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
464
|
-
const shape = (result as z.ZodObject<any>).shape;
|
|
465
|
-
expect(shape.empty._def.typeName).toBe("ZodNull");
|
|
466
|
-
});
|
|
467
|
-
|
|
468
|
-
it("should warn and return z.any() for unsupported schema types", () => {
|
|
469
|
-
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
470
|
-
|
|
471
|
-
const jsonSchema = { type: "custom_unsupported" };
|
|
472
|
-
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
473
|
-
|
|
474
|
-
expect(result._def.typeName).toBe("ZodAny");
|
|
475
|
-
expect(warnSpy).toHaveBeenCalledWith(
|
|
476
|
-
expect.stringContaining(
|
|
477
|
-
'Unsupported JSON schema type "custom_unsupported"',
|
|
478
|
-
),
|
|
479
|
-
);
|
|
480
|
-
|
|
481
|
-
warnSpy.mockRestore();
|
|
482
|
-
});
|
|
483
|
-
});
|
|
7
|
+
import type { Parameter } from "../../types";
|
|
484
8
|
|
|
485
9
|
describe("jsonSchemaToActionParameters", () => {
|
|
486
10
|
it("should convert a simple JSONSchema to Parameter array", () => {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { randomId, randomUUID } from "../random-id";
|
|
3
|
+
|
|
4
|
+
const UUID_V4 =
|
|
5
|
+
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
6
|
+
|
|
7
|
+
describe("randomUUID", () => {
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
vi.unstubAllGlobals();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("returns crypto.randomUUID() when it exists", () => {
|
|
13
|
+
vi.stubGlobal("crypto", {
|
|
14
|
+
randomUUID: () => "11111111-2222-4333-8444-555555555555",
|
|
15
|
+
});
|
|
16
|
+
expect(randomUUID()).toBe("11111111-2222-4333-8444-555555555555");
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("builds a v4 UUID from getRandomValues when randomUUID is missing", () => {
|
|
20
|
+
vi.stubGlobal("crypto", {
|
|
21
|
+
getRandomValues: (bytes: Uint8Array) => bytes.fill(0xff),
|
|
22
|
+
});
|
|
23
|
+
const id = randomUUID();
|
|
24
|
+
expect(id).toBe("ffffffff-ffff-4fff-bfff-ffffffffffff");
|
|
25
|
+
expect(id).toMatch(UUID_V4);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("throws a clear error when the runtime has no crypto", () => {
|
|
29
|
+
vi.stubGlobal("crypto", undefined);
|
|
30
|
+
expect(() => randomUUID()).toThrow(/getRandomValues/);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("prefixes randomId with ck-", () => {
|
|
34
|
+
expect(randomId()).toMatch(/^ck-/);
|
|
35
|
+
expect(randomId().slice(3)).toMatch(UUID_V4);
|
|
36
|
+
});
|
|
37
|
+
});
|
package/src/utils/errors.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { GraphQLError } from "graphql";
|
|
2
|
-
import { COPILOTKIT_VERSION } from "../index";
|
|
3
|
-
|
|
4
1
|
export enum Severity {
|
|
5
2
|
CRITICAL = "critical", // Critical errors that block core functionality
|
|
6
3
|
WARNING = "warning", // Configuration/setup issues that need attention
|
|
@@ -21,7 +18,6 @@ export const ERROR_NAMES = {
|
|
|
21
18
|
"CopilotKitRemoteEndpointDiscoveryError",
|
|
22
19
|
COPILOT_KIT_AGENT_DISCOVERY_ERROR: "CopilotKitAgentDiscoveryError",
|
|
23
20
|
COPILOT_KIT_LOW_LEVEL_ERROR: "CopilotKitLowLevelError",
|
|
24
|
-
COPILOT_KIT_VERSION_MISMATCH_ERROR: "CopilotKitVersionMismatchError",
|
|
25
21
|
RESOLVED_COPILOT_KIT_ERROR: "ResolvedCopilotKitError",
|
|
26
22
|
CONFIGURATION_ERROR: "ConfigurationError",
|
|
27
23
|
MISSING_PUBLIC_API_KEY_ERROR: "MissingPublicApiKeyError",
|
|
@@ -134,7 +130,19 @@ export const ERROR_CONFIG = {
|
|
|
134
130
|
},
|
|
135
131
|
};
|
|
136
132
|
|
|
137
|
-
export
|
|
133
|
+
export interface CopilotKitErrorExtensions {
|
|
134
|
+
name: string;
|
|
135
|
+
statusCode: number;
|
|
136
|
+
code: CopilotKitErrorCode;
|
|
137
|
+
visibility: ErrorVisibility;
|
|
138
|
+
severity?: Severity;
|
|
139
|
+
troubleshootingUrl: string | null;
|
|
140
|
+
originalError: { message: string; stack?: string };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export class CopilotKitError extends Error {
|
|
144
|
+
/** Structured error details, kept in the shape GraphQL errors used in 1.x. */
|
|
145
|
+
extensions: CopilotKitErrorExtensions;
|
|
138
146
|
code: CopilotKitErrorCode;
|
|
139
147
|
statusCode: number;
|
|
140
148
|
severity?: Severity;
|
|
@@ -159,22 +167,21 @@ export class CopilotKitError extends GraphQLError {
|
|
|
159
167
|
const resolvedSeverity =
|
|
160
168
|
severity ?? ("severity" in config ? config.severity : undefined);
|
|
161
169
|
|
|
162
|
-
super(message
|
|
163
|
-
extensions: {
|
|
164
|
-
name,
|
|
165
|
-
statusCode,
|
|
166
|
-
code,
|
|
167
|
-
visibility: resolvedVisibility,
|
|
168
|
-
severity: resolvedSeverity,
|
|
169
|
-
troubleshootingUrl:
|
|
170
|
-
"troubleshootingUrl" in config ? config.troubleshootingUrl : null,
|
|
171
|
-
originalError: {
|
|
172
|
-
message,
|
|
173
|
-
stack: new Error().stack,
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
});
|
|
170
|
+
super(message);
|
|
177
171
|
|
|
172
|
+
this.extensions = {
|
|
173
|
+
name,
|
|
174
|
+
statusCode,
|
|
175
|
+
code,
|
|
176
|
+
visibility: resolvedVisibility,
|
|
177
|
+
severity: resolvedSeverity,
|
|
178
|
+
troubleshootingUrl:
|
|
179
|
+
"troubleshootingUrl" in config ? config.troubleshootingUrl : null,
|
|
180
|
+
originalError: {
|
|
181
|
+
message,
|
|
182
|
+
stack: new Error().stack,
|
|
183
|
+
},
|
|
184
|
+
};
|
|
178
185
|
this.code = code;
|
|
179
186
|
this.name = name;
|
|
180
187
|
this.statusCode = statusCode;
|
|
@@ -208,36 +215,6 @@ export class CopilotKitMisuseError extends CopilotKitError {
|
|
|
208
215
|
}
|
|
209
216
|
}
|
|
210
217
|
|
|
211
|
-
const getVersionMismatchErrorMessage = ({
|
|
212
|
-
reactCoreVersion,
|
|
213
|
-
runtimeVersion,
|
|
214
|
-
runtimeClientGqlVersion,
|
|
215
|
-
}: VersionMismatchResponse) =>
|
|
216
|
-
`Version mismatch detected: @copilotkit/runtime@${runtimeVersion ?? ""} is not compatible with @copilotkit/react-core@${reactCoreVersion} and @copilotkit/runtime-client-gql@${runtimeClientGqlVersion}. Please ensure all installed copilotkit packages are on the same version.`;
|
|
217
|
-
/**
|
|
218
|
-
* Error thrown when CPK versions does not match
|
|
219
|
-
*
|
|
220
|
-
* @extends CopilotKitError
|
|
221
|
-
*/
|
|
222
|
-
export class CopilotKitVersionMismatchError extends CopilotKitError {
|
|
223
|
-
constructor({
|
|
224
|
-
reactCoreVersion,
|
|
225
|
-
runtimeVersion,
|
|
226
|
-
runtimeClientGqlVersion,
|
|
227
|
-
}: VersionMismatchResponse) {
|
|
228
|
-
const code = CopilotKitErrorCode.VERSION_MISMATCH;
|
|
229
|
-
super({
|
|
230
|
-
message: getVersionMismatchErrorMessage({
|
|
231
|
-
reactCoreVersion,
|
|
232
|
-
runtimeVersion,
|
|
233
|
-
runtimeClientGqlVersion,
|
|
234
|
-
}),
|
|
235
|
-
code,
|
|
236
|
-
});
|
|
237
|
-
this.name = ERROR_NAMES.COPILOT_KIT_VERSION_MISMATCH_ERROR;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
218
|
/**
|
|
242
219
|
* Error thrown when the CopilotKit API endpoint cannot be discovered or accessed.
|
|
243
220
|
* This typically occurs when:
|
|
@@ -477,41 +454,6 @@ export function ensureStructuredError<T extends CopilotKitError>(
|
|
|
477
454
|
return isStructuredCopilotKitError(error) ? error : converter(error);
|
|
478
455
|
}
|
|
479
456
|
|
|
480
|
-
interface VersionMismatchResponse {
|
|
481
|
-
runtimeVersion?: string;
|
|
482
|
-
runtimeClientGqlVersion: string;
|
|
483
|
-
reactCoreVersion: string;
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
export async function getPossibleVersionMismatch({
|
|
487
|
-
runtimeVersion,
|
|
488
|
-
runtimeClientGqlVersion,
|
|
489
|
-
}: {
|
|
490
|
-
runtimeVersion?: string;
|
|
491
|
-
runtimeClientGqlVersion: string;
|
|
492
|
-
}) {
|
|
493
|
-
if (!runtimeVersion || runtimeVersion === "" || !runtimeClientGqlVersion)
|
|
494
|
-
return;
|
|
495
|
-
if (
|
|
496
|
-
COPILOTKIT_VERSION !== runtimeVersion ||
|
|
497
|
-
COPILOTKIT_VERSION !== runtimeClientGqlVersion ||
|
|
498
|
-
runtimeVersion !== runtimeClientGqlVersion
|
|
499
|
-
) {
|
|
500
|
-
return {
|
|
501
|
-
runtimeVersion,
|
|
502
|
-
runtimeClientGqlVersion,
|
|
503
|
-
reactCoreVersion: COPILOTKIT_VERSION,
|
|
504
|
-
message: getVersionMismatchErrorMessage({
|
|
505
|
-
runtimeVersion,
|
|
506
|
-
runtimeClientGqlVersion,
|
|
507
|
-
reactCoreVersion: COPILOTKIT_VERSION,
|
|
508
|
-
}),
|
|
509
|
-
};
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
return;
|
|
513
|
-
}
|
|
514
|
-
|
|
515
457
|
const resolveLowLevelErrorMessage = ({
|
|
516
458
|
errorCode,
|
|
517
459
|
url,
|
|
@@ -552,6 +494,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
|
552
494
|
return `The server on ${url} could not be found. Check the URL or your network configuration.\n\n${getSeeMoreMarkdown(ERROR_CONFIG[CopilotKitErrorCode.NOT_FOUND].troubleshootingUrl)}`;
|
|
553
495
|
case "ETIMEDOUT":
|
|
554
496
|
return `The connection to ${url} timed out. The server might be overloaded or taking too long to respond.\n\n${getSeeMoreMarkdown(troubleshootingLink)}`;
|
|
497
|
+
case undefined:
|
|
555
498
|
default:
|
|
556
499
|
return;
|
|
557
500
|
}
|