import { InvalidArgumentError as i, JSONParseError as o, TypeValidationError as c } from "../../../../../@ai-sdk_provider@1.1.3/node_modules/@ai-sdk/provider/dist/index.js";
import { customAlphabet as l } from "../../../../../nanoid@3.3.11/node_modules/nanoid/non-secure/index.js";
import f from "../../../../../../../_virtual/index7.js";
function g(r) {
  return new ReadableStream({
    /**
     * Called when the consumer wants to pull more data from the stream.
     *
     * @param {ReadableStreamDefaultController<T>} controller - The controller to enqueue data into the stream.
     * @returns {Promise<void>}
     */
    async pull(a) {
      try {
        const { value: e, done: t } = await r.next();
        t ? a.close() : a.enqueue(e);
      } catch (e) {
        a.error(e);
      }
    },
    /**
     * Called when the consumer cancels the stream.
     */
    cancel() {
    }
  });
}
var d = ({
  prefix: r,
  size: a = 16,
  alphabet: e = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
  separator: t = "-"
} = {}) => {
  const n = l(e, a);
  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 (u) => `${r}${t}${n(u)}`;
}, h = d(), s = Symbol.for("vercel.ai.validator");
function m(r) {
  return { [s]: !0, validate: r };
}
function p(r) {
  return typeof r == "object" && r !== null && s in r && r[s] === !0 && "validate" in r;
}
function y(r) {
  return p(r) ? r : w(r);
}
function w(r) {
  return m((a) => {
    const e = r.safeParse(a);
    return e.success ? { success: !0, value: e.data } : { success: !1, error: e.error };
  });
}
function v({
  value: r,
  schema: a
}) {
  const e = y(a);
  try {
    if (e.validate == null)
      return { success: !0, value: r };
    const t = e.validate(r);
    return t.success ? t : {
      success: !1,
      error: c.wrap({ value: r, cause: t.error })
    };
  } catch (t) {
    return {
      success: !1,
      error: c.wrap({ value: r, cause: t })
    };
  }
}
function I({
  text: r,
  schema: a
}) {
  try {
    const e = f.parse(r);
    if (a == null)
      return { success: !0, value: e, rawValue: e };
    const t = v({ value: e, schema: a });
    return t.success ? { ...t, rawValue: e } : t;
  } catch (e) {
    return {
      success: !1,
      error: o.isInstance(e) ? e : new o({ text: r, cause: e })
    };
  }
}
export {
  y as asValidator,
  g as convertAsyncIteratorToReadableStream,
  d as createIdGenerator,
  h as generateId,
  p as isValidator,
  I as safeParseJSON,
  v as safeValidateTypes,
  m as validator,
  s as validatorSymbol,
  w as zodValidator
};
//# sourceMappingURL=index.js.map
