@objectivex666/dsh-settings-search 1.6.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.en.md CHANGED
@@ -16,6 +16,8 @@
16
16
  - 📂 **In-page option search (v1.2.0)** — search beyond pages and reach the specific options inside them: Plugins-page tabs (`settings.plugins.tab`), Web UI plugin cards (`web-ui.plugin.item`), general rows, and more, each shown with a "page › option" breadcrumb.
17
17
  - 🔤 **Pinyin association search (v1.5.0)** — type initials (`sz`) or full pinyin (`shezhi`) to surface Chinese settings items; navigate with `↑`/`↓`, confirm with `Enter`, dismiss with `Esc`, and matched text is highlighted.
18
18
  - 🧠 **Intent search (v1.6.0)** — describe the goal in Chinese (e.g. 「太亮了」 "too bright", 「字太小」 "text too small") to surface matching settings without knowing their names, shown in a "You may want" group.
19
+ - 🤖 **AI-assisted search (v1.7.0)** — when nothing matches locally, your own model (OpenAI-compatible or Anthropic: Base URL / model / API key) understands your search intent and suggests settings. Off by default; configure it on the plugin's settings page.
20
+ - 🧾 **Logging & export (v1.7.0)** — records key plugin actions, searches, and AI requests; export, copy, or clear them from the plugin's settings page for troubleshooting. API keys are never logged.
19
21
  - 🧭 **Click-to-jump** — selecting a result clicks the matching left-nav entry to open its section; for tab options it also opens the tab and flashes the target row. A manual-path hint appears if automatic navigation is not possible.
20
22
  - 🌱 **Progressive indexing** — self-drawing settings rows are harvested from the rendered DOM (via their `[data-slot]` anchors) the first time their page is visited, then stay searchable.
21
23
  - 🛠 **Built-in settings page (v1.4.0)** — a "Settings Search" page in the left navigation shows the current version and checks npm for a newer release on demand; when one exists it hands you a copy-ready `dsh plugin update` command.
@@ -94,3 +96,14 @@ npm test # validates the host half, the dsh.client manifest, and the client bu
94
96
  > in-session `cordis_define` dynamic-plugin source). Because keeping it in
95
97
  > sync with the shipping package kept drifting silently, it was removed in
96
98
  > v1.4.1; retrieve it from git history (tag `v1.4.0`) if you need a reference.
99
+
100
+ ## Changelog & releases
101
+
102
+ Every version bump keeps git tags and GitHub Releases in sync, with a bilingual body that lists both new features and fixes:
103
+
104
+ - Update [CHANGELOG.md](./CHANGELOG.md) (Chinese) and [CHANGELOG.en.md](./CHANGELOG.en.md) (English), each with `### ✨ Features` and `### 🐛 Fixes` sections.
105
+ - Bump the version in `package.json` and the README, then tag and push as `vX.Y.Z`; GitHub Actions publishes to npm (`npm-publish.yml`) and creates a bilingual GitHub Release (`release.yml`).
106
+ - Preview the release body locally: `node scripts/release.mjs --version <ver>`
107
+ - Tag and publish for real: `node scripts/release.mjs --version <ver> --publish` (requires `gh` CLI, logged in)
108
+
109
+ > Without `--publish` the script only validates and prints the release body; it does not create a tag, push, or release.
package/README.md CHANGED
@@ -16,6 +16,8 @@
16
16
  - 📂 **页内选项搜索(v1.2.0)**:不只搜页面,还能直达每个设置页内部的具体选项——插件页的标签页(`settings.plugins.tab`)、Web UI 插件的卡片(`web-ui.plugin.item`)、通用设置行等,结果以「页面 › 选项」面包屑展示。
17
17
  - 🔤 **拼音联想搜索(v1.5.0)**:输入拼音首字母(如 `sz`)或全拼(如 `shezhi`)即可联想中文设置项;支持 `↑`/`↓` 选择、`Enter` 跳转、`Esc` 关闭,命中的文字自动高亮。
18
18
  - 🧠 **意图联想搜索(v1.6.0)**:直接描述想做的事(如「太亮了」「字太小」「忘记密码」),无需知道选项名即可联想真实设置项,结果在「猜你想找」分组展示。
19
+ - 🤖 **AI 联想搜索(v1.7.0)**:没有本地匹配时,用你配置的模型(OpenAI 兼容或 Anthropic:Base URL / 模型名 / API Key)理解搜索意图并推荐设置项。默认关闭,可在「设置搜索」页开启并配置。
20
+ - 🧾 **日志与导出(v1.7.0)**:记录插件运行、搜索与 AI 请求的关键动作,可在「设置搜索」页一键导出、复制或清空,便于排查问题。不会记录 API Key。
19
21
  - 🧭 **点击即达**:选中结果后自动点击对应的左侧导航项打开所在分区;若是页内标签页会继续点开对应标签,并高亮闪烁目标选项行。无法自动跳转时显示手动路径提示。
20
22
  - 🌱 **渐进索引**:自绘界面的设置行会在其所在页面首次被访问时从渲染 DOM 中收割标题并加入索引(此后始终可搜)。
21
23
  - 🛠 **自带设置页(v1.4.0)**:左侧导航新增「设置搜索」页——展示当前版本,一键检查 npm 注册表上的最新版本;有更新时直接给出复制就用的 `dsh plugin update` 命令。
@@ -95,3 +97,14 @@ npm test # 校验 host 半、dsh.client 清单、client bundle handoff
95
97
  > 历史说明:v1.1 及之前仓库曾附带 `dsh-settings-search.js`(会话内
96
98
  > `cordis_define` 动态插件源)。因与正式包代码长期双份维护漂移,已于 v1.4.1
97
99
  > 移除;如需动态用法可从 git 历史(tag `v1.4.0`)取回参考。
100
+
101
+ ## 更新日志与发布
102
+
103
+ 每次版本更新需同时更新 GitHub Release 与 git tag,正文为双语,并写明「新功能」与「修复」:
104
+
105
+ - 更新 [CHANGELOG.md](./CHANGELOG.md)(中文)与 [CHANGELOG.en.md](./CHANGELOG.en.md)(英文),两者各含 `### ✨ 新功能 / Features` 与 `### 🐛 修复 / Fixes`。
106
+ - 同步 `package.json` 与 README 的版本号,按 `vX.Y.Z` 打 tag 并推送;GitHub Actions 会同时发布到 npm(`npm-publish.yml`)并创建双语 GitHub Release(`release.yml`)。
107
+ - 本地预览 release 正文:`node scripts/release.mjs --version <ver>`
108
+ - 实际打 tag 并发布:`node scripts/release.mjs --version <ver> --publish`(需 `gh` CLI 且已登录)
109
+
110
+ > 未带 `--publish` 时脚本只校验并打印 release 正文,不会创建 tag、推送或发布。
package/lib/client.js CHANGED
@@ -30,7 +30,7 @@ window.__ModuleLoader__.load({
30
30
 
31
31
  const NS = 'settings-search-v5'
32
32
  /** Single source of truth is package.json — scripts/check.mjs asserts this matches. */
33
- const PKG_VERSION = '1.6.0'
33
+ const PKG_VERSION = '1.7.0'
34
34
  const NPM_NAME = '@objectivex666/dsh-settings-search'
35
35
  const zh = {
36
36
  title: '设置',
@@ -54,6 +54,36 @@ window.__ModuleLoader__.load({
54
54
  updCopy: '复制命令',
55
55
  updCopied: '已复制 ✓',
56
56
  updCopyFail: '复制失败,请长按上方命令手动复制。',
57
+ updCLI: 'DSH CLI',
58
+ updNpx: 'npx',
59
+ updRelease: '查看 release notes',
60
+ updRestart: '更新完成后重启 DSH,新版本才会生效。',
61
+ aiSearch: 'AI 联想搜索',
62
+ aiDesc: '没有直接匹配时,用你配置的模型(OpenAI 兼容或 Anthropic)理解目标并推荐设置项。',
63
+ aiPrivacy: 'AI 请求会发送到你配置的模型服务;API Key 仅保存在本机浏览器。',
64
+ aiOn: '已开启',
65
+ aiOff: '已关闭',
66
+ aiThinking: '正在用 AI 理解搜索意图…',
67
+ aiUnavailable: 'AI 联想暂不可用',
68
+ aiNeedConfig: '请先在「设置搜索」页配置 Base URL、模型名与 API Key。',
69
+ aiProvider: '接口类型',
70
+ aiOpenAI: 'OpenAI 兼容',
71
+ aiAnthropic: 'Anthropic',
72
+ aiBaseUrl: 'Base URL',
73
+ aiModel: '模型名',
74
+ aiApiKey: 'API Key',
75
+ aiConfigSave: '保存配置',
76
+ aiConfigSaved: '已保存 ✓',
77
+ logTitle: '日志',
78
+ logDesc: '记录插件运行、搜索与 AI 请求的关键动作,便于排查问题。',
79
+ logEmpty: '暂无日志',
80
+ logExport: '导出日志',
81
+ logCopy: '复制日志',
82
+ logCopied: '已复制 ✓',
83
+ logCopyFail: '复制失败,请稍后重试。',
84
+ logClear: '清空日志',
85
+ logCleared: '已清空',
86
+ logExportFail: '导出失败,请重试。',
57
87
  }
58
88
  const en = {
59
89
  title: 'Settings',
@@ -77,6 +107,36 @@ window.__ModuleLoader__.load({
77
107
  updCopy: 'Copy command',
78
108
  updCopied: 'Copied ✓',
79
109
  updCopyFail: 'Copy failed — please long-press the command above.',
110
+ updCLI: 'DSH CLI',
111
+ updNpx: 'npx',
112
+ updRelease: 'View release notes',
113
+ updRestart: 'Restart DSH after updating for the new version to take effect.',
114
+ aiSearch: 'AI-assisted search',
115
+ aiDesc: 'When no direct match exists, your own model (OpenAI-compatible or Anthropic) understands your goal and suggests settings.',
116
+ aiPrivacy: 'AI requests are sent to the model service you configure; the API key stays only in your browser.',
117
+ aiOn: 'On',
118
+ aiOff: 'Off',
119
+ aiThinking: 'Understanding your intent with AI…',
120
+ aiUnavailable: 'AI suggestions are unavailable',
121
+ aiNeedConfig: 'Configure Base URL, model, and API key in the Settings Search panel first.',
122
+ aiProvider: 'API type',
123
+ aiOpenAI: 'OpenAI-compatible',
124
+ aiAnthropic: 'Anthropic',
125
+ aiBaseUrl: 'Base URL',
126
+ aiModel: 'Model',
127
+ aiApiKey: 'API Key',
128
+ aiConfigSave: 'Save config',
129
+ aiConfigSaved: 'Saved ✓',
130
+ logTitle: 'Logs',
131
+ logDesc: 'Logs key plugin actions, searches, and AI requests to help troubleshoot.',
132
+ logEmpty: 'No logs yet',
133
+ logExport: 'Export logs',
134
+ logCopy: 'Copy logs',
135
+ logCopied: 'Copied ✓',
136
+ logCopyFail: 'Copy failed. Please try again.',
137
+ logClear: 'Clear logs',
138
+ logCleared: 'Cleared',
139
+ logExportFail: 'Export failed. Please try again.',
80
140
  }
81
141
 
82
142
  /** Inner-row slots that represent specific options inside one page. */
@@ -223,6 +283,162 @@ window.__ModuleLoader__.load({
223
283
  return hits
224
284
  }
225
285
 
286
+ const AI_TOGGLE_EVENT = 'dsh-settings-search:ai-toggle'
287
+ const AI_CONFIG_EVENT = 'dsh-settings-search:ai-config'
288
+ /** Simple in-memory log ring used by the settings panel's export/log UI. */
289
+ const LOG_EVENT = 'dsh-settings-search:log'
290
+ const LOG_MAX = 500
291
+ const LOGS = []
292
+ const log = (level, msg, meta) => {
293
+ if (typeof window === 'undefined') return
294
+ LOGS.push({ time: new Date().toISOString(), level, msg, meta })
295
+ if (LOGS.length > LOG_MAX) LOGS.splice(0, LOGS.length - LOG_MAX)
296
+ try { window.dispatchEvent(new CustomEvent(LOG_EVENT, { detail: LOGS.length })) } catch {}
297
+ }
298
+ const formatLogs = (logs) => {
299
+ const lines = [
300
+ 'dsh-settings-search log',
301
+ `version: ${PKG_VERSION}`,
302
+ `exported: ${new Date().toISOString()}`,
303
+ `count: ${logs.length}`,
304
+ '',
305
+ ]
306
+ for (const entry of logs) {
307
+ lines.push(`[${entry.time}] [${entry.level}] ${entry.msg}${entry.meta ? ' ' + JSON.stringify(entry.meta) : ''}`)
308
+ }
309
+ return lines.join('\n')
310
+ }
311
+ const AI_CACHE = new Map()
312
+ const AI_STORAGE_KEY = 'dsh-settings-search:ai-enabled'
313
+ const AI_PROVIDER_KEY = 'dsh-settings-search:ai-provider'
314
+ const AI_BASE_URL_KEY = 'dsh-settings-search:ai-base-url'
315
+ const AI_MODEL_KEY = 'dsh-settings-search:ai-model'
316
+ const AI_API_KEY_KEY = 'dsh-settings-search:ai-api-key'
317
+ const aiSearchEnabled = () => {
318
+ if (typeof localStorage === 'undefined') return false
319
+ return localStorage.getItem(AI_STORAGE_KEY) === '1'
320
+ }
321
+ const setAiSearchEnabled = (enabled) => {
322
+ if (typeof localStorage === 'undefined') return
323
+ localStorage.setItem(AI_STORAGE_KEY, enabled ? '1' : '0')
324
+ window.dispatchEvent(new CustomEvent(AI_TOGGLE_EVENT, { detail: enabled }))
325
+ }
326
+ const aiConfig = () => {
327
+ if (typeof localStorage === 'undefined') return { provider: 'openai', baseUrl: '', model: '', apiKey: '' }
328
+ const providerRaw = (localStorage.getItem(AI_PROVIDER_KEY) ?? 'openai').trim()
329
+ return {
330
+ provider: providerRaw === 'anthropic' ? 'anthropic' : 'openai',
331
+ baseUrl: (localStorage.getItem(AI_BASE_URL_KEY) ?? '').trim(),
332
+ model: (localStorage.getItem(AI_MODEL_KEY) ?? '').trim(),
333
+ apiKey: (localStorage.getItem(AI_API_KEY_KEY) ?? '').trim(),
334
+ }
335
+ }
336
+ const setAiConfig = (cfg) => {
337
+ if (typeof localStorage === 'undefined') return
338
+ localStorage.setItem(AI_PROVIDER_KEY, cfg.provider === 'anthropic' ? 'anthropic' : 'openai')
339
+ localStorage.setItem(AI_BASE_URL_KEY, cfg.baseUrl ?? '')
340
+ localStorage.setItem(AI_MODEL_KEY, cfg.model ?? '')
341
+ localStorage.setItem(AI_API_KEY_KEY, cfg.apiKey ?? '')
342
+ window.dispatchEvent(new CustomEvent(AI_CONFIG_EVENT))
343
+ }
344
+ const extractAiKeywords = (raw) => {
345
+ const text = String(raw ?? '').replace(/^```(?:json)?/i, '').replace(/```$/, '').trim()
346
+ const start = text.indexOf('{')
347
+ const end = text.lastIndexOf('}')
348
+ if (start === -1 || end <= start) return []
349
+ const parsed = JSON.parse(text.slice(start, end + 1))
350
+ const values = Array.isArray(parsed) ? parsed : parsed?.keywords
351
+ if (!Array.isArray(values)) return []
352
+ return [...new Set(values
353
+ .filter((value) => typeof value === 'string')
354
+ .map((value) => value.trim().slice(0, 24))
355
+ .filter(Boolean))]
356
+ .slice(0, 6)
357
+ }
358
+ const AI_PROMPT = '你是设置搜索助手。只输出 JSON 对象,格式为 {"keywords":["..."]}。keywords 最多 6 个,每个最多 12 个字符,只能从用户提供的设置索引中选择或提取核心词,不要解释。'
359
+ const chatCompletionsUrl = (baseUrl) => {
360
+ const trimmed = String(baseUrl).trim().replace(/\/+$/, '')
361
+ return /\/chat\/completions$/i.test(trimmed) ? trimmed : `${trimmed}/chat/completions`
362
+ }
363
+ const anthropicMessagesUrl = (baseUrl) => {
364
+ const trimmed = String(baseUrl).trim().replace(/\/+$/, '')
365
+ if (/\/v1\/messages$/i.test(trimmed)) return trimmed
366
+ return /\/v1$/i.test(trimmed) ? `${trimmed}/messages` : `${trimmed}/v1/messages`
367
+ }
368
+ const requestUserAi = async (query, labels, signal) => {
369
+ const { provider, baseUrl, model, apiKey } = aiConfig()
370
+ if (!baseUrl || !model || !apiKey) return []
371
+ const isAnthropic = provider === 'anthropic'
372
+ const startedAt = Date.now()
373
+ log('info', 'AI 请求', { provider, model, query: String(query).slice(0, 50) })
374
+ let timer
375
+ const deadline = new Promise((_, reject) => {
376
+ timer = setTimeout(() => {
377
+ const error = new Error('AI request timed out')
378
+ error.name = 'AI_TIMEOUT'
379
+ reject(error)
380
+ }, 12000)
381
+ })
382
+ const work = (async () => {
383
+ const userContent = `用户目标:${query}\n设置索引:\n${labels}`
384
+ const headers = {
385
+ 'content-type': 'application/json',
386
+ ...(isAnthropic
387
+ ? { 'x-api-key': apiKey, 'anthropic-version': '2023-06-01', 'anthropic-dangerous-direct-browser-access': 'true' }
388
+ : { authorization: `Bearer ${apiKey}` }),
389
+ }
390
+ const body = isAnthropic
391
+ ? {
392
+ model,
393
+ max_tokens: 1024,
394
+ system: AI_PROMPT,
395
+ messages: [{ role: 'user', content: userContent }],
396
+ temperature: 0,
397
+ }
398
+ : {
399
+ model,
400
+ messages: [
401
+ { role: 'system', content: AI_PROMPT },
402
+ { role: 'user', content: userContent },
403
+ ],
404
+ temperature: 0,
405
+ }
406
+ const response = await fetch(isAnthropic ? anthropicMessagesUrl(baseUrl) : chatCompletionsUrl(baseUrl), {
407
+ method: 'POST',
408
+ headers,
409
+ signal,
410
+ body: JSON.stringify(body),
411
+ })
412
+ if (!response.ok) throw new Error(`HTTP ${response.status}`)
413
+ const data = await response.json()
414
+ const content = isAnthropic
415
+ ? (data?.content ?? []).filter((block) => block?.type === 'text').map((block) => block.text).join('')
416
+ : data?.choices?.[0]?.message?.content ?? ''
417
+ return extractAiKeywords(content)
418
+ })()
419
+ try {
420
+ const keywords = await Promise.race([work, deadline])
421
+ log('info', 'AI 结果', { count: keywords.length, duration: Date.now() - startedAt })
422
+ return keywords
423
+ } catch (error) {
424
+ if (error.name === 'AbortError') {
425
+ log('warn', 'AI 请求取消', { duration: Date.now() - startedAt })
426
+ throw error
427
+ }
428
+ log('error', 'AI 请求失败', { message: String(error?.message ?? error).slice(0, 160), duration: Date.now() - startedAt })
429
+ throw error
430
+ } finally {
431
+ clearTimeout(timer)
432
+ }
433
+ }
434
+ const requestAiKeywords = async (query, labels, signal) => {
435
+ const cacheKey = query.toLowerCase()
436
+ if (AI_CACHE.has(cacheKey)) return AI_CACHE.get(cacheKey)
437
+ const keywords = await requestUserAi(query, labels, signal)
438
+ if (keywords.length > 0) AI_CACHE.set(cacheKey, keywords)
439
+ return keywords
440
+ }
441
+
226
442
  const CSS = `
227
443
  .sss-wrap { position: relative; display: flex; flex-direction: column; gap: 8px; }
228
444
  .sss-title { font-size: 16px; font-weight: 600; line-height: 24px; color: var(--dsw-alias-label-primary); }
@@ -245,23 +461,54 @@ window.__ModuleLoader__.load({
245
461
  .sss-item-path { font-size: 10px; line-height: 14px; color: var(--dsw-alias-label-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
246
462
  .sss-item-kind { flex-shrink: 0; font-size: 10px; color: var(--dsw-alias-label-secondary); border: 1px solid var(--dsw-alias-border-l2); border-radius: 4px; padding: 1px 5px; }
247
463
  .sss-item-kind.sss-via { color: var(--dsw-alias-label-primary); background: var(--dsw-alias-interactive-bg-hover); }
464
+ .sss-ai-note { margin: 0; padding: 6px 8px; color: var(--dsw-alias-label-secondary); font-size: 12px; line-height: 18px; }
248
465
  .sss-empty { margin: 0; padding: 10px 8px; color: var(--dsw-alias-label-secondary); font-size: 13px; }
249
466
  .sss-guide { padding: 7px 10px; border-radius: 8px; background: var(--dsw-alias-bg-layer-1); border: 1px solid var(--dsw-alias-border-l1); color: var(--dsw-alias-label-primary); font-size: 12px; line-height: 18px; }
250
467
  @keyframes sssFlashBg { 0% { background-color: var(--dsw-alias-interactive-bg-hover); } 100% { background-color: transparent; } }
251
468
  .sss-flash { animation: sssFlashBg 1.8s ease-out; border-radius: 8px; }
252
- .sss-upd { display: flex; flex-direction: column; gap: 12px; padding: 16px; max-width: 560px; }
253
- .sss-upd-title { font-size: 15px; font-weight: 600; line-height: 22px; color: var(--dsw-alias-label-primary); margin: 0; }
254
- .sss-upd-desc { margin: 0; font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-secondary); }
255
- .sss-upd-card { display: flex; flex-direction: column; gap: 10px; padding: 14px; border: 1px solid var(--dsw-alias-border-l2); border-radius: 10px; background: var(--dsw-alias-bg-layer-1); }
256
- .sss-upd-row { display: flex; align-items: center; gap: 8px; font-size: 13px; line-height: 20px; }
257
- .sss-upd-key { flex-shrink: 0; width: 88px; color: var(--dsw-alias-label-secondary); }
258
- .sss-upd-val { color: var(--dsw-alias-label-primary); }
259
- .sss-upd-badge { flex-shrink: 0; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--dsw-alias-border-l2); background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-secondary); font-size: 11px; line-height: 18px; }
260
- .sss-btn { height: 28px; padding: 0 12px; border-radius: 7px; border: 1px solid var(--dsw-alias-border-l2); background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-primary); font-size: 12px; cursor: pointer; }
261
- .sss-btn:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }
262
- .sss-btn:disabled { opacity: .55; cursor: default; }
263
- .sss-cmd { user-select: all; font-family: ui-monospace, Consolas, 'Courier New', monospace; font-size: 11.5px; line-height: 20px; color: var(--dsw-alias-label-primary); background: var(--dsw-alias-bg-layer-1); border: 1px solid var(--dsw-alias-border-l2); border-radius: 6px; padding: 4px 8px; word-break: break-all; }
264
- .sss-upd-note { margin: 0; font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-secondary); }
469
+ .sss-vr { list-style: none; border: 1px solid var(--dsw-alias-border-l2); background: var(--dsw-alias-bg-layer-3); border-radius: 12px; max-width: 780px; width: 100%; box-sizing: border-box; transition: border-color .16s, background .16s; }
470
+ .sss-vr:hover { border-color: var(--dsw-alias-label-dimmed); }
471
+ .sss-vr-open { background: var(--dsw-alias-bg-layer-2); border-color: var(--dsw-alias-label-dimmed); }
472
+ .sss-vr-header { appearance: none; width: 100%; font: inherit; color: inherit; text-align: left; cursor: pointer; background: 0 0; border: 0; border-radius: 12px; align-items: center; gap: 12px; padding: 14px 16px; display: flex; }
473
+ .sss-vr-header:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: -2px; }
474
+ .sss-vr-headText { flex-direction: column; flex: 1; gap: 4px; min-width: 0; display: flex; }
475
+ .sss-vr-name { color: var(--dsw-alias-label-primary); font-size: 15px; font-weight: 600; line-height: 1.4; }
476
+ .sss-vr-desc { color: var(--dsw-alias-label-tertiary); font-size: 13px; line-height: 1.5; }
477
+ .sss-vr-chevron { color: var(--dsw-alias-label-tertiary); flex: none; transition: transform .16s; font-size: 12px; line-height: 1; }
478
+ .sss-vr-chevron-open { transform: rotate(180deg); }
479
+ .sss-vr-body { border-top: 1px solid var(--dsw-alias-border-l2); margin: 0 16px; padding-bottom: 8px; }
480
+ .sss-vr-field { content-visibility: auto; contain-intrinsic-size: auto 96px; flex-direction: column; gap: 6px; padding: 12px 0; display: flex; }
481
+ .sss-vr-field + .sss-vr-field { border-top: 1px solid var(--dsw-alias-border-l2); }
482
+ .sss-vr-form { gap: 6px; }
483
+ .sss-vr-field-head { align-items: center; gap: 8px; display: flex; }
484
+ .sss-vr-label { min-width: 0; color: var(--dsw-alias-label-primary); flex: 1; font-size: 13px; font-weight: 500; line-height: 1.5; }
485
+ .sss-vr-hint { color: var(--dsw-alias-label-tertiary); margin: 0; font-size: 12px; line-height: 1.5; }
486
+ .sss-vr-value { color: var(--dsw-alias-label-primary); font-size: 13px; font-weight: 500; line-height: 1.5; }
487
+ .sss-vr-input { border: 1px solid var(--dsw-alias-border-l2); background: var(--dsw-alias-bg-layer-3); min-height: 34px; font: inherit; color: var(--dsw-alias-label-primary); border-radius: 8px; padding: 6px 12px; font-size: 13px; line-height: 1.5; width: 100%; box-sizing: border-box; }
488
+ .sss-vr-input:focus-visible { border-color: var(--dsw-alias-brand-primary); outline: none; }
489
+ .sss-vr-input::placeholder { color: var(--dsw-alias-label-dimmed); }
490
+ .sss-vr-select { cursor: pointer; }
491
+ .sss-vr-check { width: 16px; height: 16px; accent-color: var(--dsw-alias-brand-primary); cursor: pointer; margin: 0; }
492
+ .sss-vr-btn { appearance: none; font: inherit; cursor: pointer; border: 1px solid var(--dsw-alias-border-l2); border-radius: 8px; padding: 5px 14px; font-size: 13px; line-height: 1.5; color: var(--dsw-alias-label-secondary); background: 0 0; }
493
+ .sss-vr-btn:hover:not(:disabled) { color: var(--dsw-alias-label-primary); border-color: var(--dsw-alias-label-dimmed); }
494
+ .sss-vr-btn:disabled { opacity: .4; cursor: default; }
495
+ .sss-vr-btn:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 1px; }
496
+ .sss-vr-primary { background: var(--dsw-alias-label-primary); color: var(--dsw-alias-bg-layer-3); border-color: transparent; }
497
+ .sss-vr-primary:hover:not(:disabled) { color: var(--dsw-alias-bg-layer-3); border-color: transparent; }
498
+ .sss-vr-badge { white-space: nowrap; background: var(--dsw-alias-bg-module-platform); color: var(--dsw-alias-label-secondary); border-radius: 999px; padding: 1px 8px; font-size: 11px; font-weight: 500; line-height: 17px; }
499
+ .sss-vr-code { user-select: all; display: block; width: 100%; box-sizing: border-box; overflow-x: auto; white-space: pre; padding: 9px 11px; border: 1px solid var(--dsw-alias-border-l2); border-radius: 8px; background: var(--dsw-alias-bg-layer-3); color: var(--dsw-alias-label-primary); font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 12px; line-height: 1.55; }
500
+ .sss-vr-note { color: var(--dsw-alias-label-tertiary); margin: 0; font-size: 12px; line-height: 1.5; }
501
+ .sss-vr-row { display: flex; align-items: center; gap: 8px; font-size: 13px; line-height: 20px; flex-wrap: wrap; }
502
+ .sss-vr-rowname { color: var(--dsw-alias-label-tertiary); font-size: 13px; line-height: 1.5; }
503
+ .sss-vr-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding-top: 1px; }
504
+ .sss-vr-update { width: 100%; box-sizing: border-box; border: 1px solid var(--dsw-alias-border-l2); border-radius: 10px; background: var(--dsw-alias-bg-module-platform); padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
505
+ .sss-vr-update-title { font-size: 13px; font-weight: 650; color: var(--dsw-alias-label-primary); line-height: 1.5; }
506
+ .sss-vr-update-command { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
507
+ .sss-vr-update-command-label { font-size: 11px; font-weight: 500; color: var(--dsw-alias-label-tertiary); line-height: 1.4; }
508
+ .sss-vr-update-note { margin: 0; padding: 7px 9px; border-left: 2px solid var(--dsw-alias-label-dimmed); background: var(--dsw-alias-bg-layer-3); border-radius: 0 7px 7px 0; color: var(--dsw-alias-label-tertiary); font-size: 11px; line-height: 1.55; }
509
+ .sss-vr-update-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding-top: 1px; }
510
+ .sss-vr-link { appearance: none; font: inherit; cursor: pointer; border: 1px solid var(--dsw-alias-border-l2); border-radius: 8px; padding: 5px 14px; font-size: 13px; line-height: 1.5; color: var(--dsw-alias-label-secondary); background: 0 0; text-decoration: none; display: inline-flex; align-items: center; }
511
+ .sss-vr-link:hover { color: var(--dsw-alias-label-primary); border-color: var(--dsw-alias-label-dimmed); }
265
512
  `
266
513
  let stylesInstalled = false
267
514
  function installStyles() {
@@ -504,6 +751,7 @@ window.__ModuleLoader__.load({
504
751
  }
505
752
 
506
753
  function apply(ctx) {
754
+ log('info', '应用装载', { version: PKG_VERSION })
507
755
  ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'settings-search: dictionaries')
508
756
  const t = ctx.locale.bind(NS)
509
757
  ctx.effect(() => {
@@ -538,6 +786,10 @@ window.__ModuleLoader__.load({
538
786
  const [tick, setTick] = React.useState(0)
539
787
  const [, forceTick] = React.useReducer((x) => x + 1, 0)
540
788
  void tick
789
+ const [aiEnabled, setAiEnabled] = React.useState(aiSearchEnabled)
790
+ const [aiKeywords, setAiKeywords] = React.useState([])
791
+ const [aiStatus, setAiStatus] = React.useState('idle')
792
+ const aiAbortRef = React.useRef(null)
541
793
 
542
794
  React.useEffect(() => {
543
795
  const watched = ['settings.section', ...DEEP_SLOTS.map((c) => c.slot)]
@@ -560,6 +812,18 @@ window.__ModuleLoader__.load({
560
812
  }
561
813
  }, [])
562
814
 
815
+ React.useEffect(() => {
816
+ const sync = () => setAiEnabled(aiSearchEnabled())
817
+ const onConfig = () => forceTick()
818
+ window.addEventListener(AI_TOGGLE_EVENT, sync)
819
+ window.addEventListener(AI_CONFIG_EVENT, onConfig)
820
+ return () => {
821
+ window.removeEventListener(AI_TOGGLE_EVENT, sync)
822
+ window.removeEventListener(AI_CONFIG_EVENT, onConfig)
823
+ aiAbortRef.current?.abort()
824
+ }
825
+ }, [])
826
+
563
827
  const q = query.trim().toLowerCase()
564
828
  const tokens = q.split(/\s+/).filter(Boolean)
565
829
 
@@ -584,6 +848,9 @@ window.__ModuleLoader__.load({
584
848
  if (kwMatch(item, haystackLower, kw)) return kw
585
849
  }
586
850
  }
851
+ for (const kw of aiKeywords) {
852
+ if (kwMatch(item, haystackLower, kw)) return `AI · ${kw}`
853
+ }
587
854
  return null
588
855
  }
589
856
  const mappedSections = q === '' ? [] : sections.map((s) => ({
@@ -598,6 +865,8 @@ window.__ModuleLoader__.load({
598
865
  }))
599
866
  const shownPages = mappedSections.filter((s) => directMatch(s, s.hay))
600
867
  const shownOptions = mappedOptions.filter((o) => directMatch(o, o.hay))
868
+ const noLocalMatch = shownPages.length === 0 && shownOptions.length === 0 &&
869
+ tokens.every((tok) => (expandedKeywords.get(tok) ?? []).length === 0)
601
870
  const related = [
602
871
  ...mappedSections
603
872
  .map((s) => ({ item: s, kind: 'page', via: relatedKeyword(s, s.hay) }))
@@ -609,6 +878,50 @@ window.__ModuleLoader__.load({
609
878
  const none = q !== '' && shownPages.length === 0 && shownOptions.length === 0 && related.length === 0
610
879
  const results = [...shownPages, ...shownOptions, ...related.map((r) => r.item)]
611
880
 
881
+ const cfg = aiConfig()
882
+ const aiConfigured = Boolean(cfg.baseUrl && cfg.model && cfg.apiKey)
883
+ const aiReady = aiEnabled && aiConfigured && q.length >= 2 && noLocalMatch
884
+ React.useEffect(() => {
885
+ if (!aiReady) return
886
+ setAiKeywords([])
887
+ setAiStatus('idle')
888
+ let alive = true
889
+ const controller = new AbortController()
890
+ const timer = setTimeout(() => {
891
+ aiAbortRef.current?.abort()
892
+ aiAbortRef.current = controller
893
+ setAiStatus('loading')
894
+ const labels = [...new Set([
895
+ ...sections.map((item) => item.label),
896
+ ...deeps.map((item) => `${item.parentLabel} ${item.label}`),
897
+ ].map((label) => label.trim()).filter(Boolean))].slice(0, 48).join('\n')
898
+ requestAiKeywords(q, labels, controller.signal).then((keywords) => {
899
+ if (!alive) return
900
+ setAiKeywords(keywords)
901
+ setAiStatus(keywords.length > 0 ? 'ready' : 'idle')
902
+ }).catch((error) => {
903
+ if (!alive || error.name === 'AbortError') return
904
+ setAiKeywords([])
905
+ setAiStatus('error')
906
+ }).finally(() => {
907
+ if (aiAbortRef.current === controller) aiAbortRef.current = null
908
+ })
909
+ }, 700)
910
+ return () => {
911
+ alive = false
912
+ clearTimeout(timer)
913
+ controller.abort()
914
+ }
915
+ }, [aiReady, aiEnabled, q])
916
+
917
+ const loggedQueryRef = React.useRef('')
918
+ React.useEffect(() => {
919
+ if (q === '') return
920
+ if (loggedQueryRef.current === q) return
921
+ loggedQueryRef.current = q
922
+ log('info', '搜索', { query: query.slice(0, 50), pages: shownPages.length, options: shownOptions.length, related: related.length })
923
+ }, [q, shownPages.length, shownOptions.length, related.length])
924
+
612
925
  const [hint, setHint] = React.useState(null)
613
926
  const [active, setActive] = React.useState(0)
614
927
  const popRef = React.useRef(null)
@@ -621,6 +934,7 @@ window.__ModuleLoader__.load({
621
934
  }, [activeIndex, q])
622
935
  const pick = (item) => {
623
936
  setOpen(false)
937
+ log('info', '打开设置', { kind: item.kind, id: item.id || item.key || '', label: String(item.label).slice(0, 60) })
624
938
  const jumped = item.kind === 'page'
625
939
  ? navigator.jumpToPage(item)
626
940
  : navigator.jumpToOption(item)
@@ -726,7 +1040,13 @@ window.__ModuleLoader__.load({
726
1040
  ]),
727
1041
  open && q !== '' ? React.createElement('div', { className: 'sss-pop', ref: popRef }, [
728
1042
  none
729
- ? React.createElement('p', { className: 'sss-empty' }, t('empty'))
1043
+ ? (aiStatus === 'loading'
1044
+ ? React.createElement('p', { className: 'sss-ai-note' }, t('aiThinking'))
1045
+ : aiStatus === 'error'
1046
+ ? React.createElement('p', { className: 'sss-ai-note' }, t('aiUnavailable'))
1047
+ : (aiEnabled && !aiConfigured)
1048
+ ? React.createElement('p', { className: 'sss-ai-note' }, t('aiNeedConfig'))
1049
+ : React.createElement('p', { className: 'sss-empty' }, t('empty')))
730
1050
  : React.createElement('div', { className: 'sss-groups' }, [
731
1051
  shownPages.length > 0 ? React.createElement('div', { className: 'sss-group' }, [
732
1052
  React.createElement('div', { className: 'sss-group-title' }, t('pages')),
@@ -763,10 +1083,29 @@ window.__ModuleLoader__.load({
763
1083
  }
764
1084
 
765
1085
  function UpdatePanel() {
1086
+ const [open, setOpen] = React.useState(true)
766
1087
  const [state, setState] = React.useState('idle') // idle | loading | newest | outdated | error
767
1088
  const [latest, setLatest] = React.useState('')
768
1089
  const [copied, setCopied] = React.useState(false)
769
1090
  const [copyFailed, setCopyFailed] = React.useState(false)
1091
+ const [aiOn, setAiOn] = React.useState(aiSearchEnabled)
1092
+ const cfg = aiConfig()
1093
+ const [provider, setProvider] = React.useState(cfg.provider)
1094
+ const [baseUrl, setBaseUrl] = React.useState(cfg.baseUrl)
1095
+ const [model, setModel] = React.useState(cfg.model)
1096
+ const [apiKey, setApiKey] = React.useState(cfg.apiKey)
1097
+ const [aiSaved, setAiSaved] = React.useState(false)
1098
+ const [, setLogVersion] = React.useState(0)
1099
+ const [logCopied, setLogCopied] = React.useState(false)
1100
+ const [logCopyFail, setLogCopyFail] = React.useState(false)
1101
+ const [logExportFail, setLogExportFail] = React.useState(false)
1102
+ const [logCleared, setLogCleared] = React.useState(false)
1103
+
1104
+ React.useEffect(() => {
1105
+ const sync = () => setAiOn(aiSearchEnabled())
1106
+ window.addEventListener(AI_TOGGLE_EVENT, sync)
1107
+ return () => window.removeEventListener(AI_TOGGLE_EVENT, sync)
1108
+ }, [])
770
1109
 
771
1110
  React.useEffect(() => {
772
1111
  if (!copied) return
@@ -774,6 +1113,80 @@ window.__ModuleLoader__.load({
774
1113
  return () => clearTimeout(off)
775
1114
  }, [copied])
776
1115
 
1116
+ React.useEffect(() => {
1117
+ if (!aiSaved) return
1118
+ const off = setTimeout(() => setAiSaved(false), 1600)
1119
+ return () => clearTimeout(off)
1120
+ }, [aiSaved])
1121
+
1122
+ React.useEffect(() => {
1123
+ const sync = () => setLogVersion((v) => v + 1)
1124
+ window.addEventListener(LOG_EVENT, sync)
1125
+ return () => window.removeEventListener(LOG_EVENT, sync)
1126
+ }, [])
1127
+
1128
+ React.useEffect(() => {
1129
+ if (!logCopied) return
1130
+ const off = setTimeout(() => setLogCopied(false), 1600)
1131
+ return () => clearTimeout(off)
1132
+ }, [logCopied])
1133
+
1134
+ React.useEffect(() => {
1135
+ if (!logCleared) return
1136
+ const off = setTimeout(() => setLogCleared(false), 1600)
1137
+ return () => clearTimeout(off)
1138
+ }, [logCleared])
1139
+
1140
+ React.useEffect(() => {
1141
+ if (!logExportFail) return
1142
+ const off = setTimeout(() => setLogExportFail(false), 1600)
1143
+ return () => clearTimeout(off)
1144
+ }, [logExportFail])
1145
+
1146
+ const saveAi = () => {
1147
+ setAiConfig({
1148
+ provider,
1149
+ baseUrl: baseUrl.trim(),
1150
+ model: model.trim(),
1151
+ apiKey: apiKey.trim(),
1152
+ })
1153
+ setAiSaved(true)
1154
+ log('info', '保存 AI 配置', { provider, model: model.trim() })
1155
+ }
1156
+
1157
+ const exportLogs = () => {
1158
+ setLogExportFail(false)
1159
+ try {
1160
+ const blob = new Blob([formatLogs(LOGS)], { type: 'text/plain;charset=utf-8' })
1161
+ const url = URL.createObjectURL(blob)
1162
+ const a = document.createElement('a')
1163
+ a.href = url
1164
+ a.download = `dsh-settings-search-${Date.now()}.log`
1165
+ document.body.appendChild(a)
1166
+ a.click()
1167
+ a.remove()
1168
+ URL.revokeObjectURL(url)
1169
+ } catch {
1170
+ setLogExportFail(true)
1171
+ }
1172
+ }
1173
+
1174
+ const copyLogs = async () => {
1175
+ try {
1176
+ await navigator.clipboard.writeText(formatLogs(LOGS))
1177
+ setLogCopied(true)
1178
+ setLogCopyFail(false)
1179
+ } catch {
1180
+ setLogCopyFail(true)
1181
+ }
1182
+ }
1183
+
1184
+ const clearLogs = () => {
1185
+ LOGS.length = 0
1186
+ setLogVersion((v) => v + 1)
1187
+ setLogCleared(true)
1188
+ }
1189
+
777
1190
  const check = async () => {
778
1191
  setState('loading')
779
1192
  setCopied(false)
@@ -785,54 +1198,164 @@ window.__ModuleLoader__.load({
785
1198
  const ver = typeof data?.version === 'string' ? data.version : ''
786
1199
  if (ver === '') throw new Error('no version in registry response')
787
1200
  setLatest(ver)
788
- setState(compareSemver(ver, PKG_VERSION) > 0 ? 'outdated' : 'newest')
1201
+ const newer = compareSemver(ver, PKG_VERSION) > 0
1202
+ setState(newer ? 'outdated' : 'newest')
1203
+ log('info', '检查更新', { result: newer ? 'outdated' : 'newest', latest: ver })
789
1204
  } catch {
790
1205
  setState('error')
1206
+ log('error', '检查更新失败', {})
791
1207
  }
792
1208
  }
793
1209
 
1210
+ const updateCommand = latest ? `dsh plugin --profile web add ${NPM_NAME}@${latest}` : ''
1211
+ const npxUpdateCommand = latest ? `npx @deepseek-ai/dsh plugin --profile web add ${NPM_NAME}@${latest}` : ''
1212
+ const releasesUrl = latest
1213
+ ? `https://github.com/objectivex666/dsh-settings-search/releases/tag/v${latest}`
1214
+ : 'https://github.com/objectivex666/dsh-settings-search/releases/latest'
1215
+ const commandBlock = (label, command) => React.createElement('div', { className: 'sss-vr-update-command', key: command }, [
1216
+ React.createElement('div', { className: 'sss-vr-update-command-label' }, label),
1217
+ React.createElement('code', { className: 'sss-vr-code' }, command),
1218
+ ])
794
1219
  const copyCmd = async () => {
795
- const cmd = `dsh plugin --profile web update ${NPM_NAME}`
796
- try { await navigator.clipboard.writeText(cmd); setCopied(true); setCopyFailed(false) } catch { setCopyFailed(true) }
1220
+ try { await navigator.clipboard.writeText(updateCommand); setCopied(true); setCopyFailed(false) } catch { setCopyFailed(true) }
797
1221
  }
798
1222
 
799
- const statusNode = {
800
- idle: React.createElement('span', { className: 'sss-upd-val' }, '—'),
801
- loading: React.createElement('span', { className: 'sss-upd-val' }, t('updChecking')),
802
- newest: React.createElement('span', { className: 'sss-upd-val' }, t('updNewest')),
803
- error: React.createElement('span', { className: 'sss-upd-val' }, t('updErr')),
804
- outdated: latest === '' ? null : React.createElement('div', { style: { display: 'flex', flexDirection: 'column', gap: 8 } }, [
805
- React.createElement('p', { className: 'sss-upd-note' }, t('updFound').replace('{ver}', `v${latest}`)),
806
- React.createElement('code', { className: 'sss-cmd' }, `dsh plugin --profile web update ${NPM_NAME}`),
807
- React.createElement('div', null,
808
- React.createElement('button', { className: 'sss-btn', type: 'button', onClick: () => { void copyCmd() } },
809
- copied ? t('updCopied') : t('updCopy')),
810
- copyFailed ? React.createElement('p', { className: 'sss-upd-note', style: { color: 'var(--dsw-alias-label-danger)' } }, t('updCopyFail')) : null),
811
- ]),
812
- }
1223
+ // Mirror Vision Router: check for updates automatically when the panel opens.
1224
+ React.useEffect(() => {
1225
+ if (state === 'idle') void check()
1226
+ }, [state]) // eslint-disable-line react-hooks/exhaustive-deps
813
1227
 
814
- return React.createElement('div', { className: 'sss-upd' }, [
815
- React.createElement('h3', { className: 'sss-upd-title' }, `${t('updn')} v${PKG_VERSION}`),
816
- React.createElement('p', { className: 'sss-upd-desc' }, t('updDesc')),
817
- React.createElement('div', { className: 'sss-upd-card' }, [
818
- React.createElement('div', { className: 'sss-upd-row' }, [
819
- React.createElement('span', { className: 'sss-upd-key' }, t('updCurrent')),
820
- React.createElement('code', { className: 'sss-cmd' }, PKG_VERSION),
821
- state === 'newest' ? React.createElement('span', { className: 'sss-upd-badge' }, 'npm ✓') : null,
1228
+ return React.createElement('div', { className: 'sss-vr' + (open ? ' sss-vr-open' : '') }, [
1229
+ React.createElement('button', {
1230
+ type: 'button',
1231
+ className: 'sss-vr-header',
1232
+ 'aria-expanded': open,
1233
+ onClick: () => setOpen(!open),
1234
+ }, [
1235
+ React.createElement('span', { className: 'sss-vr-headText' }, [
1236
+ React.createElement('span', { className: 'sss-vr-name' }, t('updn')),
1237
+ React.createElement('span', { className: 'sss-vr-desc' }, t('updDesc')),
822
1238
  ]),
823
- state === 'outdated' || state === 'loading'
824
- ? React.createElement('div', { className: 'sss-upd-row' }, [
825
- React.createElement('span', { className: 'sss-upd-key' }, t('updLatestKnown')),
826
- state === 'loading' ? React.createElement('span', { className: 'sss-upd-val' }, '…') : React.createElement('code', { className: 'sss-cmd' }, latest),
827
- ])
828
- : null,
829
- state === 'outdated' || state === 'loading' || state === 'error' || state === 'idle' || state === 'newest'
830
- ? (state === 'outdated' ? statusNode.outdated : statusNode[state])
831
- : null,
832
- React.createElement('div', { className: 'sss-upd-row' },
833
- React.createElement('button', { className: 'sss-btn', type: 'button', disabled: state === 'loading', onClick: () => { void check() } },
834
- state === 'loading' ? t('updChecking') : t('updCheck'))),
1239
+ React.createElement('span', { className: 'sss-vr-chevron' + (open ? ' sss-vr-chevron-open' : '') }, '▾'),
835
1240
  ]),
1241
+ open ? React.createElement('div', { className: 'sss-vr-body' }, [
1242
+ React.createElement('div', { className: 'sss-vr-field' }, [
1243
+ React.createElement('div', { className: 'sss-vr-field-head' }, [
1244
+ React.createElement('span', { className: 'sss-vr-label' }, t('aiSearch')),
1245
+ React.createElement('input', {
1246
+ className: 'sss-vr-check',
1247
+ type: 'checkbox',
1248
+ checked: aiOn,
1249
+ onChange: (event) => {
1250
+ const next = event.target.checked
1251
+ setAiSearchEnabled(next)
1252
+ setAiOn(next)
1253
+ },
1254
+ }),
1255
+ ]),
1256
+ React.createElement('p', { className: 'sss-vr-hint' }, t('aiDesc')),
1257
+ React.createElement('p', { className: 'sss-vr-hint' }, t('aiPrivacy')),
1258
+ ]),
1259
+ React.createElement('div', { className: 'sss-vr-field sss-vr-form' }, [
1260
+ React.createElement('div', { className: 'sss-vr-field-head' }, [
1261
+ React.createElement('label', { className: 'sss-vr-label' }, t('aiProvider')),
1262
+ ]),
1263
+ React.createElement('select', {
1264
+ className: 'sss-vr-input sss-vr-select',
1265
+ value: provider,
1266
+ onChange: (event) => setProvider(event.target.value),
1267
+ }, [
1268
+ React.createElement('option', { value: 'openai' }, t('aiOpenAI')),
1269
+ React.createElement('option', { value: 'anthropic' }, t('aiAnthropic')),
1270
+ ]),
1271
+ React.createElement('div', { className: 'sss-vr-field-head' }, [
1272
+ React.createElement('label', { className: 'sss-vr-label' }, t('aiBaseUrl')),
1273
+ ]),
1274
+ React.createElement('input', {
1275
+ className: 'sss-vr-input',
1276
+ type: 'url',
1277
+ value: baseUrl,
1278
+ placeholder: provider === 'anthropic' ? 'https://api.anthropic.com' : 'https://api.openai.com/v1',
1279
+ spellCheck: false,
1280
+ onChange: (event) => setBaseUrl(event.target.value),
1281
+ }),
1282
+ React.createElement('div', { className: 'sss-vr-field-head' }, [
1283
+ React.createElement('label', { className: 'sss-vr-label' }, t('aiModel')),
1284
+ ]),
1285
+ React.createElement('input', {
1286
+ className: 'sss-vr-input',
1287
+ type: 'text',
1288
+ value: model,
1289
+ placeholder: provider === 'anthropic' ? 'claude-sonnet-4-20250514' : 'gpt-4o-mini',
1290
+ spellCheck: false,
1291
+ onChange: (event) => setModel(event.target.value),
1292
+ }),
1293
+ React.createElement('div', { className: 'sss-vr-field-head' }, [
1294
+ React.createElement('label', { className: 'sss-vr-label' }, t('aiApiKey')),
1295
+ ]),
1296
+ React.createElement('input', {
1297
+ className: 'sss-vr-input',
1298
+ type: 'password',
1299
+ value: apiKey,
1300
+ placeholder: 'sk-…',
1301
+ spellCheck: false,
1302
+ autoComplete: 'off',
1303
+ onChange: (event) => setApiKey(event.target.value),
1304
+ }),
1305
+ React.createElement('div', { className: 'sss-vr-actions' },
1306
+ React.createElement('button', { className: 'sss-vr-btn sss-vr-primary', type: 'button', onClick: () => { void saveAi() } },
1307
+ aiSaved ? t('aiConfigSaved') : t('aiConfigSave'))),
1308
+ ]),
1309
+ React.createElement('div', { className: 'sss-vr-field' }, [
1310
+ React.createElement('div', { className: 'sss-vr-row' }, [
1311
+ React.createElement('span', { className: 'sss-vr-rowname' }, t('updCurrent')),
1312
+ React.createElement('span', { className: 'sss-vr-value' }, PKG_VERSION),
1313
+ state === 'newest' ? React.createElement('span', { className: 'sss-vr-badge' }, 'npm ✓') : null,
1314
+ ]),
1315
+ state === 'loading'
1316
+ ? React.createElement('p', { className: 'sss-vr-note' }, t('updChecking'))
1317
+ : null,
1318
+ state === 'error'
1319
+ ? React.createElement('p', { className: 'sss-vr-note' }, t('updErr'))
1320
+ : null,
1321
+ state === 'outdated'
1322
+ ? React.createElement('div', { className: 'sss-vr-update' }, [
1323
+ React.createElement('div', { className: 'sss-vr-update-title' }, t('updFound').replace('{ver}', `v${latest}`)),
1324
+ commandBlock(t('updCLI'), updateCommand),
1325
+ commandBlock(t('updNpx'), npxUpdateCommand),
1326
+ React.createElement('p', { className: 'sss-vr-update-note' }, t('updRestart')),
1327
+ React.createElement('div', { className: 'sss-vr-update-actions' }, [
1328
+ React.createElement('button', { className: 'sss-vr-btn', type: 'button', onClick: () => { void copyCmd() } },
1329
+ copied ? t('updCopied') : t('updCopy')),
1330
+ React.createElement('a', { className: 'sss-vr-link', href: releasesUrl, target: '_blank', rel: 'noopener noreferrer' }, t('updRelease')),
1331
+ ]),
1332
+ copyFailed ? React.createElement('p', { className: 'sss-vr-note', style: { color: 'var(--dsw-alias-label-danger)' } }, t('updCopyFail')) : null,
1333
+ ])
1334
+ : null,
1335
+ React.createElement('div', { className: 'sss-vr-actions' },
1336
+ React.createElement('button', { className: 'sss-vr-btn', type: 'button', disabled: state === 'loading', onClick: () => { void check() } },
1337
+ state === 'loading' ? t('updChecking') : t('updCheck'))),
1338
+ ]),
1339
+ React.createElement('div', { className: 'sss-vr-field' }, [
1340
+ React.createElement('div', { className: 'sss-vr-field-head' }, [
1341
+ React.createElement('span', { className: 'sss-vr-label' }, t('logTitle')),
1342
+ LOGS.length > 0 ? React.createElement('span', { className: 'sss-vr-badge' }, String(LOGS.length)) : null,
1343
+ ]),
1344
+ React.createElement('p', { className: 'sss-vr-hint' }, t('logDesc')),
1345
+ LOGS.length === 0
1346
+ ? React.createElement('p', { className: 'sss-vr-note' }, t('logEmpty'))
1347
+ : null,
1348
+ React.createElement('div', { className: 'sss-vr-actions' }, [
1349
+ React.createElement('button', { className: 'sss-vr-btn', type: 'button', onClick: () => { void exportLogs() } }, t('logExport')),
1350
+ React.createElement('button', { className: 'sss-vr-btn', type: 'button', onClick: () => { void copyLogs() } },
1351
+ logCopied ? t('logCopied') : t('logCopy')),
1352
+ React.createElement('button', { className: 'sss-vr-btn', type: 'button', onClick: () => { void clearLogs() } },
1353
+ logCleared ? t('logCleared') : t('logClear')),
1354
+ ]),
1355
+ logCopyFail ? React.createElement('p', { className: 'sss-vr-note', style: { color: 'var(--dsw-alias-label-danger)' } }, t('logCopyFail')) : null,
1356
+ logExportFail ? React.createElement('p', { className: 'sss-vr-note', style: { color: 'var(--dsw-alias-label-danger)' } }, t('logExportFail')) : null,
1357
+ ]),
1358
+ ]) : null,
836
1359
  ])
837
1360
  }
838
1361
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@objectivex666/dsh-settings-search",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "description": "DSH settings panel search plugin – instantly filter setting sections and general items with navigation guidance. Installable via `dsh plugin add`.",
5
5
  "keywords": [
6
6
  "dsh",
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * dsh-settings-search release helper.
4
+ *
5
+ * Keeps git tags and GitHub Releases in sync on every version bump, with a
6
+ * bilingual (Chinese / English) body built from CHANGELOG.md + CHANGELOG.en.md.
7
+ * Always include both "新功能 / Features" and "修复 / Fixes" sections.
8
+ *
9
+ * Usage:
10
+ * node scripts/release.mjs --version 1.8.0 # validate + print preview
11
+ * node scripts/release.mjs --version 1.8.0 --publish # tag + push + gh release
12
+ * node scripts/release.mjs --version 1.8.0 --dry-run # same as default, explicit
13
+ *
14
+ * --publish requires `gh` CLI and a git remote named `origin`.
15
+ */
16
+ import { readFileSync, writeFileSync, mkdtempSync, rmSync } from 'node:fs'
17
+ import { execFileSync } from 'node:child_process'
18
+ import { resolve, dirname, join } from 'node:path'
19
+ import { fileURLToPath } from 'node:url'
20
+ import { tmpdir } from 'node:os'
21
+
22
+ const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..')
23
+
24
+ function arg(name) {
25
+ const at = process.argv.indexOf(name)
26
+ return at >= 0 ? process.argv[at + 1] : undefined
27
+ }
28
+
29
+ const version = process.argv.includes('--version') ? arg('--version') : undefined
30
+ const publish = process.argv.includes('--publish')
31
+ const dryRun = process.argv.includes('--dry-run')
32
+
33
+ const pkg = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8'))
34
+ const target = version ?? pkg.version
35
+ if (pkg.version !== target) {
36
+ console.error(`version mismatch: package.json=${pkg.version}, requested=${target}`)
37
+ process.exit(1)
38
+ }
39
+ const tag = `v${target}`
40
+ const repo = pkg.repository?.url?.replace(/^git\+/, '').replace(/\.git$/, '') ?? 'https://github.com/objectivex666/dsh-settings-search'
41
+
42
+ function section(file, version) {
43
+ const text = readFileSync(join(ROOT, file), 'utf8')
44
+ const target = `## v${version}`
45
+ const lines = text.split(/\r?\n/)
46
+ let start = -1
47
+ for (let i = 0; i < lines.length; i += 1) {
48
+ if (lines[i].trim() === target) { start = i; break }
49
+ }
50
+ if (start === -1) return ''
51
+ const out = []
52
+ for (let i = start + 1; i < lines.length; i += 1) {
53
+ const line = lines[i]
54
+ if (/^## v/.test(line) || line.trim() === '---') break
55
+ out.push(line)
56
+ }
57
+ return out.join('\n').trim()
58
+ }
59
+
60
+ const zh = section('CHANGELOG.md', target)
61
+ const en = section('CHANGELOG.en.md', target)
62
+ if (!zh || !en) {
63
+ console.error(`missing changelog section for v${target} in CHANGELOG.md / CHANGELOG.en.md`)
64
+ process.exit(1)
65
+ }
66
+ if (!/新功能|修复/.test(zh) || !/Features|Fixes/.test(en)) {
67
+ console.error('changelog must include both Features and Fixes sections (新功能/修复, Features/Fixes)')
68
+ process.exit(1)
69
+ }
70
+
71
+ const body = [
72
+ `# v${target}`,
73
+ '',
74
+ `> ${repo}`,
75
+ '',
76
+ zh,
77
+ '',
78
+ '---',
79
+ '',
80
+ en,
81
+ '',
82
+ ].join('\n')
83
+
84
+ console.log('===== release body =====')
85
+ console.log(body)
86
+ console.log('========================')
87
+
88
+ function run(cmd, args) {
89
+ if (!publish || dryRun) {
90
+ console.log(`[preview] ${cmd} ${args.join(' ')} (not executed)`)
91
+ return undefined
92
+ }
93
+ console.log(`+ ${cmd} ${args.join(' ')}`)
94
+ return execFileSync(cmd, args, { cwd: ROOT, stdio: 'inherit' })
95
+ }
96
+
97
+ let tagExists = false
98
+ try {
99
+ const out = execFileSync('git', ['tag', '--list', tag], { cwd: ROOT, encoding: 'utf8' })
100
+ tagExists = out.split('\n').map((line) => line.trim()).includes(tag)
101
+ } catch {}
102
+ if (!tagExists) {
103
+ run('git', ['tag', tag])
104
+ } else {
105
+ console.log(`tag ${tag} already exists`)
106
+ }
107
+
108
+ if (publish && !dryRun) {
109
+ if (!tagExists) run('git', ['push', 'origin', tag])
110
+ const notes = join(mkdtempSync(join(tmpdir(), 'sss-release-')), 'notes.md')
111
+ writeFileSync(notes, body, 'utf8')
112
+ run('gh', ['release', 'create', tag, '--title', `v${target}`, '--notes-file', notes])
113
+ rmSync(dirname(notes), { recursive: true, force: true })
114
+ } else if (!publish) {
115
+ console.log('\n(no --publish: nothing was created/pushed. Re-run with --publish to tag + release.)')
116
+ }
117
+
118
+ console.log(`ok: release preview for ${tag} (tagExists=${tagExists}, publish=${publish})`)