@composio/core 0.1.29 → 0.1.30
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/index.cjs +92 -40
- package/dist/index.d.cts +46 -4
- package/dist/index.d.ts +46 -4
- package/dist/index.js +92 -40
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2123,7 +2123,12 @@ var uploadFileToS3 = async (fileName, content, toolSlug, toolkitSlug, mimeType,
|
|
|
2123
2123
|
}
|
|
2124
2124
|
return key;
|
|
2125
2125
|
};
|
|
2126
|
-
var getFileDataAfterUploadingToS3 = async (
|
|
2126
|
+
var getFileDataAfterUploadingToS3 = async ({
|
|
2127
|
+
path,
|
|
2128
|
+
toolSlug,
|
|
2129
|
+
toolkitSlug,
|
|
2130
|
+
client
|
|
2131
|
+
}) => {
|
|
2127
2132
|
const isURL = path.startsWith("http");
|
|
2128
2133
|
const fileData = isURL ? await readFileContentFromURL(path) : await readFileContent(path);
|
|
2129
2134
|
logger_default.debug(`Uploading file to S3: ${path}`);
|
|
@@ -2158,7 +2163,7 @@ var downloadFileFromS3 = async ({
|
|
|
2158
2163
|
return {
|
|
2159
2164
|
name: fileName,
|
|
2160
2165
|
mimeType,
|
|
2161
|
-
|
|
2166
|
+
s3Url,
|
|
2162
2167
|
filePath
|
|
2163
2168
|
};
|
|
2164
2169
|
};
|
|
@@ -2221,7 +2226,7 @@ var transformProperties = (properties) => {
|
|
|
2221
2226
|
format: "path"
|
|
2222
2227
|
};
|
|
2223
2228
|
}
|
|
2224
|
-
return
|
|
2229
|
+
return newProperties;
|
|
2225
2230
|
};
|
|
2226
2231
|
var FileToolModifier = class {
|
|
2227
2232
|
client;
|
|
@@ -2270,12 +2275,12 @@ var FileToolModifier = class {
|
|
|
2270
2275
|
if (toolProperty?.file_uploadable) {
|
|
2271
2276
|
logger_default.debug(`Processing file upload for: ${key}`);
|
|
2272
2277
|
try {
|
|
2273
|
-
const fileData = await getFileDataAfterUploadingToS3(
|
|
2274
|
-
args[key],
|
|
2275
|
-
options.toolSlug,
|
|
2276
|
-
options.toolkitSlug ?? "unknown",
|
|
2277
|
-
this.client
|
|
2278
|
-
);
|
|
2278
|
+
const fileData = await getFileDataAfterUploadingToS3({
|
|
2279
|
+
path: args[key],
|
|
2280
|
+
toolSlug: options.toolSlug,
|
|
2281
|
+
toolkitSlug: options.toolkitSlug ?? "unknown",
|
|
2282
|
+
client: this.client
|
|
2283
|
+
});
|
|
2279
2284
|
args[key] = fileData;
|
|
2280
2285
|
} catch (error) {
|
|
2281
2286
|
throw new ComposioFileUploadError(`Failed to upload file: ${key}`, {
|
|
@@ -2297,8 +2302,6 @@ var FileToolModifier = class {
|
|
|
2297
2302
|
* @returns The result with the file download URL included.
|
|
2298
2303
|
*/
|
|
2299
2304
|
async fileDownloadModifier(tool, options) {
|
|
2300
|
-
console.log(JSON.stringify(options.result, null, 2));
|
|
2301
|
-
console.log(JSON.stringify(tool.outputParameters, null, 2));
|
|
2302
2305
|
for (const [key, value] of Object.entries(options.result?.data)) {
|
|
2303
2306
|
const fileData = value;
|
|
2304
2307
|
if (!fileData?.s3url) continue;
|
|
@@ -2337,7 +2340,8 @@ var Tools = class {
|
|
|
2337
2340
|
client;
|
|
2338
2341
|
customTools;
|
|
2339
2342
|
provider;
|
|
2340
|
-
|
|
2343
|
+
autoUploadDownloadFiles;
|
|
2344
|
+
constructor(client, provider, options) {
|
|
2341
2345
|
if (!client) {
|
|
2342
2346
|
throw new Error("ComposioClient is required");
|
|
2343
2347
|
}
|
|
@@ -2347,6 +2351,7 @@ var Tools = class {
|
|
|
2347
2351
|
this.client = client;
|
|
2348
2352
|
this.customTools = new CustomTools(client);
|
|
2349
2353
|
this.provider = provider;
|
|
2354
|
+
this.autoUploadDownloadFiles = options?.autoUploadDownloadFiles ?? true;
|
|
2350
2355
|
this.execute = this.execute.bind(this);
|
|
2351
2356
|
this.provider._setExecuteToolFn(this.execute);
|
|
2352
2357
|
this.getRawComposioToolBySlug = this.getRawComposioToolBySlug.bind(this);
|
|
@@ -2470,12 +2475,16 @@ var Tools = class {
|
|
|
2470
2475
|
* @returns The tools with the default schema modifiers applied
|
|
2471
2476
|
*/
|
|
2472
2477
|
async applyDefaultSchemaModifiers(tools) {
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2478
|
+
if (this.autoUploadDownloadFiles) {
|
|
2479
|
+
const fileToolModifier = new FileToolModifier(this.client);
|
|
2480
|
+
return await Promise.all(
|
|
2481
|
+
tools.map(
|
|
2482
|
+
(tool) => fileToolModifier.modifyToolSchema(tool.slug, tool.toolkit?.slug ?? "unknown", tool)
|
|
2483
|
+
)
|
|
2484
|
+
);
|
|
2485
|
+
} else {
|
|
2486
|
+
return tools;
|
|
2487
|
+
}
|
|
2479
2488
|
}
|
|
2480
2489
|
/**
|
|
2481
2490
|
* Applies the before execute modifiers to the tool execution params
|
|
@@ -2490,8 +2499,15 @@ var Tools = class {
|
|
|
2490
2499
|
toolkitSlug,
|
|
2491
2500
|
params
|
|
2492
2501
|
}, modifier) {
|
|
2493
|
-
const fileToolModifier = new FileToolModifier(this.client);
|
|
2494
2502
|
let modifiedParams = params;
|
|
2503
|
+
if (this.autoUploadDownloadFiles) {
|
|
2504
|
+
const fileToolModifier = new FileToolModifier(this.client);
|
|
2505
|
+
modifiedParams = await fileToolModifier.fileUploadModifier(tool, {
|
|
2506
|
+
toolSlug,
|
|
2507
|
+
toolkitSlug,
|
|
2508
|
+
params: modifiedParams
|
|
2509
|
+
});
|
|
2510
|
+
}
|
|
2495
2511
|
if (modifier) {
|
|
2496
2512
|
if (typeof modifier === "function") {
|
|
2497
2513
|
modifiedParams = await modifier({
|
|
@@ -2503,11 +2519,6 @@ var Tools = class {
|
|
|
2503
2519
|
throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
|
|
2504
2520
|
}
|
|
2505
2521
|
}
|
|
2506
|
-
modifiedParams = await fileToolModifier.fileUploadModifier(tool, {
|
|
2507
|
-
toolSlug,
|
|
2508
|
-
toolkitSlug,
|
|
2509
|
-
params: modifiedParams
|
|
2510
|
-
});
|
|
2511
2522
|
return modifiedParams;
|
|
2512
2523
|
}
|
|
2513
2524
|
/**
|
|
@@ -2523,8 +2534,15 @@ var Tools = class {
|
|
|
2523
2534
|
toolkitSlug,
|
|
2524
2535
|
result
|
|
2525
2536
|
}, modifier) {
|
|
2526
|
-
const fileToolModifier = new FileToolModifier(this.client);
|
|
2527
2537
|
let modifiedResult = result;
|
|
2538
|
+
if (this.autoUploadDownloadFiles) {
|
|
2539
|
+
const fileToolModifier = new FileToolModifier(this.client);
|
|
2540
|
+
modifiedResult = await fileToolModifier.fileDownloadModifier(tool, {
|
|
2541
|
+
toolSlug,
|
|
2542
|
+
toolkitSlug,
|
|
2543
|
+
result: modifiedResult
|
|
2544
|
+
});
|
|
2545
|
+
}
|
|
2528
2546
|
if (modifier) {
|
|
2529
2547
|
if (typeof modifier === "function") {
|
|
2530
2548
|
modifiedResult = await modifier({
|
|
@@ -2536,11 +2554,6 @@ var Tools = class {
|
|
|
2536
2554
|
throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
|
|
2537
2555
|
}
|
|
2538
2556
|
}
|
|
2539
|
-
modifiedResult = await fileToolModifier.fileDownloadModifier(tool, {
|
|
2540
|
-
toolSlug,
|
|
2541
|
-
toolkitSlug,
|
|
2542
|
-
result: modifiedResult
|
|
2543
|
-
});
|
|
2544
2557
|
return modifiedResult;
|
|
2545
2558
|
}
|
|
2546
2559
|
/**
|
|
@@ -6049,7 +6062,48 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
6049
6062
|
};
|
|
6050
6063
|
|
|
6051
6064
|
// package.json
|
|
6052
|
-
var version = "0.1.
|
|
6065
|
+
var version = "0.1.30";
|
|
6066
|
+
|
|
6067
|
+
// src/models/Files.ts
|
|
6068
|
+
var Files = class {
|
|
6069
|
+
constructor(client) {
|
|
6070
|
+
this.client = client;
|
|
6071
|
+
telemetry.instrument(this);
|
|
6072
|
+
}
|
|
6073
|
+
/**
|
|
6074
|
+
* Upload a file to S3 and return the file data.
|
|
6075
|
+
* @param filePath - The path to the file to upload or a URL of the file to upload.
|
|
6076
|
+
* @param toolSlug - The slug of the tool that is uploading the file.
|
|
6077
|
+
* @param toolkitSlug - The slug of the toolkit that is uploading the file.
|
|
6078
|
+
* @returns The file data.
|
|
6079
|
+
*/
|
|
6080
|
+
async upload({
|
|
6081
|
+
filePath,
|
|
6082
|
+
toolSlug,
|
|
6083
|
+
toolkitSlug
|
|
6084
|
+
}) {
|
|
6085
|
+
const fileData = await getFileDataAfterUploadingToS3({
|
|
6086
|
+
path: filePath,
|
|
6087
|
+
toolSlug,
|
|
6088
|
+
toolkitSlug,
|
|
6089
|
+
client: this.client
|
|
6090
|
+
});
|
|
6091
|
+
return fileData;
|
|
6092
|
+
}
|
|
6093
|
+
/**
|
|
6094
|
+
* Download a file from S3 and return the file data.
|
|
6095
|
+
* @param s3key - The S3 key of the file to download.
|
|
6096
|
+
* @returns The file data.
|
|
6097
|
+
*/
|
|
6098
|
+
async download({
|
|
6099
|
+
toolSlug,
|
|
6100
|
+
s3Url,
|
|
6101
|
+
mimeType
|
|
6102
|
+
}) {
|
|
6103
|
+
const fileDownloadData = await downloadFileFromS3({ toolSlug, s3Url, mimeType });
|
|
6104
|
+
return fileDownloadData;
|
|
6105
|
+
}
|
|
6106
|
+
};
|
|
6053
6107
|
|
|
6054
6108
|
// src/composio.ts
|
|
6055
6109
|
var Composio = class _Composio {
|
|
@@ -6070,6 +6124,7 @@ var Composio = class _Composio {
|
|
|
6070
6124
|
toolkits;
|
|
6071
6125
|
triggers;
|
|
6072
6126
|
provider;
|
|
6127
|
+
files;
|
|
6073
6128
|
// auth configs
|
|
6074
6129
|
authConfigs;
|
|
6075
6130
|
// connected accounts
|
|
@@ -6085,7 +6140,6 @@ var Composio = class _Composio {
|
|
|
6085
6140
|
* @param {string} [config.apiKey] - The API key for authenticating with the Composio API
|
|
6086
6141
|
* @param {string} [config.baseURL] - The base URL for the Composio API (defaults to production URL)
|
|
6087
6142
|
* @param {boolean} [config.allowTracking=true] - Whether to allow anonymous usage analytics
|
|
6088
|
-
* @param {boolean} [config.allowTracing=true] - Whether to allow request tracing for debugging
|
|
6089
6143
|
* @param {TProvider} [config.provider] - The provider to use for this Composio instance (defaults to OpenAIProvider)
|
|
6090
6144
|
*
|
|
6091
6145
|
* @example
|
|
@@ -6122,15 +6176,17 @@ var Composio = class _Composio {
|
|
|
6122
6176
|
});
|
|
6123
6177
|
this.config = {
|
|
6124
6178
|
...config,
|
|
6125
|
-
allowTracking: config?.allowTracking ?? true
|
|
6126
|
-
allowTracing: config?.allowTracing ?? true
|
|
6179
|
+
allowTracking: config?.allowTracking ?? true
|
|
6127
6180
|
};
|
|
6128
6181
|
this.provider = config?.provider ?? new OpenAIProvider();
|
|
6129
|
-
this.tools = new Tools(this.client, this.provider
|
|
6182
|
+
this.tools = new Tools(this.client, this.provider, {
|
|
6183
|
+
autoUploadDownloadFiles: config?.autoUploadDownloadFiles ?? true
|
|
6184
|
+
});
|
|
6130
6185
|
this.mcp = new MCP(this.client, this.provider);
|
|
6131
6186
|
this.toolkits = new Toolkits(this.client);
|
|
6132
6187
|
this.triggers = new Triggers(this.client);
|
|
6133
6188
|
this.authConfigs = new AuthConfigs(this.client);
|
|
6189
|
+
this.files = new Files(this.client);
|
|
6134
6190
|
this.connectedAccounts = new ConnectedAccounts(this.client);
|
|
6135
6191
|
if (this.config.allowTracking) {
|
|
6136
6192
|
telemetry.setup({
|
|
@@ -6140,11 +6196,7 @@ var Composio = class _Composio {
|
|
|
6140
6196
|
version,
|
|
6141
6197
|
isBrowser: typeof window !== "undefined",
|
|
6142
6198
|
provider: this.provider?.name ?? "openai",
|
|
6143
|
-
host: this.config.host
|
|
6144
|
-
// @TODO: Users might want to pass their own session id
|
|
6145
|
-
// @TODO: We shouldn't be doing this as people might always have one session id throughout the process in server
|
|
6146
|
-
sessionId: this.config.allowTracing ? getRandomUUID() : void 0
|
|
6147
|
-
// @TODO: get the session id
|
|
6199
|
+
host: this.config.host
|
|
6148
6200
|
});
|
|
6149
6201
|
}
|
|
6150
6202
|
telemetry.instrument(this);
|
package/dist/index.d.cts
CHANGED
|
@@ -10646,7 +10646,10 @@ declare class Tools<TToolCollection, TTool, TProvider extends BaseComposioProvid
|
|
|
10646
10646
|
private client;
|
|
10647
10647
|
private readonly customTools;
|
|
10648
10648
|
private provider;
|
|
10649
|
-
|
|
10649
|
+
private autoUploadDownloadFiles;
|
|
10650
|
+
constructor(client: ComposioClient, provider: TProvider, options?: {
|
|
10651
|
+
autoUploadDownloadFiles: boolean;
|
|
10652
|
+
});
|
|
10650
10653
|
/**
|
|
10651
10654
|
* Transforms tool data from snake_case API format to camelCase for internal SDK use.
|
|
10652
10655
|
*
|
|
@@ -40443,6 +40446,45 @@ declare class OpenAIProvider extends BaseNonAgenticProvider<OpenAiToolCollection
|
|
|
40443
40446
|
|
|
40444
40447
|
type ComposioRequestHeaders = Record<string, string>;
|
|
40445
40448
|
|
|
40449
|
+
type FileUploadData = {
|
|
40450
|
+
name: string;
|
|
40451
|
+
mimetype: string;
|
|
40452
|
+
s3key: string;
|
|
40453
|
+
};
|
|
40454
|
+
type FileDownloadData = {
|
|
40455
|
+
name: string;
|
|
40456
|
+
mimeType: string;
|
|
40457
|
+
s3Url: string;
|
|
40458
|
+
filePath: string;
|
|
40459
|
+
};
|
|
40460
|
+
|
|
40461
|
+
declare class Files {
|
|
40462
|
+
private readonly client;
|
|
40463
|
+
constructor(client: ComposioClient);
|
|
40464
|
+
/**
|
|
40465
|
+
* Upload a file to S3 and return the file data.
|
|
40466
|
+
* @param filePath - The path to the file to upload or a URL of the file to upload.
|
|
40467
|
+
* @param toolSlug - The slug of the tool that is uploading the file.
|
|
40468
|
+
* @param toolkitSlug - The slug of the toolkit that is uploading the file.
|
|
40469
|
+
* @returns The file data.
|
|
40470
|
+
*/
|
|
40471
|
+
upload({ filePath, toolSlug, toolkitSlug, }: {
|
|
40472
|
+
filePath: string;
|
|
40473
|
+
toolSlug: string;
|
|
40474
|
+
toolkitSlug: string;
|
|
40475
|
+
}): Promise<FileUploadData>;
|
|
40476
|
+
/**
|
|
40477
|
+
* Download a file from S3 and return the file data.
|
|
40478
|
+
* @param s3key - The S3 key of the file to download.
|
|
40479
|
+
* @returns The file data.
|
|
40480
|
+
*/
|
|
40481
|
+
download({ toolSlug, s3Url, mimeType, }: {
|
|
40482
|
+
s3Url: string;
|
|
40483
|
+
toolSlug: string;
|
|
40484
|
+
mimeType: string;
|
|
40485
|
+
}): Promise<FileDownloadData>;
|
|
40486
|
+
}
|
|
40487
|
+
|
|
40446
40488
|
type ComposioConfig<TProvider extends BaseComposioProvider<unknown, unknown, unknown> = OpenAIProvider> = {
|
|
40447
40489
|
/**
|
|
40448
40490
|
* The API key for the Composio API.
|
|
@@ -40461,11 +40503,11 @@ type ComposioConfig<TProvider extends BaseComposioProvider<unknown, unknown, unk
|
|
|
40461
40503
|
*/
|
|
40462
40504
|
allowTracking?: boolean;
|
|
40463
40505
|
/**
|
|
40464
|
-
* Whether to
|
|
40506
|
+
* Whether to automatically upload and download files during tool execution.
|
|
40465
40507
|
* @example true, false
|
|
40466
40508
|
* @default true
|
|
40467
40509
|
*/
|
|
40468
|
-
|
|
40510
|
+
autoUploadDownloadFiles?: boolean;
|
|
40469
40511
|
/**
|
|
40470
40512
|
* The tool provider to use for this Composio instance.
|
|
40471
40513
|
* @example new OpenAIProvider()
|
|
@@ -40517,6 +40559,7 @@ declare class Composio<TProvider extends BaseComposioProvider<unknown, unknown,
|
|
|
40517
40559
|
toolkits: Toolkits;
|
|
40518
40560
|
triggers: Triggers;
|
|
40519
40561
|
provider: TProvider;
|
|
40562
|
+
files: Files;
|
|
40520
40563
|
authConfigs: AuthConfigs;
|
|
40521
40564
|
connectedAccounts: ConnectedAccounts;
|
|
40522
40565
|
mcp: MCP<ExtractMcpResponseType<TProvider>>;
|
|
@@ -40530,7 +40573,6 @@ declare class Composio<TProvider extends BaseComposioProvider<unknown, unknown,
|
|
|
40530
40573
|
* @param {string} [config.apiKey] - The API key for authenticating with the Composio API
|
|
40531
40574
|
* @param {string} [config.baseURL] - The base URL for the Composio API (defaults to production URL)
|
|
40532
40575
|
* @param {boolean} [config.allowTracking=true] - Whether to allow anonymous usage analytics
|
|
40533
|
-
* @param {boolean} [config.allowTracing=true] - Whether to allow request tracing for debugging
|
|
40534
40576
|
* @param {TProvider} [config.provider] - The provider to use for this Composio instance (defaults to OpenAIProvider)
|
|
40535
40577
|
*
|
|
40536
40578
|
* @example
|
package/dist/index.d.ts
CHANGED
|
@@ -10646,7 +10646,10 @@ declare class Tools<TToolCollection, TTool, TProvider extends BaseComposioProvid
|
|
|
10646
10646
|
private client;
|
|
10647
10647
|
private readonly customTools;
|
|
10648
10648
|
private provider;
|
|
10649
|
-
|
|
10649
|
+
private autoUploadDownloadFiles;
|
|
10650
|
+
constructor(client: ComposioClient, provider: TProvider, options?: {
|
|
10651
|
+
autoUploadDownloadFiles: boolean;
|
|
10652
|
+
});
|
|
10650
10653
|
/**
|
|
10651
10654
|
* Transforms tool data from snake_case API format to camelCase for internal SDK use.
|
|
10652
10655
|
*
|
|
@@ -40443,6 +40446,45 @@ declare class OpenAIProvider extends BaseNonAgenticProvider<OpenAiToolCollection
|
|
|
40443
40446
|
|
|
40444
40447
|
type ComposioRequestHeaders = Record<string, string>;
|
|
40445
40448
|
|
|
40449
|
+
type FileUploadData = {
|
|
40450
|
+
name: string;
|
|
40451
|
+
mimetype: string;
|
|
40452
|
+
s3key: string;
|
|
40453
|
+
};
|
|
40454
|
+
type FileDownloadData = {
|
|
40455
|
+
name: string;
|
|
40456
|
+
mimeType: string;
|
|
40457
|
+
s3Url: string;
|
|
40458
|
+
filePath: string;
|
|
40459
|
+
};
|
|
40460
|
+
|
|
40461
|
+
declare class Files {
|
|
40462
|
+
private readonly client;
|
|
40463
|
+
constructor(client: ComposioClient);
|
|
40464
|
+
/**
|
|
40465
|
+
* Upload a file to S3 and return the file data.
|
|
40466
|
+
* @param filePath - The path to the file to upload or a URL of the file to upload.
|
|
40467
|
+
* @param toolSlug - The slug of the tool that is uploading the file.
|
|
40468
|
+
* @param toolkitSlug - The slug of the toolkit that is uploading the file.
|
|
40469
|
+
* @returns The file data.
|
|
40470
|
+
*/
|
|
40471
|
+
upload({ filePath, toolSlug, toolkitSlug, }: {
|
|
40472
|
+
filePath: string;
|
|
40473
|
+
toolSlug: string;
|
|
40474
|
+
toolkitSlug: string;
|
|
40475
|
+
}): Promise<FileUploadData>;
|
|
40476
|
+
/**
|
|
40477
|
+
* Download a file from S3 and return the file data.
|
|
40478
|
+
* @param s3key - The S3 key of the file to download.
|
|
40479
|
+
* @returns The file data.
|
|
40480
|
+
*/
|
|
40481
|
+
download({ toolSlug, s3Url, mimeType, }: {
|
|
40482
|
+
s3Url: string;
|
|
40483
|
+
toolSlug: string;
|
|
40484
|
+
mimeType: string;
|
|
40485
|
+
}): Promise<FileDownloadData>;
|
|
40486
|
+
}
|
|
40487
|
+
|
|
40446
40488
|
type ComposioConfig<TProvider extends BaseComposioProvider<unknown, unknown, unknown> = OpenAIProvider> = {
|
|
40447
40489
|
/**
|
|
40448
40490
|
* The API key for the Composio API.
|
|
@@ -40461,11 +40503,11 @@ type ComposioConfig<TProvider extends BaseComposioProvider<unknown, unknown, unk
|
|
|
40461
40503
|
*/
|
|
40462
40504
|
allowTracking?: boolean;
|
|
40463
40505
|
/**
|
|
40464
|
-
* Whether to
|
|
40506
|
+
* Whether to automatically upload and download files during tool execution.
|
|
40465
40507
|
* @example true, false
|
|
40466
40508
|
* @default true
|
|
40467
40509
|
*/
|
|
40468
|
-
|
|
40510
|
+
autoUploadDownloadFiles?: boolean;
|
|
40469
40511
|
/**
|
|
40470
40512
|
* The tool provider to use for this Composio instance.
|
|
40471
40513
|
* @example new OpenAIProvider()
|
|
@@ -40517,6 +40559,7 @@ declare class Composio<TProvider extends BaseComposioProvider<unknown, unknown,
|
|
|
40517
40559
|
toolkits: Toolkits;
|
|
40518
40560
|
triggers: Triggers;
|
|
40519
40561
|
provider: TProvider;
|
|
40562
|
+
files: Files;
|
|
40520
40563
|
authConfigs: AuthConfigs;
|
|
40521
40564
|
connectedAccounts: ConnectedAccounts;
|
|
40522
40565
|
mcp: MCP<ExtractMcpResponseType<TProvider>>;
|
|
@@ -40530,7 +40573,6 @@ declare class Composio<TProvider extends BaseComposioProvider<unknown, unknown,
|
|
|
40530
40573
|
* @param {string} [config.apiKey] - The API key for authenticating with the Composio API
|
|
40531
40574
|
* @param {string} [config.baseURL] - The base URL for the Composio API (defaults to production URL)
|
|
40532
40575
|
* @param {boolean} [config.allowTracking=true] - Whether to allow anonymous usage analytics
|
|
40533
|
-
* @param {boolean} [config.allowTracing=true] - Whether to allow request tracing for debugging
|
|
40534
40576
|
* @param {TProvider} [config.provider] - The provider to use for this Composio instance (defaults to OpenAIProvider)
|
|
40535
40577
|
*
|
|
40536
40578
|
* @example
|
package/dist/index.js
CHANGED
|
@@ -1975,7 +1975,12 @@ var uploadFileToS3 = async (fileName, content, toolSlug, toolkitSlug, mimeType,
|
|
|
1975
1975
|
}
|
|
1976
1976
|
return key;
|
|
1977
1977
|
};
|
|
1978
|
-
var getFileDataAfterUploadingToS3 = async (
|
|
1978
|
+
var getFileDataAfterUploadingToS3 = async ({
|
|
1979
|
+
path,
|
|
1980
|
+
toolSlug,
|
|
1981
|
+
toolkitSlug,
|
|
1982
|
+
client
|
|
1983
|
+
}) => {
|
|
1979
1984
|
const isURL = path.startsWith("http");
|
|
1980
1985
|
const fileData = isURL ? await readFileContentFromURL(path) : await readFileContent(path);
|
|
1981
1986
|
logger_default.debug(`Uploading file to S3: ${path}`);
|
|
@@ -2010,7 +2015,7 @@ var downloadFileFromS3 = async ({
|
|
|
2010
2015
|
return {
|
|
2011
2016
|
name: fileName,
|
|
2012
2017
|
mimeType,
|
|
2013
|
-
|
|
2018
|
+
s3Url,
|
|
2014
2019
|
filePath
|
|
2015
2020
|
};
|
|
2016
2021
|
};
|
|
@@ -2073,7 +2078,7 @@ var transformProperties = (properties) => {
|
|
|
2073
2078
|
format: "path"
|
|
2074
2079
|
};
|
|
2075
2080
|
}
|
|
2076
|
-
return
|
|
2081
|
+
return newProperties;
|
|
2077
2082
|
};
|
|
2078
2083
|
var FileToolModifier = class {
|
|
2079
2084
|
client;
|
|
@@ -2122,12 +2127,12 @@ var FileToolModifier = class {
|
|
|
2122
2127
|
if (toolProperty?.file_uploadable) {
|
|
2123
2128
|
logger_default.debug(`Processing file upload for: ${key}`);
|
|
2124
2129
|
try {
|
|
2125
|
-
const fileData = await getFileDataAfterUploadingToS3(
|
|
2126
|
-
args[key],
|
|
2127
|
-
options.toolSlug,
|
|
2128
|
-
options.toolkitSlug ?? "unknown",
|
|
2129
|
-
this.client
|
|
2130
|
-
);
|
|
2130
|
+
const fileData = await getFileDataAfterUploadingToS3({
|
|
2131
|
+
path: args[key],
|
|
2132
|
+
toolSlug: options.toolSlug,
|
|
2133
|
+
toolkitSlug: options.toolkitSlug ?? "unknown",
|
|
2134
|
+
client: this.client
|
|
2135
|
+
});
|
|
2131
2136
|
args[key] = fileData;
|
|
2132
2137
|
} catch (error) {
|
|
2133
2138
|
throw new ComposioFileUploadError(`Failed to upload file: ${key}`, {
|
|
@@ -2149,8 +2154,6 @@ var FileToolModifier = class {
|
|
|
2149
2154
|
* @returns The result with the file download URL included.
|
|
2150
2155
|
*/
|
|
2151
2156
|
async fileDownloadModifier(tool, options) {
|
|
2152
|
-
console.log(JSON.stringify(options.result, null, 2));
|
|
2153
|
-
console.log(JSON.stringify(tool.outputParameters, null, 2));
|
|
2154
2157
|
for (const [key, value] of Object.entries(options.result?.data)) {
|
|
2155
2158
|
const fileData = value;
|
|
2156
2159
|
if (!fileData?.s3url) continue;
|
|
@@ -2189,7 +2192,8 @@ var Tools = class {
|
|
|
2189
2192
|
client;
|
|
2190
2193
|
customTools;
|
|
2191
2194
|
provider;
|
|
2192
|
-
|
|
2195
|
+
autoUploadDownloadFiles;
|
|
2196
|
+
constructor(client, provider, options) {
|
|
2193
2197
|
if (!client) {
|
|
2194
2198
|
throw new Error("ComposioClient is required");
|
|
2195
2199
|
}
|
|
@@ -2199,6 +2203,7 @@ var Tools = class {
|
|
|
2199
2203
|
this.client = client;
|
|
2200
2204
|
this.customTools = new CustomTools(client);
|
|
2201
2205
|
this.provider = provider;
|
|
2206
|
+
this.autoUploadDownloadFiles = options?.autoUploadDownloadFiles ?? true;
|
|
2202
2207
|
this.execute = this.execute.bind(this);
|
|
2203
2208
|
this.provider._setExecuteToolFn(this.execute);
|
|
2204
2209
|
this.getRawComposioToolBySlug = this.getRawComposioToolBySlug.bind(this);
|
|
@@ -2322,12 +2327,16 @@ var Tools = class {
|
|
|
2322
2327
|
* @returns The tools with the default schema modifiers applied
|
|
2323
2328
|
*/
|
|
2324
2329
|
async applyDefaultSchemaModifiers(tools) {
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2330
|
+
if (this.autoUploadDownloadFiles) {
|
|
2331
|
+
const fileToolModifier = new FileToolModifier(this.client);
|
|
2332
|
+
return await Promise.all(
|
|
2333
|
+
tools.map(
|
|
2334
|
+
(tool) => fileToolModifier.modifyToolSchema(tool.slug, tool.toolkit?.slug ?? "unknown", tool)
|
|
2335
|
+
)
|
|
2336
|
+
);
|
|
2337
|
+
} else {
|
|
2338
|
+
return tools;
|
|
2339
|
+
}
|
|
2331
2340
|
}
|
|
2332
2341
|
/**
|
|
2333
2342
|
* Applies the before execute modifiers to the tool execution params
|
|
@@ -2342,8 +2351,15 @@ var Tools = class {
|
|
|
2342
2351
|
toolkitSlug,
|
|
2343
2352
|
params
|
|
2344
2353
|
}, modifier) {
|
|
2345
|
-
const fileToolModifier = new FileToolModifier(this.client);
|
|
2346
2354
|
let modifiedParams = params;
|
|
2355
|
+
if (this.autoUploadDownloadFiles) {
|
|
2356
|
+
const fileToolModifier = new FileToolModifier(this.client);
|
|
2357
|
+
modifiedParams = await fileToolModifier.fileUploadModifier(tool, {
|
|
2358
|
+
toolSlug,
|
|
2359
|
+
toolkitSlug,
|
|
2360
|
+
params: modifiedParams
|
|
2361
|
+
});
|
|
2362
|
+
}
|
|
2347
2363
|
if (modifier) {
|
|
2348
2364
|
if (typeof modifier === "function") {
|
|
2349
2365
|
modifiedParams = await modifier({
|
|
@@ -2355,11 +2371,6 @@ var Tools = class {
|
|
|
2355
2371
|
throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
|
|
2356
2372
|
}
|
|
2357
2373
|
}
|
|
2358
|
-
modifiedParams = await fileToolModifier.fileUploadModifier(tool, {
|
|
2359
|
-
toolSlug,
|
|
2360
|
-
toolkitSlug,
|
|
2361
|
-
params: modifiedParams
|
|
2362
|
-
});
|
|
2363
2374
|
return modifiedParams;
|
|
2364
2375
|
}
|
|
2365
2376
|
/**
|
|
@@ -2375,8 +2386,15 @@ var Tools = class {
|
|
|
2375
2386
|
toolkitSlug,
|
|
2376
2387
|
result
|
|
2377
2388
|
}, modifier) {
|
|
2378
|
-
const fileToolModifier = new FileToolModifier(this.client);
|
|
2379
2389
|
let modifiedResult = result;
|
|
2390
|
+
if (this.autoUploadDownloadFiles) {
|
|
2391
|
+
const fileToolModifier = new FileToolModifier(this.client);
|
|
2392
|
+
modifiedResult = await fileToolModifier.fileDownloadModifier(tool, {
|
|
2393
|
+
toolSlug,
|
|
2394
|
+
toolkitSlug,
|
|
2395
|
+
result: modifiedResult
|
|
2396
|
+
});
|
|
2397
|
+
}
|
|
2380
2398
|
if (modifier) {
|
|
2381
2399
|
if (typeof modifier === "function") {
|
|
2382
2400
|
modifiedResult = await modifier({
|
|
@@ -2388,11 +2406,6 @@ var Tools = class {
|
|
|
2388
2406
|
throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
|
|
2389
2407
|
}
|
|
2390
2408
|
}
|
|
2391
|
-
modifiedResult = await fileToolModifier.fileDownloadModifier(tool, {
|
|
2392
|
-
toolSlug,
|
|
2393
|
-
toolkitSlug,
|
|
2394
|
-
result: modifiedResult
|
|
2395
|
-
});
|
|
2396
2409
|
return modifiedResult;
|
|
2397
2410
|
}
|
|
2398
2411
|
/**
|
|
@@ -5901,7 +5914,48 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
5901
5914
|
};
|
|
5902
5915
|
|
|
5903
5916
|
// package.json
|
|
5904
|
-
var version = "0.1.
|
|
5917
|
+
var version = "0.1.30";
|
|
5918
|
+
|
|
5919
|
+
// src/models/Files.ts
|
|
5920
|
+
var Files = class {
|
|
5921
|
+
constructor(client) {
|
|
5922
|
+
this.client = client;
|
|
5923
|
+
telemetry.instrument(this);
|
|
5924
|
+
}
|
|
5925
|
+
/**
|
|
5926
|
+
* Upload a file to S3 and return the file data.
|
|
5927
|
+
* @param filePath - The path to the file to upload or a URL of the file to upload.
|
|
5928
|
+
* @param toolSlug - The slug of the tool that is uploading the file.
|
|
5929
|
+
* @param toolkitSlug - The slug of the toolkit that is uploading the file.
|
|
5930
|
+
* @returns The file data.
|
|
5931
|
+
*/
|
|
5932
|
+
async upload({
|
|
5933
|
+
filePath,
|
|
5934
|
+
toolSlug,
|
|
5935
|
+
toolkitSlug
|
|
5936
|
+
}) {
|
|
5937
|
+
const fileData = await getFileDataAfterUploadingToS3({
|
|
5938
|
+
path: filePath,
|
|
5939
|
+
toolSlug,
|
|
5940
|
+
toolkitSlug,
|
|
5941
|
+
client: this.client
|
|
5942
|
+
});
|
|
5943
|
+
return fileData;
|
|
5944
|
+
}
|
|
5945
|
+
/**
|
|
5946
|
+
* Download a file from S3 and return the file data.
|
|
5947
|
+
* @param s3key - The S3 key of the file to download.
|
|
5948
|
+
* @returns The file data.
|
|
5949
|
+
*/
|
|
5950
|
+
async download({
|
|
5951
|
+
toolSlug,
|
|
5952
|
+
s3Url,
|
|
5953
|
+
mimeType
|
|
5954
|
+
}) {
|
|
5955
|
+
const fileDownloadData = await downloadFileFromS3({ toolSlug, s3Url, mimeType });
|
|
5956
|
+
return fileDownloadData;
|
|
5957
|
+
}
|
|
5958
|
+
};
|
|
5905
5959
|
|
|
5906
5960
|
// src/composio.ts
|
|
5907
5961
|
var Composio = class _Composio {
|
|
@@ -5922,6 +5976,7 @@ var Composio = class _Composio {
|
|
|
5922
5976
|
toolkits;
|
|
5923
5977
|
triggers;
|
|
5924
5978
|
provider;
|
|
5979
|
+
files;
|
|
5925
5980
|
// auth configs
|
|
5926
5981
|
authConfigs;
|
|
5927
5982
|
// connected accounts
|
|
@@ -5937,7 +5992,6 @@ var Composio = class _Composio {
|
|
|
5937
5992
|
* @param {string} [config.apiKey] - The API key for authenticating with the Composio API
|
|
5938
5993
|
* @param {string} [config.baseURL] - The base URL for the Composio API (defaults to production URL)
|
|
5939
5994
|
* @param {boolean} [config.allowTracking=true] - Whether to allow anonymous usage analytics
|
|
5940
|
-
* @param {boolean} [config.allowTracing=true] - Whether to allow request tracing for debugging
|
|
5941
5995
|
* @param {TProvider} [config.provider] - The provider to use for this Composio instance (defaults to OpenAIProvider)
|
|
5942
5996
|
*
|
|
5943
5997
|
* @example
|
|
@@ -5974,15 +6028,17 @@ var Composio = class _Composio {
|
|
|
5974
6028
|
});
|
|
5975
6029
|
this.config = {
|
|
5976
6030
|
...config,
|
|
5977
|
-
allowTracking: config?.allowTracking ?? true
|
|
5978
|
-
allowTracing: config?.allowTracing ?? true
|
|
6031
|
+
allowTracking: config?.allowTracking ?? true
|
|
5979
6032
|
};
|
|
5980
6033
|
this.provider = config?.provider ?? new OpenAIProvider();
|
|
5981
|
-
this.tools = new Tools(this.client, this.provider
|
|
6034
|
+
this.tools = new Tools(this.client, this.provider, {
|
|
6035
|
+
autoUploadDownloadFiles: config?.autoUploadDownloadFiles ?? true
|
|
6036
|
+
});
|
|
5982
6037
|
this.mcp = new MCP(this.client, this.provider);
|
|
5983
6038
|
this.toolkits = new Toolkits(this.client);
|
|
5984
6039
|
this.triggers = new Triggers(this.client);
|
|
5985
6040
|
this.authConfigs = new AuthConfigs(this.client);
|
|
6041
|
+
this.files = new Files(this.client);
|
|
5986
6042
|
this.connectedAccounts = new ConnectedAccounts(this.client);
|
|
5987
6043
|
if (this.config.allowTracking) {
|
|
5988
6044
|
telemetry.setup({
|
|
@@ -5992,11 +6048,7 @@ var Composio = class _Composio {
|
|
|
5992
6048
|
version,
|
|
5993
6049
|
isBrowser: typeof window !== "undefined",
|
|
5994
6050
|
provider: this.provider?.name ?? "openai",
|
|
5995
|
-
host: this.config.host
|
|
5996
|
-
// @TODO: Users might want to pass their own session id
|
|
5997
|
-
// @TODO: We shouldn't be doing this as people might always have one session id throughout the process in server
|
|
5998
|
-
sessionId: this.config.allowTracing ? getRandomUUID() : void 0
|
|
5999
|
-
// @TODO: get the session id
|
|
6051
|
+
host: this.config.host
|
|
6000
6052
|
});
|
|
6001
6053
|
}
|
|
6002
6054
|
telemetry.instrument(this);
|