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