import { i as formattedHeadlessTurnEventToJsonl, n as formatHeadlessResult, o as installHeadlessEventAdapter, r as formatHeadlessTurnEvent } from "../headless-CPaunZsU.js";
//#region src/output/stream-json.ts
function resolveFormatOptions(options) {
	return {
		format: options.format ?? "zidane",
		providerName: options.providerName ?? "openai"
	};
}
function defaultWrite(line) {
	process.stdout.write(line);
}
function formatStreamJsonTurnEvent(event, options = {}) {
	return formatHeadlessTurnEvent(event, resolveFormatOptions(options));
}
function streamJsonTurnEventToJsonl(event, options = {}) {
	return formattedHeadlessTurnEventToJsonl(formatStreamJsonTurnEvent(event, options));
}
function formatStreamJsonResult(result, options = {}) {
	return formatHeadlessResult(result, resolveFormatOptions(options));
}
function streamJsonResultToJsonl(result, options = {}) {
	return `${JSON.stringify(formatStreamJsonResult(result, options))}\n`;
}
function createStreamJsonOutputHandler(options = {}) {
	const write = options.write ?? defaultWrite;
	return (event) => {
		if (event.type !== "turn") return;
		write(streamJsonTurnEventToJsonl(event, options));
	};
}
function setupStreamJsonOutput(agent, options = {}) {
	return installHeadlessEventAdapter(agent.hooks, createStreamJsonOutputHandler(options));
}
//#endregion
export { createStreamJsonOutputHandler, formatStreamJsonResult, formatStreamJsonTurnEvent, setupStreamJsonOutput, streamJsonResultToJsonl, streamJsonTurnEventToJsonl };

//# sourceMappingURL=stream-json.js.map