1use reqwest::Method;
4use serde::Serialize;
5
6use crate::client::{json_body, Request};
7use crate::error::Result;
8use crate::generated::resources::EmbedSessions;
9use crate::Object;
10
11#[derive(Debug, Clone, Default, PartialEq, Serialize)]
17#[serde(rename_all = "camelCase")]
18pub struct ToolEmbedSession {
19 pub tool_id: String,
21 pub parent_origin: String,
23 #[serde(skip_serializing_if = "Option::is_none")]
25 pub preset: Option<Object>,
26 #[serde(skip_serializing_if = "Vec::is_empty")]
28 pub locked_parameters: Vec<String>,
29 #[serde(skip_serializing_if = "Option::is_none")]
31 pub source: Option<Object>,
32 #[serde(skip_serializing_if = "Option::is_none")]
34 pub branding: Option<Object>,
35 #[serde(skip_serializing_if = "Option::is_none")]
37 pub host_reference: Option<String>,
38 #[serde(skip_serializing_if = "Option::is_none")]
40 pub ttl_seconds: Option<u32>,
41}
42
43impl ToolEmbedSession {
44 pub fn new(tool_id: impl Into<String>, parent_origin: impl Into<String>) -> Self {
46 ToolEmbedSession {
47 tool_id: tool_id.into(),
48 parent_origin: parent_origin.into(),
49 ..Self::default()
50 }
51 }
52}
53
54#[derive(Serialize)]
55struct ToolEmbedSessionBody<'a> {
56 surface: &'static str,
57 #[serde(flatten)]
58 session: &'a ToolEmbedSession,
59}
60
61impl EmbedSessions {
62 pub async fn create_tool(&self, session: ToolEmbedSession) -> Result<Object> {
65 let body = ToolEmbedSessionBody {
66 surface: "TOOL",
67 session: &session,
68 };
69 let request =
70 Request::new(Method::POST, ["embed-sessions".to_owned()]).json(json_body(&body, None)?);
71 self.client.json(&self.options, request).await
72 }
73}