@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.
- package/dist/{CustomTool-Uip-fhPw.d.mts → CustomTool-CwpeQhz2.d.mts} +1 -1
- package/dist/FileToolModifier.utils.neutral-D_YkHwZP.mjs +188 -0
- package/dist/{Telemetry-DuGJSwUt.mjs → Telemetry-DK1uAWnD.mjs} +1 -1
- package/dist/{cancellation-NVtGf3St.mjs → cancellation-C-qy8rcj.mjs} +1 -1
- package/dist/{composio-B27X6i6A.d.mts → composio-XjF7EMEe.d.mts} +256 -250
- package/dist/{customTool.types-B2Ava_j5.d.mts → customTool.types-DpJbYY5m.d.mts} +167 -167
- package/dist/experimental/index.d.mts +2 -2
- package/dist/{fileUtils.node-B1Wn848p.mjs → fileUtils.node-BwpUOF0s.mjs} +2 -2
- package/dist/index.d.mts +6 -5
- package/dist/index.mjs +58 -24
- package/dist/models/Files.node.mjs +2 -2
- package/dist/{sensitiveFileUploadPaths-BVEt0peg.mjs → sensitiveFileUploadPaths-B0w8dqpv.mjs} +23 -6
- package/dist/ssrfGuard.node-DlxO8uzr.mjs +307 -0
- package/dist/{types-DdZJuMm2.d.mts → types-C9kJAurw.d.mts} +2 -2
- package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
- package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
- package/dist/utils/modifiers/FileToolModifier.node.mjs +56 -100
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
- package/dist/utils/modifiers/FileToolModifier.workerd.mjs +1 -1
- package/dist/utils/ssrfGuard.node.d.mts +14 -5
- package/dist/utils/ssrfGuard.node.mjs +1 -161
- package/package.json +7 -3
- package/src/models/ToolRouterSession.ts +36 -8
- package/src/models/Tools.ts +102 -39
- package/src/utils/modifiers/FileToolModifier.node.ts +85 -181
- package/src/utils/modifiers/FileToolModifier.utils.neutral.ts +199 -0
- package/src/utils/pinnedDispatcher.node.ts +118 -0
- package/src/utils/sensitiveFileUploadPaths.ts +36 -9
- package/src/utils/ssrfGuard.node.ts +89 -11
- package/dist/FileToolModifier.utils.neutral-B5rT711M.mjs +0 -72
package/src/models/Tools.ts
CHANGED
|
@@ -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 {
|
|
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
|
|
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
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
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,
|
|
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
|
-
|
|
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
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
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
|
|
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
|
-
//
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
-
//
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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
|
-
|
|
248
|
-
|
|
249
|
-
|
|
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
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
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'] };
|