@scienjoy/sj-ai-plus 1.0.7 → 1.0.8
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/package.json +1 -1
- package/ui/es/packages/components/src/sjDigitalHumanAssistant/src/index.vue.ts +2 -2
- package/ui/es/packages/components/src/sjDigitalHumanAssistant/src/index.vue2.ts +58 -58
- package/ui/es/sj-ai-plus.css +1 -1
- package/ui/lib/packages/components/src/sjDigitalHumanAssistant/src/index.vue.ts +1 -1
- package/ui/lib/packages/components/src/sjDigitalHumanAssistant/src/index.vue2.ts +1 -1
- package/ui/lib/sj-ai-plus.css +1 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import t from "./index.vue2.ts";
|
|
2
2
|
/* empty css */
|
|
3
3
|
import o from "../../../../../_virtual/_plugin-vue_export-helper.ts";
|
|
4
|
-
const
|
|
4
|
+
const m = /* @__PURE__ */ o(t, [["__scopeId", "data-v-0e24153b"]]);
|
|
5
5
|
export {
|
|
6
|
-
|
|
6
|
+
m as default
|
|
7
7
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent as Se, useCssVars as Ye, ref as u, reactive as Be, computed as Te, watch as P, nextTick as
|
|
1
|
+
import { defineComponent as Se, useCssVars as Ye, ref as u, reactive as Be, computed as Te, watch as P, nextTick as y, onMounted as Ue, onUnmounted as Oe, resolveDirective as je, openBlock as k, createElementBlock as D, normalizeStyle as ke, withDirectives as w, createElementVNode as n, vShow as g, normalizeClass as J, toDisplayString as ae, withModifiers as se, renderSlot as le, createCommentVNode as $, createBlock as Ge, Teleport as ze } from "vue";
|
|
2
2
|
import ce from "../../utils/api.ts";
|
|
3
3
|
import q from "../../utils/utils.ts";
|
|
4
4
|
import Fe from "../../utils/videoBackgroundRemoval.ts";
|
|
@@ -34,11 +34,11 @@ const Ae = { class: "digital-human-assistant" }, Ne = { class: "placeholder left
|
|
|
34
34
|
},
|
|
35
35
|
setup(V, { expose: Ee }) {
|
|
36
36
|
Ye((e) => ({
|
|
37
|
-
|
|
37
|
+
v4920a482: e.sidebarBgColor
|
|
38
38
|
}));
|
|
39
|
-
const i = V, de = u(null), ue = u(null), s = u(null), o = u(null), re = u(null), ve = u(null), fe = u(null), X = u(null), r = Fe(),
|
|
40
|
-
let d = null,
|
|
41
|
-
const U = u(null),
|
|
39
|
+
const i = V, de = u(null), ue = u(null), s = u(null), o = u(null), re = u(null), ve = u(null), fe = u(null), X = u(null), r = Fe(), S = u(!1), l = u(!1), f = u(!1), E = u(!1), he = u(!0), Y = u(!1), h = u(i.defaultStickSide), B = u(!1), R = u(!1), x = u(!1), K = u(!1), Q = u(!1);
|
|
40
|
+
let d = null, m = "";
|
|
41
|
+
const U = u(null), p = u(0), O = u(!1), M = u(!1), v = Be({
|
|
42
42
|
x: 0,
|
|
43
43
|
y: 0,
|
|
44
44
|
offsetX: 0,
|
|
@@ -52,11 +52,11 @@ const Ae = { class: "digital-human-assistant" }, Ne = { class: "placeholder left
|
|
|
52
52
|
top: `${v.y}px`,
|
|
53
53
|
width: `${i.windowWidth}px`,
|
|
54
54
|
height: `${i.windowHeight}px`,
|
|
55
|
-
zIndex: B.value ||
|
|
55
|
+
zIndex: B.value || x.value ? 9999 : 1e3
|
|
56
56
|
})), Le = (e) => {
|
|
57
|
-
!e && s.value ? (O.value = !1,
|
|
57
|
+
!e && s.value ? (O.value = !1, p.value = 0, Re()) : e ? (O.value = !0, Ve()) : console.warn("❌ 自动连接超时:video元素未挂载"), he.value = e;
|
|
58
58
|
}, j = (e) => {
|
|
59
|
-
Le(!e), Y.value = e, e && l.value ?
|
|
59
|
+
Le(!e), Y.value = e, e && l.value ? y(() => b()) : e || (E.value = !1);
|
|
60
60
|
}, He = () => {
|
|
61
61
|
j(!0);
|
|
62
62
|
}, we = () => {
|
|
@@ -96,11 +96,11 @@ const Ae = { class: "digital-human-assistant" }, Ne = { class: "placeholder left
|
|
|
96
96
|
K.value = t.left <= e.left + i.edgeThreshold, Q.value = t.right >= e.right - i.edgeThreshold;
|
|
97
97
|
}, be = () => {
|
|
98
98
|
const e = G(), t = ge(), c = t.left <= e.left + i.edgeThreshold ? "left" : t.right >= e.right - i.edgeThreshold ? "right" : "";
|
|
99
|
-
c !== h.value && (h.value = c, s.value && (s.value.volume = c ? 0.5 : 1), H(),
|
|
99
|
+
c !== h.value && (h.value = c, s.value && (s.value.volume = c ? 0.5 : 1), H(), b()), K.value = Q.value = !1;
|
|
100
100
|
}, Ie = () => {
|
|
101
|
-
|
|
101
|
+
E.value = !0;
|
|
102
102
|
}, Pe = () => {
|
|
103
|
-
|
|
103
|
+
E.value = !1;
|
|
104
104
|
}, De = (e) => {
|
|
105
105
|
B.value = !0, v.offsetX = e.clientX - v.x, v.offsetY = e.clientY - v.y, document.addEventListener("mousemove", ee), document.addEventListener("mouseup", te);
|
|
106
106
|
}, ee = (e) => {
|
|
@@ -114,39 +114,39 @@ const Ae = { class: "digital-human-assistant" }, Ne = { class: "placeholder left
|
|
|
114
114
|
}, z = (e) => {
|
|
115
115
|
if (!R.value) return;
|
|
116
116
|
const t = Math.abs(e.movementX), c = Math.abs(e.movementY);
|
|
117
|
-
(t > i.dragThreshold || c > i.dragThreshold) && (
|
|
117
|
+
(t > i.dragThreshold || c > i.dragThreshold) && (x.value = !0, h.value = "", document.removeEventListener("mousemove", z), document.addEventListener("mousemove", ne), document.addEventListener("mouseup", oe));
|
|
118
118
|
}, ne = (e) => {
|
|
119
|
-
if (!
|
|
119
|
+
if (!x.value) return;
|
|
120
120
|
const t = G(), { x: c, y: a } = Z(e.clientX - t.left - v.offsetX, e.clientY - t.top - v.offsetY);
|
|
121
121
|
v.x = c, v.y = a, pe();
|
|
122
122
|
}, oe = () => {
|
|
123
|
-
be(), R.value =
|
|
123
|
+
be(), R.value = x.value = !1, document.removeEventListener("mousemove", ne), document.removeEventListener("mouseup", oe);
|
|
124
124
|
}, F = () => {
|
|
125
|
-
R.value && !
|
|
125
|
+
R.value && !x.value && (R.value = !1, document.removeEventListener("mousemove", z));
|
|
126
126
|
}, ie = async (e) => {
|
|
127
|
-
if (!l.value || !
|
|
128
|
-
|
|
127
|
+
if (!l.value || !m) return;
|
|
128
|
+
console.log("✅ 准备播放文本:", e);
|
|
129
129
|
const t = {
|
|
130
130
|
text: e,
|
|
131
131
|
type: "echo",
|
|
132
132
|
interrupt: !0,
|
|
133
|
-
sessionid: parseInt(
|
|
133
|
+
sessionid: parseInt(m)
|
|
134
134
|
};
|
|
135
135
|
ce.digitalHumanChat(i.baseUrl, t).then((c) => {
|
|
136
136
|
c && Number(c.code) === 0 && console.log("✅ 播放指令发送成功");
|
|
137
137
|
}).catch((c) => {
|
|
138
138
|
console.error("❌ 播放指令发送失败:", c);
|
|
139
139
|
});
|
|
140
|
-
},
|
|
141
|
-
if (!l.value || !
|
|
142
|
-
const e = { sessionid: parseInt(
|
|
140
|
+
}, L = async () => {
|
|
141
|
+
if (!l.value || !m) return;
|
|
142
|
+
const e = { sessionid: parseInt(m) };
|
|
143
143
|
ce.digitalHumanInterruptTalk(i.baseUrl, e).then((t) => {
|
|
144
144
|
t && Number(t.code) === 0 && console.log("✅ 对话已打断");
|
|
145
145
|
}).catch((t) => {
|
|
146
146
|
console.error("❌ 打断对话失败:", t);
|
|
147
147
|
});
|
|
148
|
-
},
|
|
149
|
-
U.value && (clearTimeout(U.value), U.value = null),
|
|
148
|
+
}, T = () => {
|
|
149
|
+
U.value && (clearTimeout(U.value), U.value = null), M.value = !1, console.log("✅ 重连定时器已清除");
|
|
150
150
|
}, H = (e = !1) => {
|
|
151
151
|
if (!o.value) return;
|
|
152
152
|
e || r.stopProcessing();
|
|
@@ -156,9 +156,9 @@ const Ae = { class: "digital-human-assistant" }, Ne = { class: "placeholder left
|
|
|
156
156
|
o.value.width = c, o.value.height = a;
|
|
157
157
|
}
|
|
158
158
|
o.value && !e && (o.value.style.width = "", o.value.style.height = "", h.value === "" && (o.value.style.marginLeft = "", o.value.style.marginTop = ""));
|
|
159
|
-
},
|
|
160
|
-
if (!s.value || !o.value || !
|
|
161
|
-
await
|
|
159
|
+
}, b = async (e = !1) => {
|
|
160
|
+
if (!s.value || !o.value || !S.value || !l.value) return;
|
|
161
|
+
await y();
|
|
162
162
|
const t = s.value.videoWidth || i.windowWidth, c = s.value.videoHeight || i.windowHeight, a = t / c;
|
|
163
163
|
let C;
|
|
164
164
|
const _e = we();
|
|
@@ -173,19 +173,19 @@ const Ae = { class: "digital-human-assistant" }, Ne = { class: "placeholder left
|
|
|
173
173
|
canvas: { drawWidth: _, drawHeight: W }
|
|
174
174
|
}), e || (r.videoRef.value = s.value, r.canvasRef.value = o.value, await r.processVideo()), !r.isInitSuccess.value && l.value && (console.log("🔄 检测到WebGPU未初始化,触发手动重连"), await r.reInitWebGPU() && await r.processVideo());
|
|
175
175
|
}, I = () => {
|
|
176
|
-
if (O.value || l.value || f.value ||
|
|
176
|
+
if (O.value || l.value || f.value || M.value) {
|
|
177
177
|
console.log("🚫 重连条件不满足");
|
|
178
178
|
return;
|
|
179
179
|
}
|
|
180
|
-
if (
|
|
181
|
-
console.warn(`🚫 重连已达最大次数(${i.maxReconnectTimes})`),
|
|
180
|
+
if (L(), i.maxReconnectTimes !== -1 && p.value >= i.maxReconnectTimes) {
|
|
181
|
+
console.warn(`🚫 重连已达最大次数(${i.maxReconnectTimes})`), T(), q.funcElMessageShowCtrl(`❌ 数字人连接失败,已尝试${i.maxReconnectTimes}次重连,请重试!`, "error"), p.value = 0;
|
|
182
182
|
return;
|
|
183
183
|
}
|
|
184
|
-
|
|
184
|
+
M.value = !0, U.value = setTimeout(() => {
|
|
185
185
|
try {
|
|
186
|
-
|
|
186
|
+
p.value++, console.log(`🔄 第${p.value}次重连WebRTC...`), r.stopProcessing(), Re();
|
|
187
187
|
} finally {
|
|
188
|
-
|
|
188
|
+
M.value = !1;
|
|
189
189
|
}
|
|
190
190
|
}, i.reconnectInterval * 1e3);
|
|
191
191
|
}, $e = async () => {
|
|
@@ -205,7 +205,7 @@ const Ae = { class: "digital-human-assistant" }, Ne = { class: "placeholder left
|
|
|
205
205
|
});
|
|
206
206
|
const t = d.localDescription, c = { sdp: t.sdp, type: t.type };
|
|
207
207
|
ce.digitalHumanOffer(i.baseUrl, c).then((a) => {
|
|
208
|
-
a ? (
|
|
208
|
+
a ? (m = a.sessionid, d.setRemoteDescription(new RTCSessionDescription(a)), l.value = !0, p.value = 0, T(), console.log("✅ WebRTC连接成功"), y(() => b())) : (l.value = !1, console.log("❌ WebRTC连接失败:接口返回空"), I()), f.value = !1;
|
|
209
209
|
}).catch((a) => {
|
|
210
210
|
console.error("❌ WebRTC Offer发送失败:", a), l.value = !1, f.value = !1, I();
|
|
211
211
|
});
|
|
@@ -218,28 +218,28 @@ const Ae = { class: "digital-human-assistant" }, Ne = { class: "placeholder left
|
|
|
218
218
|
const e = { sdpSemantics: "unified-plan" };
|
|
219
219
|
d = new RTCPeerConnection(e), d.addEventListener("track", (t) => {
|
|
220
220
|
t.track.kind === "video" && s.value && (s.value.srcObject = t.streams[0], s.value.onloadedmetadata = async () => {
|
|
221
|
-
s.value && o.value && (r.videoRef.value = s.value, r.canvasRef.value = o.value, await
|
|
221
|
+
s.value && o.value && (r.videoRef.value = s.value, r.canvasRef.value = o.value, await b(), await r.processVideo());
|
|
222
222
|
}, s.value.onresize = () => {
|
|
223
|
-
|
|
223
|
+
b(!0);
|
|
224
224
|
});
|
|
225
225
|
}), d.addEventListener("iceconnectionstatechange", () => {
|
|
226
226
|
switch (console.log("📶 ICE状态变化:", d.iceConnectionState), d.iceConnectionState) {
|
|
227
227
|
case "disconnected":
|
|
228
228
|
case "failed":
|
|
229
229
|
case "closed":
|
|
230
|
-
console.log("📶 ICE连接断开,触发重连"), l.value = !1, f.value = !1, d = null,
|
|
230
|
+
console.log("📶 ICE连接断开,触发重连"), l.value = !1, f.value = !1, d = null, m = "", s.value && (s.value.srcObject = null), H(), L(), I();
|
|
231
231
|
break;
|
|
232
232
|
case "connected":
|
|
233
|
-
console.log("📶 ICE连接成功"),
|
|
233
|
+
console.log("📶 ICE连接成功"), p.value = 0, T(), y(async () => {
|
|
234
234
|
!r.isInitSuccess.value && l.value && await r.reInitWebGPU() && await r.processVideo();
|
|
235
235
|
});
|
|
236
236
|
break;
|
|
237
237
|
}
|
|
238
238
|
}), $e();
|
|
239
239
|
}, Ve = () => {
|
|
240
|
-
O.value = !0,
|
|
240
|
+
O.value = !0, T(), f.value = !1, r.stopProcessing(), H(), L().then(() => {
|
|
241
241
|
setTimeout(() => {
|
|
242
|
-
d && (d.close(), d = null),
|
|
242
|
+
d && (d.close(), d = null), m = "", s.value && (s.value.srcObject = null), l.value = !1, p.value = 0, console.log("✅ 手动断开连接,资源已清理");
|
|
243
243
|
}, 500);
|
|
244
244
|
});
|
|
245
245
|
}, Ce = q.debounce(() => {
|
|
@@ -247,7 +247,7 @@ const Ae = { class: "digital-human-assistant" }, Ne = { class: "placeholder left
|
|
|
247
247
|
const { x: e, y: t } = me();
|
|
248
248
|
v.x = e, v.y = t;
|
|
249
249
|
}
|
|
250
|
-
l.value &&
|
|
250
|
+
l.value && S.value && (H(!0), y(() => b(!0)));
|
|
251
251
|
}, 50);
|
|
252
252
|
return P(r.isInitSuccess, (e) => {
|
|
253
253
|
!e && f.value && q.funcElMessageShowCtrl("🔄 WebGPU初始化失败,正在尝试重连...", "warning");
|
|
@@ -260,31 +260,31 @@ const Ae = { class: "digital-human-assistant" }, Ne = { class: "placeholder left
|
|
|
260
260
|
), P(
|
|
261
261
|
h,
|
|
262
262
|
async (e) => {
|
|
263
|
-
!
|
|
263
|
+
!S.value || !s.value || (await y(), s.value.volume = e ? 0.5 : 1, l.value && (H(), await b()));
|
|
264
264
|
},
|
|
265
265
|
{ immediate: !0, deep: !0 }
|
|
266
266
|
), P(
|
|
267
267
|
[() => l.value, () => i.defaultPlayText],
|
|
268
268
|
async ([e, t], [c]) => {
|
|
269
|
-
e && !c && t &&
|
|
269
|
+
e && !c && t && m && (console.log("✅ 连接成功,自动播放默认文本:", t), await ie(t));
|
|
270
270
|
},
|
|
271
271
|
{ immediate: !1 }
|
|
272
272
|
), P(
|
|
273
273
|
() => i.defaultPlayText,
|
|
274
274
|
async (e) => {
|
|
275
|
-
l.value && e &&
|
|
275
|
+
l.value && e && m && (console.log("✅ 默认文本更新,自动播放:", e), await ie(e));
|
|
276
276
|
},
|
|
277
277
|
{ immediate: !0 }
|
|
278
278
|
), Ue(async () => {
|
|
279
|
-
await
|
|
279
|
+
await y(), await y(), S.value = !0;
|
|
280
280
|
const { x: e, y: t } = me();
|
|
281
281
|
v.x = e, v.y = t, window.addEventListener("resize", Ce);
|
|
282
282
|
}), Oe(() => {
|
|
283
|
-
document.removeEventListener("mousemove", z), document.removeEventListener("mousemove", ne), document.removeEventListener("mouseup", oe), document.removeEventListener("mousemove", ee), document.removeEventListener("mouseup", te), window.removeEventListener("resize", Ce),
|
|
283
|
+
document.removeEventListener("mousemove", z), document.removeEventListener("mousemove", ne), document.removeEventListener("mouseup", oe), document.removeEventListener("mousemove", ee), document.removeEventListener("mouseup", te), window.removeEventListener("resize", Ce), T(), r.stopProcessing(), L(), d && d.close(), s.value && (s.value.srcObject = null);
|
|
284
284
|
}), Ee({
|
|
285
285
|
digitalHumanChat: ie,
|
|
286
286
|
// 播放文本
|
|
287
|
-
digitalHumanInterruptTalk:
|
|
287
|
+
digitalHumanInterruptTalk: L,
|
|
288
288
|
// 打断对话
|
|
289
289
|
isConnected: l,
|
|
290
290
|
// 连接状态
|
|
@@ -292,13 +292,13 @@ const Ae = { class: "digital-human-assistant" }, Ne = { class: "placeholder left
|
|
|
292
292
|
// 连接中状态
|
|
293
293
|
reconnect: I,
|
|
294
294
|
// 手动重连WebRTC
|
|
295
|
-
clearReconnectTimer:
|
|
295
|
+
clearReconnectTimer: T,
|
|
296
296
|
// 停止重连
|
|
297
|
-
currentReconnectTimes:
|
|
297
|
+
currentReconnectTimes: p,
|
|
298
298
|
// 当前重连次数
|
|
299
|
-
isWaitingReconnect:
|
|
299
|
+
isWaitingReconnect: M,
|
|
300
300
|
// 重连冷却状态
|
|
301
|
-
adaptCanvasToContainer:
|
|
301
|
+
adaptCanvasToContainer: b,
|
|
302
302
|
// 手动适配Canvas
|
|
303
303
|
webgpuReInit: r.reInitWebGPU,
|
|
304
304
|
// 手动重连WebGPU
|
|
@@ -308,7 +308,7 @@ const Ae = { class: "digital-human-assistant" }, Ne = { class: "placeholder left
|
|
|
308
308
|
// WebGPU运行状态
|
|
309
309
|
}), (e, t) => {
|
|
310
310
|
const c = je("drag");
|
|
311
|
-
return
|
|
311
|
+
return k(), D("div", {
|
|
312
312
|
class: "draggable-window-container",
|
|
313
313
|
style: ke(xe.value)
|
|
314
314
|
}, [
|
|
@@ -327,7 +327,7 @@ const Ae = { class: "digital-human-assistant" }, Ne = { class: "placeholder left
|
|
|
327
327
|
w(n("div", Je, null, 512), [
|
|
328
328
|
[g, Q.value]
|
|
329
329
|
]),
|
|
330
|
-
Y.value && h.value === "left" ? (
|
|
330
|
+
Y.value && h.value === "left" ? (k(), D("div", {
|
|
331
331
|
key: 0,
|
|
332
332
|
class: J(["sidebar left-sidebar", { pressing: R.value }])
|
|
333
333
|
}, [
|
|
@@ -375,17 +375,17 @@ const Ae = { class: "digital-human-assistant" }, Ne = { class: "placeholder left
|
|
|
375
375
|
n("div", ot, [
|
|
376
376
|
le(e.$slots, "main", {}, void 0, !0)
|
|
377
377
|
]),
|
|
378
|
-
Y.value && h.value === "" ? (
|
|
378
|
+
Y.value && h.value === "" ? (k(), D("div", {
|
|
379
379
|
key: 0,
|
|
380
380
|
ref_key: "dragWindowRef",
|
|
381
381
|
ref: de,
|
|
382
|
-
class: J(["draggable-window", { "draggable-window-shadow": !l.value ||
|
|
382
|
+
class: J(["draggable-window", { "draggable-window-shadow": !l.value || E.value }]),
|
|
383
383
|
style: ke(Me.value),
|
|
384
384
|
onMouseenter: Ie,
|
|
385
385
|
onMouseleave: Pe
|
|
386
386
|
}, [
|
|
387
387
|
n("div", {
|
|
388
|
-
class: J(["window-header", { "window-header-opacity": l.value && !
|
|
388
|
+
class: J(["window-header", { "window-header-opacity": l.value && !E.value }]),
|
|
389
389
|
onMousedown: De
|
|
390
390
|
}, [
|
|
391
391
|
n("div", it, [
|
|
@@ -418,7 +418,7 @@ const Ae = { class: "digital-human-assistant" }, Ne = { class: "placeholder left
|
|
|
418
418
|
])
|
|
419
419
|
], 38)) : $("", !0)
|
|
420
420
|
], 512),
|
|
421
|
-
Y.value && h.value === "right" ? (
|
|
421
|
+
Y.value && h.value === "right" ? (k(), D("div", {
|
|
422
422
|
key: 1,
|
|
423
423
|
class: J(["sidebar right-sidebar", { pressing: R.value }])
|
|
424
424
|
}, [
|
|
@@ -458,7 +458,7 @@ const Ae = { class: "digital-human-assistant" }, Ne = { class: "placeholder left
|
|
|
458
458
|
}, null, 512)
|
|
459
459
|
])
|
|
460
460
|
], 2)) : $("", !0),
|
|
461
|
-
|
|
461
|
+
S.value ? (k(), Ge(ze, {
|
|
462
462
|
key: 2,
|
|
463
463
|
to: we()
|
|
464
464
|
}, [
|
|
@@ -475,7 +475,7 @@ const Ae = { class: "digital-human-assistant" }, Ne = { class: "placeholder left
|
|
|
475
475
|
ref: o,
|
|
476
476
|
class: "digital-video processed-canvas"
|
|
477
477
|
}, null, 512),
|
|
478
|
-
f.value ? (
|
|
478
|
+
f.value ? (k(), D("div", pt)) : $("", !0)
|
|
479
479
|
], 8, ["to"])) : $("", !0)
|
|
480
480
|
], 4);
|
|
481
481
|
};
|