hyphae-client) is the thin smart client your service uses to talk to a HyphaeDB
server. It is fully async (tokio + tonic) and gRPC-only: it wraps the wire contract and keeps a warm
local read cache (your inbox of gossip deliveries plus scene summaries) so recall serves from
cache first and only round-trips the server on a miss. It contains no mesh logic — gossip, the
energy model, and layer promotion all live server-side. Because it is a plain async library with no
process of its own, it is embeddable directly in another Rust service. See
the client SDK concepts for what the inbox delivers.
The crate is named
hyphae-client, not hyphaedb. It uses edition 2021 and depends only on the
generated protobuf plus async plumbing — never on the server crates.Install
Stream extension trait for consuming the inbox. Add them to
your Cargo.toml:
InboxItem) live under hyphae_client::pb:
Connect and authenticate
Every call authenticates with your full API key — the wholehyk_... string. You pass it as the
second argument to connect, and the SDK attaches it verbatim as the x-hyphae-key gRPC metadata
header on every RPC. The SDK never parses or logs the key. connect accepts a bare host:port
endpoint and prefixes http:// for you.
Identity is bound once, at connect, from the authenticated key. The SDK never self-asserts
source_agent: there is no field by which a caller can claim to be another agent (the server stamps
authorship from the key principal). This is a security invariant (INV-4 in the SDK spec) enforced
structurally — CellInput simply has no source_agent field.hyk_... credential.
Quickstart
A single end-to-end flow: connect, start a session, store a cell, recall it, consume one inbox delivery, then close.CellInput::new and RecallQuery::new are convenience constructors; you can also build the structs
with field literals when you need to set scene_id, salience, k, or filters.
API reference
connect
Info version-negotiation handshake, binds identity
from auth, and returns a ready client. Returns ClientError::Connect if the channel never comes
up, if the handshake fails, or if the server is below the SDK’s minimum supported version.
store
node_id. The SDK mints one idempotency key per logical call
(uuid4) and replays it on a transport-error retry, so a retry returns the original node_id rather
than a duplicate. salience is validated to [0.0, 1.0] before any RPC.
recall
k). When the cache and the server return the same content, the server copy wins.
start_session
agent_id is your identity label; it is threaded as the session scope, never asserted
as source_agent. Calling it again installs a fresh inbox channel for the new session generation.
place_beacon
node_id. The owner is the session agent, never
caller-asserted. Beacons shape what the mesh routes to you — see
positioning and beacons.
inbox
InboxItem is yielded at most once (deduped
by diff_id) across the live stream and any number of reconnect replays. It is single-consumer:
inbox() takes the receiver for the current session generation. The stream never hangs — on a clean
close() or a fatal error it ends, and a fatal error is yielded as the final Err item. Pin it
(for example with Box::pin) and use StreamExt::next to drain it. See
gossip propagation for what flows down this stream.
close
inbox(). Dropping the client
does the same via its Drop impl, so explicit close is optional.
Types
CellType is an enum with the nine calibrated variants: Decision, Constraint, Risk,
Pattern, Lesson, Fact, Preference, Context, Task (plus an Unspecified sentinel a newer
server’s unknown value decodes to). Tune buffer sizes, reconnect backoff, and the heartbeat timeout
with ClientConfig.
Version negotiation
At connect the SDK calls the unauthenticated
Info RPC to learn the server’s version and
capabilities. If the server is below the SDK’s minimum supported version, connect returns
ClientError::Connect and no client. After connecting, read client.server_version() and gate
optional, newer-than-floor features on client.has_capability(token) so the SDK degrades gracefully
against an older server. See API versioning for the compatibility
rules.