@devries-cameron20 / composio-1 / commits / 41c4666e9
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

fix(core): allow explicit `RemoteFile.save()` paths without a home directory (#5288)

This PR: - closes https://github.com/ComposioHQ/composio/issues/5272 - lets `RemoteFile.save(path)` write to an explicit path when the home directory cannot be resolved, e.g. an arbitrary-UID container with `HOME` unset - keeps the default destination unchanged: it still requires a home directory, validates the server-provided filename before any download or write, writes exclusively, and numbers collisions - matches the Python SDK, which only reads `Path.home()` when no path is given - builds on the fix by @shenmuegit (commit a1f24e876, kept with original authorship), who could not open the PR because PR creation is restricted to collaborators; the follow-up commit keeps the validated default filename instead of recomputing it and adds `@composio/slim` to the changeset ## Verification - New explicit-path test failed on `next` (`Cannot determine save location: home directory is not available`) and passes with the fix; a second test pins that a default save without a home still rejects before fetching or writing - `RemoteFile.test.ts`: 40 passed; full `@composio/core` suite: 2018 passed, 2 expected failures - `pnpm --filter @composio/core typecheck`, oxlint, prettier, and `SDK_RELEASE_NOTE_BASE=origin/next pnpm validate:changesets` pass --------- Co-authored-by: meolord <shenmuegm@gmail.com>

Alberto Schiabel committed Nov 13, 2026 at 17:04 UTC 41c4666e92debec80af85904d6b3a1d8b751046d
4 files changed +73 -17
.changeset/all-bags-begin.md new
+6
@@ -0,0 +1,6 @@
1 +---
2 +'@composio/core': patch
3 +'@composio/slim': patch
4 +---
5 +
6 +Allow `RemoteFile.save()` to save to an explicit path when the home directory cannot be resolved.
docs/content/reference/sdk-reference/typescript/remote-file.mdx
+1 -1
@@ -64,7 +64,7 @@ async save(path?: string): Promise<string>
64
65 | Name | Type | Description |
66 |------|------|-------------|
67 -| `path?` | `string` | Local path to save the file. If omitted, saves to the Composio temp directory using the filename from the mount path. An existing default destination gets a copy number before its extension. |
67 +| `path?` | `string` | Local path to save the file. An explicit path does not require a home directory. If omitted, saves to the Composio temp directory using the filename from the mount path. An existing default destination gets a copy number before its extension. |
68
69 **Returns**
70
ts/packages/core/src/models/RemoteFile.ts
+22 -16
@@ -175,7 +175,8 @@ export class RemoteFile {
175 * Downloads and saves the file to the local filesystem.
176 * Requires a Node.js runtime with file system support (not available in Cloudflare Workers/Edge).
177 *
178 - * @param path - Local path to save the file. If omitted, saves to the Composio temp directory using the filename from the mount path.
178 + * @param path - Local path to save the file. An explicit path does not require a home directory.
179 + * If omitted, saves to the Composio temp directory using the filename from the mount path.
180 * An existing default destination gets a copy number before its extension.
181 * @returns The absolute path where the file was saved
182 * @throws Error if file system is not supported or the save fails
@@ -189,30 +190,35 @@ export class RemoteFile {
190 );
191 }
192
193 + // An explicit `path` is the caller's own, so it needs no home directory.
194 + if (path != null) {
195 + const content = await this.buffer();
196 + const dir = getParentDir(path);
197 + if (dir && !platform.existsSync(dir)) {
198 + platform.mkdirSync(dir);
199 + }
200 + platform.writeFileSync(path, content);
201 + return path;
202 + }
203 +
204 const homeDir = platform.homedir();
205 if (!homeDir) {
206 throw new Error('Cannot determine save location: home directory is not available');
207 }
208
197 - // An explicit `path` is the caller's own. The default branch builds a path
198 - // out of `mountRelativePath`, a server-controlled response field, so it is
199 - // validated first (SEC-316, mirroring the Python SDK): a value such as `""`,
200 - // `"."` or `"foo/.."` would otherwise make `savePath` its own directory or
201 - // the parent, and fail with a raw `EISDIR` only after `mkdirSync` had run.
209 + // The default path is built from `mountRelativePath`, a server-controlled
210 + // response field, so it is validated first (SEC-316, mirroring the Python
211 + // SDK): a value such as `""`, `"."` or `"foo/.."` would otherwise make
212 + // `savePath` its own directory or the parent, and fail with a raw `EISDIR`
213 + // only after `mkdirSync` had run.
214 const defaultDir = platform.joinPath(homeDir, COMPOSIO_DIR, TEMP_FILES_DIRECTORY_NAME);
203 - const defaultName = path == null ? safeBasename(this.mountRelativePath, 'mount path') : '';
204 - const savePath = path ?? platform.joinPath(defaultDir, defaultName);
215 + const defaultName = safeBasename(this.mountRelativePath, 'mount path');
216 + const savePath = platform.joinPath(defaultDir, defaultName);
217
218 const content = await this.buffer();
219
208 - const dir = path != null ? getParentDir(savePath) : defaultDir;
209 - if (dir && !platform.existsSync(dir)) {
210 - platform.mkdirSync(dir);
211 - }
212 -
213 - if (path != null) {
214 - platform.writeFileSync(savePath, content);
215 - return savePath;
220 + if (!platform.existsSync(defaultDir)) {
221 + platform.mkdirSync(defaultDir);
222 }
223
224 // Server names can equal a digest-tagged name literally. Reserve a new
ts/packages/core/test/models/RemoteFile.test.ts
+44
@@ -284,6 +284,50 @@ describe('RemoteFile', () => {
284 expect(new Uint8Array(written)).toEqual(content);
285 });
286
287 + it('should save to an explicit path without resolving a home directory', async () => {
288 + const { platform } = await import('../../src/platform/node');
289 + const { mkdtempSync, readFileSync, rmSync, rmdirSync } = await import('node:fs');
290 + const { join } = await import('node:path');
291 + const { tmpdir } = await import('node:os');
292 + const directory = mkdtempSync(join(tmpdir(), 'composio-remote-file-explicit-'));
293 + const savePath = join(directory, 'report.pdf');
294 + const content = new Uint8Array([1, 2, 3]);
295 + const homedir = vi.spyOn(platform, 'homedir').mockReturnValue(null);
296 + globalThis.fetch = vi.fn().mockResolvedValue(new Response(content));
297 +
298 + try {
299 + await expect(new RemoteFile(validCamelCaseData).save(savePath)).resolves.toBe(savePath);
300 + expect(new Uint8Array(readFileSync(savePath))).toEqual(content);
301 + expect(homedir).not.toHaveBeenCalled();
302 + } finally {
303 + vi.restoreAllMocks();
304 + rmSync(savePath, { force: true });
305 + rmdirSync(directory);
306 + }
307 + });
308 +
309 + it('should reject a default save without a home directory before downloading or writing', async () => {
310 + const { platform } = await import('../../src/platform/node');
311 + vi.spyOn(platform, 'homedir').mockReturnValue(null);
312 + const mkdir = vi.spyOn(platform, 'mkdirSync');
313 + const write = vi.spyOn(platform, 'writeFileSync');
314 + const writeExclusive = vi.spyOn(platform, 'writeFileExclusiveSync');
315 + const fetch = vi.fn();
316 + globalThis.fetch = fetch;
317 +
318 + try {
319 + await expect(new RemoteFile(validCamelCaseData).save()).rejects.toThrow(
320 + 'Cannot determine save location: home directory is not available'
321 + );
322 + expect(fetch).not.toHaveBeenCalled();
323 + expect(mkdir).not.toHaveBeenCalled();
324 + expect(write).not.toHaveBeenCalled();
325 + expect(writeExclusive).not.toHaveBeenCalled();
326 + } finally {
327 + vi.restoreAllMocks();
328 + }
329 + });
330 +
331 describe('default location', () => {
332 // `save()` without a path derives the filename from `mountRelativePath`,
333 // a server-controlled response field. These cover the SEC-316 guard the