[PromptLab first commit]
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
import api from "./axios";
|
||||
import type {
|
||||
Agent,
|
||||
AgentDetails,
|
||||
AgentVersion,
|
||||
CreateAgentRequest,
|
||||
CreateAgentResponse,
|
||||
EditAgentRequest,
|
||||
EditAgentResponse,
|
||||
EditAgentNameRequest,
|
||||
EditAgentNameResponse,
|
||||
ToggleAgentStatusRequest,
|
||||
ToggleAgentStatusResponse,
|
||||
ListAgentsResponse,
|
||||
} from "../types/agent";
|
||||
|
||||
const estabelecimentoId = import.meta.env.VITE_ESTABELECIMENTO_ID;
|
||||
const userEmail = import.meta.env.VITE_USER_EMAIL;
|
||||
|
||||
/**
|
||||
* Cria um novo agente
|
||||
*/
|
||||
export const createAgent = async (
|
||||
nome: string,
|
||||
model_id: number
|
||||
): Promise<CreateAgentResponse> => {
|
||||
const payload: CreateAgentRequest = {
|
||||
estabelecimento_id: Number(estabelecimentoId),
|
||||
user_email: userEmail,
|
||||
nome,
|
||||
model_id,
|
||||
};
|
||||
|
||||
const response = await api.post<CreateAgentResponse>(
|
||||
"/webhook/promptlab/agente",
|
||||
payload
|
||||
);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
/**
|
||||
* Lista todos os agentes de um estabelecimento
|
||||
*/
|
||||
export const listAgents = async (
|
||||
name?: string,
|
||||
page: number = 1,
|
||||
per_page: number = 6
|
||||
): Promise<ListAgentsResponse> => {
|
||||
const params = new URLSearchParams({
|
||||
page: page.toString(),
|
||||
per_page: per_page.toString(),
|
||||
});
|
||||
|
||||
if (name) {
|
||||
params.append("name", name);
|
||||
}
|
||||
|
||||
const response = await api.get<ListAgentsResponse>(
|
||||
`/webhook/9041673e-cc46-4e3c-9127-6b5000efcc2d/promptlab/agentes/${estabelecimentoId}?${params.toString()}`
|
||||
);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
/**
|
||||
* Obtém detalhes de um agente específico
|
||||
*/
|
||||
export const getAgentDetails = async (
|
||||
agente_id: string
|
||||
): Promise<AgentDetails> => {
|
||||
const response = await api.get<AgentDetails[]>(
|
||||
`/webhook/54eb2d09-6d59-4abe-89c9-661b12de5608/promptlab/detalhes-agente/${agente_id}`
|
||||
);
|
||||
// A API retorna um array, mas só tem um elemento
|
||||
return response.data[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* Edita um agente (cria uma nova versão)
|
||||
*/
|
||||
export const editAgent = async (
|
||||
agent_id: string,
|
||||
model_id: number,
|
||||
system_prompt: string,
|
||||
version_type: "major" | "minor" | "patch",
|
||||
notes: string
|
||||
): Promise<EditAgentResponse> => {
|
||||
const payload: EditAgentRequest = {
|
||||
user_email: userEmail,
|
||||
model_id,
|
||||
system_prompt,
|
||||
version_type,
|
||||
notes,
|
||||
};
|
||||
|
||||
const response = await api.put<EditAgentResponse>(
|
||||
`/webhook/ef647dd5-6ebd-4e8e-83a3-c867595f4f8e/promptlab/agente/${agent_id}/edit`,
|
||||
payload
|
||||
);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
/**
|
||||
* Edita apenas o nome do agente
|
||||
*/
|
||||
export const editAgentName = async (
|
||||
agent_id: string,
|
||||
nome: string
|
||||
): Promise<EditAgentNameResponse> => {
|
||||
const payload: EditAgentNameRequest = {
|
||||
nome,
|
||||
user_email: userEmail,
|
||||
};
|
||||
|
||||
const response = await api.put<EditAgentNameResponse>(
|
||||
`/webhook/6c95305b-07e7-4a6f-aa64-e60f1f19ae54/promptlab/agente/${agent_id}/nome`,
|
||||
payload
|
||||
);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
/**
|
||||
* Alterna o status do agente (ativo/inativo)
|
||||
*/
|
||||
export const toggleAgentStatus = async (
|
||||
agent_id: string,
|
||||
status: "ativo" | "inativo"
|
||||
): Promise<ToggleAgentStatusResponse> => {
|
||||
const payload: ToggleAgentStatusRequest = {
|
||||
status,
|
||||
user_email: userEmail,
|
||||
};
|
||||
|
||||
const response = await api.put<ToggleAgentStatusResponse>(
|
||||
`/webhook/6c95305b-07e7-4a6f-aa64-e60f1f19ae54/promptlab/agente/${agent_id}/status`,
|
||||
payload
|
||||
);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
/**
|
||||
* Obtém o histórico de versões de um agente
|
||||
*/
|
||||
export const getAgentVersions = async (
|
||||
agent_id: string
|
||||
): Promise<AgentVersion[]> => {
|
||||
const response = await api.get<AgentVersion[]>(
|
||||
`/webhook/c7296b1d-e1d9-4cad-bbf4-2041281f3f47/promptlab/agente/${agent_id}/versions`
|
||||
);
|
||||
return response.data;
|
||||
};
|
||||
Reference in New Issue
Block a user