@gindow/vue 1.0.1 → 1.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/README.md +6 -6
- package/dist/resolver.cjs +1 -0
- package/dist/resolver.d.ts +15 -0
- package/dist/resolver.mjs +16 -0
- package/dist/style.css +1 -2
- package/dist/vue.cjs +1 -0
- package/dist/vue.d.ts +74 -258
- package/dist/vue.mjs +286 -0
- package/package.json +11 -52
- package/src/components/VueIcon.vue +43 -2
- package/src/index.ts +17 -9
- package/src/libs/auto-imports.d.ts +79 -0
- package/src/locale/index.ts +1 -1
- package/src/resolver.ts +19 -0
- package/src/style.css +9 -16
- package/src/utils/index.ts +0 -7
- package/dist/index.cjs +0 -2
- package/dist/index.mjs +0 -451
- package/src/hooks/useChat.ts +0 -135
- package/src/hooks/useNanoid.ts +0 -9
- package/src/hooks/useUpload.ts +0 -59
- package/src/types/chat.ts +0 -62
- package/src/utils/datetime.ts +0 -42
- package/src/utils/download.ts +0 -11
- package/src/utils/get.ts +0 -10
- package/src/utils/platform.ts +0 -38
- package/src/utils/request.ts +0 -146
package/dist/index.mjs
DELETED
|
@@ -1,451 +0,0 @@
|
|
|
1
|
-
import { computed as e, createBlock as t, defineComponent as n, h as r, inject as i, normalizeStyle as a, onBeforeUnmount as o, onMounted as s, openBlock as c, provide as l, reactive as u, ref as d, unref as f, useCssVars as p } from "vue";
|
|
2
|
-
import m from "js-cookie";
|
|
3
|
-
import h from "axios";
|
|
4
|
-
import g from "dayjs";
|
|
5
|
-
import { Icon as _ } from "@iconify/vue";
|
|
6
|
-
import { nanoid as v } from "nanoid";
|
|
7
|
-
import { customAlphabet as y } from "nanoid/non-secure";
|
|
8
|
-
import b from "file-type-checker";
|
|
9
|
-
import x from "heic2any";
|
|
10
|
-
import S from "compressorjs";
|
|
11
|
-
//#region src/locale/zh-CN.ts
|
|
12
|
-
var C = {
|
|
13
|
-
cancel: "取消",
|
|
14
|
-
confirm: "确认",
|
|
15
|
-
empty: { noData: "暂无数据" },
|
|
16
|
-
dialog: {
|
|
17
|
-
tip: "操作提示",
|
|
18
|
-
confirm: "操作确认"
|
|
19
|
-
}
|
|
20
|
-
}, w = {
|
|
21
|
-
cancel: "Cancel",
|
|
22
|
-
confirm: "Confirm",
|
|
23
|
-
empty: { noData: "No data" },
|
|
24
|
-
dialog: {
|
|
25
|
-
tip: "Tip",
|
|
26
|
-
confirm: "Confirm"
|
|
27
|
-
}
|
|
28
|
-
}, T = () => {
|
|
29
|
-
let e = ["en", "zh-CN"], t = localStorage.getItem("locale"), n = navigator.language;
|
|
30
|
-
return t && e.includes(t) ? t : n && e.includes(n) ? n : n && e.includes(n.split("-")[0]) ? n.split("-")[0] : e[0] ?? "zh-CN";
|
|
31
|
-
}, E = Symbol("vue-go-locale"), D = d(T()), O = u({
|
|
32
|
-
en: w,
|
|
33
|
-
"zh-CN": C
|
|
34
|
-
}), k = (e) => {
|
|
35
|
-
if (e?.locale && (D.value = e.locale), e?.messages) for (let [t, n] of Object.entries(e.messages)) O[t] = n;
|
|
36
|
-
return l(E, {
|
|
37
|
-
locale: D,
|
|
38
|
-
messages: O
|
|
39
|
-
}), {
|
|
40
|
-
locale: D,
|
|
41
|
-
messages: O
|
|
42
|
-
};
|
|
43
|
-
}, A = () => {
|
|
44
|
-
let e = i(E, void 0), t = e?.locale ?? D, n = e?.messages ?? O;
|
|
45
|
-
return {
|
|
46
|
-
locale: t,
|
|
47
|
-
t: (e, r) => {
|
|
48
|
-
let i = n[t.value], a = e.replace(/\[(\d+)]/g, ".$1").split("."), o = i;
|
|
49
|
-
for (let t of a) if (o = o?.[t], o === void 0) return e;
|
|
50
|
-
let s = o ?? e;
|
|
51
|
-
return r && typeof s == "string" && (s = s.replace(/\{(\w+)\}/g, (e, t) => r[t] === void 0 ? `{${t}}` : String(r[t]))), s;
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
}, j = (e) => D.value = e, M = () => D.value, N = class e {
|
|
55
|
-
static get userAgent() {
|
|
56
|
-
return window.navigator.userAgent.toLowerCase();
|
|
57
|
-
}
|
|
58
|
-
static get isFlutter() {
|
|
59
|
-
return e.userAgent.match(/flutter/i) !== null;
|
|
60
|
-
}
|
|
61
|
-
static get isFlutterIOS() {
|
|
62
|
-
return e.isFlutter && e.isIOS;
|
|
63
|
-
}
|
|
64
|
-
static get isWeb() {
|
|
65
|
-
return window.matchMedia("(min-width: 992px)").matches;
|
|
66
|
-
}
|
|
67
|
-
static get isMobile() {
|
|
68
|
-
return e.userAgent.match(/(phone|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i) !== null;
|
|
69
|
-
}
|
|
70
|
-
static get isIOS() {
|
|
71
|
-
return e.userAgent.match(/iphone|ipad|ipod|ios/i) !== null;
|
|
72
|
-
}
|
|
73
|
-
static get isWechat() {
|
|
74
|
-
return e.userAgent.match(/MicroMessenger/i) !== null;
|
|
75
|
-
}
|
|
76
|
-
static get isWxwork() {
|
|
77
|
-
return e.userAgent.match(/MicroMessenger/i) !== null && e.userAgent.match(/wxwork/i) !== null;
|
|
78
|
-
}
|
|
79
|
-
static get isMiniprogram() {
|
|
80
|
-
return e.userAgent.match(/MicroMessenger/i) !== null && e.userAgent.match(/miniprogram/i) !== null;
|
|
81
|
-
}
|
|
82
|
-
}, P = (e) => {
|
|
83
|
-
let t = { ...e };
|
|
84
|
-
return typeof t?.search == "string" ? t : (t?.search && (t.search = Object.keys(t.search).filter((e) => t.search[e] !== null && t.search[e] !== "").map((e) => e + ":" + t.search[e]).join(";")), t?.searchFields && (t.searchFields = Object.keys(t.searchFields).filter((e) => t.searchFields[e]).map((e) => e + ":" + t.searchFields[e]).join(";")), t);
|
|
85
|
-
}, F = {
|
|
86
|
-
baseURL: "",
|
|
87
|
-
publicKey: "",
|
|
88
|
-
headers: { Accept: "application/json" },
|
|
89
|
-
instance: null,
|
|
90
|
-
accessToken: "accessToken",
|
|
91
|
-
init(e = {}) {
|
|
92
|
-
this.baseURL = e.baseURL ?? "", this.publicKey = e.publicKey ?? "";
|
|
93
|
-
let t = () => {
|
|
94
|
-
this.delToken(), location.reload();
|
|
95
|
-
};
|
|
96
|
-
this.instance = h.create({ baseURL: this.baseURL }), this.instance.interceptors.request.use((e) => {
|
|
97
|
-
let t = localStorage.getItem("locale");
|
|
98
|
-
return t && (e.headers["Accept-Language"] = t), e;
|
|
99
|
-
}), this.instance.interceptors.response.use((e) => e.config.responseType === "blob" ? e : e.data.code === 401 ? t() : e.data.code === 200 ? e.data : Promise.reject(e.data), ({ response: e }) => Promise.reject(e.data));
|
|
100
|
-
},
|
|
101
|
-
setToken(e, t = {}) {
|
|
102
|
-
t = {
|
|
103
|
-
...t,
|
|
104
|
-
domain: "." + location.hostname
|
|
105
|
-
}, m.set(this.accessToken, e, t);
|
|
106
|
-
},
|
|
107
|
-
getToken() {
|
|
108
|
-
return m.get(this.accessToken) || "";
|
|
109
|
-
},
|
|
110
|
-
delToken() {
|
|
111
|
-
m.remove(this.accessToken, { domain: "." + location.hostname });
|
|
112
|
-
},
|
|
113
|
-
get(e, t, n = !1) {
|
|
114
|
-
return this.request({
|
|
115
|
-
method: "GET",
|
|
116
|
-
url: e,
|
|
117
|
-
params: t
|
|
118
|
-
}, n);
|
|
119
|
-
},
|
|
120
|
-
put(e, t, n = !1) {
|
|
121
|
-
return this.request({
|
|
122
|
-
method: "PUT",
|
|
123
|
-
url: e,
|
|
124
|
-
data: t
|
|
125
|
-
}, n);
|
|
126
|
-
},
|
|
127
|
-
patch(e, t, n = !1) {
|
|
128
|
-
return this.request({
|
|
129
|
-
method: "PATCH",
|
|
130
|
-
url: e,
|
|
131
|
-
data: t
|
|
132
|
-
}, n);
|
|
133
|
-
},
|
|
134
|
-
delete(e, t, n = !1) {
|
|
135
|
-
return this.request({
|
|
136
|
-
method: "DELETE",
|
|
137
|
-
url: e,
|
|
138
|
-
params: t
|
|
139
|
-
}, n);
|
|
140
|
-
},
|
|
141
|
-
post(e, t, n = !1) {
|
|
142
|
-
return this.request({
|
|
143
|
-
method: "POST",
|
|
144
|
-
url: e,
|
|
145
|
-
data: t
|
|
146
|
-
}, n);
|
|
147
|
-
},
|
|
148
|
-
blob(e, t, n = !1) {
|
|
149
|
-
return this.request({
|
|
150
|
-
method: "GET",
|
|
151
|
-
url: e,
|
|
152
|
-
params: t,
|
|
153
|
-
responseType: "blob"
|
|
154
|
-
}, n);
|
|
155
|
-
},
|
|
156
|
-
request(e, t = !1) {
|
|
157
|
-
let n = e.headers ?? this.headers;
|
|
158
|
-
return t && (n.Authorization = "Bearer " + this.getToken()), e.params &&= P(e.params), this.instance({
|
|
159
|
-
...e,
|
|
160
|
-
headers: n
|
|
161
|
-
});
|
|
162
|
-
},
|
|
163
|
-
async download(e, t, n, r = !1) {
|
|
164
|
-
let i = await this.blob(e, t, r);
|
|
165
|
-
if (N.isFlutter) return i;
|
|
166
|
-
let a = () => {
|
|
167
|
-
let e = i.headers["content-disposition"].split("filename*=")[1].split(";")[0].trim();
|
|
168
|
-
return decodeURIComponent(e.replace(/^UTF-8''/i, ""));
|
|
169
|
-
}, o = document.createElement("a");
|
|
170
|
-
return o.href = window.URL.createObjectURL(i.data), o.download = n ?? a(), o.click(), i;
|
|
171
|
-
},
|
|
172
|
-
async upload(e, t = {}) {
|
|
173
|
-
let n = {
|
|
174
|
-
...this.headers,
|
|
175
|
-
"Content-Type": "multipart/form-data"
|
|
176
|
-
};
|
|
177
|
-
return this.instance.post(e, t, { headers: n });
|
|
178
|
-
},
|
|
179
|
-
sse(e, t) {
|
|
180
|
-
let n = t ? Object.keys(t).map((e) => e + "=" + t[e]).join("&") : "";
|
|
181
|
-
return new EventSource(this.baseURL + "/" + e + "?" + n);
|
|
182
|
-
},
|
|
183
|
-
setHeader(e, t) {
|
|
184
|
-
this.headers[e] = t;
|
|
185
|
-
},
|
|
186
|
-
delHeader(e) {
|
|
187
|
-
delete this.headers[e];
|
|
188
|
-
}
|
|
189
|
-
}, I = class {
|
|
190
|
-
url;
|
|
191
|
-
auth;
|
|
192
|
-
constructor(e, t = !1) {
|
|
193
|
-
this.url = e, this.auth = t;
|
|
194
|
-
}
|
|
195
|
-
select = (e) => F.get(this.url, e, this.auth);
|
|
196
|
-
create = (e) => F.post(this.url, e, this.auth);
|
|
197
|
-
find = (e, t) => F.get(this.url + "/" + e, t, this.auth);
|
|
198
|
-
update = (e, t) => F.patch(this.url + "/" + e, t, this.auth);
|
|
199
|
-
delete = (e, t) => F.delete(this.url + "/" + e, t, this.auth);
|
|
200
|
-
async get(e) {
|
|
201
|
-
e.size = 1;
|
|
202
|
-
let t = await this.select(e);
|
|
203
|
-
return t.data = t.data[0] || {}, t;
|
|
204
|
-
}
|
|
205
|
-
}, L = (e, t, n) => {
|
|
206
|
-
if (e == null) return n;
|
|
207
|
-
let r = Array.isArray(t) ? t : t.replace(/\[(\d+)]/g, ".$1").split(".").filter(Boolean), i = e;
|
|
208
|
-
for (let e of r) if (i = i?.[e], i === void 0) return n;
|
|
209
|
-
return i;
|
|
210
|
-
}, R = (e, t) => {
|
|
211
|
-
let n = URL.createObjectURL(e), r = document.createElement("a");
|
|
212
|
-
r.href = n, r.download = t, r.style.display = "none", document.body.appendChild(r), r.click(), document.body.removeChild(r), URL.revokeObjectURL(n);
|
|
213
|
-
}, z = class {
|
|
214
|
-
static config = {};
|
|
215
|
-
static set = (e) => this.config = e;
|
|
216
|
-
static id = (e = "") => e.slice(-12).toUpperCase();
|
|
217
|
-
static date = (e = "") => e.substring(0, 10) + " " + e.substring(11, 19);
|
|
218
|
-
static idcard = (e = "") => e ? e.substring(0, 6) + "****" + e.substring(14) : "";
|
|
219
|
-
static phone = (e = "", t = !1) => t || !e ? e : e.substring(0, 3) + "****" + e.substring(e.length - 4);
|
|
220
|
-
static email = (e = "") => {
|
|
221
|
-
let [t, n] = e.split("@");
|
|
222
|
-
return !t || !n ? e : `${t.length > 2 ? t[0] + "****" + t[t.length - 1] : t}@${n}`;
|
|
223
|
-
};
|
|
224
|
-
static bankcard = (e = "") => e.substring(0, 4) + "****" + e.substring(e.length - 4);
|
|
225
|
-
static url = (e = "") => e.replace(/:\/\//g, ":##").replace(/\/+/g, "/").replace(/:##/g, "://");
|
|
226
|
-
static price = (e = 0, t) => {
|
|
227
|
-
let { locale: n, decimals: r, currency: i } = this.config, a = typeof e == "string" ? parseFloat(e) : e;
|
|
228
|
-
return new Intl.NumberFormat(n, {
|
|
229
|
-
style: "currency",
|
|
230
|
-
currency: t ?? i ?? "CNY",
|
|
231
|
-
minimumFractionDigits: r ?? 2,
|
|
232
|
-
maximumFractionDigits: r ?? 2
|
|
233
|
-
}).format(a / 100);
|
|
234
|
-
};
|
|
235
|
-
static currency = (e = 0, t) => this.price(e, t);
|
|
236
|
-
}, B = class e {
|
|
237
|
-
static country = "";
|
|
238
|
-
static set = (e) => this.country = e;
|
|
239
|
-
static get phone_pattern() {
|
|
240
|
-
return this.country.toUpperCase() === "CN" ? /([1][3,4,5,6,7,8,9][0-9]{9})$/ : /^(?:\+?[1-9]\d{7,14}|\d{6,11})$/;
|
|
241
|
-
}
|
|
242
|
-
static email_pattern = /^([a-zA-Z0-9_\.-]+)@([\da-zA-Z\.-]+)\.([a-zA-Z\.]{2,6})$/;
|
|
243
|
-
static idcard_pattern = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
|
|
244
|
-
static cname_pattern = /^(?:[\u4e00-\u9fa5·]{2,16})$/;
|
|
245
|
-
static password_pattern = /^(?![A-Za-z]+$)(?![0-9]+$)(?![^A-Za-z0-9]+$).{8,20}$/;
|
|
246
|
-
static phone = (t) => e.phone_pattern.test(t);
|
|
247
|
-
static email = (t) => e.email_pattern.test(t);
|
|
248
|
-
static idcard = (t) => e.idcard_pattern.test(t);
|
|
249
|
-
static cname = (t) => e.cname_pattern.test(t);
|
|
250
|
-
}, V = class e {
|
|
251
|
-
static dayjs = g;
|
|
252
|
-
static s(t, n = "/") {
|
|
253
|
-
return e.dayjs(t).format("YYYY/MM/DD HH:mm:ss".replace(/\//g, n));
|
|
254
|
-
}
|
|
255
|
-
static m(t, n = "/") {
|
|
256
|
-
return e.dayjs(t).format("YYYY/MM/DD HH:mm".replace(/\//g, n));
|
|
257
|
-
}
|
|
258
|
-
static h(t, n = "/") {
|
|
259
|
-
return e.dayjs(t).format("YYYY/MM/DD HH".replace(/\//g, n));
|
|
260
|
-
}
|
|
261
|
-
static d(t, n = "/") {
|
|
262
|
-
return e.dayjs(t).format("YYYY/MM/DD".replace(/\//g, n));
|
|
263
|
-
}
|
|
264
|
-
static M(t, n = "/") {
|
|
265
|
-
return e.dayjs(t).format("YYYY/MM".replace(/\//g, n));
|
|
266
|
-
}
|
|
267
|
-
static y(t) {
|
|
268
|
-
return e.dayjs(t).format("YYYY");
|
|
269
|
-
}
|
|
270
|
-
static date(t, n = "/") {
|
|
271
|
-
return e.dayjs(t).format("YYYY/MM/DD".replace(/\//g, n));
|
|
272
|
-
}
|
|
273
|
-
static time(t) {
|
|
274
|
-
return e.dayjs(t).format("HH:mm");
|
|
275
|
-
}
|
|
276
|
-
static format(t, n = "YYYY/MM/DD HH:mm:ss") {
|
|
277
|
-
return e.dayjs(t).format(n);
|
|
278
|
-
}
|
|
279
|
-
}, H = 768, U = () => {
|
|
280
|
-
let t = d(typeof window < "u" ? window.matchMedia(`(min-width: ${H}px)`).matches : !0), n, r = (e) => t.value = e.matches;
|
|
281
|
-
s(() => {
|
|
282
|
-
typeof window > "u" || (n = window.matchMedia(`(min-width: ${H}px)`), t.value = n.matches, n.addEventListener("change", r));
|
|
283
|
-
}), o(() => n?.removeEventListener("change", r));
|
|
284
|
-
let i = e(() => t.value);
|
|
285
|
-
return {
|
|
286
|
-
isMobile: e(() => !t.value),
|
|
287
|
-
isDesktop: i
|
|
288
|
-
};
|
|
289
|
-
}, W = (e) => {
|
|
290
|
-
let t = d(0), n = d(!1), r = (t = {}) => new Promise((r, a) => {
|
|
291
|
-
n.value || (n.value = !0, e(t).then(() => {
|
|
292
|
-
i(), r(!0);
|
|
293
|
-
}).catch((e) => a(e)).finally(() => n.value = !1));
|
|
294
|
-
}), i = () => {
|
|
295
|
-
t.value = 60;
|
|
296
|
-
let e = setInterval(() => {
|
|
297
|
-
t.value--, t.value || clearTimeout(e);
|
|
298
|
-
}, 1e3);
|
|
299
|
-
};
|
|
300
|
-
return {
|
|
301
|
-
waiting: t,
|
|
302
|
-
send: r
|
|
303
|
-
};
|
|
304
|
-
}, G = (e, t) => ({ sendMessage: async (n, r) => {
|
|
305
|
-
let { onMessage: i, onEnd: a, onError: o, onFinish: s } = r;
|
|
306
|
-
try {
|
|
307
|
-
let { ok: r, status: c, statusText: l, body: u } = await fetch(`${e}/chat-messages`, {
|
|
308
|
-
method: "POST",
|
|
309
|
-
headers: {
|
|
310
|
-
Authorization: `Bearer ${t}`,
|
|
311
|
-
"Content-Type": "application/json"
|
|
312
|
-
},
|
|
313
|
-
body: JSON.stringify({
|
|
314
|
-
...n,
|
|
315
|
-
response_mode: "streaming"
|
|
316
|
-
})
|
|
317
|
-
});
|
|
318
|
-
if (!r) return o?.({
|
|
319
|
-
code: String(c),
|
|
320
|
-
message: l
|
|
321
|
-
});
|
|
322
|
-
let d = u?.getReader();
|
|
323
|
-
if (!d) return o?.({
|
|
324
|
-
code: "reader_error",
|
|
325
|
-
message: "Failed to get response reader"
|
|
326
|
-
});
|
|
327
|
-
let f = new TextDecoder(), p = "";
|
|
328
|
-
for (;;) {
|
|
329
|
-
let { done: e, value: t } = await d.read();
|
|
330
|
-
if (e) break;
|
|
331
|
-
p += f.decode(t, { stream: !0 });
|
|
332
|
-
let n = p.split("\n");
|
|
333
|
-
p = n.pop() || "";
|
|
334
|
-
for (let e of n) if (e.startsWith("data:")) try {
|
|
335
|
-
let t = e.slice(5).trim();
|
|
336
|
-
if (!t) continue;
|
|
337
|
-
let n = JSON.parse(t);
|
|
338
|
-
if (n.event === "agent_message") i?.(n.answer || "");
|
|
339
|
-
else if (n.event === "message_end") a?.(n.conversation_id, n.message_id);
|
|
340
|
-
else if (n.event === "error") {
|
|
341
|
-
let { code: e, message: t } = n;
|
|
342
|
-
o?.({
|
|
343
|
-
code: e,
|
|
344
|
-
message: t
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
s?.();
|
|
348
|
-
} catch {}
|
|
349
|
-
}
|
|
350
|
-
} catch (e) {
|
|
351
|
-
o?.({
|
|
352
|
-
code: "network_error",
|
|
353
|
-
message: String(e)
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
} }), K = /* @__PURE__ */ ((e, t) => {
|
|
357
|
-
let n = e.__vccOpts || e;
|
|
358
|
-
for (let [e, r] of t) n[e] = r;
|
|
359
|
-
return n;
|
|
360
|
-
})(/* @__PURE__ */ n({
|
|
361
|
-
__name: "VueIcon",
|
|
362
|
-
props: {
|
|
363
|
-
vendor: {
|
|
364
|
-
type: String,
|
|
365
|
-
default: "icon-park-outline"
|
|
366
|
-
},
|
|
367
|
-
icon: {
|
|
368
|
-
type: String,
|
|
369
|
-
default: ""
|
|
370
|
-
},
|
|
371
|
-
size: {
|
|
372
|
-
type: Number,
|
|
373
|
-
default: 16
|
|
374
|
-
},
|
|
375
|
-
strokeWidth: {
|
|
376
|
-
type: Number,
|
|
377
|
-
default: 4
|
|
378
|
-
},
|
|
379
|
-
color: { type: String }
|
|
380
|
-
},
|
|
381
|
-
setup(n) {
|
|
382
|
-
p((e) => ({ v1903d129: s.value }));
|
|
383
|
-
let r = n, i = e(() => r.icon.indexOf(":") === -1 ? `${r.vendor}:${r.icon}` : r.icon), o = e(() => r.color ? { color: r.color } : void 0), s = e(() => r.strokeWidth);
|
|
384
|
-
return (e, r) => (c(), t(f(_), {
|
|
385
|
-
icon: i.value,
|
|
386
|
-
width: n.size,
|
|
387
|
-
height: n.size,
|
|
388
|
-
style: a(o.value),
|
|
389
|
-
"aria-hidden": null
|
|
390
|
-
}, null, 8, [
|
|
391
|
-
"icon",
|
|
392
|
-
"width",
|
|
393
|
-
"height",
|
|
394
|
-
"style"
|
|
395
|
-
]));
|
|
396
|
-
}
|
|
397
|
-
}), [["__scopeId", "data-v-2533db5c"]]), q = () => ({ i: (e, t = {}) => e ? r(K, {
|
|
398
|
-
icon: e,
|
|
399
|
-
...t
|
|
400
|
-
}) : void 0 }), J = () => ({
|
|
401
|
-
nanoid: v,
|
|
402
|
-
numeric: (e = 10) => y("1234567890", e)()
|
|
403
|
-
}), Y = () => {
|
|
404
|
-
let e = (e) => new Promise(async (t) => {
|
|
405
|
-
let n = await x({
|
|
406
|
-
blob: e,
|
|
407
|
-
toType: "image/jpeg",
|
|
408
|
-
quality: .9
|
|
409
|
-
});
|
|
410
|
-
return t(new File([n], e.name, {
|
|
411
|
-
type: n.type,
|
|
412
|
-
lastModified: Date.now()
|
|
413
|
-
}));
|
|
414
|
-
}), t = (e) => new Promise((t) => {
|
|
415
|
-
new S(e, {
|
|
416
|
-
quality: .9,
|
|
417
|
-
success: (e) => t(e)
|
|
418
|
-
});
|
|
419
|
-
});
|
|
420
|
-
return {
|
|
421
|
-
handler: (n, r = { compressor: !0 }) => new Promise((i) => {
|
|
422
|
-
let a = new FileReader();
|
|
423
|
-
a.readAsArrayBuffer(n), a.onload = () => {
|
|
424
|
-
let o = b.validateFileType(a.result, ["heic"]), s = b.validateFileType(a.result, [
|
|
425
|
-
"jpeg",
|
|
426
|
-
"png",
|
|
427
|
-
"gif",
|
|
428
|
-
"bmp"
|
|
429
|
-
]);
|
|
430
|
-
o ? i(e(n)) : s && r.compressor ? i(t(n)) : i(n);
|
|
431
|
-
};
|
|
432
|
-
}),
|
|
433
|
-
getDimension: async (e) => new Promise((t, n) => {
|
|
434
|
-
let r = new Image();
|
|
435
|
-
r.src = URL.createObjectURL(e), r.onload = () => t({
|
|
436
|
-
width: r.naturalWidth,
|
|
437
|
-
height: r.naturalHeight
|
|
438
|
-
}), r.onerror = (e) => n(e);
|
|
439
|
-
}),
|
|
440
|
-
getFileType: (e) => new Promise((t) => {
|
|
441
|
-
let n = new FileReader();
|
|
442
|
-
n.readAsArrayBuffer(e), n.onload = () => {
|
|
443
|
-
t({ mimeType: b.detectFile(n.result)?.mimeType });
|
|
444
|
-
};
|
|
445
|
-
})
|
|
446
|
-
};
|
|
447
|
-
}, X = { install(e, t) {
|
|
448
|
-
k(t), e.config.globalProperties.$setLocale = j, e.config.globalProperties.$getLocale = M;
|
|
449
|
-
} };
|
|
450
|
-
//#endregion
|
|
451
|
-
export { P as $params, V as DateTime, z as Formatter, N as Platform, B as Validate, X as default, R as download, L as get, M as getLocale, F as request, I as resource, j as setLocale, U as useBreak, W as useCaptcha, G as useChat, q as useIcon, A as useLocale, J as useNanoid, Y as useUpload };
|
package/src/hooks/useChat.ts
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
export interface IChatMessage {
|
|
2
|
-
question: string
|
|
3
|
-
answer: string
|
|
4
|
-
conversation_id: string
|
|
5
|
-
message_id: string
|
|
6
|
-
created_at: number
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface IMessageEvent {
|
|
10
|
-
event: 'message' | 'agent_message' | 'agent_thought' | 'message_file' | 'message_end' | 'tts_message' | 'tts_message_end' | 'message_replace' | 'error' | 'ping'
|
|
11
|
-
task_id: string
|
|
12
|
-
id: string
|
|
13
|
-
conversation_id: string
|
|
14
|
-
message_id: string
|
|
15
|
-
created_at: number
|
|
16
|
-
answer?: string
|
|
17
|
-
metadata?: Record<string, any>
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface IUsageEvent {
|
|
21
|
-
event: 'message_end'
|
|
22
|
-
task_id: string
|
|
23
|
-
id: string
|
|
24
|
-
conversation_id: string
|
|
25
|
-
message_id: string
|
|
26
|
-
created_at: number
|
|
27
|
-
usage: {
|
|
28
|
-
prompt_tokens: number
|
|
29
|
-
prompt_unit_price: number
|
|
30
|
-
prompt_price_unit: number
|
|
31
|
-
prompt_price: number
|
|
32
|
-
completion_tokens: number
|
|
33
|
-
completion_unit_price: number
|
|
34
|
-
completion_price_unit: number
|
|
35
|
-
completion_price: number
|
|
36
|
-
total_tokens: number
|
|
37
|
-
total_price: number
|
|
38
|
-
currency: string
|
|
39
|
-
latency: number
|
|
40
|
-
}
|
|
41
|
-
metadata?: Record<string, any>
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface IErrorEvent {
|
|
45
|
-
event: 'error'
|
|
46
|
-
task_id: string
|
|
47
|
-
id: string
|
|
48
|
-
code: string
|
|
49
|
-
message: string
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export interface ISendMessageParams {
|
|
53
|
-
query: string
|
|
54
|
-
inputs?: Record<string, any>
|
|
55
|
-
response_mode?: 'streaming' | 'blocking'
|
|
56
|
-
conversation_id?: string
|
|
57
|
-
user: string
|
|
58
|
-
files?: Array<{
|
|
59
|
-
type: string
|
|
60
|
-
transfer_method: 'remote_url' | 'local_file'
|
|
61
|
-
url?: string
|
|
62
|
-
upload_file_id?: string
|
|
63
|
-
}>
|
|
64
|
-
auto_generate_name?: boolean
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export const useChat = (baseURL: string, apiKey: string) => {
|
|
68
|
-
|
|
69
|
-
const sendMessage = async (
|
|
70
|
-
params: ISendMessageParams,
|
|
71
|
-
callbacks: {
|
|
72
|
-
onMessage?: (text: string) => void
|
|
73
|
-
onEnd?: (conversationId: string, messageId: string) => void
|
|
74
|
-
onError?: (error: { code: string; message: string }) => void
|
|
75
|
-
onFinish?: () => void
|
|
76
|
-
},
|
|
77
|
-
) => {
|
|
78
|
-
const { onMessage, onEnd, onError, onFinish } = callbacks
|
|
79
|
-
|
|
80
|
-
try {
|
|
81
|
-
const { ok, status, statusText, body } = await fetch(`${baseURL}/chat-messages`, {
|
|
82
|
-
method: 'POST',
|
|
83
|
-
headers: {
|
|
84
|
-
'Authorization': `Bearer ${apiKey}`,
|
|
85
|
-
'Content-Type': 'application/json',
|
|
86
|
-
},
|
|
87
|
-
body: JSON.stringify({
|
|
88
|
-
...params,
|
|
89
|
-
response_mode: 'streaming',
|
|
90
|
-
}),
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
if (!ok) return onError?.({ code: String(status), message: statusText })
|
|
94
|
-
|
|
95
|
-
const reader = body?.getReader()
|
|
96
|
-
if (!reader) return onError?.({ code: 'reader_error', message: 'Failed to get response reader' })
|
|
97
|
-
|
|
98
|
-
const decoder = new TextDecoder()
|
|
99
|
-
let buffer = ''
|
|
100
|
-
|
|
101
|
-
while (true) {
|
|
102
|
-
const { done, value } = await reader.read()
|
|
103
|
-
if (done) break
|
|
104
|
-
|
|
105
|
-
buffer += decoder.decode(value, { stream: true })
|
|
106
|
-
const lines = buffer.split('\n')
|
|
107
|
-
buffer = lines.pop() || ''
|
|
108
|
-
|
|
109
|
-
for (const line of lines) {
|
|
110
|
-
if (line.startsWith('data:')) {
|
|
111
|
-
try {
|
|
112
|
-
const jsonStr = line.slice(5).trim()
|
|
113
|
-
if (!jsonStr) continue
|
|
114
|
-
|
|
115
|
-
const data = JSON.parse(jsonStr) as IMessageEvent | IUsageEvent | IErrorEvent
|
|
116
|
-
|
|
117
|
-
if (data.event === 'agent_message') onMessage?.((data as IMessageEvent).answer || '')
|
|
118
|
-
else if (data.event === 'message_end') onEnd?.(data.conversation_id, data.message_id)
|
|
119
|
-
else if (data.event === 'error') {
|
|
120
|
-
const { code, message } = data as IErrorEvent
|
|
121
|
-
onError?.({ code, message })
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
onFinish?.()
|
|
125
|
-
} catch (e) {}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
} catch (error) {
|
|
130
|
-
onError?.({ code: 'network_error', message: String(error) })
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return { sendMessage }
|
|
135
|
-
}
|
package/src/hooks/useNanoid.ts
DELETED
package/src/hooks/useUpload.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import fileTypeChecker from 'file-type-checker'
|
|
2
|
-
import heic2any from 'heic2any'
|
|
3
|
-
import Compressor from 'compressorjs'
|
|
4
|
-
|
|
5
|
-
export const useUpload = () => {
|
|
6
|
-
|
|
7
|
-
const HEIC = (file: File): Promise<File> => {
|
|
8
|
-
return new Promise(async resolve => {
|
|
9
|
-
const blob = (await heic2any({ blob: file, toType: 'image/jpeg', quality: 0.9 }) as Blob)
|
|
10
|
-
const newFile = new File([blob], file.name, { type: blob.type, lastModified: Date.now() })
|
|
11
|
-
return resolve(newFile)
|
|
12
|
-
})
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const compressor = (file: File): Promise<File> => {
|
|
16
|
-
return new Promise(resolve => {
|
|
17
|
-
new Compressor(file, { quality: 0.9, success: (file: File) => resolve(file) })
|
|
18
|
-
})
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const handler = (
|
|
22
|
-
file: File,
|
|
23
|
-
para: { compressor: boolean } = { compressor: true }
|
|
24
|
-
): Promise<File> => {
|
|
25
|
-
return new Promise(resolve => {
|
|
26
|
-
const reader = new FileReader()
|
|
27
|
-
reader.readAsArrayBuffer(file)
|
|
28
|
-
reader.onload = () => {
|
|
29
|
-
const isHeic = fileTypeChecker.validateFileType(reader.result as ArrayBuffer, ['heic'])
|
|
30
|
-
const isCompressor = fileTypeChecker.validateFileType(reader.result as ArrayBuffer, ['jpeg', 'png', 'gif', 'bmp'])
|
|
31
|
-
if (isHeic) resolve(HEIC(file))
|
|
32
|
-
else if (isCompressor && para.compressor) resolve(compressor(file))
|
|
33
|
-
else resolve(file)
|
|
34
|
-
}
|
|
35
|
-
})
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const getDimension = async (blob: Blob): Promise<{ width: number; height: number }> => {
|
|
39
|
-
return new Promise((resolve, reject) => {
|
|
40
|
-
const img = new Image()
|
|
41
|
-
img.src = URL.createObjectURL(blob)
|
|
42
|
-
img.onload = () => resolve({ width: img.naturalWidth, height: img.naturalHeight })
|
|
43
|
-
img.onerror = (err) => reject(err)
|
|
44
|
-
})
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const getFileType = (file: File): Promise<{ mimeType: string }> => {
|
|
48
|
-
return new Promise(resolve => {
|
|
49
|
-
const reader = new FileReader()
|
|
50
|
-
reader.readAsArrayBuffer(file)
|
|
51
|
-
reader.onload = () => {
|
|
52
|
-
const detectedFile = fileTypeChecker.detectFile(reader.result as ArrayBuffer)
|
|
53
|
-
resolve({ mimeType: detectedFile?.mimeType! })
|
|
54
|
-
}
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return { handler, getDimension, getFileType }
|
|
59
|
-
}
|