Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
🏠 fix: Route Standalone File Writes to BYOM Workers (#15675)
Danny Avila3f9285355d73
diff --git a/api/server/services/ToolService.js b/api/server/services/ToolService.jsindex 2e4f770b7a..6b9fa06e5b 100644--- a/api/server/services/ToolService.js+++ b/api/server/services/ToolService.js@@ -49,6 +49,8 @@ const {createGitIdentityProgrammaticBashTool,resolveCodeExecutionContext,resolveCallerCapabilityProjectionSnapshot,+ CREATE_FILE_TOOL_NAME,+ EDIT_FILE_TOOL_NAME,LIST_WORKSPACE_FILES_TOOL_NAME,SEARCH_WORKSPACE_TOOL_NAME,getTransactionsConfig,@@ -2013,7 +2015,7 @@ async function loadToolsForExecution({isWorkspaceListRequested;const isSkillToolRequested = toolNames.includes(AgentConstants.SKILL_TOOL);const isSandboxFileToolRequested = toolNames.some((name) =>- [AgentConstants.READ_FILE, AgentConstants.CREATE_FILE, AgentConstants.EDIT_FILE].includes(name),+ [AgentConstants.READ_FILE, CREATE_FILE_TOOL_NAME, EDIT_FILE_TOOL_NAME].includes(name),);let enabledCapabilities;diff --git a/api/server/services/__tests__/ToolService.spec.js b/api/server/services/__tests__/ToolService.spec.jsindex 098bdcff1a..d0fdf0edf4 100644--- a/api/server/services/__tests__/ToolService.spec.js+++ b/api/server/services/__tests__/ToolService.spec.js@@ -2529,43 +2529,96 @@ describe('ToolService - Action Capability Gating', () => {}});- it('resolves stateful routing for host file tools with the controller conversation ID', async () => {- const capabilities = [- AgentCapabilities.tools,- AgentCapabilities.execute_code,- AgentCapabilities.stateful_code_sessions,- ];- const req = createMockReq(capabilities);- req.body = {};- mockGetEndpointsConfig.mockResolvedValue(createEndpointsConfig(capabilities));- process.env.LIBRECHAT_CODE_BASEURL_STATEFUL = 'http://code-stateful.test/v1';+ it.each(['read_file', 'create_file', 'edit_file'])(+ 'resolves stateful routing for standalone %s with the controller conversation ID',+ async (toolName) => {+ const capabilities = [+ AgentCapabilities.tools,+ AgentCapabilities.execute_code,+ AgentCapabilities.stateful_code_sessions,+ ];+ const req = createMockReq(capabilities);+ req.body = {};+ mockGetEndpointsConfig.mockResolvedValue(createEndpointsConfig(capabilities));+ process.env.LIBRECHAT_CODE_BASEURL_STATEFUL = 'http://code-stateful.test/v1';++ try {+ const result = await loadToolsForExecution({+ req,+ res: {},+ conversationId: 'resolved-api-conversation',+ agent: {+ id: 'stateful-agent',+ tools: [Tools.execute_code],+ stateful_code_sessions: true,+ stateful_code_environment: 'conversation',+ },+ toolNames: [toolName],+ actionsEnabled: false,+ });++ expect(result.configurable.codeExecutionContext.executionProfile).toBe('stateful');+ expect(mockResolveCodeExecutionContext).toHaveBeenLastCalledWith(+ expect.objectContaining({+ statefulSessions: true,+ conversationId: 'resolved-api-conversation',+ }),+ );+ } finally {+ delete process.env.LIBRECHAT_CODE_BASEURL_STATEFUL;+ }+ },+ );++ it.each(['read_file', 'create_file', 'edit_file'])(+ 'keeps standalone %s on the selected attached worker',+ async (toolName) => {+ const capabilities = [+ AgentCapabilities.tools,+ AgentCapabilities.execute_code,+ AgentCapabilities.stateful_code_sessions,+ ];+ const req = createMockReq(capabilities);+ req.config.endpoints.agents.statefulCodeSessions = {+ environments: [+ {+ id: 'personal-machine',+ type: 'attached',+ baseURL: 'https://attached-code.test/v1',+ workerId: 'worker-personal',+ },+ ],+ };+ mockGetEndpointsConfig.mockResolvedValue(createEndpointsConfig(capabilities));+ mockResolveCodeExecutionContext.mockImplementationOnce(+ jest.requireActual('@librechat/api').resolveCodeExecutionContext,+ );- try {const result = await loadToolsForExecution({req,res: {},conversationId: 'resolved-api-conversation',agent: {- id: 'stateful-agent',+ id: 'attached-agent',tools: [Tools.execute_code],stateful_code_sessions: true,- stateful_code_environment: 'conversation',+ code_environment_id: 'personal-machine',},- toolNames: [AgentConstants.READ_FILE],+ toolNames: [toolName],actionsEnabled: false,});- expect(result.configurable.codeExecutionContext.executionProfile).toBe('stateful');- expect(mockResolveCodeExecutionContext).toHaveBeenLastCalledWith(+ expect(result.configurable.codeExecutionContext).toEqual(expect.objectContaining({- statefulSessions: true,- conversationId: 'resolved-api-conversation',+ baseUrl: 'https://attached-code.test/v1',+ executionProfile: 'stateful',+ environmentType: 'attached',+ environmentId: 'personal-machine',+ bridgeWorkerId: 'worker-personal',}),);- } finally {- delete process.env.LIBRECHAT_CODE_BASEURL_STATEFUL;- }- });+ },+ );it('preserves attached routing when workspace search is the only requested tool', async () => {const capabilities = [