import { A as AnthropicError, p as pop } from './role-resolver-DF9BQ_U6.js';
import { t as toJSONSchema } from './paths-2M_UxD_H.js';
import './config-B0nEjgSh.js';
import './json-DXl7iDYg.js';
import './lock-BoHF25mx.js';
import './index-IVoIz4D5.js';
import 'path';
import 'fs';
import 'constants';
import 'stream';
import 'util';
import 'assert';
import 'events';
import 'node:fs';
import 'node:path';
import 'node:crypto';
import 'node:fs/promises';
import './index-Ca4C2M45.js';
import './credential-pool-B04qO8at.js';
import 'node:url';
import 'node:child_process';
import 'node:os';
import 'node:events';
import 'node:diagnostics_channel';
import 'worker_threads';
import 'module';
import 'url';
import 'buffer';
import 'node:module';
import 'node:process';
import 'node:async_hooks';

//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.88.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/lib/transform-json-schema.mjs
var SUPPORTED_STRING_FORMATS = new Set([
	"date-time",
	"time",
	"date",
	"duration",
	"email",
	"hostname",
	"uri",
	"ipv4",
	"ipv6",
	"uuid"
]);
function deepClone(obj) {
	return JSON.parse(JSON.stringify(obj));
}
function transformJSONSchema(jsonSchema) {
	return _transformJSONSchema(deepClone(jsonSchema));
}
function _transformJSONSchema(jsonSchema) {
	const strictSchema = {};
	const ref = pop(jsonSchema, "$ref");
	if (ref !== void 0) {
		strictSchema["$ref"] = ref;
		return strictSchema;
	}
	const defs = pop(jsonSchema, "$defs");
	if (defs !== void 0) {
		const strictDefs = {};
		strictSchema["$defs"] = strictDefs;
		for (const [name, defSchema] of Object.entries(defs)) strictDefs[name] = _transformJSONSchema(defSchema);
	}
	const type = pop(jsonSchema, "type");
	const anyOf = pop(jsonSchema, "anyOf");
	const oneOf = pop(jsonSchema, "oneOf");
	const allOf = pop(jsonSchema, "allOf");
	if (Array.isArray(anyOf)) strictSchema["anyOf"] = anyOf.map((variant) => _transformJSONSchema(variant));
	else if (Array.isArray(oneOf)) strictSchema["anyOf"] = oneOf.map((variant) => _transformJSONSchema(variant));
	else if (Array.isArray(allOf)) strictSchema["allOf"] = allOf.map((entry) => _transformJSONSchema(entry));
	else {
		if (type === void 0) throw new Error("JSON schema must have a type defined if anyOf/oneOf/allOf are not used");
		strictSchema["type"] = type;
	}
	const description = pop(jsonSchema, "description");
	if (description !== void 0) strictSchema["description"] = description;
	const title = pop(jsonSchema, "title");
	if (title !== void 0) strictSchema["title"] = title;
	if (type === "object") {
		const properties = pop(jsonSchema, "properties") || {};
		strictSchema["properties"] = Object.fromEntries(Object.entries(properties).map(([key, propSchema]) => [key, _transformJSONSchema(propSchema)]));
		pop(jsonSchema, "additionalProperties");
		strictSchema["additionalProperties"] = false;
		const required = pop(jsonSchema, "required");
		if (required !== void 0) strictSchema["required"] = required;
	} else if (type === "string") {
		const format = pop(jsonSchema, "format");
		if (format !== void 0 && SUPPORTED_STRING_FORMATS.has(format)) strictSchema["format"] = format;
		else if (format !== void 0) jsonSchema["format"] = format;
	} else if (type === "array") {
		const items = pop(jsonSchema, "items");
		if (items !== void 0) strictSchema["items"] = _transformJSONSchema(items);
		const minItems = pop(jsonSchema, "minItems");
		if (minItems !== void 0 && (minItems === 0 || minItems === 1)) strictSchema["minItems"] = minItems;
		else if (minItems !== void 0) jsonSchema["minItems"] = minItems;
	}
	if (Object.keys(jsonSchema).length > 0) {
		const existingDescription = strictSchema["description"];
		strictSchema["description"] = (existingDescription ? existingDescription + "\n\n" : "") + "{" + Object.entries(jsonSchema).map(([key, value]) => `${key}: ${JSON.stringify(value)}`).join(", ") + "}";
	}
	return strictSchema;
}
//#endregion
//#region ../../node_modules/.pnpm/@anthropic-ai+sdk@0.88.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/helpers/zod.mjs
/**
* Creates a JSON schema output format object from the given Zod schema.
*
* If this is passed to the `.parse()` method then the response message will contain a
* `.parsed_output` property that is the result of parsing the content with the given Zod object.
*
* This can be passed directly to the `.create()` method but will not
* result in any automatic parsing, you'll have to parse the response yourself.
*/
function zodOutputFormat(zodObject) {
	let jsonSchema = toJSONSchema(zodObject, { reused: "ref" });
	jsonSchema = transformJSONSchema(jsonSchema);
	return {
		type: "json_schema",
		schema: { ...jsonSchema },
		parse: (content) => {
			let parsed;
			try {
				parsed = JSON.parse(content);
			} catch (error) {
				throw new AnthropicError(`Failed to parse structured output as JSON: ${error instanceof Error ? error.message : String(error)}`);
			}
			const output = zodObject.safeParse(parsed);
			if (!output.success) {
				const formattedIssues = output.error.issues.slice(0, 5).map((issue) => `  - ${issue.path.join(".")}: ${issue.message}`).join("\n");
				const issueCount = output.error.issues.length;
				const suffix = issueCount > 5 ? `\n  ... and ${issueCount - 5} more issue(s)` : "";
				throw new AnthropicError(`Failed to parse structured output: ${output.error.message}\nValidation issues:\n${formattedIssues}${suffix}`);
			}
			return output.data;
		}
	};
}

export { zodOutputFormat };
//# sourceMappingURL=zod-rX0tyJVM.js.map
