@prestyj/ai 4.3.96 → 4.3.160

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.js CHANGED
@@ -26,8 +26,8 @@ var EventStream = class {
26
26
  done = false;
27
27
  error = null;
28
28
  push(event) {
29
- if (this.queue.length > 2e3) {
30
- this.queue.splice(0, this.queue.length - 1e3);
29
+ if (this.queue.length > 1e4) {
30
+ this.queue.splice(0, this.queue.length - 5e3);
31
31
  }
32
32
  this.queue.push(event);
33
33
  this.resolve?.();
@@ -124,7 +124,61 @@ import { z } from "zod";
124
124
  function zodToJsonSchema(schema) {
125
125
  const jsonSchema = z.toJSONSchema(schema);
126
126
  const { $schema: _schema, ...rest } = jsonSchema;
127
- return rest;
127
+ return normalizeRootForAnthropic(rest);
128
+ }
129
+ function normalizeRootForAnthropic(schema) {
130
+ const branches = schema.oneOf ?? schema.anyOf;
131
+ if (!branches || branches.length === 0) {
132
+ return schema;
133
+ }
134
+ const allObjects = branches.every((b) => b.type === "object");
135
+ if (!allObjects) {
136
+ return { type: "object", ...schema };
137
+ }
138
+ const mergedProps = {};
139
+ const requiredCounts = {};
140
+ const enumCandidate = {};
141
+ const everyBranchHas = {};
142
+ for (const branch of branches) {
143
+ const props = branch.properties ?? {};
144
+ const required2 = branch.required ?? [];
145
+ for (const [key, prop] of Object.entries(props)) {
146
+ everyBranchHas[key] = (everyBranchHas[key] ?? 0) + 1;
147
+ mergedProps[key] = { ...mergedProps[key], ...prop };
148
+ if (prop && typeof prop === "object" && "const" in prop) {
149
+ const v = prop.const;
150
+ enumCandidate[key] = enumCandidate[key] ?? /* @__PURE__ */ new Set();
151
+ enumCandidate[key].add(v);
152
+ }
153
+ }
154
+ for (const r of required2) {
155
+ requiredCounts[r] = (requiredCounts[r] ?? 0) + 1;
156
+ }
157
+ }
158
+ for (const [key, values] of Object.entries(enumCandidate)) {
159
+ if (everyBranchHas[key] === branches.length && values.size > 1) {
160
+ const list = [...values];
161
+ const { const: _const, ...rest } = mergedProps[key];
162
+ mergedProps[key] = { ...rest, enum: list };
163
+ }
164
+ }
165
+ const required = Object.entries(requiredCounts).filter(([, count]) => count === branches.length).map(([key]) => key);
166
+ const {
167
+ oneOf: _o,
168
+ anyOf: _a,
169
+ allOf: _all,
170
+ type: _t,
171
+ properties: _p,
172
+ required: _r,
173
+ ...meta
174
+ } = schema;
175
+ const out = {
176
+ ...meta,
177
+ type: "object",
178
+ properties: mergedProps
179
+ };
180
+ if (required.length > 0) out.required = required;
181
+ return out;
128
182
  }
129
183
 
130
184
  // src/providers/transform.ts