Skip to content

Self-improving AI Employees for everyone

feat(credentials): backend-driven default values pre-fill local-LLM Base URL

trohitgb65bbdaf01c7
diff --git a/client/src/components/credentials/catalogueAdapter.ts b/client/src/components/credentials/catalogueAdapter.ts
index 5f16a505..cb52cfd3 100644
--- a/client/src/components/credentials/catalogueAdapter.ts
+++ b/client/src/components/credentials/catalogueAdapter.ts
@@ -141,6 +141,7 @@ function buildFields(defs: ServerFieldDef[] | undefined): FieldDef[] | undefined
label: d.label ?? d.key,
secret: d.secret ?? d.type === 'password',
placeholder: d.placeholder,
+ default: d.default,
required: d.required,
}));
}
diff --git a/client/src/components/credentials/panels/ApiKeyPanel.tsx b/client/src/components/credentials/panels/ApiKeyPanel.tsx
index 42ca287b..896a795b 100644
--- a/client/src/components/credentials/panels/ApiKeyPanel.tsx
+++ b/client/src/components/credentials/panels/ApiKeyPanel.tsx
@@ -24,14 +24,16 @@ const ApiKeyPanel: React.FC<{ config: ProviderConfig; visible: boolean }> = ({ c
// Completely independent from useCredentialPanel's stored state.
const [validated, setValidated] = useState(panel.stored);
- // Sync from the form when stored credentials load
+ // Sync the input from the form. The form value may be a stored
+ // credential OR the backend-served catalogue default (e.g.
+ // local-LLM canonical Base URL); either way we render it.
+ // ``validated`` stays tied to ``panel.stored`` (real server state)
+ // so a pre-filled default doesn't flip the connected badge on.
useEffect(() => {
- if (panel.stored && field) {
+ if (field) {
const v = panel.form.getFieldValue(field.key);
- if (v) {
- setInputValue(v);
- setValidated(true);
- }
+ if (v) setInputValue(v);
+ setValidated(panel.stored);
}
}, [panel.stored, field, panel.form]);
diff --git a/client/src/components/credentials/types.ts b/client/src/components/credentials/types.ts
index a4952f7e..cdde662a 100644
--- a/client/src/components/credentials/types.ts
+++ b/client/src/components/credentials/types.ts
@@ -22,6 +22,8 @@ export interface FieldDef {
label: string;
secret?: boolean;
placeholder?: string;
+ /** Pre-fill value when nothing stored. See ServerFieldDef.default. */
+ default?: string;
required?: boolean;
}
diff --git a/client/src/components/credentials/useCredentialPanel.ts b/client/src/components/credentials/useCredentialPanel.ts
index df24dfee..29e1b878 100644
--- a/client/src/components/credentials/useCredentialPanel.ts
+++ b/client/src/components/credentials/useCredentialPanel.ts
@@ -45,40 +45,48 @@ export function useCredentialPanel(config: ProviderConfig, visible: boolean) {
}, [config.id]);
const {
- validateApiKey, saveApiKey, getStoredApiKey, hasStoredKey, removeApiKey,
+ validateApiKey, saveApiKey, removeApiKey,
getProviderDefaults, saveProviderDefaults,
getProviderUsageSummary, getAPIUsageSummary, getStoredModels, getModelConstraints,
isConnected,
} = useApiKeys();
const { sendRequest } = useWebSocket();
- // Server-cached credential values. Fields load in parallel via
- // Promise.all so a 3-field provider takes one WS round-trip instead
- // of six sequential ones.
- const credentialValuesQuery = useQuery<CredentialFormValues, Error>({
+ // Server-cached credential values. Single RPC per field consolidates
+ // the previous hasStoredKey + getStoredApiKey pair (both went to
+ // ``get_stored_api_key`` anyway). The handler returns
+ // ``{hasKey, apiKey?}``; ``apiKey`` may carry the catalogue's
+ // ``default`` (e.g. local-LLM canonical Base URL) even when
+ // ``hasKey: false``, so the form renders a sensible value on a fresh
+ // install. ``hadStored`` tracks the real server state separately so
+ // the validated/connected badge stays honest — pre-filled defaults
+ // do NOT flip it to true.
+ const credentialValuesQuery = useQuery<{ values: CredentialFormValues; hadStored: boolean }, Error>({
queryKey: queryKeys.credentialValues.byProvider(config.id).queryKey,
queryFn: async () => {
- if (!config.fields) return EMPTY_VALUES;
- const entries = await Promise.all(
+ if (!config.fields) return { values: EMPTY_VALUES, hadStored: false };
+ const results = await Promise.all(
config.fields.map(async (field) => {
const storeKey = field.key === 'apiKey' ? config.id : field.key;
- const has = await hasStoredKey(storeKey);
- if (!has) return null;
- const val = await getStoredApiKey(storeKey);
- return val ? ([field.key, val] as const) : null;
+ const r = await sendRequest<{ hasKey: boolean; apiKey?: string }>(
+ 'get_stored_api_key', { provider: storeKey },
+ );
+ return { key: field.key, hasKey: r.hasKey, apiKey: r.apiKey };
}),
);
const next: CredentialFormValues = {};
- for (const entry of entries) {
- if (entry) next[entry[0]] = entry[1];
+ let hadStored = false;
+ for (const r of results) {
+ if (r.apiKey) next[r.key] = r.apiKey;
+ if (r.hasKey) hadStored = true;
}
- return next;
+ return { values: next, hadStored };
},
enabled: visible && isConnected && !!config.fields,
staleTime: STALE_TIME.FOREVER,
});
- const values = credentialValuesQuery.data ?? EMPTY_VALUES;
+ const values = credentialValuesQuery.data?.values ?? EMPTY_VALUES;
// Imperative form-like API kept for compat with existing panel code.
// Writes go through setQueryData on the provider's query so the cache
@@ -118,8 +126,12 @@ export function useCredentialPanel(config: ProviderConfig, visible: boolean) {
);
// Sync stored from query on first load — if the backend already has
- // a key, mark stored=true so the badge renders without a validate click.
- const queriedStored = Object.keys(values).length > 0;
+ // mark stored=true based on the real server state (`hadStored`),
+ // NOT on whether the form happens to be populated. Pre-filled
+ // catalogue defaults (e.g. local-LLM Base URL) populate the form
+ // without being saved, so deriving from `Object.keys(values).length`
+ // would prematurely show the connected badge.
+ const queriedStored = credentialValuesQuery.data?.hadStored ?? false;
if (queriedStored && !stored) setStored(true);
// Generic action executor — replaces 19 duplicate handler functions.
diff --git a/client/src/hooks/useCatalogueQuery.ts b/client/src/hooks/useCatalogueQuery.ts
index 3a9e19e9..c94b8e59 100644
--- a/client/src/hooks/useCatalogueQuery.ts
+++ b/client/src/hooks/useCatalogueQuery.ts
@@ -45,6 +45,12 @@ export interface ServerFieldDef {
type?: 'string' | 'password';
secret?: boolean;
placeholder?: string;
+ /** Initial value pre-populated when the user has nothing stored yet
+ (e.g. canonical local-LLM Base URL — http://localhost:1234/v1).
+ Distinct from `placeholder`: placeholder is a UI ghost-text hint;
+ default actually fills the field so the user can click Fetch
+ without typing. */
+ default?: string;
required?: boolean;
}
diff --git a/server/config/credential_providers.json b/server/config/credential_providers.json
index 6ffac207..a28fe86e 100644
--- a/server/config/credential_providers.json
+++ b/server/config/credential_providers.json
@@ -130,6 +130,7 @@
"label": "Base URL",
"type": "string",
"placeholder": "http://localhost:11434/v1",
+ "default": "http://localhost:11434/v1",
"required": true
}
],
@@ -151,6 +152,7 @@
"label": "Base URL",
"type": "string",
"placeholder": "http://localhost:1234/v1",
+ "default": "http://localhost:1234/v1",
"required": true
}
],
diff --git a/server/routers/websocket.py b/server/routers/websocket.py
index 17912c6a..4f4ba45f 100644
--- a/server/routers/websocket.py
+++ b/server/routers/websocket.py
@@ -1261,6 +1261,33 @@ async def handle_validate_api_key(data: Dict[str, Any], websocket: WebSocket) ->
return await cred_cls.validate(normalized)
+def _lookup_credential_default(storage_key: str) -> Optional[str]:
+ """Look up a field's catalogue ``default`` for the given storage key.
+
+ Storage keys are either the provider id (``"openai"`` for cloud
+ providers whose field key is ``apiKey``) or the field key itself
+ (``"lmstudio_proxy"`` etc. for local-LLM providers). Both shapes
+ map back to a credential_providers.json field; this helper finds
+ the one and returns its ``default`` value if declared. Used by
+ ``handle_get_stored_api_key`` to surface canonical defaults
+ (e.g. local-LLM Base URL ``http://localhost:1234/v1``) to the
+ frontend without requiring per-panel pre-fill logic.
+ """
+ from services.credential_registry import get_credential_registry
+ registry = get_credential_registry()
+ for provider in registry.get_all_providers():
+ provider_id = provider.get("id") or provider.get("name", "").lower()
+ for field in (provider.get("fields") or []):
+ field_key = field.get("key")
+ if not field_key:
+ continue
+ field_storage_key = provider_id if field_key == "apiKey" else field_key
+ if field_storage_key == storage_key:
+ default = field.get("default")
+ return default if default else None
+ return None
+
+
@ws_handler("provider")
async def handle_get_stored_api_key(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
"""Get stored API key for a provider.
@@ -1269,11 +1296,21 @@ async def handle_get_stored_api_key(data: Dict[str, Any], websocket: WebSocket)
``update_api_key_status`` broadcast shape — every WS payload the
frontend receives for API key state uses the same convention, so no
per-field adapter is needed on the TypeScript side.
+
+ When nothing is stored AND the catalogue declares a ``default``
+ for this field (e.g. local-LLM canonical Base URL), the default
+ value is returned in ``apiKey`` with ``hasKey: false``. The
+ frontend renders the value but tracks ``stored`` separately via
+ ``hasKey`` so the validated/connected badge stays honest. Lets
+ users click Fetch on a fresh install without retyping the URL.
"""
auth_service = container.auth_service()
provider = data["provider"].lower()
api_key = await auth_service.get_api_key(provider, data.get("session_id", "default"))
if not api_key:
+ default = _lookup_credential_default(provider)
+ if default is not None:
+ return {"provider": provider, "hasKey": False, "apiKey": default}
return {"provider": provider, "hasKey": False}
models = await auth_service.get_stored_models(provider, data.get("session_id", "default"))
return {"provider": provider, "hasKey": True, "apiKey": api_key, "models": models, "timestamp": time.time()}