@kweaver-ai/chatkit 0.1.12 → 0.1.13
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/chatkit.cjs.js +69 -69
- package/dist/chatkit.es.js +9667 -9225
- package/dist/components/base/ChatKitBase.d.ts +19 -1
- package/dist/components/base/ToolBlockContext.d.ts +20 -2
- package/dist/components/base/assistant/AssistantBase.d.ts +2 -0
- package/dist/components/base/assistant/MessageItem.d.ts +4 -0
- package/dist/components/base/assistant/MessageList.d.ts +2 -0
- package/dist/components/base/assistant/MessageStatsBar.d.ts +15 -0
- package/dist/components/base/assistant/RelatedQuestions.d.ts +15 -0
- package/dist/components/base/assistant/blocks/ToolBlock.d.ts +1 -0
- package/dist/components/base/copilot/CopilotBase.d.ts +2 -0
- package/dist/components/base/copilot/MessageItem.d.ts +4 -0
- package/dist/components/base/copilot/MessageList.d.ts +2 -0
- package/dist/components/base/copilot/MessageStatsBar.d.ts +15 -0
- package/dist/components/base/copilot/RelatedQuestions.d.ts +15 -0
- package/dist/components/base/copilot/blocks/ToolBlock.d.ts +1 -0
- package/dist/types/index.d.ts +13 -0
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Component } from 'react';
|
|
2
|
-
import { ChatMessage, ApplicationContext, ChatKitInterface, OnboardingInfo, WebSearchQuery, ExecuteCodeResult, Text2SqlResult, Text2MetricResult, AfSailorResult, DatasourceFilterResult, DatasourceRerankResult, ChartDataSchema, DefaultToolResult } from '../../types';
|
|
2
|
+
import { ChatMessage, ApplicationContext, ChatKitInterface, OnboardingInfo, WebSearchQuery, ExecuteCodeResult, Text2SqlResult, Text2MetricResult, AfSailorResult, DatasourceFilterResult, DatasourceRerankResult, ChartDataSchema, DefaultToolResult, MessageContext } from '../../types';
|
|
3
3
|
/**
|
|
4
4
|
* ChatKitBase 组件的属性接口
|
|
5
5
|
*/
|
|
@@ -56,6 +56,11 @@ export declare abstract class ChatKitBase<P extends ChatKitBaseProps = ChatKitBa
|
|
|
56
56
|
*/
|
|
57
57
|
private isInitializing;
|
|
58
58
|
private hasInitialized;
|
|
59
|
+
/**
|
|
60
|
+
* 流式响应时是否处于「按 chunk 批处理」中,避免同一 chunk 内多行事件触发多次 setState 导致 Maximum update depth exceeded
|
|
61
|
+
*/
|
|
62
|
+
private _streamingBatch;
|
|
63
|
+
private _pendingStreamingUpdates;
|
|
59
64
|
/**
|
|
60
65
|
* 调用接口时携带的令牌
|
|
61
66
|
*/
|
|
@@ -255,6 +260,19 @@ export declare abstract class ChatKitBase<P extends ChatKitBaseProps = ChatKitBa
|
|
|
255
260
|
* @param consumeTime 耗时(毫秒),可选
|
|
256
261
|
*/
|
|
257
262
|
protected appendDefaultToolBlock(messageId: string, toolName: string, result: DefaultToolResult, consumeTime?: number): void;
|
|
263
|
+
/**
|
|
264
|
+
* 更新指定消息的 messageContext(合并更新)
|
|
265
|
+
* 用于在流式过程中或流结束时写入相关问题、耗时、Token 等辅助信息
|
|
266
|
+
*/
|
|
267
|
+
protected updateMessageContext(messageId: string, patch: Partial<MessageContext>): void;
|
|
268
|
+
/**
|
|
269
|
+
* 流式期间将状态更新入队,在 handleStreamResponse 每 chunk 结束时统一 flush,避免同一 chunk 内多行事件导致多次 setState 触发 Maximum update depth exceeded
|
|
270
|
+
*/
|
|
271
|
+
protected applyStreamingUpdate(updater: (prev: ChatKitBaseState) => Partial<ChatKitBaseState>): void;
|
|
272
|
+
/**
|
|
273
|
+
* 将当前批内的所有流式更新合并为一次 setState 执行
|
|
274
|
+
*/
|
|
275
|
+
protected flushStreamingUpdates(): void;
|
|
258
276
|
/**
|
|
259
277
|
* 更新指定工具名称对应的最后一个工具块的结果(用于流式工具如 contextloader_data_enhanced 的组装)
|
|
260
278
|
* @param messageId 消息 ID
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* 内置工具抽屉展示所需的数据(与 ToolDrawer 展示内容对应)
|
|
4
|
+
* 状态与数据存放在 Context,避免 ToolBlock 因虚拟滚动/消息更新重渲染导致抽屉状态重置
|
|
5
|
+
*/
|
|
6
|
+
export interface ToolDrawerPayload {
|
|
7
|
+
toolName: string;
|
|
8
|
+
toolTitle: string;
|
|
9
|
+
toolIcon?: string | React.ReactNode;
|
|
10
|
+
input?: any;
|
|
11
|
+
output?: any;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 工具块上下文:管理「注册工具 onClick 返回的关闭函数」及「内置工具抽屉的显示状态与数据」。
|
|
4
15
|
* 点击任意工具块时先调用上次存储的关闭函数(若有),再执行当前点击逻辑;
|
|
5
16
|
* 若当前是注册工具且 onClick 返回了函数,则存储起来,供下次切换时调用。
|
|
17
|
+
* 内置抽屉的 open/close 与 payload 由 Context 持有,ToolDrawer 在 AssistantBase 单例渲染,ToolBlock 只负责调用 openToolDrawer/closeToolDrawer。
|
|
6
18
|
*/
|
|
7
19
|
export interface ToolBlockContextValue {
|
|
8
20
|
/** 执行上次注册的关闭函数并清空;切换工具块时由 ToolBlock 先调用 */
|
|
@@ -11,8 +23,14 @@ export interface ToolBlockContextValue {
|
|
|
11
23
|
registerClose: (close: (() => void) | undefined) => void;
|
|
12
24
|
/** 是否有内置工具抽屉处于打开状态(用于控制消息列表滚动行为等) */
|
|
13
25
|
hasOpenDrawer: boolean;
|
|
14
|
-
/**
|
|
26
|
+
/** 更新内置工具抽屉的打开状态(内部使用,也可供外部同步) */
|
|
15
27
|
setHasOpenDrawer: (open: boolean) => void;
|
|
28
|
+
/** 当前要展示的抽屉数据,为 null 表示抽屉关闭 */
|
|
29
|
+
drawerPayload: ToolDrawerPayload | null;
|
|
30
|
+
/** 打开内置工具抽屉并设置展示数据 */
|
|
31
|
+
openToolDrawer: (payload: ToolDrawerPayload) => void;
|
|
32
|
+
/** 关闭内置工具抽屉并清空数据 */
|
|
33
|
+
closeToolDrawer: () => void;
|
|
16
34
|
}
|
|
17
35
|
export declare function ToolBlockProvider({ children }: {
|
|
18
36
|
children: React.ReactNode;
|
|
@@ -71,6 +71,8 @@ export declare abstract class AssistantBase<P extends AssistantBaseProps = Assis
|
|
|
71
71
|
* @param previousUserMessage 上一条用户消息
|
|
72
72
|
*/
|
|
73
73
|
handleRegenerate: (messageId: string, previousUserMessage: ChatMessage) => Promise<void>;
|
|
74
|
+
/** 点击相关问题:作为新问题发送 */
|
|
75
|
+
handleSelectQuestion: (question: string) => void;
|
|
74
76
|
/**
|
|
75
77
|
* 实现 React.Component.render() 方法
|
|
76
78
|
* 渲染 Assistant 模式的界面
|
|
@@ -12,6 +12,10 @@ interface MessageItemProps {
|
|
|
12
12
|
agentAvatar?: string;
|
|
13
13
|
/** 重新生成回调函数 */
|
|
14
14
|
onRegenerate?: (messageId: string) => Promise<void>;
|
|
15
|
+
/** 是否为最后一条助手消息(用于展示相关问题) */
|
|
16
|
+
isLastAssistantMessage?: boolean;
|
|
17
|
+
/** 点击相关问题时的回调(用于继续提问) */
|
|
18
|
+
onSelectQuestion?: (question: string) => void;
|
|
15
19
|
}
|
|
16
20
|
/**
|
|
17
21
|
* MessageItem 组件
|
|
@@ -12,6 +12,8 @@ interface MessageListProps {
|
|
|
12
12
|
agentAvatar?: string;
|
|
13
13
|
/** 重新生成回调函数 */
|
|
14
14
|
onRegenerate?: (messageId: string, previousUserMessage: ChatMessage) => Promise<void>;
|
|
15
|
+
/** 点击相关问题时的回调(用于继续提问) */
|
|
16
|
+
onSelectQuestion?: (question: string) => void;
|
|
15
17
|
}
|
|
16
18
|
declare const MessageList: React.FC<MessageListProps>;
|
|
17
19
|
export default MessageList;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface MessageStatsBarProps {
|
|
3
|
+
/** 本次回答耗时(秒) */
|
|
4
|
+
elapsedSeconds?: number;
|
|
5
|
+
/** 本次回答 Token 总数 */
|
|
6
|
+
totalTokens?: number;
|
|
7
|
+
/** 自定义样式类名 */
|
|
8
|
+
className?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 消息统计信息组件
|
|
12
|
+
* 在消息底部展示耗时和 Token 总数
|
|
13
|
+
*/
|
|
14
|
+
declare const MessageStatsBar: React.FC<MessageStatsBarProps>;
|
|
15
|
+
export default MessageStatsBar;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface RelatedQuestionsProps {
|
|
3
|
+
/** 相关推荐问题列表 */
|
|
4
|
+
questions: string[];
|
|
5
|
+
/** 点击某条问题时的回调(用于继续提问) */
|
|
6
|
+
onSelectQuestion?: (question: string) => void;
|
|
7
|
+
/** 自定义样式类名 */
|
|
8
|
+
className?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 相关问题列表组件
|
|
12
|
+
* 展示在最后一条助手消息下方,支持点击继续提问
|
|
13
|
+
*/
|
|
14
|
+
declare const RelatedQuestions: React.FC<RelatedQuestionsProps>;
|
|
15
|
+
export default RelatedQuestions;
|
|
@@ -11,6 +11,7 @@ export interface ToolBlockProps {
|
|
|
11
11
|
* ToolBlock 组件
|
|
12
12
|
* 用于在消息流中渲染工具调用块的通用组件
|
|
13
13
|
* 支持传入自定义图标和标题,并可点击右侧箭头查看详情
|
|
14
|
+
* 抽屉的显示状态与数据由 ToolBlockContext 持有,ToolDrawer 在 AssistantBase 单例渲染,本组件只负责调用 openToolDrawer/closeToolDrawer,避免虚拟滚动或消息更新导致抽屉状态重置。
|
|
14
15
|
*
|
|
15
16
|
* 根据设计文档(ChatKit for DIP.pdf)的 Block工具处理流程:
|
|
16
17
|
* 1. 获取已注册工具名称
|
|
@@ -53,6 +53,8 @@ export declare abstract class CopilotBase<P extends CopilotBaseProps = CopilotBa
|
|
|
53
53
|
* @param previousUserMessage 上一条用户消息
|
|
54
54
|
*/
|
|
55
55
|
handleRegenerate: (messageId: string, previousUserMessage: ChatMessage) => Promise<void>;
|
|
56
|
+
/** 点击相关问题:作为新问题发送 */
|
|
57
|
+
handleSelectQuestion: (question: string) => void;
|
|
56
58
|
/**
|
|
57
59
|
* 实现 React.Component.render() 方法
|
|
58
60
|
* 渲染 Copilot 模式的界面
|
|
@@ -10,6 +10,10 @@ interface MessageItemProps {
|
|
|
10
10
|
isStreaming?: boolean;
|
|
11
11
|
/** 重新生成回调函数 */
|
|
12
12
|
onRegenerate?: (messageId: string) => Promise<void>;
|
|
13
|
+
/** 是否为最后一条助手消息(用于展示相关问题) */
|
|
14
|
+
isLastAssistantMessage?: boolean;
|
|
15
|
+
/** 点击相关问题时的回调(用于继续提问) */
|
|
16
|
+
onSelectQuestion?: (question: string) => void;
|
|
13
17
|
}
|
|
14
18
|
/**
|
|
15
19
|
* MessageItem 组件
|
|
@@ -10,6 +10,8 @@ interface MessageListProps {
|
|
|
10
10
|
streamingMessageId?: string | null;
|
|
11
11
|
/** 重新生成回调函数 */
|
|
12
12
|
onRegenerate?: (messageId: string, previousUserMessage: ChatMessage) => Promise<void>;
|
|
13
|
+
/** 点击相关问题时的回调(用于继续提问) */
|
|
14
|
+
onSelectQuestion?: (question: string) => void;
|
|
13
15
|
}
|
|
14
16
|
declare const MessageList: React.FC<MessageListProps>;
|
|
15
17
|
export default MessageList;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface MessageStatsBarProps {
|
|
3
|
+
/** 本次回答耗时(秒) */
|
|
4
|
+
elapsedSeconds?: number;
|
|
5
|
+
/** 本次回答 Token 总数 */
|
|
6
|
+
totalTokens?: number;
|
|
7
|
+
/** 自定义样式类名 */
|
|
8
|
+
className?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Copilot 模式下的消息统计信息组件
|
|
12
|
+
* 在消息底部展示耗时和 Token 总数
|
|
13
|
+
*/
|
|
14
|
+
declare const MessageStatsBar: React.FC<MessageStatsBarProps>;
|
|
15
|
+
export default MessageStatsBar;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface RelatedQuestionsProps {
|
|
3
|
+
/** 相关推荐问题列表 */
|
|
4
|
+
questions: string[];
|
|
5
|
+
/** 点击某条问题时的回调(用于继续提问) */
|
|
6
|
+
onSelectQuestion?: (question: string) => void;
|
|
7
|
+
/** 自定义样式类名 */
|
|
8
|
+
className?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Copilot 模式下的相关问题列表组件
|
|
12
|
+
* 展示在最后一条助手消息下方,支持点击继续提问
|
|
13
|
+
*/
|
|
14
|
+
declare const RelatedQuestions: React.FC<RelatedQuestionsProps>;
|
|
15
|
+
export default RelatedQuestions;
|
|
@@ -11,6 +11,7 @@ export interface ToolBlockProps {
|
|
|
11
11
|
* ToolBlock 组件
|
|
12
12
|
* 用于在消息流中渲染工具调用块的通用组件
|
|
13
13
|
* 支持传入自定义图标和标题,并可点击右侧箭头查看详情
|
|
14
|
+
* 抽屉的显示状态与数据由 ToolBlockContext 持有,ToolDrawer 在 CopilotBase 单例渲染,本组件只负责调用 openToolDrawer/closeToolDrawer,避免虚拟滚动或消息更新导致抽屉状态重置。
|
|
14
15
|
*
|
|
15
16
|
* 根据设计文档(ChatKit for DIP.pdf)的 Block工具处理流程:
|
|
16
17
|
* 1. 获取已注册工具名称
|
package/dist/types/index.d.ts
CHANGED
|
@@ -106,6 +106,17 @@ export interface ToolBlockRegistration {
|
|
|
106
106
|
*/
|
|
107
107
|
export interface Json2PlotBlock extends ContentBlock<BlockType.JSON2PLOT, ChartDataSchema> {
|
|
108
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* 单条消息的扩展上下文(不参与流式内容渲染,用于相关问题、耗时、Token 等)
|
|
111
|
+
*/
|
|
112
|
+
export interface MessageContext {
|
|
113
|
+
/** 相关推荐问题列表,来自 message.ext.related_queries */
|
|
114
|
+
relatedQuestions?: string[];
|
|
115
|
+
/** 本次回答耗时(秒),用于展示「耗时: xx.xxs」 */
|
|
116
|
+
elapsedSeconds?: number;
|
|
117
|
+
/** Token 总数,用于展示「Token: x,xxx」 */
|
|
118
|
+
totalTokens?: number;
|
|
119
|
+
}
|
|
109
120
|
/**
|
|
110
121
|
* 消息接口
|
|
111
122
|
* 展示在消息区消息列表中的一条消息
|
|
@@ -121,6 +132,8 @@ export interface ChatMessage {
|
|
|
121
132
|
content: Array<TextBlock | MarkdownBlock | WebSearchBlock | ToolBlock | Json2PlotBlock>;
|
|
122
133
|
/** 与该消息关联的应用上下文(可选),仅用户消息可能包含此字段 */
|
|
123
134
|
applicationContext?: ApplicationContext;
|
|
135
|
+
/** 消息扩展上下文:相关问题、耗时、Token 等,仅助手消息在流结束后可能包含 */
|
|
136
|
+
messageContext?: MessageContext;
|
|
124
137
|
}
|
|
125
138
|
/**
|
|
126
139
|
* 应用上下文接口
|