diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/EditableMessage.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/EditableMessage.tsx index 67f1d891a..aa05cc766 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/EditableMessage.tsx +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/EditableMessage.tsx @@ -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" diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/store/hooks.ts b/apps/desktop/layer/renderer/src/modules/ai-chat/store/hooks.ts index ca3c13ab8..0302bb98b 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/store/hooks.ts +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/store/hooks.ts @@ -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 diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/store/transport.ts b/apps/desktop/layer/renderer/src/modules/ai-chat/store/transport.ts index e877cc8a1..2b5ac981f 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/store/transport.ts +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/store/transport.ts @@ -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) @@ -62,7 +61,12 @@ export function createChatTransport({ onValue, titleHandler }: CreateChatTranspo }) } -const coerceFinishChunk = (chunk: ParseResult): UIMessageChunk | null => { +type UIMessageChunkParseResult = + ReturnType> extends ReadableStream + ? 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 { stream, schema: uiMessageChunkSchema, }).pipeThrough( - new TransformStream, UIMessageChunk>({ + new TransformStream({ async transform(chunk, controller) { const parsedChunk = chunk.success ? chunk.value : coerceFinishChunk(chunk) if (!parsedChunk) {