Files
liuyao/scripts/load-secrets.mjs
woniu336 141ed9f4a8 feat(llm): DeepSeek Flash + 思考模式;本地密钥加载器
- llm_profiles 增加 thinking / reasoning_effort(migrations/0002),
  ensureD1Schema 容忍 ALTER 重复列,已有库平滑升级
- /api/read 按 profile 组装 thinking / reasoning_effort;只转发 delta.content,
  思考链 reasoning_content 不下发;max_tokens 4096
- 后台 LLM 表单新增「思考模式」「思考强度」,列表显示当前设置;测试连通沿用同一配置
- scripts/load-secrets.mjs:启动前读取 .llm.local(gitignore),
  dev / dev:bg / dev:vinext / build:vinext / start:vinext 共用
- 解卦面板显示「研墨中 · Ns」,思考模式首字慢时有提示
- 新增 llm-request 纯函数与 4 项测试;总 68 项测试通过

本地实测:DeepSeek Flash + thinking=high,/api/read 约 23s、840 字、四段齐全;
UI 4 标题/5 段、0 错误。密钥仅存于 .llm.local(不进仓库/D1)。
2026-11-05 14:36:38 +08:00

26 lines
1.0 KiB
JavaScript

/**
* 本地密钥加载(Node 侧工具脚本共用)。
*
* 读取项目根目录的 `.llm.local`(已 gitignore),只补齐**尚未设置**的环境变量,
* 不覆盖真实环境变量。格式:KEY=VALUE,支持 # 注释与引号。
*
* 为什么不用 `.env.local`:那个文件归 Next 管;vinext/vite 的配置在 Node 侧执行,
* 需要在启动前把变量放进 process.env,才能被 cloudflare.config.ts 映射成文本绑定。
*/
import fs from 'node:fs';
import path from 'node:path';
export function loadLocalSecrets(projectRoot) {
const file = path.join(projectRoot, '.llm.local');
if (!fs.existsSync(file)) return;
for (const raw of fs.readFileSync(file, 'utf8').split(/\r?\n/)) {
const line = raw.trim();
if (!line || line.startsWith('#')) continue;
const idx = line.indexOf('=');
if (idx <= 0) continue;
const key = line.slice(0, idx).trim();
const value = line.slice(idx + 1).trim().replace(/^["']|["']$/g, '');
if (key && !process.env[key]) process.env[key] = value;
}
}