Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ 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"
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"

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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>)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Loading