mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-23 02:36:12 +01:00
* agents - phase 1 (#30) * chore: copy assistant files * feat: frontend and data-provider * feat: backend get endpoint test * fix(MessageEndpointIcon): switched to AgentName and AgentAvatar * fix: small fixes * fix: agent endpoint config * fix: show Agent Builder * chore: install agentus * chore: initial scaffolding for agents * fix: updated Assistant logic to Agent Logic for some Agent components * WIP first pass, demo of agent package * WIP: initial backend infra for agents * fix: agent list error * wip: agents routing * chore: Refactor useSSE hook to handle different data events * wip: correctly emit events * chore: Update @librechat/agentus npm dependency to version 1.0.9 * remove comment * first pass: streaming agent text * chore: Remove @librechat/agentus root-level workspace npm dependency * feat: Agent Schema and Model * fix: content handling fixes * fix: content message save * WIP: new content data * fix: run step issue with tool calls * chore: Update @librechat/agentus npm dependency to version 1.1.5 * feat: update controller and agent routes * wip: initial backend tool and tool error handling support * wip: tool chunks * chore: Update @librechat/agentus npm dependency to version 1.1.7 * chore: update tool_call typing, add test conditions and logs * fix: create agent * fix: create agent * first pass: render completed content parts * fix: remove logging, fix step handler typing * chore: Update @librechat/agentus npm dependency to version 1.1.9 * refactor: cleanup maps on unmount * chore: Update BaseClient.js to safely count tokens for string, number, and boolean values * fix: support subsequent messages with tool_calls * chore: export order * fix: select agent * fix: tool call types and handling * chore: switch to anthropic for testing * fix: AgentSelect * refactor: experimental: OpenAIClient to use array for intermediateReply * fix(useSSE): revert old condition for streaming legacy client tokens * fix: lint * revert `agent_id` to `id` * chore: update localization keys for agent-related components * feat: zod schema handling for actions * refactor(actions): if no params, no zodSchema * chore: Update @librechat/agentus npm dependency to version 1.2.1 * feat: first pass, actions * refactor: empty schema for actions without params * feat: Update createRun function to accept additional options * fix: message payload formatting; feat: add more client options * fix: ToolCall component rendering when action has no args but has output * refactor(ToolCall): allow non-stringy args * WIP: first pass, correctly formatted tool_calls between providers * refactor: Remove duplicate import of 'roles' module * refactor: Exclude 'vite.config.ts' from TypeScript compilation * refactor: fix agent related types > - no need to use endpoint/model fields for identifying agent metadata > - add `provider` distinction for agent-configured 'endpoint' - no need for agent-endpoint map - reduce complexity of tools as functions into tools as string[] - fix types related to above changes - reduce unnecessary variables for queries/mutations and corresponding react-query keys * refactor: Add tools and tool_kwargs fields to agent schema * refactor: Remove unused code and update dependencies * refactor: Update updateAgentHandler to use req.body directly * refactor: Update AgentSelect component to use localized hooks * refactor: Update agent schema to include tools and provider fields * refactor(AgentPanel): add scrollbar gutter, add provider field to form, fix agent schema required values * refactor: Update AgentSwitcher component to use selectedAgentId instead of selectedAgent * refactor: Update AgentPanel component to include alternateName import and defaultAgentFormValues * refactor(SelectDropDown): allow setting value as option while still supporting legacy usage (string values only) * refactor: SelectDropdown changes - Only necessary when the available values are objects with label/value fields and the selected value is expected to be a string. * refactor: TypeError issues and handle provider as option * feat: Add placeholder for provider selection in AgentPanel component * refactor: Update agent schema to include author and provider fields * fix: show expected 'create agent' placeholder when creating agent * chore: fix localization strings, hide capabilities form for now * chore: typing * refactor: import order and use compact agents schema for now * chore: typing * refactor: Update AgentForm type to use AgentCapabilities * fix agent form agent selection issues * feat: responsive agent selection * fix: Handle cancelled fetch in useSelectAgent hook * fix: reset agent form on accordion close/open * feat: Add agent_id to default conversation for agents endpoint * feat: agents endpoint request handling * refactor: reset conversation model on agent select * refactor: add `additional_instructions` to conversation schema, organize other fields * chore: casing * chore: types * refactor(loadAgentTools): explicitly pass agent_id, do not pass `model` to loadAgentTools for now, load action sets by agent_id * WIP: initial draft of real agent client initialization * WIP: first pass, anthropic agent requests * feat: remember last selected agent * feat: openai and azure connected * fix: prioritize agent model for runs unless an explicit override model is passed from client * feat: Agent Actions * fix: save agent id to convo * feat: model panel (#29) * feat: model panel * bring back comments * fix: method still null * fix: AgentPanel FormContext * feat: add more parameters * fix: style issues; refactor: Agent Controller * fix: cherry-pick * fix: Update AgentAvatar component to use AssistantIcon instead of BrainCircuit * feat: OGDialog for delete agent; feat(assistant): update Agent types, introduced `model_parameters` * feat: icon and general `model_parameters` update * feat: use react-hook-form better * fix: agent builder form reset issue when switching panels * refactor: modularize agent builder form --------- Co-authored-by: Danny Avila <danny@librechat.ai> * fix: AgentPanel and ModelPanel type issues and use `useFormContext` and `watch` instead of `methods` directly and `useWatch`. * fix: tool call issues due to invalid input (anthropic) of empty string * fix: handle empty text in Part component --------- Co-authored-by: Marco Beretta <81851188+berry-13@users.noreply.github.com> * refactor: remove form ModelPanel and fixed nested ternary expressions in AgentConfig * fix: Model Parameters not saved correctly * refactor: remove console log * feat: avatar upload and get for Agents (#36) Co-authored-by: Marco Beretta <81851188+berry-13@users.noreply.github.com> * chore: update to public package * fix: typing, optional chaining * fix: cursor not showing for content parts * chore: conditionally enable agents * ci: fix azure test * ci: fix frontend tests, fix eslint api * refactor: Remove unused errorContentPart variable * continue of the agent message PR (#40) * last fixes * fix: agentMap * pr merge test (#41) * fix: model icon not fetching correctly * remove console logs * feat: agent name * refactor: pass documentsMap as a prop to allow re-render of assistant form * refactor: pass documentsMap as a prop to allow re-render of assistant form * chore: Bump version to 0.7.419 * fix: TypeError: Cannot read properties of undefined (reading 'id') * refactor: update AgentSwitcher component to use ControlCombobox instead of Combobox --------- Co-authored-by: Marco Beretta <81851188+berry-13@users.noreply.github.com>
684 lines
19 KiB
TypeScript
684 lines
19 KiB
TypeScript
import type { AxiosResponse } from 'axios';
|
|
import type * as t from './types';
|
|
import * as endpoints from './api-endpoints';
|
|
import * as a from './types/assistants';
|
|
import * as m from './types/mutations';
|
|
import * as q from './types/queries';
|
|
import * as f from './types/files';
|
|
import * as config from './config';
|
|
import request from './request';
|
|
import * as s from './schemas';
|
|
import * as r from './roles';
|
|
|
|
export function abortRequestWithMessage(
|
|
endpoint: string,
|
|
abortKey: string,
|
|
message: string,
|
|
): Promise<void> {
|
|
return request.post(endpoints.abortRequest(endpoint), { arg: { abortKey, message } });
|
|
}
|
|
|
|
export function revokeUserKey(name: string): Promise<unknown> {
|
|
return request.delete(endpoints.revokeUserKey(name));
|
|
}
|
|
|
|
export function revokeAllUserKeys(): Promise<unknown> {
|
|
return request.delete(endpoints.revokeAllUserKeys());
|
|
}
|
|
|
|
export function deleteUser(): Promise<s.TPreset> {
|
|
return request.delete(endpoints.deleteUser());
|
|
}
|
|
|
|
export function getMessagesByConvoId(conversationId: string): Promise<s.TMessage[]> {
|
|
if (conversationId === 'new') {
|
|
return Promise.resolve([]);
|
|
}
|
|
return request.get(endpoints.messages(conversationId));
|
|
}
|
|
|
|
export function getSharedMessages(shareId: string): Promise<t.TSharedMessagesResponse> {
|
|
return request.get(endpoints.shareMessages(shareId));
|
|
}
|
|
|
|
export const listSharedLinks = (
|
|
params?: q.SharedLinkListParams,
|
|
): Promise<q.SharedLinksResponse> => {
|
|
const pageNumber = params?.pageNumber || '1'; // Default to page 1 if not provided
|
|
const isPublic = params?.isPublic || true; // Default to true if not provided
|
|
return request.get(endpoints.getSharedLinks(pageNumber, isPublic));
|
|
};
|
|
|
|
export function getSharedLink(shareId: string): Promise<t.TSharedLinkResponse> {
|
|
return request.get(endpoints.shareMessages(shareId));
|
|
}
|
|
|
|
export function createSharedLink(payload: t.TSharedLinkRequest): Promise<t.TSharedLinkResponse> {
|
|
return request.post(endpoints.createSharedLink, payload);
|
|
}
|
|
|
|
export function updateSharedLink(payload: t.TSharedLinkRequest): Promise<t.TSharedLinkResponse> {
|
|
return request.patch(endpoints.updateSharedLink, payload);
|
|
}
|
|
|
|
export function deleteSharedLink(shareId: string): Promise<t.TDeleteSharedLinkResponse> {
|
|
return request.delete(endpoints.shareMessages(shareId));
|
|
}
|
|
|
|
export function updateMessage(payload: t.TUpdateMessageRequest): Promise<unknown> {
|
|
const { conversationId, messageId, text } = payload;
|
|
if (!conversationId) {
|
|
throw new Error('conversationId is required');
|
|
}
|
|
|
|
return request.put(endpoints.messages(conversationId, messageId), { text });
|
|
}
|
|
|
|
export function updateUserKey(payload: t.TUpdateUserKeyRequest) {
|
|
const { value } = payload;
|
|
if (!value) {
|
|
throw new Error('value is required');
|
|
}
|
|
|
|
return request.put(endpoints.keys(), payload);
|
|
}
|
|
|
|
export function getPresets(): Promise<s.TPreset[]> {
|
|
return request.get(endpoints.presets());
|
|
}
|
|
|
|
export function createPreset(payload: s.TPreset): Promise<s.TPreset> {
|
|
return request.post(endpoints.presets(), payload);
|
|
}
|
|
|
|
export function updatePreset(payload: s.TPreset): Promise<s.TPreset> {
|
|
return request.post(endpoints.presets(), payload);
|
|
}
|
|
|
|
export function deletePreset(arg: s.TPreset | undefined): Promise<m.PresetDeleteResponse> {
|
|
return request.post(endpoints.deletePreset(), arg);
|
|
}
|
|
|
|
export function getSearchEnabled(): Promise<boolean> {
|
|
return request.get(endpoints.searchEnabled());
|
|
}
|
|
|
|
export function getUser(): Promise<t.TUser> {
|
|
return request.get(endpoints.user());
|
|
}
|
|
|
|
export function getUserBalance(): Promise<string> {
|
|
return request.get(endpoints.balance());
|
|
}
|
|
|
|
export const updateTokenCount = (text: string) => {
|
|
return request.post(endpoints.tokenizer(), { arg: text });
|
|
};
|
|
|
|
export const login = (payload: t.TLoginUser) => {
|
|
return request.post(endpoints.login(), payload);
|
|
};
|
|
|
|
export const logout = () => {
|
|
return request.post(endpoints.logout());
|
|
};
|
|
|
|
export const register = (payload: t.TRegisterUser) => {
|
|
return request.post(endpoints.register(), payload);
|
|
};
|
|
|
|
export const userKeyQuery = (name: string): Promise<t.TCheckUserKeyResponse> =>
|
|
request.get(endpoints.userKeyQuery(name));
|
|
|
|
export const getLoginGoogle = () => {
|
|
return request.get(endpoints.loginGoogle());
|
|
};
|
|
|
|
export const requestPasswordReset = (
|
|
payload: t.TRequestPasswordReset,
|
|
): Promise<t.TRequestPasswordResetResponse> => {
|
|
return request.post(endpoints.requestPasswordReset(), payload);
|
|
};
|
|
|
|
export const resetPassword = (payload: t.TResetPassword) => {
|
|
return request.post(endpoints.resetPassword(), payload);
|
|
};
|
|
|
|
export const verifyEmail = (payload: t.TVerifyEmail): Promise<t.VerifyEmailResponse> => {
|
|
return request.post(endpoints.verifyEmail(), payload);
|
|
};
|
|
|
|
export const resendVerificationEmail = (
|
|
payload: t.TResendVerificationEmail,
|
|
): Promise<t.VerifyEmailResponse> => {
|
|
return request.post(endpoints.resendVerificationEmail(), payload);
|
|
};
|
|
|
|
export const getAvailablePlugins = (): Promise<s.TPlugin[]> => {
|
|
return request.get(endpoints.plugins());
|
|
};
|
|
|
|
export const updateUserPlugins = (payload: t.TUpdateUserPlugins) => {
|
|
return request.post(endpoints.userPlugins(), payload);
|
|
};
|
|
|
|
/* Config */
|
|
|
|
export const getStartupConfig = (): Promise<t.TStartupConfig> => {
|
|
return request.get(endpoints.config());
|
|
};
|
|
|
|
export const getAIEndpoints = (): Promise<t.TEndpointsConfig> => {
|
|
return request.get(endpoints.aiEndpoints());
|
|
};
|
|
|
|
export const getModels = async (): Promise<t.TModelsConfig> => {
|
|
return request.get(endpoints.models());
|
|
};
|
|
|
|
export const getEndpointsConfigOverride = (): Promise<unknown | boolean> => {
|
|
return request.get(endpoints.endpointsConfigOverride());
|
|
};
|
|
|
|
/* Assistants */
|
|
|
|
export const createAssistant = ({
|
|
version,
|
|
...data
|
|
}: a.AssistantCreateParams): Promise<a.Assistant> => {
|
|
return request.post(endpoints.assistants({ version }), data);
|
|
};
|
|
|
|
export const getAssistantById = ({
|
|
endpoint,
|
|
assistant_id,
|
|
version,
|
|
}: {
|
|
endpoint: s.AssistantsEndpoint;
|
|
assistant_id: string;
|
|
version: number | string | number;
|
|
}): Promise<a.Assistant> => {
|
|
return request.get(
|
|
endpoints.assistants({
|
|
path: assistant_id,
|
|
endpoint,
|
|
version,
|
|
}),
|
|
);
|
|
};
|
|
|
|
export const updateAssistant = ({
|
|
assistant_id,
|
|
data,
|
|
version,
|
|
}: {
|
|
assistant_id: string;
|
|
data: a.AssistantUpdateParams;
|
|
version: number | string;
|
|
}): Promise<a.Assistant> => {
|
|
return request.patch(
|
|
endpoints.assistants({
|
|
path: assistant_id,
|
|
version,
|
|
}),
|
|
data,
|
|
);
|
|
};
|
|
|
|
export const deleteAssistant = ({
|
|
assistant_id,
|
|
model,
|
|
endpoint,
|
|
version,
|
|
}: m.DeleteAssistantBody & { version: number | string }): Promise<void> => {
|
|
return request.delete(
|
|
endpoints.assistants({
|
|
path: assistant_id,
|
|
options: { model, endpoint },
|
|
version,
|
|
}),
|
|
);
|
|
};
|
|
|
|
export const listAssistants = (
|
|
params: a.AssistantListParams,
|
|
version: number | string,
|
|
): Promise<a.AssistantListResponse> => {
|
|
return request.get(
|
|
endpoints.assistants({
|
|
version,
|
|
options: params,
|
|
}),
|
|
);
|
|
};
|
|
|
|
export function getAssistantDocs({
|
|
endpoint,
|
|
version,
|
|
}: {
|
|
endpoint: s.AssistantsEndpoint | string;
|
|
version: number | string;
|
|
}): Promise<a.AssistantDocument[]> {
|
|
if (!s.isAssistantsEndpoint(endpoint)) {
|
|
return Promise.resolve([]);
|
|
}
|
|
return request.get(
|
|
endpoints.assistants({
|
|
path: 'documents',
|
|
version,
|
|
options: { endpoint },
|
|
endpoint: endpoint as s.AssistantsEndpoint,
|
|
}),
|
|
);
|
|
}
|
|
|
|
/* Tools */
|
|
|
|
export const getAvailableTools = (
|
|
_endpoint: s.AssistantsEndpoint | s.EModelEndpoint.agents,
|
|
version?: number | string,
|
|
): Promise<s.TPlugin[]> => {
|
|
let path = '';
|
|
if (s.isAssistantsEndpoint(_endpoint)) {
|
|
const endpoint = _endpoint as s.AssistantsEndpoint;
|
|
path = endpoints.assistants({
|
|
path: 'tools',
|
|
endpoint: endpoint,
|
|
version: version ?? config.defaultAssistantsVersion[endpoint],
|
|
});
|
|
} else {
|
|
path = endpoints.agents({
|
|
path: 'tools',
|
|
});
|
|
}
|
|
|
|
return request.get(path);
|
|
};
|
|
|
|
/* Files */
|
|
|
|
export const getFiles = (): Promise<f.TFile[]> => {
|
|
return request.get(endpoints.files());
|
|
};
|
|
|
|
export const getFileConfig = (): Promise<f.FileConfig> => {
|
|
return request.get(`${endpoints.files()}/config`);
|
|
};
|
|
|
|
export const uploadImage = (data: FormData): Promise<f.TFileUpload> => {
|
|
return request.postMultiPart(endpoints.images(), data);
|
|
};
|
|
|
|
export const uploadFile = (data: FormData): Promise<f.TFileUpload> => {
|
|
return request.postMultiPart(endpoints.files(), data);
|
|
};
|
|
|
|
/* actions */
|
|
|
|
export const updateAction = (data: m.UpdateActionVariables): Promise<m.UpdateActionResponse> => {
|
|
const { assistant_id, version, ...body } = data;
|
|
return request.post(
|
|
endpoints.assistants({
|
|
path: `actions/${assistant_id}`,
|
|
version,
|
|
}),
|
|
body,
|
|
);
|
|
};
|
|
|
|
export function getActions(): Promise<a.Action[]> {
|
|
return request.get(
|
|
endpoints.agents({
|
|
path: 'actions',
|
|
}),
|
|
);
|
|
}
|
|
|
|
export const deleteAction = async ({
|
|
assistant_id,
|
|
action_id,
|
|
model,
|
|
version,
|
|
endpoint,
|
|
}: m.DeleteActionVariables & { version: number | string }): Promise<void> =>
|
|
request.delete(
|
|
endpoints.assistants({
|
|
path: `actions/${assistant_id}/${action_id}/${model}`,
|
|
version,
|
|
endpoint,
|
|
}),
|
|
);
|
|
|
|
/**
|
|
* Agents
|
|
*/
|
|
|
|
export const createAgent = ({ ...data }: a.AgentCreateParams): Promise<a.Agent> => {
|
|
return request.post(endpoints.agents({}), data);
|
|
};
|
|
|
|
export const getAgentById = ({ agent_id }: { agent_id: string }): Promise<a.Agent> => {
|
|
return request.get(
|
|
endpoints.agents({
|
|
path: agent_id,
|
|
}),
|
|
);
|
|
};
|
|
|
|
export const updateAgent = ({
|
|
agent_id,
|
|
data,
|
|
}: {
|
|
agent_id: string;
|
|
data: a.AgentUpdateParams;
|
|
}): Promise<a.Agent> => {
|
|
return request.patch(
|
|
endpoints.agents({
|
|
path: agent_id,
|
|
}),
|
|
data,
|
|
);
|
|
};
|
|
|
|
export const deleteAgent = ({ agent_id }: m.DeleteAgentBody): Promise<void> => {
|
|
return request.delete(
|
|
endpoints.agents({
|
|
path: agent_id,
|
|
}),
|
|
);
|
|
};
|
|
|
|
export const listAgents = (params: a.AgentListParams): Promise<a.AgentListResponse> => {
|
|
return request.get(
|
|
endpoints.agents({
|
|
options: params,
|
|
}),
|
|
);
|
|
};
|
|
|
|
/* Tools */
|
|
|
|
export const getAvailableAgentTools = (): Promise<s.TPlugin[]> => {
|
|
return request.get(
|
|
endpoints.agents({
|
|
path: 'tools',
|
|
}),
|
|
);
|
|
};
|
|
|
|
/* Actions */
|
|
|
|
export const updateAgentAction = (
|
|
data: m.UpdateAgentActionVariables,
|
|
): Promise<m.UpdateAgentActionResponse> => {
|
|
const { agent_id, ...body } = data;
|
|
return request.post(
|
|
endpoints.agents({
|
|
path: `actions/${agent_id}`,
|
|
}),
|
|
body,
|
|
);
|
|
};
|
|
|
|
export const deleteAgentAction = async ({
|
|
agent_id,
|
|
action_id,
|
|
}: m.DeleteAgentActionVariables): Promise<void> =>
|
|
request.delete(
|
|
endpoints.agents({
|
|
path: `actions/${agent_id}/${action_id}`,
|
|
}),
|
|
);
|
|
|
|
/**
|
|
* Imports a conversations file.
|
|
*
|
|
* @param data - The FormData containing the file to import.
|
|
* @returns A Promise that resolves to the import start response.
|
|
*/
|
|
export const importConversationsFile = (data: FormData): Promise<t.TImportResponse> => {
|
|
return request.postMultiPart(endpoints.importConversation(), data);
|
|
};
|
|
|
|
export const uploadAvatar = (data: FormData): Promise<f.AvatarUploadResponse> => {
|
|
return request.postMultiPart(endpoints.avatar(), data);
|
|
};
|
|
|
|
export const uploadAssistantAvatar = (data: m.AssistantAvatarVariables): Promise<a.Assistant> => {
|
|
return request.postMultiPart(
|
|
endpoints.assistants({
|
|
path: `avatar/${data.assistant_id}`,
|
|
options: { model: data.model, endpoint: data.endpoint },
|
|
version: data.version,
|
|
}),
|
|
data.formData,
|
|
);
|
|
};
|
|
|
|
export const uploadAgentAvatar = (data: m.AgentAvatarVariables): Promise<a.Agent> => {
|
|
return request.postMultiPart(
|
|
endpoints.agents({
|
|
path: `avatar/${data.agent_id}`,
|
|
}),
|
|
data.formData,
|
|
);
|
|
};
|
|
|
|
export const getFileDownload = async (userId: string, file_id: string): Promise<AxiosResponse> => {
|
|
return request.getResponse(`${endpoints.files()}/download/${userId}/${file_id}`, {
|
|
responseType: 'blob',
|
|
headers: {
|
|
Accept: 'application/octet-stream',
|
|
},
|
|
});
|
|
};
|
|
|
|
export const deleteFiles = async (
|
|
files: f.BatchFile[],
|
|
assistant_id?: string,
|
|
tool_resource?: a.EToolResources,
|
|
): Promise<f.DeleteFilesResponse> =>
|
|
request.deleteWithOptions(endpoints.files(), {
|
|
data: { files, assistant_id, tool_resource },
|
|
});
|
|
|
|
/* Speech */
|
|
|
|
export const speechToText = (data: FormData): Promise<f.SpeechToTextResponse> => {
|
|
return request.postMultiPart(endpoints.speechToText(), data);
|
|
};
|
|
|
|
export const textToSpeech = (data: FormData): Promise<ArrayBuffer> => {
|
|
return request.postTTS(endpoints.textToSpeechManual(), data);
|
|
};
|
|
|
|
export const getVoices = (): Promise<f.VoiceResponse> => {
|
|
return request.get(endpoints.textToSpeechVoices());
|
|
};
|
|
|
|
export const getCustomConfigSpeech = (): Promise<t.TCustomConfigSpeechResponse> => {
|
|
return request.get(endpoints.getCustomConfigSpeech());
|
|
};
|
|
|
|
/* conversations */
|
|
|
|
export function forkConversation(payload: t.TForkConvoRequest): Promise<t.TForkConvoResponse> {
|
|
return request.post(endpoints.forkConversation(), payload);
|
|
}
|
|
|
|
export function deleteConversation(payload: t.TDeleteConversationRequest) {
|
|
//todo: this should be a DELETE request
|
|
return request.post(endpoints.deleteConversation(), { arg: payload });
|
|
}
|
|
|
|
export function clearAllConversations(): Promise<unknown> {
|
|
return request.post(endpoints.deleteConversation(), { arg: {} });
|
|
}
|
|
|
|
export const listConversations = (
|
|
params?: q.ConversationListParams,
|
|
): Promise<q.ConversationListResponse> => {
|
|
// Assuming params has a pageNumber property
|
|
const pageNumber = params?.pageNumber || '1'; // Default to page 1 if not provided
|
|
const isArchived = params?.isArchived || false; // Default to false if not provided
|
|
const tags = params?.tags || []; // Default to an empty array if not provided
|
|
return request.get(endpoints.conversations(pageNumber, isArchived, tags));
|
|
};
|
|
|
|
export const listConversationsByQuery = (
|
|
params?: q.ConversationListParams & { searchQuery?: string },
|
|
): Promise<q.ConversationListResponse> => {
|
|
const pageNumber = params?.pageNumber || '1'; // Default to page 1 if not provided
|
|
const searchQuery = params?.searchQuery || ''; // If no search query is provided, default to an empty string
|
|
// Update the endpoint to handle a search query
|
|
if (searchQuery !== '') {
|
|
return request.get(endpoints.search(searchQuery, pageNumber));
|
|
} else {
|
|
return request.get(endpoints.conversations(pageNumber));
|
|
}
|
|
};
|
|
|
|
export const searchConversations = async (
|
|
q: string,
|
|
pageNumber: string,
|
|
): Promise<t.TSearchResults> => {
|
|
return request.get(endpoints.search(q, pageNumber));
|
|
};
|
|
|
|
export function getConversations(pageNumber: string): Promise<t.TGetConversationsResponse> {
|
|
return request.get(endpoints.conversations(pageNumber));
|
|
}
|
|
|
|
export function getConversationById(id: string): Promise<s.TConversation> {
|
|
return request.get(endpoints.conversationById(id));
|
|
}
|
|
|
|
export function updateConversation(
|
|
payload: t.TUpdateConversationRequest,
|
|
): Promise<t.TUpdateConversationResponse> {
|
|
return request.post(endpoints.updateConversation(), { arg: payload });
|
|
}
|
|
|
|
export function archiveConversation(
|
|
payload: t.TArchiveConversationRequest,
|
|
): Promise<t.TArchiveConversationResponse> {
|
|
return request.post(endpoints.updateConversation(), { arg: payload });
|
|
}
|
|
|
|
export function genTitle(payload: m.TGenTitleRequest): Promise<m.TGenTitleResponse> {
|
|
return request.post(endpoints.genTitle(), payload);
|
|
}
|
|
|
|
export function getPrompt(id: string): Promise<{ prompt: t.TPrompt }> {
|
|
return request.get(endpoints.getPrompt(id));
|
|
}
|
|
|
|
export function getPrompts(filter: t.TPromptsWithFilterRequest): Promise<t.TPrompt[]> {
|
|
return request.get(endpoints.getPromptsWithFilters(filter));
|
|
}
|
|
|
|
export function getAllPromptGroups(): Promise<q.AllPromptGroupsResponse> {
|
|
return request.get(endpoints.getAllPromptGroups());
|
|
}
|
|
|
|
export function getPromptGroups(
|
|
filter: t.TPromptGroupsWithFilterRequest,
|
|
): Promise<t.PromptGroupListResponse> {
|
|
return request.get(endpoints.getPromptGroupsWithFilters(filter));
|
|
}
|
|
|
|
export function getPromptGroup(id: string): Promise<t.TPromptGroup> {
|
|
return request.get(endpoints.getPromptGroup(id));
|
|
}
|
|
|
|
export function createPrompt(payload: t.TCreatePrompt): Promise<t.TCreatePromptResponse> {
|
|
return request.post(endpoints.postPrompt(), payload);
|
|
}
|
|
|
|
export function updatePromptGroup(
|
|
variables: t.TUpdatePromptGroupVariables,
|
|
): Promise<t.TUpdatePromptGroupResponse> {
|
|
return request.patch(endpoints.updatePromptGroup(variables.id), variables.payload);
|
|
}
|
|
|
|
export function deletePrompt(payload: t.TDeletePromptVariables): Promise<t.TDeletePromptResponse> {
|
|
return request.delete(endpoints.deletePrompt(payload));
|
|
}
|
|
|
|
export function makePromptProduction(id: string): Promise<t.TMakePromptProductionResponse> {
|
|
return request.patch(endpoints.updatePromptTag(id));
|
|
}
|
|
|
|
export function updatePromptLabels(
|
|
variables: t.TUpdatePromptLabelsRequest,
|
|
): Promise<t.TUpdatePromptLabelsResponse> {
|
|
return request.patch(endpoints.updatePromptLabels(variables.id), variables.payload);
|
|
}
|
|
|
|
export function deletePromptGroup(id: string): Promise<t.TDeletePromptGroupResponse> {
|
|
return request.delete(endpoints.deletePromptGroup(id));
|
|
}
|
|
|
|
export function getCategories(): Promise<t.TGetCategoriesResponse> {
|
|
return request.get(endpoints.getCategories());
|
|
}
|
|
|
|
export function getRandomPrompts(
|
|
variables: t.TGetRandomPromptsRequest,
|
|
): Promise<t.TGetRandomPromptsResponse> {
|
|
return request.get(endpoints.getRandomPrompts(variables.limit, variables.skip));
|
|
}
|
|
|
|
/* Roles */
|
|
export function getRole(roleName: string): Promise<r.TRole> {
|
|
return request.get(endpoints.getRole(roleName));
|
|
}
|
|
|
|
export function updatePromptPermissions(
|
|
variables: m.UpdatePromptPermVars,
|
|
): Promise<m.UpdatePromptPermResponse> {
|
|
return request.put(endpoints.updatePromptPermissions(variables.roleName), variables.updates);
|
|
}
|
|
|
|
/* Tags */
|
|
export function getConversationTags(): Promise<t.TConversationTagsResponse> {
|
|
return request.get(endpoints.conversationTags());
|
|
}
|
|
|
|
export function createConversationTag(
|
|
payload: t.TConversationTagRequest,
|
|
): Promise<t.TConversationTagResponse> {
|
|
return request.post(endpoints.conversationTags(), payload);
|
|
}
|
|
|
|
export function updateConversationTag(
|
|
tag: string,
|
|
payload: t.TConversationTagRequest,
|
|
): Promise<t.TConversationTagResponse> {
|
|
return request.put(endpoints.conversationTags(tag), payload);
|
|
}
|
|
export function deleteConversationTag(tag: string): Promise<t.TConversationTagResponse> {
|
|
return request.delete(endpoints.conversationTags(tag));
|
|
}
|
|
|
|
export function addTagToConversation(
|
|
conversationId: string,
|
|
payload: t.TTagConversationRequest,
|
|
): Promise<t.TTagConversationResponse> {
|
|
return request.put(endpoints.addTagToConversation(conversationId), payload);
|
|
}
|
|
export function rebuildConversationTags(): Promise<t.TConversationTagsResponse> {
|
|
return request.post(endpoints.conversationTags('rebuild'));
|
|
}
|
|
|
|
export function healthCheck(): Promise<string> {
|
|
return request.get(endpoints.health());
|
|
}
|
|
|
|
export function getUserTerms(): Promise<t.TUserTermsResponse> {
|
|
return request.get(endpoints.userTerms());
|
|
}
|
|
|
|
export function acceptTerms(): Promise<t.TAcceptTermsResponse> {
|
|
return request.post(endpoints.acceptUserTerms());
|
|
}
|