mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-09 23:10:20 +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",
|
"@playwright/test": "^1.52.0",
|
||||||
"@reduxjs/toolkit": "^2.2.5",
|
"@reduxjs/toolkit": "^2.2.5",
|
||||||
"@shikijs/markdown-it": "^3.7.0",
|
"@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-query": "^5.27.0",
|
||||||
"@tanstack/react-virtual": "^3.13.12",
|
"@tanstack/react-virtual": "^3.13.12",
|
||||||
"@testing-library/dom": "^10.4.0",
|
"@testing-library/dom": "^10.4.0",
|
||||||
@ -139,7 +139,7 @@
|
|||||||
"@uiw/codemirror-extensions-langs": "^4.23.14",
|
"@uiw/codemirror-extensions-langs": "^4.23.14",
|
||||||
"@uiw/codemirror-themes-all": "^4.23.14",
|
"@uiw/codemirror-themes-all": "^4.23.14",
|
||||||
"@uiw/react-codemirror": "^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/browser": "^3.1.4",
|
||||||
"@vitest/coverage-v8": "^3.1.4",
|
"@vitest/coverage-v8": "^3.1.4",
|
||||||
"@vitest/ui": "^3.1.4",
|
"@vitest/ui": "^3.1.4",
|
||||||
|
|||||||
@ -85,17 +85,16 @@ export class AiSdkToChunkAdapter {
|
|||||||
console.log('AI SDK chunk type:', chunk.type, chunk)
|
console.log('AI SDK chunk type:', chunk.type, chunk)
|
||||||
switch (chunk.type) {
|
switch (chunk.type) {
|
||||||
// === 文本相关事件 ===
|
// === 文本相关事件 ===
|
||||||
// case 'text-start':
|
case 'text-start':
|
||||||
// this.onChunk({
|
this.onChunk({
|
||||||
// type: ChunkType.blo,
|
type: ChunkType.TEXT_START
|
||||||
// text: chunk.text || ''
|
})
|
||||||
// })
|
break
|
||||||
// break
|
|
||||||
case 'text':
|
case 'text':
|
||||||
final.text += chunk.text || ''
|
final.text += chunk.text || ''
|
||||||
this.onChunk({
|
this.onChunk({
|
||||||
type: ChunkType.TEXT_DELTA,
|
type: ChunkType.TEXT_DELTA,
|
||||||
text: chunk.text || ''
|
text: final.text || ''
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
case 'text-end':
|
case 'text-end':
|
||||||
@ -105,12 +104,18 @@ export class AiSdkToChunkAdapter {
|
|||||||
})
|
})
|
||||||
final.text = ''
|
final.text = ''
|
||||||
break
|
break
|
||||||
|
case 'reasoning-start':
|
||||||
|
this.onChunk({
|
||||||
|
type: ChunkType.THINKING_START
|
||||||
|
})
|
||||||
|
break
|
||||||
case 'reasoning':
|
case 'reasoning':
|
||||||
this.onChunk({
|
this.onChunk({
|
||||||
type: ChunkType.THINKING_DELTA,
|
type: ChunkType.THINKING_DELTA,
|
||||||
text: chunk.text || '',
|
text: final.reasoningContent || '',
|
||||||
thinking_millsec: (chunk.providerMetadata?.metadata?.thinking_millsec as number) || 0
|
thinking_millsec: (chunk.providerMetadata?.metadata?.thinking_millsec as number) || 0
|
||||||
})
|
})
|
||||||
|
final.reasoningContent += chunk.text || ''
|
||||||
break
|
break
|
||||||
case 'reasoning-end':
|
case 'reasoning-end':
|
||||||
this.onChunk({
|
this.onChunk({
|
||||||
@ -118,6 +123,7 @@ export class AiSdkToChunkAdapter {
|
|||||||
text: (chunk.providerMetadata?.metadata?.thinking_content as string) || '',
|
text: (chunk.providerMetadata?.metadata?.thinking_content as string) || '',
|
||||||
thinking_millsec: (chunk.providerMetadata?.metadata?.thinking_millsec as number) || 0
|
thinking_millsec: (chunk.providerMetadata?.metadata?.thinking_millsec as number) || 0
|
||||||
})
|
})
|
||||||
|
final.reasoningContent = ''
|
||||||
break
|
break
|
||||||
|
|
||||||
// === 工具调用相关事件(原始 AI SDK 事件,如果没有被中间件处理) ===
|
// === 工具调用相关事件(原始 AI SDK 事件,如果没有被中间件处理) ===
|
||||||
|
|||||||
@ -76,6 +76,7 @@ export class BlockManager {
|
|||||||
blockType: MessageBlockType,
|
blockType: MessageBlockType,
|
||||||
isComplete: boolean = false
|
isComplete: boolean = false
|
||||||
) {
|
) {
|
||||||
|
console.log('smartBlockUpdate', blockId, changes, blockType, isComplete)
|
||||||
const isBlockTypeChanged = this._lastBlockType !== null && this._lastBlockType !== blockType
|
const isBlockTypeChanged = this._lastBlockType !== null && this._lastBlockType !== blockType
|
||||||
if (isBlockTypeChanged || isComplete) {
|
if (isBlockTypeChanged || isComplete) {
|
||||||
// 如果块类型改变,则取消上一个块的节流更新
|
// 如果块类型改变,则取消上一个块的节流更新
|
||||||
@ -102,6 +103,7 @@ export class BlockManager {
|
|||||||
* 处理块转换
|
* 处理块转换
|
||||||
*/
|
*/
|
||||||
async handleBlockTransition(newBlock: MessageBlock, newBlockType: MessageBlockType) {
|
async handleBlockTransition(newBlock: MessageBlock, newBlockType: MessageBlockType) {
|
||||||
|
console.log('handleBlockTransition', newBlock, newBlockType)
|
||||||
this._lastBlockType = newBlockType
|
this._lastBlockType = newBlockType
|
||||||
this._activeBlockInfo = { id: newBlock.id, type: newBlockType } // 设置新的活跃块信息
|
this._activeBlockInfo = { id: newBlock.id, type: newBlockType } // 设置新的活跃块信息
|
||||||
|
|
||||||
|
|||||||
@ -434,7 +434,8 @@ describe('streamCallback Integration Tests', () => {
|
|||||||
type: 'object',
|
type: 'object',
|
||||||
title: 'Test Tool Input',
|
title: 'Test Tool Input',
|
||||||
properties: {}
|
properties: {}
|
||||||
}
|
},
|
||||||
|
type: 'mcp'
|
||||||
}
|
}
|
||||||
|
|
||||||
const chunks: Chunk[] = [
|
const chunks: Chunk[] = [
|
||||||
@ -570,7 +571,8 @@ describe('streamCallback Integration Tests', () => {
|
|||||||
type: 'object',
|
type: 'object',
|
||||||
title: 'Calculator Input',
|
title: 'Calculator Input',
|
||||||
properties: {}
|
properties: {}
|
||||||
}
|
},
|
||||||
|
type: 'mcp'
|
||||||
}
|
}
|
||||||
|
|
||||||
const chunks: Chunk[] = [
|
const chunks: Chunk[] = [
|
||||||
|
|||||||
@ -882,6 +882,7 @@ const fetchAndProcessAssistantResponseImpl = async (
|
|||||||
saveUpdatesToDB,
|
saveUpdatesToDB,
|
||||||
assistant
|
assistant
|
||||||
})
|
})
|
||||||
|
console.log('callbacks', callbacks)
|
||||||
const streamProcessorCallbacks = createStreamProcessor(callbacks)
|
const streamProcessorCallbacks = createStreamProcessor(callbacks)
|
||||||
|
|
||||||
const abortController = new AbortController()
|
const abortController = new AbortController()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user