@kenkaiiii/gg-ai 4.3.85 → 4.3.132
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/index.cjs +55 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +55 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -170,7 +170,61 @@ var import_zod = require("zod");
|
|
|
170
170
|
function zodToJsonSchema(schema) {
|
|
171
171
|
const jsonSchema = import_zod.z.toJSONSchema(schema);
|
|
172
172
|
const { $schema: _schema, ...rest } = jsonSchema;
|
|
173
|
-
return rest;
|
|
173
|
+
return normalizeRootForAnthropic(rest);
|
|
174
|
+
}
|
|
175
|
+
function normalizeRootForAnthropic(schema) {
|
|
176
|
+
const branches = schema.oneOf ?? schema.anyOf;
|
|
177
|
+
if (!branches || branches.length === 0) {
|
|
178
|
+
return schema;
|
|
179
|
+
}
|
|
180
|
+
const allObjects = branches.every((b) => b.type === "object");
|
|
181
|
+
if (!allObjects) {
|
|
182
|
+
return { type: "object", ...schema };
|
|
183
|
+
}
|
|
184
|
+
const mergedProps = {};
|
|
185
|
+
const requiredCounts = {};
|
|
186
|
+
const enumCandidate = {};
|
|
187
|
+
const everyBranchHas = {};
|
|
188
|
+
for (const branch of branches) {
|
|
189
|
+
const props = branch.properties ?? {};
|
|
190
|
+
const required2 = branch.required ?? [];
|
|
191
|
+
for (const [key, prop] of Object.entries(props)) {
|
|
192
|
+
everyBranchHas[key] = (everyBranchHas[key] ?? 0) + 1;
|
|
193
|
+
mergedProps[key] = { ...mergedProps[key], ...prop };
|
|
194
|
+
if (prop && typeof prop === "object" && "const" in prop) {
|
|
195
|
+
const v = prop.const;
|
|
196
|
+
enumCandidate[key] = enumCandidate[key] ?? /* @__PURE__ */ new Set();
|
|
197
|
+
enumCandidate[key].add(v);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
for (const r of required2) {
|
|
201
|
+
requiredCounts[r] = (requiredCounts[r] ?? 0) + 1;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
for (const [key, values] of Object.entries(enumCandidate)) {
|
|
205
|
+
if (everyBranchHas[key] === branches.length && values.size > 1) {
|
|
206
|
+
const list = [...values];
|
|
207
|
+
const { const: _const, ...rest } = mergedProps[key];
|
|
208
|
+
mergedProps[key] = { ...rest, enum: list };
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
const required = Object.entries(requiredCounts).filter(([, count]) => count === branches.length).map(([key]) => key);
|
|
212
|
+
const {
|
|
213
|
+
oneOf: _o,
|
|
214
|
+
anyOf: _a,
|
|
215
|
+
allOf: _all,
|
|
216
|
+
type: _t,
|
|
217
|
+
properties: _p,
|
|
218
|
+
required: _r,
|
|
219
|
+
...meta
|
|
220
|
+
} = schema;
|
|
221
|
+
const out = {
|
|
222
|
+
...meta,
|
|
223
|
+
type: "object",
|
|
224
|
+
properties: mergedProps
|
|
225
|
+
};
|
|
226
|
+
if (required.length > 0) out.required = required;
|
|
227
|
+
return out;
|
|
174
228
|
}
|
|
175
229
|
|
|
176
230
|
// src/providers/transform.ts
|