@duxi999/usdp-eacp-conversation 0.0.0-stage → 0.0.2

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