1use std::fmt;
2use std::{path::Path, sync::Arc};
3
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Serialize)]
7pub struct AutocompleteRequest {
8 pub debug_info: Arc<str>,
9 pub repo_name: String,
10 pub branch: Option<String>,
11 pub file_path: Arc<Path>,
12 pub file_contents: String,
13 pub recent_changes: String,
14 pub cursor_position: usize,
15 pub original_file_contents: String,
16 pub file_chunks: Vec<FileChunk>,
17 pub retrieval_chunks: Vec<RetrievalChunk>,
18 pub recent_user_actions: Vec<UserAction>,
19 pub multiple_suggestions: bool,
20 pub privacy_mode_enabled: bool,
21 pub changes_above_cursor: bool,
22}
23
24#[derive(Debug, Clone, Serialize)]
25pub struct FileChunk {
26 pub file_path: String,
27 pub start_line: usize,
28 pub end_line: usize,
29 pub content: String,
30 pub timestamp: Option<u64>,
31}
32
33#[derive(Debug, Clone, Serialize)]
34pub struct RetrievalChunk {
35 pub file_path: String,
36 pub start_line: usize,
37 pub end_line: usize,
38 pub content: String,
39 pub timestamp: u64,
40}
41
42#[derive(Debug, Clone, Serialize)]
43pub struct UserAction {
44 pub action_type: ActionType,
45 pub line_number: usize,
46 pub offset: usize,
47 pub file_path: String,
48 pub timestamp: u64,
49}
50
51#[allow(dead_code)]
52#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
53#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
54pub enum ActionType {
55 CursorMovement,
56 InsertChar,
57 DeleteChar,
58 InsertSelection,
59 DeleteSelection,
60}
61
62#[derive(Debug, Clone, Deserialize)]
63pub struct AutocompleteResponse {
64 pub autocomplete_id: String,
65 pub start_index: usize,
66 pub end_index: usize,
67 pub completion: String,
68 #[allow(dead_code)]
69 pub confidence: f64,
70 #[allow(dead_code)]
71 pub logprobs: Option<serde_json::Value>,
72 #[allow(dead_code)]
73 pub finish_reason: Option<String>,
74 #[allow(dead_code)]
75 pub elapsed_time_ms: u64,
76 #[allow(dead_code)]
77 #[serde(default, rename = "completions")]
78 pub additional_completions: Vec<AdditionalCompletion>,
79}
80
81#[allow(dead_code)]
82#[derive(Debug, Clone, Deserialize)]
83pub struct AdditionalCompletion {
84 pub start_index: usize,
85 pub end_index: usize,
86 pub completion: String,
87 pub confidence: f64,
88 pub autocomplete_id: String,
89 pub logprobs: Option<serde_json::Value>,
90 pub finish_reason: Option<String>,
91}
92
93pub(crate) fn write_event(
94 event: &cloud_llm_client::predict_edits_v3::Event,
95 f: &mut impl fmt::Write,
96) -> fmt::Result {
97 match event {
98 cloud_llm_client::predict_edits_v3::Event::BufferChange {
99 old_path,
100 path,
101 diff,
102 ..
103 } => {
104 if old_path != path {
105 // TODO confirm how to do this for sweep
106 // writeln!(f, "User renamed {:?} to {:?}\n", old_path, new_path)?;
107 }
108
109 if !diff.is_empty() {
110 write!(f, "File: {}:\n{}\n", path.display(), diff)?
111 }
112
113 fmt::Result::Ok(())
114 }
115 }
116}
117
118pub(crate) fn debug_info(cx: &gpui::App) -> Arc<str> {
119 format!(
120 "Zed v{version} ({sha}) - OS: {os} - Zed v{version}",
121 version = release_channel::AppVersion::global(cx),
122 sha = release_channel::AppCommitSha::try_global(cx)
123 .map_or("unknown".to_string(), |sha| sha.full()),
124 os = client::telemetry::os_name(),
125 )
126 .into()
127}