UNPKG

@openai/agents-realtime

Version:

The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows. This package contains the logic for building realtime voice agents on the server or in the browser.

1,393 lines (1,392 loc) 1.94 MB
var So = Object.defineProperty; var zs = (n) => { throw TypeError(n); }; var To = (n, e, t) => e in n ? So(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t; var x = (n, e, t) => To(n, typeof e != "symbol" ? e + "" : e, t), Nr = (n, e, t) => e.has(n) || zs("Cannot " + t); var u = (n, e, t) => (Nr(n, e, "read from private field"), t ? t.call(n) : e.get(n)), R = (n, e, t) => e.has(n) ? zs("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(n) : e.set(n, t), k = (n, e, t, r) => (Nr(n, e, "write to private field"), r ? r.call(n, t) : e.set(n, t), t), U = (n, e, t) => (Nr(n, e, "access private method"), t); const Br = { version: "0.3.7" }; async function ws(n) { try { return [null, await n()]; } catch (e) { return [e, null]; } } function ko(n) { const e = Object.values(n).filter((r) => typeof r == "number"); return Object.entries(n).filter(([r, s]) => e.indexOf(+r) === -1).map(([r, s]) => s); } class Xi { constructor() { this._map = /* @__PURE__ */ new Map(), this._idmap = /* @__PURE__ */ new Map(); } add(e, ...t) { const r = t[0]; if (this._map.set(e, r), r && typeof r == "object" && "id" in r) { if (this._idmap.has(r.id)) throw new Error(`ID ${r.id} already exists in the registry`); this._idmap.set(r.id, e); } return this; } clear() { return this._map = /* @__PURE__ */ new Map(), this._idmap = /* @__PURE__ */ new Map(), this; } remove(e) { const t = this._map.get(e); return t && typeof t == "object" && "id" in t && this._idmap.delete(t.id), this._map.delete(e), this; } get(e) { const t = e._zod.parent; if (t) { const r = { ...this.get(t) ?? {} }; return delete r.id, { ...r, ...this._map.get(e) }; } return this._map.get(e); } has(e) { return this._map.has(e); } } function Ao() { return new Xi(); } const Co = /* @__PURE__ */ Ao(); class Gs { constructor(e) { this.counter = 0, this.metadataRegistry = (e == null ? void 0 : e.metadata) ?? Co, this.target = (e == null ? void 0 : e.target) ?? "draft-2020-12", this.unrepresentable = (e == null ? void 0 : e.unrepresentable) ?? "throw", this.override = (e == null ? void 0 : e.override) ?? (() => { }), this.io = (e == null ? void 0 : e.io) ?? "output", this.seen = /* @__PURE__ */ new Map(); } process(e, t = { path: [], schemaPath: [] }) { var d, m, g; var r; const s = e._zod.def, i = { guid: "uuid", url: "uri", datetime: "date-time", json_string: "json-string", regex: "" // do not set }, o = this.seen.get(e); if (o) return o.count++, t.schemaPath.includes(e) && (o.cycle = t.path), o.schema; const a = { schema: {}, count: 1, cycle: void 0, path: t.path }; this.seen.set(e, a); const c = (m = (d = e._zod).toJSONSchema) == null ? void 0 : m.call(d); if (c) a.schema = c; else { const v = { ...t, schemaPath: [...t.schemaPath, e], path: t.path }, S = e._zod.parent; if (S) a.ref = S, this.process(S, v), this.seen.get(S).isParent = !0; else { const y = a.schema; switch (s.type) { case "string": { const h = y; h.type = "string"; const { minimum: b, maximum: _, format: N, patterns: T, contentEncoding: A } = e._zod.bag; if (typeof b == "number" && (h.minLength = b), typeof _ == "number" && (h.maxLength = _), N && (h.format = i[N] ?? N, h.format === "" && delete h.format), A && (h.contentEncoding = A), T && T.size > 0) { const D = [...T]; D.length === 1 ? h.pattern = D[0].source : D.length > 1 && (a.schema.allOf = [ ...D.map((F) => ({ ...this.target === "draft-7" ? { type: "string" } : {}, pattern: F.source })) ]); } break; } case "number": { const h = y, { minimum: b, maximum: _, format: N, multipleOf: T, exclusiveMaximum: A, exclusiveMinimum: D } = e._zod.bag; typeof N == "string" && N.includes("int") ? h.type = "integer" : h.type = "number", typeof D == "number" && (h.exclusiveMinimum = D), typeof b == "number" && (h.minimum = b, typeof D == "number" && (D >= b ? delete h.minimum : delete h.exclusiveMinimum)), typeof A == "number" && (h.exclusiveMaximum = A), typeof _ == "number" && (h.maximum = _, typeof A == "number" && (A <= _ ? delete h.maximum : delete h.exclusiveMaximum)), typeof T == "number" && (h.multipleOf = T); break; } case "boolean": { const h = y; h.type = "boolean"; break; } case "bigint": { if (this.unrepresentable === "throw") throw new Error("BigInt cannot be represented in JSON Schema"); break; } case "symbol": { if (this.unrepresentable === "throw") throw new Error("Symbols cannot be represented in JSON Schema"); break; } case "null": { y.type = "null"; break; } case "any": break; case "unknown": break; case "undefined": { if (this.unrepresentable === "throw") throw new Error("Undefined cannot be represented in JSON Schema"); break; } case "void": { if (this.unrepresentable === "throw") throw new Error("Void cannot be represented in JSON Schema"); break; } case "never": { y.not = {}; break; } case "date": { if (this.unrepresentable === "throw") throw new Error("Date cannot be represented in JSON Schema"); break; } case "array": { const h = y, { minimum: b, maximum: _ } = e._zod.bag; typeof b == "number" && (h.minItems = b), typeof _ == "number" && (h.maxItems = _), h.type = "array", h.items = this.process(s.element, { ...v, path: [...v.path, "items"] }); break; } case "object": { const h = y; h.type = "object", h.properties = {}; const b = s.shape; for (const T in b) h.properties[T] = this.process(b[T], { ...v, path: [...v.path, "properties", T] }); const _ = new Set(Object.keys(b)), N = new Set([..._].filter((T) => { const A = s.shape[T]._zod; return this.io === "input" ? A.optin === void 0 : A.optout === void 0; })); N.size > 0 && (h.required = Array.from(N)), ((g = s.catchall) == null ? void 0 : g._zod.def.type) === "never" ? h.additionalProperties = !1 : s.catchall ? s.catchall && (h.additionalProperties = this.process(s.catchall, { ...v, path: [...v.path, "additionalProperties"] })) : this.io === "output" && (h.additionalProperties = !1); break; } case "union": { const h = y; h.anyOf = s.options.map((b, _) => this.process(b, { ...v, path: [...v.path, "anyOf", _] })); break; } case "intersection": { const h = y, b = this.process(s.left, { ...v, path: [...v.path, "allOf", 0] }), _ = this.process(s.right, { ...v, path: [...v.path, "allOf", 1] }), N = (A) => "allOf" in A && Object.keys(A).length === 1, T = [ ...N(b) ? b.allOf : [b], ...N(_) ? _.allOf : [_] ]; h.allOf = T; break; } case "tuple": { const h = y; h.type = "array"; const b = s.items.map((T, A) => this.process(T, { ...v, path: [...v.path, "prefixItems", A] })); if (this.target === "draft-2020-12" ? h.prefixItems = b : h.items = b, s.rest) { const T = this.process(s.rest, { ...v, path: [...v.path, "items"] }); this.target === "draft-2020-12" ? h.items = T : h.additionalItems = T; } s.rest && (h.items = this.process(s.rest, { ...v, path: [...v.path, "items"] })); const { minimum: _, maximum: N } = e._zod.bag; typeof _ == "number" && (h.minItems = _), typeof N == "number" && (h.maxItems = N); break; } case "record": { const h = y; h.type = "object", h.propertyNames = this.process(s.keyType, { ...v, path: [...v.path, "propertyNames"] }), h.additionalProperties = this.process(s.valueType, { ...v, path: [...v.path, "additionalProperties"] }); break; } case "map": { if (this.unrepresentable === "throw") throw new Error("Map cannot be represented in JSON Schema"); break; } case "set": { if (this.unrepresentable === "throw") throw new Error("Set cannot be represented in JSON Schema"); break; } case "enum": { const h = y, b = ko(s.entries); b.every((_) => typeof _ == "number") && (h.type = "number"), b.every((_) => typeof _ == "string") && (h.type = "string"), h.enum = b; break; } case "literal": { const h = y, b = []; for (const _ of s.values) if (_ === void 0) { if (this.unrepresentable === "throw") throw new Error("Literal `undefined` cannot be represented in JSON Schema"); } else if (typeof _ == "bigint") { if (this.unrepresentable === "throw") throw new Error("BigInt literals cannot be represented in JSON Schema"); b.push(Number(_)); } else b.push(_); if (b.length !== 0) if (b.length === 1) { const _ = b[0]; h.type = _ === null ? "null" : typeof _, h.const = _; } else b.every((_) => typeof _ == "number") && (h.type = "number"), b.every((_) => typeof _ == "string") && (h.type = "string"), b.every((_) => typeof _ == "boolean") && (h.type = "string"), b.every((_) => _ === null) && (h.type = "null"), h.enum = b; break; } case "file": { const h = y, b = { type: "string", format: "binary", contentEncoding: "binary" }, { minimum: _, maximum: N, mime: T } = e._zod.bag; _ !== void 0 && (b.minLength = _), N !== void 0 && (b.maxLength = N), T ? T.length === 1 ? (b.contentMediaType = T[0], Object.assign(h, b)) : h.anyOf = T.map((A) => ({ ...b, contentMediaType: A })) : Object.assign(h, b); break; } case "transform": { if (this.unrepresentable === "throw") throw new Error("Transforms cannot be represented in JSON Schema"); break; } case "nullable": { const h = this.process(s.innerType, v); y.anyOf = [h, { type: "null" }]; break; } case "nonoptional": { this.process(s.innerType, v), a.ref = s.innerType; break; } case "success": { const h = y; h.type = "boolean"; break; } case "default": { this.process(s.innerType, v), a.ref = s.innerType, y.default = JSON.parse(JSON.stringify(s.defaultValue)); break; } case "prefault": { this.process(s.innerType, v), a.ref = s.innerType, this.io === "input" && (y._prefault = JSON.parse(JSON.stringify(s.defaultValue))); break; } case "catch": { this.process(s.innerType, v), a.ref = s.innerType; let h; try { h = s.catchValue(void 0); } catch { throw new Error("Dynamic catch values are not supported in JSON Schema"); } y.default = h; break; } case "nan": { if (this.unrepresentable === "throw") throw new Error("NaN cannot be represented in JSON Schema"); break; } case "template_literal": { const h = y, b = e._zod.pattern; if (!b) throw new Error("Pattern not found in template literal"); h.type = "string", h.pattern = b.source; break; } case "pipe": { const h = this.io === "input" ? s.in._zod.def.type === "transform" ? s.out : s.in : s.out; this.process(h, v), a.ref = h; break; } case "readonly": { this.process(s.innerType, v), a.ref = s.innerType, y.readOnly = !0; break; } // passthrough types case "promise": { this.process(s.innerType, v), a.ref = s.innerType; break; } case "optional": { this.process(s.innerType, v), a.ref = s.innerType; break; } case "lazy": { const h = e._zod.innerType; this.process(h, v), a.ref = h; break; } case "custom": { if (this.unrepresentable === "throw") throw new Error("Custom types cannot be represented in JSON Schema"); break; } } } } const l = this.metadataRegistry.get(e); return l && Object.assign(a.schema, l), this.io === "input" && le(e) && (delete a.schema.examples, delete a.schema.default), this.io === "input" && a.schema._prefault && ((r = a.schema).default ?? (r.default = a.schema._prefault)), delete a.schema._prefault, this.seen.get(e).schema; } emit(e, t) { var f, d, m, g, v, S; const r = { cycles: (t == null ? void 0 : t.cycles) ?? "ref", reused: (t == null ? void 0 : t.reused) ?? "inline", // unrepresentable: _params?.unrepresentable ?? "throw", // uri: _params?.uri ?? ((id) => `${id}`), external: (t == null ? void 0 : t.external) ?? void 0 }, s = this.seen.get(e); if (!s) throw new Error("Unprocessed schema. This is a bug in Zod."); const i = (y) => { var T; const h = this.target === "draft-2020-12" ? "$defs" : "definitions"; if (r.external) { const A = (T = r.external.registry.get(y[0])) == null ? void 0 : T.id, D = r.external.uri ?? ((z) => z); if (A) return { ref: D(A) }; const F = y[1].defId ?? y[1].schema.id ?? `schema${this.counter++}`; return y[1].defId = F, { defId: F, ref: `${D("__shared")}#/${h}/${F}` }; } if (y[1] === s) return { ref: "#" }; const _ = `#/${h}/`, N = y[1].schema.id ?? `__schema${this.counter++}`; return { defId: N, ref: _ + N }; }, o = (y) => { if (y[1].schema.$ref) return; const h = y[1], { ref: b, defId: _ } = i(y); h.def = { ...h.schema }, _ && (h.defId = _); const N = h.schema; for (const T in N) delete N[T]; N.$ref = b; }; if (r.cycles === "throw") for (const y of this.seen.entries()) { const h = y[1]; if (h.cycle) throw new Error(`Cycle detected: #/${(f = h.cycle) == null ? void 0 : f.join("/")}/<root> Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`); } for (const y of this.seen.entries()) { const h = y[1]; if (e === y[0]) { o(y); continue; } if (r.external) { const _ = (d = r.external.registry.get(y[0])) == null ? void 0 : d.id; if (e !== y[0] && _) { o(y); continue; } } if ((m = this.metadataRegistry.get(y[0])) == null ? void 0 : m.id) { o(y); continue; } if (h.cycle) { o(y); continue; } if (h.count > 1 && r.reused === "ref") { o(y); continue; } } const a = (y, h) => { const b = this.seen.get(y), _ = b.def ?? b.schema, N = { ..._ }; if (b.ref === null) return; const T = b.ref; if (b.ref = null, T) { a(T, h); const A = this.seen.get(T).schema; A.$ref && h.target === "draft-7" ? (_.allOf = _.allOf ?? [], _.allOf.push(A)) : (Object.assign(_, A), Object.assign(_, N)); } b.isParent || this.override({ zodSchema: y, jsonSchema: _, path: b.path ?? [] }); }; for (const y of [...this.seen.entries()].reverse()) a(y[0], { target: this.target }); const c = {}; if (this.target === "draft-2020-12" ? c.$schema = "https://json-schema.org/draft/2020-12/schema" : this.target === "draft-7" ? c.$schema = "http://json-schema.org/draft-07/schema#" : console.warn(`Invalid target: ${this.target}`), (g = r.external) != null && g.uri) { const y = (v = r.external.registry.get(e)) == null ? void 0 : v.id; if (!y) throw new Error("Schema is missing an `id` property"); c.$id = r.external.uri(y); } Object.assign(c, s.def); const l = ((S = r.external) == null ? void 0 : S.defs) ?? {}; for (const y of this.seen.entries()) { const h = y[1]; h.def && h.defId && (l[h.defId] = h.def); } r.external || Object.keys(l).length > 0 && (this.target === "draft-2020-12" ? c.$defs = l : c.definitions = l); try { return JSON.parse(JSON.stringify(c)); } catch { throw new Error("Error converting schema to JSON."); } } } function Oo(n, e) { if (n instanceof Xi) { const r = new Gs(e), s = {}; for (const a of n._idmap.entries()) { const [c, l] = a; r.process(l); } const i = {}, o = { registry: n, uri: e == null ? void 0 : e.uri, defs: s }; for (const a of n._idmap.entries()) { const [c, l] = a; i[c] = r.emit(l, { ...e, external: o }); } if (Object.keys(s).length > 0) { const a = r.target === "draft-2020-12" ? "$defs" : "definitions"; i.__shared = { [a]: s }; } return { schemas: i }; } const t = new Gs(e); return t.process(n), t.emit(n, e); } function le(n, e) { const t = e ?? { seen: /* @__PURE__ */ new Set() }; if (t.seen.has(n)) return !1; t.seen.add(n); const s = n._zod.def; switch (s.type) { case "string": case "number": case "bigint": case "boolean": case "date": case "symbol": case "undefined": case "null": case "any": case "unknown": case "never": case "void": case "literal": case "enum": case "nan": case "file": case "template_literal": return !1; case "array": return le(s.element, t); case "object": { for (const i in s.shape) if (le(s.shape[i], t)) return !0; return !1; } case "union": { for (const i of s.options) if (le(i, t)) return !0; return !1; } case "intersection": return le(s.left, t) || le(s.right, t); case "tuple": { for (const i of s.items) if (le(i, t)) return !0; return !!(s.rest && le(s.rest, t)); } case "record": return le(s.keyType, t) || le(s.valueType, t); case "map": return le(s.keyType, t) || le(s.valueType, t); case "set": return le(s.valueType, t); // inner types case "promise": case "optional": case "nonoptional": case "nullable": case "readonly": return le(s.innerType, t); case "lazy": return le(s.getter(), t); case "default": return le(s.innerType, t); case "prefault": return le(s.innerType, t); case "custom": return !1; case "transform": return !0; case "pipe": return le(s.in, t) || le(s.out, t); case "success": return !1; case "catch": return !1; } throw new Error(`Unknown schema type: ${s.type}`); } function Eo(n, e) { const t = { ...n }; return Object.defineProperties(t, { $brand: { value: "auto-parseable-response-format", enumerable: !1 }, $parseRaw: { value: e, enumerable: !1 } }), t; } const Ro = Symbol("Let zodToJsonSchema decide on which parser to use"), Vs = { name: void 0, $refStrategy: "root", effectStrategy: "input", pipeStrategy: "all", dateStrategy: "format:date-time", mapStrategy: "entries", nullableStrategy: "from-target", removeAdditionalStrategy: "passthrough", definitionPath: "definitions", target: "jsonSchema7", strictUnions: !1, errorMessages: !1, markdownDescription: !1, patternStrategy: "escape", applyRegexFlags: !1, emailStrategy: "format:email", base64Strategy: "contentEncoding:base64", nameStrategy: "ref" }, No = (n) => typeof n == "string" ? { ...Vs, basePath: ["#"], definitions: {}, name: n } : { ...Vs, basePath: ["#"], definitions: {}, ...n }, zr = (n) => "_def" in n ? n._def : n; function Po(n) { if (!n) return !0; for (const e in n) return !1; return !0; } const Do = (n) => { const e = No(n), t = e.name !== void 0 ? [...e.basePath, e.definitionPath, e.name] : e.basePath; return { ...e, currentPath: t, propertyPath: void 0, seenRefs: /* @__PURE__ */ new Set(), seen: new Map(Object.entries(e.definitions).map(([r, s]) => [ zr(s), { def: zr(s), path: [...e.basePath, e.definitionPath, r], // Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now. jsonSchema: void 0 } ])) }; }; function Qi(n, e, t, r) { r != null && r.errorMessages && t && (n.errorMessage = { ...n.errorMessage, [e]: t }); } function Q(n, e, t, r, s) { n[e] = t, Qi(n, e, r, s); } var Y; (function(n) { n.assertEqual = (s) => { }; function e(s) { } n.assertIs = e; function t(s) { throw new Error(); } n.assertNever = t, n.arrayToEnum = (s) => { const i = {}; for (const o of s) i[o] = o; return i; }, n.getValidEnumValues = (s) => { const i = n.objectKeys(s).filter((a) => typeof s[s[a]] != "number"), o = {}; for (const a of i) o[a] = s[a]; return n.objectValues(o); }, n.objectValues = (s) => n.objectKeys(s).map(function(i) { return s[i]; }), n.objectKeys = typeof Object.keys == "function" ? (s) => Object.keys(s) : (s) => { const i = []; for (const o in s) Object.prototype.hasOwnProperty.call(s, o) && i.push(o); return i; }, n.find = (s, i) => { for (const o of s) if (i(o)) return o; }, n.isInteger = typeof Number.isInteger == "function" ? (s) => Number.isInteger(s) : (s) => typeof s == "number" && Number.isFinite(s) && Math.floor(s) === s; function r(s, i = " | ") { return s.map((o) => typeof o == "string" ? `'${o}'` : o).join(i); } n.joinValues = r, n.jsonStringifyReplacer = (s, i) => typeof i == "bigint" ? i.toString() : i; })(Y || (Y = {})); var Ws; (function(n) { n.mergeShapes = (e, t) => ({ ...e, ...t // second overwrites first }); })(Ws || (Ws = {})); const M = Y.arrayToEnum([ "string", "nan", "number", "integer", "float", "boolean", "date", "bigint", "symbol", "function", "undefined", "null", "array", "object", "unknown", "promise", "void", "never", "map", "set" ]), st = (n) => { switch (typeof n) { case "undefined": return M.undefined; case "string": return M.string; case "number": return Number.isNaN(n) ? M.nan : M.number; case "boolean": return M.boolean; case "function": return M.function; case "bigint": return M.bigint; case "symbol": return M.symbol; case "object": return Array.isArray(n) ? M.array : n === null ? M.null : n.then && typeof n.then == "function" && n.catch && typeof n.catch == "function" ? M.promise : typeof Map < "u" && n instanceof Map ? M.map : typeof Set < "u" && n instanceof Set ? M.set : typeof Date < "u" && n instanceof Date ? M.date : M.object; default: return M.unknown; } }, C = Y.arrayToEnum([ "invalid_type", "invalid_literal", "custom", "invalid_union", "invalid_union_discriminator", "invalid_enum_value", "unrecognized_keys", "invalid_arguments", "invalid_return_type", "invalid_date", "invalid_string", "too_small", "too_big", "invalid_intersection_types", "not_multiple_of", "not_finite" ]); class Fe extends Error { get errors() { return this.issues; } constructor(e) { super(), this.issues = [], this.addIssue = (r) => { this.issues = [...this.issues, r]; }, this.addIssues = (r = []) => { this.issues = [...this.issues, ...r]; }; const t = new.target.prototype; Object.setPrototypeOf ? Object.setPrototypeOf(this, t) : this.__proto__ = t, this.name = "ZodError", this.issues = e; } format(e) { const t = e || function(i) { return i.message; }, r = { _errors: [] }, s = (i) => { for (const o of i.issues) if (o.code === "invalid_union") o.unionErrors.map(s); else if (o.code === "invalid_return_type") s(o.returnTypeError); else if (o.code === "invalid_arguments") s(o.argumentsError); else if (o.path.length === 0) r._errors.push(t(o)); else { let a = r, c = 0; for (; c < o.path.length; ) { const l = o.path[c]; c === o.path.length - 1 ? (a[l] = a[l] || { _errors: [] }, a[l]._errors.push(t(o))) : a[l] = a[l] || { _errors: [] }, a = a[l], c++; } } }; return s(this), r; } static assert(e) { if (!(e instanceof Fe)) throw new Error(`Not a ZodError: ${e}`); } toString() { return this.message; } get message() { return JSON.stringify(this.issues, Y.jsonStringifyReplacer, 2); } get isEmpty() { return this.issues.length === 0; } flatten(e = (t) => t.message) { const t = {}, r = []; for (const s of this.issues) if (s.path.length > 0) { const i = s.path[0]; t[i] = t[i] || [], t[i].push(e(s)); } else r.push(e(s)); return { formErrors: r, fieldErrors: t }; } get formErrors() { return this.flatten(); } } Fe.create = (n) => new Fe(n); const Gr = (n, e) => { let t; switch (n.code) { case C.invalid_type: n.received === M.undefined ? t = "Required" : t = `Expected ${n.expected}, received ${n.received}`; break; case C.invalid_literal: t = `Invalid literal value, expected ${JSON.stringify(n.expected, Y.jsonStringifyReplacer)}`; break; case C.unrecognized_keys: t = `Unrecognized key(s) in object: ${Y.joinValues(n.keys, ", ")}`; break; case C.invalid_union: t = "Invalid input"; break; case C.invalid_union_discriminator: t = `Invalid discriminator value. Expected ${Y.joinValues(n.options)}`; break; case C.invalid_enum_value: t = `Invalid enum value. Expected ${Y.joinValues(n.options)}, received '${n.received}'`; break; case C.invalid_arguments: t = "Invalid function arguments"; break; case C.invalid_return_type: t = "Invalid function return type"; break; case C.invalid_date: t = "Invalid date"; break; case C.invalid_string: typeof n.validation == "object" ? "includes" in n.validation ? (t = `Invalid input: must include "${n.validation.includes}"`, typeof n.validation.position == "number" && (t = `${t} at one or more positions greater than or equal to ${n.validation.position}`)) : "startsWith" in n.validation ? t = `Invalid input: must start with "${n.validation.startsWith}"` : "endsWith" in n.validation ? t = `Invalid input: must end with "${n.validation.endsWith}"` : Y.assertNever(n.validation) : n.validation !== "regex" ? t = `Invalid ${n.validation}` : t = "Invalid"; break; case C.too_small: n.type === "array" ? t = `Array must contain ${n.exact ? "exactly" : n.inclusive ? "at least" : "more than"} ${n.minimum} element(s)` : n.type === "string" ? t = `String must contain ${n.exact ? "exactly" : n.inclusive ? "at least" : "over"} ${n.minimum} character(s)` : n.type === "number" ? t = `Number must be ${n.exact ? "exactly equal to " : n.inclusive ? "greater than or equal to " : "greater than "}${n.minimum}` : n.type === "bigint" ? t = `Number must be ${n.exact ? "exactly equal to " : n.inclusive ? "greater than or equal to " : "greater than "}${n.minimum}` : n.type === "date" ? t = `Date must be ${n.exact ? "exactly equal to " : n.inclusive ? "greater than or equal to " : "greater than "}${new Date(Number(n.minimum))}` : t = "Invalid input"; break; case C.too_big: n.type === "array" ? t = `Array must contain ${n.exact ? "exactly" : n.inclusive ? "at most" : "less than"} ${n.maximum} element(s)` : n.type === "string" ? t = `String must contain ${n.exact ? "exactly" : n.inclusive ? "at most" : "under"} ${n.maximum} character(s)` : n.type === "number" ? t = `Number must be ${n.exact ? "exactly" : n.inclusive ? "less than or equal to" : "less than"} ${n.maximum}` : n.type === "bigint" ? t = `BigInt must be ${n.exact ? "exactly" : n.inclusive ? "less than or equal to" : "less than"} ${n.maximum}` : n.type === "date" ? t = `Date must be ${n.exact ? "exactly" : n.inclusive ? "smaller than or equal to" : "smaller than"} ${new Date(Number(n.maximum))}` : t = "Invalid input"; break; case C.custom: t = "Invalid input"; break; case C.invalid_intersection_types: t = "Intersection results could not be merged"; break; case C.not_multiple_of: t = `Number must be a multiple of ${n.multipleOf}`; break; case C.not_finite: t = "Number must be finite"; break; default: t = e.defaultError, Y.assertNever(n); } return { message: t }; }; let Mo = Gr; function jo() { return Mo; } const $o = (n) => { const { data: e, path: t, errorMaps: r, issueData: s } = n, i = [...t, ...s.path || []], o = { ...s, path: i }; if (s.message !== void 0) return { ...s, path: i, message: s.message }; let a = ""; const c = r.filter((l) => !!l).slice().reverse(); for (const l of c) a = l(o, { data: e, defaultError: a }).message; return { ...s, path: i, message: a }; }; function P(n, e) { const t = jo(), r = $o({ issueData: e, data: n.data, path: n.path, errorMaps: [ n.common.contextualErrorMap, // contextual error map is first priority n.schemaErrorMap, // then schema-bound map if available t, // then global override map t === Gr ? void 0 : Gr // then global default map ].filter((s) => !!s) }); n.common.issues.push(r); } class _e { constructor() { this.value = "valid"; } dirty() { this.value === "valid" && (this.value = "dirty"); } abort() { this.value !== "aborted" && (this.value = "aborted"); } static mergeArray(e, t) { const r = []; for (const s of t) { if (s.status === "aborted") return J; s.status === "dirty" && e.dirty(), r.push(s.value); } return { status: e.value, value: r }; } static async mergeObjectAsync(e, t) { const r = []; for (const s of t) { const i = await s.key, o = await s.value; r.push({ key: i, value: o }); } return _e.mergeObjectSync(e, r); } static mergeObjectSync(e, t) { const r = {}; for (const s of t) { const { key: i, value: o } = s; if (i.status === "aborted" || o.status === "aborted") return J; i.status === "dirty" && e.dirty(), o.status === "dirty" && e.dirty(), i.value !== "__proto__" && (typeof o.value < "u" || s.alwaysSet) && (r[i.value] = o.value); } return { status: e.value, value: r }; } } const J = Object.freeze({ status: "aborted" }), fn = (n) => ({ status: "dirty", value: n }), Ae = (n) => ({ status: "valid", value: n }), Hs = (n) => n.status === "aborted", Ks = (n) => n.status === "dirty", an = (n) => n.status === "valid", sr = (n) => typeof Promise < "u" && n instanceof Promise; var $; (function(n) { n.errToObj = (e) => typeof e == "string" ? { message: e } : e || {}, n.toString = (e) => typeof e == "string" ? e : e == null ? void 0 : e.message; })($ || ($ = {})); class Le { constructor(e, t, r, s) { this._cachedPath = [], this.parent = e, this.data = t, this._path = r, this._key = s; } get path() { return this._cachedPath.length || (Array.isArray(this._key) ? this._cachedPath.push(...this._path, ...this._key) : this._cachedPath.push(...this._path, this._key)), this._cachedPath; } } const Ys = (n, e) => { if (an(e)) return { success: !0, data: e.value }; if (!n.common.issues.length) throw new Error("Validation failed but no issues detected."); return { success: !1, get error() { if (this._error) return this._error; const t = new Fe(n.common.issues); return this._error = t, this._error; } }; }; function G(n) { if (!n) return {}; const { errorMap: e, invalid_type_error: t, required_error: r, description: s } = n; if (e && (t || r)) throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`); return e ? { errorMap: e, description: s } : { errorMap: (o, a) => { const { message: c } = n; return o.code === "invalid_enum_value" ? { message: c ?? a.defaultError } : typeof a.data > "u" ? { message: c ?? r ?? a.defaultError } : o.code !== "invalid_type" ? { message: a.defaultError } : { message: c ?? t ?? a.defaultError }; }, description: s }; } class H { get description() { return this._def.description; } _getType(e) { return st(e.data); } _getOrReturnCtx(e, t) { return t || { common: e.parent.common, data: e.data, parsedType: st(e.data), schemaErrorMap: this._def.errorMap, path: e.path, parent: e.parent }; } _processInputParams(e) { return { status: new _e(), ctx: { common: e.parent.common, data: e.data, parsedType: st(e.data), schemaErrorMap: this._def.errorMap, path: e.path, parent: e.parent } }; } _parseSync(e) { const t = this._parse(e); if (sr(t)) throw new Error("Synchronous parse encountered promise."); return t; } _parseAsync(e) { const t = this._parse(e); return Promise.resolve(t); } parse(e, t) { const r = this.safeParse(e, t); if (r.success) return r.data; throw r.error; } safeParse(e, t) { const r = { common: { issues: [], async: (t == null ? void 0 : t.async) ?? !1, contextualErrorMap: t == null ? void 0 : t.errorMap }, path: (t == null ? void 0 : t.path) || [], schemaErrorMap: this._def.errorMap, parent: null, data: e, parsedType: st(e) }, s = this._parseSync({ data: e, path: r.path, parent: r }); return Ys(r, s); } "~validate"(e) { var r, s; const t = { common: { issues: [], async: !!this["~standard"].async }, path: [], schemaErrorMap: this._def.errorMap, parent: null, data: e, parsedType: st(e) }; if (!this["~standard"].async) try { const i = this._parseSync({ data: e, path: [], parent: t }); return an(i) ? { value: i.value } : { issues: t.common.issues }; } catch (i) { (s = (r = i == null ? void 0 : i.message) == null ? void 0 : r.toLowerCase()) != null && s.includes("encountered") && (this["~standard"].async = !0), t.common = { issues: [], async: !0 }; } return this._parseAsync({ data: e, path: [], parent: t }).then((i) => an(i) ? { value: i.value } : { issues: t.common.issues }); } async parseAsync(e, t) { const r = await this.safeParseAsync(e, t); if (r.success) return r.data; throw r.error; } async safeParseAsync(e, t) { const r = { common: { issues: [], contextualErrorMap: t == null ? void 0 : t.errorMap, async: !0 }, path: (t == null ? void 0 : t.path) || [], schemaErrorMap: this._def.errorMap, parent: null, data: e, parsedType: st(e) }, s = this._parse({ data: e, path: r.path, parent: r }), i = await (sr(s) ? s : Promise.resolve(s)); return Ys(r, i); } refine(e, t) { const r = (s) => typeof t == "string" || typeof t > "u" ? { message: t } : typeof t == "function" ? t(s) : t; return this._refinement((s, i) => { const o = e(s), a = () => i.addIssue({ code: C.custom, ...r(s) }); return typeof Promise < "u" && o instanceof Promise ? o.then((c) => c ? !0 : (a(), !1)) : o ? !0 : (a(), !1); }); } refinement(e, t) { return this._refinement((r, s) => e(r) ? !0 : (s.addIssue(typeof t == "function" ? t(r, s) : t), !1)); } _refinement(e) { return new Dt({ schema: this, typeName: O.ZodEffects, effect: { type: "refinement", refinement: e } }); } superRefine(e) { return this._refinement(e); } constructor(e) { this.spa = this.safeParseAsync, this._def = e, this.parse = this.parse.bind(this), this.safeParse = this.safeParse.bind(this), this.parseAsync = this.parseAsync.bind(this), this.safeParseAsync = this.safeParseAsync.bind(this), this.spa = this.spa.bind(this), this.refine = this.refine.bind(this), this.refinement = this.refinement.bind(this), this.superRefine = this.superRefine.bind(this), this.optional = this.optional.bind(this), this.nullable = this.nullable.bind(this), this.nullish = this.nullish.bind(this), this.array = this.array.bind(this), this.promise = this.promise.bind(this), this.or = this.or.bind(this), this.and = this.and.bind(this), this.transform = this.transform.bind(this), this.brand = this.brand.bind(this), this.default = this.default.bind(this), this.catch = this.catch.bind(this), this.describe = this.describe.bind(this), this.pipe = this.pipe.bind(this), this.readonly = this.readonly.bind(this), this.isNullable = this.isNullable.bind(this), this.isOptional = this.isOptional.bind(this), this["~standard"] = { version: 1, vendor: "zod", validate: (t) => this["~validate"](t) }; } optional() { return et.create(this, this._def); } nullable() { return Mt.create(this, this._def); } nullish() { return this.nullable().optional(); } array() { return $e.create(this); } promise() { return dr.create(this, this._def); } or(e) { return ar.create([this, e], this._def); } and(e) { return or.create(this, e, this._def); } transform(e) { return new Dt({ ...G(this._def), schema: this, typeName: O.ZodEffects, effect: { type: "transform", transform: e } }); } default(e) { const t = typeof e == "function" ? e : () => e; return new pr({ ...G(this._def), innerType: this, defaultValue: t, typeName: O.ZodDefault }); } brand() { return new ra({ typeName: O.ZodBranded, type: this, ...G(this._def) }); } catch(e) { const t = typeof e == "function" ? e : () => e; return new fr({ ...G(this._def), innerType: this, catchValue: t, typeName: O.ZodCatch }); } describe(e) { const t = this.constructor; return new t({ ...this._def, description: e }); } pipe(e) { return Is.create(this, e); } readonly() { return hr.create(this); } isOptional() { return this.safeParse(void 0).success; } isNullable() { return this.safeParse(null).success; } } const Fo = /^c[^\s-]{8,}$/i, Lo = /^[0-9a-z]+$/, Uo = /^[0-9A-HJKMNP-TV-Z]{26}$/i, Zo = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i, qo = /^[a-z0-9_-]{21}$/i, Jo = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/, Bo = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/, zo = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i, Go = "^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$"; let Pr; const Vo = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/, Wo = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/, Ho = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/, Ko = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/, Yo = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/, Xo = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/, ea = "((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))", Qo = new RegExp(`^${ea}$`); function ta(n) { let e = "[0-5]\\d"; n.precision ? e = `${e}\\.\\d{${n.precision}}` : n.precision == null && (e = `${e}(\\.\\d+)?`); const t = n.precision ? "+" : "?"; return `([01]\\d|2[0-3]):[0-5]\\d(:${e})${t}`; } function eu(n) { return new RegExp(`^${ta(n)}$`); } function tu(n) { let e = `${ea}T${ta(n)}`; const t = []; return t.push(n.local ? "Z?" : "Z"), n.offset && t.push("([+-]\\d{2}:?\\d{2})"), e = `${e}(${t.join("|")})`, new RegExp(`^${e}$`); } function nu(n, e) { return !!((e === "v4" || !e) && Vo.test(n) || (e === "v6" || !e) && Ho.test(n)); } function ru(n, e) { if (!Jo.test(n)) return !1; try { const [t] = n.split("."); if (!t) return !1; const r = t.replace(/-/g, "+").replace(/_/g, "/").padEnd(t.length + (4 - t.length % 4) % 4, "="), s = JSON.parse(atob(r)); return !(typeof s != "object" || s === null || "typ" in s && (s == null ? void 0 : s.typ) !== "JWT" || !s.alg || e && s.alg !== e); } catch { return !1; } } function su(n, e) { return !!((e === "v4" || !e) && Wo.test(n) || (e === "v6" || !e) && Ko.test(n)); } class Qe extends H { _parse(e) { if (this._def.coerce && (e.data = String(e.data)), this._getType(e) !== M.string) { const i = this._getOrReturnCtx(e); return P(i, { code: C.invalid_type, expected: M.string, received: i.parsedType }), J; } const r = new _e(); let s; for (const i of this._def.checks) if (i.kind === "min") e.data.length < i.value && (s = this._getOrReturnCtx(e, s), P(s, { code: C.too_small, minimum: i.value, type: "string", inclusive: !0, exact: !1, message: i.message }), r.dirty()); else if (i.kind === "max") e.data.length > i.value && (s = this._getOrReturnCtx(e, s), P(s, { code: C.too_big, maximum: i.value, type: "string", inclusive: !0, exact: !1, message: i.message }), r.dirty()); else if (i.kind === "length") { const o = e.data.length > i.value, a = e.data.length < i.value; (o || a) && (s = this._getOrReturnCtx(e, s), o ? P(s, { code: C.too_big, maximum: i.value, type: "string", inclusive: !0, exact: !0, message: i.message }) : a && P(s, { code: C.too_small, minimum: i.value, type: "string", inclusive: !0, exact: !0, message: i.message }), r.dirty()); } else if (i.kind === "email") zo.test(e.data) || (s = this._getOrReturnCtx(e, s), P(s, { validation: "email", code: C.invalid_string, message: i.message }), r.dirty()); else if (i.kind === "emoji") Pr || (Pr = new RegExp(Go, "u")), Pr.test(e.data) || (s = this._getOrReturnCtx(e, s), P(s, { validation: "emoji", code: C.invalid_string, message: i.message }), r.dirty()); else if (i.kind === "uuid") Zo.test(e.data) || (s = this._getOrReturnCtx(e, s), P(s, { validation: "uuid", code: C.invalid_string, message: i.message }), r.dirty()); else if (i.kind === "nanoid") qo.test(e.data) || (s = this._getOrReturnCtx(e, s), P(s, { validation: "nanoid", code: C.invalid_string, message: i.message }), r.dirty()); else if (i.kind === "cuid") Fo.test(e.data) || (s = this._getOrReturnCtx(e, s), P(s, { validation: "cuid", code: C.invalid_string, message: i.message }), r.dirty()); else if (i.kind === "cuid2") Lo.test(e.data) || (s = this._getOrReturnCtx(e, s), P(s, { validation: "cuid2", code: C.invalid_string, message: i.message }), r.dirty()); else if (i.kind === "ulid") Uo.test(e.data) || (s = this._getOrReturnCtx(e, s), P(s, { validation: "ulid", code: C.invalid_string, message: i.message }), r.dirty()); else if (i.kind === "url") try { new URL(e.data); } catch { s = this._getOrReturnCtx(e, s), P(s, { validation: "url", code: C.invalid_string, message: i.message }), r.dirty(); } else i.kind === "regex" ? (i.regex.lastIndex = 0, i.regex.test(e.data) || (s = this._getOrReturnCtx(e, s), P(s, { validation: "regex", code: C.invalid_string, message: i.message }), r.dirty())) : i.kind === "trim" ? e.data = e.data.trim() : i.kind === "includes" ? e.data.includes(i.value, i.position) || (s = this._getOrReturnCtx(e, s), P(s, { code: C.invalid_string, validation: { includes: i.value, position: i.position }, message: i.message }), r.dirty()) : i.kind === "toLowerCase" ? e.data = e.data.toLowerCase() : i.kind === "toUpperCase" ? e.data = e.data.toUpperCase() : i.kind === "startsWith" ? e.data.startsWith(i.value) || (s = this._getOrReturnCtx(e, s), P(s, { code: C.invalid_string, validation: { startsWith: i.value }, message: i.message }), r.dirty()) : i.kind === "endsWith" ? e.data.endsWith(i.value) || (s = this._getOrReturnCtx(e, s), P(s, { code: C.invalid_string, validation: { endsWith: i.value }, message: i.message }), r.dirty()) : i.kind === "datetime" ? tu(i).test(e.data) || (s = this._getOrReturnCtx(e, s), P(s, { code: C.invalid_string, validation: "datetime", message: i.message }), r.dirty()) : i.kind === "date" ? Qo.test(e.data) || (s = this._getOrReturnCtx(e, s), P(s, { code: C.invalid_string, validation: "date", message: i.message }), r.dirty()) : i.kind === "time" ? eu(i).test(e.data) || (s = this._getOrReturnCtx(e, s), P(s, { code: C.invalid_string, validation: "time", message: i.message }), r.dirty()) : i.kind === "duration" ? Bo.test(e.data) || (s = this._getOrReturnCtx(e, s), P(s, { validation: "duration", code: C.invalid_string, message: i.message }), r.dirty()) : i.kind === "ip" ? nu(e.data, i.version) || (s = this._getOrReturnCtx(e, s), P(s, { validation: "ip", code: C.invalid_string, message: i.message }), r.dirty()) : i.kind === "jwt" ? ru(e.data, i.alg) || (s = this._getOrReturnCtx(e, s), P(s, { validation: "jwt", code: C.invalid_string, message: i.message }), r.dirty()) : i.kind ==