mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-31 14:16:39 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Agents use a harness, a model, and a credential to run tasks. > - Connections already store credentials and control who can use them. > - Custom providers also need an endpoint and a supported API format. > - A per-agent endpoint would duplicate credentials and access rules. > - This pull request stores routing on the connection and projects it into the harness. > - Isolated credentials and protocol checks keep the selected connection authoritative. ## Linked Issues or Issue Description Refs #37, #13083, #14104, #14565, #12692. #14016 is a reference only. This PR has its own schema, vault persistence, routing validation, runtime projection, and tests. None of the five commits in #14016 is an ancestor of this branch. We do not depend on or plan to merge it. #14967 addresses task-pinned account pools. #14422 addresses another provider integration. This is the first of two linked PRs. Merge this connection change before #15341, which refines agent setup and adds the qualification harness. The split keeps each review below 100 changed files. Provider catalog entries have usable setup forms in this PR. Local browser subscription sign-in is included. ## What Changed - Store non-secret routing metadata on AI connections. Vault provider API keys, including Bedrock bearer API keys. Reject general AWS access keys. - Enforce company, owner, human audience, agent access, connection status, and protocol checks before resolving credentials. Keep reconnect destinations immutable and retain connection identity during key rotation. - Project OpenRouter and compatible custom endpoints into Codex, Claude, OpenCode, and local Hermes. Carry these settings through both legacy and native runner transports. Clear conflicting host credentials and redact keys from diagnostics. - Preserve older OpenRouter accounts and native personal defaults. Add Google API-key accounts and migration `0306` for the two provider-default constraints. - Run local Claude and Codex subscription sign-in behind the existing browser sign-in card. Use private attempt homes and owner-bound completion instead of a copied terminal command. - Seed isolated Gemini authentication and preserve OpenCode workspace permissions. Keep the selected connection authoritative. The independent Gemini and Grok workflow fixes are in #15341. - Keep native OpenCode custom gateway keys in a runner-owned selected-model proxy; the harness config contains only a session-scoped capability. Honor runtime outgoing proxy and certificate settings. Preserve streamed responses and revoke the proxy on close or startup failure. - Allow ordinary members to connect native personal accounts before an agent exists. - Repair routed accounts from task cards using the saved provider destination, protocol, model aliases, and connection identity. - Add provider catalog definitions, model discovery, pinned logos, and complete native and routed setup forms. Allow a personal routed connection before a new agent exists. Keep endpoint authentication keys out of Hermes terminal children. - Recover cancelled or restarted browser sign-in with a clear restart action. Support no-auth endpoints without a vault credential. Add isolation and recovery regressions and runtime documentation. ## Verification - Updated with `origin/master` at `22a3ea341`. Migration `0306` follows the new master migration and passes migration and snapshot checks. - The integrated connection regressions passed 152 tests and 50 native OpenCode driver tests, including key-free child-shell configuration reads, authenticated/no-auth forwarding, streaming, model/path restrictions, cancellation, outgoing proxy routing, and NO_PROXY bypass. Provider setup has 14 passing tests. The pinned real OpenCode 1.18.34 executable also completed a turn through the proxy against a local synthetic provider; the reusable key was absent from its config. A second real-executable smoke passed with an HTTPS CONNECT proxy and runtime-specific synthetic certificate trust. Certificate-file and certificate-directory regressions pass. - Task-card repair passed 48 tests, including OpenRouter, Bedrock, and custom gateway reconnect cases. UI typecheck and token gates passed. - The prior core regression set passed 133 tests across new-agent setup, provider forms, browser sign-in, routing projection, and connection authorization. Token gates and UI typecheck passed. - Full workspace typecheck and production build passed again after the latest integration and credential-proxy fix. The merged deterministic runner E2E suite passed 1,400 Vitest tests and 128 Node tests. - Full workspace typecheck passed on the prior linked combined implementation. Production build, Storybook build, 1,316 browser-harness Vitest tests, and 128 Node tests passed. Head `9d964c8d9` includes the latest master integration and regenerated migration. This exact head passed 54 remote checks with four expected skips and Greptile 5/5; no review threads remain open. An unchanged server fixture had a random six-character issue-prefix collision on its first attempt. All 245 tests passed locally and the single CI retry passed. - A provider-free terminal check used the cited supported Hermes source and dummy keys. Gateway and OpenRouter terminal children could not read the selected key. - The broad local Vitest attempt passed 15,442 tests but was not green. It had an embedded-Postgres startup failure, an HTTP logger timeout, an origin socket error, and a browser cancellation wait timeout. The cancellation wait was corrected. The relevant connection tests and the full origin test file passed separately. Latest-head CI must pass before merge. - Prior credential-backed acceptance exercised task creation, tool use, artifact delivery, completion, and context-dependent follow-up. Claude legacy and native runners passed Bedrock with `us-east-1` and `us.anthropic.claude-sonnet-4-6`. - Historical local qualification retained 43 passing API/gateway cells out of 46. Those attempts span earlier builds. They do not qualify this exact commit or staging. All subscription combinations and staging remain unqualified. - Verify native subscription and API-key setup. Connect a regular provider catalog row. Verify an incompatible harness and a changed reconnect URL are rejected. Use #15341 for the complete browser campaign. ## Risks - Migration `0306` changes two check constraints. It preserves rows and is safe to reapply. It takes normal constraint-change locks. - Credential projection touches several harnesses. CLI upgrades can change provider configuration and session behavior. - The native OpenCode proxy adds a loopback hop, pins requests to the selected model, limits request bodies to 16 MiB, rejects redirects, and expires at session close. It prevents reusable keys in the child configuration; it is not an OS isolation boundary against a process debugger running as the same user. - Custom endpoints must be reachable from the agent environment. Saving a connection does not prove connectivity. Bedrock keys require rotation before expiry. - Gemini CLI 0.58.0 has an upstream ACP new-file error conversion defect. Provider overloads and an unresolved follow-up timeout also affect live Gemini qualification. We have not patched the installed CLI or marked those cases as passing. - OpenClaw Gateway, Hermes Gateway, Claude Managed, AWS AgentCore, Process, HTTP, and legacy ACPX local are excluded. Vertex, ambient AWS identity, arbitrary auth headers, and custom routing for other harnesses are excluded. - These PRs do not establish production or staging qualification for every provider and login method. ## Model Used OpenAI GPT-6 through Codex, with reasoning, repository tools, code execution, and browser testing. The exact deployment model ID and context window size were not exposed in this session. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
416 lines
15 KiB
TypeScript
416 lines
15 KiB
TypeScript
/**
|
|
* Environment test for the Hermes Agent adapter.
|
|
*
|
|
* Verifies that Hermes Agent is installed, accessible, and configured
|
|
* before allowing the adapter to be used.
|
|
*/
|
|
|
|
import type {
|
|
AdapterEnvironmentTestContext,
|
|
AdapterEnvironmentTestResult,
|
|
AdapterEnvironmentCheck,
|
|
} from "@paperclipai/adapter-utils";
|
|
|
|
import { execFile } from "node:child_process";
|
|
import { readFileSync } from "node:fs";
|
|
import { promisify } from "node:util";
|
|
|
|
import { HERMES_CLI, DEFAULT_MODEL, ADAPTER_TYPE, VALID_PROVIDERS } from "../shared/constants.js";
|
|
import { detectModel, resolveProvider, inferProviderFromModel } from "./detect-model.js";
|
|
import { resolveHermesCommand } from "./execute.js";
|
|
|
|
const execFileAsync = promisify(execFile);
|
|
|
|
function asString(v: unknown): string | undefined {
|
|
return typeof v === "string" ? v : undefined;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Checks
|
|
// ---------------------------------------------------------------------------
|
|
|
|
async function checkCliInstalled(
|
|
command: string,
|
|
): Promise<AdapterEnvironmentCheck | null> {
|
|
try {
|
|
// Try to run the command to see if it exists
|
|
await execFileAsync(command, ["--version"], { timeout: 10_000 });
|
|
return null; // OK — it ran successfully
|
|
} catch (err: unknown) {
|
|
const e = err as NodeJS.ErrnoException;
|
|
if (e.code === "ENOENT") {
|
|
return {
|
|
level: "error",
|
|
message: `Hermes CLI "${command}" not found in PATH`,
|
|
hint: "Install Hermes Agent: pip install hermes-agent",
|
|
code: "hermes_cli_not_found",
|
|
};
|
|
}
|
|
// Command exists but --version might have failed for some reason
|
|
// Still consider it installed
|
|
return null;
|
|
}
|
|
}
|
|
|
|
async function checkCliVersion(
|
|
command: string,
|
|
): Promise<AdapterEnvironmentCheck | null> {
|
|
try {
|
|
const { stdout } = await execFileAsync(command, ["--version"], {
|
|
timeout: 10_000,
|
|
});
|
|
const version = stdout.trim();
|
|
if (version) {
|
|
return {
|
|
level: "info",
|
|
message: `Hermes Agent version: ${version}`,
|
|
code: "hermes_version",
|
|
};
|
|
}
|
|
return {
|
|
level: "warn",
|
|
message: "Could not determine Hermes Agent version",
|
|
code: "hermes_version_unknown",
|
|
};
|
|
} catch {
|
|
return {
|
|
level: "warn",
|
|
message:
|
|
"Could not determine Hermes Agent version (hermes --version failed)",
|
|
hint: "Make sure the hermes CLI is properly installed and functional",
|
|
code: "hermes_version_failed",
|
|
};
|
|
}
|
|
}
|
|
|
|
async function checkPython(): Promise<AdapterEnvironmentCheck | null> {
|
|
try {
|
|
const { stdout } = await execFileAsync("python3", ["--version"], {
|
|
timeout: 5_000,
|
|
});
|
|
const version = stdout.trim();
|
|
const match = version.match(/(\d+)\.(\d+)/);
|
|
if (match) {
|
|
const major = parseInt(match[1], 10);
|
|
const minor = parseInt(match[2], 10);
|
|
if (major < 3 || (major === 3 && minor < 10)) {
|
|
return {
|
|
level: "error",
|
|
message: `Python ${version} found — Hermes requires Python 3.10+`,
|
|
hint: "Upgrade Python to 3.10 or later",
|
|
code: "hermes_python_old",
|
|
};
|
|
}
|
|
}
|
|
return null; // OK
|
|
} catch {
|
|
return {
|
|
level: "warn",
|
|
message: "python3 not found in PATH",
|
|
hint: "Hermes Agent requires Python 3.10+. Install it from python.org",
|
|
code: "hermes_python_missing",
|
|
};
|
|
}
|
|
}
|
|
|
|
function checkModel(
|
|
config: Record<string, unknown>,
|
|
): AdapterEnvironmentCheck | null {
|
|
const model = asString(config.model);
|
|
if (!model) {
|
|
return {
|
|
level: "info",
|
|
message: "No model specified — Hermes will use its configured default model",
|
|
hint: "Set a model explicitly in Paperclip only if you want to override your local Hermes configuration.",
|
|
code: "hermes_configured_default_model",
|
|
};
|
|
}
|
|
return {
|
|
level: "info",
|
|
message: `Model: ${model}`,
|
|
code: "hermes_model_configured",
|
|
};
|
|
}
|
|
|
|
async function checkApiKeys(
|
|
config: Record<string, unknown>,
|
|
detectedConfig: Awaited<ReturnType<typeof detectModel>> | null,
|
|
): Promise<AdapterEnvironmentCheck | null> {
|
|
// The server resolves secret refs into config.env before calling testEnvironment,
|
|
// so we check config.env first (adapter-configured secrets), then fall back to
|
|
// process.env (server/host environment), then ~/.hermes/.env (Hermes local config).
|
|
const envConfig = (config.env ?? {}) as Record<string, unknown>;
|
|
const resolvedEnv: Record<string, string> = {};
|
|
for (const [key, value] of Object.entries(envConfig)) {
|
|
if (typeof value === "string" && value.length > 0) resolvedEnv[key] = value;
|
|
}
|
|
|
|
// Also read ~/.hermes/.env — Hermes stores API keys there by default and does
|
|
// not export them to the parent process, so Paperclip's process.env won't
|
|
// contain them. Parsing this file ensures the environment test reports
|
|
// accurate results for keys that Hermes already knows about.
|
|
const hermesEnvKeys: Record<string, string> = {};
|
|
try {
|
|
const homeDir = process.env.HOME || process.env.USERPROFILE || "/root";
|
|
const hermesEnvPath = `${homeDir}/.hermes/.env`;
|
|
const content = readFileSync(hermesEnvPath, "utf-8");
|
|
for (const line of content.split("\n")) {
|
|
const trimmed = line.trim();
|
|
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
const eqIdx = trimmed.indexOf("=");
|
|
if (eqIdx > 0) {
|
|
const key = trimmed.substring(0, eqIdx).trim();
|
|
const value = trimmed.substring(eqIdx + 1).trim();
|
|
if (value.length > 0) hermesEnvKeys[key] = value;
|
|
}
|
|
}
|
|
} catch {
|
|
// ~/.hermes/.env may not exist — that's fine
|
|
}
|
|
|
|
const has = (key: string): boolean =>
|
|
!!(resolvedEnv[key] ?? process.env[key] ?? hermesEnvKeys[key]);
|
|
|
|
const hasAnthropic = has("ANTHROPIC_API_KEY");
|
|
const hasOpenRouter = has("OPENROUTER_API_KEY");
|
|
const hasOpenAI = has("OPENAI_API_KEY");
|
|
const hasZai = has("ZAI_API_KEY");
|
|
const hasKimi = has("KIMI_API_KEY");
|
|
const hasMiniMax = has("MINIMAX_API_KEY");
|
|
|
|
const providers: string[] = [];
|
|
if (hasAnthropic) providers.push("Anthropic");
|
|
if (hasOpenRouter) providers.push("OpenRouter");
|
|
if (hasOpenAI) providers.push("OpenAI");
|
|
if (hasZai) providers.push("Z.AI");
|
|
if (hasKimi) providers.push("Kimi");
|
|
if (hasMiniMax) providers.push("MiniMax");
|
|
|
|
if (providers.length > 0) {
|
|
return {
|
|
level: "info",
|
|
message: `API keys found: ${providers.join(", ")}`,
|
|
code: "hermes_api_keys_found",
|
|
};
|
|
}
|
|
|
|
const requestedModel = asString(config.model);
|
|
|
|
const supportedProviders = VALID_PROVIDERS as readonly string[];
|
|
const modelMatchesRequested =
|
|
!!detectedConfig?.model &&
|
|
(!requestedModel || detectedConfig.model.toLowerCase() === requestedModel.toLowerCase());
|
|
|
|
const matchingHermesConfigApiKey =
|
|
!!detectedConfig?.hasApiKey &&
|
|
modelMatchesRequested;
|
|
|
|
if (matchingHermesConfigApiKey && detectedConfig) {
|
|
const providerLabel = detectedConfig.provider.trim();
|
|
|
|
if (!providerLabel) {
|
|
return {
|
|
level: "info",
|
|
message: "Hermes config includes an API key for the requested model via ~/.hermes/config.yaml without an explicit provider",
|
|
hint: "Skipping the built-in API-key warning because Hermes can use model.api_key from the local Hermes config.",
|
|
code: "hermes_api_key_in_config",
|
|
};
|
|
}
|
|
|
|
if (!supportedProviders.includes(providerLabel)) {
|
|
return {
|
|
level: "info",
|
|
message: `Hermes config includes runtime settings for unsupported adapter provider "${providerLabel}" via ~/.hermes/config.yaml`,
|
|
hint: "Skipping the built-in API-key warning because Hermes can resolve this provider at runtime.",
|
|
code: "hermes_custom_provider_config",
|
|
};
|
|
}
|
|
|
|
return {
|
|
level: "info",
|
|
message: `Hermes config includes an API key for provider "${providerLabel}" via ~/.hermes/config.yaml`,
|
|
hint: "Skipping the built-in API-key warning because Hermes can use model.api_key from the local Hermes config.",
|
|
code: "hermes_api_key_in_config",
|
|
};
|
|
}
|
|
|
|
return {
|
|
level: "warn",
|
|
message: "No LLM API keys found in environment",
|
|
hint: "Set API keys in the agent's env secrets or ~/.hermes/.env. Hermes supports: ANTHROPIC_API_KEY, OPENROUTER_API_KEY, OPENAI_API_KEY, ZAI_API_KEY, KIMI_API_KEY, MINIMAX_API_KEY",
|
|
code: "hermes_no_api_keys",
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Check provider/model consistency.
|
|
* Warns if the configured provider might be wrong for the model.
|
|
*/
|
|
async function checkProviderConsistency(
|
|
config: Record<string, unknown>,
|
|
detectedConfig: Awaited<ReturnType<typeof detectModel>> | null,
|
|
): Promise<AdapterEnvironmentCheck | null> {
|
|
const model = asString(config.model);
|
|
if (!model) return null;
|
|
|
|
const explicitProvider = asString(config.provider);
|
|
|
|
const { provider: resolved, resolvedFrom } = resolveProvider({
|
|
explicitProvider,
|
|
detectedProvider: detectedConfig?.provider,
|
|
detectedModel: detectedConfig?.model,
|
|
detectedBaseUrl: detectedConfig?.baseUrl,
|
|
detectedHasApiKey: detectedConfig?.hasApiKey,
|
|
detectedApiMode: detectedConfig?.apiMode,
|
|
model,
|
|
});
|
|
|
|
// If provider was explicitly set but doesn't match what Hermes config says,
|
|
// that's worth flagging.
|
|
if (explicitProvider && detectedConfig?.provider && explicitProvider !== detectedConfig.provider) {
|
|
return {
|
|
level: "warn",
|
|
message: `Provider mismatch: adapterConfig has "${explicitProvider}" but ~/.hermes/config.yaml has "${detectedConfig.provider}". Using adapterConfig value.`,
|
|
hint: `Model "${model}" may not work correctly with provider "${explicitProvider}". Consider aligning with your Hermes config or removing the explicit provider to use auto-detection.`,
|
|
code: "hermes_provider_mismatch",
|
|
};
|
|
}
|
|
|
|
// If Hermes config matches the requested model but uses an adapter-unsupported
|
|
// provider such as "custom", do not report a false provider inference.
|
|
if (!explicitProvider && resolvedFrom.startsWith("hermesConfigUnsupported:")) {
|
|
const unsupportedProvider = resolvedFrom.split(":", 2)[1] || detectedConfig?.provider || "unknown";
|
|
return {
|
|
level: "info",
|
|
message: `Hermes config uses unsupported adapter provider "${unsupportedProvider}" for model "${model}" — deferring to Hermes auto-detection`,
|
|
hint: "Paperclip will avoid model-name provider inference here and let Hermes resolve the provider from ~/.hermes/config.yaml at runtime.",
|
|
code: "hermes_provider_unsupported",
|
|
};
|
|
}
|
|
|
|
// If matching Hermes config provides runtime signals without an explicit provider,
|
|
// also defer to Hermes rather than inventing a provider from the model name.
|
|
if (!explicitProvider && resolvedFrom === "hermesConfigRuntime") {
|
|
return {
|
|
level: "info",
|
|
message: `Hermes config provides runtime settings for model "${model}" without an explicit adapter provider — deferring to Hermes auto-detection`,
|
|
hint: "Paperclip will avoid model-name provider inference here and let Hermes resolve the provider from ~/.hermes/config.yaml at runtime.",
|
|
code: "hermes_provider_runtime_config",
|
|
};
|
|
}
|
|
|
|
// If provider was auto-detected (not explicitly set), log what was resolved
|
|
if (!explicitProvider && resolvedFrom !== "auto") {
|
|
return {
|
|
level: "info",
|
|
message: `Provider auto-detected as "${resolved}" (from ${resolvedFrom}) for model "${model}"`,
|
|
code: "hermes_provider_detected",
|
|
};
|
|
}
|
|
|
|
// If we couldn't resolve any provider, warn
|
|
if (resolvedFrom === "auto" && !explicitProvider) {
|
|
return {
|
|
level: "warn",
|
|
message: `Could not determine provider for model "${model}" — will use Hermes auto-detection`,
|
|
hint: "Set an explicit provider in the agent config or ensure ~/.hermes/config.yaml has a matching provider for this model.",
|
|
code: "hermes_provider_unknown",
|
|
};
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Main test
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export async function testEnvironment(
|
|
ctx: AdapterEnvironmentTestContext,
|
|
): Promise<AdapterEnvironmentTestResult> {
|
|
const config = (ctx.config ?? {}) as Record<string, unknown>;
|
|
const command = resolveHermesCommand(config);
|
|
const checks: AdapterEnvironmentCheck[] = [];
|
|
|
|
// Managed connections must prove the selected destination with the isolated
|
|
// runtime environment. Host credentials and ~/.hermes are not evidence.
|
|
if (config.managedAiRouting) {
|
|
const remote = ctx.executionTarget?.kind === "remote";
|
|
if (remote) {
|
|
checks.push({ level: "error", code: "hermes_remote_probe_unsupported", message: "Hermes connection testing requires a local execution environment." });
|
|
} else {
|
|
const env = { ...process.env };
|
|
for (const [key, value] of Object.entries((config.env ?? {}) as Record<string, unknown>)) {
|
|
if (typeof value === "string") env[key] = value;
|
|
}
|
|
const args = ["chat", "-Q", "-q", "Respond with hello. Do not use tools.", "--max-turns", "1"];
|
|
if (asString(config.model)) args.push("-m", asString(config.model)!);
|
|
const provider = asString(config.provider);
|
|
if (provider && provider !== "auto") args.push("--provider", provider);
|
|
try {
|
|
const { stdout } = await execFileAsync(command, args, {
|
|
env, cwd: asString(config.cwd), timeout: 45_000, maxBuffer: 1024 * 1024,
|
|
});
|
|
if (!/\bhello\b/i.test(stdout)) throw new Error("No hello response");
|
|
checks.push({ level: "info", code: "hermes_hello_probe_passed", message: "Hermes responded through the selected connection." });
|
|
} catch {
|
|
checks.push({ level: "error", code: "hermes_hello_probe_failed", message: "Hermes could not complete a request through this connection.", hint: "Check the Hermes installation, endpoint, credential, and model, then test again." });
|
|
}
|
|
}
|
|
return { adapterType: ADAPTER_TYPE, status: checks.some(check => check.level === "error") ? "fail" : "pass", checks, testedAt: new Date().toISOString() };
|
|
}
|
|
|
|
// 1. CLI installed?
|
|
const cliCheck = await checkCliInstalled(command);
|
|
if (cliCheck) {
|
|
checks.push(cliCheck);
|
|
if (cliCheck.level === "error") {
|
|
return {
|
|
adapterType: ADAPTER_TYPE,
|
|
status: "fail",
|
|
checks,
|
|
testedAt: new Date().toISOString(),
|
|
};
|
|
}
|
|
}
|
|
|
|
// 2. CLI version
|
|
const versionCheck = await checkCliVersion(command);
|
|
if (versionCheck) checks.push(versionCheck);
|
|
|
|
// 3. Python available?
|
|
const pythonCheck = await checkPython();
|
|
if (pythonCheck) checks.push(pythonCheck);
|
|
|
|
// 4. Model config
|
|
const modelCheck = checkModel(config);
|
|
if (modelCheck) checks.push(modelCheck);
|
|
|
|
// 5. Detect Hermes config once for the remaining checks.
|
|
let detectedConfig: Awaited<ReturnType<typeof detectModel>> | null = null;
|
|
try {
|
|
detectedConfig = await detectModel();
|
|
} catch {
|
|
// Non-fatal
|
|
}
|
|
|
|
// 6. API keys (check config.env — server resolves secrets before calling us)
|
|
const apiKeyCheck = await checkApiKeys(config, detectedConfig);
|
|
if (apiKeyCheck) checks.push(apiKeyCheck);
|
|
|
|
// 7. Provider/model consistency
|
|
const providerCheck = await checkProviderConsistency(config, detectedConfig);
|
|
if (providerCheck) checks.push(providerCheck);
|
|
|
|
// Determine overall status
|
|
const hasErrors = checks.some((c) => c.level === "error");
|
|
const hasWarnings = checks.some((c) => c.level === "warn");
|
|
|
|
return {
|
|
adapterType: ADAPTER_TYPE,
|
|
status: hasErrors ? "fail" : hasWarnings ? "warn" : "pass",
|
|
checks,
|
|
testedAt: new Date().toISOString(),
|
|
};
|
|
}
|