var marker = "vercel.ai.error", symbol = Symbol.for(marker), _a, _b, AISDKError = class C extends (_b = Error, _a = symbol, _b) {
	constructor({ name: e, message: b, cause: S }) {
		super(b), this[_a] = !0, this.name = e, this.cause = S;
	}
	static isInstance(b) {
		return C.hasMarker(b, marker);
	}
	static hasMarker(e, b) {
		let x = Symbol.for(b);
		return typeof e == "object" && !!e && x in e && typeof e[x] == "boolean" && e[x] === !0;
	}
};
function getErrorMessage(e) {
	return e == null ? "unknown error" : typeof e == "string" ? e : e instanceof Error ? e.message : JSON.stringify(e);
}
var name3 = "AI_InvalidArgumentError", marker4 = `vercel.ai.error.${name3}`, symbol4 = Symbol.for(marker4), _a4, _b4, InvalidArgumentError = class extends (_b4 = AISDKError, _a4 = symbol4, _b4) {
	constructor({ message: e, cause: b, argument: x }) {
		super({
			name: name3,
			message: e,
			cause: b
		}), this[_a4] = !0, this.argument = x;
	}
	static isInstance(e) {
		return AISDKError.hasMarker(e, marker4);
	}
}, name6 = "AI_JSONParseError", marker7 = `vercel.ai.error.${name6}`, symbol7 = Symbol.for(marker7), _a7, _b7, JSONParseError = class extends (_b7 = AISDKError, _a7 = symbol7, _b7) {
	constructor({ text: e, cause: b }) {
		super({
			name: name6,
			message: `JSON parsing failed: Text: ${e}.
Error message: ${getErrorMessage(b)}`,
			cause: b
		}), this[_a7] = !0, this.text = e;
	}
	static isInstance(e) {
		return AISDKError.hasMarker(e, marker7);
	}
}, name12 = "AI_TypeValidationError", marker13 = `vercel.ai.error.${name12}`, symbol13 = Symbol.for(marker13), _a13, _b13, TypeValidationError = class e extends (_b13 = AISDKError, _a13 = symbol13, _b13) {
	constructor({ value: e, cause: b, context: x }) {
		let S = "Type validation failed";
		if (x?.field && (S += ` for ${x.field}`), x?.entityName || x?.entityId) {
			S += " (";
			let e = [];
			x.entityName && e.push(x.entityName), x.entityId && e.push(`id: "${x.entityId}"`), S += e.join(", "), S += ")";
		}
		super({
			name: name12,
			message: `${S}: Value: ${JSON.stringify(e)}.
Error message: ${getErrorMessage(b)}`,
			cause: b
		}), this[_a13] = !0, this.value = e, this.context = x;
	}
	static isInstance(e) {
		return AISDKError.hasMarker(e, marker13);
	}
	static wrap({ value: b, cause: x, context: S }) {
		return e.isInstance(x) && x.value === b && x.context?.field === S?.field && x.context?.entityName === S?.entityName && x.context?.entityId === S?.entityId ? x : new e({
			value: b,
			cause: x,
			context: S
		});
	}
};
export { AISDKError, InvalidArgumentError, JSONParseError, TypeValidationError };
