Skip to content

feat(plugin): add experimental WebSocket send and receive hooks - #49136

Open
rekram1-node wants to merge 1 commit into
v2from
ws-frame-hooks
Open

rekram1-node wants to merge 1 commit into
v2from
ws-frame-hooks

Conversation

@rekram1-node

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #49131. That PR added experimental.ws.handshake so plugins could shape the connection; this one adds experimental.ws.send and experimental.ws.receive so plugins can shape the frames — the WebSocket counterpart of editing an HTTP request or response body via http.request / http.response.

Hooks (@opencode/plugin, both effect/ and promise/)

  • experimental.ws.send{ sessionID, agent, model, kind, mode, frame }. Runs after the provider driver builds an outbound frame and before it is written. mode is "full" or "incremental" (delta since the provider's last checkpoint). Whatever frame holds 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. Whatever frame holds 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 bare handshake function from feat(plugin): add experimental WebSocket handshake hook #49131 becomes an Interceptor with optional handshake / send / receive. send runs after driver.create, before sendText; receive runs in the inbound stream before driver.observe. Interrupts during send close the channel, matching create.
  • model-request.ts wires all three to the session hooks with the same scope (sessionID, agent, model, kind).

No provider or route changes.

Tests

  • session-model-transport: the wire carries the send rewrite; the driver observes the receive rewrite; mode reported as "full" on a fresh channel.
  • session-model-request-hooks: all three hooks fire with kind, mutations flow through to the transport, mode passes through.
  • Typecheck green in plugin and core; packages/core test/plugin/ + transport + request-hooks + runner suites: 519 passed.

Docs

build/plugins/index.mdx and effect.mdx: send/receive sections with examples, reference types added; effect.mdx's SessionHooks reference block also gains the handshake entry it was missing from #49131.

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