fix: handle missing provider keys and tool schema types (#5069)

* fix: handle missing api keys and tool schema types

* fix: preserve nested tool schemas

---------

Co-authored-by: Jason <farion1231@gmail.com>
This commit is contained in:
Komi
2026-07-11 16:57:46 +08:00
committed by GitHub
parent 6245caa6c5
commit ded0b63a8e
4 changed files with 201 additions and 12 deletions
@@ -60,15 +60,12 @@ export function useApiKeyState({
initialConfig || "{}",
key.trim(),
{
// 最佳实践:仅在"新增模式"且"非官方类别"时补齐缺失字段
// - 新增模式:selectedPresetId !== null
// - 非官方类别:category !== undefined && category !== "official"
// 最佳实践:仅在"非官方/非云厂商类别"时补齐缺失字段
// - 官方类别:不创建字段(UI 也会禁用输入框)
// - 未传入 category:不创建字段(避免意外行为)
// - 云厂商类别:通常使用专用鉴权字段,不自动创建 Anthropic key
// - 未传入 category:按历史导入/自定义 provider 处理,允许补齐
createIfMissing:
selectedPresetId !== null &&
category !== undefined &&
category !== "official",
category !== "official" && category !== "cloud_provider",
appType,
apiKeyField,
},
@@ -90,10 +87,13 @@ export function useApiKeyState({
(config: string, isEditMode: boolean) => {
return (
selectedPresetId !== null ||
(isEditMode &&
category !== "official" &&
category !== "cloud_provider") ||
(isEditMode && hasApiKeyField(config, appType))
);
},
[selectedPresetId, appType],
[selectedPresetId, category, appType],
);
return {