Files
openclaw/ui/src/lib/model-auth.ts
Peter Steinberger d5a8233e76 feat(gateway,ui): agent-scoped model provider credentials (#111796)
* feat: scope model provider credentials by agent

* fix: reject unknown model auth agent ids

* fix: discard stale model provider preload

* fix(gateway): reject whitespace-only explicit agent ids

* fix: scope model provider probes by agent

* fix: complete model provider agent scoping

* fix(ui): always clear the providers refresh flag on completion

* fix(ui): keep probe epochs monotonic across agent switches

* fix: derive agent scope for provider aborts

* fix: satisfy model provider CI checks
2026-07-20 16:22:09 -07:00

44 lines
1.6 KiB
TypeScript

// Control UI module implements model auth behavior.
import type { GatewayBrowserClient } from "../api/gateway.ts";
import type { ModelAuthStatusProvider, ModelAuthStatusResult } from "../api/types.ts";
const EMPTY_AUTH_STATUS: ModelAuthStatusResult = { ts: 0, providers: [] };
/**
* True when a provider's auth should be actively monitored on the dashboard.
*
* Includes:
* - Providers with at least one OAuth or bearer-token profile (refreshable
* credentials that can expire and need rotation)
* - Providers with status="missing" (configured-but-not-logged-in — the
* server synthesizes these so the UI can prompt for login)
*
* Excludes API-key-only providers — their credentials don't expire on a
* schedule the dashboard can meaningfully monitor.
*
* Single source of truth for the chat composer and the sidebar attention
* chips. Keep consumers in sync by always routing through this helper.
*/
export function isMonitoredAuthProvider(p: ModelAuthStatusProvider): boolean {
if (p.status === "missing") {
return true;
}
if (!Array.isArray(p.profiles)) {
return false;
}
return p.profiles.some((prof) => prof.type === "oauth" || prof.type === "token");
}
export async function loadModelAuthStatus(
client: GatewayBrowserClient,
opts?: { refresh?: boolean; agentId?: string },
): Promise<ModelAuthStatusResult> {
const params = {
...(opts?.refresh ? { refresh: true } : {}),
...(opts?.agentId ? { agentId: opts.agentId } : {}),
};
return (
(await client.request<ModelAuthStatusResult>("models.authStatus", params)) ?? EMPTY_AUTH_STATUS
);
}