UNPKG

@forbespro/lead-agent

Version:
83 lines (82 loc) 1.95 kB
import { InvalidArgumentError as i, JSONParseError as o, TypeValidationError as u } from "./index32.js"; import { customAlphabet as l } from "./index33.js"; import f from "./index34.js"; var d = ({ prefix: r, size: s = 16, alphabet: e = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", separator: t = "-" } = {}) => { const n = l(e, s); if (r == null) return n; if (e.includes(t)) throw new i({ argument: "separator", message: `The separator "${t}" must not be part of the alphabet "${e}".` }); return (c) => `${r}${t}${n(c)}`; }, b = d(), a = Symbol.for("vercel.ai.validator"); function m(r) { return { [a]: !0, validate: r }; } function p(r) { return typeof r == "object" && r !== null && a in r && r[a] === !0 && "validate" in r; } function w(r) { return p(r) ? r : y(r); } function y(r) { return m((s) => { const e = r.safeParse(s); return e.success ? { success: !0, value: e.data } : { success: !1, error: e.error }; }); } function V({ value: r, schema: s }) { const e = w(s); try { if (e.validate == null) return { success: !0, value: r }; const t = e.validate(r); return t.success ? t : { success: !1, error: u.wrap({ value: r, cause: t.error }) }; } catch (t) { return { success: !1, error: u.wrap({ value: r, cause: t }) }; } } function h({ text: r, schema: s }) { try { const e = f.parse(r); if (s == null) return { success: !0, value: e, rawValue: e }; const t = V({ value: e, schema: s }); return t.success ? { ...t, rawValue: e } : t; } catch (e) { return { success: !1, error: o.isInstance(e) ? e : new o({ text: r, cause: e }) }; } } export { w as asValidator, d as createIdGenerator, b as generateId, p as isValidator, h as safeParseJSON, V as safeValidateTypes, m as validator, a as validatorSymbol, y as zodValidator };