@linxin666/dsh-liangshen 0.3.20 → 0.3.21
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.i18n.yaml +2 -2
- package/README.md +51 -35
- package/README.zh.md +53 -37
- package/lib/client.js +640 -0
- package/lib/client.js.map +1 -0
- package/lib/index.js +10 -6
- package/lib/types/announce.test.d.ts +1 -0
- package/lib/types/client/LiangShenLever.d.ts +17 -0
- package/lib/types/client/index.d.ts +45 -0
- package/lib/types/client/lever-controller.d.ts +133 -0
- package/lib/types/client/locales.d.ts +27 -0
- package/lib/types/core/lever.d.ts +50 -0
- package/lib/types/index.d.ts +10 -6
- package/lib/types/index.test.d.ts +1 -0
- package/lib/types/schema.test.d.ts +1 -0
- package/lib/types/sync.test.d.ts +1 -0
- package/package.json +29 -2
- package/presets/liangshen/NOTICE +4 -3
- package/presets/liangshen/agent.cordis.yml +122 -86
- package/presets/liangshen/custom-bash.mjs +4 -4
- package/presets/liangshen/minimal-prompt.mjs +534 -0
- package/presets/liangshen/tool-catalog.mjs +518 -0
- package/src/client/LiangShenLever.module.css +314 -0
- package/src/client/LiangShenLever.tsx +176 -0
- package/src/client/css-modules.d.ts +5 -0
- package/src/client/index.ts +89 -0
- package/src/client/lever-controller.ts +331 -0
- package/src/client/locales.ts +46 -0
- package/src/core/lever.ts +68 -0
- package/src/index.ts +10 -6
- package/src/schema.test.ts +1 -1
- package/src/sync.test.ts +4 -4
- package/tools/analyze-session.mjs +25 -5
- package/presets/liangshen/tool-bootstrap.mjs +0 -601
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lever styles: an arcade cabinet arm that reads as part of the composer tool
|
|
3
|
+
* row, plus the jackpot burst it fires when LiangShen mode lands.
|
|
4
|
+
*
|
|
5
|
+
* Semantic hooks are the data attributes (`data-dsh-plugin` / `data-dsh-part` /
|
|
6
|
+
* `data-state`), never these hashed class names, so skins can target the lever
|
|
7
|
+
* without a build-time dependency. Every animation is disabled under
|
|
8
|
+
* `prefers-reduced-motion`, where the burst degrades to a short fade.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
.lever {
|
|
12
|
+
position: relative;
|
|
13
|
+
display: inline-flex;
|
|
14
|
+
align-items: center;
|
|
15
|
+
font-size: 12px;
|
|
16
|
+
line-height: 1;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.control {
|
|
20
|
+
display: inline-flex;
|
|
21
|
+
align-items: center;
|
|
22
|
+
gap: 6px;
|
|
23
|
+
margin: 0;
|
|
24
|
+
padding: 2px 8px 2px 4px;
|
|
25
|
+
border: none;
|
|
26
|
+
border-radius: 999px;
|
|
27
|
+
background: transparent;
|
|
28
|
+
color: var(--dsw-alias-label-secondary, inherit);
|
|
29
|
+
font: inherit;
|
|
30
|
+
cursor: pointer;
|
|
31
|
+
touch-action: none;
|
|
32
|
+
transition: background-color 0.16s ease, color 0.16s ease;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.control:hover:not(:disabled) {
|
|
36
|
+
background: var(--dsw-alias-interactive-bg-hover, rgb(0 0 0 / 6%));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.control:focus-visible {
|
|
40
|
+
outline: 2px solid var(--dsw-alias-brand-primary, currentColor);
|
|
41
|
+
outline-offset: 2px;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.control:disabled {
|
|
45
|
+
cursor: default;
|
|
46
|
+
opacity: 0.55;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/* The cabinet slot the arm swings inside: dark, so the arm reads against it. */
|
|
50
|
+
.track {
|
|
51
|
+
position: relative;
|
|
52
|
+
display: inline-flex;
|
|
53
|
+
align-items: flex-end;
|
|
54
|
+
justify-content: center;
|
|
55
|
+
width: 24px;
|
|
56
|
+
height: 28px;
|
|
57
|
+
border-radius: 8px;
|
|
58
|
+
overflow: hidden;
|
|
59
|
+
background: linear-gradient(180deg, #2b2f36, #14161a);
|
|
60
|
+
box-shadow:
|
|
61
|
+
inset 0 0 0 1px rgb(255 255 255 / 14%),
|
|
62
|
+
inset 0 6px 10px rgb(0 0 0 / 55%);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/* The base plate the arm pivots on. */
|
|
66
|
+
.track::after {
|
|
67
|
+
content: '';
|
|
68
|
+
position: absolute;
|
|
69
|
+
left: 3px;
|
|
70
|
+
right: 3px;
|
|
71
|
+
bottom: 2px;
|
|
72
|
+
height: 3px;
|
|
73
|
+
border-radius: 2px;
|
|
74
|
+
background: rgb(255 255 255 / 22%);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.arm {
|
|
78
|
+
position: absolute;
|
|
79
|
+
bottom: 2px;
|
|
80
|
+
left: 50%;
|
|
81
|
+
width: 16px;
|
|
82
|
+
height: 26px;
|
|
83
|
+
margin-left: -8px;
|
|
84
|
+
transform-origin: 50% 24px;
|
|
85
|
+
transform: rotate(-24deg);
|
|
86
|
+
transition: transform 0.34s cubic-bezier(0.2, 1.7, 0.32, 1);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.lever[data-state='on'] .arm {
|
|
90
|
+
transform: rotate(24deg);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.rod {
|
|
94
|
+
fill: #c9ced6;
|
|
95
|
+
transition: fill 0.2s ease;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.knob {
|
|
99
|
+
fill: #e04a33;
|
|
100
|
+
stroke: rgb(0 0 0 / 35%);
|
|
101
|
+
stroke-width: 0.6;
|
|
102
|
+
transition: fill 0.2s ease;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.lever[data-state='on'] .rod {
|
|
106
|
+
fill: #ffd76a;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.lever[data-state='on'] .knob {
|
|
110
|
+
fill: #f7c637;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.lever[data-state='on'] .track {
|
|
114
|
+
box-shadow:
|
|
115
|
+
inset 0 0 0 1px var(--dsw-alias-border-l3, rgb(0 0 0 / 12%)),
|
|
116
|
+
0 0 10px rgb(247 198 55 / 55%);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.lever[data-busy='true'] .arm {
|
|
120
|
+
animation: lever-jitter 0.42s ease-in-out infinite;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/* Width-stable label: the composer row must not shift when the mode changes. */
|
|
124
|
+
.readout {
|
|
125
|
+
min-width: 4.4em;
|
|
126
|
+
white-space: nowrap;
|
|
127
|
+
letter-spacing: 0.02em;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.lever[data-state='on'] .readout {
|
|
131
|
+
color: var(--dsw-alias-label-primary, inherit);
|
|
132
|
+
font-weight: 600;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/*
|
|
136
|
+
* Inline error, kept in flow so it never floats over the composer: the full
|
|
137
|
+
* host reason stays available through the title attribute when it is elided.
|
|
138
|
+
*/
|
|
139
|
+
.error {
|
|
140
|
+
max-width: 22ch;
|
|
141
|
+
margin-left: 4px;
|
|
142
|
+
padding: 2px 6px;
|
|
143
|
+
border-radius: 6px;
|
|
144
|
+
overflow: hidden;
|
|
145
|
+
background: var(--dsw-alias-bg-layer-3, rgb(0 0 0 / 6%));
|
|
146
|
+
color: var(--dsw-alias-state-error-primary, #c0392b);
|
|
147
|
+
text-overflow: ellipsis;
|
|
148
|
+
white-space: nowrap;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/* ── the jackpot ─────────────────────────────────────────────────────────── */
|
|
152
|
+
|
|
153
|
+
.burst {
|
|
154
|
+
position: fixed;
|
|
155
|
+
inset: 0;
|
|
156
|
+
z-index: 60;
|
|
157
|
+
pointer-events: none;
|
|
158
|
+
display: grid;
|
|
159
|
+
place-items: center;
|
|
160
|
+
overflow: hidden;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.flash {
|
|
164
|
+
position: absolute;
|
|
165
|
+
inset: 0;
|
|
166
|
+
background: radial-gradient(circle at 50% 62%, rgb(255 246 200 / 92%), rgb(255 208 74 / 45%) 38%, rgb(255 160 0 / 0%) 72%);
|
|
167
|
+
animation: burst-flash 0.72s ease-out both;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.ring {
|
|
171
|
+
position: absolute;
|
|
172
|
+
width: 220px;
|
|
173
|
+
height: 220px;
|
|
174
|
+
border: 6px solid rgb(255 214 90 / 85%);
|
|
175
|
+
border-radius: 50%;
|
|
176
|
+
animation: burst-ring 1.1s cubic-bezier(0.16, 0.9, 0.3, 1) both;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
.ring:nth-of-type(2) {
|
|
180
|
+
animation-delay: 0.12s;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.ring:nth-of-type(3) {
|
|
184
|
+
animation-delay: 0.24s;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.banner {
|
|
188
|
+
position: relative;
|
|
189
|
+
display: flex;
|
|
190
|
+
flex-direction: column;
|
|
191
|
+
align-items: center;
|
|
192
|
+
gap: 6px;
|
|
193
|
+
padding: 22px 40px;
|
|
194
|
+
border-radius: 22px;
|
|
195
|
+
background: linear-gradient(160deg, rgb(24 16 4 / 94%), rgb(64 38 4 / 92%));
|
|
196
|
+
box-shadow:
|
|
197
|
+
0 0 0 2px rgb(255 214 90 / 75%),
|
|
198
|
+
0 24px 70px rgb(0 0 0 / 45%);
|
|
199
|
+
color: #ffe9a8;
|
|
200
|
+
text-align: center;
|
|
201
|
+
animation: banner-slam 0.6s cubic-bezier(0.16, 1.5, 0.3, 1) both, banner-shake 0.5s ease-in-out 0.6s 2;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.bannerName {
|
|
205
|
+
font-size: 44px;
|
|
206
|
+
font-weight: 800;
|
|
207
|
+
letter-spacing: 0.16em;
|
|
208
|
+
background: linear-gradient(180deg, #fff6d0, #ffc93c 55%, #b8730a);
|
|
209
|
+
-webkit-background-clip: text;
|
|
210
|
+
background-clip: text;
|
|
211
|
+
color: transparent;
|
|
212
|
+
text-shadow: 0 0 24px rgb(255 201 60 / 65%);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.line {
|
|
216
|
+
font-size: 15px;
|
|
217
|
+
letter-spacing: 0.08em;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
.code {
|
|
221
|
+
font-family: var(--dsw-font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
|
|
222
|
+
font-size: 11px;
|
|
223
|
+
letter-spacing: 0.06em;
|
|
224
|
+
opacity: 0.82;
|
|
225
|
+
animation: code-blink 0.5s steps(2, end) 6;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
.sparks {
|
|
229
|
+
position: absolute;
|
|
230
|
+
inset: 0;
|
|
231
|
+
display: grid;
|
|
232
|
+
place-items: center;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/*
|
|
236
|
+
* Sparks pivot about their own centre: the `rotate` property puts each one on
|
|
237
|
+
* its spoke, and the keyframes' translate then travels along that spoke, so
|
|
238
|
+
* they read as speed lines leaving the centre rather than stray hairlines.
|
|
239
|
+
*/
|
|
240
|
+
.spark {
|
|
241
|
+
grid-area: 1 / 1;
|
|
242
|
+
width: 3px;
|
|
243
|
+
height: 30px;
|
|
244
|
+
border-radius: 3px;
|
|
245
|
+
background: linear-gradient(180deg, rgb(255 236 160 / 95%), rgb(255 170 20 / 0%));
|
|
246
|
+
transform-origin: 50% 50%;
|
|
247
|
+
animation: spark-fly 0.95s ease-out both;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
@keyframes lever-jitter {
|
|
251
|
+
0%, 100% { transform: rotate(-22deg); }
|
|
252
|
+
50% { transform: rotate(-8deg); }
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
@keyframes burst-flash {
|
|
256
|
+
0% { opacity: 0; transform: scale(0.6); }
|
|
257
|
+
18% { opacity: 1; }
|
|
258
|
+
100% { opacity: 0; transform: scale(1.5); }
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
@keyframes burst-ring {
|
|
262
|
+
0% { opacity: 0.9; transform: scale(0.2); }
|
|
263
|
+
100% { opacity: 0; transform: scale(3.4); }
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
@keyframes banner-slam {
|
|
267
|
+
0% { opacity: 0; transform: scale(3.6) rotate(-9deg); }
|
|
268
|
+
55% { opacity: 1; transform: scale(0.94) rotate(1.5deg); }
|
|
269
|
+
75% { transform: scale(1.06) rotate(-1deg); }
|
|
270
|
+
100% { opacity: 1; transform: scale(1) rotate(0deg); }
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
@keyframes banner-shake {
|
|
274
|
+
0%, 100% { transform: translateX(0); }
|
|
275
|
+
25% { transform: translateX(-9px) rotate(-0.6deg); }
|
|
276
|
+
75% { transform: translateX(9px) rotate(0.6deg); }
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
@keyframes spark-fly {
|
|
280
|
+
0% { opacity: 0; transform: translateY(-40px) scaleY(0.3); }
|
|
281
|
+
18% { opacity: 1; }
|
|
282
|
+
100% { opacity: 0; transform: translateY(-300px) scaleY(1.15); }
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
@keyframes code-blink {
|
|
286
|
+
0%, 100% { opacity: 0.35; }
|
|
287
|
+
50% { opacity: 1; }
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
@media (prefers-reduced-motion: reduce) {
|
|
291
|
+
.arm,
|
|
292
|
+
.control,
|
|
293
|
+
.rod,
|
|
294
|
+
.knob {
|
|
295
|
+
transition: none;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
.lever[data-busy='true'] .arm,
|
|
299
|
+
.flash,
|
|
300
|
+
.ring,
|
|
301
|
+
.banner,
|
|
302
|
+
.code,
|
|
303
|
+
.spark {
|
|
304
|
+
animation: none;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
.burst {
|
|
308
|
+
animation: burst-flash 0.3s ease-out both;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
.spark {
|
|
312
|
+
display: none;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The homepage lever: a slot-machine arm beside the model selector.
|
|
3
|
+
*
|
|
4
|
+
* Pull it down and the session about to start becomes LiangShen mode; push it
|
|
5
|
+
* up and the preset the user was on comes back. The arm tracks the real preset
|
|
6
|
+
* (never a local guess), and the theatrical part — flash, shockwave, sparks,
|
|
7
|
+
* and the three-language jackpot banner — plays only once the switch actually
|
|
8
|
+
* landed, so a refused switch never celebrates.
|
|
9
|
+
*
|
|
10
|
+
* The component is pure: every fact and verb arrives through the injected face.
|
|
11
|
+
* A pointer drag past {@link DRAG_THRESHOLD_PX} counts as a pull or a push; a
|
|
12
|
+
* plain click or a keyboard activation toggles instead.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { useEffect, useRef, useState, useSyncExternalStore, type PointerEvent as ReactPointerEvent, type ReactElement } from 'react'
|
|
16
|
+
import type { LeverFace } from './lever-controller.ts'
|
|
17
|
+
import css from './LiangShenLever.module.css'
|
|
18
|
+
|
|
19
|
+
/** Vertical travel that separates a pull or push from a plain click. */
|
|
20
|
+
const DRAG_THRESHOLD_PX = 14
|
|
21
|
+
|
|
22
|
+
/** How long the burst overlay stays mounted, matching its CSS duration. */
|
|
23
|
+
const BURST_MS = 2200
|
|
24
|
+
|
|
25
|
+
/** Jackpot lines that read the same in every language. */
|
|
26
|
+
const BINARY = '01001100 01001001 01000001 01001110 01000111'
|
|
27
|
+
const MORSE = '-.. . . .--. ... . . -.- / .... .- .-. -. . ... ...'
|
|
28
|
+
|
|
29
|
+
/** One spark per spoke of the burst. */
|
|
30
|
+
const SPARKS = Array.from({ length: 14 }, (_, index) => index)
|
|
31
|
+
|
|
32
|
+
/** Slot entry for `conversation.input.right` (left of the model selector). */
|
|
33
|
+
export function LiangShenLever(face: LeverFace): ReactElement | null {
|
|
34
|
+
const snapshot = useSyncExternalStore(face.store.subscribe, face.store.getSnapshot)
|
|
35
|
+
const { state, restoreLabel, busy, error, burst } = snapshot
|
|
36
|
+
const [burstKey, setBurstKey] = useState(0)
|
|
37
|
+
const seen = useRef(burst)
|
|
38
|
+
const drag = useRef<{ y: number, fired: boolean } | undefined>(undefined)
|
|
39
|
+
const actionable = !busy && (state === 'on' || state === 'off')
|
|
40
|
+
const on = state === 'on'
|
|
41
|
+
const errorText = error === undefined
|
|
42
|
+
? undefined
|
|
43
|
+
: error.kind === 'locked'
|
|
44
|
+
? face.t('lever.failed.locked')
|
|
45
|
+
: error.kind === 'missing'
|
|
46
|
+
? face.t('lever.failed.missing')
|
|
47
|
+
: error.kind === 'timeout'
|
|
48
|
+
? face.t('lever.failed.timeout')
|
|
49
|
+
: face.t('lever.failed.failed', { reason: error.reason })
|
|
50
|
+
|
|
51
|
+
// The burst is driven by the controller's counter, so a reload or a refresh
|
|
52
|
+
// can never replay it and a refused switch can never start it.
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (burst > seen.current) setBurstKey(burst)
|
|
55
|
+
seen.current = burst
|
|
56
|
+
}, [burst])
|
|
57
|
+
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (burstKey === 0) return
|
|
60
|
+
const timer = setTimeout(() => { setBurstKey(0) }, BURST_MS)
|
|
61
|
+
return () => { clearTimeout(timer) }
|
|
62
|
+
}, [burstKey])
|
|
63
|
+
|
|
64
|
+
// The lever exists only while the preset can still change, which is the
|
|
65
|
+
// blank-session window: a started session reports `locked`, a deployment
|
|
66
|
+
// without the preset reports `missing`, and both mean the row renders
|
|
67
|
+
// nothing instead of a dead control in the composer of a running session.
|
|
68
|
+
if (state === 'locked' || state === 'missing') return null
|
|
69
|
+
|
|
70
|
+
const toggle = (): void => {
|
|
71
|
+
if (!actionable) return
|
|
72
|
+
if (on) face.push()
|
|
73
|
+
else face.pull()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const onPointerDown = (event: ReactPointerEvent<HTMLButtonElement>): void => {
|
|
77
|
+
if (!actionable) return
|
|
78
|
+
drag.current = { y: event.clientY, fired: false }
|
|
79
|
+
event.currentTarget.setPointerCapture?.(event.pointerId)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const onPointerMove = (event: ReactPointerEvent<HTMLButtonElement>): void => {
|
|
83
|
+
const pending = drag.current
|
|
84
|
+
if (pending === undefined || pending.fired) return
|
|
85
|
+
const travel = event.clientY - pending.y
|
|
86
|
+
if (travel >= DRAG_THRESHOLD_PX) {
|
|
87
|
+
pending.fired = true
|
|
88
|
+
face.pull()
|
|
89
|
+
} else if (travel <= -DRAG_THRESHOLD_PX) {
|
|
90
|
+
pending.fired = true
|
|
91
|
+
face.push()
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const onPointerUp = (): void => {
|
|
96
|
+
const pending = drag.current
|
|
97
|
+
drag.current = undefined
|
|
98
|
+
// A drag already fired its verb; a click without travel still toggles.
|
|
99
|
+
if (pending === undefined || pending.fired) return
|
|
100
|
+
toggle()
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<span
|
|
105
|
+
className={css.lever}
|
|
106
|
+
data-dsh-plugin="liangshen"
|
|
107
|
+
data-dsh-part="lever"
|
|
108
|
+
data-state={state}
|
|
109
|
+
data-busy={busy ? 'true' : undefined}
|
|
110
|
+
>
|
|
111
|
+
<button
|
|
112
|
+
type="button"
|
|
113
|
+
role="switch"
|
|
114
|
+
aria-checked={on}
|
|
115
|
+
aria-label={face.t('lever.a11y')}
|
|
116
|
+
aria-busy={busy}
|
|
117
|
+
title={hint(face, state, restoreLabel)}
|
|
118
|
+
className={css.control}
|
|
119
|
+
disabled={!actionable}
|
|
120
|
+
onPointerDown={onPointerDown}
|
|
121
|
+
onPointerMove={onPointerMove}
|
|
122
|
+
onPointerUp={onPointerUp}
|
|
123
|
+
onPointerCancel={onPointerUp}
|
|
124
|
+
// Keyboard and assistive activation arrives as a detail-less click;
|
|
125
|
+
// pointer activation is already handled on pointerup.
|
|
126
|
+
onClick={(event) => { if (event.detail === 0) toggle() }}
|
|
127
|
+
>
|
|
128
|
+
<span className={css.track} data-dsh-part="lever-track" aria-hidden="true">
|
|
129
|
+
<svg className={css.arm} data-dsh-part="lever-arm" viewBox="0 0 16 26" aria-hidden="true">
|
|
130
|
+
<rect className={css.rod} x="6.5" y="3.5" width="3" height="21" rx="1.5" />
|
|
131
|
+
<circle className={css.knob} cx="8" cy="4" r="3.4" />
|
|
132
|
+
</svg>
|
|
133
|
+
</span>
|
|
134
|
+
<span className={css.readout}>{busy ? face.t('lever.busy') : on ? face.t('lever.state.on') : face.t('lever.state.off')}</span>
|
|
135
|
+
</button>
|
|
136
|
+
{errorText !== undefined && (
|
|
137
|
+
<span className={css.error} role="status" title={errorText}>{errorText}</span>
|
|
138
|
+
)}
|
|
139
|
+
{burstKey !== 0 && <Burst key={burstKey} face={face} />}
|
|
140
|
+
</span>
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** The hover hint: what this gesture would do right now. */
|
|
145
|
+
function hint(face: LeverFace, state: string, restoreLabel: string): string {
|
|
146
|
+
if (state === 'locked') return face.t('lever.hint.locked')
|
|
147
|
+
if (state === 'missing') return face.t('lever.hint.missing')
|
|
148
|
+
if (state === 'on') return face.t('lever.hint.push', { preset: restoreLabel === '' ? face.t('lever.state.off') : restoreLabel })
|
|
149
|
+
return face.t('lever.hint.pull')
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** The jackpot overlay: flash, shockwave rings, sparks, and the banner. */
|
|
153
|
+
function Burst({ face }: { face: LeverFace }): ReactElement {
|
|
154
|
+
return (
|
|
155
|
+
<span className={css.burst} data-dsh-part="lever-burst" aria-hidden="true">
|
|
156
|
+
<span className={css.flash} />
|
|
157
|
+
<span className={css.ring} />
|
|
158
|
+
<span className={css.ring} />
|
|
159
|
+
<span className={css.ring} />
|
|
160
|
+
<span className={css.banner} data-dsh-part="lever-banner">
|
|
161
|
+
<span className={css.bannerName}>{face.t('lever.name')}</span>
|
|
162
|
+
<span className={css.line}>{face.t('burst.line1')}</span>
|
|
163
|
+
<span className={css.line}>{face.t('burst.line2')}</span>
|
|
164
|
+
<span className={css.code}>{BINARY}</span>
|
|
165
|
+
<span className={css.code}>{MORSE}</span>
|
|
166
|
+
</span>
|
|
167
|
+
<span className={css.sparks}>
|
|
168
|
+
{SPARKS.map(spoke => (
|
|
169
|
+
// `rotate` is its own property so the keyframes' translate runs along
|
|
170
|
+
// the spoke after the rotation composes with it.
|
|
171
|
+
<i key={spoke} className={css.spark} style={{ rotate: `${spoke * (360 / SPARKS.length)}deg` }} />
|
|
172
|
+
))}
|
|
173
|
+
</span>
|
|
174
|
+
</span>
|
|
175
|
+
)
|
|
176
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-liangshen browser half: the LiangShen lever in the composer tool row.
|
|
3
|
+
*
|
|
4
|
+
* The slot is `conversation.input.right` — "compact controls before the
|
|
5
|
+
* composer submit action", which renders immediately left of the model
|
|
6
|
+
* selector (`conversation.input.model`) inside the same composer card, on the
|
|
7
|
+
* homepage's new-session hero as well as in a session. The lever lives only
|
|
8
|
+
* while the session is still blank, because that is the only window in which a
|
|
9
|
+
* preset can change at all: `agentPresets.select` refuses an already-started
|
|
10
|
+
* session, and the arm would have nothing to do in one.
|
|
11
|
+
*
|
|
12
|
+
* This half talks to the host over the agent-preset Remote namespace rather
|
|
13
|
+
* than through the official preset package's browser module: cross-plugin
|
|
14
|
+
* collaboration here goes through cordis services and Remote surfaces, not
|
|
15
|
+
* value imports.
|
|
16
|
+
*
|
|
17
|
+
* Failure policy: a missing slot or a refused Remote call is handled, never
|
|
18
|
+
* thrown — one external plugin must not take the GUI boot down.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import type { Context as ClientContext } from '@deepseek-ai/cordis'
|
|
22
|
+
import type {} from '@deepseek-ai/dsh-client-ui-renderer/client'
|
|
23
|
+
import type {} from '@deepseek-ai/dsh-client-locale/client'
|
|
24
|
+
// Type-only: pulls the ui-conversation SlotMap merge (the composer tool row).
|
|
25
|
+
import type {} from '@deepseek-ai/dsh-client-ui-conversation/client'
|
|
26
|
+
import type {} from '@deepseek-ai/dsh-client-ui-slots'
|
|
27
|
+
import { LiangShenLever } from './LiangShenLever.tsx'
|
|
28
|
+
import { LeverController } from './lever-controller.ts'
|
|
29
|
+
import { en, zh, type LiangShenKey } from './locales.ts'
|
|
30
|
+
|
|
31
|
+
/** Locale namespace this half owns. */
|
|
32
|
+
export const NS = 'liangshen'
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Required client services: the slot registry, locale, sessions, and the roster
|
|
36
|
+
* Remote. Both `remote` and `remote.agentPresets` are declared: the context
|
|
37
|
+
* proxy refuses an uninjected service, and a nested service name does not imply
|
|
38
|
+
* its parent, so reading `ctx.remote.agentPresets` needs `remote` as well.
|
|
39
|
+
*/
|
|
40
|
+
export const inject = ['slots', 'locale', 'sessions', 'remote', 'remote.agentPresets']
|
|
41
|
+
|
|
42
|
+
declare module '@deepseek-ai/dsh-client-ui-slots' {
|
|
43
|
+
interface LocaleNamespaceMap {
|
|
44
|
+
/** The LiangShen lever copy. */
|
|
45
|
+
'liangshen': LiangShenKey
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { LiangShenLever } from './LiangShenLever.tsx'
|
|
50
|
+
export { LeverController, type LeverFace, type LeverSnapshot } from './lever-controller.ts'
|
|
51
|
+
export { LIANGSHEN_PRESET_ID, leverState, restoreTarget, type LeverFacts, type LeverState } from '../core/lever.ts'
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Mount the lever: register the copy, follow the roster and the current
|
|
55
|
+
* session, and claim the composer tool row.
|
|
56
|
+
* @param ctx - the browser plugin context.
|
|
57
|
+
*/
|
|
58
|
+
export function apply(ctx: ClientContext): void {
|
|
59
|
+
ctx.effect(() => {
|
|
60
|
+
try {
|
|
61
|
+
return ctx.locale.register(NS, { zh, en })
|
|
62
|
+
} catch {
|
|
63
|
+
return () => {}
|
|
64
|
+
}
|
|
65
|
+
}, 'liangshen: lever dictionaries')
|
|
66
|
+
|
|
67
|
+
const controller = new LeverController(ctx)
|
|
68
|
+
ctx.effect(() => () => controller.dispose(), 'liangshen: lever controller')
|
|
69
|
+
try {
|
|
70
|
+
controller.start()
|
|
71
|
+
} catch {
|
|
72
|
+
// An unavailable sessions or Remote service leaves the lever inert; the
|
|
73
|
+
// view still renders and reports what it knows.
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
ctx.slots.inject('conversation.input.right', () => {
|
|
77
|
+
try {
|
|
78
|
+
const unregister = ctx.slots.register({
|
|
79
|
+
name: 'conversation.input.right',
|
|
80
|
+
id: 'liangshen-lever',
|
|
81
|
+
order: 20,
|
|
82
|
+
inject: () => controller.face(),
|
|
83
|
+
}, LiangShenLever)
|
|
84
|
+
return () => { unregister() }
|
|
85
|
+
} catch {
|
|
86
|
+
return () => {}
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
}
|