mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-24 12:44:18 +08:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user