Skip to content

Commit e0cf59a

Browse files
committed
🧠 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
1 parent cd7dd57 commit e0cf59a

File tree

170 files changed

+5689
-3622
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+5689
-3622
lines changed

.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Project maintainers have the right and responsibility to remove, edit, or reject
3030
2. Install typescript globally: `npm i -g typescript`.
3131
3. Run `npm ci` to install dependencies.
3232
4. Build the data provider: `npm run build:data-provider`.
33-
5. Build MCP: `npm run build:mcp`.
33+
5. Build API methods: `npm run build:api`.
3434
6. Build data schemas: `npm run build:data-schemas`.
3535
7. Setup and run unit tests:
3636
- Copy `.env.test`: `cp api/test/.env.test.example api/test/.env.test`.

.github/workflows/backend-review.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
- release/*
88
paths:
99
- 'api/**'
10+
- 'packages/api/**'
1011
jobs:
1112
tests_Backend:
1213
name: Run Backend unit tests
@@ -37,7 +38,7 @@ jobs:
3738
run: npm run build:data-provider
3839

3940
- name: Install MCP Package
40-
run: npm run build:mcp
41+
run: npm run build:api
4142

4243
- name: Install Data Schemas Package
4344
run: npm run build:data-schemas
@@ -66,5 +67,5 @@ jobs:
6667
- name: Run librechat-data-provider unit tests
6768
run: cd packages/data-provider && npm run test:ci
6869

69-
- name: Run librechat-mcp unit tests
70-
run: cd packages/mcp && npm run test:ci
70+
- name: Run librechat-api unit tests
71+
run: cd packages/api && npm run test:ci

Dockerfile.multi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ RUN npm config set fetch-retry-maxtimeout 600000 && \
1414
npm config set fetch-retry-mintimeout 15000
1515
COPY package*.json ./
1616
COPY packages/data-provider/package*.json ./packages/data-provider/
17-
COPY packages/mcp/package*.json ./packages/mcp/
17+
COPY packages/api/package*.json ./packages/api/
1818
COPY packages/data-schemas/package*.json ./packages/data-schemas/
1919
COPY client/package*.json ./client/
2020
COPY api/package*.json ./api/
@@ -32,8 +32,8 @@ RUN npm run build
3232

3333
# Build mcp package
3434
FROM base AS mcp-build
35-
WORKDIR /app/packages/mcp
36-
COPY packages/mcp ./
35+
WORKDIR /app/packages/api
36+
COPY packages/api ./
3737
COPY --from=data-provider-build /app/packages/data-provider/dist /app/packages/data-provider/dist
3838
RUN npm run build
3939

@@ -63,7 +63,7 @@ RUN npm ci --omit=dev
6363
COPY api ./api
6464
COPY config ./config
6565
COPY --from=data-provider-build /app/packages/data-provider/dist ./packages/data-provider/dist
66-
COPY --from=mcp-build /app/packages/mcp/dist ./packages/mcp/dist
66+
COPY --from=mcp-build /app/packages/api/dist ./packages/api/dist
6767
COPY --from=data-schemas-build /app/packages/data-schemas/dist ./packages/data-schemas/dist
6868
COPY --from=client-build /app/client/dist ./client/dist
6969
WORKDIR /app/api

api/app/clients/AnthropicClient.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const {
1010
validateVisionModel,
1111
} = require('librechat-data-provider');
1212
const { SplitStreamHandler: _Handler } = require('@librechat/agents');
13+
const { Tokenizer, createFetch, createStreamEventHandlers } = require('@librechat/api');
1314
const {
1415
truncateText,
1516
formatMessage,
@@ -26,8 +27,6 @@ const {
2627
const { getModelMaxTokens, getModelMaxOutputTokens, matchModelName } = require('~/utils');
2728
const { spendTokens, spendStructuredTokens } = require('~/models/spendTokens');
2829
const { encodeAndFormat } = require('~/server/services/Files/images/encode');
29-
const { createFetch, createStreamEventHandlers } = require('./generators');
30-
const Tokenizer = require('~/server/services/Tokenizer');
3130
const { sleep } = require('~/server/utils');
3231
const BaseClient = require('./BaseClient');
3332
const { logger } = require('~/config');

api/app/clients/ChatGPTClient.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const { Keyv } = require('keyv');
22
const crypto = require('crypto');
33
const { CohereClient } = require('cohere-ai');
44
const { fetchEventSource } = require('@waylaidwanderer/fetch-event-source');
5+
const { constructAzureURL, genAzureChatCompletion } = require('@librechat/api');
56
const { encoding_for_model: encodingForModel, get_encoding: getEncoding } = require('tiktoken');
67
const {
78
ImageDetail,
@@ -10,9 +11,9 @@ const {
1011
CohereConstants,
1112
mapModelToAzureConfig,
1213
} = require('librechat-data-provider');
13-
const { extractBaseURL, constructAzureURL, genAzureChatCompletion } = require('~/utils');
1414
const { createContextHandlers } = require('./prompts');
1515
const { createCoherePayload } = require('./llm');
16+
const { extractBaseURL } = require('~/utils');
1617
const BaseClient = require('./BaseClient');
1718
const { logger } = require('~/config');
1819

api/app/clients/GoogleClient.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const { google } = require('googleapis');
2+
const { Tokenizer } = require('@librechat/api');
23
const { concat } = require('@langchain/core/utils/stream');
34
const { ChatVertexAI } = require('@langchain/google-vertexai');
45
const { ChatGoogleGenerativeAI } = require('@langchain/google-genai');
@@ -19,7 +20,6 @@ const {
1920
} = require('librechat-data-provider');
2021
const { getSafetySettings } = require('~/server/services/Endpoints/google/llm');
2122
const { encodeAndFormat } = require('~/server/services/Files/images');
22-
const Tokenizer = require('~/server/services/Tokenizer');
2323
const { spendTokens } = require('~/models/spendTokens');
2424
const { getModelMaxTokens } = require('~/utils');
2525
const { sleep } = require('~/server/utils');

api/app/clients/OpenAIClient.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
const { OllamaClient } = require('./OllamaClient');
22
const { HttpsProxyAgent } = require('https-proxy-agent');
33
const { SplitStreamHandler, CustomOpenAIClient: OpenAI } = require('@librechat/agents');
4+
const {
5+
isEnabled,
6+
Tokenizer,
7+
createFetch,
8+
constructAzureURL,
9+
genAzureChatCompletion,
10+
createStreamEventHandlers,
11+
} = require('@librechat/api');
412
const {
513
Constants,
614
ImageDetail,
@@ -16,24 +24,16 @@ const {
1624
validateVisionModel,
1725
mapModelToAzureConfig,
1826
} = require('librechat-data-provider');
19-
const {
20-
extractBaseURL,
21-
constructAzureURL,
22-
getModelMaxTokens,
23-
genAzureChatCompletion,
24-
getModelMaxOutputTokens,
25-
} = require('~/utils');
2627
const {
2728
truncateText,
2829
formatMessage,
2930
CUT_OFF_PROMPT,
3031
titleInstruction,
3132
createContextHandlers,
3233
} = require('./prompts');
34+
const { extractBaseURL, getModelMaxTokens, getModelMaxOutputTokens } = require('~/utils');
3335
const { encodeAndFormat } = require('~/server/services/Files/images/encode');
34-
const { createFetch, createStreamEventHandlers } = require('./generators');
35-
const { addSpaceIfNeeded, isEnabled, sleep } = require('~/server/utils');
36-
const Tokenizer = require('~/server/services/Tokenizer');
36+
const { addSpaceIfNeeded, sleep } = require('~/server/utils');
3737
const { spendTokens } = require('~/models/spendTokens');
3838
const { handleOpenAIErrors } = require('./tools/util');
3939
const { createLLM, RunManager } = require('./llm');

api/app/clients/generators.js

Lines changed: 0 additions & 71 deletions
This file was deleted.

api/app/clients/llm/createLLM.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const { ChatOpenAI } = require('@langchain/openai');
2-
const { sanitizeModelName, constructAzureURL } = require('~/utils');
3-
const { isEnabled } = require('~/server/utils');
2+
const { isEnabled, sanitizeModelName, constructAzureURL } = require('@librechat/api');
43

54
/**
65
* Creates a new instance of a language model (LLM) for chat interactions.

api/app/clients/specs/BaseClient.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ jest.mock('~/models', () => ({
3333
const { getConvo, saveConvo } = require('~/models');
3434

3535
jest.mock('@librechat/agents', () => {
36+
const { Providers } = jest.requireActual('@librechat/agents');
3637
return {
38+
Providers,
3739
ChatOpenAI: jest.fn().mockImplementation(() => {
3840
return {};
3941
}),

0 commit comments

Comments
 (0)