feat(plugin): add experimental WebSocket send and receive hooks - #49136
Open
rekram1-node wants to merge 1 commit into
Open
rekram1-node wants to merge 1 commit into
rekram1-node wants to merge 1 commit into
Conversation
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.
Summary
Follow-up to #49131. That PR added
experimental.ws.handshakeso plugins could shape the connection; this one addsexperimental.ws.sendandexperimental.ws.receiveso plugins can shape the frames — the WebSocket counterpart of editing an HTTP request or response body viahttp.request/http.response.Hooks (
@opencode/plugin, botheffect/andpromise/)experimental.ws.send—{ sessionID, agent, model, kind, mode, frame }. Runs after the provider driver builds an outbound frame and before it is written.modeis"full"or"incremental"(delta since the provider's last checkpoint). Whateverframeholds when the hook returns is sent verbatim.experimental.ws.receive—{ sessionID, agent, model, kind, frame }. Runs on each inbound frame before the driver observes it. Whateverframeholds is handed to the driver verbatim.Frames are not validated. The driver tracks state from the provider's replies, so a rewrite that changes protocol meaning is on the plugin — same contract as a rewritten HTTP body. Documented as such.
Core
SessionModelTransport.bind(sessionID, interceptor?)— the barehandshakefunction from feat(plugin): add experimental WebSocket handshake hook #49131 becomes anInterceptorwith optionalhandshake/send/receive.sendruns afterdriver.create, beforesendText;receiveruns in the inbound stream beforedriver.observe. Interrupts duringsendclose the channel, matchingcreate.model-request.tswires all three to the session hooks with the samescope(sessionID,agent,model,kind).No provider or route changes.
Tests
session-model-transport: the wire carries thesendrewrite; the driver observes thereceiverewrite;modereported as"full"on a fresh channel.session-model-request-hooks: all three hooks fire withkind, mutations flow through to the transport,modepasses through.pluginandcore;packages/coretest/plugin/+ transport + request-hooks + runner suites: 519 passed.Docs
build/plugins/index.mdxandeffect.mdx: send/receive sections with examples, reference types added;effect.mdx'sSessionHooksreference block also gains thehandshakeentry it was missing from #49131.