pub struct SocketClient {
pub session_id: SessionId,
/* private fields */
}Expand description
A client connection to the kernel’s Unix-domain socket.
Fields§
§session_id: SessionIdThe unique identifier for this session.
Implementations§
Source§impl SocketClient
impl SocketClient
Sourcepub async fn connect(session_id: SessionId) -> Result<Self>
pub async fn connect(session_id: SessionId) -> Result<Self>
Connect to an existing session socket and perform the authenticated handshake.
§Errors
Returns an error if the socket file does not exist, connection fails, or the handshake is rejected.
Sourcepub async fn read_message(&mut self) -> Result<Option<IpcMessage>>
pub async fn read_message(&mut self) -> Result<Option<IpcMessage>>
Read the next IPC message from the daemon.
Frames that don’t deserialize cleanly as
IpcMessage (notably the
kernel’s astrid.v1.capsules_loaded broadcast, whose
IpcPayload::RawJson inner value is emitted without the
type discriminator) are logged at debug and skipped. Without
this tolerance interactive clients would die on the first
broadcast.
§Errors
Returns an error if the connection is unrecoverable (over-large frame, IO failure mid-read).
Sourcepub async fn read_raw_frame(&mut self) -> Result<Option<Vec<u8>>>
pub async fn read_raw_frame(&mut self) -> Result<Option<Vec<u8>>>
Read the next length-prefixed frame as raw bytes, without
attempting to deserialize. Used by crate::admin_client when
it needs to tolerate broadcast messages that don’t deserialize
cleanly into IpcMessage.
§Errors
Returns an error if the frame cannot be read.
Sourcepub async fn read_until_topic(
&mut self,
want_topic: &str,
timeout: Duration,
) -> Result<Value>
pub async fn read_until_topic( &mut self, want_topic: &str, timeout: Duration, ) -> Result<Value>
Read frames until one arrives on want_topic or timeout
elapses. Frames that fail to deserialize as JSON or carry a
different topic are silently skipped.
§Errors
Returns an error if the deadline elapses, the connection closes, or a read fails.
Sourcepub fn extract_kernel_response(raw: &Value) -> Option<KernelResponse>
pub fn extract_kernel_response(raw: &Value) -> Option<KernelResponse>
Extract the inner kernel response from a raw frame previously
returned by read_until_topic.
The kernel emits one of two on-wire shapes depending on which router branch produced the response:
- Bare typed payload —
{ "type": "...", ... }, already aKernelResponse-shaped object thatserde_json::from_valuecan deserialize directly. RawJson-wrapped payload —{ "type": "raw_json", "value": { "type": "...", ... } }(the older router branch wraps the typed body inIpcPayload::RawJson).
Both have to be tolerated by every consumer of the bare verbs.
Returns None when the frame has no payload field or the
deserialization fails — callers fall back to an empty display
rather than crashing.
Sourcepub async fn send_input(
&mut self,
text: String,
caller: &PrincipalId,
) -> Result<()>
pub async fn send_input( &mut self, text: String, caller: &PrincipalId, ) -> Result<()>
Send a user-prompt message on behalf of caller.
Convenience helper for chat-style uplinks. Stamps
IpcMessage.principal from the caller so the kernel’s
resolve_caller sees the right principal for session, KV,
home, secret, and quota scoping.
§Errors
Returns an error if the message cannot be sent.
Sourcepub async fn send_message(&mut self, msg: IpcMessage) -> Result<()>
pub async fn send_message(&mut self, msg: IpcMessage) -> Result<()>
Send a raw IPC message to the kernel.
The caller is responsible for stamping
IpcMessage::principal
before calling — this transport does not infer it.
§Errors
Returns an error if the message cannot be serialized or sent.