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 { homedir } from "node:os";
|
||||||
import type { Logger } from "pino";
|
import type { Logger } from "pino";
|
||||||
import {
|
import {
|
||||||
|
AuthStorage,
|
||||||
ModelRegistry,
|
ModelRegistry,
|
||||||
SessionManager,
|
SessionManager,
|
||||||
createAgentSessionFromServices,
|
createAgentSessionFromServices,
|
||||||
@@ -1470,12 +1471,8 @@ export class PiDirectAgentClient implements AgentClient {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
const registry = ModelRegistry.create(AuthStorage.create());
|
||||||
Boolean(process.env.OPENAI_API_KEY) ||
|
return registry.getAvailable().length > 0;
|
||||||
Boolean(process.env.ANTHROPIC_API_KEY) ||
|
|
||||||
Boolean(process.env.OPENROUTER_API_KEY) ||
|
|
||||||
existsSync(join(homedir(), ".pi", "agent", "auth.json"))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getDiagnostic(): Promise<{ diagnostic: string }> {
|
async getDiagnostic(): Promise<{ diagnostic: string }> {
|
||||||
@@ -1490,6 +1487,10 @@ export class PiDirectAgentClient implements AgentClient {
|
|||||||
const authConfigPath = join(homedir(), ".pi", "agent", "auth.json");
|
const authConfigPath = join(homedir(), ".pi", "agent", "auth.json");
|
||||||
let modelsValue = "Not checked";
|
let modelsValue = "Not checked";
|
||||||
let status = formatDiagnosticStatus(available);
|
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) {
|
if (available) {
|
||||||
try {
|
try {
|
||||||
@@ -1509,16 +1510,8 @@ export class PiDirectAgentClient implements AgentClient {
|
|||||||
{ label: "Binary", value: binary ?? "not found" },
|
{ label: "Binary", value: binary ?? "not found" },
|
||||||
{ label: "Version", value: version },
|
{ label: "Version", value: version },
|
||||||
{
|
{
|
||||||
label: "OPENAI_API_KEY",
|
label: "Configured providers",
|
||||||
value: process.env.OPENAI_API_KEY ? "set" : "not set",
|
value: configuredProviders.length > 0 ? configuredProviders.join(", ") : "none",
|
||||||
},
|
|
||||||
{
|
|
||||||
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: "Auth config (~/.pi/agent/auth.json)",
|
label: "Auth config (~/.pi/agent/auth.json)",
|
||||||
|
|||||||
Reference in New Issue
Block a user