@composio/core 0.1.55 → 0.2.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/index.cjs +186 -196
- package/dist/index.d.cts +194 -39
- package/dist/index.d.ts +194 -39
- package/dist/index.js +173 -185
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -68,6 +68,7 @@ __export(index_exports, {
|
|
|
68
68
|
ComposioProviderNotDefinedError: () => ComposioProviderNotDefinedError,
|
|
69
69
|
ComposioToolExecutionError: () => ComposioToolExecutionError,
|
|
70
70
|
ComposioToolNotFoundError: () => ComposioToolNotFoundError,
|
|
71
|
+
ComposioToolVersionRequiredError: () => ComposioToolVersionRequiredError,
|
|
71
72
|
ComposioToolkitFetchError: () => ComposioToolkitFetchError,
|
|
72
73
|
ComposioToolkitNotFoundError: () => ComposioToolkitNotFoundError,
|
|
73
74
|
ConnectedAccountAuthConfigSchema: () => ConnectedAccountAuthConfigSchema,
|
|
@@ -179,6 +180,7 @@ __export(index_exports, {
|
|
|
179
180
|
ValidationErrorCodes: () => ValidationErrorCodes,
|
|
180
181
|
constants: () => constants_exports,
|
|
181
182
|
createConnectionRequest: () => createConnectionRequest,
|
|
183
|
+
handleToolExecutionError: () => handleToolExecutionError,
|
|
182
184
|
jsonSchemaToZodSchema: () => jsonSchemaToZodSchema,
|
|
183
185
|
logger: () => logger_default,
|
|
184
186
|
removeNonRequiredProperties: () => removeNonRequiredProperties
|
|
@@ -186,7 +188,7 @@ __export(index_exports, {
|
|
|
186
188
|
module.exports = __toCommonJS(index_exports);
|
|
187
189
|
|
|
188
190
|
// src/composio.ts
|
|
189
|
-
var
|
|
191
|
+
var import_client8 = __toESM(require("@composio/client"), 1);
|
|
190
192
|
|
|
191
193
|
// src/types/tool.types.ts
|
|
192
194
|
var import_v33 = require("zod/v3");
|
|
@@ -893,8 +895,8 @@ var ToolExecuteParamsSchema = import_v33.z.object({
|
|
|
893
895
|
customConnectionData: CustomConnectionDataSchema.optional(),
|
|
894
896
|
arguments: import_v33.z.record(import_v33.z.string(), import_v33.z.unknown()).optional(),
|
|
895
897
|
userId: import_v33.z.string().optional(),
|
|
896
|
-
// we have no auth apps which can be execute
|
|
897
898
|
version: import_v33.z.union([import_v33.z.literal("latest"), import_v33.z.string()]).optional(),
|
|
899
|
+
dangerouslySkipVersionCheck: import_v33.z.boolean().optional(),
|
|
898
900
|
text: import_v33.z.string().optional()
|
|
899
901
|
});
|
|
900
902
|
var ToolExecuteResponseSchema = import_v33.z.object({
|
|
@@ -1046,6 +1048,9 @@ var Logger = class {
|
|
|
1046
1048
|
var logger = new Logger();
|
|
1047
1049
|
var logger_default = logger;
|
|
1048
1050
|
|
|
1051
|
+
// src/errors/ToolErrors.ts
|
|
1052
|
+
var import_client2 = require("@composio/client");
|
|
1053
|
+
|
|
1049
1054
|
// src/errors/ComposioError.ts
|
|
1050
1055
|
var import_chalk2 = __toESM(require("chalk"), 1);
|
|
1051
1056
|
var import_v34 = require("zod/v3");
|
|
@@ -1284,6 +1289,46 @@ ${originalStackBody}`;
|
|
|
1284
1289
|
}
|
|
1285
1290
|
};
|
|
1286
1291
|
|
|
1292
|
+
// src/errors/ConnectedAccountsErrors.ts
|
|
1293
|
+
var ConnectedAccountErrorCodes = {
|
|
1294
|
+
CONNECTED_ACCOUNT_NOT_FOUND: "CONNECTED_ACCOUNT_NOT_FOUND",
|
|
1295
|
+
MULTIPLE_CONNECTED_ACCOUNTS: "MULTIPLE_CONNECTED_ACCOUNTS",
|
|
1296
|
+
FAILED_TO_CREATE_CONNECTED_ACCOUNT_LINK: "FAILED_TO_CREATE_CONNECTED_ACCOUNT_LINK"
|
|
1297
|
+
};
|
|
1298
|
+
var ComposioConnectedAccountNotFoundError = class extends ComposioError {
|
|
1299
|
+
constructor(message = "Connected account not found", options = {}) {
|
|
1300
|
+
super(message, {
|
|
1301
|
+
...options,
|
|
1302
|
+
code: ConnectedAccountErrorCodes.CONNECTED_ACCOUNT_NOT_FOUND,
|
|
1303
|
+
statusCode: 404,
|
|
1304
|
+
possibleFixes: options.possibleFixes || [
|
|
1305
|
+
"Ensure the connected account exists and is active in your Composio dashboard"
|
|
1306
|
+
]
|
|
1307
|
+
});
|
|
1308
|
+
this.name = "ComposioConnectedAccountNotFoundError";
|
|
1309
|
+
}
|
|
1310
|
+
};
|
|
1311
|
+
var ComposioMultipleConnectedAccountsError = class extends ComposioError {
|
|
1312
|
+
constructor(message = "Multiple connected accounts found") {
|
|
1313
|
+
super(message, {
|
|
1314
|
+
code: ConnectedAccountErrorCodes.MULTIPLE_CONNECTED_ACCOUNTS,
|
|
1315
|
+
possibleFixes: [
|
|
1316
|
+
"Use the allowMultiple flag to allow multiple connected accounts per user for an auth config"
|
|
1317
|
+
]
|
|
1318
|
+
});
|
|
1319
|
+
this.name = "ComposioMultipleConnectedAccountsError";
|
|
1320
|
+
}
|
|
1321
|
+
};
|
|
1322
|
+
var ComposioFailedToCreateConnectedAccountLink = class extends ComposioError {
|
|
1323
|
+
constructor(message = "Failed to create connected account link", options = {}) {
|
|
1324
|
+
super(message, {
|
|
1325
|
+
...options,
|
|
1326
|
+
code: ConnectedAccountErrorCodes.FAILED_TO_CREATE_CONNECTED_ACCOUNT_LINK
|
|
1327
|
+
});
|
|
1328
|
+
this.name = "ComposioFailedToCreateConnectedAccountLink";
|
|
1329
|
+
}
|
|
1330
|
+
};
|
|
1331
|
+
|
|
1287
1332
|
// src/errors/ToolErrors.ts
|
|
1288
1333
|
var ToolErrorCodes = {
|
|
1289
1334
|
TOOLSET_NOT_DEFINED: "TOOLSET_NOT_DEFINED",
|
|
@@ -1292,7 +1337,8 @@ var ToolErrorCodes = {
|
|
|
1292
1337
|
CUSTOM_TOOLS_NOT_INITIALIZED: "CUSTOM_TOOLS_NOT_INITIALIZED",
|
|
1293
1338
|
TOOL_EXECUTION_ERROR: "TOOL_EXECUTION_ERROR",
|
|
1294
1339
|
INVALID_EXECUTE_FUNCTION: "INVALID_EXECUTE_FUNCTION",
|
|
1295
|
-
GLOBAL_EXECUTE_TOOL_FN_NOT_SET: "GLOBAL_EXECUTE_TOOL_FN_NOT_SET"
|
|
1340
|
+
GLOBAL_EXECUTE_TOOL_FN_NOT_SET: "GLOBAL_EXECUTE_TOOL_FN_NOT_SET",
|
|
1341
|
+
TOOL_VERSION_REQUIRED: "TOOL_VERSION_REQUIRED"
|
|
1296
1342
|
};
|
|
1297
1343
|
var ComposioProviderNotDefinedError = class extends ComposioError {
|
|
1298
1344
|
constructor(message = "Provider not defined", options = {}) {
|
|
@@ -1343,18 +1389,16 @@ var ComposioCustomToolsNotInitializedError = class extends ComposioError {
|
|
|
1343
1389
|
}
|
|
1344
1390
|
};
|
|
1345
1391
|
var ComposioToolExecutionError = class extends ComposioError {
|
|
1346
|
-
error;
|
|
1347
1392
|
constructor(message = "Tool execution error", options = {}) {
|
|
1348
|
-
const { originalError, ...restOptions } = options;
|
|
1349
1393
|
super(message, {
|
|
1350
|
-
...
|
|
1394
|
+
...options,
|
|
1351
1395
|
code: options.code || ToolErrorCodes.TOOL_EXECUTION_ERROR,
|
|
1352
|
-
cause: options.cause
|
|
1396
|
+
cause: options.cause,
|
|
1353
1397
|
possibleFixes: options.possibleFixes || [
|
|
1354
|
-
"Ensure the tool is correctly configured and the input is valid"
|
|
1398
|
+
"Ensure the tool is correctly configured and the input is valid",
|
|
1399
|
+
"Ensure the userId is correct and has an active connected account for the user in case of non NoAuth toolkits"
|
|
1355
1400
|
]
|
|
1356
1401
|
});
|
|
1357
|
-
this.error = originalError || (options.cause instanceof Error ? options.cause : options.cause ? new Error(String(options.cause)) : new Error("Unknown error"));
|
|
1358
1402
|
this.name = "ComposioToolExecutionError";
|
|
1359
1403
|
}
|
|
1360
1404
|
};
|
|
@@ -1382,49 +1426,43 @@ var ComposioGlobalExecuteToolFnNotSetError = class extends ComposioError {
|
|
|
1382
1426
|
this.name = "ComposioGlobalExecuteToolFnNotSetError";
|
|
1383
1427
|
}
|
|
1384
1428
|
};
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
var ConnectedAccountErrorCodes = {
|
|
1388
|
-
CONNECTED_ACCOUNT_NOT_FOUND: "CONNECTED_ACCOUNT_NOT_FOUND",
|
|
1389
|
-
MULTIPLE_CONNECTED_ACCOUNTS: "MULTIPLE_CONNECTED_ACCOUNTS",
|
|
1390
|
-
FAILED_TO_CREATE_CONNECTED_ACCOUNT_LINK: "FAILED_TO_CREATE_CONNECTED_ACCOUNT_LINK"
|
|
1391
|
-
};
|
|
1392
|
-
var ComposioConnectedAccountNotFoundError = class extends ComposioError {
|
|
1393
|
-
constructor(message = "Connected account not found", options = {}) {
|
|
1429
|
+
var ComposioToolVersionRequiredError = class extends ComposioError {
|
|
1430
|
+
constructor(message = "Toolkit version not specified. For manual execution of the tool please pass a specific toolkit version", options = {}) {
|
|
1394
1431
|
super(message, {
|
|
1395
1432
|
...options,
|
|
1396
|
-
code:
|
|
1397
|
-
statusCode: 404,
|
|
1433
|
+
code: ToolErrorCodes.TOOL_VERSION_REQUIRED,
|
|
1398
1434
|
possibleFixes: options.possibleFixes || [
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
}
|
|
1404
|
-
};
|
|
1405
|
-
var ComposioMultipleConnectedAccountsError = class extends ComposioError {
|
|
1406
|
-
constructor(message = "Multiple connected accounts found") {
|
|
1407
|
-
super(message, {
|
|
1408
|
-
code: ConnectedAccountErrorCodes.MULTIPLE_CONNECTED_ACCOUNTS,
|
|
1409
|
-
possibleFixes: [
|
|
1410
|
-
"Use the allowMultiple flag to allow multiple connected accounts per user for an auth config"
|
|
1435
|
+
'Pass the toolkit version as a parameter to the execute function ("latest" is not supported in manual execution)',
|
|
1436
|
+
'Set the toolkit versions in the Composio config (toolkitVersions: { <toolkit-slug>: "<toolkit-version>" })',
|
|
1437
|
+
"Set the toolkit version in the environment variable (COMPOSIO_TOOLKIT_VERSION_<TOOLKIT_SLUG>)",
|
|
1438
|
+
"Set dangerouslySkipVersionCheck to true (this might cause unexpected behavior when new versions of the tools are released)"
|
|
1411
1439
|
]
|
|
1412
1440
|
});
|
|
1413
|
-
this.name = "ComposioMultipleConnectedAccountsError";
|
|
1414
1441
|
}
|
|
1415
1442
|
};
|
|
1416
|
-
var
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1443
|
+
var ERROR_CODE_HANDLERS = /* @__PURE__ */ new Map([
|
|
1444
|
+
[1803, (msg) => new ComposioConnectedAccountNotFoundError(msg)]
|
|
1445
|
+
// Add more error code handlers here as needed
|
|
1446
|
+
]);
|
|
1447
|
+
var handleToolExecutionError = (tool, actualError) => {
|
|
1448
|
+
if (actualError instanceof import_client2.APIError && actualError.error) {
|
|
1449
|
+
const errorBody = actualError.error;
|
|
1450
|
+
const errorCode = errorBody?.error?.code;
|
|
1451
|
+
const errorMessage = errorBody?.error?.message;
|
|
1452
|
+
if (errorCode && ERROR_CODE_HANDLERS.has(errorCode)) {
|
|
1453
|
+
return ERROR_CODE_HANDLERS.get(errorCode)(errorMessage || "An error occurred");
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
return new ComposioToolExecutionError(`Error executing the tool ${tool}`, {
|
|
1457
|
+
cause: actualError,
|
|
1458
|
+
possibleFixes: [
|
|
1459
|
+
"Ensure the tool slug is correct and the input arguments for the tool is valid"
|
|
1460
|
+
]
|
|
1461
|
+
});
|
|
1424
1462
|
};
|
|
1425
1463
|
|
|
1426
1464
|
// src/telemetry/Telemetry.ts
|
|
1427
|
-
var
|
|
1465
|
+
var import_client3 = require("@composio/client");
|
|
1428
1466
|
|
|
1429
1467
|
// src/types/telemetry.types.ts
|
|
1430
1468
|
var TELEMETRY_EVENTS = {
|
|
@@ -1645,7 +1683,7 @@ var TelemetryTransport = class {
|
|
|
1645
1683
|
},
|
|
1646
1684
|
source: this.telemetrySource
|
|
1647
1685
|
};
|
|
1648
|
-
if (error instanceof
|
|
1686
|
+
if (error instanceof import_client3.ComposioError) {
|
|
1649
1687
|
telemetryPayload.error = {
|
|
1650
1688
|
errorId: error.errorId,
|
|
1651
1689
|
name: error.name,
|
|
@@ -2135,9 +2173,6 @@ var CustomTools = class {
|
|
|
2135
2173
|
* ```
|
|
2136
2174
|
*/
|
|
2137
2175
|
async getCustomToolBySlug(slug) {
|
|
2138
|
-
if (!slug) {
|
|
2139
|
-
throw new Error("Tool slug is required");
|
|
2140
|
-
}
|
|
2141
2176
|
try {
|
|
2142
2177
|
const tool = this.customToolsRegistry.get(slug.toLowerCase());
|
|
2143
2178
|
return tool?.schema;
|
|
@@ -2775,39 +2810,6 @@ var Tools = class {
|
|
|
2775
2810
|
sessionInfo: response.session_info
|
|
2776
2811
|
});
|
|
2777
2812
|
}
|
|
2778
|
-
/**
|
|
2779
|
-
* Get the connected account id for a given tool
|
|
2780
|
-
* @param {string} userId - The user id
|
|
2781
|
-
* @param {string} toolSlug - The tool slug
|
|
2782
|
-
* @returns {Promise<string | null>} The connected account id or null if the toolkit is a no auth app
|
|
2783
|
-
*/
|
|
2784
|
-
async getConnectedAccountIdForTool(userId, toolSlug) {
|
|
2785
|
-
const tool = await this.getRawComposioToolBySlug(toolSlug);
|
|
2786
|
-
if (!tool.toolkit) {
|
|
2787
|
-
throw new Error(`Unable to find toolkit for tool ${toolSlug}`);
|
|
2788
|
-
}
|
|
2789
|
-
const toolkit = await this.client.toolkits.retrieve(tool.toolkit.slug);
|
|
2790
|
-
if (!toolkit) {
|
|
2791
|
-
throw new Error(`Unable to find toolkit for tool ${toolSlug}`);
|
|
2792
|
-
}
|
|
2793
|
-
const isNoAuthApp = toolkit.auth_config_details?.some(
|
|
2794
|
-
(authConfigDetails) => authConfigDetails.mode === AuthSchemeTypes.NO_AUTH
|
|
2795
|
-
);
|
|
2796
|
-
if (!isNoAuthApp) {
|
|
2797
|
-
const connectedAccounts = await this.client.connectedAccounts.list({
|
|
2798
|
-
user_ids: [userId],
|
|
2799
|
-
toolkit_slugs: [tool.toolkit.slug]
|
|
2800
|
-
});
|
|
2801
|
-
if (connectedAccounts.items.length === 0) {
|
|
2802
|
-
throw new Error("No connected accounts found");
|
|
2803
|
-
}
|
|
2804
|
-
logger_default.warn(
|
|
2805
|
-
`Using the first connected account for tool ${toolSlug}. To change this behaviour please explicitly pass a connectedAccountId for the tool`
|
|
2806
|
-
);
|
|
2807
|
-
return connectedAccounts.items[0].id;
|
|
2808
|
-
}
|
|
2809
|
-
return null;
|
|
2810
|
-
}
|
|
2811
2813
|
/**
|
|
2812
2814
|
* Applies the default schema modifiers to the tools
|
|
2813
2815
|
* @param tools - The tools to apply the default schema modifiers to
|
|
@@ -3137,7 +3139,10 @@ var Tools = class {
|
|
|
3137
3139
|
toolSlug,
|
|
3138
3140
|
{
|
|
3139
3141
|
userId,
|
|
3140
|
-
arguments: input
|
|
3142
|
+
arguments: input,
|
|
3143
|
+
// dangerously skip version check for agentic and non agentic tool execution via providers
|
|
3144
|
+
// this can be safe because most agentic flows users fetch latest version and then execute the tool
|
|
3145
|
+
dangerouslySkipVersionCheck: true
|
|
3141
3146
|
},
|
|
3142
3147
|
modifiers
|
|
3143
3148
|
);
|
|
@@ -3146,81 +3151,32 @@ var Tools = class {
|
|
|
3146
3151
|
}
|
|
3147
3152
|
/**
|
|
3148
3153
|
* @internal
|
|
3149
|
-
*
|
|
3154
|
+
* Executes a composio tool via API without modifiers
|
|
3150
3155
|
* @param tool - The tool to execute
|
|
3151
3156
|
* @param body - The body of the tool execution
|
|
3152
|
-
* @param modifiers - The modifiers to be applied to the tool execution
|
|
3153
3157
|
* @returns The response from the tool execution
|
|
3154
3158
|
*/
|
|
3155
|
-
async
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
toolSlug: tool.slug,
|
|
3160
|
-
toolkitSlug: tool.toolkit?.slug ?? "unknown",
|
|
3161
|
-
params: body
|
|
3162
|
-
});
|
|
3163
|
-
} else {
|
|
3164
|
-
throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
|
|
3165
|
-
}
|
|
3159
|
+
async executeComposioTool(tool, body) {
|
|
3160
|
+
const toolkitVersion = body.version ?? getToolkitVersion(tool.toolkit?.slug ?? "unknown", this.toolkitVersions);
|
|
3161
|
+
if (toolkitVersion === "latest" && !body.dangerouslySkipVersionCheck) {
|
|
3162
|
+
throw new ComposioToolVersionRequiredError();
|
|
3166
3163
|
}
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
}
|
|
3164
|
+
try {
|
|
3165
|
+
const result = await this.client.tools.execute(tool.slug, {
|
|
3166
|
+
allow_tracing: body.allowTracing,
|
|
3167
|
+
connected_account_id: body.connectedAccountId,
|
|
3168
|
+
custom_auth_params: body.customAuthParams,
|
|
3169
|
+
custom_connection_data: body.customConnectionData,
|
|
3170
|
+
arguments: body.arguments,
|
|
3171
|
+
user_id: body.userId,
|
|
3172
|
+
version: toolkitVersion,
|
|
3173
|
+
text: body.text
|
|
3174
|
+
});
|
|
3175
|
+
return this.transformToolExecuteResponse(result);
|
|
3176
|
+
} catch (error) {
|
|
3177
|
+
const toolError = handleToolExecutionError(tool.slug, error);
|
|
3178
|
+
throw toolError;
|
|
3178
3179
|
}
|
|
3179
|
-
return result;
|
|
3180
|
-
}
|
|
3181
|
-
/**
|
|
3182
|
-
* @internal
|
|
3183
|
-
* Handles the execution of a composio tool
|
|
3184
|
-
* @param tool - The tool to execute
|
|
3185
|
-
* @param body - The body of the tool execution
|
|
3186
|
-
* @param modifiers - The modifiers to be applied to the tool execution
|
|
3187
|
-
* @returns The response from the tool execution
|
|
3188
|
-
*/
|
|
3189
|
-
async handleComposioToolExecution(tool, body, modifiers) {
|
|
3190
|
-
body = await this.applyBeforeExecuteModifiers(
|
|
3191
|
-
tool,
|
|
3192
|
-
{
|
|
3193
|
-
toolSlug: tool.slug,
|
|
3194
|
-
toolkitSlug: tool.toolkit?.slug ?? "unknown",
|
|
3195
|
-
params: body
|
|
3196
|
-
},
|
|
3197
|
-
modifiers?.beforeExecute
|
|
3198
|
-
);
|
|
3199
|
-
let connectedAccountId = body.connectedAccountId;
|
|
3200
|
-
if (!connectedAccountId && body.userId) {
|
|
3201
|
-
connectedAccountId = await this.getConnectedAccountIdForTool(body.userId, tool.slug) || void 0;
|
|
3202
|
-
}
|
|
3203
|
-
let result = await this.client.tools.execute(tool.slug, {
|
|
3204
|
-
allow_tracing: body.allowTracing,
|
|
3205
|
-
connected_account_id: body.connectedAccountId,
|
|
3206
|
-
custom_auth_params: body.customAuthParams,
|
|
3207
|
-
custom_connection_data: body.customConnectionData,
|
|
3208
|
-
arguments: body.arguments,
|
|
3209
|
-
user_id: body.userId,
|
|
3210
|
-
version: body.version ?? getToolkitVersion(tool.toolkit?.slug ?? "unknown", this.toolkitVersions),
|
|
3211
|
-
text: body.text
|
|
3212
|
-
});
|
|
3213
|
-
result = this.transformToolExecuteResponse(result);
|
|
3214
|
-
result = await this.applyAfterExecuteModifiers(
|
|
3215
|
-
tool,
|
|
3216
|
-
{
|
|
3217
|
-
toolSlug: tool.slug,
|
|
3218
|
-
toolkitSlug: tool.toolkit?.slug ?? "unknown",
|
|
3219
|
-
result
|
|
3220
|
-
},
|
|
3221
|
-
modifiers?.afterExecute
|
|
3222
|
-
);
|
|
3223
|
-
return result;
|
|
3224
3180
|
}
|
|
3225
3181
|
/**
|
|
3226
3182
|
* Executes a given tool with the provided parameters.
|
|
@@ -3228,34 +3184,68 @@ var Tools = class {
|
|
|
3228
3184
|
* This method calls the Composio API or a custom tool handler to execute the tool and returns the response.
|
|
3229
3185
|
* It automatically determines whether to use a custom tool or a Composio API tool based on the slug.
|
|
3230
3186
|
*
|
|
3187
|
+
* **Version Control:**
|
|
3188
|
+
* By default, manual tool execution requires a specific toolkit version. If the version resolves to "latest",
|
|
3189
|
+
* the execution will throw a `ComposioToolVersionRequiredError` unless `dangerouslySkipVersionCheck` is set to `true`.
|
|
3190
|
+
* This helps prevent unexpected behavior when new toolkit versions are released.
|
|
3191
|
+
*
|
|
3231
3192
|
* @param {string} slug - The slug/ID of the tool to be executed
|
|
3232
3193
|
* @param {ToolExecuteParams} body - The parameters to be passed to the tool
|
|
3194
|
+
* @param {string} [body.version] - The specific version of the tool to execute (e.g., "20250909_00")
|
|
3195
|
+
* @param {boolean} [body.dangerouslySkipVersionCheck] - Skip version validation for "latest" version (use with caution)
|
|
3196
|
+
* @param {string} [body.userId] - The user ID to execute the tool for
|
|
3197
|
+
* @param {string} [body.connectedAccountId] - The connected account ID to use for authenticated tools
|
|
3198
|
+
* @param {Record<string, unknown>} [body.arguments] - The arguments to pass to the tool
|
|
3233
3199
|
* @param {ExecuteToolModifiers} [modifiers] - Optional modifiers to transform the request or response
|
|
3234
3200
|
* @returns {Promise<ToolExecuteResponse>} - The response from the tool execution
|
|
3235
3201
|
*
|
|
3236
3202
|
* @throws {ComposioCustomToolsNotInitializedError} If the CustomTools instance is not initialized
|
|
3203
|
+
* @throws {ComposioConnectedAccountNotFoundError} If the connected account is not found
|
|
3237
3204
|
* @throws {ComposioToolNotFoundError} If the tool with the given slug is not found
|
|
3205
|
+
* @throws {ComposioToolVersionRequiredError} If version resolves to "latest" and dangerouslySkipVersionCheck is not true
|
|
3238
3206
|
* @throws {ComposioToolExecutionError} If there is an error during tool execution
|
|
3239
3207
|
*
|
|
3240
|
-
* @example
|
|
3208
|
+
* @example Execute with a specific version (recommended for production)
|
|
3209
|
+
* ```typescript
|
|
3210
|
+
* const result = await composio.tools.execute('GITHUB_GET_REPOS', {
|
|
3211
|
+
* userId: 'default',
|
|
3212
|
+
* version: '20250909_00',
|
|
3213
|
+
* arguments: { owner: 'composio' }
|
|
3214
|
+
* });
|
|
3215
|
+
* ```
|
|
3216
|
+
*
|
|
3217
|
+
* @example Execute with dangerouslySkipVersionCheck (not recommended for production)
|
|
3241
3218
|
* ```typescript
|
|
3242
|
-
* // Execute a Composio API tool
|
|
3243
3219
|
* const result = await composio.tools.execute('HACKERNEWS_GET_USER', {
|
|
3244
3220
|
* userId: 'default',
|
|
3245
|
-
* arguments: { userId: 'pg' }
|
|
3221
|
+
* arguments: { userId: 'pg' },
|
|
3222
|
+
* dangerouslySkipVersionCheck: true // Allows execution with "latest" version
|
|
3246
3223
|
* });
|
|
3224
|
+
* ```
|
|
3247
3225
|
*
|
|
3248
|
-
*
|
|
3226
|
+
* @example Execute with SDK-level toolkit versions configuration
|
|
3227
|
+
* ```typescript
|
|
3228
|
+
* // If toolkitVersions are set during Composio initialization, no need to pass version
|
|
3229
|
+
* const composio = new Composio({ toolkitVersions: { github: '20250909_00' } });
|
|
3230
|
+
* const result = await composio.tools.execute('GITHUB_GET_REPOS', {
|
|
3231
|
+
* userId: 'default',
|
|
3232
|
+
* arguments: { owner: 'composio' }
|
|
3233
|
+
* });
|
|
3234
|
+
* ```
|
|
3235
|
+
*
|
|
3236
|
+
* @example Execute with modifiers
|
|
3237
|
+
* ```typescript
|
|
3249
3238
|
* const result = await composio.tools.execute('GITHUB_GET_ISSUES', {
|
|
3250
3239
|
* userId: 'default',
|
|
3240
|
+
* version: '20250909_00',
|
|
3251
3241
|
* arguments: { owner: 'composio', repo: 'sdk' }
|
|
3252
3242
|
* }, {
|
|
3253
|
-
* beforeExecute: (toolSlug, toolkitSlug, params) => {
|
|
3254
|
-
*
|
|
3243
|
+
* beforeExecute: ({ toolSlug, toolkitSlug, params }) => {
|
|
3244
|
+
* console.log(`Executing ${toolSlug} from ${toolkitSlug}`);
|
|
3255
3245
|
* return params;
|
|
3256
3246
|
* },
|
|
3257
|
-
* afterExecute: (toolSlug, toolkitSlug, result) => {
|
|
3258
|
-
*
|
|
3247
|
+
* afterExecute: ({ toolSlug, toolkitSlug, result }) => {
|
|
3248
|
+
* console.log(`Completed ${toolSlug}`);
|
|
3259
3249
|
* return result;
|
|
3260
3250
|
* }
|
|
3261
3251
|
* });
|
|
@@ -3271,31 +3261,29 @@ var Tools = class {
|
|
|
3271
3261
|
if (!executeParams.success) {
|
|
3272
3262
|
throw new ValidationError("Invalid tool execute parameters", { cause: executeParams.error });
|
|
3273
3263
|
}
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
);
|
|
3298
|
-
}
|
|
3264
|
+
const customTool = await this.customTools.getCustomToolBySlug(slug);
|
|
3265
|
+
const tool = customTool ?? await this.getRawComposioToolBySlug(slug);
|
|
3266
|
+
const toolkitSlug = tool.toolkit?.slug ?? "unknown";
|
|
3267
|
+
const params = await this.applyBeforeExecuteModifiers(
|
|
3268
|
+
tool,
|
|
3269
|
+
{
|
|
3270
|
+
toolSlug: slug,
|
|
3271
|
+
toolkitSlug,
|
|
3272
|
+
params: executeParams.data
|
|
3273
|
+
},
|
|
3274
|
+
modifiers?.beforeExecute
|
|
3275
|
+
);
|
|
3276
|
+
let result = customTool ? await this.customTools.executeCustomTool(customTool.slug, params) : await this.executeComposioTool(tool, params);
|
|
3277
|
+
result = await this.applyAfterExecuteModifiers(
|
|
3278
|
+
tool,
|
|
3279
|
+
{
|
|
3280
|
+
toolSlug: slug,
|
|
3281
|
+
toolkitSlug,
|
|
3282
|
+
result
|
|
3283
|
+
},
|
|
3284
|
+
modifiers?.afterExecute
|
|
3285
|
+
);
|
|
3286
|
+
return result;
|
|
3299
3287
|
}
|
|
3300
3288
|
/**
|
|
3301
3289
|
* Fetches the list of all available tools in the Composio SDK.
|
|
@@ -3437,7 +3425,7 @@ var Tools = class {
|
|
|
3437
3425
|
};
|
|
3438
3426
|
|
|
3439
3427
|
// src/models/Toolkits.ts
|
|
3440
|
-
var
|
|
3428
|
+
var import_client5 = __toESM(require("@composio/client"), 1);
|
|
3441
3429
|
|
|
3442
3430
|
// src/types/toolkit.types.ts
|
|
3443
3431
|
var import_v37 = require("zod/v3");
|
|
@@ -3835,7 +3823,7 @@ var AuthConfigs = class {
|
|
|
3835
3823
|
};
|
|
3836
3824
|
|
|
3837
3825
|
// src/models/ConnectionRequest.ts
|
|
3838
|
-
var
|
|
3826
|
+
var import_client4 = __toESM(require("@composio/client"), 1);
|
|
3839
3827
|
function createConnectionRequest(client, connectedAccountId, status, redirectUrl) {
|
|
3840
3828
|
const state = {
|
|
3841
3829
|
id: connectedAccountId,
|
|
@@ -3851,7 +3839,7 @@ function createConnectionRequest(client, connectedAccountId, status, redirectUrl
|
|
|
3851
3839
|
return transformConnectedAccountResponse(response);
|
|
3852
3840
|
}
|
|
3853
3841
|
} catch (error) {
|
|
3854
|
-
if (error instanceof
|
|
3842
|
+
if (error instanceof import_client4.default.NotFoundError) {
|
|
3855
3843
|
throw new ComposioConnectedAccountNotFoundError(
|
|
3856
3844
|
`Connected account with id ${state.id} not found`,
|
|
3857
3845
|
{
|
|
@@ -4539,7 +4527,7 @@ var Toolkits = class {
|
|
|
4539
4527
|
});
|
|
4540
4528
|
authConfigIdToUse = authConfig.id;
|
|
4541
4529
|
} catch (error) {
|
|
4542
|
-
if (error instanceof
|
|
4530
|
+
if (error instanceof import_client5.default.APIError && error.status === 400) {
|
|
4543
4531
|
throw new ComposioAuthConfigNotFoundError(
|
|
4544
4532
|
`No Default auth config found for toolkit ${toolkitSlug}`,
|
|
4545
4533
|
{
|
|
@@ -4575,7 +4563,7 @@ var Toolkits = class {
|
|
|
4575
4563
|
};
|
|
4576
4564
|
|
|
4577
4565
|
// src/models/Triggers.ts
|
|
4578
|
-
var
|
|
4566
|
+
var import_client7 = require("@composio/client");
|
|
4579
4567
|
|
|
4580
4568
|
// src/types/triggers.types.ts
|
|
4581
4569
|
var import_v38 = require("zod/v3");
|
|
@@ -4725,7 +4713,7 @@ var InternalService = class {
|
|
|
4725
4713
|
};
|
|
4726
4714
|
|
|
4727
4715
|
// src/errors/TriggerErrors.ts
|
|
4728
|
-
var
|
|
4716
|
+
var import_client6 = require("@composio/client");
|
|
4729
4717
|
var TriggerErrorCodes = {
|
|
4730
4718
|
TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS: "TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS",
|
|
4731
4719
|
TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT: "TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT",
|
|
@@ -4733,7 +4721,7 @@ var TriggerErrorCodes = {
|
|
|
4733
4721
|
TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL: "TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL",
|
|
4734
4722
|
TRIGGER_TYPE_NOT_FOUND: "TRIGGER_TYPE_NOT_FOUND"
|
|
4735
4723
|
};
|
|
4736
|
-
var ComposioFailedToGetSDKRealtimeCredentialsError = class extends
|
|
4724
|
+
var ComposioFailedToGetSDKRealtimeCredentialsError = class extends import_client6.ComposioError {
|
|
4737
4725
|
name = "ComposioFailedToGetSDKRealtimeCredentialsError";
|
|
4738
4726
|
code = TriggerErrorCodes.TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS;
|
|
4739
4727
|
statusCode = 500;
|
|
@@ -4742,7 +4730,7 @@ var ComposioFailedToGetSDKRealtimeCredentialsError = class extends import_client
|
|
|
4742
4730
|
super(message, options);
|
|
4743
4731
|
}
|
|
4744
4732
|
};
|
|
4745
|
-
var ComposioFailedToCreatePusherClientError = class extends
|
|
4733
|
+
var ComposioFailedToCreatePusherClientError = class extends import_client6.ComposioError {
|
|
4746
4734
|
name = "ComposioFailedToCreatePusherClientError";
|
|
4747
4735
|
code = TriggerErrorCodes.TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT;
|
|
4748
4736
|
statusCode = 500;
|
|
@@ -4751,7 +4739,7 @@ var ComposioFailedToCreatePusherClientError = class extends import_client5.Compo
|
|
|
4751
4739
|
super(message, options);
|
|
4752
4740
|
}
|
|
4753
4741
|
};
|
|
4754
|
-
var ComposioFailedToSubscribeToPusherChannelError = class extends
|
|
4742
|
+
var ComposioFailedToSubscribeToPusherChannelError = class extends import_client6.ComposioError {
|
|
4755
4743
|
name = "ComposioFailedToSubscribeToPusherChannelError";
|
|
4756
4744
|
code = TriggerErrorCodes.TRIGGER_FAILED_TO_SUBSCRIBE_TO_PUSHER_CHANNEL;
|
|
4757
4745
|
statusCode = 500;
|
|
@@ -4760,7 +4748,7 @@ var ComposioFailedToSubscribeToPusherChannelError = class extends import_client5
|
|
|
4760
4748
|
super(message, options);
|
|
4761
4749
|
}
|
|
4762
4750
|
};
|
|
4763
|
-
var ComposioTriggerTypeNotFoundError = class extends
|
|
4751
|
+
var ComposioTriggerTypeNotFoundError = class extends import_client6.ComposioError {
|
|
4764
4752
|
name = "ComposioTriggerTypeNotFoundError";
|
|
4765
4753
|
code = TriggerErrorCodes.TRIGGER_TYPE_NOT_FOUND;
|
|
4766
4754
|
statusCode = 404;
|
|
@@ -5091,7 +5079,7 @@ var Triggers = class {
|
|
|
5091
5079
|
triggerType = await this.getType(slug);
|
|
5092
5080
|
toolkitSlug = triggerType.toolkit.slug;
|
|
5093
5081
|
} catch (error) {
|
|
5094
|
-
if (error instanceof
|
|
5082
|
+
if (error instanceof import_client7.APIError && (error.status === 400 || error.status === 404)) {
|
|
5095
5083
|
throw new ComposioTriggerTypeNotFoundError(`Trigger type ${slug} not found`, {
|
|
5096
5084
|
cause: error,
|
|
5097
5085
|
possibleFixes: [
|
|
@@ -5140,7 +5128,7 @@ var Triggers = class {
|
|
|
5140
5128
|
);
|
|
5141
5129
|
}
|
|
5142
5130
|
} catch (error) {
|
|
5143
|
-
if (error instanceof
|
|
5131
|
+
if (error instanceof import_client7.APIError && [400, 404].includes(error.status)) {
|
|
5144
5132
|
throw new ComposioConnectedAccountNotFoundError(
|
|
5145
5133
|
`No connected account found for user ${userId} for toolkit ${toolkitSlug}`,
|
|
5146
5134
|
{
|
|
@@ -7352,7 +7340,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
7352
7340
|
};
|
|
7353
7341
|
|
|
7354
7342
|
// package.json
|
|
7355
|
-
var version = "0.
|
|
7343
|
+
var version = "0.2.0";
|
|
7356
7344
|
|
|
7357
7345
|
// src/models/Files.ts
|
|
7358
7346
|
var Files = class {
|
|
@@ -7565,7 +7553,7 @@ var Composio = class _Composio {
|
|
|
7565
7553
|
};
|
|
7566
7554
|
this.provider = config?.provider ?? new OpenAIProvider();
|
|
7567
7555
|
const defaultHeaders = getDefaultHeaders(this.config.defaultHeaders, this.provider);
|
|
7568
|
-
this.client = new
|
|
7556
|
+
this.client = new import_client8.default({
|
|
7569
7557
|
apiKey: apiKeyParsed,
|
|
7570
7558
|
baseURL: baseURLParsed,
|
|
7571
7559
|
defaultHeaders,
|
|
@@ -7897,6 +7885,7 @@ var AuthScheme = class {
|
|
|
7897
7885
|
ComposioProviderNotDefinedError,
|
|
7898
7886
|
ComposioToolExecutionError,
|
|
7899
7887
|
ComposioToolNotFoundError,
|
|
7888
|
+
ComposioToolVersionRequiredError,
|
|
7900
7889
|
ComposioToolkitFetchError,
|
|
7901
7890
|
ComposioToolkitNotFoundError,
|
|
7902
7891
|
ConnectedAccountAuthConfigSchema,
|
|
@@ -8008,6 +7997,7 @@ var AuthScheme = class {
|
|
|
8008
7997
|
ValidationErrorCodes,
|
|
8009
7998
|
constants,
|
|
8010
7999
|
createConnectionRequest,
|
|
8000
|
+
handleToolExecutionError,
|
|
8011
8001
|
jsonSchemaToZodSchema,
|
|
8012
8002
|
logger,
|
|
8013
8003
|
removeNonRequiredProperties
|