@kweaver-ai/chatkit 0.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.
Files changed (47) hide show
  1. package/README.md +528 -0
  2. package/dist/chatkit.cjs.js +66 -0
  3. package/dist/chatkit.es.js +2966 -0
  4. package/dist/components/base/ChatKitBase.d.ts +261 -0
  5. package/dist/components/base/assistant/AssistantBase.d.ts +17 -0
  6. package/dist/components/base/assistant/Header.d.ts +20 -0
  7. package/dist/components/base/assistant/InputArea.d.ts +29 -0
  8. package/dist/components/base/assistant/MessageItem.d.ts +15 -0
  9. package/dist/components/base/assistant/MessageList.d.ts +15 -0
  10. package/dist/components/base/assistant/Prologue.d.ts +18 -0
  11. package/dist/components/base/assistant/blocks/MarkdownBlock.d.ts +15 -0
  12. package/dist/components/base/assistant/blocks/TextBlock.d.ts +15 -0
  13. package/dist/components/base/assistant/blocks/ToolBlock.d.ts +16 -0
  14. package/dist/components/base/assistant/blocks/ToolDrawer.d.ts +26 -0
  15. package/dist/components/base/assistant/blocks/WebSearchBlock.d.ts +16 -0
  16. package/dist/components/base/assistant/blocks/index.d.ts +9 -0
  17. package/dist/components/base/copilot/CopilotBase.d.ts +16 -0
  18. package/dist/components/base/copilot/Header.d.ts +22 -0
  19. package/dist/components/base/copilot/InputArea.d.ts +29 -0
  20. package/dist/components/base/copilot/MessageItem.d.ts +15 -0
  21. package/dist/components/base/copilot/MessageList.d.ts +15 -0
  22. package/dist/components/base/copilot/Prologue.d.ts +18 -0
  23. package/dist/components/base/copilot/blocks/MarkdownBlock.d.ts +15 -0
  24. package/dist/components/base/copilot/blocks/TextBlock.d.ts +15 -0
  25. package/dist/components/base/copilot/blocks/ToolBlock.d.ts +16 -0
  26. package/dist/components/base/copilot/blocks/ToolDrawer.d.ts +26 -0
  27. package/dist/components/base/copilot/blocks/WebSearchBlock.d.ts +16 -0
  28. package/dist/components/base/copilot/blocks/index.d.ts +9 -0
  29. package/dist/components/coze/Copilot.d.ts +102 -0
  30. package/dist/components/dip/Assistant.d.ts +22 -0
  31. package/dist/components/dip/Copilot.d.ts +22 -0
  32. package/dist/components/dip/DIPBase.d.ts +310 -0
  33. package/dist/components/icons/ClockIcon.d.ts +6 -0
  34. package/dist/components/icons/CloseIcon.d.ts +6 -0
  35. package/dist/components/icons/SendIcon.d.ts +13 -0
  36. package/dist/components/icons/StopIcon.d.ts +6 -0
  37. package/dist/components/icons/index.d.ts +7 -0
  38. package/dist/icons/assistant.svg +14 -0
  39. package/dist/icons/close.svg +6 -0
  40. package/dist/icons/expand.svg +3 -0
  41. package/dist/icons/more.svg +3 -0
  42. package/dist/icons/new.svg +10 -0
  43. package/dist/icons/send.svg +4 -0
  44. package/dist/index.d.ts +20 -0
  45. package/dist/types/index.d.ts +285 -0
  46. package/dist/utils/mixins.d.ts +18 -0
  47. package/package.json +66 -0
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ /**
3
+ * ToolDrawer 组件的属性接口
4
+ */
5
+ export interface ToolDrawerProps {
6
+ /** 抽屉是否打开 */
7
+ isOpen: boolean;
8
+ /** 关闭抽屉的回调函数 */
9
+ onClose: () => void;
10
+ /** 工具名称 */
11
+ toolName: string;
12
+ /** 工具标题 */
13
+ toolTitle: string;
14
+ /** 工具图标 */
15
+ toolIcon?: string | React.ReactNode;
16
+ /** 工具输入参数 */
17
+ input?: any;
18
+ /** 工具输出结果 */
19
+ output?: any;
20
+ }
21
+ /**
22
+ * ToolDrawer 组件
23
+ * 用于展示工具调用的详细信息(输入和输出)的抽屉组件
24
+ */
25
+ declare const ToolDrawer: React.FC<ToolDrawerProps>;
26
+ export default ToolDrawer;
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import { WebSearchBlock as WebSearchBlockType } from '../../../../types';
3
+ /**
4
+ * WebSearchBlock 组件的属性接口
5
+ */
6
+ export interface WebSearchBlockProps {
7
+ /** Web 搜索块数据 */
8
+ block: WebSearchBlockType;
9
+ }
10
+ /**
11
+ * WebSearchBlock 组件
12
+ * 用于渲染 Web 搜索类型的消息块
13
+ * 现在使用通用的 ToolBlock 组件来展示工具调用信息
14
+ */
15
+ declare const WebSearchBlock: React.FC<WebSearchBlockProps>;
16
+ export default WebSearchBlock;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Block 组件导出文件
3
+ * 导出所有类型的 Block 组件
4
+ */
5
+ export { default as TextBlock } from './TextBlock';
6
+ export { default as MarkdownBlock } from './MarkdownBlock';
7
+ export { default as WebSearchBlock } from './WebSearchBlock';
8
+ export { default as ToolBlock } from './ToolBlock';
9
+ export { default as ToolDrawer } from './ToolDrawer';
@@ -0,0 +1,102 @@
1
+ import { ChatKitBase, ChatKitBaseProps } from '../base/ChatKitBase';
2
+ import { ChatMessage, ApplicationContext, OnboardingInfo } from '../../types';
3
+ /**
4
+ * ChatKitCoze 组件的属性接口
5
+ */
6
+ export interface ChatKitCozeProps extends ChatKitBaseProps {
7
+ /** 扣子 Bot ID */
8
+ botId: string;
9
+ /** 扣子 API Token */
10
+ apiToken: string;
11
+ /** 扣子 API 基础 URL */
12
+ baseUrl?: string;
13
+ /** 用户 ID */
14
+ userId?: string;
15
+ }
16
+ /**
17
+ * ChatKitCoze 组件
18
+ * 专门适配扣子(Coze) API 的智能体对话组件
19
+ * 继承自 ChatKitBase,实现了 generateConversation、sendMessage 和 reduceAssistantMessage 方法
20
+ */
21
+ export declare class ChatKitCoze extends ChatKitBase<ChatKitCozeProps> {
22
+ /** 扣子 Bot ID */
23
+ private botId;
24
+ /** 扣子 API Token */
25
+ private apiToken;
26
+ /** 扣子 API 基础 URL */
27
+ private baseUrl;
28
+ /** 用户 ID */
29
+ private userId;
30
+ constructor(props: ChatKitCozeProps);
31
+ /**
32
+ * 获取开场白和预置问题
33
+ * 调用扣子 API 获取智能体配置信息,提取开场白和预置问题
34
+ * API 端点: GET /v1/bots/{bot_id}
35
+ * 注意:该方法是一个无状态无副作用的函数,不允许修改 state
36
+ * @returns 返回开场白信息,包含开场白文案和预置问题
37
+ */
38
+ getOnboardingInfo(): Promise<OnboardingInfo>;
39
+ /**
40
+ * 创建新的会话
41
+ * 调用扣子 API 创建新的会话,返回会话 ID
42
+ * 注意:该方法是一个无状态无副作用的函数,不允许修改 state
43
+ * @returns 返回新创建的会话 ID
44
+ */
45
+ generateConversation(): Promise<string>;
46
+ /**
47
+ * 向扣子后端发送消息 (流式响应)
48
+ * 注意:该方法是一个无状态无副作用的函数,不允许修改 state
49
+ * @param text 发送给后端的用户输入的文本
50
+ * @param ctx 随用户输入文本一起发送的应用上下文
51
+ * @param conversationID 发送的对话消息所属的会话 ID
52
+ * @returns 返回发送的消息结构
53
+ */
54
+ sendMessage(text: string, ctx: ApplicationContext, conversationID?: string): Promise<ChatMessage>;
55
+ /**
56
+ * 将 API 接口返回的 EventStream 增量解析成完整的 AssistantMessage 对象
57
+ * 对于 Coze,AssistantMessage 就是累积的文本字符串
58
+ * @param eventMessage 接收到的一条 Event Message
59
+ * @param prev 上一次增量更新后的文本 buffer
60
+ * @returns 返回更新后的文本 buffer
61
+ */
62
+ reduceAssistantMessage<T = any, K = any>(eventMessage: T, prev: K, messageId: string): K;
63
+ /**
64
+ * 检查是否需要刷新 token
65
+ * Coze 平台返回 401 状态码时表示 token 失效
66
+ * @param status HTTP 状态码
67
+ * @param error 错误响应体
68
+ * @returns 返回是否需要刷新 token
69
+ */
70
+ shouldRefreshToken(status: number, _error: any): boolean;
71
+ /**
72
+ * 终止会话
73
+ * Coze 平台目前不支持主动终止会话,此方法为空实现
74
+ * @param conversationId 要终止的会话 ID
75
+ * @returns 返回 Promise,直接 resolve
76
+ */
77
+ terminateConversation(_conversationId: string): Promise<void>;
78
+ /**
79
+ * 获取历史会话列表 (Coze 暂不支持)
80
+ * @param _page 分页页码
81
+ * @param _size 每页返回条数
82
+ * @returns 返回空数组
83
+ */
84
+ getConversations(_page?: number, _size?: number): Promise<import('../../types').ConversationHistory[]>;
85
+ /**
86
+ * 获取指定会话 ID 的对话消息列表 (Coze 暂不支持)
87
+ * @param _conversationId 会话 ID
88
+ * @returns 返回空数组
89
+ */
90
+ getConversationMessages(_conversationId: string): Promise<ChatMessage[]>;
91
+ /**
92
+ * 删除指定 ID 的会话 (Coze 暂不支持)
93
+ * @param _conversationID 会话 ID
94
+ * @returns 返回 Promise,直接 resolve
95
+ */
96
+ deleteConversation(_conversationID: string): Promise<void>;
97
+ /**
98
+ * 渲染 Copilot 模式界面
99
+ */
100
+ render(): import("react/jsx-runtime").JSX.Element | null;
101
+ }
102
+ export default ChatKitCoze;
@@ -0,0 +1,22 @@
1
+ import { DIPBaseProps } from './DIPBase';
2
+ import { ChatKitBaseProps } from '../base/ChatKitBase';
3
+ /**
4
+ * Assistant 组件的属性接口
5
+ * 合并 ChatKitBaseProps 和 DIPBaseProps
6
+ */
7
+ export interface AssistantProps extends ChatKitBaseProps, DIPBaseProps {
8
+ }
9
+ declare const Assistant_base: any;
10
+ /**
11
+ * Assistant 组件
12
+ * 主 AI 对话入口,适配 AISHU DIP 平台
13
+ *
14
+ * 使用 TypeScript mixin 模式实现多重继承:
15
+ * - 继承 AssistantBase 的交互逻辑和界面
16
+ * - 通过 DIPBaseMixin 混入 DIP 的 API 实现
17
+ *
18
+ * 注意:sendMessage 方法已在 DIPBaseMixin 中实现,无需在此覆盖
19
+ */
20
+ export declare class Assistant extends Assistant_base {
21
+ }
22
+ export default Assistant;
@@ -0,0 +1,22 @@
1
+ import { DIPBaseProps } from './DIPBase';
2
+ import { ChatKitBaseProps } from '../base/ChatKitBase';
3
+ /**
4
+ * Copilot 组件的属性接口
5
+ * 合并 ChatKitBaseProps 和 DIPBaseProps
6
+ */
7
+ export interface CopilotProps extends ChatKitBaseProps, DIPBaseProps {
8
+ }
9
+ declare const Copilot_base: any;
10
+ /**
11
+ * Copilot 组件
12
+ * 右侧跟随的 AI 助手,适配 AISHU DIP 平台
13
+ *
14
+ * 使用 TypeScript mixin 模式实现多重继承:
15
+ * - 继承 CopilotBase 的交互逻辑和界面
16
+ * - 通过 DIPBaseMixin 混入 DIP 的 API 实现
17
+ *
18
+ * 注意:sendMessage 方法已在 DIPBaseMixin 中实现,无需在此覆盖
19
+ */
20
+ export declare class Copilot extends Copilot_base {
21
+ }
22
+ export default Copilot;
@@ -0,0 +1,310 @@
1
+ import { ApplicationContext, ChatMessage, OnboardingInfo, WebSearchQuery, ConversationHistory } from '../../types';
2
+ import { Constructor } from '../../utils/mixins';
3
+ /**
4
+ * DIP 的 AssistantMessage 接口
5
+ * 对应 agent-app.schemas.yaml#/components/schemas/Message
6
+ */
7
+ interface AssistantMessage {
8
+ message?: {
9
+ id?: string;
10
+ conversation_id?: string;
11
+ role?: string;
12
+ content?: {
13
+ final_answer?: {
14
+ thinking?: string;
15
+ answer?: {
16
+ text?: string;
17
+ };
18
+ answer_type_other?: OtherTypeAnswer;
19
+ };
20
+ middle_answer?: {
21
+ progress?: Progress[];
22
+ };
23
+ };
24
+ };
25
+ error?: string;
26
+ }
27
+ /**
28
+ * OtherTypeAnswer 接口
29
+ * 智能体输出的非文本类型内容
30
+ * 对应 agent-app.schemas.yaml#/components/schemas/OtherTypeAnswer
31
+ */
32
+ interface OtherTypeAnswer {
33
+ stage?: string;
34
+ answer?: any;
35
+ skill_info?: SkillInfo;
36
+ }
37
+ /**
38
+ * SkillInfo 接口
39
+ * 调用技能的技能详情
40
+ * 对应 agent-app.schemas.yaml#/components/schemas/SkillInfo
41
+ */
42
+ interface SkillInfo {
43
+ type?: 'TOOL' | 'MCP' | 'AGENT';
44
+ name?: string;
45
+ args?: Array<{
46
+ name?: string;
47
+ type?: string;
48
+ value?: string;
49
+ }>;
50
+ }
51
+ /**
52
+ * Progress 接口
53
+ * 智能体执行过程中的一个步骤
54
+ */
55
+ interface Progress {
56
+ stage?: string;
57
+ answer?: string | any;
58
+ skill_info?: SkillInfo;
59
+ }
60
+ /**
61
+ * EventMessage 接口
62
+ * DIP 的 Event Stream Message
63
+ */
64
+ interface EventMessage {
65
+ seq_id?: number;
66
+ key?: Array<string | number>;
67
+ action?: 'append' | 'upsert' | 'end';
68
+ content?: any;
69
+ }
70
+ /**
71
+ * DIPBase 的 props 接口
72
+ */
73
+ export interface DIPBaseProps {
74
+ /** AISHU DIP 的 Agent ID,用作路径参数 */
75
+ agentId: string;
76
+ /** 访问令牌,需要包含 Bearer 前缀 (已废弃,请使用 token 属性) */
77
+ bearerToken?: string;
78
+ /** 服务端基础地址,应包含 /api/agent-app/v1 前缀 */
79
+ baseUrl?: string;
80
+ /** agent 版本,"v0"表示最新版本,默认 "v0" */
81
+ agentVersion?: string;
82
+ /** 智能体执行引擎版本,最新为"v2",默认 "v2" */
83
+ executorVersion?: string;
84
+ /** 智能体所属的业务域,用于 agent-factory API */
85
+ businessDomain?: string;
86
+ /** 调用接口时携带的令牌 */
87
+ token?: string;
88
+ /** 刷新 token 的方法 */
89
+ refreshToken?: () => Promise<string>;
90
+ }
91
+ /**
92
+ * DIPBase Mixin 函数
93
+ * 根据 TypeScript 官方文档实现的 mixin 模式
94
+ *
95
+ * 该 mixin 为基础类添加 AISHU DIP API 的集成能力,包括:
96
+ * - getOnboardingInfo(): 获取开场白信息
97
+ * - generateConversation(): 创建新会话
98
+ * - reduceAssistantMessage(): 从 EventStream 中提取出 action 和 content,并根据 action 将 content 增量更新到 AssistantMessage
99
+ * - shouldRefreshToken(): 判断 API 响应的状态码是否是 401,如果是,则表示需要刷新 Token
100
+ * - terminateConversation(): 终止会话
101
+ *
102
+ * @param Base 基础类,通常是 CopilotBase 或 AssistantBase
103
+ * @returns 混入 DIP 功能后的类
104
+ */
105
+ export declare function DIPBaseMixin<TBase extends Constructor>(Base: TBase): {
106
+ new (...args: any[]): {
107
+ /** 服务端基础地址 */
108
+ dipBaseUrl: string;
109
+ /** Agent ID */
110
+ dipId: string;
111
+ /** agent 版本 */
112
+ dipVersion: string;
113
+ /** 智能体执行引擎版本 */
114
+ dipExecutorVersion: string;
115
+ /** 业务域 */
116
+ dipBusinessDomain: string;
117
+ /** DIP 调用接口时携带的令牌 */
118
+ dipToken: string;
119
+ /** DIP 刷新 token 的方法 */
120
+ dipRefreshToken?: () => Promise<string>;
121
+ /**
122
+ * 获取开场白和预置问题
123
+ * 调用 AISHU DIP 的 agent-factory API 获取智能体配置信息,提取开场白和预置问题
124
+ * API 端点: GET /api/agent-factory/v3/agent-market/agent/{agent_id}/version/v0
125
+ * 注意:该方法是一个无状态无副作用的函数,不允许修改 state
126
+ * @returns 返回开场白信息,包含开场白文案和预置问题
127
+ */
128
+ getOnboardingInfo(): Promise<OnboardingInfo>;
129
+ /**
130
+ * 创建新的会话
131
+ * 调用 DIP API 创建新的会话,返回会话 ID
132
+ * API 端点: POST /app/{agent_id}/conversation
133
+ * 注意:该方法是一个无状态无副作用的函数,不允许修改 state
134
+ * @returns 返回新创建的会话 ID
135
+ */
136
+ generateConversation(): Promise<string>;
137
+ /**
138
+ * 调用 DIP API 发送消息(流式)
139
+ * 该方法实现了完整的消息发送逻辑,子类无需覆盖
140
+ * @param text 用户输入
141
+ * @param ctx 应用上下文
142
+ * @param conversationID 发送的对话消息所属的会话 ID
143
+ * @returns 返回助手消息
144
+ */
145
+ sendMessage(text: string, ctx: ApplicationContext, conversationID?: string): Promise<ChatMessage>;
146
+ /**
147
+ * 将 API 接口返回的 EventStream 增量解析成完整的 AssistantMessage 对象
148
+ * 根据设计文档实现白名单机制和 JSONPath 处理
149
+ * @param eventMessage 接收到的一条 Event Message
150
+ * @param prev 上一次增量更新后的 AssistantMessage 对象
151
+ * @param messageId 当前正在更新的消息 ID
152
+ * @returns 返回更新后的 AssistantMessage 对象
153
+ */
154
+ reduceAssistantMessage<T = any, K = any>(eventMessage: T, prev: K, messageId: string): K;
155
+ /**
156
+ * 解析原始事件为 EventMessage
157
+ */
158
+ parseEventMessage(raw: any): EventMessage;
159
+ /**
160
+ * 将 key 数组转换为 JSONPath 字符串
161
+ * 例如: ["message", "content", "final_answer", "answer", "text"]
162
+ * => "message.content.final_answer.answer.text"
163
+ */
164
+ keyToJSONPath(key: Array<string | number>): string;
165
+ /**
166
+ * 白名单定义
167
+ * 根据设计文档 3.2 Event Message 白名单
168
+ *
169
+ * 注意:postProcess 方法需要调用 appendMarkdownBlock 和 appendWebSearchBlock
170
+ * 这些方法需要在子类中实现
171
+ */
172
+ getWhitelistEntry(action: string, jsonPath: string): {
173
+ postProcess?: (assistantMessage: AssistantMessage, content: any, messageId: string) => void;
174
+ } | null;
175
+ /**
176
+ * 从 Progress 对象中提取 Web 搜索查询
177
+ * 根据 OpenAPI 规范,搜索数据在 answer.choices[0].message.tool_calls 中
178
+ * tool_calls[0] 是 SearchIntent(输入),tool_calls[1] 是 SearchResult(输出)
179
+ */
180
+ extractWebSearchQuery(progress: any): WebSearchQuery | null;
181
+ /**
182
+ * 处理技能调用的统一方法
183
+ * 根据设计文档 3.2 Event Message 白名单中的后处理逻辑
184
+ * @param skillInfo 技能信息
185
+ * @param answer 技能执行的 answer 字段
186
+ * @param messageId 消息 ID
187
+ */
188
+ processSkillExecution(skillInfo: SkillInfo | undefined, answer: any, messageId: string): void;
189
+ /**
190
+ * 处理 final_answer.answer_type_other
191
+ * 根据设计文档 3.2 Event Message 白名单中的后处理逻辑
192
+ * @param content OtherTypeAnswer 对象
193
+ * @param messageId 消息 ID
194
+ */
195
+ processFinalAnswerTypeOther(content: OtherTypeAnswer, messageId: string): void;
196
+ /**
197
+ * 处理 middle_answer.progress 中的一个元素
198
+ * 根据设计文档 3.2 Event Message 白名单中的后处理逻辑
199
+ * @param content Progress 对象
200
+ * @param messageId 消息 ID
201
+ */
202
+ processMiddleAnswerProgress(content: Progress, messageId: string): void;
203
+ /**
204
+ * 从 answer.choices 中提取 Web 搜索查询
205
+ * 用于处理 final_answer.answer_type_other 和 middle_answer.progress 中的搜索结果
206
+ */
207
+ extractWebSearchQueryFromAnswer(answer: any): WebSearchQuery | null;
208
+ /**
209
+ * 从 skill_info.args 中提取图表数据
210
+ * 用于处理 json2plot 工具的输出
211
+ */
212
+ extractChartDataFromArgs(args: Array<{
213
+ name?: string;
214
+ type?: string;
215
+ value?: string;
216
+ }> | undefined): any;
217
+ /**
218
+ * 从 skill_info.args 和 answer 中提取代码执行结果
219
+ * 用于处理 execute_code 工具的输入和输出
220
+ * @param args skill_info.args 数组,包含执行的代码
221
+ * @param answer 技能执行的 answer 字段,包含执行结果
222
+ * @returns ExecuteCodeResult 对象,包含 input 和 output
223
+ */
224
+ extractExecuteCodeResult(args: Array<{
225
+ name?: string;
226
+ type?: string;
227
+ value?: string;
228
+ }> | undefined, answer: any): {
229
+ input: string;
230
+ output: string;
231
+ } | null;
232
+ /**
233
+ * 将技能调用或 LLM 回答的内容追加到消息中
234
+ * 用于历史消息解析,根据 stage 和 skill_info 将内容添加到 ChatMessage.content 数组
235
+ * @param item Progress 或 OtherTypeAnswer 对象
236
+ * @param message ChatMessage 对象
237
+ */
238
+ appendSkillOrLLMContentToMessage(item: Progress | OtherTypeAnswer, message: ChatMessage): void;
239
+ /**
240
+ * 执行 upsert 操作
241
+ * 将 content 赋值到 JSONPath 指定的位置
242
+ */
243
+ applyUpsert(obj: AssistantMessage, key: Array<string | number>, content: any): AssistantMessage;
244
+ /**
245
+ * 执行 append 操作
246
+ * 如果 JSONPath 是数组下标,在该位置插入新对象
247
+ * 否则在文本后追加内容
248
+ */
249
+ applyAppend(obj: AssistantMessage, key: Array<string | number>, content: any): AssistantMessage;
250
+ /**
251
+ * 获取嵌套属性
252
+ */
253
+ getNestedProperty(obj: any, key: Array<string | number>): any;
254
+ /**
255
+ * 设置嵌套属性
256
+ */
257
+ setNestedProperty(obj: any, key: Array<string | number>, value: any): void;
258
+ /**
259
+ * 检查是否需要刷新 token
260
+ * AISHU DIP 平台返回 401 状态码时表示 token 失效
261
+ * @param status HTTP 状态码
262
+ * @param error 错误响应体
263
+ * @returns 返回是否需要刷新 token
264
+ */
265
+ shouldRefreshToken(status: number, _error: any): boolean;
266
+ /**
267
+ * 终止会话
268
+ * 调用 DIP 的 /app/{agent_id}/chat/termination 接口终止指定会话
269
+ * @param conversationId 要终止的会话 ID
270
+ * @returns 返回 Promise,成功时 resolve,失败时 reject
271
+ */
272
+ terminateConversation(conversationId: string): Promise<void>;
273
+ /**
274
+ * 执行 API 调用,并在需要时自动刷新 token 并重试一次
275
+ * @param apiCall API 调用函数
276
+ * @returns API 调用结果
277
+ */
278
+ executeDataAgentWithTokenRefresh<T>(apiCall: () => Promise<T>): Promise<T>;
279
+ /**
280
+ * 获取历史会话列表
281
+ * 调用 DIP 的 GET /app/{agent_id}/conversation 接口获取会话列表
282
+ * API 端点: GET /app/{agent_id}/conversation?page={page}&size={size}
283
+ * 注意:该方法是一个无状态无副作用的函数,不允许修改 state
284
+ * @param page 分页页码,默认为 1
285
+ * @param size 每页返回条数,默认为 10
286
+ * @returns 返回历史会话列表
287
+ */
288
+ getConversations(page?: number, size?: number): Promise<ConversationHistory[]>;
289
+ /**
290
+ * 获取指定会话 ID 的对话消息列表
291
+ * 调用 DIP 的 GET /app/{agent_id}/conversation/{conversation_id} 接口获取会话详情
292
+ * 如果对话消息是 AI 助手消息,则需要调用 reduceAssistantMessage() 解析消息
293
+ * API 端点: GET /app/{agent_id}/conversation/{conversation_id}
294
+ * 注意:该方法是一个无状态无副作用的函数,不允许修改 state
295
+ * @param conversationId 会话 ID
296
+ * @returns 返回对话消息列表
297
+ */
298
+ getConversationMessages(conversationId: string): Promise<ChatMessage[]>;
299
+ /**
300
+ * 删除指定 ID 的会话
301
+ * 调用 DIP 的 DELETE /app/{agent_id}/conversation/{conversation_id} 接口删除会话
302
+ * API 端点: DELETE /app/{agent_id}/conversation/{conversation_id}
303
+ * 注意:该方法是一个无状态无副作用的函数,不允许修改 state
304
+ * @param conversationID 会话 ID
305
+ * @returns 返回 Promise,成功时 resolve,失败时 reject
306
+ */
307
+ deleteConversation(conversationID: string): Promise<void>;
308
+ };
309
+ } & TBase;
310
+ export {};
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ /**
3
+ * 时钟图标组件(用于预设问题)
4
+ */
5
+ export declare const ClockIcon: React.FC<React.SVGProps<SVGSVGElement>>;
6
+ export default ClockIcon;
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ /**
3
+ * 关闭图标组件
4
+ */
5
+ export declare const CloseIcon: React.FC<React.SVGProps<SVGSVGElement>>;
6
+ export default CloseIcon;
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ /**
3
+ * 发送图标组件的属性接口
4
+ */
5
+ interface SendIconProps extends React.SVGProps<SVGSVGElement> {
6
+ /** 是否禁用状态 */
7
+ disabled?: boolean;
8
+ }
9
+ /**
10
+ * 发送图标组件
11
+ */
12
+ export declare const SendIcon: React.FC<SendIconProps>;
13
+ export default SendIcon;
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ /**
3
+ * 停止图标组件
4
+ */
5
+ export declare const StopIcon: React.FC<React.SVGProps<SVGSVGElement>>;
6
+ export default StopIcon;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 图标组件导出文件
3
+ */
4
+ export { CloseIcon } from './CloseIcon';
5
+ export { StopIcon } from './StopIcon';
6
+ export { SendIcon } from './SendIcon';
7
+ export { ClockIcon } from './ClockIcon';
@@ -0,0 +1,14 @@
1
+ <svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M8.81177 15.1168L9.34275 15.4944C9.34275 15.4944 6.16634 18.1559 3.65366 18.2919C1.39698 18.4145 0.0979692 16.9082 0.00315093 14.6241C-0.0878747 12.4345 1.81418 10.8621 3.00131 10.6016C5.88189 9.97109 9.76564 11.9852 11.6449 13.45C13.5242 14.9148 18.7165 18.6788 19.7595 19.1262C20.8025 19.5736 22.9283 20.6363 24.9916 20.07C27.0548 19.5037 27.9006 17.6444 27.4568 15.1942C27.0131 12.744 25.7141 9.78799 23.2848 8.7309C20.8556 7.67382 16.805 10.1164 16.236 10.5317C15.6671 10.947 12.5817 12.8554 12.5817 12.8554L11.901 12.3401C11.901 12.3401 16.0293 8.39301 19.4219 6.96973C21.7753 5.98249 23.8101 5.75408 25.6932 6.60352C27.3184 7.33593 29.3968 8.78753 30.6503 11.7983C31.9038 14.8091 32.0669 19.5018 30.84 21.2913C29.613 23.0808 27.4265 24.7099 24.1363 23.6792C20.8461 22.6485 13.8352 17.6293 12.8548 16.7893C11.8744 15.9493 9.93442 14.2315 8.82125 13.6935C8.27131 13.4236 6.31805 12.1985 4.95836 12.3099C3.3692 12.4401 2.42481 13.7332 2.30344 14.5751C2.18208 15.417 2.46653 16.4873 4.01017 16.5269C5.55382 16.5665 6.94385 15.9776 7.80291 15.6114C8.66196 15.2452 8.81177 15.1168 8.81177 15.1168Z" fill="url(#paint0_linear_30_1309)"/>
3
+ <path d="M0.385796 16.3835C0.385796 16.3835 -0.265616 15.1851 0.124474 13.4083C0.478584 11.8369 1.82875 10.5952 3.55385 10.2051C4.93053 9.89235 6.61776 10.0638 9.53018 11.9141C12.2324 13.6382 18.2087 18.475 20.1857 19.1948C22.2535 19.9484 25.0826 21.3333 27.4232 20.2254C29.9398 19.0327 31.1101 16.4739 31.0968 14.7819C31.053 13.4817 30.7572 12.2021 30.2258 11.0135C30.852 12.0061 31.282 13.1087 31.4926 14.2619C31.8221 16.0651 32.1743 18.9178 31.2332 21.1393C29.4096 25.4447 25.7643 24.578 25.3288 24.5516C24.8933 24.5252 22.1096 23.747 19.3695 21.844C16.957 20.1632 15.5046 19.0007 14.0901 17.8626C12.6755 16.7245 7.92058 12.3701 5.38879 12.0969C3.52545 11.8953 2.54833 12.1666 1.68294 12.8185C1.1584 13.2123 0.546755 13.9905 0.385796 14.7178C0.264603 15.2511 0.385796 16.3835 0.385796 16.3835Z" fill="url(#paint1_linear_30_1309)"/>
4
+ <defs>
5
+ <linearGradient id="paint0_linear_30_1309" x1="-0.253817" y1="902.024" x2="3168.01" y2="902.024" gradientUnits="userSpaceOnUse">
6
+ <stop offset="0.600962" stop-color="#3D4EFD"/>
7
+ <stop offset="1" stop-color="#031B83"/>
8
+ </linearGradient>
9
+ <linearGradient id="paint1_linear_30_1309" x1="15.92" y1="10.08" x2="15.92" y2="24.64" gradientUnits="userSpaceOnUse">
10
+ <stop stop-color="#A2F1FF"/>
11
+ <stop offset="1" stop-color="#007AFF"/>
12
+ </linearGradient>
13
+ </defs>
14
+ </svg>
@@ -0,0 +1,6 @@
1
+ <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <g opacity="0.452602">
3
+ <rect opacity="0.01" width="16" height="16" fill="black"/>
4
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M8.98924 8L13.9638 2.2411C14.0472 2.1454 13.9771 2 13.8482 2H12.336C12.2469 2 12.1616 2.03865 12.1029 2.10491L8 6.85521L3.89713 2.10491C3.84028 2.03865 3.755 2 3.66404 2H2.15176C2.02289 2 1.95277 2.1454 2.03616 2.2411L7.01076 8L2.03616 13.7589C1.95277 13.8546 2.02289 14 2.15176 14H3.66404C3.75311 14 3.83839 13.9613 3.89713 13.8951L8 9.14479L12.1029 13.8951C12.1597 13.9613 12.245 14 12.336 14H13.8482C13.9771 14 14.0472 13.8546 13.9638 13.7589L8.98924 8Z" fill="black"/>
5
+ </g>
6
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg width="14" height="13" viewBox="0 0 14 13" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M2.33333 9.52241e-09C1.71449 9.52241e-09 1.121 0.256807 0.683417 0.713927C0.245833 1.17105 9.11547e-09 1.79103 9.11547e-09 2.4375V6.5C-1.56292e-05 6.60671 0.0200905 6.71238 0.0591705 6.81097C0.0982505 6.90956 0.155539 6.99915 0.227764 7.07461C0.299989 7.15007 0.385735 7.20993 0.480107 7.25077C0.57448 7.2916 0.675629 7.31263 0.777778 7.31263C0.879927 7.31263 0.981076 7.2916 1.07545 7.25077C1.16982 7.20993 1.25557 7.15007 1.32779 7.07461C1.40002 6.99915 1.4573 6.90956 1.49638 6.81097C1.53546 6.71238 1.55557 6.60671 1.55556 6.5V2.4375C1.55556 2.22201 1.6375 2.01535 1.78336 1.86298C1.92922 1.7106 2.12705 1.625 2.33333 1.625H6.22222C6.32437 1.62502 6.42552 1.60401 6.5199 1.56319C6.61428 1.52236 6.70003 1.46252 6.77227 1.38707C6.84451 1.31162 6.90181 1.22204 6.9409 1.12346C6.98 1.02487 7.00012 0.919209 7.00012 0.8125C7.00012 0.70579 6.98 0.600126 6.9409 0.501541C6.90181 0.402956 6.84451 0.313381 6.77227 0.237932C6.70003 0.162482 6.61428 0.102637 6.5199 0.0618121C6.42552 0.0209874 6.32437 -1.6327e-05 6.22222 9.52241e-09H2.33333ZM11.6667 13C12.2855 13 12.879 12.7432 13.3166 12.2861C13.7542 11.829 14 11.209 14 10.5625V7.3125C14 7.20579 13.9799 7.10012 13.9408 7.00153C13.9017 6.90294 13.8445 6.81336 13.7722 6.7379C13.7 6.66244 13.6143 6.60258 13.5199 6.56174C13.4255 6.5209 13.3244 6.49988 13.2222 6.49988C13.1201 6.49988 13.0189 6.5209 12.9246 6.56174C12.8302 6.60258 12.7444 6.66244 12.6722 6.7379C12.6 6.81336 12.5427 6.90294 12.5036 7.00153C12.4645 7.10012 12.4444 7.20579 12.4444 7.3125V10.5625C12.4444 10.778 12.3625 10.9847 12.2166 11.137C12.0708 11.2894 11.8729 11.375 11.6667 11.375H8.16667C8.06452 11.375 7.96337 11.396 7.86899 11.4368C7.77461 11.4776 7.68885 11.5375 7.61662 11.6129C7.54438 11.6884 7.48708 11.778 7.44799 11.8765C7.40889 11.9751 7.38877 12.0808 7.38877 12.1875C7.38877 12.2942 7.40889 12.3999 7.44799 12.4985C7.48708 12.597 7.54438 12.6866 7.61662 12.7621C7.68885 12.8375 7.77461 12.8974 7.86899 12.9382C7.96337 12.979 8.06452 13 8.16667 13H11.6667Z" fill="#14101C"/>
3
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M10.8159 10.8702C11.126 10.6914 11.3173 10.3608 11.3175 10.0028C11.3179 9.44943 10.8697 9.00048 10.3163 9.00006C9.76293 8.99964 9.31399 9.4479 9.31357 10.0013C9.3133 10.3592 9.50402 10.6902 9.8139 10.8694C10.1238 11.0486 10.5057 11.0489 10.8159 10.8702ZM7.0036 10.002C7.01334 10.3665 6.82439 10.7074 6.51024 10.8923C6.19608 11.0772 5.80628 11.0769 5.49241 10.8915C5.17853 10.7061 4.99011 10.3649 5.0004 10.0005C5.01572 9.45808 5.46009 9.02641 6.00274 9.02683C6.5454 9.02724 6.98911 9.45958 7.0036 10.002ZM15.6307 10.0019C15.6405 10.3664 15.4515 10.7073 15.1373 10.8923C14.8232 11.0772 14.4333 11.0769 14.1194 10.8915C13.8056 10.7061 13.6171 10.3648 13.6275 10.0004C13.6429 9.458 14.0872 9.02641 14.6298 9.02683C15.1724 9.02724 15.6161 9.45951 15.6307 10.0019Z" fill="black"/>
3
+ </svg>
@@ -0,0 +1,10 @@
1
+ <svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <g clip-path="url(#clip0_30_1294)">
3
+ <path d="M7.4725 3.07108e-07C7.60612 -0.000144133 7.73477 0.0506664 7.83223 0.142078C7.92969 0.233489 7.98862 0.358623 7.99703 0.491979C8.00543 0.625334 7.96267 0.756877 7.87746 0.859801C7.79225 0.962725 7.671 1.02928 7.53842 1.04592L7.4725 1.05H1.05V12.95H12.95V6.25917C12.9501 6.13143 12.9968 6.00813 13.0813 5.91234C13.1658 5.81656 13.2824 5.75487 13.4091 5.73883L13.475 5.73475C13.6028 5.73473 13.7263 5.78136 13.8222 5.86588C13.9181 5.9504 13.9799 6.06701 13.9959 6.19383L14 6.25975V13.475C14 13.6028 13.9534 13.7263 13.8689 13.8222C13.7843 13.9181 13.6677 13.9799 13.5409 13.9959L13.475 14H0.525C0.397165 14 0.273716 13.9534 0.177811 13.8689C0.0819055 13.7843 0.0201337 13.6677 0.00408334 13.5409L4.83321e-09 13.475V0.525C-1.73322e-05 0.397166 0.0466079 0.273717 0.131129 0.177811C0.215651 0.0819058 0.33226 0.020134 0.459083 0.00408365L0.525 3.07108e-07H7.4725ZM13.846 0.154C13.9356 0.243747 13.9897 0.362895 13.9983 0.489425C14.0069 0.615955 13.9693 0.741314 13.8927 0.842334L13.846 0.896L5.67933 9.06267C5.58513 9.15607 5.45906 9.21034 5.32647 9.21458C5.19388 9.21882 5.0646 9.1727 4.96462 9.08551C4.86465 8.99832 4.80139 8.87651 4.78756 8.74458C4.77373 8.61264 4.81036 8.48036 4.89008 8.37433L4.93675 8.32067L13.1034 0.154C13.1522 0.105231 13.2101 0.0665448 13.2738 0.0401504C13.3375 0.013756 13.4058 0.000170749 13.4747 0.000170749C13.5437 0.000170749 13.6119 0.013756 13.6757 0.0401504C13.7394 0.0665448 13.7972 0.105231 13.846 0.154Z" fill="black" fill-opacity="0.85"/>
4
+ </g>
5
+ <defs>
6
+ <clipPath id="clip0_30_1294">
7
+ <rect width="14" height="14" fill="white"/>
8
+ </clipPath>
9
+ </defs>
10
+ </svg>
@@ -0,0 +1,4 @@
1
+ <svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <rect width="32" height="32" rx="6" fill="#126EE3"/>
3
+ <path d="M23.5693 15.016C24.1332 15.5998 24.1487 16.5405 23.585 17.1244L18.1182 22.7845C17.8716 23.0397 17.4721 23.0398 17.2256 22.7845C16.979 22.5293 16.979 22.115 17.2256 21.8597L22.2998 16.6215L8.62695 16.6215C8.28094 16.6215 8.00002 16.3313 8 15.973C8 15.6147 8.28093 15.3246 8.62695 15.3246L22.1123 15.3246L17.0225 10.0697C16.9044 9.94994 16.8363 9.7867 16.834 9.6156C16.8375 9.35614 16.99 9.12366 17.2217 9.02478C17.4535 8.92595 17.7204 8.97978 17.8994 9.1615L23.5693 15.016Z" fill="white"/>
4
+ </svg>
@@ -0,0 +1,20 @@
1
+ /**
2
+ * ChatKit - AI 对话组件
3
+ *
4
+ * @module chatkit
5
+ */
6
+ import './styles/index.css';
7
+ export { ChatKitBase } from './components/base/ChatKitBase';
8
+ export type { ChatKitBaseProps, ChatKitBaseState } from './components/base/ChatKitBase';
9
+ export { CopilotBase } from './components/base/copilot/CopilotBase';
10
+ export { AssistantBase } from './components/base/assistant/AssistantBase';
11
+ export { DIPBaseMixin } from './components/dip/DIPBase';
12
+ export type { DIPBaseProps } from './components/dip/DIPBase';
13
+ export { Copilot } from './components/dip/Copilot';
14
+ export type { CopilotProps } from './components/dip/Copilot';
15
+ export { Assistant } from './components/dip/Assistant';
16
+ export type { AssistantProps } from './components/dip/Assistant';
17
+ export { default as ChatKitCoze } from './components/coze/Copilot';
18
+ export type { ChatKitCozeProps } from './components/coze/Copilot';
19
+ export { RoleType, ChatMessageType } from './types';
20
+ export type { Role, ChatMessage, ApplicationContext, ChatKitInterface, EventStreamMessage, ConversationHistory, } from './types';