dsh-watch-together 0.2.13 → 0.2.14
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 +42 -0
- package/CREDITS.md +37 -0
- package/README.md +24 -5
- package/docs/INTERFACES.zh.md +13 -0
- package/dsh.plugin.json +12 -12
- package/examples/floating-chat/glass_static.py +158 -0
- package/examples/floating-chat/window.py +380 -50
- package/lib/client.js +41 -9
- package/package.json +133 -118
- package/scripts/check-expand-message.py +279 -0
- package/scripts/check-input-caret.py +151 -0
- package/src/settings/config.js +53 -0
- package/src/settings/page.html +38 -4
- package/src/settings/server.js +8 -2
package/lib/client.js
CHANGED
|
@@ -22,6 +22,8 @@ window.__ModuleLoader__.load({
|
|
|
22
22
|
'[data-dsh-vs] .dsh-vs-input{width:100%;height:34px;padding:0 10px;border:1px solid var(--dsw-alias-border-l2,rgba(0,0,0,.14));border-radius:8px;background:var(--dsw-alias-bg-layer-1,#fff);color:inherit;font:inherit;outline:none}',
|
|
23
23
|
'[data-dsh-vs] .dsh-vs-input::placeholder{color:var(--dsw-alias-label-tertiary,#a0a6b0)}',
|
|
24
24
|
'[data-dsh-vs] .dsh-vs-input:focus{border-color:var(--dsw-alias-brand-primary,#4f7cff);box-shadow:0 0 0 3px rgba(79,124,255,.14)}',
|
|
25
|
+
'[data-dsh-vs] .dsh-vs-select{width:100%;height:34px;padding:0 8px;border:1px solid var(--dsw-alias-border-l2,rgba(0,0,0,.14));border-radius:8px;background:var(--dsw-alias-bg-layer-1,#fff);color:inherit;font:inherit;outline:none}',
|
|
26
|
+
'[data-dsh-vs] .dsh-vs-select:focus{border-color:var(--dsw-alias-brand-primary,#4f7cff);box-shadow:0 0 0 3px rgba(79,124,255,.14)}',
|
|
25
27
|
'[data-dsh-vs] .dsh-vs-deps{display:flex;flex-direction:column}',
|
|
26
28
|
'[data-dsh-vs] .dsh-vs-dep{display:flex;align-items:center;gap:10px;min-height:46px;padding:8px 0;border-top:1px solid var(--dsw-alias-border-l2,rgba(0,0,0,.08))}',
|
|
27
29
|
'[data-dsh-vs] .dsh-vs-dep:first-child{border-top:0;padding-top:2px}',
|
|
@@ -83,10 +85,12 @@ window.__ModuleLoader__.load({
|
|
|
83
85
|
const video = state && state.video ? state.video : {};
|
|
84
86
|
const watch = state && state.watch ? state.watch : {};
|
|
85
87
|
const voice = state && state.voice ? state.voice : {};
|
|
88
|
+
const win = state && state.window ? state.window : {};
|
|
86
89
|
return {
|
|
87
90
|
browserPort: video.browserPort ? String(video.browserPort) : '',
|
|
88
91
|
chatPort: watch.chatPort ? String(watch.chatPort) : '9377',
|
|
89
92
|
adapter: typeof voice.adapter === 'string' ? voice.adapter : '',
|
|
93
|
+
windowStyle: typeof win.style === 'string' ? win.style : 'auto',
|
|
90
94
|
voiceEnvOverrides: Array.isArray(voice.envOverrides) ? voice.envOverrides : [],
|
|
91
95
|
};
|
|
92
96
|
}
|
|
@@ -107,6 +111,19 @@ window.__ModuleLoader__.load({
|
|
|
107
111
|
);
|
|
108
112
|
}
|
|
109
113
|
|
|
114
|
+
function SelectField(props) {
|
|
115
|
+
return h('div', { className: 'dsh-vs-field' + (props.wide ? ' dsh-vs-span-2' : '') },
|
|
116
|
+
h('span', { className: 'dsh-vs-label' }, props.label),
|
|
117
|
+
h('select', {
|
|
118
|
+
className: 'dsh-vs-select',
|
|
119
|
+
value: props.value,
|
|
120
|
+
onChange: event => props.onChange(event.target.value),
|
|
121
|
+
}, (props.options || []).map(option =>
|
|
122
|
+
h('option', { key: option.value, value: option.value }, option.label))),
|
|
123
|
+
props.hint ? h('span', { className: 'dsh-vs-hint' }, props.hint) : null,
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
110
127
|
function depDetail(check) {
|
|
111
128
|
if (check.ok && (check.id === 'core' || check.id === 'extension' || check.id === 'floating')) return '已安装';
|
|
112
129
|
return check.detail || '';
|
|
@@ -213,8 +230,9 @@ window.__ModuleLoader__.load({
|
|
|
213
230
|
};
|
|
214
231
|
const watch = { chatPort: Number(current.chatPort) };
|
|
215
232
|
const voice = { adapter: current.adapter };
|
|
216
|
-
|
|
217
|
-
|
|
233
|
+
const win = { style: current.windowStyle };
|
|
234
|
+
await apiCall(api, '/save', { video: video, watch: watch, voice: voice, window: win });
|
|
235
|
+
setNotice('已自动保存。悬浮窗样式立刻生效;聊天端口改动在下次启动 DSH 后生效。');
|
|
218
236
|
} catch (e) {
|
|
219
237
|
setError(String(e && e.message ? e.message : e));
|
|
220
238
|
} finally {
|
|
@@ -234,7 +252,7 @@ window.__ModuleLoader__.load({
|
|
|
234
252
|
}
|
|
235
253
|
const timer = setTimeout(() => { void save(); }, 550);
|
|
236
254
|
return () => clearTimeout(timer);
|
|
237
|
-
}, [form && form.browserPort, form && form.chatPort, form && form.adapter]);
|
|
255
|
+
}, [form && form.browserPort, form && form.chatPort, form && form.adapter, form && form.windowStyle]);
|
|
238
256
|
|
|
239
257
|
if (!form) {
|
|
240
258
|
return h('div', { 'data-dsh-vs': 'watch', className: 'dsh-vs dsh-vs-loading' }, error || '正在加载设置…');
|
|
@@ -287,6 +305,26 @@ window.__ModuleLoader__.load({
|
|
|
287
305
|
'环境变量优先:' + form.voiceEnvOverrides.join('、') + ';这里的改动不会覆盖它们。')
|
|
288
306
|
: null,
|
|
289
307
|
),
|
|
308
|
+
h('section', { className: 'dsh-vs-section' },
|
|
309
|
+
h('div', { className: 'dsh-vs-section-head' },
|
|
310
|
+
h('h3', { className: 'dsh-vs-section-title' }, '悬浮窗样式'),
|
|
311
|
+
),
|
|
312
|
+
h('div', { className: 'dsh-vs-grid' },
|
|
313
|
+
h(SelectField, {
|
|
314
|
+
label: '外观预设',
|
|
315
|
+
value: form.windowStyle,
|
|
316
|
+
wide: true,
|
|
317
|
+
options: [
|
|
318
|
+
{ value: 'auto', label: '自动 —— 远程/录屏用纯色,其余实时玻璃' },
|
|
319
|
+
{ value: 'live', label: '实时玻璃 —— 跟着桌面模糊(好看,吃 CPU)' },
|
|
320
|
+
{ value: 'frost', label: '静态磨砂 —— 不吃性能(低配机选这个)' },
|
|
321
|
+
{ value: 'solid', label: '纯色 —— 最省,背后不透' },
|
|
322
|
+
],
|
|
323
|
+
hint: '改完立刻生效,不用重开窗口。实时玻璃每帧都要抓屏再模糊 —— 卡就换成静态磨砂:不抓屏、只画一张预生成的底板。',
|
|
324
|
+
onChange: value => setForm(prev => ({ ...prev, windowStyle: value })),
|
|
325
|
+
}),
|
|
326
|
+
),
|
|
327
|
+
),
|
|
290
328
|
h('section', { className: 'dsh-vs-section' },
|
|
291
329
|
h('div', { className: 'dsh-vs-section-head' },
|
|
292
330
|
h('h3', { className: 'dsh-vs-section-title' }, '连接状态'),
|
|
@@ -344,12 +382,6 @@ window.__ModuleLoader__.load({
|
|
|
344
382
|
}
|
|
345
383
|
|
|
346
384
|
function apply(ctx) {
|
|
347
|
-
ctx.slots.inject('settings.plugins.tab', () => ctx.slots.register({
|
|
348
|
-
name: 'settings.plugins.tab',
|
|
349
|
-
id: 'watch-together',
|
|
350
|
-
order: 20,
|
|
351
|
-
label: () => '一起看',
|
|
352
|
-
}, SettingsTab));
|
|
353
385
|
ctx.slots.inject('plugins.bundle.config', () => ctx.slots.register({
|
|
354
386
|
name: 'plugins.bundle.config',
|
|
355
387
|
key: 'dsh-watch-together',
|
package/package.json
CHANGED
|
@@ -1,118 +1,133 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dsh-watch-together",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "Watch a video together
|
|
5
|
-
"keywords": [
|
|
6
|
-
"dsh",
|
|
7
|
-
"dsh-plugin",
|
|
8
|
-
"deepseek-harness",
|
|
9
|
-
"video",
|
|
10
|
-
"watch-together",
|
|
11
|
-
"watch-party",
|
|
12
|
-
"companion",
|
|
13
|
-
"playback",
|
|
14
|
-
"subtitle",
|
|
15
|
-
"caption",
|
|
16
|
-
"tts"
|
|
17
|
-
],
|
|
18
|
-
"homepage": "https://github.com/SAOS-3624/dsh-watch-together#readme",
|
|
19
|
-
"bugs": {
|
|
20
|
-
"url": "https://github.com/SAOS-3624/dsh-watch-together/issues"
|
|
21
|
-
},
|
|
22
|
-
"repository": {
|
|
23
|
-
"type": "git",
|
|
24
|
-
"url": "git+https://github.com/SAOS-3624/dsh-watch-together.git"
|
|
25
|
-
},
|
|
26
|
-
"author": "SAOS-3624",
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"
|
|
46
|
-
"./
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"src",
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
"
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
"
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
"
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-watch-together",
|
|
3
|
+
"version": "0.2.14",
|
|
4
|
+
"description": "Watch a video together, in sync with the user's real playback: every segment arrives as one storyboard image plus its subtitle lines just before it ends, while the floating window carries spoken replies and live room audio — picture and voice, not a transcript.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"dsh",
|
|
7
|
+
"dsh-plugin",
|
|
8
|
+
"deepseek-harness",
|
|
9
|
+
"video",
|
|
10
|
+
"watch-together",
|
|
11
|
+
"watch-party",
|
|
12
|
+
"companion",
|
|
13
|
+
"playback",
|
|
14
|
+
"subtitle",
|
|
15
|
+
"caption",
|
|
16
|
+
"tts"
|
|
17
|
+
],
|
|
18
|
+
"homepage": "https://github.com/SAOS-3624/dsh-watch-together#readme",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/SAOS-3624/dsh-watch-together/issues"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/SAOS-3624/dsh-watch-together.git"
|
|
25
|
+
},
|
|
26
|
+
"author": "SAOS-3624",
|
|
27
|
+
"contributors": [
|
|
28
|
+
{
|
|
29
|
+
"name": "ggfgfgf-on",
|
|
30
|
+
"url": "https://github.com/ggfgfgf-on"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"name": "gao804",
|
|
34
|
+
"url": "https://github.com/gao804"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"name": "DreamDLYY",
|
|
38
|
+
"url": "https://github.com/DreamDLYY"
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
"license": "Apache-2.0",
|
|
42
|
+
"type": "module",
|
|
43
|
+
"main": "./src/index.js",
|
|
44
|
+
"exports": {
|
|
45
|
+
".": "./src/index.js",
|
|
46
|
+
"./client": "./lib/client.js",
|
|
47
|
+
"./register": "./src/register.js",
|
|
48
|
+
"./tool-spec": "./src/tool-spec.js",
|
|
49
|
+
"./watch": "./src/watch.js",
|
|
50
|
+
"./batches": "./src/batches.js",
|
|
51
|
+
"./chat": "./src/chat.js",
|
|
52
|
+
"./voice": "./src/voice.js",
|
|
53
|
+
"./speech-bus": "./src/speech-bus.js",
|
|
54
|
+
"./voice-adapter": "./src/voice-adapter.js",
|
|
55
|
+
"./interfaces": "./src/interfaces.js",
|
|
56
|
+
"./public-api": "./src/public-api.js",
|
|
57
|
+
"./recognition-interface": "./src/recognition-interface.js",
|
|
58
|
+
"./tts-interface": "./src/tts-interface.js",
|
|
59
|
+
"./window-interface": "./src/window-interface.js",
|
|
60
|
+
"./window-protocol": "./src/window-protocol.js"
|
|
61
|
+
},
|
|
62
|
+
"bin": {
|
|
63
|
+
"dsh-watch": "./bin/watch.mjs",
|
|
64
|
+
"dsh-watch-lines": "./bin/lines.mjs"
|
|
65
|
+
},
|
|
66
|
+
"files": [
|
|
67
|
+
"src",
|
|
68
|
+
"lib",
|
|
69
|
+
"bin",
|
|
70
|
+
"extension",
|
|
71
|
+
"scripts",
|
|
72
|
+
"docs",
|
|
73
|
+
"cordis.patch.yml",
|
|
74
|
+
"dsh.plugin.json",
|
|
75
|
+
"README.md",
|
|
76
|
+
"CHANGELOG.md",
|
|
77
|
+
"CREDITS.md",
|
|
78
|
+
"LICENSE",
|
|
79
|
+
"NOTICE",
|
|
80
|
+
"examples/floating-chat/*.py",
|
|
81
|
+
"examples/floating-chat/*.cmd",
|
|
82
|
+
"examples/floating-chat/*.png",
|
|
83
|
+
"examples/floating-chat/*.txt",
|
|
84
|
+
"examples/voice-edge-tts/index.mjs",
|
|
85
|
+
"examples/voice-edge-tts/stream/*.mjs",
|
|
86
|
+
"examples/voice-edge-tts/stream/*.py",
|
|
87
|
+
"examples/voice-edge-tts/stream/*.mp3"
|
|
88
|
+
],
|
|
89
|
+
"engines": {
|
|
90
|
+
"node": ">=20"
|
|
91
|
+
},
|
|
92
|
+
"scripts": {
|
|
93
|
+
"test": "node --test",
|
|
94
|
+
"pretest": "node scripts/sync-dep.mjs",
|
|
95
|
+
"sync:dep": "node scripts/sync-dep.mjs",
|
|
96
|
+
"prepublishOnly": "node scripts/check-syntax.mjs && node --test",
|
|
97
|
+
"check": "node scripts/check-syntax.mjs",
|
|
98
|
+
"doctor": "node bin/watch.mjs doctor",
|
|
99
|
+
"install:extension": "node bin/watch.mjs install-extension",
|
|
100
|
+
"sim": "node scripts/watch-sim.mjs",
|
|
101
|
+
"e2e": "node scripts/watch-e2e.mjs"
|
|
102
|
+
},
|
|
103
|
+
"dependencies": {
|
|
104
|
+
"dsh-video-storyboard": "^0.6.0"
|
|
105
|
+
},
|
|
106
|
+
"peerDependencies": {
|
|
107
|
+
"@deepseek-ai/dsh-tools": ">=0.1.0-rc.7"
|
|
108
|
+
},
|
|
109
|
+
"peerDependenciesMeta": {
|
|
110
|
+
"@deepseek-ai/dsh-tools": {
|
|
111
|
+
"optional": true
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
"dsh": {
|
|
115
|
+
"bundle": {
|
|
116
|
+
"patch": "./cordis.patch.yml"
|
|
117
|
+
},
|
|
118
|
+
"client": {
|
|
119
|
+
"platform": "web"
|
|
120
|
+
},
|
|
121
|
+
"catalog": {
|
|
122
|
+
"category": "tool",
|
|
123
|
+
"summary": {
|
|
124
|
+
"en": "Watch a video together, in sync with the user's playback: each segment arrives as one storyboard image plus its subtitle lines just before it ends, and the floating window carries spoken replies and live room audio.",
|
|
125
|
+
"zh": "和智能体一起看视频:跟着真实播放位置,每段结束前把分镜画面 + 带秒台词交过去;悬浮窗里能出声,也听得见房间里的声音 —— 给的是画面和声音,不是一段转写文本。"
|
|
126
|
+
},
|
|
127
|
+
"capabilities": [
|
|
128
|
+
"fs",
|
|
129
|
+
"shell"
|
|
130
|
+
]
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"""check-expand-message.py — 长消息展开的回归(不需要真的开窗)。
|
|
2
|
+
|
|
3
|
+
跑法(仓库根):
|
|
4
|
+
|
|
5
|
+
python scripts/check-expand-message.py
|
|
6
|
+
|
|
7
|
+
背景:气泡按 `chat_layout()` 的四个固定槽位排,一个槽 88px(窗口 >=560 时),
|
|
8
|
+
11 号字行高约 15px,所以一条消息最多五行多一点,再长就被 `_fit_lines` 砍掉加
|
|
9
|
+
省略号,没有任何展开入口 —— 长句里最关键的半句经常正好落在省略号后面。
|
|
10
|
+
|
|
11
|
+
这里守四件事:
|
|
12
|
+
|
|
13
|
+
1. **槽高和内容无关**:`chat_layout` 是窗口高度的纯函数。被截断不是因为气泡
|
|
14
|
+
高度和内容互相依赖(这是个容易反推错的结论),而是因为槽位网格固定成 4 格。
|
|
15
|
+
2. **展开真的变高**:展开那条独占 4 槽的纵向范围,可见行数必须显著增加。
|
|
16
|
+
3. **不许压到输入框**:展开后气泡底边仍要在 `input_shape` 上沿之上 —— 文字
|
|
17
|
+
画出底板就落在透明区上,直接看不清。
|
|
18
|
+
4. **按消息身份跟随**:展开状态存 (role, text, at),不是槽位下标。新消息进来
|
|
19
|
+
会让同一条消息换槽,存下标就会变成"展开的是另一条"。
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
import sys
|
|
25
|
+
from pathlib import Path
|
|
26
|
+
|
|
27
|
+
HERE = Path(__file__).resolve().parent
|
|
28
|
+
sys.path.insert(0, str(HERE.parent / "examples" / "floating-chat"))
|
|
29
|
+
|
|
30
|
+
from glass_geometry import MESSAGE_SLOTS, chat_layout # noqa: E402
|
|
31
|
+
from window import LiveGlass # noqa: E402
|
|
32
|
+
|
|
33
|
+
LS = 15 # 11 号字实测行高
|
|
34
|
+
SIZES = (420, 560, 627, 800)
|
|
35
|
+
|
|
36
|
+
failures: list[str] = []
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def check(name, cond, detail=""):
|
|
40
|
+
if not cond:
|
|
41
|
+
failures.append(f"{name}{(': ' + detail) if detail else ''}")
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def fit_rows(max_height, ls=LS):
|
|
45
|
+
"""_fit_lines 的行数上限部分。"""
|
|
46
|
+
return max(1, int(max_height // ls))
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_slot_height_is_pure_function_of_h():
|
|
50
|
+
"""槽高只由窗口高度决定 —— 和消息内容、条数都无关。"""
|
|
51
|
+
for h in SIZES:
|
|
52
|
+
a = chat_layout(h)
|
|
53
|
+
b = chat_layout(h)
|
|
54
|
+
check(f"h={h} chat_layout 幂等", a == b)
|
|
55
|
+
ys, bh = chat_layout(627)
|
|
56
|
+
check("627 的四个槽等高", bh == 88, str(bh))
|
|
57
|
+
check("627 槽位是 [104,198,292,386]", ys == [104, 198, 292, 386], str(ys))
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_expand_adds_rows():
|
|
61
|
+
"""展开后可见行数必须显著增加。"""
|
|
62
|
+
for h in SIZES:
|
|
63
|
+
ys, bh = chat_layout(h)
|
|
64
|
+
collapsed = bh
|
|
65
|
+
expanded = ys[MESSAGE_SLOTS - 1] + bh - ys[0]
|
|
66
|
+
c_rows, e_rows = fit_rows(collapsed), fit_rows(expanded)
|
|
67
|
+
check(f"h={h} 展开后更高", expanded > collapsed, f"{expanded} <= {collapsed}")
|
|
68
|
+
check(f"h={h} 展开后行数变多", e_rows > c_rows, f"{e_rows} <= {c_rows}")
|
|
69
|
+
check(f"h={h} 至少翻倍", e_rows >= c_rows * 2, f"{c_rows} -> {e_rows}")
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def test_expand_never_covers_input():
|
|
73
|
+
"""展开后的气泡底边不能压到输入框上沿。"""
|
|
74
|
+
for h in SIZES:
|
|
75
|
+
ys, bh = chat_layout(h)
|
|
76
|
+
bottom = ys[MESSAGE_SLOTS - 1] + bh
|
|
77
|
+
input_top = h - 80
|
|
78
|
+
check(f"h={h} 不压输入框", bottom <= input_top,
|
|
79
|
+
f"气泡底 {bottom} > 输入框顶 {input_top}")
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def test_identity_not_index():
|
|
83
|
+
"""展开状态按消息身份跟随,换槽不跟错,滚出视野不误展开。"""
|
|
84
|
+
msgs = [
|
|
85
|
+
{"role": "assistant", "text": "短", "at": 1},
|
|
86
|
+
{"role": "user", "text": "也短", "at": 2},
|
|
87
|
+
{"role": "assistant", "text": "很长" * 60, "at": 3},
|
|
88
|
+
{"role": "user", "text": "末尾", "at": 4},
|
|
89
|
+
]
|
|
90
|
+
key = LiveGlass._msg_key(msgs[2])
|
|
91
|
+
check("_msg_key 是三元组", key == ("assistant", "很长" * 60, 3), str(key))
|
|
92
|
+
|
|
93
|
+
stub = object.__new__(LiveGlass)
|
|
94
|
+
stub._expanded = key
|
|
95
|
+
check("命中当前槽", LiveGlass._expanded_index(stub, msgs) == 2)
|
|
96
|
+
|
|
97
|
+
# 新消息进来,同一条消息从槽 2 挪到槽 1
|
|
98
|
+
shifted = msgs[1:] + [{"role": "assistant", "text": "新来的", "at": 5}]
|
|
99
|
+
check("换槽后跟着走", LiveGlass._expanded_index(stub, shifted) == 1)
|
|
100
|
+
check("这正是不能存下标的原因",
|
|
101
|
+
LiveGlass._msg_key(shifted[2]) != key)
|
|
102
|
+
|
|
103
|
+
# 滚出视野:不许退化成"展开那一槽的任何一条"
|
|
104
|
+
gone = [{"role": "assistant", "text": f"其他{i}", "at": 10 + i} for i in range(4)]
|
|
105
|
+
check("滚出视野返回 None", LiveGlass._expanded_index(stub, gone) is None)
|
|
106
|
+
|
|
107
|
+
# 同文不同时间戳是两条消息,不能互相顶替
|
|
108
|
+
twin = dict(msgs[2])
|
|
109
|
+
twin["at"] = 999
|
|
110
|
+
check("同文不同 at 不算同一条",
|
|
111
|
+
LiveGlass._msg_key(twin) != key)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def test_toggle_and_autocollapse():
|
|
115
|
+
"""点同一条收起、点另一条换过去;自动收起要真的清掉状态。"""
|
|
116
|
+
laid_out = []
|
|
117
|
+
stub = object.__new__(LiveGlass)
|
|
118
|
+
stub._expanded = None
|
|
119
|
+
stub._layout = lambda *_a, **_k: laid_out.append(True)
|
|
120
|
+
|
|
121
|
+
a = ("user", "a", 1)
|
|
122
|
+
b = ("user", "b", 2)
|
|
123
|
+
LiveGlass._toggle_expand(stub, a)
|
|
124
|
+
check("点一下展开", stub._expanded == a, str(stub._expanded))
|
|
125
|
+
LiveGlass._toggle_expand(stub, a)
|
|
126
|
+
check("再点收起", stub._expanded is None, str(stub._expanded))
|
|
127
|
+
LiveGlass._toggle_expand(stub, a)
|
|
128
|
+
LiveGlass._toggle_expand(stub, b)
|
|
129
|
+
check("点另一条就换过去", stub._expanded == b, str(stub._expanded))
|
|
130
|
+
check("每次都重排", len(laid_out) == 4, str(len(laid_out)))
|
|
131
|
+
|
|
132
|
+
LiveGlass._collapse_expanded(stub)
|
|
133
|
+
check("自动收起清掉状态", stub._expanded is None)
|
|
134
|
+
LiveGlass._collapse_expanded(stub)
|
|
135
|
+
check("已经收起时再调不报错", stub._expanded is None)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def test_clip_flag():
|
|
139
|
+
"""_fit_lines 要如实报告有没有砍:短消息不标、长消息标。"""
|
|
140
|
+
class FakeFont:
|
|
141
|
+
def measure(self, s):
|
|
142
|
+
return len(s) * 10
|
|
143
|
+
|
|
144
|
+
def metrics(self, _k):
|
|
145
|
+
return LS
|
|
146
|
+
|
|
147
|
+
class FakeFonts:
|
|
148
|
+
def get(self, _size, _bold=False):
|
|
149
|
+
return FakeFont()
|
|
150
|
+
|
|
151
|
+
stub = object.__new__(LiveGlass)
|
|
152
|
+
stub.fonts = FakeFonts()
|
|
153
|
+
stub._fit_clipped = False
|
|
154
|
+
|
|
155
|
+
# 一个槽 88px → 最多 5 行;每行最多 10 个字符(maxw=100)
|
|
156
|
+
LiveGlass._fit_lines(stub, "短", 11, 100, 88)
|
|
157
|
+
check("短消息不标截断", stub._fit_clipped is False)
|
|
158
|
+
|
|
159
|
+
LiveGlass._fit_lines(stub, "x" * 200, 11, 100, 88)
|
|
160
|
+
check("长消息标截断", stub._fit_clipped is True)
|
|
161
|
+
|
|
162
|
+
# 展开后放得下的,就不该再标
|
|
163
|
+
lines = LiveGlass._fit_lines(stub, "x" * 60, 11, 100, 88)
|
|
164
|
+
clipped_collapsed = stub._fit_clipped
|
|
165
|
+
LiveGlass._fit_lines(stub, "x" * 60, 11, 100, 386 + 88 - 104)
|
|
166
|
+
check("60 字符收起时被砍", clipped_collapsed is True, f"{len(lines)} 行")
|
|
167
|
+
check("60 字符展开后放得下", stub._fit_clipped is False)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def _stub_for_shapes(h, expanded=None, w=882):
|
|
171
|
+
"""能跑 _message_shapes 的最小壳子:它只用到 _geo.width/height、fonts、_expanded。"""
|
|
172
|
+
class FakeFont:
|
|
173
|
+
def measure(self, s):
|
|
174
|
+
return len(s) * 10
|
|
175
|
+
|
|
176
|
+
def metrics(self, _k):
|
|
177
|
+
return LS
|
|
178
|
+
|
|
179
|
+
class FakeFonts:
|
|
180
|
+
def get(self, _size, _bold=False):
|
|
181
|
+
return FakeFont()
|
|
182
|
+
|
|
183
|
+
class FakeGeo:
|
|
184
|
+
width = w
|
|
185
|
+
height = h
|
|
186
|
+
|
|
187
|
+
stub = object.__new__(LiveGlass)
|
|
188
|
+
stub.fonts = FakeFonts()
|
|
189
|
+
stub._geo = FakeGeo()
|
|
190
|
+
stub._expanded = expanded
|
|
191
|
+
stub._fit_clipped = False
|
|
192
|
+
return stub
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def test_message_shapes_honors_expand():
|
|
196
|
+
"""直接验 _message_shapes:展开那条的框必须真的横跨 4 槽,其余是零框。"""
|
|
197
|
+
# 文本要足够长才撑得满展开后的高度:假字体一行放得下 54 个字符,
|
|
198
|
+
# 展开后约 24 行,所以 1500 字才打得满(气泡高度按内容算,内容不够
|
|
199
|
+
# 本来就不该撑满 —— 这里要验的是"长内容能用上多出来的空间")。
|
|
200
|
+
msgs = [
|
|
201
|
+
{"role": "assistant", "text": "甲" * 1500, "at": 1},
|
|
202
|
+
{"role": "user", "text": "乙", "at": 2},
|
|
203
|
+
{"role": "assistant", "text": "丙" * 1500, "at": 3},
|
|
204
|
+
{"role": "user", "text": "丁", "at": 4},
|
|
205
|
+
]
|
|
206
|
+
h = 627
|
|
207
|
+
ys, bh = chat_layout(h)
|
|
208
|
+
span = ys[MESSAGE_SLOTS - 1] + bh - ys[0]
|
|
209
|
+
|
|
210
|
+
# 收起态:每条各占自己的槽,框高不超过单槽
|
|
211
|
+
shapes, infos = LiveGlass._message_shapes(_stub_for_shapes(h), msgs)
|
|
212
|
+
check("收起态四条都有框", len(infos) == MESSAGE_SLOTS, str(len(infos)))
|
|
213
|
+
for i, info in enumerate(infos):
|
|
214
|
+
_bx0, by0, _bx1, by1, _r = info["shape"]
|
|
215
|
+
check(f"收起态槽 {i} 不超单槽", by1 - by0 <= bh, f"{by1 - by0} > {bh}")
|
|
216
|
+
check(f"收起态槽 {i} 没标展开", info["expanded"] is False)
|
|
217
|
+
|
|
218
|
+
# 展开第三条(下标 2)
|
|
219
|
+
key = LiveGlass._msg_key(msgs[2])
|
|
220
|
+
shapes, infos = LiveGlass._message_shapes(_stub_for_shapes(h, key), msgs)
|
|
221
|
+
check("展开态只画一条", len(infos) == 1, str(len(infos)))
|
|
222
|
+
info = infos[0]
|
|
223
|
+
check("展开的是第三条", info["key"] == key)
|
|
224
|
+
check("展开标记置位", info["expanded"] is True)
|
|
225
|
+
_bx0, by0, _bx1, by1, _r = info["shape"]
|
|
226
|
+
check("展开框高跨 4 槽", by1 - by0 > bh,
|
|
227
|
+
f"框高 {by1 - by0} 不比单槽 {bh} 高")
|
|
228
|
+
check("展开框顶对齐第一槽", by0 <= ys[0] + LS, f"by0={by0} ys0={ys[0]}")
|
|
229
|
+
check("展开框底不超第四槽", by1 <= ys[MESSAGE_SLOTS - 1] + bh,
|
|
230
|
+
f"by1={by1} 上限={ys[MESSAGE_SLOTS - 1] + bh}")
|
|
231
|
+
check("展开框底不压输入框", by1 <= h - 80, f"by1={by1} 输入框顶={h - 80}")
|
|
232
|
+
|
|
233
|
+
# 其余三槽必须是零框(让位),否则底板会画在老位置
|
|
234
|
+
zero = [s for s in shapes[:MESSAGE_SLOTS] if s == (0, 0, 0, 0, 0)]
|
|
235
|
+
check("其余三槽让位", len(zero) == MESSAGE_SLOTS - 1, str(len(zero)))
|
|
236
|
+
|
|
237
|
+
# 展开后能看到的行数要真的比收起时多
|
|
238
|
+
collapsed_rows = fit_rows(bh)
|
|
239
|
+
expanded_rows = len(info["lines"])
|
|
240
|
+
check("展开后行数变多", expanded_rows > collapsed_rows,
|
|
241
|
+
f"{expanded_rows} <= {collapsed_rows}")
|
|
242
|
+
check("展开后用上了多出来的空间", expanded_rows >= fit_rows(span) - 2,
|
|
243
|
+
f"{expanded_rows} 行,跨高能放 {fit_rows(span)} 行")
|
|
244
|
+
|
|
245
|
+
# 展开一条已经滚出视野的消息:不许误展开别人
|
|
246
|
+
stray = ("user", "不在列表里", 999)
|
|
247
|
+
shapes, infos = LiveGlass._message_shapes(_stub_for_shapes(h, stray), msgs)
|
|
248
|
+
check("身份不在视野时退回收起态", len(infos) == MESSAGE_SLOTS, str(len(infos)))
|
|
249
|
+
for info in infos:
|
|
250
|
+
check("没有谁被误标成展开", info["expanded"] is False)
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def main():
|
|
254
|
+
test_slot_height_is_pure_function_of_h()
|
|
255
|
+
test_expand_adds_rows()
|
|
256
|
+
test_expand_never_covers_input()
|
|
257
|
+
test_identity_not_index()
|
|
258
|
+
test_toggle_and_autocollapse()
|
|
259
|
+
test_clip_flag()
|
|
260
|
+
test_message_shapes_honors_expand()
|
|
261
|
+
|
|
262
|
+
if failures:
|
|
263
|
+
print(f"FAIL ({len(failures)})")
|
|
264
|
+
for f in failures:
|
|
265
|
+
print(" -", f)
|
|
266
|
+
return 1
|
|
267
|
+
|
|
268
|
+
print("槽高是 h 的纯函数、展开行数翻倍、不压输入框、按身份跟随 —— 全过")
|
|
269
|
+
print()
|
|
270
|
+
print("窗口高 槽高 收起可见行 展开可见行")
|
|
271
|
+
for h in SIZES:
|
|
272
|
+
ys, bh = chat_layout(h)
|
|
273
|
+
e = ys[MESSAGE_SLOTS - 1] + bh - ys[0]
|
|
274
|
+
print(f"{h:<8} {bh:<6} {fit_rows(bh):<12} {fit_rows(e)}")
|
|
275
|
+
return 0
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
if __name__ == "__main__":
|
|
279
|
+
raise SystemExit(main())
|