Skip to content

feat(collab): broadcast user message and AI stream to relay#92

Merged
andrewchumchal merged 5 commits into
devfrom
feat/collab-stream-relay
May 26, 2026
Merged

feat(collab): broadcast user message and AI stream to relay#92
andrewchumchal merged 5 commits into
devfrom
feat/collab-stream-relay

Conversation

@andrewchumchal

Copy link
Copy Markdown
Contributor

Problem

When a user sends a message in a live collaboration room, the message and the AI response stream were never forwarded to the relay server. Other participants couldn't see any messages or the AI response.

Root causes

  1. ipc.ts CHAT_SEND handler streamed AI events to the renderer via wc.send(...) but never called sendToRoom(...) to broadcast to the relay.
  2. The relay's assertLock rejected all sends when lockHolder === null (nobody has explicitly requested a turn), blocking the host from broadcasting their first message.
  3. The relay's handleMessageAdd used broadcastAll (echoed back to sender), which would cause duplicate messages for the sender.

Changes

packages/desktop/src/main/ipc.ts

  • Before the iteration loop: broadcast the user message via message_add and signal stream_start
  • Inside the delta handler: forward each chunk as stream_chunk
  • On completion (no tool calls): broadcast stream_end with the final assistant message

sendToRoom is a no-op when no collaboration session is active, so these calls are safe in all normal (non-collab) conversations.

Relay server (separate PR / already pushed to relay-server main)

  • assertLock: allow sending when lockHolder === null (no one has claimed a turn yet)
  • handleMessageAdd: switched from broadcastAllbroadcastExcept to prevent the sender receiving their own message back as a duplicate

…elay

- Broadcast message_add for the user message before starting the AI stream
- Broadcast stream_start before the provider iteration loop
- Broadcast stream_chunk for every AI delta event
- Broadcast stream_end with the final assistant message on completion

sendToRoom is a no-op when no collaboration session is active, so these
calls are safe in all non-collab conversations.
- providers/perplexity.ts: delegates to streamOpenAI with api.perplexity.ai base URL
- main/ipc.ts: add 'perplexity' case to both getStream() switches
@andrewchumchal andrewchumchal merged commit bdba327 into dev May 26, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant