mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-03 05:29:12 +00:00
Ingest new format for server sent events within the HTTP streamed response
- Note that the SSR for next doesn't support rendering on the client-side, so it'll only update it one big chunk - Fix unique key error in the chatmessage history for incoming messages - Remove websocket value usage in the chat history side panel - Remove other websocket code from the chat page
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
import { Context, OnlineContextData } from "../components/chatMessage/chatMessage";
|
||||
|
||||
interface ResponseWithReferences {
|
||||
export interface RawReferenceData {
|
||||
context?: Context[];
|
||||
onlineContext?: {
|
||||
[key: string]: OnlineContextData
|
||||
}
|
||||
}
|
||||
|
||||
export interface ResponseWithReferences {
|
||||
context?: Context[];
|
||||
online?: {
|
||||
[key: string]: OnlineContextData
|
||||
@@ -108,7 +115,42 @@ export const setupWebSocket = async (conversationId: string, initialMessage?: st
|
||||
return chatWS;
|
||||
};
|
||||
|
||||
export function handleImageResponse(imageJson: any) {
|
||||
interface MessageChunk {
|
||||
type: string;
|
||||
data: string | object;
|
||||
}
|
||||
|
||||
export function convertMessageChunkToJson(chunk: string): MessageChunk {
|
||||
if (chunk.startsWith("{") && chunk.endsWith("}")) {
|
||||
try {
|
||||
const jsonChunk = JSON.parse(chunk);
|
||||
if (!jsonChunk.type) {
|
||||
return {
|
||||
type: "message",
|
||||
data: jsonChunk
|
||||
};
|
||||
}
|
||||
return jsonChunk;
|
||||
} catch (error) {
|
||||
return {
|
||||
type: "message",
|
||||
data: chunk
|
||||
};
|
||||
}
|
||||
} else if (chunk.length > 0) {
|
||||
return {
|
||||
type: "message",
|
||||
data: chunk
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
type: "message",
|
||||
data: ""
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function handleImageResponse(imageJson: any, liveStream: boolean): ResponseWithReferences {
|
||||
|
||||
let rawResponse = "";
|
||||
|
||||
@@ -123,7 +165,7 @@ export function handleImageResponse(imageJson: any) {
|
||||
} else if (imageJson.intentType === "text-to-image-v3") {
|
||||
rawResponse = ``;
|
||||
}
|
||||
if (inferredQuery) {
|
||||
if (inferredQuery && !liveStream) {
|
||||
rawResponse += `\n\n**Inferred Query**:\n\n${inferredQuery}`;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user