@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.
@@ -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) {