mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-19 16:56:12 +01:00
refactor: original changes
This commit is contained in:
parent
fa9177180f
commit
f9c0e9853f
83 changed files with 413 additions and 505 deletions
|
|
@ -1,10 +1,7 @@
|
|||
// Export all types
|
||||
export { default as logger } from './config/winston';
|
||||
export { default as meiliLogger } from './config/meiliLogger';
|
||||
export * from './types';
|
||||
|
||||
// Export all models
|
||||
export * from './models';
|
||||
|
||||
// Export all methods
|
||||
export * from './methods';
|
||||
|
||||
// Export schemas (if needed for direct access)
|
||||
|
|
@ -16,13 +13,10 @@ export { default as tokenSchema } from './schema/token';
|
|||
export { signPayload, hashToken } from './schema/session';
|
||||
|
||||
export { default as actionSchema } from './schema/action';
|
||||
export type { IAction } from './schema/action';
|
||||
|
||||
export { default as agentSchema } from './schema/agent';
|
||||
export type { IAgent } from './schema/agent';
|
||||
|
||||
export { default as assistantSchema } from './schema/assistant';
|
||||
export type { IAssistant } from './schema/assistant';
|
||||
|
||||
export { default as balanceSchema } from './schema/balance';
|
||||
|
||||
|
|
@ -38,10 +32,8 @@ export type { IConversationTag } from './schema/conversationTag';
|
|||
export { default as convoSchema } from './schema/convo';
|
||||
|
||||
export { default as fileSchema } from './schema/file';
|
||||
export type { IMongoFile } from './schema/file';
|
||||
|
||||
export { default as keySchema } from './schema/key';
|
||||
export type { IKey } from './schema/key';
|
||||
|
||||
export { default as messageSchema } from './schema/message';
|
||||
export type { IMessage } from './schema/message';
|
||||
|
|
@ -62,7 +54,6 @@ export { default as promptGroupSchema } from './schema/promptGroup';
|
|||
export type { IPromptGroup, IPromptGroupDocument } from './schema/promptGroup';
|
||||
|
||||
export { default as roleSchema } from './schema/role';
|
||||
export type { IRole } from './schema/role';
|
||||
|
||||
export { default as shareSchema } from './schema/share';
|
||||
export type { ISharedLink } from './schema/share';
|
||||
|
|
|
|||
5
packages/data-schemas/src/models/action.ts
Normal file
5
packages/data-schemas/src/models/action.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import mongoose from 'mongoose';
|
||||
import actionSchema from '~/schema/action';
|
||||
import type { IAction } from '~/types';
|
||||
|
||||
export const Action = mongoose.models.Action || mongoose.model<IAction>('Action', actionSchema);
|
||||
5
packages/data-schemas/src/models/agent.ts
Normal file
5
packages/data-schemas/src/models/agent.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import mongoose from 'mongoose';
|
||||
import agentSchema from '~/schema/agent';
|
||||
import type { IAgent } from '~/types';
|
||||
|
||||
export const Agent = mongoose.models.Agent || mongoose.model<IAgent>('Agent', agentSchema);
|
||||
6
packages/data-schemas/src/models/assistant.ts
Normal file
6
packages/data-schemas/src/models/assistant.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import mongoose from 'mongoose';
|
||||
import assistantSchema from '~/schema/assistant';
|
||||
import type { IAssistant } from '~/types';
|
||||
|
||||
export const Assistant =
|
||||
mongoose.models.Assistant || mongoose.model<IAssistant>('Assistant', assistantSchema);
|
||||
5
packages/data-schemas/src/models/banner.ts
Normal file
5
packages/data-schemas/src/models/banner.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import mongoose from 'mongoose';
|
||||
import bannerSchema from '~/schema/banner';
|
||||
import type { IBanner } from '~/types';
|
||||
|
||||
export const Banner = mongoose.models.Banner || mongoose.model<IBanner>('Banner', bannerSchema);
|
||||
5
packages/data-schemas/src/models/file.ts
Normal file
5
packages/data-schemas/src/models/file.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import mongoose from 'mongoose';
|
||||
import fileSchema from '~/schema/file';
|
||||
import type { IMongoFile } from '~/types';
|
||||
|
||||
export const File = mongoose.models.File || mongoose.model<IMongoFile>('File', fileSchema);
|
||||
|
|
@ -5,3 +5,8 @@ export { Session } from './session';
|
|||
export { Balance } from './balance';
|
||||
export { Conversation } from './convo';
|
||||
export { Message } from './message';
|
||||
export { Agent } from './agent';
|
||||
export { Role } from './role';
|
||||
export { Action } from './action';
|
||||
export { Assistant } from './assistant';
|
||||
export { File } from './file';
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import _ from 'lodash';
|
||||
import mongoose, { Schema, Document, Model, Query } from 'mongoose';
|
||||
import { MeiliSearch, Index } from 'meilisearch';
|
||||
import mongoose, { Schema, Document, Model, Query } from 'mongoose';
|
||||
import logger from '~/config/meiliLogger';
|
||||
|
||||
interface MongoMeiliOptions {
|
||||
|
|
|
|||
5
packages/data-schemas/src/models/role.ts
Normal file
5
packages/data-schemas/src/models/role.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import mongoose from 'mongoose';
|
||||
import roleSchema from '~/schema/role';
|
||||
import type { IRole } from '~/types';
|
||||
|
||||
export const Role = mongoose.models.Role || mongoose.model<IRole>('Role', roleSchema);
|
||||
|
|
@ -1,31 +1,5 @@
|
|||
import mongoose, { Schema, Document } from 'mongoose';
|
||||
|
||||
export interface IAction extends Document {
|
||||
user: mongoose.Types.ObjectId;
|
||||
action_id: string;
|
||||
type: string;
|
||||
settings?: unknown;
|
||||
agent_id?: string;
|
||||
assistant_id?: string;
|
||||
metadata: {
|
||||
api_key?: string;
|
||||
auth: {
|
||||
authorization_type?: string;
|
||||
custom_auth_header?: string;
|
||||
type: 'service_http' | 'oauth' | 'none';
|
||||
authorization_content_type?: string;
|
||||
authorization_url?: string;
|
||||
client_url?: string;
|
||||
scope?: string;
|
||||
token_exchange_method: 'default_post' | 'basic_auth_header' | null;
|
||||
};
|
||||
domain: string;
|
||||
privacy_policy_url?: string;
|
||||
raw_spec?: string;
|
||||
oauth_client_id?: string;
|
||||
oauth_client_secret?: string;
|
||||
};
|
||||
}
|
||||
import mongoose, { Schema } from 'mongoose';
|
||||
import type { IAction } from '~/types';
|
||||
|
||||
// Define the Auth sub-schema with type-safety.
|
||||
const AuthSchema = new Schema(
|
||||
|
|
|
|||
|
|
@ -1,33 +1,5 @@
|
|||
import { Schema, Document, Types } from 'mongoose';
|
||||
export interface IAgent extends Omit<Document, 'model'> {
|
||||
id: string;
|
||||
name?: string;
|
||||
description?: string;
|
||||
instructions?: string;
|
||||
avatar?: {
|
||||
filepath: string;
|
||||
source: string;
|
||||
};
|
||||
provider: string;
|
||||
model: string;
|
||||
model_parameters?: Record<string, unknown>;
|
||||
artifacts?: string;
|
||||
access_level?: number;
|
||||
recursion_limit?: number;
|
||||
tools?: string[];
|
||||
tool_kwargs?: Array<unknown>;
|
||||
actions?: string[];
|
||||
author: Types.ObjectId;
|
||||
authorName?: string;
|
||||
hide_sequential_outputs?: boolean;
|
||||
end_after_tools?: boolean;
|
||||
agent_ids?: string[];
|
||||
isCollaborative?: boolean;
|
||||
conversation_starters?: string[];
|
||||
tool_resources?: unknown;
|
||||
projectIds?: Types.ObjectId[];
|
||||
versions?: Omit<IAgent, 'versions'>[];
|
||||
}
|
||||
import { Schema } from 'mongoose';
|
||||
import type { IAgent } from '~/types';
|
||||
|
||||
const agentSchema = new Schema<IAgent>(
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,18 +1,5 @@
|
|||
import { Schema, Document, Types } from 'mongoose';
|
||||
|
||||
export interface IAssistant extends Document {
|
||||
user: Types.ObjectId;
|
||||
assistant_id: string;
|
||||
avatar?: {
|
||||
filepath: string;
|
||||
source: string;
|
||||
};
|
||||
conversation_starters?: string[];
|
||||
access_level?: number;
|
||||
file_ids?: string[];
|
||||
actions?: string[];
|
||||
append_current_datetime?: boolean;
|
||||
}
|
||||
import { Schema } from 'mongoose';
|
||||
import type { IAssistant } from '~/types';
|
||||
|
||||
const assistantSchema = new Schema<IAssistant>(
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,32 +1,6 @@
|
|||
import mongoose, { Schema, Document, Types } from 'mongoose';
|
||||
import mongoose, { Schema } from 'mongoose';
|
||||
import { FileSources } from 'librechat-data-provider';
|
||||
|
||||
// @ts-ignore
|
||||
export interface IMongoFile extends Document {
|
||||
user: Types.ObjectId;
|
||||
conversationId?: string;
|
||||
file_id: string;
|
||||
temp_file_id?: string;
|
||||
bytes: number;
|
||||
text?: string;
|
||||
filename: string;
|
||||
filepath: string;
|
||||
object: 'file';
|
||||
embedded?: boolean;
|
||||
type: string;
|
||||
context?: string;
|
||||
usage: number;
|
||||
source: string;
|
||||
model?: string;
|
||||
width?: number;
|
||||
height?: number;
|
||||
metadata?: {
|
||||
fileIdentifier?: string;
|
||||
};
|
||||
expiresAt?: Date;
|
||||
createdAt?: Date;
|
||||
updatedAt?: Date;
|
||||
}
|
||||
import type { IMongoFile } from '~/types';
|
||||
|
||||
const file: Schema<IMongoFile> = new Schema(
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,36 +1,6 @@
|
|||
import { Schema, Document } from 'mongoose';
|
||||
import { Schema } from 'mongoose';
|
||||
import { PermissionTypes, Permissions } from 'librechat-data-provider';
|
||||
|
||||
export interface IRole extends Document {
|
||||
name: string;
|
||||
permissions: {
|
||||
[PermissionTypes.BOOKMARKS]?: {
|
||||
[Permissions.USE]?: boolean;
|
||||
};
|
||||
[PermissionTypes.PROMPTS]?: {
|
||||
[Permissions.SHARED_GLOBAL]?: boolean;
|
||||
[Permissions.USE]?: boolean;
|
||||
[Permissions.CREATE]?: boolean;
|
||||
};
|
||||
[PermissionTypes.AGENTS]?: {
|
||||
[Permissions.SHARED_GLOBAL]?: boolean;
|
||||
[Permissions.USE]?: boolean;
|
||||
[Permissions.CREATE]?: boolean;
|
||||
};
|
||||
[PermissionTypes.MULTI_CONVO]?: {
|
||||
[Permissions.USE]?: boolean;
|
||||
};
|
||||
[PermissionTypes.TEMPORARY_CHAT]?: {
|
||||
[Permissions.USE]?: boolean;
|
||||
};
|
||||
[PermissionTypes.RUN_CODE]?: {
|
||||
[Permissions.USE]?: boolean;
|
||||
};
|
||||
[PermissionTypes.WEB_SEARCH]?: {
|
||||
[Permissions.USE]?: boolean;
|
||||
};
|
||||
};
|
||||
}
|
||||
import type { IRole } from '~/types';
|
||||
|
||||
// Create a sub-schema for permissions. Notice we disable _id for this subdocument.
|
||||
const rolePermissionsSchema = new Schema(
|
||||
|
|
|
|||
28
packages/data-schemas/src/types/action.ts
Normal file
28
packages/data-schemas/src/types/action.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import mongoose, { Document } from 'mongoose';
|
||||
|
||||
export interface IAction extends Document {
|
||||
user: mongoose.Types.ObjectId;
|
||||
action_id: string;
|
||||
type: string;
|
||||
settings?: unknown;
|
||||
agent_id?: string;
|
||||
assistant_id?: string;
|
||||
metadata: {
|
||||
api_key?: string;
|
||||
auth: {
|
||||
authorization_type?: string;
|
||||
custom_auth_header?: string;
|
||||
type: 'service_http' | 'oauth' | 'none';
|
||||
authorization_content_type?: string;
|
||||
authorization_url?: string;
|
||||
client_url?: string;
|
||||
scope?: string;
|
||||
token_exchange_method: 'default_post' | 'basic_auth_header' | null;
|
||||
};
|
||||
domain: string;
|
||||
privacy_policy_url?: string;
|
||||
raw_spec?: string;
|
||||
oauth_client_id?: string;
|
||||
oauth_client_secret?: string;
|
||||
};
|
||||
}
|
||||
31
packages/data-schemas/src/types/agent.ts
Normal file
31
packages/data-schemas/src/types/agent.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { Document, Types } from 'mongoose';
|
||||
|
||||
export interface IAgent extends Omit<Document, 'model'> {
|
||||
id: string;
|
||||
name?: string;
|
||||
description?: string;
|
||||
instructions?: string;
|
||||
avatar?: {
|
||||
filepath: string;
|
||||
source: string;
|
||||
};
|
||||
provider: string;
|
||||
model: string;
|
||||
model_parameters?: Record<string, unknown>;
|
||||
artifacts?: string;
|
||||
access_level?: number;
|
||||
recursion_limit?: number;
|
||||
tools?: string[];
|
||||
tool_kwargs?: Array<unknown>;
|
||||
actions?: string[];
|
||||
author: Types.ObjectId;
|
||||
authorName?: string;
|
||||
hide_sequential_outputs?: boolean;
|
||||
end_after_tools?: boolean;
|
||||
agent_ids?: string[];
|
||||
isCollaborative?: boolean;
|
||||
conversation_starters?: string[];
|
||||
tool_resources?: unknown;
|
||||
projectIds?: Types.ObjectId[];
|
||||
versions?: Omit<IAgent, 'versions'>[];
|
||||
}
|
||||
15
packages/data-schemas/src/types/assistant.ts
Normal file
15
packages/data-schemas/src/types/assistant.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import { Document, Types } from 'mongoose';
|
||||
|
||||
export interface IAssistant extends Document {
|
||||
user: Types.ObjectId;
|
||||
assistant_id: string;
|
||||
avatar?: {
|
||||
filepath: string;
|
||||
source: string;
|
||||
};
|
||||
conversation_starters?: string[];
|
||||
access_level?: number;
|
||||
file_ids?: string[];
|
||||
actions?: string[];
|
||||
append_current_datetime?: boolean;
|
||||
}
|
||||
10
packages/data-schemas/src/types/banner.ts
Normal file
10
packages/data-schemas/src/types/banner.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import type { Document } from 'mongoose';
|
||||
|
||||
export interface IBanner extends Document {
|
||||
bannerId: string;
|
||||
message: string;
|
||||
displayFrom: Date;
|
||||
displayTo?: Date;
|
||||
type: 'banner' | 'popup';
|
||||
isPublic: boolean;
|
||||
}
|
||||
27
packages/data-schemas/src/types/file.ts
Normal file
27
packages/data-schemas/src/types/file.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { Document, Types } from 'mongoose';
|
||||
|
||||
export interface IMongoFile extends Omit<Document, 'model'> {
|
||||
user: Types.ObjectId;
|
||||
conversationId?: string;
|
||||
file_id: string;
|
||||
temp_file_id?: string;
|
||||
bytes: number;
|
||||
text?: string;
|
||||
filename: string;
|
||||
filepath: string;
|
||||
object: 'file';
|
||||
embedded?: boolean;
|
||||
type: string;
|
||||
context?: string;
|
||||
usage: number;
|
||||
source: string;
|
||||
model?: string;
|
||||
width?: number;
|
||||
height?: number;
|
||||
metadata?: {
|
||||
fileIdentifier?: string;
|
||||
};
|
||||
expiresAt?: Date;
|
||||
createdAt?: Date;
|
||||
updatedAt?: Date;
|
||||
}
|
||||
|
|
@ -3,4 +3,10 @@ export * from './token';
|
|||
export * from './convo';
|
||||
export * from './session';
|
||||
export * from './balance';
|
||||
export * from './banner';
|
||||
export * from './message';
|
||||
export * from './agent';
|
||||
export * from './role';
|
||||
export * from './action';
|
||||
export * from './assistant';
|
||||
export * from './file';
|
||||
|
|
|
|||
33
packages/data-schemas/src/types/role.ts
Normal file
33
packages/data-schemas/src/types/role.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { Document } from 'mongoose';
|
||||
import { PermissionTypes, Permissions } from 'librechat-data-provider';
|
||||
|
||||
export interface IRole extends Document {
|
||||
name: string;
|
||||
permissions: {
|
||||
[PermissionTypes.BOOKMARKS]?: {
|
||||
[Permissions.USE]?: boolean;
|
||||
};
|
||||
[PermissionTypes.PROMPTS]?: {
|
||||
[Permissions.SHARED_GLOBAL]?: boolean;
|
||||
[Permissions.USE]?: boolean;
|
||||
[Permissions.CREATE]?: boolean;
|
||||
};
|
||||
[PermissionTypes.AGENTS]?: {
|
||||
[Permissions.SHARED_GLOBAL]?: boolean;
|
||||
[Permissions.USE]?: boolean;
|
||||
[Permissions.CREATE]?: boolean;
|
||||
};
|
||||
[PermissionTypes.MULTI_CONVO]?: {
|
||||
[Permissions.USE]?: boolean;
|
||||
};
|
||||
[PermissionTypes.TEMPORARY_CHAT]?: {
|
||||
[Permissions.USE]?: boolean;
|
||||
};
|
||||
[PermissionTypes.RUN_CODE]?: {
|
||||
[Permissions.USE]?: boolean;
|
||||
};
|
||||
[PermissionTypes.WEB_SEARCH]?: {
|
||||
[Permissions.USE]?: boolean;
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue