agentsclimarketplace

Typed websocket rpc boundary validation

Skill kjuhwa/skills-hub/skills/websocket/typed-websocket-rpc-boundary-validation

Enforce strict schema validation at the WebSocket transport layer to catch contract breakages earlyFrom its SKILL.md

Install
npx -y skills add kjuhwa/skills-hub --skill typed-websocket-rpc-boundary-validation

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

2.4 KB, 406 tokens by cl100k_base, as published. Nobody here has run it

When to Apply

  • You serve WebSocket RPC with multiple method handlers (requests + typed pushes)
  • You want decode failures to produce structured diagnostics with path/reason
  • You need to prevent invalid payloads from reaching business logic
  • Client/server contracts can drift; early validation catches breakages

Steps

  1. Define contracts as schema unions in a shared package (e.g., @t3tools/contracts/src/rpc.ts)
  2. Define RPC method shapes, request/response schemas, and push channel schemas
  3. At server startup, create RPC server with schema-based encoding/decoding
  4. On client, create transport that wraps outbound requests and inbound pushes with schema parsing
  5. Decode failures at transport boundary immediately return WsDecodeDiagnostic with code, reason, and path
  6. Never cast payloads; always parse through schema
  7. For pushes, validate and cache per channel; allow clients to opt into replayLatest

Example

// Server: define schemas
const ServerWelcomeSchema = Schema.Struct({ type: Schema.Literal('server.welcome'), state: ThreadStateSchema })
const RpcGroup = Schema.Union([ MethodASchema, MethodBSchema ])

// Server: validate inbound
const request = yield* Schema.decode(RpcGroup)(payload)  // throws or returns typed request

// Client: encode/decode via transport
const wsTransport = new WsTransport({
  url: 'ws://server',
  schemas: { 'server.welcome': ServerWelcomeSchema, ... }
})
wsTransport.on('server.welcome', (data) => { /* data is typed */ })

Counter / Caveats

  • Schema validation adds latency; use for contract boundaries, not hot loops
  • Caching latest push per channel can grow memory; cap channel subscriptions
  • If schema is too strict, valid legacy clients may disconnect; plan versioning strategy
  • Decode path info helps debugging but reveals schema structure to clients

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 326,835. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.