From ab8af53a2457b8c1fbacf9e8684de13f9ec9a494 Mon Sep 17 00:00:00 2001 From: Faisal Amir Date: Thu, 22 Aug 2024 15:20:45 +0700 Subject: [PATCH] fix: setting extension placeholder and input action apikey (#3430) * fix: setting extension placeholder apikey * fix: extension settings migration --------- Co-authored-by: Louis --- core/src/browser/extension.ts | 13 ++++++---- .../resources/settings.json | 25 ++++++++++--------- .../resources/settings.json | 23 +++++++++-------- .../resources/settings.json | 23 +++++++++-------- .../resources/settings.json | 23 +++++++++-------- .../resources/settings.json | 23 +++++++++-------- .../resources/settings.json | 24 +++++++++--------- .../resources/settings.json | 23 +++++++++-------- .../resources/settings.json | 17 +++---------- .../resources/settings.json | 23 +++++++++-------- 10 files changed, 109 insertions(+), 108 deletions(-) diff --git a/core/src/browser/extension.ts b/core/src/browser/extension.ts index def85093e..603445745 100644 --- a/core/src/browser/extension.ts +++ b/core/src/browser/extension.ts @@ -122,13 +122,16 @@ export abstract class BaseExtension implements ExtensionType { await fs.mkdir(extensionSettingFolderPath) const settingFilePath = await joinPath([extensionSettingFolderPath, this.settingFileName]) - // Persists new setting only + // Persists new settings if (await fs.existsSync(settingFilePath)) { const oldSettings = JSON.parse(await fs.readFileSync(settingFilePath, 'utf-8')) - if (Array.isArray(oldSettings)) - settings = oldSettings.concat( - settings.filter((e) => !oldSettings.some((o) => o.key === e.key)) - ) + settings.forEach((setting) => { + // Keep setting value + if (setting.controllerProps && Array.isArray(oldSettings)) + setting.controllerProps.value = oldSettings.find( + (e: any) => e.key === setting.key + )?.controllerProps?.value + }) } await fs.writeFileSync(settingFilePath, JSON.stringify(settings, null, 2)) } catch (err) { diff --git a/extensions/inference-anthropic-extension/resources/settings.json b/extensions/inference-anthropic-extension/resources/settings.json index bb35e6b3d..9ca4405ac 100644 --- a/extensions/inference-anthropic-extension/resources/settings.json +++ b/extensions/inference-anthropic-extension/resources/settings.json @@ -1,4 +1,16 @@ [ + { + "key": "anthropic-api-key", + "title": "API Key", + "description": "The Anthropic API uses API keys for authentication. Visit your [API Keys](https://console.anthropic.com/settings/keys) page to retrieve the API key you'll use in your requests.", + "controllerType": "input", + "controllerProps": { + "placeholder": "Insert API Key", + "value": "", + "type": "password", + "inputActions": ["unobscure", "copy"] + } + }, { "key": "chat-completions-endpoint", "title": "Chat Completions Endpoint", @@ -8,16 +20,5 @@ "placeholder": "https://api.anthropic.com/v1/messages", "value": "https://api.anthropic.com/v1/messages" } - }, - { - "key": "anthropic-api-key", - "title": "API Key", - "description": "The Anthropic API uses API keys for authentication. Visit your [API Keys](https://console.anthropic.com/settings/keys) page to retrieve the API key you'll use in your requests.", - "controllerType": "input", - "controllerProps": { - "placeholder": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - "value": "", - "type": "password" - } } -] \ No newline at end of file +] diff --git a/extensions/inference-cohere-extension/resources/settings.json b/extensions/inference-cohere-extension/resources/settings.json index 2a32b57f8..79150d7e5 100644 --- a/extensions/inference-cohere-extension/resources/settings.json +++ b/extensions/inference-cohere-extension/resources/settings.json @@ -1,4 +1,16 @@ [ + { + "key": "cohere-api-key", + "title": "API Key", + "description": "The Cohere API uses API keys for authentication. Visit your [API Keys](https://dashboard.cohere.com/api-keys) page to retrieve the API key you'll use in your requests.", + "controllerType": "input", + "controllerProps": { + "placeholder": "Insert API Key", + "value": "", + "type": "password", + "inputActions": ["unobscure", "copy"] + } + }, { "key": "chat-completions-endpoint", "title": "Chat Completions Endpoint", @@ -8,16 +20,5 @@ "placeholder": "https://api.cohere.ai/v1/chat", "value": "https://api.cohere.ai/v1/chat" } - }, - { - "key": "cohere-api-key", - "title": "API Key", - "description": "The Cohere API uses API keys for authentication. Visit your [API Keys](https://dashboard.cohere.com/api-keys) page to retrieve the API key you'll use in your requests.", - "controllerType": "input", - "controllerProps": { - "placeholder": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - "value": "", - "type": "password" - } } ] diff --git a/extensions/inference-groq-extension/resources/settings.json b/extensions/inference-groq-extension/resources/settings.json index 493b602cd..767fec0ba 100644 --- a/extensions/inference-groq-extension/resources/settings.json +++ b/extensions/inference-groq-extension/resources/settings.json @@ -1,4 +1,16 @@ [ + { + "key": "groq-api-key", + "title": "API Key", + "description": "The Groq API uses API keys for authentication. Visit your [API Keys](https://console.groq.com/keys) page to retrieve the API key you'll use in your requests.", + "controllerType": "input", + "controllerProps": { + "placeholder": "Insert API Key", + "value": "", + "type": "password", + "inputActions": ["unobscure", "copy"] + } + }, { "key": "chat-completions-endpoint", "title": "Chat Completions Endpoint", @@ -8,16 +20,5 @@ "placeholder": "https://api.groq.com/openai/v1/chat/completions", "value": "https://api.groq.com/openai/v1/chat/completions" } - }, - { - "key": "groq-api-key", - "title": "API Key", - "description": "The Groq API uses API keys for authentication. Visit your [API Keys](https://console.groq.com/keys) page to retrieve the API key you'll use in your requests.", - "controllerType": "input", - "controllerProps": { - "placeholder": "gsk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - "value": "", - "type": "password" - } } ] diff --git a/extensions/inference-martian-extension/resources/settings.json b/extensions/inference-martian-extension/resources/settings.json index bc83d76d4..2341ad6cd 100644 --- a/extensions/inference-martian-extension/resources/settings.json +++ b/extensions/inference-martian-extension/resources/settings.json @@ -1,4 +1,16 @@ [ + { + "key": "martian-api-key", + "title": "API Key", + "description": "The Martian API uses API keys for authentication. Visit your [API Keys](https://withmartian.com/dashboard) page to retrieve the API key you'll use in your requests.", + "controllerType": "input", + "controllerProps": { + "placeholder": "Insert API Key", + "value": "", + "type": "password", + "inputActions": ["unobscure", "copy"] + } + }, { "key": "chat-completions-endpoint", "title": "Chat Completions Endpoint", @@ -8,16 +20,5 @@ "placeholder": "https://withmartian.com/api/openai/v1/chat/completions", "value": "https://withmartian.com/api/openai/v1/chat/completions" } - }, - { - "key": "martian-api-key", - "title": "API Key", - "description": "The Martian API uses API keys for authentication. Visit your [API Keys](https://withmartian.com/dashboard) page to retrieve the API key you'll use in your requests.", - "controllerType": "input", - "controllerProps": { - "placeholder": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - "value": "", - "type": "password" - } } ] diff --git a/extensions/inference-mistral-extension/resources/settings.json b/extensions/inference-mistral-extension/resources/settings.json index 2ca8ec7e5..963674b02 100644 --- a/extensions/inference-mistral-extension/resources/settings.json +++ b/extensions/inference-mistral-extension/resources/settings.json @@ -1,4 +1,16 @@ [ + { + "key": "mistral-api-key", + "title": "API Key", + "description": "The Mistral API uses API keys for authentication. Visit your [API Keys](https://console.mistral.ai/api-keys/) page to retrieve the API key you'll use in your requests.", + "controllerType": "input", + "controllerProps": { + "placeholder": "Insert API Key", + "value": "", + "type": "password", + "inputActions": ["unobscure", "copy"] + } + }, { "key": "chat-completions-endpoint", "title": "Chat Completions Endpoint", @@ -8,16 +20,5 @@ "placeholder": "https://api.mistral.ai/v1/chat/completions", "value": "https://api.mistral.ai/v1/chat/completions" } - }, - { - "key": "mistral-api-key", - "title": "API Key", - "description": "The Mistral API uses API keys for authentication. Visit your [API Keys](https://console.mistral.ai/api-keys/) page to retrieve the API key you'll use in your requests.", - "controllerType": "input", - "controllerProps": { - "placeholder": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - "value": "", - "type": "password" - } } ] diff --git a/extensions/inference-nvidia-extension/resources/settings.json b/extensions/inference-nvidia-extension/resources/settings.json index e7647b562..6b2652653 100644 --- a/extensions/inference-nvidia-extension/resources/settings.json +++ b/extensions/inference-nvidia-extension/resources/settings.json @@ -1,4 +1,16 @@ [ + { + "key": "nvidia-api-key", + "title": "API Key", + "description": "The NVIDIA API uses API keys for authentication. Visit your [API Keys](https://org.ngc.nvidia.com/setup/personal-keys) page to retrieve the API key you'll use in your requests..", + "controllerType": "input", + "controllerProps": { + "placeholder": "Insert API Key", + "value": "", + "type": "password", + "inputActions": ["unobscure", "copy"] + } + }, { "key": "chat-completions-endpoint", "title": "Chat Completions Endpoint", @@ -8,17 +20,5 @@ "placeholder": "https://integrate.api.nvidia.com/v1/chat/completions", "value": "https://integrate.api.nvidia.com/v1/chat/completions" } - }, - { - "key": "nvidia-api-key", - "title": "API Key", - "description": "The NVIDIA API uses API keys for authentication. Visit your [API Keys](https://org.ngc.nvidia.com/setup/personal-keys) page to retrieve the API key you'll use in your requests..", - "controllerType": "input", - "controllerProps": { - "placeholder": "nvapi-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - "value": "", - "type": "password", - "inputActions": ["unobscure", "copy"] - } } ] diff --git a/extensions/inference-openai-extension/resources/settings.json b/extensions/inference-openai-extension/resources/settings.json index ccd7dd545..db2e80c9b 100644 --- a/extensions/inference-openai-extension/resources/settings.json +++ b/extensions/inference-openai-extension/resources/settings.json @@ -1,4 +1,16 @@ [ + { + "key": "openai-api-key", + "title": "API Key", + "description": "The OpenAI API uses API keys for authentication. Visit your [API Keys](https://platform.openai.com/account/api-keys) page to retrieve the API key you'll use in your requests.", + "controllerType": "input", + "controllerProps": { + "placeholder": "Insert API Key", + "value": "", + "type": "password", + "inputActions": ["unobscure", "copy"] + } + }, { "key": "chat-completions-endpoint", "title": "Chat Completions Endpoint", @@ -8,16 +20,5 @@ "placeholder": "https://api.openai.com/v1/chat/completions", "value": "https://api.openai.com/v1/chat/completions" } - }, - { - "key": "openai-api-key", - "title": "API Key", - "description": "The OpenAI API uses API keys for authentication. Visit your [API Keys](https://platform.openai.com/account/api-keys) page to retrieve the API key you'll use in your requests.", - "controllerType": "input", - "controllerProps": { - "placeholder": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - "value": "", - "type": "password" - } } ] diff --git a/extensions/inference-openrouter-extension/resources/settings.json b/extensions/inference-openrouter-extension/resources/settings.json index 891ffec86..ebd7ef7a9 100644 --- a/extensions/inference-openrouter-extension/resources/settings.json +++ b/extensions/inference-openrouter-extension/resources/settings.json @@ -1,23 +1,14 @@ [ - { - "key": "chat-completions-endpoint", - "title": "Chat Completions Endpoint", - "description": "The endpoint to use for chat completions. See the [OpenRouter API documentation](https://openrouter.ai/docs) for more information.", - "controllerType": "input", - "controllerProps": { - "placeholder": "https://openrouter.ai/api/v1/chat/completions", - "value": "https://openrouter.ai/api/v1/chat/completions" - } - }, { "key": "openrouter-api-key", "title": "API Key", "description": "The OpenRouter API uses API keys for authentication. Visit your [API Keys](https://openrouter.ai/keys) page to retrieve the API key you'll use in your requests.", "controllerType": "input", "controllerProps": { - "placeholder": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "placeholder": "Insert API Key", "value": "", - "type": "password" + "type": "password", + "inputActions": ["unobscure", "copy"] } }, { @@ -28,6 +19,6 @@ "controllerProps": { "placeholder": "Leave empty for default model", "value": "" - } + } } ] diff --git a/extensions/inference-triton-trtllm-extension/resources/settings.json b/extensions/inference-triton-trtllm-extension/resources/settings.json index 9c220eed7..26b80a686 100644 --- a/extensions/inference-triton-trtllm-extension/resources/settings.json +++ b/extensions/inference-triton-trtllm-extension/resources/settings.json @@ -1,4 +1,16 @@ [ + { + "key": "tritonllm-api-key", + "title": "API Key", + "description": "The Triton LLM API uses API keys for authentication.", + "controllerType": "input", + "controllerProps": { + "placeholder": "Insert API Key", + "value": "", + "type": "password", + "inputActions": ["unobscure", "copy"] + } + }, { "key": "chat-completions-endpoint", "title": "Chat Completions Endpoint", @@ -8,16 +20,5 @@ "placeholder": "http://localhost:8000/v2/models/tensorrt_llm_bls/generate", "value": "http://localhost:8000/v2/models/tensorrt_llm_bls/generate" } - }, - { - "key": "tritonllm-api-key", - "title": "Triton LLM API Key", - "description": "The Triton LLM API uses API keys for authentication.", - "controllerType": "input", - "controllerProps": { - "placeholder": "xxxxxxxxxxxxxxxxxxxx", - "value": "", - "type": "password" - } } ]