@copilotkit/shared 1.54.1 → 1.55.0-next.7
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 +5 -1
- package/dist/constants/index.cjs +5 -0
- package/dist/constants/index.cjs.map +1 -1
- package/dist/constants/index.d.cts +4 -1
- package/dist/constants/index.d.cts.map +1 -1
- package/dist/constants/index.d.mts +4 -1
- package/dist/constants/index.d.mts.map +1 -1
- package/dist/constants/index.mjs +4 -1
- package/dist/constants/index.mjs.map +1 -1
- package/dist/finalize-events.cjs +106 -0
- package/dist/finalize-events.cjs.map +1 -0
- package/dist/finalize-events.d.cts +11 -0
- package/dist/finalize-events.d.cts.map +1 -0
- package/dist/finalize-events.d.mts +11 -0
- package/dist/finalize-events.d.mts.map +1 -0
- package/dist/finalize-events.mjs +105 -0
- package/dist/finalize-events.mjs.map +1 -0
- package/dist/index.cjs +25 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -4
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +9 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +10 -3
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +286 -5
- package/dist/index.umd.js.map +1 -1
- package/dist/logger.cjs +7 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +5 -0
- package/dist/logger.d.cts.map +1 -0
- package/dist/logger.d.mts +5 -0
- package/dist/logger.d.mts.map +1 -0
- package/dist/logger.mjs +6 -0
- package/dist/logger.mjs.map +1 -0
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/standard-schema.cjs +29 -0
- package/dist/standard-schema.cjs.map +1 -0
- package/dist/standard-schema.d.cts +32 -0
- package/dist/standard-schema.d.cts.map +1 -0
- package/dist/standard-schema.d.mts +32 -0
- package/dist/standard-schema.d.mts.map +1 -0
- package/dist/standard-schema.mjs +28 -0
- package/dist/standard-schema.mjs.map +1 -0
- package/dist/transcription-errors.cjs +84 -0
- package/dist/transcription-errors.cjs.map +1 -0
- package/dist/transcription-errors.d.cts +52 -0
- package/dist/transcription-errors.d.cts.map +1 -0
- package/dist/transcription-errors.d.mts +52 -0
- package/dist/transcription-errors.d.mts.map +1 -0
- package/dist/transcription-errors.mjs +82 -0
- package/dist/transcription-errors.mjs.map +1 -0
- package/dist/types/message.d.cts +1 -1
- package/dist/types/message.d.mts +1 -1
- package/dist/utils/index.cjs +49 -0
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +24 -2
- package/dist/utils/index.d.cts.map +1 -1
- package/dist/utils/index.d.mts +24 -2
- package/dist/utils/index.d.mts.map +1 -1
- package/dist/utils/index.mjs +45 -1
- package/dist/utils/index.mjs.map +1 -1
- package/dist/utils/types.cjs +9 -0
- package/dist/utils/types.cjs.map +1 -0
- package/dist/utils/types.d.cts +12 -1
- package/dist/utils/types.d.cts.map +1 -1
- package/dist/utils/types.d.mts +12 -1
- package/dist/utils/types.d.mts.map +1 -1
- package/dist/utils/types.mjs +7 -0
- package/dist/utils/types.mjs.map +1 -0
- package/package.json +11 -4
- package/src/__tests__/standard-schema-types.test.ts +144 -0
- package/src/__tests__/standard-schema.test.ts +267 -0
- package/src/__tests__/zod-regression.test.ts +319 -0
- package/src/constants/index.ts +5 -0
- package/src/finalize-events.ts +154 -0
- package/src/index.ts +12 -0
- package/src/logger.ts +1 -0
- package/src/standard-schema.ts +76 -0
- package/src/transcription-errors.ts +99 -0
- package/src/types/message.ts +1 -1
- package/src/utils/index.ts +58 -0
- package/src/utils/types.ts +21 -0
- package/src/utils.test.ts +66 -0
- package/tsconfig.json +9 -1
- package/tsdown.config.ts +10 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","names":[],"sources":["../../src/utils/types.ts"],"mappings":";KAAY,YAAA,MAAkB,CAAA,GAAI,WAAA,CAAY,CAAA;AAA9C;;;AAAA,KAKY,cAAA,MACV,CAAA,SAAU,MAAA,0BACA,CAAA,yBAEJ,CAAA;;;;UAMS,gBAAA;EACf,IAAA;EACA,SAAA;EACA,WAAA;AAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"types.d.cts","names":[],"sources":["../../src/utils/types.ts"],"mappings":";KAAY,YAAA,MAAkB,CAAA,GAAI,WAAA,CAAY,CAAA;AAA9C;;;AAAA,KAKY,cAAA,MACV,CAAA,SAAU,MAAA,0BACA,CAAA,yBAEJ,CAAA;;;;UAMS,gBAAA;EACf,IAAA;EACA,SAAA;EACA,WAAA;AAAA;AAAA,KAGU,WAAA;AAAA,cAEC,gBAAA;AAAA,cACA,yBAAA;AAAA,UAEI,uBAAA;EACf,KAAA;AAAA;AAAA,KAGU,oBAAA;AAAA,UAQK,WAAA;EACf,OAAA;EACA,MAAA,EAAQ,MAAA,SAAe,gBAAA;EACvB,6BAAA;EACA,IAAA,EAAM,WAAA;EACN,YAAA,GAAe,uBAAA;EACf,WAAA;EACA,aAAA,GAAgB,oBAAA;AAAA"}
|
package/dist/utils/types.d.mts
CHANGED
|
@@ -12,11 +12,22 @@ interface AgentDescription {
|
|
|
12
12
|
className: string;
|
|
13
13
|
description: string;
|
|
14
14
|
}
|
|
15
|
+
type RuntimeMode = "sse" | "intelligence";
|
|
16
|
+
declare const RUNTIME_MODE_SSE: "sse";
|
|
17
|
+
declare const RUNTIME_MODE_INTELLIGENCE: "intelligence";
|
|
18
|
+
interface IntelligenceRuntimeInfo {
|
|
19
|
+
wsUrl: string;
|
|
20
|
+
}
|
|
21
|
+
type RuntimeLicenseStatus = "valid" | "none" | "expired" | "expiring" | "invalid" | "unknown";
|
|
15
22
|
interface RuntimeInfo {
|
|
16
23
|
version: string;
|
|
17
24
|
agents: Record<string, AgentDescription>;
|
|
18
25
|
audioFileTranscriptionEnabled: boolean;
|
|
26
|
+
mode: RuntimeMode;
|
|
27
|
+
intelligence?: IntelligenceRuntimeInfo;
|
|
28
|
+
a2uiEnabled?: boolean;
|
|
29
|
+
licenseStatus?: RuntimeLicenseStatus;
|
|
19
30
|
}
|
|
20
31
|
//#endregion
|
|
21
|
-
export { AgentDescription, MaybePromise, NonEmptyRecord, RuntimeInfo };
|
|
32
|
+
export { AgentDescription, IntelligenceRuntimeInfo, MaybePromise, NonEmptyRecord, RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE, RuntimeInfo, RuntimeLicenseStatus, RuntimeMode };
|
|
22
33
|
//# sourceMappingURL=types.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","names":[],"sources":["../../src/utils/types.ts"],"mappings":";KAAY,YAAA,MAAkB,CAAA,GAAI,WAAA,CAAY,CAAA;AAA9C;;;AAAA,KAKY,cAAA,MACV,CAAA,SAAU,MAAA,0BACA,CAAA,yBAEJ,CAAA;;;;UAMS,gBAAA;EACf,IAAA;EACA,SAAA;EACA,WAAA;AAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../../src/utils/types.ts"],"mappings":";KAAY,YAAA,MAAkB,CAAA,GAAI,WAAA,CAAY,CAAA;AAA9C;;;AAAA,KAKY,cAAA,MACV,CAAA,SAAU,MAAA,0BACA,CAAA,yBAEJ,CAAA;;;;UAMS,gBAAA;EACf,IAAA;EACA,SAAA;EACA,WAAA;AAAA;AAAA,KAGU,WAAA;AAAA,cAEC,gBAAA;AAAA,cACA,yBAAA;AAAA,UAEI,uBAAA;EACf,KAAA;AAAA;AAAA,KAGU,oBAAA;AAAA,UAQK,WAAA;EACf,OAAA;EACA,MAAA,EAAQ,MAAA,SAAe,gBAAA;EACvB,6BAAA;EACA,IAAA,EAAM,WAAA;EACN,YAAA,GAAe,uBAAA;EACf,WAAA;EACA,aAAA,GAAgB,oBAAA;AAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.mjs","names":[],"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>\n ? keyof T extends never\n ? never\n : T\n : 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 type RuntimeMode = \"sse\" | \"intelligence\";\n\nexport const RUNTIME_MODE_SSE = \"sse\" as const;\nexport const RUNTIME_MODE_INTELLIGENCE = \"intelligence\" as const;\n\nexport interface IntelligenceRuntimeInfo {\n wsUrl: string;\n}\n\nexport type RuntimeLicenseStatus =\n | \"valid\"\n | \"none\"\n | \"expired\"\n | \"expiring\"\n | \"invalid\"\n | \"unknown\";\n\nexport interface RuntimeInfo {\n version: string;\n agents: Record<string, AgentDescription>;\n audioFileTranscriptionEnabled: boolean;\n mode: RuntimeMode;\n intelligence?: IntelligenceRuntimeInfo;\n a2uiEnabled?: boolean;\n licenseStatus?: RuntimeLicenseStatus;\n}\n"],"mappings":";AAuBA,MAAa,mBAAmB;AAChC,MAAa,4BAA4B"}
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"access": "public"
|
|
11
11
|
},
|
|
12
12
|
"type": "module",
|
|
13
|
-
"version": "1.
|
|
13
|
+
"version": "1.55.0-next.7",
|
|
14
14
|
"sideEffects": false,
|
|
15
15
|
"main": "./dist/index.cjs",
|
|
16
16
|
"module": "./dist/index.mjs",
|
|
@@ -27,19 +27,26 @@
|
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/uuid": "^10.0.0",
|
|
30
|
+
"@valibot/to-json-schema": "^1.5.0",
|
|
31
|
+
"arktype": "^2.1.29",
|
|
30
32
|
"eslint": "^8.56.0",
|
|
31
33
|
"tsdown": "^0.20.3",
|
|
32
34
|
"typescript": "^5.2.3",
|
|
35
|
+
"valibot": "^1.2.0",
|
|
33
36
|
"vitest": "^3.2.4",
|
|
34
37
|
"zod-to-json-schema": "^3.23.5",
|
|
35
|
-
"eslint-config-custom": "1.4.
|
|
36
|
-
"tsconfig": "1.4.
|
|
38
|
+
"eslint-config-custom": "1.4.12",
|
|
39
|
+
"tsconfig": "1.4.12"
|
|
37
40
|
},
|
|
38
41
|
"dependencies": {
|
|
42
|
+
"@ag-ui/client": "0.0.47",
|
|
39
43
|
"@segment/analytics-node": "^2.1.2",
|
|
44
|
+
"@standard-schema/spec": "^1.0.0",
|
|
40
45
|
"chalk": "4.1.2",
|
|
41
46
|
"graphql": "^16.8.1",
|
|
42
|
-
"
|
|
47
|
+
"partial-json": "^0.1.7",
|
|
48
|
+
"uuid": "^11.1.0",
|
|
49
|
+
"@copilotkit/license-verifier": "0.0.1-a1",
|
|
43
50
|
"zod": "^3.23.3"
|
|
44
51
|
},
|
|
45
52
|
"peerDependencies": {
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { describe, it, expectTypeOf } from "vitest";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import * as v from "valibot";
|
|
4
|
+
import { type } from "arktype";
|
|
5
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
6
|
+
import type { InferSchemaOutput } from "../standard-schema";
|
|
7
|
+
|
|
8
|
+
describe("InferSchemaOutput type inference", () => {
|
|
9
|
+
describe("Zod schemas", () => {
|
|
10
|
+
it("infers output type from a Zod object schema", () => {
|
|
11
|
+
const schema = z.object({
|
|
12
|
+
city: z.string(),
|
|
13
|
+
count: z.number(),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
expectTypeOf<InferSchemaOutput<typeof schema>>().toEqualTypeOf<{
|
|
17
|
+
city: string;
|
|
18
|
+
count: number;
|
|
19
|
+
}>();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("infers output type with optional fields", () => {
|
|
23
|
+
const schema = z.object({
|
|
24
|
+
name: z.string(),
|
|
25
|
+
age: z.number().optional(),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
expectTypeOf<InferSchemaOutput<typeof schema>>().toEqualTypeOf<{
|
|
29
|
+
name: string;
|
|
30
|
+
age?: number | undefined;
|
|
31
|
+
}>();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("infers output type with enums", () => {
|
|
35
|
+
const schema = z.object({
|
|
36
|
+
unit: z.enum(["celsius", "fahrenheit"]),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
expectTypeOf<InferSchemaOutput<typeof schema>>().toEqualTypeOf<{
|
|
40
|
+
unit: "celsius" | "fahrenheit";
|
|
41
|
+
}>();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("infers output type with nested objects", () => {
|
|
45
|
+
const schema = z.object({
|
|
46
|
+
user: z.object({
|
|
47
|
+
name: z.string(),
|
|
48
|
+
email: z.string(),
|
|
49
|
+
}),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
expectTypeOf<InferSchemaOutput<typeof schema>>().toEqualTypeOf<{
|
|
53
|
+
user: { name: string; email: string };
|
|
54
|
+
}>();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("infers output type with arrays", () => {
|
|
58
|
+
const schema = z.object({
|
|
59
|
+
tags: z.array(z.string()),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
expectTypeOf<InferSchemaOutput<typeof schema>>().toEqualTypeOf<{
|
|
63
|
+
tags: string[];
|
|
64
|
+
}>();
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe("Valibot schemas", () => {
|
|
69
|
+
it("infers output type from a Valibot object schema", () => {
|
|
70
|
+
const schema = v.object({
|
|
71
|
+
query: v.string(),
|
|
72
|
+
limit: v.number(),
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
expectTypeOf<InferSchemaOutput<typeof schema>>().toEqualTypeOf<{
|
|
76
|
+
query: string;
|
|
77
|
+
limit: number;
|
|
78
|
+
}>();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("infers output type with optional fields", () => {
|
|
82
|
+
const schema = v.object({
|
|
83
|
+
name: v.string(),
|
|
84
|
+
age: v.optional(v.number()),
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
expectTypeOf<InferSchemaOutput<typeof schema>>().toEqualTypeOf<{
|
|
88
|
+
name: string;
|
|
89
|
+
age?: number | undefined;
|
|
90
|
+
}>();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("infers output type with nested objects", () => {
|
|
94
|
+
const schema = v.object({
|
|
95
|
+
user: v.object({
|
|
96
|
+
name: v.string(),
|
|
97
|
+
email: v.string(),
|
|
98
|
+
}),
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
expectTypeOf<InferSchemaOutput<typeof schema>>().toEqualTypeOf<{
|
|
102
|
+
user: { name: string; email: string };
|
|
103
|
+
}>();
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe("ArkType schemas", () => {
|
|
108
|
+
it("infers output type from an ArkType object schema", () => {
|
|
109
|
+
const schema = type({
|
|
110
|
+
query: "string",
|
|
111
|
+
limit: "number",
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
expectTypeOf<InferSchemaOutput<typeof schema>>().toEqualTypeOf<{
|
|
115
|
+
query: string;
|
|
116
|
+
limit: number;
|
|
117
|
+
}>();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("infers output type with optional fields", () => {
|
|
121
|
+
const schema = type({
|
|
122
|
+
name: "string",
|
|
123
|
+
"age?": "number",
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
expectTypeOf<InferSchemaOutput<typeof schema>>().toEqualTypeOf<{
|
|
127
|
+
name: string;
|
|
128
|
+
age?: number;
|
|
129
|
+
}>();
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe("StandardSchemaV1 compatibility", () => {
|
|
134
|
+
it("all schema types satisfy StandardSchemaV1", () => {
|
|
135
|
+
expectTypeOf(
|
|
136
|
+
z.object({ a: z.string() }),
|
|
137
|
+
).toMatchTypeOf<StandardSchemaV1>();
|
|
138
|
+
expectTypeOf(
|
|
139
|
+
v.object({ a: v.string() }),
|
|
140
|
+
).toMatchTypeOf<StandardSchemaV1>();
|
|
141
|
+
expectTypeOf(type({ a: "string" })).toMatchTypeOf<StandardSchemaV1>();
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
});
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import * as v from "valibot";
|
|
4
|
+
import { toStandardJsonSchema } from "@valibot/to-json-schema";
|
|
5
|
+
import { type } from "arktype";
|
|
6
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
7
|
+
import { schemaToJsonSchema } from "../standard-schema";
|
|
8
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
9
|
+
|
|
10
|
+
describe("schemaToJsonSchema", () => {
|
|
11
|
+
describe("Zod schemas (via injected zodToJsonSchema)", () => {
|
|
12
|
+
it("converts a simple zod object schema", () => {
|
|
13
|
+
const schema = z.object({
|
|
14
|
+
name: z.string(),
|
|
15
|
+
age: z.number(),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const result = schemaToJsonSchema(schema, { zodToJsonSchema });
|
|
19
|
+
|
|
20
|
+
expect(result).toHaveProperty("type", "object");
|
|
21
|
+
expect(result).toHaveProperty("properties.name.type", "string");
|
|
22
|
+
expect(result).toHaveProperty("properties.age.type", "number");
|
|
23
|
+
expect(result).toHaveProperty("required");
|
|
24
|
+
expect(result.required).toContain("name");
|
|
25
|
+
expect(result.required).toContain("age");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("converts a zod schema with optional fields", () => {
|
|
29
|
+
const schema = z.object({
|
|
30
|
+
city: z.string(),
|
|
31
|
+
units: z.enum(["celsius", "fahrenheit"]).optional(),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const result = schemaToJsonSchema(schema, { zodToJsonSchema });
|
|
35
|
+
|
|
36
|
+
expect(result).toHaveProperty("type", "object");
|
|
37
|
+
expect(result).toHaveProperty("properties.city.type", "string");
|
|
38
|
+
expect(result.required).toContain("city");
|
|
39
|
+
expect(result.required).not.toContain("units");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("has vendor 'zod' on ~standard", () => {
|
|
43
|
+
const schema = z.object({ foo: z.string() });
|
|
44
|
+
expect(schema["~standard"].vendor).toBe("zod");
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe("Valibot schemas (via toStandardJsonSchema wrapper)", () => {
|
|
49
|
+
it("has vendor 'valibot' on ~standard", () => {
|
|
50
|
+
const schema = v.object({ name: v.string() });
|
|
51
|
+
expect(schema["~standard"].vendor).toBe("valibot");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("satisfies StandardSchemaV1", () => {
|
|
55
|
+
const schema = v.object({ name: v.string() });
|
|
56
|
+
const _: StandardSchemaV1 = schema;
|
|
57
|
+
expect(_["~standard"].version).toBe(1);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("raw valibot schema throws (no ~standard.jsonSchema)", () => {
|
|
61
|
+
const schema = v.object({ name: v.string() });
|
|
62
|
+
expect(() => schemaToJsonSchema(schema)).toThrow(
|
|
63
|
+
/Cannot convert schema to JSON Schema/,
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("converts a valibot schema wrapped with toStandardJsonSchema", () => {
|
|
68
|
+
const schema = toStandardJsonSchema(
|
|
69
|
+
v.object({
|
|
70
|
+
name: v.string(),
|
|
71
|
+
age: v.number(),
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const result = schemaToJsonSchema(schema);
|
|
76
|
+
|
|
77
|
+
expect(result).toHaveProperty("type", "object");
|
|
78
|
+
expect(result).toHaveProperty("properties.name.type", "string");
|
|
79
|
+
expect(result).toHaveProperty("properties.age.type", "number");
|
|
80
|
+
expect(result.required).toContain("name");
|
|
81
|
+
expect(result.required).toContain("age");
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("converts a valibot schema with optional fields", () => {
|
|
85
|
+
const schema = toStandardJsonSchema(
|
|
86
|
+
v.object({
|
|
87
|
+
city: v.string(),
|
|
88
|
+
units: v.optional(v.picklist(["celsius", "fahrenheit"])),
|
|
89
|
+
}),
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const result = schemaToJsonSchema(schema);
|
|
93
|
+
|
|
94
|
+
expect(result).toHaveProperty("type", "object");
|
|
95
|
+
expect(result).toHaveProperty("properties.city");
|
|
96
|
+
expect(result.required).toContain("city");
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe("ArkType schemas (native ~standard.jsonSchema)", () => {
|
|
101
|
+
it("has vendor 'arktype' on ~standard", () => {
|
|
102
|
+
const schema = type({ name: "string" });
|
|
103
|
+
expect(schema["~standard"].vendor).toBe("arktype");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("satisfies StandardSchemaV1", () => {
|
|
107
|
+
const schema = type({ name: "string" });
|
|
108
|
+
const _: StandardSchemaV1 = schema;
|
|
109
|
+
expect(_["~standard"].version).toBe(1);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("natively implements ~standard.jsonSchema", () => {
|
|
113
|
+
const schema = type({ name: "string" });
|
|
114
|
+
const props = schema["~standard"];
|
|
115
|
+
expect(props.jsonSchema).toBeDefined();
|
|
116
|
+
expect(typeof props.jsonSchema.input).toBe("function");
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("converts an arktype schema directly", () => {
|
|
120
|
+
const schema = type({
|
|
121
|
+
name: "string",
|
|
122
|
+
age: "number",
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const result = schemaToJsonSchema(schema);
|
|
126
|
+
|
|
127
|
+
expect(result).toHaveProperty("type", "object");
|
|
128
|
+
expect(result).toHaveProperty("properties.name.type", "string");
|
|
129
|
+
expect(result).toHaveProperty("properties.age.type", "number");
|
|
130
|
+
expect(result.required).toContain("name");
|
|
131
|
+
expect(result.required).toContain("age");
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("converts an arktype schema without needing zodToJsonSchema fallback", () => {
|
|
135
|
+
const schema = type({ query: "string" });
|
|
136
|
+
|
|
137
|
+
// No zodToJsonSchema option needed — arktype uses Standard JSON Schema V1 natively
|
|
138
|
+
const result = schemaToJsonSchema(schema);
|
|
139
|
+
|
|
140
|
+
expect(result).toHaveProperty("type", "object");
|
|
141
|
+
expect(result).toHaveProperty("properties.query.type", "string");
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe("Standard JSON Schema V1 protocol (mock)", () => {
|
|
146
|
+
it("uses ~standard.jsonSchema.input() when present", () => {
|
|
147
|
+
const mockSchema: StandardSchemaV1 & {
|
|
148
|
+
"~standard": StandardSchemaV1["~standard"] & {
|
|
149
|
+
jsonSchema: {
|
|
150
|
+
input: (opts: { target: string }) => Record<string, unknown>;
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
} = {
|
|
154
|
+
"~standard": {
|
|
155
|
+
version: 1,
|
|
156
|
+
vendor: "mock-lib",
|
|
157
|
+
validate: (value: unknown) => ({ value }),
|
|
158
|
+
jsonSchema: {
|
|
159
|
+
input: (opts: { target: string }) => ({
|
|
160
|
+
type: "object",
|
|
161
|
+
properties: {
|
|
162
|
+
query: { type: "string" },
|
|
163
|
+
},
|
|
164
|
+
required: ["query"],
|
|
165
|
+
$generatedBy: "mock-lib",
|
|
166
|
+
$target: opts.target,
|
|
167
|
+
}),
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const result = schemaToJsonSchema(mockSchema);
|
|
173
|
+
|
|
174
|
+
expect(result).toEqual({
|
|
175
|
+
type: "object",
|
|
176
|
+
properties: { query: { type: "string" } },
|
|
177
|
+
required: ["query"],
|
|
178
|
+
$generatedBy: "mock-lib",
|
|
179
|
+
$target: "draft-07",
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it("prefers ~standard.jsonSchema over zodToJsonSchema fallback", () => {
|
|
184
|
+
const mockSchema = {
|
|
185
|
+
"~standard": {
|
|
186
|
+
version: 1,
|
|
187
|
+
vendor: "zod",
|
|
188
|
+
validate: (value: unknown) => ({ value }),
|
|
189
|
+
jsonSchema: {
|
|
190
|
+
input: () => ({
|
|
191
|
+
type: "object",
|
|
192
|
+
properties: { fromJsonSchema: { type: "boolean" } },
|
|
193
|
+
}),
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
const zodFallback = () => ({
|
|
199
|
+
type: "object",
|
|
200
|
+
properties: { fromZodFallback: { type: "boolean" } },
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
const result = schemaToJsonSchema(mockSchema, {
|
|
204
|
+
zodToJsonSchema: zodFallback,
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// Should use ~standard.jsonSchema, not the zod fallback
|
|
208
|
+
expect(result).toHaveProperty("properties.fromJsonSchema");
|
|
209
|
+
expect(result).not.toHaveProperty("properties.fromZodFallback");
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
describe("Error handling", () => {
|
|
214
|
+
it("throws when schema has no jsonSchema support and no zodToJsonSchema", () => {
|
|
215
|
+
const mockSchema: StandardSchemaV1 = {
|
|
216
|
+
"~standard": {
|
|
217
|
+
version: 1,
|
|
218
|
+
vendor: "unknown-lib",
|
|
219
|
+
validate: (value: unknown) => ({ value }),
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
expect(() => schemaToJsonSchema(mockSchema)).toThrow(
|
|
224
|
+
/Cannot convert schema to JSON Schema/,
|
|
225
|
+
);
|
|
226
|
+
expect(() => schemaToJsonSchema(mockSchema)).toThrow(/unknown-lib/);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it("throws for non-zod vendor when zodToJsonSchema is not provided", () => {
|
|
230
|
+
const mockSchema: StandardSchemaV1 = {
|
|
231
|
+
"~standard": {
|
|
232
|
+
version: 1,
|
|
233
|
+
vendor: "some-other-lib",
|
|
234
|
+
validate: (value: unknown) => ({ value }),
|
|
235
|
+
},
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
expect(() => schemaToJsonSchema(mockSchema)).toThrow(
|
|
239
|
+
/no zodToJsonSchema fallback/,
|
|
240
|
+
);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it("uses zodToJsonSchema fallback for zod vendor schemas", () => {
|
|
244
|
+
const mockZodSchema: StandardSchemaV1 = {
|
|
245
|
+
"~standard": {
|
|
246
|
+
version: 1,
|
|
247
|
+
vendor: "zod",
|
|
248
|
+
validate: (value: unknown) => ({ value }),
|
|
249
|
+
},
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
const fallback = () => ({
|
|
253
|
+
type: "object",
|
|
254
|
+
properties: { test: { type: "string" } },
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
const result = schemaToJsonSchema(mockZodSchema, {
|
|
258
|
+
zodToJsonSchema: fallback,
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
expect(result).toEqual({
|
|
262
|
+
type: "object",
|
|
263
|
+
properties: { test: { type: "string" } },
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
});
|