@kweaver-ai/chatkit 0.1.11 → 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 +83 -83
- package/dist/chatkit.es.js +16404 -15810
- package/dist/components/base/ChatKitBase.d.ts +26 -1
- package/dist/components/base/DrawerPortalContext.d.ts +16 -0
- package/dist/components/base/ToolBlockContext.d.ts +38 -0
- package/dist/components/base/assistant/AssistantBase.d.ts +9 -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/TaskInProgress.d.ts +1 -1
- package/dist/components/base/assistant/blocks/ToolBlock.d.ts +1 -0
- package/dist/components/base/assistant/blocks/ToolDrawer.d.ts +5 -0
- package/dist/components/base/copilot/CopilotBase.d.ts +14 -1
- 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/components/base/copilot/blocks/ToolDrawer.d.ts +5 -0
- package/dist/components/dip/DIPBase.d.ts +18 -0
- package/dist/types/index.d.ts +15 -1
- package/dist/utils/BlockRegistry.d.ts +2 -1
- 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,26 @@ 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;
|
|
276
|
+
/**
|
|
277
|
+
* 更新指定工具名称对应的最后一个工具块的结果(用于流式工具如 contextloader_data_enhanced 的组装)
|
|
278
|
+
* @param messageId 消息 ID
|
|
279
|
+
* @param toolName 工具名称
|
|
280
|
+
* @param result 更新后的默认工具结果
|
|
281
|
+
*/
|
|
282
|
+
protected updateDefaultToolBlockResult(messageId: string, toolName: string, result: DefaultToolResult): void;
|
|
258
283
|
/**
|
|
259
284
|
* 创建新的会话
|
|
260
285
|
* 内部会调用子类实现的 generateConversation() 和 getOnboardingInfo() 方法
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface DrawerPortalProviderProps {
|
|
3
|
+
/** Portal 挂载的 DOM 节点;不传或 null 表示使用默认(root 优先,再 body) */
|
|
4
|
+
value?: HTMLElement | null;
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
}
|
|
7
|
+
export declare function DrawerPortalProvider({ value, children }: DrawerPortalProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
/**
|
|
9
|
+
* 获取抽屉 Portal 挂载容器(来自 Context)。
|
|
10
|
+
* 返回 null 表示使用组件内部默认:document.getElementById('root') ?? document.body
|
|
11
|
+
*/
|
|
12
|
+
export declare function useDrawerPortalContainer(): HTMLElement | null;
|
|
13
|
+
/**
|
|
14
|
+
* 解析最终挂载节点:prop/context 优先,否则 root 再 body(默认不挂到 body,而是 root)
|
|
15
|
+
*/
|
|
16
|
+
export declare function resolveDrawerPortalContainer(propContainer: HTMLElement | null | undefined, contextContainer: HTMLElement | null): HTMLElement;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
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 返回的关闭函数」及「内置工具抽屉的显示状态与数据」。
|
|
15
|
+
* 点击任意工具块时先调用上次存储的关闭函数(若有),再执行当前点击逻辑;
|
|
16
|
+
* 若当前是注册工具且 onClick 返回了函数,则存储起来,供下次切换时调用。
|
|
17
|
+
* 内置抽屉的 open/close 与 payload 由 Context 持有,ToolDrawer 在 AssistantBase 单例渲染,ToolBlock 只负责调用 openToolDrawer/closeToolDrawer。
|
|
18
|
+
*/
|
|
19
|
+
export interface ToolBlockContextValue {
|
|
20
|
+
/** 执行上次注册的关闭函数并清空;切换工具块时由 ToolBlock 先调用 */
|
|
21
|
+
closeRegistered: () => void;
|
|
22
|
+
/** 存储本次打开的关闭函数(onClick 的返回值);不返回或非函数则存空 */
|
|
23
|
+
registerClose: (close: (() => void) | undefined) => void;
|
|
24
|
+
/** 是否有内置工具抽屉处于打开状态(用于控制消息列表滚动行为等) */
|
|
25
|
+
hasOpenDrawer: boolean;
|
|
26
|
+
/** 更新内置工具抽屉的打开状态(内部使用,也可供外部同步) */
|
|
27
|
+
setHasOpenDrawer: (open: boolean) => void;
|
|
28
|
+
/** 当前要展示的抽屉数据,为 null 表示抽屉关闭 */
|
|
29
|
+
drawerPayload: ToolDrawerPayload | null;
|
|
30
|
+
/** 打开内置工具抽屉并设置展示数据 */
|
|
31
|
+
openToolDrawer: (payload: ToolDrawerPayload) => void;
|
|
32
|
+
/** 关闭内置工具抽屉并清空数据 */
|
|
33
|
+
closeToolDrawer: () => void;
|
|
34
|
+
}
|
|
35
|
+
export declare function ToolBlockProvider({ children }: {
|
|
36
|
+
children: React.ReactNode;
|
|
37
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
38
|
+
export declare function useToolBlockContext(): ToolBlockContextValue;
|
|
@@ -7,6 +7,11 @@ import { ChatMessage } from '../../../types';
|
|
|
7
7
|
export interface AssistantBaseProps extends ChatKitBaseProps {
|
|
8
8
|
/** 是否启用历史对话功能,默认为 true */
|
|
9
9
|
enableHistory?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* ToolDrawer Portal 挂载的 DOM 节点(可选)。
|
|
12
|
+
* 不传时抽屉挂到主内容区域 div(flex h-full w-full bg-white)下,便于在乾坤等微前端中正确挂载
|
|
13
|
+
*/
|
|
14
|
+
drawerContainer?: HTMLElement | null;
|
|
10
15
|
}
|
|
11
16
|
/**
|
|
12
17
|
* AssistantBase 组件的状态接口
|
|
@@ -14,6 +19,8 @@ export interface AssistantBaseProps extends ChatKitBaseProps {
|
|
|
14
19
|
*/
|
|
15
20
|
export interface AssistantBaseState extends ChatKitBaseState {
|
|
16
21
|
showHistory: boolean;
|
|
22
|
+
/** 主内容区域 DOM 引用,用于未传 drawerContainer 时作为抽屉挂载点 */
|
|
23
|
+
drawerContainerEl: HTMLElement | null;
|
|
17
24
|
}
|
|
18
25
|
/**
|
|
19
26
|
* AssistantBase 基础组件
|
|
@@ -64,6 +71,8 @@ export declare abstract class AssistantBase<P extends AssistantBaseProps = Assis
|
|
|
64
71
|
* @param previousUserMessage 上一条用户消息
|
|
65
72
|
*/
|
|
66
73
|
handleRegenerate: (messageId: string, previousUserMessage: ChatMessage) => Promise<void>;
|
|
74
|
+
/** 点击相关问题:作为新问题发送 */
|
|
75
|
+
handleSelectQuestion: (question: string) => void;
|
|
67
76
|
/**
|
|
68
77
|
* 实现 React.Component.render() 方法
|
|
69
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. 获取已注册工具名称
|
|
@@ -17,6 +17,11 @@ export interface ToolDrawerProps {
|
|
|
17
17
|
input?: any;
|
|
18
18
|
/** 工具输出结果 */
|
|
19
19
|
output?: any;
|
|
20
|
+
/**
|
|
21
|
+
* Portal 挂载的 DOM 节点(可选)。
|
|
22
|
+
* 不传时优先使用 DrawerPortalContext,再默认挂到 document.getElementById('root') ?? document.body
|
|
23
|
+
*/
|
|
24
|
+
container?: HTMLElement | null;
|
|
20
25
|
}
|
|
21
26
|
/**
|
|
22
27
|
* ToolDrawer 组件
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { ChatKitBase, ChatKitBaseProps, ChatKitBaseState } from '../ChatKitBase';
|
|
2
2
|
import { ChatMessage } from '../../../types';
|
|
3
|
+
/**
|
|
4
|
+
* CopilotBase 组件的属性接口
|
|
5
|
+
* 扩展 ChatKitBaseProps,支持抽屉 Portal 挂载节点配置
|
|
6
|
+
*/
|
|
7
|
+
export interface CopilotBaseProps extends ChatKitBaseProps {
|
|
8
|
+
/**
|
|
9
|
+
* ToolDrawer Portal 挂载的 DOM 节点(可选)。
|
|
10
|
+
* 不传时抽屉挂到 document.getElementById('root') ?? document.body,避免虚拟滚动影响定位
|
|
11
|
+
*/
|
|
12
|
+
drawerContainer?: HTMLElement | null;
|
|
13
|
+
}
|
|
3
14
|
/**
|
|
4
15
|
* CopilotBase 组件的状态接口
|
|
5
16
|
* 扩展 ChatKitBaseState(当前不需要额外状态,保留接口以便未来扩展)
|
|
@@ -13,7 +24,7 @@ export interface CopilotBaseState extends ChatKitBaseState {
|
|
|
13
24
|
* 该类继承自 ChatKitBase,实现了 Copilot 模式的交互界面和交互逻辑
|
|
14
25
|
* 区别于 AssistantBase,CopilotBase 在 render() 函数中渲染 Copilot 模式的界面
|
|
15
26
|
*/
|
|
16
|
-
export declare abstract class CopilotBase<P extends
|
|
27
|
+
export declare abstract class CopilotBase<P extends CopilotBaseProps = CopilotBaseProps> extends ChatKitBase<P> {
|
|
17
28
|
/**
|
|
18
29
|
* 组件状态,包含历史对话显示状态
|
|
19
30
|
*/
|
|
@@ -42,6 +53,8 @@ export declare abstract class CopilotBase<P extends ChatKitBaseProps = ChatKitBa
|
|
|
42
53
|
* @param previousUserMessage 上一条用户消息
|
|
43
54
|
*/
|
|
44
55
|
handleRegenerate: (messageId: string, previousUserMessage: ChatMessage) => Promise<void>;
|
|
56
|
+
/** 点击相关问题:作为新问题发送 */
|
|
57
|
+
handleSelectQuestion: (question: string) => void;
|
|
45
58
|
/**
|
|
46
59
|
* 实现 React.Component.render() 方法
|
|
47
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. 获取已注册工具名称
|
|
@@ -17,6 +17,11 @@ export interface ToolDrawerProps {
|
|
|
17
17
|
input?: any;
|
|
18
18
|
/** 工具输出结果 */
|
|
19
19
|
output?: any;
|
|
20
|
+
/**
|
|
21
|
+
* Portal 挂载的 DOM 节点(可选)。
|
|
22
|
+
* 不传时优先使用 DrawerPortalContext,再默认挂到 document.getElementById('root') ?? document.body
|
|
23
|
+
*/
|
|
24
|
+
container?: HTMLElement | null;
|
|
20
25
|
}
|
|
21
26
|
/**
|
|
22
27
|
* ToolDrawer 组件
|
|
@@ -117,6 +117,12 @@ export declare function DIPBaseMixin<TBase extends Constructor>(Base: TBase): {
|
|
|
117
117
|
dipToken: string;
|
|
118
118
|
/** DIP 刷新 token 的方法 */
|
|
119
119
|
dipRefreshToken?: () => Promise<string>;
|
|
120
|
+
/** LeftHeaderTool 使用的 API 方法(构造时缓存,避免流式消息时重复创建) */
|
|
121
|
+
_leftHeaderApiMethods?: {
|
|
122
|
+
getKnowledgeNetworksDetail: (id: string) => Promise<any>;
|
|
123
|
+
getKnowledgeNetworkObjectTypes: (id: string, offset?: number, limit?: number) => Promise<any>;
|
|
124
|
+
getMetricInfoByIds: (ids: string[]) => Promise<any[]>;
|
|
125
|
+
};
|
|
120
126
|
/**
|
|
121
127
|
* 获取开场白和预置问题
|
|
122
128
|
* 调用 AISHU DIP 的 agent-factory API 获取智能体配置信息,提取开场白和预置问题
|
|
@@ -398,6 +404,18 @@ export declare function DIPBaseMixin<TBase extends Constructor>(Base: TBase): {
|
|
|
398
404
|
* 设置嵌套属性
|
|
399
405
|
*/
|
|
400
406
|
setNestedProperty(obj: any, key: Array<string | number>, value: any): void;
|
|
407
|
+
/**
|
|
408
|
+
* 按路径不可变设置:只克隆从根到 key 路径上的节点,其余引用复用,避免全量深拷贝大对象
|
|
409
|
+
*/
|
|
410
|
+
immutableSetNested(obj: any, key: Array<string | number>, value: any): any;
|
|
411
|
+
/**
|
|
412
|
+
* 不可变 upsert:按路径更新,不深拷贝整棵树
|
|
413
|
+
*/
|
|
414
|
+
immutableApplyUpsert(obj: AssistantMessage, key: Array<string | number>, content: any): AssistantMessage;
|
|
415
|
+
/**
|
|
416
|
+
* 不可变 append:按路径追加后按路径更新,不深拷贝整棵树
|
|
417
|
+
*/
|
|
418
|
+
immutableApplyAppend(obj: AssistantMessage, key: Array<string | number>, content: any): AssistantMessage;
|
|
401
419
|
/**
|
|
402
420
|
* 检查是否需要刷新 token
|
|
403
421
|
* AISHU DIP 平台返回 401 状态码时表示 token 失效
|
package/dist/types/index.d.ts
CHANGED
|
@@ -97,14 +97,26 @@ export interface ToolBlockRegistration {
|
|
|
97
97
|
Icon?: React.ReactNode;
|
|
98
98
|
/** 工具点击事件
|
|
99
99
|
* @param block 工具块数据,类型为 Record<string, any>
|
|
100
|
+
* @returns 可选返回关闭函数;切换工具块时 SDK 会先调用该函数,用于关闭本次打开的外层内容
|
|
100
101
|
*/
|
|
101
|
-
onClick?: (block: Record<string, any>) => void;
|
|
102
|
+
onClick?: (block: Record<string, any>) => void | (() => void);
|
|
102
103
|
}
|
|
103
104
|
/**
|
|
104
105
|
* JSON2Plot 图表类型的消息块
|
|
105
106
|
*/
|
|
106
107
|
export interface Json2PlotBlock extends ContentBlock<BlockType.JSON2PLOT, ChartDataSchema> {
|
|
107
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
|
+
}
|
|
108
120
|
/**
|
|
109
121
|
* 消息接口
|
|
110
122
|
* 展示在消息区消息列表中的一条消息
|
|
@@ -120,6 +132,8 @@ export interface ChatMessage {
|
|
|
120
132
|
content: Array<TextBlock | MarkdownBlock | WebSearchBlock | ToolBlock | Json2PlotBlock>;
|
|
121
133
|
/** 与该消息关联的应用上下文(可选),仅用户消息可能包含此字段 */
|
|
122
134
|
applicationContext?: ApplicationContext;
|
|
135
|
+
/** 消息扩展上下文:相关问题、耗时、Token 等,仅助手消息在流结束后可能包含 */
|
|
136
|
+
messageContext?: MessageContext;
|
|
123
137
|
}
|
|
124
138
|
/**
|
|
125
139
|
* 应用上下文接口
|
|
@@ -10,8 +10,9 @@ export interface ToolBlockRegistration {
|
|
|
10
10
|
Icon?: React.ReactNode;
|
|
11
11
|
/** 工具点击事件
|
|
12
12
|
* @param block 工具块数据,类型为 Record<string, any>
|
|
13
|
+
* @returns 可选返回一个关闭函数;切换工具块时 SDK 会先调用该函数,用于关闭本次打开的外层内容(如抽屉/弹窗)
|
|
13
14
|
*/
|
|
14
|
-
onClick?: (block: Record<string, any>) => void;
|
|
15
|
+
onClick?: (block: Record<string, any>) => void | (() => void);
|
|
15
16
|
}
|
|
16
17
|
/**
|
|
17
18
|
* Block 注册表
|