rig_core/providers/copilot/
extension.rs1use serde::{Deserialize, Serialize};
15use serde_json::Value;
16
17use crate::completion::provider_options::reply_field;
18use crate::completion::{ExtensionOptions, ProviderExtension, ReplyExtras};
19use crate::message::Api;
20
21#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
23pub struct CopilotExt;
24
25impl ProviderExtension for CopilotExt {
26 const PROVIDER: &'static str = super::PROVIDER_NAME;
27 type Options = CopilotOptions;
28 type Extras = CopilotExtras;
29}
30
31#[non_exhaustive]
33#[derive(Clone, Debug, Default, PartialEq, Serialize)]
34pub struct CopilotOptions {}
35
36impl CopilotOptions {
37 pub fn new() -> Self {
39 Self::default()
40 }
41}
42
43impl ExtensionOptions for CopilotOptions {
44 type Ext = CopilotExt;
45}
46
47#[non_exhaustive]
49#[derive(Clone, Debug, Default, PartialEq)]
50pub struct CopilotExtras {
51 pub copilot_usage: Option<CopilotUsage>,
53 pub prompt_filter_results: Option<Vec<Value>>,
55}
56
57#[non_exhaustive]
59#[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize)]
60pub struct CopilotUsage {
61 #[serde(default)]
63 pub token_details: Option<Vec<TokenDetail>>,
64 #[serde(default)]
66 pub total_nano_aiu: Option<u64>,
67}
68
69#[non_exhaustive]
71#[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize)]
72pub struct TokenDetail {
73 #[serde(default)]
75 pub token_type: Option<String>,
76 #[serde(default)]
78 pub token_count: Option<u64>,
79 #[serde(default)]
81 pub batch_size: Option<u64>,
82 #[serde(default)]
84 pub cost_per_batch: Option<u64>,
85}
86
87impl ReplyExtras for CopilotExtras {
88 fn from_reply(_api: &Api, raw: &Value) -> Result<Self, serde_json::Error> {
89 Ok(Self {
90 copilot_usage: reply_field(raw, "/copilot_usage")?,
91 prompt_filter_results: reply_field(raw, "/prompt_filter_results")?,
92 })
93 }
94}
95
96#[cfg(test)]
97mod tests;