knight-ui 1.1.1 → 1.1.2
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/README.md +15 -0
- package/component/ai/AIChatDialogue.d.ts +47 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2212,9 +2212,24 @@ const messages = [
|
|
|
2212
2212
|
| `userAvatar / assistantAvatar` | `string` | — | 头像 |
|
|
2213
2213
|
| `userNickname / assistantNickname` | `string` | — | 昵称 |
|
|
2214
2214
|
| `maxHeight` | `number` | — | 最大高度 |
|
|
2215
|
+
| `showThinking` | `boolean` | `true` | 是否显示"思考过程"块 |
|
|
2216
|
+
| `thinkingTitle` | `React.ReactNode` | `"思考过程"` | 思考块标题 |
|
|
2217
|
+
| `thinkingDefaultCollapsed` | `boolean` | `false` | 思考块默认是否收起 |
|
|
2218
|
+
| `thinkingBodyMaxHeight` | `number` | `320` | 思考正文最大高度(px),超出内部滚动 |
|
|
2215
2219
|
| `onCopy` | `(msg) => void` | — | 复制回调 |
|
|
2216
2220
|
| `onRetry` | `(msg, index) => void` | — | 重试回调 |
|
|
2217
2221
|
|
|
2222
|
+
> **AIMessage 思考内容支持(assistant 专用)**:`thinkingContent?: React.ReactNode` 思考/推理内容(Markdown 字符串或节点),展示为消息上方可折叠的灰色思考块;`thinkingTokens?: number` 真实 token 数(缺省按 ~3.5 字符/token 估算);`thinkingDurationMs?: number` 思考耗时(ms),完整消息可传,流式思考期间由组件自动计时无需传入。
|
|
2223
|
+
> 流式阶段约定:仅思考时消息为 `{ role:"assistant", thinkingContent: 增量, status:"streaming" }`(正文留空、与 content 互斥增长);结束后替换为带 `content`(与可选 `thinkingDurationMs`)的完整消息。
|
|
2224
|
+
>
|
|
2225
|
+
> ```tsx
|
|
2226
|
+
> <AIChatDialogue
|
|
2227
|
+
> dataSource={[{ id: "2", role: "assistant", content: "回答正文",
|
|
2228
|
+
> thinkingContent: "先分析…", thinkingTokens: 86, thinkingDurationMs: 12400 }]}
|
|
2229
|
+
> thinkingTitle="思考过程"
|
|
2230
|
+
> />
|
|
2231
|
+
> ```
|
|
2232
|
+
|
|
2218
2233
|
### Sidebar AI 侧栏
|
|
2219
2234
|
|
|
2220
2235
|
```tsx
|
|
@@ -5,6 +5,13 @@ export interface AIMessage {
|
|
|
5
5
|
id?: string | number;
|
|
6
6
|
role: AIRole;
|
|
7
7
|
content: React.ReactNode;
|
|
8
|
+
/** 思考/推理内容(assistant 专用),展示为消息上方可折叠的思考块。
|
|
9
|
+
* 流式时模型先出 thinking 后出 content,二者分阶段增长 */
|
|
10
|
+
thinkingContent?: React.ReactNode;
|
|
11
|
+
/** 该条思考的真实 token 数;缺省时按字符数估算(与 agent 侧 /3.5 口径一致) */
|
|
12
|
+
thinkingTokens?: number;
|
|
13
|
+
/** 思考耗时(ms,完整消息);流式思考期间由组件内部计时,无需传入 */
|
|
14
|
+
thinkingDurationMs?: number;
|
|
8
15
|
avatar?: string;
|
|
9
16
|
name?: string;
|
|
10
17
|
time?: string;
|
|
@@ -13,9 +20,21 @@ export interface AIMessage {
|
|
|
13
20
|
/**
|
|
14
21
|
* AI 对话展示。
|
|
15
22
|
*/
|
|
16
|
-
export declare class AIChatDialogue extends AbstractUI<AIChatDialogueProps,
|
|
23
|
+
export declare class AIChatDialogue extends AbstractUI<AIChatDialogueProps, AIChatDialogueState> {
|
|
17
24
|
private listRef;
|
|
18
25
|
private listEl;
|
|
26
|
+
/** 思考块折叠映射:key=消息 id(缺省退化为索引),value=是否展开;缺 key 走默认规则 */
|
|
27
|
+
private foldThinking;
|
|
28
|
+
/** 思考正文元素缓存(供流式时内部滚到底) */
|
|
29
|
+
private thinkingBodyEls;
|
|
30
|
+
/** 各消息"开始流式思考"的锚点时刻(performance.now),用于实时计时 */
|
|
31
|
+
private thinkAnchor;
|
|
32
|
+
/** 思考结束补记的耗时(ms),key=消息 id(当 dataSource 最终消息未带 thinkingDurationMs 时兜底) */
|
|
33
|
+
private thinkFinalMs;
|
|
34
|
+
/** 实时计时的最新时刻:有任一消息在流式思考时由定时器驱动刷新 */
|
|
35
|
+
private thinkNow;
|
|
36
|
+
/** 刷新定时器 id(仅流式思考期间存在) */
|
|
37
|
+
private thinkTimer;
|
|
19
38
|
constructor(props: AIChatDialogueProps);
|
|
20
39
|
componentDidMount(): void;
|
|
21
40
|
componentWillUnmount(): void;
|
|
@@ -23,6 +42,23 @@ export declare class AIChatDialogue extends AbstractUI<AIChatDialogueProps, UISt
|
|
|
23
42
|
private onListWheel;
|
|
24
43
|
private setListRef;
|
|
25
44
|
private scrollToBottom;
|
|
45
|
+
private getMsgKey;
|
|
46
|
+
private isEmptyNode;
|
|
47
|
+
/** 思考显示开关:showThinking !== false 时显示思考块 */
|
|
48
|
+
private thinkingEnabled;
|
|
49
|
+
/** 是否正处于"只吐思考、还没出正文"的流式阶段 */
|
|
50
|
+
private isStreamingThinking;
|
|
51
|
+
/** 展开判定:用户显式折叠/展开优先;否则流式思考强制展开,静态态按 defaultCollapsed */
|
|
52
|
+
private isThinkingExpanded;
|
|
53
|
+
private thinkingTokensOf;
|
|
54
|
+
private setThinkingBodyRef;
|
|
55
|
+
private toggleThinking;
|
|
56
|
+
private autoScrollThinkingBody;
|
|
57
|
+
/** 思考时长文案:流式=锚点实时差;静态=thinkingDurationMs,其次组件内思考结束的补记值 */
|
|
58
|
+
private thinkingTimeText;
|
|
59
|
+
/** 维护"流式思考"计时:登记锚点、结束后补记耗时、起停刷新定时器 */
|
|
60
|
+
private syncThinkingClock;
|
|
61
|
+
private renderThinkingBlock;
|
|
26
62
|
private renderAvatar;
|
|
27
63
|
private renderActionBtn;
|
|
28
64
|
protected OnRenderContent(): React.ReactElement;
|
|
@@ -37,8 +73,18 @@ export interface AIChatDialogueProps extends UIProps {
|
|
|
37
73
|
showAvatar?: boolean;
|
|
38
74
|
showNickname?: boolean;
|
|
39
75
|
maxHeight?: number;
|
|
76
|
+
/** 是否显示"思考过程"块 @default true */
|
|
77
|
+
showThinking?: boolean;
|
|
78
|
+
/** 思考块标题 @default "思考过程" */
|
|
79
|
+
thinkingTitle?: React.ReactNode;
|
|
80
|
+
/** 思考块默认是否收起(折叠时仅显示头部) @default false */
|
|
81
|
+
thinkingDefaultCollapsed?: boolean;
|
|
82
|
+
/** 思考正文最大高度(px),超出后内部滚动 @default 320 */
|
|
83
|
+
thinkingBodyMaxHeight?: number;
|
|
40
84
|
emptyContent?: React.ReactNode;
|
|
41
85
|
onCopy?: (msg: AIMessage) => void;
|
|
42
86
|
onRetry?: (msg: AIMessage, index: number) => void;
|
|
43
87
|
}
|
|
88
|
+
interface AIChatDialogueState extends UIState {
|
|
89
|
+
}
|
|
44
90
|
export {};
|