pub struct AppState {
pub global_config: Option<OpenCodeConfig>,
pub project_config: Option<OpenCodeConfig>,
pub custom_config: Option<OpenCodeConfig>,
pub merged_config: OpenCodeConfig,
pub paths: ConfigPaths,
pub mode: AppMode,
pub dirty: bool,
pub edit_layer: ConfigLayer,
}Expand description
The application state.
Fields§
§global_config: Option<OpenCodeConfig>Loaded global config.
project_config: Option<OpenCodeConfig>Loaded project config.
custom_config: Option<OpenCodeConfig>Loaded custom config (from –config / OPENCODE_CONFIG).
merged_config: OpenCodeConfigMerged config (global + custom + project, per documented precedence).
paths: ConfigPathsResolved config paths.
mode: AppModeCurrent UI state.
dirty: boolWhether any config has unsaved changes.
edit_layer: ConfigLayerCurrently selected layer for edits.
Implementations§
Source§impl AppState
Actions the user can perform on the app state.
impl AppState
Actions the user can perform on the app state.
Sourcepub fn add_provider(
&mut self,
provider_id: String,
config: ProviderConfig,
layer: ConfigLayer,
) -> Result<()>
pub fn add_provider( &mut self, provider_id: String, config: ProviderConfig, layer: ConfigLayer, ) -> Result<()>
Add a new provider to the config at the specified layer.
Sourcepub fn remove_provider(
&mut self,
provider_id: &str,
layer: ConfigLayer,
) -> Result<()>
pub fn remove_provider( &mut self, provider_id: &str, layer: ConfigLayer, ) -> Result<()>
Remove a provider from the config at the specified layer.
Sourcepub fn edit_provider_field(
&mut self,
provider_id: &str,
field: &str,
value: Value,
layer: ConfigLayer,
) -> Result<()>
pub fn edit_provider_field( &mut self, provider_id: &str, field: &str, value: Value, layer: ConfigLayer, ) -> Result<()>
Edit a provider field in the config at the specified layer.
Sourcepub fn add_model(
&mut self,
provider_id: &str,
model_id: String,
model_config: ModelConfig,
layer: ConfigLayer,
) -> Result<()>
pub fn add_model( &mut self, provider_id: &str, model_id: String, model_config: ModelConfig, layer: ConfigLayer, ) -> Result<()>
Add a model to a provider.
Sourcepub fn remove_model(
&mut self,
provider_id: &str,
model_id: &str,
layer: ConfigLayer,
) -> Result<()>
pub fn remove_model( &mut self, provider_id: &str, model_id: &str, layer: ConfigLayer, ) -> Result<()>
Remove a model from a provider.
Sourcepub fn save(&mut self, layer: ConfigLayer) -> Result<()>
pub fn save(&mut self, layer: ConfigLayer) -> Result<()>
Save the config at the specified layer to disk.
For the Project layer, falls back to ./opencode.json in the current
directory when no project file was discovered, so that new project
configs can be created.
pub fn recompute_merged(&mut self)
Source§impl AppState
impl AppState
Sourcepub fn load_configs(&mut self) -> Result<()>
pub fn load_configs(&mut self) -> Result<()>
Load all config layers and merge them.
Merge order follows the documented OpenCode precedence: global < custom (OPENCODE_CONFIG) < project.
Sourcepub fn get_provider(&self, provider_id: &str) -> Option<&ProviderConfig>
pub fn get_provider(&self, provider_id: &str) -> Option<&ProviderConfig>
Get a provider from the merged config.
Sourcepub fn provider_ids(&self) -> Vec<String>
pub fn provider_ids(&self) -> Vec<String>
Get the list of configured provider IDs.
Sourcepub fn mark_dirty(&mut self)
pub fn mark_dirty(&mut self)
Mark state as dirty (unsaved changes).