pub struct KlpClient { /* private fields */ }Expand description
Shared KLP connection. Cheap to clone (everything behind Arc),
so each Tauri command clones it out of AppState and runs its
round-trip without holding the app-state mutex across the await.
Implementations§
Source§impl KlpClient
impl KlpClient
Sourcepub async fn connect() -> Result<Self, ConnectError>
pub async fn connect() -> Result<Self, ConnectError>
Open the pipe, run the SPEC §2.12.6 handshake, split the pipe,
and spawn the reader task. Bubbles up the underlying error so
the Tauri setup callback can surface a clear “agent not
running” banner if the pipe isn’t there yet.
Sourcepub async fn connect_to(path: impl AsRef<Path>) -> Result<Self, ConnectError>
pub async fn connect_to(path: impl AsRef<Path>) -> Result<Self, ConnectError>
Connect to an explicit socket endpoint (tests / development).
pub async fn connect_with_retry() -> Result<Self, ConnectError>
pub async fn connect_to_with_retry(path: &Path) -> Result<Self, ConnectError>
Sourcepub async fn wait_closed(&self)
pub async fn wait_closed(&self)
Resolve once the connection has closed (the reader task exited — the agent’s pipe went away). The Tauri supervisor awaits this to trigger reconnection. Returns immediately if already closed.
Sourcepub fn handshake(&self) -> Arc<HandshakeResult> ⓘ
pub fn handshake(&self) -> Arc<HandshakeResult> ⓘ
Cached handshake result. Returned to the UI on every
get_handshake invoke — handshake is one-shot per
connection so the cache is the source of truth.
Sourcepub fn subscribe(&self) -> Receiver<RpcNotification>
pub fn subscribe(&self) -> Receiver<RpcNotification>
Subscribe to agent→client push notifications (jobs.progress,
state.changed, …). The Tauri layer drains this and re-emits
each notification to the WebView as a klp://notification
event. A subscriber only receives notifications sent after
it subscribes (broadcast semantics) — subscribe right after
connect so no early progress is missed.
Sourcepub async fn request<P: Serialize, R: DeserializeOwned>(
&self,
method: &str,
params: &P,
) -> Result<R>
pub async fn request<P: Serialize, R: DeserializeOwned>( &self, method: &str, params: &P, ) -> Result<R>
Round-trip one request through the pipe. Mints a UUID id, registers a pending waiter, writes the frame, and awaits the reader task’s correlated response.
params is the typed request payload; R is the per-method
result struct (e.g. PingResult).
Sourcepub async fn ping(&self) -> Result<PingResult>
pub async fn ping(&self) -> Result<PingResult>
Convenience wrapper for system.ping.
Sourcepub async fn snapshot(&self) -> Result<StateSnapshot>
pub async fn snapshot(&self) -> Result<StateSnapshot>
state.snapshot — the full endpoint health bundle the Health
tab renders (#290).
Sourcepub async fn jobs_list(&self, params: &JobsListParams) -> Result<JobsListResult>
pub async fn jobs_list(&self, params: &JobsListParams) -> Result<JobsListResult>
jobs.list — the user-invokable job catalog for the three job
tabs (#291). params.category narrows to one tab.
Sourcepub async fn jobs_execute(&self, id: &str) -> Result<JobsExecuteResult>
pub async fn jobs_execute(&self, id: &str) -> Result<JobsExecuteResult>
jobs.execute — run a user-invokable job by id; returns the
run_id whose jobs.progress pushes arrive via
KlpClient::subscribe (#291).
Sourcepub async fn jobs_kill(&self, run_id: &str) -> Result<JobsKillResult>
pub async fn jobs_kill(&self, run_id: &str) -> Result<JobsKillResult>
jobs.kill — request termination of a run this connection
started (#291).
Sourcepub async fn support_unlock(&self, code: &str) -> Result<SupportUnlockResult>
pub async fn support_unlock(&self, code: &str) -> Result<SupportUnlockResult>
support.unlock — redeem an operator-issued support code, revealing
this OS user’s client.unlock-gated jobs until the grant expires.
A wrong code comes back as an error, never an empty grant list.
Sourcepub async fn support_lock(&self) -> Result<SupportLockResult>
pub async fn support_lock(&self) -> Result<SupportLockResult>
support.lock — end the support session now, dropping every grant.
Sourcepub async fn support_status(&self) -> Result<SupportStatusResult>
pub async fn support_status(&self) -> Result<SupportStatusResult>
support.status — the grants this OS user currently holds. Called on
every (re)connect: grants outlive a single KLP connection, so a client
that reconnected mid-session restores its banner from this rather than
asking the desk to re-type the code.
Sourcepub async fn notifications_subscribe(
&self,
) -> Result<NotificationsSubscribeResult>
pub async fn notifications_subscribe( &self, ) -> Result<NotificationsSubscribeResult>
notifications.subscribe — ask the agent to start streaming
notifications.new pushes on this connection (Phase E, #102).
Until it lands the agent fans nothing out to this client, so the
WebView calls it once per connection (re-called on reconnect);
the pushes then arrive via KlpClient::subscribe like any
other agent→client notification.
Sourcepub async fn notifications_list(
&self,
params: &NotificationsListParams,
) -> Result<NotificationsListResult>
pub async fn notifications_list( &self, params: &NotificationsListParams, ) -> Result<NotificationsListResult>
notifications.list — this user’s notification history (#102),
scoped to the caller’s OS SID agent-side. params.filter selects
unread-only vs all; params.cursor pages.
Sourcepub async fn notifications_ack(
&self,
id: &str,
) -> Result<NotificationsAckResult>
pub async fn notifications_ack( &self, id: &str, ) -> Result<NotificationsAckResult>
notifications.ack — mark a notification read for the caller’s
OS user (#102). The agent derives the SID from the connection,
never the payload, then persists notifications_read KV and
publishes the events.notifications.acked.> event the SPA’s
ack-status view reads (#604).
Sourcepub async fn notifications_unack(
&self,
id: &str,
) -> Result<NotificationsUnackResult>
pub async fn notifications_unack( &self, id: &str, ) -> Result<NotificationsUnackResult>
notifications.unack — retract the caller’s prior ack (the
read↔unread toggle). Inverse of Self::notifications_ack: the
agent deletes the notifications_read KV entry and publishes
events.notifications.unacked.> so the SPA roster flips back to
“未確認” while the audit log keeps the original confirmation.