Skip to main content

oino_extension_api/
guest.rs

1//! `guest.wit` records: init input, tool invocations, completion items.
2
3use serde::{Deserialize, Serialize};
4
5use crate::json::RawJson;
6
7/// `init-input`.
8#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct InitInput {
11    /// Manifest JSON (as installed).
12    pub manifest: RawJson,
13    /// Resolved settings for the extension's namespaces (`{namespace: {...}}`).
14    pub settings: RawJson,
15    /// CLI flag values (`{name: value}`).
16    pub flags: RawJson,
17}
18
19impl Default for InitInput {
20    fn default() -> Self {
21        let empty = RawJson::from_json_value(&serde_json::Value::Object(serde_json::Map::new()));
22        Self {
23            manifest: empty.clone(),
24            settings: empty.clone(),
25            flags: empty,
26        }
27    }
28}
29
30/// `tool-invocation`.
31#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
32#[serde(rename_all = "camelCase")]
33pub struct ToolInvocation {
34    /// Tool call id.
35    pub tool_call_id: String,
36    /// Tool name.
37    pub name: String,
38    /// Validated arguments (JSON object).
39    pub args: RawJson,
40    /// Set for nested calls made through `control.execute-tool`.
41    #[serde(default, skip_serializing_if = "Option::is_none")]
42    pub parent_tool_call_id: Option<String>,
43}
44
45/// `completion-item` (command argument completion).
46#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
47#[serde(rename_all = "camelCase")]
48pub struct CompletionItem {
49    /// Inserted text.
50    pub value: String,
51    /// Label (defaults to `value`).
52    #[serde(default, skip_serializing_if = "Option::is_none")]
53    pub label: Option<String>,
54    /// Description.
55    #[serde(default, skip_serializing_if = "Option::is_none")]
56    pub description: Option<String>,
57}