1use chrono::Duration;
2use serde::{Deserialize, Serialize};
3use std::{ops::Range, path::PathBuf};
4use uuid::Uuid;
5
6use crate::PredictEditsGitInfo;
7
8// TODO: snippet ordering within file / relative to excerpt
9
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct PredictEditsRequest {
12 pub excerpt: String,
13 pub excerpt_path: PathBuf,
14 /// Within file
15 pub excerpt_range: Range<usize>,
16 /// Within `excerpt`
17 pub cursor_offset: usize,
18 /// Within `signatures`
19 pub excerpt_parent: Option<usize>,
20 pub signatures: Vec<Signature>,
21 pub referenced_declarations: Vec<ReferencedDeclaration>,
22 pub events: Vec<Event>,
23 #[serde(default)]
24 pub can_collect_data: bool,
25 #[serde(skip_serializing_if = "Vec::is_empty", default)]
26 pub diagnostic_groups: Vec<DiagnosticGroup>,
27 /// Info about the git repository state, only present when can_collect_data is true.
28 #[serde(skip_serializing_if = "Option::is_none", default)]
29 pub git_info: Option<PredictEditsGitInfo>,
30 #[serde(default)]
31 pub debug_info: bool,
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(tag = "event")]
36pub enum Event {
37 BufferChange {
38 path: Option<PathBuf>,
39 old_path: Option<PathBuf>,
40 diff: String,
41 predicted: bool,
42 },
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
46pub struct Signature {
47 pub text: String,
48 pub text_is_truncated: bool,
49 #[serde(skip_serializing_if = "Option::is_none", default)]
50 pub parent_index: Option<usize>,
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
54pub struct ReferencedDeclaration {
55 pub path: PathBuf,
56 pub text: String,
57 pub text_is_truncated: bool,
58 /// Range of `text` within file, potentially truncated according to `text_is_truncated`
59 pub range: Range<usize>,
60 /// Range within `text`
61 pub signature_range: Range<usize>,
62 /// Index within `signatures`.
63 #[serde(skip_serializing_if = "Option::is_none", default)]
64 pub parent_index: Option<usize>,
65 pub score_components: ScoreComponents,
66 pub signature_score: f32,
67 pub declaration_score: f32,
68}
69
70#[derive(Debug, Clone, Serialize, Deserialize)]
71pub struct ScoreComponents {
72 pub is_same_file: bool,
73 pub is_referenced_nearby: bool,
74 pub is_referenced_in_breadcrumb: bool,
75 pub reference_count: usize,
76 pub same_file_declaration_count: usize,
77 pub declaration_count: usize,
78 pub reference_line_distance: u32,
79 pub declaration_line_distance: u32,
80 pub declaration_line_distance_rank: usize,
81 pub containing_range_vs_item_jaccard: f32,
82 pub containing_range_vs_signature_jaccard: f32,
83 pub adjacent_vs_item_jaccard: f32,
84 pub adjacent_vs_signature_jaccard: f32,
85 pub containing_range_vs_item_weighted_overlap: f32,
86 pub containing_range_vs_signature_weighted_overlap: f32,
87 pub adjacent_vs_item_weighted_overlap: f32,
88 pub adjacent_vs_signature_weighted_overlap: f32,
89}
90
91#[derive(Debug, Clone, Serialize, Deserialize)]
92pub struct DiagnosticGroup {
93 pub language_server: String,
94 pub diagnostic_group: serde_json::Value,
95}
96
97#[derive(Debug, Clone, Serialize, Deserialize)]
98pub struct PredictEditsResponse {
99 pub request_id: Uuid,
100 pub edits: Vec<Edit>,
101 pub debug_info: Option<DebugInfo>,
102}
103
104#[derive(Debug, Clone, Serialize, Deserialize)]
105pub struct DebugInfo {
106 pub prompt: String,
107 pub prompt_planning_time: Duration,
108 pub model_response: String,
109 pub inference_time: Duration,
110 pub parsing_time: Duration,
111}
112
113#[derive(Debug, Clone, Serialize, Deserialize)]
114pub struct Edit {
115 pub path: PathBuf,
116 pub range: Range<usize>,
117 pub content: String,
118}