Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (codex): unshadowed edit route + cross-tab field validation

Adam Eivycec2a05dc817
diff --git a/client/src/App.jsx b/client/src/App.jsx
index a7748492c8..19e36493f9 100644
--- a/client/src/App.jsx
+++ b/client/src/App.jsx
@@ -275,9 +275,13 @@ export default function App() {
<Route path="devtools/agents" element={<AgentsPage />} />
<Route path="ai" element={<AIProviders />} />
{/* The provider editor is a deep-linkable slide-in over the same page:
- /ai/new creates, /ai/:providerId edits. */}
+ /ai/new creates, /ai/edit/:providerId edits. The id sits under its
+ own `edit` segment rather than directly under /ai so the create
+ route can't be shadowed by a real provider: ids are slugified from
+ the display name, so a provider named "New" gets the id `new` and
+ /ai/new would otherwise match the static create route instead. */}
<Route path="ai/new" element={<AIProviders />} />
- <Route path="ai/:providerId" element={<AIProviders />} />
+ <Route path="ai/edit/:providerId" element={<AIProviders />} />
<Route path="prompts" element={<PromptManager />} />
<Route path="cos" element={<Navigate to="/cos/tasks" replace />} />
<Route path="cos/:tab" element={<ChiefOfStaff />} />
diff --git a/client/src/components/Layout.test.jsx b/client/src/components/Layout.test.jsx
index 3c2abc2046..a1c4d82e84 100644
--- a/client/src/components/Layout.test.jsx
+++ b/client/src/components/Layout.test.jsx
@@ -277,7 +277,7 @@ describe('Layout — isFullWidthRoute classification', () => {
['/story-builder', false], ['/story-builder/s1/step', true],
// AI Providers: the index AND its editor sub-routes (a drawer over the same
// page) are full-width, but a sibling path sharing the `/ai` prefix is not.
- ['/ai', true], ['/ai/new', true], ['/ai/codex', true], ['/airlock', false],
+ ['/ai', true], ['/ai/new', true], ['/ai/edit/codex', true], ['/airlock', false],
['/pipeline', false], ['/pipeline/series/s1', true],
['/local-llm', false], ['/local-llm/m', true],
// Music owns the same full-bleed title/tab/body shell as Media Gen, but
diff --git a/client/src/pages/AIProviders.jsx b/client/src/pages/AIProviders.jsx
index 154f5042fe..0faa33191d 100644
--- a/client/src/pages/AIProviders.jsx
+++ b/client/src/pages/AIProviders.jsx
@@ -61,8 +61,8 @@ export const PROVIDER_SECTIONS = [
];
// The provider editor's Drawer tabs. `connection` is the default, so a bare
-// /ai/:providerId deep link opens on the identity/transport fields; the others
-// are reachable as /ai/:providerId?providerTab=<id>.
+// /ai/edit/:providerId deep link opens on the identity/transport fields; the
+// others are reachable as /ai/edit/:providerId?providerTab=<id>.
const PROVIDER_FORM_TABS = [
{ id: 'connection', label: 'Connection' },
{ id: 'models', label: 'Models' },
@@ -71,6 +71,22 @@ const PROVIDER_FORM_TABS = [
];
const PROVIDER_FORM_TAB_IDS = PROVIDER_FORM_TABS.map(t => t.id);
+// Numeric bounds for the editor's number inputs. Declared once so an input's own
+// `min`/`max` and the submit-time check that stands in for it (the drawer
+// unmounts inactive tabs, so the browser can't validate a field the user isn't
+// looking at) can never drift apart. Mirrors the provider schema in
+// `server/lib/aiToolkit/validation.js`; `timeout` is absent because it has a
+// shared parser (`parseTimeoutMs`) that already owns its bounds.
+const PROVIDER_FIELD_RANGES = {
+ tuiPromptDelayMs: { min: 250, max: 60000 },
+ contextWindow: { min: 512, max: 2097152 },
+ numCtx: { min: 512, max: 1048576 },
+ temperature: { min: 0, max: 2 },
+};
+
+const rangeMessage = (label, { min, max }, unit = '') =>
+ `${label} must be between ${min.toLocaleString()} and ${max.toLocaleString()}${unit ? ` ${unit}` : ''}`;
+
export default function AIProviders() {
const [providers, setProviders] = useState([]);
// The CoS Agent Runner's exec allowlist, published by GET /api/providers.
@@ -117,17 +133,18 @@ export default function AIProviders() {
const localModels = useLocalModels();
// The editor is a deep-linkable slide-in over this page, so which provider is
- // open lives in the URL (/ai/new · /ai/:providerId) rather than local state —
- // the same "URL is the source of truth for what's open" rule the rest of the
- // app follows. `/ai/new` is its own static route, so `providerId` is undefined
- // there; the pathname test keeps the two apart without reserving `new` as an
- // un-editable provider id.
+ // open lives in the URL (/ai/new · /ai/edit/:providerId) rather than local
+ // state — the same "URL is the source of truth for what's open" rule the rest
+ // of the app follows. The edit id sits under its own `edit` segment because
+ // provider ids are slugified from the display name: a provider named "New"
+ // gets the id `new`, and a bare /ai/:providerId route would let the static
+ // create route shadow its editor.
const navigate = useNavigate();
const location = useLocation();
const { providerId: editingProviderId } = useParams();
const creatingProvider = location.pathname.replace(/\/+$/, '').endsWith('/ai/new');
const closeForm = useCallback(() => navigate('/ai'), [navigate]);
- const openForm = useCallback((target) => navigate(target ? `/ai/${target.id}` : '/ai/new'), [navigate]);
+ const openForm = useCallback((target) => navigate(target ? `/ai/edit/${target.id}` : '/ai/new'), [navigate]);
useEffect(() => {
loadData();
@@ -428,12 +445,12 @@ export default function AIProviders() {
};
}, [providers, statuses, activeProviderId, runtimeForProvider]);
- // Resolved only once the list has loaded, so an /ai/:providerId reload can't
+ // Resolved only once the list has loaded, so an /ai/edit/:providerId reload can't
// flash the editor in "Add Provider" mode before the record arrives. An id
// that never resolves (deleted provider, hand-edited link) bounces back to the
// list rather than leaving a blank editor open. `hasOwn` rather than a plain
- // lookup because the id comes straight off the URL: `/ai/__proto__` would
- // otherwise resolve to `Object.prototype` and open the editor on it.
+ // lookup because the id comes straight off the URL: `/ai/edit/__proto__`
+ // would otherwise resolve to `Object.prototype` and open the editor on it.
const editingProvider = editingProviderId && Object.hasOwn(providersById, editingProviderId)
? providersById[editingProviderId]
: null;
@@ -909,22 +926,66 @@ function ProviderForm({ provider, onClose, onSave, onEditProvider, allProviders
return input === '' ? undefined : Number(input);
};
+ // Every constraint the inputs themselves declare (`required`, `type="url"`,
+ // `min`/`max`), restated as a check the SUBMIT path runs. The drawer mounts
+ // only the active tab, so the browser's own constraint validation sees just
+ // that panel: a Save pressed from Models would otherwise ship an unparseable
+ // endpoint or an out-of-range num_ctx straight to the server and surface it as
+ // a generic API error with no pointer to the offending field. Returns the tab
+ // that owns the first problem plus its message, or null when the form is
+ // valid. Order matches the tab order so the user is sent to the earliest
+ // offending panel.
+ const findValidationError = () => {
+ const text = (value) => String(value ?? '').trim();
+ const outOfRange = (value, { min, max }) => {
+ const input = text(value);
+ if (input === '') return false;
+ const parsed = Number(input);
+ return !Number.isFinite(parsed) || parsed < min || parsed > max;
+ };
+
+ if (!text(formData.name)) return { tab: 'connection', message: 'Name is required' };
+ if (isProcessProvider(formData) && !text(formData.command)) {
+ return { tab: 'connection', message: 'Command is required' };
+ }
+ if (formData.type === 'api') {
+ if (!text(formData.endpoint)) return { tab: 'connection', message: 'Endpoint is required' };
+ // Mirrors the field's `type="url"` and the server's `z.string().url()`:
+ // an absolute URL with a scheme.
+ if (!URL.canParse(text(formData.endpoint))) {
+ return { tab: 'connection', message: 'Endpoint must be a full URL, e.g. http://localhost:1234/v1' };
+ }
+ }
+ if (formData.type === 'tui' && outOfRange(formData.tuiPromptDelayMs, PROVIDER_FIELD_RANGES.tuiPromptDelayMs)) {
+ return { tab: 'connection', message: rangeMessage('Prompt Paste Delay', PROVIDER_FIELD_RANGES.tuiPromptDelayMs, 'ms') };
+ }
+ if (text(formData.timeout) !== '' && parseTimeoutMs(formData.timeout) == null) {
+ return {
+ tab: 'generation',
+ message: `Timeout must be a whole number of ms between ${TIMEOUT_INPUT_MIN_MS.toLocaleString()} and ${TIMEOUT_INPUT_MAX_MS.toLocaleString()}`,
+ };
+ }
+ if (outOfRange(formData.contextWindow, PROVIDER_FIELD_RANGES.contextWindow)) {
+ return { tab: 'generation', message: rangeMessage('Planning Window', PROVIDER_FIELD_RANGES.contextWindow, 'tokens') };
+ }
+ if (showsNumCtx) {
+ if (outOfRange(formData.numCtx, PROVIDER_FIELD_RANGES.numCtx)) {
+ return { tab: 'generation', message: rangeMessage('Local num_ctx', PROVIDER_FIELD_RANGES.numCtx, 'tokens') };
+ }
+ if (outOfRange(formData.temperature, PROVIDER_FIELD_RANGES.temperature)) {
+ return { tab: 'generation', message: rangeMessage('Temperature', PROVIDER_FIELD_RANGES.temperature) };
+ }
+ }
+ return null;
+ };
+
const handleSubmit = async (e) => {
e.preventDefault();
- // The drawer renders only the active tab, so the browser's own constraint
- // validation can't block a Save triggered from another tab. Re-check the
- // Connection tab's required fields here and send the user back to them.
- const missingField = !formData.name.trim()
- ? 'Name'
- : (isProcessProvider(formData) && !formData.command.trim())
- ? 'Command'
- : (formData.type === 'api' && !formData.endpoint.trim())
- ? 'Endpoint'
- : null;
- if (missingField) {
- setActiveTab('connection');
- toast.error(`${missingField} is required`);
+ const invalid = findValidationError();
+ if (invalid) {
+ setActiveTab(invalid.tab);
+ toast.error(invalid.message);
return;
}
@@ -1090,8 +1151,8 @@ function ProviderForm({ provider, onClose, onSave, onEditProvider, allProviders
<FormField label="Prompt Paste Delay (ms)">
<input
type="number"
- min="250"
- max="60000"
+ min={PROVIDER_FIELD_RANGES.tuiPromptDelayMs.min}
+ max={PROVIDER_FIELD_RANGES.tuiPromptDelayMs.max}
value={formData.tuiPromptDelayMs}
onChange={(e) => setFormData(prev => ({ ...prev, tuiPromptDelayMs: e.target.value }))}
className="w-full px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white focus:border-port-accent focus:outline-hidden"
@@ -1406,8 +1467,8 @@ function ProviderForm({ provider, onClose, onSave, onEditProvider, allProviders
<input
type="number"
inputMode="numeric"
- min="512"
- max="2097152"
+ min={PROVIDER_FIELD_RANGES.contextWindow.min}
+ max={PROVIDER_FIELD_RANGES.contextWindow.max}
value={formData.contextWindow}
onChange={(e) => setFormData(prev => ({ ...prev, contextWindow: e.target.value }))}
placeholder="Auto from model"
@@ -1423,8 +1484,8 @@ function ProviderForm({ provider, onClose, onSave, onEditProvider, allProviders
<input
type="number"
inputMode="numeric"
- min="512"
- max="1048576"
+ min={PROVIDER_FIELD_RANGES.numCtx.min}
+ max={PROVIDER_FIELD_RANGES.numCtx.max}
value={formData.numCtx}
onChange={(e) => setFormData(prev => ({ ...prev, numCtx: e.target.value }))}
placeholder="Ollama request size"
@@ -1447,8 +1508,8 @@ function ProviderForm({ provider, onClose, onSave, onEditProvider, allProviders
<FormField label="Temperature">
<input
type="number"
- min="0"
- max="2"
+ min={PROVIDER_FIELD_RANGES.temperature.min}
+ max={PROVIDER_FIELD_RANGES.temperature.max}
step="0.1"
value={formData.temperature}
onChange={(e) => setFormData(prev => ({ ...prev, temperature: e.target.value }))}
diff --git a/client/src/pages/AIProviders.test.jsx b/client/src/pages/AIProviders.test.jsx
index a5e3351d8d..08fd60ab5f 100644
--- a/client/src/pages/AIProviders.test.jsx
+++ b/client/src/pages/AIProviders.test.jsx
@@ -48,15 +48,15 @@ import AIProviders, { PROVIDER_SECTIONS } from './AIProviders';
import { CARD_STATE_STYLES } from '../components/providers/ProviderCard';
import { PROVIDER_CARD_STATE } from '../utils/providers';
-// The editor is route-driven (/ai/new · /ai/:providerId over the same page), so
-// the tests mount the real route table rather than a bare page — clicking Edit
-// navigates, and a deep link can be rendered directly.
+// The editor is route-driven (/ai/new · /ai/edit/:providerId over the same
+// page), so the tests mount the real route table rather than a bare page —
+// clicking Edit navigates, and a deep link can be rendered directly.
const renderPage = (initialPath = '/ai') => render(
<MemoryRouter initialEntries={[initialPath]}>
<Routes>
<Route path="/ai" element={<AIProviders />} />
<Route path="/ai/new" element={<AIProviders />} />
- <Route path="/ai/:providerId" element={<AIProviders />} />
+ <Route path="/ai/edit/:providerId" element={<AIProviders />} />
</Routes>
</MemoryRouter>
);
@@ -646,7 +646,7 @@ describe('provider editor deep links', () => {
});
it('opens the editor for the provider named in the URL', async () => {
- renderPage('/ai/codex');
+ renderPage('/ai/edit/codex');
expect(await screen.findByRole('heading', { name: 'Edit Provider' })).toBeInTheDocument();
expect(screen.getByDisplayValue('Codex')).toBeInTheDocument();
@@ -662,7 +662,7 @@ describe('provider editor deep links', () => {
// A deleted/hand-edited id must bounce back to the list rather than leaving a
// blank editor open over it.
it('sends an unknown provider id back to the list', async () => {
- renderPage('/ai/does-not-exist');
+ renderPage('/ai/edit/does-not-exist');
await waitFor(() => expect(toast.error).toHaveBeenCalledWith('No provider with id "does-not-exist"'));
expect(screen.queryByRole('heading', { name: 'Edit Provider' })).toBeNull();
@@ -671,14 +671,14 @@ describe('provider editor deep links', () => {
// The id comes off the URL, so a prototype key must not resolve to
// Object.prototype and open the editor on it.
it('does not open the editor for a prototype-chain id', async () => {
- renderPage('/ai/__proto__');
+ renderPage('/ai/edit/__proto__');
await waitFor(() => expect(toast.error).toHaveBeenCalledWith('No provider with id "__proto__"'));
expect(screen.queryByRole('heading', { name: 'Edit Provider' })).toBeNull();
});
it('honors the ?providerTab deep link', async () => {
- renderPage('/ai/codex?providerTab=models');
+ renderPage('/ai/edit/codex?providerTab=models');
expect(await screen.findByLabelText('Default Model')).toBeInTheDocument();
expect(screen.getByRole('tab', { name: 'Models' })).toHaveAttribute('aria-selected', 'true');
@@ -687,7 +687,7 @@ describe('provider editor deep links', () => {
// Only the active tab renders, so the browser can't run its own required-field
// check for a Save triggered from another tab.
it('sends the user back to the field a cross-tab Save left empty', async () => {
- renderPage('/ai/codex');
+ renderPage('/ai/edit/codex');
fireEvent.change(await screen.findByDisplayValue('Codex'), { target: { value: ' ' } });
await openEditorTab('Models');
@@ -699,8 +699,43 @@ describe('provider editor deep links', () => {
expect(screen.getByRole('tab', { name: 'Connection' })).toHaveAttribute('aria-selected', 'true');
});
+ // A provider whose display name slugifies to `new` must still be editable —
+ // the create route would shadow it if the edit id sat directly under /ai.
+ it('edits a provider whose id collides with the create route', async () => {
+ api.getProviders.mockResolvedValue({
+ providers: [{ ...provider, id: 'new', name: 'New' }],
+ activeProvider: 'new',
+ });
+
+ renderPage('/ai/edit/new');
+
+ expect(await screen.findByRole('heading', { name: 'Edit Provider' })).toBeInTheDocument();
+ expect(screen.getByDisplayValue('New')).toBeInTheDocument();
+ });
+
+ // The inputs' own `min`/`max`/`type="url"` only run for the mounted tab, so
+ // the submit path restates them and points at the tab that owns the field.
+ it.each([
+ ['an unparseable endpoint', { type: 'api', endpoint: 'not-a-url', command: '' }, 'Endpoint must be a full URL, e.g. http://localhost:1234/v1', 'Connection'],
+ ['an out-of-range planning window', { contextWindow: 1 }, 'Planning Window must be between 512 and 2,097,152 tokens', 'Generation'],
+ ])('blocks a cross-tab Save with %s', async (_label, patch, message, tab) => {
+ api.getProviders.mockResolvedValue({
+ providers: [{ ...provider, ...patch }],
+ activeProvider: 'codex',
+ });
+
+ renderPage('/ai/edit/codex?providerTab=models');
+
+ await screen.findByLabelText('Default Model');
+ fireEvent.click(screen.getByRole('button', { name: 'Save' }));
+
+ await waitFor(() => expect(toast.error).toHaveBeenCalledWith(message));
+ expect(api.updateProvider).not.toHaveBeenCalled();
+ expect(screen.getByRole('tab', { name: tab })).toHaveAttribute('aria-selected', 'true');
+ });
+
it('closes back to the list', async () => {
- renderPage('/ai/codex');
+ renderPage('/ai/edit/codex');
fireEvent.click(await screen.findByRole('button', { name: 'Cancel' }));