fix: clear incompatible tools when switching models

When switching from a model with tools to one without those tools,
the previously selected tools remained active. This happened because
the settings.tools fallback did not check compatibility with the
current model.

Now when a model doesn't define toolIds, the global settings tools
are only applied if they are compatible with the current model's
filters or toolIds. This prevents tools from a previous model from
leaking into a model that doesn't support them.

Fixes #14157
This commit is contained in:
armorbreak001 2026-04-15 08:39:07 +08:00
parent 1860874192
commit 3cb7bee4d7

View file

@ -338,7 +338,12 @@
selectedToolIds = authed;
pendingOAuthTools = unauthed;
} else if ($settings?.tools) {
selectedToolIds = $settings.tools;
// Only apply global tool settings for tools compatible with the current model
const modelFilterIds = model?.filters?.map((f) => f.id) ?? [];
const modelToolIds = model?.info?.meta?.toolIds ?? [];
selectedToolIds = $settings.tools.filter(
(id) => modelToolIds.includes(id) || modelFilterIds.includes(id)
);
} else {
selectedToolIds = selectedToolIds.filter((id) => !id.startsWith('direct_server:'));
}