@composio/core 0.17.0 → 1.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/{CustomTool-Uip-fhPw.d.mts → CustomTool-CwpeQhz2.d.mts} +1 -1
  2. package/dist/FileToolModifier.utils.neutral-D_YkHwZP.mjs +188 -0
  3. package/dist/{Telemetry-DuGJSwUt.mjs → Telemetry-DK1uAWnD.mjs} +1 -1
  4. package/dist/{cancellation-NVtGf3St.mjs → cancellation-C-qy8rcj.mjs} +1 -1
  5. package/dist/{composio-B27X6i6A.d.mts → composio-XjF7EMEe.d.mts} +256 -250
  6. package/dist/{customTool.types-B2Ava_j5.d.mts → customTool.types-DpJbYY5m.d.mts} +167 -167
  7. package/dist/experimental/index.d.mts +2 -2
  8. package/dist/{fileUtils.node-B1Wn848p.mjs → fileUtils.node-BwpUOF0s.mjs} +2 -2
  9. package/dist/index.d.mts +6 -5
  10. package/dist/index.mjs +58 -24
  11. package/dist/models/Files.node.mjs +2 -2
  12. package/dist/{sensitiveFileUploadPaths-BVEt0peg.mjs → sensitiveFileUploadPaths-B0w8dqpv.mjs} +23 -6
  13. package/dist/ssrfGuard.node-DlxO8uzr.mjs +307 -0
  14. package/dist/{types-DdZJuMm2.d.mts → types-C9kJAurw.d.mts} +2 -2
  15. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
  16. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
  17. package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
  18. package/dist/utils/modifiers/FileToolModifier.node.mjs +56 -100
  19. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
  20. package/dist/utils/modifiers/FileToolModifier.workerd.mjs +1 -1
  21. package/dist/utils/ssrfGuard.node.d.mts +14 -5
  22. package/dist/utils/ssrfGuard.node.mjs +1 -161
  23. package/package.json +7 -3
  24. package/src/models/ToolRouterSession.ts +36 -8
  25. package/src/models/Tools.ts +102 -39
  26. package/src/utils/modifiers/FileToolModifier.node.ts +85 -181
  27. package/src/utils/modifiers/FileToolModifier.utils.neutral.ts +199 -0
  28. package/src/utils/pinnedDispatcher.node.ts +118 -0
  29. package/src/utils/sensitiveFileUploadPaths.ts +36 -9
  30. package/src/utils/ssrfGuard.node.ts +89 -11
  31. package/dist/FileToolModifier.utils.neutral-B5rT711M.mjs +0 -72
@@ -54,7 +54,11 @@ import { handleToolExecutionError } from '../errors/ToolErrors';
54
54
  import type { SessionExecuteParams } from '@composio/client/resources/tool-router/session/session.mjs';
55
55
  import { CONFIG_DEFAULTS } from '../utils/config-defaults';
56
56
  import { resolveEffectiveUploadAllowlist } from '../utils/fileDirs';
57
- import { schemaHasFileUploadable } from '../utils/modifiers/FileToolModifier.utils.neutral';
57
+ import {
58
+ dropEmptyFileUploads,
59
+ schemaHasFileUploadable,
60
+ } from '../utils/modifiers/FileToolModifier.utils.neutral';
61
+ import { dereferenceJsonSchema } from '../utils/jsonSchema';
58
62
  import { ComposioRequestOptions } from '../types/requestOptions.types';
59
63
  import { withCancellation } from '../utils/cancellation';
60
64
  import { ComposioRequestCancelledError } from '../errors/SDKErrors';
@@ -268,12 +272,56 @@ export class Tools<
268
272
  if (requestOptions?.signal?.aborted) {
269
273
  throw new ComposioRequestCancelledError();
270
274
  }
275
+ let modifiedParams = await this.applyFileUploadModifiers(
276
+ tool,
277
+ { toolSlug, toolkitSlug, params },
278
+ modifiers?.beforeFileUpload,
279
+ requestOptions
280
+ );
281
+
282
+ // apply the before execute modifiers
283
+ if (modifiers?.beforeExecute) {
284
+ if (typeof modifiers.beforeExecute === 'function') {
285
+ modifiedParams = await modifiers.beforeExecute({
286
+ toolSlug,
287
+ toolkitSlug,
288
+ params: modifiedParams,
289
+ });
290
+ if (requestOptions?.signal?.aborted) {
291
+ throw new ComposioRequestCancelledError();
292
+ }
293
+ } else {
294
+ throw new ComposioInvalidModifierError('Invalid beforeExecute modifier. Not a function.');
295
+ }
296
+ }
297
+ return modifiedParams;
298
+ }
299
+
300
+ /**
301
+ * Applies schema-aware file preprocessing shared by direct and Tool Router
302
+ * session execution. This always runs before the caller's `beforeExecute`
303
+ * hook so the hook observes the exact arguments sent to the backend.
304
+ */
305
+ private async applyFileUploadModifiers(
306
+ tool: Tool,
307
+ {
308
+ toolSlug,
309
+ toolkitSlug,
310
+ params,
311
+ }: {
312
+ toolSlug: string;
313
+ toolkitSlug: string;
314
+ params: ToolExecuteParams;
315
+ },
316
+ beforeFileUpload?: ExecuteToolModifiers['beforeFileUpload'],
317
+ requestOptions?: ComposioRequestOptions
318
+ ): Promise<ToolExecuteParams> {
271
319
  let modifiedParams = params;
272
320
  // if auto upload download files is enabled, upload the files to the Composio API
273
321
  if (this.autoUploadDownloadFiles) {
274
322
  const fileToolModifier = new FileToolModifier(this.client, {
275
323
  ...this.fileUploadPathOptions,
276
- beforeFileUpload: modifiers?.beforeFileUpload,
324
+ beforeFileUpload,
277
325
  });
278
326
  modifiedParams = await fileToolModifier.fileUploadModifier(tool, {
279
327
  toolSlug,
@@ -284,40 +332,37 @@ export class Tools<
284
332
  if (requestOptions?.signal?.aborted) {
285
333
  throw new ComposioRequestCancelledError();
286
334
  }
287
- } else if (
288
- schemaHasFileUploadable(tool.inputParameters) &&
289
- !this.warnedAutoUploadDisabledForTool.has(toolSlug)
290
- ) {
291
- // With auto-upload off, the raw `{ name, mimetype, s3key }` shape is
292
- // what the LLM / caller sees on `tool.inputParameters`. LLMs can't
293
- // produce a valid `s3key` and will hallucinate one, which then fails
294
- // at the staging-lookup step on the backend. Nudge the caller toward
295
- // manual staging or opting into auto-upload.
296
- this.warnedAutoUploadDisabledForTool.add(toolSlug);
297
- logger.warn(
298
- `Tool "${toolSlug}" (toolkit "${toolkitSlug}") has a file-uploadable input, but ` +
299
- `\`dangerouslyAllowAutoUploadDownloadFiles\` is disabled. The SDK will forward ` +
300
- `the file argument as-is; if it isn't already a staged ` +
301
- `{ name, mimetype, s3key } descriptor, the backend will reject the call. Either:\n` +
302
- ` 1) Stage the file yourself: \`const f = await composio.files.upload({ file, toolSlug, toolkitSlug }); ` +
303
- `await composio.tools.execute('${toolSlug}', { userId, arguments: { <fileField>: f } })\`, or\n` +
304
- ` 2) Enable auto-upload with a scoped allowlist: ` +
305
- `\`new Composio({ dangerouslyAllowAutoUploadDownloadFiles: true, fileUploadDirs: ['/safe/dir'] })\`.`
306
- );
307
- }
308
- // apply the before execute modifiers
309
- if (modifiers?.beforeExecute) {
310
- if (typeof modifiers.beforeExecute === 'function') {
311
- modifiedParams = await modifiers.beforeExecute({
312
- toolSlug,
313
- toolkitSlug,
314
- params: modifiedParams,
315
- });
316
- if (requestOptions?.signal?.aborted) {
317
- throw new ComposioRequestCancelledError();
318
- }
319
- } else {
320
- throw new ComposioInvalidModifierError('Invalid beforeExecute modifier. Not a function.');
335
+ } else if (tool.inputParameters && schemaHasFileUploadable(tool.inputParameters)) {
336
+ // Auto-upload is opt-in, but "no file" must still be sent as an
337
+ // omitted key rather than `''`, which the backend rejects
338
+ // (https://github.com/ComposioHQ/composio/issues/4233).
339
+ if (modifiedParams.arguments) {
340
+ modifiedParams = {
341
+ ...modifiedParams,
342
+ arguments: (await dropEmptyFileUploads(
343
+ modifiedParams.arguments,
344
+ dereferenceJsonSchema(tool.inputParameters, { onUnresolved: 'sentinel' })
345
+ )) as ToolExecuteParams['arguments'],
346
+ };
347
+ }
348
+
349
+ if (!this.warnedAutoUploadDisabledForTool.has(toolSlug)) {
350
+ // With auto-upload off, the raw `{ name, mimetype, s3key }` shape is
351
+ // what the LLM / caller sees on `tool.inputParameters`. LLMs can't
352
+ // produce a valid `s3key` and will hallucinate one, which then fails
353
+ // at the staging-lookup step on the backend. Nudge the caller toward
354
+ // manual staging or opting into auto-upload.
355
+ this.warnedAutoUploadDisabledForTool.add(toolSlug);
356
+ logger.warn(
357
+ `Tool "${toolSlug}" (toolkit "${toolkitSlug}") has a file-uploadable input, but ` +
358
+ `\`dangerouslyAllowAutoUploadDownloadFiles\` is disabled. The SDK will forward ` +
359
+ `the file argument as-is; if it isn't already a staged ` +
360
+ `{ name, mimetype, s3key } descriptor, the backend will reject the call. Either:\n` +
361
+ ` 1) Stage the file yourself: \`const f = await composio.files.upload({ file, toolSlug, toolkitSlug }); ` +
362
+ `await composio.tools.execute('${toolSlug}', { userId, arguments: { <fileField>: f } })\`, or\n` +
363
+ ` 2) Enable auto-upload with a scoped allowlist: ` +
364
+ `\`new Composio({ dangerouslyAllowAutoUploadDownloadFiles: true, fileUploadDirs: ['/safe/dir'] })\`.`
365
+ );
321
366
  }
322
367
  }
323
368
  return modifiedParams;
@@ -851,9 +896,10 @@ export class Tools<
851
896
  wrapToolsForToolRouter(
852
897
  sessionId: string,
853
898
  tools: Tool[],
854
- modifiers?: SessionExecuteMetaModifiers
899
+ modifiers?: SessionExecuteMetaModifiers,
900
+ rawTools: Tool[] = tools.map(tool => ToolSchema.parse(tool))
855
901
  ): Tool[] {
856
- const executeToolFn = this.createExecuteToolFnForToolRouter(sessionId, tools, modifiers);
902
+ const executeToolFn = this.createExecuteToolFnForToolRouter(sessionId, rawTools, modifiers);
857
903
  return this.provider.wrapTools(tools, executeToolFn) as Tool[];
858
904
  }
859
905
 
@@ -1150,9 +1196,25 @@ export class Tools<
1150
1196
  });
1151
1197
  }
1152
1198
 
1153
- // Apply beforeExecute modifier if provided
1154
1199
  let modifiedParams = body.arguments ?? {};
1155
1200
  const toolkitSlug = tool?.toolkit?.slug ?? 'composio';
1201
+
1202
+ if (tool) {
1203
+ const fileModifiedParams = await this.applyFileUploadModifiers(
1204
+ tool,
1205
+ {
1206
+ toolSlug,
1207
+ toolkitSlug,
1208
+ params: { arguments: modifiedParams },
1209
+ },
1210
+ undefined,
1211
+ requestOptions
1212
+ );
1213
+ modifiedParams = fileModifiedParams.arguments ?? {};
1214
+ }
1215
+
1216
+ // Apply beforeExecute modifier after file preprocessing so the hook sees
1217
+ // the same arguments that will be sent to the Tool Router.
1156
1218
  if (modifiers?.beforeExecute) {
1157
1219
  modifiedParams = await modifiers.beforeExecute({
1158
1220
  toolSlug,
@@ -1308,6 +1370,7 @@ export class Tools<
1308
1370
  * @deprecated The `customConnectionData` proxy param is deprecated and will be
1309
1371
  * removed in a future release. Use `customAuthParams` instead.
1310
1372
  */
1373
+ // oxlint-disable-next-line typescript/ban-ts-comment -- generated client versions disagree about this deprecated field
1311
1374
  // @ts-ignore
1312
1375
  custom_connection_data: toolProxyParams.data.customConnectionData,
1313
1376
  } as ComposioToolProxyParams;
@@ -22,9 +22,13 @@ import {
22
22
  type GetFileDataAfterUploadingToS3Options,
23
23
  } from '../fileUtils.node';
24
24
  import {
25
+ DELETE_VALUE,
26
+ findSchemaVariantWithFileProperty,
27
+ getSchemaVariants,
28
+ isEmptyFileValue,
25
29
  isPlainObject,
26
30
  transformProperties,
27
- schemaHasFileProperty,
31
+ walkFileUploadableLeaves,
28
32
  } from './FileToolModifier.utils.neutral';
29
33
  import { dereferenceJsonSchema } from '../jsonSchema';
30
34
  import { withCancellation } from '../cancellation';
@@ -44,68 +48,14 @@ const resolveFileSchema = <Schema extends JSONSchemaProperty>(
44
48
  ): Schema | undefined =>
45
49
  schema ? dereferenceJsonSchema(schema, { onUnresolved: 'sentinel' }) : schema;
46
50
 
47
- const getSchemaVariants = (schema: JSONSchemaProperty | undefined): JSONSchemaProperty[] => [
48
- ...(schema?.anyOf ?? []),
49
- ...(schema?.oneOf ?? []),
50
- ...(schema?.allOf ?? []),
51
- ];
52
-
53
- const jsonSchemaTypeMatchesValue = (schema: JSONSchemaProperty, value: unknown): boolean => {
54
- const schemaType = schema.type;
55
-
56
- if (Array.isArray(schemaType)) {
57
- return schemaType.some(type => jsonSchemaTypeMatchesValue({ ...schema, type }, value));
58
- }
59
-
60
- if (schemaType === undefined) {
61
- if (schema.properties) return isPlainObject(value);
62
- if (schema.items) return Array.isArray(value);
63
- return false;
64
- }
65
-
66
- switch (schemaType) {
67
- case 'array':
68
- return Array.isArray(value);
69
- case 'object':
70
- return isPlainObject(value);
71
- case 'string':
72
- return typeof value === 'string';
73
- case 'integer':
74
- return Number.isInteger(value);
75
- case 'number':
76
- return typeof value === 'number';
77
- case 'boolean':
78
- return typeof value === 'boolean';
79
- case 'null':
80
- return value === null;
81
- default:
82
- return false;
83
- }
84
- };
85
-
86
- const findSchemaVariantWithFileProperty = (
87
- schema: JSONSchemaProperty | undefined,
88
- property: 'file_uploadable' | 'file_downloadable',
89
- value: unknown
90
- ): JSONSchemaProperty | undefined => {
91
- const candidates = getSchemaVariants(schema).filter(variant =>
92
- schemaHasFileProperty(variant, property)
93
- );
94
-
95
- return (
96
- candidates.find(candidate => jsonSchemaTypeMatchesValue(candidate, value)) ?? candidates[0]
97
- );
98
- };
99
-
100
51
  /**
101
- * Recursively walks a runtime value and its matching JSON-Schema node,
102
- * uploading any string path whose schema node has `file_uploadable: true`.
103
- * The function returns a **new** value with all substitutions applied;
104
- * nothing is mutated in-place.
52
+ * Stages one `file_uploadable` leaf: a local path / URL string or a `File`
53
+ * is uploaded to S3 and replaced by its `{ name, mimetype, s3key }`
54
+ * descriptor; `''` means "no file" and is dropped from the request;
55
+ * anything else (e.g. an already-staged descriptor) passes through.
105
56
  */
106
- const hydrateFiles = async (
57
+ const stageFileValue = async (
107
58
  value: unknown,
108
- schema: JSONSchemaProperty | undefined,
109
59
  ctx: {
110
60
  toolSlug: string;
111
61
  toolkitSlug: string;
@@ -120,133 +70,85 @@ const hydrateFiles = async (
120
70
  beforeFileUpload?: beforeFileUploadModifier;
121
71
  }
122
72
  ): Promise<unknown> => {
123
- // ──────────────────────────────────────────────────────────────────────────
124
- // 1. Direct file upload
125
- // ──────────────────────────────────────────────────────────────────────────
126
- if (schema?.file_uploadable) {
127
- // Upload only if the runtime value is a string (i.e., a local path) or blob
128
- if (typeof value !== 'string' && !(value instanceof File)) return value;
129
-
130
- const runBeforeFileUpload = async (
131
- path: string,
132
- source: 'path' | 'url' | 'file'
133
- ): Promise<string> => {
134
- if (!ctx.beforeFileUpload) {
135
- return path;
136
- }
137
- const out = await ctx.beforeFileUpload({
138
- path,
139
- source,
140
- toolSlug: ctx.toolSlug,
141
- toolkitSlug: ctx.toolkitSlug,
142
- });
143
- if (out === false) {
144
- throw new ComposioFileUploadAbortedError(
145
- 'File upload was aborted because beforeFileUpload returned false.'
146
- );
147
- }
148
- return out;
149
- };
150
-
151
- if (typeof value === 'string') {
152
- // Match the URL/local-path split used downstream in
153
- // getFileDataAfterUploadingToS3 so the hook sees the same categorisation.
154
- const source = isHttpUrl(value) ? 'url' : 'path';
155
- const pathOrUrl = await runBeforeFileUpload(value, source);
156
- logger.debug(`Uploading file "${pathOrUrl}"`);
157
- return getFileDataAfterUploadingToS3(pathOrUrl, {
158
- toolSlug: ctx.toolSlug,
159
- toolkitSlug: ctx.toolkitSlug,
160
- client: ctx.client,
161
- sensitiveFileUploadProtection: ctx.sensitiveFileUploadProtection,
162
- fileUploadPathDenySegments: ctx.fileUploadPathDenySegments,
163
- fileUploadAllowlist: ctx.fileUploadAllowlist,
164
- signal: ctx.signal,
165
- });
73
+ if (isEmptyFileValue(value)) return DELETE_VALUE;
74
+ // Upload only if the runtime value is a string (i.e., a local path) or blob
75
+ if (typeof value !== 'string' && !(value instanceof File)) return value;
76
+
77
+ const runBeforeFileUpload = async (
78
+ path: string,
79
+ source: 'path' | 'url' | 'file'
80
+ ): Promise<string> => {
81
+ if (!ctx.beforeFileUpload) {
82
+ return path;
166
83
  }
167
-
168
- // File — `path` is the filename only; a string return replaces it with a
169
- // local-path upload.
170
- if (ctx.beforeFileUpload) {
171
- const out = await ctx.beforeFileUpload({
172
- path: value.name,
173
- source: 'file',
174
- toolSlug: ctx.toolSlug,
175
- toolkitSlug: ctx.toolkitSlug,
176
- });
177
- if (out === false) {
178
- throw new ComposioFileUploadAbortedError(
179
- 'File upload was aborted because beforeFileUpload returned false.'
180
- );
181
- }
182
- if (typeof out === 'string' && out !== value.name) {
183
- logger.debug(`Uploading file from path "${out}" (replaced File: ${value.name})`);
184
- return getFileDataAfterUploadingToS3(out, {
185
- toolSlug: ctx.toolSlug,
186
- toolkitSlug: ctx.toolkitSlug,
187
- client: ctx.client,
188
- sensitiveFileUploadProtection: ctx.sensitiveFileUploadProtection,
189
- fileUploadPathDenySegments: ctx.fileUploadPathDenySegments,
190
- fileUploadAllowlist: ctx.fileUploadAllowlist,
191
- signal: ctx.signal,
192
- });
193
- }
84
+ const out = await ctx.beforeFileUpload({
85
+ path,
86
+ source,
87
+ toolSlug: ctx.toolSlug,
88
+ toolkitSlug: ctx.toolkitSlug,
89
+ });
90
+ if (out === false) {
91
+ throw new ComposioFileUploadAbortedError(
92
+ 'File upload was aborted because beforeFileUpload returned false.'
93
+ );
194
94
  }
195
- logger.debug(`Uploading file "${value.name}"`);
196
- // File/Blob values are not subject to the upload-dir allowlist.
197
- return getFileDataAfterUploadingToS3(value, {
95
+ return out;
96
+ };
97
+
98
+ if (typeof value === 'string') {
99
+ // Match the URL/local-path split used downstream in
100
+ // getFileDataAfterUploadingToS3 so the hook sees the same categorisation.
101
+ const source = isHttpUrl(value) ? 'url' : 'path';
102
+ const pathOrUrl = await runBeforeFileUpload(value, source);
103
+ logger.debug(`Uploading file "${pathOrUrl}"`);
104
+ return getFileDataAfterUploadingToS3(pathOrUrl, {
198
105
  toolSlug: ctx.toolSlug,
199
106
  toolkitSlug: ctx.toolkitSlug,
200
107
  client: ctx.client,
201
108
  sensitiveFileUploadProtection: ctx.sensitiveFileUploadProtection,
202
109
  fileUploadPathDenySegments: ctx.fileUploadPathDenySegments,
110
+ fileUploadAllowlist: ctx.fileUploadAllowlist,
203
111
  signal: ctx.signal,
204
112
  });
205
113
  }
206
114
 
207
- // ──────────────────────────────────────────────────────────────────────────
208
- // 2. Handle anyOf/oneOf/allOf — pick the file-bearing variant whose
209
- // JSON Schema shape matches the runtime value, then hydrate against it.
210
- //
211
- // We deliberately do NOT loop over every uploadable variant. With `oneOf`,
212
- // exactly one variant should apply at runtime, and applying multiple would
213
- // upload the same file once per variant — two presigned-URL round-trips and
214
- // two S3 PUTs for a two-variant `oneOf`. If no runtime shape matches, fall
215
- // back to the first file-bearing variant to preserve historical behavior.
216
- // ──────────────────────────────────────────────────────────────────────────
217
- const uploadableVariant = findSchemaVariantWithFileProperty(schema, 'file_uploadable', value);
218
- if (uploadableVariant) {
219
- return hydrateFiles(value, uploadableVariant, ctx);
220
- }
221
-
222
- // ──────────────────────────────────────────────────────────────────────────
223
- // 3. Object → traverse each property
224
- // ──────────────────────────────────────────────────────────────────────────
225
- if (schema?.type === 'object' && schema.properties && isPlainObject(value)) {
226
- const transformed: Record<string, unknown> = {};
227
-
228
- for (const [k, v] of Object.entries(value)) {
229
- transformed[k] = await hydrateFiles(v, schema.properties[k], ctx);
115
+ // File — `path` is the filename only; a string return replaces it with a
116
+ // local-path upload.
117
+ if (ctx.beforeFileUpload) {
118
+ const out = await ctx.beforeFileUpload({
119
+ path: value.name,
120
+ source: 'file',
121
+ toolSlug: ctx.toolSlug,
122
+ toolkitSlug: ctx.toolkitSlug,
123
+ });
124
+ if (out === false) {
125
+ throw new ComposioFileUploadAbortedError(
126
+ 'File upload was aborted because beforeFileUpload returned false.'
127
+ );
128
+ }
129
+ if (typeof out === 'string' && out !== value.name) {
130
+ logger.debug(`Uploading file from path "${out}" (replaced File: ${value.name})`);
131
+ return getFileDataAfterUploadingToS3(out, {
132
+ toolSlug: ctx.toolSlug,
133
+ toolkitSlug: ctx.toolkitSlug,
134
+ client: ctx.client,
135
+ sensitiveFileUploadProtection: ctx.sensitiveFileUploadProtection,
136
+ fileUploadPathDenySegments: ctx.fileUploadPathDenySegments,
137
+ fileUploadAllowlist: ctx.fileUploadAllowlist,
138
+ signal: ctx.signal,
139
+ });
230
140
  }
231
- return transformed;
232
- }
233
-
234
- // ──────────────────────────────────────────────────────────────────────────
235
- // 4. Array → traverse each item
236
- // ──────────────────────────────────────────────────────────────────────────
237
- if (schema?.type === 'array' && schema.items && Array.isArray(value)) {
238
- // `items` can be a single schema or an array of schemas; we handle both.
239
- const itemSchema = Array.isArray(schema.items) ? schema.items[0] : schema.items;
240
-
241
- return Promise.all(
242
- value.map(item => hydrateFiles(item, itemSchema as JSONSchemaProperty, ctx))
243
- );
244
141
  }
245
-
246
- // ──────────────────────────────────────────────────────────────────────────
247
- // 5. Primitive or schema-less branch → return unchanged
248
- // ──────────────────────────────────────────────────────────────────────────
249
- return value;
142
+ logger.debug(`Uploading file "${value.name}"`);
143
+ // File/Blob values are not subject to the upload-dir allowlist.
144
+ return getFileDataAfterUploadingToS3(value, {
145
+ toolSlug: ctx.toolSlug,
146
+ toolkitSlug: ctx.toolkitSlug,
147
+ client: ctx.client,
148
+ sensitiveFileUploadProtection: ctx.sensitiveFileUploadProtection,
149
+ fileUploadPathDenySegments: ctx.fileUploadPathDenySegments,
150
+ signal: ctx.signal,
151
+ });
250
152
  };
251
153
 
252
154
  /**
@@ -426,13 +328,15 @@ export class FileToolModifier {
426
328
  try {
427
329
  const newArgs = await withCancellation(
428
330
  () =>
429
- hydrateFiles(args, resolveFileSchema(tool.inputParameters), {
430
- toolSlug,
431
- toolkitSlug,
432
- client: this.client,
433
- ...this.fileUploadPathOptions,
434
- signal,
435
- }),
331
+ walkFileUploadableLeaves(args, resolveFileSchema(tool.inputParameters), value =>
332
+ stageFileValue(value, {
333
+ toolSlug,
334
+ toolkitSlug,
335
+ client: this.client,
336
+ ...this.fileUploadPathOptions,
337
+ signal,
338
+ })
339
+ ),
436
340
  signal
437
341
  );
438
342
  return { ...params, arguments: newArgs as ToolExecuteParams['arguments'] };