langchat-widget 0.1.0 → 0.2.0
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 +11 -0
- package/dist/favicon.ico +0 -0
- package/dist/index.d.ts +258 -3
- package/dist/langchat-widget.css +1 -1
- package/dist/langchat-widget.es.js +66531 -10692
- package/dist/langchat-widget.es.js.map +1 -1
- package/dist/langchat-widget.umd.js +60 -11
- package/dist/langchat-widget.umd.js.map +1 -1
- package/package.json +11 -8
package/README.md
CHANGED
package/dist/favicon.ico
CHANGED
|
Binary file
|
package/dist/index.d.ts
CHANGED
|
@@ -35,6 +35,8 @@ export declare interface ChatRequest {
|
|
|
35
35
|
temperature?: number;
|
|
36
36
|
maxTokens?: number;
|
|
37
37
|
stream?: boolean;
|
|
38
|
+
conversationId?: string;
|
|
39
|
+
chatId?: string;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
export declare interface ChatResponse {
|
|
@@ -80,6 +82,9 @@ export declare function createMessageStore(options?: {
|
|
|
80
82
|
enableHistory?: boolean;
|
|
81
83
|
}): MessageStore;
|
|
82
84
|
|
|
85
|
+
/**
|
|
86
|
+
* 创建OpenAI客户端实例
|
|
87
|
+
*/
|
|
83
88
|
export declare function createOpenAIClient(config: OpenAIConfig): OpenAIClient;
|
|
84
89
|
|
|
85
90
|
export declare function createThemeManager(initialTheme?: Partial<ThemeConfig_2>): ThemeManager;
|
|
@@ -95,21 +100,69 @@ declare class ErrorHandler {
|
|
|
95
100
|
private errorHistory;
|
|
96
101
|
private retryQueue;
|
|
97
102
|
constructor(config?: Partial<ErrorHandlerConfig>);
|
|
103
|
+
/**
|
|
104
|
+
* 处理错误
|
|
105
|
+
*/
|
|
98
106
|
handleError(error: any, context?: Record<string, any>): ErrorInfo;
|
|
107
|
+
/**
|
|
108
|
+
* 创建错误信息
|
|
109
|
+
*/
|
|
99
110
|
private createErrorInfo;
|
|
111
|
+
/**
|
|
112
|
+
* 安排重试
|
|
113
|
+
*/
|
|
100
114
|
private scheduleRetry;
|
|
115
|
+
/**
|
|
116
|
+
* 执行重试
|
|
117
|
+
*/
|
|
101
118
|
private executeRetry;
|
|
119
|
+
/**
|
|
120
|
+
* 日志记录
|
|
121
|
+
*/
|
|
102
122
|
private logError;
|
|
123
|
+
/**
|
|
124
|
+
* 获取日志级别
|
|
125
|
+
*/
|
|
103
126
|
private getLogLevel;
|
|
127
|
+
/**
|
|
128
|
+
* 获取错误历史
|
|
129
|
+
*/
|
|
104
130
|
getErrorHistory(): ErrorInfo[];
|
|
131
|
+
/**
|
|
132
|
+
* 获取特定类型的错误
|
|
133
|
+
*/
|
|
105
134
|
getErrorsByType(type: ErrorType): ErrorInfo[];
|
|
135
|
+
/**
|
|
136
|
+
* 获取特定严重程度的错误
|
|
137
|
+
*/
|
|
106
138
|
getErrorsBySeverity(severity: ErrorSeverity): ErrorInfo[];
|
|
139
|
+
/**
|
|
140
|
+
* 获取可重试的错误
|
|
141
|
+
*/
|
|
107
142
|
getRetryableErrors(): ErrorInfo[];
|
|
143
|
+
/**
|
|
144
|
+
* 清理错误历史
|
|
145
|
+
*/
|
|
108
146
|
clearErrorHistory(): void;
|
|
147
|
+
/**
|
|
148
|
+
* 清理过期错误
|
|
149
|
+
*/
|
|
109
150
|
cleanupOldErrors(olderThanHours?: number): number;
|
|
151
|
+
/**
|
|
152
|
+
* 获取错误统计
|
|
153
|
+
*/
|
|
110
154
|
getErrorStats(): Record<string, any>;
|
|
155
|
+
/**
|
|
156
|
+
* 更新配置
|
|
157
|
+
*/
|
|
111
158
|
updateConfig(config: Partial<ErrorHandlerConfig>): void;
|
|
159
|
+
/**
|
|
160
|
+
* 获取当前配置
|
|
161
|
+
*/
|
|
112
162
|
getConfig(): ErrorHandlerConfig;
|
|
163
|
+
/**
|
|
164
|
+
* 销毁
|
|
165
|
+
*/
|
|
113
166
|
destroy(): void;
|
|
114
167
|
}
|
|
115
168
|
|
|
@@ -170,6 +223,7 @@ declare class LangChatBot implements LangChatInstance {
|
|
|
170
223
|
private app;
|
|
171
224
|
private config;
|
|
172
225
|
private container;
|
|
226
|
+
private currentAbortController;
|
|
173
227
|
private eventListeners;
|
|
174
228
|
private isInitialized;
|
|
175
229
|
private messages;
|
|
@@ -177,38 +231,144 @@ declare class LangChatBot implements LangChatInstance {
|
|
|
177
231
|
private streamingMessageId;
|
|
178
232
|
private suggestedQuestions;
|
|
179
233
|
private welcomeData;
|
|
234
|
+
private conversationService;
|
|
235
|
+
private conversations;
|
|
236
|
+
private currentConversationId;
|
|
237
|
+
private isContextAvailable;
|
|
180
238
|
constructor(config: LangChatConfig);
|
|
239
|
+
/**
|
|
240
|
+
* 中断当前请求
|
|
241
|
+
*/
|
|
242
|
+
abortCurrentRequest(): void;
|
|
243
|
+
/**
|
|
244
|
+
* 清空历史记录
|
|
245
|
+
*/
|
|
181
246
|
clearHistory(): void;
|
|
247
|
+
/**
|
|
248
|
+
* 关闭聊天窗口
|
|
249
|
+
*/
|
|
182
250
|
close(): void;
|
|
251
|
+
/**
|
|
252
|
+
* 销毁聊天组件
|
|
253
|
+
*/
|
|
183
254
|
destroy(): void;
|
|
255
|
+
/**
|
|
256
|
+
* 获取当前配置
|
|
257
|
+
*/
|
|
184
258
|
getConfig(): LangChatConfig;
|
|
259
|
+
/**
|
|
260
|
+
* 获取历史记录
|
|
261
|
+
*/
|
|
185
262
|
getHistory(): ChatMessage[];
|
|
263
|
+
/**
|
|
264
|
+
* 获取建议问题
|
|
265
|
+
*/
|
|
186
266
|
getSuggestedQuestions(context?: string): Promise<QuestionItem[]>;
|
|
187
|
-
|
|
267
|
+
/**
|
|
268
|
+
* 初始化聊天组件
|
|
269
|
+
*/
|
|
270
|
+
init(): Promise<void>;
|
|
271
|
+
/**
|
|
272
|
+
* 检查是否正在加载
|
|
273
|
+
*/
|
|
188
274
|
isLoading(): boolean;
|
|
275
|
+
/**
|
|
276
|
+
* 检查聊天窗口是否打开
|
|
277
|
+
*/
|
|
189
278
|
isOpen(): boolean;
|
|
279
|
+
/**
|
|
280
|
+
* 移除事件监听器
|
|
281
|
+
*/
|
|
190
282
|
off(event: LangChatEvent, callback: Function): void;
|
|
283
|
+
/**
|
|
284
|
+
* 添加事件监听器
|
|
285
|
+
*/
|
|
191
286
|
on(event: LangChatEvent, callback: Function): void;
|
|
287
|
+
/**
|
|
288
|
+
* 打开聊天窗口
|
|
289
|
+
*/
|
|
192
290
|
open(): void;
|
|
291
|
+
/**
|
|
292
|
+
* 发送消息
|
|
293
|
+
*/
|
|
193
294
|
sendMessage(content: string): Promise<void>;
|
|
295
|
+
/**
|
|
296
|
+
* 开始流式消息
|
|
297
|
+
*/
|
|
194
298
|
startStreaming(messageId: string): void;
|
|
299
|
+
/**
|
|
300
|
+
* 停止流式消息
|
|
301
|
+
*/
|
|
195
302
|
stopStreaming(messageId: string): void;
|
|
303
|
+
/**
|
|
304
|
+
* 切换聊天窗口状态
|
|
305
|
+
*/
|
|
196
306
|
toggle(): void;
|
|
307
|
+
/**
|
|
308
|
+
* 更新配置
|
|
309
|
+
*/
|
|
197
310
|
updateConfig(config: Partial<LangChatConfig>): void;
|
|
311
|
+
/**
|
|
312
|
+
* 创建DOM容器
|
|
313
|
+
*/
|
|
198
314
|
private createContainer;
|
|
315
|
+
/**
|
|
316
|
+
* 创建Vue应用
|
|
317
|
+
*/
|
|
199
318
|
private createVueApp;
|
|
319
|
+
/**
|
|
320
|
+
* 触发事件
|
|
321
|
+
*/
|
|
200
322
|
private emit;
|
|
323
|
+
/**
|
|
324
|
+
* 生成唯一ID
|
|
325
|
+
*/
|
|
201
326
|
private generateId;
|
|
327
|
+
/**
|
|
328
|
+
* 初始化OpenAI客户端
|
|
329
|
+
*/
|
|
202
330
|
private initializeOpenAIClient;
|
|
331
|
+
/**
|
|
332
|
+
* 初始化主题管理器
|
|
333
|
+
*/
|
|
203
334
|
private initializeThemeManager;
|
|
335
|
+
/**
|
|
336
|
+
* 初始化欢迎语和问题建议
|
|
337
|
+
*/
|
|
204
338
|
private initializeWelcomeAndQuestions;
|
|
339
|
+
/**
|
|
340
|
+
* 合并配置
|
|
341
|
+
*/
|
|
205
342
|
private mergeConfig;
|
|
343
|
+
/**
|
|
344
|
+
* 保存到历史记录
|
|
345
|
+
*/
|
|
206
346
|
private saveToHistory;
|
|
347
|
+
/**
|
|
348
|
+
* 开始流式回复
|
|
349
|
+
*/
|
|
207
350
|
private startStreamingReply;
|
|
351
|
+
/**
|
|
352
|
+
* 更新容器位置
|
|
353
|
+
*/
|
|
208
354
|
private updateContainerPosition;
|
|
355
|
+
/**
|
|
356
|
+
* 更新OpenAI客户端配置
|
|
357
|
+
*/
|
|
209
358
|
private updateOpenAIClient;
|
|
359
|
+
/**
|
|
360
|
+
* 更新问题建议
|
|
361
|
+
*/
|
|
210
362
|
private updateSuggestedQuestions;
|
|
363
|
+
/**
|
|
364
|
+
* 验证配置
|
|
365
|
+
*/
|
|
211
366
|
private validateConfig;
|
|
367
|
+
private initializeContext;
|
|
368
|
+
private mapAndSetMessages;
|
|
369
|
+
private createConversation;
|
|
370
|
+
private deleteConversation;
|
|
371
|
+
private selectConversation;
|
|
212
372
|
}
|
|
213
373
|
export { LangChatBot }
|
|
214
374
|
export default LangChatBot;
|
|
@@ -228,6 +388,8 @@ export declare interface LangChatConfig {
|
|
|
228
388
|
autoOpen?: boolean;
|
|
229
389
|
position?: 'bottom-left' | 'bottom-right' | 'top-left' | 'top-right';
|
|
230
390
|
zIndex?: number;
|
|
391
|
+
buttonOffset?: string;
|
|
392
|
+
buttonClassName?: string;
|
|
231
393
|
enableMarkdown?: boolean;
|
|
232
394
|
enableHistory?: boolean;
|
|
233
395
|
maxHistoryItems?: number;
|
|
@@ -245,7 +407,7 @@ export declare interface LangChatConfig {
|
|
|
245
407
|
export declare type LangChatEvent = 'close' | 'config-updated' | 'error' | 'init' | 'message-received' | 'message-sent' | 'open' | 'questions-updated' | 'streaming-update';
|
|
246
408
|
|
|
247
409
|
export declare interface LangChatInstance {
|
|
248
|
-
init(): void
|
|
410
|
+
init(): Promise<void>;
|
|
249
411
|
destroy(): void;
|
|
250
412
|
open(): void;
|
|
251
413
|
close(): void;
|
|
@@ -359,7 +521,7 @@ declare class MessageStore {
|
|
|
359
521
|
subtitle?: string | undefined;
|
|
360
522
|
icon?: string | undefined;
|
|
361
523
|
} | undefined;
|
|
362
|
-
}
|
|
524
|
+
}>;
|
|
363
525
|
get userMessages(): ComputedRef< {
|
|
364
526
|
id: string;
|
|
365
527
|
type: "ai" | "questions" | "user" | "welcome";
|
|
@@ -505,12 +667,33 @@ declare class OpenAIClient {
|
|
|
505
667
|
private client;
|
|
506
668
|
private config;
|
|
507
669
|
constructor(config: OpenAIConfig);
|
|
670
|
+
/**
|
|
671
|
+
* 流式聊天(主要方法)
|
|
672
|
+
*/
|
|
508
673
|
chatCompletionStream(request: ChatRequest): AsyncGenerator<StreamingChatResponse, void, unknown>;
|
|
674
|
+
/**
|
|
675
|
+
* 清理资源
|
|
676
|
+
*/
|
|
509
677
|
destroy(): void;
|
|
678
|
+
/**
|
|
679
|
+
* 获取当前配置
|
|
680
|
+
*/
|
|
510
681
|
getConfig(): OpenAIConfig;
|
|
682
|
+
/**
|
|
683
|
+
* 获取模型列表
|
|
684
|
+
*/
|
|
511
685
|
listModels(): Promise<any[]>;
|
|
686
|
+
/**
|
|
687
|
+
* 测试API连接
|
|
688
|
+
*/
|
|
512
689
|
testConnection(): Promise<boolean>;
|
|
690
|
+
/**
|
|
691
|
+
* 更新配置
|
|
692
|
+
*/
|
|
513
693
|
updateConfig(config: Partial<OpenAIConfig>): void;
|
|
694
|
+
/**
|
|
695
|
+
* 错误处理
|
|
696
|
+
*/
|
|
514
697
|
private handleError;
|
|
515
698
|
}
|
|
516
699
|
|
|
@@ -582,27 +765,93 @@ declare class ThemeManager {
|
|
|
582
765
|
private customThemes;
|
|
583
766
|
private styleElement;
|
|
584
767
|
constructor(initialTheme?: Partial<ThemeConfig_2>);
|
|
768
|
+
/**
|
|
769
|
+
* 初始化主题
|
|
770
|
+
*/
|
|
585
771
|
private initializeTheme;
|
|
772
|
+
/**
|
|
773
|
+
* 设置主题监听器
|
|
774
|
+
*/
|
|
586
775
|
private setupThemeWatcher;
|
|
776
|
+
/**
|
|
777
|
+
* 创建样式元素
|
|
778
|
+
*/
|
|
587
779
|
private createStyleElement;
|
|
780
|
+
/**
|
|
781
|
+
* 应用主题
|
|
782
|
+
*/
|
|
588
783
|
private applyTheme;
|
|
784
|
+
/**
|
|
785
|
+
* 生成CSS变量
|
|
786
|
+
*/
|
|
589
787
|
private generateCSSVariables;
|
|
788
|
+
/**
|
|
789
|
+
* 获取系统主题
|
|
790
|
+
*/
|
|
590
791
|
private getSystemTheme;
|
|
792
|
+
/**
|
|
793
|
+
* 从本地存储加载主题
|
|
794
|
+
*/
|
|
591
795
|
private loadThemeFromStorage;
|
|
796
|
+
/**
|
|
797
|
+
* 保存主题到本地存储
|
|
798
|
+
*/
|
|
592
799
|
private saveThemeToStorage;
|
|
800
|
+
/**
|
|
801
|
+
* 获取当前主题
|
|
802
|
+
*/
|
|
593
803
|
getCurrentTheme(): ThemeConfig_2;
|
|
804
|
+
/**
|
|
805
|
+
* 设置主题
|
|
806
|
+
*/
|
|
594
807
|
setTheme(theme: Partial<ThemeConfig_2>): void;
|
|
808
|
+
/**
|
|
809
|
+
* 切换主题模式
|
|
810
|
+
*/
|
|
595
811
|
setThemeMode(mode: ThemeMode): void;
|
|
812
|
+
/**
|
|
813
|
+
* 应用预设主题
|
|
814
|
+
*/
|
|
596
815
|
applyPresetTheme(themeName: string): void;
|
|
816
|
+
/**
|
|
817
|
+
* 添加自定义主题
|
|
818
|
+
*/
|
|
597
819
|
addCustomTheme(name: string, theme: ThemeConfig_2): void;
|
|
820
|
+
/**
|
|
821
|
+
* 获取自定义主题
|
|
822
|
+
*/
|
|
598
823
|
getCustomTheme(name: string): ThemeConfig_2 | null;
|
|
824
|
+
/**
|
|
825
|
+
* 获取所有可用主题
|
|
826
|
+
*/
|
|
599
827
|
getAvailableThemes(): string[];
|
|
828
|
+
/**
|
|
829
|
+
* 获取主题模式
|
|
830
|
+
*/
|
|
600
831
|
getThemeMode(): ThemeMode;
|
|
832
|
+
/**
|
|
833
|
+
* 检查是否为暗色主题
|
|
834
|
+
*/
|
|
601
835
|
isDarkMode(): boolean;
|
|
836
|
+
/**
|
|
837
|
+
* 获取主题CSS变量
|
|
838
|
+
*/
|
|
602
839
|
getCSSVariables(): Record<string, string>;
|
|
840
|
+
/**
|
|
841
|
+
* 导出主题配置
|
|
842
|
+
*/
|
|
603
843
|
exportTheme(): string;
|
|
844
|
+
/**
|
|
845
|
+
* 导入主题配置
|
|
846
|
+
*/
|
|
604
847
|
importTheme(themeData: string): boolean;
|
|
848
|
+
/**
|
|
849
|
+
* 重置为默认主题
|
|
850
|
+
*/
|
|
605
851
|
resetToDefault(): void;
|
|
852
|
+
/**
|
|
853
|
+
* 销毁主题管理器
|
|
854
|
+
*/
|
|
606
855
|
destroy(): void;
|
|
607
856
|
}
|
|
608
857
|
|
|
@@ -610,8 +859,14 @@ export declare const themeManager: ThemeManager;
|
|
|
610
859
|
|
|
611
860
|
declare type ThemeMode = 'light' | 'dark' | 'auto';
|
|
612
861
|
|
|
862
|
+
/**
|
|
863
|
+
* 验证API密钥格式
|
|
864
|
+
*/
|
|
613
865
|
export declare function validateApiKey(apiKey: string): boolean;
|
|
614
866
|
|
|
867
|
+
/**
|
|
868
|
+
* 验证baseUrl格式
|
|
869
|
+
*/
|
|
615
870
|
export declare function validateBaseUrl(baseUrl: string): boolean;
|
|
616
871
|
|
|
617
872
|
export declare const VuePlugin: {
|