opencode-studio-server 1.16.1 → 1.16.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +105 -15
  2. package/package.json +1 -1
  3. package/server.log +2 -0
package/index.js CHANGED
@@ -184,9 +184,13 @@ function processLogLine(line) {
184
184
  const modelMatch = line.match(/modelID=([^\s]+)/);
185
185
 
186
186
  if (providerMatch) {
187
- const provider = providerMatch[1];
187
+ let provider = providerMatch[1];
188
188
  const model = modelMatch ? modelMatch[1] : 'unknown';
189
189
 
190
+ // Normalize providers
191
+ if (provider === 'codex') provider = 'openai';
192
+ if (provider === 'claude') provider = 'anthropic';
193
+
190
194
  // Map provider to pool namespace
191
195
  let namespace = provider;
192
196
  if (provider === 'google') {
@@ -1611,15 +1615,37 @@ app.delete('/api/auth/profiles/:provider/all', (req, res) => {
1611
1615
 
1612
1616
  const authCfg = loadAuthConfig() || {};
1613
1617
  if (authCfg[provider]) {
1614
- delete authCfg[provider];
1615
- if (provider === 'google') {
1616
- const key = 'google.antigravity';
1617
- delete authCfg.google;
1618
- delete authCfg[key];
1618
+ const paths = getPaths();
1619
+ const allPaths = paths.candidates;
1620
+ if (paths.current && !allPaths.includes(paths.current)) {
1621
+ allPaths.push(paths.current);
1619
1622
  }
1620
- const cp = getConfigPath();
1621
- const ap = path.join(path.dirname(cp), 'auth.json');
1622
- atomicWriteFileSync(ap, JSON.stringify(authCfg, null, 2));
1623
+
1624
+ allPaths.forEach(p => {
1625
+ const ap = path.join(path.dirname(p), 'auth.json');
1626
+ if (fs.existsSync(ap)) {
1627
+ try {
1628
+ const cfg = JSON.parse(fs.readFileSync(ap, 'utf8'));
1629
+ let modified = false;
1630
+
1631
+ if (provider === 'google') {
1632
+ if (cfg.google) { delete cfg.google; modified = true; }
1633
+ if (cfg['google.antigravity']) { delete cfg['google.antigravity']; modified = true; }
1634
+ if (cfg['google.gemini']) { delete cfg['google.gemini']; modified = true; }
1635
+ } else if (cfg[provider]) {
1636
+ delete cfg[provider];
1637
+ modified = true;
1638
+ }
1639
+
1640
+ if (modified) {
1641
+ console.log(`[Auth] Removing ${provider} (all) from ${ap}`);
1642
+ atomicWriteFileSync(ap, JSON.stringify(cfg, null, 2));
1643
+ }
1644
+ } catch (e) {
1645
+ console.error(`[Auth] Failed to update ${ap}:`, e.message);
1646
+ }
1647
+ }
1648
+ });
1623
1649
  }
1624
1650
 
1625
1651
  const metadata = loadPoolMetadata();
@@ -1668,15 +1694,71 @@ app.delete('/api/auth/profiles/:provider/:name', (req, res) => {
1668
1694
  delete authCfg['google.gemini'];
1669
1695
  changed = true;
1670
1696
  }
1671
- } else if (wasActive && authCfg[provider]) {
1672
- delete authCfg[provider];
1673
- changed = true;
1697
+ } else if (authCfg[provider]) {
1698
+ // Check if the auth config matches the profile being deleted
1699
+ const creds = authCfg[provider];
1700
+ let matches = false;
1701
+
1702
+ // Try to match by email if available (OpenAI/Anthropic don't store email in auth.json usually, but we can check decoded token)
1703
+ if (creds.email === name) matches = true;
1704
+ else if (creds.accountId === name) matches = true;
1705
+ else if (provider === 'openai' && creds.access) {
1706
+ const decoded = decodeJWT(creds.access);
1707
+ if (decoded && decoded['https://api.openai.com/profile']?.email === name) matches = true;
1708
+ }
1709
+
1710
+ if (matches) {
1711
+ delete authCfg[provider];
1712
+ changed = true;
1713
+ }
1674
1714
  }
1675
1715
 
1676
1716
  if (changed) {
1677
- const cp = getConfigPath();
1678
- const ap = path.join(path.dirname(cp), 'auth.json');
1679
- atomicWriteFileSync(ap, JSON.stringify(authCfg, null, 2));
1717
+ const paths = getPaths();
1718
+ const allPaths = paths.candidates;
1719
+ if (paths.current && !allPaths.includes(paths.current)) {
1720
+ allPaths.push(paths.current);
1721
+ }
1722
+
1723
+ allPaths.forEach(p => {
1724
+ const ap = path.join(path.dirname(p), 'auth.json');
1725
+ if (fs.existsSync(ap)) {
1726
+ try {
1727
+ const cfg = JSON.parse(fs.readFileSync(ap, 'utf8'));
1728
+ let modified = false;
1729
+
1730
+ if (provider === 'google') {
1731
+ if (cfg.google?.email === name || cfg['google.antigravity']?.email === name || cfg['google.gemini']?.email === name) {
1732
+ delete cfg.google;
1733
+ delete cfg['google.antigravity'];
1734
+ delete cfg['google.gemini'];
1735
+ modified = true;
1736
+ }
1737
+ } else if (cfg[provider]) {
1738
+ const creds = cfg[provider];
1739
+ let matches = false;
1740
+ if (creds.email === name) matches = true;
1741
+ else if (creds.accountId === name) matches = true;
1742
+ else if (provider === 'openai' && creds.access) {
1743
+ const decoded = decodeJWT(creds.access);
1744
+ if (decoded && decoded['https://api.openai.com/profile']?.email === name) matches = true;
1745
+ }
1746
+
1747
+ if (matches) {
1748
+ delete cfg[provider];
1749
+ modified = true;
1750
+ }
1751
+ }
1752
+
1753
+ if (modified) {
1754
+ console.log(`[Auth] Removing credentials from ${ap}`);
1755
+ atomicWriteFileSync(ap, JSON.stringify(cfg, null, 2));
1756
+ }
1757
+ } catch (e) {
1758
+ console.error(`[Auth] Failed to update ${ap}:`, e.message);
1759
+ }
1760
+ }
1761
+ });
1680
1762
  }
1681
1763
 
1682
1764
  const metadata = loadPoolMetadata();
@@ -2004,6 +2086,14 @@ function importCurrentGoogleAuthToPool() {
2004
2086
  };
2005
2087
  }
2006
2088
  savePoolMetadata(metadata);
2089
+
2090
+ // Also update active profile to match what we just imported
2091
+ const studio = loadStudioConfig();
2092
+ if (!studio.activeProfiles) studio.activeProfiles = {};
2093
+ if (studio.activeProfiles.google !== email) {
2094
+ studio.activeProfiles.google = email;
2095
+ saveStudioConfig(studio);
2096
+ }
2007
2097
  }
2008
2098
  }
2009
2099
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-studio-server",
3
- "version": "1.16.1",
3
+ "version": "1.16.3",
4
4
  "description": "Backend server for OpenCode Studio - manages opencode configurations",
5
5
  "main": "index.js",
6
6
  "bin": {
package/server.log ADDED
@@ -0,0 +1,2 @@
1
+ [Auth] Syncing github-copilot login for profile-1768767863510 to pool.
2
+ Server running at http://localhost:3001