Skip to main content

opencode_sdk/types/
project.rs

1//! Project types for opencode_rs.
2
3use serde::{Deserialize, Serialize};
4
5/// A project in OpenCode.
6#[derive(Debug, Clone, Serialize, Deserialize)]
7#[serde(rename_all = "camelCase")]
8pub struct Project {
9    /// Project identifier.
10    pub id: String,
11    /// Project name.
12    #[serde(default, skip_serializing_if = "Option::is_none")]
13    pub name: Option<String>,
14    /// Project directory path.
15    #[serde(alias = "path", default, skip_serializing_if = "Option::is_none")]
16    pub directory: Option<String>,
17    /// Whether this is the current project.
18    #[serde(default)]
19    pub current: bool,
20    /// Project settings.
21    #[serde(default, skip_serializing_if = "Option::is_none")]
22    pub settings: Option<ProjectSettings>,
23    /// Additional fields from server.
24    #[serde(flatten)]
25    pub extra: serde_json::Value,
26}
27
28/// Project settings.
29#[derive(Debug, Clone, Default, Serialize, Deserialize)]
30#[serde(rename_all = "camelCase")]
31pub struct ProjectSettings {
32    /// Default model for this project.
33    #[serde(default, skip_serializing_if = "Option::is_none")]
34    pub default_model: Option<ModelRef>,
35    /// Default agent for this project.
36    #[serde(default, skip_serializing_if = "Option::is_none")]
37    pub default_agent: Option<String>,
38    /// Additional project-specific settings.
39    #[serde(flatten)]
40    pub extra: serde_json::Value,
41}
42
43// TODO(3): Derive PartialEq on ModelRef, Project, ProjectSettings, UpdateProjectRequest for testing convenience
44/// Reference to a model.
45#[derive(Debug, Clone, Serialize, Deserialize)]
46pub struct ModelRef {
47    /// Provider identifier.
48    #[serde(rename = "providerID")]
49    pub provider_id: String,
50    /// Model identifier.
51    #[serde(rename = "modelID")]
52    pub model_id: String,
53}
54
55/// Request to update a project.
56#[derive(Debug, Clone, Default, Serialize, Deserialize)]
57#[serde(rename_all = "camelCase")]
58pub struct UpdateProjectRequest {
59    /// New project name.
60    #[serde(default, skip_serializing_if = "Option::is_none")]
61    pub name: Option<String>,
62    /// New project settings.
63    #[serde(default, skip_serializing_if = "Option::is_none")]
64    pub settings: Option<ProjectSettings>,
65}