@owlmeans/socket
v0.1.11
Published
Shared WebSocket connection types and message protocol for OwlMeans real-time communication.
Downloads
98
Readme
@owlmeans/socket
Shared WebSocket connection types and message protocol for OwlMeans real-time communication.
Overview
- Defines the
Connectioninterface used by both server and client socket implementations MessageTypeenum covers all message categories: Call, Result, Event, Request, Response, Auth, SystemEventMessage<T>is the typed event payload received byconnection.observe()- Used in viable for real-time thinking journal updates and file watching
Installation
bun add @owlmeans/socketUsage
Send a typed event and observe responses:
import type { EventMessage, Connection } from '@owlmeans/socket'
import { MessageType } from '@owlmeans/socket'
// Observe events on a connection
const unsubscribe = connection.observe<FileUpdate>('file-update', async (event: EventMessage<FileUpdate>) => {
console.log('file updated:', event.payload)
})
// Notify connected clients
await connection.notify('file-update', { path: '/src/app.ts', content: '...' })RPC call over WebSocket:
const result = await connection.call<ProjectSlot>('project.slot', projectId)Checking the message type in a raw message handler:
import { MessageType } from '@owlmeans/socket'
if (message.type === MessageType.Event) {
// handle event
}API
Connection
The main interface for WebSocket connections. Key methods:
notify<T>(event, payload)— emit an event to the other sideobserve<T>(event, handler)— subscribe to events; returns unsubscribe functioncall<R, T[]>(method, ...payload)— make an RPC call and await the resultperform<R, T[]>(method, handler)— register an RPC handlerrequest<T, R>(payload, observer?)— send a streaming requestauth<T, R>(stage, payload)— perform a WebSocket auth handshake stepstage: AuthenticationStage— current auth state of the connection
MessageType
enum MessageType {
Call, Result, Error, Request, Response, Event, Message, Auth, System
}EventMessage<T>
The payload structure for observe() handlers: { type, payload: T, ... }.
CALL_TIMEOUT
Default RPC call timeout in milliseconds (60 000).
Related Packages
@owlmeans/server-socket— server-side connection implementation@owlmeans/client-socket— client-side connection implementation
Agent guidance
This package ships embedded Claude Code skills and GitHub Copilot instructions under
agent-meta/. After installing your @owlmeans/* packages, run the OwlMeans
agent-skills installer to place them into your project's native locations
(.claude/skills/ and .github/instructions/):
npx @owlmeans/agent-skillsThe embedded files are version-matched to this package release. Do not edit them directly — they are regenerated on each publish. To contribute guidance edits, open a PR against the source monorepo.
