@@ -17,6 +17,7 @@ import { useState } from "react";
1717import { useEnvironmentSettings , useUpdateEnvironmentSettings } from "../../hooks/useSettings" ;
1818import {
1919 checkTextGeneratorConfig ,
20+ rereadTextGeneratorModels ,
2021 nextTextGeneratorId ,
2122 refreshTextGeneratorModels ,
2223 testTextGeneratorModel ,
@@ -177,7 +178,12 @@ export function TextGeneratorsSettings({
177178 editing = { editing }
178179 providers = { providers }
179180 onClose = { ( ) => setEditing ( null ) }
180- onSave = { ( id , config ) => updateSettings ( { textGenerators : { [ id ] : config } } ) }
181+ onSave = { ( id , config ) =>
182+ updateSettings (
183+ { textGenerators : { [ id ] : config } } ,
184+ { onSaved : ( ) => rereadTextGeneratorModels ( environmentId , id ) } ,
185+ )
186+ }
181187 newId = { ( preset ) => nextTextGeneratorId ( preset . id , settings , providers ) }
182188 />
183189 ) : null }
@@ -297,6 +303,7 @@ function TextGeneratorWizard({
297303 const id = savedId ?? newId ( preset ) ;
298304 setChecking ( true ) ;
299305 setCheckError ( null ) ;
306+ // The form is disabled while this runs, so the checked config is the one saved below.
300307 const result = await checkTextGeneratorConfig ( environmentId , id , config . value ) ;
301308 setChecking ( false ) ;
302309 if ( "error" in result ) {
@@ -337,104 +344,106 @@ function TextGeneratorWizard({
337344 void connect ( ) ;
338345 } }
339346 >
340- { existing === null ? (
341- < div className = "grid gap-1.5" >
342- < span className = "text-sm font-medium" > Service</ span >
343- < div
344- role = "radiogroup"
345- aria-label = "Service"
346- className = "grid grid-cols-2 gap-2 sm:grid-cols-4"
347- >
348- { TEXT_GENERATOR_PRESETS . map ( ( candidate ) => {
349- const selected = candidate . id === preset . id ;
350- return (
351- < button
352- key = { candidate . id }
353- type = "button"
354- role = "radio"
355- aria-checked = { selected }
356- className = {
357- selected
358- ? "flex flex-col items-center gap-2 rounded-lg border border-primary bg-primary/5 px-2 py-3 text-sm font-medium text-foreground ring-1 ring-primary ring-inset outline-none focus-visible:ring-2 focus-visible:ring-inset"
359- : "flex flex-col items-center gap-2 rounded-lg border bg-background px-2 py-3 text-sm text-muted-foreground outline-none hover:bg-accent/50 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset"
360- }
361- onClick = { ( ) => {
362- setPreset ( candidate ) ;
363- setBaseUrl ( candidate . baseUrl ) ;
364- setCheckError ( null ) ;
365- } }
366- >
367- { candidate . id === "custom" ? (
368- < ServerIcon className = "size-5" aria-hidden />
369- ) : (
370- < ProviderInstanceIcon
371- driverKind = { textGeneratorBrand ( candidate ) }
372- displayName = { candidate . label }
373- badgeContent = "none"
374- />
375- ) }
376- { candidate . id === "custom" ? "Custom" : candidate . label }
377- </ button >
378- ) ;
379- } ) }
347+ < fieldset disabled = { checking } className = "contents" >
348+ { existing === null ? (
349+ < div className = "grid gap-1.5" >
350+ < span className = "text-sm font-medium" > Service</ span >
351+ < div
352+ role = "radiogroup"
353+ aria-label = "Service"
354+ className = "grid grid-cols-2 gap-2 sm:grid-cols-4"
355+ >
356+ { TEXT_GENERATOR_PRESETS . map ( ( candidate ) => {
357+ const selected = candidate . id === preset . id ;
358+ return (
359+ < button
360+ key = { candidate . id }
361+ type = "button"
362+ role = "radio"
363+ aria-checked = { selected }
364+ className = {
365+ selected
366+ ? "flex flex-col items-center gap-2 rounded-lg border border-primary bg-primary/5 px-2 py-3 text-sm font-medium text-foreground ring-1 ring-primary ring-inset outline-none focus-visible:ring-2 focus-visible:ring-inset"
367+ : "flex flex-col items-center gap-2 rounded-lg border bg-background px-2 py-3 text-sm text-muted-foreground outline-none hover:bg-accent/50 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset"
368+ }
369+ onClick = { ( ) => {
370+ setPreset ( candidate ) ;
371+ setBaseUrl ( candidate . baseUrl ) ;
372+ setCheckError ( null ) ;
373+ } }
374+ >
375+ { candidate . id === "custom" ? (
376+ < ServerIcon className = "size-5" aria-hidden />
377+ ) : (
378+ < ProviderInstanceIcon
379+ driverKind = { textGeneratorBrand ( candidate ) }
380+ displayName = { candidate . label }
381+ badgeContent = "none"
382+ />
383+ ) }
384+ { candidate . id === "custom" ? "Custom" : candidate . label }
385+ </ button >
386+ ) ;
387+ } ) }
388+ </ div >
380389 </ div >
381- </ div >
382- ) : null }
383- { showBaseUrl ? (
390+ ) : null }
391+ { showBaseUrl ? (
392+ < div className = "grid gap-1.5" >
393+ < Label htmlFor = "text-generator-url" > Base URL</ Label >
394+ < Input
395+ id = "text-generator-url"
396+ placeholder = "http://localhost:11434/v1"
397+ value = { baseUrl }
398+ onChange = { ( event ) => {
399+ setBaseUrl ( event . target . value ) ;
400+ setCheckError ( null ) ;
401+ } }
402+ spellCheck = { false }
403+ autoFocus = { existing === null && preset . id === "custom" }
404+ />
405+ </ div >
406+ ) : null }
384407 < div className = "grid gap-1.5" >
385- < Label htmlFor = "text-generator-url" > Base URL</ Label >
386- < Input
387- id = "text-generator-url"
388- placeholder = "http://localhost:11434/v1"
389- value = { baseUrl }
408+ < Label htmlFor = "text-generator-key" >
409+ { keyRequired ? "API key" : "API key (optional)" }
410+ </ Label >
411+ < SecretSourceInput
412+ id = "text-generator-key"
413+ aria-label = "API key"
414+ value = { keyDraft }
415+ configured = { storedKey !== "" }
416+ sources = { secretSources }
390417 onChange = { ( event ) => {
391- setBaseUrl ( event . target . value ) ;
418+ setKeyDraft ( event . target . value ) ;
392419 setCheckError ( null ) ;
393420 } }
394- spellCheck = { false }
395- autoFocus = { existing === null && preset . id === "custom" }
421+ onSecretChange = { ( secret ) => setKeyDraft ( secret ?? "" ) }
422+ autoFocus = { existing === null && preset . id !== "custom" }
423+ onValidityChange = { setKeyValid }
396424 />
397425 </ div >
398- ) : null }
399- < div className = "grid gap-1.5" >
400- < Label htmlFor = "text-generator-key" >
401- { keyRequired ? "API key" : "API key (optional)" }
402- </ Label >
403- < SecretSourceInput
404- id = "text-generator-key"
405- aria-label = "API key"
406- value = { keyDraft }
407- configured = { storedKey !== "" }
408- sources = { secretSources }
409- onChange = { ( event ) => {
410- setKeyDraft ( event . target . value ) ;
411- setCheckError ( null ) ;
412- } }
413- onSecretChange = { ( secret ) => setKeyDraft ( secret ?? "" ) }
414- autoFocus = { existing === null && preset . id !== "custom" }
415- onValidityChange = { setKeyValid }
416- />
417- </ div >
418- < div className = "grid gap-1.5" >
419- < Label htmlFor = "text-generator-label" > Name (optional)</ Label >
420- < Input
421- id = "text-generator-label"
422- placeholder = {
423- existing !== null
424- ? textGeneratorDisplayName ( existing )
425- : preset . id === "custom"
426- ? "e.g. My local model"
427- : preset . label
428- }
429- value = { label }
430- onChange = { ( event ) => setLabel ( event . target . value ) }
431- />
432- </ div >
433- { checkError ? (
434- < p role = "alert" className = "text-sm text-destructive" >
435- { checkError }
436- </ p >
437- ) : null }
426+ < div className = "grid gap-1.5" >
427+ < Label htmlFor = "text-generator-label" > Name (optional)</ Label >
428+ < Input
429+ id = "text-generator-label"
430+ placeholder = {
431+ existing !== null
432+ ? textGeneratorDisplayName ( existing )
433+ : preset . id === "custom"
434+ ? "e.g. My local model"
435+ : preset . label
436+ }
437+ value = { label }
438+ onChange = { ( event ) => setLabel ( event . target . value ) }
439+ />
440+ </ div >
441+ { checkError ? (
442+ < p role = "alert" className = "text-sm text-destructive" >
443+ { checkError }
444+ </ p >
445+ ) : null }
446+ </ fieldset >
438447 </ form >
439448 ) : (
440449 < div className = "grid gap-4" >
0 commit comments