nova implementacao modo chat e agente no Parecer
This commit is contained in:
@@ -56,8 +56,15 @@ export interface ParecerChatMessage {
|
||||
role: "user" | "assistant";
|
||||
content: string;
|
||||
created_at: string;
|
||||
tipo_resposta?: "chat" | "agente" | null;
|
||||
}
|
||||
|
||||
export type ParecerChatModo = "chat" | "agente";
|
||||
|
||||
export type EnviarMensagemChatResposta =
|
||||
| { message: string }
|
||||
| { conteudo_gerado: string };
|
||||
|
||||
export interface ParecerDetalhe {
|
||||
id: string;
|
||||
estabelecimento_id: number;
|
||||
@@ -77,6 +84,23 @@ export interface ParecerDetalhe {
|
||||
atualizado_por: string | null;
|
||||
}
|
||||
|
||||
export interface EditarParecerTituloAreaBody {
|
||||
titulo: string;
|
||||
area_id: string;
|
||||
}
|
||||
|
||||
export interface EditarParecerTituloAreaSuccessResponse {
|
||||
success: true;
|
||||
id: string;
|
||||
titulo: string;
|
||||
area_id: string;
|
||||
}
|
||||
|
||||
export interface EditarParecerTituloAreaErrorResponse {
|
||||
success: false;
|
||||
message?: string;
|
||||
}
|
||||
|
||||
export type ParecerStatus = "processando" | "concluido" | "erro";
|
||||
|
||||
export interface ParecerListItem {
|
||||
@@ -216,7 +240,11 @@ class ParecerService {
|
||||
return item as ParecerDetalhe;
|
||||
}
|
||||
|
||||
async enviarMensagemChat(parecerId: string, message: string): Promise<{ conteudo_gerado: string }> {
|
||||
async enviarMensagemChat(
|
||||
parecerId: string,
|
||||
messageText: string,
|
||||
modo: ParecerChatModo = "agente"
|
||||
): Promise<EnviarMensagemChatResposta> {
|
||||
const userEmail = GlobalFunctions.getTransferProperty(TransferAreaProperties.UsuarioEmail);
|
||||
if (!userEmail) {
|
||||
throw new Error("Usuário não identificado (user_email)");
|
||||
@@ -224,20 +252,33 @@ class ParecerService {
|
||||
if (!parecerId?.trim()) {
|
||||
throw new Error("ID do parecer é obrigatório");
|
||||
}
|
||||
if (!message?.trim()) {
|
||||
if (!messageText?.trim()) {
|
||||
throw new Error("Digite uma mensagem");
|
||||
}
|
||||
type ChatPostPayload = { success: boolean; conteudo_gerado?: string; message?: string };
|
||||
const response = await apiService.post<ChatPostPayload[] | ChatPostPayload>(
|
||||
PARECER_CHAT_ENVIAR_URL(parecerId),
|
||||
{ user_email: String(userEmail), message: message.trim() },
|
||||
{ user_email: String(userEmail), message: messageText.trim(), modo },
|
||||
{ timeout: 0, headers: { "Content-Type": "application/json" } }
|
||||
);
|
||||
const raw = response.data;
|
||||
const payload = Array.isArray(raw) ? raw[0] : raw;
|
||||
if (!payload?.success || typeof payload.conteudo_gerado !== "string") {
|
||||
|
||||
if (!payload?.success) {
|
||||
throw new Error(payload?.message ?? "Erro ao processar a mensagem do chat");
|
||||
}
|
||||
|
||||
if (modo === "chat") {
|
||||
if (typeof payload.message !== "string") {
|
||||
throw new Error(payload?.message ?? "Erro ao processar resposta do chat");
|
||||
}
|
||||
return { message: payload.message };
|
||||
}
|
||||
|
||||
// modo === "agente"
|
||||
if (typeof payload.conteudo_gerado !== "string") {
|
||||
throw new Error(payload?.message ?? "Erro ao processar atualização do parecer");
|
||||
}
|
||||
return { conteudo_gerado: payload.conteudo_gerado };
|
||||
}
|
||||
|
||||
@@ -272,6 +313,47 @@ class ParecerService {
|
||||
return item;
|
||||
}
|
||||
|
||||
async editarTituloArea(
|
||||
parecerId: string,
|
||||
body: EditarParecerTituloAreaBody
|
||||
): Promise<EditarParecerTituloAreaSuccessResponse> {
|
||||
if (!parecerId?.trim()) {
|
||||
throw new Error("ID do parecer é obrigatório");
|
||||
}
|
||||
if (!body?.titulo?.trim()) {
|
||||
throw new Error("Título é obrigatório");
|
||||
}
|
||||
if (!body?.area_id?.trim()) {
|
||||
throw new Error("Área é obrigatória");
|
||||
}
|
||||
|
||||
const url = `https://prod-hgtx-intelligence-n8n.hgtx.com.br/webhook/fd073ec0-81ab-4681-8acd-b0da71f6ad30/codex/parecer/${encodeURIComponent(
|
||||
parecerId
|
||||
)}/editar`;
|
||||
|
||||
const response = await apiService.put<
|
||||
| EditarParecerTituloAreaSuccessResponse
|
||||
| EditarParecerTituloAreaErrorResponse
|
||||
| (EditarParecerTituloAreaSuccessResponse | EditarParecerTituloAreaErrorResponse)[]
|
||||
>(url, {
|
||||
titulo: body.titulo.trim(),
|
||||
area_id: body.area_id.trim(),
|
||||
});
|
||||
|
||||
const raw = response.data;
|
||||
const data = Array.isArray(raw) ? raw[0] : raw;
|
||||
|
||||
if (!data || typeof data !== "object" || !("success" in data)) {
|
||||
throw new Error("Resposta inválida ao editar o parecer");
|
||||
}
|
||||
|
||||
if (data.success === false) {
|
||||
throw new Error((data as EditarParecerTituloAreaErrorResponse).message ?? "Erro ao editar parecer");
|
||||
}
|
||||
|
||||
return data as EditarParecerTituloAreaSuccessResponse;
|
||||
}
|
||||
|
||||
async excluir(id: string): Promise<{ message: string }> {
|
||||
if (!id?.trim()) {
|
||||
throw new Error("ID do parecer é obrigatório");
|
||||
|
||||
Reference in New Issue
Block a user