(config: &opencode_config::Config)
| 1767 | } |
| 1768 | |
| 1769 | async fn load_plugin_auth_store(config: &opencode_config::Config) -> HashMap<String, AuthInfo> { |
| 1770 | let loader = match PluginLoader::new() { |
| 1771 | Ok(loader) => loader, |
| 1772 | Err(error) => { |
| 1773 | tracing::warn!(%error, "failed to initialize plugin loader in CLI"); |
| 1774 | return HashMap::new(); |
| 1775 | } |
| 1776 | }; |
| 1777 | init_global(loader.hook_system()); |
| 1778 | |
| 1779 | let cwd = match std::env::current_dir() { |
| 1780 | Ok(cwd) => cwd, |
| 1781 | Err(error) => { |
| 1782 | tracing::warn!(%error, "failed to get cwd for plugin loader context"); |
| 1783 | return HashMap::new(); |
| 1784 | } |
| 1785 | }; |
| 1786 | let directory = cwd.to_string_lossy().to_string(); |
| 1787 | let server_url = |
| 1788 | std::env::var("OPENCODE_SERVER_URL").unwrap_or_else(|_| DEFAULT_PLUGIN_SERVER_URL.into()); |
| 1789 | let context = PluginContext { |
| 1790 | worktree: directory.clone(), |
| 1791 | directory, |
| 1792 | server_url, |
| 1793 | }; |
| 1794 | |
| 1795 | if let Err(error) = loader.load_builtins(&context).await { |
| 1796 | tracing::warn!(%error, "failed to load builtin auth plugins in CLI"); |
| 1797 | } |
| 1798 | |
| 1799 | if !config.plugin.is_empty() { |
| 1800 | if let Err(error) = loader.load_all(&config.plugin, &context).await { |
| 1801 | tracing::warn!(%error, "failed to load configured plugins in CLI"); |
| 1802 | } |
| 1803 | } |
| 1804 | |
| 1805 | let mut auth_store = HashMap::new(); |
| 1806 | for (provider_id, bridge) in loader.auth_bridges().await { |
| 1807 | match bridge.load().await { |
| 1808 | Ok(result) => { |
| 1809 | if let Some(api_key) = result.api_key { |
| 1810 | auth_store.insert( |
| 1811 | provider_id.clone(), |
| 1812 | AuthInfo::Api { |
| 1813 | key: api_key.clone(), |
| 1814 | }, |
| 1815 | ); |
| 1816 | if provider_id == "github-copilot" { |
| 1817 | auth_store.insert( |
| 1818 | "github-copilot-enterprise".to_string(), |
| 1819 | AuthInfo::Api { key: api_key }, |
| 1820 | ); |
| 1821 | } |
| 1822 | } |
| 1823 | } |
| 1824 | Err(error) => { |
| 1825 | tracing::warn!(provider = provider_id, %error, "failed to load plugin auth in CLI"); |
| 1826 | } |
no test coverage detected