ibc-ai-web-sdk 2.0.5 → 2.1.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/dist/index.cjs.js +277 -618
- package/dist/index.esm.js +277 -618
- package/dist/index.umd.js +5268 -5609
- package/dist/index.umd.min.js +1 -1
- package/dist-ts/AIChatDialog.d.ts +184 -0
- package/dist-ts/config/defaultConfig.d.ts +43 -0
- package/dist-ts/config/themes.d.ts +1568 -0
- package/dist-ts/core/AIChatClient.d.ts +56 -0
- package/dist-ts/index.d.ts +45 -0
- package/dist-ts/types.d.ts +456 -0
- package/dist-ts/utils/errorCodes.d.ts +15 -0
- package/dist-ts/utils/logger.d.ts +16 -0
- package/dist-ts/utils/messageIdGenerator.d.ts +12 -0
- package/package.json +17 -9
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.esm.js.map +0 -1
- package/dist/index.umd.js.map +0 -1
- package/index.d.ts +0 -130
- package/src/types.ts +0 -599
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AIChatDialog - 纯JavaScript实现的AI对话组件 (Web Components)
|
|
3
|
+
* 样式与功能完全对齐 Vue 版本(1:1 复刻)
|
|
4
|
+
*
|
|
5
|
+
* @author IBC AI Team
|
|
6
|
+
* @version 2.1.0
|
|
7
|
+
*/
|
|
8
|
+
declare class AIChatDialog extends HTMLElement {
|
|
9
|
+
static get observedAttributes(): string[];
|
|
10
|
+
private _messages;
|
|
11
|
+
private _isLoading;
|
|
12
|
+
private _config;
|
|
13
|
+
private _mockMode;
|
|
14
|
+
private _isDragging;
|
|
15
|
+
private _isExpanded;
|
|
16
|
+
private _chatClient;
|
|
17
|
+
private _attachments;
|
|
18
|
+
private _dragStartX;
|
|
19
|
+
private _dragStartY;
|
|
20
|
+
private _dialogX;
|
|
21
|
+
private _dialogY;
|
|
22
|
+
private _appDetail;
|
|
23
|
+
private _historyVisible;
|
|
24
|
+
private _historyRecords;
|
|
25
|
+
private _historyLoading;
|
|
26
|
+
private _historyLoaded;
|
|
27
|
+
private _historyPageIndex;
|
|
28
|
+
private _historyHasMore;
|
|
29
|
+
private _isMobile;
|
|
30
|
+
private _streamTextEl;
|
|
31
|
+
private _streamInitDone;
|
|
32
|
+
private _streamFullText;
|
|
33
|
+
private _streamVisibleLength;
|
|
34
|
+
private _streamTypeRaf;
|
|
35
|
+
private _streaming;
|
|
36
|
+
private _runtimePanelEl;
|
|
37
|
+
private _runtimeEventsContainerEl;
|
|
38
|
+
private _runtimeStatusEl;
|
|
39
|
+
private _runtimeCountEl;
|
|
40
|
+
private _context;
|
|
41
|
+
private _themeVars;
|
|
42
|
+
private _handleOnline;
|
|
43
|
+
private _handleOffline;
|
|
44
|
+
private _handleResize;
|
|
45
|
+
private _dialog;
|
|
46
|
+
private _body;
|
|
47
|
+
private _input;
|
|
48
|
+
private _sendBtn;
|
|
49
|
+
private _attachBtn;
|
|
50
|
+
private _attachmentInput;
|
|
51
|
+
private _closeBtn;
|
|
52
|
+
private _expandBtn;
|
|
53
|
+
private _newChatBtn;
|
|
54
|
+
private _historyBtn;
|
|
55
|
+
private _floatBtn;
|
|
56
|
+
private _inputContainer;
|
|
57
|
+
private _conversationId;
|
|
58
|
+
private _lastSendTime;
|
|
59
|
+
private _dragMouseDownHandler;
|
|
60
|
+
private _dragMouseMoveHandler;
|
|
61
|
+
private _dragMouseUpHandler;
|
|
62
|
+
private _dragTouchStartHandler;
|
|
63
|
+
private _dragTouchMoveHandler;
|
|
64
|
+
private _dragTouchEndHandler;
|
|
65
|
+
private _dragInitialized;
|
|
66
|
+
private _ERROR_CONTENT_PATTERNS;
|
|
67
|
+
constructor();
|
|
68
|
+
connectedCallback(): void;
|
|
69
|
+
disconnectedCallback(): void;
|
|
70
|
+
_detectMobile(): void;
|
|
71
|
+
_applyMobileLayout(): void;
|
|
72
|
+
attributeChangedCallback(name: any, oldValue: any, newValue: any): void;
|
|
73
|
+
get visible(): boolean;
|
|
74
|
+
set visible(v: boolean);
|
|
75
|
+
get messages(): any[];
|
|
76
|
+
get isLoading(): boolean;
|
|
77
|
+
get config(): any;
|
|
78
|
+
init(config?: any): this;
|
|
79
|
+
open(): this;
|
|
80
|
+
close(): this;
|
|
81
|
+
toggle(forceState: any): this;
|
|
82
|
+
destroy(): void;
|
|
83
|
+
addMessage(message: any): this;
|
|
84
|
+
clearMessages(): this;
|
|
85
|
+
setLoading(loading: any): this;
|
|
86
|
+
updateConfig(config: any): this;
|
|
87
|
+
enableMockMode(): this;
|
|
88
|
+
disableMockMode(): this;
|
|
89
|
+
/**
|
|
90
|
+
* 设置页面上下文数据(宿主页面选中的数据,随每次请求发送)
|
|
91
|
+
* @param {Object} context - 上下文数据对象,传 null 清空
|
|
92
|
+
* @returns {this}
|
|
93
|
+
*/
|
|
94
|
+
setContext(context: any): this;
|
|
95
|
+
/**
|
|
96
|
+
* 获取当前上下文数据
|
|
97
|
+
* @returns {Object}
|
|
98
|
+
*/
|
|
99
|
+
getContext(): {
|
|
100
|
+
[x: string]: any;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* 外部触发表态发送(业务层主动调用,如点击外部按钮触发 AI 请求)
|
|
104
|
+
* @param {string} text - 要发送的消息内容
|
|
105
|
+
* @returns {this}
|
|
106
|
+
*/
|
|
107
|
+
send(text: any): this;
|
|
108
|
+
showDialog(): void;
|
|
109
|
+
hideDialog(): void;
|
|
110
|
+
render(): void;
|
|
111
|
+
bindEvents(): void;
|
|
112
|
+
toggleExpand(): void;
|
|
113
|
+
initDraggable(): void;
|
|
114
|
+
_cleanupDragListeners(): void;
|
|
115
|
+
applyConfig(): void;
|
|
116
|
+
loadAppDetail(): Promise<void>;
|
|
117
|
+
_parsePrologue(prologue: any): {
|
|
118
|
+
text: string;
|
|
119
|
+
questions: any[];
|
|
120
|
+
};
|
|
121
|
+
renderMessages(options?: any): void;
|
|
122
|
+
renderHistoryView(): void;
|
|
123
|
+
_buildHistoryItem(record: any, idx: any): string;
|
|
124
|
+
_getFilteredHistoryRecords(): any[];
|
|
125
|
+
toggleHistory(): Promise<void>;
|
|
126
|
+
loadHistoryRecords(append?: boolean): Promise<void>;
|
|
127
|
+
openHistoryRecord(record: any): Promise<void>;
|
|
128
|
+
_recordsToMessages(records: any): any[];
|
|
129
|
+
updateLoadingUI(): void;
|
|
130
|
+
scrollToBottom(): void;
|
|
131
|
+
_shouldAutoScroll(): boolean;
|
|
132
|
+
_autoResizeInput(): void;
|
|
133
|
+
_updateSendButtonState(): void;
|
|
134
|
+
_handleAttachmentSelect(): void;
|
|
135
|
+
handleSend(): Promise<void>;
|
|
136
|
+
sendMessageToAI(content: any, options?: any): Promise<void>;
|
|
137
|
+
mockResponse(userContent: any): Promise<void>;
|
|
138
|
+
updateStreamingBubble(msgId: any, content: any): void;
|
|
139
|
+
finalizeStream(msgId: any): void;
|
|
140
|
+
_directApiCallStream(msgId: any, content: any, requestOptions?: any): Promise<void>;
|
|
141
|
+
_getStreamTextEl(): any;
|
|
142
|
+
_updateMsg(msgId: any, content: any): void;
|
|
143
|
+
_finalizeMsg(msgId: any, content: any): void;
|
|
144
|
+
_isPlaceholder(text: any): boolean;
|
|
145
|
+
_isEventLike(text: any): any;
|
|
146
|
+
_isErrorContent(content: any): boolean;
|
|
147
|
+
_formatContextText(context: any): string;
|
|
148
|
+
_addRuntimeEvent(msgId: any, event: any): void;
|
|
149
|
+
_findStreamingMessageContent(): any;
|
|
150
|
+
_createRuntimePanelDOM(msg: any): HTMLDivElement;
|
|
151
|
+
_getCustomActions(msg: any, idx: any): any;
|
|
152
|
+
_buildCustomActions(msg: any, idx: any): any;
|
|
153
|
+
_buildRuntimePanel(msg: any, msgIdx: any): string;
|
|
154
|
+
_fetchConversationResult(conversationId: any): Promise<any>;
|
|
155
|
+
regenerate(index: any): Promise<void>;
|
|
156
|
+
showToast(msg: any): void;
|
|
157
|
+
handleError(err: any): void;
|
|
158
|
+
copyContent(text: any): Promise<void>;
|
|
159
|
+
_fallbackCopy(text: any): void;
|
|
160
|
+
copyMessage(content: any, idx: any): Promise<void>;
|
|
161
|
+
clearChat(): void;
|
|
162
|
+
stopGeneration(): Promise<void>;
|
|
163
|
+
uploadAttachment(file: any, options?: any): Promise<any>;
|
|
164
|
+
generateId(): string;
|
|
165
|
+
formatTime(): string;
|
|
166
|
+
/**
|
|
167
|
+
* 调试日志(仅在 config.debug === true 时输出)
|
|
168
|
+
*/
|
|
169
|
+
_debugLog(tag: any, ...args: any[]): void;
|
|
170
|
+
_debugWarn(tag: any, ...args: any[]): void;
|
|
171
|
+
escapeHtml(s: any): string;
|
|
172
|
+
escapeAttr(s: any): any;
|
|
173
|
+
/**
|
|
174
|
+
* 重置 _themeVars 为默认值(主题切换时调用,防止残留)
|
|
175
|
+
*/
|
|
176
|
+
_resetThemeVars(): void;
|
|
177
|
+
/**
|
|
178
|
+
* Markdown → HTML 解析(仅用于AI回复,用户消息保持纯文本)
|
|
179
|
+
* 使用 marked + DOMPurify 双重保障安全
|
|
180
|
+
*/
|
|
181
|
+
parseMarkdown(text: any): any;
|
|
182
|
+
}
|
|
183
|
+
export default AIChatDialog;
|
|
184
|
+
export { AIChatDialog };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 默认配置(精简版 - 只保留实际使用的配置)
|
|
3
|
+
*/
|
|
4
|
+
export declare const defaultConfig: {
|
|
5
|
+
apiBaseUrl: string;
|
|
6
|
+
apiEndpoint: string;
|
|
7
|
+
streamEndpoint: string;
|
|
8
|
+
stopEndpoint: string;
|
|
9
|
+
asyncEndpoint: string;
|
|
10
|
+
attachmentUploadEndpoint: string;
|
|
11
|
+
conversationQueryEndpoint: string;
|
|
12
|
+
conversationDeleteEndpoint: string;
|
|
13
|
+
appDetailEndpoint: string;
|
|
14
|
+
taskStatusEndpoint: string;
|
|
15
|
+
appId: string;
|
|
16
|
+
agentAppId: string;
|
|
17
|
+
userId: string;
|
|
18
|
+
bizType: string;
|
|
19
|
+
token: string;
|
|
20
|
+
refreshToken: string;
|
|
21
|
+
tokenExpiresAt: number;
|
|
22
|
+
tokenRefreshBufferMs: number;
|
|
23
|
+
refreshTokenFn: any;
|
|
24
|
+
onTokenRefreshed: any;
|
|
25
|
+
onTokenExpired: any;
|
|
26
|
+
authErrorCodes: any[];
|
|
27
|
+
backgroundRefreshEnabled: boolean;
|
|
28
|
+
backgroundRefreshIntervalMs: number;
|
|
29
|
+
timeout: number;
|
|
30
|
+
headers: {};
|
|
31
|
+
extendInfo: any;
|
|
32
|
+
title: string;
|
|
33
|
+
welcomeText: string;
|
|
34
|
+
welcomeDesc: string;
|
|
35
|
+
historyPageSize: number;
|
|
36
|
+
historyDays: number;
|
|
37
|
+
theme: string;
|
|
38
|
+
enableDrag: boolean;
|
|
39
|
+
authFn: any;
|
|
40
|
+
onLoad: any;
|
|
41
|
+
onError: any;
|
|
42
|
+
};
|
|
43
|
+
export default defaultConfig;
|