Skip to main content

objectiveai_sdk/daemon/
viewer_plugin.rs

1//! The viewer-plugin bundle download —
2//! [`Client::get_viewer_plugin`](super::Client::get_viewer_plugin)'s
3//! response. LOW-LEVEL by design: raw tar.gz bytes, caller-paced, no
4//! filesystem — the consumer (the viewer's installer) un-tars into
5//! its own staging its own way.
6
7use futures::TryStreamExt;
8
9/// One in-flight viewer-extension bundle: the tag's commit SHA (from
10/// the `X-OBJECTIVEAI-SHA` response header) plus the tar.gz byte
11/// stream. Dropping it aborts the transfer.
12pub struct ViewerPlugin {
13    /// The plugin tag's commit SHA, when the daemon stamped it.
14    pub commit_sha: Option<String>,
15    response: reqwest::Response,
16}
17
18impl ViewerPlugin {
19    pub(crate) fn new(commit_sha: Option<String>, response: reqwest::Response) -> Self {
20        Self {
21            commit_sha,
22            response,
23        }
24    }
25
26    /// The next chunk of tar.gz bytes; `None` = the body ended. A
27    /// TRUNCATED body is indistinguishable here from a complete one —
28    /// the caller's un-gzip/un-tar is what validates completeness
29    /// (a daemon-side failure mid-build never streams: the tar starts
30    /// only after the build succeeded).
31    pub async fn chunk(&mut self) -> Result<Option<bytes::Bytes>, super::Error> {
32        Ok(self.response.chunk().await?)
33    }
34
35    /// The remaining body as a byte stream.
36    pub fn bytes_stream(
37        self,
38    ) -> impl futures::Stream<Item = Result<bytes::Bytes, super::Error>> {
39        self.response.bytes_stream().map_err(super::Error::from)
40    }
41}