Skip to main content

comindly_api/
settings.rs

1//! Your settings and the team's (`/api/v1/settings*`, `/team*`, `/join`).
2
3use serde::{Deserialize, Serialize};
4
5pub use crate::credentials::Source as KeySource;
6pub use crate::team::TeamSettings;
7
8/// `GET /api/v1/settings`: your preferences and what is in effect.
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct Settings {
11    pub config_path: String,
12    pub index_dir: Option<String>,
13    pub index_effective: String,
14    pub author_name: Option<String>,
15    pub author_effective: Option<String>,
16    pub record_names: bool,
17    pub llm_model: String,
18    pub defaults: Defaults,
19    pub llm_key: KeySource,
20    pub cache_ttl_secs: u64,
21}
22
23/// comindly's built-in values, shown where a setting is left empty.
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct Defaults {
26    pub llm_model: String,
27    pub llm_base_url: String,
28    pub embed_model: String,
29    pub llm_concurrency: usize,
30    pub format: String,
31}
32
33/// `POST /api/v1/settings`: only the given settings change; an empty text removes one.
34#[derive(Debug, Clone, Default, Serialize, Deserialize)]
35pub struct SettingsChange {
36    #[serde(default, skip_serializing_if = "Option::is_none")]
37    pub index_dir: Option<String>,
38    #[serde(default, skip_serializing_if = "Option::is_none")]
39    pub author_name: Option<String>,
40    #[serde(default, skip_serializing_if = "Option::is_none")]
41    pub record_names: Option<bool>,
42    #[serde(default, skip_serializing_if = "Option::is_none")]
43    pub cache_ttl_secs: Option<u64>,
44}
45
46/// `POST /api/v1/settings/test`: whether an index location can be read.
47#[derive(Debug, Clone, Serialize, Deserialize)]
48pub struct IndexDirRequest {
49    pub index_dir: String,
50}
51
52/// `GET /api/v1/team`: the index's shared settings and where your API key comes from.
53#[derive(Debug, Clone, Serialize, Deserialize)]
54pub struct Team {
55    pub settings: TeamSettings,
56    pub key_source: KeySource,
57    pub version: Option<u64>,
58    pub changed_by: Option<String>,
59    pub changed_at: Option<String>,
60    pub defaults: Defaults,
61}
62
63/// `POST /api/v1/team`: `version` is the one read, so a concurrent change is not overwritten.
64#[derive(Debug, Clone, Serialize, Deserialize)]
65pub struct TeamSave {
66    pub settings: TeamSettings,
67    pub version: Option<u64>,
68}
69
70/// `POST /api/v1/teams`: the whole team list, at the settings version read.
71#[derive(Debug, Clone, Serialize, Deserialize)]
72pub struct TeamsSave {
73    pub teams: Vec<crate::team::TeamDef>,
74    pub version: Option<u64>,
75}
76
77/// `POST /api/v1/repos/teams`: exactly these teams on `repo` (its indexed name).
78#[derive(Debug, Clone, Serialize, Deserialize)]
79pub struct RepoTeams {
80    pub repo: String,
81    pub teams: Vec<String>,
82}
83
84/// `POST /api/v1/me/teams`: the teams you belong to.
85#[derive(Debug, Clone, Serialize, Deserialize)]
86pub struct MyTeams {
87    pub teams: Vec<String>,
88}
89
90/// `POST /api/v1/team/key`: your API key; empty removes it.
91#[derive(Debug, Clone, Serialize, Deserialize)]
92pub struct KeyRequest {
93    pub key: String,
94}
95
96/// `POST /api/v1/join`: use a team's index.
97#[derive(Debug, Clone, Serialize, Deserialize)]
98pub struct JoinRequest {
99    pub index: String,
100}
101
102/// `POST /api/v1/team/create`: start a team at an empty location.
103#[derive(Debug, Clone, Serialize, Deserialize)]
104pub struct CreateTeam {
105    pub name: String,
106    pub index: String,
107}
108
109/// `GET /api/v1/prompts`: each LLM task's built-in prompt, its saved versions and the one in use.
110#[derive(Debug, Clone, Serialize, Deserialize)]
111pub struct Prompts {
112    pub tasks: Vec<PromptTask>,
113    pub version: Option<u64>,
114    pub changed_by: Option<String>,
115    pub changed_at: Option<String>,
116}
117
118#[derive(Debug, Clone, Serialize, Deserialize)]
119pub struct PromptTask {
120    pub task: crate::prompts::Task,
121    pub builtin: String,
122    /// The reply format and its JSON schema, added after whichever instructions run.
123    pub format: String,
124    /// `None`: the built-in prompt.
125    pub active: Option<u32>,
126    /// The active version, when a release changed the built-in prompt since it was written.
127    pub builtin_changed: Option<u32>,
128    /// Style guide only: the built-in guidance of each section.
129    pub sections: Vec<GuideSectionText>,
130    pub versions: Vec<crate::prompts::Version>,
131}
132
133#[derive(Debug, Clone, Serialize, Deserialize)]
134pub struct GuideSectionText {
135    pub title: String,
136    pub guidance: String,
137}
138
139/// `POST /api/v1/prompts`: one change, at the version read.
140#[derive(Debug, Clone, Serialize, Deserialize)]
141pub struct PromptChange {
142    pub version: Option<u64>,
143    #[serde(flatten)]
144    pub action: PromptAction,
145}
146
147#[derive(Debug, Clone, Serialize, Deserialize)]
148#[serde(tag = "action", rename_all = "lowercase")]
149pub enum PromptAction {
150    /// A new version, not in use until activated.
151    Save {
152        task: crate::prompts::Task,
153        text: String,
154        /// Style guide only: section guidance by title.
155        #[serde(default)]
156        sections: std::collections::BTreeMap<String, String>,
157        #[serde(default)]
158        note: Option<String>,
159    },
160    Activate {
161        task: crate::prompts::Task,
162        n: u32,
163    },
164    /// Back to the built-in prompt.
165    Deactivate {
166        task: crate::prompts::Task,
167    },
168    Delete {
169        task: crate::prompts::Task,
170        n: u32,
171    },
172}
173
174/// `POST /api/v1/prompts/try`: run `text` on one sample without saving it.
175#[derive(Debug, Clone, Serialize, Deserialize)]
176pub struct PromptTry {
177    pub task: crate::prompts::Task,
178    pub text: String,
179    #[serde(default)]
180    pub sections: std::collections::BTreeMap<String, String>,
181    /// A symbol id for a summary, an entry point for a walkthrough, a repository for a style
182    /// guide; otherwise the most used one, the furthest-reaching flow or the first repository.
183    #[serde(default)]
184    pub sample: Option<String>,
185    /// Style guide only: the section to write; the first one otherwise.
186    #[serde(default)]
187    pub section: Option<String>,
188}
189
190#[derive(Debug, Clone, Serialize, Deserialize)]
191pub struct PromptTried {
192    pub sample: String,
193    pub output: String,
194    /// What the index holds for the same sample now.
195    pub current: Option<String>,
196}
197
198/// `GET`/`POST /api/v1/logging`: which kinds of lines the engine logs, switched without a restart.
199#[derive(Debug, Clone, Serialize, Deserialize)]
200pub struct Logging {
201    /// One line per request.
202    pub access: bool,
203    /// One line per MCP tool call, with the client's name.
204    pub tool: bool,
205}