dsh-bat-think 1.0.0 → 1.0.1
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.md +7 -79
- package/assets/accessories/bare/hair-tufts.png +0 -0
- package/assets/accessories/bare/red-flower.png +0 -0
- package/assets/eyes/closed.png +0 -0
- package/assets/eyes/half.png +0 -0
- package/assets/eyes/open.png +0 -0
- package/assets/idle-bare.png +0 -0
- package/assets/idle.png +0 -0
- package/assets/pet.json +44 -35
- package/assets/thinking-bare.png +0 -0
- package/assets/thinking.png +0 -0
- package/client.js +217 -31
- package/index.js +17 -5
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +5 -3
- package/README.zh.md +0 -52
- /package/assets/accessories/{grapple-rope.png → helmet/grapple-rope.png} +0 -0
- /package/assets/accessories/{super-shield.png → helmet/super-shield.png} +0 -0
package/README.md
CHANGED
|
@@ -1,83 +1,11 @@
|
|
|
1
|
-
# dsh-bat-think
|
|
2
1
|
|
|
3
|
-
A Batman desktop pet for the DeepSeek Harness Web GUI. It lives in the
|
|
4
|
-
frame-wide `shell.overlay` seat: it floats above the conversation without
|
|
5
|
-
covering controls, and only its own pixels take pointer events.
|
|
6
2
|
|
|
7
3
|

|
|
8
4
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
`正在归档……` / `我要夜巡了`). While the Agent runs, a click hides the bubble
|
|
17
|
-
and says `thinkingAck` (「稍等」); the bubble returns a few seconds later if
|
|
18
|
-
the run is still going.
|
|
19
|
-
- **API usage:** click the laptop to open a small card with the current model,
|
|
20
|
-
output / input / cache-read tokens, context occupancy, and a total across
|
|
21
|
-
loaded sessions. Click the laptop again or `×` to close it.
|
|
22
|
-
- **Stickers:** the dice button in the hover toolbar puts a random accessory
|
|
23
|
-
from `assets/accessories/` on the pet. Accessories share the artwork's
|
|
24
|
-
512×512 canvas, so they land exactly where they were drawn, and they breathe,
|
|
25
|
-
drag and scale with the pet. Clicking a sticker's pixels removes it.
|
|
26
|
-
- **Placement:** drag the pet anywhere (remembered); hover for `−` / `+` to
|
|
27
|
-
resize (96–320 px) and `×` to tuck it into a small round chip.
|
|
28
|
-
|
|
29
|
-
## Install
|
|
30
|
-
|
|
31
|
-
From the DSH CLI:
|
|
32
|
-
|
|
33
|
-
```bash
|
|
34
|
-
dsh plugin --profile <your-profile> add dsh-bat-think
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
Or open **Plugins → Add plugin** in the GUI and give it `dsh-bat-think`, then
|
|
38
|
-
refresh the window (Ctrl+R). The pet appears in the bottom-right corner.
|
|
39
|
-
|
|
40
|
-
Requires a DSH release whose Web GUI has the `shell.overlay` slot (the
|
|
41
|
-
`@deepseek-ai/dsh-client-ui-layout` package). No build step: the bundle ships
|
|
42
|
-
plain ES modules and PNGs.
|
|
43
|
-
|
|
44
|
-
## Customize without code
|
|
45
|
-
|
|
46
|
-
Everything the pet shows comes from `assets/`:
|
|
47
|
-
|
|
48
|
-
| File | When it shows |
|
|
49
|
-
| --- | --- |
|
|
50
|
-
| `assets/idle.png` | normal |
|
|
51
|
-
| `assets/thinking.png` | while an Agent is running |
|
|
52
|
-
| `assets/accessories/*.png` | picked by the dice |
|
|
53
|
-
|
|
54
|
-
- Both frames should be transparent PNGs on the same canvas, with the character
|
|
55
|
-
aligned, so switching does not jump.
|
|
56
|
-
- `assets/pet.json` holds the display name, default width (`size`), speech lines
|
|
57
|
-
(`sayings`, `thinkingAck`), the accessory list, and the `canvas` contract:
|
|
58
|
-
`{ "width": 512, "height": 512, "crop": [left, top, width, height] }` records
|
|
59
|
-
which part of the 512×512 canvas the frames crop, which is what lets
|
|
60
|
-
accessories land at their drawn position. If you replace the frames with an
|
|
61
|
-
uncropped 512×512 image, set `crop` to `[0, 0, 512, 512]`.
|
|
62
|
-
- Drop a new PNG into `assets/accessories/` and restart DSH: the folder is
|
|
63
|
-
scanned at runtime. Without a restart, add the filename to `accessories` in
|
|
64
|
-
`pet.json`.
|
|
65
|
-
|
|
66
|
-
## Layout
|
|
67
|
-
|
|
68
|
-
- `index.js` — Host half: serves `assets/` at `/dsh-bat-think/*`, plus a live
|
|
69
|
-
JSON listing of `assets/accessories/`.
|
|
70
|
-
- `client.js` — Client half: the `shell.overlay` entry, the pet component, the
|
|
71
|
-
thought bubble, the usage card and the sticker layer.
|
|
72
|
-
- `cordis.patch.yml` — inserts the `dsh-bat-think` plugin row.
|
|
73
|
-
|
|
74
|
-
## Remove
|
|
75
|
-
|
|
76
|
-
Disable **Batman desktop pet** in Settings → Plugins, or remove the bundle. The
|
|
77
|
-
pet keeps only local UI state: `dsh-bat-think:position`, `:size`, `:collapsed`,
|
|
78
|
-
`:accessory` in `localStorage` and `:greeted` in `sessionStorage`.
|
|
79
|
-
|
|
80
|
-
## License
|
|
81
|
-
|
|
82
|
-
MIT for the code. The character art is fan art and is **not** covered by the
|
|
83
|
-
MIT license — see [NOTICE.md](NOTICE.md).
|
|
5
|
+
点击人物有随机对话
|
|
6
|
+
点击电脑有用量信息
|
|
7
|
+
点击骰子可以产生装扮,点击装扮可以去掉
|
|
8
|
+
可以放大缩小
|
|
9
|
+
可以拖动
|
|
10
|
+
快速连点三下可以切换戴面罩 / 摘面罩(摘下面罩会眨眼)
|
|
11
|
+
不戴面罩有自己的贴纸
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/assets/idle.png
CHANGED
|
Binary file
|
package/assets/pet.json
CHANGED
|
@@ -1,35 +1,44 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "蝙蝠侠",
|
|
3
|
-
"size":
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
]
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "蝙蝠侠",
|
|
3
|
+
"size": 168,
|
|
4
|
+
"canvas": {
|
|
5
|
+
"width": 512,
|
|
6
|
+
"height": 512,
|
|
7
|
+
"crop": [92, 76, 316, 359]
|
|
8
|
+
},
|
|
9
|
+
"hotspot": [148, 318, 214, 100],
|
|
10
|
+
"variants": {
|
|
11
|
+
"helmet": {
|
|
12
|
+
"idle": ["idle.png"],
|
|
13
|
+
"thinking": ["thinking.png"]
|
|
14
|
+
},
|
|
15
|
+
"bare": {
|
|
16
|
+
"idle": ["idle-bare.png"],
|
|
17
|
+
"thinking": ["thinking-bare.png"],
|
|
18
|
+
"eyes": {
|
|
19
|
+
"open": "eyes/open.png",
|
|
20
|
+
"half": "eyes/half.png",
|
|
21
|
+
"closed": "eyes/closed.png"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"fps": {
|
|
26
|
+
"idle": 3
|
|
27
|
+
},
|
|
28
|
+
"sayings": [
|
|
29
|
+
"阿尔弗雷德!",
|
|
30
|
+
"正在归档……",
|
|
31
|
+
"我要夜巡了"
|
|
32
|
+
],
|
|
33
|
+
"thinkingAck": "稍等",
|
|
34
|
+
"accessories": {
|
|
35
|
+
"helmet": [
|
|
36
|
+
"helmet/super-shield.png",
|
|
37
|
+
"helmet/grapple-rope.png"
|
|
38
|
+
],
|
|
39
|
+
"bare": [
|
|
40
|
+
"bare/red-flower.png",
|
|
41
|
+
"bare/hair-tufts.png"
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
}
|
|
Binary file
|
package/assets/thinking.png
CHANGED
|
Binary file
|
package/client.js
CHANGED
|
@@ -22,9 +22,12 @@ window.__ModuleLoader__.load({
|
|
|
22
22
|
const KEY_COLLAPSED = 'dsh-bat-think:collapsed'
|
|
23
23
|
const KEY_GREETED = 'dsh-bat-think:greeted'
|
|
24
24
|
const KEY_ACCESSORY = 'dsh-bat-think:accessory'
|
|
25
|
+
const KEY_VARIANT = 'dsh-bat-think:variant'
|
|
26
|
+
const BUILD = '1.0.1'
|
|
27
|
+
const KEY_CANVAS_WIDTH = 'dsh-bat-think:canvas-width'
|
|
25
28
|
const MIN_SIZE = 96
|
|
26
29
|
const MAX_SIZE = 320
|
|
27
|
-
const DEFAULT_SIZE =
|
|
30
|
+
const DEFAULT_SIZE = 168
|
|
28
31
|
const DEFAULT_RATIO = 1.42
|
|
29
32
|
const EDGE_RIGHT = 24
|
|
30
33
|
const EDGE_BOTTOM = 16
|
|
@@ -35,12 +38,20 @@ window.__ModuleLoader__.load({
|
|
|
35
38
|
const FALLBACK = {
|
|
36
39
|
name: '蝙蝠侠',
|
|
37
40
|
size: DEFAULT_SIZE,
|
|
38
|
-
|
|
41
|
+
canvas: { width: 512, height: 512, crop: [92, 76, 316, 359] },
|
|
42
|
+
hotspot: [148, 318, 214, 100],
|
|
43
|
+
variants: {
|
|
44
|
+
helmet: { idle: ['idle.png'], thinking: ['thinking.png'] },
|
|
45
|
+
bare: {
|
|
46
|
+
idle: ['idle-bare.png'],
|
|
47
|
+
thinking: ['thinking-bare.png'],
|
|
48
|
+
eyes: { open: 'eyes/open.png', half: 'eyes/half.png', closed: 'eyes/closed.png' },
|
|
49
|
+
},
|
|
50
|
+
},
|
|
39
51
|
fps: { idle: 3 },
|
|
40
52
|
sayings: ['阿尔弗雷德!', '正在归档……', '我要夜巡了'],
|
|
41
53
|
thinkingAck: '稍等',
|
|
42
|
-
accessories: [],
|
|
43
|
-
canvas: { width: 512, height: 512, crop: [130, 84, 247, 353] },
|
|
54
|
+
accessories: { helmet: [], bare: [] },
|
|
44
55
|
}
|
|
45
56
|
|
|
46
57
|
// The pet watches the session list so the thought bubble follows the Agent.
|
|
@@ -116,6 +127,11 @@ window.__ModuleLoader__.load({
|
|
|
116
127
|
-webkit-user-drag: none;
|
|
117
128
|
}
|
|
118
129
|
.dsh-bat-think-img:active { cursor: grabbing; }
|
|
130
|
+
.dsh-bat-think-eyes {
|
|
131
|
+
position: absolute;
|
|
132
|
+
pointer-events: none;
|
|
133
|
+
-webkit-user-drag: none;
|
|
134
|
+
}
|
|
119
135
|
@keyframes dsh-bat-think-breathe {
|
|
120
136
|
0%, 100% { transform: translateY(0) scale(1); }
|
|
121
137
|
50% { transform: translateY(-3px) scale(1.02); }
|
|
@@ -404,6 +420,10 @@ window.__ModuleLoader__.load({
|
|
|
404
420
|
}
|
|
405
421
|
}
|
|
406
422
|
|
|
423
|
+
function assetUrl(file) {
|
|
424
|
+
return `${ROUTE}/${String(file).split('/').map(encodeURIComponent).join('/')}`
|
|
425
|
+
}
|
|
426
|
+
|
|
407
427
|
function accessoryUrl(file) {
|
|
408
428
|
return `${ROUTE}/accessories/${String(file).split('/').map(encodeURIComponent).join('/')}`
|
|
409
429
|
}
|
|
@@ -471,14 +491,18 @@ window.__ModuleLoader__.load({
|
|
|
471
491
|
}
|
|
472
492
|
|
|
473
493
|
function mergeManifest(base, extra) {
|
|
474
|
-
const
|
|
475
|
-
for (const [name,
|
|
476
|
-
|
|
494
|
+
const variants = { ...(base.variants || {}) }
|
|
495
|
+
for (const [name, definition] of Object.entries(extra.variants || {})) {
|
|
496
|
+
variants[name] = { ...(variants[name] || {}), ...definition }
|
|
477
497
|
}
|
|
498
|
+
const accessories = extra.accessories && !Array.isArray(extra.accessories)
|
|
499
|
+
? { ...(base.accessories || {}), ...extra.accessories }
|
|
500
|
+
: (base.accessories || { helmet: [], bare: [] })
|
|
478
501
|
return {
|
|
479
502
|
...base,
|
|
480
503
|
...extra,
|
|
481
|
-
|
|
504
|
+
variants,
|
|
505
|
+
accessories,
|
|
482
506
|
fps: { ...(base.fps || {}), ...(extra.fps || {}) },
|
|
483
507
|
sayings: Array.isArray(extra.sayings) && extra.sayings.length > 0
|
|
484
508
|
? extra.sayings.map(String)
|
|
@@ -486,12 +510,22 @@ window.__ModuleLoader__.load({
|
|
|
486
510
|
}
|
|
487
511
|
}
|
|
488
512
|
|
|
513
|
+
function readVariant() {
|
|
514
|
+
try {
|
|
515
|
+
return localStorage.getItem(KEY_VARIANT) === 'bare' ? 'bare' : 'helmet'
|
|
516
|
+
} catch {
|
|
517
|
+
return 'helmet'
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
489
521
|
function Pet() {
|
|
490
522
|
// A single line in the browser console makes a missing registration obvious.
|
|
491
523
|
useEffect(() => { console.info('[dsh-bat-think] mounted at shell.overlay') }, [])
|
|
492
524
|
|
|
493
525
|
const [manifest, setManifest] = useState(FALLBACK)
|
|
494
526
|
const [bubble, setBubble] = useState('')
|
|
527
|
+
const [variant, setVariant] = useState(readVariant)
|
|
528
|
+
const [eyeFrame, setEyeFrame] = useState('open')
|
|
495
529
|
const [position, setPosition] = useState(null)
|
|
496
530
|
const [size, setSize] = useState(() => clampSize(readNumber(KEY_SIZE, DEFAULT_SIZE)))
|
|
497
531
|
const [ratio, setRatio] = useState(DEFAULT_RATIO)
|
|
@@ -499,6 +533,17 @@ window.__ModuleLoader__.load({
|
|
|
499
533
|
try { return localStorage.getItem(KEY_COLLAPSED) === '1' } catch { return false }
|
|
500
534
|
})
|
|
501
535
|
const [missing, setMissing] = useState(false)
|
|
536
|
+
const [loadAttempt, setLoadAttempt] = useState(0)
|
|
537
|
+
const [failedFile, setFailedFile] = useState('')
|
|
538
|
+
const [failedInfo, setFailedInfo] = useState('')
|
|
539
|
+
const [blobs, setBlobs] = useState({})
|
|
540
|
+
const blobsRef = useRef(blobs)
|
|
541
|
+
blobsRef.current = blobs
|
|
542
|
+
useEffect(() => () => {
|
|
543
|
+
for (const url of Object.values(blobsRef.current)) {
|
|
544
|
+
try { URL.revokeObjectURL(url) } catch {}
|
|
545
|
+
}
|
|
546
|
+
}, [])
|
|
502
547
|
const [frame, setFrame] = useState(0)
|
|
503
548
|
const [bump, setBump] = useState(false)
|
|
504
549
|
const [thinkPaused, setThinkPaused] = useState(false)
|
|
@@ -596,10 +641,13 @@ window.__ModuleLoader__.load({
|
|
|
596
641
|
return () => { try { dispose() } catch {} }
|
|
597
642
|
}, [mainSessionId, modelService])
|
|
598
643
|
|
|
599
|
-
const
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
644
|
+
const variantAccessories = useMemo(() => {
|
|
645
|
+
const prefix = `${variant}/`
|
|
646
|
+
const fromIndex = accessoryList.filter((file) => String(file).startsWith(prefix))
|
|
647
|
+
if (fromIndex.length > 0) return fromIndex
|
|
648
|
+
const map = manifest.accessories && !Array.isArray(manifest.accessories) ? manifest.accessories : {}
|
|
649
|
+
return Array.isArray(map[variant]) ? map[variant].map(String) : []
|
|
650
|
+
}, [accessoryList, manifest, variant])
|
|
603
651
|
|
|
604
652
|
// Accessories are discovered from the folder; `pet.json` lists the same
|
|
605
653
|
// names as a fallback for a Host that has not reloaded yet.
|
|
@@ -616,13 +664,13 @@ window.__ModuleLoader__.load({
|
|
|
616
664
|
}, [])
|
|
617
665
|
|
|
618
666
|
useEffect(() => {
|
|
619
|
-
if (
|
|
667
|
+
if (variantAccessories.length === 0) return
|
|
620
668
|
setAccessory((current) => {
|
|
621
|
-
if (!current ||
|
|
669
|
+
if (!current || variantAccessories.includes(current.file)) return current
|
|
622
670
|
writeAccessory(null)
|
|
623
671
|
return null
|
|
624
672
|
})
|
|
625
|
-
}, [
|
|
673
|
+
}, [variantAccessories])
|
|
626
674
|
|
|
627
675
|
// Bounding box and alpha mask of the current accessory, for placement and
|
|
628
676
|
// for "click the pixels, not the box" removal.
|
|
@@ -689,10 +737,23 @@ window.__ModuleLoader__.load({
|
|
|
689
737
|
.then((response) => (response.ok ? response.json() : null))
|
|
690
738
|
.then((json) => {
|
|
691
739
|
if (cancelled || !json) return
|
|
692
|
-
|
|
740
|
+
const merged = mergeManifest(FALLBACK, json)
|
|
741
|
+
setManifest(merged)
|
|
742
|
+
const cropWidth = merged.canvas && Array.isArray(merged.canvas.crop) ? Number(merged.canvas.crop[2]) : 0
|
|
693
743
|
let stored = 0
|
|
694
744
|
try { stored = Number(localStorage.getItem(KEY_SIZE)) } catch {}
|
|
695
|
-
if (!Number.isFinite(stored) || stored <= 0)
|
|
745
|
+
if (!Number.isFinite(stored) || stored <= 0) {
|
|
746
|
+
setSize(clampSize(json.size))
|
|
747
|
+
} else if (cropWidth > 0) {
|
|
748
|
+
// The shared canvas got wider when the bare variant arrived: scale
|
|
749
|
+
// the saved size once so the pet keeps its on-screen size.
|
|
750
|
+
let previousWidth = readNumber(KEY_CANVAS_WIDTH, 0)
|
|
751
|
+
if (!previousWidth && stored > 0) previousWidth = 247
|
|
752
|
+
if (previousWidth > 0 && Math.abs(previousWidth - cropWidth) > 1) {
|
|
753
|
+
setSize((current) => clampSize(Math.round(current * (cropWidth / previousWidth))))
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
if (cropWidth > 0) writeSetting(KEY_CANVAS_WIDTH, String(cropWidth))
|
|
696
757
|
})
|
|
697
758
|
.catch((error) => console.warn('[dsh-bat-think] pet.json could not be loaded', error))
|
|
698
759
|
return () => { cancelled = true }
|
|
@@ -725,14 +786,19 @@ window.__ModuleLoader__.load({
|
|
|
725
786
|
}, [size, ratio])
|
|
726
787
|
|
|
727
788
|
const frames = useMemo(() => {
|
|
728
|
-
const
|
|
729
|
-
const list = thinking && Array.isArray(
|
|
789
|
+
const definition = (manifest.variants && manifest.variants[variant]) || {}
|
|
790
|
+
const list = thinking && Array.isArray(definition.thinking) && definition.thinking.length > 0
|
|
791
|
+
? definition.thinking
|
|
792
|
+
: definition.idle
|
|
730
793
|
return Array.isArray(list) && list.length > 0 ? list : ['idle.png']
|
|
731
|
-
}, [manifest, thinking])
|
|
794
|
+
}, [manifest, thinking, variant])
|
|
732
795
|
|
|
733
796
|
// Warm both frames so switching to the working picture does not flicker.
|
|
734
797
|
useEffect(() => {
|
|
735
|
-
const files = []
|
|
798
|
+
const files = []
|
|
799
|
+
for (const definition of Object.values(manifest.variants || {})) {
|
|
800
|
+
files.push(...(definition.idle || []), ...(definition.thinking || []), ...Object.values(definition.eyes || {}))
|
|
801
|
+
}
|
|
736
802
|
for (const file of files) {
|
|
737
803
|
const image = new Image()
|
|
738
804
|
image.src = `${ROUTE}/${String(file).split('/').map(encodeURIComponent).join('/')}`
|
|
@@ -750,6 +816,24 @@ window.__ModuleLoader__.load({
|
|
|
750
816
|
return () => clearInterval(timer)
|
|
751
817
|
}, [frames, manifest, thinking])
|
|
752
818
|
|
|
819
|
+
// Blink only in the bare-face variant: the eye layer steps open → half →
|
|
820
|
+
// closed → half → open on a loose timer.
|
|
821
|
+
useEffect(() => {
|
|
822
|
+
if (variant !== 'bare') { setEyeFrame('open'); return undefined }
|
|
823
|
+
const sequence = ['open', 'half', 'closed', 'half', 'open']
|
|
824
|
+
let step = 0
|
|
825
|
+
let timer = 0
|
|
826
|
+
setEyeFrame('open')
|
|
827
|
+
const tick = () => {
|
|
828
|
+
step = (step + 1) % sequence.length
|
|
829
|
+
if (alive.current) setEyeFrame(sequence[step])
|
|
830
|
+
const wait = step === 0 ? 2800 + Math.random() * 3800 : 95
|
|
831
|
+
timer = window.setTimeout(tick, wait)
|
|
832
|
+
}
|
|
833
|
+
timer = window.setTimeout(tick, 2800 + Math.random() * 3800)
|
|
834
|
+
return () => window.clearTimeout(timer)
|
|
835
|
+
}, [variant])
|
|
836
|
+
|
|
753
837
|
const say = (text) => {
|
|
754
838
|
if (!text) return
|
|
755
839
|
setBubble(text)
|
|
@@ -817,8 +901,46 @@ window.__ModuleLoader__.load({
|
|
|
817
901
|
say(lines[Math.floor(Math.random() * lines.length)])
|
|
818
902
|
}
|
|
819
903
|
|
|
904
|
+
useEffect(() => {
|
|
905
|
+
setMissing(false)
|
|
906
|
+
setLoadAttempt(0)
|
|
907
|
+
}, [variant])
|
|
908
|
+
|
|
909
|
+
const toggleVariant = () => {
|
|
910
|
+
const next = variant === 'bare' ? 'helmet' : 'bare'
|
|
911
|
+
setVariant(next)
|
|
912
|
+
try { localStorage.setItem(KEY_VARIANT, next) } catch {}
|
|
913
|
+
setAccessory(null)
|
|
914
|
+
writeAccessory(null)
|
|
915
|
+
setBump(true)
|
|
916
|
+
window.clearTimeout(bumpTimer.current)
|
|
917
|
+
bumpTimer.current = window.setTimeout(() => {
|
|
918
|
+
if (alive.current) setBump(false)
|
|
919
|
+
}, 1300)
|
|
920
|
+
say(next === 'bare' ? '摘下面罩' : '戴上面罩')
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
// Three quick clicks swap the helmet, so a single click waits briefly.
|
|
924
|
+
const clickRef = useRef({ count: 0, last: 0, timer: 0 })
|
|
925
|
+
const onPetClick = () => {
|
|
926
|
+
const now = Date.now()
|
|
927
|
+
const state = clickRef.current
|
|
928
|
+
if (now - state.last > 700) state.count = 0
|
|
929
|
+
state.last = now
|
|
930
|
+
state.count += 1
|
|
931
|
+
window.clearTimeout(state.timer)
|
|
932
|
+
if (state.count >= 3) {
|
|
933
|
+
state.count = 0
|
|
934
|
+
toggleVariant()
|
|
935
|
+
return
|
|
936
|
+
}
|
|
937
|
+
state.timer = window.setTimeout(() => {
|
|
938
|
+
if (alive.current) react()
|
|
939
|
+
}, 300)
|
|
940
|
+
}
|
|
941
|
+
|
|
820
942
|
const rollAccessory = () => {
|
|
821
|
-
const list =
|
|
943
|
+
const list = variantAccessories
|
|
822
944
|
if (list.length === 0) {
|
|
823
945
|
say('还没有配件,把 PNG 放进 assets/accessories/ 就行')
|
|
824
946
|
return
|
|
@@ -885,7 +1007,7 @@ window.__ModuleLoader__.load({
|
|
|
885
1007
|
return current
|
|
886
1008
|
})
|
|
887
1009
|
} else {
|
|
888
|
-
|
|
1010
|
+
onPetClick()
|
|
889
1011
|
}
|
|
890
1012
|
}
|
|
891
1013
|
|
|
@@ -907,7 +1029,8 @@ window.__ModuleLoader__.load({
|
|
|
907
1029
|
}
|
|
908
1030
|
|
|
909
1031
|
const current = frames[Math.min(frame, frames.length - 1)] || 'idle.png'
|
|
910
|
-
const
|
|
1032
|
+
const directSrc = `${assetUrl(current)}?v=${BUILD}${loadAttempt > 0 ? `&retry=${loadAttempt}` : ''}`
|
|
1033
|
+
const src = blobs[current] || directSrc
|
|
911
1034
|
const showThink = thinking && !thinkPaused && !bubble && !usageOpen
|
|
912
1035
|
const centreX = position.x + size / 2
|
|
913
1036
|
const viewportWidth = window.innerWidth || 1024
|
|
@@ -919,12 +1042,42 @@ window.__ModuleLoader__.load({
|
|
|
919
1042
|
const canvasSpec = manifest.canvas && Array.isArray(manifest.canvas.crop) && manifest.canvas.crop.length === 4
|
|
920
1043
|
? manifest.canvas
|
|
921
1044
|
: null
|
|
1045
|
+
const crop = canvasSpec ? canvasSpec.crop.map(Number) : [0, 0, 247, 353]
|
|
1046
|
+
const unit = size / (crop[2] || 1)
|
|
1047
|
+
const canvasWidth = canvasSpec ? Number(canvasSpec.width) || 512 : 512
|
|
1048
|
+
const canvasHeight = canvasSpec ? Number(canvasSpec.height) || 512 : 512
|
|
1049
|
+
|
|
1050
|
+
const eyes = variant === 'bare' && manifest.variants && manifest.variants.bare
|
|
1051
|
+
? manifest.variants.bare.eyes
|
|
1052
|
+
: null
|
|
1053
|
+
const eyeFile = eyes ? (eyes[eyeFrame] || eyes.open || '') : ''
|
|
1054
|
+
const eyesLayer = !missing && eyeFile
|
|
1055
|
+
? h('img', {
|
|
1056
|
+
className: 'dsh-bat-think-eyes',
|
|
1057
|
+
src: assetUrl(eyeFile),
|
|
1058
|
+
alt: '',
|
|
1059
|
+
draggable: false,
|
|
1060
|
+
style: {
|
|
1061
|
+
left: `${-crop[0] * unit}px`,
|
|
1062
|
+
top: `${-crop[1] * unit}px`,
|
|
1063
|
+
width: `${canvasWidth * unit}px`,
|
|
1064
|
+
height: `${canvasHeight * unit}px`,
|
|
1065
|
+
},
|
|
1066
|
+
})
|
|
1067
|
+
: null
|
|
1068
|
+
|
|
1069
|
+
const hotspotPixels = Array.isArray(manifest.hotspot) && manifest.hotspot.length === 4 ? manifest.hotspot.map(Number) : null
|
|
1070
|
+
const hotspotStyle = hotspotPixels
|
|
1071
|
+
? {
|
|
1072
|
+
left: `${(hotspotPixels[0] - crop[0]) * unit}px`,
|
|
1073
|
+
top: `${(hotspotPixels[1] - crop[1]) * unit}px`,
|
|
1074
|
+
width: `${hotspotPixels[2] * unit}px`,
|
|
1075
|
+
height: `${hotspotPixels[3] * unit}px`,
|
|
1076
|
+
}
|
|
1077
|
+
: { left: '8%', top: '69%', width: '52%', height: '30%' }
|
|
1078
|
+
|
|
922
1079
|
const accessoryLayer = accessory && accMeta && canvasSpec
|
|
923
1080
|
? (() => {
|
|
924
|
-
const crop = canvasSpec.crop.map(Number)
|
|
925
|
-
const unit = size / (crop[2] || 1)
|
|
926
|
-
const canvasWidth = Number(canvasSpec.width) || 512
|
|
927
|
-
const canvasHeight = Number(canvasSpec.height) || 512
|
|
928
1081
|
return h('div', {
|
|
929
1082
|
className: 'dsh-bat-think-accessory',
|
|
930
1083
|
style: {
|
|
@@ -995,7 +1148,9 @@ window.__ModuleLoader__.load({
|
|
|
995
1148
|
: null,
|
|
996
1149
|
bubble && !usageOpen ? h('div', { className: `dsh-bat-think-bubble${bubbleEdge}`, role: 'status' }, bubble) : null,
|
|
997
1150
|
missing
|
|
998
|
-
? h('div', { className: `dsh-bat-think-bubble${bubbleEdge}` },
|
|
1151
|
+
? h('div', { className: `dsh-bat-think-bubble${bubbleEdge}` },
|
|
1152
|
+
h('div', null, `立绘没找到:${failedFile || current}(${manifest.variants && manifest.variants[variant] ? variant : '?'})`),
|
|
1153
|
+
failedInfo ? h('div', { style: { fontSize: '10px', opacity: 0.75, wordBreak: 'break-all', marginTop: '4px' } }, failedInfo) : null)
|
|
999
1154
|
: null,
|
|
1000
1155
|
h('div', { className: `dsh-bat-think-body${bump ? ' is-bump' : ''}` },
|
|
1001
1156
|
missing
|
|
@@ -1014,14 +1169,45 @@ window.__ModuleLoader__.load({
|
|
|
1014
1169
|
setRatio((value) => (Math.abs(value - next) > 0.01 ? next : value))
|
|
1015
1170
|
}
|
|
1016
1171
|
},
|
|
1017
|
-
onError: () =>
|
|
1172
|
+
onError: () => {
|
|
1173
|
+
// A file swapped on disk can 404 for a moment; try twice, then
|
|
1174
|
+
// try the same bytes through fetch() as a blob URL, and only
|
|
1175
|
+
// then tell the user the artwork is missing.
|
|
1176
|
+
if (loadAttempt < 2) {
|
|
1177
|
+
window.setTimeout(() => {
|
|
1178
|
+
if (alive.current) setLoadAttempt((attempt) => attempt + 1)
|
|
1179
|
+
}, 800)
|
|
1180
|
+
return
|
|
1181
|
+
}
|
|
1182
|
+
if (!blobs[current]) {
|
|
1183
|
+
fetch(assetUrl(current), { cache: 'no-store' })
|
|
1184
|
+
.then((response) => {
|
|
1185
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`)
|
|
1186
|
+
return response.blob()
|
|
1187
|
+
})
|
|
1188
|
+
.then((blob) => {
|
|
1189
|
+
const url = URL.createObjectURL(blob)
|
|
1190
|
+
setBlobs((map) => ({ ...map, [current]: url }))
|
|
1191
|
+
})
|
|
1192
|
+
.catch((error) => {
|
|
1193
|
+
setFailedFile(current)
|
|
1194
|
+
setFailedInfo(`${window.location.origin}${directSrc} · ${error && error.message ? error.message : 'fetch failed'}`)
|
|
1195
|
+
setMissing(true)
|
|
1196
|
+
})
|
|
1197
|
+
return
|
|
1198
|
+
}
|
|
1199
|
+
setFailedFile(current)
|
|
1200
|
+
setFailedInfo(`${window.location.origin}${directSrc}`)
|
|
1201
|
+
setMissing(true)
|
|
1202
|
+
},
|
|
1018
1203
|
}),
|
|
1204
|
+
eyesLayer,
|
|
1019
1205
|
missing
|
|
1020
1206
|
? null
|
|
1021
1207
|
: h('button', {
|
|
1022
1208
|
type: 'button',
|
|
1023
1209
|
className: 'dsh-bat-think-laptop',
|
|
1024
|
-
style:
|
|
1210
|
+
style: hotspotStyle,
|
|
1025
1211
|
title: 'API 用量',
|
|
1026
1212
|
'aria-label': '查看 API 用量',
|
|
1027
1213
|
onPointerDown: stopTool,
|
package/index.js
CHANGED
|
@@ -50,11 +50,23 @@ async function serveAsset(req, res) {
|
|
|
50
50
|
if (suffix === 'accessories/index.json') {
|
|
51
51
|
let files = []
|
|
52
52
|
try {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
// One level deep: accessories/helmet/*.png and accessories/bare/*.png.
|
|
54
|
+
// The folder name is the variant the sticker belongs to.
|
|
55
|
+
const root = resolve(ASSET_ROOT, 'accessories')
|
|
56
|
+
const image = /\.(png|webp|gif|svg)$/i
|
|
57
|
+
const entries = await readdir(root, { withFileTypes: true })
|
|
58
|
+
for (const entry of entries) {
|
|
59
|
+
if (entry.isFile() && image.test(entry.name)) {
|
|
60
|
+
files.push(entry.name)
|
|
61
|
+
continue
|
|
62
|
+
}
|
|
63
|
+
if (!entry.isDirectory()) continue
|
|
64
|
+
const nested = await readdir(resolve(root, entry.name), { withFileTypes: true })
|
|
65
|
+
for (const child of nested) {
|
|
66
|
+
if (child.isFile() && image.test(child.name)) files.push(`${entry.name}/${child.name}`)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
files.sort((left, right) => left.localeCompare(right))
|
|
58
70
|
} catch {
|
|
59
71
|
files = []
|
|
60
72
|
}
|
package/locale/en.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "Batman desktop pet",
|
|
4
|
-
"description": "Shows a draggable Batman in the bottom-right corner of the DSH window: it works at its laptop
|
|
4
|
+
"description": "Shows a draggable Batman in the bottom-right corner of the DSH window: it works at its laptop, switches to a mouse-in-hand frame with a thought bubble while an Agent runs, and blinks naturally in the bare-face variant (triple-click to take the helmet off or put it back). Clicking it while idle says one of three lines; clicking the laptop opens an API usage card; the dice puts a random sticker on the current variant — each variant has its own stickers, placed by the artwork's canvas coordinates and following its breathing, drag and scale."
|
|
5
5
|
}
|
|
6
6
|
}
|
package/locale/zh.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "蝙蝠侠桌宠",
|
|
4
|
-
"description": "在 DSH
|
|
4
|
+
"description": "在 DSH 窗口右下角放一只可拖动的蝙蝠侠:平时敲电脑,Agent 在跑的时候换成拿鼠标的工作图并冒出三点跳动的思考气泡。快速连点三下可以切换「戴面罩 / 摘面罩」——摘下面罩后会自然眨眼(三帧)。空闲时点击随机说「阿尔弗雷德!」「正在归档……」「我要夜巡了」;点脚边的电脑弹出 API 用量面板;悬停工具栏的骰子会随机戴一个贴纸,戴面罩和不戴面罩各有自己的贴纸,按画布原坐标贴合,会跟着呼吸、拖动、缩放,点图案即可摘掉。"
|
|
5
5
|
}
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-bat-think",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Batman desktop pet for DeepSeek Harness: it works at a laptop, switches to a mouse-in-hand pose with a thought bubble while an Agent runs, rolls a dice for stickers, and shows an API usage card when you click the laptop.",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Batman desktop pet for DeepSeek Harness: it works at a laptop, switches to a mouse-in-hand pose with a thought bubble while an Agent runs, blinks in the bare-face variant (triple-click to swap the helmet), rolls a dice for stickers, and shows an API usage card when you click the laptop.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"keywords": [
|
|
@@ -28,12 +28,14 @@
|
|
|
28
28
|
"cordis.patch.yml",
|
|
29
29
|
"icon.svg",
|
|
30
30
|
"assets/idle.png",
|
|
31
|
+
"assets/idle-bare.png",
|
|
31
32
|
"assets/thinking.png",
|
|
33
|
+
"assets/thinking-bare.png",
|
|
32
34
|
"assets/pet.json",
|
|
35
|
+
"assets/eyes",
|
|
33
36
|
"assets/accessories",
|
|
34
37
|
"locale/*.json",
|
|
35
38
|
"README.md",
|
|
36
|
-
"README.zh.md",
|
|
37
39
|
"LICENSE",
|
|
38
40
|
"NOTICE.md"
|
|
39
41
|
],
|
package/README.zh.md
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
# dsh-bat-think
|
|
2
|
-
|
|
3
|
-
一只住在 DeepSeek Harness Web GUI 里的蝙蝠侠桌宠。它挂在整窗的 `shell.overlay` 层上,浮在对话区之上,只有自己身体范围会接收鼠标。
|
|
4
|
-
|
|
5
|
-

|
|
6
|
-
|
|
7
|
-
## 会做什么
|
|
8
|
-
|
|
9
|
-
- **日常**:敲电脑(`idle.png`),轻轻呼吸;
|
|
10
|
-
- **思考**:Agent 在跑(回复、调工具)时换成拿鼠标那张(`thinking.png`),头顶冒三点跳动的思考气泡,跑完自动变回;
|
|
11
|
-
- **点击**:空闲时随机说一句 `sayings`(阿尔弗雷德!/ 正在归档…… / 我要夜巡了);思考时点击先收起气泡、改说「稍等」,几秒后还在跑就把气泡换回来;
|
|
12
|
-
- **API 用量**:点它脚边的电脑弹出小面板——当前模型、输出 / 输入 / 缓存读取 token、上下文占用,以及已加载会话的合计;再点电脑或点 `×` 关闭;
|
|
13
|
-
- **配件**:悬停工具栏里的骰子会从 `assets/accessories/` 随机戴一个贴纸。配件和立绘共用 512×512 画布,所以**按原坐标贴合**,并跟着立绘一起呼吸、拖动、缩放;点贴纸图案本身摘掉;
|
|
14
|
-
- **摆放**:拖动换位置(记住);悬停 `−` / `+` 调大小(96–320 px),`×` 收成小圆头像。
|
|
15
|
-
|
|
16
|
-
## 安装
|
|
17
|
-
|
|
18
|
-
```bash
|
|
19
|
-
dsh plugin --profile <你的 profile> add dsh-bat-think
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
或在图形界面里 **插件 → 添加插件**,填 `dsh-bat-think`,然后刷新窗口(Ctrl+R)。宠物会出现在右下角。
|
|
23
|
-
|
|
24
|
-
要求宿主的 Web GUI 提供 `shell.overlay` 插槽(即装有 `@deepseek-ai/dsh-client-ui-layout`)。无需构建:包里就是普通 ES 模块和 PNG。
|
|
25
|
-
|
|
26
|
-
## 不改代码的定制
|
|
27
|
-
|
|
28
|
-
所有画面都来自 `assets/`:
|
|
29
|
-
|
|
30
|
-
| 文件 | 什么时候显示 |
|
|
31
|
-
| --- | --- |
|
|
32
|
-
| `assets/idle.png` | 平时 |
|
|
33
|
-
| `assets/thinking.png` | Agent 在跑时 |
|
|
34
|
-
| `assets/accessories/*.png` | 骰子随机挑 |
|
|
35
|
-
|
|
36
|
-
- 两张立绘用同一块画布、透明 PNG、角色对齐,切换才不会跳;
|
|
37
|
-
- `assets/pet.json` 里是名字、默认宽度(`size`)、台词(`sayings`、`thinkingAck`)、配件列表,以及 `canvas` 契约:`{ "width": 512, "height": 512, "crop": [左, 上, 宽, 高] }` 记录立绘是从 512×512 画布哪一块裁出来的——配件就是靠它对齐的。如果你换成不裁的 512×512 整图,把 `crop` 改成 `[0, 0, 512, 512]`;
|
|
38
|
-
- 新配件:PNG 丢进 `assets/accessories/`,重启 DSH 后会自动扫描;不想重启就在 `pet.json` 的 `accessories` 里加文件名。
|
|
39
|
-
|
|
40
|
-
## 结构
|
|
41
|
-
|
|
42
|
-
- `index.js` —— Host 半部分:把 `assets/` 挂到 `/dsh-bat-think/*`,并提供配件目录的实时 JSON 列表;
|
|
43
|
-
- `client.js` —— Client 半部分:`shell.overlay` 插槽、宠物组件、思考气泡、用量面板、贴纸层;
|
|
44
|
-
- `cordis.patch.yml` —— 插入 `dsh-bat-think` 插件行。
|
|
45
|
-
|
|
46
|
-
## 卸载
|
|
47
|
-
|
|
48
|
-
设置 → 插件 → 关掉「蝙蝠侠桌宠」,或移除 bundle。插件只在本地存了几个 UI 状态:`dsh-bat-think:position`、`:size`、`:collapsed`、`:accessory`(`localStorage`)和 `:greeted`(`sessionStorage`)。
|
|
49
|
-
|
|
50
|
-
## 许可
|
|
51
|
-
|
|
52
|
-
代码 MIT;角色立绘是饭制同人画,**不在 MIT 覆盖范围内**,见 [NOTICE.md](NOTICE.md)。
|
|
File without changes
|
|
File without changes
|