var e=class{#e=[];#t=[];#n=``;#r;#i=!1;#a;constructor(e,t){this.#r=e,this.#a=t}start(e,t){this.#n=e,this.#t=t,this.#e=[],this.#i=!0;let n={id:crypto.randomUUID(),role:`system`,content:`Topic: ${e}\nParticipants: ${t.join(`, `)}`,timestamp:Date.now()};this.#o(n),this.nextTurn()}stop(){this.#i=!1}async nextTurn(){if(!this.#i)return;let e=[...this.#e].reverse().find(e=>e.role===`assistant`),t=0;e&&e.model&&(t=(this.#t.indexOf(e.model)+1)%this.#t.length);let n=this.#t[t],r=this.#e.map(e=>e.role===`system`?`[System]: ${e.content}`:`[${e.model||`User`}]: ${e.content}`).join(`

`),i=`You are ${n} in a group chat.
The topic is: "${this.#n}".
The other participants are: ${this.#t.filter(e=>e!==n).join(`, `)}.

Here is the conversation history:
${r}

Respond to the conversation as ${n}. Keep your response concise and conversational. Do not prefix your response with your name.`,a=crypto.randomUUID(),o=Date.now();this.#a({id:a,role:`assistant`,content:``,model:n,timestamp:o});try{let e={messages:[{role:`user`,content:i}],model:n,stream:!0},t=await this.#r.executeStream(e),r=``;for await(let e of t.textStream){if(!this.#i)break;r+=e,this.#a({id:a,role:`assistant`,content:r,model:n,timestamp:o})}this.#i&&this.#o({id:a,role:`assistant`,content:r,model:n,timestamp:o})}catch(e){console.error(`Error generating response from ${n}:`,e),this.#a({id:a,role:`system`,content:`Error: ${e.message}`,timestamp:Date.now()})}}#o(e){this.#e.push(e),this.#a(e)}get messages(){return this.#e}get isDiscussing(){return this.#i}};export{e as ChatRoom};