dsh-bat-think 1.0.0 → 1.0.2
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 +246 -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.
|
|
@@ -50,6 +61,26 @@ window.__ModuleLoader__.load({
|
|
|
50
61
|
let bridgeTarget = null
|
|
51
62
|
let bridgeDispose = null
|
|
52
63
|
let modelDirectories = null
|
|
64
|
+
let pluginCtx = null
|
|
65
|
+
|
|
66
|
+
/** Platform wallet balance through the account Remote namespace, if present. */
|
|
67
|
+
async function readAccountBalance() {
|
|
68
|
+
try {
|
|
69
|
+
const remote = pluginCtx && pluginCtx.remote
|
|
70
|
+
const account = remote && remote.account
|
|
71
|
+
if (!account || typeof account.getBalance !== 'function') return null
|
|
72
|
+
const result = await account.getBalance()
|
|
73
|
+
if (!result || result.status !== 'ready' || !Array.isArray(result.value) || result.value.length === 0) return null
|
|
74
|
+
const wallet = result.value[0]
|
|
75
|
+
if (!wallet || (wallet.currency !== 'CNY' && wallet.currency !== 'USD') || typeof wallet.balance !== 'string') return null
|
|
76
|
+
const bonus = Array.isArray(result.bonusWallets)
|
|
77
|
+
? result.bonusWallets.find((item) => item && item.currency === wallet.currency && Number(item.balance) > 0)
|
|
78
|
+
: null
|
|
79
|
+
return { currency: wallet.currency, balance: wallet.balance, bonus: bonus ? bonus.balance : '' }
|
|
80
|
+
} catch {
|
|
81
|
+
return null
|
|
82
|
+
}
|
|
83
|
+
}
|
|
53
84
|
const modelListeners = new Set()
|
|
54
85
|
function setModelDirectories(next) {
|
|
55
86
|
if (modelDirectories === next) return
|
|
@@ -116,6 +147,11 @@ window.__ModuleLoader__.load({
|
|
|
116
147
|
-webkit-user-drag: none;
|
|
117
148
|
}
|
|
118
149
|
.dsh-bat-think-img:active { cursor: grabbing; }
|
|
150
|
+
.dsh-bat-think-eyes {
|
|
151
|
+
position: absolute;
|
|
152
|
+
pointer-events: none;
|
|
153
|
+
-webkit-user-drag: none;
|
|
154
|
+
}
|
|
119
155
|
@keyframes dsh-bat-think-breathe {
|
|
120
156
|
0%, 100% { transform: translateY(0) scale(1); }
|
|
121
157
|
50% { transform: translateY(-3px) scale(1.02); }
|
|
@@ -404,6 +440,10 @@ window.__ModuleLoader__.load({
|
|
|
404
440
|
}
|
|
405
441
|
}
|
|
406
442
|
|
|
443
|
+
function assetUrl(file) {
|
|
444
|
+
return `${ROUTE}/${String(file).split('/').map(encodeURIComponent).join('/')}`
|
|
445
|
+
}
|
|
446
|
+
|
|
407
447
|
function accessoryUrl(file) {
|
|
408
448
|
return `${ROUTE}/accessories/${String(file).split('/').map(encodeURIComponent).join('/')}`
|
|
409
449
|
}
|
|
@@ -471,14 +511,18 @@ window.__ModuleLoader__.load({
|
|
|
471
511
|
}
|
|
472
512
|
|
|
473
513
|
function mergeManifest(base, extra) {
|
|
474
|
-
const
|
|
475
|
-
for (const [name,
|
|
476
|
-
|
|
514
|
+
const variants = { ...(base.variants || {}) }
|
|
515
|
+
for (const [name, definition] of Object.entries(extra.variants || {})) {
|
|
516
|
+
variants[name] = { ...(variants[name] || {}), ...definition }
|
|
477
517
|
}
|
|
518
|
+
const accessories = extra.accessories && !Array.isArray(extra.accessories)
|
|
519
|
+
? { ...(base.accessories || {}), ...extra.accessories }
|
|
520
|
+
: (base.accessories || { helmet: [], bare: [] })
|
|
478
521
|
return {
|
|
479
522
|
...base,
|
|
480
523
|
...extra,
|
|
481
|
-
|
|
524
|
+
variants,
|
|
525
|
+
accessories,
|
|
482
526
|
fps: { ...(base.fps || {}), ...(extra.fps || {}) },
|
|
483
527
|
sayings: Array.isArray(extra.sayings) && extra.sayings.length > 0
|
|
484
528
|
? extra.sayings.map(String)
|
|
@@ -486,12 +530,22 @@ window.__ModuleLoader__.load({
|
|
|
486
530
|
}
|
|
487
531
|
}
|
|
488
532
|
|
|
533
|
+
function readVariant() {
|
|
534
|
+
try {
|
|
535
|
+
return localStorage.getItem(KEY_VARIANT) === 'bare' ? 'bare' : 'helmet'
|
|
536
|
+
} catch {
|
|
537
|
+
return 'helmet'
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
489
541
|
function Pet() {
|
|
490
542
|
// A single line in the browser console makes a missing registration obvious.
|
|
491
543
|
useEffect(() => { console.info('[dsh-bat-think] mounted at shell.overlay') }, [])
|
|
492
544
|
|
|
493
545
|
const [manifest, setManifest] = useState(FALLBACK)
|
|
494
546
|
const [bubble, setBubble] = useState('')
|
|
547
|
+
const [variant, setVariant] = useState(readVariant)
|
|
548
|
+
const [eyeFrame, setEyeFrame] = useState('open')
|
|
495
549
|
const [position, setPosition] = useState(null)
|
|
496
550
|
const [size, setSize] = useState(() => clampSize(readNumber(KEY_SIZE, DEFAULT_SIZE)))
|
|
497
551
|
const [ratio, setRatio] = useState(DEFAULT_RATIO)
|
|
@@ -499,6 +553,17 @@ window.__ModuleLoader__.load({
|
|
|
499
553
|
try { return localStorage.getItem(KEY_COLLAPSED) === '1' } catch { return false }
|
|
500
554
|
})
|
|
501
555
|
const [missing, setMissing] = useState(false)
|
|
556
|
+
const [loadAttempt, setLoadAttempt] = useState(0)
|
|
557
|
+
const [failedFile, setFailedFile] = useState('')
|
|
558
|
+
const [failedInfo, setFailedInfo] = useState('')
|
|
559
|
+
const [blobs, setBlobs] = useState({})
|
|
560
|
+
const blobsRef = useRef(blobs)
|
|
561
|
+
blobsRef.current = blobs
|
|
562
|
+
useEffect(() => () => {
|
|
563
|
+
for (const url of Object.values(blobsRef.current)) {
|
|
564
|
+
try { URL.revokeObjectURL(url) } catch {}
|
|
565
|
+
}
|
|
566
|
+
}, [])
|
|
502
567
|
const [frame, setFrame] = useState(0)
|
|
503
568
|
const [bump, setBump] = useState(false)
|
|
504
569
|
const [thinkPaused, setThinkPaused] = useState(false)
|
|
@@ -568,6 +633,7 @@ window.__ModuleLoader__.load({
|
|
|
568
633
|
setModelService(modelDirectories)
|
|
569
634
|
return () => { modelListeners.delete(listener) }
|
|
570
635
|
}, [])
|
|
636
|
+
const [balance, setBalance] = useState(null)
|
|
571
637
|
const [modelLabel, setModelLabel] = useState('')
|
|
572
638
|
useEffect(() => {
|
|
573
639
|
setModelLabel('')
|
|
@@ -596,10 +662,13 @@ window.__ModuleLoader__.load({
|
|
|
596
662
|
return () => { try { dispose() } catch {} }
|
|
597
663
|
}, [mainSessionId, modelService])
|
|
598
664
|
|
|
599
|
-
const
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
665
|
+
const variantAccessories = useMemo(() => {
|
|
666
|
+
const prefix = `${variant}/`
|
|
667
|
+
const fromIndex = accessoryList.filter((file) => String(file).startsWith(prefix))
|
|
668
|
+
if (fromIndex.length > 0) return fromIndex
|
|
669
|
+
const map = manifest.accessories && !Array.isArray(manifest.accessories) ? manifest.accessories : {}
|
|
670
|
+
return Array.isArray(map[variant]) ? map[variant].map(String) : []
|
|
671
|
+
}, [accessoryList, manifest, variant])
|
|
603
672
|
|
|
604
673
|
// Accessories are discovered from the folder; `pet.json` lists the same
|
|
605
674
|
// names as a fallback for a Host that has not reloaded yet.
|
|
@@ -616,13 +685,13 @@ window.__ModuleLoader__.load({
|
|
|
616
685
|
}, [])
|
|
617
686
|
|
|
618
687
|
useEffect(() => {
|
|
619
|
-
if (
|
|
688
|
+
if (variantAccessories.length === 0) return
|
|
620
689
|
setAccessory((current) => {
|
|
621
|
-
if (!current ||
|
|
690
|
+
if (!current || variantAccessories.includes(current.file)) return current
|
|
622
691
|
writeAccessory(null)
|
|
623
692
|
return null
|
|
624
693
|
})
|
|
625
|
-
}, [
|
|
694
|
+
}, [variantAccessories])
|
|
626
695
|
|
|
627
696
|
// Bounding box and alpha mask of the current accessory, for placement and
|
|
628
697
|
// for "click the pixels, not the box" removal.
|
|
@@ -689,10 +758,23 @@ window.__ModuleLoader__.load({
|
|
|
689
758
|
.then((response) => (response.ok ? response.json() : null))
|
|
690
759
|
.then((json) => {
|
|
691
760
|
if (cancelled || !json) return
|
|
692
|
-
|
|
761
|
+
const merged = mergeManifest(FALLBACK, json)
|
|
762
|
+
setManifest(merged)
|
|
763
|
+
const cropWidth = merged.canvas && Array.isArray(merged.canvas.crop) ? Number(merged.canvas.crop[2]) : 0
|
|
693
764
|
let stored = 0
|
|
694
765
|
try { stored = Number(localStorage.getItem(KEY_SIZE)) } catch {}
|
|
695
|
-
if (!Number.isFinite(stored) || stored <= 0)
|
|
766
|
+
if (!Number.isFinite(stored) || stored <= 0) {
|
|
767
|
+
setSize(clampSize(json.size))
|
|
768
|
+
} else if (cropWidth > 0) {
|
|
769
|
+
// The shared canvas got wider when the bare variant arrived: scale
|
|
770
|
+
// the saved size once so the pet keeps its on-screen size.
|
|
771
|
+
let previousWidth = readNumber(KEY_CANVAS_WIDTH, 0)
|
|
772
|
+
if (!previousWidth && stored > 0) previousWidth = 247
|
|
773
|
+
if (previousWidth > 0 && Math.abs(previousWidth - cropWidth) > 1) {
|
|
774
|
+
setSize((current) => clampSize(Math.round(current * (cropWidth / previousWidth))))
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
if (cropWidth > 0) writeSetting(KEY_CANVAS_WIDTH, String(cropWidth))
|
|
696
778
|
})
|
|
697
779
|
.catch((error) => console.warn('[dsh-bat-think] pet.json could not be loaded', error))
|
|
698
780
|
return () => { cancelled = true }
|
|
@@ -725,14 +807,19 @@ window.__ModuleLoader__.load({
|
|
|
725
807
|
}, [size, ratio])
|
|
726
808
|
|
|
727
809
|
const frames = useMemo(() => {
|
|
728
|
-
const
|
|
729
|
-
const list = thinking && Array.isArray(
|
|
810
|
+
const definition = (manifest.variants && manifest.variants[variant]) || {}
|
|
811
|
+
const list = thinking && Array.isArray(definition.thinking) && definition.thinking.length > 0
|
|
812
|
+
? definition.thinking
|
|
813
|
+
: definition.idle
|
|
730
814
|
return Array.isArray(list) && list.length > 0 ? list : ['idle.png']
|
|
731
|
-
}, [manifest, thinking])
|
|
815
|
+
}, [manifest, thinking, variant])
|
|
732
816
|
|
|
733
817
|
// Warm both frames so switching to the working picture does not flicker.
|
|
734
818
|
useEffect(() => {
|
|
735
|
-
const files = []
|
|
819
|
+
const files = []
|
|
820
|
+
for (const definition of Object.values(manifest.variants || {})) {
|
|
821
|
+
files.push(...(definition.idle || []), ...(definition.thinking || []), ...Object.values(definition.eyes || {}))
|
|
822
|
+
}
|
|
736
823
|
for (const file of files) {
|
|
737
824
|
const image = new Image()
|
|
738
825
|
image.src = `${ROUTE}/${String(file).split('/').map(encodeURIComponent).join('/')}`
|
|
@@ -750,6 +837,24 @@ window.__ModuleLoader__.load({
|
|
|
750
837
|
return () => clearInterval(timer)
|
|
751
838
|
}, [frames, manifest, thinking])
|
|
752
839
|
|
|
840
|
+
// Blink only in the bare-face variant: the eye layer steps open → half →
|
|
841
|
+
// closed → half → open on a loose timer.
|
|
842
|
+
useEffect(() => {
|
|
843
|
+
if (variant !== 'bare') { setEyeFrame('open'); return undefined }
|
|
844
|
+
const sequence = ['open', 'half', 'closed', 'half', 'open']
|
|
845
|
+
let step = 0
|
|
846
|
+
let timer = 0
|
|
847
|
+
setEyeFrame('open')
|
|
848
|
+
const tick = () => {
|
|
849
|
+
step = (step + 1) % sequence.length
|
|
850
|
+
if (alive.current) setEyeFrame(sequence[step])
|
|
851
|
+
const wait = step === 0 ? 2800 + Math.random() * 3800 : 95
|
|
852
|
+
timer = window.setTimeout(tick, wait)
|
|
853
|
+
}
|
|
854
|
+
timer = window.setTimeout(tick, 2800 + Math.random() * 3800)
|
|
855
|
+
return () => window.clearTimeout(timer)
|
|
856
|
+
}, [variant])
|
|
857
|
+
|
|
753
858
|
const say = (text) => {
|
|
754
859
|
if (!text) return
|
|
755
860
|
setBubble(text)
|
|
@@ -817,8 +922,46 @@ window.__ModuleLoader__.load({
|
|
|
817
922
|
say(lines[Math.floor(Math.random() * lines.length)])
|
|
818
923
|
}
|
|
819
924
|
|
|
925
|
+
useEffect(() => {
|
|
926
|
+
setMissing(false)
|
|
927
|
+
setLoadAttempt(0)
|
|
928
|
+
}, [variant])
|
|
929
|
+
|
|
930
|
+
const toggleVariant = () => {
|
|
931
|
+
const next = variant === 'bare' ? 'helmet' : 'bare'
|
|
932
|
+
setVariant(next)
|
|
933
|
+
try { localStorage.setItem(KEY_VARIANT, next) } catch {}
|
|
934
|
+
setAccessory(null)
|
|
935
|
+
writeAccessory(null)
|
|
936
|
+
setBump(true)
|
|
937
|
+
window.clearTimeout(bumpTimer.current)
|
|
938
|
+
bumpTimer.current = window.setTimeout(() => {
|
|
939
|
+
if (alive.current) setBump(false)
|
|
940
|
+
}, 1300)
|
|
941
|
+
say(next === 'bare' ? '摘下面罩' : '戴上面罩')
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
// Three quick clicks swap the helmet, so a single click waits briefly.
|
|
945
|
+
const clickRef = useRef({ count: 0, last: 0, timer: 0 })
|
|
946
|
+
const onPetClick = () => {
|
|
947
|
+
const now = Date.now()
|
|
948
|
+
const state = clickRef.current
|
|
949
|
+
if (now - state.last > 700) state.count = 0
|
|
950
|
+
state.last = now
|
|
951
|
+
state.count += 1
|
|
952
|
+
window.clearTimeout(state.timer)
|
|
953
|
+
if (state.count >= 3) {
|
|
954
|
+
state.count = 0
|
|
955
|
+
toggleVariant()
|
|
956
|
+
return
|
|
957
|
+
}
|
|
958
|
+
state.timer = window.setTimeout(() => {
|
|
959
|
+
if (alive.current) react()
|
|
960
|
+
}, 300)
|
|
961
|
+
}
|
|
962
|
+
|
|
820
963
|
const rollAccessory = () => {
|
|
821
|
-
const list =
|
|
964
|
+
const list = variantAccessories
|
|
822
965
|
if (list.length === 0) {
|
|
823
966
|
say('还没有配件,把 PNG 放进 assets/accessories/ 就行')
|
|
824
967
|
return
|
|
@@ -885,7 +1028,7 @@ window.__ModuleLoader__.load({
|
|
|
885
1028
|
return current
|
|
886
1029
|
})
|
|
887
1030
|
} else {
|
|
888
|
-
|
|
1031
|
+
onPetClick()
|
|
889
1032
|
}
|
|
890
1033
|
}
|
|
891
1034
|
|
|
@@ -907,7 +1050,8 @@ window.__ModuleLoader__.load({
|
|
|
907
1050
|
}
|
|
908
1051
|
|
|
909
1052
|
const current = frames[Math.min(frame, frames.length - 1)] || 'idle.png'
|
|
910
|
-
const
|
|
1053
|
+
const directSrc = `${assetUrl(current)}?v=${BUILD}${loadAttempt > 0 ? `&retry=${loadAttempt}` : ''}`
|
|
1054
|
+
const src = blobs[current] || directSrc
|
|
911
1055
|
const showThink = thinking && !thinkPaused && !bubble && !usageOpen
|
|
912
1056
|
const centreX = position.x + size / 2
|
|
913
1057
|
const viewportWidth = window.innerWidth || 1024
|
|
@@ -919,12 +1063,42 @@ window.__ModuleLoader__.load({
|
|
|
919
1063
|
const canvasSpec = manifest.canvas && Array.isArray(manifest.canvas.crop) && manifest.canvas.crop.length === 4
|
|
920
1064
|
? manifest.canvas
|
|
921
1065
|
: null
|
|
1066
|
+
const crop = canvasSpec ? canvasSpec.crop.map(Number) : [0, 0, 247, 353]
|
|
1067
|
+
const unit = size / (crop[2] || 1)
|
|
1068
|
+
const canvasWidth = canvasSpec ? Number(canvasSpec.width) || 512 : 512
|
|
1069
|
+
const canvasHeight = canvasSpec ? Number(canvasSpec.height) || 512 : 512
|
|
1070
|
+
|
|
1071
|
+
const eyes = variant === 'bare' && manifest.variants && manifest.variants.bare
|
|
1072
|
+
? manifest.variants.bare.eyes
|
|
1073
|
+
: null
|
|
1074
|
+
const eyeFile = eyes ? (eyes[eyeFrame] || eyes.open || '') : ''
|
|
1075
|
+
const eyesLayer = !missing && eyeFile
|
|
1076
|
+
? h('img', {
|
|
1077
|
+
className: 'dsh-bat-think-eyes',
|
|
1078
|
+
src: assetUrl(eyeFile),
|
|
1079
|
+
alt: '',
|
|
1080
|
+
draggable: false,
|
|
1081
|
+
style: {
|
|
1082
|
+
left: `${-crop[0] * unit}px`,
|
|
1083
|
+
top: `${-crop[1] * unit}px`,
|
|
1084
|
+
width: `${canvasWidth * unit}px`,
|
|
1085
|
+
height: `${canvasHeight * unit}px`,
|
|
1086
|
+
},
|
|
1087
|
+
})
|
|
1088
|
+
: null
|
|
1089
|
+
|
|
1090
|
+
const hotspotPixels = Array.isArray(manifest.hotspot) && manifest.hotspot.length === 4 ? manifest.hotspot.map(Number) : null
|
|
1091
|
+
const hotspotStyle = hotspotPixels
|
|
1092
|
+
? {
|
|
1093
|
+
left: `${(hotspotPixels[0] - crop[0]) * unit}px`,
|
|
1094
|
+
top: `${(hotspotPixels[1] - crop[1]) * unit}px`,
|
|
1095
|
+
width: `${hotspotPixels[2] * unit}px`,
|
|
1096
|
+
height: `${hotspotPixels[3] * unit}px`,
|
|
1097
|
+
}
|
|
1098
|
+
: { left: '8%', top: '69%', width: '52%', height: '30%' }
|
|
1099
|
+
|
|
922
1100
|
const accessoryLayer = accessory && accMeta && canvasSpec
|
|
923
1101
|
? (() => {
|
|
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
1102
|
return h('div', {
|
|
929
1103
|
className: 'dsh-bat-think-accessory',
|
|
930
1104
|
style: {
|
|
@@ -977,6 +1151,12 @@ window.__ModuleLoader__.load({
|
|
|
977
1151
|
modelLabel
|
|
978
1152
|
? h('div', { className: 'dsh-bat-think-usage-row' }, h('span', null, '模型'), h('b', { title: modelLabel }, modelLabel))
|
|
979
1153
|
: null,
|
|
1154
|
+
balance
|
|
1155
|
+
? h('div', { className: 'dsh-bat-think-usage-row' },
|
|
1156
|
+
h('span', null, '余额'),
|
|
1157
|
+
h('b', { title: balance.bonus ? `赠送余额 ${balance.bonus}` : '' },
|
|
1158
|
+
`${balance.currency === 'USD' ? '$' : '¥'}${balance.balance}${balance.bonus ? `(含赠 ${balance.bonus})` : ''}`))
|
|
1159
|
+
: null,
|
|
980
1160
|
hasUsage
|
|
981
1161
|
? [
|
|
982
1162
|
h('div', { key: 'out', className: 'dsh-bat-think-usage-row' }, h('span', null, '输出'), h('b', null, formatCount(usage && usage.outputTokens))),
|
|
@@ -995,7 +1175,9 @@ window.__ModuleLoader__.load({
|
|
|
995
1175
|
: null,
|
|
996
1176
|
bubble && !usageOpen ? h('div', { className: `dsh-bat-think-bubble${bubbleEdge}`, role: 'status' }, bubble) : null,
|
|
997
1177
|
missing
|
|
998
|
-
? h('div', { className: `dsh-bat-think-bubble${bubbleEdge}` },
|
|
1178
|
+
? h('div', { className: `dsh-bat-think-bubble${bubbleEdge}` },
|
|
1179
|
+
h('div', null, `立绘没找到:${failedFile || current}(${manifest.variants && manifest.variants[variant] ? variant : '?'})`),
|
|
1180
|
+
failedInfo ? h('div', { style: { fontSize: '10px', opacity: 0.75, wordBreak: 'break-all', marginTop: '4px' } }, failedInfo) : null)
|
|
999
1181
|
: null,
|
|
1000
1182
|
h('div', { className: `dsh-bat-think-body${bump ? ' is-bump' : ''}` },
|
|
1001
1183
|
missing
|
|
@@ -1014,14 +1196,45 @@ window.__ModuleLoader__.load({
|
|
|
1014
1196
|
setRatio((value) => (Math.abs(value - next) > 0.01 ? next : value))
|
|
1015
1197
|
}
|
|
1016
1198
|
},
|
|
1017
|
-
onError: () =>
|
|
1199
|
+
onError: () => {
|
|
1200
|
+
// A file swapped on disk can 404 for a moment; try twice, then
|
|
1201
|
+
// try the same bytes through fetch() as a blob URL, and only
|
|
1202
|
+
// then tell the user the artwork is missing.
|
|
1203
|
+
if (loadAttempt < 2) {
|
|
1204
|
+
window.setTimeout(() => {
|
|
1205
|
+
if (alive.current) setLoadAttempt((attempt) => attempt + 1)
|
|
1206
|
+
}, 800)
|
|
1207
|
+
return
|
|
1208
|
+
}
|
|
1209
|
+
if (!blobs[current]) {
|
|
1210
|
+
fetch(assetUrl(current), { cache: 'no-store' })
|
|
1211
|
+
.then((response) => {
|
|
1212
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`)
|
|
1213
|
+
return response.blob()
|
|
1214
|
+
})
|
|
1215
|
+
.then((blob) => {
|
|
1216
|
+
const url = URL.createObjectURL(blob)
|
|
1217
|
+
setBlobs((map) => ({ ...map, [current]: url }))
|
|
1218
|
+
})
|
|
1219
|
+
.catch((error) => {
|
|
1220
|
+
setFailedFile(current)
|
|
1221
|
+
setFailedInfo(`${window.location.origin}${directSrc} · ${error && error.message ? error.message : 'fetch failed'}`)
|
|
1222
|
+
setMissing(true)
|
|
1223
|
+
})
|
|
1224
|
+
return
|
|
1225
|
+
}
|
|
1226
|
+
setFailedFile(current)
|
|
1227
|
+
setFailedInfo(`${window.location.origin}${directSrc}`)
|
|
1228
|
+
setMissing(true)
|
|
1229
|
+
},
|
|
1018
1230
|
}),
|
|
1231
|
+
eyesLayer,
|
|
1019
1232
|
missing
|
|
1020
1233
|
? null
|
|
1021
1234
|
: h('button', {
|
|
1022
1235
|
type: 'button',
|
|
1023
1236
|
className: 'dsh-bat-think-laptop',
|
|
1024
|
-
style:
|
|
1237
|
+
style: hotspotStyle,
|
|
1025
1238
|
title: 'API 用量',
|
|
1026
1239
|
'aria-label': '查看 API 用量',
|
|
1027
1240
|
onPointerDown: stopTool,
|
|
@@ -1045,6 +1258,8 @@ window.__ModuleLoader__.load({
|
|
|
1045
1258
|
return {
|
|
1046
1259
|
inject: ['slots'],
|
|
1047
1260
|
apply(ctx) {
|
|
1261
|
+
pluginCtx = ctx
|
|
1262
|
+
ctx.effect(() => () => { pluginCtx = null }, 'dsh-bat-think: context handle')
|
|
1048
1263
|
const softGet = typeof ctx.get === 'function' ? ctx.get.bind(ctx) : undefined
|
|
1049
1264
|
try {
|
|
1050
1265
|
const soft = softGet ? softGet('sessions') : ctx.sessions
|
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 with the platform wallet balance; 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.2",
|
|
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
|