Merge branch 'main' into feat/user-groups

This commit is contained in:
Ruben Talstra 2025-03-19 14:36:27 +01:00 committed by GitHub
commit c696b935b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
108 changed files with 7249 additions and 1732 deletions

View file

@ -1,6 +1,6 @@
{
"name": "librechat-data-provider",
"version": "0.7.7",
"version": "0.7.73",
"description": "data services for librechat apps",
"main": "dist/index.js",
"module": "dist/index.es.js",

View file

@ -168,6 +168,8 @@ export enum AgentCapabilities {
artifacts = 'artifacts',
actions = 'actions',
tools = 'tools',
chain = 'chain',
ocr = 'ocr',
}
export const defaultAssistantsVersion = {
@ -233,6 +235,7 @@ export const agentsEndpointSChema = baseEndpointSchema.merge(
/* agents specific */
recursionLimit: z.number().optional(),
disableBuilder: z.boolean().optional(),
maxRecursionLimit: z.number().optional(),
capabilities: z
.array(z.nativeEnum(AgentCapabilities))
.optional()
@ -242,6 +245,8 @@ export const agentsEndpointSChema = baseEndpointSchema.merge(
AgentCapabilities.artifacts,
AgentCapabilities.actions,
AgentCapabilities.tools,
AgentCapabilities.ocr,
AgentCapabilities.chain,
]),
}),
);
@ -534,9 +539,22 @@ export type TStartupConfig = {
bundlerURL?: string;
};
export enum OCRStrategy {
MISTRAL_OCR = 'mistral_ocr',
CUSTOM_OCR = 'custom_ocr',
}
export const ocrSchema = z.object({
mistralModel: z.string().optional(),
apiKey: z.string().optional().default('OCR_API_KEY'),
baseURL: z.string().optional().default('OCR_BASEURL'),
strategy: z.nativeEnum(OCRStrategy).default(OCRStrategy.MISTRAL_OCR),
});
export const configSchema = z.object({
version: z.string(),
cache: z.boolean().default(true),
ocr: ocrSchema.optional(),
secureImageLinks: z.boolean().optional(),
imageOutputType: z.nativeEnum(EImageOutputType).default(EImageOutputType.PNG),
includedTools: z.array(z.string()).optional(),
@ -812,28 +830,29 @@ export const supportsBalanceCheck = {
};
export const visionModels = [
'grok-3',
'grok-2-vision',
'qwen-vl',
'grok-vision',
'gpt-4.5',
'gpt-4o',
'grok-2-vision',
'grok-3',
'gpt-4o-mini',
'o1',
'gpt-4o',
'gpt-4-turbo',
'gpt-4-vision',
'o1',
'gpt-4.5',
'llava',
'llava-13b',
'gemini-pro-vision',
'claude-3',
'gemini-2.0',
'gemini-1.5',
'gemini-exp',
'gemini-1.5',
'gemini-2.0',
'moondream',
'llama3.2-vision',
'llama-3.2-90b-vision',
'llama-3.2-11b-vision',
'llama-3-2-90b-vision',
'llama-3-2-11b-vision',
'llama-3.2-90b-vision',
'llama-3-2-90b-vision',
];
export enum VisionModes {
generative = 'generative',
@ -1175,7 +1194,7 @@ export enum Constants {
/** Key for the app's version. */
VERSION = 'v0.7.7',
/** Key for the Custom Config's version (librechat.yaml). */
CONFIG_VERSION = '1.2.1',
CONFIG_VERSION = '1.2.3',
/** Standard value for the first message's `parentMessageId` value, to indicate no parent exists. */
NO_PARENT = '00000000-0000-0000-0000-000000000000',
/** Standard value for the initial conversationId before a request is sent */

View file

@ -7,6 +7,7 @@ export * from './file-config';
export * from './artifacts';
/* schema helpers */
export * from './parsers';
export * from './ocr';
export * from './zod';
/* custom/dynamic configurations */
export * from './generate';

View file

@ -4,6 +4,7 @@ import { extractEnvVariable } from './utils';
const BaseOptionsSchema = z.object({
iconPath: z.string().optional(),
timeout: z.number().optional(),
initTimeout: z.number().optional(),
});
export const StdioOptionsSchema = BaseOptionsSchema.extend({
@ -85,3 +86,26 @@ export const MCPOptionsSchema = z.union([
]);
export const MCPServersSchema = z.record(z.string(), MCPOptionsSchema);
export type MCPOptions = z.infer<typeof MCPOptionsSchema>;
/**
* Recursively processes an object to replace environment variables in string values
* @param {MCPOptions} obj - The object to process
* @returns {MCPOptions} - The processed object with environment variables replaced
*/
export function processMCPEnv(obj: MCPOptions): MCPOptions {
if (obj === null || obj === undefined) {
return obj;
}
if ('env' in obj && obj.env) {
const processedEnv: Record<string, string> = {};
for (const [key, value] of Object.entries(obj.env)) {
processedEnv[key] = extractEnvVariable(value);
}
obj.env = processedEnv;
}
return obj;
}

View file

@ -0,0 +1,14 @@
import type { TCustomConfig } from '../src/config';
import { OCRStrategy } from '../src/config';
export function loadOCRConfig(config: TCustomConfig['ocr']): TCustomConfig['ocr'] {
const baseURL = config?.baseURL ?? '';
const apiKey = config?.apiKey ?? '';
const mistralModel = config?.mistralModel ?? '';
return {
apiKey,
baseURL,
mistralModel,
strategy: config?.strategy ?? OCRStrategy.MISTRAL_OCR,
};
}

View file

@ -47,6 +47,7 @@ export enum BedrockProviders {
Meta = 'meta',
MistralAI = 'mistral',
StabilityAI = 'stability',
DeepSeek = 'deepseek',
}
export const getModelKey = (endpoint: EModelEndpoint | string, model: string) => {
@ -157,6 +158,7 @@ export const defaultAgentFormValues = {
projectIds: [],
artifacts: '',
isCollaborative: false,
recursion_limit: undefined,
[Tools.execute_code]: false,
[Tools.file_search]: false,
};
@ -1152,7 +1154,6 @@ export const compactAgentsSchema = tConversationSchema
iconURL: true,
greeting: true,
agent_id: true,
resendFiles: true,
instructions: true,
additional_instructions: true,
})

View file

@ -19,6 +19,15 @@ export namespace Agents {
tool_call_ids?: string[];
};
export type AgentUpdate = {
type: ContentTypes.AGENT_UPDATE;
agent_update: {
index: number;
runId: string;
agentId: string;
};
};
export type MessageContentImageUrl = {
type: ContentTypes.IMAGE_URL;
image_url: string | { url: string; detail?: ImageDetail };
@ -26,6 +35,7 @@ export namespace Agents {
export type MessageContentComplex =
| ReasoningContentText
| AgentUpdate
| MessageContentText
| MessageContentImageUrl
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@ -159,12 +169,7 @@ export namespace Agents {
index: number; // #new
stepIndex?: number; // #new
stepDetails: StepDetails;
usage: null | {
// Define usage structure if it's ever non-null
// prompt_tokens: number; // #new
// completion_tokens: number; // #new
// total_tokens: number; // #new
};
usage: null | object;
};
/**
* Represents a run step delta i.e. any changed fields on a run step during

View file

@ -27,6 +27,7 @@ export enum EToolResources {
code_interpreter = 'code_interpreter',
execute_code = 'execute_code',
file_search = 'file_search',
ocr = 'ocr',
}
export type Tool = {
@ -163,7 +164,8 @@ export type AgentModelParameters = {
export interface AgentToolResources {
execute_code?: ExecuteCodeResource;
file_search?: AgentFileSearchResource;
file_search?: AgentFileResource;
ocr?: Omit<AgentFileResource, 'vector_store_ids'>;
}
export interface ExecuteCodeResource {
/**
@ -177,7 +179,7 @@ export interface ExecuteCodeResource {
files?: Array<TFile>;
}
export interface AgentFileSearchResource {
export interface AgentFileResource {
/**
* The ID of the vector store attached to this agent. There
* can be a maximum of 1 vector store attached to the agent.
@ -220,6 +222,7 @@ export type Agent = {
end_after_tools?: boolean;
hide_sequential_outputs?: boolean;
artifacts?: ArtifactModes;
recursion_limit?: number;
};
export type TAgentsMap = Record<string, Agent | undefined>;
@ -234,7 +237,10 @@ export type AgentCreateParams = {
provider: AgentProvider;
model: string | null;
model_parameters: AgentModelParameters;
} & Pick<Agent, 'agent_ids' | 'end_after_tools' | 'hide_sequential_outputs' | 'artifacts'>;
} & Pick<
Agent,
'agent_ids' | 'end_after_tools' | 'hide_sequential_outputs' | 'artifacts' | 'recursion_limit'
>;
export type AgentUpdateParams = {
name?: string | null;
@ -250,7 +256,10 @@ export type AgentUpdateParams = {
projectIds?: string[];
removeProjectIds?: string[];
isCollaborative?: boolean;
} & Pick<Agent, 'agent_ids' | 'end_after_tools' | 'hide_sequential_outputs' | 'artifacts'>;
} & Pick<
Agent,
'agent_ids' | 'end_after_tools' | 'hide_sequential_outputs' | 'artifacts' | 'recursion_limit'
>;
export type AgentListParams = {
limit?: number;
@ -453,6 +462,7 @@ export type TMessageContentParts =
PartMetadata;
}
| { type: ContentTypes.IMAGE_FILE; image_file: ImageFile & PartMetadata }
| Agents.AgentUpdate
| Agents.MessageContentImageUrl;
export type StreamContentData = TMessageContentParts & {

View file

@ -8,6 +8,8 @@ export enum FileSources {
s3 = 's3',
vectordb = 'vectordb',
execute_code = 'execute_code',
mistral_ocr = 'mistral_ocr',
text = 'text',
}
export const checkOpenAIStorage = (source: string) =>

View file

@ -5,6 +5,7 @@ export enum ContentTypes {
TOOL_CALL = 'tool_call',
IMAGE_FILE = 'image_file',
IMAGE_URL = 'image_url',
AGENT_UPDATE = 'agent_update',
ERROR = 'error',
}

View file

@ -1,6 +1,6 @@
{
"name": "@librechat/data-schemas",
"version": "0.0.2",
"version": "0.0.3",
"type": "module",
"description": "Mongoose schemas and models for LibreChat",
"main": "dist/index.cjs",
@ -60,7 +60,7 @@
"access": "public"
},
"dependencies": {
"mongoose": "^8.9.5"
"mongoose": "^8.12.1"
},
"peerDependencies": {
"keyv": "^4.5.4"

View file

@ -13,6 +13,7 @@ export interface IAgent extends Omit<Document, 'model'> {
model_parameters?: Record<string, unknown>;
artifacts?: string;
access_level?: number;
recursion_limit?: number;
tools?: string[];
tool_kwargs?: Array<unknown>;
actions?: string[];
@ -65,6 +66,9 @@ const agentSchema = new Schema<IAgent>(
access_level: {
type: Number,
},
recursion_limit: {
type: Number,
},
tools: {
type: [String],
default: undefined,

View file

@ -8,6 +8,7 @@ export interface IMongoFile extends Document {
file_id: string;
temp_file_id?: string;
bytes: number;
text?: string;
filename: string;
filepath: string;
object: 'file';
@ -72,6 +73,9 @@ const file: Schema<IMongoFile> = new Schema(
type: String,
required: true,
},
text: {
type: String,
},
context: {
type: String,
},

View file

@ -269,7 +269,7 @@ export class MCPConnection extends EventEmitter {
this.transport = this.constructTransport(this.options);
this.setupTransportDebugHandlers();
const connectTimeout = 10000;
const connectTimeout = this.options.initTimeout ?? 10000;
await Promise.race([
this.client.connect(this.transport),
new Promise((_resolve, reject) =>

View file

@ -1,5 +1,5 @@
import { CallToolResultSchema } from '@modelcontextprotocol/sdk/types.js';
import type { JsonSchemaType } from 'librechat-data-provider';
import type { JsonSchemaType, MCPOptions } from 'librechat-data-provider';
import type { Logger } from 'winston';
import type * as t from './types/mcp';
import { formatToolContent } from './parsers';
@ -31,13 +31,17 @@ export class MCPManager {
return MCPManager.instance;
}
public async initializeMCP(mcpServers: t.MCPServers): Promise<void> {
public async initializeMCP(
mcpServers: t.MCPServers,
processMCPEnv?: (obj: MCPOptions) => MCPOptions,
): Promise<void> {
this.logger.info('[MCP] Initializing servers');
const entries = Object.entries(mcpServers);
const initializedServers = new Set();
const connectionResults = await Promise.allSettled(
entries.map(async ([serverName, config], i) => {
entries.map(async ([serverName, _config], i) => {
const config = processMCPEnv ? processMCPEnv(_config) : _config;
const connection = new MCPConnection(serverName, config, this.logger);
connection.on('connectionChange', (state) => {