opencode-1password-auth 1.0.5 → 1.0.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.ts +78 -42
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -252,17 +252,20 @@ export const OnePasswordAuthPlugin: Plugin = async ({ client, $ }) => {
|
|
|
252
252
|
|
|
253
253
|
try {
|
|
254
254
|
// Authenticate with OpenCode runtime
|
|
255
|
-
debugLog(`Calling client.auth.set for ${providerId}`);
|
|
256
|
-
await client.auth.set({
|
|
255
|
+
debugLog(`Calling client.auth.set for ${providerId} with key length ${apiKey.length}`);
|
|
256
|
+
const result = await client.auth.set({
|
|
257
257
|
path: { id: providerId },
|
|
258
258
|
body: { type: "api", key: apiKey },
|
|
259
259
|
});
|
|
260
|
-
debugLog(`✓ ${providerId} authenticated (from ${variableName})`);
|
|
260
|
+
debugLog(`✓ ${providerId} authenticated (from ${variableName}) - Result: ${JSON.stringify(result)}`);
|
|
261
261
|
} catch (err) {
|
|
262
262
|
debugLog(`Failed to authenticate ${providerId}: ${err}`);
|
|
263
263
|
if (err instanceof Error) {
|
|
264
264
|
debugLog(`Error message: ${err.message}`);
|
|
265
|
+
debugLog(`Error stack: ${err.stack}`);
|
|
265
266
|
}
|
|
267
|
+
// Also log to console for immediate visibility
|
|
268
|
+
console.error(`[1Password Plugin] Failed to authenticate ${providerId}: ${err}`);
|
|
266
269
|
}
|
|
267
270
|
}
|
|
268
271
|
};
|
|
@@ -311,52 +314,85 @@ export const OnePasswordAuthPlugin: Plugin = async ({ client, $ }) => {
|
|
|
311
314
|
return toInject;
|
|
312
315
|
};
|
|
313
316
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
if (event.type === "server.connected") {
|
|
318
|
-
debugLog("Initializing...");
|
|
317
|
+
// Initialize as soon as plugin loads (config hook runs early)
|
|
318
|
+
const initializePlugin = async () => {
|
|
319
|
+
debugLog("Initializing plugin...");
|
|
319
320
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
321
|
+
opClient = await initClient();
|
|
322
|
+
if (!opClient) {
|
|
323
|
+
debugLog("No client available");
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
325
326
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
327
|
+
const configEnvId = process.env.OP_CONFIG_ENV_ID;
|
|
328
|
+
if (!configEnvId) {
|
|
329
|
+
debugLog("Missing OP_CONFIG_ENV_ID");
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
331
332
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
333
|
+
debugLog(`Reading config from environment ${configEnvId}`);
|
|
334
|
+
const vars = await readEnvironmentVariables(configEnvId);
|
|
335
|
+
const configEnvIds: Record<string, string> = {};
|
|
336
|
+
for (const v of vars) {
|
|
337
|
+
if (v.name.endsWith("_ENV_ID") && v.value) {
|
|
338
|
+
configEnvIds[v.name] = v.value;
|
|
339
|
+
debugLog(`Found ${v.name} = ${v.value.substring(0, 10)}...`);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
341
342
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
343
|
+
const providersEnvId = configEnvIds.OPENCODE_PROVIDERS_ENV_ID;
|
|
344
|
+
if (providersEnvId) {
|
|
345
|
+
// First update the config files to use env var references
|
|
346
|
+
await updateAuthJson(providersEnvId);
|
|
347
|
+
await authenticateProviders(providersEnvId);
|
|
348
|
+
}
|
|
348
349
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
350
|
+
const mcpEnvIdFromConfig = configEnvIds.OPENCODE_MCPS_ENV_ID;
|
|
351
|
+
if (mcpEnvIdFromConfig) {
|
|
352
|
+
mcpsEnvId = mcpEnvIdFromConfig;
|
|
353
|
+
await updateOpenCodeJsonMCP(mcpEnvIdFromConfig);
|
|
354
|
+
const toInject = await injectMCPSecrets(mcpEnvIdFromConfig);
|
|
355
|
+
if (Object.keys(toInject).length > 0) {
|
|
356
|
+
debugLog(`Injected ${Object.keys(toInject).join(", ")} for MCP`);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
debugLog("Plugin initialization complete");
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
// Start initialization immediately
|
|
364
|
+
initializePlugin().catch(err => {
|
|
365
|
+
debugLog(`Failed to initialize plugin: ${err}`);
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
return {
|
|
369
|
+
async config(config: any) {
|
|
370
|
+
debugLog("Config hook called");
|
|
371
|
+
// Config hook runs early, we could also initialize here
|
|
372
|
+
// but we're already initializing above
|
|
373
|
+
},
|
|
374
|
+
|
|
375
|
+
async event({ event }: { event: { type: string } }) {
|
|
376
|
+
debugLog(`Received event: ${event.type}`);
|
|
377
|
+
if (event.type === "server.connected") {
|
|
378
|
+
debugLog("Server connected - rechecking authentication");
|
|
379
|
+
// Re-authenticate providers in case they weren't set earlier
|
|
380
|
+
if (opClient) {
|
|
381
|
+
const configEnvId = process.env.OP_CONFIG_ENV_ID;
|
|
382
|
+
if (configEnvId) {
|
|
383
|
+
const vars = await readEnvironmentVariables(configEnvId);
|
|
384
|
+
const configEnvIds: Record<string, string> = {};
|
|
385
|
+
for (const v of vars) {
|
|
386
|
+
if (v.name.endsWith("_ENV_ID") && v.value) {
|
|
387
|
+
configEnvIds[v.name] = v.value;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
const providersEnvId = configEnvIds.OPENCODE_PROVIDERS_ENV_ID;
|
|
391
|
+
if (providersEnvId) {
|
|
392
|
+
await authenticateProviders(providersEnvId);
|
|
393
|
+
}
|
|
356
394
|
}
|
|
357
395
|
}
|
|
358
|
-
|
|
359
|
-
debugLog("Initialization complete");
|
|
360
396
|
}
|
|
361
397
|
},
|
|
362
398
|
|
package/package.json
CHANGED