{"version":3,"file":"event-stream-QxN1yvIF.mjs","names":[],"sources":["../node_modules/.pnpm/@earendil-works+pi-ai@0.84.1_ws@8.21.3_zod@4.4.3/node_modules/@earendil-works/pi-ai/dist/utils/event-stream.js"],"sourcesContent":["// Generic event stream class for async iteration\nexport class EventStream {\n    queue = [];\n    waiting = [];\n    done = false;\n    finalResultPromise;\n    resolveFinalResult;\n    isComplete;\n    extractResult;\n    constructor(isComplete, extractResult) {\n        this.isComplete = isComplete;\n        this.extractResult = extractResult;\n        this.finalResultPromise = new Promise((resolve) => {\n            this.resolveFinalResult = resolve;\n        });\n    }\n    push(event) {\n        if (this.done)\n            return;\n        if (this.isComplete(event)) {\n            this.done = true;\n            this.resolveFinalResult(this.extractResult(event));\n        }\n        // Deliver to waiting consumer or queue it\n        const waiter = this.waiting.shift();\n        if (waiter) {\n            waiter({ value: event, done: false });\n        }\n        else {\n            this.queue.push(event);\n        }\n    }\n    end(result) {\n        this.done = true;\n        if (result !== undefined) {\n            this.resolveFinalResult(result);\n        }\n        // Notify all waiting consumers that we're done\n        while (this.waiting.length > 0) {\n            const waiter = this.waiting.shift();\n            waiter({ value: undefined, done: true });\n        }\n    }\n    async *[Symbol.asyncIterator]() {\n        while (true) {\n            if (this.queue.length > 0) {\n                yield this.queue.shift();\n            }\n            else if (this.done) {\n                return;\n            }\n            else {\n                const result = await new Promise((resolve) => this.waiting.push(resolve));\n                if (result.done)\n                    return;\n                yield result.value;\n            }\n        }\n    }\n    result() {\n        return this.finalResultPromise;\n    }\n}\nexport class AssistantMessageEventStream extends EventStream {\n    constructor() {\n        super((event) => event.type === \"done\" || event.type === \"error\", (event) => {\n            if (event.type === \"done\") {\n                return event.message;\n            }\n            else if (event.type === \"error\") {\n                return event.error;\n            }\n            throw new Error(\"Unexpected event type for final result\");\n        });\n    }\n}\n/** Factory function for AssistantMessageEventStream (for use in extensions) */\nexport function createAssistantMessageEventStream() {\n    return new AssistantMessageEventStream();\n}\n//# sourceMappingURL=event-stream.js.map"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