Skip to main content

oo_protocol/
lib.rs

1//! Shared protocol types for the oo extension ABI.
2//!
3//! Used by both the host (`oo`) and WASM extensions (`oo-api`).
4//! Compiled with `no_std` when the `std` feature is disabled (for WASM targets).
5
6#![cfg_attr(not(feature = "std"), no_std)]
7
8extern crate alloc;
9
10use alloc::string::String;
11use alloc::vec::Vec;
12use serde::{Deserialize, Serialize};
13
14// ---------------------------------------------------------------------------
15// Envelope
16// ---------------------------------------------------------------------------
17
18/// Top-level message envelope — either a request from WASM→host or a
19/// response from host→WASM.
20#[derive(Serialize, Deserialize)]
21pub enum Message {
22    Request(Request),
23    Response(Response),
24}
25
26/// A request from the WASM extension to the host.
27#[derive(Serialize, Deserialize)]
28pub struct Request {
29    /// Monotonically increasing request ID used to match responses.
30    pub id: u32,
31    pub payload: HostRequest,
32}
33
34/// A response from the host back to the WASM extension.
35#[derive(Serialize, Deserialize)]
36pub struct Response {
37    /// Mirrors the `id` field of the originating `Request`.
38    pub id: u32,
39    pub result: ResponsePayload,
40}
41
42#[derive(Serialize, Deserialize)]
43pub enum ResponsePayload {
44    None,
45    String(String),
46    Error(String),
47}
48
49// ---------------------------------------------------------------------------
50// Host requests
51// ---------------------------------------------------------------------------
52
53#[derive(Serialize, Deserialize)]
54pub enum HostRequest {
55    Operation(Operation),
56    GetConfig { key: String },
57    Log { message: String },
58}
59
60// ---------------------------------------------------------------------------
61// Namespaced operations
62// ---------------------------------------------------------------------------
63
64#[derive(Serialize, Deserialize)]
65pub enum Operation {
66    Window(WindowOp),
67    Workspace(WorkspaceOp),
68    Terminal(TerminalOp),
69    Command(CommandOp),
70}
71
72#[derive(Serialize, Deserialize)]
73pub enum WindowOp {
74    ShowNotification {
75        message: String,
76        level: String,
77    },
78    UpdateStatusBar {
79        text: String,
80        slot: Option<String>,
81    },
82    ShowPicker {
83        title: Option<String>,
84        items: Vec<PickerItem>,
85    },
86}
87
88#[derive(Serialize, Deserialize)]
89pub enum WorkspaceOp {
90    OpenFile { path: String },
91}
92
93#[derive(Serialize, Deserialize)]
94pub enum TerminalOp {
95    Create { command: String },
96}
97
98#[derive(Serialize, Deserialize)]
99pub enum CommandOp {
100    Run { id: String },
101}
102
103#[derive(Serialize, Deserialize, Clone)]
104pub struct PickerItem {
105    pub label: String,
106    pub value: String,
107}