@jxgame2020/dsh-token-quota 0.1.23 → 0.1.26
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/lib/client.js +341 -195
- package/lib/index.js +13 -4
- package/lib/types/client/TokenQuotaPanel.d.ts +3 -1
- package/lib/types/client/TokenQuotaPanel.js +3 -2
- package/lib/types/client/index.js +26 -8
- package/lib/types/client/locales.d.ts +4 -0
- package/lib/types/client/locales.js +4 -0
- package/lib/types/client/music.d.ts +43 -18
- package/lib/types/client/music.js +222 -66
- package/lib/types/client/store.d.ts +2 -0
- package/lib/types/client/store.js +2 -0
- package/lib/types/index.js +5 -0
- package/lib/types/types.d.ts +10 -0
- package/lib/types/types.js +1 -0
- package/package.json +1 -1
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Live-composed soundtrack driven by host actions (turns, steps,
|
|
3
|
-
* etc.).
|
|
4
|
-
* sends MIDI NoteOn/NoteOff to the first available MIDI output when one is
|
|
5
|
-
* detected (both play simultaneously when MIDI is present — use the panel
|
|
6
|
-
* volume for overall level, the MIDI output has its own gain on the receiver).
|
|
2
|
+
* Live-composed ambient soundtrack driven by host actions (turns, steps,
|
|
3
|
+
* tool calls, etc.). Three layers:
|
|
7
4
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
5
|
+
* - **Pad**: a sustained three-note chord (triangle waves) that fades in when
|
|
6
|
+
* a request starts and crossfades to the next chord on every step.
|
|
7
|
+
* - **Bass**: one long root note per beat (lower octave), keeps the pulse.
|
|
8
|
+
* - **Melody**: an eighth-note scale line that dances inside the current
|
|
9
|
+
* chord — always in key, never a wrong note.
|
|
10
|
+
*
|
|
11
|
+
* Outputs through Web Audio (built-in synthesis) by default, and also sends
|
|
12
|
+
* MIDI NoteOn/NoteOff to the first available MIDI output when one is detected
|
|
13
|
+
* (both play simultaneously when MIDI is present — use the panel volume for
|
|
14
|
+
* overall level, the MIDI output has its own gain on the receiver).
|
|
12
15
|
*
|
|
13
16
|
* @module @jxgame2020/dsh-token-quota/music
|
|
14
17
|
*/
|
|
@@ -32,14 +35,24 @@ const CHORD_QUALITIES = {
|
|
|
32
35
|
minor: ['minor', 'major', 'major', 'major'],
|
|
33
36
|
pentatonic: ['major', 'major', 'major', 'major'],
|
|
34
37
|
};
|
|
35
|
-
/**
|
|
36
|
-
* Turn a MIDI note number into a frequency (Hz) using equal temperament at
|
|
37
|
-
* A4 = 440 Hz.
|
|
38
|
-
*/
|
|
38
|
+
/** Turn a MIDI note number into a frequency (equal temperament, A4 = 440). */
|
|
39
39
|
function midiToFreq(midi) {
|
|
40
40
|
return 440 * Math.pow(2, (midi - 69) / 12);
|
|
41
41
|
}
|
|
42
|
-
/**
|
|
42
|
+
/** Interval in semitones from the root for each chord-tone. */
|
|
43
|
+
function chordIntervals(quality) {
|
|
44
|
+
const third = quality === 'major' ? 4 : quality === 'minor' ? 3 : 3;
|
|
45
|
+
const fifth = quality === 'dim' ? 6 : 7;
|
|
46
|
+
return [0, third, fifth];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Live-composed music engine driven by host actions.
|
|
50
|
+
*
|
|
51
|
+
* The engine is idle until `ensureStarted()` is called from a user gesture
|
|
52
|
+
* (the panel switch), and only produces sound while `enabled` is true AND a
|
|
53
|
+
* request is in flight (pad + bass + melody are gated by `startPad` /
|
|
54
|
+
* `stopPad`).
|
|
55
|
+
*/
|
|
43
56
|
export class TokenQuotaMusic {
|
|
44
57
|
audio = null;
|
|
45
58
|
midiOutput = null;
|
|
@@ -47,14 +60,27 @@ export class TokenQuotaMusic {
|
|
|
47
60
|
enabled = false;
|
|
48
61
|
volume = 0.5;
|
|
49
62
|
style = 'major';
|
|
50
|
-
|
|
63
|
+
// Composition state
|
|
51
64
|
chordIndex = 0;
|
|
52
|
-
/** Step counter — used for melody degree selection. */
|
|
53
65
|
stepCount = 0;
|
|
54
|
-
/** Tool counter — used for tool-note pitch. */
|
|
55
66
|
toolCount = 0;
|
|
56
|
-
|
|
67
|
+
// Pad layer (sustained chord)
|
|
68
|
+
padOscs = [];
|
|
69
|
+
padGain = null;
|
|
70
|
+
padTarget = 0;
|
|
71
|
+
padActive = false;
|
|
72
|
+
// Bass + melody timing (shared beat clock)
|
|
73
|
+
beatTimer;
|
|
74
|
+
beatIndex = 0; // 0..3 inside a 4-beat bar
|
|
75
|
+
melodyDirection = 1;
|
|
76
|
+
melodyDegree = 0;
|
|
77
|
+
// Current chord (root midi + quality) for the melody and bass.
|
|
78
|
+
currentRoot = 60; // C4
|
|
79
|
+
currentQuality = 'major';
|
|
80
|
+
/** Base MIDI note of the key. C4 = middle C. */
|
|
57
81
|
static BASE_MIDI = 60;
|
|
82
|
+
/** Beat length in ms — eighth note = beat / 2. */
|
|
83
|
+
static BEAT_MS = 640;
|
|
58
84
|
/** True once the audio context has been started (needs a user gesture). */
|
|
59
85
|
get started() {
|
|
60
86
|
return this.audio !== null;
|
|
@@ -96,12 +122,20 @@ export class TokenQuotaMusic {
|
|
|
96
122
|
}
|
|
97
123
|
setEnabled(value) {
|
|
98
124
|
this.enabled = value;
|
|
125
|
+
if (!value)
|
|
126
|
+
this.stopAll();
|
|
99
127
|
}
|
|
100
128
|
setVolume(value) {
|
|
101
129
|
this.volume = Math.max(0, Math.min(1, value));
|
|
130
|
+
if (this.padGain !== null && this.audio !== null) {
|
|
131
|
+
this.padGain.gain.setValueAtTime(this.volume * this.padTarget, this.audio.currentTime);
|
|
132
|
+
}
|
|
102
133
|
}
|
|
103
134
|
setStyle(value) {
|
|
104
135
|
this.style = value;
|
|
136
|
+
// Reset position so the new scale feels immediately.
|
|
137
|
+
this.melodyDegree = 0;
|
|
138
|
+
this.melodyDirection = 1;
|
|
105
139
|
}
|
|
106
140
|
/** Handle one incoming host action and turn it into sound. */
|
|
107
141
|
onAction(action) {
|
|
@@ -110,93 +144,218 @@ export class TokenQuotaMusic {
|
|
|
110
144
|
const base = TokenQuotaMusic.BASE_MIDI;
|
|
111
145
|
switch (action.type) {
|
|
112
146
|
case 'turn/start':
|
|
147
|
+
this.stopAll();
|
|
113
148
|
this.chordIndex = 0;
|
|
114
149
|
this.stepCount = 0;
|
|
115
150
|
this.toolCount = 0;
|
|
116
|
-
this.
|
|
151
|
+
this.currentRoot = base;
|
|
152
|
+
this.currentQuality = CHORD_QUALITIES[this.style][0] ?? 'major';
|
|
153
|
+
this.playChord(base, this.currentQuality, 1.6, 0.6);
|
|
117
154
|
break;
|
|
118
155
|
case 'step/start': {
|
|
119
156
|
this.chordIndex = (this.chordIndex + 1) % CHORD_PROGRESSIONS[this.style].length;
|
|
120
157
|
this.stepCount += 1;
|
|
121
|
-
|
|
122
|
-
this.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
setTimeout(() => this.playNote(root + d2, 0.2, 0.4), 80);
|
|
128
|
-
setTimeout(() => this.playNote(root + d3, 0.35, 0.4), 160);
|
|
158
|
+
const root = base + (CHORD_PROGRESSIONS[this.style][this.chordIndex] ?? 0);
|
|
159
|
+
const quality = CHORD_QUALITIES[this.style][this.chordIndex] ?? 'major';
|
|
160
|
+
this.currentRoot = root;
|
|
161
|
+
this.currentQuality = quality;
|
|
162
|
+
if (this.padActive)
|
|
163
|
+
this.crossfadePad(root, quality);
|
|
129
164
|
break;
|
|
130
165
|
}
|
|
131
166
|
case 'request/header': {
|
|
132
|
-
//
|
|
167
|
+
// Kick off the full three-layer ambient bed — the model is thinking
|
|
168
|
+
// and the user is waiting; this is where the soundtrack lives.
|
|
169
|
+
this.startPad(this.currentRoot, this.currentQuality);
|
|
170
|
+
this.startBeatClock();
|
|
171
|
+
// Small melodic flicker on top to mark the exact start.
|
|
133
172
|
const degree = (this.stepCount * 2 + this.toolCount) % SCALES[this.style].length;
|
|
134
|
-
const note = base + 12 + SCALES[this.style][degree];
|
|
135
|
-
this.playNote(note, 0.
|
|
173
|
+
const note = base + 12 + (SCALES[this.style][degree] ?? 0);
|
|
174
|
+
this.playNote(note, 0.25, 0.4);
|
|
136
175
|
break;
|
|
137
176
|
}
|
|
138
177
|
case 'tool/call':
|
|
139
178
|
this.toolCount += 1;
|
|
140
|
-
//
|
|
179
|
+
// High plink + low percussive tap — stays distinguishable over the pad.
|
|
141
180
|
this.playNote(base + 24 + (this.toolCount % 3) * 2, 0.12, 0.45);
|
|
142
|
-
this.playNote(base - 12, 0.08, 0.
|
|
181
|
+
this.playNote(base - 12, 0.08, 0.3);
|
|
143
182
|
break;
|
|
144
183
|
case 'tool/result': {
|
|
145
184
|
if (action.error) {
|
|
146
|
-
//
|
|
185
|
+
// Dissonant downward glint (two half-steps).
|
|
147
186
|
this.playNote(base + 13, 0.18, 0.4);
|
|
148
187
|
setTimeout(() => this.playNote(base + 12, 0.25, 0.4), 90);
|
|
149
188
|
}
|
|
150
189
|
else {
|
|
151
|
-
//
|
|
152
|
-
this.playNote(base + 9, 0.14, 0.
|
|
153
|
-
setTimeout(() => this.playNote(base + 11, 0.22, 0.
|
|
190
|
+
// Upward resolution.
|
|
191
|
+
this.playNote(base + 9, 0.14, 0.35);
|
|
192
|
+
setTimeout(() => this.playNote(base + 11, 0.22, 0.35), 70);
|
|
154
193
|
}
|
|
155
194
|
break;
|
|
156
195
|
}
|
|
196
|
+
case 'assistant/attempt':
|
|
197
|
+
// Failed attempt: wind down a moment and play a falling tension figure.
|
|
198
|
+
this.playNote(base + 8, 0.18, 0.4);
|
|
199
|
+
setTimeout(() => this.playNote(base + 7, 0.2, 0.4), 100);
|
|
200
|
+
setTimeout(() => this.playNote(base + 5, 0.3, 0.4), 200);
|
|
201
|
+
break;
|
|
157
202
|
case 'assistant/message':
|
|
203
|
+
this.stopBeatClock();
|
|
204
|
+
this.stopPad();
|
|
158
205
|
if (action.interrupted) {
|
|
159
|
-
|
|
160
|
-
this.playChord(base + 7, 'dim', 0.9, 0.5);
|
|
206
|
+
this.playChord(base + 7, 'dim', 0.9, 0.55);
|
|
161
207
|
}
|
|
162
208
|
else {
|
|
163
|
-
|
|
164
|
-
this.playChord(this.currentChordRoot(base), this.currentChordQuality(), 1.1, 0.55);
|
|
209
|
+
this.playChord(this.currentRoot, this.currentQuality, 1.1, 0.6);
|
|
165
210
|
}
|
|
166
211
|
break;
|
|
167
212
|
case 'turn/end':
|
|
168
|
-
|
|
169
|
-
|
|
213
|
+
this.stopAll();
|
|
214
|
+
// Final tonic chord, longer release.
|
|
215
|
+
this.playChord(base, this.style === 'minor' ? 'minor' : 'major', 2.4, 0.7);
|
|
170
216
|
this.chordIndex = 0;
|
|
171
217
|
break;
|
|
172
218
|
}
|
|
173
219
|
}
|
|
174
|
-
// ──
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
220
|
+
// ── pad layer (sustained chord) ────────────────────────────────────────
|
|
221
|
+
/** Start the pad from silence, fading in to the target level. */
|
|
222
|
+
startPad(rootMidi, quality) {
|
|
223
|
+
if (!this.audio)
|
|
224
|
+
return;
|
|
225
|
+
if (this.padActive)
|
|
226
|
+
return;
|
|
227
|
+
const now = this.audio.currentTime;
|
|
228
|
+
const gain = this.audio.createGain();
|
|
229
|
+
gain.gain.setValueAtTime(0, now);
|
|
230
|
+
gain.connect(this.audio.destination);
|
|
231
|
+
const intervals = chordIntervals(quality);
|
|
232
|
+
const oscs = [];
|
|
233
|
+
for (const interval of intervals) {
|
|
234
|
+
const osc = this.audio.createOscillator();
|
|
235
|
+
osc.type = 'triangle';
|
|
236
|
+
osc.frequency.value = midiToFreq(rootMidi + interval);
|
|
237
|
+
osc.connect(gain);
|
|
238
|
+
osc.start(now);
|
|
239
|
+
oscs.push(osc);
|
|
240
|
+
}
|
|
241
|
+
this.padOscs = oscs;
|
|
242
|
+
this.padGain = gain;
|
|
243
|
+
this.padTarget = 0.18;
|
|
244
|
+
gain.gain.linearRampToValueAtTime(this.volume * this.padTarget, now + 0.6);
|
|
245
|
+
this.padActive = true;
|
|
178
246
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
247
|
+
/** Smoothly morph the pad to a new root + quality. */
|
|
248
|
+
crossfadePad(rootMidi, quality) {
|
|
249
|
+
if (!this.audio || !this.padActive || this.padGain === null)
|
|
250
|
+
return;
|
|
251
|
+
const now = this.audio.currentTime;
|
|
252
|
+
const intervals = chordIntervals(quality);
|
|
253
|
+
this.padOscs.forEach((osc, i) => {
|
|
254
|
+
const interval = intervals[i] ?? 0;
|
|
255
|
+
osc.frequency.setValueAtTime(osc.frequency.value, now);
|
|
256
|
+
osc.frequency.exponentialRampToValueAtTime(midiToFreq(rootMidi + interval), now + 0.5);
|
|
257
|
+
});
|
|
182
258
|
}
|
|
183
|
-
/**
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
259
|
+
/** Fade the pad to silence, then stop the oscillators. */
|
|
260
|
+
stopPad() {
|
|
261
|
+
if (!this.audio || !this.padActive || this.padGain === null)
|
|
262
|
+
return;
|
|
263
|
+
const now = this.audio.currentTime;
|
|
264
|
+
const gain = this.padGain;
|
|
265
|
+
gain.gain.cancelScheduledValues(now);
|
|
266
|
+
gain.gain.setValueAtTime(gain.gain.value, now);
|
|
267
|
+
gain.gain.linearRampToValueAtTime(0, now + 0.8);
|
|
268
|
+
const oscs = this.padOscs;
|
|
269
|
+
setTimeout(() => {
|
|
270
|
+
for (const osc of oscs) {
|
|
271
|
+
try {
|
|
272
|
+
osc.stop();
|
|
273
|
+
}
|
|
274
|
+
catch { /* ignore */ }
|
|
275
|
+
try {
|
|
276
|
+
osc.disconnect();
|
|
277
|
+
}
|
|
278
|
+
catch { /* ignore */ }
|
|
279
|
+
}
|
|
280
|
+
try {
|
|
281
|
+
gain.disconnect();
|
|
282
|
+
}
|
|
283
|
+
catch { /* ignore */ }
|
|
284
|
+
}, 850);
|
|
285
|
+
this.padActive = false;
|
|
286
|
+
this.padOscs = [];
|
|
287
|
+
this.padGain = null;
|
|
190
288
|
}
|
|
289
|
+
// ── beat clock (bass + melody) ────────────────────────────────────────
|
|
290
|
+
/** Start the per-beat clock that drives bass and melody. */
|
|
291
|
+
startBeatClock() {
|
|
292
|
+
if (this.beatTimer !== undefined)
|
|
293
|
+
return;
|
|
294
|
+
this.beatIndex = 0;
|
|
295
|
+
this.melodyDegree = 0;
|
|
296
|
+
this.melodyDirection = 1;
|
|
297
|
+
const tick = () => {
|
|
298
|
+
if (!this.audio || !this.enabled)
|
|
299
|
+
return;
|
|
300
|
+
// Bass note on beats 1 and 3 — root of the current chord, low octave.
|
|
301
|
+
if (this.beatIndex % 2 === 0) {
|
|
302
|
+
this.playNote(this.currentRoot - 12, 0.45, 0.3);
|
|
303
|
+
}
|
|
304
|
+
// Melody: eighth-note scale line inside the current chord.
|
|
305
|
+
const scale = SCALES[this.style];
|
|
306
|
+
const chordTones = new Set(chordIntervals(this.currentQuality));
|
|
307
|
+
// Walk up and down the scale, preferring chord tones on beats.
|
|
308
|
+
let degree = this.melodyDegree;
|
|
309
|
+
// Pick the next scale degree in the current direction.
|
|
310
|
+
let next = degree + this.melodyDirection;
|
|
311
|
+
if (next >= scale.length) {
|
|
312
|
+
this.melodyDirection = -1;
|
|
313
|
+
next = scale.length - 2;
|
|
314
|
+
}
|
|
315
|
+
else if (next < 0) {
|
|
316
|
+
this.melodyDirection = 1;
|
|
317
|
+
next = 0;
|
|
318
|
+
}
|
|
319
|
+
this.melodyDegree = next;
|
|
320
|
+
degree = next;
|
|
321
|
+
// Make sure we land on a chord tone on the downbeat.
|
|
322
|
+
if (this.beatIndex % 2 === 0) {
|
|
323
|
+
const rootRel = (scale[degree] ?? 0) % 12;
|
|
324
|
+
if (!chordTones.has(rootRel)) {
|
|
325
|
+
// Shift one step toward the nearest chord tone.
|
|
326
|
+
this.melodyDegree += this.melodyDirection;
|
|
327
|
+
degree = this.melodyDegree;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
const note = this.currentRoot + 12 + (scale[degree] ?? 0);
|
|
331
|
+
// Melody note — slightly shorter than a beat, staccato feel.
|
|
332
|
+
this.playNote(note, 0.22, 0.28);
|
|
333
|
+
this.beatIndex = (this.beatIndex + 1) % 4;
|
|
334
|
+
};
|
|
335
|
+
// First tick right away so the melody starts with the request.
|
|
336
|
+
tick();
|
|
337
|
+
this.beatTimer = setInterval(tick, TokenQuotaMusic.BEAT_MS);
|
|
338
|
+
}
|
|
339
|
+
stopBeatClock() {
|
|
340
|
+
if (this.beatTimer !== undefined) {
|
|
341
|
+
clearInterval(this.beatTimer);
|
|
342
|
+
this.beatTimer = undefined;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
// ── teardown ──────────────────────────────────────────────────────────
|
|
346
|
+
stopAll() {
|
|
347
|
+
this.stopBeatClock();
|
|
348
|
+
this.stopPad();
|
|
349
|
+
}
|
|
350
|
+
// ── primitive note / chord playback (shared by all layers) ────────────
|
|
191
351
|
/** Play one note: Web Audio + MIDI simultaneously when available. */
|
|
192
352
|
playNote(midi, durationSec, velocity) {
|
|
193
353
|
if (!this.audio)
|
|
194
354
|
return;
|
|
195
|
-
const now = this.audio.currentTime;
|
|
196
355
|
const peak = this.volume * velocity * 0.5;
|
|
197
356
|
if (peak <= 0)
|
|
198
357
|
return;
|
|
199
|
-
|
|
358
|
+
const now = this.audio.currentTime;
|
|
200
359
|
const osc = this.audio.createOscillator();
|
|
201
360
|
osc.type = 'sine';
|
|
202
361
|
osc.frequency.value = midiToFreq(midi);
|
|
@@ -208,7 +367,6 @@ export class TokenQuotaMusic {
|
|
|
208
367
|
gain.connect(this.audio.destination);
|
|
209
368
|
osc.start(now);
|
|
210
369
|
osc.stop(now + durationSec + 0.05);
|
|
211
|
-
// MIDI: same note on the first output, if any. Velocity 1..127.
|
|
212
370
|
if (this.midiOutput !== null) {
|
|
213
371
|
const vel = Math.max(1, Math.floor(velocity * 127));
|
|
214
372
|
this.midiOutput.send([0x90, midi & 0x7F, vel]);
|
|
@@ -219,13 +377,11 @@ export class TokenQuotaMusic {
|
|
|
219
377
|
}
|
|
220
378
|
/** Play a three-note chord plus a bass octave below. */
|
|
221
379
|
playChord(rootMidi, quality, durationSec, velocity) {
|
|
222
|
-
const
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
this.playNote(rootMidi
|
|
227
|
-
// bass in the octave below — slightly longer for warmth
|
|
228
|
-
this.playNote(rootMidi - 12, durationSec * 1.15, velocity * 0.45);
|
|
380
|
+
const intervals = chordIntervals(quality);
|
|
381
|
+
for (const interval of intervals) {
|
|
382
|
+
this.playNote(rootMidi + interval, durationSec, velocity * 0.45);
|
|
383
|
+
}
|
|
384
|
+
this.playNote(rootMidi - 12, durationSec * 1.1, velocity * 0.5);
|
|
229
385
|
}
|
|
230
386
|
}
|
|
231
387
|
//# sourceMappingURL=music.js.map
|
|
@@ -54,6 +54,7 @@ export interface TokenQuotaPanelState {
|
|
|
54
54
|
musicEnabled: boolean;
|
|
55
55
|
musicVolume: number;
|
|
56
56
|
musicStyle: TokenQuotaMusicStyle;
|
|
57
|
+
musicOnlyCurrentSession: boolean;
|
|
57
58
|
/** Latest upgrade availability from the Host; null = up to date or unknown. */
|
|
58
59
|
upgrade: TokenQuotaUpgrade | null;
|
|
59
60
|
/** Whether the one-shot upgrade banner was dismissed for the current latest version. */
|
|
@@ -99,6 +100,7 @@ export type TokenQuotaPanelActions = {
|
|
|
99
100
|
setMusicEnabled: (d: TokenQuotaPanelState, enabled: boolean) => void;
|
|
100
101
|
setMusicVolume: (d: TokenQuotaPanelState, volume: number) => void;
|
|
101
102
|
setMusicStyle: (d: TokenQuotaPanelState, style: TokenQuotaMusicStyle) => void;
|
|
103
|
+
setMusicOnlyCurrentSession: (d: TokenQuotaPanelState, only: boolean) => void;
|
|
102
104
|
setUpgrade: (d: TokenQuotaPanelState, upgrade: TokenQuotaUpgrade | null) => void;
|
|
103
105
|
setUpgradeDismissed: (d: TokenQuotaPanelState, dismissed: boolean) => void;
|
|
104
106
|
setCheckingUpdates: (d: TokenQuotaPanelState, checking: boolean) => void;
|
|
@@ -31,6 +31,7 @@ export function createTokenQuotaPanelStore() {
|
|
|
31
31
|
musicEnabled: false,
|
|
32
32
|
musicVolume: 0.5,
|
|
33
33
|
musicStyle: 'major',
|
|
34
|
+
musicOnlyCurrentSession: true,
|
|
34
35
|
upgrade: null,
|
|
35
36
|
upgradeDismissed: false,
|
|
36
37
|
checkingUpdates: false,
|
|
@@ -59,6 +60,7 @@ export function createTokenQuotaPanelStore() {
|
|
|
59
60
|
setMusicEnabled: (d, enabled) => { d.musicEnabled = enabled; },
|
|
60
61
|
setMusicVolume: (d, volume) => { d.musicVolume = volume; },
|
|
61
62
|
setMusicStyle: (d, style) => { d.musicStyle = style; },
|
|
63
|
+
setMusicOnlyCurrentSession: (d, only) => { d.musicOnlyCurrentSession = only; },
|
|
62
64
|
setUpgrade: (d, upgrade) => {
|
|
63
65
|
// Guard against host/client version skew (e.g. the host process still
|
|
64
66
|
// runs an older bundle after an upgrade): when the reported "latest"
|
package/lib/types/index.js
CHANGED
|
@@ -211,6 +211,7 @@ const TOKEN_QUOTA_SETTINGS_SCHEMA = z.object({
|
|
|
211
211
|
enabled: z.boolean().default(TOKEN_QUOTA_DEFAULT_MUSIC.enabled),
|
|
212
212
|
volume: z.number().min(0).max(1).default(TOKEN_QUOTA_DEFAULT_MUSIC.volume),
|
|
213
213
|
style: z.union(['major', 'minor', 'pentatonic']).default(TOKEN_QUOTA_DEFAULT_MUSIC.style),
|
|
214
|
+
onlyCurrentSession: z.boolean().default(TOKEN_QUOTA_DEFAULT_MUSIC.onlyCurrentSession),
|
|
214
215
|
}).default({ ...TOKEN_QUOTA_DEFAULT_MUSIC }),
|
|
215
216
|
});
|
|
216
217
|
/** Two-digit zero-pad helper. */
|
|
@@ -341,6 +342,7 @@ export class TokenQuotaService extends Service {
|
|
|
341
342
|
enabled: doc.music?.enabled ?? TOKEN_QUOTA_DEFAULT_MUSIC.enabled,
|
|
342
343
|
volume: doc.music?.volume ?? TOKEN_QUOTA_DEFAULT_MUSIC.volume,
|
|
343
344
|
style: doc.music?.style ?? TOKEN_QUOTA_DEFAULT_MUSIC.style,
|
|
345
|
+
onlyCurrentSession: doc.music?.onlyCurrentSession ?? TOKEN_QUOTA_DEFAULT_MUSIC.onlyCurrentSession,
|
|
344
346
|
},
|
|
345
347
|
};
|
|
346
348
|
};
|
|
@@ -690,6 +692,9 @@ export class TokenQuotaService extends Service {
|
|
|
690
692
|
case 'tool/result':
|
|
691
693
|
this.pushMusicAction({ type: 'tool/result', sessionId, error: event.data.error !== undefined });
|
|
692
694
|
break;
|
|
695
|
+
case 'assistant/attempt':
|
|
696
|
+
this.pushMusicAction({ type: 'assistant/attempt', sessionId });
|
|
697
|
+
break;
|
|
693
698
|
case 'assistant/message':
|
|
694
699
|
this.pushMusicAction({ type: 'assistant/message', sessionId, interrupted: event.data.interrupted === true });
|
|
695
700
|
if (event.data.usage !== undefined) {
|
package/lib/types/types.d.ts
CHANGED
|
@@ -50,6 +50,13 @@ export interface TokenQuotaMusicSettings {
|
|
|
50
50
|
volume: number;
|
|
51
51
|
/** Harmonic style of the live composition. */
|
|
52
52
|
style: TokenQuotaMusicStyle;
|
|
53
|
+
/**
|
|
54
|
+
* When true, the soundtrack only follows the currently-visible session;
|
|
55
|
+
* background tasks (subagents, other open chats) stay silent. When false,
|
|
56
|
+
* every session on the profile contributes its events (can sound busy with
|
|
57
|
+
* concurrent work). On by default.
|
|
58
|
+
*/
|
|
59
|
+
onlyCurrentSession: boolean;
|
|
53
60
|
}
|
|
54
61
|
/** Default music settings: silent until the user flips the panel switch. */
|
|
55
62
|
export declare const TOKEN_QUOTA_DEFAULT_MUSIC: TokenQuotaMusicSettings;
|
|
@@ -85,6 +92,9 @@ export type TokenQuotaMusicAction = {
|
|
|
85
92
|
type: 'assistant/message';
|
|
86
93
|
sessionId: string;
|
|
87
94
|
interrupted: boolean;
|
|
95
|
+
} | {
|
|
96
|
+
type: 'assistant/attempt';
|
|
97
|
+
sessionId: string;
|
|
88
98
|
};
|
|
89
99
|
/**
|
|
90
100
|
* Per-model daily-limit settings document shape. Keys are `provider/model`
|
package/lib/types/types.js
CHANGED
|
@@ -29,6 +29,7 @@ export const TOKEN_QUOTA_DEFAULT_MUSIC = {
|
|
|
29
29
|
enabled: false,
|
|
30
30
|
volume: 0.5,
|
|
31
31
|
style: 'major',
|
|
32
|
+
onlyCurrentSession: true,
|
|
32
33
|
};
|
|
33
34
|
/** Build the stable per-model key shared by the counter, settings, and snapshot. */
|
|
34
35
|
export function tokenQuotaKey(provider, model) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jxgame2020/dsh-token-quota",
|
|
3
3
|
"description": "Daily per-model token quota accounting, enforcement, and a floating quota panel for the DeepSeek Harness — a fully self-contained plugin (no core-Harness wiring, no generated RPC contract)",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.26",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|