fix: gate assistant models on saved connection
This commit is contained in:
1 parent
00e4cc8100
commit
c157001455
2 files changed
+28
-18
No files matched your search
+27
-18
@@ -72,13 +72,18 @@ export const AssistantConfiguration = () => {
|
|||||||
setEnabled(configuration?.enabled ?? false);
|
setEnabled(configuration?.enabled ?? false);
|
||||||
}, [configuration]);
|
}, [configuration]);
|
||||||
|
|
||||||
|
const destinationChanged =
|
||||||
|
configuration?.connectionConfigured === true &&
|
||||||
|
(configuration.provider !== provider || configuration.baseUrl !== baseUrl.trim().replace(/\/$/, ""));
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: models,
|
data: models,
|
||||||
error: discoveryError,
|
error: discoveryError,
|
||||||
isFetching: isDiscovering,
|
isFetching: isDiscovering,
|
||||||
refetch: discoverModels,
|
refetch: discoverModels,
|
||||||
} = clientApi.assistant.discoverModels.useQuery(undefined, {
|
} = clientApi.assistant.discoverModels.useQuery(undefined, {
|
||||||
enabled: configuration?.connectionConfigured === true && configuration.modelDiscoveryPath !== null,
|
enabled:
|
||||||
|
configuration?.connectionConfigured === true && configuration.modelDiscoveryPath !== null && !destinationChanged,
|
||||||
staleTime: 5 * 60_000,
|
staleTime: 5 * 60_000,
|
||||||
retry: false,
|
retry: false,
|
||||||
});
|
});
|
||||||
@@ -104,17 +109,16 @@ export const AssistantConfiguration = () => {
|
|||||||
})),
|
})),
|
||||||
[t],
|
[t],
|
||||||
);
|
);
|
||||||
const selectedModel = models?.find((model) => model.id === modelId);
|
const selectedModel = destinationChanged ? undefined : models?.find((model) => model.id === modelId);
|
||||||
|
|
||||||
const destinationChanged =
|
|
||||||
configuration?.connectionConfigured === true &&
|
|
||||||
(configuration.provider !== provider || configuration.baseUrl !== baseUrl.trim().replace(/\/$/, ""));
|
|
||||||
const preset = assistantProviderPresets[provider];
|
const preset = assistantProviderPresets[provider];
|
||||||
const headerValuesValid = headers.every((header) => header.name.trim().length > 0 && header.value.length > 0);
|
const headerValuesValid = headers.every((header) => header.name.trim().length > 0 && header.value.length > 0);
|
||||||
const hasEffectiveApiKey =
|
const hasEffectiveApiKey =
|
||||||
apiKey.trim().length > 0 || (!destinationChanged && configuration?.apiKeyConfigured === true && !clearApiKey);
|
apiKey.trim().length > 0 || (!destinationChanged && configuration?.apiKeyConfigured === true && !clearApiKey);
|
||||||
const connectionValid =
|
const connectionValid =
|
||||||
baseUrl.trim().length > 0 && headerValuesValid && (!preset.requiresApiKey || hasEffectiveApiKey);
|
baseUrl.trim().length > 0 && headerValuesValid && (!preset.requiresApiKey || hasEffectiveApiKey);
|
||||||
|
const modelControlsDisabled = configuration?.connectionConfigured !== true || destinationChanged;
|
||||||
|
const canSaveConfiguration = !modelControlsDisabled && modelId.trim().length > 0;
|
||||||
|
|
||||||
const updateConnection = clientApi.assistant.updateConnection.useMutation({
|
const updateConnection = clientApi.assistant.updateConnection.useMutation({
|
||||||
onSuccess: async ({ credentialsClearedForDestinationChange }) => {
|
onSuccess: async ({ credentialsClearedForDestinationChange }) => {
|
||||||
@@ -222,6 +226,11 @@ export const AssistantConfiguration = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const saveAssistantConfiguration = () => {
|
||||||
|
if (!canSaveConfiguration) return;
|
||||||
|
saveConfiguration.mutate({ enabled, modelId: modelId.trim() });
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack>
|
<Stack>
|
||||||
<Card pos="relative" withBorder>
|
<Card pos="relative" withBorder>
|
||||||
@@ -405,7 +414,7 @@ export const AssistantConfiguration = () => {
|
|||||||
size="compact-sm"
|
size="compact-sm"
|
||||||
leftSection={<IconDatabaseSearch size={14} />}
|
leftSection={<IconDatabaseSearch size={14} />}
|
||||||
loading={isDiscovering}
|
loading={isDiscovering}
|
||||||
disabled={!configuration?.connectionConfigured || configuration.modelDiscoveryPath === null}
|
disabled={modelControlsDisabled || configuration?.modelDiscoveryPath === null}
|
||||||
onClick={() => void discoverModels()}
|
onClick={() => void discoverModels()}
|
||||||
>
|
>
|
||||||
{t("model.refresh")}
|
{t("model.refresh")}
|
||||||
@@ -415,18 +424,21 @@ export const AssistantConfiguration = () => {
|
|||||||
aria-label={t("model.title")}
|
aria-label={t("model.title")}
|
||||||
value={modelId}
|
value={modelId}
|
||||||
onChange={setModelId}
|
onChange={setModelId}
|
||||||
data={modelOptions}
|
data={modelControlsDisabled ? [] : modelOptions}
|
||||||
|
disabled={modelControlsDisabled}
|
||||||
placeholder={t("model.placeholder")}
|
placeholder={t("model.placeholder")}
|
||||||
description={
|
description={
|
||||||
discoveryError
|
modelControlsDisabled
|
||||||
? t("model.manualFallback")
|
? t("model.saveConnectionFirst")
|
||||||
: models
|
: discoveryError
|
||||||
? t("model.discovered", { count: models.length })
|
? t("model.manualFallback")
|
||||||
: t("model.manual")
|
: models
|
||||||
|
? t("model.discovered", { count: models.length })
|
||||||
|
: t("model.manual")
|
||||||
}
|
}
|
||||||
limit={100}
|
limit={100}
|
||||||
/>
|
/>
|
||||||
{discoveryError && (
|
{discoveryError && !modelControlsDisabled && (
|
||||||
<Alert color="yellow" icon={<IconAlertTriangle size={18} />} title={t("model.discoveryFailed")}>
|
<Alert color="yellow" icon={<IconAlertTriangle size={18} />} title={t("model.discoveryFailed")}>
|
||||||
{discoveryError.message}
|
{discoveryError.message}
|
||||||
</Alert>
|
</Alert>
|
||||||
@@ -464,16 +476,13 @@ export const AssistantConfiguration = () => {
|
|||||||
<Switch
|
<Switch
|
||||||
checked={enabled}
|
checked={enabled}
|
||||||
onChange={(event) => setEnabled(event.currentTarget.checked)}
|
onChange={(event) => setEnabled(event.currentTarget.checked)}
|
||||||
disabled={!configuration?.connectionConfigured || modelId.trim().length === 0}
|
disabled={!canSaveConfiguration}
|
||||||
label={t("enabled.label")}
|
label={t("enabled.label")}
|
||||||
description={t("enabled.description")}
|
description={t("enabled.description")}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Group justify="flex-end">
|
<Group justify="flex-end">
|
||||||
<Button
|
<Button onClick={saveAssistantConfiguration} disabled={!canSaveConfiguration}>
|
||||||
onClick={() => saveConfiguration.mutate({ enabled, modelId: modelId.trim() })}
|
|
||||||
disabled={!configuration?.connectionConfigured || modelId.trim().length === 0}
|
|
||||||
>
|
|
||||||
{t("save")}
|
{t("save")}
|
||||||
</Button>
|
</Button>
|
||||||
</Group>
|
</Group>
|
||||||
|
|||||||
@@ -5888,6 +5888,7 @@
|
|||||||
"discoveryPathDescription": "Appended to the API base URL. Leave blank to disable discovery and use a manual model ID.",
|
"discoveryPathDescription": "Appended to the API base URL. Leave blank to disable discovery and use a manual model ID.",
|
||||||
"manual": "Enter a model ID manually or save the connection to discover models.",
|
"manual": "Enter a model ID manually or save the connection to discover models.",
|
||||||
"manualFallback": "Discovery is unavailable. You can still enter a model ID manually.",
|
"manualFallback": "Discovery is unavailable. You can still enter a model ID manually.",
|
||||||
|
"saveConnectionFirst": "Save the provider connection before choosing a model.",
|
||||||
"discovered": "Discovered {count} models. Tool support depends on the selected endpoint and model.",
|
"discovered": "Discovered {count} models. Tool support depends on the selected endpoint and model.",
|
||||||
"discoveryFailed": "Model discovery did not complete",
|
"discoveryFailed": "Model discovery did not complete",
|
||||||
"context": "{count} token context",
|
"context": "{count} token context",
|
||||||
|
|||||||
Reference in new issue
Block a user