mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-05 13:52:40 +02:00
feat: moved chat persistance to Server Side
This commit is contained in:
parent
2e1b9b5582
commit
19b6e0a025
19 changed files with 4515 additions and 390 deletions
|
|
@ -114,6 +114,29 @@ export function readStreamedChatTurnId(data: unknown): string | null {
|
|||
return typeof value === "string" && value.length > 0 ? value : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the payload of `data-user-message-id` / `data-assistant-message-id`
|
||||
* SSE events emitted by `stream_new_chat` and `stream_resume_chat` after
|
||||
* `persist_user_turn` / `persist_assistant_shell` resolve a canonical
|
||||
* `new_chat_messages.id`. Mirrors {@link readStreamedChatTurnId}.
|
||||
*
|
||||
* Returns `null` when the payload is malformed (missing or non-numeric
|
||||
* `message_id`); callers should treat this as "ignore the event" so a
|
||||
* malformed BE payload never overwrites the optimistic id with a bogus
|
||||
* value.
|
||||
*/
|
||||
export function readStreamedMessageId(
|
||||
data: unknown
|
||||
): { messageId: number; turnId: string | null } | null {
|
||||
if (typeof data !== "object" || data === null) return null;
|
||||
const obj = data as { message_id?: unknown; turn_id?: unknown };
|
||||
if (typeof obj.message_id !== "number" || !Number.isFinite(obj.message_id)) {
|
||||
return null;
|
||||
}
|
||||
const turnId = typeof obj.turn_id === "string" && obj.turn_id.length > 0 ? obj.turn_id : null;
|
||||
return { messageId: obj.message_id, turnId };
|
||||
}
|
||||
|
||||
export function applyTurnIdToAssistantMessageList(
|
||||
messages: ThreadMessageLike[],
|
||||
assistantMsgId: string,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue