//#region src/browser/pipeline/output.ts
function createPipelineOutput(name) {
	return {
		ok: true,
		name,
		data: void 0,
		artifacts: [],
		diagnostics: { warnings: [] },
		steps: []
	};
}
function addStepResult(output, stepIndex, result) {
	output.steps.push({
		action: result.action,
		ok: result.ok,
		text: result.text?.slice(0, 200)
	});
	if (result.artifacts) output.artifacts.push(...result.artifacts);
	if (!result.ok) {
		output.ok = false;
		output.error = {
			step: stepIndex,
			action: result.action,
			code: result.error?.code ?? "UNKNOWN",
			message: result.error?.message ?? "Step failed"
		};
	}
	if (result.diagnostics) {
		if (result.diagnostics.url) output.diagnostics.url = result.diagnostics.url;
		if (result.diagnostics.title) output.diagnostics.title = result.diagnostics.title;
		if (result.diagnostics.snapshot) output.diagnostics.snapshot = result.diagnostics.snapshot;
		if (result.diagnostics.screenshot) output.diagnostics.screenshot = result.diagnostics.screenshot;
		if (result.diagnostics.console) output.diagnostics.console = result.diagnostics.console;
		if (result.diagnostics.network) output.diagnostics.network = result.diagnostics.network;
		if (result.diagnostics.warnings) output.diagnostics.warnings.push(...result.diagnostics.warnings);
	}
}
/**
* Format a PipelineOutput into a BrowserActionResult for tool consumption.
*/
function formatPipelineResult(output) {
	if (output.ok) return {
		ok: true,
		action: "pipeline",
		text: output.data ? typeof output.data === "string" ? output.data : JSON.stringify(output.data, null, 2) : `Pipeline "${output.name}" completed (${output.steps.length} steps).`,
		data: output.data,
		artifacts: output.artifacts.length > 0 ? output.artifacts : void 0
	};
	const errText = output.error ? `Pipeline "${output.name}" failed at step ${output.error.step + 1} (${output.error.action}): [${output.error.code}] ${output.error.message}` : `Pipeline "${output.name}" failed.`;
	return {
		ok: false,
		action: "pipeline",
		text: errText,
		error: output.error ? {
			code: output.error.code,
			message: output.error.message
		} : {
			code: "PIPELINE_FAILED",
			message: errText
		},
		artifacts: output.artifacts.length > 0 ? output.artifacts : void 0,
		diagnostics: output.diagnostics
	};
}
//#endregion
export { addStepResult, createPipelineOutput, formatPipelineResult };

//# sourceMappingURL=output.js.map