sooyie-pgss 0.0.6 → 0.0.7

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.
@@ -0,0 +1,266 @@
1
+ import { defineComponent as H, ref as r, resolveComponent as k, openBlock as l, createElementBlock as o, createElementVNode as a, toDisplayString as i, createBlock as V, withCtx as b, createTextVNode as C, createCommentVNode as P, Fragment as _, renderList as A, normalizeClass as j, withDirectives as G, vShow as J, createVNode as w, nextTick as Q } from "vue";
2
+ import { ElMessage as U } from "element-plus";
3
+ import { useI18n as W } from "vue-i18n";
4
+ import { a as X } from "./index-MA9jC8ZF.mjs";
5
+ import { u as Y } from "./index-CeyTmMNJ.mjs";
6
+ import { useUserStore as Z, clearEmpty as ee, request as te } from "jmash-core";
7
+ import { _ as se } from "./_plugin-vue_export-helper-CHgC5LLL.mjs";
8
+ class ne {
9
+ // 发送对话消息
10
+ chat(c) {
11
+ return c.tenant = Z().user.tenant, ee(c), te({
12
+ url: "/v1/pgss/message/chat",
13
+ method: "post",
14
+ data: c
15
+ });
16
+ }
17
+ }
18
+ const ae = new ne(), le = { class: "chat-container" }, oe = { class: "chat-header" }, ie = { class: "chat-header__title" }, re = {
19
+ key: 0,
20
+ class: "chat-empty"
21
+ }, ce = { class: "chat-empty__title" }, ue = { class: "chat-empty__desc" }, de = {
22
+ key: 1,
23
+ class: "message-list"
24
+ }, pe = { class: "message__avatar" }, he = { class: "message__bubble" }, _e = {
25
+ key: 0,
26
+ class: "message__thinking"
27
+ }, ge = ["onClick"], ve = { class: "message__thinking-toggle" }, me = {
28
+ key: 1,
29
+ class: "message__pending"
30
+ }, fe = {
31
+ key: 2,
32
+ class: "message__answer"
33
+ }, ye = { class: "chat-input" }, ke = { class: "chat-input__box" }, be = { class: "chat-input__toolbar" }, we = { class: "chat-input__selectors" }, $e = /* @__PURE__ */ H({
34
+ __name: "index",
35
+ setup(D) {
36
+ const { t: c } = W(), u = r([]), p = r(""), h = r(!1), O = r();
37
+ let g = 0;
38
+ const v = r(), m = r([]), $ = r(!1), f = r(), I = r([]), y = r(!1);
39
+ let N = !1;
40
+ function E() {
41
+ return `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
42
+ }
43
+ async function T() {
44
+ await Q();
45
+ const e = O.value;
46
+ e && (e.scrollTop = e.scrollHeight);
47
+ }
48
+ function L(e) {
49
+ e.thinkingOpen = !e.thinkingOpen;
50
+ }
51
+ function q(e) {
52
+ $.value = !0;
53
+ const t = {
54
+ curPage: 1,
55
+ pageSize: 100,
56
+ likeIdentityName: e || void 0
57
+ };
58
+ Y.findPage(t).then(({ data: d }) => {
59
+ m.value = (d.results ?? []).filter((n) => !!n.thirdUserId).map((n) => ({
60
+ value: n.thirdUserId,
61
+ label: n.identityName ? `${n.identityName}(${n.thirdUserId})` : n.thirdUserId
62
+ }));
63
+ }).catch((d) => {
64
+ console.error("[pgss-chat] 用户列表加载失败:", d), m.value = [];
65
+ }).finally(() => {
66
+ $.value = !1;
67
+ });
68
+ }
69
+ function z() {
70
+ N || y.value || (y.value = !0, X.findList().then(({ data: e }) => {
71
+ I.value = e.results ?? [], N = !0;
72
+ }).catch((e) => {
73
+ console.error("[pgss-chat] 应用列表加载失败:", e), I.value = [];
74
+ }).finally(() => {
75
+ y.value = !1;
76
+ }));
77
+ }
78
+ function K(e) {
79
+ e && !m.value.length && q("");
80
+ }
81
+ function M(e) {
82
+ e && z();
83
+ }
84
+ function F(e) {
85
+ e.key !== "Enter" || e.shiftKey || e.isComposing || (e.preventDefault(), R());
86
+ }
87
+ async function R() {
88
+ const e = p.value.trim();
89
+ if (!e || h.value)
90
+ return;
91
+ if (!v.value) {
92
+ U.warning(c("chat.userRequired"));
93
+ return;
94
+ }
95
+ if (!f.value) {
96
+ U.warning(c("chat.appTypeRequired"));
97
+ return;
98
+ }
99
+ g += 1, u.value.push({
100
+ id: `user-${g}`,
101
+ role: "user",
102
+ content: e
103
+ }), g += 1, u.value.push({
104
+ id: `ai-${g}`,
105
+ role: "ai",
106
+ content: "",
107
+ pending: !0
108
+ });
109
+ const t = u.value[u.value.length - 1];
110
+ p.value = "", h.value = !0, T();
111
+ const d = {
112
+ requestId: E(),
113
+ appId: f.value,
114
+ thirdUserId: v.value,
115
+ content: e
116
+ };
117
+ try {
118
+ const { data: n } = await ae.chat(d);
119
+ if (t.pending = !1, (n == null ? void 0 : n.success) === !1) {
120
+ t.content = c("chat.failAnswer"), U.error(c("chat.sendFail"));
121
+ return;
122
+ }
123
+ t.thinking = (n == null ? void 0 : n.promptOutput) ?? "", t.thinkingOpen = !0, t.content = (n == null ? void 0 : n.contentAnswer) ?? "";
124
+ } catch (n) {
125
+ console.error("[pgss-chat] 发送对话消息失败:", n), t.pending = !1, t.content = c("chat.failAnswer");
126
+ } finally {
127
+ h.value = !1, T();
128
+ }
129
+ }
130
+ function x() {
131
+ u.value = [];
132
+ }
133
+ return (e, t) => {
134
+ const d = k("el-button"), n = k("el-input"), S = k("el-option"), B = k("el-select");
135
+ return l(), o("div", le, [
136
+ a("div", oe, [
137
+ a("span", ie, i(e.$t("chat.name")), 1),
138
+ u.value.length ? (l(), V(d, {
139
+ key: 0,
140
+ text: "",
141
+ class: "chat-header__action",
142
+ onClick: x
143
+ }, {
144
+ default: b(() => [
145
+ C(i(e.$t("chat.clear")), 1)
146
+ ]),
147
+ _: 1
148
+ })) : P("", !0)
149
+ ]),
150
+ a("div", {
151
+ ref_key: "messageBodyRef",
152
+ ref: O,
153
+ class: "chat-body"
154
+ }, [
155
+ u.value.length ? (l(), o("div", de, [
156
+ (l(!0), o(_, null, A(u.value, (s) => (l(), o("div", {
157
+ key: s.id,
158
+ class: j(["message", s.role === "user" ? "message--user" : "message--ai"])
159
+ }, [
160
+ a("div", pe, i(s.role === "user" ? e.$t("chat.meAvatar") : "AI"), 1),
161
+ a("div", he, [
162
+ s.role === "user" ? (l(), o(_, { key: 0 }, [
163
+ C(i(s.content), 1)
164
+ ], 64)) : (l(), o(_, { key: 1 }, [
165
+ s.thinking ? (l(), o("div", _e, [
166
+ a("div", {
167
+ class: "message__thinking-head",
168
+ onClick: (Ie) => L(s)
169
+ }, [
170
+ t[4] || (t[4] = a("span", { class: "message__thinking-dot" }, null, -1)),
171
+ a("span", null, i(e.$t("chat.thinking")), 1),
172
+ a("span", ve, i(s.thinkingOpen ? e.$t("chat.collapse") : e.$t("chat.expand")), 1)
173
+ ], 8, ge),
174
+ G(a("div", { class: "message__thinking-body" }, i(s.thinking), 513), [
175
+ [J, s.thinkingOpen]
176
+ ])
177
+ ])) : P("", !0),
178
+ s.pending ? (l(), o("div", me, [
179
+ t[5] || (t[5] = a("span", { class: "message__pending-dot" }, null, -1)),
180
+ t[6] || (t[6] = a("span", { class: "message__pending-dot" }, null, -1)),
181
+ t[7] || (t[7] = a("span", { class: "message__pending-dot" }, null, -1)),
182
+ a("span", null, i(e.$t("chat.generating")), 1)
183
+ ])) : (l(), o("div", fe, i(s.content), 1))
184
+ ], 64))
185
+ ])
186
+ ], 2))), 128))
187
+ ])) : (l(), o("div", re, [
188
+ t[3] || (t[3] = a("div", { class: "chat-empty__logo" }, "AI", -1)),
189
+ a("p", ce, i(e.$t("chat.welcomeTitle")), 1),
190
+ a("p", ue, i(e.$t("chat.welcomeDesc")), 1)
191
+ ]))
192
+ ], 512),
193
+ a("div", ye, [
194
+ a("div", ke, [
195
+ w(n, {
196
+ modelValue: p.value,
197
+ "onUpdate:modelValue": t[0] || (t[0] = (s) => p.value = s),
198
+ type: "textarea",
199
+ autosize: { minRows: 2, maxRows: 6 },
200
+ resize: "none",
201
+ class: "chat-input__textarea",
202
+ placeholder: e.$t("chat.inputPlaceholder"),
203
+ onKeydown: F
204
+ }, null, 8, ["modelValue", "placeholder"]),
205
+ a("div", be, [
206
+ a("div", we, [
207
+ w(B, {
208
+ modelValue: v.value,
209
+ "onUpdate:modelValue": t[1] || (t[1] = (s) => v.value = s),
210
+ filterable: "",
211
+ remote: "",
212
+ "reserve-keyword": "",
213
+ "remote-method": q,
214
+ loading: $.value,
215
+ placeholder: e.$t("chat.userPlaceholder"),
216
+ class: "chat-input__select",
217
+ onVisibleChange: K
218
+ }, {
219
+ default: b(() => [
220
+ (l(!0), o(_, null, A(m.value, (s) => (l(), V(S, {
221
+ key: s.value,
222
+ label: s.label,
223
+ value: s.value
224
+ }, null, 8, ["label", "value"]))), 128))
225
+ ]),
226
+ _: 1
227
+ }, 8, ["modelValue", "loading", "placeholder"]),
228
+ w(B, {
229
+ modelValue: f.value,
230
+ "onUpdate:modelValue": t[2] || (t[2] = (s) => f.value = s),
231
+ loading: y.value,
232
+ placeholder: e.$t("chat.appTypePlaceholder"),
233
+ class: "chat-input__select",
234
+ onVisibleChange: M
235
+ }, {
236
+ default: b(() => [
237
+ (l(!0), o(_, null, A(I.value, (s) => (l(), V(S, {
238
+ key: s.appId,
239
+ label: s.appName,
240
+ value: s.appId
241
+ }, null, 8, ["label", "value"]))), 128))
242
+ ]),
243
+ _: 1
244
+ }, 8, ["modelValue", "loading", "placeholder"])
245
+ ]),
246
+ w(d, {
247
+ class: "chat-input__send",
248
+ loading: h.value,
249
+ disabled: !p.value.trim() || h.value,
250
+ onClick: R
251
+ }, {
252
+ default: b(() => [
253
+ C(i(e.$t("chat.send")), 1)
254
+ ]),
255
+ _: 1
256
+ }, 8, ["loading", "disabled"])
257
+ ])
258
+ ])
259
+ ])
260
+ ]);
261
+ };
262
+ }
263
+ }), qe = /* @__PURE__ */ se($e, [["__scopeId", "data-v-ea6d4ba5"]]);
264
+ export {
265
+ qe as default
266
+ };