/**
 * Streaming Executor Proxy
 *
 * Wraps an IAgentExecutor, transparently intercepting execute() calls
 * and routing them through executeStream(). Stream events are forwarded
 * to a shared EventChannel while the accumulated result is returned
 * to the caller (the graph node) as if execute() had been called normally.
 *
 * This allows graph nodes to remain unaware of streaming — they call
 * execute() and get an AgentExecutionResult back, while consumers of
 * the EventChannel receive real-time events.
 */
export class StreamingExecutorProxy {
    inner;
    channel;
    get agentType() {
        return this.inner.agentType;
    }
    constructor(inner, channel) {
        this.inner = inner;
        this.channel = channel;
    }
    async execute(prompt, options) {
        let result = '';
        try {
            for await (const event of this.inner.executeStream(prompt, options)) {
                this.channel.push(event);
                if (event.type === 'result') {
                    result = event.content;
                }
            }
        }
        catch (error) {
            this.channel.push({
                type: 'error',
                content: error instanceof Error ? error.message : String(error),
                timestamp: new Date(),
            });
            this.channel.close();
            throw error;
        }
        this.channel.close();
        return { result };
    }
    async *executeStream(prompt, options) {
        yield* this.inner.executeStream(prompt, options);
    }
    supportsFeature(feature) {
        return this.inner.supportsFeature(feature);
    }
}
