mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 17:30:16 +01:00
* 🧠 feat: User Memories for Conversational Context
chore: mcp typing, use `t`
WIP: first pass, Memories UI
- Added MemoryViewer component for displaying, editing, and deleting user memories.
- Integrated data provider hooks for fetching, updating, and deleting memories.
- Implemented pagination and loading states for better user experience.
- Created unit tests for MemoryViewer to ensure functionality and interaction with data provider.
- Updated translation files to include new UI strings related to memories.
chore: move mcp-related files to own directory
chore: rename librechat-mcp to librechat-api
WIP: first pass, memory processing and data schemas
chore: linting in fileSearch.js query description
chore: rename librechat-api to @librechat/api across the project
WIP: first pass, functional memory agent
feat: add MemoryEditDialog and MemoryViewer components for managing user memories
- Introduced MemoryEditDialog for editing memory entries with validation and toast notifications.
- Updated MemoryViewer to support editing and deleting memories, including pagination and loading states.
- Enhanced data provider to handle memory updates with optional original key for better management.
- Added new localization strings for memory-related UI elements.
feat: add memory permissions management
- Implemented memory permissions in the backend, allowing roles to have specific permissions for using, creating, updating, and reading memories.
- Added new API endpoints for updating memory permissions associated with roles.
- Created a new AdminSettings component for managing memory permissions in the frontend.
- Integrated memory permissions into the existing roles and permissions schemas.
- Updated the interface to include memory settings and permissions.
- Enhanced the MemoryViewer component to conditionally render admin settings based on user roles.
- Added localization support for memory permissions in the translation files.
feat: move AdminSettings component to a new position in MemoryViewer for better visibility
refactor: clean up commented code in MemoryViewer component
feat: enhance MemoryViewer with search functionality and improve MemoryEditDialog integration
- Added a search input to filter memories in the MemoryViewer component.
- Refactored MemoryEditDialog to accept children for better customization.
- Updated MemoryViewer to utilize the new EditMemoryButton and DeleteMemoryButton components for editing and deleting memories.
- Improved localization support by adding new strings for memory filtering and deletion confirmation.
refactor: optimize memory filtering in MemoryViewer using match-sorter
- Replaced manual filtering logic with match-sorter for improved search functionality.
- Enhanced performance and readability of the filteredMemories computation.
feat: enhance MemoryEditDialog with triggerRef and improve updateMemory mutation handling
feat: implement access control for MemoryEditDialog and MemoryViewer components
refactor: remove commented out code and create runMemory method
refactor: rename role based files
feat: implement access control for memory usage in AgentClient
refactor: simplify checkVisionRequest method in AgentClient by removing commented-out code
refactor: make `agents` dir in api package
refactor: migrate Azure utilities to TypeScript and consolidate imports
refactor: move sanitizeFilename function to a new file and update imports, add related tests
refactor: update LLM configuration types and consolidate Azure options in the API package
chore: linting
chore: import order
refactor: replace getLLMConfig with getOpenAIConfig and remove unused LLM configuration file
chore: update winston-daily-rotate-file to version 5.0.0 and add object-hash dependency in package-lock.json
refactor: move primeResources and optionalChainWithEmptyCheck functions to resources.ts and update imports
refactor: move createRun function to a new run.ts file and update related imports
fix: ensure safeAttachments is correctly typed as an array of TFile
chore: add node-fetch dependency and refactor fetch-related functions into packages/api/utils, removing the old generators file
refactor: enhance TEndpointOption type by using Pick to streamline endpoint fields and add new properties for model parameters and client options
feat: implement initializeOpenAIOptions function and update OpenAI types for enhanced configuration handling
fix: update types due to new TEndpointOption typing
fix: ensure safe access to group parameters in initializeOpenAIOptions function
fix: remove redundant API key validation comment in initializeOpenAIOptions function
refactor: rename initializeOpenAIOptions to initializeOpenAI for consistency and update related documentation
refactor: decouple req.body fields and tool loading from initializeAgentOptions
chore: linting
refactor: adjust column widths in MemoryViewer for improved layout
refactor: simplify agent initialization by creating loadAgent function and removing unused code
feat: add memory configuration loading and validation functions
WIP: first pass, memory processing with config
feat: implement memory callback and artifact handling
feat: implement memory artifacts display and processing updates
feat: add memory configuration options and schema validation for validKeys
fix: update MemoryEditDialog and MemoryViewer to handle memory state and display improvements
refactor: remove padding from BookmarkTable and MemoryViewer headers for consistent styling
WIP: initial tokenLimit config and move Tokenizer to @librechat/api
refactor: update mongoMeili plugin methods to use callback for better error handling
feat: enhance memory management with token tracking and usage metrics
- Added token counting for memory entries to enforce limits and provide usage statistics.
- Updated memory retrieval and update routes to include total token usage and limit.
- Enhanced MemoryEditDialog and MemoryViewer components to display memory usage and token information.
- Refactored memory processing functions to handle token limits and provide feedback on memory capacity.
feat: implement memory artifact handling in attachment handler
- Enhanced useAttachmentHandler to process memory artifacts when receiving updates.
- Introduced handleMemoryArtifact utility to manage memory updates and deletions.
- Updated query client to reflect changes in memory state based on incoming data.
refactor: restructure web search key extraction logic
- Moved the logic for extracting API keys from the webSearchAuth configuration into a dedicated function, getWebSearchKeys.
- Updated webSearchKeys to utilize the new function for improved clarity and maintainability.
- Prevents build time errors
feat: add personalization settings and memory preferences management
- Introduced a new Personalization tab in settings to manage user memory preferences.
- Implemented API endpoints and client-side logic for updating memory preferences.
- Enhanced user interface components to reflect personalization options and memory usage.
- Updated permissions to allow users to opt out of memory features.
- Added localization support for new settings and messages related to personalization.
style: personalization switch class
feat: add PersonalizationIcon and align Side Panel UI
feat: implement memory creation functionality
- Added a new API endpoint for creating memory entries, including validation for key and value.
- Introduced MemoryCreateDialog component for user interface to facilitate memory creation.
- Integrated token limit checks to prevent exceeding user memory capacity.
- Updated MemoryViewer to include a button for opening the memory creation dialog.
- Enhanced localization support for new messages related to memory creation.
feat: enhance message processing with configurable window size
- Updated AgentClient to use a configurable message window size for processing messages.
- Introduced messageWindowSize option in memory configuration schema with a default value of 5.
- Improved logic for selecting messages to process based on the configured window size.
chore: update librechat-data-provider version to 0.7.87 in package.json and package-lock.json
chore: remove OpenAPIPlugin and its associated tests
chore: remove MIGRATION_README.md as migration tasks are completed
ci: fix backend tests
chore: remove unused translation keys from localization file
chore: remove problematic test file and unused var in AgentClient
chore: remove unused import and import directly for JSDoc
* feat: add api package build stage in Dockerfile for improved modularity
* docs: reorder build steps in contributing guide for clarity
837 lines
23 KiB
TypeScript
837 lines
23 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 getSharedMessages(shareId: string): Promise<t.TSharedMessagesResponse> {
|
|
return request.get(endpoints.shareMessages(shareId));
|
|
}
|
|
|
|
export const listSharedLinks = async (
|
|
params: q.SharedLinksListParams,
|
|
): Promise<q.SharedLinksResponse> => {
|
|
const { pageSize, isPublic, sortBy, sortDirection, search, cursor } = params;
|
|
|
|
return request.get(
|
|
endpoints.getSharedLinks(pageSize, isPublic, sortBy, sortDirection, search, cursor),
|
|
);
|
|
};
|
|
|
|
export function getSharedLink(conversationId: string): Promise<t.TSharedLinkGetResponse> {
|
|
return request.get(endpoints.getSharedLink(conversationId));
|
|
}
|
|
|
|
export function createSharedLink(conversationId: string): Promise<t.TSharedLinkResponse> {
|
|
return request.post(endpoints.createSharedLink(conversationId));
|
|
}
|
|
|
|
export function updateSharedLink(shareId: string): Promise<t.TSharedLinkResponse> {
|
|
return request.patch(endpoints.updateSharedLink(shareId));
|
|
}
|
|
|
|
export function deleteSharedLink(shareId: string): Promise<m.TDeleteSharedLinkResponse> {
|
|
return request.delete(endpoints.shareMessages(shareId));
|
|
}
|
|
|
|
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<t.TBalanceResponse> {
|
|
return request.get(endpoints.balance());
|
|
}
|
|
|
|
export const updateTokenCount = (text: string) => {
|
|
return request.post(endpoints.tokenizer(), { arg: text });
|
|
};
|
|
|
|
export const login = (payload: t.TLoginUser): Promise<t.TLoginResponse> => {
|
|
return request.post(endpoints.login(), payload);
|
|
};
|
|
|
|
export const logout = (): Promise<m.TLogoutResponse> => {
|
|
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<config.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);
|
|
};
|
|
|
|
export const getVerifyAgentToolAuth = (
|
|
params: q.VerifyToolAuthParams,
|
|
): Promise<q.VerifyToolAuthResponse> => {
|
|
return request.get(
|
|
endpoints.agents({
|
|
path: `tools/${params.toolId}/auth`,
|
|
}),
|
|
);
|
|
};
|
|
|
|
export const callTool = <T extends m.ToolId>({
|
|
toolId,
|
|
toolParams,
|
|
}: {
|
|
toolId: T;
|
|
toolParams: m.ToolParams<T>;
|
|
}): Promise<m.ToolCallResponse> => {
|
|
return request.post(
|
|
endpoints.agents({
|
|
path: `tools/${toolId}/call`,
|
|
}),
|
|
toolParams,
|
|
);
|
|
};
|
|
|
|
export const getToolCalls = (params: q.GetToolCallParams): Promise<q.ToolCallResults> => {
|
|
return request.get(
|
|
endpoints.agents({
|
|
path: 'tools/calls',
|
|
options: params,
|
|
}),
|
|
);
|
|
};
|
|
|
|
/* 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,
|
|
signal?: AbortSignal | null,
|
|
): Promise<f.TFileUpload> => {
|
|
const requestConfig = signal ? { signal } : undefined;
|
|
return request.postMultiPart(endpoints.images(), data, requestConfig);
|
|
};
|
|
|
|
export const uploadFile = (data: FormData, signal?: AbortSignal | null): Promise<f.TFileUpload> => {
|
|
const requestConfig = signal ? { signal } : undefined;
|
|
return request.postMultiPart(endpoints.files(), data, requestConfig);
|
|
};
|
|
|
|
/* 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 duplicateAgent = ({
|
|
agent_id,
|
|
}: m.DuplicateAgentBody): Promise<{ agent: a.Agent; actions: a.Action[] }> => {
|
|
return request.post(
|
|
endpoints.agents({
|
|
path: `${agent_id}/duplicate`,
|
|
}),
|
|
);
|
|
};
|
|
|
|
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,
|
|
}),
|
|
);
|
|
};
|
|
|
|
export const revertAgentVersion = ({
|
|
agent_id,
|
|
version_index,
|
|
}: {
|
|
agent_id: string;
|
|
version_index: number;
|
|
}): Promise<a.Agent> => request.post(endpoints.revertAgentVersion(agent_id), { version_index });
|
|
|
|
/* 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({
|
|
isAvatar: true,
|
|
path: `${data.assistant_id}/avatar`,
|
|
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.images()}/agents/${data.agent_id}/avatar`,
|
|
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 getCodeOutputDownload = async (url: string): Promise<AxiosResponse> => {
|
|
return request.getResponse(url, {
|
|
responseType: 'blob',
|
|
headers: {
|
|
Accept: 'application/octet-stream',
|
|
},
|
|
});
|
|
};
|
|
|
|
export const deleteFiles = async (payload: {
|
|
files: f.BatchFile[];
|
|
agent_id?: string;
|
|
assistant_id?: string;
|
|
tool_resource?: a.EToolResources;
|
|
}): Promise<f.DeleteFilesResponse> =>
|
|
request.deleteWithOptions(endpoints.files(), {
|
|
data: payload,
|
|
});
|
|
|
|
/* 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 duplicateConversation(
|
|
payload: t.TDuplicateConvoRequest,
|
|
): Promise<t.TDuplicateConvoResponse> {
|
|
return request.post(endpoints.duplicateConversation(), payload);
|
|
}
|
|
|
|
export function forkConversation(payload: t.TForkConvoRequest): Promise<t.TForkConvoResponse> {
|
|
return request.post(endpoints.forkConversation(), payload);
|
|
}
|
|
|
|
export function deleteConversation(payload: t.TDeleteConversationRequest) {
|
|
return request.deleteWithOptions(endpoints.deleteConversation(), { data: { arg: payload } });
|
|
}
|
|
|
|
export function clearAllConversations(): Promise<unknown> {
|
|
return request.delete(endpoints.deleteAllConversation());
|
|
}
|
|
|
|
export const listConversations = (
|
|
params?: q.ConversationListParams,
|
|
): Promise<q.ConversationListResponse> => {
|
|
return request.get(endpoints.conversations(params ?? {}));
|
|
};
|
|
|
|
export function getConversations(cursor: string): Promise<t.TGetConversationsResponse> {
|
|
return request.get(endpoints.conversations({ cursor }));
|
|
}
|
|
|
|
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 const listMessages = (params?: q.MessagesListParams): Promise<q.MessagesListResponse> => {
|
|
return request.get(endpoints.messages(params ?? {}));
|
|
};
|
|
|
|
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 updateMessageContent(payload: t.TUpdateMessageContent): Promise<unknown> {
|
|
const { conversationId, messageId, index, text } = payload;
|
|
if (!conversationId) {
|
|
throw new Error('conversationId is required');
|
|
}
|
|
|
|
return request.put(endpoints.messages({ conversationId, messageId }), { text, index });
|
|
}
|
|
|
|
export const editArtifact = async ({
|
|
messageId,
|
|
...params
|
|
}: m.TEditArtifactRequest): Promise<m.TEditArtifactResponse> => {
|
|
return request.post(`/api/messages/artifact/${messageId}`, params);
|
|
};
|
|
|
|
export function getMessagesByConvoId(conversationId: string): Promise<s.TMessage[]> {
|
|
if (
|
|
conversationId === config.Constants.NEW_CONVO ||
|
|
conversationId === config.Constants.PENDING_CONVO
|
|
) {
|
|
return Promise.resolve([]);
|
|
}
|
|
return request.get(endpoints.messages({ conversationId }));
|
|
}
|
|
|
|
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.UpdatePermResponse> {
|
|
return request.put(endpoints.updatePromptPermissions(variables.roleName), variables.updates);
|
|
}
|
|
|
|
export function updateAgentPermissions(
|
|
variables: m.UpdateAgentPermVars,
|
|
): Promise<m.UpdatePermResponse> {
|
|
return request.put(endpoints.updateAgentPermissions(variables.roleName), variables.updates);
|
|
}
|
|
|
|
export function updateMemoryPermissions(
|
|
variables: m.UpdateMemoryPermVars,
|
|
): Promise<m.UpdatePermResponse> {
|
|
return request.put(endpoints.updateMemoryPermissions(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());
|
|
}
|
|
|
|
export function getBanner(): Promise<t.TBannerResponse> {
|
|
return request.get(endpoints.banner());
|
|
}
|
|
|
|
export function updateFeedback(
|
|
conversationId: string,
|
|
messageId: string,
|
|
payload: t.TUpdateFeedbackRequest,
|
|
): Promise<t.TUpdateFeedbackResponse> {
|
|
return request.put(endpoints.feedback(conversationId, messageId), payload);
|
|
}
|
|
|
|
// 2FA
|
|
export function enableTwoFactor(): Promise<t.TEnable2FAResponse> {
|
|
return request.get(endpoints.enableTwoFactor());
|
|
}
|
|
|
|
export function verifyTwoFactor(payload: t.TVerify2FARequest): Promise<t.TVerify2FAResponse> {
|
|
return request.post(endpoints.verifyTwoFactor(), payload);
|
|
}
|
|
|
|
export function confirmTwoFactor(payload: t.TVerify2FARequest): Promise<t.TVerify2FAResponse> {
|
|
return request.post(endpoints.confirmTwoFactor(), payload);
|
|
}
|
|
|
|
export function disableTwoFactor(): Promise<t.TDisable2FAResponse> {
|
|
return request.post(endpoints.disableTwoFactor());
|
|
}
|
|
|
|
export function regenerateBackupCodes(): Promise<t.TRegenerateBackupCodesResponse> {
|
|
return request.post(endpoints.regenerateBackupCodes());
|
|
}
|
|
|
|
export function verifyTwoFactorTemp(
|
|
payload: t.TVerify2FATempRequest,
|
|
): Promise<t.TVerify2FATempResponse> {
|
|
return request.post(endpoints.verifyTwoFactorTemp(), payload);
|
|
}
|
|
|
|
/* Memories */
|
|
export const getMemories = (): Promise<q.MemoriesResponse> => {
|
|
return request.get(endpoints.memories());
|
|
};
|
|
|
|
export const deleteMemory = (key: string): Promise<void> => {
|
|
return request.delete(endpoints.memory(key));
|
|
};
|
|
|
|
export const updateMemory = (
|
|
key: string,
|
|
value: string,
|
|
originalKey?: string,
|
|
): Promise<q.TUserMemory> => {
|
|
return request.patch(endpoints.memory(originalKey || key), { key, value });
|
|
};
|
|
|
|
export const updateMemoryPreferences = (preferences: {
|
|
memories: boolean;
|
|
}): Promise<{ updated: boolean; preferences: { memories: boolean } }> => {
|
|
return request.patch(endpoints.memoryPreferences(), preferences);
|
|
};
|
|
|
|
export const createMemory = (data: {
|
|
key: string;
|
|
value: string;
|
|
}): Promise<{ created: boolean; memory: q.TUserMemory }> => {
|
|
return request.post(endpoints.memories(), data);
|
|
};
|