feat(toolbar): real-time SSE sync for created & deleted annotations#24
Merged
Conversation
The SSE listener in the toolbar only handled "annotation.updated" (resolved/dismissed removal). Extend the same EventSource handler to also react to "annotation.created" and "annotation.deleted" so changes made by the agent or other connected clients sync into the view live. - created: add the remote annotation to local state, deduped by id so we don't double-add the server's echo of our own optimistic create. The optimistic-create id swap is now dedup-aware to cover the race where the SSE echo lands before the POST response resolves. - deleted: remove the annotation from local state (shared removal path with updated, preserving the feedback exit animation and the placement/rearrange reverse-lookups). The server already emits and broadcasts all three event types, so only the client handler needed wiring. Added a unit test for the dedup-on-created logic. Reimplemented from the ~50-line SSE concept in upstream benjitaylor#116 by @remorses rather than cherry-picked: the upstream PR is stale and bundles already-merged draw-mode code, and its handler dropped this fork's placement/rearrange handling. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Extends the toolbar's existing
EventSourcelistener (which only handledannotation.updated) to also handleannotation.createdandannotation.deleted, giving the toolbar live two-way sync with the server.isRenderableAnnotation.removeAnnotationLocallyhelper reused by theupdatedhandler, soannotation.updatedbehavior is unchanged.addAnnotationis now dedup-aware — if the SSEcreatedecho lands before the POST response resolves, the optimistic copy is dropped instead of renamed (which would otherwise duplicate the marker).Server
No server changes needed:
mcp/src/server/store.tsalready emitsannotation.created/annotation.updated/annotation.deleted, andhttp.ts(/sessions/:id/events) already broadcasts every event type to browser SSE clients. Only the client handler was missing.Reimplemented, not cherry-picked
Concept from upstream benjitaylor#116 by @remorses. That PR is stale and bundles already-merged draw-mode code, and its rewritten handler dropped this fork's
placement/rearrangespecial-casing. Reimplemented the ~50-line SSE concept cleanly against current code, keeping the fork's behavior intact.Behavior changes to flag for maintainer
onAnnotationAdd/onAnnotationDeletecallbacks for remote events (those callbacks fire only for local user actions, as before), avoiding a stale-closureannotationsRef. Flag if you'd prefer remote events to invoke callbacks too.Build / test
pnpm buildpasses;pnpm --filter agentation testpasses (103 tests, incl. 3 new for the dedup-on-created helper).🤖 Generated with Claude Code