2026-03-12 21:55:17 -06:00
|
|
|
import type { AuthStorage } from '@gsd/pi-coding-agent'
|
2026-03-10 22:28:37 -06:00
|
|
|
|
2026-03-11 01:22:38 -06:00
|
|
|
// ─── Env hydration ────────────────────────────────────────────────────────────
|
|
|
|
|
|
2026-03-10 22:28:37 -06:00
|
|
|
/**
|
|
|
|
|
* Hydrate process.env from stored auth.json credentials for optional tool keys.
|
|
|
|
|
* Runs on every launch so extensions see Brave/Context7/Jina keys stored via the
|
|
|
|
|
* wizard on prior launches.
|
|
|
|
|
*/
|
|
|
|
|
export function loadStoredEnvKeys(authStorage: AuthStorage): void {
|
|
|
|
|
const providers: Array<[string, string]> = [
|
2026-03-11 01:22:38 -06:00
|
|
|
['brave', 'BRAVE_API_KEY'],
|
2026-03-10 22:44:28 -06:00
|
|
|
['brave_answers', 'BRAVE_ANSWERS_KEY'],
|
2026-03-11 01:22:38 -06:00
|
|
|
['context7', 'CONTEXT7_API_KEY'],
|
|
|
|
|
['jina', 'JINA_API_KEY'],
|
2026-03-12 14:12:19 +01:00
|
|
|
['tavily', 'TAVILY_API_KEY'],
|
2026-03-11 11:28:23 -03:00
|
|
|
['slack_bot', 'SLACK_BOT_TOKEN'],
|
|
|
|
|
['discord_bot', 'DISCORD_BOT_TOKEN'],
|
2026-03-16 13:18:02 -05:00
|
|
|
['telegram_bot', 'TELEGRAM_BOT_TOKEN'],
|
2026-03-14 15:08:36 +00:00
|
|
|
['groq', 'GROQ_API_KEY'],
|
2026-03-14 22:03:31 -05:00
|
|
|
['ollama-cloud', 'OLLAMA_API_KEY'],
|
2026-03-16 13:18:02 -05:00
|
|
|
['custom-openai', 'CUSTOM_OPENAI_API_KEY'],
|
2026-03-10 22:28:37 -06:00
|
|
|
]
|
|
|
|
|
for (const [provider, envVar] of providers) {
|
|
|
|
|
if (!process.env[envVar]) {
|
2026-03-26 17:16:42 -05:00
|
|
|
// Use getCredentialsForProvider to skip empty-key entries at index 0
|
|
|
|
|
// (left by legacy removeProviderToken which used set() with empty key)
|
|
|
|
|
const creds = authStorage.getCredentialsForProvider(provider)
|
|
|
|
|
const cred = creds.find((c: any) => c.type === 'api_key' && c.key)
|
|
|
|
|
if (cred?.type === 'api_key' && (cred as any).key) {
|
|
|
|
|
process.env[envVar] = (cred as any).key as string
|
2026-03-10 22:28:37 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|