dsh-podwave 0.11.23 → 0.11.25
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/CHANGELOG.md +503 -0
- package/README.md +2 -2
- package/dist/client.js +3 -3
- package/docs/ARCHITECTURE.md +138 -0
- package/docs/DETAIL.md +3 -0
- package/docs/DETAIL.zh.md +3 -0
- package/docs/screenshot-detail.png +0 -0
- package/icon.svg +12 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +11 -2
- package/src/host.js +63 -3
- package/src/models.js +104 -19
- package/scripts/__pycache__/asr_sherpa.cpython-312.pyc +0 -0
- package/scripts/release.mjs +0 -79
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# dsh-podwave 架构
|
|
2
|
+
|
|
3
|
+
## 插件形态
|
|
4
|
+
|
|
5
|
+
dsh-podwave 是一个 DSH 插件,分两片:
|
|
6
|
+
|
|
7
|
+
- **host 半片** `src/host.js`:在 DSH 的 `ctx.webServer` 上注册 `/podwave` 前缀路由;负责媒体库扫描、音频 Range 流、转写/翻译任务、配置读写。
|
|
8
|
+
- **client 半片** `client/src/plugin.jsx` → `dist/client.js`:通过 `ctx.slots.register` 往 DSH 注入主界面(`main`、`sidebar.panellist`)和设置页(`settings.section`)。
|
|
9
|
+
|
|
10
|
+
构建:`node build.mjs` 用 esbuild 打包 React 组件,用 PostCSS 把 CSS 选择器统一加上 `.podwave-root` 前缀,最后包成 `window.__ModuleLoader__.load({ id: 'dsh-podwave', factory })`。
|
|
11
|
+
|
|
12
|
+
## 分层
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
UI(App.jsx / SettingsPage.jsx)
|
|
16
|
+
↓ /podwave/api/*
|
|
17
|
+
host.js(路由 + 鉴权 + 扫描触发)
|
|
18
|
+
↓
|
|
19
|
+
transcribe.js translate.js diarize.js
|
|
20
|
+
↓ ↓ ↓
|
|
21
|
+
jobs.js(任务落盘) config.js(统一配置)
|
|
22
|
+
↓
|
|
23
|
+
library.js(媒体库) state.js(播放进度/文件夹)
|
|
24
|
+
↓
|
|
25
|
+
~/.podwave/*
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## 节目适配器(providers)
|
|
29
|
+
|
|
30
|
+
所有节目来源统一走 `src/providers.js`:
|
|
31
|
+
|
|
32
|
+
- `providers/local.js`:本地音频库(`library.js`)。
|
|
33
|
+
- `providers/xyz.js`:小宇宙单集(`xyz.js`),已下载音频会自动挂上本地 `file`。
|
|
34
|
+
- `getProviderById(id)` 先让显式适配器匹配,`local` 只做兜底;`findEpisode(id)` 跨适配器查找,`listAllEpisodes()` 合并列表。
|
|
35
|
+
- 新增平台(RSS、喜马拉雅等):在 `src/providers/` 加一个文件,注册进 `providers.js` 即可,宿主路由无需改动。
|
|
36
|
+
|
|
37
|
+
## 数据文件(~/.podwave)
|
|
38
|
+
|
|
39
|
+
| 文件 | 作用 |
|
|
40
|
+
| --- | --- |
|
|
41
|
+
| `state.json` | 媒体库文件夹、每集播放进度、播放器设置(倍速/音量/上次播放) |
|
|
42
|
+
| `config.json` | 统一配置:`ui`(侧栏开关/收起)、`translate`(API 与目标语言)、`models`(已选 ASR / 翻译模型)、`transcribe`(热词) |
|
|
43
|
+
| `jobs.json` | 转写/翻译任务记录(最多 80 条,重启时未完成标 `interrupted`) |
|
|
44
|
+
| `transcripts/<id>.json` | 字幕 v2(见下);旧格式迁移后原文件保留 `<id>.json.v1.bak` |
|
|
45
|
+
| `imports/<batch>/` | 拖拽上传进来的音频 |
|
|
46
|
+
| `models/<name>/` | 本地模型目录(ASR、翻译) |
|
|
47
|
+
| `runtime/.venv/` | MLX 运行环境(uv 创建的 Python 虚拟环境) |
|
|
48
|
+
|
|
49
|
+
旧的 `ui.json` / `translate.json` / `models.json` 会在首次启动时迁入 `config.json` 并改名为 `*.bak`。
|
|
50
|
+
|
|
51
|
+
## 媒体库状态
|
|
52
|
+
|
|
53
|
+
- `state.json` 里 `favorites: [episodeId]`、`hidden: [episodeId]`;`hidden` 只影响列表,不会删除源文件。
|
|
54
|
+
- 导入策略与孤儿清理的配置在 `config.json` 的 `import.mode`(`copy` / `reference`)。
|
|
55
|
+
|
|
56
|
+
## transcript v2
|
|
57
|
+
|
|
58
|
+
```json
|
|
59
|
+
{
|
|
60
|
+
"schemaVersion": 2,
|
|
61
|
+
"id": "episode-id",
|
|
62
|
+
"title": "标题",
|
|
63
|
+
"createdAt": 1760000000000,
|
|
64
|
+
"updatedAt": 1760000000000,
|
|
65
|
+
"model": "qwen3-asr-1.7b-8bit",
|
|
66
|
+
"language": "Chinese",
|
|
67
|
+
"duration": 42.5,
|
|
68
|
+
"text": "全文",
|
|
69
|
+
"source": { "path": "/abs/path.m4a", "size": 123, "mtime": 1760000000000 },
|
|
70
|
+
"lines": [
|
|
71
|
+
{ "id": 1, "start": 0, "end": 2.96, "text": "第一行", "speaker": null, "translations": { "en": "First line" } }
|
|
72
|
+
],
|
|
73
|
+
"providers": { "en": "local" },
|
|
74
|
+
"speakers": []
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
- 行级时间戳来自模型 chunk 与词级时间戳对齐;标点取自 chunk 文本。
|
|
79
|
+
- 译文按行存放,`providers` 记录本集每个目标语言用的翻译来源(`api` / `local`)。
|
|
80
|
+
- `speaker` 由说话人分离(sherpa-onnx)填充,从 0 开始;`speakers` 是标签表(如 `[{"id":0,"label":"说话人 1"}]`),分离失败时为空。
|
|
81
|
+
- 旧格式(`segments` + `translations[target][id]`)会在读取或启动迁移时自动升级。
|
|
82
|
+
|
|
83
|
+
## job
|
|
84
|
+
|
|
85
|
+
```json
|
|
86
|
+
{
|
|
87
|
+
"key": "transcribe:<episodeId>",
|
|
88
|
+
"type": "transcribe | translate",
|
|
89
|
+
"status": "queued | running | done | error | interrupted",
|
|
90
|
+
"episodeId": "...",
|
|
91
|
+
"target": "en",
|
|
92
|
+
"progress": { "done": 3, "total": 12 },
|
|
93
|
+
"error": null,
|
|
94
|
+
"startedAt": 1760000000000,
|
|
95
|
+
"finishedAt": 1760000000000
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`jobs.js` 在启动时把遗留的 `queued` / `running` 任务改为 `interrupted`,避免 UI 永远停在“进行中”。
|
|
100
|
+
|
|
101
|
+
## HTTP API(/podwave/api)
|
|
102
|
+
|
|
103
|
+
| 方法 | 路径 | 说明 |
|
|
104
|
+
| --- | --- | --- |
|
|
105
|
+
| GET | `/health` | 版本、转写运行时、翻译配置、说话人分离状态 |
|
|
106
|
+
| GET | `/state` | 文件夹、播放进度、设置 |
|
|
107
|
+
| GET | `/episodes` | 媒体库条目(含 `hasTranscript` / `favorite`,过滤 `hidden`) |
|
|
108
|
+
| POST | `/scan` | 重新扫描 |
|
|
109
|
+
| POST/DELETE | `/folders` | 添加/移除文件夹 |
|
|
110
|
+
| POST | `/pick-folder` | 系统文件夹选择器 |
|
|
111
|
+
| POST | `/import/upload` | 拖拽上传音频 |
|
|
112
|
+
| POST | `/import/paths` | 按路径导入(拖拽可得路径时) |
|
|
113
|
+
| GET | `/episodes/:id/audio` | Range 音频流 |
|
|
114
|
+
| GET | `/episodes/:id/cover` | 封面 |
|
|
115
|
+
| PUT | `/progress/:id` · PATCH `/settings` | 播放进度 / 播放器设置 |
|
|
116
|
+
| GET/DELETE/POST | `/episodes/:id/transcript` · `/transcribe` | 读取/删除/开始转写 |
|
|
117
|
+
| POST | `/episodes/:id/transcribe/cancel` | 取消正在进行的转写 |
|
|
118
|
+
| POST | `/transcribe/batch` | 批量转写({ids}) |
|
|
119
|
+
| GET/PUT | `/transcribe/settings` | 热词、分块时长、是否自动识别说话人 |
|
|
120
|
+
| POST | `/episodes/:id/diarize` | 对已有字幕补跑说话人分离 |
|
|
121
|
+
| PUT/POST | `/episodes/:id/transcript/lines/:lineId` 及 `/split` `/merge` `/undo` `/validate` | 字幕行编辑 |
|
|
122
|
+
| GET/DELETE/POST/GET | `/episodes/:id/translate` · `/translate/settings` | 翻译与配置 |
|
|
123
|
+
| GET | `/episodes/:id/transcript/export?format=srt\|md` | 导出字幕 |
|
|
124
|
+
| GET/PUT | `/models` | 模型列表 / 选择 |
|
|
125
|
+
| GET | `/history` | 已完成的转写/翻译 |
|
|
126
|
+
| GET | `/jobs` | 任务记录 |
|
|
127
|
+
| GET/PUT | `/ui-settings` | 侧栏入口与收起状态 |
|
|
128
|
+
| PUT | `/episodes/:id/favorite` | 收藏 / 取消收藏 |
|
|
129
|
+
| DELETE | `/episodes/:id` | 仅从索引隐藏(不动源文件) |
|
|
130
|
+
| GET/PUT | `/import/settings` | 导入策略(copy / reference)与孤儿统计 |
|
|
131
|
+
| GET/DELETE | `/imports/orphans` | 列出 / 清理未引用的 imports 批次 |
|
|
132
|
+
|
|
133
|
+
## 发布流程
|
|
134
|
+
|
|
135
|
+
1. `npm run build` 生成 `dist/client.js`。
|
|
136
|
+
2. 更新 `package.json`、`CHANGELOG.md`、README。
|
|
137
|
+
3. `npm pack` 产物校验后 `git commit` → `git tag vX.Y.Z` → `gh release create vX.Y.Z dsh-podwave-X.Y.Z.tgz`。
|
|
138
|
+
4. 桌面端:`plugin_manager` remove + install `file:/Users/tangwenxuan/Deepseek-Harness/dsh-podwave`(或刷新 DSH)。
|
package/docs/DETAIL.md
ADDED
|
Binary file
|
package/icon.svg
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<svg width="36" height="36" viewBox="0 0 36 36" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<rect x="21.3" y="8.6" width="3.4" height="18.8" rx="1.7" fill="url(#pw_icon_gradient)" />
|
|
3
|
+
<rect x="15.1" y="12.4" width="3.4" height="11.2" rx="1.7" fill="url(#pw_icon_gradient)" opacity="0.82" />
|
|
4
|
+
<rect x="8.9" y="15.6" width="3.4" height="4.8" rx="1.7" fill="url(#pw_icon_gradient)" opacity="0.6" />
|
|
5
|
+
<rect x="27.5" y="15.6" width="3.4" height="4.8" rx="1.7" fill="url(#pw_icon_gradient)" opacity="0.6" />
|
|
6
|
+
<defs>
|
|
7
|
+
<linearGradient id="pw_icon_gradient" x1="8.9" y1="8.6" x2="30.9" y2="27.4" gradientUnits="userSpaceOnUse">
|
|
8
|
+
<stop stop-color="#E6A54A" />
|
|
9
|
+
<stop offset="1" stop-color="#B26A12" />
|
|
10
|
+
</linearGradient>
|
|
11
|
+
</defs>
|
|
12
|
+
</svg>
|
package/locale/en.json
ADDED
package/locale/zh.json
ADDED
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-podwave",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.25",
|
|
4
4
|
"description": "DeepSeek Harness 插件:本地优先的播客播放器 + 转写 + 双语字幕 + 字幕翻译。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/host.js",
|
|
7
|
+
"icon": "./icon.svg",
|
|
7
8
|
"exports": {
|
|
8
9
|
".": "./src/host.js",
|
|
9
10
|
"./client": "./dist/client.js",
|
|
10
11
|
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
12
|
+
"./locale/*.json": "./locale/*.json",
|
|
11
13
|
"./package.json": "./package.json"
|
|
12
14
|
},
|
|
13
15
|
"dsh": {
|
|
@@ -55,6 +57,13 @@
|
|
|
55
57
|
"dist",
|
|
56
58
|
"cordis.patch.yml",
|
|
57
59
|
"README.md",
|
|
58
|
-
"
|
|
60
|
+
"CHANGELOG.md",
|
|
61
|
+
"locale",
|
|
62
|
+
"icon.svg",
|
|
63
|
+
"docs/DETAIL.md",
|
|
64
|
+
"docs/DETAIL.zh.md",
|
|
65
|
+
"docs/ARCHITECTURE.md",
|
|
66
|
+
"docs/screenshot-detail.png",
|
|
67
|
+
"scripts/*.py"
|
|
59
68
|
]
|
|
60
69
|
}
|
package/src/host.js
CHANGED
|
@@ -78,7 +78,7 @@ import { scan as scanSetup, plan as planSetup, install as installSetup, cancelSe
|
|
|
78
78
|
import { getSection, updateSection } from './config.js'
|
|
79
79
|
import { diarizeInfo } from './diarize.js'
|
|
80
80
|
import { getTranslationState, publicConfig, saveConfig, startTranslation } from './translate.js'
|
|
81
|
-
import { listModels, loadModelConfig, modelsDir, modelsMoveState, modelsSummary, removeModel, saveModelConfig, setModelsDir } from './models.js'
|
|
81
|
+
import { listModels, loadModelConfig, modelsDir, modelsMoveState, modelsSummary, removeModel, saveModelConfig, setModelsDir, setWorkspaceRoots, getWorkspaceRoot } from './models.js'
|
|
82
82
|
import { findEpisode, getProviderById, listAllEpisodes } from './providers.js'
|
|
83
83
|
// 设置页每次打开都会拉 /api/update;漏了这个 import 会让整页 500(v0.11.10 起就漏了)。
|
|
84
84
|
import { checkUpdate } from './update.js'
|
|
@@ -209,6 +209,48 @@ export function closeWatchers() {
|
|
|
209
209
|
if (rescanTimer) { clearTimeout(rescanTimer); rescanTimer = null }
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
+
// 发布版(npm 安装)没有源码工作树,模型该落在「用户当前工作区」下的 models/。
|
|
213
|
+
// host 侧唯一能无 Session 拿到工作区的地方就是 workspaceRegistry,
|
|
214
|
+
// 这里挑「最近用过的那个」,并把它灌给 models.js 当默认目录候选。
|
|
215
|
+
function registeredWorkspaces(ctx) {
|
|
216
|
+
try {
|
|
217
|
+
return ctx.get('workspaceRegistry')?.list?.() || []
|
|
218
|
+
} catch {
|
|
219
|
+
/* 拿不到注册表就当没有工作区 */
|
|
220
|
+
return []
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// 会话开在具体某个目录时,比「最近更新的工作区」更准:优先认它。
|
|
225
|
+
function rememberWorkspaceFor(ctx, cwd) {
|
|
226
|
+
const dir = String(cwd || '').trim()
|
|
227
|
+
if (!dir || !path.isAbsolute(dir)) return
|
|
228
|
+
const workspaces = registeredWorkspaces(ctx)
|
|
229
|
+
const hit = workspaces.find((workspace) => {
|
|
230
|
+
const target = String(workspace?.path || '').trim()
|
|
231
|
+
return target && (target === dir || dir.startsWith(target + path.sep))
|
|
232
|
+
})
|
|
233
|
+
setWorkspaceRoots(workspaceOrder(ctx, hit ? hit.path : dir))
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// 当前工作区排第一,其余按「最近更新」排;切工作区时旧模型照样认。
|
|
237
|
+
function workspaceOrder(ctx, current) {
|
|
238
|
+
const list = registeredWorkspaces(ctx)
|
|
239
|
+
.map((workspace) => ({ dir: String(workspace?.path || '').trim(), time: Date.parse(workspace?.updatedAt || workspace?.createdAt || '') || 0 }))
|
|
240
|
+
.filter((item) => item.dir)
|
|
241
|
+
.sort((a, b) => b.time - a.time)
|
|
242
|
+
.map((item) => item.dir)
|
|
243
|
+
const head = String(current || '').trim()
|
|
244
|
+
const ordered = head ? [head, ...list] : list
|
|
245
|
+
return ordered
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function rememberWorkspace(ctx) {
|
|
249
|
+
// 已经有精确值(会话给过 cwd)就别被「最近更新」覆盖掉。
|
|
250
|
+
const current = getWorkspaceRoot()
|
|
251
|
+
setWorkspaceRoots(workspaceOrder(ctx, current))
|
|
252
|
+
}
|
|
253
|
+
|
|
212
254
|
function boot() {
|
|
213
255
|
if (!booted) {
|
|
214
256
|
booted = (async () => {
|
|
@@ -467,7 +509,7 @@ async function route(ctx, req, res) {
|
|
|
467
509
|
return json(res, 200, {
|
|
468
510
|
ok: true,
|
|
469
511
|
generatedAt: new Date().toISOString(),
|
|
470
|
-
version: '0.11.
|
|
512
|
+
version: '0.11.25',
|
|
471
513
|
platform,
|
|
472
514
|
engine: recommendEngine(platform),
|
|
473
515
|
paths: {
|
|
@@ -496,7 +538,7 @@ async function route(ctx, req, res) {
|
|
|
496
538
|
}
|
|
497
539
|
if ((method === 'GET' || method === 'HEAD') && routePath === 'api/health') {
|
|
498
540
|
await mediaReady
|
|
499
|
-
return json(res, 200, { ok: true, app: 'podwave', version: '0.11.
|
|
541
|
+
return json(res, 200, { ok: true, app: 'podwave', version: '0.11.24', mediaBase, transcribe: runtimeInfo(), diarize: diarizeInfo(), translate: publicConfig() })
|
|
500
542
|
}
|
|
501
543
|
if (method === 'GET' && routePath === 'api/state') {
|
|
502
544
|
const state = getState()
|
|
@@ -1184,6 +1226,22 @@ export default {
|
|
|
1184
1226
|
apply(ctx) {
|
|
1185
1227
|
const ready = boot()
|
|
1186
1228
|
startMediaServer()
|
|
1229
|
+
// 记住「当前工作区」:发布版靠它决定模型默认落在哪儿。
|
|
1230
|
+
// 优先认会话真正开在的目录(session/created 带 cwd),
|
|
1231
|
+
// 拿不到就退化成「最近更新的工作区」。
|
|
1232
|
+
rememberWorkspace(ctx)
|
|
1233
|
+
ctx.effect(() => {
|
|
1234
|
+
// 测试用的假 ctx 没有 on;真 DSH 里跟着 session/created 学 cwd。
|
|
1235
|
+
if (typeof ctx.on !== 'function') return () => {}
|
|
1236
|
+
const off = ctx.on('session/created', (session) => {
|
|
1237
|
+
rememberWorkspaceFor(ctx, session?.header?.cwd)
|
|
1238
|
+
})
|
|
1239
|
+
return () => {
|
|
1240
|
+
// cordis 的 ctx.on 返回 dispose 函数;个别版本给的是对象,兜一下。
|
|
1241
|
+
if (typeof off === 'function') off()
|
|
1242
|
+
else if (typeof off?.dispose === 'function') off.dispose()
|
|
1243
|
+
}
|
|
1244
|
+
}, 'dsh-podwave: track workspace')
|
|
1187
1245
|
ctx.effect(() => () => {
|
|
1188
1246
|
closeWatchers()
|
|
1189
1247
|
try {
|
|
@@ -1205,6 +1263,8 @@ export default {
|
|
|
1205
1263
|
return
|
|
1206
1264
|
}
|
|
1207
1265
|
await ready
|
|
1266
|
+
// 还没拿到精确 cwd 时,先用「最近更新的工作区」顶一下。
|
|
1267
|
+
if (!getWorkspaceRoot()) rememberWorkspace(ctx)
|
|
1208
1268
|
if (req.method && req.method !== 'GET' && req.method !== 'HEAD') {
|
|
1209
1269
|
const site = req.headers['sec-fetch-site']
|
|
1210
1270
|
if (site && site !== 'same-origin' && site !== 'none') {
|
package/src/models.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
1
|
+
// 模型目录与选择:默认放在「项目文件夹」里,也可以在设置里改到任意目录
|
|
2
|
+
// (比如外置硬盘),改完能把已有模型原样搬过去。
|
|
3
3
|
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
4
|
+
// 「项目文件夹」分两种情况:
|
|
5
|
+
// - 开发工作树 / file: 安装 → 插件自己的仓库目录下的 models/
|
|
6
|
+
// - 发布版(npm 安装)→ 用户当前工作区下的 models/
|
|
7
|
+
// 两者都由 modelsDirCandidates() 解析,绝不硬编码:模型有 5 GB 量级,
|
|
8
|
+
// 但也不能塞进 node_modules——桌面端装的是拷贝,升级会整个替换掉。
|
|
6
9
|
import fs from 'node:fs'
|
|
7
10
|
import os from 'node:os'
|
|
8
11
|
import path from 'node:path'
|
|
@@ -89,18 +92,93 @@ function hasModels(dir) {
|
|
|
89
92
|
}
|
|
90
93
|
}
|
|
91
94
|
|
|
95
|
+
// 发布版(npm 安装)没有源码工作树,认不出「项目文件夹」,
|
|
96
|
+
// 所以由 host 每次请求前把「当前工作区」灌进来,模型就落在 <工作区>/models。
|
|
97
|
+
// 这里只存提示值,models.js 本身不依赖 DSH 的任何 service。
|
|
98
|
+
let workspaceRoot = ''
|
|
99
|
+
// 其他已知工作区:切走再切回来时,模型不至于「凭空消失」。
|
|
100
|
+
let otherWorkspaces = []
|
|
101
|
+
|
|
102
|
+
function absoluteRoot(dir) {
|
|
103
|
+
const next = String(dir || '').trim()
|
|
104
|
+
return next && path.isAbsolute(next) ? next : ''
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function uniqueRoots(list) {
|
|
108
|
+
const seen = new Set()
|
|
109
|
+
const out = []
|
|
110
|
+
for (const item of list) {
|
|
111
|
+
const dir = absoluteRoot(item)
|
|
112
|
+
if (!dir || seen.has(dir)) continue
|
|
113
|
+
seen.add(dir)
|
|
114
|
+
out.push(dir)
|
|
115
|
+
}
|
|
116
|
+
return out
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// 当前工作区 + 其他已知工作区,当前的那个永远排第一。
|
|
120
|
+
export function setWorkspaceRoots(list) {
|
|
121
|
+
const roots = uniqueRoots(Array.isArray(list) ? list : [])
|
|
122
|
+
workspaceRoot = roots[0] || ''
|
|
123
|
+
otherWorkspaces = roots.slice(1)
|
|
124
|
+
return workspaceRoot
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function setWorkspaceRoot(dir) {
|
|
128
|
+
const next = absoluteRoot(dir)
|
|
129
|
+
if (!next) {
|
|
130
|
+
workspaceRoot = ''
|
|
131
|
+
otherWorkspaces = []
|
|
132
|
+
return ''
|
|
133
|
+
}
|
|
134
|
+
// 换到已知工作区时,别把原来那个忘了。
|
|
135
|
+
const rest = [workspaceRoot, ...otherWorkspaces].filter((item) => item && item !== next)
|
|
136
|
+
return setWorkspaceRoots([next, ...rest])
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function getWorkspaceRoot() {
|
|
140
|
+
return workspaceRoot
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function knownWorkspaceRoots() {
|
|
144
|
+
return workspaceRoot ? [workspaceRoot, ...otherWorkspaces] : [...otherWorkspaces]
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// 工作区里的模型目录:发布版的默认位置。
|
|
148
|
+
export function workspaceModelsDir() {
|
|
149
|
+
return workspaceRoot ? path.join(workspaceRoot, 'models') : ''
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// 默认下载位置的候选,按优先级排列:
|
|
153
|
+
// 1. 开发工作树 / file: 安装 → 插件仓库自己的 models/
|
|
154
|
+
// 2. 发布版 → 当前工作区下的 models/
|
|
155
|
+
// 3. 其他已知工作区 → 切工作区时接着用旧模型,而不是重下一遍
|
|
156
|
+
// 设置页把它第一个当成「项目文件夹」,一键切过去。
|
|
157
|
+
export function modelsDirCandidates(start) {
|
|
158
|
+
// 测试/便携场景可以关掉「项目内默认」,让默认位置稳定落到数据目录。
|
|
159
|
+
if (process.env.PODWAVE_MODELS_NO_PROJECT === '1') return []
|
|
160
|
+
const list = []
|
|
161
|
+
const project = projectModelsDir(start) || installModelsDir(start)
|
|
162
|
+
if (project) list.push({ kind: 'project', dir: project })
|
|
163
|
+
for (const root of knownWorkspaceRoots()) {
|
|
164
|
+
const dir = path.join(root, 'models')
|
|
165
|
+
if (!project || dir !== project) list.push({ kind: 'workspace', dir })
|
|
166
|
+
}
|
|
167
|
+
return list
|
|
168
|
+
}
|
|
169
|
+
|
|
92
170
|
// 默认下载位置:
|
|
93
|
-
// 1.
|
|
94
|
-
// 2.
|
|
95
|
-
// 3.
|
|
171
|
+
// 1. 候选目录里已经有模型 → 用它(装了就用,不来回横跳)
|
|
172
|
+
// 2. 都没有、但老位置(~/.podwave/models)有模型 → 沿用,不搬家(避免升级后突然要重下 5 GB)
|
|
173
|
+
// 3. 全新安装 → 候选第一名(项目文件夹);连候选都没有才回落老位置
|
|
96
174
|
export function defaultModelsDir(start) {
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (hasModels(project)) return project
|
|
175
|
+
const candidates = modelsDirCandidates(start)
|
|
176
|
+
for (const candidate of candidates) {
|
|
177
|
+
if (hasModels(candidate.dir)) return candidate.dir
|
|
178
|
+
}
|
|
102
179
|
if (hasModels(LEGACY_MODELS_DIR)) return LEGACY_MODELS_DIR
|
|
103
|
-
return
|
|
180
|
+
if (candidates.length) return candidates[0].dir
|
|
181
|
+
return LEGACY_MODELS_DIR
|
|
104
182
|
}
|
|
105
183
|
|
|
106
184
|
// 把 ~ / ~/x / %VAR% 解析成绝对路径;空串返回 ''。只接受绝对路径或 ~ 开头。
|
|
@@ -224,17 +302,24 @@ export function listModels() {
|
|
|
224
302
|
.sort((a, b) => b.bytes - a.bytes || a.name.localeCompare(b.name))
|
|
225
303
|
}
|
|
226
304
|
|
|
227
|
-
export function modelsSummary() {
|
|
305
|
+
export function modelsSummary(start) {
|
|
228
306
|
const items = listModels()
|
|
229
307
|
const totalBytes = items.reduce((sum, item) => sum + item.bytes, 0)
|
|
230
|
-
const fallback = defaultModelsDir()
|
|
231
|
-
//
|
|
232
|
-
|
|
308
|
+
const fallback = defaultModelsDir(start)
|
|
309
|
+
// 「项目文件夹」候选:开发/file: 安装是插件仓库,发布版是当前工作区。
|
|
310
|
+
// 设置页拿第一个当一键入口,第二个用来提示「发布版会落在工作区」。
|
|
311
|
+
const candidates = modelsDirCandidates(start)
|
|
312
|
+
const project = candidates[0]?.dir || ''
|
|
313
|
+
const workspace = candidates.find((candidate) => candidate.kind === 'workspace')?.dir || workspaceModelsDir()
|
|
314
|
+
const dir = modelsDir()
|
|
233
315
|
return {
|
|
234
|
-
dir
|
|
316
|
+
dir,
|
|
235
317
|
defaultDir: fallback,
|
|
236
318
|
projectDir: project,
|
|
237
|
-
|
|
319
|
+
projectKind: candidates[0]?.kind || '',
|
|
320
|
+
workspaceDir: workspace,
|
|
321
|
+
legacyDir: LEGACY_MODELS_DIR,
|
|
322
|
+
custom: dir !== fallback,
|
|
238
323
|
totalBytes,
|
|
239
324
|
items,
|
|
240
325
|
}
|
|
Binary file
|
package/scripts/release.mjs
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// 发布脚本:node scripts/release.mjs 0.8.0
|
|
3
|
-
// 只做一条链路:改版本号 → 跑测试 → 构建 → 打包 → 提交 → 打 tag → 推送 → 建 Release。
|
|
4
|
-
// Release 说明取自 CHANGELOG.md 里对应的 "## <version> — <date>" 小节。
|
|
5
|
-
import { execSync } from 'node:child_process'
|
|
6
|
-
import fs from 'node:fs'
|
|
7
|
-
import path from 'node:path'
|
|
8
|
-
import { fileURLToPath } from 'node:url'
|
|
9
|
-
|
|
10
|
-
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
|
|
11
|
-
const version = process.argv[2]
|
|
12
|
-
if (!version || !/^\d+\.\d+\.\d+(-[\w.]+)?$/.test(version)) {
|
|
13
|
-
console.error('用法: node scripts/release.mjs <version>,例如 0.8.0')
|
|
14
|
-
process.exit(1)
|
|
15
|
-
}
|
|
16
|
-
const [major, minor] = version.split('.')
|
|
17
|
-
const tag = `v${version}`
|
|
18
|
-
|
|
19
|
-
function run(command) {
|
|
20
|
-
console.log(`\n$ ${command}`)
|
|
21
|
-
execSync(command, { cwd: root, stdio: 'inherit' })
|
|
22
|
-
}
|
|
23
|
-
function read(rel) {
|
|
24
|
-
return fs.readFileSync(path.join(root, rel), 'utf8')
|
|
25
|
-
}
|
|
26
|
-
function write(rel, content) {
|
|
27
|
-
fs.writeFileSync(path.join(root, rel), content)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// 1. CHANGELOG 小节
|
|
31
|
-
const changelog = read('CHANGELOG.md')
|
|
32
|
-
const heading = new RegExp(`^## ${version.replace(/\./g, '\\.')} — .+$`, 'm')
|
|
33
|
-
if (!heading.test(changelog)) {
|
|
34
|
-
console.error(`CHANGELOG.md 里没有 ${version} 的小节(## ${version} — YYYY-MM-DD)`)
|
|
35
|
-
process.exit(1)
|
|
36
|
-
}
|
|
37
|
-
const start = changelog.search(heading)
|
|
38
|
-
const rest = changelog.slice(start)
|
|
39
|
-
const end = rest.indexOf('\n## ', 1)
|
|
40
|
-
const notes = rest.slice(0, end === -1 ? undefined : end).trim()
|
|
41
|
-
const lines = notes.split('\n')
|
|
42
|
-
const headingText = lines[0].replace(/^##\s*/, '')
|
|
43
|
-
const descLine = lines.slice(1).map((line) => line.trim()).find(Boolean) || headingText
|
|
44
|
-
const title = `${tag} ${descLine.replace(/^[-*]\s*/, '').replace(/\*\*/g, '').slice(0, 90)}`
|
|
45
|
-
|
|
46
|
-
// 2. 版本号:package.json / host health / 客户端 brand
|
|
47
|
-
write('package.json', read('package.json').replace(/"version": "[^"]+"/, `"version": "${version}"`))
|
|
48
|
-
let host = read('src/host.js')
|
|
49
|
-
if (!/version: '\d+\.\d+\.\d+'/.test(host)) throw new Error('host.js 里找不到 version 字面量')
|
|
50
|
-
host = host.replace(/version: '\d+\.\d+\.\d+'/, `version: '${version}'`)
|
|
51
|
-
write('src/host.js', host)
|
|
52
|
-
let app = read('client/src/App.jsx')
|
|
53
|
-
if (!/<span className="brand-version">[\d.]+<\/span>/.test(app)) throw new Error('App.jsx 里找不到 brand-version')
|
|
54
|
-
app = app.replace(/<span className="brand-version">[\d.]+<\/span>/, `<span className="brand-version">${major}.${minor}</span>`)
|
|
55
|
-
write('client/src/App.jsx', app)
|
|
56
|
-
|
|
57
|
-
// 3. 测试 + 构建
|
|
58
|
-
run('npm test')
|
|
59
|
-
run('npm run build')
|
|
60
|
-
|
|
61
|
-
// 4. 打包(产物只用于 Release 附件,不提交)
|
|
62
|
-
const packDir = fs.mkdtempSync('/tmp/podwave-release-')
|
|
63
|
-
run(`npm pack --pack-destination "${packDir}"`)
|
|
64
|
-
const tgz = path.join(packDir, `dsh-podwave-${version}.tgz`)
|
|
65
|
-
if (!fs.existsSync(tgz)) throw new Error(`没有找到打包产物 ${tgz}`)
|
|
66
|
-
|
|
67
|
-
// 5. 提交、打 tag、推送
|
|
68
|
-
run('git add -A')
|
|
69
|
-
const description = title.replace(/^v\S+\s+/, '').replace(/"/g, "'")
|
|
70
|
-
run(`git commit -m "v${version}: ${description}"`)
|
|
71
|
-
run(`git tag -f ${tag}`)
|
|
72
|
-
run('git push')
|
|
73
|
-
run(`git push -f origin ${tag}`)
|
|
74
|
-
|
|
75
|
-
// 6. Release
|
|
76
|
-
const notesFile = path.join(packDir, 'notes.md')
|
|
77
|
-
fs.writeFileSync(notesFile, notes)
|
|
78
|
-
run(`gh release create ${tag} "${tgz}" --title "${title.replace(/"/g, "'")}" --notes-file "${notesFile}"`)
|
|
79
|
-
console.log(`\n完成:https://github.com/Watchcats211/dsh-podwave/releases/tag/${tag}`)
|