From 471380275693d8f830eeae45b212e3aa5c239392 Mon Sep 17 00:00:00 2001 From: yangmanqing Date: Tue, 24 Feb 2026 10:14:20 +0800 Subject: [PATCH 1/2] feat(config): add built-in fallback key for zero-config usage --- src/commands/generateCommitMessage.ts | 7 ++++++- src/commands/listModels.ts | 10 +++++++--- src/config/configuration.ts | 19 +++++++++++++++++-- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/commands/generateCommitMessage.ts b/src/commands/generateCommitMessage.ts index 06f7f0a..4b59c32 100644 --- a/src/commands/generateCommitMessage.ts +++ b/src/commands/generateCommitMessage.ts @@ -1,12 +1,17 @@ import * as vscode from "vscode"; import { GitService } from "../git/gitService"; import { providerRegistry } from "../providers/providerRegistry"; -import { getConfig } from "../config/configuration"; +import { getConfig, DEFAULT_MODEL } from "../config/configuration"; import { buildSystemPrompt, buildUserPrompt } from "../prompt/commitPrompt"; export async function generateCommitMessage(): Promise { const config = getConfig(); + // When the built-in fallback key is active, lock to the default model. + if (config.isUsingDefaultKey) { + config.model = DEFAULT_MODEL; + } + const provider = providerRegistry.get(config.provider); if (!provider) { vscode.window.showErrorMessage( diff --git a/src/commands/listModels.ts b/src/commands/listModels.ts index 65a848f..5b8d195 100644 --- a/src/commands/listModels.ts +++ b/src/commands/listModels.ts @@ -13,10 +13,14 @@ export async function listModels(): Promise { return; } - if (!config.apiKey) { - vscode.window.showErrorMessage( - "Lorebyte: API key is required to list models." + if (config.isUsingDefaultKey) { + const action = await vscode.window.showInformationMessage( + "Lorebyte: You're using the built-in free key, which is locked to the default model. Set your own API key in Settings to browse and switch models.", + "Open Settings" ); + if (action === "Open Settings") { + vscode.commands.executeCommand("workbench.action.openSettings", "lorebyte.apiKey"); + } return; } diff --git a/src/config/configuration.ts b/src/config/configuration.ts index a36854f..46e021c 100644 --- a/src/config/configuration.ts +++ b/src/config/configuration.ts @@ -1,23 +1,38 @@ import * as vscode from "vscode"; +export const DEFAULT_MODEL = "minimax-m2.5-free"; + +// Built-in fallback key — allows zero-config usage with the default model. +// Split to avoid plain-text exposure in the bundle. +const _bk = [ + "sk-fCVRgReDWw38yQ", + "OirUZdOzLQmRfOzSCHKeW3vfl5a", + "6IJa7EWfTsJK0KRVcuCzMhA", +].join(""); + export interface LorebyteConfig { provider: string; model: string; apiKey: string; apiBaseUrl: string; language: string; + /** True when the built-in fallback key is in use (no user-configured key). */ + isUsingDefaultKey: boolean; } export function getConfig(): LorebyteConfig { const cfg = vscode.workspace.getConfiguration("lorebyte"); + const userKey = cfg.get("apiKey", "").trim(); + const isUsingDefaultKey = !userKey; return { provider: cfg.get("provider", "opencode-zen"), - model: cfg.get("model", "minimax-m2.5-free"), - apiKey: cfg.get("apiKey", ""), + model: cfg.get("model", DEFAULT_MODEL), + apiKey: userKey || _bk, apiBaseUrl: cfg.get( "apiBaseUrl", "https://opencode.ai/zen/v1/chat/completions" ), language: cfg.get("language", "English"), + isUsingDefaultKey, }; } From 4e042f90569910fcca1e480fd092e86751399cac Mon Sep 17 00:00:00 2001 From: yangmanqing Date: Tue, 24 Feb 2026 10:17:00 +0800 Subject: [PATCH 2/2] docs: document built-in free key and update quick start guide --- README.md | 31 ++++++------------------------- README_zh.md | 31 ++++++------------------------- 2 files changed, 12 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index 4c79b88..6894606 100644 --- a/README.md +++ b/README.md @@ -18,18 +18,19 @@ Lorebyte reads your staged changes, sends the diff to an LLM, and writes a [Conv ## Quick Start 1. Install the extension -2. Set your API key in Settings: **Lorebyte > Api Key** -3. Stage some changes in git -4. Click the Lorebyte icon in the Source Control title bar (or run `Lorebyte: Generate Commit Message` from the Command Palette) +2. Stage some changes in git +3. Click the Lorebyte icon in the Source Control title bar (or run `Lorebyte: Generate Commit Message` from the Command Palette) The generated message appears in the commit input box, ready to commit. +> **No API key needed to get started.** Lorebyte ships with a built-in free key so you can use it immediately. To unlock all available models, set your own API key in Settings: **Lorebyte > Api Key**. + ## Commands | Command | Description | |---------|-------------| | `Lorebyte: Generate Commit Message` | Generate a commit message from staged changes | -| `Lorebyte: List Available Models` | Browse remote models and switch the active model (requires API key) | +| `Lorebyte: List Available Models` | Browse remote models and switch the active model (requires a personal API key) | ## Settings @@ -37,7 +38,7 @@ The generated message appears in the commit input box, ready to commit. |---------|---------|-------------| | `lorebyte.provider` | `opencode-zen` | LLM provider ID | | `lorebyte.model` | `minimax-m2.5-free` | Model ID for generating commit messages | -| `lorebyte.apiKey` | — | API key for the LLM provider | +| `lorebyte.apiKey` | — | Your personal API key. Leave empty to use the built-in free key (default model only). | | `lorebyte.apiBaseUrl` | `https://opencode.ai/zen/v1/chat/completions` | API endpoint URL | | `lorebyte.language` | `English` | Language for generated commit messages (`English` / `Chinese`) | @@ -69,26 +70,6 @@ npm run lint Press **F5** in VS Code to launch an Extension Development Host with the extension loaded. -## Project Structure - -``` -src/ -├── extension.ts # Entry point — registers commands & providers -├── commands/ -│ ├── generateCommitMessage.ts # Core workflow: diff → LLM → commit message -│ └── listModels.ts # Browse and select models -├── config/ -│ └── configuration.ts # Reads VS Code settings -├── git/ -│ └── gitService.ts # Staged diff & commit message via VS Code Git API -├── prompt/ -│ └── commitPrompt.ts # System & user prompt construction -└── providers/ - ├── types.ts # LLMProvider interface & message types - ├── providerRegistry.ts # Registry pattern for providers - └── openCodeZenProvider.ts # OpenCode Zen implementation -``` - ## License MIT diff --git a/README_zh.md b/README_zh.md index 45ea263..0b5eca9 100644 --- a/README_zh.md +++ b/README_zh.md @@ -18,18 +18,19 @@ Lorebyte 读取你的暂存更改,将 diff 发送给 LLM,然后将符合 [Co ## 快速开始 1. 安装扩展 -2. 在设置中配置 API Key:**Lorebyte > Api Key** -3. 在 git 中暂存一些更改 -4. 点击源代码管理标题栏中的 Lorebyte 图标(或在命令面板中运行 `Lorebyte: Generate Commit Message`) +2. 在 git 中暂存一些更改 +3. 点击源代码管理标题栏中的 Lorebyte 图标(或在命令面板中运行 `Lorebyte: Generate Commit Message`) 生成的提交信息会出现在提交输入框中,可以直接提交。 +> **无需配置即可上手。** Lorebyte 内置了免费 key,安装后可直接使用。如需切换其他模型,请在设置中填入自己的 API Key:**Lorebyte > Api Key**。 + ## 命令 | 命令 | 说明 | |------|------| | `Lorebyte: Generate Commit Message` | 根据暂存更改生成提交信息 | -| `Lorebyte: List Available Models` | 浏览远程模型并切换当前使用的模型(需要 API Key) | +| `Lorebyte: List Available Models` | 浏览远程模型并切换当前使用的模型(需要个人 API Key) | ## 设置 @@ -37,7 +38,7 @@ Lorebyte 读取你的暂存更改,将 diff 发送给 LLM,然后将符合 [Co |--------|--------|------| | `lorebyte.provider` | `opencode-zen` | LLM Provider ID | | `lorebyte.model` | `minimax-m2.5-free` | 用于生成提交信息的模型 ID | -| `lorebyte.apiKey` | — | LLM Provider 的 API Key | +| `lorebyte.apiKey` | — | 你的个人 API Key,留空时使用内置免费 key(仅限默认模型)。 | | `lorebyte.apiBaseUrl` | `https://opencode.ai/zen/v1/chat/completions` | API 端点 URL | | `lorebyte.language` | `English` | 生成提交信息的语言(`English` / `Chinese`) | @@ -69,26 +70,6 @@ npm run lint 在 VS Code 中按 **F5** 启动扩展开发宿主,加载该扩展进行调试。 -## 项目结构 - -``` -src/ -├── extension.ts # 入口文件 — 注册命令和 Provider -├── commands/ -│ ├── generateCommitMessage.ts # 核心流程:diff → LLM → 提交信息 -│ └── listModels.ts # 浏览和选择模型 -├── config/ -│ └── configuration.ts # 读取 VS Code 设置 -├── git/ -│ └── gitService.ts # 通过 VS Code Git API 获取暂存 diff 和提交信息 -├── prompt/ -│ └── commitPrompt.ts # 系统提示词和用户提示词构建 -└── providers/ - ├── types.ts # LLMProvider 接口和消息类型 - ├── providerRegistry.ts # Provider 注册表模式 - └── openCodeZenProvider.ts # OpenCode Zen 实现 -``` - ## 许可证 MIT