Skip to main content

KlpClient

Struct KlpClient 

Source
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

Source

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.

Source

pub async fn connect_to(path: impl AsRef<Path>) -> Result<Self, ConnectError>

Connect to an explicit socket endpoint (tests / development).

Source

pub async fn connect_with_retry() -> Result<Self, ConnectError>

Source

pub async fn connect_to_with_retry(path: &Path) -> Result<Self, ConnectError>

Source

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.

Source

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.

Source

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.

Source

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).

Source

pub async fn ping(&self) -> Result<PingResult>

Convenience wrapper for system.ping.

Source

pub async fn snapshot(&self) -> Result<StateSnapshot>

state.snapshot — the full endpoint health bundle the Health tab renders (#290).

Source

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.

Source

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).

Source

pub async fn jobs_kill(&self, run_id: &str) -> Result<JobsKillResult>

jobs.kill — request termination of a run this connection started (#291).

Source

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.

Source

pub async fn support_lock(&self) -> Result<SupportLockResult>

support.lock — end the support session now, dropping every grant.

Source

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.

Source

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.

Source

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.

Source

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).

Source

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.

Trait Implementations§

Source§

impl Clone for KlpClient

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more