Skip to main content

fallow_api/similar_code/
protocol.rs

1//! Generated constants and wire DTOs for the local similar-code companion.
2
3#![allow(
4    dead_code,
5    clippy::unreadable_literal,
6    reason = "generated protocol fields are validated even when not consumed by this crate"
7)]
8
9use serde::{Deserialize, Serialize};
10
11/// One immutable model artifact required by the official local provider.
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub struct SimilarCodeArtifact {
14    /// Repository-relative model artifact path.
15    pub path: &'static str,
16    /// Expected artifact size in bytes.
17    pub size: u64,
18    /// Expected lowercase SHA-256 digest.
19    pub sha256: &'static str,
20}
21
22include!(concat!(env!("OUT_DIR"), "/similar_code_protocol.rs"));
23
24/// One transient function submitted to the local provider.
25#[derive(Debug, Serialize)]
26pub(super) struct EmbedFunctionRequest<'a> {
27    /// Opaque request-local key. It carries no path or source identity.
28    pub key: u32,
29    /// Full bounded function source.
30    pub source: &'a str,
31}
32
33/// One bounded inference batch.
34#[derive(Debug, Serialize)]
35pub(super) struct EmbedBatchRequest<'a> {
36    /// Wire operation.
37    pub operation: &'static str,
38    /// Wire protocol version.
39    pub protocol_version: u32,
40    /// Required embedding calculation semantics.
41    pub embedding_semantics_version: u32,
42    /// Required immutable model revision.
43    pub model_revision: &'static str,
44    /// Expected embedding width.
45    pub dimensions: usize,
46    /// Maximum tokenizer length before deterministic truncation.
47    pub max_tokens: usize,
48    /// Functions in this batch.
49    pub functions: &'a [EmbedFunctionRequest<'a>],
50}
51
52/// One provider-returned vector.
53#[derive(Debug, Deserialize)]
54#[serde(deny_unknown_fields)]
55pub(super) struct EmbedFunctionResponse {
56    /// Request-local key copied from the input.
57    pub key: u32,
58    /// Dense normalized embedding values.
59    pub values: Vec<f32>,
60    /// Whether tokenizer length bounded this source fragment.
61    #[serde(default)]
62    pub truncated: bool,
63}
64
65/// Provider timing for one batch.
66#[derive(Debug, Deserialize)]
67#[serde(deny_unknown_fields)]
68pub(super) struct EmbedBatchTiming {
69    /// Model inference wall time.
70    pub inference_ms: f64,
71}
72
73/// Response from one bounded inference batch.
74#[derive(Debug, Deserialize)]
75#[serde(deny_unknown_fields)]
76pub(super) struct EmbedBatchResponse {
77    /// Wire protocol version used by the provider.
78    pub protocol_version: u32,
79    /// Embedding calculation semantics used by the provider.
80    pub embedding_semantics_version: u32,
81    /// Immutable model revision used by the provider.
82    pub model_revision: String,
83    /// Returned embedding width.
84    pub dimensions: usize,
85    /// Vectors in request order or keyed form.
86    pub vectors: Vec<EmbedFunctionResponse>,
87    /// Provider timing.
88    pub timing: EmbedBatchTiming,
89    /// Overall provider outcome for this request.
90    pub status: EmbedCompletionStatus,
91    /// Typed provider limit and completion accounting.
92    pub completion: EmbedCompletion,
93    /// Per-function or request-level failures.
94    #[serde(default)]
95    pub errors: Vec<EmbedFunctionError>,
96}
97
98/// Provider completion state for one embed request.
99#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
100#[serde(rename_all = "kebab-case")]
101pub(super) enum EmbedCompletionStatus {
102    Complete,
103    Partial,
104    Error,
105}
106
107/// Limits the provider applied independently of caller input.
108#[derive(Debug, Deserialize)]
109#[serde(deny_unknown_fields)]
110pub(super) struct EmbedAppliedLimits {
111    pub max_functions: usize,
112    pub max_total_source_bytes: usize,
113    pub max_source_bytes_per_function: usize,
114    pub max_tokens: usize,
115    pub batch_size: usize,
116    pub timeout_ms: u64,
117}
118
119/// Typed completion accounting from the provider.
120#[derive(Debug, Deserialize)]
121#[serde(deny_unknown_fields)]
122pub(super) struct EmbedCompletion {
123    pub requested_functions: usize,
124    pub embedded_functions: usize,
125    pub skipped_functions: usize,
126    pub truncated_functions: usize,
127    pub applied_limits: EmbedAppliedLimits,
128}
129
130/// Closed provider error catalogue.
131#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
132#[serde(rename_all = "kebab-case")]
133pub(super) enum EmbedErrorCode {
134    InvalidRequest,
135    ProtocolMismatch,
136    EmbeddingSemanticsMismatch,
137    ModelRevisionMismatch,
138    DimensionMismatch,
139    MaxTokensMismatch,
140    DuplicateFunctionKey,
141    FunctionLimit,
142    TotalSourceBytesLimit,
143    FunctionSourceBytesLimit,
144    Timeout,
145    ModelNotReady,
146    InferenceFailed,
147    RequestTooLarge,
148}
149
150/// One bounded provider error without source content.
151#[derive(Debug, Deserialize)]
152#[serde(deny_unknown_fields)]
153pub(super) struct EmbedFunctionError {
154    pub key: Option<u32>,
155    pub code: EmbedErrorCode,
156    pub retryable: bool,
157    pub observed: Option<u64>,
158    pub limit: Option<u64>,
159    pub message: Option<String>,
160}
161
162/// Machine-readable companion and model availability.
163#[derive(Debug, Clone, Deserialize, Serialize)]
164#[serde(deny_unknown_fields)]
165pub struct SimilarCodeProviderStatus {
166    /// Wire protocol version implemented by the sidecar.
167    pub protocol_version: u32,
168    /// Embedding calculation semantics implemented by the sidecar.
169    pub embedding_semantics_version: u32,
170    /// Installed sidecar package version.
171    pub sidecar_version: String,
172    /// Whether every pinned model artifact is present and valid.
173    pub model_ready: bool,
174    /// Immutable model identifier.
175    pub model_id: String,
176    /// Immutable model revision.
177    pub model_revision: String,
178    /// Embedding width.
179    pub dimensions: usize,
180    /// Maximum tokenizer length before deterministic truncation.
181    pub max_tokens: usize,
182    /// Model license identifier.
183    pub license: String,
184    /// User-cache directory containing model artifacts.
185    pub cache_dir: String,
186    /// Total expected artifact bytes.
187    pub download_bytes: u64,
188    /// Whether source analysis stays offline after setup.
189    pub analysis_offline: bool,
190    /// Whether all pinned artifacts passed size and SHA-256 validation.
191    pub integrity_verified: bool,
192    /// Actionable readiness problem when the model is not ready.
193    #[serde(skip_serializing_if = "Option::is_none")]
194    pub problem: Option<String>,
195    /// Whether setup downloaded new bytes, present only after setup.
196    #[serde(skip_serializing_if = "Option::is_none")]
197    pub downloaded: Option<bool>,
198}