opencode-studio-server 1.9.4 → 1.9.6
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.
- package/index.js +112 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -17,10 +17,24 @@ const atomicWriteFileSync = (filePath, data, options = 'utf8') => {
|
|
|
17
17
|
const tempPath = path.join(dir, `.${path.basename(filePath)}.${crypto.randomBytes(6).toString('hex')}.tmp`);
|
|
18
18
|
try {
|
|
19
19
|
fs.writeFileSync(tempPath, data, options);
|
|
20
|
-
|
|
20
|
+
// Retry rename for Windows file locking issues
|
|
21
|
+
let retries = 5;
|
|
22
|
+
while (retries > 0) {
|
|
23
|
+
try {
|
|
24
|
+
fs.renameSync(tempPath, filePath);
|
|
25
|
+
break;
|
|
26
|
+
} catch (e) {
|
|
27
|
+
if (retries === 1) throw e;
|
|
28
|
+
retries--;
|
|
29
|
+
// Synchronous delay
|
|
30
|
+
const start = Date.now();
|
|
31
|
+
while (Date.now() - start < 50) {}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
21
34
|
} catch (err) {
|
|
22
|
-
|
|
23
|
-
|
|
35
|
+
if (fs.existsSync(tempPath)) {
|
|
36
|
+
try { fs.unlinkSync(tempPath); } catch (e) {}
|
|
37
|
+
}
|
|
24
38
|
throw err;
|
|
25
39
|
}
|
|
26
40
|
};
|
|
@@ -1342,6 +1356,7 @@ app.get('/api/auth/providers', (req, res) => {
|
|
|
1342
1356
|
});
|
|
1343
1357
|
|
|
1344
1358
|
app.get('/api/auth', (req, res) => {
|
|
1359
|
+
importCurrentGoogleAuthToPool();
|
|
1345
1360
|
syncAntigravityPool();
|
|
1346
1361
|
const authCfg = loadAuthConfig() || {};
|
|
1347
1362
|
const studio = loadStudioConfig();
|
|
@@ -1519,6 +1534,51 @@ app.post('/api/auth/profiles/:provider/:name/activate', (req, res) => {
|
|
|
1519
1534
|
res.json({ success: true });
|
|
1520
1535
|
});
|
|
1521
1536
|
|
|
1537
|
+
// IMPORTANT: This route must be BEFORE /:provider/:name to avoid 'all' being captured as :name
|
|
1538
|
+
app.delete('/api/auth/profiles/:provider/all', (req, res) => {
|
|
1539
|
+
const { provider } = req.params;
|
|
1540
|
+
console.log(`[Auth] Deleting ALL profiles for: ${provider}`);
|
|
1541
|
+
const activePlugin = getActiveGooglePlugin();
|
|
1542
|
+
const namespace = provider === 'google'
|
|
1543
|
+
? (activePlugin === 'antigravity' ? 'google.antigravity' : 'google.gemini')
|
|
1544
|
+
: provider;
|
|
1545
|
+
|
|
1546
|
+
const dir = getProfileDir(provider, activePlugin);
|
|
1547
|
+
|
|
1548
|
+
if (fs.existsSync(dir)) {
|
|
1549
|
+
const files = fs.readdirSync(dir).filter(f => f.endsWith('.json'));
|
|
1550
|
+
files.forEach(f => fs.unlinkSync(path.join(dir, f)));
|
|
1551
|
+
console.log(`[Auth] Deleted ${files.length} profiles from ${dir}`);
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
const studio = loadStudioConfig();
|
|
1555
|
+
if (studio.activeProfiles && studio.activeProfiles[provider]) {
|
|
1556
|
+
delete studio.activeProfiles[provider];
|
|
1557
|
+
saveStudioConfig(studio);
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
const authCfg = loadAuthConfig() || {};
|
|
1561
|
+
if (authCfg[provider]) {
|
|
1562
|
+
delete authCfg[provider];
|
|
1563
|
+
if (provider === 'google') {
|
|
1564
|
+
const key = activePlugin === 'antigravity' ? 'google.antigravity' : 'google.gemini';
|
|
1565
|
+
delete authCfg.google;
|
|
1566
|
+
delete authCfg[key];
|
|
1567
|
+
}
|
|
1568
|
+
const cp = getConfigPath();
|
|
1569
|
+
const ap = path.join(path.dirname(cp), 'auth.json');
|
|
1570
|
+
atomicWriteFileSync(ap, JSON.stringify(authCfg, null, 2));
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1573
|
+
const metadata = loadPoolMetadata();
|
|
1574
|
+
if (metadata[namespace]) {
|
|
1575
|
+
delete metadata[namespace];
|
|
1576
|
+
savePoolMetadata(metadata);
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
res.json({ success: true });
|
|
1580
|
+
});
|
|
1581
|
+
|
|
1522
1582
|
app.delete('/api/auth/profiles/:provider/:name', (req, res) => {
|
|
1523
1583
|
const { provider, name } = req.params;
|
|
1524
1584
|
console.log(`[Auth] Deleting profile: ${provider}/${name}`);
|
|
@@ -1769,6 +1829,55 @@ function listAntigravityAccounts() {
|
|
|
1769
1829
|
}));
|
|
1770
1830
|
}
|
|
1771
1831
|
|
|
1832
|
+
function importCurrentGoogleAuthToPool() {
|
|
1833
|
+
const studio = loadStudioConfig();
|
|
1834
|
+
// Only applies if Antigravity is active
|
|
1835
|
+
if (studio.activeGooglePlugin !== 'antigravity') return;
|
|
1836
|
+
|
|
1837
|
+
const authCfg = loadAuthConfig();
|
|
1838
|
+
if (!authCfg || !authCfg.google || !authCfg.google.email) return;
|
|
1839
|
+
|
|
1840
|
+
const namespace = 'google.antigravity';
|
|
1841
|
+
const profileDir = path.join(AUTH_PROFILES_DIR, namespace);
|
|
1842
|
+
if (!fs.existsSync(profileDir)) fs.mkdirSync(profileDir, { recursive: true });
|
|
1843
|
+
|
|
1844
|
+
const email = authCfg.google.email;
|
|
1845
|
+
const profilePath = path.join(profileDir, `${email}.json`);
|
|
1846
|
+
|
|
1847
|
+
// Check if we need to sync (new account or updated tokens)
|
|
1848
|
+
let shouldSync = true;
|
|
1849
|
+
if (fs.existsSync(profilePath)) {
|
|
1850
|
+
try {
|
|
1851
|
+
const current = JSON.parse(fs.readFileSync(profilePath, 'utf8'));
|
|
1852
|
+
if (current.access_token === authCfg.google.access_token) {
|
|
1853
|
+
shouldSync = false;
|
|
1854
|
+
}
|
|
1855
|
+
} catch {
|
|
1856
|
+
// Corrupt file, overwrite
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
|
|
1860
|
+
if (shouldSync) {
|
|
1861
|
+
console.log(`[Auth] Syncing Google login for ${email} to Antigravity pool.`);
|
|
1862
|
+
atomicWriteFileSync(profilePath, JSON.stringify(authCfg.google, null, 2));
|
|
1863
|
+
|
|
1864
|
+
const metadata = loadPoolMetadata();
|
|
1865
|
+
if (!metadata[namespace]) metadata[namespace] = {};
|
|
1866
|
+
|
|
1867
|
+
// Only update metadata if it doesn't exist
|
|
1868
|
+
if (!metadata[namespace][email]) {
|
|
1869
|
+
metadata[namespace][email] = {
|
|
1870
|
+
email: email,
|
|
1871
|
+
createdAt: Date.now(),
|
|
1872
|
+
lastUsed: Date.now(),
|
|
1873
|
+
usageCount: 0,
|
|
1874
|
+
imported: true
|
|
1875
|
+
};
|
|
1876
|
+
savePoolMetadata(metadata);
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
|
|
1772
1881
|
function syncAntigravityPool() {
|
|
1773
1882
|
const accounts = listAntigravityAccounts();
|
|
1774
1883
|
const namespace = 'google.antigravity';
|