@ai-sdk/harness-claude-code 1.0.37 → 1.0.39

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.
@@ -0,0 +1,154 @@
1
+ import { z } from 'zod/v4';
2
+
3
+ type JsonLiteral = string | number | boolean | null;
4
+
5
+ export type JsonSchemaObject = {
6
+ type?: string | string[];
7
+ description?: string;
8
+ properties?: Record<string, JsonSchemaObject>;
9
+ required?: string[];
10
+ items?: JsonSchemaObject | JsonSchemaObject[];
11
+ enum?: unknown[];
12
+ const?: unknown;
13
+ oneOf?: JsonSchemaObject[];
14
+ anyOf?: JsonSchemaObject[];
15
+ nullable?: boolean;
16
+ };
17
+
18
+ type ZodShape = Record<string, z.ZodTypeAny>;
19
+
20
+ export function jsonSchemaToZodShape(input: unknown): ZodShape {
21
+ const schema = isJsonSchemaObject(input) ? input : {};
22
+ return toZodShape(schema);
23
+ }
24
+
25
+ function toZodShape(schema: JsonSchemaObject | undefined): ZodShape {
26
+ if (!schema?.properties) return {};
27
+ const required = new Set(schema.required ?? []);
28
+ const shape: ZodShape = {};
29
+ for (const [key, propSchema] of Object.entries(schema.properties)) {
30
+ const propType = toZodType(propSchema);
31
+ let propertyType = required.has(key) ? propType : propType.optional();
32
+ if (propSchema.description) {
33
+ propertyType = propertyType.describe(propSchema.description);
34
+ }
35
+ shape[key] = propertyType;
36
+ }
37
+ return shape;
38
+ }
39
+
40
+ function toZodType(schema: JsonSchemaObject | undefined): z.ZodTypeAny {
41
+ if (!schema) return z.any();
42
+
43
+ let zType =
44
+ zodForConst(schema) ??
45
+ zodForEnum(schema) ??
46
+ zodForNullableUnion(schema) ??
47
+ zodForType(schema);
48
+
49
+ if (isNullable(schema)) zType = zType.nullable();
50
+ if (schema.description) zType = zType.describe(schema.description);
51
+ return zType;
52
+ }
53
+
54
+ function zodForType(schema: JsonSchemaObject): z.ZodTypeAny {
55
+ const types = getNonNullTypes(schema);
56
+ if (types.length > 1) return z.any();
57
+ if (Array.isArray(schema.type) && types.length === 0) return z.null();
58
+ const type = types[0] ?? (schema.properties ? 'object' : undefined);
59
+
60
+ switch (type) {
61
+ case 'string':
62
+ return z.string();
63
+ case 'number':
64
+ return z.number();
65
+ case 'integer':
66
+ return z.number().int();
67
+ case 'boolean':
68
+ return z.boolean();
69
+ case 'array':
70
+ return z.array(
71
+ Array.isArray(schema.items) ? z.any() : toZodType(schema.items),
72
+ );
73
+ case 'object':
74
+ return z.object(toZodShape(schema));
75
+ case 'null':
76
+ return z.null();
77
+ default:
78
+ return z.any();
79
+ }
80
+ }
81
+
82
+ function zodForConst(schema: JsonSchemaObject): z.ZodTypeAny | undefined {
83
+ if (!('const' in schema)) return undefined;
84
+ return isJsonLiteral(schema.const) ? z.literal(schema.const) : z.any();
85
+ }
86
+
87
+ function zodForEnum(schema: JsonSchemaObject): z.ZodTypeAny | undefined {
88
+ if (!Array.isArray(schema.enum)) return undefined;
89
+ if (!schema.enum.every(isJsonLiteral)) return z.any();
90
+ return zodForLiterals(schema.enum);
91
+ }
92
+
93
+ function zodForNullableUnion(
94
+ schema: JsonSchemaObject,
95
+ ): z.ZodTypeAny | undefined {
96
+ const unionSchemas = schema.anyOf ?? schema.oneOf;
97
+ if (!unionSchemas || unionSchemas.length < 2) return undefined;
98
+
99
+ const nonNullSchemas = unionSchemas.filter(item => !isNullOnlySchema(item));
100
+ if (nonNullSchemas.length !== 1) return undefined;
101
+
102
+ return toZodType(nonNullSchemas[0]).nullable();
103
+ }
104
+
105
+ function zodForLiterals(values: JsonLiteral[]): z.ZodTypeAny {
106
+ if (values.length === 0) return z.any();
107
+ if (values.length === 1) return z.literal(values[0]);
108
+
109
+ const literals = values.map(value => z.literal(value)) as unknown as [
110
+ z.ZodTypeAny,
111
+ z.ZodTypeAny,
112
+ ...z.ZodTypeAny[],
113
+ ];
114
+ return z.union(literals);
115
+ }
116
+
117
+ function getNonNullTypes(schema: JsonSchemaObject): string[] {
118
+ return Array.isArray(schema.type)
119
+ ? schema.type.filter(type => type !== 'null')
120
+ : ([schema.type].filter(Boolean) as string[]);
121
+ }
122
+
123
+ function isNullable(schema: JsonSchemaObject): boolean {
124
+ return (
125
+ schema.nullable === true ||
126
+ (Array.isArray(schema.type) && schema.type.includes('null'))
127
+ );
128
+ }
129
+
130
+ function isNullOnlySchema(schema: JsonSchemaObject): boolean {
131
+ return (
132
+ schema.type === 'null' ||
133
+ (Array.isArray(schema.type) &&
134
+ schema.type.length === 1 &&
135
+ schema.type[0] === 'null') ||
136
+ schema.const === null ||
137
+ (Array.isArray(schema.enum) &&
138
+ schema.enum.length === 1 &&
139
+ schema.enum[0] === null)
140
+ );
141
+ }
142
+
143
+ function isJsonSchemaObject(input: unknown): input is JsonSchemaObject {
144
+ return input != null && typeof input === 'object' && !Array.isArray(input);
145
+ }
146
+
147
+ function isJsonLiteral(value: unknown): value is JsonLiteral {
148
+ return (
149
+ value === null ||
150
+ typeof value === 'string' ||
151
+ typeof value === 'boolean' ||
152
+ (typeof value === 'number' && Number.isFinite(value))
153
+ );
154
+ }
@@ -4,10 +4,10 @@
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "dependencies": {
7
- "@anthropic-ai/claude-agent-sdk": "0.3.177",
8
- "@anthropic-ai/claude-code": "2.1.177",
7
+ "@anthropic-ai/claude-agent-sdk": "0.3.213",
8
+ "@anthropic-ai/claude-code": "2.1.213",
9
9
  "@modelcontextprotocol/sdk": "1.29.0",
10
10
  "ws": "8.21.0",
11
- "zod": "3.25.76"
11
+ "zod": "4.4.3"
12
12
  }
13
13
  }