|
6 | 6 | IChatComponent, |
7 | 7 | IChatMarkdownContent, |
8 | 8 | IChatProgress, |
| 9 | + IChatReasoning, |
9 | 10 | IChatToolContent, |
10 | 11 | IChatTreeData, |
11 | 12 | uuid, |
@@ -33,7 +34,8 @@ export type IChatProgressResponseContent = |
33 | 34 | | IChatAsyncContent |
34 | 35 | | IChatTreeData |
35 | 36 | | IChatComponent |
36 | | - | IChatToolContent; |
| 37 | + | IChatToolContent |
| 38 | + | IChatReasoning; |
37 | 39 |
|
38 | 40 | export class ChatResponseModel extends Disposable { |
39 | 41 | #responseParts: IChatProgressResponseContent[] = []; |
@@ -131,6 +133,18 @@ export class ChatResponseModel extends Disposable { |
131 | 133 | }; |
132 | 134 | } |
133 | 135 |
|
| 136 | + this.#updateResponseText(); |
| 137 | + } else if (progress.kind === 'reasoning') { |
| 138 | + const lastResponsePart = this.#responseParts[responsePartLength]; |
| 139 | + if (!lastResponsePart || lastResponsePart.kind !== 'reasoning') { |
| 140 | + // 去掉开头的 <think> 标签 |
| 141 | + this.#responseParts.push({ content: progress.content.replace(/^<think>/, ''), kind: 'reasoning' }); |
| 142 | + } else { |
| 143 | + this.#responseParts[responsePartLength] = { |
| 144 | + content: lastResponsePart.content + progress.content, |
| 145 | + kind: 'reasoning', |
| 146 | + }; |
| 147 | + } |
134 | 148 | this.#updateResponseText(); |
135 | 149 | } else if (progress.kind === 'asyncContent') { |
136 | 150 | // Add a new resolving part |
@@ -181,6 +195,9 @@ export class ChatResponseModel extends Disposable { |
181 | 195 | if (part.kind === 'toolCall') { |
182 | 196 | return part.content.function.name; |
183 | 197 | } |
| 198 | + if (part.kind === 'reasoning') { |
| 199 | + return ''; |
| 200 | + } |
184 | 201 | return part.content.value; |
185 | 202 | }) |
186 | 203 | .join('\n\n'); |
@@ -387,7 +404,7 @@ export class ChatModel extends Disposable implements IChatModel { |
387 | 404 |
|
388 | 405 | const { kind } = progress; |
389 | 406 |
|
390 | | - const basicKind = ['content', 'markdownContent', 'asyncContent', 'treeData', 'component', 'toolCall']; |
| 407 | + const basicKind = ['content', 'markdownContent', 'asyncContent', 'treeData', 'component', 'toolCall', 'reasoning']; |
391 | 408 |
|
392 | 409 | if (basicKind.includes(kind)) { |
393 | 410 | request.response.updateContent(progress, quiet); |
|
0 commit comments