const require_http = require("./http.cjs");
const require_websocket = require("./websocket.cjs");
//#region src/client/stream/transport/agent-server.ts
var HttpAgentServerAdapter = class {
	threadId;
	apiUrl;
	#delegate;
	/**
	* Thread-state reads are SSE-only. WebSocket delegates omit this so
	* {@link StreamController} falls back to `client.threads.getState()`.
	*/
	getState;
	constructor(options) {
		this.threadId = options.threadId ?? "";
		this.apiUrl = options.apiUrl;
		this.#delegate = options.webSocketFactory != null ? new require_websocket.ProtocolWebSocketTransportAdapter({
			apiUrl: options.apiUrl,
			threadId: options.threadId,
			defaultHeaders: options.defaultHeaders,
			onRequest: options.onRequest,
			paths: options.paths,
			webSocketFactory: options.webSocketFactory
		}) : new require_http.ProtocolSseTransportAdapter({
			apiUrl: options.apiUrl,
			threadId: options.threadId,
			defaultHeaders: options.defaultHeaders,
			onRequest: options.onRequest,
			fetch: options.fetch,
			asyncCaller: options.asyncCaller,
			paths: options.paths
		});
		if (options.webSocketFactory == null) {
			const sse = this.#delegate;
			this.getState = sse.getState.bind(sse);
		}
	}
	/** {@inheritDoc TransportAdapter.setThreadId} */
	setThreadId(threadId) {
		this.threadId = threadId;
		this.#delegate.setThreadId?.(threadId);
	}
	open() {
		return this.#delegate.open();
	}
	send(command) {
		return this.#delegate.send(command);
	}
	events() {
		return this.#delegate.events();
	}
	openEventStream(params) {
		if (this.#delegate.openEventStream == null) throw new Error("HttpAgentServerAdapter delegate does not support openEventStream (WebSocket path).");
		return this.#delegate.openEventStream(params);
	}
	close() {
		return this.#delegate.close();
	}
};
//#endregion
exports.HttpAgentServerAdapter = HttpAgentServerAdapter;

//# sourceMappingURL=agent-server.cjs.map