@gindow/vue 1.0.0 → 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 +219 -0
- package/dist/vue.mjs +286 -0
- package/package.json +11 -52
- package/src/components/VueIcon.vue +65 -0
- package/src/hooks/useIcon.ts +9 -0
- package/src/index.ts +18 -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 -406
- package/dist/vue-go.d.ts +0 -394
- 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/vue-go.d.ts
DELETED
|
@@ -1,394 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance } from 'axios';
|
|
2
|
-
import { AxiosResponse } from 'axios';
|
|
3
|
-
import { ComputedRef } from 'vue';
|
|
4
|
-
import { default as default_2 } from 'dayjs';
|
|
5
|
-
import { nanoid } from 'nanoid';
|
|
6
|
-
import { Plugin as Plugin_2 } from 'vue';
|
|
7
|
-
import { Ref } from 'vue';
|
|
8
|
-
|
|
9
|
-
export declare const $params: (params: IModel) => {
|
|
10
|
-
[property: string]: any;
|
|
11
|
-
id?: string | any;
|
|
12
|
-
created_at?: string;
|
|
13
|
-
updated_at?: string;
|
|
14
|
-
deleted_at?: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export declare class DateTime {
|
|
18
|
-
static dayjs: typeof default_2;
|
|
19
|
-
static s(date?: default_2.ConfigType, symbol?: string): string;
|
|
20
|
-
static m(date?: default_2.ConfigType, symbol?: string): string;
|
|
21
|
-
static h(date?: default_2.ConfigType, symbol?: string): string;
|
|
22
|
-
static d(date?: default_2.ConfigType, symbol?: string): string;
|
|
23
|
-
static M(date?: default_2.ConfigType, symbol?: string): string;
|
|
24
|
-
static y(date?: default_2.ConfigType): string;
|
|
25
|
-
static date(date?: default_2.ConfigType, symbol?: string): string;
|
|
26
|
-
static time(date?: default_2.ConfigType): string;
|
|
27
|
-
static format(date?: default_2.ConfigType, format?: string): string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export declare const download: (blob: Blob, filename: string) => void;
|
|
31
|
-
|
|
32
|
-
export declare class Formatter {
|
|
33
|
-
static config: {
|
|
34
|
-
locale?: string;
|
|
35
|
-
currency?: string;
|
|
36
|
-
decimals?: number;
|
|
37
|
-
};
|
|
38
|
-
static set: (config: {
|
|
39
|
-
locale?: string;
|
|
40
|
-
currency?: string;
|
|
41
|
-
decimals?: number;
|
|
42
|
-
}) => {
|
|
43
|
-
locale?: string;
|
|
44
|
-
currency?: string;
|
|
45
|
-
decimals?: number;
|
|
46
|
-
};
|
|
47
|
-
static id: (str?: string) => string;
|
|
48
|
-
static date: (datestr?: string) => string;
|
|
49
|
-
static idcard: (idcard?: string) => string;
|
|
50
|
-
static phone: (phone?: string, naked?: boolean) => string;
|
|
51
|
-
static email: (email?: string) => string;
|
|
52
|
-
static bankcard: (bankcard?: string) => string;
|
|
53
|
-
static url: (url?: string) => string;
|
|
54
|
-
static price: (value?: string | number, currency?: string) => string;
|
|
55
|
-
static currency: (value?: string | number, currency?: string) => string;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export declare const get: (object: any, path: string | string[], defaultValue?: any) => any;
|
|
59
|
-
|
|
60
|
-
export declare const getLocale: () => string;
|
|
61
|
-
|
|
62
|
-
export declare interface IAIResponse {
|
|
63
|
-
message: IChatMessageItem;
|
|
64
|
-
sessionId: string;
|
|
65
|
-
suggestions?: string[];
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export declare interface IAsset extends IModel {
|
|
69
|
-
id: string;
|
|
70
|
-
type: string;
|
|
71
|
-
title: string;
|
|
72
|
-
url: string;
|
|
73
|
-
shrink: string;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export declare interface IChatConfig {
|
|
77
|
-
placeholder?: string;
|
|
78
|
-
maxFileSize?: number;
|
|
79
|
-
allowedFileTypes?: string[];
|
|
80
|
-
enableStreaming?: boolean;
|
|
81
|
-
showTimestamp?: boolean;
|
|
82
|
-
showSuggestions?: boolean;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export declare interface IChatFile {
|
|
86
|
-
id: string;
|
|
87
|
-
name: string;
|
|
88
|
-
type: string;
|
|
89
|
-
size: number;
|
|
90
|
-
url?: string;
|
|
91
|
-
thumbnail?: string;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export declare interface IChatMessage {
|
|
95
|
-
question: string;
|
|
96
|
-
answer: string;
|
|
97
|
-
conversation_id: string;
|
|
98
|
-
message_id: string;
|
|
99
|
-
created_at: number;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export declare interface IChatMessageItem {
|
|
103
|
-
id: string;
|
|
104
|
-
role: MessageRole;
|
|
105
|
-
content: string;
|
|
106
|
-
contentType?: MessageContentType;
|
|
107
|
-
timestamp: number;
|
|
108
|
-
isLoading?: boolean;
|
|
109
|
-
isError?: boolean;
|
|
110
|
-
files?: IChatFile[];
|
|
111
|
-
metadata?: Record<string, any>;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export declare interface IChatSession {
|
|
115
|
-
id: string;
|
|
116
|
-
title: string;
|
|
117
|
-
messages: IChatMessageItem[];
|
|
118
|
-
createdAt: number;
|
|
119
|
-
updatedAt: number;
|
|
120
|
-
isPinned?: boolean;
|
|
121
|
-
isArchived?: boolean;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export declare interface ICodeBlock {
|
|
125
|
-
language: string;
|
|
126
|
-
code: string;
|
|
127
|
-
filename?: string;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export declare interface IErrorEvent {
|
|
131
|
-
event: 'error';
|
|
132
|
-
task_id: string;
|
|
133
|
-
id: string;
|
|
134
|
-
code: string;
|
|
135
|
-
message: string;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export declare interface IField extends IModel {
|
|
139
|
-
name: string;
|
|
140
|
-
type: string;
|
|
141
|
-
readonly?: boolean;
|
|
142
|
-
multiple?: boolean;
|
|
143
|
-
required?: boolean;
|
|
144
|
-
options?: {
|
|
145
|
-
label: string;
|
|
146
|
-
value: string;
|
|
147
|
-
}[] | any[];
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export declare type IFilter = Omit<IField, 'name'> & {
|
|
151
|
-
label?: string;
|
|
152
|
-
rules?: any[];
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
export declare interface IMenu {
|
|
156
|
-
key?: string;
|
|
157
|
-
title: string;
|
|
158
|
-
path: string;
|
|
159
|
-
name?: string;
|
|
160
|
-
icon?: string;
|
|
161
|
-
depend?: string;
|
|
162
|
-
hidden?: boolean;
|
|
163
|
-
divider?: boolean;
|
|
164
|
-
disabled?: boolean;
|
|
165
|
-
children?: IMenu[];
|
|
166
|
-
isGroup?: boolean;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export declare interface IMessageEvent {
|
|
170
|
-
event: 'message' | 'agent_message' | 'agent_thought' | 'message_file' | 'message_end' | 'tts_message' | 'tts_message_end' | 'message_replace' | 'error' | 'ping';
|
|
171
|
-
task_id: string;
|
|
172
|
-
id: string;
|
|
173
|
-
conversation_id: string;
|
|
174
|
-
message_id: string;
|
|
175
|
-
created_at: number;
|
|
176
|
-
answer?: string;
|
|
177
|
-
metadata?: Record<string, any>;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export declare interface IModel {
|
|
181
|
-
id?: string | any;
|
|
182
|
-
created_at?: string;
|
|
183
|
-
updated_at?: string;
|
|
184
|
-
deleted_at?: string;
|
|
185
|
-
[property: string]: any;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
export declare interface IPagination {
|
|
189
|
-
current_page: number;
|
|
190
|
-
per_page: number;
|
|
191
|
-
count: number;
|
|
192
|
-
total: number;
|
|
193
|
-
total_pages: number;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
export declare interface IParams extends IModel {
|
|
197
|
-
filter?: Object;
|
|
198
|
-
search?: string;
|
|
199
|
-
include?: string;
|
|
200
|
-
page?: number;
|
|
201
|
-
size?: number;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export declare interface IResult {
|
|
205
|
-
code: number;
|
|
206
|
-
message: string;
|
|
207
|
-
data?: IModel | IModel[] | null;
|
|
208
|
-
meta?: {
|
|
209
|
-
pagination?: IPagination;
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
export declare interface ISendChatParams {
|
|
214
|
-
content: string;
|
|
215
|
-
contentType?: MessageContentType;
|
|
216
|
-
files?: IChatFile[];
|
|
217
|
-
sessionId?: string;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
export declare interface ISendMessageParams {
|
|
221
|
-
query: string;
|
|
222
|
-
inputs?: Record<string, any>;
|
|
223
|
-
response_mode?: 'streaming' | 'blocking';
|
|
224
|
-
conversation_id?: string;
|
|
225
|
-
user: string;
|
|
226
|
-
files?: Array<{
|
|
227
|
-
type: string;
|
|
228
|
-
transfer_method: 'remote_url' | 'local_file';
|
|
229
|
-
url?: string;
|
|
230
|
-
upload_file_id?: string;
|
|
231
|
-
}>;
|
|
232
|
-
auto_generate_name?: boolean;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
export declare interface IUploadUserFile {
|
|
236
|
-
id?: string;
|
|
237
|
-
percentage?: number;
|
|
238
|
-
asset?: IAsset;
|
|
239
|
-
title?: string;
|
|
240
|
-
width?: number;
|
|
241
|
-
height?: number;
|
|
242
|
-
type?: string;
|
|
243
|
-
mimeType?: string;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
export declare interface IUsageEvent {
|
|
247
|
-
event: 'message_end';
|
|
248
|
-
task_id: string;
|
|
249
|
-
id: string;
|
|
250
|
-
conversation_id: string;
|
|
251
|
-
message_id: string;
|
|
252
|
-
created_at: number;
|
|
253
|
-
usage: {
|
|
254
|
-
prompt_tokens: number;
|
|
255
|
-
prompt_unit_price: number;
|
|
256
|
-
prompt_price_unit: number;
|
|
257
|
-
prompt_price: number;
|
|
258
|
-
completion_tokens: number;
|
|
259
|
-
completion_unit_price: number;
|
|
260
|
-
completion_price_unit: number;
|
|
261
|
-
completion_price: number;
|
|
262
|
-
total_tokens: number;
|
|
263
|
-
total_price: number;
|
|
264
|
-
currency: string;
|
|
265
|
-
latency: number;
|
|
266
|
-
};
|
|
267
|
-
metadata?: Record<string, any>;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
export declare type MessageContentType = 'text' | 'image' | 'code' | 'file';
|
|
271
|
-
|
|
272
|
-
export declare type MessageRole = 'user' | 'assistant' | 'system';
|
|
273
|
-
|
|
274
|
-
export declare class Platform {
|
|
275
|
-
static get userAgent(): string;
|
|
276
|
-
static get isFlutter(): boolean;
|
|
277
|
-
static get isFlutterIOS(): boolean;
|
|
278
|
-
static get isWeb(): boolean;
|
|
279
|
-
static get isMobile(): boolean;
|
|
280
|
-
static get isIOS(): boolean;
|
|
281
|
-
static get isWechat(): boolean;
|
|
282
|
-
static get isWxwork(): boolean;
|
|
283
|
-
static get isMiniprogram(): boolean;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
export declare const request: {
|
|
287
|
-
baseURL: string;
|
|
288
|
-
publicKey: string;
|
|
289
|
-
headers: Record<string, string>;
|
|
290
|
-
instance: AxiosInstance | null;
|
|
291
|
-
accessToken: string;
|
|
292
|
-
init(config?: {
|
|
293
|
-
baseURL?: string;
|
|
294
|
-
publicKey?: string;
|
|
295
|
-
}): void;
|
|
296
|
-
setToken(token: string, options?: {
|
|
297
|
-
expires?: number;
|
|
298
|
-
domain?: string;
|
|
299
|
-
}): void;
|
|
300
|
-
getToken(): string;
|
|
301
|
-
delToken(): void;
|
|
302
|
-
get(url: string, params?: {}, auth?: boolean): any;
|
|
303
|
-
put(url: string, data?: {}, auth?: boolean): any;
|
|
304
|
-
patch(url: string, data?: {}, auth?: boolean): any;
|
|
305
|
-
delete(url: string, params?: {}, auth?: boolean): any;
|
|
306
|
-
post(url: string, data?: {}, auth?: boolean): any;
|
|
307
|
-
blob(url: string, params?: {}, auth?: boolean): any;
|
|
308
|
-
request(para: any, auth?: boolean): any;
|
|
309
|
-
download(url: string, params?: {}, filename?: string, auth?: boolean): Promise<any>;
|
|
310
|
-
upload(url: string, data?: {}): Promise<AxiosResponse<any, any, {}>>;
|
|
311
|
-
sse(url: string, para?: {
|
|
312
|
-
[key: string]: string | number | undefined | null | void;
|
|
313
|
-
} | null): EventSource;
|
|
314
|
-
setHeader(key: string, value: string): void;
|
|
315
|
-
delHeader(key: string): void;
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
export declare class resource {
|
|
319
|
-
url: string;
|
|
320
|
-
auth: boolean;
|
|
321
|
-
constructor(url: string, auth?: boolean);
|
|
322
|
-
select: (para?: {}) => any;
|
|
323
|
-
create: (para?: {}) => any;
|
|
324
|
-
find: (id: string, para?: {}) => any;
|
|
325
|
-
update: (id: string, para?: {}) => any;
|
|
326
|
-
delete: (id: string, para?: {}) => any;
|
|
327
|
-
get(para: any): Promise<any>;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
export declare const setLocale: (lang: string) => string;
|
|
331
|
-
|
|
332
|
-
export declare const useBreak: () => {
|
|
333
|
-
isMobile: ComputedRef<boolean>;
|
|
334
|
-
isDesktop: ComputedRef<boolean>;
|
|
335
|
-
};
|
|
336
|
-
|
|
337
|
-
export declare const useCaptcha: (api: (data: any) => Promise<void>) => {
|
|
338
|
-
waiting: Ref<number, number>;
|
|
339
|
-
send: (para?: {}) => Promise<unknown>;
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
export declare const useChat: (baseURL: string, apiKey: string) => {
|
|
343
|
-
sendMessage: (params: ISendMessageParams, callbacks: {
|
|
344
|
-
onMessage?: (text: string) => void;
|
|
345
|
-
onEnd?: (conversationId: string, messageId: string) => void;
|
|
346
|
-
onError?: (error: {
|
|
347
|
-
code: string;
|
|
348
|
-
message: string;
|
|
349
|
-
}) => void;
|
|
350
|
-
onFinish?: () => void;
|
|
351
|
-
}) => Promise<void>;
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
export declare const useLocale: () => {
|
|
355
|
-
locale: Ref<string, string>;
|
|
356
|
-
t: (path: string, params?: Record<string, string | number>) => string;
|
|
357
|
-
};
|
|
358
|
-
|
|
359
|
-
export declare const useNanoid: () => {
|
|
360
|
-
nanoid: typeof nanoid;
|
|
361
|
-
numeric: (length?: number) => string;
|
|
362
|
-
};
|
|
363
|
-
|
|
364
|
-
export declare const useUpload: () => {
|
|
365
|
-
handler: (file: File, para?: {
|
|
366
|
-
compressor: boolean;
|
|
367
|
-
}) => Promise<File>;
|
|
368
|
-
getDimension: (blob: Blob) => Promise<{
|
|
369
|
-
width: number;
|
|
370
|
-
height: number;
|
|
371
|
-
}>;
|
|
372
|
-
getFileType: (file: File) => Promise<{
|
|
373
|
-
mimeType: string;
|
|
374
|
-
}>;
|
|
375
|
-
};
|
|
376
|
-
|
|
377
|
-
export declare class Validate {
|
|
378
|
-
static country: string;
|
|
379
|
-
static set: (country: string) => string;
|
|
380
|
-
static get phone_pattern(): RegExp;
|
|
381
|
-
static email_pattern: RegExp;
|
|
382
|
-
static idcard_pattern: RegExp;
|
|
383
|
-
static cname_pattern: RegExp;
|
|
384
|
-
static password_pattern: RegExp;
|
|
385
|
-
static phone: (str: string) => boolean;
|
|
386
|
-
static email: (str: string) => boolean;
|
|
387
|
-
static idcard: (str: string) => boolean;
|
|
388
|
-
static cname: (str: string) => boolean;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
declare const VueGo: Plugin_2;
|
|
392
|
-
export default VueGo;
|
|
393
|
-
|
|
394
|
-
export { }
|
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
|
-
}
|
package/src/types/chat.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
export type MessageRole = 'user' | 'assistant' | 'system'
|
|
2
|
-
|
|
3
|
-
export type MessageContentType = 'text' | 'image' | 'code' | 'file'
|
|
4
|
-
|
|
5
|
-
export interface IChatFile {
|
|
6
|
-
id: string
|
|
7
|
-
name: string
|
|
8
|
-
type: string
|
|
9
|
-
size: number
|
|
10
|
-
url?: string
|
|
11
|
-
thumbnail?: string
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface IChatMessageItem {
|
|
15
|
-
id: string
|
|
16
|
-
role: MessageRole
|
|
17
|
-
content: string
|
|
18
|
-
contentType?: MessageContentType
|
|
19
|
-
timestamp: number
|
|
20
|
-
isLoading?: boolean
|
|
21
|
-
isError?: boolean
|
|
22
|
-
files?: IChatFile[]
|
|
23
|
-
metadata?: Record<string, any>
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface IChatSession {
|
|
27
|
-
id: string
|
|
28
|
-
title: string
|
|
29
|
-
messages: IChatMessageItem[]
|
|
30
|
-
createdAt: number
|
|
31
|
-
updatedAt: number
|
|
32
|
-
isPinned?: boolean
|
|
33
|
-
isArchived?: boolean
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface ISendChatParams {
|
|
37
|
-
content: string
|
|
38
|
-
contentType?: MessageContentType
|
|
39
|
-
files?: IChatFile[]
|
|
40
|
-
sessionId?: string
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface IAIResponse {
|
|
44
|
-
message: IChatMessageItem
|
|
45
|
-
sessionId: string
|
|
46
|
-
suggestions?: string[]
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface IChatConfig {
|
|
50
|
-
placeholder?: string
|
|
51
|
-
maxFileSize?: number
|
|
52
|
-
allowedFileTypes?: string[]
|
|
53
|
-
enableStreaming?: boolean
|
|
54
|
-
showTimestamp?: boolean
|
|
55
|
-
showSuggestions?: boolean
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export interface ICodeBlock {
|
|
59
|
-
language: string
|
|
60
|
-
code: string
|
|
61
|
-
filename?: string
|
|
62
|
-
}
|
package/src/utils/datetime.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import dayjs from 'dayjs'
|
|
2
|
-
|
|
3
|
-
export class DateTime {
|
|
4
|
-
|
|
5
|
-
static dayjs = dayjs
|
|
6
|
-
|
|
7
|
-
static s(date?: dayjs.ConfigType, symbol = '/') {
|
|
8
|
-
return DateTime.dayjs(date).format('YYYY/MM/DD HH:mm:ss'.replace(/\//g, symbol))
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
static m(date?: dayjs.ConfigType, symbol = '/') {
|
|
12
|
-
return DateTime.dayjs(date).format('YYYY/MM/DD HH:mm'.replace(/\//g, symbol))
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
static h(date?: dayjs.ConfigType, symbol = '/') {
|
|
16
|
-
return DateTime.dayjs(date).format('YYYY/MM/DD HH'.replace(/\//g, symbol))
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
static d(date?: dayjs.ConfigType, symbol = '/') {
|
|
20
|
-
return DateTime.dayjs(date).format('YYYY/MM/DD'.replace(/\//g, symbol))
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
static M(date?: dayjs.ConfigType, symbol = '/') {
|
|
24
|
-
return DateTime.dayjs(date).format('YYYY/MM'.replace(/\//g, symbol))
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
static y(date?: dayjs.ConfigType) {
|
|
28
|
-
return DateTime.dayjs(date).format('YYYY')
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
static date(date?: dayjs.ConfigType, symbol = '/') {
|
|
32
|
-
return DateTime.dayjs(date).format('YYYY/MM/DD'.replace(/\//g, symbol))
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
static time(date?: dayjs.ConfigType) {
|
|
36
|
-
return DateTime.dayjs(date).format('HH:mm')
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
static format(date?: dayjs.ConfigType, format = 'YYYY/MM/DD HH:mm:ss') {
|
|
40
|
-
return DateTime.dayjs(date).format(format)
|
|
41
|
-
}
|
|
42
|
-
}
|
package/src/utils/download.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export const download = (blob: Blob, filename: string) => {
|
|
2
|
-
const url = URL.createObjectURL(blob)
|
|
3
|
-
const a = document.createElement('a')
|
|
4
|
-
a.href = url
|
|
5
|
-
a.download = filename
|
|
6
|
-
a.style.display = 'none'
|
|
7
|
-
document.body.appendChild(a)
|
|
8
|
-
a.click()
|
|
9
|
-
document.body.removeChild(a)
|
|
10
|
-
URL.revokeObjectURL(url)
|
|
11
|
-
}
|