BlueGit

ict rusty-teams

Files

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

copilot.rs

copilot.rs 1.4 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(&self, chat_id: &str, user_html: &str, action: ComposeAction) -> Result<String> {
28 let rewrite = ComposeRewrite {
29 tenant_id: self.my_tenant_id(chat_id).await?,
30 thread_id: chat_id.to_owned(),
31 user_html: user_html.to_owned(),
32 action,
33 ui_language: COPILOT_LOCALE.to_owned(),
34 time_zone: iana_time_zone::get_timezone().unwrap_or_else(|_| FALLBACK_TIME_ZONE.to_owned()),
35 };
36 self.remote.rewrite_draft(&rewrite).await
37 }
38}