@inupedia/spotlight-vue 0.8.6 → 0.9.1

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