Skip to main content

scv_protocol/
lib.rs

1//! Dependency-light wire types shared by SCV clients and the server.
2//!
3//! [`ClientMessage`] is everything a client sends and [`ServerEvent`]
4//! everything the server answers, one JSON object per line ([`FrameDecoder`]
5//! bounds each line). Additive fields, and new values of the enums that
6//! parse unknown values as `Unknown` ([`ErrorCode`], [`ToolErrorKind`],
7//! [`ServerEvent`]), keep [`PROTOCOL_VERSION`]; a breaking change bumps it.
8//! This crate holds no runtime policy and does no I/O.
9
10#![forbid(unsafe_code)]
11#![warn(missing_docs)]
12
13mod attachment;
14mod background;
15mod client;
16mod daemon;
17mod error;
18mod frame;
19mod server;
20
21use serde::{Deserialize, Serialize};
22
23pub use attachment::{Attachment, ReplyAttachment, reply_attachment};
24pub use background::{JobChange, JobStatus, OriginKind, TurnOrigin, job_agent};
25pub use client::{ChatLog, ClientMessage};
26pub use daemon::{
27    ComponentHealth, ComponentState, ConfirmInfo, ConfirmState, DEFAULT_CONFIRM_SECONDS,
28    DaemonCommand, DaemonStatus, DelegationInfo, DelegationSummary, MAX_CONFIRM_SECONDS,
29    MailCounts, ProjectEvent, ProjectPhase, ProjectReport, ProjectResponse, ProjectRun,
30    ProjectRunStatus, ProjectStatus, ProjectSummary, ProjectTask, ProjectTaskStatus, Purpose,
31    RemoteTools, RestartInfo, Senders,
32};
33pub use error::{ErrorCode, ToolErrorKind};
34pub use frame::{Frame, FrameDecoder, Overflow, Step, encode_frame, trim_line};
35pub use server::ServerEvent;
36
37/// The protocol version. Client and server must speak the same one.
38pub const PROTOCOL_VERSION: u32 = 3;
39
40/// The longest `session.start` channel name.
41pub const MAX_CHANNEL_NAME_BYTES: usize = 32;
42/// Longest `session.start` `system_prompt`, in bytes.
43pub const MAX_SYSTEM_PROMPT_BYTES: usize = 16 * 1024;
44/// Files one `turn.start` may attach.
45pub const MAX_TURN_ATTACHMENTS: usize = 16;
46/// The tool a chat session's model calls to send a file with its reply.
47pub const CHAT_ATTACH_TOOL: &str = "chat_attach";
48
49/// A prompt waiting for the running turn to finish.
50#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
51pub struct QueueEntry {
52    /// Stable ID of this queued prompt.
53    pub queue_id: String,
54    /// Bumped on every change; edits must name the current revision.
55    pub revision: u64,
56    /// The prompt text.
57    pub prompt: String,
58    /// The client that queued it.
59    pub submitter: String,
60    /// Files the queued `turn.start` attached; they run with its prompt.
61    #[serde(default, skip_serializing_if = "Vec::is_empty")]
62    pub attachments: Vec<Attachment>,
63}
64
65/// A client's or server's name and version, exchanged at `initialize`.
66#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
67pub struct PeerInfo {
68    /// Program name, such as `scv-tui`.
69    pub name: String,
70    /// Its release.
71    pub version: String,
72}
73
74/// Tokens a turn used, as the provider reported them.
75#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
76pub struct Usage {
77    /// Prompt tokens, when reported.
78    #[serde(skip_serializing_if = "Option::is_none")]
79    pub input_tokens: Option<u64>,
80    /// Answer tokens, when reported.
81    #[serde(skip_serializing_if = "Option::is_none")]
82    pub output_tokens: Option<u64>,
83}
84
85#[cfg(test)]
86mod tests;