opencode-studio-server 1.3.8 → 1.3.9

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 (2) hide show
  1. package/index.js +65 -0
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -221,6 +221,7 @@ function processLogLine(line) {
221
221
 
222
222
  // Start watcher on server start
223
223
  setupLogWatcher();
224
+ importExistingAuth();
224
225
 
225
226
  let pendingActionMemory = null;
226
227
 
@@ -1192,6 +1193,70 @@ function syncAntigravityPool() {
1192
1193
  savePoolMetadata(metadata);
1193
1194
  }
1194
1195
 
1196
+ function importExistingAuth() {
1197
+ const authCfg = loadAuthConfig();
1198
+ if (!authCfg) return;
1199
+
1200
+ const studio = loadStudioConfig();
1201
+ const activeProfiles = studio.activeProfiles || {};
1202
+ let changed = false;
1203
+
1204
+ // Standard providers to check
1205
+ const providers = ['google', 'openai', 'anthropic', 'xai', 'openrouter', 'github-copilot', 'mistral', 'deepseek', 'amazon-bedrock', 'azure'];
1206
+
1207
+ providers.forEach(provider => {
1208
+ if (!authCfg[provider]) return; // No creds for this provider
1209
+
1210
+ // Determine namespace
1211
+ // For auto-import, we target the standard 'google' namespace unless antigravity plugin is active?
1212
+ // Actually, auth.json 'google' key usually means Gemini/Vertex standard auth.
1213
+ const namespace = provider === 'google' && studio.activeGooglePlugin === 'antigravity'
1214
+ ? 'google.antigravity'
1215
+ : (provider === 'google' ? 'google.gemini' : provider);
1216
+
1217
+ const profileDir = path.join(AUTH_PROFILES_DIR, namespace);
1218
+
1219
+ // If we already have an active profile for this provider, skip import
1220
+ if (activeProfiles[provider]) return;
1221
+
1222
+ // If directory exists and has files, check if empty
1223
+ if (fs.existsSync(profileDir) && fs.readdirSync(profileDir).filter(f => f.endsWith('.json')).length > 0) {
1224
+ return;
1225
+ }
1226
+
1227
+ // Import!
1228
+ if (!fs.existsSync(profileDir)) fs.mkdirSync(profileDir, { recursive: true });
1229
+
1230
+ const email = authCfg[provider].email || null;
1231
+ const name = email || `imported-${Date.now()}`;
1232
+ const profilePath = path.join(profileDir, `${name}.json`);
1233
+
1234
+ console.log(`[AutoImport] Importing existing ${provider} credentials as ${name}`);
1235
+ atomicWriteFileSync(profilePath, JSON.stringify(authCfg[provider], null, 2));
1236
+
1237
+ // Set as active
1238
+ if (!studio.activeProfiles) studio.activeProfiles = {};
1239
+ studio.activeProfiles[provider] = name;
1240
+ changed = true;
1241
+
1242
+ // Update metadata
1243
+ const metadata = loadPoolMetadata();
1244
+ if (!metadata[namespace]) metadata[namespace] = {};
1245
+ metadata[namespace][name] = {
1246
+ email: email,
1247
+ createdAt: Date.now(),
1248
+ lastUsed: Date.now(),
1249
+ usageCount: 0,
1250
+ imported: true
1251
+ };
1252
+ savePoolMetadata(metadata);
1253
+ });
1254
+
1255
+ if (changed) {
1256
+ saveStudioConfig(studio);
1257
+ }
1258
+ }
1259
+
1195
1260
  function getAccountStatus(meta, now) {
1196
1261
  if (!meta) return 'ready';
1197
1262
  if (meta.cooldownUntil && meta.cooldownUntil > now) return 'cooldown';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-studio-server",
3
- "version": "1.3.8",
3
+ "version": "1.3.9",
4
4
  "description": "Backend server for OpenCode Studio - manages opencode configurations",
5
5
  "main": "index.js",
6
6
  "bin": {