Skip to main content

starweaver_model/adapter/
params.rs

1use serde::{Deserialize, Serialize};
2use serde_json::{Map, Value};
3
4use crate::{
5    request::{OutputMode, PreparedInstruction},
6    settings::ThinkingSettings,
7    transport::HttpRequestOptions,
8};
9
10/// Request parameters derived from tools, output schemas, and runtime policy.
11#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
12pub struct ModelRequestParameters {
13    /// Tool definitions in provider-neutral JSON schema form.
14    #[serde(default, skip_serializing_if = "Vec::is_empty")]
15    pub tools: Vec<ToolDefinition>,
16    /// Provider-executed native tool definitions.
17    #[serde(default, skip_serializing_if = "Vec::is_empty")]
18    pub native_tools: Vec<NativeToolDefinition>,
19    /// Optional output schema.
20    #[serde(default, skip_serializing_if = "Option::is_none")]
21    pub output_schema: Option<Value>,
22    /// Selected output mode.
23    #[serde(default, skip_serializing_if = "Option::is_none")]
24    pub output_mode: Option<OutputMode>,
25    /// Prepared instruction fragments attached during request preparation.
26    #[serde(default, skip_serializing_if = "Vec::is_empty")]
27    pub instructions: Vec<PreparedInstruction>,
28    /// Request-level thinking settings selected during request preparation.
29    #[serde(default, skip_serializing_if = "Option::is_none")]
30    pub thinking: Option<ThinkingSettings>,
31    /// Allow text output.
32    #[serde(default, skip_serializing_if = "Option::is_none")]
33    pub allow_text_output: Option<bool>,
34    /// Allow image output.
35    #[serde(default, skip_serializing_if = "Option::is_none")]
36    pub allow_image_output: Option<bool>,
37    /// Request-level HTTP overrides for gateway, audit, and routing integrations.
38    #[serde(default)]
39    pub http: HttpRequestOptions,
40    /// Provider-specific JSON object merged into the top-level request body.
41    #[serde(default, skip_serializing_if = "Map::is_empty")]
42    pub extra_body: Map<String, Value>,
43    /// Request metadata for replay, trace, and audit.
44    #[serde(default, skip_serializing_if = "Map::is_empty")]
45    pub metadata: Map<String, Value>,
46}
47
48/// Provider-neutral tool definition.
49#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
50pub struct ToolDefinition {
51    /// Tool name.
52    pub name: String,
53    /// Tool description.
54    #[serde(default, skip_serializing_if = "Option::is_none")]
55    pub description: Option<String>,
56    /// JSON schema parameters.
57    #[serde(default)]
58    pub parameters: Value,
59    /// Optional JSON schema for a successful tool return value.
60    #[serde(default, skip_serializing_if = "Option::is_none")]
61    pub return_schema: Option<Value>,
62    /// Whether provider-supported schema validation should be strict.
63    #[serde(default, skip_serializing_if = "Option::is_none")]
64    pub strict: Option<bool>,
65    /// Whether the tool should run sequentially with respect to other tool calls.
66    #[serde(default, skip_serializing_if = "Option::is_none")]
67    pub sequential: Option<bool>,
68    /// Runtime metadata for capability hooks, filtering, approval, and provider adaptation.
69    #[serde(default, skip_serializing_if = "Map::is_empty")]
70    pub metadata: Map<String, Value>,
71}
72
73/// Provider-executed native tool definition.
74#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
75pub struct NativeToolDefinition {
76    /// Provider-neutral native tool type, such as `web_search` or `code_interpreter`.
77    pub tool_type: String,
78    /// Provider-specific native tool configuration.
79    #[serde(default, skip_serializing_if = "Map::is_empty")]
80    pub config: Map<String, Value>,
81    /// Runtime metadata for capability hooks, filtering, and audit.
82    #[serde(default, skip_serializing_if = "Map::is_empty")]
83    pub metadata: Map<String, Value>,
84}
85
86impl NativeToolDefinition {
87    /// Create a native tool definition.
88    #[must_use]
89    pub fn new(tool_type: impl Into<String>) -> Self {
90        Self {
91            tool_type: tool_type.into(),
92            config: Map::new(),
93            metadata: Map::new(),
94        }
95    }
96
97    /// Attach provider-specific configuration.
98    #[must_use]
99    pub fn with_config(mut self, config: Map<String, Value>) -> Self {
100        self.config = config;
101        self
102    }
103
104    /// Attach runtime metadata.
105    #[must_use]
106    pub fn with_metadata(mut self, metadata: Map<String, Value>) -> Self {
107        self.metadata = metadata;
108        self
109    }
110}