mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-27 21:01:32 +08:00
chore: update package dependencies and improve AI SDK chunk handling
- Bumped versions of several dependencies in package.json, including `@swc/plugin-styled-components` to 8.0.4 and `@vitejs/plugin-react-swc` to 3.10.2. - Enhanced `AiSdkToChunkAdapter` to streamline chunk processing, including better handling of text and reasoning events. - Added console logging for debugging in `BlockManager` and `messageThunk` to track state changes and callback executions. - Updated integration tests to reflect changes in message structure and types.
This commit is contained in:
parent
a356492d6f
commit
f38e4a87b8
@ -116,7 +116,7 @@
|
||||
"@playwright/test": "^1.52.0",
|
||||
"@reduxjs/toolkit": "^2.2.5",
|
||||
"@shikijs/markdown-it": "^3.7.0",
|
||||
"@swc/plugin-styled-components": "^7.1.5",
|
||||
"@swc/plugin-styled-components": "^8.0.4",
|
||||
"@tanstack/react-query": "^5.27.0",
|
||||
"@tanstack/react-virtual": "^3.13.12",
|
||||
"@testing-library/dom": "^10.4.0",
|
||||
@ -139,7 +139,7 @@
|
||||
"@uiw/codemirror-extensions-langs": "^4.23.14",
|
||||
"@uiw/codemirror-themes-all": "^4.23.14",
|
||||
"@uiw/react-codemirror": "^4.23.14",
|
||||
"@vitejs/plugin-react-swc": "^3.9.0",
|
||||
"@vitejs/plugin-react-swc": "^3.10.2",
|
||||
"@vitest/browser": "^3.1.4",
|
||||
"@vitest/coverage-v8": "^3.1.4",
|
||||
"@vitest/ui": "^3.1.4",
|
||||
|
||||
@ -85,17 +85,16 @@ export class AiSdkToChunkAdapter {
|
||||
console.log('AI SDK chunk type:', chunk.type, chunk)
|
||||
switch (chunk.type) {
|
||||
// === 文本相关事件 ===
|
||||
// case 'text-start':
|
||||
// this.onChunk({
|
||||
// type: ChunkType.blo,
|
||||
// text: chunk.text || ''
|
||||
// })
|
||||
// break
|
||||
case 'text-start':
|
||||
this.onChunk({
|
||||
type: ChunkType.TEXT_START
|
||||
})
|
||||
break
|
||||
case 'text':
|
||||
final.text += chunk.text || ''
|
||||
this.onChunk({
|
||||
type: ChunkType.TEXT_DELTA,
|
||||
text: chunk.text || ''
|
||||
text: final.text || ''
|
||||
})
|
||||
break
|
||||
case 'text-end':
|
||||
@ -105,12 +104,18 @@ export class AiSdkToChunkAdapter {
|
||||
})
|
||||
final.text = ''
|
||||
break
|
||||
case 'reasoning-start':
|
||||
this.onChunk({
|
||||
type: ChunkType.THINKING_START
|
||||
})
|
||||
break
|
||||
case 'reasoning':
|
||||
this.onChunk({
|
||||
type: ChunkType.THINKING_DELTA,
|
||||
text: chunk.text || '',
|
||||
text: final.reasoningContent || '',
|
||||
thinking_millsec: (chunk.providerMetadata?.metadata?.thinking_millsec as number) || 0
|
||||
})
|
||||
final.reasoningContent += chunk.text || ''
|
||||
break
|
||||
case 'reasoning-end':
|
||||
this.onChunk({
|
||||
@ -118,6 +123,7 @@ export class AiSdkToChunkAdapter {
|
||||
text: (chunk.providerMetadata?.metadata?.thinking_content as string) || '',
|
||||
thinking_millsec: (chunk.providerMetadata?.metadata?.thinking_millsec as number) || 0
|
||||
})
|
||||
final.reasoningContent = ''
|
||||
break
|
||||
|
||||
// === 工具调用相关事件(原始 AI SDK 事件,如果没有被中间件处理) ===
|
||||
|
||||
@ -76,6 +76,7 @@ export class BlockManager {
|
||||
blockType: MessageBlockType,
|
||||
isComplete: boolean = false
|
||||
) {
|
||||
console.log('smartBlockUpdate', blockId, changes, blockType, isComplete)
|
||||
const isBlockTypeChanged = this._lastBlockType !== null && this._lastBlockType !== blockType
|
||||
if (isBlockTypeChanged || isComplete) {
|
||||
// 如果块类型改变,则取消上一个块的节流更新
|
||||
@ -102,6 +103,7 @@ export class BlockManager {
|
||||
* 处理块转换
|
||||
*/
|
||||
async handleBlockTransition(newBlock: MessageBlock, newBlockType: MessageBlockType) {
|
||||
console.log('handleBlockTransition', newBlock, newBlockType)
|
||||
this._lastBlockType = newBlockType
|
||||
this._activeBlockInfo = { id: newBlock.id, type: newBlockType } // 设置新的活跃块信息
|
||||
|
||||
|
||||
@ -434,7 +434,8 @@ describe('streamCallback Integration Tests', () => {
|
||||
type: 'object',
|
||||
title: 'Test Tool Input',
|
||||
properties: {}
|
||||
}
|
||||
},
|
||||
type: 'mcp'
|
||||
}
|
||||
|
||||
const chunks: Chunk[] = [
|
||||
@ -570,7 +571,8 @@ describe('streamCallback Integration Tests', () => {
|
||||
type: 'object',
|
||||
title: 'Calculator Input',
|
||||
properties: {}
|
||||
}
|
||||
},
|
||||
type: 'mcp'
|
||||
}
|
||||
|
||||
const chunks: Chunk[] = [
|
||||
|
||||
@ -882,6 +882,7 @@ const fetchAndProcessAssistantResponseImpl = async (
|
||||
saveUpdatesToDB,
|
||||
assistant
|
||||
})
|
||||
console.log('callbacks', callbacks)
|
||||
const streamProcessorCallbacks = createStreamProcessor(callbacks)
|
||||
|
||||
const abortController = new AbortController()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user