fix: align ai-chat message types (#4792)

This commit is contained in:
DIYgod 2026-01-01 16:45:54 +08:00 committed by GitHub
parent 3ab9ece910
commit f39bcb97d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 6 deletions

View File

@ -3,7 +3,6 @@ import type { LexicalRichEditorRef } from "@follow/components/ui/lexical-rich-ed
import { LexicalRichEditor } from "@follow/components/ui/lexical-rich-editor/index.js"
import { ScrollArea } from "@follow/components/ui/scroll-area/ScrollArea.js"
import { cn, nextFrame } from "@follow/utils"
import type { BizUIMessage } from "@folo-services/ai-tools"
import { isEqual } from "es-toolkit"
import type { EditorState, LexicalEditor, SerializedEditorState } from "lexical"
import { $getRoot } from "lexical"
@ -11,6 +10,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react"
import { useEditingMessageId, useSetEditingMessageId } from "~/modules/ai-chat/atoms/session"
import { useChatStatus } from "~/modules/ai-chat/store/hooks"
import type { BizUIMessage } from "~/modules/ai-chat/store/types"
import { MentionPlugin, ShortcutPlugin } from "../../editor"

View File

@ -1,8 +1,8 @@
import type { BizUIMessage } from "@folo-services/ai-tools"
import { useShallow } from "zustand/shallow"
import { useAIChatStore } from "./AIChatContext"
import type { BlockSlice } from "./slices/block.slice"
import type { BizUIMessage } from "./types"
/**
* Hook to get the current room ID (chat ID) from the AI chat store

View File

@ -1,11 +1,10 @@
import type { ParseResult } from "@ai-sdk/provider-utils"
import { env } from "@follow/shared/env.desktop"
import type { BizUIMessage } from "@folo-services/ai-tools"
import type { HttpChatTransportInitOptions, UIMessageChunk } from "ai"
import { HttpChatTransport, parseJsonEventStream, uiMessageChunkSchema } from "ai"
import { getAIModelState } from "../atoms/session"
import { AIPersistService } from "../services"
import type { BizUIMessage } from "./types"
type TitleHandlerPersistOption = boolean | ((title: string) => void | Promise<void>)
@ -62,7 +61,12 @@ export function createChatTransport({ onValue, titleHandler }: CreateChatTranspo
})
}
const coerceFinishChunk = (chunk: ParseResult<UIMessageChunk>): UIMessageChunk | null => {
type UIMessageChunkParseResult =
ReturnType<typeof parseJsonEventStream<UIMessageChunk>> extends ReadableStream<infer T>
? T
: never
const coerceFinishChunk = (chunk: UIMessageChunkParseResult): UIMessageChunk | null => {
const { rawValue } = chunk
if (!rawValue || typeof rawValue !== "object" || Array.isArray(rawValue)) {
return null
@ -103,7 +107,7 @@ class ExtendChatTransport extends HttpChatTransport<BizUIMessage> {
stream,
schema: uiMessageChunkSchema,
}).pipeThrough(
new TransformStream<ParseResult<UIMessageChunk>, UIMessageChunk>({
new TransformStream<UIMessageChunkParseResult, UIMessageChunk>({
async transform(chunk, controller) {
const parsedChunk = chunk.success ? chunk.value : coerceFinishChunk(chunk)
if (!parsedChunk) {