@copilotkit/shared 1.56.0 → 1.56.2-canary.pin-to-send
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/dist/debug-event-envelope.d.cts +13 -0
- package/dist/debug-event-envelope.d.cts.map +1 -0
- package/dist/debug-event-envelope.d.mts +13 -0
- package/dist/debug-event-envelope.d.mts.map +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +28 -3
- 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 +4 -2
- package/dist/standard-schema.cjs.map +1 -1
- package/dist/standard-schema.d.cts +3 -2
- package/dist/standard-schema.d.cts.map +1 -1
- package/dist/standard-schema.d.mts +3 -2
- package/dist/standard-schema.d.mts.map +1 -1
- package/dist/standard-schema.mjs +4 -2
- package/dist/standard-schema.mjs.map +1 -1
- package/dist/utils/json-schema.cjs +23 -0
- package/dist/utils/json-schema.cjs.map +1 -1
- package/dist/utils/json-schema.d.cts.map +1 -1
- package/dist/utils/json-schema.d.mts.map +1 -1
- package/dist/utils/json-schema.mjs +23 -0
- package/dist/utils/json-schema.mjs.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/standard-schema.test.ts +92 -0
- package/src/debug-event-envelope.ts +9 -0
- package/src/index.ts +2 -0
- package/src/standard-schema.ts +9 -3
- package/src/utils/__tests__/json-schema.test.ts +137 -0
- package/src/utils/json-schema.ts +32 -0
package/src/utils/json-schema.ts
CHANGED
|
@@ -99,6 +99,19 @@ function convertJsonSchemaToParameter(
|
|
|
99
99
|
baseParameter.required = false;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
// Handle null-union types like ["string", "null"] by picking the non-null type
|
|
103
|
+
if (Array.isArray(schema.type)) {
|
|
104
|
+
const types = schema.type as string[];
|
|
105
|
+
const hasNull = types.includes("null");
|
|
106
|
+
const nonNullTypes = types.filter((t: string) => t !== "null");
|
|
107
|
+
const resolvedType = nonNullTypes.length > 0 ? nonNullTypes[0] : "string";
|
|
108
|
+
return convertJsonSchemaToParameter(
|
|
109
|
+
name,
|
|
110
|
+
{ ...schema, type: resolvedType } as JSONSchema,
|
|
111
|
+
hasNull ? false : isRequired,
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
102
115
|
switch (schema.type) {
|
|
103
116
|
case "string":
|
|
104
117
|
return {
|
|
@@ -281,6 +294,25 @@ export function convertJsonSchemaToZodSchema(
|
|
|
281
294
|
// Collect top-level definitions for $ref resolution
|
|
282
295
|
const defs = definitions ?? jsonSchema.$defs ?? jsonSchema.definitions;
|
|
283
296
|
|
|
297
|
+
// Handle null-union types like ["string", "null"]
|
|
298
|
+
if (Array.isArray(jsonSchema.type)) {
|
|
299
|
+
const types = jsonSchema.type as string[];
|
|
300
|
+
const hasNull = types.includes("null");
|
|
301
|
+
const nonNullTypes = types.filter((t: string) => t !== "null");
|
|
302
|
+
const resolvedType = nonNullTypes.length > 0 ? nonNullTypes[0] : "string";
|
|
303
|
+
const innerSchema = convertJsonSchemaToZodSchema(
|
|
304
|
+
{ ...jsonSchema, type: resolvedType },
|
|
305
|
+
true,
|
|
306
|
+
defs,
|
|
307
|
+
visitedRefs,
|
|
308
|
+
);
|
|
309
|
+
let schema = hasNull ? z.union([innerSchema, z.null()]) : innerSchema;
|
|
310
|
+
if (jsonSchema.description) {
|
|
311
|
+
schema = schema.describe(jsonSchema.description);
|
|
312
|
+
}
|
|
313
|
+
return required ? schema : schema.optional();
|
|
314
|
+
}
|
|
315
|
+
|
|
284
316
|
// Handle anyOf / oneOf as z.union
|
|
285
317
|
const unionVariants = jsonSchema.anyOf ?? jsonSchema.oneOf;
|
|
286
318
|
if (Array.isArray(unionVariants) && unionVariants.length > 0) {
|