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,
/* private fields */
}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 layer has unsaved changes (OR of all dirty_* flags).
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 copy_provider_to_global(&mut self, provider_id: &str) -> Result<()>
pub fn copy_provider_to_global(&mut self, provider_id: &str) -> Result<()>
Copy a provider from the current edit_layer to the global config (merge if already present).
The incoming provider (from edit_layer) is treated as higher priority: its fields override the existing global entry for the same provider, but models that only exist in global are preserved. Only the Global layer is marked dirty — edit_layer’s dirty state is unchanged.
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 provider_ids_for_layer(&self, layer: ConfigLayer) -> Vec<String>
pub fn provider_ids_for_layer(&self, layer: ConfigLayer) -> Vec<String>
Get provider IDs from a specific config layer. Falls back to merged.
Sourcepub fn mark_dirty(&mut self, layer: ConfigLayer)
pub fn mark_dirty(&mut self, layer: ConfigLayer)
Mark a specific config layer as having unsaved changes.
Sourcepub fn mark_clean(&mut self, layer: ConfigLayer)
pub fn mark_clean(&mut self, layer: ConfigLayer)
Mark a specific config layer as clean (saved). Recomputes the overall dirty flag.