ibc-ai-web-sdk 2.0.4 → 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 +560 -654
- package/dist/index.esm.js +560 -654
- package/dist/index.umd.js +5305 -5399
- 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 -96
- package/src/types.ts +0 -599
package/index.d.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* IBC AI Web SDK - 类型声明文件
|
|
3
|
-
* 为 JavaScript 项目提供 TypeScript 类型提示
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type {
|
|
7
|
-
AIChatConfig,
|
|
8
|
-
AIChatClient,
|
|
9
|
-
AIResponse,
|
|
10
|
-
Message,
|
|
11
|
-
SDKEvents,
|
|
12
|
-
ErrorCode,
|
|
13
|
-
TokenRefreshContext,
|
|
14
|
-
TokenRefreshResult,
|
|
15
|
-
TokenRefreshSuccess
|
|
16
|
-
} from './src/types'
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* AI Chat Dialog 组件配置
|
|
20
|
-
*/
|
|
21
|
-
export interface AIChatDialogProps {
|
|
22
|
-
config: AIChatConfig
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* AI Chat Dialog 组件事件
|
|
27
|
-
*/
|
|
28
|
-
export interface AIChatDialogEvents extends SDKEvents {
|
|
29
|
-
/** 清除对话 */
|
|
30
|
-
'clear': void
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* AI Chat Dialog 组件方法
|
|
35
|
-
*/
|
|
36
|
-
export interface AIChatDialogMethods {
|
|
37
|
-
/** 打开对话框 */
|
|
38
|
-
open(): void
|
|
39
|
-
|
|
40
|
-
/** 关闭对话框 */
|
|
41
|
-
close(): void
|
|
42
|
-
|
|
43
|
-
/** 清除对话(开始新对话) */
|
|
44
|
-
clearChat(): void
|
|
45
|
-
|
|
46
|
-
/** 停止当前生成 */
|
|
47
|
-
stopGeneration(): Promise<void>
|
|
48
|
-
|
|
49
|
-
/** 上传附件 */
|
|
50
|
-
uploadAttachment(file: File, options?: Record<string, any>): Promise<AIResponse>
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* 导入 SDK 插件
|
|
55
|
-
*/
|
|
56
|
-
export function install(Vue: any): void
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* AI Chat Dialog 组件
|
|
60
|
-
*/
|
|
61
|
-
export const AIChatDialog: any
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* AI Chat Client
|
|
65
|
-
*/
|
|
66
|
-
export const AIChatClient: {
|
|
67
|
-
new(config: AIChatConfig): AIChatClient
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function createAIChatDialog(options?: Partial<AIChatConfig>): any
|
|
71
|
-
|
|
72
|
-
export function installVuePlugin(Vue: any): void
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* 默认导出
|
|
76
|
-
*/
|
|
77
|
-
export default {
|
|
78
|
-
install,
|
|
79
|
-
AIChatDialog,
|
|
80
|
-
AIChatClient,
|
|
81
|
-
createAIChatDialog,
|
|
82
|
-
installVuePlugin
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// 导出类型
|
|
86
|
-
export {
|
|
87
|
-
AIChatConfig,
|
|
88
|
-
AIChatClient,
|
|
89
|
-
AIResponse,
|
|
90
|
-
Message,
|
|
91
|
-
SDKEvents,
|
|
92
|
-
ErrorCode,
|
|
93
|
-
TokenRefreshContext,
|
|
94
|
-
TokenRefreshResult,
|
|
95
|
-
TokenRefreshSuccess
|
|
96
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,599 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* IBC AI Web SDK - TypeScript 类型定义
|
|
3
|
-
* 统一定义所有类型和接口,提供完整的类型提示
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* AI 聊天配置接口
|
|
8
|
-
*/
|
|
9
|
-
export interface AIChatConfig {
|
|
10
|
-
// ===== 必填配置 =====
|
|
11
|
-
|
|
12
|
-
/** API 接口地址 */
|
|
13
|
-
apiEndpoint: string
|
|
14
|
-
|
|
15
|
-
/** API 基础地址,默认空字符串 */
|
|
16
|
-
apiBaseUrl?: string
|
|
17
|
-
|
|
18
|
-
/** 流式接口地址,默认 /v1/app/completion/stream */
|
|
19
|
-
streamEndpoint?: string
|
|
20
|
-
|
|
21
|
-
/** 停止生成接口地址,默认 /v1/app/completion/stop */
|
|
22
|
-
stopEndpoint?: string
|
|
23
|
-
|
|
24
|
-
/** 附件上传接口地址,默认 /v1/app/attachment/upload */
|
|
25
|
-
attachmentUploadEndpoint?: string
|
|
26
|
-
|
|
27
|
-
/** 应用详情接口地址,默认 /v1/app/{appId} */
|
|
28
|
-
appDetailEndpoint?: string
|
|
29
|
-
|
|
30
|
-
/** 异步任务提交接口地址,默认 /v1/app/completion/async */
|
|
31
|
-
asyncEndpoint?: string
|
|
32
|
-
|
|
33
|
-
/** 任务状态查询接口地址,默认 /v1/app/task/{taskId} */
|
|
34
|
-
taskStatusEndpoint?: string
|
|
35
|
-
|
|
36
|
-
/** 会话查询接口地址,默认 /v1/app/conversation/query */
|
|
37
|
-
conversationQueryEndpoint?: string
|
|
38
|
-
|
|
39
|
-
/** 会话删除接口地址,默认 /v1/app/conversation/delete */
|
|
40
|
-
conversationDeleteEndpoint?: string
|
|
41
|
-
|
|
42
|
-
/** 应用列表接口地址,默认 /v1/app/list */
|
|
43
|
-
appListEndpoint?: string
|
|
44
|
-
|
|
45
|
-
/** 权限确认回复接口地址,默认 /v1/app/runtime/permission/reply */
|
|
46
|
-
runtimePermissionReplyEndpoint?: string
|
|
47
|
-
|
|
48
|
-
/** 问题回复接口地址,默认 /v1/app/runtime/question/reply */
|
|
49
|
-
runtimeQuestionReplyEndpoint?: string
|
|
50
|
-
|
|
51
|
-
/** 问题拒绝接口地址,默认 /v1/app/runtime/question/reject */
|
|
52
|
-
runtimeQuestionRejectEndpoint?: string
|
|
53
|
-
|
|
54
|
-
/** 应用 ID */
|
|
55
|
-
appId: string
|
|
56
|
-
|
|
57
|
-
/** @deprecated 请使用 appId */
|
|
58
|
-
agentAppId?: string
|
|
59
|
-
|
|
60
|
-
/** 用户 ID */
|
|
61
|
-
userId: string
|
|
62
|
-
|
|
63
|
-
/** 业务类型标识 */
|
|
64
|
-
bizType: string
|
|
65
|
-
|
|
66
|
-
/** 认证 Token */
|
|
67
|
-
token?: string
|
|
68
|
-
|
|
69
|
-
/** 刷新 Token,可由 refreshTokenFn 使用 */
|
|
70
|
-
refreshToken?: string
|
|
71
|
-
|
|
72
|
-
/** Token 过期时间戳(毫秒),配置后 SDK 会在过期前自动刷新 */
|
|
73
|
-
tokenExpiresAt?: number
|
|
74
|
-
|
|
75
|
-
/** Token 过期前多久主动刷新,默认 60000ms */
|
|
76
|
-
tokenRefreshBufferMs?: number
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Token 刷新函数。返回字符串时视为新的 access token;
|
|
80
|
-
* 返回对象时支持 token/accessToken、refreshToken、expiresAt、expiresIn、headers。
|
|
81
|
-
*/
|
|
82
|
-
refreshTokenFn?: (context: TokenRefreshContext) => Promise<TokenRefreshResult>
|
|
83
|
-
|
|
84
|
-
/** Token 刷新成功回调 */
|
|
85
|
-
onTokenRefreshed?: (result: TokenRefreshSuccess) => void
|
|
86
|
-
|
|
87
|
-
/** Token 刷新失败或未配置刷新函数时触发 */
|
|
88
|
-
onTokenExpired?: (error: Error | unknown) => void
|
|
89
|
-
|
|
90
|
-
/** 额外业务未授权错误码,默认已包含 401/403/1005/S00001/ET0006/999990 */
|
|
91
|
-
authErrorCodes?: Array<string | number>
|
|
92
|
-
|
|
93
|
-
// ===== 可选配置 =====
|
|
94
|
-
|
|
95
|
-
/** 请求超时时间(毫秒),默认 60000 */
|
|
96
|
-
timeout?: number
|
|
97
|
-
|
|
98
|
-
/** 自定义请求头 */
|
|
99
|
-
headers?: Record<string, string>
|
|
100
|
-
|
|
101
|
-
/** 扩展信息 */
|
|
102
|
-
extendInfo?: Record<string, any> | null
|
|
103
|
-
|
|
104
|
-
// ===== UI 配置 =====
|
|
105
|
-
|
|
106
|
-
/** 对话框标题,默认 'AI 智能助理' */
|
|
107
|
-
title?: string
|
|
108
|
-
|
|
109
|
-
/** 欢迎文本,默认 '您好!我是 AI 智能助理' */
|
|
110
|
-
welcomeText?: string
|
|
111
|
-
|
|
112
|
-
/** 欢迎描述,默认 '我可以帮您解答系统使用问题' */
|
|
113
|
-
welcomeDesc?: string
|
|
114
|
-
|
|
115
|
-
/** 最大消息数量,默认 50 */
|
|
116
|
-
maxMessages?: number
|
|
117
|
-
|
|
118
|
-
/** 输入框最大字数,默认 500 */
|
|
119
|
-
maxLength?: number
|
|
120
|
-
|
|
121
|
-
/** 历史记录查询条数,默认 20 */
|
|
122
|
-
historyPageSize?: number
|
|
123
|
-
|
|
124
|
-
/** 历史记录保留天数,默认 30;0 表示不按天过滤 */
|
|
125
|
-
historyDays?: number
|
|
126
|
-
|
|
127
|
-
/** 是否允许拖拽,默认 true */
|
|
128
|
-
enableDrag?: boolean
|
|
129
|
-
|
|
130
|
-
// ===== 可选鉴权 =====
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* 可选鉴权函数
|
|
134
|
-
* @param token - 当前用户的 token
|
|
135
|
-
* @param userId - 用户 ID
|
|
136
|
-
* @returns Promise<void>,resolve 表示通过,reject/throw 表示拒绝
|
|
137
|
-
*/
|
|
138
|
-
authFn?: (token: string, userId: string) => Promise<void>
|
|
139
|
-
|
|
140
|
-
// ===== 事件回调 =====
|
|
141
|
-
|
|
142
|
-
/** SDK 加载完成回调 */
|
|
143
|
-
onLoad?: (client: AIChatClient) => void
|
|
144
|
-
|
|
145
|
-
/** 错误回调 */
|
|
146
|
-
onError?: (error: Error | string) => void
|
|
147
|
-
|
|
148
|
-
// ===== 主题配置(可选) =====
|
|
149
|
-
|
|
150
|
-
/** 主题配置 */
|
|
151
|
-
theme?: {
|
|
152
|
-
/** 主色调 */
|
|
153
|
-
primaryColor?: string
|
|
154
|
-
/** 背景色 */
|
|
155
|
-
backgroundColor?: string
|
|
156
|
-
/** 气泡背景色 */
|
|
157
|
-
bubbleColor?: string
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* AI 聊天客户端接口
|
|
163
|
-
*/
|
|
164
|
-
export interface AIChatClient {
|
|
165
|
-
/** 发送聊天消息 */
|
|
166
|
-
sendMessage(prompt: string, token?: string, options?: AIChatRequestOptions): Promise<AIResponse>
|
|
167
|
-
|
|
168
|
-
/** 发送流式聊天消息 */
|
|
169
|
-
sendMessageStream(prompt: string, handlers?: AIStreamHandlers, options?: AIChatRequestOptions): Promise<AIResponse>
|
|
170
|
-
|
|
171
|
-
/** 停止当前流式生成 */
|
|
172
|
-
stopCompletion(requestId?: string): Promise<AIResponse>
|
|
173
|
-
|
|
174
|
-
/** 上传附件 */
|
|
175
|
-
uploadAttachment(file: File, options?: UploadAttachmentOptions): Promise<AIResponse<AttachmentUploadResponse>>
|
|
176
|
-
|
|
177
|
-
/** 查询会话记录 */
|
|
178
|
-
queryConversation(options?: ConversationQueryOptions): Promise<AIResponse<ConversationQueryResponse>>
|
|
179
|
-
|
|
180
|
-
/** 删除会话记录 */
|
|
181
|
-
deleteConversation(conversationId?: string, options?: ConversationQueryOptions): Promise<AIResponse>
|
|
182
|
-
|
|
183
|
-
/** 异步提交任务 */
|
|
184
|
-
asyncCompletion(prompt: string, options?: AIChatRequestOptions): Promise<AIResponse>
|
|
185
|
-
|
|
186
|
-
/** 查询异步任务状态 */
|
|
187
|
-
getTaskStatus(taskId: string): Promise<AIResponse>
|
|
188
|
-
|
|
189
|
-
/** 查询智能体详情 */
|
|
190
|
-
getAppDetail(appId?: string): Promise<AIResponse>
|
|
191
|
-
|
|
192
|
-
/** 查询可用智能体应用列表 */
|
|
193
|
-
listApplications(options?: AppListOptions): Promise<AIResponse<AppListResponse>>
|
|
194
|
-
|
|
195
|
-
/** 回复权限确认请求(HITL权限交互) */
|
|
196
|
-
replyPermission(request: PermissionReplyRequest): Promise<AIResponse>
|
|
197
|
-
|
|
198
|
-
/** 回复智能体问题(HITL问答交互) */
|
|
199
|
-
replyQuestion(request: QuestionReplyRequest): Promise<AIResponse>
|
|
200
|
-
|
|
201
|
-
/** 拒绝智能体问题(HITL问答拒绝) */
|
|
202
|
-
rejectQuestion(request: QuestionRejectRequest): Promise<AIResponse>
|
|
203
|
-
|
|
204
|
-
/** 设置会话 ID */
|
|
205
|
-
setConversationId(conversationId: string): void
|
|
206
|
-
|
|
207
|
-
/** 清除会话 ID(开始新对话) */
|
|
208
|
-
clearConversation(): void
|
|
209
|
-
|
|
210
|
-
/** 取消当前请求 */
|
|
211
|
-
cancelCurrentRequest(): void
|
|
212
|
-
|
|
213
|
-
/** 更新配置 */
|
|
214
|
-
updateConfig(newConfig: Partial<AIChatConfig>): void
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
export interface TokenRefreshContext {
|
|
218
|
-
token: string
|
|
219
|
-
refreshToken: string
|
|
220
|
-
userId: string
|
|
221
|
-
reason: 'preflight' | 'response' | 'authFn' | string
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
export type TokenRefreshResult = string | {
|
|
225
|
-
token?: string
|
|
226
|
-
accessToken?: string
|
|
227
|
-
authorization?: string
|
|
228
|
-
refreshToken?: string
|
|
229
|
-
expiresAt?: number
|
|
230
|
-
expiresIn?: number
|
|
231
|
-
headers?: Record<string, string>
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
export interface TokenRefreshSuccess {
|
|
235
|
-
token: string
|
|
236
|
-
refreshToken?: string
|
|
237
|
-
tokenExpiresAt?: number
|
|
238
|
-
raw?: TokenRefreshResult
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* AI 响应接口
|
|
243
|
-
*/
|
|
244
|
-
export interface AIResponse<TData = {
|
|
245
|
-
/** AI 回复内容 */
|
|
246
|
-
content?: string
|
|
247
|
-
/** 回复文本(兼容旧格式) */
|
|
248
|
-
replyText?: string
|
|
249
|
-
/** 会话 ID */
|
|
250
|
-
conversationId?: string
|
|
251
|
-
/** 消息 ID */
|
|
252
|
-
messageId?: string
|
|
253
|
-
/** 使用量统计 */
|
|
254
|
-
usage?: {
|
|
255
|
-
/** 输入 token 数 */
|
|
256
|
-
inputTokens: number
|
|
257
|
-
/** 输出 token 数 */
|
|
258
|
-
outputTokens: number
|
|
259
|
-
}
|
|
260
|
-
} | null> {
|
|
261
|
-
/** 是否成功 */
|
|
262
|
-
success: boolean
|
|
263
|
-
|
|
264
|
-
/** 状态码 */
|
|
265
|
-
code: number
|
|
266
|
-
|
|
267
|
-
/** 消息 */
|
|
268
|
-
message: string
|
|
269
|
-
|
|
270
|
-
/** 响应数据 */
|
|
271
|
-
data: TData
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
export interface AIChatRequestOptions {
|
|
275
|
-
appId?: string
|
|
276
|
-
userId?: string
|
|
277
|
-
bizType?: string
|
|
278
|
-
conversationId?: string
|
|
279
|
-
requestId?: string
|
|
280
|
-
attachmentIds?: string[]
|
|
281
|
-
attachments?: Array<string | { attachmentId?: string; fileId?: string; id?: string }>
|
|
282
|
-
bizParams?: Record<string, any> | string
|
|
283
|
-
extendInfo?: Record<string, any> | string
|
|
284
|
-
timeout?: number
|
|
285
|
-
retries?: number
|
|
286
|
-
endpoint?: string
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
export interface AIStreamHandlers {
|
|
290
|
-
onStart?: () => void
|
|
291
|
-
onProgress?: (message: string) => void
|
|
292
|
-
onMessage?: (chunk: string) => void
|
|
293
|
-
onMeta?: (meta: Record<string, any>) => void
|
|
294
|
-
onPlanningEvent?: (event: Record<string, any>) => void
|
|
295
|
-
/** 思考/推理文本增量(DeepSeek-R1 / Claude thinking) */
|
|
296
|
-
onThinking?: (thinking: string) => void
|
|
297
|
-
/** 执行进度书签事件 */
|
|
298
|
-
onProgressEvent?: (stage: string, message: string) => void
|
|
299
|
-
/** 工具调用开始 */
|
|
300
|
-
onToolStart?: (toolName: string, toolCallId: string) => void
|
|
301
|
-
/** 工具调用结果增量 */
|
|
302
|
-
onToolResult?: (toolName: string, text: string) => void
|
|
303
|
-
/** 工具调用结束 */
|
|
304
|
-
onToolEnd?: (toolName: string, toolCallId: string) => void
|
|
305
|
-
/** 工作流节点开始 */
|
|
306
|
-
onNodeStart?: (nodeName: string, message: string) => void
|
|
307
|
-
/** 工作流节点进度 */
|
|
308
|
-
onNodeProgress?: (nodeName: string, message: string) => void
|
|
309
|
-
/** 工作流节点完成 */
|
|
310
|
-
onNodeComplete?: (nodeName: string, message: string) => void
|
|
311
|
-
/** 警告事件 */
|
|
312
|
-
onWarning?: (message: string) => void
|
|
313
|
-
/** HITL 人机交互中断(权限确认/问题提问) */
|
|
314
|
-
onHitlInterrupt?: (hitlData: HitlInterruptData) => void
|
|
315
|
-
onError?: (message: string, raw?: any) => void
|
|
316
|
-
onDone?: (finalText?: string) => void
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* HITL 交互中断数据
|
|
321
|
-
*/
|
|
322
|
-
export interface HitlInterruptData {
|
|
323
|
-
type: 'TOOL_CONFIRMATION' | 'QUESTION'
|
|
324
|
-
requestId: string
|
|
325
|
-
sessionId: string
|
|
326
|
-
taskRunId?: string
|
|
327
|
-
toolCalls?: ToolCallInfo[]
|
|
328
|
-
message?: string
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* 工具调用信息
|
|
333
|
-
*/
|
|
334
|
-
export interface ToolCallInfo {
|
|
335
|
-
id?: string
|
|
336
|
-
name?: string
|
|
337
|
-
input?: Record<string, any>
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
export interface UploadAttachmentOptions {
|
|
341
|
-
userId?: string
|
|
342
|
-
fileType?: string
|
|
343
|
-
conversationId?: string
|
|
344
|
-
timeout?: number
|
|
345
|
-
endpoint?: string
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
export interface AttachmentUploadResponse {
|
|
349
|
-
attachmentId: string
|
|
350
|
-
fileName: string
|
|
351
|
-
fileSize?: number
|
|
352
|
-
fileType?: string
|
|
353
|
-
fileUrl?: string
|
|
354
|
-
filePath?: string
|
|
355
|
-
mimeType?: string
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
export interface ConversationQueryOptions {
|
|
359
|
-
userId?: string
|
|
360
|
-
conversationId?: string
|
|
361
|
-
appId?: string
|
|
362
|
-
bizType?: string
|
|
363
|
-
pageIndex?: number
|
|
364
|
-
pageSize?: number
|
|
365
|
-
requestId?: string
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
export interface ConversationRecord {
|
|
369
|
-
recordId?: string | number
|
|
370
|
-
requestId?: string
|
|
371
|
-
conversationId?: string
|
|
372
|
-
role?: string
|
|
373
|
-
content?: string
|
|
374
|
-
prompt?: string
|
|
375
|
-
replyText?: string
|
|
376
|
-
answer?: string
|
|
377
|
-
createTime?: string
|
|
378
|
-
attachments?: AttachmentUploadResponse[]
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
export interface ConversationQueryResponse {
|
|
382
|
-
conversationId: string
|
|
383
|
-
appId?: string
|
|
384
|
-
records: ConversationRecord[]
|
|
385
|
-
total?: number
|
|
386
|
-
pageIndex?: number
|
|
387
|
-
pageSize?: number
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
* HITL 权限回复请求
|
|
392
|
-
*/
|
|
393
|
-
export interface PermissionReplyRequest {
|
|
394
|
-
/** 会话ID(来自[HITL]事件) */
|
|
395
|
-
sessionId: string
|
|
396
|
-
/** 权限请求ID(来自[HITL]事件) */
|
|
397
|
-
requestId: string
|
|
398
|
-
/** 回复动作:once-仅本次 always-始终允许 reject-拒绝 */
|
|
399
|
-
reply: 'once' | 'always' | 'reject'
|
|
400
|
-
/** 补充说明 */
|
|
401
|
-
message?: string
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
/**
|
|
405
|
-
* HITL 问题回复请求
|
|
406
|
-
*/
|
|
407
|
-
export interface QuestionReplyRequest {
|
|
408
|
-
/** 会话ID(来自[HITL]事件) */
|
|
409
|
-
sessionId: string
|
|
410
|
-
/** 问题请求ID(来自[HITL]事件) */
|
|
411
|
-
requestId: string
|
|
412
|
-
/** 答案列表(二维数组) */
|
|
413
|
-
answers: string[][]
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
/**
|
|
417
|
-
* HITL 问题拒绝请求
|
|
418
|
-
*/
|
|
419
|
-
export interface QuestionRejectRequest {
|
|
420
|
-
/** 会话ID(来自[HITL]事件) */
|
|
421
|
-
sessionId: string
|
|
422
|
-
/** 问题请求ID(来自[HITL]事件) */
|
|
423
|
-
requestId: string
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
/**
|
|
427
|
-
* 应用列表查询选项
|
|
428
|
-
*/
|
|
429
|
-
export interface AppListOptions {
|
|
430
|
-
/** 应用类型过滤:1-简易问答 3-智能助手 2-高级编排,不传则返回全部 */
|
|
431
|
-
applicationType?: number
|
|
432
|
-
/** 页码,默认1 */
|
|
433
|
-
pageIndex?: number
|
|
434
|
-
/** 每页大小,默认20,最大50 */
|
|
435
|
-
pageSize?: number
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
/**
|
|
439
|
-
* 应用列表项
|
|
440
|
-
*/
|
|
441
|
-
export interface AppListItem {
|
|
442
|
-
/** 应用ID */
|
|
443
|
-
appId: string
|
|
444
|
-
/** 应用名称 */
|
|
445
|
-
name: string
|
|
446
|
-
/** 应用描述 */
|
|
447
|
-
description?: string
|
|
448
|
-
/** 应用类型 */
|
|
449
|
-
applicationType?: number
|
|
450
|
-
/** 应用图标URL */
|
|
451
|
-
icon?: string
|
|
452
|
-
/** 开场白/欢迎语 */
|
|
453
|
-
prologue?: string
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
/**
|
|
457
|
-
* 应用列表响应
|
|
458
|
-
*/
|
|
459
|
-
export interface AppListResponse {
|
|
460
|
-
/** 应用列表 */
|
|
461
|
-
records: AppListItem[]
|
|
462
|
-
/** 总数 */
|
|
463
|
-
total?: number
|
|
464
|
-
/** 当前页码 */
|
|
465
|
-
currentPage?: number
|
|
466
|
-
/** 每页大小 */
|
|
467
|
-
pageSize?: number
|
|
468
|
-
/** 总页数 */
|
|
469
|
-
pages?: number
|
|
470
|
-
/** 默认对话应用ID */
|
|
471
|
-
defaultChatAppId?: string
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
/**
|
|
475
|
-
* 消息类型枚举
|
|
476
|
-
*/
|
|
477
|
-
export enum MessageType {
|
|
478
|
-
/** 用户消息 */
|
|
479
|
-
USER = 'user',
|
|
480
|
-
/** AI 消息 */
|
|
481
|
-
AI = 'ai'
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
/**
|
|
485
|
-
* 消息接口
|
|
486
|
-
*/
|
|
487
|
-
export interface Message {
|
|
488
|
-
/** 消息 ID */
|
|
489
|
-
id: string
|
|
490
|
-
|
|
491
|
-
/** 消息类型 */
|
|
492
|
-
type: MessageType
|
|
493
|
-
|
|
494
|
-
/** 消息内容 */
|
|
495
|
-
content: string
|
|
496
|
-
|
|
497
|
-
/** 渲染后的内容(HTML) */
|
|
498
|
-
renderedContent: string
|
|
499
|
-
|
|
500
|
-
/** 消息时间 */
|
|
501
|
-
time: string
|
|
502
|
-
|
|
503
|
-
/** 是否失败 */
|
|
504
|
-
error?: boolean
|
|
505
|
-
|
|
506
|
-
/** 是否已复制 */
|
|
507
|
-
copied?: boolean
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
/**
|
|
511
|
-
* SDK 事件参数
|
|
512
|
-
*/
|
|
513
|
-
export interface SDKEvents {
|
|
514
|
-
/** 用户发送消息 */
|
|
515
|
-
'message-send': { message: string; index: number }
|
|
516
|
-
|
|
517
|
-
/** AI 回复消息 */
|
|
518
|
-
'message-receive': { response: AIResponse; index: number }
|
|
519
|
-
|
|
520
|
-
/** Loading 状态变化 */
|
|
521
|
-
'loading-change': boolean
|
|
522
|
-
|
|
523
|
-
/** 关闭对话框 */
|
|
524
|
-
close: void
|
|
525
|
-
|
|
526
|
-
/** 展开/收起 */
|
|
527
|
-
expand: boolean
|
|
528
|
-
|
|
529
|
-
/** 清除对话 */
|
|
530
|
-
clear: void
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
/**
|
|
534
|
-
* 错误码枚举
|
|
535
|
-
*/
|
|
536
|
-
export const ERROR_CODES = {
|
|
537
|
-
// 成功
|
|
538
|
-
SUCCESS: 200,
|
|
539
|
-
|
|
540
|
-
// 客户端错误 (40000-49999)
|
|
541
|
-
AGENT_NOT_FOUND: 40001, // 智能体不存在或禁用
|
|
542
|
-
PROMPT_EMPTY: 40002, // 提示词不能为空
|
|
543
|
-
AUTH_FAILED: 40301, // 鉴权失败
|
|
544
|
-
|
|
545
|
-
// 服务器错误 (50000-59999)
|
|
546
|
-
NETWORK_ERROR: 500, // 网络请求失败
|
|
547
|
-
SERVER_ERROR: 50001, // 服务器内部错误
|
|
548
|
-
TIMEOUT_ERROR: 50002, // 请求超时
|
|
549
|
-
|
|
550
|
-
// 取消
|
|
551
|
-
REQUEST_CANCELLED: 0 // 请求已取消
|
|
552
|
-
} as const
|
|
553
|
-
|
|
554
|
-
/**
|
|
555
|
-
* 导出错误码类型
|
|
556
|
-
*/
|
|
557
|
-
export type ErrorCode = typeof ERROR_CODES[keyof typeof ERROR_CODES]
|
|
558
|
-
|
|
559
|
-
/**
|
|
560
|
-
* 默认配置
|
|
561
|
-
*/
|
|
562
|
-
export const defaultConfig: AIChatConfig = {
|
|
563
|
-
apiBaseUrl: '',
|
|
564
|
-
apiEndpoint: '/v1/app/completion',
|
|
565
|
-
streamEndpoint: '/v1/app/completion/stream',
|
|
566
|
-
stopEndpoint: '/v1/app/completion/stop',
|
|
567
|
-
attachmentUploadEndpoint: '/v1/app/attachment/upload',
|
|
568
|
-
conversationQueryEndpoint: '/v1/app/conversation/query',
|
|
569
|
-
conversationDeleteEndpoint: '/v1/app/conversation/delete',
|
|
570
|
-
appListEndpoint: '/v1/app/list',
|
|
571
|
-
runtimePermissionReplyEndpoint: '/v1/app/runtime/permission/reply',
|
|
572
|
-
runtimeQuestionReplyEndpoint: '/v1/app/runtime/question/reply',
|
|
573
|
-
runtimeQuestionRejectEndpoint: '/v1/app/runtime/question/reject',
|
|
574
|
-
appId: '',
|
|
575
|
-
userId: '',
|
|
576
|
-
bizType: '',
|
|
577
|
-
token: '',
|
|
578
|
-
refreshToken: '',
|
|
579
|
-
tokenExpiresAt: 0,
|
|
580
|
-
tokenRefreshBufferMs: 60000,
|
|
581
|
-
refreshTokenFn: null,
|
|
582
|
-
onTokenRefreshed: null,
|
|
583
|
-
onTokenExpired: null,
|
|
584
|
-
authErrorCodes: [],
|
|
585
|
-
timeout: 60000,
|
|
586
|
-
headers: {},
|
|
587
|
-
extendInfo: null,
|
|
588
|
-
title: 'AI 智能助理',
|
|
589
|
-
welcomeText: '您好!我是 AI 智能助理',
|
|
590
|
-
welcomeDesc: '我可以帮您解答系统使用问题',
|
|
591
|
-
maxMessages: 50,
|
|
592
|
-
maxLength: 500,
|
|
593
|
-
historyPageSize: 20,
|
|
594
|
-
historyDays: 30,
|
|
595
|
-
enableDrag: true,
|
|
596
|
-
authFn: null,
|
|
597
|
-
onLoad: null,
|
|
598
|
-
onError: null
|
|
599
|
-
}
|