@inupedia/spotlight-vue 0.8.5 → 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 (59) 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/Live2dPanel2.vue.js +31 -27
  31. package/dist/components/SpotlightShell.vue.d.ts.map +1 -1
  32. package/dist/components/SpotlightShell.vue.js +5 -2
  33. package/dist/components/SpotlightShell2.vue.js +289 -222
  34. package/dist/config.d.ts +3 -0
  35. package/dist/config.d.ts.map +1 -1
  36. package/dist/index.d.ts +1 -0
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +24 -22
  39. package/dist/mountShell.d.ts.map +1 -1
  40. package/dist/mountShell.js +13 -10
  41. package/dist/plugin.js +1 -1
  42. package/dist/remote/audio.d.ts.map +1 -1
  43. package/dist/remote/audio.js +19 -18
  44. package/dist/remote/runPipeline.d.ts +10 -3
  45. package/dist/remote/runPipeline.d.ts.map +1 -1
  46. package/dist/remote/runPipeline.js +120 -111
  47. package/dist/store/live2dSpeechStore.d.ts +2 -2
  48. package/dist/store/memoryPreferenceStore.d.ts +1 -1
  49. package/dist/store/pipeline/constants.d.ts +2 -0
  50. package/dist/store/pipeline/constants.d.ts.map +1 -1
  51. package/dist/store/pipeline/constants.js +2 -0
  52. package/dist/store/runtime/types.d.ts +1 -1
  53. package/dist/store/runtime/types.d.ts.map +1 -1
  54. package/dist/store/spotlightStore.d.ts +11 -13
  55. package/dist/store/spotlightStore.d.ts.map +1 -1
  56. package/package.json +3 -3
  57. package/dist/avatar/speech/live2dBriefingSummarizer.js +0 -91
  58. package/dist/avatar/speech/live2dStreamSpeech.js +0 -4
  59. package/dist/avatar/speech/llmUtils.js +0 -18
@@ -1,87 +1,98 @@
1
- import { defineComponent as me, computed as R, ref as c, watch as Z, nextTick as W, onMounted as be, onUnmounted as we, openBlock as ee, createElementBlock as ye, Fragment as Se, createVNode as Le, unref as U, createBlock as ke, createCommentVNode as Te } from "vue";
2
- import { buildFastLive2dBriefing as Ee, summarizeLive2dBriefing as Ce } from "../avatar/speech/live2dBriefingSummarizer.js";
3
- import { isGenericHostExecutionReply as te } from "../avatar/speech/live2dAnswerSpeechPolicy.js";
4
- import { LIVE2D_ANSWER_STEP_ID as Ae } from "../avatar/speech/live2dStreamSpeech.js";
5
- import { waitForAudioNaturalEnd as Pe } from "../avatar/speech/live2dTtsPlayback.js";
6
- import { hasSpotlightSpeechConfig as ne, SpotlightSpeechService as Ve } from "../avatar/speech/spotlightSpeech.js";
7
- import { storeToRefs as xe } from "pinia";
8
- import { useSpotlightStore as Be } from "../store/spotlightStore.js";
9
- import { useSpotlightAvatarConfig as Ke } from "../avatar/config.js";
10
- import Re from "./SpotlightRoot.vue.js";
11
- import _e from "./Live2dPanel.vue.js";
12
- import { useLive2dOverlayStore as He } from "../store/live2dOverlayStore.js";
13
- import { useLive2dSpeechStore as Fe } from "../store/live2dSpeechStore.js";
14
- import { useLive2dVoiceChannelStore as Ie } from "../store/live2dVoiceChannelStore.js";
15
- import { devWarn as Oe } from "../utils/devConsole.js";
16
- const ie = "Backquote", Ue = "`", tt = /* @__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({
17
19
  __name: "SpotlightShell",
18
20
  props: {
19
21
  avatarEnabled: { type: Boolean, default: !1 }
20
22
  },
21
- setup(z) {
22
- const T = z, _ = Ke(), re = R(
23
- () => _.deckKicker?.trim() || "SPOTLIGHT"
24
- ), H = R(
25
- () => _.greetingText?.trim() || "您好,我是 Spotlight 助手"
26
- ), n = Be(), F = He(), { visible: d } = xe(F), l = Fe(), p = Ie(), b = new Ve(), E = c(null), o = c(!1), y = c(!1), C = c(!1), V = c(null), x = c(null), I = c(null), A = c(null), P = c(0), G = c(0), s = c(!1), $ = R(
23
+ setup(O) {
24
+ const V = O, K = Ye(), ae = _(
25
+ () => K.deckKicker?.trim() || "SPOTLIGHT"
26
+ ), R = _(
27
+ () => K.greetingText?.trim() || "您好,我是 Spotlight 助手"
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 = _(
27
29
  () => Math.max(
28
30
  0,
29
- _.briefingKeepLastMs ?? 0
31
+ K.briefingKeepLastMs ?? 0
30
32
  )
31
33
  );
32
- let S = null;
33
- const w = c(!1), ae = R(() => n.showThinkingBar ? !T.avatarEnabled || !d.value || n.pipelinePhase === "running" || s.value ? !0 : n.pipelinePhase === "done" : !1), le = R(() => {
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 = _(() => {
34
45
  const e = n.agentSteps.length === 1 && n.agentSteps[0]?.label === "回答";
35
- return n.pipelinePhase === "running" || e || s.value;
46
+ return n.pipelinePhase === "running" || e || S.value;
36
47
  });
37
- function oe() {
38
- s.value = !1, d.value && (n.showThinkingBar = !1);
48
+ function ce() {
49
+ S.value = !1, h.value && (n.showThinkingBar = !1);
39
50
  }
40
- function j() {
41
- E.value != null && (window.clearTimeout(E.value), E.value = null);
51
+ function z() {
52
+ T.value != null && (window.clearTimeout(T.value), T.value = null);
42
53
  }
43
- function M() {
44
- j(), V.value && (V.value.abort(), V.value = null), y.value = !1, C.value = !1, o.value = !1, w.value = !1, p.reset(), b.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();
45
56
  }
46
- function g() {
47
- S && (S.abort(), S = null), A.value && (A.value.abort(), A.value = null), B(), l.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(
48
59
  (e) => e.stopLive2dLipSync()
49
60
  );
50
61
  }
51
- function q(e, t) {
62
+ function ue(e, t) {
52
63
  return e <= 0 ? Promise.resolve() : new Promise((i, r) => {
53
64
  const a = window.setTimeout(() => {
54
- t?.removeEventListener("abort", h), i();
55
- }, e), h = () => {
65
+ t?.removeEventListener("abort", o), i();
66
+ }, e), o = () => {
56
67
  window.clearTimeout(a), r(new DOMException("Aborted", "AbortError"));
57
68
  };
58
69
  if (t?.aborted) {
59
- h();
70
+ o();
60
71
  return;
61
72
  }
62
- t?.addEventListener("abort", h, { once: !0 });
73
+ t?.addEventListener("abort", o, { once: !0 });
63
74
  });
64
75
  }
65
- async function se() {
66
- if (!d.value || n.pipelinePhase === "running") return;
67
- g(), P.value += 1;
68
- const e = P.value, t = new AbortController();
69
- if (S = t, !ne()) {
70
- S = null, await W(), (await import("../avatar/spine/live2dApp.js")).playLive2dHello(), l.start(H.value, { instant: !0 }), l.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();
71
82
  return;
72
83
  }
73
84
  const i = b.synthesize(
74
- H.value,
85
+ R.value,
75
86
  t.signal
76
87
  );
77
- if (await W(), await new Promise((r) => {
88
+ if (await ne(), await new Promise((r) => {
78
89
  requestAnimationFrame(() => r());
79
- }), !!f(t, e))
90
+ }), !!v(t, e))
80
91
  try {
81
92
  const { blob: r } = await i;
82
- if (!f(t, e)) return;
93
+ if (!v(t, e)) return;
83
94
  await Q(
84
- H.value,
95
+ R.value,
85
96
  r,
86
97
  t,
87
98
  e,
@@ -90,123 +101,163 @@ const ie = "Backquote", Ue = "`", tt = /* @__PURE__ */ me({
90
101
  } catch (r) {
91
102
  if (t.signal.aborted) return;
92
103
  const a = r instanceof Error ? r.message : "数字人招呼语音失败,请稍后重试。";
93
- Oe("[live2d-greeting]", a), f(t, e) && ((await import("../avatar/spine/live2dApp.js")).playLive2dHello(), l.start(H.value, { instant: !0 }), l.reset());
104
+ rt("[live2d-greeting]", a), v(t, e) && ((await import("../avatar/spine/live2dApp.js")).playLive2dHello(), s.start(R.value, { instant: !0 }), s.reset());
94
105
  } finally {
95
- S === t && (S = null);
106
+ k === t && (k = null);
96
107
  }
97
108
  }
98
- function B() {
99
- x.value && (x.value.pause(), x.value.src = "", x.value = null), I.value && (URL.revokeObjectURL(I.value), I.value = null);
109
+ function I() {
110
+ Oe();
100
111
  }
101
- function Y() {
102
- return (n.agentSteps.find((t) => t.id === Ae) ?? n.agentSteps.find((t) => t.label === "回答") ?? n.agentSteps.find((t) => t.label === "执行工具与回答") ?? n.agentSteps.find((t) => t.label === "知识问答"))?.content ?? "";
112
+ function $() {
113
+ return globalThis.crypto?.randomUUID?.() ?? `turn-${Date.now()}-${Math.random()}`;
103
114
  }
104
- async function ue() {
105
- const e = Y().trim();
106
- if (!e || !d.value || te(e)) {
107
- s.value = !1;
108
- return;
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();
109
121
  }
110
- g();
111
- const t = P.value, i = new AbortController();
112
- A.value = i;
113
- try {
114
- let a = Ee(e).sentences;
115
- if (!a.length) {
116
- s.value = !1;
117
- return;
118
- }
119
- let h = null, K = !1;
120
- const L = Ce(e, i.signal).then((u) => {
121
- u.sentences.length > 0 && (h = u.sentences);
122
- }).catch(() => {
123
- });
124
- let m = -1, k = null;
125
- const O = (u) => {
126
- u < 0 || u >= a.length || m === u && k || (m = u, k = b.synthesize(a[u].text, i.signal).then((N) => N.blob));
127
- };
128
- let v = 0;
129
- for (; v < a.length; ) {
130
- if (!f(i, t)) return;
131
- if (!K && h && (a = h, K = !0, m = -1, k = null, v >= a.length))
132
- break;
133
- const u = a[v];
134
- O(v);
135
- const N = m === v && k ? await k : (await b.synthesize(u.text, i.signal)).blob;
136
- if (!f(i, t)) return;
137
- O(v + 1), v === 0 && oe(), await Q(u.text, N, i, t, {
122
+ return "";
123
+ }
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;
132
+ const e = new AbortController();
133
+ p.value = e, B = Promise.resolve(), F = 0, f = "", L = 0, S.value = !0, x.value = !0, $(), D = 0;
134
+ }
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 })
143
+ );
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,
153
+ t,
154
+ i,
155
+ {
138
156
  instantText: !0,
139
- hasFollowingClip: v + 1 < a.length
140
- });
141
- const X = u.pauseMs ?? 0;
142
- if (X > 0 && f(i, t))
143
- try {
144
- await q(X, i.signal);
145
- } catch {
146
- return;
147
- }
148
- v += 1;
149
- }
150
- await L;
151
- } catch (r) {
152
- if (i.signal.aborted) return;
153
- g();
154
- const a = r instanceof Error ? r.message : "数字人语音播放失败,请稍后重试。";
155
- n.error = a;
156
- } finally {
157
- if (s.value = !1, B(), (await import("../avatar/spine/live2dApp.js")).stopLive2dLipSync(), f(i, t)) {
158
- if ($.value > 0)
159
- try {
160
- await q($.value, i.signal);
161
- } catch {
162
- }
163
- f(i, t) && l.reset();
164
- }
165
- A.value === i && (A.value = null);
157
+ hasFollowingClip: P
158
+ }
159
+ );
160
+ }).catch((o) => {
161
+ t.signal.aborted || (n.error = o instanceof Error ? o.message : "数字人语音播放失败,请稍后重试。");
162
+ });
163
+ }
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)
188
+ try {
189
+ await ue(q.value, e.signal);
190
+ } catch {
191
+ }
192
+ v(e, t) && s.reset();
166
193
  }
194
+ p.value === e && (p.value = null), x.value = !1;
167
195
  }
168
- function f(e, t) {
169
- return !e.signal.aborted && P.value === t;
196
+ function v(e, t) {
197
+ return !e.signal.aborted && g.value === t;
170
198
  }
171
199
  async function Q(e, t, i, r, a) {
172
- if (!f(i, r)) return;
173
- const h = a?.hasFollowingClip ?? !1;
174
- B();
175
- const K = URL.createObjectURL(t);
176
- I.value = K;
177
- const L = new Audio(K);
178
- L.volume = 1, x.value = L;
179
- const m = await import("../avatar/spine/live2dApp.js"), { buildWavEnvelopeFromBlob: k } = await import("../avatar/spine/spineLipSync.js"), O = a?.lipSyncEnvelope ?? await k(t);
180
- if (f(i, r)) {
181
- a?.playHelloWithSpeech && m.playLive2dHello(), m.bindLive2dLipSyncToAudio(L, O), l.start(e, { instant: a?.instantText ?? !0 });
182
- try {
183
- await L.play();
184
- } catch (v) {
185
- throw m.stopLive2dLipSync(), B(), v;
186
- }
187
- if (await Pe(L, i.signal), m.stopLive2dLipSync(), B(), !!f(i, r)) {
188
- if (h) {
189
- l.finish();
190
- return;
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);
191
215
  }
192
- l.reset();
193
- }
216
+ });
217
+ } catch (N) {
218
+ throw P.stopLive2dLipSync(), I(), N;
194
219
  }
220
+ o || P.stopLive2dLipSync(), I(), v(i, r) && (o || s.reset());
195
221
  }
196
- function D() {
197
- return T.avatarEnabled ? d.value && !n.visible && !n.loading && !C.value && !y.value : !1;
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;
227
+ }
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
+ }
198
246
  }
199
- async function J() {
247
+ async function X() {
200
248
  if (y.value) return;
201
- const e = w.value;
202
- o.value = !1, e && p.setTranscribing(!0), y.value = !0;
249
+ const e = m.value;
250
+ u.value = !1, e && c.setTranscribing(!0), y.value = !0;
203
251
  const t = new AbortController();
204
- V.value = t;
252
+ A.value = t;
205
253
  try {
206
254
  const { text: i } = await b.stopAndTranscribe(t.signal), r = i.trim();
207
255
  if (e) {
208
- if (w.value = !1, !r) return;
209
- n.prompt = r, await n.submit();
256
+ if (m.value = !1, c.setTranscribing(!1), !r) {
257
+ n.error = "没识别到内容,请靠近麦克风再说一次。";
258
+ return;
259
+ }
260
+ await ge(r);
210
261
  return;
211
262
  }
212
263
  const a = n.prompt.trim();
@@ -216,125 +267,141 @@ const ie = "Backquote", Ue = "`", tt = /* @__PURE__ */ me({
216
267
  const r = i instanceof Error ? i.message : "语音识别失败,请重试。";
217
268
  n.error = r;
218
269
  } finally {
219
- V.value = null, y.value = !1, o.value = !1, w.value = !1, p.reset();
270
+ A.value = null, y.value = !1, u.value = !1, m.value = !1, c.reset();
220
271
  }
221
272
  }
222
- function ce(e) {
273
+ function me(e) {
223
274
  if (e.repeat || e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) return;
224
- const t = D();
225
- !n.visible && !t || n.visible && n.loading || (e.preventDefault(), !(E.value != null || o.value) && (E.value = window.setTimeout(async () => {
226
- E.value = null;
227
- const i = D();
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();
228
279
  if (!(!n.visible && !i) && !(n.visible && n.loading))
229
280
  try {
230
- await b.startRecording(), o.value = !0, w.value = i, i ? p.setRecording(!0) : p.reset(), n.error = "";
281
+ await b.startRecording(), u.value = !0, m.value = i, i ? c.setRecording(!0) : c.reset(), n.error = "";
231
282
  } catch (r) {
232
283
  const a = r instanceof Error ? r.message : "无法启动语音录制。";
233
- n.error = a, o.value = !1, w.value = !1, p.reset();
284
+ n.error = a, u.value = !1, m.value = !1, c.reset();
234
285
  }
235
286
  }, 450)));
236
287
  }
237
- async function fe() {
238
- if (!(!D() || C.value)) {
288
+ async function be() {
289
+ if (!(!j() || C.value)) {
239
290
  C.value = !0;
240
291
  try {
241
- if (g(), await b.startRecording(), !d.value) {
292
+ if (w(), await b.startRecording(), !h.value) {
242
293
  b.cancel();
243
294
  return;
244
295
  }
245
- o.value = !0, w.value = !0, p.setRecording(!0), n.error = "";
296
+ u.value = !0, m.value = !0, c.setRecording(!0), n.error = "";
246
297
  } catch (e) {
247
298
  const t = e instanceof Error ? e.message : "无法启动语音录制。";
248
- n.error = t, o.value = !1, w.value = !1, p.reset();
299
+ n.error = t, u.value = !1, m.value = !1, c.reset();
249
300
  } finally {
250
301
  C.value = !1;
251
302
  }
252
303
  }
253
304
  }
254
- function ve() {
255
- o.value && J();
305
+ function ye() {
306
+ u.value && X();
256
307
  }
257
- function de(e) {
258
- if (e.code !== ie || !n.visible && !o.value) return;
308
+ function Se(e) {
309
+ if (e.code !== oe || !n.visible && !u.value) return;
259
310
  e.preventDefault();
260
- const t = o.value;
261
- j(), t && J();
311
+ const t = u.value;
312
+ z(), t && X();
262
313
  }
263
- function pe(e) {
264
- if (e.code === ie) {
265
- ce(e);
314
+ function ke(e) {
315
+ if (e.code === oe) {
316
+ me(e);
266
317
  return;
267
318
  }
268
319
  const t = e.key.toLowerCase(), i = e.metaKey || e.ctrlKey;
269
- T.avatarEnabled && i && t === "l" && (e.preventDefault(), F.toggle());
320
+ V.avatarEnabled && i && t === "l" && (e.preventDefault(), E.toggle());
321
+ }
322
+ function we() {
323
+ E.show();
270
324
  }
271
- function he() {
272
- s.value = !1, P.value += 1, g(), l.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
+ });
273
329
  }
274
- function ge(e) {
330
+ function Ce(e) {
275
331
  if (!e) {
276
- M(), d.value && n.prepareLive2dVoiceChannel();
277
- 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();
278
340
  }
279
341
  }
280
- return Z(d, (e) => {
281
- if (T.avatarEnabled) {
342
+ return Z(h, (e) => {
343
+ if (V.avatarEnabled) {
282
344
  if (!e) {
283
- s.value = !1, M(), g(), l.reset(), p.reset();
345
+ S.value = !1, l.abort("avatar_close"), H(), w(), s.reset(), c.reset();
284
346
  return;
285
347
  }
286
- n.visible || n.prepareLive2dVoiceChannel(), se();
348
+ n.visible || n.prepareLive2dVoiceChannel(), Qe(), fe();
287
349
  }
288
350
  }), Z(
289
- () => [n.pipelinePhase, n.pipelineRunId, d.value],
290
- ([e, t, i]) => {
291
- if (T.avatarEnabled) {
292
- if (e === "running") {
293
- s.value = !1, g();
294
- return;
295
- }
296
- if (e !== "done") {
297
- (e === "error" || e === "cancelled") && (s.value = !1, g());
298
- return;
299
- }
300
- i && (t <= G.value || (G.value = t, W(() => {
301
- const r = Y().trim();
302
- if (!r || te(r) || !ne()) {
303
- s.value = !1;
304
- return;
305
- }
306
- s.value = !0, P.value += 1, ue();
307
- })));
308
- }
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);
309
363
  }
310
- ), be(() => {
311
- T.avatarEnabled && _.initiallyVisible && F.show();
312
- }), we(() => {
313
- M(), g(), l.reset(), p.reset();
314
- }), (e, t) => (ee(), ye(Se, null, [
315
- Le(Re, {
316
- "deck-kicker": re.value,
317
- "voice-hold-active": o.value,
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,
318
372
  "speech-pending": y.value,
319
- "voice-key-label": Ue,
320
- "show-thinking": ae.value,
321
- "thinking-centered": le.value,
322
- "on-escape": he,
323
- "on-keydown": pe,
324
- "on-keyup": de,
325
- onVisibleChange: ge
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
326
380
  }, null, 8, ["deck-kicker", "voice-hold-active", "speech-pending", "show-thinking", "thinking-centered"]),
327
- z.avatarEnabled && U(d) ? (ee(), ke(_e, {
381
+ O.avatarEnabled && M(h) ? (U(), Ke(et, {
328
382
  key: 0,
329
- "voice-disabled": U(n).loading || y.value || C.value,
330
- "voice-error": U(n).error,
331
- onVoiceStart: fe,
332
- onVoiceStop: ve,
333
- onClose: U(F).hide
334
- }, null, 8, ["voice-disabled", "voice-error", "onClose"])) : Te("", !0)
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", {
389
+ key: 1,
390
+ type: "button",
391
+ class: "spotlight-avatar-reopen",
392
+ "aria-label": "再次打开数字人小滴",
393
+ title: "再次打开小滴(Ctrl/Command + L)",
394
+ onClick: we
395
+ }, [...t[0] || (t[0] = [
396
+ te("span", {
397
+ class: "spotlight-avatar-reopen__drop",
398
+ "aria-hidden": "true"
399
+ }, null, -1),
400
+ te("span", { class: "spotlight-avatar-reopen__label" }, "小滴", -1)
401
+ ])])) : Re("", !0)
335
402
  ], 64));
336
403
  }
337
404
  });
338
405
  export {
339
- tt as default
406
+ Tt as default
340
407
  };