//#region src/agent/messaging/stream-manager.ts
var StreamManager = class {
	currentHandle = null;
	skipFinalOutboundPending = false;
	/**
	* Set the current stream handle
	*/
	setHandle(handle) {
		this.currentHandle = handle;
	}
	/**
	* Get the current stream handle
	*/
	getHandle() {
		return this.currentHandle;
	}
	/**
	* Clear the current stream handle
	*/
	clearHandle() {
		this.currentHandle = null;
	}
	/**
	* Check if a stream handle is currently active
	*/
	hasActiveHandle() {
		return this.currentHandle !== null;
	}
	/**
	* Update the stream with text content
	*/
	update(text) {
		this.currentHandle?.update(text);
	}
	/**
	* End the stream and clear the handle
	*/
	async end() {
		if (this.currentHandle) {
			const handle = this.currentHandle;
			await handle.end();
			this.skipFinalOutboundPending = handle.skipFinalOutbound?.() ?? false;
			this.clearHandle();
		} else this.skipFinalOutboundPending = false;
	}
	/**
	* Abort the stream and clear the handle
	*/
	async abort() {
		if (this.currentHandle) {
			await this.currentHandle.abort();
			this.skipFinalOutboundPending = false;
			this.clearHandle();
		}
	}
	/**
	* Whether the channel already delivered the final assistant text (e.g. Telegram streaming).
	* Consumes the flag for one outbound decision.
	*/
	consumeSkipFinalOutbound() {
		const v = this.skipFinalOutboundPending;
		this.skipFinalOutboundPending = false;
		return v;
	}
	/**
	* Get the current message ID from the stream handle
	*/
	getMessageId() {
		return this.currentHandle?.messageId();
	}
	/**
	* Update progress via the stream handle
	*/
	updateProgress(text, stage, detail) {
		if (this.currentHandle?.updateProgress) this.currentHandle.updateProgress(text, stage, detail);
	}
	/**
	* Set progress stage via the stream handle
	*/
	setProgress(stage, detail) {
		if (this.currentHandle?.setProgress) this.currentHandle.setProgress(stage, detail);
	}
};
//#endregion
export { StreamManager };

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