//#region src/domains/run/utils/schema-validation.ts
/**
* Extract preview fields from a schema (fields marked with inPreview: true)
*/
function extractPreviewFields(schema) {
	const previewProperties = {};
	if (schema.properties) {
		for (const [key, prop] of Object.entries(schema.properties)) if (prop.inPreview === true) {
			const cleanProp = { ...prop };
			delete cleanProp.inPreview;
			previewProperties[key] = cleanProp;
		}
	}
	return {
		type: "object",
		properties: previewProperties,
		required: schema.required?.filter((field) => previewProperties[field])
	};
}
/**
* Convert a JSON Schema properties map into a compact readable shape.
* Arrays become [{...}], objects recurse, primitives become their type string.
* Useful for displaying artifact schemas in prompts.
*/
function buildSchemaShape(properties) {
	const shape = {};
	for (const [key, value] of Object.entries(properties)) if (value.type === "array") if (value.items?.properties) shape[key] = [buildSchemaShape(value.items.properties)];
	else if (value.items?.type) shape[key] = [value.items.type];
	else shape[key] = [];
	else if (value.type === "object" && value.properties) shape[key] = buildSchemaShape(value.properties);
	else shape[key] = value.type || "unknown";
	return shape;
}
/**
* Extract full fields from a schema (all fields, with inPreview flags removed)
*/
function extractFullFields(schema) {
	const fullProperties = {};
	if (schema.properties) for (const [key, prop] of Object.entries(schema.properties)) {
		const cleanProp = { ...prop };
		delete cleanProp.inPreview;
		fullProperties[key] = cleanProp;
	}
	return {
		type: "object",
		properties: fullProperties,
		required: schema.required
	};
}

//#endregion
export { buildSchemaShape, extractFullFields, extractPreviewFields };