@duxi999/usdp-eacp-conversation 0.0.0-stage → 0.0.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.
package/dist/index.js ADDED
@@ -0,0 +1,581 @@
1
+ import { defineComponent as Xe, computed as G, ref as s, watch as J, onMounted as We, onUnmounted as Ye, resolveComponent as I, resolveDirective as je, openBlock as w, createElementBlock as L, createVNode as i, withCtx as l, createTextVNode as C, unref as _e, createElementVNode as z, toDisplayString as H, createCommentVNode as Fe, withDirectives as Ge, createBlock as Je } from "vue";
2
+ import { Loading as he } from "@element-plus/icons-vue";
3
+ import { ElMessage as K } from "element-plus";
4
+ const Ke = { class: "conversation-session" }, Qe = {
5
+ key: 0,
6
+ class: "status-placeholder"
7
+ }, Ze = {
8
+ key: 1,
9
+ class: "status-placeholder"
10
+ }, et = {
11
+ key: 2,
12
+ class: "status-placeholder"
13
+ }, tt = {
14
+ key: 3,
15
+ class: "iframe-container"
16
+ }, nt = ["src"], at = {
17
+ key: 4,
18
+ class: "status-placeholder"
19
+ }, ot = {
20
+ key: 5,
21
+ class: "status-placeholder"
22
+ }, it = { class: "env-limit-dialog" }, we = 30, st = 2e3, lt = 45, rt = 300 * 1e3, ut = /* @__PURE__ */ Xe({
23
+ name: "UsdpXjgzConversation",
24
+ __name: "UsdpEacpConversation",
25
+ props: {
26
+ appCode: {},
27
+ request: {}
28
+ },
29
+ emits: ["state-change"],
30
+ setup(b, { expose: Q, emit: X }) {
31
+ const o = b, Z = X, ee = G(
32
+ () => o.appCode !== void 0 && o.appCode !== null && o.appCode !== "" ? String(o.appCode) : void 0
33
+ ), n = s("not_exist"), te = s(""), u = s(""), r = s(""), m = s(""), k = s(""), g = s(!1), y = G(() => n.value);
34
+ G(() => r.value || "智能助手");
35
+ const be = G(() => k.value || ee.value || null);
36
+ J(
37
+ [y, () => r.value, be],
38
+ ([e, t, a]) => {
39
+ Z("state-change", {
40
+ status: e,
41
+ nickname: t,
42
+ appCode: a
43
+ });
44
+ },
45
+ { immediate: !0 }
46
+ );
47
+ const x = s(!1), Te = {
48
+ workspace: "工作区",
49
+ knowledge_base: "知识库",
50
+ agent: "智能体",
51
+ skill: "技能构建",
52
+ personal_assistant: "个人助手",
53
+ bid: "智能投标"
54
+ }, ne = s(!1), ae = s(!1), oe = s([]), D = s([]), Ee = s();
55
+ function Se(e) {
56
+ if (!e) return "-";
57
+ try {
58
+ return new Date(e).toLocaleString("zh-CN", {
59
+ year: "numeric",
60
+ month: "2-digit",
61
+ day: "2-digit",
62
+ hour: "2-digit",
63
+ minute: "2-digit"
64
+ });
65
+ } catch {
66
+ return e;
67
+ }
68
+ }
69
+ async function Ie() {
70
+ ne.value = !0, D.value = [];
71
+ try {
72
+ oe.value = await o.request.get("/app-conversation/my-running-environments");
73
+ } catch {
74
+ K.error("获取运行中环境列表失败"), oe.value = [];
75
+ } finally {
76
+ ne.value = !1;
77
+ }
78
+ }
79
+ J(x, (e) => {
80
+ e && Ie();
81
+ });
82
+ function Le(e) {
83
+ D.value = e;
84
+ }
85
+ async function ke() {
86
+ if (D.value.length !== 0) {
87
+ ae.value = !0;
88
+ try {
89
+ const e = D.value.map((a) => ({
90
+ appCode: a.appCode
91
+ })), t = await o.request.post("/app-conversation/batch-stop-environments", { environments: e });
92
+ t.allSuccess || K.warning(`关闭完成:成功 ${t.successCount} 个,失败 ${t.failedCount} 个`), x.value = !1, await Ue();
93
+ } catch {
94
+ K.error("关闭环境失败,请重试");
95
+ } finally {
96
+ ae.value = !1;
97
+ }
98
+ }
99
+ }
100
+ const _ = s(""), ce = s(null), h = s("");
101
+ let U = 0, q = null, M = null, P = null, T = null, V = !1, W = null, Y = 0, j = null;
102
+ function F(e) {
103
+ if (!e) return "";
104
+ try {
105
+ const t = new URL(e);
106
+ return t.searchParams.delete("token"), t.toString();
107
+ } catch {
108
+ return e;
109
+ }
110
+ }
111
+ async function ie() {
112
+ g.value = !0;
113
+ try {
114
+ const e = await o.request.post("/app-conversation/start-environment", {
115
+ appCode: o.appCode
116
+ });
117
+ return e.status !== n.value && (n.value = e.status), e.environmentId && e.environmentId !== m.value && (m.value = e.environmentId), e.proxyUrl && e.proxyUrl !== u.value && (u.value = e.proxyUrl), e;
118
+ } finally {
119
+ g.value = !1;
120
+ }
121
+ }
122
+ async function A() {
123
+ try {
124
+ const e = await o.request.get("/app-conversation/environment-status", {
125
+ appCode: o.appCode
126
+ }, { silent: !0 });
127
+ e.status !== n.value && (n.value = e.status), e.environmentId && e.environmentId !== m.value && (m.value = e.environmentId), e.proxyUrl && e.proxyUrl !== u.value && (u.value = e.proxyUrl);
128
+ } catch {
129
+ }
130
+ }
131
+ async function ve() {
132
+ g.value = !0;
133
+ try {
134
+ await o.request.post("/app-conversation/stop-environment", {
135
+ appCode: o.appCode
136
+ }), n.value = "stopped";
137
+ } finally {
138
+ g.value = !1;
139
+ }
140
+ }
141
+ async function xe() {
142
+ g.value = !0;
143
+ try {
144
+ await o.request.post("/app-conversation/destroy-environment", {
145
+ appCode: o.appCode
146
+ }), n.value = "not_exist", u.value = "", m.value = "";
147
+ } finally {
148
+ g.value = !1;
149
+ }
150
+ }
151
+ async function E() {
152
+ try {
153
+ const e = await o.request.get("/app-conversation/session-info", {
154
+ appCode: o.appCode
155
+ }, { silent: !0 });
156
+ return e.sessionId !== te.value && (te.value = e.sessionId), e.proxyUrl !== u.value && (u.value = e.proxyUrl), e.agentNickname !== r.value && (r.value = e.agentNickname), e.environmentId !== m.value && (m.value = e.environmentId), e.appCode && e.appCode !== k.value && (k.value = e.appCode), e.environmentStatus !== n.value && (n.value = e.environmentStatus), e;
157
+ } catch {
158
+ return;
159
+ }
160
+ }
161
+ function O() {
162
+ c(), Y = 0, W = setInterval(async () => {
163
+ if (Y++, Y > lt) {
164
+ if (await A(), n.value === "running") {
165
+ c(), S(), r.value || E();
166
+ return;
167
+ }
168
+ c(), n.value = "start_failed";
169
+ return;
170
+ }
171
+ await A(), n.value === "running" ? (c(), S(), r.value || E()) : n.value === "start_failed" && c();
172
+ }, st);
173
+ }
174
+ function c() {
175
+ W !== null && (clearInterval(W), W = null), Y = 0;
176
+ }
177
+ function S() {
178
+ N(), j = setInterval(async () => {
179
+ document.visibilityState === "visible" && await A();
180
+ }, rt);
181
+ }
182
+ function N() {
183
+ j !== null && (clearInterval(j), j = null);
184
+ }
185
+ function se() {
186
+ c(), N(), n.value = "not_exist", te.value = "", u.value = "", r.value = "", m.value = "", k.value = "", g.value = !1;
187
+ }
188
+ J(
189
+ [() => n.value, () => u.value],
190
+ ([e, t], [a, d]) => {
191
+ if (!t || e !== "running") {
192
+ _.value = "", h.value = "", v(), $();
193
+ return;
194
+ }
195
+ F(t) !== F(d || "") && pe(t, a === "starting");
196
+ },
197
+ { immediate: !0 }
198
+ ), J(
199
+ () => n.value,
200
+ (e, t) => {
201
+ if (e === "running" && t === "starting") {
202
+ const a = u.value;
203
+ if (!a) return;
204
+ (!_.value || F(a) === F(_.value)) && pe(a, !0);
205
+ }
206
+ }
207
+ );
208
+ async function R() {
209
+ if (g.value) return;
210
+ const e = n.value;
211
+ if (!(e === "running" || e === "starting")) {
212
+ if (e === "start_failed") {
213
+ await A();
214
+ const t = n.value;
215
+ if (t === "running") {
216
+ S();
217
+ return;
218
+ }
219
+ if (t === "starting") {
220
+ O();
221
+ return;
222
+ }
223
+ }
224
+ try {
225
+ await ie(), r.value || E(), n.value === "starting" ? O() : n.value === "running" && S();
226
+ } catch (t) {
227
+ if ((t == null ? void 0 : t.code) === 23010) {
228
+ x.value = !0;
229
+ return;
230
+ }
231
+ }
232
+ }
233
+ }
234
+ async function Ue() {
235
+ await new Promise((e) => setTimeout(e, 500)), await R();
236
+ }
237
+ async function Ae() {
238
+ n.value = "stopping", c(), N(), v(), $();
239
+ try {
240
+ return await ve(), !0;
241
+ } catch {
242
+ return n.value = "running", !1;
243
+ }
244
+ }
245
+ async function Ne() {
246
+ let e = k.value || ee.value;
247
+ return e || (await E(), e = k.value || ee.value), e || void 0;
248
+ }
249
+ function Re() {
250
+ const e = _.value;
251
+ if (!e) return;
252
+ v(), U = 0;
253
+ const t = e.includes("?") ? "&" : "?";
254
+ h.value = `${e}${t}_refresh=${Date.now()}`, re(h.value);
255
+ }
256
+ function $e() {
257
+ de();
258
+ }
259
+ function De() {
260
+ ue("network");
261
+ }
262
+ function de() {
263
+ V && (v(), U = 0);
264
+ }
265
+ function qe(e) {
266
+ try {
267
+ const t = new URL(e);
268
+ return t.pathname = "/test", t.search = "", t.hash = "", t.toString();
269
+ } catch {
270
+ return `${e.split("?")[0].split("#")[0].replace(/\/+$/, "")}/test`;
271
+ }
272
+ }
273
+ async function Me(e) {
274
+ try {
275
+ const t = qe(e), a = new AbortController(), d = setTimeout(() => a.abort(), 5e3), f = await fetch(t, {
276
+ method: "HEAD",
277
+ mode: "cors",
278
+ cache: "no-cache",
279
+ signal: a.signal
280
+ });
281
+ return clearTimeout(d), f.status === 200;
282
+ } catch {
283
+ return !1;
284
+ }
285
+ }
286
+ async function le(e, t = 0) {
287
+ if (await Me(e)) {
288
+ fe(e);
289
+ return;
290
+ }
291
+ t < we ? q = setTimeout(() => {
292
+ le(e, t + 1);
293
+ }, 100) : fe(e);
294
+ }
295
+ function fe(e) {
296
+ _.value = e, h.value = e, re(e);
297
+ }
298
+ function pe(e, t) {
299
+ v(), $(), U = 0, t ? M = setTimeout(() => {
300
+ le(e), M = null;
301
+ }, 1500) : le(e);
302
+ }
303
+ function $() {
304
+ q && (clearTimeout(q), q = null), M && (clearTimeout(M), M = null), T && (clearTimeout(T), T = null);
305
+ }
306
+ function re(e) {
307
+ if (v(), !window.PerformanceObserver) {
308
+ me();
309
+ return;
310
+ }
311
+ V = !0;
312
+ try {
313
+ P = new PerformanceObserver((t) => {
314
+ for (const a of t.getEntries()) {
315
+ const d = a;
316
+ if (a.name !== e && a.name !== h.value) continue;
317
+ const f = d.responseStatus;
318
+ if (f === 502) {
319
+ ue("502");
320
+ return;
321
+ }
322
+ f >= 200 && f < 400 && de();
323
+ }
324
+ }), P.observe({ type: "resource", buffered: !0 });
325
+ } catch {
326
+ }
327
+ me();
328
+ }
329
+ function v() {
330
+ P && (P.disconnect(), P = null), T && (clearTimeout(T), T = null), V = !1;
331
+ }
332
+ function me(e) {
333
+ T = setTimeout(() => {
334
+ V && ue("timeout");
335
+ }, 15e3);
336
+ }
337
+ function ue(e) {
338
+ if (!V) return;
339
+ if (v(), U++, U > we) {
340
+ K.error("应用加载失败,请刷新页面重试");
341
+ return;
342
+ }
343
+ console.warn(`[ConversationSession] 加载失败: ${e === "network" ? "网络错误" : e === "timeout" ? "加载超时" : "应用暂不可用"}, 第 ${U} 次重试`), q = setTimeout(() => {
344
+ if (!_.value) return;
345
+ const a = _.value.includes("?") ? "&" : "?";
346
+ h.value = `${_.value}${a}_retry=${Date.now()}`, re(h.value);
347
+ }, 1e3);
348
+ }
349
+ function ge() {
350
+ document.visibilityState === "visible" && y.value === "running" && A();
351
+ }
352
+ We(async () => {
353
+ document.addEventListener("visibilitychange", ge), await A();
354
+ const e = n.value;
355
+ e === "not_exist" || e === "stopped" ? R() : (await E(), e === "starting" ? O() : e === "running" && S());
356
+ });
357
+ async function Pe() {
358
+ const e = n.value;
359
+ if (n.value = "stopping", c(), N(), v(), $(), e === "running" || e === "starting")
360
+ try {
361
+ await ve();
362
+ } catch {
363
+ }
364
+ se(), n.value = "starting";
365
+ try {
366
+ await ie(), E(), n.value === "starting" ? O() : n.value === "running" && S();
367
+ } catch {
368
+ }
369
+ }
370
+ async function Ve() {
371
+ n.value = "stopping", c(), N(), v(), $();
372
+ try {
373
+ await xe();
374
+ } catch {
375
+ }
376
+ se(), n.value = "starting";
377
+ try {
378
+ await ie(), E(), n.value === "starting" ? O() : n.value === "running" && S();
379
+ } catch {
380
+ }
381
+ }
382
+ function Oe(e, t) {
383
+ var d;
384
+ const a = (d = ce.value) == null ? void 0 : d.contentWindow;
385
+ a && a.postMessage({ target: "dsh", type: e, payload: t }, "*");
386
+ }
387
+ return Q({ start: R, stop: Ae, restart: Pe, rebuild: Ve, refresh: Re, resolveAgentId: Ne, postDshEvent: Oe }), Ye(() => {
388
+ c(), N(), document.removeEventListener("visibilitychange", ge), v(), $(), se();
389
+ }), (e, t) => {
390
+ const a = I("el-button"), d = I("el-empty"), f = I("el-icon"), ye = I("el-result"), B = I("el-table-column"), Be = I("el-table"), ze = I("el-dialog"), He = je("loading");
391
+ return w(), L("div", Ke, [
392
+ y.value === "not_exist" ? (w(), L("div", Qe, [
393
+ i(d, {
394
+ description: `${r.value} 环境未启动`
395
+ }, {
396
+ default: l(() => [
397
+ i(a, {
398
+ type: "primary",
399
+ onClick: R
400
+ }, {
401
+ default: l(() => [...t[2] || (t[2] = [
402
+ C("启动环境", -1)
403
+ ])]),
404
+ _: 1
405
+ })
406
+ ]),
407
+ _: 1
408
+ }, 8, ["description"])
409
+ ])) : y.value === "starting" ? (w(), L("div", Ze, [
410
+ i(f, {
411
+ class: "is-loading",
412
+ size: 48
413
+ }, {
414
+ default: l(() => [
415
+ i(_e(he))
416
+ ]),
417
+ _: 1
418
+ }),
419
+ z("p", null, H(r.value) + " 环境启动中...", 1)
420
+ ])) : y.value === "stopping" ? (w(), L("div", et, [
421
+ i(f, {
422
+ class: "is-loading",
423
+ size: 48
424
+ }, {
425
+ default: l(() => [
426
+ i(_e(he))
427
+ ]),
428
+ _: 1
429
+ }),
430
+ z("p", null, "正在停止 " + H(r.value) + "...", 1)
431
+ ])) : y.value === "running" ? (w(), L("div", tt, [
432
+ z("iframe", {
433
+ ref_key: "iframeRef",
434
+ ref: ce,
435
+ src: h.value,
436
+ class: "conversation-iframe",
437
+ onLoad: $e,
438
+ onError: De
439
+ }, null, 40, nt)
440
+ ])) : y.value === "start_failed" ? (w(), L("div", at, [
441
+ i(ye, {
442
+ icon: "error",
443
+ title: "环境启动失败"
444
+ }, {
445
+ extra: l(() => [
446
+ i(a, {
447
+ type: "primary",
448
+ onClick: R
449
+ }, {
450
+ default: l(() => [...t[3] || (t[3] = [
451
+ C("重新启动", -1)
452
+ ])]),
453
+ _: 1
454
+ })
455
+ ]),
456
+ _: 1
457
+ })
458
+ ])) : y.value === "stopped" ? (w(), L("div", ot, [
459
+ i(ye, {
460
+ icon: "info",
461
+ title: "环境已停止"
462
+ }, {
463
+ extra: l(() => [
464
+ i(a, {
465
+ type: "primary",
466
+ onClick: R
467
+ }, {
468
+ default: l(() => [...t[4] || (t[4] = [
469
+ C("重新启动", -1)
470
+ ])]),
471
+ _: 1
472
+ })
473
+ ]),
474
+ _: 1
475
+ })
476
+ ])) : Fe("", !0),
477
+ i(ze, {
478
+ "model-value": x.value,
479
+ title: "运行中环境数量已达上限",
480
+ width: "720px",
481
+ "close-on-click-modal": !1,
482
+ "onUpdate:modelValue": t[1] || (t[1] = (p) => x.value = p)
483
+ }, {
484
+ footer: l(() => [
485
+ i(a, {
486
+ onClick: t[0] || (t[0] = (p) => x.value = !1)
487
+ }, {
488
+ default: l(() => [...t[6] || (t[6] = [
489
+ C("暂不关闭", -1)
490
+ ])]),
491
+ _: 1
492
+ }),
493
+ i(a, {
494
+ type: "primary",
495
+ loading: ae.value,
496
+ disabled: D.value.length === 0,
497
+ onClick: ke
498
+ }, {
499
+ default: l(() => [...t[7] || (t[7] = [
500
+ C(" 关闭已选环境 ", -1)
501
+ ])]),
502
+ _: 1
503
+ }, 8, ["loading", "disabled"])
504
+ ]),
505
+ default: l(() => [
506
+ z("div", it, [
507
+ t[5] || (t[5] = z("p", { class: "env-limit-dialog__tip" }, " 您的运行中智能会话数量已达上限,请选择需要关闭的会话后重试。 ", -1)),
508
+ Ge((w(), Je(Be, {
509
+ ref_key: "envLimitTableRef",
510
+ ref: Ee,
511
+ data: oe.value,
512
+ "max-height": "520",
513
+ "header-cell-style": { textAlign: "center" },
514
+ onSelectionChange: Le
515
+ }, {
516
+ default: l(() => [
517
+ i(B, {
518
+ type: "selection",
519
+ width: "42"
520
+ }),
521
+ i(B, {
522
+ label: "场景类型",
523
+ "min-width": "100"
524
+ }, {
525
+ default: l(({ row: p }) => [
526
+ C(H(Te[p.sceneType] || p.sceneType), 1)
527
+ ]),
528
+ _: 1
529
+ }),
530
+ i(B, {
531
+ prop: "sceneName",
532
+ label: "场景名称",
533
+ "min-width": "150",
534
+ "show-overflow-tooltip": ""
535
+ }),
536
+ i(B, {
537
+ label: "智能体",
538
+ "min-width": "130",
539
+ "show-overflow-tooltip": ""
540
+ }, {
541
+ default: l(({ row: p }) => [
542
+ C(H(p.agentNickname || "-"), 1)
543
+ ]),
544
+ _: 1
545
+ }),
546
+ i(B, {
547
+ label: "创建时间",
548
+ "min-width": "170"
549
+ }, {
550
+ default: l(({ row: p }) => [
551
+ C(H(Se(p.createdAt)), 1)
552
+ ]),
553
+ _: 1
554
+ })
555
+ ]),
556
+ _: 1
557
+ }, 8, ["data"])), [
558
+ [He, ne.value]
559
+ ])
560
+ ])
561
+ ]),
562
+ _: 1
563
+ }, 8, ["model-value"])
564
+ ]);
565
+ };
566
+ }
567
+ }), ct = (b, Q) => {
568
+ const X = b.__vccOpts || b;
569
+ for (const [o, Z] of Q)
570
+ X[o] = Z;
571
+ return X;
572
+ }, Ce = /* @__PURE__ */ ct(ut, [["__scopeId", "data-v-e1586830"]]), vt = "usdp-eacp-conversation", mt = {
573
+ install(b) {
574
+ b.component(vt, Ce), b.component("UsdpEacpConversation", Ce);
575
+ }
576
+ };
577
+ export {
578
+ Ce as ConversationSession,
579
+ mt as default
580
+ };
581
+ //# sourceMappingURL=index.js.map