@devries-cameron20 / composio-1 / commits / e547eb016
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(cli): upload local files with their MIME type (#5037)

This PR: - closes #4984 - builds on #5126, which already infers the MIME type of a local file in `composio execute` (`--file` and paths in `-d`) from its extension with the `mime` package; the CLI keeps that one lookup - infers the type the same way in the core SDK's `readFileContent`, from an extension table in `@composio/core`'s `utils/mime.ts` (internal, no new runtime dependency); unknown or missing extensions still fall back to `application/octet-stream` - uses the same extension table in the Python SDK's `composio.utils.mimetypes.guess`, so a local file uploads with the same type from the TypeScript SDK, the Python SDK, and the CLI. The table holds 311 extensions: the values of the `mime` package (which the CLI uses) where it knows the extension, otherwise the value Python's standard `mimetypes` gives (such as `.h5` and `.pyc`), plus `.tgz`. A core test checks the table against `mime`, and a Python test compares `_types` with the TypeScript source - in `composio run`, uploads a `File` under its own name and `type` (it used to upload as `application/octet-stream` under a random prefix, `1bfa14f5-deck.pptx`): the run helper stages it at a generated `file-<id>[.ext]` path and passes `{ name, mimetype }` to the spawned `composio execute` through a per-execution JSON metadata file named by the internal `COMPOSIO_RUN_STAGED_FILES_FILE` variable, so a `File` named `deck` with a PPTX type uploads as PPTX - prefers that declared type, then the name's extension, then `application/octet-stream`; the staged labels only rename an upload, the sensitive-path denylist still runs on the path as given - names a nameless `Blob` `file-<id>.bin` when its subtype is not a plain token, instead of `file-<id>.vnd.openxmlformats-officedocument.presentationml.presentation` ## Context `composio run` reaches the upload through a spawned `composio execute`, and `--data` carries the staged path. The companion writes the original names and types to a per-execution JSON metadata file and passes only its path through `COMPOSIO_RUN_STAGED_FILES_FILE`. This avoids Linux's per-string environment limit for large file batches. The child reads and validates the metadata into a `Map`; unreadable or invalid metadata fails before upload. The metadata file has mode `0600` and is removed after the child completes or fails. Calls without staged files clear any inherited metadata path. The user-facing `--data` contract is unchanged. Files are staged under generated names, not their own, so a script-created `.env.example` or `id_rsa` is not refused by the denylist meant for the user's real files. The variable cannot exempt a path from that check: a `.env` path with a harmless staged label is still refused. Reproduced against a local fake backend that records the presigned-URL request, the S3 PUT (via `HTTP_PROXY`), and the tool input sent to the Dashboard: | | `--file deck.pptx` before | `run`, `File('deck.pptx')` before | `run`, `File('deck')` before | all three after | |---|---|---|---|---| | presign `filename` | `deck.pptx` | `1bfa14f5-deck.pptx` | `<id>-deck` | `deck.pptx` / `deck.pptx` / `deck` | | presign `mimetype` | `application/octet-stream` | `application/octet-stream` | `application/octet-stream` | PPTX | | S3 PUT `Content-Type` | `application/octet-stream` | `application/octet-stream` | `application/octet-stream` | PPTX | | tool input `file.mimetype` | `application/octet-stream` | `application/octet-stream` | `application/octet-stream` | PPTX | PPTX = `application/vnd.openxmlformats-officedocument.presentationml.presentation`. The "before" columns predate #5126. On `next`, `--file deck.pptx` now uploads as PPTX already; the two `run` columns are what this PR still changes. Open questions for the Canva toolkit owner: - The rejection names `parameter file`, and the live schema requires `mimetype` inside `file`. Should the separate `mime_type` argument override `file.mimetype` when validating? Today it does not. - Which MIME values does the validator accept for AI, PSD, and Keynote/Numbers/Pages? This PR sends `application/postscript`, `image/vnd.adobe.photoshop`, and `application/vnd.apple.keynote`/`numbers`/`pages`. An end-to-end import against a real Canva account is still pending. ## Python SDK alignment Python's old table was a legacy list of about 500 extensions, and it disagreed with TypeScript on common files: `.js` (`application/javascript`), `.xml` (`text/xml`), `.ogg` (`video/ogg`), `.wav` (`audio/x-wav`), `.yaml` (`application/x-yaml`), `.bmp`, `.gz`, `.flac`, and `.psd` (`application/octet-stream`). It also had no entry for `.md`, `.key`, `.numbers`, `.pages`, `.odt`/`.ods`/`.odp`, `.epub`, `.avif`, or `.m4a`. The aligned table drops about 190 obsolete entries that neither `mime` nor Python's `mimetypes` recognizes, such as `x-world/x-3dmf` and `www/mime`; those extensions now upload as `application/octet-stream`. ## Review regression verification - After merging `next`: 2,450 CLI tests pass (209 files, 1 skipped), including 214 in the focused upload, run-helper, entry-point, config, and execute suites: a 512-file spawned-child case whose metadata exceeds 128 KiB, metadata cleanup on success and failure, rejection of unreadable or invalid metadata, and one table covering extension-only and staged-label MIME cases. - 1,964 core tests pass (77 files, 2 expected failures), 21 of them in the MIME and `readFileContent` suites. - Root `pnpm typecheck`, CLI Effect diagnostics, `oxlint` over the CLI and core packages, and the CLI boundary and command-test validators pass. - A Linux reproduction with 1,000 labels fails with `E2BIG` when 295,781 bytes are passed in one environment string; a 40-byte metadata-file path succeeds with all labels preserved.

Alberto Schiabel committed Oct 28, 2026 at 11:10 UTC e547eb016c6504efa46756800beaa9a621b9b4e8
20 files changed +1404 -517
.changeset/local-file-upload-mime-type.md new
+7
@@ -0,0 +1,7 @@
1 +---
2 +'@composio/core': patch
3 +---
4 +
5 +Upload local files with the MIME type of their extension
6 +
7 +A file uploaded from a local path used to be sent as `application/octet-stream` whatever it was, so tools that check the file's type, such as Canva's design import, rejected it. The SDK now infers the type from the file name's extension (a `.pptx` uploads as `application/vnd.openxmlformats-officedocument.presentationml.presentation`) and keeps `application/octet-stream` only for missing or unknown extensions. The TypeScript and Python SDKs now use the same extension table, so a file uploads with the same type from either SDK and from the CLI. Files passed as `File` objects and URLs keep the type they carry.
pnpm-lock.yaml
+47 -50
@@ -117,10 +117,11 @@ overrides:
117 ip-address@>=10.0.0 <10.7.1: '>=10.7.1 <11'
118 proxy-addr@>=1.1.0 <2.0.8: '>=2.0.8 <3'
119 '@modelcontextprotocol/sdk@>=1.12.0 <1.31.0': '>=1.31.0 <2'
120 - '@modelcontextprotocol/client@>=2.0.0 <2.3.1': 2.3.1
121 - '@modelcontextprotocol/core@>=2.0.0 <2.3.1': 2.3.1
122 - '@modelcontextprotocol/server@>=2.0.0 <2.3.1': 2.3.1
123 - '@modelcontextprotocol/server-legacy@>=2.0.0 <2.3.1': 2.3.1
120 + '@modelcontextprotocol/client@>=2.0.0 <2.4.0': 2.4.0
121 + '@modelcontextprotocol/core@>=2.0.0 <2.4.0': 2.4.0
122 + '@modelcontextprotocol/node@>=2.0.0 <2.1.2': 2.1.2
123 + '@modelcontextprotocol/server@>=2.0.0 <2.4.0': 2.4.0
124 + '@modelcontextprotocol/server-legacy@>=2.0.0 <2.4.0': 2.4.0
125 undici@>=7.0.0 <7.30.1: '>=7.30.1 <8'
126 body-parser@>=2.0.0 <2.4.0: '>=2.4.0 <3'
127 brace-expansion@<=5.0.10: '>=5.0.11 <6'
@@ -482,7 +483,7 @@ importers:
483 version: 1.53.0(@cfworker/json-schema@4.1.1)(ai@6.0.311(zod@3.25.76))(express@5.3.0)(zod@3.25.76)
484 '@mastra/mcp':
485 specifier: 1.17.2
485 - version: 1.17.2(@cfworker/json-schema@4.1.1)(@mastra/core@1.53.0(@cfworker/json-schema@4.1.1)(ai@6.0.311(zod@3.25.76))(express@5.3.0)(zod@3.25.76))(express@5.3.0)(hono@4.13.13)(zod@3.25.76)
486 + version: 1.17.2(@cfworker/json-schema@4.1.1)(@mastra/core@1.53.0(@cfworker/json-schema@4.1.1)(ai@6.0.311(zod@3.25.76))(express@5.3.0)(zod@3.25.76))(express@5.3.0)(zod@3.25.76)
487 ai:
488 specifier: ^6.0.311
489 version: 6.0.311(zod@3.25.76)
@@ -510,7 +511,7 @@ importers:
511 version: 1.53.0(@cfworker/json-schema@4.1.1)(ai@6.0.311(zod@4.6.7))(express@5.3.0)(zod@4.6.7)
512 '@mastra/mcp':
513 specifier: 1.17.2
513 - version: 1.17.2(@cfworker/json-schema@4.1.1)(@mastra/core@1.53.0(@cfworker/json-schema@4.1.1)(ai@6.0.311(zod@4.6.7))(express@5.3.0)(zod@4.6.7))(express@5.3.0)(hono@4.13.13)(zod@4.6.7)
514 + version: 1.17.2(@cfworker/json-schema@4.1.1)(@mastra/core@1.53.0(@cfworker/json-schema@4.1.1)(ai@6.0.311(zod@4.6.7))(express@5.3.0)(zod@4.6.7))(express@5.3.0)(zod@4.6.7)
515 ai:
516 specifier: ^6.0.311
517 version: 6.0.311(zod@4.6.7)
@@ -620,7 +621,7 @@ importers:
621 version: 1.53.0(@cfworker/json-schema@4.1.1)(ai@6.0.311(zod@4.6.7))(express@5.3.0)(zod@4.6.7)
622 '@mastra/mcp':
623 specifier: 1.17.2
623 - version: 1.17.2(@cfworker/json-schema@4.1.1)(@mastra/core@1.53.0(@cfworker/json-schema@4.1.1)(ai@6.0.311(zod@4.6.7))(express@5.3.0)(zod@4.6.7))(express@5.3.0)(hono@4.13.13)(zod@4.6.7)
624 + version: 1.17.2(@cfworker/json-schema@4.1.1)(@mastra/core@1.53.0(@cfworker/json-schema@4.1.1)(ai@6.0.311(zod@4.6.7))(express@5.3.0)(zod@4.6.7))(express@5.3.0)(zod@4.6.7)
625 ai:
626 specifier: ^6.0.311
627 version: 6.0.311(zod@4.6.7)
@@ -1395,6 +1396,9 @@ importers:
1396 hono:
1397 specifier: 'catalog:'
1398 version: 4.13.13
1399 + mime:
1400 + specifier: ^4.1.1
1401 + version: 4.1.1
1402 tsdown:
1403 specifier: 'catalog:'
1404 version: 0.23.1(@arethetypeswrong/core@0.18.5)(@typescript/typescript6@6.0.2)(publint@0.3.25)(tsx@4.23.15)(unrun@0.2.27(@emnapi/core@1.11.2)(@emnapi/runtime@1.11.3))
@@ -3264,12 +3268,12 @@ packages:
3268 peerDependencies:
3269 zod: ^3.25.0 || ^4.0.0
3270
3267 - '@modelcontextprotocol/client@2.3.1':
3268 - resolution: {integrity: sha512-mIGZXpHsjnZ6lD+gD/WCMpR5k8yVQQ8nNFH1N0Srf7AvnwTUMYD6pvTY8ng2+He5FfV7YMZLmrjL7cLa/cc3dQ==}
3271 + '@modelcontextprotocol/client@2.4.0':
3272 + resolution: {integrity: sha512-LgrD2OphHuG12vfKFKz6SOnq7bKHQmhGJIAYdD+MZBn2npHEyry6uD8zvktodtl5CQM85MO0anUyD9JwmUmxww==}
3273 engines: {node: '>=20'}
3274
3271 - '@modelcontextprotocol/core@2.3.1':
3272 - resolution: {integrity: sha512-laVmIhPGpWi7rG9q+0UigblRN0Hws/Yjlb6qLFtVqryXVLkc4h+yN8z731POD2LnAGQlFe7/tXhUm7Bi0YB91g==}
3275 + '@modelcontextprotocol/core@2.4.0':
3276 + resolution: {integrity: sha512-z8QBKqdfXLPzkLQuG4xp8hrVEMm1PZ1IgxMN2sMbJiFiAKOWXnAzogXn2W4aqIBlP1ea6U5yiqVquvUNM1Cj6Q==}
3277 engines: {node: '>=20'}
3278
3279 '@modelcontextprotocol/ext-apps@1.7.5':
@@ -3286,15 +3290,11 @@ packages:
3290 react-dom:
3291 optional: true
3292
3289 - '@modelcontextprotocol/node@2.0.0':
3290 - resolution: {integrity: sha512-Y4hAC2XdGDUdDOCbLDOCA4+aL3NUldjsOWlDL/YwpAxrPhRm1xHd7lZ+mLacvZ9t3PaH28wgNoaLQGrIk1P2pg==}
3293 + '@modelcontextprotocol/node@2.1.2':
3294 + resolution: {integrity: sha512-IIcIqBpr6NCQQs5DgJTgvbSOAw+3iaR/uquqg+e0nXCdudfjPg/80x0TseUnQx14AUAtE4fsJCEpJKPyb6WPVA==}
3295 engines: {node: '>=20'}
3296 peerDependencies:
3293 - '@modelcontextprotocol/server': 2.3.1
3294 - hono: ^4.11.4
3295 - peerDependenciesMeta:
3296 - hono:
3297 - optional: true
3297 + '@modelcontextprotocol/server': ^2.4.0
3298
3299 '@modelcontextprotocol/sdk@1.32.0':
3300 resolution: {integrity: sha512-8BviX/hK4Gd2eL1KdTwm0gfl4d3wdoErW0Jd00h6nomUAtk6IJk5vwQJc6kfWtJTzN5OEV/lgIiJKI8fiDGAlA==}
@@ -3316,8 +3316,8 @@ packages:
3316 '@cfworker/json-schema':
3317 optional: true
3318
3319 - '@modelcontextprotocol/server-legacy@2.3.1':
3320 - resolution: {integrity: sha512-+cuB+hl7s8DiFXIt13le3cD2wZPOeDYwlycAkRMPljqqNbOLekGRiyslx8WXfqaXSCveS1eDD8/B8rmxz9BZFQ==}
3319 + '@modelcontextprotocol/server-legacy@2.4.0':
3320 + resolution: {integrity: sha512-xWq1YTZiLZltEXp/NJhsW7IvpuowrapEFuriAz3a86CIwMnt7+r8EaG/7xtWi7aqLzhtplOJJffUE5YIcUT+Aw==}
3321 engines: {node: '>=20'}
3322 deprecated: This package is a frozen copy of v1's SSE transport and OAuth Authorization Server helpers for migration purposes only. Use StreamableHTTP from @modelcontextprotocol/server and a dedicated OAuth server in production. Will not receive new features.
3323 peerDependencies:
@@ -3326,8 +3326,8 @@ packages:
3326 express:
3327 optional: true
3328
3329 - '@modelcontextprotocol/server@2.3.1':
3330 - resolution: {integrity: sha512-e59MfWuSssj6DoQ96JCTqdW1AXT5/XtnTl0WWd6MU1Ka434fFUGGosCLJbGNySDhHGvxQWoRWK137FXYFkYNWw==}
3329 + '@modelcontextprotocol/server@2.4.0':
3330 + resolution: {integrity: sha512-rgR9yxSaAJ+bcsi/XroT/S2AfPiIWloXAnrdfYSCms9ivVju0ishu/wW0J21Ho6+ZOR1r7RyeRbjiRuF87ix5Q==}
3331 engines: {node: '>=20'}
3332
3333 '@napi-rs/lzma-linux-x64-gnu@1.5.1':
@@ -8210,8 +8210,8 @@ snapshots:
8210 dependencies:
8211 '@langchain/core': 1.2.19(@opentelemetry/api@1.10.0)(openai@7.39.0(@aws-sdk/credential-provider-node@3.972.87)(@smithy/signature-v4@5.7.4)(undici@6.29.1)(ws@8.22.0)(zod@4.6.7))(ws@8.22.0)
8212 '@langchain/langgraph': 1.5.1(@langchain/core@1.2.19(@opentelemetry/api@1.10.0)(openai@7.39.0(@aws-sdk/credential-provider-node@3.972.87)(@smithy/signature-v4@5.7.4)(undici@6.29.1)(ws@8.22.0)(zod@4.6.7))(ws@8.22.0))(zod@4.6.7)
8213 - '@modelcontextprotocol/client': 2.3.1
8214 - '@modelcontextprotocol/core': 2.3.1
8213 + '@modelcontextprotocol/client': 2.4.0
8214 + '@modelcontextprotocol/core': 2.4.0
8215 zod: 4.6.7
8216
8217 '@langchain/openai@1.6.2(@aws-sdk/credential-provider-node@3.972.87)(@langchain/core@1.2.19(@opentelemetry/api@1.10.0)(openai@7.39.0(@aws-sdk/credential-provider-node@3.972.87)(@smithy/signature-v4@5.7.4)(undici@6.29.1)(ws@8.22.0)(zod@4.6.7))(ws@8.22.0))(@smithy/signature-v4@5.7.4)(undici@6.29.1)(ws@8.22.0)':
@@ -8442,43 +8442,41 @@ snapshots:
8442 - supports-color
8443 - utf-8-validate
8444
8445 - '@mastra/mcp@1.17.2(@cfworker/json-schema@4.1.1)(@mastra/core@1.53.0(@cfworker/json-schema@4.1.1)(ai@6.0.311(zod@3.25.76))(express@5.3.0)(zod@3.25.76))(express@5.3.0)(hono@4.13.13)(zod@3.25.76)':
8445 + '@mastra/mcp@1.17.2(@cfworker/json-schema@4.1.1)(@mastra/core@1.53.0(@cfworker/json-schema@4.1.1)(ai@6.0.311(zod@3.25.76))(express@5.3.0)(zod@3.25.76))(express@5.3.0)(zod@3.25.76)':
8446 dependencies:
8447 '@mastra/core': 1.53.0(@cfworker/json-schema@4.1.1)(ai@6.0.311(zod@3.25.76))(express@5.3.0)(zod@3.25.76)
8448 - '@modelcontextprotocol/client': 2.3.1
8449 - '@modelcontextprotocol/core': 2.3.1
8448 + '@modelcontextprotocol/client': 2.4.0
8449 + '@modelcontextprotocol/core': 2.4.0
8450 '@modelcontextprotocol/ext-apps': 1.7.5(@modelcontextprotocol/sdk@1.32.1(@cfworker/json-schema@4.1.1)(zod@3.25.76))(zod@3.25.76)
8451 - '@modelcontextprotocol/node': 2.0.0(@modelcontextprotocol/server@2.3.1)(hono@4.13.13)
8451 + '@modelcontextprotocol/node': 2.1.2(@modelcontextprotocol/server@2.4.0)
8452 '@modelcontextprotocol/sdk': 1.32.1(@cfworker/json-schema@4.1.1)(zod@3.25.76)
8453 - '@modelcontextprotocol/server': 2.3.1
8454 - '@modelcontextprotocol/server-legacy': 2.3.1(express@5.3.0)
8453 + '@modelcontextprotocol/server': 2.4.0
8454 + '@modelcontextprotocol/server-legacy': 2.4.0(express@5.3.0)
8455 exit-hook: 5.1.0
8456 fast-deep-equal: 3.1.3
8457 transitivePeerDependencies:
8458 - '@cfworker/json-schema'
8459 - express
8460 - - hono
8460 - react
8461 - react-dom
8462 - supports-color
8463 - zod
8464
8466 - '@mastra/mcp@1.17.2(@cfworker/json-schema@4.1.1)(@mastra/core@1.53.0(@cfworker/json-schema@4.1.1)(ai@6.0.311(zod@4.6.7))(express@5.3.0)(zod@4.6.7))(express@5.3.0)(hono@4.13.13)(zod@4.6.7)':
8465 + '@mastra/mcp@1.17.2(@cfworker/json-schema@4.1.1)(@mastra/core@1.53.0(@cfworker/json-schema@4.1.1)(ai@6.0.311(zod@4.6.7))(express@5.3.0)(zod@4.6.7))(express@5.3.0)(zod@4.6.7)':
8466 dependencies:
8467 '@mastra/core': 1.53.0(@cfworker/json-schema@4.1.1)(ai@6.0.311(zod@4.6.7))(express@5.3.0)(zod@4.6.7)
8469 - '@modelcontextprotocol/client': 2.3.1
8470 - '@modelcontextprotocol/core': 2.3.1
8468 + '@modelcontextprotocol/client': 2.4.0
8469 + '@modelcontextprotocol/core': 2.4.0
8470 '@modelcontextprotocol/ext-apps': 1.7.5(@modelcontextprotocol/sdk@1.32.1(@cfworker/json-schema@4.1.1)(zod@4.6.7))(zod@4.6.7)
8472 - '@modelcontextprotocol/node': 2.0.0(@modelcontextprotocol/server@2.3.1)(hono@4.13.13)
8471 + '@modelcontextprotocol/node': 2.1.2(@modelcontextprotocol/server@2.4.0)
8472 '@modelcontextprotocol/sdk': 1.32.1(@cfworker/json-schema@4.1.1)(zod@4.6.7)
8474 - '@modelcontextprotocol/server': 2.3.1
8475 - '@modelcontextprotocol/server-legacy': 2.3.1(express@5.3.0)
8473 + '@modelcontextprotocol/server': 2.4.0
8474 + '@modelcontextprotocol/server-legacy': 2.4.0(express@5.3.0)
8475 exit-hook: 5.1.0
8476 fast-deep-equal: 3.1.3
8477 transitivePeerDependencies:
8478 - '@cfworker/json-schema'
8479 - express
8481 - - hono
8480 - react
8481 - react-dom
8482 - supports-color
@@ -8506,17 +8504,17 @@ snapshots:
8504 zod-from-json-schema-v3: zod-from-json-schema@0.0.5
8505 zod-to-json-schema: 3.25.2(zod@4.6.7)
8506
8509 - '@modelcontextprotocol/client@2.3.1':
8507 + '@modelcontextprotocol/client@2.4.0':
8508 dependencies:
8511 - '@modelcontextprotocol/core': 2.3.1
8509 + '@modelcontextprotocol/core': 2.4.0
8510 cross-spawn: 7.0.6
8511 eventsource: 3.0.7
8512 eventsource-parser: 3.1.1
8515 - jose: 6.2.12
8513 + jose: 6.2.13
8514 pkce-challenge: 5.0.1
8515 zod: 4.6.7
8516
8519 - '@modelcontextprotocol/core@2.3.1':
8517 + '@modelcontextprotocol/core@2.4.0':
8518 dependencies:
8519 zod: 4.6.7
8520
@@ -8532,11 +8530,10 @@ snapshots:
8530 '@standard-schema/spec': 1.1.0
8531 zod: 4.6.7
8532
8535 - '@modelcontextprotocol/node@2.0.0(@modelcontextprotocol/server@2.3.1)(hono@4.13.13)':
8533 + '@modelcontextprotocol/node@2.1.2(@modelcontextprotocol/server@2.4.0)':
8534 dependencies:
8535 '@hono/node-server': 2.1.5(hono@4.13.13)
8538 - '@modelcontextprotocol/server': 2.3.1
8539 - optionalDependencies:
8536 + '@modelcontextprotocol/server': 2.4.0
8537 hono: 4.13.13
8538
8539 '@modelcontextprotocol/sdk@1.32.0(@cfworker/json-schema@4.1.1)(zod@3.25.76)':
@@ -8635,9 +8632,9 @@ snapshots:
8632 transitivePeerDependencies:
8633 - supports-color
8634
8638 - '@modelcontextprotocol/server-legacy@2.3.1(express@5.3.0)':
8635 + '@modelcontextprotocol/server-legacy@2.4.0(express@5.3.0)':
8636 dependencies:
8640 - '@modelcontextprotocol/core': 2.3.1
8637 + '@modelcontextprotocol/core': 2.4.0
8638 content-type: 1.0.5
8639 cors: 2.8.6
8640 express-rate-limit: 8.7.1(express@5.3.0)
@@ -8649,9 +8646,9 @@ snapshots:
8646 transitivePeerDependencies:
8647 - supports-color
8648
8652 - '@modelcontextprotocol/server@2.3.1':
8649 + '@modelcontextprotocol/server@2.4.0':
8650 dependencies:
8654 - '@modelcontextprotocol/core': 2.3.1
8651 + '@modelcontextprotocol/core': 2.4.0
8652 zod: 4.6.7
8653
8654 '@napi-rs/lzma-linux-x64-gnu@1.5.1':
@@ -8670,7 +8667,7 @@ snapshots:
8667 debug: 4.4.3(supports-color@10.2.2)
8668 openai: 7.39.0(@aws-sdk/credential-provider-node@3.972.87)(@smithy/signature-v4@5.7.4)(undici@6.29.1)(ws@8.22.0)(zod@4.6.7)
8669 optionalDependencies:
8673 - '@modelcontextprotocol/client': 2.3.1
8670 + '@modelcontextprotocol/client': 2.4.0
8671 zod: 4.6.7
8672 transitivePeerDependencies:
8673 - '@aws-sdk/credential-provider-node'
pnpm-workspace.yaml
+9 -7
@@ -153,13 +153,15 @@ overrides:
153 # temporary: @mastra/mcp@1.17.2 (held back above) exact-pins the whole 2.x
154 # family at 2.0.0. GHSA-6qxp-vccf-f47h is patched in @modelcontextprotocol/client
155 # 2.2.0; GHSA-jm63-cq47-j5jp and GHSA-46jr-4wx8-v453 in
156 - # @modelcontextprotocol/server 2.3.0. Each package exact-pins its matching
157 - # core, so the siblings move together to keep a single core instance. Drop
158 - # with the @mastra/mcp override.
159 - '@modelcontextprotocol/client@>=2.0.0 <2.3.1': 2.3.1
160 - '@modelcontextprotocol/core@>=2.0.0 <2.3.1': 2.3.1
161 - '@modelcontextprotocol/server@>=2.0.0 <2.3.1': 2.3.1
162 - '@modelcontextprotocol/server-legacy@>=2.0.0 <2.3.1': 2.3.1
156 + # @modelcontextprotocol/server 2.3.0; GHSA-f897-62hf-6gxq in
157 + # @modelcontextprotocol/node 2.1.0, whose 2.1.2 needs server ^2.4.0. Each
158 + # package exact-pins its matching core, so the siblings move together to keep
159 + # a single core instance. Drop with the @mastra/mcp override.
160 + '@modelcontextprotocol/client@>=2.0.0 <2.4.0': 2.4.0
161 + '@modelcontextprotocol/core@>=2.0.0 <2.4.0': 2.4.0
162 + '@modelcontextprotocol/node@>=2.0.0 <2.1.2': 2.1.2
163 + '@modelcontextprotocol/server@>=2.0.0 <2.4.0': 2.4.0
164 + '@modelcontextprotocol/server-legacy@>=2.0.0 <2.4.0': 2.4.0
165 # temporary: GHSA-4cwx-7wf7-3272, then GHSA-xjj6-f33q-929c raised the patched
166 # floor to 7.30.1. @ai-sdk/provider-utils accepts the patched 7.x line. Drop
167 # when its lockfile resolution is >=7.30.1 without an override.
python/composio/utils/mimetypes.py
+151 -334
@@ -2,507 +2,324 @@ import typing as t
2 from pathlib import Path
3
4 _default = "application/octet-stream"
5 +# Extension (lowercase, with leading dot) -> MIME type. Mirrors
6 +# `MIME_TYPES_BY_EXTENSION` in the TypeScript SDK
7 +# (`ts/packages/core/src/utils/mime.ts`), whose values come from the `mime` npm
8 +# package; keep the two identical.
9 _types = {
6 - ".3dm": "x-world/x-3dmf",
7 - ".3dmf": "x-world/x-3dmf",
10 + ".3g2": "video/3gpp2",
11 + ".3gp": "video/3gpp",
12 + ".3gpp": "video/3gpp",
13 ".7z": "application/x-7z-compressed",
9 - ".a": "application/octet-stream",
14 ".aab": "application/x-authorware-bin",
15 + ".aac": "audio/aac",
16 ".aam": "application/x-authorware-map",
17 ".aas": "application/x-authorware-seg",
13 - ".abc": "text/vnd.abc",
14 - ".acgi": "text/html",
15 - ".afl": "video/animaflex",
18 + ".adts": "audio/aac",
19 ".ai": "application/postscript",
20 ".aif": "audio/x-aiff",
21 ".aifc": "audio/x-aiff",
22 ".aiff": "audio/x-aiff",
20 - ".aim": "application/x-aim",
21 - ".aip": "text/x-audiosoft-intra",
22 - ".ani": "application/x-navi-animation",
23 - ".aos": "application/x-nokia-9000-communicator-add-on-software",
24 - ".aps": "application/mime",
25 - ".arc": "application/octet-stream",
26 - ".arj": "application/octet-stream",
27 - ".art": "image/x-jg",
23 + ".arc": "application/x-freearc",
24 + ".arj": "application/x-arj",
25 ".asf": "video/x-ms-asf",
26 ".asm": "text/x-asm",
30 - ".asp": "text/asp",
31 - ".asx": "video/x-ms-asf-plugin",
27 + ".asx": "video/x-ms-asf",
28 ".au": "audio/basic",
29 ".avi": "video/x-msvideo",
34 - ".avs": "video/avs-video",
30 + ".avif": "image/avif",
31 + ".bat": "application/x-msdownload",
32 ".bcpio": "application/x-bcpio",
36 - ".bin": "application/octet-stream",
37 - ".bm": "image/bmp",
38 - ".bmp": "image/x-ms-bmp",
39 - ".boo": "application/book",
40 - ".book": "application/book",
33 + ".bmp": "image/bmp",
34 + ".book": "application/vnd.framemaker",
35 ".boz": "application/x-bzip2",
42 - ".bsh": "application/x-bsh",
36 ".bz": "application/x-bzip",
37 ".bz2": "application/x-bzip2",
45 - ".c": "text/plain",
46 - ".c+": "text/plain",
38 + ".c": "text/x-c",
39 ".cat": "application/vnd.ms-pki.seccat",
40 ".cc": "text/x-c",
49 - ".ccad": "application/clariscad",
41 ".cco": "application/x-cocoa",
42 ".cdf": "application/x-netcdf",
52 - ".cer": "application/x-x509-ca-cert",
53 - ".cha": "application/x-chat",
43 + ".cer": "application/pkix-cert",
44 ".chat": "application/x-chat",
55 - ".class": "application/x-java-class",
56 - ".com": "text/plain",
45 + ".class": "application/java-vm",
46 + ".com": "application/x-msdownload",
47 ".conf": "text/plain",
48 ".cpio": "application/x-cpio",
49 ".cpp": "text/x-c",
60 - ".cpt": "application/x-cpt",
50 + ".cpt": "application/mac-compactpro",
51 ".crl": "application/pkix-crl",
62 - ".crt": "application/x-x509-user-cert",
52 + ".crt": "application/x-x509-ca-cert",
53 ".csh": "application/x-csh",
54 ".css": "text/css",
55 ".csv": "text/csv",
66 - ".cxx": "text/plain",
56 + ".cxx": "text/x-c",
57 ".dcr": "application/x-director",
68 - ".deepv": "application/x-deepv",
58 ".def": "text/plain",
59 ".der": "application/x-x509-ca-cert",
71 - ".dif": "video/x-dv",
60 ".dir": "application/x-director",
73 - ".dl": "video/x-dl",
61 ".doc": "application/msword",
62 ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
63 ".dot": "application/msword",
77 - ".dp": "application/commonground",
78 - ".drw": "application/drafting",
79 - ".dump": "application/octet-stream",
80 - ".dv": "video/x-dv",
64 + ".dp": "application/vnd.osgi.dp",
65 ".dvi": "application/x-dvi",
66 ".dwf": "model/vnd.dwf",
83 - ".dwg": "image/x-dwg",
84 - ".dxf": "image/x-dwg",
67 + ".dwg": "image/vnd.dwg",
68 + ".dxf": "image/vnd.dxf",
69 ".dxr": "application/x-director",
86 - ".el": "text/x-script.elisp",
87 - ".elc": "application/x-elc",
88 - ".env": "application/x-envoy",
70 + ".eml": "message/rfc822",
71 ".eot": "application/vnd.ms-fontobject",
72 ".eps": "application/postscript",
91 - ".es": "application/x-esrehber",
73 + ".epub": "application/epub+zip",
74 ".etx": "text/x-setext",
75 ".evy": "application/x-envoy",
94 - ".exe": "application/octet-stream",
76 ".f": "text/x-fortran",
77 ".f77": "text/x-fortran",
78 ".f90": "text/x-fortran",
98 - ".fdf": "application/vnd.fdf",
99 - ".fif": "image/fif",
100 - ".flac": "audio/flac",
79 + ".fdf": "application/fdf",
80 + ".flac": "audio/x-flac",
81 ".fli": "video/x-fli",
102 - ".flo": "image/florian",
82 + ".flo": "application/vnd.micrografx.flo",
83 ".flx": "text/vnd.fmi.flexstor",
104 - ".fmf": "video/x-atomic3d-feature",
84 ".for": "text/x-fortran",
106 - ".fpx": "image/vnd.net-fpx",
107 - ".frl": "application/freeloader",
108 - ".funk": "audio/make",
109 - ".g": "text/plain",
85 + ".fpx": "image/vnd.fpx",
86 ".g3": "image/g3fax",
87 ".gif": "image/gif",
112 - ".gl": "video/x-gl",
113 - ".gsd": "audio/x-gsm",
114 - ".gsm": "audio/x-gsm",
115 - ".gsp": "application/x-gsp",
116 - ".gss": "application/x-gss",
88 ".gtar": "application/x-gtar",
118 - ".gz": "application/x-gzip",
119 - ".gzip": "multipart/x-gzip",
120 - ".h": "text/plain",
89 + ".gz": "application/gzip",
90 + ".h": "text/x-c",
91 ".hdf": "application/x-hdf",
122 - ".help": "application/x-helpfile",
123 - ".hgl": "application/vnd.hp-hpgl",
124 - ".hh": "text/x-h",
125 - ".hlb": "text/x-script",
126 - ".hlp": "application/x-winhelp",
127 - ".hpg": "application/vnd.hp-hpgl",
92 + ".heic": "image/heic",
93 + ".heif": "image/heif",
94 + ".hh": "text/x-c",
95 + ".hlp": "application/winhlp",
96 ".hpgl": "application/vnd.hp-hpgl",
129 - ".hqx": "application/x-mac-binhex40",
130 - ".hta": "application/hta",
97 + ".hqx": "application/mac-binhex40",
98 ".htc": "text/x-component",
99 ".htm": "text/html",
100 ".html": "text/html",
134 - ".htmls": "text/html",
135 - ".htt": "text/webviewhtml",
136 - ".htx": "text/html",
101 ".ice": "x-conference/x-cooltalk",
102 ".ico": "image/vnd.microsoft.icon",
103 ".ics": "text/calendar",
140 - ".idc": "text/plain",
104 ".ief": "image/ief",
142 - ".iefs": "image/ief",
105 ".iges": "model/iges",
106 ".igs": "model/iges",
145 - ".ima": "application/x-ima",
146 - ".imap": "application/x-httpd-imap",
147 - ".inf": "application/inf",
148 - ".ins": "application/x-internett-signup",
149 - ".ip": "application/x-ip2",
150 - ".isu": "video/x-isvideo",
151 - ".it": "audio/it",
152 - ".iv": "application/x-inventor",
153 - ".ivr": "i-world/i-vrml",
154 - ".ivy": "application/x-livescreen",
155 - ".jam": "audio/x-jam",
156 - ".jav": "text/x-java-source",
107 + ".jam": "application/vnd.jam",
108 ".java": "text/x-java-source",
158 - ".jcm": "application/x-java-commerce",
109 ".jfif": "image/pjpeg",
160 - ".jfif-bnl": "image/jpeg",
110 ".jpe": "image/jpeg",
111 ".jpeg": "image/jpeg",
112 ".jpg": "image/jpeg",
164 - ".jps": "image/x-jps",
165 - ".js": "application/javascript",
113 + ".js": "text/javascript",
114 ".json": "application/json",
167 - ".jut": "image/jutvision",
168 - ".kar": "music/x-karaoke",
169 - ".ksh": "text/plain",
170 - ".la": "audio/x-nspaudio",
171 - ".lam": "audio/x-liveaudio",
115 + ".kar": "audio/midi",
116 + ".key": "application/vnd.apple.keynote",
117 ".latex": "application/x-latex",
173 - ".lha": "application/x-lha",
174 - ".lhx": "application/octet-stream",
118 + ".lha": "application/x-lzh-compressed",
119 ".list": "text/plain",
176 - ".lma": "audio/x-nspaudio",
120 ".log": "text/plain",
178 - ".lsp": "text/x-script.lisp",
179 - ".lst": "text/plain",
180 - ".lsx": "text/x-la-asf",
181 - ".ltx": "application/x-latex",
182 - ".lzh": "application/x-lzh",
183 - ".lzx": "application/x-lzx",
184 - ".m": "text/x-m",
121 + ".lzh": "application/x-lzh-compressed",
122 ".m1v": "video/mpeg",
123 ".m2a": "audio/mpeg",
124 ".m2v": "video/mpeg",
188 - ".m3u": "application/vnd.apple.mpegurl",
189 - ".man": "application/x-troff-man",
190 - ".map": "application/x-navimap",
191 - ".mar": "text/plain",
192 - ".mbd": "application/mbedlet",
193 - ".mc": "application/x-magic-cap-package-1.0",
194 - ".mcd": "application/x-mathcad",
195 - ".mcf": "text/mcf",
196 - ".mcp": "application/netmc",
197 - ".me": "application/x-troff-me",
125 + ".m3u": "audio/x-mpegurl",
126 + ".m3u8": "application/vnd.apple.mpegurl",
127 + ".m4a": "audio/mp4",
128 + ".man": "text/troff",
129 + ".map": "application/json",
130 + ".mcd": "application/vnd.mcd",
131 + ".md": "text/markdown",
132 + ".me": "text/troff",
133 ".mht": "message/rfc822",
134 ".mhtml": "message/rfc822",
135 ".mid": "audio/midi",
136 ".midi": "audio/midi",
202 - ".mif": "application/x-mif",
203 - ".mime": "www/mime",
204 - ".mjf": "audio/x-vnd.audioexplosion.mjuicemediafile",
205 - ".mjpg": "video/x-motion-jpeg",
137 + ".mif": "application/vnd.mif",
138 + ".mime": "message/rfc822",
139 + ".mjs": "text/javascript",
140 ".mka": "audio/x-matroska",
141 ".mkv": "video/x-matroska",
208 - ".mm": "application/x-meme",
209 - ".mme": "application/base64",
210 - ".mod": "audio/x-mod",
211 - ".moov": "video/quicktime",
142 ".mov": "video/quicktime",
143 ".movie": "video/x-sgi-movie",
144 ".mp2": "audio/mpeg",
145 ".mp3": "audio/mpeg",
146 ".mp4": "video/mp4",
217 - ".mpa": "video/mpeg",
218 - ".mpc": "application/x-project",
147 + ".mpc": "application/vnd.mophun.certificate",
148 ".mpe": "video/mpeg",
149 ".mpeg": "video/mpeg",
150 ".mpg": "video/mpeg",
151 ".mpga": "audio/mpeg",
223 - ".mpp": "application/vnd.ms-project",
224 - ".mpt": "application/x-project",
225 - ".mpv": "application/x-project",
226 - ".mpx": "application/x-project",
152 + ".mpp": "application/dash-patch+xml",
153 + ".mpt": "application/vnd.ms-project",
154 ".mrc": "application/marc",
228 - ".ms": "application/x-troff-ms",
229 - ".mv": "video/x-sgi-movie",
230 - ".my": "audio/make",
231 - ".mzz": "application/x-vnd.audioexplosion.mzz",
232 - ".nap": "image/naplps",
233 - ".naplps": "image/naplps",
155 + ".ms": "text/troff",
156 ".nc": "application/x-netcdf",
235 - ".ncm": "application/vnd.nokia.configuration-message",
236 - ".nif": "image/x-niff",
237 - ".niff": "image/x-niff",
238 - ".nix": "application/x-mix-transfer",
157 ".nsc": "application/x-conference",
240 - ".nvd": "application/x-navidoc",
241 - ".o": "application/octet-stream",
158 + ".numbers": "application/vnd.apple.numbers",
159 + ".obj": "model/obj",
160 ".oda": "application/oda",
243 - ".ogg": "video/ogg",
244 - ".omc": "application/x-omc",
245 - ".omcd": "application/x-omcdatamaker",
246 - ".omcr": "application/x-omcregerator",
161 + ".odg": "application/vnd.oasis.opendocument.graphics",
162 + ".odp": "application/vnd.oasis.opendocument.presentation",
163 + ".ods": "application/vnd.oasis.opendocument.spreadsheet",
164 + ".odt": "application/vnd.oasis.opendocument.text",
165 + ".ogg": "audio/ogg",
166 + ".opus": "audio/ogg",
167 ".otf": "font/otf",
168 ".p": "text/x-pascal",
249 - ".p10": "application/x-pkcs10",
169 + ".p10": "application/pkcs10",
170 ".p12": "application/x-pkcs12",
251 - ".p7a": "application/x-pkcs7-signature",
171 ".p7c": "application/pkcs7-mime",
253 - ".p7m": "application/x-pkcs7-mime",
172 + ".p7m": "application/pkcs7-mime",
173 ".p7r": "application/x-pkcs7-certreqresp",
174 ".p7s": "application/pkcs7-signature",
256 - ".part": "application/pro_eng",
257 - ".pas": "text/pascal",
175 + ".pages": "application/vnd.apple.pages",
176 + ".pas": "text/x-pascal",
177 ".pbm": "image/x-portable-bitmap",
259 - ".pcl": "application/x-pcl",
260 - ".pct": "image/pict",
261 - ".pcx": "image/x-pcx",
262 - ".pdb": "chemical/x-pdb",
178 + ".pcl": "application/vnd.hp-pcl",
179 + ".pct": "image/x-pict",
180 + ".pcx": "image/vnd.zbrush.pcx",
181 + ".pdb": "application/vnd.palm",
182 ".pdf": "application/pdf",
264 - ".pfunk": "audio/make.my.funk",
183 + ".pfx": "application/x-pkcs12",
184 ".pgm": "image/x-portable-graymap",
266 - ".pic": "image/pict",
267 - ".pict": "image/pict",
268 - ".pkg": "application/x-newton-compatible-pkg",
269 - ".pko": "application/vnd.ms-pki.pko",
270 - ".pl": "text/plain",
271 - ".plx": "application/x-pixclscript",
272 - ".pm": "text/x-script.perl-module",
273 - ".pm4": "application/x-pagemaker",
274 - ".pm5": "application/x-pagemaker",
185 + ".pic": "image/x-pict",
186 + ".pl": "application/x-perl",
187 + ".pm": "application/x-perl",
188 ".png": "image/png",
189 ".pnm": "image/x-portable-anymap",
190 ".pot": "application/vnd.ms-powerpoint",
278 - ".pov": "model/x-pov",
279 - ".ppa": "application/vnd.ms-powerpoint",
191 ".ppm": "image/x-portable-pixmap",
192 ".pps": "application/vnd.ms-powerpoint",
193 ".ppt": "application/vnd.ms-powerpoint",
194 ".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
284 - ".ppz": "application/mspowerpoint",
285 - ".pre": "application/x-freelance",
286 - ".prt": "application/pro_eng",
195 + ".pre": "application/vnd.lotus-freelance",
196 ".ps": "application/postscript",
288 - ".psd": "application/octet-stream",
289 - ".pvu": "paleovu/x-pv",
290 - ".pwz": "application/vnd.ms-powerpoint",
291 - ".py": "text/x-python",
292 - ".pyc": "application/x-python-code",
293 - ".qcp": "audio/vnd.qcelp",
294 - ".qd3": "x-world/x-3dmf",
295 - ".qd3d": "x-world/x-3dmf",
296 - ".qif": "image/x-quicktime",
197 + ".psd": "image/vnd.adobe.photoshop",
198 + ".pyo": "model/vnd.pytha.pyox",
199 ".qt": "video/quicktime",
298 - ".qtc": "video/x-qtc",
299 - ".qti": "image/x-quicktime",
300 - ".qtif": "image/x-quicktime",
200 ".ra": "audio/x-pn-realaudio",
302 - ".ram": "application/x-pn-realaudio",
303 - ".ras": "image/x-cmu-raster",
304 - ".rast": "image/cmu-raster",
201 + ".ram": "audio/x-pn-realaudio",
202 ".rar": "application/vnd.rar",
306 - ".rexx": "text/x-script.rexx",
307 - ".rf": "image/vnd.rn-realflash",
203 + ".ras": "image/x-cmu-raster",
204 + ".rdf": "application/rdf+xml",
205 ".rgb": "image/x-rgb",
309 - ".rm": "audio/x-pn-realaudio",
310 - ".rmi": "audio/mid",
311 - ".rmm": "audio/x-pn-realaudio",
206 + ".rm": "application/vnd.rn-realmedia",
207 + ".rmi": "audio/midi",
208 ".rmp": "audio/x-pn-realaudio-plugin",
313 - ".rng": "application/vnd.nokia.ringing-tone",
314 - ".rnx": "application/vnd.rn-realplayer",
315 - ".roff": "application/x-troff",
316 - ".rp": "image/vnd.rn-realpix",
317 - ".rpm": "audio/x-pn-realaudio-plugin",
318 - ".rt": "text/vnd.rn-realtext",
209 + ".rng": "application/xml",
210 + ".roff": "text/troff",
211 + ".rpm": "application/x-redhat-package-manager",
212 ".rtf": "application/rtf",
213 ".rtx": "text/richtext",
321 - ".rv": "video/vnd.rn-realvideo",
214 ".s": "text/x-asm",
215 ".s3m": "audio/s3m",
324 - ".saveme": "application/octet-stream",
325 - ".sbk": "application/x-tbook",
326 - ".scm": "video/x-scm",
327 - ".sdml": "text/plain",
328 - ".sdp": "application/x-sdp",
329 - ".sdr": "application/sounder",
216 + ".scm": "application/vnd.lotus-screencam",
217 + ".sdp": "application/sdp",
218 ".sea": "application/x-sea",
331 - ".set": "application/set",
332 - ".sgm": "text/x-sgml",
333 - ".sgml": "text/x-sgml",
219 + ".sgm": "text/sgml",
220 + ".sgml": "text/sgml",
221 ".sh": "application/x-sh",
222 ".shar": "application/x-shar",
336 - ".shtml": "text/x-server-parsed-html",
337 - ".sid": "audio/x-psid",
223 + ".shtml": "text/html",
224 + ".sid": "image/x-mrsid-image",
225 ".sit": "application/x-stuffit",
339 - ".skd": "application/x-koan",
340 - ".skm": "application/x-koan",
341 - ".skp": "application/x-koan",
342 - ".skt": "application/x-koan",
343 - ".sl": "application/x-seelogo",
344 - ".smi": "application/smil",
345 - ".smil": "application/smil",
226 + ".skd": "application/vnd.koan",
227 + ".skm": "application/vnd.koan",
228 + ".skp": "application/vnd.koan",
229 + ".skt": "application/vnd.koan",
230 + ".smi": "application/smil+xml",
231 + ".smil": "application/smil+xml",
232 ".snd": "audio/basic",
347 - ".sol": "application/solids",
348 - ".spc": "text/x-speech",
349 - ".spl": "application/futuresplash",
350 - ".spr": "application/x-sprite",
351 - ".sprite": "application/x-sprite",
233 + ".spc": "application/x-pkcs7-certificates",
234 + ".spl": "application/x-futuresplash",
235 ".src": "application/x-wais-source",
353 - ".ssi": "text/x-server-parsed-html",
354 - ".ssm": "application/streamingmedia",
355 - ".sst": "application/vnd.ms-pki.certstore",
356 - ".step": "application/step",
357 - ".stl": "application/x-navistyle",
358 - ".stp": "application/step",
236 + ".step": "model/step",
237 + ".stl": "model/stl",
238 + ".stp": "model/step",
239 ".sv4cpio": "application/x-sv4cpio",
240 ".sv4crc": "application/x-sv4crc",
361 - ".svf": "image/x-dwg",
241 ".svg": "image/svg+xml",
363 - ".svr": "x-world/x-svr",
242 ".swf": "application/x-shockwave-flash",
365 - ".t": "application/x-troff",
366 - ".talk": "text/x-speech",
243 + ".t": "text/troff",
244 ".tar": "application/x-tar",
368 - ".tbk": "application/x-tbook",
245 ".tcl": "application/x-tcl",
370 - ".tcsh": "text/x-script.tcsh",
246 ".tex": "application/x-tex",
247 ".texi": "application/x-texinfo",
248 ".texinfo": "application/x-texinfo",
249 ".text": "text/plain",
375 - ".tgz": "application/x-compressed",
250 ".tif": "image/tiff",
251 ".tiff": "image/tiff",
378 - ".tr": "application/x-troff",
252 + ".tr": "text/troff",
253 ".ts": "video/mp2t",
380 - ".tsi": "audio/tsp-audio",
381 - ".tsp": "audio/tsplayer",
254 ".tsv": "text/tab-separated-values",
383 - ".turbot": "image/florian",
255 ".txt": "text/plain",
385 - ".uil": "text/x-uil",
386 - ".uni": "text/uri-list",
387 - ".unis": "text/uri-list",
388 - ".unv": "application/i-deas",
256 ".uri": "text/uri-list",
257 ".uris": "text/uri-list",
258 ".ustar": "application/x-ustar",
259 ".uu": "text/x-uuencode",
393 - ".uue": "text/x-uuencode",
260 ".vcd": "application/x-cdlink",
261 + ".vcf": "text/x-vcard",
262 ".vcs": "text/x-vcalendar",
396 - ".vda": "application/vda",
397 - ".vdo": "video/vdo",
398 - ".vew": "application/groupwise",
263 ".viv": "video/vnd.vivo",
400 - ".vivo": "video/vnd.vivo",
401 - ".vmd": "application/vocaltec-media-desc",
402 - ".vmf": "application/vocaltec-media-file",
403 - ".voc": "audio/x-voc",
404 - ".vos": "video/vosaic",
405 - ".vox": "audio/voxware",
406 - ".vqe": "audio/x-twinvq-plugin",
407 - ".vqf": "audio/x-twinvq",
408 - ".vql": "audio/x-twinvq-plugin",
409 - ".vrml": "x-world/x-vrml",
410 - ".vrt": "x-world/x-vrt",
411 - ".vsd": "application/x-visio",
412 - ".vst": "application/x-visio",
413 - ".vsw": "application/x-visio",
414 - ".w60": "application/wordperfect6.0",
415 - ".w61": "application/wordperfect6.1",
416 - ".w6w": "application/msword",
417 - ".wav": "audio/x-wav",
418 - ".wb1": "application/x-qpro",
264 + ".vox": "application/x-authorware-bin",
265 + ".vrml": "model/vrml",
266 + ".vsd": "application/vnd.visio",
267 + ".vst": "application/vnd.visio",
268 + ".vsw": "application/vnd.visio",
269 + ".wasm": "application/wasm",
270 + ".wav": "audio/wav",
271 ".wbmp": "image/vnd.wap.wbmp",
420 - ".web": "application/vnd.xara",
272 ".webm": "video/webm",
273 + ".webmanifest": "application/manifest+json",
274 ".webp": "image/webp",
423 - ".wiz": "application/msword",
424 - ".wk1": "application/x-123",
425 - ".wmf": "windows/metafile",
275 + ".wmf": "image/wmf",
276 ".wml": "text/vnd.wap.wml",
277 ".wmlc": "application/vnd.wap.wmlc",
278 ".wmls": "text/vnd.wap.wmlscript",
279 ".wmlsc": "application/vnd.wap.wmlscriptc",
430 - ".word": "application/msword",
280 ".woff": "font/woff",
281 ".woff2": "font/woff2",
433 - ".wp": "application/wordperfect",
434 - ".wp5": "application/wordperfect6.0",
435 - ".wp6": "application/wordperfect",
436 - ".wpd": "application/x-wpwin",
437 - ".wq1": "application/x-lotus",
438 - ".wri": "application/x-wri",
439 - ".wrl": "x-world/x-vrml",
440 - ".wrz": "x-world/x-vrml",
441 - ".wsc": "text/scriplet",
442 - ".wsrc": "application/x-wais-source",
443 - ".wtk": "application/x-wintalk",
282 + ".wpd": "application/vnd.wordperfect",
283 + ".wri": "application/x-mswrite",
284 + ".wrl": "model/vrml",
285 + ".wsc": "message/vnd.wfa.wsc",
286 + ".wsdl": "application/wsdl+xml",
287 ".xbm": "image/x-xbitmap",
445 - ".xdr": "video/x-amt-demorun",
446 - ".xgz": "xgl/drawing",
288 ".xif": "image/vnd.xiff",
448 - ".xl": "application/excel",
449 - ".xla": "application/x-msexcel",
450 - ".xlb": "application/vnd.ms-excel",
451 - ".xlc": "application/x-excel",
452 - ".xld": "application/x-excel",
453 - ".xlk": "application/x-excel",
454 - ".xll": "application/x-excel",
455 - ".xlm": "application/x-excel",
289 + ".xla": "application/vnd.ms-excel",
290 + ".xlc": "application/vnd.ms-excel",
291 + ".xlm": "application/vnd.ms-excel",
292 ".xls": "application/vnd.ms-excel",
457 - ".xlt": "application/x-excel",
458 - ".xlv": "application/x-excel",
459 - ".xlw": "application/x-msexcel",
293 + ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
294 + ".xlt": "application/vnd.ms-excel",
295 + ".xlw": "application/vnd.ms-excel",
296 ".xm": "audio/xm",
461 - ".xml": "text/xml",
462 - ".xmz": "xgl/movie",
463 - ".xpix": "application/x-vnd.ls-xpix",
297 + ".xml": "application/xml",
298 ".xpm": "image/x-xpixmap",
465 - ".x-ng": "image/png",
466 - ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
467 - ".xsr": "video/x-amt-showrun",
299 + ".xsl": "application/xml",
300 + ".xul": "application/vnd.mozilla.xul+xml",
301 ".xwd": "image/x-xwindowdump",
469 - ".xyz": "chemical/x-pdb",
470 - ".yaml": "application/x-yaml",
471 - ".yml": "application/x-yaml",
472 - ".z": "application/x-compressed",
302 + ".xyz": "chemical/x-xyz",
303 + ".yaml": "text/yaml",
304 + ".yml": "text/yaml",
305 ".zip": "application/zip",
474 - ".zoo": "application/octet-stream",
475 - ".zsh": "text/x-script.zsh",
476 - ".mjs": "application/javascript",
477 - ".webmanifest": "application/manifest+json",
478 - ".dll": "application/octet-stream",
479 - ".obj": "application/octet-stream",
480 - ".so": "application/octet-stream",
481 - ".m3u8": "application/vnd.apple.mpegurl",
482 - ".wasm": "application/wasm",
483 - ".h5": "application/x-hdf5",
484 - ".pfx": "application/x-pkcs12",
485 - ".pyo": "application/x-python-code",
486 - ".xsl": "application/xml",
487 - ".rdf": "application/xml",
488 - ".wsdl": "application/xml",
489 - ".xpdl": "application/xml",
490 - ".3gp": "audio/3gpp",
491 - ".3gpp": "audio/3gpp",
492 - ".3g2": "audio/3gpp2",
306 + # Not known to the `mime` npm package; values from Python's standard
307 + # `mimetypes`, except `.tgz`.
308 ".3gpp2": "audio/3gpp2",
494 - ".aac": "audio/aac",
495 - ".adts": "audio/aac",
496 - ".loas": "audio/aac",
309 ".ass": "audio/aac",
498 - ".opus": "audio/opus",
499 - ".heic": "image/heic",
500 - ".heif": "image/heif",
501 - ".eml": "message/rfc822",
310 + ".h5": "application/x-hdf5",
311 + ".ksh": "text/plain",
312 + ".loas": "audio/aac",
313 + ".mpa": "video/mpeg",
314 ".nws": "message/rfc822",
503 - ".bat": "text/plain",
504 - ".vcf": "text/x-vcard",
505 - ".xul": "text/xul",
315 + ".ppa": "application/vnd.ms-powerpoint",
316 + ".pwz": "application/vnd.ms-powerpoint",
317 + ".py": "text/x-python",
318 + ".pyc": "application/x-python-code",
319 + ".tgz": "application/gzip",
320 + ".wiz": "application/msword",
321 + ".xlb": "application/vnd.ms-excel",
322 + ".xpdl": "application/xml",
323 }
324
325
python/tests/test_mimetypes.py
+30 -1
@@ -1,11 +1,13 @@
1 """Tests for the mimetypes utility module."""
2
3 +import re
4 from pathlib import Path
5
6 import pytest
7
8 from composio.utils.mimetypes import (
9 _default,
10 + _types,
11 get_extension_from_mime_type,
12 guess,
13 )
@@ -22,7 +24,15 @@ class TestGuess:
24 ("a.txt", "text/plain"),
25 ("a.pdf", "application/pdf"),
26 ("a.css", "text/css"),
25 - ("a.js", "application/javascript"),
27 + ("a.js", "text/javascript"),
28 + (
29 + "a.pptx",
30 + "application/vnd.openxmlformats-officedocument.presentationml.presentation",
31 + ),
32 + ("a.psd", "image/vnd.adobe.photoshop"),
33 + ("a.py", "text/x-python"),
34 + ("a.h5", "application/x-hdf5"),
35 + ("a.pyc", "application/x-python-code"),
36 ("a.png", "image/png"),
37 ("a.jpg", "image/jpeg"),
38 ("a.jpeg", "image/jpeg"),
@@ -66,6 +76,25 @@ class TestGuess:
76 assert guess(Path("dir/sub/a.png")) == "image/png"
77
78
79 +TS_MIME_TABLE = (
80 + Path(__file__).resolve().parents[2] / "ts/packages/core/src/utils/mime.ts"
81 +)
82 +
83 +
84 +def test_types_match_the_typescript_sdk() -> None:
85 + """A local file uploads with the same MIME type from either SDK."""
86 + source = TS_MIME_TABLE.read_text()
87 + table = source[source.index("MIME_TYPES_BY_EXTENSION") :]
88 + table = table[: table.index("};")]
89 + ts_types = {
90 + f".{extension}": mime_type
91 + for extension, mime_type in re.findall(
92 + r"^\s+'?([a-z0-9]+)'?: '([^']+)',$", table, re.M
93 + )
94 + }
95 + assert _types == ts_types
96 +
97 +
98 class TestGetExtensionFromMimeType:
99 """Test cases for get_extension_from_mime_type() (MIME type -> extension)."""
100
ts/packages/cli/CHANGELOG.md
+6
@@ -39,6 +39,12 @@
39 lookup, now fails with the message those commands print, as a plain message
40 on stderr with exit 1.
41
42 +- In `composio run`, a `File` or `Blob` passed to `execute()` now uploads with
43 + its own `type`, even when its name has no extension, and a `File` keeps its
44 + name. It used to upload as `application/octet-stream` under a name with a
45 + random prefix, such as `1bfa14f5-deck.pptx`. A nameless `Blob` whose type has
46 + no short extension, such as PPTX, is named `file-<id>.bin`.
47 +
48 - `composio upgrade` no longer starts with a stale "Update available" line.
49 The line came from the cached daily update check, so right after a release
50 it could name an older version than the one `composio upgrade` then
ts/packages/cli/README.md
+6 -5
@@ -98,11 +98,12 @@ By default, both files are stored in `~/.composio`, but you can specify a custom
98
99 The CLI and its installer use these variables to coordinate nested commands. They aren't intended for manual configuration.
100
101 -| Environment Variable | Description | Default |
102 -| ------------------------------ | -------------------------------------------------------------------------- | ------- |
103 -| COMPOSIO_CLI_INVOCATION_ORIGIN | Identifies whether another CLI surface, such as `composio run`, invoked it | cli |
104 -| COMPOSIO_CLI_PARENT_RUN_ID | Reuses the parent run ID for nested command telemetry | None |
105 -| COMPOSIO_RUN_OUTPUT_DIR | Shares one artifact directory across nested `composio run` commands | None |
101 +| Environment Variable | Description | Default |
102 +| ------------------------------ | ---------------------------------------------------------------------------------------------------- | ------- |
103 +| COMPOSIO_CLI_INVOCATION_ORIGIN | Identifies whether another CLI surface, such as `composio run`, invoked it | cli |
104 +| COMPOSIO_CLI_PARENT_RUN_ID | Reuses the parent run ID for nested command telemetry | None |
105 +| COMPOSIO_RUN_OUTPUT_DIR | Shares one artifact directory across nested `composio run` commands | None |
106 +| COMPOSIO_RUN_STAGED_FILES_FILE | Points to the temporary JSON file containing upload names and types for the child `composio execute` | None |
107
108 Additionally, `composio upgrade` supports the following environment variables:
109
ts/packages/cli/src/config/app.ts
+2
@@ -90,6 +90,8 @@ export const APP_CONFIG = {
90 CLI_INVOCATION_ORIGIN: optionalString('COMPOSIO_CLI_INVOCATION_ORIGIN'),
91 CLI_PARENT_RUN_ID: optionalString('COMPOSIO_CLI_PARENT_RUN_ID'),
92 RUN_OUTPUT_DIR: optionalString('COMPOSIO_RUN_OUTPUT_DIR'),
93 + // Staged file path -> name and MIME type, for the Files a `composio run` script passed to `execute()`
94 + RUN_STAGED_FILES_FILE: optionalString('COMPOSIO_RUN_STAGED_FILES_FILE'),
95
96 // Disable connected account cache (defaults to true — cache is off by default)
97 DISABLE_CONNECTED_ACCOUNT_CACHE: flag('COMPOSIO_DISABLE_CONNECTED_ACCOUNT_CACHE', true),
ts/packages/cli/src/services/run-helpers-runtime.ts
+122 -53
@@ -229,21 +229,18 @@ const attachPromptMethod = <T>(value: T): T => {
229
230 const isPlainObjectForExecute = Predicate.isObject;
231
232 -const runFileExtensionFromMimeType = (mimeType: string | undefined): string => {
233 - if (typeof mimeType !== 'string' || mimeType.trim().length === 0) return 'bin';
232 +// The extension of the name a nameless Blob is uploaded under. Cosmetic: the Blob's
233 +// type reaches the upload through `COMPOSIO_RUN_STAGED_FILES_FILE`, not through this
234 +// extension. A subtype that is not a plain token (`vnd.openxmlformats-…`) is `bin`.
235 +const runFileExtensionFromMimeType = (mimeType: string): string => {
236 const normalized = mimeType.split(';')[0]?.trim().toLowerCase() ?? '';
237 const explicit: Record<string, string> = {
238 'text/plain': 'txt',
237 - 'application/json': 'json',
238 - 'application/pdf': 'pdf',
239 'image/jpeg': 'jpg',
240 - 'image/png': 'png',
241 - 'image/webp': 'webp',
242 - 'image/gif': 'gif',
240 };
244 - if (explicit[normalized]) return explicit[normalized];
245 - const subtype = normalized.split('/')[1] || 'bin';
246 - return subtype.includes('+') ? (subtype.split('+').pop() ?? 'bin') : subtype;
241 + if (Object.hasOwn(explicit, normalized)) return explicit[normalized];
242 + const subtype = normalized.split('/')[1]?.split('+').pop() ?? '';
243 + return /^[a-z0-9]{1,10}$/.test(subtype) ? subtype : 'bin';
244 };
245
246 const describeDebugValue = (value: unknown) => {
@@ -388,47 +385,79 @@ const createRunHelperLoggers = (params: {
385 return { perfDebugLog, helperDebugLog };
386 };
387
388 +/**
389 + * An `execute()` payload with every File and Blob written to disk: the spawned
390 + * `composio execute` takes `--data` JSON, so each one becomes its staged path.
391 + */
392 +/** What the upload reports for a staged file, in place of its staged path's. */
393 +type StagedFileLabel = { readonly name: string; readonly mimetype?: string };
394 +
395 +/**
396 + * An `execute()` payload with every File and Blob written to disk: the spawned
397 + * `composio execute` takes `--data` JSON, so each one becomes its staged path.
398 + */
399 +type MaterializedExecutePayload = {
400 + readonly payload: unknown;
401 + /**
402 + * Staged path -> the File or Blob's own name and `type`. A path carries
403 + * neither, so the child receives these through `COMPOSIO_RUN_STAGED_FILES_FILE`
404 + * and uploads the file under them.
405 + */
406 + readonly stagedFiles: ReadonlyArray<readonly [string, StagedFileLabel]>;
407 +};
408 +
409 const createExecutePayloadMaterializer = (params: {
410 readonly path: Path.Path;
411 readonly tmpdir: string;
412 readonly sharedRunOutputDir: string | null;
395 -}): ((value: unknown) => Promise<unknown>) => {
413 +}): ((value: unknown) => Promise<MaterializedExecutePayload>) => {
414 const { path, tmpdir, sharedRunOutputDir } = params;
415
398 - const writeTempExecuteFile = async (value: unknown): Promise<unknown> => {
416 + // The name the upload sends: a File's own, without any directory part.
417 + const uploadName = (blob: Blob): string => {
418 + const baseName = blob instanceof File ? path.basename(blob.name).trim() : '';
419 + return baseName.length > 0 && baseName !== '.' && baseName !== '..'
420 + ? baseName
421 + : `file-${executeId()}.${runFileExtensionFromMimeType(blob.type)}`;
422 + };
423 +
424 + const writeTempExecuteFile = async (
425 + blob: Blob,
426 + stagedFiles: Array<readonly [string, StagedFileLabel]>
427 + ): Promise<string> => {
428 const outputDir = sharedRunOutputDir || path.join(tmpdir, 'composio-run-files');
429 fs.mkdirSync(outputDir, { recursive: true });
401 - if (typeof File !== 'undefined' && value instanceof File) {
402 - const safeName =
403 - typeof value.name === 'string' && value.name.trim().length > 0
404 - ? value.name
405 - : `file-${executeId()}.${runFileExtensionFromMimeType(value.type)}`;
406 - const filePath = path.join(outputDir, `${executeId()}-${safeName}`);
407 - fs.writeFileSync(filePath, new Uint8Array(await value.arrayBuffer()));
408 - return filePath;
409 - }
410 - if (typeof Blob !== 'undefined' && value instanceof Blob) {
411 - const filePath = path.join(
412 - outputDir,
413 - `${executeId()}.${runFileExtensionFromMimeType(value.type)}`
414 - );
415 - fs.writeFileSync(filePath, new Uint8Array(await value.arrayBuffer()));
416 - return filePath;
417 - }
418 - return value;
430 + const name = uploadName(blob);
431 + // Staged under a generated name, never the File's own: the child still runs
432 + // the sensitive-path denylist on this path, and a script-created
433 + // `.env.example` or `id_rsa` is not a file of the user's to protect. The
434 + // extension is kept only as a fallback for the type.
435 + const extension = path.extname(name);
436 + const filePath = path.join(
437 + outputDir,
438 + `file-${executeId()}${/^\.[A-Za-z0-9]{1,10}$/.test(extension) ? extension : ''}`
439 + );
440 + fs.writeFileSync(filePath, new Uint8Array(await blob.arrayBuffer()));
441 + const mimetype = blob.type.trim();
442 + stagedFiles.push([filePath, mimetype.length > 0 ? { name, mimetype } : { name }]);
443 + return filePath;
444 };
445
421 - const materializeExecutePayload = async (value: unknown): Promise<unknown> => {
422 - if (typeof File !== 'undefined' && value instanceof File) return writeTempExecuteFile(value);
423 - if (typeof Blob !== 'undefined' && value instanceof Blob) return writeTempExecuteFile(value);
446 + const materialize = async (
447 + value: unknown,
448 + stagedFiles: Array<readonly [string, StagedFileLabel]>
449 + ): Promise<unknown> => {
450 + if (typeof Blob !== 'undefined' && value instanceof Blob) {
451 + return writeTempExecuteFile(value, stagedFiles);
452 + }
453 if (Array.isArray(value)) {
425 - return Promise.all(value.map(item => materializeExecutePayload(item)));
454 + return Promise.all(value.map(item => materialize(item, stagedFiles)));
455 }
456 if (isPlainObjectForExecute(value)) {
457 const entries = await Promise.all(
458 Object.entries(value).map(async ([key, entryValue]) => [
459 key,
431 - await materializeExecutePayload(entryValue),
460 + await materialize(entryValue, stagedFiles),
461 ])
462 );
463 return Object.fromEntries(entries);
@@ -436,12 +465,21 @@ const createExecutePayloadMaterializer = (params: {
465 return value;
466 };
467
439 - return materializeExecutePayload;
468 + return async value => {
469 + const stagedFiles: Array<readonly [string, StagedFileLabel]> = [];
470 + const payload = await materialize(value, stagedFiles);
471 + return { payload, stagedFiles };
472 + };
473 };
474
475 const isReportedFailure = (result: RunCliResult): boolean =>
476 Predicate.isObject(result) && result.successful === false;
477
478 +type RunCliJson = (
479 + args: ReadonlyArray<string>,
480 + extraEnv?: Readonly<Record<string, string>>
481 +) => Promise<RunCliResult>;
482 +
483 const createCliRunner = (params: {
484 readonly cliPrefix: ReadonlyArray<string>;
485 readonly helperContext: RunHelperContext;
@@ -449,7 +487,7 @@ const createCliRunner = (params: {
487 readonly perfDebugEnabled: boolean;
488 readonly toolDebugEnabled: boolean;
489 readonly loggers: RunHelperLoggers;
452 -}): ((args: ReadonlyArray<string>) => Promise<RunCliResult>) => {
490 +}): RunCliJson => {
491 const { cliPrefix, helperContext, sharedRunOutputDir, perfDebugEnabled, toolDebugEnabled } =
492 params;
493 const { perfDebugLog, helperDebugLog } = params.loggers;
@@ -520,7 +558,10 @@ const createCliRunner = (params: {
558 }),
559 };
560
523 - const runCliJson = async (args: ReadonlyArray<string>): Promise<RunCliResult> => {
561 + const runCliJson = async (
562 + args: ReadonlyArray<string>,
563 + extraEnv: Readonly<Record<string, string>> = {}
564 + ): Promise<RunCliResult> => {
565 const requestId = `${args[0] ?? 'cli'}#${++perfDebugSeq}`;
566 helperDebugLog('cli.start', { requestId, args });
567 perfDebugLog('start', requestId, { cmd: args });
@@ -530,7 +571,7 @@ const createCliRunner = (params: {
571 Effect.scoped(
572 Effect.gen(function* () {
573 const child = yield* Command.make(executable, commandArgs, {
533 - env,
574 + env: { ...env, ...extraEnv },
575 extendEnv: true,
576 stdin: 'inherit',
577 stderr: inheritStderr ? 'inherit' : 'pipe',
@@ -598,13 +639,17 @@ const createCliRunner = (params: {
639 const createSearchAndExecuteHelpers = (params: {
640 readonly helperContext: RunHelperContext;
641 readonly sharedRunOutputDir: string | null;
601 - readonly runCliJson: (args: ReadonlyArray<string>) => Promise<RunCliResult>;
602 - readonly materializeExecutePayload: (value: unknown) => Promise<unknown>;
642 + readonly path: Path.Path;
643 + readonly tmpdir: string;
644 + readonly runCliJson: RunCliJson;
645 + readonly materializeExecutePayload: (value: unknown) => Promise<MaterializedExecutePayload>;
646 readonly helperDebugLog: HelperDebugLog;
647 }) => {
648 const {
649 helperContext,
650 sharedRunOutputDir,
651 + path,
652 + tmpdir,
653 runCliJson,
654 materializeExecutePayload,
655 helperDebugLog,
@@ -645,8 +690,12 @@ const createSearchAndExecuteHelpers = (params: {
690 if (typeof options.account === 'string' && options.account.trim().length > 0) {
691 args.push('--account', options.account.trim());
692 }
693 + // Always set, so a value this process inherited never reaches the child.
694 + let stagedFiles: MaterializedExecutePayload['stagedFiles'] = [];
695 if (data !== undefined) {
649 - const preparedData = await materializeExecutePayload(data);
696 + const materialized = await materializeExecutePayload(data);
697 + const preparedData = materialized.payload;
698 + stagedFiles = materialized.stagedFiles;
699 const serialized =
700 typeof preparedData === 'string' ? preparedData : JSON.stringify(preparedData);
701 if (sharedRunOutputDir) {
@@ -657,17 +706,35 @@ const createSearchAndExecuteHelpers = (params: {
706 args.push('--data', serialized);
707 }
708 }
660 - const result = await runCliJson(args);
661 - if (Predicate.isObject(result) && result.successful === false) {
662 - const message =
663 - typeof result.error === 'string' && result.error.trim().length > 0
664 - ? result.error.trim()
665 - : `composio execute ${slug} failed`;
666 - const error = new Error(message);
667 - Object.assign(error, { result, slug });
668 - throw error;
669 - }
670 - return result;
709 + const metadataDirectory =
710 + stagedFiles.length > 0
711 + ? fs.mkdtempSync(path.join(tmpdir, 'composio-run-staged-'))
712 + : undefined;
713 + const metadataFile = metadataDirectory ? path.join(metadataDirectory, 'files.json') : '';
714 + const runWithStagedFiles = async (): Promise<RunCliResult> => {
715 + if (metadataFile) {
716 + fs.writeFileSync(metadataFile, JSON.stringify(Object.fromEntries(stagedFiles)), {
717 + encoding: 'utf8',
718 + mode: 0o600,
719 + });
720 + }
721 + const result = await runCliJson(args, {
722 + COMPOSIO_RUN_STAGED_FILES_FILE: metadataFile,
723 + });
724 + if (Predicate.isObject(result) && result.successful === false) {
725 + const message =
726 + typeof result.error === 'string' && result.error.trim().length > 0
727 + ? result.error.trim()
728 + : `composio execute ${slug} failed`;
729 + const error = new Error(message);
730 + Object.assign(error, { result, slug });
731 + throw error;
732 + }
733 + return result;
734 + };
735 + return runWithStagedFiles().finally(() => {
736 + if (metadataDirectory) fs.rmSync(metadataDirectory, { recursive: true, force: true });
737 + });
738 };
739
740 return { search, execute };
@@ -846,6 +913,8 @@ export const installRunHelpers = async ({
913 const { search, execute } = createSearchAndExecuteHelpers({
914 helperContext,
915 sharedRunOutputDir,
916 + path,
917 + tmpdir: nodeOs.tmpdir,
918 runCliJson,
919 materializeExecutePayload,
920 helperDebugLog,
ts/packages/cli/src/services/tool-file-uploads.ts
+61 -8
@@ -6,15 +6,21 @@
6 import type * as FileSystem from 'effect/FileSystem';
7 import type * as Path from 'effect/Path';
8 import type { ComposioClientShape, ComposioError } from '@composio/client/effect';
9 -import { Data, Effect, Predicate } from 'effect';
9 +import { Data, Effect, Predicate, Schema } from 'effect';
10 import mime from 'mime';
11 import { guessToolkitFromToolSlug } from 'src/utils/toolkit-from-tool-slug';
12 import { isPlainRecord } from 'src/utils/parse-json';
13 import { idempotent } from 'src/services/composio-request';
14
15 type JsonSchema = Record<string, unknown>;
16 +/**
17 + * Local path -> the name and MIME type to upload it under, for files their caller
18 + * staged (`composio run` writes each script File to a generated path). Labels
19 + * only: the path is still read, and checked against the denylist, as given.
20 + */
21 +type StagedFiles = ReadonlyMap<string, { readonly name: string; readonly mimetype?: string }>;
22
17 -// The three core helpers below are only reached once an execute actually carries
23 +// The core helpers below are only reached once an execute actually carries
24 // a file input, so they are imported on that path rather than at module scope:
25 // `@composio/core`'s root entry evaluates the whole SDK, which every command
26 // would otherwise pay for at startup. The module registry memoizes the import.
@@ -47,6 +53,27 @@ const asSourceReadError = (cause: unknown): ToolFileUploadError =>
53 reason: 'source-read',
54 });
55
56 +const decodeRunStagedFiles = Schema.decodeUnknownEffect(
57 + Schema.fromJsonString(
58 + Schema.Record(
59 + Schema.String,
60 + Schema.Struct({ name: Schema.String, mimetype: Schema.optional(Schema.String) })
61 + )
62 + )
63 +);
64 +
65 +/** Read the per-execute labels without putting the file batch in the environment. */
66 +export const readRunStagedFiles = (
67 + fs: FileSystem.FileSystem,
68 + manifestPath: string | undefined
69 +): Effect.Effect<StagedFiles, ToolFileUploadError> =>
70 + Effect.gen(function* () {
71 + if (!manifestPath) return new Map();
72 + const content = yield* fs.readFileString(manifestPath).pipe(Effect.mapError(asSourceReadError));
73 + const labels = yield* decodeRunStagedFiles(content).pipe(Effect.mapError(asSourceReadError));
74 + return new Map(Object.entries(labels));
75 + });
76 +
77 // Releases a body this module does not read, ignoring a cancellation failure.
78 const discardBody = (response: Response) =>
79 Effect.ignore(Effect.tryPromise(() => response.body?.cancel() ?? Promise.resolve()));
@@ -449,7 +476,12 @@ const readFileFromUrl = (path: Path.Path, url: string) =>
476 };
477 });
478
452 -const readFileFromDisk = (fs: FileSystem.FileSystem, path: Path.Path, filePath: string) =>
479 +const readFileFromDisk = (
480 + fs: FileSystem.FileSystem,
481 + path: Path.Path,
482 + filePath: string,
483 + stagedFiles: StagedFiles
484 +) =>
485 Effect.gen(function* () {
486 // Enforce the sensitive-path denylist at the lowest-level local read, so any
487 // caller of this reader (not just `uploadToolInputFiles`) is protected. This
@@ -475,16 +507,28 @@ const readFileFromDisk = (fs: FileSystem.FileSystem, path: Path.Path, filePath:
507 catch: asSourceReadError,
508 });
509 const bytes = yield* fs.readFile(filePath).pipe(Effect.mapError(asSourceReadError));
510 + // A staged file is uploaded under the name and type its caller declared. A
511 + // local file carries no Content-Type, so otherwise the type is inferred from
512 + // the name's extension. Tools validate it (Canva's import rejects a .pptx
513 + // labelled `application/octet-stream`, #4984).
514 + const staged = stagedFiles.get(filePath);
515 + const stagedName = path.basename(staged?.name ?? '');
516 + const fileName = stagedName.length > 0 ? stagedName : path.basename(filePath);
517 return {
518 // Copy into a fresh ArrayBuffer-backed view: `fetch` bodies reject the
519 // wider ArrayBufferLike-backed Uint8Array that FileSystem returns.
520 bytes: new Uint8Array(bytes),
482 - fileName: path.basename(filePath),
483 - mimeType: mime.getType(path.basename(filePath)) ?? 'application/octet-stream',
521 + fileName,
522 + mimeType: staged?.mimetype ?? mime.getType(fileName) ?? 'application/octet-stream',
523 };
524 });
525
487 -const readUploadSource = (fs: FileSystem.FileSystem, path: Path.Path, file: string | File) => {
526 +const readUploadSource = (
527 + fs: FileSystem.FileSystem,
528 + path: Path.Path,
529 + file: string | File,
530 + stagedFiles: StagedFiles
531 +) => {
532 if (isFileLike(file)) {
533 return Effect.tryPromise({ try: () => file.arrayBuffer(), catch: asSourceReadError }).pipe(
534 Effect.map(buffer => ({
@@ -500,7 +544,7 @@ const readUploadSource = (fs: FileSystem.FileSystem, path: Path.Path, file: stri
544 }
545
546 if (typeof file === 'string') {
503 - return readFileFromDisk(fs, path, file);
547 + return readFileFromDisk(fs, path, file, stagedFiles);
548 }
549
550 return Effect.fail(
@@ -518,9 +562,15 @@ const uploadFile = (params: {
562 readonly toolSlug: string;
563 readonly toolkitSlug: string;
564 readonly client: ComposioClientShape;
565 + readonly stagedFiles: StagedFiles;
566 }) =>
567 Effect.gen(function* () {
523 - const fileData = yield* readUploadSource(params.fs, params.path, params.file);
568 + const fileData = yield* readUploadSource(
569 + params.fs,
570 + params.path,
571 + params.file,
572 + params.stagedFiles
573 + );
574 // eslint-disable-next-line no-restricted-imports -- MD5 for the presigned-upload checksum is not available in Web Crypto
575 const { createHash } = yield* Effect.promise(() => import('node:crypto'));
576 const md5 = createHash('md5').update(fileData.bytes).digest('hex');
@@ -598,6 +648,8 @@ export const uploadToolInputFiles = (params: {
648 readonly inputSchema: JsonSchema;
649 readonly client: ComposioClientShape;
650 readonly toolkitSlug?: string;
651 + /** Local path -> name and MIME type its caller staged it under. */
652 + readonly stagedFiles?: StagedFiles;
653 }): Effect.Effect<Record<string, unknown>, ToolInputUploadError> =>
654 Effect.gen(function* () {
655 yield* rejectLocalFilesWithoutUpload(params);
@@ -608,5 +660,6 @@ export const uploadToolInputFiles = (params: {
660 toolSlug: params.toolSlug,
661 toolkitSlug: params.toolkitSlug ?? guessToolkitFromToolSlug(params.toolSlug) ?? 'unknown',
662 client: params.client,
663 + stagedFiles: params.stagedFiles ?? new Map(),
664 });
665 });
ts/packages/cli/src/services/tools-executor.ts
+9 -1
@@ -28,9 +28,14 @@ import {
28 } from 'src/services/composio-error-overrides';
29 import { getOrFetchToolInputDefinition } from 'src/services/tool-input-validation';
30 import type { CliDebugFlags } from 'src/services/runtime-flags';
31 -import { ToolFileUploadError, uploadToolInputFiles } from 'src/services/tool-file-uploads';
31 +import {
32 + readRunStagedFiles,
33 + ToolFileUploadError,
34 + uploadToolInputFiles,
35 +} from 'src/services/tool-file-uploads';
36 import { toolkitFromToolSlug } from 'src/effects/toolkit-from-tool-slug';
37 import { ToolkitSlugCatalog } from 'src/services/toolkit-slug-catalog';
38 +import { APP_CONFIG } from 'src/config';
39 import { isMetaToolSlug } from 'src/utils/meta-tool-slugs';
40 import { toolInputRequiredError, type ToolInputRequiredError } from 'src/utils/tool-input-required';
41 import type { NodeOs } from 'src/services/node-os';
@@ -293,6 +298,8 @@ const prepareToolExecution = (
298 });
299 const fs = yield* FileSystem.FileSystem;
300 const path = yield* Path.Path;
301 + const manifestPath = yield* Effect.orDie(APP_CONFIG.RUN_STAGED_FILES_FILE);
302 + const stagedFiles = yield* readRunStagedFiles(fs, manifestPath);
303 const preparedArguments = isMetaToolSlug(slug)
304 ? params.arguments
305 : yield* getOrFetchToolInputDefinition(slug, params.projectScope).pipe(
@@ -313,6 +320,7 @@ const prepareToolExecution = (
320 arguments_: params.arguments,
321 inputSchema: definition.schema,
322 client,
323 + stagedFiles,
324 }).pipe(
325 Effect.catchIf(
326 isComposioError,
ts/packages/cli/test/src/cli-main.test.ts
+128
@@ -718,3 +718,131 @@ describe('expected failures without the crash banner', () => {
718 30_000
719 );
720 });
721 +
722 +describe('local file uploads', () => {
723 + const PPTX = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
724 +
725 + // Records the presigned-URL request, then refuses it so no upload is attempted.
726 + const fakeUploadBackend =
727 + (presignRequests: Array<unknown>) => (req: IncomingMessage, res: ServerResponse) => {
728 + const { pathname } = new URL(req.url ?? '/', 'http://127.0.0.1');
729 + if (/^\/api\/v3(\.1)?\/tools\/CANVA_CREATE_DESIGN_IMPORT_JOB$/u.test(pathname)) {
730 + return sendJson(res, 200, {
731 + slug: 'CANVA_CREATE_DESIGN_IMPORT_JOB',
732 + name: 'Create Design Import Job',
733 + description: '',
734 + version: '20260101_00',
735 + available_versions: ['20260101_00'],
736 + input_parameters: {
737 + type: 'object',
738 + properties: {
739 + file: { type: 'object', file_uploadable: true },
740 + title: { type: 'string' },
741 + },
742 + },
743 + output_parameters: {},
744 + tags: [],
745 + });
746 + }
747 + if (pathname.endsWith('/files/upload/request')) {
748 + const chunks: Array<Buffer> = [];
749 + req.on('data', (chunk: Buffer) => chunks.push(chunk));
750 + req.on('end', () => {
751 + presignRequests.push(JSON.parse(Buffer.concat(chunks).toString('utf8')));
752 + sendJson(res, 400, { error: { message: 'stop here', status: 400 } });
753 + });
754 + return;
755 + }
756 + fakeComposio(req, res);
757 + };
758 +
759 + const uploadWith = async (
760 + baseUrl: string,
761 + file: string,
762 + stagedFiles?: Record<string, { name: string; mimetype?: string }>
763 + ) => {
764 + const metadataDirectory = fs.mkdtempSync(path.join(tempy.temporaryDirectory(), 'labels-'));
765 + const metadataFile = path.join(metadataDirectory, 'files.json');
766 + if (stagedFiles) fs.writeFileSync(metadataFile, JSON.stringify(stagedFiles));
767 + try {
768 + return await runCliAgainst(
769 + baseUrl,
770 + [
771 + 'execute',
772 + 'CANVA_CREATE_DESIGN_IMPORT_JOB',
773 + '--skip-connection-check',
774 + '--file',
775 + file,
776 + '-d',
777 + '{"title":"Deck"}',
778 + ],
779 + {
780 + env: { COMPOSIO_RUN_STAGED_FILES_FILE: stagedFiles ? metadataFile : '' },
781 + }
782 + );
783 + } finally {
784 + fs.rmSync(metadataDirectory, { recursive: true, force: true });
785 + }
786 + };
787 +
788 + it.each([
789 + {
790 + name: 'a .pptx path',
791 + onDisk: 'deck.pptx',
792 + staged: undefined,
793 + filename: 'deck.pptx',
794 + mimetype: PPTX,
795 + },
796 + {
797 + name: 'an extensionless path with no staged name or type',
798 + onDisk: 'deck',
799 + staged: undefined,
800 + filename: 'deck',
801 + mimetype: 'application/octet-stream',
802 + },
803 + {
804 + name: 'a path `composio run` staged an extensionless PPTX File at',
805 + onDisk: 'file-a1b2c3d4',
806 + staged: { name: 'deck', mimetype: PPTX },
807 + filename: 'deck',
808 + mimetype: PPTX,
809 + },
810 + {
811 + name: 'a path `composio run` staged a `.env.example` File at',
812 + onDisk: 'file-a1b2c3d4.example',
813 + staged: { name: '.env.example', mimetype: 'text/plain' },
814 + filename: '.env.example',
815 + mimetype: 'text/plain',
816 + },
817 + ])(
818 + '[Given] $name [Then] `composio execute --file` requests the upload as $filename, $mimetype',
819 + ({ onDisk, staged, filename, mimetype }) => {
820 + const file = path.join(tempy.temporaryDirectory(), onDisk);
821 + fs.writeFileSync(file, 'PK fake pptx');
822 + const presignRequests: Array<unknown> = [];
823 + return withHttpServer(fakeUploadBackend(presignRequests), async baseUrl => {
824 + await uploadWith(baseUrl, file, staged && { [file]: staged });
825 +
826 + expect(presignRequests).toEqual([
827 + expect.objectContaining({ filename, mimetype, toolkit_slug: 'canva' }),
828 + ]);
829 + });
830 + },
831 + 30_000
832 + );
833 +
834 + it('[Given] a `.env` path staged under a harmless name [Then] the denylist still refuses it', () => {
835 + const file = path.join(tempy.temporaryDirectory(), '.env');
836 + fs.writeFileSync(file, 'SECRET=value');
837 + const presignRequests: Array<unknown> = [];
838 + return withHttpServer(fakeUploadBackend(presignRequests), async baseUrl => {
839 + const result = await uploadWith(baseUrl, file, {
840 + [file]: { name: 'deck.pptx', mimetype: PPTX },
841 + });
842 +
843 + expect(result.status).toBe(1);
844 + expect(`${result.stdout}${result.stderr}`).toContain('looks like a credential');
845 + expect(presignRequests).toEqual([]);
846 + });
847 + }, 30_000);
848 +});
ts/packages/cli/test/src/config/app.test.ts
+3
@@ -34,6 +34,7 @@ describe('APP_CONFIG', () => {
34 CLI_INVOCATION_ORIGIN: undefined,
35 CLI_PARENT_RUN_ID: undefined,
36 RUN_OUTPUT_DIR: undefined,
37 + RUN_STAGED_FILES_FILE: undefined,
38 DISABLE_CONNECTED_ACCOUNT_CACHE: true,
39 TOOLKIT_VERSIONS: Option.none(),
40 });
@@ -67,6 +68,7 @@ describe('APP_CONFIG', () => {
68 COMPOSIO_CLI_INVOCATION_ORIGIN: 'run',
69 COMPOSIO_CLI_PARENT_RUN_ID: 'run_parent',
70 COMPOSIO_RUN_OUTPUT_DIR: '\t/tmp/composio-output\n',
71 + COMPOSIO_RUN_STAGED_FILES_FILE: '/tmp/composio-output/metadata.json',
72 COMPOSIO_DISABLE_CONNECTED_ACCOUNT_CACHE: 'OFF',
73 COMPOSIO_TOOLKIT_VERSION_GMAIL: '20250901_00',
74 });
@@ -92,6 +94,7 @@ describe('APP_CONFIG', () => {
94 CLI_INVOCATION_ORIGIN: 'run',
95 CLI_PARENT_RUN_ID: 'run_parent',
96 RUN_OUTPUT_DIR: '/tmp/composio-output',
97 + RUN_STAGED_FILES_FILE: '/tmp/composio-output/metadata.json',
98 DISABLE_CONNECTED_ACCOUNT_CACHE: false,
99 TOOLKIT_VERSIONS: Option.some({ GMAIL: '20250901_00' }),
100 });
ts/packages/cli/test/src/services/run-helpers-runtime.test.ts
+157
@@ -1,5 +1,9 @@
1 +import * as path from 'node:path';
2 +import * as fs from 'node:fs';
3 +import * as os from 'node:os';
4 import { inspect } from 'node:util';
5 import { Predicate } from 'effect';
6 +import { isBlockedSensitiveFileUploadPath } from '@composio/core';
7 import { afterEach, assert, describe, expect, it, vi } from 'vitest';
8 import { installRunHelpers, parseJson } from 'src/services/run-helpers-runtime';
9 import { ToolInputRequiredError } from 'src/utils/tool-input-required';
@@ -361,6 +365,159 @@ describe('run-helpers-runtime', () => {
365 });
366 });
367
368 + it('[Given] file labels larger than the Linux environment limit [Then] the child reads all labels from a temporary manifest', async () => {
369 + const outputDir = fs.mkdtempSync(path.join(os.tmpdir(), 'composio-run-batch-'));
370 + const childScript = [
371 + 'const fs = require("node:fs");',
372 + 'const manifestPath = process.env.COMPOSIO_RUN_STAGED_FILES_FILE;',
373 + 'const manifest = fs.readFileSync(manifestPath, "utf8");',
374 + 'const labels = JSON.parse(manifest);',
375 + 'const input = process.argv[process.argv.indexOf("--data") + 1];',
376 + 'const data = JSON.parse(fs.readFileSync(input.slice(1), "utf8"));',
377 + 'console.log(JSON.stringify({ successful: true, data: { manifestPath, manifestBytes: Buffer.byteLength(manifest), mode: fs.statSync(manifestPath).mode & 0o777, count: Object.keys(labels).length, dataCount: data.files.length, first: labels[data.files[0]], last: labels[data.files.at(-1)] } }));',
378 + ].join('\n');
379 + const mimeType = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
380 + const fileName = (i: number) => `${i}-${'a'.repeat(200)}.pptx`;
381 + try {
382 + await installRunHelpers({
383 + cliPrefix: [process.execPath, '-e', childScript],
384 + helperContext: { runOutputDir: outputDir },
385 + });
386 + const result = await readInstalledFunction('execute')('TEST_UPLOAD', {
387 + files: Array.from(
388 + { length: 512 },
389 + (_, i) => new File(['PK'], fileName(i), { type: mimeType })
390 + ),
391 + });
392 + assert(
393 + Predicate.hasProperty(result, 'data') &&
394 + Predicate.hasProperty(result.data, 'manifestPath') &&
395 + typeof result.data.manifestPath === 'string'
396 + );
397 + expect(result.data).toMatchObject({
398 + count: 512,
399 + dataCount: 512,
400 + mode: 0o600,
401 + first: { name: fileName(0), mimetype: mimeType },
402 + last: { name: fileName(511), mimetype: mimeType },
403 + });
404 + assert(
405 + Predicate.hasProperty(result.data, 'manifestBytes') &&
406 + typeof result.data.manifestBytes === 'number'
407 + );
408 + expect(result.data.manifestBytes).toBeGreaterThan(128 * 1024);
409 + expect(Buffer.byteLength(result.data.manifestPath)).toBeLessThan(1024);
410 + expect(fs.existsSync(result.data.manifestPath)).toBe(false);
411 + } finally {
412 + fs.rmSync(outputDir, { recursive: true, force: true });
413 + }
414 + });
415 +
416 + it.each([true, false])(
417 + '[Given] a child fails with JSON result=%s [Then] its metadata is removed',
418 + async reportsResult => {
419 + const outputDir = fs.mkdtempSync(path.join(os.tmpdir(), 'composio-run-failure-'));
420 + const observedPath = path.join(outputDir, 'observed-manifest');
421 + const childScript = [
422 + 'const fs = require("node:fs");',
423 + `fs.writeFileSync(${JSON.stringify(observedPath)}, process.env.COMPOSIO_RUN_STAGED_FILES_FILE);`,
424 + ...(reportsResult
425 + ? ['console.log(JSON.stringify({ successful: false, error: "refused" }));']
426 + : []),
427 + 'process.exit(1);',
428 + ].join('\n');
429 + try {
430 + await installRunHelpers({ cliPrefix: [process.execPath, '-e', childScript] });
431 + await expect(
432 + readInstalledFunction('execute')('TEST_UPLOAD', { file: new File(['x'], 'x.txt') })
433 + ).rejects.toBeInstanceOf(Error);
434 + const manifestPath = fs.readFileSync(observedPath, 'utf8');
435 + expect(fs.existsSync(path.dirname(manifestPath))).toBe(false);
436 + } finally {
437 + fs.rmSync(outputDir, { recursive: true, force: true });
438 + }
439 + }
440 + );
441 +
442 + it('[Given] a stale inherited metadata path and no Files [Then] the child receives no metadata path', async () => {
443 + vi.stubEnv('COMPOSIO_RUN_STAGED_FILES_FILE', '/stale/metadata.json');
444 + const childScript =
445 + 'console.log(JSON.stringify({ successful: true, data: { manifestPath: process.env.COMPOSIO_RUN_STAGED_FILES_FILE } }));';
446 + await installRunHelpers({ cliPrefix: [process.execPath, '-e', childScript] });
447 + expect(await readInstalledFunction('execute')('TEST_UPLOAD', { text: 'plain' })).toMatchObject({
448 + data: { manifestPath: '' },
449 + });
450 + });
451 +
452 + it("[Given] File and Blob arguments [Then] the spawned `composio execute` gets generated paths, and each one's own name and type beside them", async () => {
453 + // Echoes the `--data` JSON and the staged files it was spawned with, and
454 + // whether each staged file exists.
455 + const childScript = [
456 + 'const fs = require("node:fs");',
457 + 'const data = JSON.parse(process.argv[process.argv.indexOf("--data") + 1]);',
458 + 'const stagedFiles = JSON.parse(fs.readFileSync(process.env.COMPOSIO_RUN_STAGED_FILES_FILE, "utf8"));',
459 + 'const exists = Object.fromEntries(Object.entries(data).map(([k, v]) => [k, fs.existsSync(v)]));',
460 + 'console.log(JSON.stringify({ successful: true, data: { data, stagedFiles, exists } }));',
461 + ].join('\n');
462 + // A value the run process inherited must not reach the child.
463 + vi.stubEnv('COMPOSIO_RUN_STAGED_FILES_FILE', '/stale/metadata.json');
464 + await installRunHelpers({ cliPrefix: [process.execPath, '-e', childScript] });
465 + const PPTX = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
466 +
467 + const result = await readInstalledFunction('execute')('CANVA_CREATE_DESIGN_IMPORT_JOB', {
468 + named: new File(['PK'], 'deck.pptx', { type: PPTX }),
469 + sameName: new File(['PK'], 'deck.pptx', { type: PPTX }),
470 + extensionless: new File(['PK'], 'deck', { type: PPTX }),
471 + traversal: new File(['PK'], '../escape.pptx', { type: PPTX }),
472 + untyped: new File(['hi'], 'notes.txt'),
473 + envExample: new File(['EXAMPLE=value'], '.env.example', { type: 'text/plain' }),
474 + privateKeyName: new File(['not a key'], 'keys/id_rsa'),
475 + blob: new Blob(['PK'], { type: PPTX }),
476 + });
477 +
478 + assert(
479 + Predicate.hasProperty(result, 'data') &&
480 + Predicate.hasProperty(result.data, 'data') &&
481 + Predicate.isObject(result.data.data) &&
482 + Predicate.hasProperty(result.data, 'stagedFiles')
483 + );
484 + const staged = result.data.data;
485 + const stagedPaths = Object.values(staged).map(String);
486 + // Every File is staged under a generated name, with its extension when it has one…
487 + expect(stagedPaths.map(stagedPath => path.basename(stagedPath))).toEqual([
488 + expect.stringMatching(/^file-[0-9a-f]{8}\.pptx$/),
489 + expect.stringMatching(/^file-[0-9a-f]{8}\.pptx$/),
490 + expect.stringMatching(/^file-[0-9a-f]{8}$/),
491 + expect.stringMatching(/^file-[0-9a-f]{8}\.pptx$/),
492 + expect.stringMatching(/^file-[0-9a-f]{8}\.txt$/),
493 + expect.stringMatching(/^file-[0-9a-f]{8}\.example$/),
494 + expect.stringMatching(/^file-[0-9a-f]{8}$/),
495 + expect.stringMatching(/^file-[0-9a-f]{8}\.bin$/),
496 + ]);
497 + // …that the child's denylist does not refuse, and that two Files with one name do not share.
498 + expect(stagedPaths.filter(stagedPath => isBlockedSensitiveFileUploadPath(stagedPath))).toEqual(
499 + []
500 + );
501 + expect(new Set(stagedPaths).size).toBe(stagedPaths.length);
502 + expect(result.data).toMatchObject({
503 + exists: Object.fromEntries(Object.keys(staged).map(key => [key, true])),
504 + });
505 + // The child uploads each one under its own name and type.
506 + expect(result.data.stagedFiles).toEqual({
507 + [String(staged.named)]: { name: 'deck.pptx', mimetype: PPTX },
508 + [String(staged.sameName)]: { name: 'deck.pptx', mimetype: PPTX },
509 + [String(staged.extensionless)]: { name: 'deck', mimetype: PPTX },
510 + [String(staged.traversal)]: { name: 'escape.pptx', mimetype: PPTX },
511 + [String(staged.untyped)]: { name: 'notes.txt' },
512 + [String(staged.envExample)]: { name: '.env.example', mimetype: 'text/plain' },
513 + [String(staged.privateKeyName)]: { name: 'id_rsa' },
514 + [String(staged.blob)]: {
515 + name: expect.stringMatching(/^file-[0-9a-f]{8}\.bin$/),
516 + mimetype: PPTX,
517 + },
518 + });
519 + });
520 +
521 it('[Given] a CLI child exits non-zero without a failed result [Then] the helper rejects with the exit code', async () => {
522 const childScript = ['console.error("boom");', 'process.exit(2);'].join('\n');
523 await installRunHelpers({ cliPrefix: [process.execPath, '-e', childScript] });
ts/packages/cli/test/src/services/tool-file-uploads.test.ts
+185 -54
@@ -15,6 +15,7 @@ import {
15 MAX_URL_UPLOAD_SIZE_BYTES,
16 } from '@composio/core';
17 import {
18 + readRunStagedFiles,
19 findFileUploadablePaths,
20 findLocalPathArguments,
21 schemaHasFileUploadable,
@@ -109,71 +110,59 @@ describe('file argument paths', () => {
110 });
111 });
112
112 -describe('local file MIME metadata', () => {
113 - afterEach(() => {
114 - vi.unstubAllGlobals();
115 - vi.restoreAllMocks();
113 +// The client over a transport that answers the presigned-URL request with
114 +// `presigned`, and records each request it receives.
115 +const makeClient = (
116 + presigned: { readonly new_presigned_url: string; readonly key: string } = {
117 + new_presigned_url: 'https://1.1.1.1/put',
118 + key: 's3key-123',
119 + }
120 +) => stubComposioClient(() => Response.json(presigned));
121 +
122 +describe('readRunStagedFiles', () => {
123 + it.effect('loads original upload names and MIME types from the manifest', () => {
124 + const root = mkdtempSync(path.join(os.tmpdir(), 'composio-labels-'));
125 + const file = path.join(root, 'files.json');
126 + writeFileSync(
127 + file,
128 + JSON.stringify({
129 + '/tmp/file-1': { name: 'deck', mimetype: 'application/pdf' },
130 + '/tmp/file-2': { name: 'notes.txt' },
131 + })
132 + );
133 + return Effect.gen(function* () {
134 + const fsApi = yield* FileSystem.FileSystem;
135 + expect(yield* readRunStagedFiles(fsApi, file)).toEqual(
136 + new Map([
137 + ['/tmp/file-1', { name: 'deck', mimetype: 'application/pdf' }],
138 + ['/tmp/file-2', { name: 'notes.txt' }],
139 + ])
140 + );
141 + }).pipe(
142 + Effect.provide(BunFileSystem.layer),
143 + Effect.ensuring(Effect.sync(() => rmSync(root, { recursive: true, force: true })))
144 + );
145 });
146
118 - it.effect.each([
119 - { filename: 'picture.png', expectedMime: 'image/png' },
120 - { filename: 'picture.JPG', expectedMime: 'image/jpeg' },
121 - { filename: 'document.pdf', expectedMime: 'application/pdf' },
122 - {
123 - filename: 'slides.pptx',
124 - expectedMime: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
125 - },
126 - {
127 - filename: 'document.docx',
128 - expectedMime: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
129 - },
130 - { filename: 'unknown.extension-dogfood', expectedMime: 'application/octet-stream' },
131 - { filename: 'no-extension', expectedMime: 'application/octet-stream' },
132 - ])(
133 - 'uses the same MIME for the request, upload, and hydrated $filename',
134 - ({ filename, expectedMime }) => {
135 - const root = mkdtempSync(path.join(os.tmpdir(), 'composio-mime-'));
136 - const file = path.join(root, filename);
137 - writeFileSync(file, 'fixture bytes');
138 - const { client, requests } = makeClient();
139 - const uploadFetch = vi.fn(async () => new Response(null, { status: 200 }));
140 - vi.stubGlobal('fetch', uploadFetch);
147 + it.effect.each(['not json', '["a"]', '{"/a":1}', '{"/a":{"mimetype":"text/plain"}}', undefined])(
148 + 'rejects unreadable or invalid metadata (%s) instead of dropping labels',
149 + content => {
150 + const root = mkdtempSync(path.join(os.tmpdir(), 'composio-labels-'));
151 + const file = path.join(root, 'files.json');
152 + if (content !== undefined) writeFileSync(file, content);
153 return Effect.gen(function* () {
154 const fsApi = yield* FileSystem.FileSystem;
143 - const pathApi = yield* Path.Path;
144 - const result = yield* uploadToolInputFiles({
145 - fs: fsApi,
146 - path: pathApi,
147 - toolSlug: 'GMAIL_SEND_EMAIL',
148 - arguments_: { attachment: file },
149 - inputSchema,
150 - client,
151 - });
152 - expect(requests[0]?.body).toMatchObject({ mimetype: expectedMime });
153 - expect(uploadFetch).toHaveBeenCalledWith(
154 - 'https://1.1.1.1/put',
155 - expect.objectContaining({
156 - headers: expect.objectContaining({ 'Content-Type': expectedMime }),
157 - })
158 - );
159 - expect(result.attachment).toMatchObject({ name: filename, mimetype: expectedMime });
155 + const failure = yield* Effect.flip(readRunStagedFiles(fsApi, file));
156 + expect(failure).toBeInstanceOf(ToolFileUploadError);
157 + expect(failure.reason).toBe('source-read');
158 }).pipe(
161 - Effect.provide(Layer.mergeAll(BunFileSystem.layer, BunPath.layer)),
159 + Effect.provide(BunFileSystem.layer),
160 Effect.ensuring(Effect.sync(() => rmSync(root, { recursive: true, force: true })))
161 );
162 }
163 );
164 });
165
168 -// The client over a transport that answers the presigned-URL request with
169 -// `presigned`, and records each request it receives.
170 -const makeClient = (
171 - presigned: { readonly new_presigned_url: string; readonly key: string } = {
172 - new_presigned_url: 'https://1.1.1.1/put',
173 - key: 's3key-123',
174 - }
175 -) => stubComposioClient(() => Response.json(presigned));
176 -
166 describe('uploadToolInputFiles — sensitive-path guard (issue #3746)', () => {
167 afterEach(() => {
168 vi.unstubAllGlobals();
@@ -309,6 +298,148 @@ describe('uploadToolInputFiles — sensitive-path guard (issue #3746)', () => {
298 });
299 });
300
301 +describe('uploadToolInputFiles — MIME type of a local file (issue #4984)', () => {
302 + afterEach(() => {
303 + vi.unstubAllGlobals();
304 + vi.restoreAllMocks();
305 + });
306 +
307 + const PPTX = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
308 + const canvaSchema = {
309 + type: 'object',
310 + properties: {
311 + file: { file_uploadable: true, type: 'object' },
312 + title: { type: 'string' },
313 + mime_type: { type: 'string' },
314 + },
315 + };
316 +
317 + it.effect.each([
318 + // A file the caller did not stage takes the type of its extension.
319 + { onDisk: 'deck.pptx', staged: undefined, name: 'deck.pptx', mimetype: PPTX },
320 + { onDisk: 'Deck.PPTX', staged: undefined, name: 'Deck.PPTX', mimetype: PPTX },
321 + { onDisk: 'picture.png', staged: undefined, name: 'picture.png', mimetype: 'image/png' },
322 + { onDisk: 'picture.JPG', staged: undefined, name: 'picture.JPG', mimetype: 'image/jpeg' },
323 + {
324 + onDisk: 'document.pdf',
325 + staged: undefined,
326 + name: 'document.pdf',
327 + mimetype: 'application/pdf',
328 + },
329 + {
330 + onDisk: 'document.docx',
331 + staged: undefined,
332 + name: 'document.docx',
333 + mimetype: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
334 + },
335 + {
336 + onDisk: 'unknown.extension-dogfood',
337 + staged: undefined,
338 + name: 'unknown.extension-dogfood',
339 + mimetype: 'application/octet-stream',
340 + },
341 + {
342 + onDisk: 'no-extension',
343 + staged: undefined,
344 + name: 'no-extension',
345 + mimetype: 'application/octet-stream',
346 + },
347 + // What its caller staged it under (a `composio run` File's own name and type)
348 + // wins over the path's.
349 + { onDisk: 'file-a1', staged: { name: 'deck', mimetype: PPTX }, name: 'deck', mimetype: PPTX },
350 + {
351 + onDisk: 'file-a1.pdf',
352 + staged: { name: 'deck.pdf', mimetype: PPTX },
353 + name: 'deck.pdf',
354 + mimetype: PPTX,
355 + },
356 + { onDisk: 'file-a1.pptx', staged: { name: 'deck.pptx' }, name: 'deck.pptx', mimetype: PPTX },
357 + // Names the denylist refuses on a path are only labels here.
358 + {
359 + onDisk: 'file-a1.example',
360 + staged: { name: '.env.example', mimetype: 'text/plain' },
361 + name: '.env.example',
362 + mimetype: 'text/plain',
363 + },
364 + {
365 + onDisk: 'file-a1',
366 + staged: { name: 'id_rsa' },
367 + name: 'id_rsa',
368 + mimetype: 'application/octet-stream',
369 + },
370 + ])(
371 + '[Given] $onDisk staged as $staged [Then] the presign request, the PUT and the tool input carry $name and $mimetype',
372 + ({ onDisk, staged, name, mimetype }) => {
373 + const root = mkdtempSync(path.join(os.tmpdir(), 'composio-upload-'));
374 + const file = path.join(root, onDisk);
375 + writeFileSync(file, 'PK fake pptx');
376 +
377 + const { client, requests } = makeClient();
378 + const uploadFetch = vi.fn(async (_url: string, _init: RequestInit) => ({
379 + ok: true,
380 + statusText: 'OK',
381 + }));
382 + vi.stubGlobal('fetch', uploadFetch);
383 +
384 + return Effect.gen(function* () {
385 + const fsApi = yield* FileSystem.FileSystem;
386 + const pathApi = yield* Path.Path;
387 + const result = yield* uploadToolInputFiles({
388 + fs: fsApi,
389 + path: pathApi,
390 + toolSlug: 'CANVA_CREATE_DESIGN_IMPORT_JOB',
391 + arguments_: { file, title: 'Deck', mime_type: PPTX },
392 + inputSchema: canvaSchema,
393 + client,
394 + stagedFiles: new Map(staged === undefined ? [] : [[file, staged]]),
395 + });
396 +
397 + expect(requests).toMatchObject([
398 + { body: { filename: name, mimetype, toolkit_slug: 'canva' } },
399 + ]);
400 + expect(uploadFetch.mock.calls[0]?.[1]?.headers).toMatchObject({
401 + 'Content-Type': mimetype,
402 + });
403 + expect(result).toEqual({
404 + file: { name, mimetype, s3key: 's3key-123' },
405 + title: 'Deck',
406 + mime_type: PPTX,
407 + });
408 + }).pipe(
409 + Effect.provide(Layer.mergeAll(BunFileSystem.layer, BunPath.layer)),
410 + Effect.ensuring(Effect.sync(() => rmSync(root, { recursive: true, force: true })))
411 + );
412 + }
413 + );
414 +
415 + it.effect(
416 + '[Given] a sensitive path staged under a harmless name [Then] it is still refused',
417 + () =>
418 + Effect.gen(function* () {
419 + const fsApi = yield* FileSystem.FileSystem;
420 + const pathApi = yield* Path.Path;
421 + const { client, requests } = makeClient();
422 + const envFile = path.join(os.homedir(), '.env');
423 +
424 + // The staged-file labels rename an upload; they never exempt a path from the denylist.
425 + const failure = yield* Effect.flip(
426 + uploadToolInputFiles({
427 + fs: fsApi,
428 + path: pathApi,
429 + toolSlug: 'CANVA_CREATE_DESIGN_IMPORT_JOB',
430 + arguments_: { file: envFile, title: 'Deck' },
431 + inputSchema: canvaSchema,
432 + client,
433 + stagedFiles: new Map([[envFile, { name: 'deck.pptx', mimetype: PPTX }]]),
434 + })
435 + );
436 +
437 + expect(failure.cause).toBeInstanceOf(ComposioSensitiveFilePathBlockedError);
438 + expect(requests).toEqual([]);
439 + }).pipe(Effect.provide(Layer.mergeAll(BunFileSystem.layer, BunPath.layer)))
440 + );
441 +});
442 +
443 describe('uploadToolInputFiles — presigned-URL request', () => {
444 afterEach(() => {
445 vi.unstubAllGlobals();
ts/packages/core/package.json
+1
@@ -126,6 +126,7 @@
126 "ajv": "^8.20.0",
127 "fast-check": "^4.10.2",
128 "hono": "catalog:",
129 + "mime": "^4.1.1",
130 "tsdown": "catalog:",
131 "tsx": "catalog:",
132 "typedoc": "^0.28.20",
ts/packages/core/src/utils/fileUtils.node.ts
+4 -2
@@ -11,6 +11,7 @@ import { assertSafeFileUploadPath } from './sensitiveFileUploadPaths';
11 import { assertPathInsideUploadDirs } from './uploadDirAllowlist.node';
12 import { ssrfSafeFetch } from './ssrfGuard.node';
13 import { readResponseBodyWithLimit } from './readResponseBody';
14 +import { getMimeTypeFromFileName } from './mime';
15
16 /**
17 * Options for {@link getFileDataAfterUploadingToS3} (S3 presigned upload from local path, URL, or File).
@@ -102,7 +103,8 @@ const getExtensionFromMimeType = (mimeType: string): string => {
103 const cleanMimeType = mimeType.split(';')[0].toLowerCase().trim();
104
105 // Try exact match first
105 - if (mimeToExt[cleanMimeType]) {
106 + // An own property only: `constructor` or `__proto__` must not reach Object.prototype.
107 + if (Object.hasOwn(mimeToExt, cleanMimeType)) {
108 return mimeToExt[cleanMimeType];
109 }
110
@@ -160,7 +162,7 @@ const readFileContent = async (
162 content instanceof Uint8Array
163 ? uint8ArrayToBase64(content)
164 : uint8ArrayToBase64(new TextEncoder().encode(content)),
163 - mimeType: 'application/octet-stream',
165 + mimeType: getMimeTypeFromFileName(filePath),
166 };
167 } catch (error) {
168 throw new Error(`Error reading file at ${filePath}: ${error}`);
ts/packages/core/src/utils/mime.ts
+346 -1
@@ -42,7 +42,8 @@ export function getExtensionFromMimeType(mimeType: string): string {
42
43 const cleanMimeType = mimeType.split(';')[0].toLowerCase().trim();
44
45 - if (mimeToExt[cleanMimeType]) {
45 + // An own property only: `constructor` or `__proto__` must not reach Object.prototype.
46 + if (Object.hasOwn(mimeToExt, cleanMimeType)) {
47 return mimeToExt[cleanMimeType];
48 }
49
@@ -73,3 +74,347 @@ export function getExtensionFromMimeType(mimeType: string): string {
74
75 return 'bin';
76 }
77 +
78 +// A local file has no Content-Type of its own, so its MIME type is inferred from
79 +// its name's extension, as the Python SDK does (`composio.utils.mimetypes.guess`).
80 +// Tools validate the `mimetype` of an uploaded file (Canva's design import rejects
81 +// `application/octet-stream`, issue #4984), so the generic type is a last resort.
82 +export const DEFAULT_MIME_TYPE = 'application/octet-stream';
83 +
84 +// Extension (lowercase, no leading dot) -> MIME type. Each value is what the
85 +// `mime` package returns, which the CLI's `composio execute` uses for the same
86 +// files. The Python SDK mirrors this table in `composio/utils/mimetypes.py`;
87 +// keep the two identical.
88 +export const MIME_TYPES_BY_EXTENSION: Readonly<Record<string, string>> = {
89 + '3g2': 'video/3gpp2',
90 + '3gp': 'video/3gpp',
91 + '3gpp': 'video/3gpp',
92 + '7z': 'application/x-7z-compressed',
93 + aab: 'application/x-authorware-bin',
94 + aac: 'audio/aac',
95 + aam: 'application/x-authorware-map',
96 + aas: 'application/x-authorware-seg',
97 + adts: 'audio/aac',
98 + ai: 'application/postscript',
99 + aif: 'audio/x-aiff',
100 + aifc: 'audio/x-aiff',
101 + aiff: 'audio/x-aiff',
102 + arc: 'application/x-freearc',
103 + arj: 'application/x-arj',
104 + asf: 'video/x-ms-asf',
105 + asm: 'text/x-asm',
106 + asx: 'video/x-ms-asf',
107 + au: 'audio/basic',
108 + avi: 'video/x-msvideo',
109 + avif: 'image/avif',
110 + bat: 'application/x-msdownload',
111 + bcpio: 'application/x-bcpio',
112 + bmp: 'image/bmp',
113 + book: 'application/vnd.framemaker',
114 + boz: 'application/x-bzip2',
115 + bz: 'application/x-bzip',
116 + bz2: 'application/x-bzip2',
117 + c: 'text/x-c',
118 + cat: 'application/vnd.ms-pki.seccat',
119 + cc: 'text/x-c',
120 + cco: 'application/x-cocoa',
121 + cdf: 'application/x-netcdf',
122 + cer: 'application/pkix-cert',
123 + chat: 'application/x-chat',
124 + class: 'application/java-vm',
125 + com: 'application/x-msdownload',
126 + conf: 'text/plain',
127 + cpio: 'application/x-cpio',
128 + cpp: 'text/x-c',
129 + cpt: 'application/mac-compactpro',
130 + crl: 'application/pkix-crl',
131 + crt: 'application/x-x509-ca-cert',
132 + csh: 'application/x-csh',
133 + css: 'text/css',
134 + csv: 'text/csv',
135 + cxx: 'text/x-c',
136 + dcr: 'application/x-director',
137 + def: 'text/plain',
138 + der: 'application/x-x509-ca-cert',
139 + dir: 'application/x-director',
140 + doc: 'application/msword',
141 + docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
142 + dot: 'application/msword',
143 + dp: 'application/vnd.osgi.dp',
144 + dvi: 'application/x-dvi',
145 + dwf: 'model/vnd.dwf',
146 + dwg: 'image/vnd.dwg',
147 + dxf: 'image/vnd.dxf',
148 + dxr: 'application/x-director',
149 + eml: 'message/rfc822',
150 + eot: 'application/vnd.ms-fontobject',
151 + eps: 'application/postscript',
152 + epub: 'application/epub+zip',
153 + etx: 'text/x-setext',
154 + evy: 'application/x-envoy',
155 + f: 'text/x-fortran',
156 + f77: 'text/x-fortran',
157 + f90: 'text/x-fortran',
158 + fdf: 'application/fdf',
159 + flac: 'audio/x-flac',
160 + fli: 'video/x-fli',
161 + flo: 'application/vnd.micrografx.flo',
162 + flx: 'text/vnd.fmi.flexstor',
163 + for: 'text/x-fortran',
164 + fpx: 'image/vnd.fpx',
165 + g3: 'image/g3fax',
166 + gif: 'image/gif',
167 + gtar: 'application/x-gtar',
168 + gz: 'application/gzip',
169 + h: 'text/x-c',
170 + hdf: 'application/x-hdf',
171 + heic: 'image/heic',
172 + heif: 'image/heif',
173 + hh: 'text/x-c',
174 + hlp: 'application/winhlp',
175 + hpgl: 'application/vnd.hp-hpgl',
176 + hqx: 'application/mac-binhex40',
177 + htc: 'text/x-component',
178 + htm: 'text/html',
179 + html: 'text/html',
180 + ice: 'x-conference/x-cooltalk',
181 + ico: 'image/vnd.microsoft.icon',
182 + ics: 'text/calendar',
183 + ief: 'image/ief',
184 + iges: 'model/iges',
185 + igs: 'model/iges',
186 + jam: 'application/vnd.jam',
187 + java: 'text/x-java-source',
188 + jfif: 'image/pjpeg',
189 + jpe: 'image/jpeg',
190 + jpeg: 'image/jpeg',
191 + jpg: 'image/jpeg',
192 + js: 'text/javascript',
193 + json: 'application/json',
194 + kar: 'audio/midi',
195 + key: 'application/vnd.apple.keynote',
196 + latex: 'application/x-latex',
197 + lha: 'application/x-lzh-compressed',
198 + list: 'text/plain',
199 + log: 'text/plain',
200 + lzh: 'application/x-lzh-compressed',
201 + m1v: 'video/mpeg',
202 + m2a: 'audio/mpeg',
203 + m2v: 'video/mpeg',
204 + m3u: 'audio/x-mpegurl',
205 + m3u8: 'application/vnd.apple.mpegurl',
206 + m4a: 'audio/mp4',
207 + man: 'text/troff',
208 + map: 'application/json',
209 + mcd: 'application/vnd.mcd',
210 + md: 'text/markdown',
211 + me: 'text/troff',
212 + mht: 'message/rfc822',
213 + mhtml: 'message/rfc822',
214 + mid: 'audio/midi',
215 + midi: 'audio/midi',
216 + mif: 'application/vnd.mif',
217 + mime: 'message/rfc822',
218 + mjs: 'text/javascript',
219 + mka: 'audio/x-matroska',
220 + mkv: 'video/x-matroska',
221 + mov: 'video/quicktime',
222 + movie: 'video/x-sgi-movie',
223 + mp2: 'audio/mpeg',
224 + mp3: 'audio/mpeg',
225 + mp4: 'video/mp4',
226 + mpc: 'application/vnd.mophun.certificate',
227 + mpe: 'video/mpeg',
228 + mpeg: 'video/mpeg',
229 + mpg: 'video/mpeg',
230 + mpga: 'audio/mpeg',
231 + mpp: 'application/dash-patch+xml',
232 + mpt: 'application/vnd.ms-project',
233 + mrc: 'application/marc',
234 + ms: 'text/troff',
235 + nc: 'application/x-netcdf',
236 + nsc: 'application/x-conference',
237 + numbers: 'application/vnd.apple.numbers',
238 + obj: 'model/obj',
239 + oda: 'application/oda',
240 + odg: 'application/vnd.oasis.opendocument.graphics',
241 + odp: 'application/vnd.oasis.opendocument.presentation',
242 + ods: 'application/vnd.oasis.opendocument.spreadsheet',
243 + odt: 'application/vnd.oasis.opendocument.text',
244 + ogg: 'audio/ogg',
245 + opus: 'audio/ogg',
246 + otf: 'font/otf',
247 + p: 'text/x-pascal',
248 + p10: 'application/pkcs10',
249 + p12: 'application/x-pkcs12',
250 + p7c: 'application/pkcs7-mime',
251 + p7m: 'application/pkcs7-mime',
252 + p7r: 'application/x-pkcs7-certreqresp',
253 + p7s: 'application/pkcs7-signature',
254 + pages: 'application/vnd.apple.pages',
255 + pas: 'text/x-pascal',
256 + pbm: 'image/x-portable-bitmap',
257 + pcl: 'application/vnd.hp-pcl',
258 + pct: 'image/x-pict',
259 + pcx: 'image/vnd.zbrush.pcx',
260 + pdb: 'application/vnd.palm',
261 + pdf: 'application/pdf',
262 + pfx: 'application/x-pkcs12',
263 + pgm: 'image/x-portable-graymap',
264 + pic: 'image/x-pict',
265 + pl: 'application/x-perl',
266 + pm: 'application/x-perl',
267 + png: 'image/png',
268 + pnm: 'image/x-portable-anymap',
269 + pot: 'application/vnd.ms-powerpoint',
270 + ppm: 'image/x-portable-pixmap',
271 + pps: 'application/vnd.ms-powerpoint',
272 + ppt: 'application/vnd.ms-powerpoint',
273 + pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
274 + pre: 'application/vnd.lotus-freelance',
275 + ps: 'application/postscript',
276 + psd: 'image/vnd.adobe.photoshop',
277 + pyo: 'model/vnd.pytha.pyox',
278 + qt: 'video/quicktime',
279 + ra: 'audio/x-pn-realaudio',
280 + ram: 'audio/x-pn-realaudio',
281 + rar: 'application/vnd.rar',
282 + ras: 'image/x-cmu-raster',
283 + rdf: 'application/rdf+xml',
284 + rgb: 'image/x-rgb',
285 + rm: 'application/vnd.rn-realmedia',
286 + rmi: 'audio/midi',
287 + rmp: 'audio/x-pn-realaudio-plugin',
288 + rng: 'application/xml',
289 + roff: 'text/troff',
290 + rpm: 'application/x-redhat-package-manager',
291 + rtf: 'application/rtf',
292 + rtx: 'text/richtext',
293 + s: 'text/x-asm',
294 + s3m: 'audio/s3m',
295 + scm: 'application/vnd.lotus-screencam',
296 + sdp: 'application/sdp',
297 + sea: 'application/x-sea',
298 + sgm: 'text/sgml',
299 + sgml: 'text/sgml',
300 + sh: 'application/x-sh',
301 + shar: 'application/x-shar',
302 + shtml: 'text/html',
303 + sid: 'image/x-mrsid-image',
304 + sit: 'application/x-stuffit',
305 + skd: 'application/vnd.koan',
306 + skm: 'application/vnd.koan',
307 + skp: 'application/vnd.koan',
308 + skt: 'application/vnd.koan',
309 + smi: 'application/smil+xml',
310 + smil: 'application/smil+xml',
311 + snd: 'audio/basic',
312 + spc: 'application/x-pkcs7-certificates',
313 + spl: 'application/x-futuresplash',
314 + src: 'application/x-wais-source',
315 + step: 'model/step',
316 + stl: 'model/stl',
317 + stp: 'model/step',
318 + sv4cpio: 'application/x-sv4cpio',
319 + sv4crc: 'application/x-sv4crc',
320 + svg: 'image/svg+xml',
321 + swf: 'application/x-shockwave-flash',
322 + t: 'text/troff',
323 + tar: 'application/x-tar',
324 + tcl: 'application/x-tcl',
325 + tex: 'application/x-tex',
326 + texi: 'application/x-texinfo',
327 + texinfo: 'application/x-texinfo',
328 + text: 'text/plain',
329 + tif: 'image/tiff',
330 + tiff: 'image/tiff',
331 + tr: 'text/troff',
332 + ts: 'video/mp2t',
333 + tsv: 'text/tab-separated-values',
334 + txt: 'text/plain',
335 + uri: 'text/uri-list',
336 + uris: 'text/uri-list',
337 + ustar: 'application/x-ustar',
338 + uu: 'text/x-uuencode',
339 + vcd: 'application/x-cdlink',
340 + vcf: 'text/x-vcard',
341 + vcs: 'text/x-vcalendar',
342 + viv: 'video/vnd.vivo',
343 + vox: 'application/x-authorware-bin',
344 + vrml: 'model/vrml',
345 + vsd: 'application/vnd.visio',
346 + vst: 'application/vnd.visio',
347 + vsw: 'application/vnd.visio',
348 + wasm: 'application/wasm',
349 + wav: 'audio/wav',
350 + wbmp: 'image/vnd.wap.wbmp',
351 + webm: 'video/webm',
352 + webmanifest: 'application/manifest+json',
353 + webp: 'image/webp',
354 + wmf: 'image/wmf',
355 + wml: 'text/vnd.wap.wml',
356 + wmlc: 'application/vnd.wap.wmlc',
357 + wmls: 'text/vnd.wap.wmlscript',
358 + wmlsc: 'application/vnd.wap.wmlscriptc',
359 + woff: 'font/woff',
360 + woff2: 'font/woff2',
361 + wpd: 'application/vnd.wordperfect',
362 + wri: 'application/x-mswrite',
363 + wrl: 'model/vrml',
364 + wsc: 'message/vnd.wfa.wsc',
365 + wsdl: 'application/wsdl+xml',
366 + xbm: 'image/x-xbitmap',
367 + xif: 'image/vnd.xiff',
368 + xla: 'application/vnd.ms-excel',
369 + xlc: 'application/vnd.ms-excel',
370 + xlm: 'application/vnd.ms-excel',
371 + xls: 'application/vnd.ms-excel',
372 + xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
373 + xlt: 'application/vnd.ms-excel',
374 + xlw: 'application/vnd.ms-excel',
375 + xm: 'audio/xm',
376 + xml: 'application/xml',
377 + xpm: 'image/x-xpixmap',
378 + xsl: 'application/xml',
379 + xul: 'application/vnd.mozilla.xul+xml',
380 + xwd: 'image/x-xwindowdump',
381 + xyz: 'chemical/x-xyz',
382 + yaml: 'text/yaml',
383 + yml: 'text/yaml',
384 + zip: 'application/zip',
385 + // Not known to the `mime` package; values from Python's standard `mimetypes`,
386 + // except `tgz`.
387 + '3gpp2': 'audio/3gpp2',
388 + ass: 'audio/aac',
389 + h5: 'application/x-hdf5',
390 + ksh: 'text/plain',
391 + loas: 'audio/aac',
392 + mpa: 'video/mpeg',
393 + nws: 'message/rfc822',
394 + ppa: 'application/vnd.ms-powerpoint',
395 + pwz: 'application/vnd.ms-powerpoint',
396 + py: 'text/x-python',
397 + pyc: 'application/x-python-code',
398 + tgz: 'application/gzip',
399 + wiz: 'application/msword',
400 + xlb: 'application/vnd.ms-excel',
401 + xpdl: 'application/xml',
402 +};
403 +
404 +/**
405 + * The MIME type of a file, from its name's extension; `application/octet-stream`
406 + * when the extension is missing or unknown. Accepts a bare name or a path.
407 + *
408 + * @example getMimeTypeFromFileName('/tmp/deck.pptx') // 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
409 + */
410 +export const getMimeTypeFromFileName = (fileName: string): string => {
411 + const baseName = fileName.split(/[\\/]/).pop() ?? '';
412 + const dot = baseName.lastIndexOf('.');
413 + // A leading dot is a hidden file's name (`.env`), not an extension.
414 + if (dot <= 0) return DEFAULT_MIME_TYPE;
415 + const extension = baseName.slice(dot + 1).toLowerCase();
416 + // An own property only: `report.constructor` must not reach Object.prototype.
417 + return Object.hasOwn(MIME_TYPES_BY_EXTENSION, extension)
418 + ? MIME_TYPES_BY_EXTENSION[extension]
419 + : DEFAULT_MIME_TYPE;
420 +};
ts/packages/core/test/utils/fileUtils.mimeType.test.ts new
+79
@@ -0,0 +1,79 @@
1 +import { afterEach, describe, expect, it, vi } from 'vitest';
2 +import * as os from 'node:os';
3 +import * as path from 'node:path';
4 +import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
5 +import ComposioClient from '@composio/client';
6 +import { DEFAULT_MIME_TYPE, getMimeTypeFromFileName } from '../../src/utils/mime';
7 +import { getFileDataAfterUploadingToS3 } from '../../src/utils/fileUtils.node';
8 +
9 +const PPTX = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
10 +
11 +describe('getMimeTypeFromFileName', () => {
12 + it.each([
13 + ['deck.pptx', PPTX],
14 + ['/tmp/dir/Report.PDF', 'application/pdf'],
15 + [
16 + 'C:\\Users\\me\\sheet.xlsx',
17 + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
18 + ],
19 + ['notes.md', 'text/markdown'],
20 + ['photo.jpeg', 'image/jpeg'],
21 + ['archive.tar.gz', 'application/gzip'],
22 + ])('maps %s to %s', (fileName, mimeType) => {
23 + expect(getMimeTypeFromFileName(fileName)).toBe(mimeType);
24 + });
25 +
26 + it.each([
27 + 'README',
28 + '.env',
29 + 'dir.d/file',
30 + 'blob.unknownext',
31 + '',
32 + // Object.prototype members are not extensions.
33 + 'report.constructor',
34 + 'report.__proto__',
35 + 'report.toString',
36 + 'report.hasOwnProperty',
37 + ])('falls back to octet-stream for %j', fileName => {
38 + expect(getMimeTypeFromFileName(fileName)).toBe(DEFAULT_MIME_TYPE);
39 + });
40 +});
41 +
42 +describe('getFileDataAfterUploadingToS3 — local path MIME type (issue #4984)', () => {
43 + afterEach(() => {
44 + vi.unstubAllGlobals();
45 + });
46 +
47 + it('labels a local .pptx with its PPTX MIME type in the presign request, the PUT, and the result', async () => {
48 + const root = mkdtempSync(path.join(os.tmpdir(), 'composio-mime-'));
49 + const file = path.join(root, 'deck.pptx');
50 + writeFileSync(file, 'PK fake pptx');
51 + const createPresignedURL = vi.fn().mockResolvedValue({
52 + key: 's3key-deck',
53 + type: 'new',
54 + new_presigned_url: 'https://1.1.1.1/put',
55 + });
56 + const client = { files: { createPresignedURL } } as unknown as ComposioClient;
57 + const fetchMock = vi.fn().mockResolvedValue(new Response(null, { status: 200 }));
58 + vi.stubGlobal('fetch', fetchMock);
59 +
60 + try {
61 + const result = await getFileDataAfterUploadingToS3(file, {
62 + toolSlug: 'CANVA_CREATE_DESIGN_IMPORT_JOB',
63 + toolkitSlug: 'canva',
64 + client,
65 + });
66 +
67 + expect(createPresignedURL).toHaveBeenCalledWith(
68 + expect.objectContaining({ mimetype: PPTX }),
69 + expect.anything()
70 + );
71 + const [, init] = fetchMock.mock.calls[0] as [string, RequestInit];
72 + expect(new Headers(init.headers).get('content-type')).toBe(PPTX);
73 + expect(result).toMatchObject({ mimetype: PPTX, s3key: 's3key-deck' });
74 + expect(result.name).toMatch(/\.pptx$/);
75 + } finally {
76 + rmSync(root, { recursive: true, force: true });
77 + }
78 + });
79 +});
ts/packages/core/test/utils/mime.test.ts
+51 -1
@@ -1,9 +1,59 @@
1 +import mime from 'mime';
2 import { describe, it, expect } from 'vitest';
2 -import { getExtensionFromMimeType } from '../../src/utils/mime';
3 +import { getExtensionFromMimeType, MIME_TYPES_BY_EXTENSION } from '../../src/utils/mime';
4
5 describe('getExtensionFromMimeType', () => {
6 it('should return extension for known mimetype', () => {
7 expect(getExtensionFromMimeType('image/png')).toBe('png');
8 expect(getExtensionFromMimeType('application/pdf')).toBe('pdf');
9 });
10 +
11 + it.each(['constructor', '__proto__', 'toString', 'hasOwnProperty'])(
12 + 'does not return an Object.prototype member for %j',
13 + mimeType => {
14 + expect(getExtensionFromMimeType(mimeType)).toBe('bin');
15 + }
16 + );
17 +});
18 +
19 +// The CLI's `composio execute` labels local files with the `mime` package, so the
20 +// SDK must send the same type for the same extension.
21 +describe('MIME_TYPES_BY_EXTENSION', () => {
22 + // Extensions the mime package does not know, kept for parity with the Python SDK.
23 + const EXTENSIONS_UNKNOWN_TO_MIME = [
24 + '3gpp2',
25 + 'ass',
26 + 'h5',
27 + 'ksh',
28 + 'loas',
29 + 'mpa',
30 + 'nws',
31 + 'ppa',
32 + 'pwz',
33 + 'py',
34 + 'pyc',
35 + 'tgz',
36 + 'wiz',
37 + 'xlb',
38 + 'xpdl',
39 + ];
40 + const known = Object.fromEntries(
41 + Object.entries(MIME_TYPES_BY_EXTENSION).filter(
42 + ([extension]) => !EXTENSIONS_UNKNOWN_TO_MIME.includes(extension)
43 + )
44 + );
45 +
46 + it('matches the mime package for every extension it knows', () => {
47 + const fromMimePackage = Object.fromEntries(
48 + Object.keys(known).map(extension => [extension, mime.getType(`file.${extension}`)])
49 + );
50 + expect(fromMimePackage).toEqual(known);
51 + });
52 +
53 + it('adds only extensions the mime package does not know', () => {
54 + const fromMimePackage = EXTENSIONS_UNKNOWN_TO_MIME.map(extension =>
55 + mime.getType(`file.${extension}`)
56 + );
57 + expect(fromMimePackage).toEqual(EXTENSIONS_UNKNOWN_TO_MIME.map(() => null));
58 + });
59 });