BlueGit

ict rusty-teams

Files

rusty-teams / crates / core / src / copilot.rs

copilot.rs

chore: cargo fmt the workspace
metis Daniel Däschle · pushed by metis · 2 weeks ago
a6592765 History
copilot.rs 1.5 KiB Download Raw
1use chatsvc::compose_copilot::{ComposeAction, ComposeRewrite};
2use chatsvc::copilot::CopilotAsk;
3use chrono::Local;
4
5use crate::engine::SyncEngine;
6use crate::error::Result;
7use crate::remote::Remote;
8
9const COPILOT_LOCALE: &str = "en-us";
10const SECONDS_PER_HOUR: i32 = 3600;
11const FALLBACK_TIME_ZONE: &str = "UTC";
12
13impl<R: Remote> SyncEngine<R> {
14 pub async fn ask_copilot(&self, chat_id: &str, prompt: &str) -> Result<String> {
15 let ask = CopilotAsk {
16 user_id: self.my_user_id().await?,
17 tenant_id: self.my_tenant_id(chat_id).await?,
18 chat_id: chat_id.to_owned(),
19 prompt: prompt.to_owned(),
20 locale: COPILOT_LOCALE.to_owned(),
21 utc_offset_hours: Local::now().offset().local_minus_utc() / SECONDS_PER_HOUR,
22 };
23 self.remote.ask_copilot(&ask).await
24 }
25
26 /// Copilot's proposal for the draft as Teams HTML; the draft itself stays untouched.
27 pub async fn rewrite_draft(
28 &self,
29 chat_id: &str,
30 user_html: &str,
31 action: ComposeAction,
32 ) -> Result<String> {
33 let rewrite = ComposeRewrite {
34 tenant_id: self.my_tenant_id(chat_id).await?,
35 thread_id: chat_id.to_owned(),
36 user_html: user_html.to_owned(),
37 action,
38 ui_language: COPILOT_LOCALE.to_owned(),
39 time_zone: iana_time_zone::get_timezone()
40 .unwrap_or_else(|_| FALLBACK_TIME_ZONE.to_owned()),
41 };
42 self.remote.rewrite_draft(&rewrite).await
43 }
44}