@inupedia/spotlight-vue 0.8.6 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/assets/spotlight-vue.css +1 -1
  2. package/dist/avatar/speech/live2dTtsPlayback.d.ts +15 -2
  3. package/dist/avatar/speech/live2dTtsPlayback.d.ts.map +1 -1
  4. package/dist/avatar/speech/live2dTtsPlayback.js +77 -15
  5. package/dist/avatar/speech/spotlightSpeech.d.ts.map +1 -1
  6. package/dist/avatar/speech/spotlightSpeech.js +44 -36
  7. package/dist/avatar/spine/live2dApp.d.ts +3 -0
  8. package/dist/avatar/spine/live2dApp.d.ts.map +1 -1
  9. package/dist/avatar/spine/live2dApp.js +30 -18
  10. package/dist/avatar/spine/spineAvatar.d.ts +4 -0
  11. package/dist/avatar/spine/spineAvatar.d.ts.map +1 -1
  12. package/dist/avatar/spine/spineAvatar.js +114 -83
  13. package/dist/avatar/spine/spineLipSync.d.ts +1 -0
  14. package/dist/avatar/spine/spineLipSync.d.ts.map +1 -1
  15. package/dist/avatar/spine/spineLipSync.js +41 -36
  16. package/dist/avatar/voice/avatarDirector.d.ts +8 -0
  17. package/dist/avatar/voice/avatarDirector.d.ts.map +1 -0
  18. package/dist/avatar/voice/avatarDirector.js +6 -0
  19. package/dist/avatar/voice/config.d.ts +5 -0
  20. package/dist/avatar/voice/config.d.ts.map +1 -0
  21. package/dist/avatar/voice/config.js +5 -0
  22. package/dist/avatar/voice/panelHidePolicy.d.ts +6 -0
  23. package/dist/avatar/voice/panelHidePolicy.d.ts.map +1 -0
  24. package/dist/avatar/voice/panelHidePolicy.js +6 -0
  25. package/dist/avatar/voice/voiceSession.d.ts +5 -0
  26. package/dist/avatar/voice/voiceSession.d.ts.map +1 -0
  27. package/dist/avatar/voice/voiceSession.js +14 -0
  28. package/dist/components/Live2dPanel.vue.d.ts.map +1 -1
  29. package/dist/components/Live2dPanel.vue.js +2 -2
  30. package/dist/components/SpotlightShell.vue.d.ts.map +1 -1
  31. package/dist/components/SpotlightShell.vue.js +1 -1
  32. package/dist/components/SpotlightShell2.vue.js +290 -200
  33. package/dist/config.d.ts +3 -0
  34. package/dist/config.d.ts.map +1 -1
  35. package/dist/index.d.ts +1 -0
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +24 -22
  38. package/dist/mountShell.d.ts.map +1 -1
  39. package/dist/mountShell.js +13 -10
  40. package/dist/plugin.js +1 -1
  41. package/dist/remote/audio.d.ts.map +1 -1
  42. package/dist/remote/audio.js +19 -18
  43. package/dist/remote/runPipeline.d.ts +1 -0
  44. package/dist/remote/runPipeline.d.ts.map +1 -1
  45. package/dist/remote/runPipeline.js +83 -96
  46. package/dist/store/live2dSpeechStore.d.ts +2 -2
  47. package/dist/store/memoryPreferenceStore.d.ts +1 -1
  48. package/dist/store/runtime/types.d.ts +1 -1
  49. package/dist/store/runtime/types.d.ts.map +1 -1
  50. package/dist/store/spotlightStore.d.ts +10 -10
  51. package/package.json +3 -3
@@ -1,317 +1,407 @@
1
- import { defineComponent as me, computed as P, ref as u, watch as ge, onMounted as be, onUnmounted as we, openBlock as N, createElementBlock as G, Fragment as ye, createVNode as Se, unref as _, createBlock as Le, createElementVNode as $, createCommentVNode as ke, nextTick as j } from "vue";
2
- import { waitForAudioNaturalEnd as Te } from "../avatar/speech/live2dTtsPlayback.js";
3
- import { SpotlightSpeechService as Ce, hasSpotlightSpeechConfig as Ee } from "../avatar/speech/spotlightSpeech.js";
4
- import { storeToRefs as Ve } from "pinia";
5
- import { useSpotlightStore as Ae } from "../store/spotlightStore.js";
6
- import { useSpotlightAvatarConfig as Pe } from "../avatar/config.js";
7
- import Ke from "./SpotlightRoot.vue.js";
8
- import xe from "./Live2dPanel.vue.js";
9
- import { useLive2dOverlayStore as Be } from "../store/live2dOverlayStore.js";
10
- import { useLive2dSpeechStore as He } from "../store/live2dSpeechStore.js";
11
- import { useLive2dVoiceChannelStore as Re } from "../store/live2dVoiceChannelStore.js";
12
- import { devWarn as _e } from "../utils/devConsole.js";
13
- const Y = "Backquote", Fe = "`", Ye = /* @__PURE__ */ me({
1
+ import { defineComponent as Ae, computed as _, ref as d, watch as Z, onMounted as Be, onUnmounted as xe, openBlock as U, createElementBlock as ee, Fragment as He, createVNode as _e, unref as M, createBlock as Ke, createElementVNode as te, createCommentVNode as Re, nextTick as ne } from "vue";
2
+ import { VoiceTurnController as Fe, sanitizeSpokenText as Ie, drainSpokenClips as ie, packSpokenSentences as Me } from "@inupedia/spotlight-protocol";
3
+ import { stopTtsBufferPlayback as Oe, decodeTtsAudioFromBlob as De, getTtsPlaybackContext as Ne, appendSilenceToAudioBuffer as Ue, playTtsAudioBuffer as qe, TTS_CLIP_SILENCE_MS as re } from "../avatar/speech/live2dTtsPlayback.js";
4
+ import { SpotlightSpeechService as ze, hasSpotlightSpeechConfig as $e } from "../avatar/speech/spotlightSpeech.js";
5
+ import { storeToRefs as Ge } from "pinia";
6
+ import { useSpotlightStore as We } from "../store/spotlightStore.js";
7
+ import { useSpotlightAvatarConfig as Ye } from "../avatar/config.js";
8
+ import { unlockVoicePlayback as Qe } from "../avatar/voice/voiceSession.js";
9
+ import { shouldAbortVoiceOnPanelHide as je } from "../avatar/voice/panelHidePolicy.js";
10
+ import { directorPhaseFromTurn as Je } from "../avatar/voice/avatarDirector.js";
11
+ import { useAgentSessionStore as Xe } from "../session/agentSession.js";
12
+ import Ze from "./SpotlightRoot.vue.js";
13
+ import et from "./Live2dPanel.vue.js";
14
+ import { useLive2dOverlayStore as tt } from "../store/live2dOverlayStore.js";
15
+ import { useLive2dSpeechStore as nt } from "../store/live2dSpeechStore.js";
16
+ import { useLive2dVoiceChannelStore as it } from "../store/live2dVoiceChannelStore.js";
17
+ import { devWarn as rt } from "../utils/devConsole.js";
18
+ const oe = "Backquote", ot = "`", Tt = /* @__PURE__ */ Ae({
14
19
  __name: "SpotlightShell",
15
20
  props: {
16
21
  avatarEnabled: { type: Boolean, default: !1 }
17
22
  },
18
- setup(F) {
19
- const k = F, K = Pe(), Q = P(
23
+ setup(O) {
24
+ const V = O, K = Ye(), ae = _(
20
25
  () => K.deckKicker?.trim() || "SPOTLIGHT"
21
- ), x = P(
26
+ ), R = _(
22
27
  () => K.greetingText?.trim() || "您好,我是 Spotlight 助手"
23
- ), n = Ae(), T = Be(), { visible: v } = Ve(T), o = He(), s = Re(), p = new Ce(), w = u(null), l = u(!1), h = u(!1), y = u(!1), C = u(null), E = u(null), B = u(null), f = u(null), m = u(0), g = u(!1), D = P(
28
+ ), n = We(), E = tt(), { visible: h } = Ge(E), s = nt(), c = it(), b = new ze(), T = d(null), u = d(!1), y = d(!1), C = d(!1), A = d(null), p = d(null), g = d(0), S = d(!1), q = _(
24
29
  () => Math.max(
25
30
  0,
26
31
  K.briefingKeepLastMs ?? 0
27
32
  )
28
33
  );
29
- let b = null;
30
- const d = u(!1);
31
- let H = Promise.resolve(), O = 0;
32
- const J = P(() => n.showThinkingBar ? !k.avatarEnabled || !v.value || n.pipelinePhase === "running" || g.value ? !0 : n.pipelinePhase === "done" : !1), X = P(() => {
34
+ let k = null;
35
+ const m = d(!1);
36
+ let B = Promise.resolve(), F = 0;
37
+ const l = new Fe(), x = d(!1);
38
+ let D = 0, f = "", L = 0;
39
+ l.onAbort(async () => {
40
+ n.cancelPipeline(), x.value = !1, f = "", L = 0, w(), H(), s.reset(), import("../avatar/spine/live2dApp.js").then(
41
+ (e) => e.stopLive2dLipSync()
42
+ );
43
+ });
44
+ const le = _(() => n.showThinkingBar ? !V.avatarEnabled || !h.value || n.pipelinePhase === "running" || S.value ? !0 : n.pipelinePhase === "done" : !1), se = _(() => {
33
45
  const e = n.agentSteps.length === 1 && n.agentSteps[0]?.label === "回答";
34
- return n.pipelinePhase === "running" || e || g.value;
46
+ return n.pipelinePhase === "running" || e || S.value;
35
47
  });
36
- function Z() {
37
- g.value = !1, v.value && (n.showThinkingBar = !1);
48
+ function ce() {
49
+ S.value = !1, h.value && (n.showThinkingBar = !1);
38
50
  }
39
- function I() {
40
- w.value != null && (window.clearTimeout(w.value), w.value = null);
51
+ function z() {
52
+ T.value != null && (window.clearTimeout(T.value), T.value = null);
41
53
  }
42
- function U() {
43
- I(), C.value && (C.value.abort(), C.value = null), h.value = !1, y.value = !1, l.value = !1, d.value = !1, s.reset(), p.cancel();
54
+ function H() {
55
+ z(), A.value && (A.value.abort(), A.value = null), y.value = !1, C.value = !1, u.value = !1, m.value = !1, c.reset(), b.cancel();
44
56
  }
45
- function S() {
46
- b && (b.abort(), b = null), f.value && (f.value.abort(), f.value = null), V(), o.reset(), import("../avatar/spine/live2dApp.js").then(
57
+ function w() {
58
+ k && (k.abort(), k = null), p.value && (p.value.abort(), p.value = null), I(), s.reset(), import("../avatar/spine/live2dApp.js").then(
47
59
  (e) => e.stopLive2dLipSync()
48
60
  );
49
61
  }
50
- function ee(e, t) {
51
- return e <= 0 ? Promise.resolve() : new Promise((i, a) => {
52
- const r = window.setTimeout(() => {
53
- t?.removeEventListener("abort", L), i();
54
- }, e), L = () => {
55
- window.clearTimeout(r), a(new DOMException("Aborted", "AbortError"));
62
+ function ue(e, t) {
63
+ return e <= 0 ? Promise.resolve() : new Promise((i, r) => {
64
+ const a = window.setTimeout(() => {
65
+ t?.removeEventListener("abort", o), i();
66
+ }, e), o = () => {
67
+ window.clearTimeout(a), r(new DOMException("Aborted", "AbortError"));
56
68
  };
57
69
  if (t?.aborted) {
58
- L();
70
+ o();
59
71
  return;
60
72
  }
61
- t?.addEventListener("abort", L, { once: !0 });
73
+ t?.addEventListener("abort", o, { once: !0 });
62
74
  });
63
75
  }
64
- async function te() {
65
- if (!v.value || n.pipelinePhase === "running") return;
66
- S(), m.value += 1;
67
- const e = m.value, t = new AbortController();
68
- if (b = t, !Ee()) {
69
- b = null, await j(), (await import("../avatar/spine/live2dApp.js")).playLive2dHello(), o.start(x.value, { instant: !0 }), o.reset();
76
+ async function fe() {
77
+ if (!h.value || n.pipelinePhase === "running") return;
78
+ w(), g.value += 1;
79
+ const e = g.value, t = new AbortController();
80
+ if (k = t, !$e()) {
81
+ k = null, await ne(), (await import("../avatar/spine/live2dApp.js")).playLive2dHello(), s.start(R.value, { instant: !0 }), s.reset();
70
82
  return;
71
83
  }
72
- const i = p.synthesize(
73
- x.value,
84
+ const i = b.synthesize(
85
+ R.value,
74
86
  t.signal
75
87
  );
76
- if (await j(), await new Promise((a) => {
77
- requestAnimationFrame(() => a());
78
- }), !!c(t, e))
88
+ if (await ne(), await new Promise((r) => {
89
+ requestAnimationFrame(() => r());
90
+ }), !!v(t, e))
79
91
  try {
80
- const { blob: a } = await i;
81
- if (!c(t, e)) return;
82
- await W(
83
- x.value,
84
- a,
92
+ const { blob: r } = await i;
93
+ if (!v(t, e)) return;
94
+ await Q(
95
+ R.value,
96
+ r,
85
97
  t,
86
98
  e,
87
99
  { instantText: !0, playHelloWithSpeech: !0 }
88
100
  );
89
- } catch (a) {
101
+ } catch (r) {
90
102
  if (t.signal.aborted) return;
91
- const r = a instanceof Error ? a.message : "数字人招呼语音失败,请稍后重试。";
92
- _e("[live2d-greeting]", r), c(t, e) && ((await import("../avatar/spine/live2dApp.js")).playLive2dHello(), o.start(x.value, { instant: !0 }), o.reset());
103
+ const a = r instanceof Error ? r.message : "数字人招呼语音失败,请稍后重试。";
104
+ rt("[live2d-greeting]", a), v(t, e) && ((await import("../avatar/spine/live2dApp.js")).playLive2dHello(), s.start(R.value, { instant: !0 }), s.reset());
93
105
  } finally {
94
- b === t && (b = null);
106
+ k === t && (k = null);
95
107
  }
96
108
  }
97
- function V() {
98
- E.value && (E.value.pause(), E.value.src = "", E.value = null), B.value && (URL.revokeObjectURL(B.value), B.value = null);
109
+ function I() {
110
+ Oe();
111
+ }
112
+ function $() {
113
+ return globalThis.crypto?.randomUUID?.() ?? `turn-${Date.now()}-${Math.random()}`;
114
+ }
115
+ function ve() {
116
+ const e = Xe();
117
+ for (let t = e.conversationHistory.length - 1; t >= 0; t -= 1) {
118
+ const i = e.conversationHistory[t];
119
+ if (i?.role === "assistant" && i.content.trim())
120
+ return i.content.trim();
121
+ }
122
+ return "";
99
123
  }
100
- function ne() {
101
- S(), m.value += 1;
124
+ function de(e) {
125
+ const t = Me(e);
126
+ t.length !== 0 && (l.setPhase("speaking"), t.forEach((i, r) => {
127
+ Y({ text: i });
128
+ }));
129
+ }
130
+ function pe() {
131
+ w(), g.value += 1;
102
132
  const e = new AbortController();
103
- f.value = e, H = Promise.resolve(), O = 0, g.value = !0;
133
+ p.value = e, B = Promise.resolve(), F = 0, f = "", L = 0, S.value = !0, x.value = !0, $(), D = 0;
104
134
  }
105
- function ie(e) {
106
- const t = f.value;
107
- if (!t || t.signal.aborted || !e.text.trim()) return;
108
- const i = m.value, a = p.synthesize(e.text, t.signal).then(
109
- (r) => ({ blob: r.blob, error: null }),
110
- (r) => ({ blob: null, error: r })
135
+ function G(e) {
136
+ const t = p.value;
137
+ if (!t || t.signal.aborted || !e) return;
138
+ const i = g.value, r = L;
139
+ L += 1;
140
+ const a = b.synthesize(e, t.signal).then(
141
+ (o) => ({ blob: o.blob, error: null }),
142
+ (o) => ({ blob: null, error: o })
111
143
  );
112
- O += 1, H = H.then(async () => {
113
- const r = await a;
114
- if (r.error) throw r.error;
115
- r.blob && c(t, i) && (e.index === 0 && Z(), await W(
116
- e.text,
117
- r.blob,
144
+ F += 1, B = B.then(async () => {
145
+ const o = await a;
146
+ if (o.error) throw o.error;
147
+ if (!o.blob || !v(t, i)) return;
148
+ r === 0 && ce();
149
+ const P = L > r + 1 || f.length > 0 || n.pipelinePhase === "running" || n.loading;
150
+ await Q(
151
+ e,
152
+ o.blob,
118
153
  t,
119
154
  i,
120
155
  {
121
156
  instantText: !0,
122
- hasFollowingClip: !0
157
+ hasFollowingClip: P
123
158
  }
124
- ));
125
- }).catch((r) => {
126
- t.signal.aborted || (n.error = r instanceof Error ? r.message : "数字人语音播放失败,请稍后重试。");
159
+ );
160
+ }).catch((o) => {
161
+ t.signal.aborted || (n.error = o instanceof Error ? o.message : "数字人语音播放失败,请稍后重试。");
127
162
  });
128
163
  }
129
- async function re() {
130
- const e = f.value;
131
- if (!e) return;
132
- const t = m.value;
133
- if (await H, g.value = !1, V(), (await import("../avatar/spine/live2dApp.js")).stopLive2dLipSync(), c(e, t)) {
134
- if (D.value > 0 && O > 0)
164
+ function W() {
165
+ if (!f) return;
166
+ const e = ie(f, { force: !0 });
167
+ f = "";
168
+ for (const t of e.ready) G(t);
169
+ }
170
+ function Y(e) {
171
+ e.generation != null && e.generation !== D && (D = e.generation, $(), B = Promise.resolve(), f = "", L = 0);
172
+ const t = Ie(e.text);
173
+ if (!t) return;
174
+ f += t;
175
+ const i = ie(f);
176
+ f = i.rest;
177
+ for (const r of i.ready) G(r);
178
+ }
179
+ async function he() {
180
+ const e = p.value;
181
+ if (!e) {
182
+ x.value = !1;
183
+ return;
184
+ }
185
+ const t = g.value;
186
+ if (await B, S.value = !1, (await import("../avatar/spine/live2dApp.js")).stopLive2dLipSync(), v(e, t)) {
187
+ if (q.value > 0 && F > 0)
135
188
  try {
136
- await ee(D.value, e.signal);
189
+ await ue(q.value, e.signal);
137
190
  } catch {
138
191
  }
139
- c(e, t) && o.reset();
192
+ v(e, t) && s.reset();
140
193
  }
141
- f.value === e && (f.value = null);
194
+ p.value === e && (p.value = null), x.value = !1;
142
195
  }
143
- function c(e, t) {
144
- return !e.signal.aborted && m.value === t;
196
+ function v(e, t) {
197
+ return !e.signal.aborted && g.value === t;
145
198
  }
146
- async function W(e, t, i, a, r) {
147
- if (!c(i, a)) return;
148
- const L = r?.hasFollowingClip ?? !1;
149
- V();
150
- const z = URL.createObjectURL(t);
151
- B.value = z;
152
- const A = new Audio(z);
153
- A.volume = 1, E.value = A;
154
- const R = await import("../avatar/spine/live2dApp.js"), { buildWavEnvelopeFromBlob: de } = await import("../avatar/spine/spineLipSync.js"), pe = r?.lipSyncEnvelope ?? await de(t);
155
- if (c(i, a)) {
156
- r?.playHelloWithSpeech && R.playLive2dHello(), R.bindLive2dLipSyncToAudio(A, pe), o.start(e, { instant: r?.instantText ?? !0 });
157
- try {
158
- await A.play();
159
- } catch (he) {
160
- throw R.stopLive2dLipSync(), V(), he;
161
- }
162
- if (await Te(A, i.signal), R.stopLive2dLipSync(), V(), !!c(i, a)) {
163
- if (L) {
164
- o.finish();
165
- return;
199
+ async function Q(e, t, i, r, a) {
200
+ if (!v(i, r)) return;
201
+ const o = a?.hasFollowingClip ?? !1;
202
+ I();
203
+ const P = await import("../avatar/spine/live2dApp.js"), { audioBuffer: Le, envelope: Pe } = await De(t);
204
+ if (!v(i, r)) return;
205
+ a?.playHelloWithSpeech && P.playLive2dHello(), s.start(e, { instant: a?.instantText ?? !0 });
206
+ const Ve = Ne(), Ee = Ue(
207
+ Ve,
208
+ Le,
209
+ o ? re : Math.round(re / 2)
210
+ );
211
+ try {
212
+ await qe(Ee, i.signal, {
213
+ onStart: (N) => {
214
+ P.bindLive2dLipSyncToClock(N, Pe);
166
215
  }
167
- o.reset();
168
- }
216
+ });
217
+ } catch (N) {
218
+ throw P.stopLive2dLipSync(), I(), N;
169
219
  }
220
+ o || P.stopLive2dLipSync(), I(), v(i, r) && (o || s.reset());
221
+ }
222
+ function j() {
223
+ return !V.avatarEnabled || !h.value ? !1 : !n.loading && !C.value && !y.value;
224
+ }
225
+ function J() {
226
+ return j() && !n.visible;
170
227
  }
171
- function M() {
172
- return k.avatarEnabled ? v.value && !n.visible && !n.loading && !y.value && !h.value : !1;
228
+ async function ge(e) {
229
+ const t = e.trim();
230
+ if (!t) return;
231
+ n.prompt = t, l.setPhase("thinking"), pe();
232
+ const i = p.value, r = g.value;
233
+ try {
234
+ await n.submit({
235
+ interactionMode: "voice",
236
+ onVoiceSentence: Y
237
+ });
238
+ } finally {
239
+ const a = !!i && v(i, r);
240
+ if (W(), a && F === 0) {
241
+ const o = ve();
242
+ o && de(o), W();
243
+ }
244
+ await he(), a && (l.resetTo("idle"), c.reset());
245
+ }
173
246
  }
174
- async function q() {
175
- if (h.value) return;
176
- const e = d.value;
177
- l.value = !1, e && s.setTranscribing(!0), h.value = !0;
247
+ async function X() {
248
+ if (y.value) return;
249
+ const e = m.value;
250
+ u.value = !1, e && c.setTranscribing(!0), y.value = !0;
178
251
  const t = new AbortController();
179
- C.value = t;
252
+ A.value = t;
180
253
  try {
181
- const { text: i } = await p.stopAndTranscribe(t.signal), a = i.trim();
254
+ const { text: i } = await b.stopAndTranscribe(t.signal), r = i.trim();
182
255
  if (e) {
183
- if (d.value = !1, s.setTranscribing(!1), !a) return;
184
- n.prompt = a, ne();
185
- try {
186
- await n.submit({
187
- interactionMode: "voice",
188
- onVoiceSentence: ie
189
- });
190
- } finally {
191
- await re();
256
+ if (m.value = !1, c.setTranscribing(!1), !r) {
257
+ n.error = "没识别到内容,请靠近麦克风再说一次。";
258
+ return;
192
259
  }
260
+ await ge(r);
193
261
  return;
194
262
  }
195
- const r = n.prompt.trim();
196
- n.prompt = r ? `${r} ${i}` : i;
263
+ const a = n.prompt.trim();
264
+ n.prompt = a ? `${a} ${i}` : i;
197
265
  } catch (i) {
198
266
  if (t.signal.aborted) return;
199
- const a = i instanceof Error ? i.message : "语音识别失败,请重试。";
200
- n.error = a;
267
+ const r = i instanceof Error ? i.message : "语音识别失败,请重试。";
268
+ n.error = r;
201
269
  } finally {
202
- C.value = null, h.value = !1, l.value = !1, d.value = !1, s.reset();
270
+ A.value = null, y.value = !1, u.value = !1, m.value = !1, c.reset();
203
271
  }
204
272
  }
205
- function ae(e) {
273
+ function me(e) {
206
274
  if (e.repeat || e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) return;
207
- const t = M();
208
- !n.visible && !t || n.visible && n.loading || (e.preventDefault(), !(w.value != null || l.value) && (w.value = window.setTimeout(async () => {
209
- w.value = null;
210
- const i = M();
275
+ const t = J();
276
+ !n.visible && !t || n.visible && n.loading || (e.preventDefault(), !(T.value != null || u.value) && (T.value = window.setTimeout(async () => {
277
+ T.value = null;
278
+ const i = J();
211
279
  if (!(!n.visible && !i) && !(n.visible && n.loading))
212
280
  try {
213
- await p.startRecording(), l.value = !0, d.value = i, i ? s.setRecording(!0) : s.reset(), n.error = "";
214
- } catch (a) {
215
- const r = a instanceof Error ? a.message : "无法启动语音录制。";
216
- n.error = r, l.value = !1, d.value = !1, s.reset();
281
+ await b.startRecording(), u.value = !0, m.value = i, i ? c.setRecording(!0) : c.reset(), n.error = "";
282
+ } catch (r) {
283
+ const a = r instanceof Error ? r.message : "无法启动语音录制。";
284
+ n.error = a, u.value = !1, m.value = !1, c.reset();
217
285
  }
218
286
  }, 450)));
219
287
  }
220
- async function oe() {
221
- if (!(!M() || y.value)) {
222
- y.value = !0;
288
+ async function be() {
289
+ if (!(!j() || C.value)) {
290
+ C.value = !0;
223
291
  try {
224
- if (S(), await p.startRecording(), !v.value) {
225
- p.cancel();
292
+ if (w(), await b.startRecording(), !h.value) {
293
+ b.cancel();
226
294
  return;
227
295
  }
228
- l.value = !0, d.value = !0, s.setRecording(!0), n.error = "";
296
+ u.value = !0, m.value = !0, c.setRecording(!0), n.error = "";
229
297
  } catch (e) {
230
298
  const t = e instanceof Error ? e.message : "无法启动语音录制。";
231
- n.error = t, l.value = !1, d.value = !1, s.reset();
299
+ n.error = t, u.value = !1, m.value = !1, c.reset();
232
300
  } finally {
233
- y.value = !1;
301
+ C.value = !1;
234
302
  }
235
303
  }
236
304
  }
237
- function le() {
238
- l.value && q();
305
+ function ye() {
306
+ u.value && X();
239
307
  }
240
- function se(e) {
241
- if (e.code !== Y || !n.visible && !l.value) return;
308
+ function Se(e) {
309
+ if (e.code !== oe || !n.visible && !u.value) return;
242
310
  e.preventDefault();
243
- const t = l.value;
244
- I(), t && q();
311
+ const t = u.value;
312
+ z(), t && X();
245
313
  }
246
- function ue(e) {
247
- if (e.code === Y) {
248
- ae(e);
314
+ function ke(e) {
315
+ if (e.code === oe) {
316
+ me(e);
249
317
  return;
250
318
  }
251
319
  const t = e.key.toLowerCase(), i = e.metaKey || e.ctrlKey;
252
- k.avatarEnabled && i && t === "l" && (e.preventDefault(), T.toggle());
320
+ V.avatarEnabled && i && t === "l" && (e.preventDefault(), E.toggle());
253
321
  }
254
- function ce() {
255
- T.show();
322
+ function we() {
323
+ E.show();
256
324
  }
257
- function ve() {
258
- g.value = !1, m.value += 1, S(), o.reset(), n.showThinkingBar ? n.closeThinking() : n.visible && n.close();
325
+ function Te() {
326
+ l.abort("escape").then(() => {
327
+ S.value = !1, g.value += 1, w(), s.reset(), n.showThinkingBar ? n.closeThinking() : n.visible && n.close();
328
+ });
259
329
  }
260
- function fe(e) {
330
+ function Ce(e) {
261
331
  if (!e) {
262
- U(), v.value && n.prepareLive2dVoiceChannel();
263
- return;
332
+ if (!je({
333
+ loading: n.loading,
334
+ pipelinePhase: n.pipelinePhase
335
+ })) {
336
+ H();
337
+ return;
338
+ }
339
+ l.abort("panel_close"), H(), h.value && n.prepareLive2dVoiceChannel();
264
340
  }
265
341
  }
266
- return ge(v, (e) => {
267
- if (k.avatarEnabled) {
342
+ return Z(h, (e) => {
343
+ if (V.avatarEnabled) {
268
344
  if (!e) {
269
- g.value = !1, U(), S(), o.reset(), s.reset();
345
+ S.value = !1, l.abort("avatar_close"), H(), w(), s.reset(), c.reset();
270
346
  return;
271
347
  }
272
- n.visible || n.prepareLive2dVoiceChannel(), te();
348
+ n.visible || n.prepareLive2dVoiceChannel(), Qe(), fe();
349
+ }
350
+ }), Z(
351
+ () => Je({
352
+ loading: n.loading,
353
+ speaking: l.phase === "speaking" || x.value,
354
+ toolRunning: n.agentSteps.some(
355
+ (e) => e.toolCalls?.some(
356
+ (t) => t.status === "running" || t.status === "pending"
357
+ )
358
+ ),
359
+ interrupted: l.phase === "interrupted"
360
+ }),
361
+ (e) => {
362
+ l.phase === "interrupted" || l.phase === "error" || l.setPhase(e);
273
363
  }
274
- }), be(() => {
275
- k.avatarEnabled && K.initiallyVisible && T.show();
276
- }), we(() => {
277
- U(), S(), o.reset(), s.reset();
278
- }), (e, t) => (N(), G(ye, null, [
279
- Se(Ke, {
280
- "deck-kicker": Q.value,
281
- "voice-hold-active": l.value,
282
- "speech-pending": h.value,
283
- "voice-key-label": Fe,
284
- "show-thinking": J.value,
285
- "thinking-centered": X.value,
286
- "on-escape": ve,
287
- "on-keydown": ue,
288
- "on-keyup": se,
289
- onVisibleChange: fe
364
+ ), Be(() => {
365
+ V.avatarEnabled && K.initiallyVisible && E.show();
366
+ }), xe(() => {
367
+ l.abort("session_end"), H(), w(), s.reset(), c.reset();
368
+ }), (e, t) => (U(), ee(He, null, [
369
+ _e(Ze, {
370
+ "deck-kicker": ae.value,
371
+ "voice-hold-active": u.value,
372
+ "speech-pending": y.value,
373
+ "voice-key-label": ot,
374
+ "show-thinking": le.value,
375
+ "thinking-centered": se.value,
376
+ "on-escape": Te,
377
+ "on-keydown": ke,
378
+ "on-keyup": Se,
379
+ onVisibleChange: Ce
290
380
  }, null, 8, ["deck-kicker", "voice-hold-active", "speech-pending", "show-thinking", "thinking-centered"]),
291
- F.avatarEnabled && _(v) ? (N(), Le(xe, {
381
+ O.avatarEnabled && M(h) ? (U(), Ke(et, {
292
382
  key: 0,
293
- "voice-disabled": _(n).loading || h.value || y.value,
294
- "voice-error": _(n).error,
295
- onVoiceStart: oe,
296
- onVoiceStop: le,
297
- onClose: _(T).hide
298
- }, null, 8, ["voice-disabled", "voice-error", "onClose"])) : F.avatarEnabled ? (N(), G("button", {
383
+ "voice-disabled": M(n).loading || y.value || C.value,
384
+ "voice-error": M(n).error,
385
+ onVoiceStart: be,
386
+ onVoiceStop: ye,
387
+ onClose: M(E).hide
388
+ }, null, 8, ["voice-disabled", "voice-error", "onClose"])) : O.avatarEnabled ? (U(), ee("button", {
299
389
  key: 1,
300
390
  type: "button",
301
391
  class: "spotlight-avatar-reopen",
302
392
  "aria-label": "再次打开数字人小滴",
303
393
  title: "再次打开小滴(Ctrl/Command + L)",
304
- onClick: ce
394
+ onClick: we
305
395
  }, [...t[0] || (t[0] = [
306
- $("span", {
396
+ te("span", {
307
397
  class: "spotlight-avatar-reopen__drop",
308
398
  "aria-hidden": "true"
309
399
  }, null, -1),
310
- $("span", { class: "spotlight-avatar-reopen__label" }, "小滴", -1)
311
- ])])) : ke("", !0)
400
+ te("span", { class: "spotlight-avatar-reopen__label" }, "小滴", -1)
401
+ ])])) : Re("", !0)
312
402
  ], 64));
313
403
  }
314
404
  });
315
405
  export {
316
- Ye as default
406
+ Tt as default
317
407
  };
package/dist/config.d.ts CHANGED
@@ -49,6 +49,7 @@ export type SpotlightQuickPanelActions = {
49
49
  export declare function defineSpotlightConfig(input: SpotlightConfig): SpotlightConfig;
50
50
  export declare const SPOTLIGHT_CONFIG_KEY: unique symbol;
51
51
  import type { SpotlightAvatarConfig } from "./avatar/config.js";
52
+ import type { SpotlightVoiceConfig } from "@inupedia/spotlight-protocol";
52
53
  export type SpotlightVueUiOptions = {
53
54
  /** Mount command panel + thinking UI (default: true). */
54
55
  enabled?: boolean;
@@ -56,6 +57,8 @@ export type SpotlightVueUiOptions = {
56
57
  avatarEnabled?: boolean;
57
58
  /** Avatar copy + Spine asset paths (when avatarEnabled). */
58
59
  avatar?: SpotlightAvatarConfig;
60
+ /** HTTP speech (STT/TTS). Independent of the LLM provider. */
61
+ voice?: SpotlightVoiceConfig;
59
62
  };
60
63
  /** `app.use(SpotlightVue, config)` is preferred; nested config remains source-compatible. */
61
64
  export type SpotlightVuePluginOptions = (SpotlightVueUiOptions & {
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,uBAAuB,EACvB,mCAAmC,EACnC,cAAc,EACf,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EACV,UAAU,EACV,qBAAqB,EACrB,yBAAyB,EAC1B,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,KAAK,EAAE,UAAU,EAA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