openreplay/frontend/app/components/Kai/KaiService.ts
Delirium dca5e54811
Kai UI (#3336)
* ui: kai ui thing

ui: fixes for picking existing chat, feedback and retry buttons

ui: connect finding, creating threads

ui: more ui tuning for chat window, socket manager

ui: get/delete chats logic, create testing socket

ui: testing

ui: use on click query

ui: minor fixed for chat display, rebase

ui: start kai thing

* ui: add logs, add threadid

* ui: feedback methods and ui

* ui: store, replacing messages and giving feedback

* ui: move retry btn to right corner

* ui: move kai service out for ease of code splitting

* ui: add thread id to socket connection

* ui: support state messages

* ui: cancel response generation method

* ui: fix toast str

* ui: add gfm plugin

* ui: ensure md table has max sizes to prevent overflow

* ui: revert tailwind styles on markdown block layer

* ui: export as pdf, copy text contents of a message

* ui: try to save text with formatting in secure contexts

* ui: fix types

* ui: fixup dark mode colors

* ui: add duration for msgs

* ui: take out custom jwt

* ui: removing hardcode...

* ui: change endpoints to prod

* ui: swap socket path

* ui: flip vis toggle

* ui: lock file regenerate
2025-05-13 14:00:09 +02:00

61 lines
1.8 KiB
TypeScript

import AiService from "@/services/AiService";
export default class KaiService extends AiService {
getKaiChats = async (projectId: string): Promise<{ title: string, threadId: string }[]> => {
const r = await this.client.get(`/kai/${projectId}/chats`);
if (!r.ok) {
throw new Error('Failed to fetch chats');
}
const data = await r.json();
return data;
}
deleteKaiChat = async (projectId: string, threadId: string): Promise<boolean> => {
const r = await this.client.delete(`/kai/${projectId}/chats/${threadId}`);
if (!r.ok) {
throw new Error('Failed to delete chat');
}
return true;
}
getKaiChat = async (projectId: string, threadId: string): Promise<{ role: string, content: string, message_id: any, duration?: number }[]> => {
const r = await this.client.get(`/kai/${projectId}/chats/${threadId}`);
if (!r.ok) {
throw new Error('Failed to fetch chat');
}
const data = await r.json();
return data;
}
createKaiChat = async (projectId: string): Promise<number> => {
const r = await this.client.get(`/kai/${projectId}/chat/new`)
if (!r.ok) {
throw new Error('Failed to create chat');
}
const data = await r.json();
return data;
}
feedback = async (positive: boolean | null, messageId: string, projectId: string) => {
const r = await this.client.post(`/kai/${projectId}/messages/feedback`, {
message_id: messageId,
value: positive,
user_id: userId,
});
if (!r.ok) {
throw new Error('Failed to send feedback');
}
return await r.json()
}
cancelGeneration = async (projectId: string, threadId: string) => {
const r = await this.client.post(`/kai/${projectId}/cancel/${threadId}`);
if (!r.ok) {
throw new Error('Failed to cancel generation');
}
const data = await r.json();
return data;
}
}