@copilotkit/shared 2.0.0-rc.8 → 2.0.0-rc.9
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/index.cjs +0 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -4
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +12 -95
- 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 +7 -7
- package/dist/standard-schema.cjs.map +1 -1
- package/dist/standard-schema.d.cts +7 -16
- package/dist/standard-schema.d.cts.map +1 -1
- package/dist/standard-schema.d.mts +7 -16
- package/dist/standard-schema.d.mts.map +1 -1
- package/dist/standard-schema.mjs +7 -7
- package/dist/standard-schema.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/utils/index.d.cts +1 -1
- package/dist/utils/index.d.mts +1 -1
- package/dist/utils/index.mjs +1 -1
- package/dist/utils/json-schema.cjs +0 -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 +1 -78
- package/dist/utils/json-schema.mjs.map +1 -1
- package/package.json +7 -28
- package/src/__tests__/root-entry-browser-safety.test.ts +5 -7
- package/src/__tests__/standard-schema.test.ts +38 -103
- package/src/index.ts +3 -16
- package/src/standard-schema.ts +9 -27
- package/src/telemetry/telemetry-disabled.ts +0 -5
- package/src/utils/__tests__/json-schema.test.ts +3 -479
- package/src/utils/json-schema.ts +1 -152
- package/tsdown.config.ts +2 -10
- 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/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/dist/package.cjs
CHANGED
package/dist/package.mjs
CHANGED
package/dist/standard-schema.cjs
CHANGED
|
@@ -25,17 +25,17 @@ function hasStandardJsonSchema(schema) {
|
|
|
25
25
|
* Strategy:
|
|
26
26
|
* 1. If the schema implements Standard JSON Schema V1 (`~standard.jsonSchema`),
|
|
27
27
|
* call `schema['~standard'].jsonSchema.input({ target: 'draft-07' })`.
|
|
28
|
-
* 2
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
28
|
+
* Zod 4.2+, ArkType 2.1.28+ and Valibot (via `toStandardJsonSchema`) do.
|
|
29
|
+
* 2. If the schema exposes a `toJSONSchema()` method, call it directly.
|
|
30
|
+
* 3. Otherwise throw a descriptive error. Zod 3 schemas land here: they
|
|
31
|
+
* implement Standard Schema validation but cannot describe themselves as
|
|
32
|
+
* JSON Schema.
|
|
32
33
|
*/
|
|
33
|
-
function schemaToJsonSchema(schema
|
|
34
|
+
function schemaToJsonSchema(schema) {
|
|
34
35
|
if (hasStandardJsonSchema(schema)) return schema["~standard"].jsonSchema.input({ target: "draft-07" });
|
|
35
36
|
if (typeof schema.toJSONSchema === "function") return schema.toJSONSchema();
|
|
36
37
|
const vendor = schema["~standard"].vendor;
|
|
37
|
-
|
|
38
|
-
throw new Error(`Cannot convert schema to JSON Schema. The schema (vendor: "${vendor}") does not implement Standard JSON Schema V1 and no zodToJsonSchema fallback is available. Use a library that supports Standard JSON Schema (e.g., Zod 3.24+, Valibot v1+, ArkType v2+) or pass a zodToJsonSchema function in options.`);
|
|
38
|
+
throw new Error(`Cannot convert schema to JSON Schema. The schema (vendor: "${vendor}") does not implement Standard JSON Schema V1. Use a library that does: Zod 4.2+ (Zod 3 is not supported), Valibot v1+ wrapped with toStandardJsonSchema() from @valibot/to-json-schema, or ArkType v2.1.28+.`);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standard-schema.cjs","names":[],"sources":["../src/standard-schema.ts"],"sourcesContent":["import type {\n StandardSchemaV1,\n StandardJSONSchemaV1,\n} from \"@standard-schema/spec\";\n\nexport type { StandardSchemaV1, StandardJSONSchemaV1 };\n\n/**\n * A Standard Schema that accepts any value and returns it unchanged.\n *\n * Wildcard tool call renderers use it when they declare no `args` schema.\n *\n * @internal Application authors must not depend on this contract.\n */\nexport const ɵanySchema: StandardSchemaV1<unknown, unknown> = {\n \"~standard\": {\n version: 1,\n vendor: \"copilotkit\",\n validate: (value) => ({ value }),\n },\n};\n\n/**\n * Extract the Output type from a StandardSchemaV1 schema.\n * Replaces `z.infer<S>` for generic schema inference.\n */\nexport type InferSchemaOutput<S> =\n S extends StandardSchemaV1<any, infer O> ? O : never;\n\
|
|
1
|
+
{"version":3,"file":"standard-schema.cjs","names":[],"sources":["../src/standard-schema.ts"],"sourcesContent":["import type {\n StandardSchemaV1,\n StandardJSONSchemaV1,\n} from \"@standard-schema/spec\";\n\nexport type { StandardSchemaV1, StandardJSONSchemaV1 };\n\n/**\n * A Standard Schema that accepts any value and returns it unchanged.\n *\n * Wildcard tool call renderers use it when they declare no `args` schema.\n *\n * @internal Application authors must not depend on this contract.\n */\nexport const ɵanySchema: StandardSchemaV1<unknown, unknown> = {\n \"~standard\": {\n version: 1,\n vendor: \"copilotkit\",\n validate: (value) => ({ value }),\n },\n};\n\n/**\n * Extract the Output type from a StandardSchemaV1 schema.\n * Replaces `z.infer<S>` for generic schema inference.\n */\nexport type InferSchemaOutput<S> =\n S extends StandardSchemaV1<any, infer O> ? O : never;\n\n/**\n * Check whether a schema implements the Standard JSON Schema V1 protocol.\n */\nfunction hasStandardJsonSchema(\n schema: StandardSchemaV1,\n): schema is StandardSchemaV1 & StandardJSONSchemaV1 {\n const props = schema[\"~standard\"];\n return (\n props != null &&\n typeof props === \"object\" &&\n \"jsonSchema\" in props &&\n props.jsonSchema != null &&\n typeof props.jsonSchema === \"object\" &&\n \"input\" in props.jsonSchema &&\n typeof props.jsonSchema.input === \"function\"\n );\n}\n\n/**\n * Convert any StandardSchemaV1-compatible schema to a JSON Schema object.\n *\n * Strategy:\n * 1. If the schema implements Standard JSON Schema V1 (`~standard.jsonSchema`),\n * call `schema['~standard'].jsonSchema.input({ target: 'draft-07' })`.\n * Zod 4.2+, ArkType 2.1.28+ and Valibot (via `toStandardJsonSchema`) do.\n * 2. If the schema exposes a `toJSONSchema()` method, call it directly.\n * 3. Otherwise throw a descriptive error. Zod 3 schemas land here: they\n * implement Standard Schema validation but cannot describe themselves as\n * JSON Schema.\n */\nexport function schemaToJsonSchema(\n schema: StandardSchemaV1,\n): Record<string, unknown> {\n // 1. Standard JSON Schema V1\n if (hasStandardJsonSchema(schema)) {\n return schema[\"~standard\"].jsonSchema.input({ target: \"draft-07\" });\n }\n\n // 2. Native toJSONSchema() method\n if (typeof (schema as any).toJSONSchema === \"function\") {\n return (schema as any).toJSONSchema() as Record<string, unknown>;\n }\n\n const vendor = schema[\"~standard\"].vendor;\n throw new Error(\n `Cannot convert schema to JSON Schema. The schema (vendor: \"${vendor}\") does not implement Standard JSON Schema V1. ` +\n `Use a library that does: Zod 4.2+ (Zod 3 is not supported), Valibot v1+ wrapped with ` +\n `toStandardJsonSchema() from @valibot/to-json-schema, or ArkType v2.1.28+.`,\n );\n}\n"],"mappings":";;;;;;;;;AAcA,MAAa,aAAiD,EAC5D,aAAa;CACX,SAAS;CACT,QAAQ;CACR,WAAW,WAAW,EAAE,OAAO;CAChC,EACF;;;;AAYD,SAAS,sBACP,QACmD;CACnD,MAAM,QAAQ,OAAO;AACrB,QACE,SAAS,QACT,OAAO,UAAU,YACjB,gBAAgB,SAChB,MAAM,cAAc,QACpB,OAAO,MAAM,eAAe,YAC5B,WAAW,MAAM,cACjB,OAAO,MAAM,WAAW,UAAU;;;;;;;;;;;;;;AAgBtC,SAAgB,mBACd,QACyB;AAEzB,KAAI,sBAAsB,OAAO,CAC/B,QAAO,OAAO,aAAa,WAAW,MAAM,EAAE,QAAQ,YAAY,CAAC;AAIrE,KAAI,OAAQ,OAAe,iBAAiB,WAC1C,QAAQ,OAAe,cAAc;CAGvC,MAAM,SAAS,OAAO,aAAa;AACnC,OAAM,IAAI,MACR,8DAA8D,OAAO,+MAGtE"}
|
|
@@ -14,28 +14,19 @@ declare const ɵanySchema: StandardSchemaV1<unknown, unknown>;
|
|
|
14
14
|
* Replaces `z.infer<S>` for generic schema inference.
|
|
15
15
|
*/
|
|
16
16
|
type InferSchemaOutput<S> = S extends StandardSchemaV1<any, infer O> ? O : never;
|
|
17
|
-
interface SchemaToJsonSchemaOptions {
|
|
18
|
-
/**
|
|
19
|
-
* Injected `zodToJsonSchema` function so that `shared` does not depend on
|
|
20
|
-
* `zod-to-json-schema`. Required when the schema is a Zod v3 schema that
|
|
21
|
-
* does not implement Standard JSON Schema V1.
|
|
22
|
-
*/
|
|
23
|
-
zodToJsonSchema?: (schema: unknown, options?: {
|
|
24
|
-
$refStrategy?: string;
|
|
25
|
-
}) => Record<string, unknown>;
|
|
26
|
-
}
|
|
27
17
|
/**
|
|
28
18
|
* Convert any StandardSchemaV1-compatible schema to a JSON Schema object.
|
|
29
19
|
*
|
|
30
20
|
* Strategy:
|
|
31
21
|
* 1. If the schema implements Standard JSON Schema V1 (`~standard.jsonSchema`),
|
|
32
22
|
* call `schema['~standard'].jsonSchema.input({ target: 'draft-07' })`.
|
|
33
|
-
* 2
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
23
|
+
* Zod 4.2+, ArkType 2.1.28+ and Valibot (via `toStandardJsonSchema`) do.
|
|
24
|
+
* 2. If the schema exposes a `toJSONSchema()` method, call it directly.
|
|
25
|
+
* 3. Otherwise throw a descriptive error. Zod 3 schemas land here: they
|
|
26
|
+
* implement Standard Schema validation but cannot describe themselves as
|
|
27
|
+
* JSON Schema.
|
|
37
28
|
*/
|
|
38
|
-
declare function schemaToJsonSchema(schema: StandardSchemaV1
|
|
29
|
+
declare function schemaToJsonSchema(schema: StandardSchemaV1): Record<string, unknown>;
|
|
39
30
|
//#endregion
|
|
40
|
-
export { InferSchemaOutput,
|
|
31
|
+
export { InferSchemaOutput, type StandardJSONSchemaV1, type StandardSchemaV1, schemaToJsonSchema, ɵanySchema };
|
|
41
32
|
//# sourceMappingURL=standard-schema.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standard-schema.d.cts","names":[],"sources":["../src/standard-schema.ts"],"mappings":";;;;AAcA;;;;;AAYA;cAZa,UAAA,EAAY,gBAAA;;;;;KAYb,iBAAA,MACV,CAAA,SAAU,gBAAA,iBAAiC,CAAA
|
|
1
|
+
{"version":3,"file":"standard-schema.d.cts","names":[],"sources":["../src/standard-schema.ts"],"mappings":";;;;AAcA;;;;;AAYA;cAZa,UAAA,EAAY,gBAAA;;;;;KAYb,iBAAA,MACV,CAAA,SAAU,gBAAA,iBAAiC,CAAA;;;;;AAgC7C;;;;;;;;iBAAgB,kBAAA,CACd,MAAA,EAAQ,gBAAA,GACP,MAAA"}
|
|
@@ -14,28 +14,19 @@ declare const ɵanySchema: StandardSchemaV1<unknown, unknown>;
|
|
|
14
14
|
* Replaces `z.infer<S>` for generic schema inference.
|
|
15
15
|
*/
|
|
16
16
|
type InferSchemaOutput<S> = S extends StandardSchemaV1<any, infer O> ? O : never;
|
|
17
|
-
interface SchemaToJsonSchemaOptions {
|
|
18
|
-
/**
|
|
19
|
-
* Injected `zodToJsonSchema` function so that `shared` does not depend on
|
|
20
|
-
* `zod-to-json-schema`. Required when the schema is a Zod v3 schema that
|
|
21
|
-
* does not implement Standard JSON Schema V1.
|
|
22
|
-
*/
|
|
23
|
-
zodToJsonSchema?: (schema: unknown, options?: {
|
|
24
|
-
$refStrategy?: string;
|
|
25
|
-
}) => Record<string, unknown>;
|
|
26
|
-
}
|
|
27
17
|
/**
|
|
28
18
|
* Convert any StandardSchemaV1-compatible schema to a JSON Schema object.
|
|
29
19
|
*
|
|
30
20
|
* Strategy:
|
|
31
21
|
* 1. If the schema implements Standard JSON Schema V1 (`~standard.jsonSchema`),
|
|
32
22
|
* call `schema['~standard'].jsonSchema.input({ target: 'draft-07' })`.
|
|
33
|
-
* 2
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
23
|
+
* Zod 4.2+, ArkType 2.1.28+ and Valibot (via `toStandardJsonSchema`) do.
|
|
24
|
+
* 2. If the schema exposes a `toJSONSchema()` method, call it directly.
|
|
25
|
+
* 3. Otherwise throw a descriptive error. Zod 3 schemas land here: they
|
|
26
|
+
* implement Standard Schema validation but cannot describe themselves as
|
|
27
|
+
* JSON Schema.
|
|
37
28
|
*/
|
|
38
|
-
declare function schemaToJsonSchema(schema: StandardSchemaV1
|
|
29
|
+
declare function schemaToJsonSchema(schema: StandardSchemaV1): Record<string, unknown>;
|
|
39
30
|
//#endregion
|
|
40
|
-
export { InferSchemaOutput,
|
|
31
|
+
export { InferSchemaOutput, type StandardJSONSchemaV1, type StandardSchemaV1, schemaToJsonSchema, ɵanySchema };
|
|
41
32
|
//# sourceMappingURL=standard-schema.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standard-schema.d.mts","names":[],"sources":["../src/standard-schema.ts"],"mappings":";;;;AAcA;;;;;AAYA;cAZa,UAAA,EAAY,gBAAA;;;;;KAYb,iBAAA,MACV,CAAA,SAAU,gBAAA,iBAAiC,CAAA
|
|
1
|
+
{"version":3,"file":"standard-schema.d.mts","names":[],"sources":["../src/standard-schema.ts"],"mappings":";;;;AAcA;;;;;AAYA;cAZa,UAAA,EAAY,gBAAA;;;;;KAYb,iBAAA,MACV,CAAA,SAAU,gBAAA,iBAAiC,CAAA;;;;;AAgC7C;;;;;;;;iBAAgB,kBAAA,CACd,MAAA,EAAQ,gBAAA,GACP,MAAA"}
|
package/dist/standard-schema.mjs
CHANGED
|
@@ -24,17 +24,17 @@ function hasStandardJsonSchema(schema) {
|
|
|
24
24
|
* Strategy:
|
|
25
25
|
* 1. If the schema implements Standard JSON Schema V1 (`~standard.jsonSchema`),
|
|
26
26
|
* call `schema['~standard'].jsonSchema.input({ target: 'draft-07' })`.
|
|
27
|
-
* 2
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
27
|
+
* Zod 4.2+, ArkType 2.1.28+ and Valibot (via `toStandardJsonSchema`) do.
|
|
28
|
+
* 2. If the schema exposes a `toJSONSchema()` method, call it directly.
|
|
29
|
+
* 3. Otherwise throw a descriptive error. Zod 3 schemas land here: they
|
|
30
|
+
* implement Standard Schema validation but cannot describe themselves as
|
|
31
|
+
* JSON Schema.
|
|
31
32
|
*/
|
|
32
|
-
function schemaToJsonSchema(schema
|
|
33
|
+
function schemaToJsonSchema(schema) {
|
|
33
34
|
if (hasStandardJsonSchema(schema)) return schema["~standard"].jsonSchema.input({ target: "draft-07" });
|
|
34
35
|
if (typeof schema.toJSONSchema === "function") return schema.toJSONSchema();
|
|
35
36
|
const vendor = schema["~standard"].vendor;
|
|
36
|
-
|
|
37
|
-
throw new Error(`Cannot convert schema to JSON Schema. The schema (vendor: "${vendor}") does not implement Standard JSON Schema V1 and no zodToJsonSchema fallback is available. Use a library that supports Standard JSON Schema (e.g., Zod 3.24+, Valibot v1+, ArkType v2+) or pass a zodToJsonSchema function in options.`);
|
|
37
|
+
throw new Error(`Cannot convert schema to JSON Schema. The schema (vendor: "${vendor}") does not implement Standard JSON Schema V1. Use a library that does: Zod 4.2+ (Zod 3 is not supported), Valibot v1+ wrapped with toStandardJsonSchema() from @valibot/to-json-schema, or ArkType v2.1.28+.`);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standard-schema.mjs","names":[],"sources":["../src/standard-schema.ts"],"sourcesContent":["import type {\n StandardSchemaV1,\n StandardJSONSchemaV1,\n} from \"@standard-schema/spec\";\n\nexport type { StandardSchemaV1, StandardJSONSchemaV1 };\n\n/**\n * A Standard Schema that accepts any value and returns it unchanged.\n *\n * Wildcard tool call renderers use it when they declare no `args` schema.\n *\n * @internal Application authors must not depend on this contract.\n */\nexport const ɵanySchema: StandardSchemaV1<unknown, unknown> = {\n \"~standard\": {\n version: 1,\n vendor: \"copilotkit\",\n validate: (value) => ({ value }),\n },\n};\n\n/**\n * Extract the Output type from a StandardSchemaV1 schema.\n * Replaces `z.infer<S>` for generic schema inference.\n */\nexport type InferSchemaOutput<S> =\n S extends StandardSchemaV1<any, infer O> ? O : never;\n\
|
|
1
|
+
{"version":3,"file":"standard-schema.mjs","names":[],"sources":["../src/standard-schema.ts"],"sourcesContent":["import type {\n StandardSchemaV1,\n StandardJSONSchemaV1,\n} from \"@standard-schema/spec\";\n\nexport type { StandardSchemaV1, StandardJSONSchemaV1 };\n\n/**\n * A Standard Schema that accepts any value and returns it unchanged.\n *\n * Wildcard tool call renderers use it when they declare no `args` schema.\n *\n * @internal Application authors must not depend on this contract.\n */\nexport const ɵanySchema: StandardSchemaV1<unknown, unknown> = {\n \"~standard\": {\n version: 1,\n vendor: \"copilotkit\",\n validate: (value) => ({ value }),\n },\n};\n\n/**\n * Extract the Output type from a StandardSchemaV1 schema.\n * Replaces `z.infer<S>` for generic schema inference.\n */\nexport type InferSchemaOutput<S> =\n S extends StandardSchemaV1<any, infer O> ? O : never;\n\n/**\n * Check whether a schema implements the Standard JSON Schema V1 protocol.\n */\nfunction hasStandardJsonSchema(\n schema: StandardSchemaV1,\n): schema is StandardSchemaV1 & StandardJSONSchemaV1 {\n const props = schema[\"~standard\"];\n return (\n props != null &&\n typeof props === \"object\" &&\n \"jsonSchema\" in props &&\n props.jsonSchema != null &&\n typeof props.jsonSchema === \"object\" &&\n \"input\" in props.jsonSchema &&\n typeof props.jsonSchema.input === \"function\"\n );\n}\n\n/**\n * Convert any StandardSchemaV1-compatible schema to a JSON Schema object.\n *\n * Strategy:\n * 1. If the schema implements Standard JSON Schema V1 (`~standard.jsonSchema`),\n * call `schema['~standard'].jsonSchema.input({ target: 'draft-07' })`.\n * Zod 4.2+, ArkType 2.1.28+ and Valibot (via `toStandardJsonSchema`) do.\n * 2. If the schema exposes a `toJSONSchema()` method, call it directly.\n * 3. Otherwise throw a descriptive error. Zod 3 schemas land here: they\n * implement Standard Schema validation but cannot describe themselves as\n * JSON Schema.\n */\nexport function schemaToJsonSchema(\n schema: StandardSchemaV1,\n): Record<string, unknown> {\n // 1. Standard JSON Schema V1\n if (hasStandardJsonSchema(schema)) {\n return schema[\"~standard\"].jsonSchema.input({ target: \"draft-07\" });\n }\n\n // 2. Native toJSONSchema() method\n if (typeof (schema as any).toJSONSchema === \"function\") {\n return (schema as any).toJSONSchema() as Record<string, unknown>;\n }\n\n const vendor = schema[\"~standard\"].vendor;\n throw new Error(\n `Cannot convert schema to JSON Schema. The schema (vendor: \"${vendor}\") does not implement Standard JSON Schema V1. ` +\n `Use a library that does: Zod 4.2+ (Zod 3 is not supported), Valibot v1+ wrapped with ` +\n `toStandardJsonSchema() from @valibot/to-json-schema, or ArkType v2.1.28+.`,\n );\n}\n"],"mappings":";;;;;;;;AAcA,MAAa,aAAiD,EAC5D,aAAa;CACX,SAAS;CACT,QAAQ;CACR,WAAW,WAAW,EAAE,OAAO;CAChC,EACF;;;;AAYD,SAAS,sBACP,QACmD;CACnD,MAAM,QAAQ,OAAO;AACrB,QACE,SAAS,QACT,OAAO,UAAU,YACjB,gBAAgB,SAChB,MAAM,cAAc,QACpB,OAAO,MAAM,eAAe,YAC5B,WAAW,MAAM,cACjB,OAAO,MAAM,WAAW,UAAU;;;;;;;;;;;;;;AAgBtC,SAAgB,mBACd,QACyB;AAEzB,KAAI,sBAAsB,OAAO,CAC/B,QAAO,OAAO,aAAa,WAAW,MAAM,EAAE,QAAQ,YAAY,CAAC;AAIrE,KAAI,OAAQ,OAAe,iBAAiB,WAC1C,QAAQ,OAAe,cAAc;CAGvC,MAAM,SAAS,OAAO,aAAa;AACnC,OAAM,IAAI,MACR,8DAA8D,OAAO,+MAGtE"}
|
|
@@ -6,11 +6,6 @@ const require_process_env = require('../utils/process-env.cjs');
|
|
|
6
6
|
* Users can opt out by setting:
|
|
7
7
|
* - COPILOTKIT_TELEMETRY_DISABLED=true or COPILOTKIT_TELEMETRY_DISABLED=1
|
|
8
8
|
* - DO_NOT_TRACK=true or DO_NOT_TRACK=1
|
|
9
|
-
*
|
|
10
|
-
* Lives in its own module so that the browser-facing root entry can
|
|
11
|
-
* re-export it without pulling in `telemetry-client.ts`, whose
|
|
12
|
-
* `@segment/analytics-node` import drags Node built-ins into browser
|
|
13
|
-
* bundler module graphs. See the note in `../index.ts`.
|
|
14
9
|
*/
|
|
15
10
|
function isTelemetryDisabled() {
|
|
16
11
|
const env = require_process_env.processEnv();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry-disabled.cjs","names":["processEnv"],"sources":["../../src/telemetry/telemetry-disabled.ts"],"sourcesContent":["import { processEnv } from \"../utils/process-env\";\n\n/**\n * Checks if telemetry is disabled via environment variables.\n * Users can opt out by setting:\n * - COPILOTKIT_TELEMETRY_DISABLED=true or COPILOTKIT_TELEMETRY_DISABLED=1\n * - DO_NOT_TRACK=true or DO_NOT_TRACK=1\n
|
|
1
|
+
{"version":3,"file":"telemetry-disabled.cjs","names":["processEnv"],"sources":["../../src/telemetry/telemetry-disabled.ts"],"sourcesContent":["import { processEnv } from \"../utils/process-env\";\n\n/**\n * Checks if telemetry is disabled via environment variables.\n * Users can opt out by setting:\n * - COPILOTKIT_TELEMETRY_DISABLED=true or COPILOTKIT_TELEMETRY_DISABLED=1\n * - DO_NOT_TRACK=true or DO_NOT_TRACK=1\n */\nexport function isTelemetryDisabled(): boolean {\n const env = processEnv();\n return (\n env.COPILOTKIT_TELEMETRY_DISABLED === \"true\" ||\n env.COPILOTKIT_TELEMETRY_DISABLED === \"1\" ||\n env.DO_NOT_TRACK === \"true\" ||\n env.DO_NOT_TRACK === \"1\"\n );\n}\n"],"mappings":";;;;;;;;;AAQA,SAAgB,sBAA+B;CAC7C,MAAM,MAAMA,gCAAY;AACxB,QACE,IAAI,kCAAkC,UACtC,IAAI,kCAAkC,OACtC,IAAI,iBAAiB,UACrB,IAAI,iBAAiB"}
|
|
@@ -4,11 +4,6 @@
|
|
|
4
4
|
* Users can opt out by setting:
|
|
5
5
|
* - COPILOTKIT_TELEMETRY_DISABLED=true or COPILOTKIT_TELEMETRY_DISABLED=1
|
|
6
6
|
* - DO_NOT_TRACK=true or DO_NOT_TRACK=1
|
|
7
|
-
*
|
|
8
|
-
* Lives in its own module so that the browser-facing root entry can
|
|
9
|
-
* re-export it without pulling in `telemetry-client.ts`, whose
|
|
10
|
-
* `@segment/analytics-node` import drags Node built-ins into browser
|
|
11
|
-
* bundler module graphs. See the note in `../index.ts`.
|
|
12
7
|
*/
|
|
13
8
|
declare function isTelemetryDisabled(): boolean;
|
|
14
9
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry-disabled.d.cts","names":[],"sources":["../../src/telemetry/telemetry-disabled.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"telemetry-disabled.d.cts","names":[],"sources":["../../src/telemetry/telemetry-disabled.ts"],"mappings":";;AAQA;;;;;iBAAgB,mBAAA,CAAA"}
|
|
@@ -4,11 +4,6 @@
|
|
|
4
4
|
* Users can opt out by setting:
|
|
5
5
|
* - COPILOTKIT_TELEMETRY_DISABLED=true or COPILOTKIT_TELEMETRY_DISABLED=1
|
|
6
6
|
* - DO_NOT_TRACK=true or DO_NOT_TRACK=1
|
|
7
|
-
*
|
|
8
|
-
* Lives in its own module so that the browser-facing root entry can
|
|
9
|
-
* re-export it without pulling in `telemetry-client.ts`, whose
|
|
10
|
-
* `@segment/analytics-node` import drags Node built-ins into browser
|
|
11
|
-
* bundler module graphs. See the note in `../index.ts`.
|
|
12
7
|
*/
|
|
13
8
|
declare function isTelemetryDisabled(): boolean;
|
|
14
9
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry-disabled.d.mts","names":[],"sources":["../../src/telemetry/telemetry-disabled.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"telemetry-disabled.d.mts","names":[],"sources":["../../src/telemetry/telemetry-disabled.ts"],"mappings":";;AAQA;;;;;iBAAgB,mBAAA,CAAA"}
|
|
@@ -6,11 +6,6 @@ import { processEnv } from "../utils/process-env.mjs";
|
|
|
6
6
|
* Users can opt out by setting:
|
|
7
7
|
* - COPILOTKIT_TELEMETRY_DISABLED=true or COPILOTKIT_TELEMETRY_DISABLED=1
|
|
8
8
|
* - DO_NOT_TRACK=true or DO_NOT_TRACK=1
|
|
9
|
-
*
|
|
10
|
-
* Lives in its own module so that the browser-facing root entry can
|
|
11
|
-
* re-export it without pulling in `telemetry-client.ts`, whose
|
|
12
|
-
* `@segment/analytics-node` import drags Node built-ins into browser
|
|
13
|
-
* bundler module graphs. See the note in `../index.ts`.
|
|
14
9
|
*/
|
|
15
10
|
function isTelemetryDisabled() {
|
|
16
11
|
const env = processEnv();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry-disabled.mjs","names":[],"sources":["../../src/telemetry/telemetry-disabled.ts"],"sourcesContent":["import { processEnv } from \"../utils/process-env\";\n\n/**\n * Checks if telemetry is disabled via environment variables.\n * Users can opt out by setting:\n * - COPILOTKIT_TELEMETRY_DISABLED=true or COPILOTKIT_TELEMETRY_DISABLED=1\n * - DO_NOT_TRACK=true or DO_NOT_TRACK=1\n
|
|
1
|
+
{"version":3,"file":"telemetry-disabled.mjs","names":[],"sources":["../../src/telemetry/telemetry-disabled.ts"],"sourcesContent":["import { processEnv } from \"../utils/process-env\";\n\n/**\n * Checks if telemetry is disabled via environment variables.\n * Users can opt out by setting:\n * - COPILOTKIT_TELEMETRY_DISABLED=true or COPILOTKIT_TELEMETRY_DISABLED=1\n * - DO_NOT_TRACK=true or DO_NOT_TRACK=1\n */\nexport function isTelemetryDisabled(): boolean {\n const env = processEnv();\n return (\n env.COPILOTKIT_TELEMETRY_DISABLED === \"true\" ||\n env.COPILOTKIT_TELEMETRY_DISABLED === \"1\" ||\n env.DO_NOT_TRACK === \"true\" ||\n env.DO_NOT_TRACK === \"1\"\n );\n}\n"],"mappings":";;;;;;;;;AAQA,SAAgB,sBAA+B;CAC7C,MAAM,MAAM,YAAY;AACxB,QACE,IAAI,kCAAkC,UACtC,IAAI,kCAAkC,OACtC,IAAI,iBAAiB,UACrB,IAAI,iBAAiB"}
|
package/dist/utils/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { copyToClipboard } from "./clipboard.cjs";
|
|
2
2
|
import { BANNER_ERROR_NAMES, COPILOT_CLOUD_ERROR_NAMES, ConfigurationError, CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitErrorExtensions, CopilotKitLowLevelError, CopilotKitMisuseError, CopilotKitRemoteEndpointDiscoveryError, ERROR_CONFIG, ERROR_NAMES, ErrorVisibility, MissingPublicApiKeyError, ResolvedCopilotKitError, Severity, UpgradeRequiredError, ensureStructuredError, isStructuredCopilotKitError } from "./errors.cjs";
|
|
3
|
-
import { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema,
|
|
3
|
+
import { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema, jsonSchemaToActionParameters } from "./json-schema.cjs";
|
|
4
4
|
import { InspectorMetadataV1, parseInspectorMetadataV1 } from "./inspector-metadata.cjs";
|
|
5
5
|
import { InspectorLearningEvidence, InspectorLearningInsight, InspectorLearningPage, InspectorLearningRequestV1, InspectorLearningSkill, InspectorLearningSnapshotV1, InspectorLearningTrajectoryEvidence, parseInspectorLearningRequestV1, parseInspectorLearningSnapshotV1, parseInspectorLearningUrl } from "./inspector-learning.cjs";
|
|
6
6
|
import { InspectorVisibilityOptions, shouldEnableInspector } from "./inspector-visibility.cjs";
|
package/dist/utils/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { copyToClipboard } from "./clipboard.mjs";
|
|
2
2
|
import { BANNER_ERROR_NAMES, COPILOT_CLOUD_ERROR_NAMES, ConfigurationError, CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitErrorExtensions, CopilotKitLowLevelError, CopilotKitMisuseError, CopilotKitRemoteEndpointDiscoveryError, ERROR_CONFIG, ERROR_NAMES, ErrorVisibility, MissingPublicApiKeyError, ResolvedCopilotKitError, Severity, UpgradeRequiredError, ensureStructuredError, isStructuredCopilotKitError } from "./errors.mjs";
|
|
3
|
-
import { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema,
|
|
3
|
+
import { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema, jsonSchemaToActionParameters } from "./json-schema.mjs";
|
|
4
4
|
import { InspectorMetadataV1, parseInspectorMetadataV1 } from "./inspector-metadata.mjs";
|
|
5
5
|
import { InspectorLearningEvidence, InspectorLearningInsight, InspectorLearningPage, InspectorLearningRequestV1, InspectorLearningSkill, InspectorLearningSnapshotV1, InspectorLearningTrajectoryEvidence, parseInspectorLearningRequestV1, parseInspectorLearningSnapshotV1, parseInspectorLearningUrl } from "./inspector-learning.mjs";
|
|
6
6
|
import { InspectorVisibilityOptions, shouldEnableInspector } from "./inspector-visibility.mjs";
|
package/dist/utils/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { copyToClipboard } from "./clipboard.mjs";
|
|
2
2
|
import { BANNER_ERROR_NAMES, COPILOT_CLOUD_ERROR_NAMES, ConfigurationError, CopilotKitAgentDiscoveryError, CopilotKitApiDiscoveryError, CopilotKitError, CopilotKitErrorCode, CopilotKitLowLevelError, CopilotKitMisuseError, CopilotKitRemoteEndpointDiscoveryError, ERROR_CONFIG, ERROR_NAMES, ErrorVisibility, MissingPublicApiKeyError, ResolvedCopilotKitError, Severity, UpgradeRequiredError, ensureStructuredError, isStructuredCopilotKitError } from "./errors.mjs";
|
|
3
|
-
import { actionParametersToJsonSchema,
|
|
3
|
+
import { actionParametersToJsonSchema, jsonSchemaToActionParameters } from "./json-schema.mjs";
|
|
4
4
|
import { parseInspectorMetadataV1 } from "./inspector-metadata.mjs";
|
|
5
5
|
import { parseInspectorLearningRequestV1, parseInspectorLearningSnapshotV1, parseInspectorLearningUrl } from "./inspector-learning.mjs";
|
|
6
6
|
import { shouldEnableInspector } from "./inspector-visibility.mjs";
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
|
-
let zod = require("zod");
|
|
3
1
|
|
|
4
2
|
//#region src/utils/json-schema.ts
|
|
5
3
|
function actionParametersToJsonSchema(actionParameters) {
|
|
@@ -131,85 +129,8 @@ function convertAttribute(attribute) {
|
|
|
131
129
|
};
|
|
132
130
|
}
|
|
133
131
|
}
|
|
134
|
-
function convertJsonSchemaToZodSchema(jsonSchema, required, definitions, visitedRefs) {
|
|
135
|
-
if (jsonSchema.$ref && definitions) {
|
|
136
|
-
const refPath = jsonSchema.$ref.replace(/^#\/\$defs\/|^#\/definitions\//, "");
|
|
137
|
-
const refs = visitedRefs ?? /* @__PURE__ */ new Set();
|
|
138
|
-
if (refs.has(refPath)) {
|
|
139
|
-
console.warn(`[CopilotKit] Circular $ref detected for "${refPath}" — falling back to z.any()`);
|
|
140
|
-
let schema = zod.z.any();
|
|
141
|
-
if (jsonSchema.description) schema = schema.describe(jsonSchema.description);
|
|
142
|
-
return required ? schema : schema.optional();
|
|
143
|
-
}
|
|
144
|
-
const resolved = definitions[refPath];
|
|
145
|
-
if (resolved) {
|
|
146
|
-
const nextRefs = new Set(refs);
|
|
147
|
-
nextRefs.add(refPath);
|
|
148
|
-
return convertJsonSchemaToZodSchema(resolved, required, definitions, nextRefs);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
const defs = definitions ?? jsonSchema.$defs ?? jsonSchema.definitions;
|
|
152
|
-
if (Array.isArray(jsonSchema.type)) {
|
|
153
|
-
const types = jsonSchema.type;
|
|
154
|
-
const hasNull = types.includes("null");
|
|
155
|
-
const nonNullTypes = types.filter((t) => t !== "null");
|
|
156
|
-
const resolvedType = nonNullTypes.length > 0 ? nonNullTypes[0] : "string";
|
|
157
|
-
const innerSchema = convertJsonSchemaToZodSchema({
|
|
158
|
-
...jsonSchema,
|
|
159
|
-
type: resolvedType
|
|
160
|
-
}, true, defs, visitedRefs);
|
|
161
|
-
let schema = hasNull ? zod.z.union([innerSchema, zod.z.null()]) : innerSchema;
|
|
162
|
-
if (jsonSchema.description) schema = schema.describe(jsonSchema.description);
|
|
163
|
-
return required ? schema : schema.optional();
|
|
164
|
-
}
|
|
165
|
-
const unionVariants = jsonSchema.anyOf ?? jsonSchema.oneOf;
|
|
166
|
-
if (Array.isArray(unionVariants) && unionVariants.length > 0) {
|
|
167
|
-
if (unionVariants.length === 1) return convertJsonSchemaToZodSchema(unionVariants[0], required, defs, visitedRefs);
|
|
168
|
-
const schemas = unionVariants.map((v) => convertJsonSchemaToZodSchema(v, true, defs, visitedRefs));
|
|
169
|
-
let schema = zod.z.union(schemas);
|
|
170
|
-
if (jsonSchema.description) schema = schema.describe(jsonSchema.description);
|
|
171
|
-
return required ? schema : schema.optional();
|
|
172
|
-
}
|
|
173
|
-
if (jsonSchema.type === "object") {
|
|
174
|
-
const spec = {};
|
|
175
|
-
if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) return !required ? zod.z.object(spec).optional() : zod.z.object(spec);
|
|
176
|
-
for (const [key, value] of Object.entries(jsonSchema.properties)) spec[key] = convertJsonSchemaToZodSchema(value, jsonSchema.required ? jsonSchema.required.includes(key) : false, defs, visitedRefs);
|
|
177
|
-
let schema = zod.z.object(spec).describe(jsonSchema.description);
|
|
178
|
-
return required ? schema : schema.optional();
|
|
179
|
-
} else if (jsonSchema.type === "string") {
|
|
180
|
-
if (jsonSchema.enum && jsonSchema.enum.length > 0) {
|
|
181
|
-
let schema = zod.z.enum(jsonSchema.enum).describe(jsonSchema.description);
|
|
182
|
-
return required ? schema : schema.optional();
|
|
183
|
-
}
|
|
184
|
-
let schema = zod.z.string().describe(jsonSchema.description);
|
|
185
|
-
return required ? schema : schema.optional();
|
|
186
|
-
} else if (jsonSchema.type === "number" || jsonSchema.type === "integer") {
|
|
187
|
-
let schema = zod.z.number().describe(jsonSchema.description);
|
|
188
|
-
return required ? schema : schema.optional();
|
|
189
|
-
} else if (jsonSchema.type === "boolean") {
|
|
190
|
-
let schema = zod.z.boolean().describe(jsonSchema.description);
|
|
191
|
-
return required ? schema : schema.optional();
|
|
192
|
-
} else if (jsonSchema.type === "array") {
|
|
193
|
-
let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, true, defs, visitedRefs);
|
|
194
|
-
let schema = zod.z.array(itemSchema).describe(jsonSchema.description);
|
|
195
|
-
return required ? schema : schema.optional();
|
|
196
|
-
} else if (jsonSchema.type === "null") {
|
|
197
|
-
let schema = zod.z.null().describe(jsonSchema.description);
|
|
198
|
-
return required ? schema : schema.optional();
|
|
199
|
-
}
|
|
200
|
-
console.warn(`[CopilotKit] Unsupported JSON schema type "${jsonSchema.type ?? "unknown"}" — falling back to z.any()`);
|
|
201
|
-
let schema = zod.z.any();
|
|
202
|
-
if (jsonSchema.description) schema = schema.describe(jsonSchema.description);
|
|
203
|
-
return required ? schema : schema.optional();
|
|
204
|
-
}
|
|
205
|
-
function getZodParameters(parameters) {
|
|
206
|
-
if (!parameters) return zod.z.object({});
|
|
207
|
-
return convertJsonSchemaToZodSchema(actionParametersToJsonSchema(parameters), true);
|
|
208
|
-
}
|
|
209
132
|
|
|
210
133
|
//#endregion
|
|
211
134
|
exports.actionParametersToJsonSchema = actionParametersToJsonSchema;
|
|
212
|
-
exports.convertJsonSchemaToZodSchema = convertJsonSchemaToZodSchema;
|
|
213
|
-
exports.getZodParameters = getZodParameters;
|
|
214
135
|
exports.jsonSchemaToActionParameters = jsonSchemaToActionParameters;
|
|
215
136
|
//# sourceMappingURL=json-schema.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-schema.cjs","names":["z"],"sources":["../../src/utils/json-schema.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { Parameter } from \"../types\";\n\nexport type JSONSchemaString = {\n type: \"string\";\n description?: string;\n enum?: string[];\n};\n\nexport type JSONSchemaNumber = {\n type: \"number\";\n description?: string;\n};\n\nexport type JSONSchemaBoolean = {\n type: \"boolean\";\n description?: string;\n};\n\nexport type JSONSchemaObject = {\n type: \"object\";\n properties?: Record<string, JSONSchema>;\n required?: string[];\n description?: string;\n};\n\nexport type JSONSchemaArray = {\n type: \"array\";\n items: JSONSchema;\n description?: string;\n};\n\nexport type JSONSchema =\n | JSONSchemaString\n | JSONSchemaNumber\n | JSONSchemaBoolean\n | JSONSchemaObject\n | JSONSchemaArray;\n\nexport function actionParametersToJsonSchema(\n actionParameters: Parameter[],\n): JSONSchema {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let parameter of actionParameters || []) {\n parameters[parameter.name] = convertAttribute(parameter);\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of actionParameters || []) {\n if (arg.required !== false) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n return {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n };\n}\n\n// Convert JSONSchema to Parameter[]\nexport function jsonSchemaToActionParameters(\n jsonSchema: JSONSchema,\n): Parameter[] {\n if (jsonSchema.type !== \"object\" || !jsonSchema.properties) {\n return [];\n }\n\n const parameters: Parameter[] = [];\n const requiredFields = jsonSchema.required || [];\n\n for (const [name, schema] of Object.entries(jsonSchema.properties)) {\n const parameter = convertJsonSchemaToParameter(\n name,\n schema,\n requiredFields.includes(name),\n );\n parameters.push(parameter);\n }\n\n return parameters;\n}\n\n// Convert JSONSchema property to Parameter\nfunction convertJsonSchemaToParameter(\n name: string,\n schema: JSONSchema,\n isRequired: boolean,\n): Parameter {\n const baseParameter: Parameter = {\n name,\n description: schema.description,\n };\n\n if (!isRequired) {\n baseParameter.required = false;\n }\n\n // Handle null-union types like [\"string\", \"null\"] by picking the non-null type\n if (Array.isArray(schema.type)) {\n const types = schema.type as string[];\n const hasNull = types.includes(\"null\");\n const nonNullTypes = types.filter((t: string) => t !== \"null\");\n const resolvedType = nonNullTypes.length > 0 ? nonNullTypes[0] : \"string\";\n return convertJsonSchemaToParameter(\n name,\n { ...schema, type: resolvedType } as JSONSchema,\n hasNull ? false : isRequired,\n );\n }\n\n switch (schema.type) {\n case \"string\":\n return {\n ...baseParameter,\n type: \"string\",\n ...(schema.enum && { enum: schema.enum }),\n };\n case \"number\":\n case \"boolean\":\n return {\n ...baseParameter,\n type: schema.type,\n };\n case \"object\":\n if (schema.properties) {\n const attributes: Parameter[] = [];\n const requiredFields = schema.required || [];\n\n for (const [propName, propSchema] of Object.entries(\n schema.properties,\n )) {\n attributes.push(\n convertJsonSchemaToParameter(\n propName,\n propSchema,\n requiredFields.includes(propName),\n ),\n );\n }\n\n return {\n ...baseParameter,\n type: \"object\",\n attributes,\n };\n }\n return {\n ...baseParameter,\n type: \"object\",\n };\n case \"array\":\n if (schema.items.type === \"object\" && \"properties\" in schema.items) {\n const attributes: Parameter[] = [];\n const requiredFields = schema.items.required || [];\n\n for (const [propName, propSchema] of Object.entries(\n schema.items.properties || {},\n )) {\n attributes.push(\n convertJsonSchemaToParameter(\n propName,\n propSchema,\n requiredFields.includes(propName),\n ),\n );\n }\n\n return {\n ...baseParameter,\n type: \"object[]\",\n attributes,\n };\n } else if (schema.items.type === \"array\") {\n throw new Error(\"Nested arrays are not supported\");\n } else {\n return {\n ...baseParameter,\n type: `${schema.items.type}[]`,\n };\n }\n default:\n return {\n ...baseParameter,\n type: \"string\",\n };\n }\n}\n\nfunction convertAttribute(attribute: Parameter): JSONSchema {\n switch (attribute.type) {\n case \"string\":\n return {\n type: \"string\",\n description: attribute.description,\n ...(attribute.enum && { enum: attribute.enum }),\n };\n case \"number\":\n case \"boolean\":\n return {\n type: attribute.type,\n description: attribute.description,\n };\n case \"object\":\n case \"object[]\":\n const properties = attribute.attributes?.reduce(\n (acc, attr) => {\n acc[attr.name] = convertAttribute(attr);\n return acc;\n },\n {} as Record<string, any>,\n );\n const required = attribute.attributes\n ?.filter((attr) => attr.required !== false)\n .map((attr) => attr.name);\n if (attribute.type === \"object[]\") {\n return {\n type: \"array\",\n items: {\n type: \"object\",\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n },\n description: attribute.description,\n };\n }\n return {\n type: \"object\",\n description: attribute.description,\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n };\n default:\n // Handle arrays of primitive types and undefined attribute.type\n if (attribute.type?.endsWith(\"[]\")) {\n const itemType = attribute.type.slice(0, -2);\n return {\n type: \"array\",\n items: { type: itemType as any },\n description: attribute.description,\n };\n }\n // Fallback for undefined type or any other unexpected type\n return {\n type: \"string\",\n description: attribute.description,\n };\n }\n}\n\nexport function convertJsonSchemaToZodSchema(\n jsonSchema: any,\n required: boolean,\n definitions?: Record<string, any>,\n visitedRefs?: Set<string>,\n): z.ZodSchema {\n // Resolve $ref references\n if (jsonSchema.$ref && definitions) {\n const refPath = jsonSchema.$ref.replace(\n /^#\\/\\$defs\\/|^#\\/definitions\\//,\n \"\",\n );\n\n // Detect circular $ref cycles\n const refs = visitedRefs ?? new Set<string>();\n if (refs.has(refPath)) {\n console.warn(\n `[CopilotKit] Circular $ref detected for \"${refPath}\" — falling back to z.any()`,\n );\n let schema = z.any();\n if (jsonSchema.description) {\n schema = schema.describe(jsonSchema.description);\n }\n return required ? schema : schema.optional();\n }\n\n const resolved = definitions[refPath];\n if (resolved) {\n // Clone the set so sibling branches don't see each other's visited refs\n const nextRefs = new Set(refs);\n nextRefs.add(refPath);\n return convertJsonSchemaToZodSchema(\n resolved,\n required,\n definitions,\n nextRefs,\n );\n }\n }\n\n // Collect top-level definitions for $ref resolution\n const defs = definitions ?? jsonSchema.$defs ?? jsonSchema.definitions;\n\n // Handle null-union types like [\"string\", \"null\"]\n if (Array.isArray(jsonSchema.type)) {\n const types = jsonSchema.type as string[];\n const hasNull = types.includes(\"null\");\n const nonNullTypes = types.filter((t: string) => t !== \"null\");\n const resolvedType = nonNullTypes.length > 0 ? nonNullTypes[0] : \"string\";\n const innerSchema = convertJsonSchemaToZodSchema(\n { ...jsonSchema, type: resolvedType },\n true,\n defs,\n visitedRefs,\n );\n let schema = hasNull ? z.union([innerSchema, z.null()]) : innerSchema;\n if (jsonSchema.description) {\n schema = schema.describe(jsonSchema.description);\n }\n return required ? schema : schema.optional();\n }\n\n // Handle anyOf / oneOf as z.union\n const unionVariants = jsonSchema.anyOf ?? jsonSchema.oneOf;\n if (Array.isArray(unionVariants) && unionVariants.length > 0) {\n if (unionVariants.length === 1) {\n return convertJsonSchemaToZodSchema(\n unionVariants[0],\n required,\n defs,\n visitedRefs,\n );\n }\n const schemas = unionVariants.map((v: any) =>\n convertJsonSchemaToZodSchema(v, true, defs, visitedRefs),\n );\n let schema = z.union(\n schemas as [z.ZodSchema, z.ZodSchema, ...z.ZodSchema[]],\n );\n if (jsonSchema.description) {\n schema = schema.describe(jsonSchema.description);\n }\n return required ? schema : schema.optional();\n }\n\n if (jsonSchema.type === \"object\") {\n const spec: { [key: string]: z.ZodSchema } = {};\n\n if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) {\n return !required ? z.object(spec).optional() : z.object(spec);\n }\n\n for (const [key, value] of Object.entries(jsonSchema.properties)) {\n spec[key] = convertJsonSchemaToZodSchema(\n value,\n jsonSchema.required ? jsonSchema.required.includes(key) : false,\n defs,\n visitedRefs,\n );\n }\n let schema = z.object(spec).describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"string\") {\n if (jsonSchema.enum && jsonSchema.enum.length > 0) {\n let schema = z\n .enum(jsonSchema.enum as [string, ...string[]])\n .describe(jsonSchema.description);\n return required ? schema : schema.optional();\n }\n let schema = z.string().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"number\" || jsonSchema.type === \"integer\") {\n let schema = z.number().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"boolean\") {\n let schema = z.boolean().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"array\") {\n let itemSchema = convertJsonSchemaToZodSchema(\n jsonSchema.items,\n true,\n defs,\n visitedRefs,\n );\n let schema = z.array(itemSchema).describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"null\") {\n let schema = z.null().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n }\n\n // Fallback: accept any value rather than throwing\n console.warn(\n `[CopilotKit] Unsupported JSON schema type \"${jsonSchema.type ?? \"unknown\"}\" — falling back to z.any()`,\n );\n let schema = z.any();\n if (jsonSchema.description) {\n schema = schema.describe(jsonSchema.description);\n }\n return required ? schema : schema.optional();\n}\n\nexport function getZodParameters<T extends [] | Parameter[] | undefined>(\n parameters: T,\n): any {\n if (!parameters) return z.object({});\n const jsonParams = actionParametersToJsonSchema(parameters);\n return convertJsonSchemaToZodSchema(jsonParams, true);\n}\n"],"mappings":";;;;AAuCA,SAAgB,6BACd,kBACY;CAEZ,IAAI,aAAqC,EAAE;AAC3C,MAAK,IAAI,aAAa,oBAAoB,EAAE,CAC1C,YAAW,UAAU,QAAQ,iBAAiB,UAAU;CAG1D,IAAI,yBAAmC,EAAE;AACzC,MAAK,IAAI,OAAO,oBAAoB,EAAE,CACpC,KAAI,IAAI,aAAa,MACnB,wBAAuB,KAAK,IAAI,KAAK;AAKzC,QAAO;EACL,MAAM;EACN,YAAY;EACZ,UAAU;EACX;;AAIH,SAAgB,6BACd,YACa;AACb,KAAI,WAAW,SAAS,YAAY,CAAC,WAAW,WAC9C,QAAO,EAAE;CAGX,MAAM,aAA0B,EAAE;CAClC,MAAM,iBAAiB,WAAW,YAAY,EAAE;AAEhD,MAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAAQ,WAAW,WAAW,EAAE;EAClE,MAAM,YAAY,6BAChB,MACA,QACA,eAAe,SAAS,KAAK,CAC9B;AACD,aAAW,KAAK,UAAU;;AAG5B,QAAO;;AAIT,SAAS,6BACP,MACA,QACA,YACW;CACX,MAAM,gBAA2B;EAC/B;EACA,aAAa,OAAO;EACrB;AAED,KAAI,CAAC,WACH,eAAc,WAAW;AAI3B,KAAI,MAAM,QAAQ,OAAO,KAAK,EAAE;EAC9B,MAAM,QAAQ,OAAO;EACrB,MAAM,UAAU,MAAM,SAAS,OAAO;EACtC,MAAM,eAAe,MAAM,QA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A,MAAE,OAAO,EAAE,CAAC;AAEpC,QAAO,6BADY,6BAA6B,WAAW,EACX,KAAK"}
|
|
1
|
+
{"version":3,"file":"json-schema.cjs","names":[],"sources":["../../src/utils/json-schema.ts"],"sourcesContent":["import type { Parameter } from \"../types\";\n\nexport type JSONSchemaString = {\n type: \"string\";\n description?: string;\n enum?: string[];\n};\n\nexport type JSONSchemaNumber = {\n type: \"number\";\n description?: string;\n};\n\nexport type JSONSchemaBoolean = {\n type: \"boolean\";\n description?: string;\n};\n\nexport type JSONSchemaObject = {\n type: \"object\";\n properties?: Record<string, JSONSchema>;\n required?: string[];\n description?: string;\n};\n\nexport type JSONSchemaArray = {\n type: \"array\";\n items: JSONSchema;\n description?: string;\n};\n\nexport type JSONSchema =\n | JSONSchemaString\n | JSONSchemaNumber\n | JSONSchemaBoolean\n | JSONSchemaObject\n | JSONSchemaArray;\n\nexport function actionParametersToJsonSchema(\n actionParameters: Parameter[],\n): JSONSchema {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let parameter of actionParameters || []) {\n parameters[parameter.name] = convertAttribute(parameter);\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of actionParameters || []) {\n if (arg.required !== false) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n return {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n };\n}\n\n// Convert JSONSchema to Parameter[]\nexport function jsonSchemaToActionParameters(\n jsonSchema: JSONSchema,\n): Parameter[] {\n if (jsonSchema.type !== \"object\" || !jsonSchema.properties) {\n return [];\n }\n\n const parameters: Parameter[] = [];\n const requiredFields = jsonSchema.required || [];\n\n for (const [name, schema] of Object.entries(jsonSchema.properties)) {\n const parameter = convertJsonSchemaToParameter(\n name,\n schema,\n requiredFields.includes(name),\n );\n parameters.push(parameter);\n }\n\n return parameters;\n}\n\n// Convert JSONSchema property to Parameter\nfunction convertJsonSchemaToParameter(\n name: string,\n schema: JSONSchema,\n isRequired: boolean,\n): Parameter {\n const baseParameter: Parameter = {\n name,\n description: schema.description,\n };\n\n if (!isRequired) {\n baseParameter.required = false;\n }\n\n // Handle null-union types like [\"string\", \"null\"] by picking the non-null type\n if (Array.isArray(schema.type)) {\n const types = schema.type as string[];\n const hasNull = types.includes(\"null\");\n const nonNullTypes = types.filter((t: string) => t !== \"null\");\n const resolvedType = nonNullTypes.length > 0 ? nonNullTypes[0] : \"string\";\n return convertJsonSchemaToParameter(\n name,\n { ...schema, type: resolvedType } as JSONSchema,\n hasNull ? false : isRequired,\n );\n }\n\n switch (schema.type) {\n case \"string\":\n return {\n ...baseParameter,\n type: \"string\",\n ...(schema.enum && { enum: schema.enum }),\n };\n case \"number\":\n case \"boolean\":\n return {\n ...baseParameter,\n type: schema.type,\n };\n case \"object\":\n if (schema.properties) {\n const attributes: Parameter[] = [];\n const requiredFields = schema.required || [];\n\n for (const [propName, propSchema] of Object.entries(\n schema.properties,\n )) {\n attributes.push(\n convertJsonSchemaToParameter(\n propName,\n propSchema,\n requiredFields.includes(propName),\n ),\n );\n }\n\n return {\n ...baseParameter,\n type: \"object\",\n attributes,\n };\n }\n return {\n ...baseParameter,\n type: \"object\",\n };\n case \"array\":\n if (schema.items.type === \"object\" && \"properties\" in schema.items) {\n const attributes: Parameter[] = [];\n const requiredFields = schema.items.required || [];\n\n for (const [propName, propSchema] of Object.entries(\n schema.items.properties || {},\n )) {\n attributes.push(\n convertJsonSchemaToParameter(\n propName,\n propSchema,\n requiredFields.includes(propName),\n ),\n );\n }\n\n return {\n ...baseParameter,\n type: \"object[]\",\n attributes,\n };\n } else if (schema.items.type === \"array\") {\n throw new Error(\"Nested arrays are not supported\");\n } else {\n return {\n ...baseParameter,\n type: `${schema.items.type}[]`,\n };\n }\n default:\n return {\n ...baseParameter,\n type: \"string\",\n };\n }\n}\n\nfunction convertAttribute(attribute: Parameter): JSONSchema {\n switch (attribute.type) {\n case \"string\":\n return {\n type: \"string\",\n description: attribute.description,\n ...(attribute.enum && { enum: attribute.enum }),\n };\n case \"number\":\n case \"boolean\":\n return {\n type: attribute.type,\n description: attribute.description,\n };\n case \"object\":\n case \"object[]\":\n const properties = attribute.attributes?.reduce(\n (acc, attr) => {\n acc[attr.name] = convertAttribute(attr);\n return acc;\n },\n {} as Record<string, any>,\n );\n const required = attribute.attributes\n ?.filter((attr) => attr.required !== false)\n .map((attr) => attr.name);\n if (attribute.type === \"object[]\") {\n return {\n type: \"array\",\n items: {\n type: \"object\",\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n },\n description: attribute.description,\n };\n }\n return {\n type: \"object\",\n description: attribute.description,\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n };\n default:\n // Handle arrays of primitive types and undefined attribute.type\n if (attribute.type?.endsWith(\"[]\")) {\n const itemType = attribute.type.slice(0, -2);\n return {\n type: \"array\",\n items: { type: itemType as any },\n description: attribute.description,\n };\n }\n // Fallback for undefined type or any other unexpected type\n return {\n type: \"string\",\n description: attribute.description,\n };\n }\n}\n"],"mappings":";;AAsCA,SAAgB,6BACd,kBACY;CAEZ,IAAI,aAAqC,EAAE;AAC3C,MAAK,IAAI,aAAa,oBAAoB,EAAE,CAC1C,YAAW,UAAU,QAAQ,iBAAiB,UAAU;CAG1D,IAAI,yBAAmC,EAAE;AACzC,MAAK,IAAI,OAAO,oBAAoB,EAAE,CACpC,KAAI,IAAI,aAAa,MACnB,wBAAuB,KAAK,IAAI,KAAK;AAKzC,QAAO;EACL,MAAM;EACN,YAAY;EACZ,UAAU;EACX;;AAIH,SAAgB,6BACd,YACa;AACb,KAAI,WAAW,SAAS,YAAY,CAAC,WAAW,WAC9C,QAAO,EAAE;CAGX,MAAM,aAA0B,EAAE;CAClC,MAAM,iBAAiB,WAAW,YAAY,EAAE;AAEhD,MAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAAQ,WAAW,WAAW,EAAE;EAClE,MAAM,YAAY,6BAChB,MACA,QACA,eAAe,SAAS,KAAK,CAC9B;AAC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
2
|
|
|
4
3
|
//#region src/utils/json-schema.d.ts
|
|
5
4
|
type JSONSchemaString = {
|
|
@@ -29,8 +28,6 @@ type JSONSchemaArray = {
|
|
|
29
28
|
type JSONSchema = JSONSchemaString | JSONSchemaNumber | JSONSchemaBoolean | JSONSchemaObject | JSONSchemaArray;
|
|
30
29
|
declare function actionParametersToJsonSchema(actionParameters: Parameter[]): JSONSchema;
|
|
31
30
|
declare function jsonSchemaToActionParameters(jsonSchema: JSONSchema): Parameter[];
|
|
32
|
-
declare function convertJsonSchemaToZodSchema(jsonSchema: any, required: boolean, definitions?: Record<string, any>, visitedRefs?: Set<string>): z.ZodSchema;
|
|
33
|
-
declare function getZodParameters<T extends [] | Parameter[] | undefined>(parameters: T): any;
|
|
34
31
|
//#endregion
|
|
35
|
-
export { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema,
|
|
32
|
+
export { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema, jsonSchemaToActionParameters };
|
|
36
33
|
//# sourceMappingURL=json-schema.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-schema.d.cts","names":[],"sources":["../../src/utils/json-schema.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"json-schema.d.cts","names":[],"sources":["../../src/utils/json-schema.ts"],"mappings":";;;KAEY,gBAAA;EACV,IAAA;EACA,WAAA;EACA,IAAA;AAAA;AAAA,KAGU,gBAAA;EACV,IAAA;EACA,WAAA;AAAA;AAAA,KAGU,iBAAA;EACV,IAAA;EACA,WAAA;AAAA;AAAA,KAGU,gBAAA;EACV,IAAA;EACA,UAAA,GAAa,MAAA,SAAe,UAAA;EAC5B,QAAA;EACA,WAAA;AAAA;AAAA,KAGU,eAAA;EACV,IAAA;EACA,KAAA,EAAO,UAAA;EACP,WAAA;AAAA;AAAA,KAGU,UAAA,GACR,gBAAA,GACA,gBAAA,GACA,iBAAA,GACA,gBAAA,GACA,eAAA;AAAA,iBAEY,4BAAA,CACd,gBAAA,EAAkB,SAAA,KACjB,UAAA;AAAA,iBAuBa,4BAAA,CACd,UAAA,EAAY,UAAA,GACX,SAAA"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Parameter } from "../types/action.mjs";
|
|
2
|
-
import { z } from "zod";
|
|
3
2
|
|
|
4
3
|
//#region src/utils/json-schema.d.ts
|
|
5
4
|
type JSONSchemaString = {
|
|
@@ -29,8 +28,6 @@ type JSONSchemaArray = {
|
|
|
29
28
|
type JSONSchema = JSONSchemaString | JSONSchemaNumber | JSONSchemaBoolean | JSONSchemaObject | JSONSchemaArray;
|
|
30
29
|
declare function actionParametersToJsonSchema(actionParameters: Parameter[]): JSONSchema;
|
|
31
30
|
declare function jsonSchemaToActionParameters(jsonSchema: JSONSchema): Parameter[];
|
|
32
|
-
declare function convertJsonSchemaToZodSchema(jsonSchema: any, required: boolean, definitions?: Record<string, any>, visitedRefs?: Set<string>): z.ZodSchema;
|
|
33
|
-
declare function getZodParameters<T extends [] | Parameter[] | undefined>(parameters: T): any;
|
|
34
31
|
//#endregion
|
|
35
|
-
export { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema,
|
|
32
|
+
export { JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, actionParametersToJsonSchema, jsonSchemaToActionParameters };
|
|
36
33
|
//# sourceMappingURL=json-schema.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-schema.d.mts","names":[],"sources":["../../src/utils/json-schema.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"json-schema.d.mts","names":[],"sources":["../../src/utils/json-schema.ts"],"mappings":";;;KAEY,gBAAA;EACV,IAAA;EACA,WAAA;EACA,IAAA;AAAA;AAAA,KAGU,gBAAA;EACV,IAAA;EACA,WAAA;AAAA;AAAA,KAGU,iBAAA;EACV,IAAA;EACA,WAAA;AAAA;AAAA,KAGU,gBAAA;EACV,IAAA;EACA,UAAA,GAAa,MAAA,SAAe,UAAA;EAC5B,QAAA;EACA,WAAA;AAAA;AAAA,KAGU,eAAA;EACV,IAAA;EACA,KAAA,EAAO,UAAA;EACP,WAAA;AAAA;AAAA,KAGU,UAAA,GACR,gBAAA,GACA,gBAAA,GACA,iBAAA,GACA,gBAAA,GACA,eAAA;AAAA,iBAEY,4BAAA,CACd,gBAAA,EAAkB,SAAA,KACjB,UAAA;AAAA,iBAuBa,4BAAA,CACd,UAAA,EAAY,UAAA,GACX,SAAA"}
|