Skip to content

The open-source agent harness - the runtime layer that turns an LLM into a working agent.

Fix: don't error the auto-derived Model name in the custom provider form (#189)

shubhamagarwal-create8cb9f23bba09
diff --git a/packages/trueforge-ui-sdk/src/containers/SettingsBuilder/CustomModelProviderForm.tsx b/packages/trueforge-ui-sdk/src/containers/SettingsBuilder/CustomModelProviderForm.tsx
index 2659f4532..445c22df0 100644
--- a/packages/trueforge-ui-sdk/src/containers/SettingsBuilder/CustomModelProviderForm.tsx
+++ b/packages/trueforge-ui-sdk/src/containers/SettingsBuilder/CustomModelProviderForm.tsx
@@ -53,7 +53,9 @@ const PLACEHOLDER_MAX_OUTPUT_TOKENS = '4096';
const createEmptyModelRow = (): ModelRow => ({
id: '',
name: '',
- advancedExpanded: false,
+ // Expanded by default: Context length and Max output tokens are required, so they
+ // shouldn't be hidden behind a collapsed section.
+ advancedExpanded: true,
contextLength: '',
maxOutputTokens: '',
});
@@ -199,7 +201,8 @@ const CustomModelProviderForm = ({
const field = target && modelContextError(target) ? 'context-length' : 'max-output-tokens';
setTimeout(() => {
const el = document.getElementById(`custom-provider-model-${incompleteIndex}-${field}`);
- el?.scrollIntoView({ block: 'center', behavior: 'smooth' });
+ // scrollIntoView is unimplemented in jsdom; guard the method so tests don't throw.
+ el?.scrollIntoView?.({ block: 'center', behavior: 'smooth' });
(el as HTMLInputElement | null)?.focus();
}, 0);
return;
@@ -316,11 +319,10 @@ const CustomModelProviderForm = ({
const idError = modelIdError(model);
const showIdError = model.idTouched && idError;
const nameFieldError = modelNameError(model);
- // Surface auto-derived name problems as soon as there is a Model ID: the name is
- // derived from it, so a bad slug must show without waiting for a blur or submit
- // (the submit button can be disabled, so those triggers may never fire). When the
- // id is empty the id's own "required" error covers it, so we don't double up here.
- const showNameFieldError = (model.id.trim() !== '' || model.nameDirty) && nameFieldError;
+ // The Model name is auto-derived from the Model ID and is editable. Never flag an
+ // auto-derived value: if the id yields no usable name, stay silent and let the user
+ // type one. Only surface an error once they have hand-edited the name themselves.
+ const showNameFieldError = !!nameFieldError && model.nameDirty;
const contextError = modelContextError(model);
const maxError = modelMaxOutputError(model);
const showContextError = model.contextTouched && contextError;
@@ -405,6 +407,60 @@ const CustomModelProviderForm = ({
{model.advancedExpanded ? (
<div id={`custom-provider-model-${index}-advanced`} className="mt-3 space-y-4 pl-6">
+ <div>
+ <label
+ htmlFor={`custom-provider-model-${index}-context-length`}
+ className="mb-1.5 block text-xs font-medium text-muted-foreground"
+ >
+ Context length
+ <RequiredMark />
+ </label>
+ <input
+ id={`custom-provider-model-${index}-context-length`}
+ type="number"
+ min={1}
+ inputMode="numeric"
+ value={model.contextLength}
+ onChange={event => updateModel(index, { contextLength: event.target.value })}
+ onBlur={() => updateModel(index, { contextTouched: true })}
+ placeholder={PLACEHOLDER_CONTEXT_LENGTH}
+ aria-invalid={showContextError ? true : undefined}
+ className={cn(inputClassName, showContextError && inputErrorClassName)}
+ />
+ {showContextError ? (
+ <FieldError>{contextError}</FieldError>
+ ) : model.contextLength.trim() === '' ? (
+ <FieldHelp>Prevents the context window from overflowing during a run.</FieldHelp>
+ ) : null}
+ </div>
+
+ <div>
+ <label
+ htmlFor={`custom-provider-model-${index}-max-output-tokens`}
+ className="mb-1.5 block text-xs font-medium text-muted-foreground"
+ >
+ Max output tokens
+ <RequiredMark />
+ </label>
+ <input
+ id={`custom-provider-model-${index}-max-output-tokens`}
+ type="number"
+ min={1}
+ inputMode="numeric"
+ value={model.maxOutputTokens}
+ onChange={event => updateModel(index, { maxOutputTokens: event.target.value })}
+ onBlur={() => updateModel(index, { maxTouched: true })}
+ placeholder={PLACEHOLDER_MAX_OUTPUT_TOKENS}
+ aria-invalid={showMaxError ? true : undefined}
+ className={cn(inputClassName, showMaxError && inputErrorClassName)}
+ />
+ {showMaxError ? (
+ <FieldError>{maxError}</FieldError>
+ ) : model.maxOutputTokens.trim() === '' ? (
+ <FieldHelp>Caps tokens per model call.</FieldHelp>
+ ) : null}
+ </div>
+
{reasoningEffortOptions && reasoningEffortOptions.length > 0 ? (
<div>
<div className="flex items-center justify-between gap-3">
@@ -471,60 +527,6 @@ const CustomModelProviderForm = ({
) : null}
</div>
) : null}
-
- <div>
- <label
- htmlFor={`custom-provider-model-${index}-context-length`}
- className="mb-1.5 block text-xs font-medium text-muted-foreground"
- >
- Context length
- <RequiredMark />
- </label>
- <input
- id={`custom-provider-model-${index}-context-length`}
- type="number"
- min={1}
- inputMode="numeric"
- value={model.contextLength}
- onChange={event => updateModel(index, { contextLength: event.target.value })}
- onBlur={() => updateModel(index, { contextTouched: true })}
- placeholder={PLACEHOLDER_CONTEXT_LENGTH}
- aria-invalid={showContextError ? true : undefined}
- className={cn(inputClassName, showContextError && inputErrorClassName)}
- />
- {showContextError ? (
- <FieldError>{contextError}</FieldError>
- ) : (
- <FieldHelp>Prevents the context window from overflowing during a run.</FieldHelp>
- )}
- </div>
-
- <div>
- <label
- htmlFor={`custom-provider-model-${index}-max-output-tokens`}
- className="mb-1.5 block text-xs font-medium text-muted-foreground"
- >
- Max output tokens
- <RequiredMark />
- </label>
- <input
- id={`custom-provider-model-${index}-max-output-tokens`}
- type="number"
- min={1}
- inputMode="numeric"
- value={model.maxOutputTokens}
- onChange={event => updateModel(index, { maxOutputTokens: event.target.value })}
- onBlur={() => updateModel(index, { maxTouched: true })}
- placeholder={PLACEHOLDER_MAX_OUTPUT_TOKENS}
- aria-invalid={showMaxError ? true : undefined}
- className={cn(inputClassName, showMaxError && inputErrorClassName)}
- />
- {showMaxError ? (
- <FieldError>{maxError}</FieldError>
- ) : (
- <FieldHelp>Caps tokens per model call.</FieldHelp>
- )}
- </div>
</div>
) : null}
</div>
diff --git a/packages/trueforge-ui-sdk/test/containers/SettingsBuilder/ConnectorDetails.test.tsx b/packages/trueforge-ui-sdk/test/containers/SettingsBuilder/ConnectorDetails.test.tsx
index 2f6a5424f..b3a778c8f 100644
--- a/packages/trueforge-ui-sdk/test/containers/SettingsBuilder/ConnectorDetails.test.tsx
+++ b/packages/trueforge-ui-sdk/test/containers/SettingsBuilder/ConnectorDetails.test.tsx
@@ -28,8 +28,8 @@ function wrapperFor(tools: ToolBase[]) {
getToolsByConnectorId: async () => tools,
createConnector: async () => connector,
updateConnector: async () => connector,
- authenticateConnector: async () => ({ redirectUrl: '' }),
- disconnectConnector: async () => undefined,
+ authenticateConnector: async () => connector,
+ disconnectConnector: async () => connector,
},
}),
});
diff --git a/packages/trueforge-ui-sdk/test/containers/SettingsBuilder/CustomModelProviderForm.test.tsx b/packages/trueforge-ui-sdk/test/containers/SettingsBuilder/CustomModelProviderForm.test.tsx
index a40842cac..9d3fec4b9 100644
--- a/packages/trueforge-ui-sdk/test/containers/SettingsBuilder/CustomModelProviderForm.test.tsx
+++ b/packages/trueforge-ui-sdk/test/containers/SettingsBuilder/CustomModelProviderForm.test.tsx
@@ -70,7 +70,7 @@ describe('CustomModelProviderForm', () => {
expect(submit).toBeDisabled(); // model ID still empty
fireEvent.change(screen.getByPlaceholderText('llama3.1:70b'), { target: { value: 'llama3.1:70b' } });
- // Enabled even though the collapsed limits are still empty — the click reveals them.
+ // Enabled even though the required limits are still empty — they're enforced on submit.
expect(submit).toBeEnabled();
});
@@ -93,18 +93,15 @@ describe('CustomModelProviderForm', () => {
it('does not prefill Context length or Max output tokens', () => {
renderForm();
- fireEvent.click(screen.getByRole('button', { name: 'Advanced' }));
+ // Advanced is expanded by default, so the limits are visible immediately.
expect((screen.getByPlaceholderText('128000') as HTMLInputElement).value).toBe('');
expect((screen.getByPlaceholderText('4096') as HTMLInputElement).value).toBe('');
});
- it('requires both limits: submitting empty auto-expands Advanced, shows the error, and does not submit', () => {
+ it('requires both limits: submitting with them empty shows the error and does not submit', () => {
const onAdd = renderForm();
- fillVisible();
- expect(screen.queryByPlaceholderText('128000')).not.toBeInTheDocument(); // Advanced starts collapsed
+ fillVisible(); // Advanced is expanded by default; the limits are visible but empty.
fireEvent.click(screen.getByRole('button', { name: 'Add provider' }));
- // The offending model's Advanced expands and its required error appears; nothing is submitted.
- expect(screen.getByPlaceholderText('128000')).toBeInTheDocument();
expect(screen.getByText(/Set the model.s context window/)).toBeInTheDocument();
expect(onAdd).not.toHaveBeenCalled();
});
@@ -181,17 +178,25 @@ describe('CustomModelProviderForm', () => {
expect(screen.getByRole('button', { name: 'Add provider' })).toBeDisabled();
});
- it('surfaces the auto-derived Model name error immediately, without a blur or submit', () => {
+ it('never errors the auto-derived Model name; the user just enters one', () => {
renderForm();
- fireEvent.change(screen.getByPlaceholderText('local-llama'), { target: { value: 'local-llama' } });
- fireEvent.change(screen.getByPlaceholderText('http://localhost:11434/v1'), {
- target: { value: 'http://localhost:11434/v1' },
- });
- // An all-digits id slugifies to an empty name. The error must show from typing alone —
- // the id field is never blurred and the disabled button prevents a submit.
- fireEvent.change(screen.getByPlaceholderText('llama3.1:70b'), { target: { value: '123' } });
- expect(screen.getByText('Model name is required.')).toBeInTheDocument();
- expect(screen.getByRole('button', { name: 'Add provider' })).toBeDisabled();
+ const id = screen.getByPlaceholderText('llama3.1:70b');
+ // An all-digits id slugifies to an empty name. No error while typing…
+ fireEvent.change(id, { target: { value: '111' } });
+ expect(screen.queryByText('Model name is required.')).not.toBeInTheDocument();
+ // …and none after the id is blurred either — an auto-derived value is never flagged.
+ fireEvent.blur(id);
+ expect(screen.queryByText('Model name is required.')).not.toBeInTheDocument();
+ });
+
+ it('shows only the Model ID error when the id is empty (no stacked name error)', () => {
+ renderForm();
+ const id = screen.getByPlaceholderText('llama3.1:70b');
+ fireEvent.change(id, { target: { value: 'x' } }); // touch, then clear
+ fireEvent.change(id, { target: { value: '' } });
+ fireEvent.blur(id);
+ expect(screen.getByText('Model ID is required.')).toBeInTheDocument();
+ expect(screen.queryByText('Model name is required.')).not.toBeInTheDocument();
});
it('accepts backend-valid names with adjacent separators (matches NameSchema)', () => {