fix: invalidate assistant models on discovery changes
This commit is contained in:
1 parent
703c27c639
commit
5da5433b58
2 files changed
+29
-12
No files matched your search
+28
-12
@@ -72,9 +72,14 @@ export const AssistantConfiguration = () => {
|
|||||||
setEnabled(configuration?.enabled ?? false);
|
setEnabled(configuration?.enabled ?? false);
|
||||||
}, [configuration]);
|
}, [configuration]);
|
||||||
|
|
||||||
|
const normalizedBaseUrl = baseUrl.trim().replace(/\/$/, "");
|
||||||
|
const normalizedModelDiscoveryPath = modelDiscoveryPath.trim() || null;
|
||||||
const destinationChanged =
|
const destinationChanged =
|
||||||
configuration?.connectionConfigured === true &&
|
configuration?.connectionConfigured === true &&
|
||||||
(configuration.provider !== provider || configuration.baseUrl !== baseUrl.trim().replace(/\/$/, ""));
|
(configuration.provider !== provider || configuration.baseUrl !== normalizedBaseUrl);
|
||||||
|
const connectionChanged =
|
||||||
|
configuration?.connectionConfigured === true &&
|
||||||
|
(destinationChanged || configuration.modelDiscoveryPath !== normalizedModelDiscoveryPath);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: models,
|
data: models,
|
||||||
@@ -83,7 +88,7 @@ export const AssistantConfiguration = () => {
|
|||||||
refetch: discoverModels,
|
refetch: discoverModels,
|
||||||
} = clientApi.assistant.discoverModels.useQuery(undefined, {
|
} = clientApi.assistant.discoverModels.useQuery(undefined, {
|
||||||
enabled:
|
enabled:
|
||||||
configuration?.connectionConfigured === true && configuration.modelDiscoveryPath !== null && !destinationChanged,
|
configuration?.connectionConfigured === true && configuration.modelDiscoveryPath !== null && !connectionChanged,
|
||||||
staleTime: 5 * 60_000,
|
staleTime: 5 * 60_000,
|
||||||
retry: false,
|
retry: false,
|
||||||
});
|
});
|
||||||
@@ -109,7 +114,7 @@ export const AssistantConfiguration = () => {
|
|||||||
})),
|
})),
|
||||||
[t],
|
[t],
|
||||||
);
|
);
|
||||||
const selectedModel = destinationChanged ? undefined : models?.find((model) => model.id === modelId);
|
const selectedModel = connectionChanged ? undefined : models?.find((model) => model.id === modelId);
|
||||||
|
|
||||||
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);
|
||||||
@@ -117,7 +122,8 @@ export const AssistantConfiguration = () => {
|
|||||||
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 connectionPending = configuration?.connectionConfigured !== true || connectionChanged;
|
||||||
|
const modelControlsDisabled = connectionPending || isDiscovering;
|
||||||
const canSaveConfiguration = !modelControlsDisabled && modelId.trim().length > 0;
|
const canSaveConfiguration = !modelControlsDisabled && modelId.trim().length > 0;
|
||||||
|
|
||||||
const updateConnection = clientApi.assistant.updateConnection.useMutation({
|
const updateConnection = clientApi.assistant.updateConnection.useMutation({
|
||||||
@@ -202,6 +208,14 @@ export const AssistantConfiguration = () => {
|
|||||||
setBaseUrl(value);
|
setBaseUrl(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const changeModelDiscoveryPath = (value: string) => {
|
||||||
|
if (value !== modelDiscoveryPath) {
|
||||||
|
setModelId("");
|
||||||
|
setEnabled(false);
|
||||||
|
}
|
||||||
|
setModelDiscoveryPath(value);
|
||||||
|
};
|
||||||
|
|
||||||
const addHeader = () => {
|
const addHeader = () => {
|
||||||
setHeaders((current) => [...current, { id: nextHeaderId, name: "", value: "" }]);
|
setHeaders((current) => [...current, { id: nextHeaderId, name: "", value: "" }]);
|
||||||
setNextHeaderId((current) => current + 1);
|
setNextHeaderId((current) => current + 1);
|
||||||
@@ -282,7 +296,7 @@ export const AssistantConfiguration = () => {
|
|||||||
label={t("model.discoveryPath")}
|
label={t("model.discoveryPath")}
|
||||||
description={t("model.discoveryPathDescription")}
|
description={t("model.discoveryPathDescription")}
|
||||||
value={modelDiscoveryPath}
|
value={modelDiscoveryPath}
|
||||||
onChange={(event) => setModelDiscoveryPath(event.currentTarget.value)}
|
onChange={(event) => changeModelDiscoveryPath(event.currentTarget.value)}
|
||||||
placeholder="/models"
|
placeholder="/models"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@@ -428,17 +442,19 @@ export const AssistantConfiguration = () => {
|
|||||||
disabled={modelControlsDisabled}
|
disabled={modelControlsDisabled}
|
||||||
placeholder={t("model.placeholder")}
|
placeholder={t("model.placeholder")}
|
||||||
description={
|
description={
|
||||||
modelControlsDisabled
|
connectionPending
|
||||||
? t("model.saveConnectionFirst")
|
? t("model.saveConnectionFirst")
|
||||||
: discoveryError
|
: isDiscovering
|
||||||
? t("model.manualFallback")
|
? t("model.discovering")
|
||||||
: 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 && !modelControlsDisabled && (
|
{discoveryError && !connectionPending && (
|
||||||
<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>
|
||||||
|
|||||||
@@ -4986,6 +4986,7 @@
|
|||||||
"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.",
|
"saveConnectionFirst": "Save the provider connection before choosing a model.",
|
||||||
|
"discovering": "Refreshing the models available from this provider…",
|
||||||
"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