fix(server): detect Pi availability via SDK model registry (#586)
The hardcoded OPENAI/ANTHROPIC/OPENROUTER env-var check missed DEEPSEEK_API_KEY and ~14 other providers the pi-ai SDK supports, hiding the Pi provider entirely when only those keys were set. Delegate to ModelRegistry.getAvailable() so every supported provider is recognized automatically. Diagnostic now lists configured providers dynamically instead of three hardcoded keys.
This commit is contained in:
@@ -4,6 +4,7 @@ import { join } from "node:path";
|
||||
import { homedir } from "node:os";
|
||||
import type { Logger } from "pino";
|
||||
import {
|
||||
AuthStorage,
|
||||
ModelRegistry,
|
||||
SessionManager,
|
||||
createAgentSessionFromServices,
|
||||
@@ -1470,12 +1471,8 @@ export class PiDirectAgentClient implements AgentClient {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (
|
||||
Boolean(process.env.OPENAI_API_KEY) ||
|
||||
Boolean(process.env.ANTHROPIC_API_KEY) ||
|
||||
Boolean(process.env.OPENROUTER_API_KEY) ||
|
||||
existsSync(join(homedir(), ".pi", "agent", "auth.json"))
|
||||
);
|
||||
const registry = ModelRegistry.create(AuthStorage.create());
|
||||
return registry.getAvailable().length > 0;
|
||||
}
|
||||
|
||||
async getDiagnostic(): Promise<{ diagnostic: string }> {
|
||||
@@ -1490,6 +1487,10 @@ export class PiDirectAgentClient implements AgentClient {
|
||||
const authConfigPath = join(homedir(), ".pi", "agent", "auth.json");
|
||||
let modelsValue = "Not checked";
|
||||
let status = formatDiagnosticStatus(available);
|
||||
const registry = ModelRegistry.create(AuthStorage.create());
|
||||
const configuredProviders = Array.from(
|
||||
new Set(registry.getAvailable().map((model) => model.provider)),
|
||||
).sort();
|
||||
|
||||
if (available) {
|
||||
try {
|
||||
@@ -1509,16 +1510,8 @@ export class PiDirectAgentClient implements AgentClient {
|
||||
{ label: "Binary", value: binary ?? "not found" },
|
||||
{ label: "Version", value: version },
|
||||
{
|
||||
label: "OPENAI_API_KEY",
|
||||
value: process.env.OPENAI_API_KEY ? "set" : "not set",
|
||||
},
|
||||
{
|
||||
label: "ANTHROPIC_API_KEY",
|
||||
value: process.env.ANTHROPIC_API_KEY ? "set" : "not set",
|
||||
},
|
||||
{
|
||||
label: "OPENROUTER_API_KEY",
|
||||
value: process.env.OPENROUTER_API_KEY ? "set" : "not set",
|
||||
label: "Configured providers",
|
||||
value: configuredProviders.length > 0 ? configuredProviders.join(", ") : "none",
|
||||
},
|
||||
{
|
||||
label: "Auth config (~/.pi/agent/auth.json)",
|
||||
|
||||
Reference in New Issue
Block a user