BlueGit

ict rusty-teams

fix(chat): Copilot answers and gets its own island like Teams

- Token through nested app auth for the M365 Copilot app, as Teams does
- Chathub URL carries the host parameters Substrate requires
- Copilot pane is its own island on the right with the Teams layout and logo
- Errors show a short reason instead of the full URL

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-05 · 3 weeks ago

Hash
f239793db797d7594e00875133843ac6bf85a31f
Parent
b703fbc2
11 files changed +210 −83
crates/app-base/src/assets.rs +2 −1
@@ -8,8 +8,9 @@ macro_rules! symbols {
8 8 };
9 9 }
10 10
11 const SYMBOLS: [(&str, &[u8]); 76] = symbols![
11 const SYMBOLS: [(&str, &[u8]); 77] = symbols![
12 12 "bot",
13 "copilot_color",
13 14 "done",
14 15 "table",
15 16 "done_all",
@@ -8,8 +8,9 @@ macro_rules! symbols {
8 };
8 };
9}
9}
10
10
11const SYMBOLS: [(&str, &[u8]); 76] = symbols![
11const SYMBOLS: [(&str, &[u8]); 77] = symbols![
12 "bot",
12 "bot",
13 "copilot_color",
13 "done",
14 "done",
14 "table",
15 "table",
15 "done_all",
16 "done_all",
crates/app/assets/symbols/copilot_color.svg added +21 −0
@@ -0,0 +1,21 @@
1 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
2 <defs>
3 <linearGradient id="a" x1="0" y1="0" x2="1" y2="1">
4 <stop offset="0" stop-color="#2D7FF9"/>
5 <stop offset="0.55" stop-color="#7B5CFA"/>
6 <stop offset="1" stop-color="#E24FA8"/>
7 </linearGradient>
8 <linearGradient id="b" x1="0" y1="1" x2="1" y2="0">
9 <stop offset="0" stop-color="#F7B526"/>
10 <stop offset="0.5" stop-color="#F06C3A"/>
11 <stop offset="1" stop-color="#E24FA8"/>
12 </linearGradient>
13 <linearGradient id="c" x1="0" y1="0" x2="1" y2="1">
14 <stop offset="0" stop-color="#1FC7A8"/>
15 <stop offset="1" stop-color="#2D7FF9"/>
16 </linearGradient>
17 </defs>
18 <path d="M9.4 2.5h5.2c1.3 0 2.4.9 2.7 2.1l2.9 11.2c.4 1.6-.8 3.2-2.5 3.2h-3.4c-1.2 0-2.3-.8-2.6-2L9.4 2.5z" fill="url(#a)"/>
19 <path d="M14.6 21.5H9.4c-1.3 0-2.4-.9-2.7-2.1L3.8 8.2c-.4-1.6.8-3.2 2.5-3.2h3.4c1.2 0 2.3.8 2.6 2l2.3 14.5z" fill="url(#b)" fill-opacity="0.92"/>
20 <path d="M9.4 2.5c1.2 0 2.3.8 2.6 2l.9 3.4c-.6-1.1-1.8-1.9-3.2-1.9H6.3c-.6 0-1.1.2-1.5.5.4-2.3 2.4-4 4.6-4z" fill="url(#c)"/>
21 </svg>
@@ -0,0 +1,21 @@
1<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
2 <defs>
3 <linearGradient id="a" x1="0" y1="0" x2="1" y2="1">
4 <stop offset="0" stop-color="#2D7FF9"/>
5 <stop offset="0.55" stop-color="#7B5CFA"/>
6 <stop offset="1" stop-color="#E24FA8"/>
7 </linearGradient>
8 <linearGradient id="b" x1="0" y1="1" x2="1" y2="0">
9 <stop offset="0" stop-color="#F7B526"/>
10 <stop offset="0.5" stop-color="#F06C3A"/>
11 <stop offset="1" stop-color="#E24FA8"/>
12 </linearGradient>
13 <linearGradient id="c" x1="0" y1="0" x2="1" y2="1">
14 <stop offset="0" stop-color="#1FC7A8"/>
15 <stop offset="1" stop-color="#2D7FF9"/>
16 </linearGradient>
17 </defs>
18 <path d="M9.4 2.5h5.2c1.3 0 2.4.9 2.7 2.1l2.9 11.2c.4 1.6-.8 3.2-2.5 3.2h-3.4c-1.2 0-2.3-.8-2.6-2L9.4 2.5z" fill="url(#a)"/>
19 <path d="M14.6 21.5H9.4c-1.3 0-2.4-.9-2.7-2.1L3.8 8.2c-.4-1.6.8-3.2 2.5-3.2h3.4c1.2 0 2.3.8 2.6 2l2.3 14.5z" fill="url(#b)" fill-opacity="0.92"/>
20 <path d="M9.4 2.5c1.2 0 2.3.8 2.6 2l.9 3.4c-.6-1.1-1.8-1.9-3.2-1.9H6.3c-.6 0-1.1.2-1.5.5.4-2.3 2.4-4 4.6-4z" fill="url(#c)"/>
21</svg>
crates/app/src/views/conversation.rs +15 −6
@@ -3785,6 +3785,7 @@ impl Render for ConversationView {
3785 3785 .h_full()
3786 3786 .rounded(px(10.))
3787 3787 .bg(background)
3788 .overflow_hidden()
3788 3789 .track_focus(&self.focus_handle);
3789 3790 let drafting = self.draft_active;
3790 3791 if self.current.is_none() && !drafting {
@@ -4015,9 +4016,8 @@ impl Render for ConversationView {
4015 4016 } else {
4016 4017 scroller.into_any_element()
4017 4018 };
4018 let channel_details = self
4019 .render_channel_details(cx)
4020 .or_else(|| self.render_copilot(cx));
4019 let channel_details = self.render_channel_details(cx);
4020 let copilot_island = self.render_copilot(cx);
4021 4021 let find_panel = self.find_panel.clone().filter(|_| !drafting);
4022 4022 let find_overlays = self.header_width(window) < FIND_PANEL_WIDTH + FIND_MIN_TIMELINE_WIDTH;
4023 4023 let content = v_flex()
@@ -4064,7 +4064,7 @@ impl Render for ConversationView {
4064 4064 },
4065 4065 )
4066 4066 .child(self.render_drop_overlay(cx));
4067 root.child(
4067 let root = root.child(
4068 4068 h_flex()
4069 4069 .relative()
4070 4070 .flex_1()
@@ -4100,8 +4100,17 @@ impl Render for ConversationView {
4100 4100 } else if !this.on_escape(window, cx) {
4101 4101 cx.propagate();
4102 4102 }
4103 }))
4104 .into_any_element()
4103 }));
4104 match copilot_island {
4105 Some(island) => h_flex()
4106 .size_full()
4107 .min_w_0()
4108 .gap(px(ISLAND_GAP))
4109 .child(root)
4110 .child(island)
4111 .into_any_element(),
4112 None => root.into_any_element(),
4113 }
4105 4114 }
4106 4115 }
4107 4116
@@ -3785,6 +3785,7 @@ impl Render for ConversationView {
3785 .h_full()
3785 .h_full()
3786 .rounded(px(10.))
3786 .rounded(px(10.))
3787 .bg(background)
3787 .bg(background)
3788 .overflow_hidden()
3788 .track_focus(&self.focus_handle);
3789 .track_focus(&self.focus_handle);
3789 let drafting = self.draft_active;
3790 let drafting = self.draft_active;
3790 if self.current.is_none() && !drafting {
3791 if self.current.is_none() && !drafting {
@@ -4015,9 +4016,8 @@ impl Render for ConversationView {
4015 } else {
4016 } else {
4016 scroller.into_any_element()
4017 scroller.into_any_element()
4017 };
4018 };
4018 let channel_details = self
4019 let channel_details = self.render_channel_details(cx);
4019 .render_channel_details(cx)
4020 let copilot_island = self.render_copilot(cx);
4020 .or_else(|| self.render_copilot(cx));
4021 let find_panel = self.find_panel.clone().filter(|_| !drafting);
4021 let find_panel = self.find_panel.clone().filter(|_| !drafting);
4022 let find_overlays = self.header_width(window) < FIND_PANEL_WIDTH + FIND_MIN_TIMELINE_WIDTH;
4022 let find_overlays = self.header_width(window) < FIND_PANEL_WIDTH + FIND_MIN_TIMELINE_WIDTH;
4023 let content = v_flex()
4023 let content = v_flex()
@@ -4064,7 +4064,7 @@ impl Render for ConversationView {
4064 },
4064 },
4065 )
4065 )
4066 .child(self.render_drop_overlay(cx));
4066 .child(self.render_drop_overlay(cx));
4067 root.child(
4067 let root = root.child(
4068 h_flex()
4068 h_flex()
4069 .relative()
4069 .relative()
4070 .flex_1()
4070 .flex_1()
@@ -4100,8 +4100,17 @@ impl Render for ConversationView {
4100 } else if !this.on_escape(window, cx) {
4100 } else if !this.on_escape(window, cx) {
4101 cx.propagate();
4101 cx.propagate();
4102 }
4102 }
4103 }))
4103 }));
4104 .into_any_element()
4104 match copilot_island {
4105 Some(island) => h_flex()
4106 .size_full()
4107 .min_w_0()
4108 .gap(px(ISLAND_GAP))
4109 .child(root)
4110 .child(island)
4111 .into_any_element(),
4112 None => root.into_any_element(),
4113 }
4105 }
4114 }
4106}
4115}
4107
4116
crates/app/src/views/conversation/copilot.rs +119 −60
@@ -2,7 +2,7 @@ use gpui_kit::assets::IconName;
2 2 use gpui_kit::component::button::{Button, ButtonVariants as _};
3 3 use gpui_kit::component::input::{Input, InputEvent, InputState};
4 4 use gpui_kit::component::scroll::ScrollableElement as _;
5 use gpui_kit::component::{Disableable as _, Selectable as _, h_flex, v_flex};
5 use gpui_kit::component::{Selectable as _, h_flex, v_flex};
6 6 use gpui_kit::prelude::FluentBuilder as _;
7 7 use gpui_kit::*;
8 8
@@ -13,21 +13,29 @@ use crate::runtime;
13 13 use crate::theme;
14 14 use crate::views::scroll_edge::with_top_edge;
15 15
16 pub const COPILOT_PANE_TAG: &str = "shell/islands/main/copilot";
17 const COPILOT_SCROLL_DIVIDER: &str = "shell/islands/main/copilot/divider-scroll";
16 pub const COPILOT_PANE_TAG: &str = "shell/islands/copilot";
17 const COPILOT_SCROLL_DIVIDER: &str = "shell/islands/copilot/divider-scroll";
18 18 const TITLE: &str = "Copilot";
19 19 const OPEN_LABEL: &str = "Open Copilot";
20 20 const CLOSE_LABEL: &str = "Close Copilot";
21 21 const PLACEHOLDER: &str = "Message Copilot";
22 22 const WORKING: &str = "Copilot is reading the chat ...";
23 23 const UNAVAILABLE: &str = "Copilot needs a signed-in account.";
24 const INTRO: &str = "Ask Copilot about this chat.";
24 const FAILED: &str = "Copilot could not answer:";
25 const GREETING: &str = "Hi, how can I help?";
26 const LOGO_ASSET: &str = "symbols/copilot_color.svg";
27 const LOGO_BUTTON: f32 = 18.;
28 const LOGO_TITLE: f32 = 20.;
29 const INPUT_MIN_HEIGHT: f32 = 72.;
30 const INPUT_RADIUS: f32 = 12.;
31 const CHIP_RADIUS: f32 = 8.;
25 32 const SUGGESTIONS: [&str; 3] = [
26 33 "Summarize this chat",
27 34 "What are open items?",
28 35 "What decisions were made?",
29 36 ];
30 const PANE_WIDTH: f32 = 360.;
37 const PANE_WIDTH: f32 = 400.;
38 const ISLAND_RADIUS: f32 = 10.;
31 39 const PANE_PADDING: f32 = 16.;
32 40 const HEADER_HEIGHT: f32 = 48.;
33 41 const BUTTON_SIZE: f32 = 32.;
@@ -67,7 +75,7 @@ impl ConversationView {
67 75 let open = self.copilot.open;
68 76 Some(
69 77 Button::new("copilot-toggle")
70 .icon(IconName::Sparkles)
78 .child(copilot_logo(LOGO_BUTTON))
71 79 .ghost()
72 80 .size(px(BUTTON_SIZE))
73 81 .rounded(px(8.))
@@ -164,7 +172,10 @@ impl ConversationView {
164 172 };
165 173 turn.answer = match answer {
166 174 Ok(text) => CopilotAnswer::Ready(text),
167 Err(error) => CopilotAnswer::Failed(error),
175 Err(error) => CopilotAnswer::Failed(format!(
176 "{FAILED} {}",
177 error.split(" (https://").next().unwrap_or_default()
178 )),
168 179 };
169 180 self.copilot.scroll.scroll_to_bottom();
170 181 cx.notify();
@@ -175,56 +186,105 @@ impl ConversationView {
175 186 return None;
176 187 }
177 188 self.copilot_chat_id()?;
178 let mut body = v_flex()
179 .w_full()
180 .px(px(PANE_PADDING))
181 .pb(px(PANE_PADDING))
182 .gap(px(12.));
183 if self.copilot.turns.is_empty() {
184 body = body.child(
185 div()
186 .text_size(px(13.))
187 .text_color(theme::text_muted())
188 .child(INTRO),
189 );
190 }
191 for (index, turn) in self.copilot.turns.iter().enumerate() {
192 body = body.child(prompt_bubble(&turn.prompt)).child(answer_view(index, &turn.answer, cx));
193 }
194 189 let busy = self
195 190 .copilot
196 191 .turns
197 192 .last()
198 193 .is_some_and(|turn| matches!(turn.answer, CopilotAnswer::Waiting));
199 let suggestions = h_flex().flex_wrap().gap(px(6.)).children(
200 SUGGESTIONS.iter().enumerate().map(|(index, prompt)| {
201 Button::new(("copilot-suggestion", index))
202 .label(*prompt)
203 .outline()
204 .rounded(px(BUBBLE_RADIUS))
205 .disabled(busy)
206 .on_click(cx.listener(move |this, _, _, cx| {
207 this.ask_copilot((*prompt).to_owned(), cx)
208 }))
209 }),
210 );
211 let footer = v_flex()
212 .flex_none()
213 .px(px(PANE_PADDING))
214 .py(px(12.))
215 .gap(px(8.))
216 .child(suggestions)
217 .children(self.copilot.input.as_ref().map(|input| Input::new(input)));
194 let input_box = self.copilot.input.as_ref().map(|input| {
195 div()
196 .w_full()
197 .min_h(px(INPUT_MIN_HEIGHT))
198 .px(px(12.))
199 .py(px(10.))
200 .rounded(px(INPUT_RADIUS))
201 .bg(theme::surface_raised())
202 .child(Input::new(input).appearance(false).bordered(false))
203 });
204 let content = if self.copilot.turns.is_empty() {
205 let suggestions = v_flex().w_full().gap(px(8.)).children(
206 SUGGESTIONS.iter().enumerate().map(|(index, prompt)| {
207 div()
208 .id(("copilot-suggestion", index))
209 .w_full()
210 .px(px(12.))
211 .py(px(10.))
212 .rounded(px(CHIP_RADIUS))
213 .bg(theme::surface_raised())
214 .text_size(px(12.))
215 .font_weight(FontWeight::SEMIBOLD)
216 .text_color(theme::text())
217 .cursor_pointer()
218 .hover(|chip| chip.bg(theme::row_hover()))
219 .child(*prompt)
220 .on_click(cx.listener(move |this, _, _, cx| {
221 this.ask_copilot((*prompt).to_owned(), cx)
222 }))
223 }),
224 );
225 v_flex()
226 .flex_1()
227 .min_h_0()
228 .px(px(PANE_PADDING))
229 .pb(px(PANE_PADDING))
230 .justify_center()
231 .gap(px(16.))
232 .child(
233 div()
234 .px(px(4.))
235 .text_size(px(24.))
236 .text_color(theme::text())
237 .child(GREETING),
238 )
239 .children(input_box)
240 .child(suggestions)
241 .into_any_element()
242 } else {
243 let mut body = v_flex()
244 .w_full()
245 .px(px(PANE_PADDING))
246 .pb(px(PANE_PADDING))
247 .gap(px(12.));
248 for (index, turn) in self.copilot.turns.iter().enumerate() {
249 body = body
250 .child(prompt_bubble(&turn.prompt))
251 .child(answer_view(index, &turn.answer, cx));
252 }
253 v_flex()
254 .flex_1()
255 .min_h_0()
256 .child(with_top_edge(
257 div()
258 .id("copilot-body")
259 .flex_1()
260 .min_h_0()
261 .overflow_y_scrollbar()
262 .track_scroll(&self.copilot.scroll)
263 .child(body),
264 &self.copilot.scroll,
265 COPILOT_SCROLL_DIVIDER,
266 ))
267 .child(
268 div()
269 .flex_none()
270 .px(px(PANE_PADDING))
271 .pb(px(PANE_PADDING))
272 .when(busy, |footer| footer.opacity(0.6))
273 .children(input_box),
274 )
275 .into_any_element()
276 };
218 277 Some(
219 278 h_flex()
220 279 .h_full()
221 280 .flex_none()
222 .child(div().w(px(1.)).h_full().flex_none().bg(theme::border()))
223 281 .child(
224 282 v_flex()
225 283 .debug_selector(|| COPILOT_PANE_TAG.into())
226 284 .w(px(PANE_WIDTH))
227 285 .h_full()
286 .rounded(px(ISLAND_RADIUS))
287 .overflow_hidden()
228 288 .bg(theme::surface())
229 289 .child(
230 290 h_flex()
@@ -234,11 +294,17 @@ impl ConversationView {
234 294 .items_center()
235 295 .justify_between()
236 296 .child(
237 div()
238 .text_size(px(15.))
239 .font_weight(FontWeight::SEMIBOLD)
240 .text_color(theme::text())
241 .child(TITLE),
297 h_flex()
298 .gap(px(8.))
299 .items_center()
300 .child(copilot_logo(LOGO_TITLE))
301 .child(
302 div()
303 .text_size(px(15.))
304 .font_weight(FontWeight::SEMIBOLD)
305 .text_color(theme::text())
306 .child(TITLE),
307 ),
242 308 )
243 309 .child(
244 310 Button::new("copilot-close")
@@ -253,24 +319,17 @@ impl ConversationView {
253 319 })),
254 320 ),
255 321 )
256 .child(with_top_edge(
257 div()
258 .id("copilot-body")
259 .flex_1()
260 .min_h_0()
261 .overflow_y_scrollbar()
262 .track_scroll(&self.copilot.scroll)
263 .child(body),
264 &self.copilot.scroll,
265 COPILOT_SCROLL_DIVIDER,
266 ))
267 .child(footer),
322 .child(content),
268 323 )
269 324 .into_any_element(),
270 325 )
271 326 }
272 327 }
273 328
329 fn copilot_logo(size: f32) -> Img {
330 img(LOGO_ASSET).size(px(size)).flex_none()
331 }
332
274 333 fn prompt_bubble(prompt: &str) -> Div {
275 334 h_flex().w_full().justify_end().child(
276 335 div()
@@ -2,7 +2,7 @@ use gpui_kit::assets::IconName;
2use gpui_kit::component::button::{Button, ButtonVariants as _};
2use gpui_kit::component::button::{Button, ButtonVariants as _};
3use gpui_kit::component::input::{Input, InputEvent, InputState};
3use gpui_kit::component::input::{Input, InputEvent, InputState};
4use gpui_kit::component::scroll::ScrollableElement as _;
4use gpui_kit::component::scroll::ScrollableElement as _;
5use gpui_kit::component::{Disableable as _, Selectable as _, h_flex, v_flex};
5use gpui_kit::component::{Selectable as _, h_flex, v_flex};
6use gpui_kit::prelude::FluentBuilder as _;
6use gpui_kit::prelude::FluentBuilder as _;
7use gpui_kit::*;
7use gpui_kit::*;
8
8
@@ -13,21 +13,29 @@ use crate::runtime;
13use crate::theme;
13use crate::theme;
14use crate::views::scroll_edge::with_top_edge;
14use crate::views::scroll_edge::with_top_edge;
15
15
16pub const COPILOT_PANE_TAG: &str = "shell/islands/main/copilot";
16pub const COPILOT_PANE_TAG: &str = "shell/islands/copilot";
17const COPILOT_SCROLL_DIVIDER: &str = "shell/islands/main/copilot/divider-scroll";
17const COPILOT_SCROLL_DIVIDER: &str = "shell/islands/copilot/divider-scroll";
18const TITLE: &str = "Copilot";
18const TITLE: &str = "Copilot";
19const OPEN_LABEL: &str = "Open Copilot";
19const OPEN_LABEL: &str = "Open Copilot";
20const CLOSE_LABEL: &str = "Close Copilot";
20const CLOSE_LABEL: &str = "Close Copilot";
21const PLACEHOLDER: &str = "Message Copilot";
21const PLACEHOLDER: &str = "Message Copilot";
22const WORKING: &str = "Copilot is reading the chat ...";
22const WORKING: &str = "Copilot is reading the chat ...";
23const UNAVAILABLE: &str = "Copilot needs a signed-in account.";
23const UNAVAILABLE: &str = "Copilot needs a signed-in account.";
24const INTRO: &str = "Ask Copilot about this chat.";
24const FAILED: &str = "Copilot could not answer:";
25const GREETING: &str = "Hi, how can I help?";
26const LOGO_ASSET: &str = "symbols/copilot_color.svg";
27const LOGO_BUTTON: f32 = 18.;
28const LOGO_TITLE: f32 = 20.;
29const INPUT_MIN_HEIGHT: f32 = 72.;
30const INPUT_RADIUS: f32 = 12.;
31const CHIP_RADIUS: f32 = 8.;
25const SUGGESTIONS: [&str; 3] = [
32const SUGGESTIONS: [&str; 3] = [
26 "Summarize this chat",
33 "Summarize this chat",
27 "What are open items?",
34 "What are open items?",
28 "What decisions were made?",
35 "What decisions were made?",
29];
36];
30const PANE_WIDTH: f32 = 360.;
37const PANE_WIDTH: f32 = 400.;
38const ISLAND_RADIUS: f32 = 10.;
31const PANE_PADDING: f32 = 16.;
39const PANE_PADDING: f32 = 16.;
32const HEADER_HEIGHT: f32 = 48.;
40const HEADER_HEIGHT: f32 = 48.;
33const BUTTON_SIZE: f32 = 32.;
41const BUTTON_SIZE: f32 = 32.;
@@ -67,7 +75,7 @@ impl ConversationView {
67 let open = self.copilot.open;
75 let open = self.copilot.open;
68 Some(
76 Some(
69 Button::new("copilot-toggle")
77 Button::new("copilot-toggle")
70 .icon(IconName::Sparkles)
78 .child(copilot_logo(LOGO_BUTTON))
71 .ghost()
79 .ghost()
72 .size(px(BUTTON_SIZE))
80 .size(px(BUTTON_SIZE))
73 .rounded(px(8.))
81 .rounded(px(8.))
@@ -164,7 +172,10 @@ impl ConversationView {
164 };
172 };
165 turn.answer = match answer {
173 turn.answer = match answer {
166 Ok(text) => CopilotAnswer::Ready(text),
174 Ok(text) => CopilotAnswer::Ready(text),
167 Err(error) => CopilotAnswer::Failed(error),
175 Err(error) => CopilotAnswer::Failed(format!(
176 "{FAILED} {}",
177 error.split(" (https://").next().unwrap_or_default()
178 )),
168 };
179 };
169 self.copilot.scroll.scroll_to_bottom();
180 self.copilot.scroll.scroll_to_bottom();
170 cx.notify();
181 cx.notify();
@@ -175,56 +186,105 @@ impl ConversationView {
175 return None;
186 return None;
176 }
187 }
177 self.copilot_chat_id()?;
188 self.copilot_chat_id()?;
178 let mut body = v_flex()
179 .w_full()
180 .px(px(PANE_PADDING))
181 .pb(px(PANE_PADDING))
182 .gap(px(12.));
183 if self.copilot.turns.is_empty() {
184 body = body.child(
185 div()
186 .text_size(px(13.))
187 .text_color(theme::text_muted())
188 .child(INTRO),
189 );
190 }
191 for (index, turn) in self.copilot.turns.iter().enumerate() {
192 body = body.child(prompt_bubble(&turn.prompt)).child(answer_view(index, &turn.answer, cx));
193 }
194 let busy = self
189 let busy = self
195 .copilot
190 .copilot
196 .turns
191 .turns
197 .last()
192 .last()
198 .is_some_and(|turn| matches!(turn.answer, CopilotAnswer::Waiting));
193 .is_some_and(|turn| matches!(turn.answer, CopilotAnswer::Waiting));
199 let suggestions = h_flex().flex_wrap().gap(px(6.)).children(
194 let input_box = self.copilot.input.as_ref().map(|input| {
200 SUGGESTIONS.iter().enumerate().map(|(index, prompt)| {
195 div()
201 Button::new(("copilot-suggestion", index))
196 .w_full()
202 .label(*prompt)
197 .min_h(px(INPUT_MIN_HEIGHT))
203 .outline()
198 .px(px(12.))
204 .rounded(px(BUBBLE_RADIUS))
199 .py(px(10.))
205 .disabled(busy)
200 .rounded(px(INPUT_RADIUS))
206 .on_click(cx.listener(move |this, _, _, cx| {
201 .bg(theme::surface_raised())
207 this.ask_copilot((*prompt).to_owned(), cx)
202 .child(Input::new(input).appearance(false).bordered(false))
208 }))
203 });
209 }),
204 let content = if self.copilot.turns.is_empty() {
210 );
205 let suggestions = v_flex().w_full().gap(px(8.)).children(
211 let footer = v_flex()
206 SUGGESTIONS.iter().enumerate().map(|(index, prompt)| {
212 .flex_none()
207 div()
213 .px(px(PANE_PADDING))
208 .id(("copilot-suggestion", index))
214 .py(px(12.))
209 .w_full()
215 .gap(px(8.))
210 .px(px(12.))
216 .child(suggestions)
211 .py(px(10.))
217 .children(self.copilot.input.as_ref().map(|input| Input::new(input)));
212 .rounded(px(CHIP_RADIUS))
213 .bg(theme::surface_raised())
214 .text_size(px(12.))
215 .font_weight(FontWeight::SEMIBOLD)
216 .text_color(theme::text())
217 .cursor_pointer()
218 .hover(|chip| chip.bg(theme::row_hover()))
219 .child(*prompt)
220 .on_click(cx.listener(move |this, _, _, cx| {
221 this.ask_copilot((*prompt).to_owned(), cx)
222 }))
223 }),
224 );
225 v_flex()
226 .flex_1()
227 .min_h_0()
228 .px(px(PANE_PADDING))
229 .pb(px(PANE_PADDING))
230 .justify_center()
231 .gap(px(16.))
232 .child(
233 div()
234 .px(px(4.))
235 .text_size(px(24.))
236 .text_color(theme::text())
237 .child(GREETING),
238 )
239 .children(input_box)
240 .child(suggestions)
241 .into_any_element()
242 } else {
243 let mut body = v_flex()
244 .w_full()
245 .px(px(PANE_PADDING))
246 .pb(px(PANE_PADDING))
247 .gap(px(12.));
248 for (index, turn) in self.copilot.turns.iter().enumerate() {
249 body = body
250 .child(prompt_bubble(&turn.prompt))
251 .child(answer_view(index, &turn.answer, cx));
252 }
253 v_flex()
254 .flex_1()
255 .min_h_0()
256 .child(with_top_edge(
257 div()
258 .id("copilot-body")
259 .flex_1()
260 .min_h_0()
261 .overflow_y_scrollbar()
262 .track_scroll(&self.copilot.scroll)
263 .child(body),
264 &self.copilot.scroll,
265 COPILOT_SCROLL_DIVIDER,
266 ))
267 .child(
268 div()
269 .flex_none()
270 .px(px(PANE_PADDING))
271 .pb(px(PANE_PADDING))
272 .when(busy, |footer| footer.opacity(0.6))
273 .children(input_box),
274 )
275 .into_any_element()
276 };
218 Some(
277 Some(
219 h_flex()
278 h_flex()
220 .h_full()
279 .h_full()
221 .flex_none()
280 .flex_none()
222 .child(div().w(px(1.)).h_full().flex_none().bg(theme::border()))
223 .child(
281 .child(
224 v_flex()
282 v_flex()
225 .debug_selector(|| COPILOT_PANE_TAG.into())
283 .debug_selector(|| COPILOT_PANE_TAG.into())
226 .w(px(PANE_WIDTH))
284 .w(px(PANE_WIDTH))
227 .h_full()
285 .h_full()
286 .rounded(px(ISLAND_RADIUS))
287 .overflow_hidden()
228 .bg(theme::surface())
288 .bg(theme::surface())
229 .child(
289 .child(
230 h_flex()
290 h_flex()
@@ -234,11 +294,17 @@ impl ConversationView {
234 .items_center()
294 .items_center()
235 .justify_between()
295 .justify_between()
236 .child(
296 .child(
237 div()
297 h_flex()
238 .text_size(px(15.))
298 .gap(px(8.))
239 .font_weight(FontWeight::SEMIBOLD)
299 .items_center()
240 .text_color(theme::text())
300 .child(copilot_logo(LOGO_TITLE))
241 .child(TITLE),
301 .child(
302 div()
303 .text_size(px(15.))
304 .font_weight(FontWeight::SEMIBOLD)
305 .text_color(theme::text())
306 .child(TITLE),
307 ),
242 )
308 )
243 .child(
309 .child(
244 Button::new("copilot-close")
310 Button::new("copilot-close")
@@ -253,24 +319,17 @@ impl ConversationView {
253 })),
319 })),
254 ),
320 ),
255 )
321 )
256 .child(with_top_edge(
322 .child(content),
257 div()
258 .id("copilot-body")
259 .flex_1()
260 .min_h_0()
261 .overflow_y_scrollbar()
262 .track_scroll(&self.copilot.scroll)
263 .child(body),
264 &self.copilot.scroll,
265 COPILOT_SCROLL_DIVIDER,
266 ))
267 .child(footer),
268 )
323 )
269 .into_any_element(),
324 .into_any_element(),
270 )
325 )
271 }
326 }
272}
327}
273
328
329fn copilot_logo(size: f32) -> Img {
330 img(LOGO_ASSET).size(px(size)).flex_none()
331}
332
274fn prompt_bubble(prompt: &str) -> Div {
333fn prompt_bubble(prompt: &str) -> Div {
275 h_flex().w_full().justify_end().child(
334 h_flex().w_full().justify_end().child(
276 div()
335 div()
crates/app/src/views/shell.rs +1 −9
@@ -846,15 +846,7 @@ impl AppShell {
846 846 (None, None) => self
847 847 .conversation
848 848 .clone()
849 .cached(
850 StyleRefinement::default()
851 .flex_1()
852 .min_w_0()
853 .h_full()
854 .rounded(px(10.))
855 .bg(theme::surface())
856 .overflow_hidden(),
857 )
849 .cached(StyleRefinement::default().flex_1().min_w_0().h_full())
858 850 .into_any_element(),
859 851 })
860 852 }
@@ -846,15 +846,7 @@ impl AppShell {
846 (None, None) => self
846 (None, None) => self
847 .conversation
847 .conversation
848 .clone()
848 .clone()
849 .cached(
849 .cached(StyleRefinement::default().flex_1().min_w_0().h_full())
850 StyleRefinement::default()
851 .flex_1()
852 .min_w_0()
853 .h_full()
854 .rounded(px(10.))
855 .bg(theme::surface())
856 .overflow_hidden(),
857 )
858 .into_any_element(),
850 .into_any_element(),
859 })
851 })
860 }
852 }
crates/chatsvc/src/copilot.rs +12 −3
@@ -1,5 +1,5 @@
1 1 use serde_json::{Value, json};
2 use session::{Request, Scope, Session, SignalrExchange};
2 use session::{NestedApp, Request, Scope, Session, SignalrExchange};
3 3 use uuid::Uuid;
4 4
5 5 use crate::error::{Error, Result};
@@ -7,6 +7,12 @@ use crate::error::{Error, Result};
7 7 const CHATHUB_URL: &str = "https://substrate.office.com/m365Copilot/Chathub";
8 8 const SYDNEY_RESOURCE: &str = "https://substrate.office.com/sydney";
9 9 const SYDNEY_SCOPE: &str = "sydney.readwrite";
10 const COPILOT_APP: NestedApp = NestedApp {
11 client_id: "c0ab8ce9-e9a0-42e7-b064-33d422df41f1",
12 redirect_uri: "brk-multihub://m365copilotapp.svc.cloud.microsoft",
13 broker_redirect_uri: "https://teams.cloud.microsoft/v2/authv2",
14 };
15 const HOST_PARAMETERS: &str = "source=%22officeweb%22&product=Office&agentHost=Bizchat.FullScreen&licenseType=Premium&isEdu=false&agent=work&scenario=officeweb";
10 16 const HANDSHAKE: &str = r#"{"protocol":"json","version":1}"#;
11 17 const INVOCATION: u8 = 4;
12 18 const COMPLETION: u8 = 2;
@@ -52,7 +58,10 @@ impl Copilot {
52 58 );
53 59 let response = self
54 60 .session
55 .send(request, &Scope::new(SYDNEY_RESOURCE, SYDNEY_SCOPE))
61 .send(
62 request,
63 &Scope::new(SYDNEY_RESOURCE, SYDNEY_SCOPE).for_nested_app(COPILOT_APP),
64 )
56 65 .await?;
57 66 answer_of(&response.body)
58 67 }
@@ -61,7 +70,7 @@ impl Copilot {
61 70 fn chathub_url(ask: &CopilotAsk, session_id: &str, request_id: &str) -> String {
62 71 let route = format!("{}@{}", ask.user_id, ask.tenant_id);
63 72 format!(
64 "{CHATHUB_URL}/{route}?chatsessionid={request_id}&XRoutingParameterSessionKey={user}&clientrequestid={request_id}&X-SessionId={session_id}&ConversationId={conversation}",
73 "{CHATHUB_URL}/{route}?chatsessionid={request_id}&XRoutingParameterSessionKey={user}&clientrequestid={request_id}&X-SessionId={session_id}&ConversationId={conversation}&{HOST_PARAMETERS}",
65 74 user = ask.user_id,
66 75 conversation = Uuid::new_v4(),
67 76 )
@@ -1,5 +1,5 @@
1use serde_json::{Value, json};
1use serde_json::{Value, json};
2use session::{Request, Scope, Session, SignalrExchange};
2use session::{NestedApp, Request, Scope, Session, SignalrExchange};
3use uuid::Uuid;
3use uuid::Uuid;
4
4
5use crate::error::{Error, Result};
5use crate::error::{Error, Result};
@@ -7,6 +7,12 @@ use crate::error::{Error, Result};
7const CHATHUB_URL: &str = "https://substrate.office.com/m365Copilot/Chathub";
7const CHATHUB_URL: &str = "https://substrate.office.com/m365Copilot/Chathub";
8const SYDNEY_RESOURCE: &str = "https://substrate.office.com/sydney";
8const SYDNEY_RESOURCE: &str = "https://substrate.office.com/sydney";
9const SYDNEY_SCOPE: &str = "sydney.readwrite";
9const SYDNEY_SCOPE: &str = "sydney.readwrite";
10const COPILOT_APP: NestedApp = NestedApp {
11 client_id: "c0ab8ce9-e9a0-42e7-b064-33d422df41f1",
12 redirect_uri: "brk-multihub://m365copilotapp.svc.cloud.microsoft",
13 broker_redirect_uri: "https://teams.cloud.microsoft/v2/authv2",
14};
15const HOST_PARAMETERS: &str = "source=%22officeweb%22&product=Office&agentHost=Bizchat.FullScreen&licenseType=Premium&isEdu=false&agent=work&scenario=officeweb";
10const HANDSHAKE: &str = r#"{"protocol":"json","version":1}"#;
16const HANDSHAKE: &str = r#"{"protocol":"json","version":1}"#;
11const INVOCATION: u8 = 4;
17const INVOCATION: u8 = 4;
12const COMPLETION: u8 = 2;
18const COMPLETION: u8 = 2;
@@ -52,7 +58,10 @@ impl Copilot {
52 );
58 );
53 let response = self
59 let response = self
54 .session
60 .session
55 .send(request, &Scope::new(SYDNEY_RESOURCE, SYDNEY_SCOPE))
61 .send(
62 request,
63 &Scope::new(SYDNEY_RESOURCE, SYDNEY_SCOPE).for_nested_app(COPILOT_APP),
64 )
56 .await?;
65 .await?;
57 answer_of(&response.body)
66 answer_of(&response.body)
58 }
67 }
@@ -61,7 +70,7 @@ impl Copilot {
61fn chathub_url(ask: &CopilotAsk, session_id: &str, request_id: &str) -> String {
70fn chathub_url(ask: &CopilotAsk, session_id: &str, request_id: &str) -> String {
62 let route = format!("{}@{}", ask.user_id, ask.tenant_id);
71 let route = format!("{}@{}", ask.user_id, ask.tenant_id);
63 format!(
72 format!(
64 "{CHATHUB_URL}/{route}?chatsessionid={request_id}&XRoutingParameterSessionKey={user}&clientrequestid={request_id}&X-SessionId={session_id}&ConversationId={conversation}",
73 "{CHATHUB_URL}/{route}?chatsessionid={request_id}&XRoutingParameterSessionKey={user}&clientrequestid={request_id}&X-SessionId={session_id}&ConversationId={conversation}&{HOST_PARAMETERS}",
65 user = ask.user_id,
74 user = ask.user_id,
66 conversation = Uuid::new_v4(),
75 conversation = Uuid::new_v4(),
67 )
76 )
crates/session/assets/fetch.js +11 −3
@@ -1,4 +1,4 @@
1 (async ({requests, resource, scope, marginMs, concurrency, maxBytes, forceRefresh}) => {
1 (async ({requests, resource, scope, marginMs, concurrency, maxBytes, forceRefresh, nestedApp}) => {
2 2 const fresh = (expires) => expires > Date.now() + marginMs;
3 3 const normalize = (value) => value.toLowerCase().replace(/\/\/+(?=[^/]*$)/, '/');
4 4 const covers = (value, name) => value === name || value === name + '.all';
@@ -62,15 +62,17 @@
62 62 const underResource = (name) => normalize(name).startsWith(base.toLowerCase() + '/');
63 63 const grants = (scopes) => scopes.some(s => (scope === '.default' ? underResource(s) : covers(normalize(s), wanted))
64 64 || (base === 'https://graph.microsoft.com' && covers(s.toLowerCase(), short)));
65 const cacheKey = nestedApp ? base + '|' + nestedApp.clientId : base;
65 66 let token = null, expiresOn = 0;
66 67 for (const entry of forceRefresh ? [] : entries) {
67 68 if (entry.credentialType !== 'AccessToken' || (entry.tokenType && entry.tokenType !== 'Bearer')) continue;
69 if (nestedApp && entry.clientId !== nestedApp.clientId) continue;
68 70 if (!ownAccount(entry) || (entry.realm && entry.realm !== homeTenant(entry))) continue;
69 71 const expires = Number(entry.expiresOn) * 1000;
70 72 if (!grants((entry.target || '').split(' ')) || !fresh(expires) || expires <= expiresOn) continue;
71 73 token = entry.secret; expiresOn = expires;
72 74 }
73 const cached = cache[base];
75 const cached = cache[cacheKey];
74 76 if (!token && !forceRefresh && cached && fresh(cached.expires)) {
75 77 if (grants(cached.scopes)) token = cached.token;
76 78 else return {token: null, refreshError: `the app is not granted ${scope}`};
@@ -85,13 +87,19 @@
85 87 client_id: refreshToken.clientId, grant_type: 'refresh_token', refresh_token: refreshToken.secret,
86 88 scope: base + '/.default openid profile offline_access',
87 89 });
90 if (nestedApp) {
91 form.set('client_id', nestedApp.clientId);
92 form.set('brk_client_id', refreshToken.clientId);
93 form.set('redirect_uri', nestedApp.redirectUri);
94 form.set('brk_redirect_uri', nestedApp.brokerRedirectUri);
95 }
88 96 try {
89 97 const response = await fetch(`https://login.microsoftonline.com/${homeTenant(refreshToken) || 'organizations'}/oauth2/v2.0/token`,
90 98 {method: 'POST', body: form});
91 99 const answer = await response.json();
92 100 if (!response.ok) { refreshError = answer.error || `HTTP ${response.status}`; continue; }
93 101 const scopes = (answer.scope || '').split(' ');
94 cache[base] = {token: answer.access_token, scopes, expires: Date.now() + answer.expires_in * 1000};
102 cache[cacheKey] = {token: answer.access_token, scopes, expires: Date.now() + answer.expires_in * 1000};
95 103 if (grants(scopes)) { token = answer.access_token; break; }
96 104 refreshError = `the app is not granted ${scope}`;
97 105 } catch (error) {
@@ -1,4 +1,4 @@
1(async ({requests, resource, scope, marginMs, concurrency, maxBytes, forceRefresh}) => {
1(async ({requests, resource, scope, marginMs, concurrency, maxBytes, forceRefresh, nestedApp}) => {
2 const fresh = (expires) => expires > Date.now() + marginMs;
2 const fresh = (expires) => expires > Date.now() + marginMs;
3 const normalize = (value) => value.toLowerCase().replace(/\/\/+(?=[^/]*$)/, '/');
3 const normalize = (value) => value.toLowerCase().replace(/\/\/+(?=[^/]*$)/, '/');
4 const covers = (value, name) => value === name || value === name + '.all';
4 const covers = (value, name) => value === name || value === name + '.all';
@@ -62,15 +62,17 @@
62 const underResource = (name) => normalize(name).startsWith(base.toLowerCase() + '/');
62 const underResource = (name) => normalize(name).startsWith(base.toLowerCase() + '/');
63 const grants = (scopes) => scopes.some(s => (scope === '.default' ? underResource(s) : covers(normalize(s), wanted))
63 const grants = (scopes) => scopes.some(s => (scope === '.default' ? underResource(s) : covers(normalize(s), wanted))
64 || (base === 'https://graph.microsoft.com' && covers(s.toLowerCase(), short)));
64 || (base === 'https://graph.microsoft.com' && covers(s.toLowerCase(), short)));
65 const cacheKey = nestedApp ? base + '|' + nestedApp.clientId : base;
65 let token = null, expiresOn = 0;
66 let token = null, expiresOn = 0;
66 for (const entry of forceRefresh ? [] : entries) {
67 for (const entry of forceRefresh ? [] : entries) {
67 if (entry.credentialType !== 'AccessToken' || (entry.tokenType && entry.tokenType !== 'Bearer')) continue;
68 if (entry.credentialType !== 'AccessToken' || (entry.tokenType && entry.tokenType !== 'Bearer')) continue;
69 if (nestedApp && entry.clientId !== nestedApp.clientId) continue;
68 if (!ownAccount(entry) || (entry.realm && entry.realm !== homeTenant(entry))) continue;
70 if (!ownAccount(entry) || (entry.realm && entry.realm !== homeTenant(entry))) continue;
69 const expires = Number(entry.expiresOn) * 1000;
71 const expires = Number(entry.expiresOn) * 1000;
70 if (!grants((entry.target || '').split(' ')) || !fresh(expires) || expires <= expiresOn) continue;
72 if (!grants((entry.target || '').split(' ')) || !fresh(expires) || expires <= expiresOn) continue;
71 token = entry.secret; expiresOn = expires;
73 token = entry.secret; expiresOn = expires;
72 }
74 }
73 const cached = cache[base];
75 const cached = cache[cacheKey];
74 if (!token && !forceRefresh && cached && fresh(cached.expires)) {
76 if (!token && !forceRefresh && cached && fresh(cached.expires)) {
75 if (grants(cached.scopes)) token = cached.token;
77 if (grants(cached.scopes)) token = cached.token;
76 else return {token: null, refreshError: `the app is not granted ${scope}`};
78 else return {token: null, refreshError: `the app is not granted ${scope}`};
@@ -85,13 +87,19 @@
85 client_id: refreshToken.clientId, grant_type: 'refresh_token', refresh_token: refreshToken.secret,
87 client_id: refreshToken.clientId, grant_type: 'refresh_token', refresh_token: refreshToken.secret,
86 scope: base + '/.default openid profile offline_access',
88 scope: base + '/.default openid profile offline_access',
87 });
89 });
90 if (nestedApp) {
91 form.set('client_id', nestedApp.clientId);
92 form.set('brk_client_id', refreshToken.clientId);
93 form.set('redirect_uri', nestedApp.redirectUri);
94 form.set('brk_redirect_uri', nestedApp.brokerRedirectUri);
95 }
88 try {
96 try {
89 const response = await fetch(`https://login.microsoftonline.com/${homeTenant(refreshToken) || 'organizations'}/oauth2/v2.0/token`,
97 const response = await fetch(`https://login.microsoftonline.com/${homeTenant(refreshToken) || 'organizations'}/oauth2/v2.0/token`,
90 {method: 'POST', body: form});
98 {method: 'POST', body: form});
91 const answer = await response.json();
99 const answer = await response.json();
92 if (!response.ok) { refreshError = answer.error || `HTTP ${response.status}`; continue; }
100 if (!response.ok) { refreshError = answer.error || `HTTP ${response.status}`; continue; }
93 const scopes = (answer.scope || '').split(' ');
101 const scopes = (answer.scope || '').split(' ');
94 cache[base] = {token: answer.access_token, scopes, expires: Date.now() + answer.expires_in * 1000};
102 cache[cacheKey] = {token: answer.access_token, scopes, expires: Date.now() + answer.expires_in * 1000};
95 if (grants(scopes)) { token = answer.access_token; break; }
103 if (grants(scopes)) { token = answer.access_token; break; }
96 refreshError = `the app is not granted ${scope}`;
104 refreshError = `the app is not granted ${scope}`;
97 } catch (error) {
105 } catch (error) {
crates/session/src/lib.rs +1 −1
@@ -13,6 +13,6 @@ pub use error::{Error, Result};
13 13 pub use events::{TabChannel, TabCommand, TabControl, TabEvent, TabEvents};
14 14 pub use page_script::token_acquirer_script;
15 15 pub use request::{ApiResponse, BodyToken, Method, Request, SignalrExchange};
16 pub use scope::{GRAPH, IC3, OUTLOOK, PRESENCE, SPACES, Scope};
16 pub use scope::{GRAPH, IC3, NestedApp, OUTLOOK, PRESENCE, SPACES, Scope};
17 17 pub use session::{DEFAULT_ENDPOINT, Session, SessionConfig, TabHold};
18 18 pub use transport::{BoxFuture, CdpTransport, Diagnosis, OpenedTab, Transport};
@@ -13,6 +13,6 @@ pub use error::{Error, Result};
13pub use events::{TabChannel, TabCommand, TabControl, TabEvent, TabEvents};
13pub use events::{TabChannel, TabCommand, TabControl, TabEvent, TabEvents};
14pub use page_script::token_acquirer_script;
14pub use page_script::token_acquirer_script;
15pub use request::{ApiResponse, BodyToken, Method, Request, SignalrExchange};
15pub use request::{ApiResponse, BodyToken, Method, Request, SignalrExchange};
16pub use scope::{GRAPH, IC3, OUTLOOK, PRESENCE, SPACES, Scope};
16pub use scope::{GRAPH, IC3, NestedApp, OUTLOOK, PRESENCE, SPACES, Scope};
17pub use session::{DEFAULT_ENDPOINT, Session, SessionConfig, TabHold};
17pub use session::{DEFAULT_ENDPOINT, Session, SessionConfig, TabHold};
18pub use transport::{BoxFuture, CdpTransport, Diagnosis, OpenedTab, Transport};
18pub use transport::{BoxFuture, CdpTransport, Diagnosis, OpenedTab, Transport};
crates/session/src/page_script.rs +1 −0
@@ -50,6 +50,7 @@ impl Session {
50 50 "requests": [],
51 51 "resource": scope.resource,
52 52 "scope": scope.name,
53 "nestedApp": scope.nested_app_json(),
53 54 "marginMs": self.config.refresh_margin.as_millis() as u64,
54 55 "concurrency": 1,
55 56 "maxBytes": 1,
@@ -50,6 +50,7 @@ impl Session {
50 "requests": [],
50 "requests": [],
51 "resource": scope.resource,
51 "resource": scope.resource,
52 "scope": scope.name,
52 "scope": scope.name,
53 "nestedApp": scope.nested_app_json(),
53 "marginMs": self.config.refresh_margin.as_millis() as u64,
54 "marginMs": self.config.refresh_margin.as_millis() as u64,
54 "concurrency": 1,
55 "concurrency": 1,
55 "maxBytes": 1,
56 "maxBytes": 1,
crates/session/src/scope.rs +26 −0
@@ -12,6 +12,15 @@ pub const SPACES: &str = "https://api.spaces.skype.com";
12 12 pub struct Scope {
13 13 pub resource: Cow<'static, str>,
14 14 pub name: Cow<'static, str>,
15 pub nested_app: Option<NestedApp>,
16 }
17
18 /// An app hosted inside the tab that gets its tokens through the tab's own sign-in (nested app auth).
19 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
20 pub struct NestedApp {
21 pub client_id: &'static str,
22 pub redirect_uri: &'static str,
23 pub broker_redirect_uri: &'static str,
15 24 }
16 25
17 26 impl Scope {
@@ -19,6 +28,23 @@ impl Scope {
19 28 Scope {
20 29 resource: resource.into(),
21 30 name: name.into(),
31 nested_app: None,
32 }
33 }
34
35 pub fn for_nested_app(mut self, app: NestedApp) -> Self {
36 self.nested_app = Some(app);
37 self
38 }
39
40 pub(crate) fn nested_app_json(&self) -> serde_json::Value {
41 match self.nested_app {
42 Some(app) => serde_json::json!({
43 "clientId": app.client_id,
44 "redirectUri": app.redirect_uri,
45 "brokerRedirectUri": app.broker_redirect_uri,
46 }),
47 None => serde_json::Value::Null,
22 48 }
23 49 }
24 50
@@ -12,6 +12,15 @@ pub const SPACES: &str = "https://api.spaces.skype.com";
12pub struct Scope {
12pub struct Scope {
13 pub resource: Cow<'static, str>,
13 pub resource: Cow<'static, str>,
14 pub name: Cow<'static, str>,
14 pub name: Cow<'static, str>,
15 pub nested_app: Option<NestedApp>,
16}
17
18/// An app hosted inside the tab that gets its tokens through the tab's own sign-in (nested app auth).
19#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20pub struct NestedApp {
21 pub client_id: &'static str,
22 pub redirect_uri: &'static str,
23 pub broker_redirect_uri: &'static str,
15}
24}
16
25
17impl Scope {
26impl Scope {
@@ -19,6 +28,23 @@ impl Scope {
19 Scope {
28 Scope {
20 resource: resource.into(),
29 resource: resource.into(),
21 name: name.into(),
30 name: name.into(),
31 nested_app: None,
32 }
33 }
34
35 pub fn for_nested_app(mut self, app: NestedApp) -> Self {
36 self.nested_app = Some(app);
37 self
38 }
39
40 pub(crate) fn nested_app_json(&self) -> serde_json::Value {
41 match self.nested_app {
42 Some(app) => serde_json::json!({
43 "clientId": app.client_id,
44 "redirectUri": app.redirect_uri,
45 "brokerRedirectUri": app.broker_redirect_uri,
46 }),
47 None => serde_json::Value::Null,
22 }
48 }
23 }
49 }
24
50
crates/session/src/session.rs +1 −0
@@ -238,6 +238,7 @@ impl Session {
238 238 "requests": wire,
239 239 "resource": scope.resource,
240 240 "scope": scope.name,
241 "nestedApp": scope.nested_app_json(),
241 242 "marginMs": self.config.refresh_margin.as_millis() as u64,
242 243 "concurrency": DEFAULT_CONCURRENCY,
243 244 "maxBytes": MAX_DOWNLOAD_BYTES,
@@ -238,6 +238,7 @@ impl Session {
238 "requests": wire,
238 "requests": wire,
239 "resource": scope.resource,
239 "resource": scope.resource,
240 "scope": scope.name,
240 "scope": scope.name,
241 "nestedApp": scope.nested_app_json(),
241 "marginMs": self.config.refresh_margin.as_millis() as u64,
242 "marginMs": self.config.refresh_margin.as_millis() as u64,
242 "concurrency": DEFAULT_CONCURRENCY,
243 "concurrency": DEFAULT_CONCURRENCY,
243 "maxBytes": MAX_DOWNLOAD_BYTES,
244 "maxBytes": MAX_DOWNLOAD_BYTES,