@klein-kit/client
v0.1.2
Published
Connect to a @klein-kit/server over WebSocket and drive remote coding-agent sessions through the exact @klein-kit/core AgentSession API.
Maintainers
Readme
@klein-kit/client
Drive remote klein-kit sessions through the exact AgentSession API. Connect to a @klein-kit/server and get back objects implementing @klein-kit/core's AgentSession / Turn interfaces — code written against core works unchanged when the agent runs on another machine.
import { connect } from "@klein-kit/client";
const client = await connect("ws://127.0.0.1:12199", { token });
const session = await client.createAgent({ provider: "codex", cwd: "/repo" });
const turn = session.prompt("fix the failing test");
for await (const event of turn) render(event); // same AgentEvent stream as core
const result = await turn;- No third-party runtime dependencies — uses the global
WebSocket(browsers, Node ≥ 22); on Node 20/21 passwebSocket: (url) => new WS(url)with thewspackage. - Remote workflows —
client.runWorkflow(def)dispatches an@klein-kit/orchestrateworkflow to the server and returns a handle synchronously: await it for the result, iterate it for events,cancel()it, reattach after a disconnect. - Reconnects forever — exponential backoff (250 ms → 16 s, jittered, reset after 30 s stable); auth failures block instead of burning retries.
- Turns survive outages — mirrors reattach with a sequence cursor and replay what they missed; unacknowledged prompts re-send idempotently; results lost past the replay window are recovered from the server's settled-turn history.
- Attach from anywhere —
client.attach(sessionId)mirrors a session another device created;session.detach()leaves it running. - Permission handlers stay local —
onPermissionRequestruns on the client and answers over the wire; without one, requests surface aspermission.requestedevents for your UI. - Encrypted with a pinned cert — pass
tlsFingerprint(printed byklein serve) to connect over wss to a self-signed certificate, verified by fingerprint during the handshake. Needs thewspackage on Node.
Wire contract: @klein-kit/protocol and docs/design/remote-protocol.md.
Full docs: github.com/yvescomputer/klein-kit · MIT © Yves Computer Company
