dsh-dock 0.11.2 → 0.11.5

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.
Files changed (41) hide show
  1. package/LICENSE +18 -18
  2. package/README.md +255 -396
  3. package/client.js +596 -98
  4. package/cordis.patch.yml +2 -2
  5. package/features/animation/host.js +119 -119
  6. package/features/animation/view.jsx +1662 -1662
  7. package/features/balance/host.js +494 -494
  8. package/features/balance/view.js +351 -351
  9. package/features/games/games/breakout.jsx +227 -227
  10. package/features/games/games/gomoku.jsx +244 -244
  11. package/features/games/games/racer.jsx +169 -169
  12. package/features/games/games/shared.jsx +118 -118
  13. package/features/games/games/snake.jsx +144 -144
  14. package/features/games/games/sokoban.jsx +180 -180
  15. package/features/games/games/tank.jsx +128 -128
  16. package/features/games/games/tetris.jsx +308 -308
  17. package/features/games/games/xiangqi.jsx +277 -277
  18. package/features/games/tank-core.js +152 -152
  19. package/features/games/view.jsx +639 -639
  20. package/features/games/xiangqi-core.js +299 -299
  21. package/features/heartbeat/view.js +35 -35
  22. package/features/mobile-relay/gateway.js +472 -472
  23. package/features/mobile-relay/host.js +622 -570
  24. package/features/mobile-relay/view.jsx +380 -300
  25. package/features/modelconfig/host.js +406 -406
  26. package/features/modelconfig/view.js +490 -490
  27. package/features/notify/host.js +374 -374
  28. package/features/notify/view.jsx +751 -751
  29. package/features/theme/view.js +61 -61
  30. package/features/tokenlog/host.js +882 -883
  31. package/features/tokenlog/view.jsx +1369 -932
  32. package/features/visionproxy/host.js +315 -315
  33. package/index.js +195 -195
  34. package/package.json +66 -64
  35. package/screenshots/dock-tokenlog-charts-2.png +0 -0
  36. package/screenshots/dock-tokenlog-charts-3.png +0 -0
  37. package/screenshots/dock-tokenlog-charts.png +0 -0
  38. package/src/client.jsx +677 -677
  39. package/src/host-core.js +207 -207
  40. package/src/shared.js +192 -192
  41. package/src/task-track.js +354 -359
package/cordis.patch.yml CHANGED
@@ -1,3 +1,3 @@
1
- - insert:
2
- - id: dsh-dock
1
+ - insert:
2
+ - id: dsh-dock
3
3
  name: dsh-dock
@@ -1,119 +1,119 @@
1
- // dsh-dock · 功能模块【任务动画】· 宿主半部
2
- //
3
- // 职责:动画配置持久化(动效开关 / 模式 / 桌面伙伴大小)+ 状态路由。
4
- // 会话级任务追踪在 src/task-track.js(与【任务通知】【运行状态】共用一份数据);
5
- // 通知在 features/notify/、运行状态在 features/runstate/,三个功能各自独立启停。
6
- //
7
- // RPC(webServer HTTP 路由,前缀 /dsh-dock/animation/):
8
- // POST /status —— 活跃任务 + 最近完成 + 动画配置(客户端据此渲染动效)
9
- // POST /config —— 增量更新动画配置字段并持久化到 settings(dsh-dock 命名空间 animation 段)
10
- //
11
- // 配置模型(schemastery schema 见 src/host-core.js DockConfig.animation):
12
- // animationEnabled / effectMode / robotScale
13
- import { DOCK_NS, ANIMATION_MODES, sendJson, readBody } from '../../src/host-core.js'
14
- import { acquireTaskTracker } from '../../src/task-track.js'
15
-
16
- // 默认配置(schema 默认值一致;settings.get 未挂载时的兜底)
17
- function defaultConfig() {
18
- return {
19
- animationEnabled: true,
20
- effectMode: 'flow',
21
- robotScale: 1.35,
22
- }
23
- }
24
-
25
- // 读 settings 里的 animation 配置(resolved 值已含 schema 默认),异常时回退默认
26
- function readConfig(ctx) {
27
- const cfg = defaultConfig()
28
- try {
29
- const settings = ctx.get('settings')
30
- const v = settings && typeof settings.get === 'function' ? settings.get(DOCK_NS) : null
31
- const a = v && typeof v === 'object' && v.animation && typeof v.animation === 'object' ? v.animation : null
32
- if (a) {
33
- for (const key of Object.keys(cfg)) {
34
- if (a[key] !== undefined) cfg[key] = a[key]
35
- }
36
- if (!ANIMATION_MODES.includes(cfg.effectMode)) cfg.effectMode = 'flow'
37
- }
38
- } catch { /* settings 未挂载,用默认 */ }
39
- return cfg
40
- }
41
-
42
- export const feature = {
43
- id: 'animation',
44
- name: '任务动画',
45
- description: '19 种任务运行动画(速度随任务活动联动,配置持久化;通知见「任务通知」,任务状态见「运行状态」)',
46
- defaultEnabled: false,
47
- setup(ctx) {
48
- const disposers = []
49
- const dispose = () => {
50
- while (disposers.length > 0) {
51
- const fn = disposers.pop()
52
- try { if (typeof fn === 'function') fn() } catch { /* 停用清理失败不阻断 */ }
53
- }
54
- }
55
-
56
- // 会话级任务追踪(与【任务通知】共享一份;两个功能都停用后自动退订会话事件)
57
- const lease = acquireTaskTracker(ctx)
58
- disposers.push(() => lease.release())
59
- const tracker = lease.tracker
60
-
61
- // ===== RPC 路由 =====
62
- disposers.push(ctx.inject(['webServer'], (wsCtx) => {
63
- wsCtx.effect(() => wsCtx.webServer.register({
64
- kind: 'prefix',
65
- path: '/dsh-dock/animation',
66
- async handler(req, res) {
67
- try {
68
- const url = new URL(req.url || '/', 'http://dsh.internal')
69
- const method = url.pathname.replace(/^\/dsh-dock\/animation\/?/, '').split('/')[0] || ''
70
- const payload = await readBody(req)
71
-
72
- if (method === 'status') {
73
- return sendJson(res, 200, {
74
- ok: true,
75
- data: Object.assign({}, tracker.snapshot(Date.now()), { config: readConfig(ctx) }),
76
- })
77
- }
78
-
79
- if (method === 'config') {
80
- // 增量合并:只接受已知字段,类型不符忽略;整体写回 animation 段
81
- const cfg = readConfig(ctx)
82
- const p = payload || {}
83
- if (typeof p.animationEnabled === 'boolean') cfg.animationEnabled = p.animationEnabled
84
- if (typeof p.effectMode === 'string' && ANIMATION_MODES.includes(p.effectMode)) cfg.effectMode = p.effectMode
85
- if (typeof p.robotScale === 'number' && Number.isFinite(p.robotScale)) {
86
- cfg.robotScale = Math.max(0.85, Math.min(2.2, Math.round(p.robotScale * 100) / 100))
87
- }
88
-
89
- const settings = ctx.get('settings')
90
- if (!settings || typeof settings.mutate !== 'function') {
91
- throw new Error('settings 服务不可用,配置无法持久化')
92
- }
93
- try {
94
- await settings.mutate(DOCK_NS, [{ op: 'set', path: ['animation'], value: cfg }])
95
- } catch (e) {
96
- const err = new Error('保存配置被拒绝:' + ((e && e.message) || String(e)))
97
- err.statusCode = 400
98
- throw err
99
- }
100
- console.log('[dsh-dock] animation config saved:', cfg.effectMode, 'anim=' + cfg.animationEnabled)
101
- return sendJson(res, 200, { ok: true, data: { config: cfg, savedAt: Date.now() } })
102
- }
103
-
104
- return sendJson(res, 404, { ok: false, error: { code: 'method-not-found', message: 'unknown method: ' + method } })
105
- } catch (e) {
106
- const status = e && e.statusCode ? e.statusCode : 500
107
- console.error('[dsh-dock] animation HTTP error:', status, e && e.message)
108
- return sendJson(res, status, {
109
- ok: false,
110
- error: { code: status >= 500 ? 'internal' : 'bad-request', message: (e && e.message) || String(e) },
111
- })
112
- }
113
- },
114
- }), 'dsh-dock animation: /dsh-dock/animation HTTP route')
115
- }))
116
-
117
- return dispose
118
- },
119
- }
1
+ // dsh-dock · 功能模块【任务动画】· 宿主半部
2
+ //
3
+ // 职责:动画配置持久化(动效开关 / 模式 / 桌面伙伴大小)+ 状态路由。
4
+ // 会话级任务追踪在 src/task-track.js(与【任务通知】【运行状态】共用一份数据);
5
+ // 通知在 features/notify/、运行状态在 features/runstate/,三个功能各自独立启停。
6
+ //
7
+ // RPC(webServer HTTP 路由,前缀 /dsh-dock/animation/):
8
+ // POST /status —— 活跃任务 + 最近完成 + 动画配置(客户端据此渲染动效)
9
+ // POST /config —— 增量更新动画配置字段并持久化到 settings(dsh-dock 命名空间 animation 段)
10
+ //
11
+ // 配置模型(schemastery schema 见 src/host-core.js DockConfig.animation):
12
+ // animationEnabled / effectMode / robotScale
13
+ import { DOCK_NS, ANIMATION_MODES, sendJson, readBody } from '../../src/host-core.js'
14
+ import { acquireTaskTracker } from '../../src/task-track.js'
15
+
16
+ // 默认配置(schema 默认值一致;settings.get 未挂载时的兜底)
17
+ function defaultConfig() {
18
+ return {
19
+ animationEnabled: true,
20
+ effectMode: 'flow',
21
+ robotScale: 1.35,
22
+ }
23
+ }
24
+
25
+ // 读 settings 里的 animation 配置(resolved 值已含 schema 默认),异常时回退默认
26
+ function readConfig(ctx) {
27
+ const cfg = defaultConfig()
28
+ try {
29
+ const settings = ctx.get('settings')
30
+ const v = settings && typeof settings.get === 'function' ? settings.get(DOCK_NS) : null
31
+ const a = v && typeof v === 'object' && v.animation && typeof v.animation === 'object' ? v.animation : null
32
+ if (a) {
33
+ for (const key of Object.keys(cfg)) {
34
+ if (a[key] !== undefined) cfg[key] = a[key]
35
+ }
36
+ if (!ANIMATION_MODES.includes(cfg.effectMode)) cfg.effectMode = 'flow'
37
+ }
38
+ } catch { /* settings 未挂载,用默认 */ }
39
+ return cfg
40
+ }
41
+
42
+ export const feature = {
43
+ id: 'animation',
44
+ name: '任务动画',
45
+ description: '19 种任务运行动画(速度随任务活动联动,配置持久化;通知见「任务通知」,任务状态见「运行状态」)',
46
+ defaultEnabled: false,
47
+ setup(ctx) {
48
+ const disposers = []
49
+ const dispose = () => {
50
+ while (disposers.length > 0) {
51
+ const fn = disposers.pop()
52
+ try { if (typeof fn === 'function') fn() } catch { /* 停用清理失败不阻断 */ }
53
+ }
54
+ }
55
+
56
+ // 会话级任务追踪(与【任务通知】共享一份;两个功能都停用后自动退订会话事件)
57
+ const lease = acquireTaskTracker(ctx)
58
+ disposers.push(() => lease.release())
59
+ const tracker = lease.tracker
60
+
61
+ // ===== RPC 路由 =====
62
+ disposers.push(ctx.inject(['webServer'], (wsCtx) => {
63
+ wsCtx.effect(() => wsCtx.webServer.register({
64
+ kind: 'prefix',
65
+ path: '/dsh-dock/animation',
66
+ async handler(req, res) {
67
+ try {
68
+ const url = new URL(req.url || '/', 'http://dsh.internal')
69
+ const method = url.pathname.replace(/^\/dsh-dock\/animation\/?/, '').split('/')[0] || ''
70
+ const payload = await readBody(req)
71
+
72
+ if (method === 'status') {
73
+ return sendJson(res, 200, {
74
+ ok: true,
75
+ data: Object.assign({}, tracker.snapshot(Date.now()), { config: readConfig(ctx) }),
76
+ })
77
+ }
78
+
79
+ if (method === 'config') {
80
+ // 增量合并:只接受已知字段,类型不符忽略;整体写回 animation 段
81
+ const cfg = readConfig(ctx)
82
+ const p = payload || {}
83
+ if (typeof p.animationEnabled === 'boolean') cfg.animationEnabled = p.animationEnabled
84
+ if (typeof p.effectMode === 'string' && ANIMATION_MODES.includes(p.effectMode)) cfg.effectMode = p.effectMode
85
+ if (typeof p.robotScale === 'number' && Number.isFinite(p.robotScale)) {
86
+ cfg.robotScale = Math.max(0.85, Math.min(2.2, Math.round(p.robotScale * 100) / 100))
87
+ }
88
+
89
+ const settings = ctx.get('settings')
90
+ if (!settings || typeof settings.mutate !== 'function') {
91
+ throw new Error('settings 服务不可用,配置无法持久化')
92
+ }
93
+ try {
94
+ await settings.mutate(DOCK_NS, [{ op: 'set', path: ['animation'], value: cfg }])
95
+ } catch (e) {
96
+ const err = new Error('保存配置被拒绝:' + ((e && e.message) || String(e)))
97
+ err.statusCode = 400
98
+ throw err
99
+ }
100
+ console.log('[dsh-dock] animation config saved:', cfg.effectMode, 'anim=' + cfg.animationEnabled)
101
+ return sendJson(res, 200, { ok: true, data: { config: cfg, savedAt: Date.now() } })
102
+ }
103
+
104
+ return sendJson(res, 404, { ok: false, error: { code: 'method-not-found', message: 'unknown method: ' + method } })
105
+ } catch (e) {
106
+ const status = e && e.statusCode ? e.statusCode : 500
107
+ console.error('[dsh-dock] animation HTTP error:', status, e && e.message)
108
+ return sendJson(res, status, {
109
+ ok: false,
110
+ error: { code: status >= 500 ? 'internal' : 'bad-request', message: (e && e.message) || String(e) },
111
+ })
112
+ }
113
+ },
114
+ }), 'dsh-dock animation: /dsh-dock/animation HTTP route')
115
+ }))
116
+
117
+ return dispose
118
+ },
119
+ }