UNPKG

@forbespro/lead-agent

Version:
100 lines (99 loc) 2.96 kB
var o = "vercel.ai.error", S = Symbol.for(o), i, d = class l extends Error { /** * Creates an AI SDK Error. * * @param {Object} params - The parameters for creating the error. * @param {string} params.name - The name of the error. * @param {string} params.message - The error message. * @param {unknown} [params.cause] - The underlying cause of the error. */ constructor({ name: r, message: e, cause: s }) { super(e), this[i] = !0, this.name = r, this.cause = s; } /** * Checks if the given error is an AI SDK Error. * @param {unknown} error - The error to check. * @returns {boolean} True if the error is an AI SDK Error, false otherwise. */ static isInstance(r) { return l.hasMarker(r, o); } static hasMarker(r, e) { const s = Symbol.for(e); return r != null && typeof r == "object" && s in r && typeof r[s] == "boolean" && r[s] === !0; } }; i = S; var t = d; function m(a) { return a == null ? "unknown error" : typeof a == "string" ? a : a instanceof Error ? a.message : JSON.stringify(a); } var v = "AI_InvalidArgumentError", c = `vercel.ai.error.${v}`, I = Symbol.for(c), u, _ = class extends t { constructor({ message: a, cause: r, argument: e }) { super({ name: v, message: a, cause: r }), this[u] = !0, this.argument = e; } static isInstance(a) { return t.hasMarker(a, c); } }; u = I; var y = "AI_JSONParseError", f = `vercel.ai.error.${y}`, b = Symbol.for(f), E, $ = class extends t { constructor({ text: a, cause: r }) { super({ name: y, message: `JSON parsing failed: Text: ${a}. Error message: ${m(r)}`, cause: r }), this[E] = !0, this.text = a; } static isInstance(a) { return t.hasMarker(a, f); } }; E = b; var p = "AI_TypeValidationError", g = `vercel.ai.error.${p}`, k = Symbol.for(g), h, A = class n extends t { constructor({ value: r, cause: e }) { super({ name: p, message: `Type validation failed: Value: ${JSON.stringify(r)}. Error message: ${m(e)}`, cause: e }), this[h] = !0, this.value = r; } static isInstance(r) { return t.hasMarker(r, g); } /** * Wraps an error into a TypeValidationError. * If the cause is already a TypeValidationError with the same value, it returns the cause. * Otherwise, it creates a new TypeValidationError. * * @param {Object} params - The parameters for wrapping the error. * @param {unknown} params.value - The value that failed validation. * @param {unknown} params.cause - The original error or cause of the validation failure. * @returns {TypeValidationError} A TypeValidationError instance. */ static wrap({ value: r, cause: e }) { return n.isInstance(e) && e.value === r ? e : new n({ value: r, cause: e }); } }; h = k; var x = A; export { t as AISDKError, _ as InvalidArgumentError, $ as JSONParseError, x as TypeValidationError, m as getErrorMessage };