- Add ilike import and search/agentId conditions in chatService.listConversations - Extract search and agentId from req.query in GET /conversations route - Extend chatApi.listConversations opts with search and agentId params - Update useChatConversations to accept opts.search and include in queryKey
57 lines
1.9 KiB
TypeScript
57 lines
1.9 KiB
TypeScript
import { api } from "./client";
|
|
import type {
|
|
ChatConversation,
|
|
ChatConversationListResponse,
|
|
ChatMessage,
|
|
ChatMessageListResponse,
|
|
} from "@paperclipai/shared";
|
|
|
|
export const chatApi = {
|
|
listConversations(companyId: string, opts?: { cursor?: string; limit?: number; search?: string; agentId?: string }) {
|
|
const params = new URLSearchParams();
|
|
if (opts?.cursor) params.set("cursor", opts.cursor);
|
|
if (opts?.limit) params.set("limit", String(opts.limit));
|
|
if (opts?.search) params.set("search", opts.search);
|
|
if (opts?.agentId) params.set("agentId", opts.agentId);
|
|
const qs = params.toString();
|
|
return api.get<ChatConversationListResponse>(
|
|
`/companies/${companyId}/conversations${qs ? `?${qs}` : ""}`,
|
|
);
|
|
},
|
|
|
|
createConversation(companyId: string, data?: { title?: string; agentId?: string }) {
|
|
return api.post<ChatConversation>(`/companies/${companyId}/conversations`, data ?? {});
|
|
},
|
|
|
|
getConversation(id: string) {
|
|
return api.get<ChatConversation>(`/conversations/${id}`);
|
|
},
|
|
|
|
updateConversation(
|
|
id: string,
|
|
data: { title?: string; pinnedAt?: string | null; archivedAt?: string | null },
|
|
) {
|
|
return api.patch<ChatConversation>(`/conversations/${id}`, data);
|
|
},
|
|
|
|
deleteConversation(id: string) {
|
|
return api.delete<void>(`/conversations/${id}`);
|
|
},
|
|
|
|
listMessages(conversationId: string, opts?: { cursor?: string; limit?: number }) {
|
|
const params = new URLSearchParams();
|
|
if (opts?.cursor) params.set("cursor", opts.cursor);
|
|
if (opts?.limit) params.set("limit", String(opts.limit));
|
|
const qs = params.toString();
|
|
return api.get<ChatMessageListResponse>(
|
|
`/conversations/${conversationId}/messages${qs ? `?${qs}` : ""}`,
|
|
);
|
|
},
|
|
|
|
postMessage(
|
|
conversationId: string,
|
|
data: { role: string; content: string; agentId?: string },
|
|
) {
|
|
return api.post<ChatMessage>(`/conversations/${conversationId}/messages`, data);
|
|
},
|
|
};
|