@kweaver-ai/chatkit 0.1.14 → 0.1.16
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.
|
@@ -18,6 +18,13 @@ export interface ChatKitBaseProps {
|
|
|
18
18
|
token?: string;
|
|
19
19
|
/** 刷新 token 的方法,由集成方传入 */
|
|
20
20
|
refreshToken?: () => Promise<string>;
|
|
21
|
+
/**
|
|
22
|
+
* 初始用户问题。
|
|
23
|
+
*
|
|
24
|
+
* - 外层在挂载 Assistant / Copilot 等组件时传入
|
|
25
|
+
* - 当组件首次可见且当前没有任何消息时,会自动发送该问题并触发问答
|
|
26
|
+
*/
|
|
27
|
+
initialQuestion?: string;
|
|
21
28
|
}
|
|
22
29
|
/**
|
|
23
30
|
* ChatKitBase 组件的状态接口
|
|
@@ -56,6 +63,20 @@ export declare abstract class ChatKitBase<P extends ChatKitBaseProps = ChatKitBa
|
|
|
56
63
|
*/
|
|
57
64
|
private isInitializing;
|
|
58
65
|
private hasInitialized;
|
|
66
|
+
/**
|
|
67
|
+
* 会话代数:用于区分「旧会话的流式更新」和「新会话」
|
|
68
|
+
* 每次清空/新建会话时自增,流式处理只在代数未变化时才继续写入 state
|
|
69
|
+
*/
|
|
70
|
+
private conversationSeq;
|
|
71
|
+
/**
|
|
72
|
+
* 当前流式请求的 AbortController
|
|
73
|
+
* 子类在发起流式 fetch 时应设置该字段,便于在 handleStop / 新建会话时主动中断连接
|
|
74
|
+
*/
|
|
75
|
+
protected currentStreamController?: AbortController;
|
|
76
|
+
/**
|
|
77
|
+
* 是否已经根据 initialQuestion 触发过一次自动发送
|
|
78
|
+
*/
|
|
79
|
+
private hasSentInitialQuestion;
|
|
59
80
|
/**
|
|
60
81
|
* 流式响应时是否处于「按 chunk 批处理」中,避免同一 chunk 内多行事件触发多次 setState 导致 Maximum update depth exceeded
|
|
61
82
|
*/
|
|
@@ -85,6 +106,16 @@ export declare abstract class ChatKitBase<P extends ChatKitBaseProps = ChatKitBa
|
|
|
85
106
|
* 仅在组件首次可见时调用,防止重复初始化
|
|
86
107
|
*/
|
|
87
108
|
private initializeConversation;
|
|
109
|
+
/**
|
|
110
|
+
* 根据 props.initialQuestion 在合适的时机自动触发一次问答
|
|
111
|
+
*
|
|
112
|
+
* 触发条件:
|
|
113
|
+
* - 组件当前处于可见状态(visible !== false)
|
|
114
|
+
* - props.initialQuestion 为非空字符串
|
|
115
|
+
* - 当前还没有任何对话消息(messages.length === 0)
|
|
116
|
+
* - 仅触发一次(hasSentInitialQuestion 为 false)
|
|
117
|
+
*/
|
|
118
|
+
private trySendInitialQuestion;
|
|
88
119
|
/**
|
|
89
120
|
* 获取开场白和预置问题 (抽象方法,由子类实现)
|
|
90
121
|
* 该方法需要由子类继承并重写,以适配扣子、Dify 等 LLMOps 平台的接口
|
|
@@ -427,6 +427,7 @@ export declare function DIPBaseMixin<TBase extends Constructor>(Base: TBase): {
|
|
|
427
427
|
/**
|
|
428
428
|
* 终止会话
|
|
429
429
|
* 调用 DIP 的 /app/{agent_key}/chat/termination 接口终止指定会话
|
|
430
|
+
* 若返回 401 会先调用 refreshToken 获取新 token 并重试一次
|
|
430
431
|
* @param conversationId 要终止的会话 ID
|
|
431
432
|
* @returns 返回 Promise,成功时 resolve,失败时 reject
|
|
432
433
|
*/
|