LibreChat/packages/data-schemas
Ruben Talstra 3a62a2633d
💵 feat: Add Automatic Balance Refill (#6452)
* 🚀 feat: Add automatic refill settings to balance schema

* 🚀 feat: Refactor balance feature to use global interface configuration

* 🚀 feat: Implement auto-refill functionality for balance management

* 🚀 feat: Enhance auto-refill logic and configuration for balance management

* 🚀 chore: Bump version to 0.7.74 in package.json and package-lock.json

* 🚀 chore: Bump version to 0.0.5 in package.json and package-lock.json

* 🚀 docs: Update comment for balance settings in librechat.example.yaml

* chore: space in `.env.example`

* 🚀 feat: Implement balance configuration loading and refactor related components

* 🚀 test: Refactor tests to use custom config for balance feature

* 🚀 fix: Update balance response handling in Transaction.js to use Balance model

* 🚀 test: Update AppService tests to include balance configuration in mock setup

* 🚀 test: Enhance AppService tests with complete balance configuration scenarios

* 🚀 refactor: Rename balanceConfig to balance and update related tests for clarity

* 🚀 refactor: Remove loadDefaultBalance and update balance handling in AppService

* 🚀 test: Update AppService tests to reflect new balance structure and defaults

* 🚀 test: Mock getCustomConfig in BaseClient tests to control balance configuration

* 🚀 test: Add get method to mockCache in OpenAIClient tests for improved cache handling

* 🚀 test: Mock getCustomConfig in OpenAIClient tests to control balance configuration

* 🚀 test: Remove mock for getCustomConfig in OpenAIClient tests to streamline configuration handling

* 🚀 fix: Update balance configuration reference in config.js for consistency

* refactor: Add getBalanceConfig function to retrieve balance configuration

* chore: Comment out example balance settings in librechat.example.yaml

* refactor: Replace getCustomConfig with getBalanceConfig for balance handling

* fix: tests

* refactor: Replace getBalanceConfig call with balance from request locals

* refactor: Update balance handling to use environment variables for configuration

* refactor: Replace getBalanceConfig calls with balance from request locals

* refactor: Simplify balance configuration logic in getBalanceConfig

---------

Co-authored-by: Danny Avila <danny@librechat.ai>
2025-03-21 17:48:11 -04:00
..
src 💵 feat: Add Automatic Balance Refill (#6452) 2025-03-21 17:48:11 -04:00
.gitignore 📦 refactor: Move DB Models to @librechat/data-schemas (#6210) 2025-03-07 11:55:44 -05:00
babel.config.cjs 📦 refactor: Move DB Models to @librechat/data-schemas (#6210) 2025-03-07 11:55:44 -05:00
jest.config.mjs 📦 refactor: Move DB Models to @librechat/data-schemas (#6210) 2025-03-07 11:55:44 -05:00
LICENSE 🔏 fix: Enhance Two-Factor Authentication (#6247) 2025-03-08 15:28:27 -05:00
package.json 💵 feat: Add Automatic Balance Refill (#6452) 2025-03-21 17:48:11 -04:00
README.md 🔏 fix: Enhance Two-Factor Authentication (#6247) 2025-03-08 15:28:27 -05:00
rollup.config.js 🚀 feat: Refactor schema exports and update package version to 0.0.4 (#6455) 2025-03-21 08:20:23 -04:00
tsconfig.json 🚀 feat: Refactor schema exports and update package version to 0.0.4 (#6455) 2025-03-21 08:20:23 -04:00
tsconfig.spec.json 📦 refactor: Move DB Models to @librechat/data-schemas (#6210) 2025-03-07 11:55:44 -05:00

@librechat/data-schemas

Mongoose schemas and models for LibreChat. This package provides a comprehensive collection of Mongoose schemas used across the LibreChat project, enabling robust data modeling and validation for various entities such as actions, agents, messages, users, and more.

Features

  • Modular Schemas: Includes schemas for actions, agents, assistants, balance, banners, categories, conversation tags, conversations, files, keys, messages, plugin authentication, presets, projects, prompts, prompt groups, roles, sessions, shared links, tokens, tool calls, transactions, and users.
  • TypeScript Support: Provides TypeScript definitions for type-safe development.
  • Ready for Mongoose Integration: Easily integrate with Mongoose to create models and interact with your MongoDB database.
  • Flexible & Extensible: Designed to support the evolving needs of LibreChat while being adaptable to other projects.

Installation

Install the package via npm or yarn:

npm install @librechat/data-schemas

Or with yarn:

yarn add @librechat/data-schemas

Usage

After installation, you can import and use the schemas in your project. For example, to create a Mongoose model for a user:

import mongoose from 'mongoose';
import { userSchema } from '@librechat/data-schemas';

const UserModel = mongoose.model('User', userSchema);

// Now you can use UserModel to create, read, update, and delete user documents.

You can also import other schemas as needed:

import { actionSchema, agentSchema, messageSchema } from '@librechat/data-schemas';

Each schema is designed to integrate seamlessly with Mongoose and provides indexes, timestamps, and validations tailored for LibreChats use cases.

Development

This package uses Rollup and TypeScript for building and bundling.

Available Scripts

  • Build:
    Cleans the dist directory and builds the package.

    npm run build
    
  • Build Watch:
    Rebuilds automatically on file changes.

    npm run build:watch
    
  • Test:
    Runs tests with coverage in watch mode.

    npm run test
    
  • Test (CI):
    Runs tests with coverage for CI environments.

    npm run test:ci
    
  • Verify:
    Runs tests in CI mode to verify code integrity.

    npm run verify
    
  • Clean:
    Removes the dist directory.

    npm run clean
    

For those using Bun, equivalent scripts are available:

  • Bun Clean: bun run b:clean
  • Bun Build: bun run b:build

Repository & Issues

The source code is maintained on GitHub.

License

This project is licensed under the MIT License.

Contributing

Contributions to improve and expand the data schemas are welcome. If you have suggestions, improvements, or bug fixes, please open an issue or submit a pull request on the GitHub repository.

For more detailed documentation on each schema and model, please refer to the source code or visit the LibreChat website.