Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
feat(credentials): add and manage endpoints in the Credentials panel
trohitga305d89604e1
diff --git a/client/src/components/credentials/catalogueAdapter.ts b/client/src/components/credentials/catalogueAdapter.tsindex 2df94c13..ef58676a 100644--- a/client/src/components/credentials/catalogueAdapter.ts+++ b/client/src/components/credentials/catalogueAdapter.ts@@ -176,6 +176,7 @@ export function rehydrateProvider(entry: ServerProviderConfig): ProviderConfig {usageService: entry.usage_service,stored: entry.stored,account_label: entry.account_label ?? null,+ endpoints: entry.endpoints,};}diff --git a/client/src/components/credentials/panels/ApiKeyPanel.tsx b/client/src/components/credentials/panels/ApiKeyPanel.tsxindex feb7ad68..23e28ba1 100644--- a/client/src/components/credentials/panels/ApiKeyPanel.tsx+++ b/client/src/components/credentials/panels/ApiKeyPanel.tsx@@ -17,7 +17,9 @@ import { useCredentialPanel } from '../useCredentialPanel';import { ProviderDefaultsSection, LlmUsageSection, ApiUsageSection } from '../sections';import { NodeIcon } from '../../../assets/icons';import { theme } from '../../../styles/theme';+import type { ServerEndpointSummary } from '@/hooks/useCatalogueQuery';import type { ProviderConfig } from '../types';+import EndpointList from './EndpointList';const ApiKeyPanel: React.FC<{ config: ProviderConfig; visible: boolean }> = ({ config, visible }) => {const panel = useCredentialPanel(config, visible);@@ -33,9 +35,40 @@ const ApiKeyPanel: React.FC<{ config: ProviderConfig; visible: boolean }> = ({ c// Reactive — when the query resolves the input re-renders. No// separate useState/useEffect mirror.const inputValue = field ? (panel.values[field.key] ?? '') : '';- // ``validated`` mirrors panel.stored (real server state). Pre-filled- // catalogue defaults do NOT flip it to true.- const validated = panel.stored;+ // A provider that holds several rows (named OpenAI-compatible endpoints)+ // gets them from the catalogue, and its fields become a form adding one.+ const endpoints = config.endpoints;+ // ``validated`` mirrors real server state: panel.stored, or for a+ // several-row provider the catalogue's own flag. Pre-filled catalogue+ // defaults do NOT flip it to true.+ const validated = endpoints ? Boolean(config.stored) : panel.stored;+ const busy = panel.loading !== null;++ // Every field goes out under its catalogue key; the backend Credential+ // decides what each means. A rejected save carries its reason in+ // `message`, which the generic executor does not surface on its own.+ const addEndpoint = async () => {+ const res = await panel.actions.sendWs('validate_api_key', {+ provider: config.id,+ api_key: inputValue.trim(),+ ...Object.fromEntries(secondaryFields.map((sf) => [sf.key, String(panel.values[sf.key] ?? '').trim()])),+ });+ if (res?.valid) {+ for (const f of config.fields ?? []) panel.form.setFieldValue(f.key, '');+ } else if (res?.message) {+ panel.setError(res.message);+ }+ };+ const refreshEndpoint = async (endpoint: ServerEndpointSummary) => {+ const res = await panel.actions.sendWs('validate_api_key', {+ provider: config.id,+ api_key: endpoint.base_url || endpoint.ref,+ ref: endpoint.ref,+ });+ if (res && !res.valid && res.message) panel.setError(res.message);+ };+ const removeEndpoint = (endpoint: ServerEndpointSummary) =>+ panel.actions.sendWs('delete_api_key', { provider: endpoint.ref });return (<div className="flex flex-col gap-5 p-5">@@ -70,7 +103,10 @@ const ApiKeyPanel: React.FC<{ config: ProviderConfig; visible: boolean }> = ({ c)}</CardHeader><CardContent>- {field && (+ {endpoints && config.instructions && (+ <p className="text-xs text-muted-foreground">{config.instructions}</p>+ )}+ {field && !endpoints && (<ApiKeyInputvalue={inputValue}onChange={(v) => panel.form.setFieldValue(field.key, v)}@@ -100,7 +136,7 @@ const ApiKeyPanel: React.FC<{ config: ProviderConfig; visible: boolean }> = ({ csavedLabel={field.key === 'apiKey' ? 'Valid' : 'Connected'}/>)}- {field?.help && (+ {field?.help && !endpoints && (<p className="mt-2 text-xs text-muted-foreground">{field.help}</p>)}</CardContent>@@ -117,7 +153,7 @@ const ApiKeyPanel: React.FC<{ config: ProviderConfig; visible: boolean }> = ({ cpath because these are operator metadata, not credentialsto probe upstream. Save writes via the same auth_servicepath the primary uses (panel.actions.save). */}- {secondaryFields.map((sf) => (+ {(endpoints ? config.fields ?? [] : secondaryFields).map((sf) => (<SecondaryFieldRowkey={sf.key}fieldKey={sf.key}@@ -127,11 +163,22 @@ const ApiKeyPanel: React.FC<{ config: ProviderConfig; visible: boolean }> = ({ csecret={sf.secret}value={panel.values[sf.key] ?? ''}onChange={(v) => panel.form.setFieldValue(sf.key, v)}- onSave={() => panel.actions.save(sf.key, panel.values[sf.key] ?? '')}+ onSave={endpoints ? undefined : () => panel.actions.save(sf.key, panel.values[sf.key] ?? '')}loading={panel.loading === 'save'}/>))}+ {endpoints && (+ <>+ <div className="flex justify-end">+ <ActionButton intent="save" onClick={addEndpoint} disabled={busy || !inputValue.trim()}>+ Add endpoint+ </ActionButton>+ </div>+ <EndpointList endpoints={endpoints} busy={busy} onRefresh={refreshEndpoint} onRemove={removeEndpoint} />+ </>+ )}+{config.hasDefaults && <ProviderDefaultsSection providerId={config.id} />}{config.hasDefaults && <LlmUsageSection providerId={config.id} providerName={config.name} />}{config.usageService && <ApiUsageSection service={config.usageService} serviceName={config.name} />}@@ -147,7 +194,8 @@ interface SecondaryFieldRowProps {secret?: boolean;value: string;onChange: (v: string) => void;- onSave: () => void;+ /** Absent for a field of an add-row form, which is submitted as a whole. */+ onSave?: () => void;loading: boolean;}@@ -172,13 +220,15 @@ const SecondaryFieldRow: React.FC<SecondaryFieldRowProps> = ({placeholder={placeholder}className="flex-1"/>- <ActionButton- intent="save"- onClick={onSave}- disabled={loading}- >- Save- </ActionButton>+ {onSave && (+ <ActionButton+ intent="save"+ onClick={onSave}+ disabled={loading}+ >+ Save+ </ActionButton>+ )}</div>{help && (<p className="text-xs text-muted-foreground">{help}</p>diff --git a/client/src/components/credentials/panels/EndpointList.tsx b/client/src/components/credentials/panels/EndpointList.tsxnew file mode 100644index 00000000..919cfd9f--- /dev/null+++ b/client/src/components/credentials/panels/EndpointList.tsx@@ -0,0 +1,63 @@+/**+ * EndpointList — the saved rows of a provider that holds several (named+ * OpenAI-compatible endpoints). Stateless: rows come from the catalogue,+ * which the backend refreshes after every add, refresh and remove, and the+ * `base_url` it shows is already redacted server-side.+ */++import React from 'react';+import { RefreshCw, Trash2 } from 'lucide-react';++import { Card, CardContent } from '@/components/ui/card';+import { Badge } from '@/components/ui/badge';+import { ActionButton } from '@/components/ui/action-button';+import type { ServerEndpointSummary } from '@/hooks/useCatalogueQuery';++interface EndpointListProps {+ endpoints: ServerEndpointSummary[];+ busy: boolean;+ onRefresh: (endpoint: ServerEndpointSummary) => void;+ onRemove: (endpoint: ServerEndpointSummary) => void;+}++const EndpointList: React.FC<EndpointListProps> = ({ endpoints, busy, onRefresh, onRemove }) => {+ if (endpoints.length === 0) {+ return <p className="text-sm text-muted-foreground">No endpoints saved yet.</p>;+ }+ return (+ <div className="flex flex-col gap-2">+ {endpoints.map((endpoint) => (+ <Card key={endpoint.ref}>+ <CardContent className="flex items-center gap-3 pt-4">+ <div className="flex min-w-0 flex-1 flex-col gap-1">+ <span className="truncate text-sm font-medium">{endpoint.label}</span>+ <span className="truncate font-mono text-xs text-muted-foreground">{endpoint.base_url}</span>+ </div>+ <Badge variant="secondary">{endpoint.kind}</Badge>+ <Badge variant="outline">+ {endpoint.model_count} {endpoint.model_count === 1 ? 'model' : 'models'}+ </Badge>+ <ActionButton+ intent="config"+ onClick={() => onRefresh(endpoint)}+ disabled={busy}+ aria-label={`Refresh ${endpoint.label}`}+ >+ <RefreshCw className="h-3.5 w-3.5" />+ </ActionButton>+ <ActionButton+ intent="stop"+ onClick={() => onRemove(endpoint)}+ disabled={busy}+ aria-label={`Remove ${endpoint.label}`}+ >+ <Trash2 className="h-3.5 w-3.5" />+ </ActionButton>+ </CardContent>+ </Card>+ ))}+ </div>+ );+};++export default EndpointList;diff --git a/client/src/components/credentials/panels/__tests__/EndpointList.test.tsx b/client/src/components/credentials/panels/__tests__/EndpointList.test.tsxnew file mode 100644index 00000000..b5fc220b--- /dev/null+++ b/client/src/components/credentials/panels/__tests__/EndpointList.test.tsx@@ -0,0 +1,63 @@+/**+ * EndpointList renders the saved rows the catalogue sends and hands the+ * clicked row back; it owns no state and builds no request itself.+ */++import { describe, it, expect, vi } from 'vitest';+import { render, screen } from '@testing-library/react';+import userEvent from '@testing-library/user-event';++import EndpointList from '../EndpointList';+import type { ServerEndpointSummary } from '@/hooks/useCatalogueQuery';++const HOME: ServerEndpointSummary = {+ ref: 'openai_compatible:home-vllm',+ label: 'Home vLLM',+ base_url: 'http://host:8000/v1',+ kind: 'generic',+ model_count: 2,+};+const LAB: ServerEndpointSummary = {+ ref: 'openai_compatible:lab',+ label: 'Lab',+ base_url: 'http://lab:8080',+ kind: 'llamacpp',+ model_count: 1,+};++describe('EndpointList', () => {+ it('renders one row per saved endpoint', () => {+ render(<EndpointList endpoints={[HOME, LAB]} busy={false} onRefresh={vi.fn()} onRemove={vi.fn()} />);++ expect(screen.getByText('Home vLLM')).toBeTruthy();+ expect(screen.getByText('http://host:8000/v1')).toBeTruthy();+ expect(screen.getByText('llamacpp')).toBeTruthy();+ expect(screen.getByText('2 models')).toBeTruthy();+ expect(screen.getByText('1 model')).toBeTruthy();+ });++ it('hands the clicked row back for refresh and remove', async () => {+ const onRefresh = vi.fn();+ const onRemove = vi.fn();+ render(<EndpointList endpoints={[HOME, LAB]} busy={false} onRefresh={onRefresh} onRemove={onRemove} />);++ await userEvent.click(screen.getByRole('button', { name: 'Refresh Lab' }));+ await userEvent.click(screen.getByRole('button', { name: 'Remove Home vLLM' }));++ expect(onRefresh).toHaveBeenCalledWith(LAB);+ expect(onRemove).toHaveBeenCalledWith(HOME);+ });++ it('disables its actions while a request is in flight', () => {+ render(<EndpointList endpoints={[HOME]} busy onRefresh={vi.fn()} onRemove={vi.fn()} />);++ expect((screen.getByRole('button', { name: 'Refresh Home vLLM' }) as HTMLButtonElement).disabled).toBe(true);+ expect((screen.getByRole('button', { name: 'Remove Home vLLM' }) as HTMLButtonElement).disabled).toBe(true);+ });++ it('says so when nothing is saved', () => {+ render(<EndpointList endpoints={[]} busy={false} onRefresh={vi.fn()} onRemove={vi.fn()} />);++ expect(screen.getByText('No endpoints saved yet.')).toBeTruthy();+ });+});diff --git a/client/src/components/credentials/types.ts b/client/src/components/credentials/types.tsindex 4d7ee506..c914a9a9 100644--- a/client/src/components/credentials/types.ts+++ b/client/src/components/credentials/types.ts@@ -5,6 +5,7 @@*/import type { ActionButtonIntent } from '@/components/ui/action-button';+import type { ServerEndpointSummary } from '@/hooks/useCatalogueQuery';export type { ActionButtonIntent };// ============================================================================@@ -127,6 +128,10 @@ export interface ProviderConfig {stored?: boolean;/** Connected account identifier (email or display name) for OAuth providers. */account_label?: string | null;+ /** Saved rows of a provider that holds several (named OpenAI-compatible+ * endpoints). Present only for such providers; the panel then adds rows+ * instead of storing one value. */+ endpoints?: ServerEndpointSummary[];}// ============================================================================diff --git a/client/src/hooks/useCatalogueQuery.ts b/client/src/hooks/useCatalogueQuery.tsindex 48405540..fae1906a 100644--- a/client/src/hooks/useCatalogueQuery.ts+++ b/client/src/hooks/useCatalogueQuery.ts@@ -91,6 +91,17 @@ export interface ServerQrDef {scan_text: string;}+/** One saved row of a provider that holds several (named OpenAI-compatible+ * endpoints). `ref` is the provider reference agents select; `base_url`+ * is already redacted server-side. */+export interface ServerEndpointSummary {+ ref: string;+ label: string;+ base_url: string;+ kind: string;+ model_count: number;+}+/** One entry as it appears in the `providers` array of the catalogue response. */export interface ServerProviderConfig {id: string;@@ -118,6 +129,8 @@ export interface ServerProviderConfig {stored?: boolean;/** Connected account identifier (email or display name) for OAuth providers. */account_label?: string | null;+ /** Saved rows, for a provider that holds several (server-resolved). */+ endpoints?: ServerEndpointSummary[];}export interface CatalogueResponse {