@composio/core 0.1.9-alpha.0 → 0.1.11-alpha.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/README.md +6 -6
- package/dist/index.cjs +200 -102
- package/dist/index.d.cts +151 -79
- package/dist/index.d.ts +151 -79
- package/dist/index.js +196 -98
- package/package.json +6 -5
- package/src/index.ts +5 -5
package/dist/index.js
CHANGED
|
@@ -179,18 +179,19 @@ var ToolErrorCodes = {
|
|
|
179
179
|
INVALID_MODIFIER: "INVALID_MODIFIER",
|
|
180
180
|
CUSTOM_TOOLS_NOT_INITIALIZED: "CUSTOM_TOOLS_NOT_INITIALIZED",
|
|
181
181
|
TOOL_EXECUTION_ERROR: "TOOL_EXECUTION_ERROR",
|
|
182
|
-
INVALID_EXECUTE_FUNCTION: "INVALID_EXECUTE_FUNCTION"
|
|
182
|
+
INVALID_EXECUTE_FUNCTION: "INVALID_EXECUTE_FUNCTION",
|
|
183
|
+
GLOBAL_EXECUTE_TOOL_FN_NOT_SET: "GLOBAL_EXECUTE_TOOL_FN_NOT_SET"
|
|
183
184
|
};
|
|
184
|
-
var
|
|
185
|
-
constructor(message = "
|
|
185
|
+
var ComposioProviderNotDefinedError = class extends ComposioError {
|
|
186
|
+
constructor(message = "Provider not defined", meta = {}) {
|
|
186
187
|
super(message, {
|
|
187
188
|
code: ToolErrorCodes.TOOLSET_NOT_DEFINED,
|
|
188
189
|
meta,
|
|
189
190
|
possibleFixes: [
|
|
190
|
-
"Ensure that the
|
|
191
|
+
"Ensure that the provider is defined in the Composio project and passed into the tool instance"
|
|
191
192
|
]
|
|
192
193
|
});
|
|
193
|
-
this.name = "
|
|
194
|
+
this.name = "ComposioProviderNotDefinedError";
|
|
194
195
|
}
|
|
195
196
|
};
|
|
196
197
|
var ComposioToolNotFoundError = class extends ComposioError {
|
|
@@ -246,6 +247,16 @@ var ComposioInvalidExecuteFunctionError = class extends ComposioError {
|
|
|
246
247
|
this.name = "ComposioInvalidExecuteFunctionError";
|
|
247
248
|
}
|
|
248
249
|
};
|
|
250
|
+
var ComposioGlobalExecuteToolFnNotSetError = class extends ComposioError {
|
|
251
|
+
constructor(message = "Global execute tool function not set", meta = {}) {
|
|
252
|
+
super(message, {
|
|
253
|
+
code: ToolErrorCodes.GLOBAL_EXECUTE_TOOL_FN_NOT_SET,
|
|
254
|
+
meta,
|
|
255
|
+
possibleFixes: ["Ensure the global execute tool function is set in the provider"]
|
|
256
|
+
});
|
|
257
|
+
this.name = "ComposioGlobalExecuteToolFnNotSetError";
|
|
258
|
+
}
|
|
259
|
+
};
|
|
249
260
|
|
|
250
261
|
// src/errors/ConnectedAccountsError.ts
|
|
251
262
|
var ConnectedAccountErrorCodes = {
|
|
@@ -470,20 +481,20 @@ var ValidationError = class extends ComposioError {
|
|
|
470
481
|
var Tools = class {
|
|
471
482
|
client;
|
|
472
483
|
customTools;
|
|
473
|
-
|
|
474
|
-
constructor(client,
|
|
484
|
+
provider;
|
|
485
|
+
constructor(client, provider) {
|
|
475
486
|
if (!client) {
|
|
476
487
|
throw new Error("ComposioClient is required");
|
|
477
488
|
}
|
|
478
|
-
if (!
|
|
479
|
-
throw new
|
|
489
|
+
if (!provider) {
|
|
490
|
+
throw new ComposioProviderNotDefinedError("Provider not passed into Tools instance");
|
|
480
491
|
}
|
|
481
492
|
this.client = client;
|
|
482
493
|
this.customTools = new CustomTools(client);
|
|
483
|
-
this.
|
|
494
|
+
this.provider = provider;
|
|
484
495
|
this.execute = this.execute.bind(this);
|
|
485
|
-
this.
|
|
486
|
-
this.
|
|
496
|
+
this.getRawComposioToolBySlug = this.getRawComposioToolBySlug.bind(this);
|
|
497
|
+
this.getRawComposioTools = this.getRawComposioTools.bind(this);
|
|
487
498
|
}
|
|
488
499
|
/**
|
|
489
500
|
* Transform the tool cases
|
|
@@ -517,12 +528,12 @@ var Tools = class {
|
|
|
517
528
|
* @param {ToolList} tools - The tools to check.
|
|
518
529
|
* @returns {Promise<boolean>} True if the connected account exists for the given tools, false otherwise.
|
|
519
530
|
*/
|
|
520
|
-
async checkIfConnectedAccountExistsForTools(
|
|
531
|
+
async checkIfConnectedAccountExistsForTools(userIds, tools) {
|
|
521
532
|
if (!tools.length) {
|
|
522
533
|
return true;
|
|
523
534
|
}
|
|
524
535
|
const connectedAccounts = await this.client.connectedAccounts.list({
|
|
525
|
-
|
|
536
|
+
user_ids: userIds
|
|
526
537
|
});
|
|
527
538
|
if (connectedAccounts.items.length === 0) {
|
|
528
539
|
return false;
|
|
@@ -558,7 +569,7 @@ var Tools = class {
|
|
|
558
569
|
* @returns {Promise<string | null>} The connected account id or null if the toolkit is a no auth app
|
|
559
570
|
*/
|
|
560
571
|
async getConnectedAccountIdForTool(userId, toolSlug) {
|
|
561
|
-
const tool = await this.
|
|
572
|
+
const tool = await this.getRawComposioToolBySlug(userId, toolSlug);
|
|
562
573
|
if (!tool.toolkit) {
|
|
563
574
|
throw new Error(`Unable to find toolkit for tool ${toolSlug}`);
|
|
564
575
|
}
|
|
@@ -571,8 +582,8 @@ var Tools = class {
|
|
|
571
582
|
);
|
|
572
583
|
if (!isNoAuthApp) {
|
|
573
584
|
const connectedAccounts = await this.client.connectedAccounts.list({
|
|
574
|
-
|
|
575
|
-
|
|
585
|
+
user_ids: [userId],
|
|
586
|
+
toolkit_slugs: [tool.toolkit.slug]
|
|
576
587
|
});
|
|
577
588
|
if (connectedAccounts.items.length === 0) {
|
|
578
589
|
throw new Error("No connected accounts found");
|
|
@@ -586,16 +597,16 @@ var Tools = class {
|
|
|
586
597
|
}
|
|
587
598
|
/**
|
|
588
599
|
* Lists all tools available in the Composio SDK as well as custom tools.
|
|
589
|
-
* This method fetches the tools from the Composio API and wraps them using the
|
|
600
|
+
* This method fetches the tools from the Composio API and wraps them using the provider.
|
|
590
601
|
* @returns {ToolList} List of tools
|
|
591
602
|
*/
|
|
592
|
-
async
|
|
603
|
+
async getRawComposioTools(userId, query = {}, modifier) {
|
|
593
604
|
const queryParams = ToolListParamsSchema.safeParse(query);
|
|
594
605
|
if (queryParams.error) {
|
|
595
606
|
throw new ValidationError(queryParams.error);
|
|
596
607
|
}
|
|
597
608
|
const tools = await this.client.tools.list({
|
|
598
|
-
tool_slugs: queryParams.data.tools
|
|
609
|
+
tool_slugs: queryParams.data.tools,
|
|
599
610
|
toolkit_slug: queryParams.data.toolkits?.join(","),
|
|
600
611
|
cursor: queryParams.data.cursor,
|
|
601
612
|
important: queryParams.data.important,
|
|
@@ -625,15 +636,22 @@ var Tools = class {
|
|
|
625
636
|
* Retrieves a tool by its Slug.
|
|
626
637
|
* @param slug The ID of the tool to be retrieved
|
|
627
638
|
* @returns {Promise<Tool>} The tool
|
|
639
|
+
*
|
|
640
|
+
* @example
|
|
641
|
+
* ```ts
|
|
642
|
+
* const tool = await composio.tools.getRawComposioToolBySlug('default', 'github');
|
|
643
|
+
* ```
|
|
628
644
|
*/
|
|
629
|
-
async
|
|
645
|
+
async getRawComposioToolBySlug(userId, slug, modifier) {
|
|
630
646
|
const customTool = await this.customTools.getCustomToolBySlug(slug);
|
|
631
647
|
if (customTool) {
|
|
632
648
|
return customTool;
|
|
633
649
|
}
|
|
634
650
|
const tool = await this.client.tools.retrieve(slug);
|
|
635
651
|
if (!tool) {
|
|
636
|
-
throw new ComposioToolNotFoundError(
|
|
652
|
+
throw new ComposioToolNotFoundError(
|
|
653
|
+
`[getRawComposioToolBySlug] Tool with slug ${slug} not found`
|
|
654
|
+
);
|
|
637
655
|
}
|
|
638
656
|
let modifiedToool = this.transformToolCases(tool);
|
|
639
657
|
if (modifier) {
|
|
@@ -645,17 +663,25 @@ var Tools = class {
|
|
|
645
663
|
}
|
|
646
664
|
return modifiedToool;
|
|
647
665
|
}
|
|
666
|
+
/**
|
|
667
|
+
* Get a tool by its slug
|
|
668
|
+
* @param userId - The user id
|
|
669
|
+
* @param arg2 - The slug of the tool or the filters for the tools
|
|
670
|
+
* @param options - The options for the tools
|
|
671
|
+
* @returns The tool or the tools
|
|
672
|
+
*/
|
|
648
673
|
async get(userId, arg2, options) {
|
|
649
674
|
const executeToolFn = this.createExecuteToolFn(userId, options);
|
|
650
675
|
if (typeof arg2 === "string") {
|
|
651
|
-
const tool = await this.
|
|
652
|
-
return this.
|
|
676
|
+
const tool = await this.getRawComposioToolBySlug(userId, arg2, options?.modifyToolSchema);
|
|
677
|
+
return this.provider.wrapTool(tool, executeToolFn);
|
|
653
678
|
} else {
|
|
654
|
-
const tools = await this.
|
|
655
|
-
return this.
|
|
679
|
+
const tools = await this.getRawComposioTools(userId, arg2, options?.modifyToolSchema);
|
|
680
|
+
return this.provider.wrapTools(tools, executeToolFn);
|
|
656
681
|
}
|
|
657
682
|
}
|
|
658
683
|
/**
|
|
684
|
+
* @internal
|
|
659
685
|
* Creates a function that executes a tool.
|
|
660
686
|
* This function is used by agentic the toolsets to execute the tool
|
|
661
687
|
* @param {string} userId - The user id
|
|
@@ -675,6 +701,14 @@ var Tools = class {
|
|
|
675
701
|
};
|
|
676
702
|
return executeToolFn;
|
|
677
703
|
}
|
|
704
|
+
/**
|
|
705
|
+
* @internal
|
|
706
|
+
* Handles the execution of a custom tool
|
|
707
|
+
* @param tool - The tool to execute
|
|
708
|
+
* @param body - The body of the tool execution
|
|
709
|
+
* @param modifiers - The modifiers to be applied to the tool execution
|
|
710
|
+
* @returns The response from the tool execution
|
|
711
|
+
*/
|
|
678
712
|
async handleCustomToolExecution(tool, body, modifiers) {
|
|
679
713
|
if (modifiers?.beforeToolExecute) {
|
|
680
714
|
if (typeof modifiers.beforeToolExecute === "function") {
|
|
@@ -700,6 +734,14 @@ var Tools = class {
|
|
|
700
734
|
}
|
|
701
735
|
return result;
|
|
702
736
|
}
|
|
737
|
+
/**
|
|
738
|
+
* @internal
|
|
739
|
+
* Handles the execution of a composio tool
|
|
740
|
+
* @param tool - The tool to execute
|
|
741
|
+
* @param body - The body of the tool execution
|
|
742
|
+
* @param modifiers - The modifiers to be applied to the tool execution
|
|
743
|
+
* @returns The response from the tool execution
|
|
744
|
+
*/
|
|
703
745
|
async handleComposioToolExecution(tool, body, modifiers) {
|
|
704
746
|
if (modifiers?.beforeToolExecute) {
|
|
705
747
|
if (typeof modifiers.beforeToolExecute === "function") {
|
|
@@ -755,7 +797,7 @@ var Tools = class {
|
|
|
755
797
|
if (customTool) {
|
|
756
798
|
return this.handleCustomToolExecution(customTool, body, modifiers);
|
|
757
799
|
} else {
|
|
758
|
-
const composioTool = await this.
|
|
800
|
+
const composioTool = await this.getRawComposioToolBySlug(body.userId, slug);
|
|
759
801
|
if (!composioTool) {
|
|
760
802
|
throw new ComposioToolNotFoundError(`Tool with slug ${slug} not found`);
|
|
761
803
|
}
|
|
@@ -810,7 +852,7 @@ var Tools = class {
|
|
|
810
852
|
|
|
811
853
|
// src/types/toolkit.types.ts
|
|
812
854
|
import { z as z2 } from "zod";
|
|
813
|
-
var ToolkitMangedByEnumSchema = z2.enum(["all", "
|
|
855
|
+
var ToolkitMangedByEnumSchema = z2.enum(["all", "composio", "project"]);
|
|
814
856
|
var ToolkitSortByEnumSchema = z2.enum(["usage", "alphabetically"]);
|
|
815
857
|
var ToolkitsListParamsSchema = z2.object({
|
|
816
858
|
category: z2.string().optional(),
|
|
@@ -867,8 +909,8 @@ var ToolkitAuthConfigDetailsSchema = z2.object({
|
|
|
867
909
|
})
|
|
868
910
|
}),
|
|
869
911
|
proxy: z2.object({
|
|
870
|
-
baseUrl: z2.string()
|
|
871
|
-
})
|
|
912
|
+
baseUrl: z2.string().optional()
|
|
913
|
+
}).optional()
|
|
872
914
|
});
|
|
873
915
|
var ToolkitRetrieveResponseSchema = z2.object({
|
|
874
916
|
name: z2.string(),
|
|
@@ -977,9 +1019,20 @@ var AuthConfigListResponseSchema = z3.object({
|
|
|
977
1019
|
nextCursor: z3.string().optional(),
|
|
978
1020
|
totalPages: z3.number()
|
|
979
1021
|
});
|
|
980
|
-
var
|
|
981
|
-
credentials: z3.record(z3.string(), z3.union([z3.string(), z3.
|
|
1022
|
+
var AuthCustomConfigUpdateParamsSchema = z3.object({
|
|
1023
|
+
credentials: z3.record(z3.string(), z3.union([z3.string(), z3.unknown()])),
|
|
1024
|
+
type: z3.literal("custom"),
|
|
1025
|
+
restrictToFollowingTools: z3.array(z3.string()).optional()
|
|
1026
|
+
});
|
|
1027
|
+
var AuthDefaultConfigUpdateParamsSchema = z3.object({
|
|
1028
|
+
scopes: z3.string(),
|
|
1029
|
+
type: z3.literal("default"),
|
|
1030
|
+
restrictToFollowingTools: z3.array(z3.string()).optional()
|
|
982
1031
|
});
|
|
1032
|
+
var AuthConfigUpdateParamsSchema = z3.discriminatedUnion("type", [
|
|
1033
|
+
AuthCustomConfigUpdateParamsSchema,
|
|
1034
|
+
AuthDefaultConfigUpdateParamsSchema
|
|
1035
|
+
]);
|
|
983
1036
|
|
|
984
1037
|
// src/models/AuthConfigs.ts
|
|
985
1038
|
var AuthConfigs = class {
|
|
@@ -987,6 +1040,14 @@ var AuthConfigs = class {
|
|
|
987
1040
|
constructor(client) {
|
|
988
1041
|
this.client = client;
|
|
989
1042
|
}
|
|
1043
|
+
/**
|
|
1044
|
+
* Protected getter for the client instance.
|
|
1045
|
+
* This is primarily used for testing purposes.
|
|
1046
|
+
* @protected
|
|
1047
|
+
*/
|
|
1048
|
+
getClient() {
|
|
1049
|
+
return this.client;
|
|
1050
|
+
}
|
|
990
1051
|
parseAuthConfigRetrieveResponse(authConfig) {
|
|
991
1052
|
const result = AuthConfigRetrieveResponseSchema.safeParse({
|
|
992
1053
|
id: authConfig.id,
|
|
@@ -1093,11 +1154,22 @@ var AuthConfigs = class {
|
|
|
1093
1154
|
* @returns {Promise<AuthConfigUpdateResponse>} Updated auth config
|
|
1094
1155
|
*/
|
|
1095
1156
|
async update(nanoid, data) {
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1157
|
+
const parsedData = AuthConfigUpdateParamsSchema.safeParse(data);
|
|
1158
|
+
if (parsedData.error) {
|
|
1159
|
+
throw new ValidationError(parsedData.error);
|
|
1160
|
+
}
|
|
1161
|
+
return this.client.authConfigs.update(
|
|
1162
|
+
nanoid,
|
|
1163
|
+
parsedData.data.type === "custom" ? {
|
|
1164
|
+
type: "custom",
|
|
1165
|
+
credentials: parsedData.data.credentials,
|
|
1166
|
+
restrict_to_following_tools: parsedData.data.restrictToFollowingTools
|
|
1167
|
+
} : {
|
|
1168
|
+
type: "default",
|
|
1169
|
+
scopes: parsedData.data.scopes,
|
|
1170
|
+
restrict_to_following_tools: parsedData.data.restrictToFollowingTools
|
|
1099
1171
|
}
|
|
1100
|
-
|
|
1172
|
+
);
|
|
1101
1173
|
}
|
|
1102
1174
|
/**
|
|
1103
1175
|
* Delete an auth config
|
|
@@ -1162,7 +1234,7 @@ import { z as z4 } from "zod";
|
|
|
1162
1234
|
var ConnectedAccountStatuses = {
|
|
1163
1235
|
ACTIVE: "ACTIVE",
|
|
1164
1236
|
INACTIVE: "INACTIVE",
|
|
1165
|
-
|
|
1237
|
+
DELETED: "DELETED",
|
|
1166
1238
|
INITIATED: "INITIATED",
|
|
1167
1239
|
EXPIRED: "EXPIRED",
|
|
1168
1240
|
FAILED: "FAILED"
|
|
@@ -1170,7 +1242,7 @@ var ConnectedAccountStatuses = {
|
|
|
1170
1242
|
var ConnectedAccountStatusSchema = z4.enum([
|
|
1171
1243
|
ConnectedAccountStatuses.ACTIVE,
|
|
1172
1244
|
ConnectedAccountStatuses.INACTIVE,
|
|
1173
|
-
ConnectedAccountStatuses.
|
|
1245
|
+
ConnectedAccountStatuses.DELETED,
|
|
1174
1246
|
ConnectedAccountStatuses.INITIATED,
|
|
1175
1247
|
ConnectedAccountStatuses.EXPIRED,
|
|
1176
1248
|
ConnectedAccountStatuses.FAILED
|
|
@@ -1262,7 +1334,8 @@ import { ZodError as ZodError2 } from "zod";
|
|
|
1262
1334
|
|
|
1263
1335
|
// src/errors/ConnectionRequestError.ts
|
|
1264
1336
|
var ConnectionRequestErrorCodes = {
|
|
1265
|
-
CONNECTION_REQUEST_TIMEOUT: "CONNECTION_REQUEST_TIMEOUT"
|
|
1337
|
+
CONNECTION_REQUEST_TIMEOUT: "CONNECTION_REQUEST_TIMEOUT",
|
|
1338
|
+
CONNECTION_REQUEST_FAILED: "CONNECTION_REQUEST_FAILED"
|
|
1266
1339
|
};
|
|
1267
1340
|
var ConnectionRequestTimeoutError = class extends ComposioError {
|
|
1268
1341
|
constructor(message = "Connection request timed out", meta = {}) {
|
|
@@ -1270,6 +1343,16 @@ var ConnectionRequestTimeoutError = class extends ComposioError {
|
|
|
1270
1343
|
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_TIMEOUT,
|
|
1271
1344
|
meta
|
|
1272
1345
|
});
|
|
1346
|
+
this.name = "ConnectionRequestTimeoutError";
|
|
1347
|
+
}
|
|
1348
|
+
};
|
|
1349
|
+
var ConnectionRequestFailedError = class extends ComposioError {
|
|
1350
|
+
constructor(message = "Connection request failed", meta = {}) {
|
|
1351
|
+
super(message, {
|
|
1352
|
+
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_FAILED,
|
|
1353
|
+
meta
|
|
1354
|
+
});
|
|
1355
|
+
this.name = "ConnectionRequestFailedError";
|
|
1273
1356
|
}
|
|
1274
1357
|
};
|
|
1275
1358
|
|
|
@@ -1326,30 +1409,40 @@ var ConnectionRequest = class {
|
|
|
1326
1409
|
async waitForConnection(timeout = 6e4) {
|
|
1327
1410
|
if (this.connectedAccountStatus === ConnectedAccountStatuses.ACTIVE) {
|
|
1328
1411
|
const response = await this.client.connectedAccounts.retrieve(this.connectedAccountId);
|
|
1329
|
-
return
|
|
1330
|
-
}
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1412
|
+
return this.transformResponse(response);
|
|
1413
|
+
}
|
|
1414
|
+
const terminalErrorStates = [
|
|
1415
|
+
ConnectedAccountStatuses.FAILED,
|
|
1416
|
+
ConnectedAccountStatuses.EXPIRED,
|
|
1417
|
+
ConnectedAccountStatuses.DELETED
|
|
1418
|
+
];
|
|
1419
|
+
const start = Date.now();
|
|
1420
|
+
const pollInterval = 1e3;
|
|
1421
|
+
while (Date.now() - start < timeout) {
|
|
1422
|
+
try {
|
|
1423
|
+
const response = await this.client.connectedAccounts.retrieve(this.connectedAccountId);
|
|
1424
|
+
if (response.status === ConnectedAccountStatuses.ACTIVE) {
|
|
1425
|
+
return this.transformResponse(response);
|
|
1342
1426
|
}
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1427
|
+
if (terminalErrorStates.includes(response.status)) {
|
|
1428
|
+
throw new ConnectionRequestFailedError(
|
|
1429
|
+
`Connection request failed with status: ${response.status}${response.status_reason ? `, reason: ${response.status_reason}` : ""}`,
|
|
1430
|
+
{
|
|
1431
|
+
userId: response.user_id,
|
|
1432
|
+
connectedAccountId: this.connectedAccountId,
|
|
1433
|
+
status: response.status,
|
|
1434
|
+
statusReason: response.status_reason
|
|
1435
|
+
}
|
|
1436
|
+
);
|
|
1437
|
+
}
|
|
1438
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
1439
|
+
} catch (error) {
|
|
1440
|
+
throw error;
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
throw new ConnectionRequestTimeoutError(
|
|
1444
|
+
`Connection request timed out for ${this.connectedAccountId}`
|
|
1445
|
+
);
|
|
1353
1446
|
}
|
|
1354
1447
|
};
|
|
1355
1448
|
|
|
@@ -1579,20 +1672,21 @@ var Toolkits = class {
|
|
|
1579
1672
|
* @param {string} authConfigId - The id of the auth config to use
|
|
1580
1673
|
* @returns {Promise<ConnectionRequest>} The connection request object
|
|
1581
1674
|
*/
|
|
1582
|
-
async authorize(userId, toolkitSlug
|
|
1675
|
+
async authorize(userId, toolkitSlug) {
|
|
1583
1676
|
const toolkit = await this.getToolkitBySlug(toolkitSlug);
|
|
1584
1677
|
const composioAuthConfig = new AuthConfigs(this.client);
|
|
1585
1678
|
let authConfigIdToUse;
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1679
|
+
const authConfig = await composioAuthConfig.list({
|
|
1680
|
+
toolkitSlug
|
|
1681
|
+
});
|
|
1682
|
+
authConfigIdToUse = authConfig.items[0]?.id;
|
|
1683
|
+
if (!authConfigIdToUse) {
|
|
1590
1684
|
if (toolkit.authConfigDetails && toolkit.authConfigDetails.length > 0) {
|
|
1591
|
-
const
|
|
1685
|
+
const authConfig2 = await composioAuthConfig.create(toolkitSlug, {
|
|
1592
1686
|
type: "use_composio_managed_auth",
|
|
1593
1687
|
name: `${toolkit.name} Auth Config`
|
|
1594
1688
|
});
|
|
1595
|
-
authConfigIdToUse =
|
|
1689
|
+
authConfigIdToUse = authConfig2.id;
|
|
1596
1690
|
} else {
|
|
1597
1691
|
throw new ComposioAuthConfigNotFoundError("No auth config found for toolkit", {
|
|
1598
1692
|
toolkitSlug
|
|
@@ -1822,6 +1916,7 @@ var Triggers = class {
|
|
|
1822
1916
|
const sessionInfo = await session.getInfo();
|
|
1823
1917
|
const clientId = sessionInfo.project?.id;
|
|
1824
1918
|
if (!clientId) throw new Error("Client ID not found");
|
|
1919
|
+
if (!this.client.apiKey) throw new Error("API key not found");
|
|
1825
1920
|
await PusherUtils.getPusherClient(this.client.baseURL, this.client.apiKey);
|
|
1826
1921
|
const shouldSendTrigger = (data) => {
|
|
1827
1922
|
if (Object.keys(filters).length === 0) return true;
|
|
@@ -2127,8 +2222,8 @@ async function checkForLatestVersionFromNPM(currentVersion) {
|
|
|
2127
2222
|
}
|
|
2128
2223
|
}
|
|
2129
2224
|
|
|
2130
|
-
// src/
|
|
2131
|
-
var
|
|
2225
|
+
// src/provider/BaseProvider.ts
|
|
2226
|
+
var BaseProvider = class {
|
|
2132
2227
|
/**
|
|
2133
2228
|
* @internal
|
|
2134
2229
|
* The function to execute a tool.
|
|
@@ -2138,7 +2233,7 @@ var BaseToolset = class {
|
|
|
2138
2233
|
/**
|
|
2139
2234
|
* @internal
|
|
2140
2235
|
* Set the function to execute a tool.
|
|
2141
|
-
* This is set automatically injected by the core SDK.
|
|
2236
|
+
* This is set automatically and injected by the core SDK.
|
|
2142
2237
|
*/
|
|
2143
2238
|
_setExecuteToolFn(executeToolFn) {
|
|
2144
2239
|
this._globalExecuteToolFn = executeToolFn;
|
|
@@ -2146,29 +2241,32 @@ var BaseToolset = class {
|
|
|
2146
2241
|
/**
|
|
2147
2242
|
* @public
|
|
2148
2243
|
* Gloabl function to execute a tool.
|
|
2149
|
-
* This function is used by
|
|
2244
|
+
* This function is used by provider providers to implement helper functions to execute tools.
|
|
2150
2245
|
* This is a 1:1 mapping of the `execute` method in the `Tools` class.
|
|
2151
2246
|
* @param {string} toolSlug - The slug of the tool to execute.
|
|
2152
2247
|
* @param {Record<string, unknown>} input - The input to the tool.
|
|
2153
2248
|
* @returns {Promise<string>} The result of the tool execution.
|
|
2154
2249
|
*/
|
|
2155
2250
|
executeTool(toolSlug, body, modifers) {
|
|
2251
|
+
if (!this._globalExecuteToolFn) {
|
|
2252
|
+
throw new ComposioGlobalExecuteToolFnNotSetError("executeToolFn is not set");
|
|
2253
|
+
}
|
|
2156
2254
|
return this._globalExecuteToolFn(toolSlug, body, modifers);
|
|
2157
2255
|
}
|
|
2158
2256
|
};
|
|
2159
|
-
var
|
|
2257
|
+
var BaseNonAgenticProvider = class extends BaseProvider {
|
|
2160
2258
|
_isAgentic = false;
|
|
2161
2259
|
};
|
|
2162
|
-
var
|
|
2260
|
+
var BaseAgenticProvider = class extends BaseProvider {
|
|
2163
2261
|
_isAgentic = true;
|
|
2164
2262
|
};
|
|
2165
2263
|
|
|
2166
|
-
// src/
|
|
2167
|
-
var
|
|
2264
|
+
// src/provider/OpenAIProvider.ts
|
|
2265
|
+
var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
2168
2266
|
name = "openai";
|
|
2169
2267
|
/**
|
|
2170
|
-
* Absract method to wrap a tool in the
|
|
2171
|
-
* This method is implemented by the
|
|
2268
|
+
* Absract method to wrap a tool in the provider.
|
|
2269
|
+
* This method is implemented by the provider.
|
|
2172
2270
|
* @param tool - The tool to wrap.
|
|
2173
2271
|
* @returns The wrapped tool.
|
|
2174
2272
|
*/
|
|
@@ -2329,7 +2427,7 @@ var OpenAIToolset = class extends BaseNonAgenticToolset {
|
|
|
2329
2427
|
};
|
|
2330
2428
|
|
|
2331
2429
|
// package.json
|
|
2332
|
-
var version = "0.1.
|
|
2430
|
+
var version = "0.1.11-alpha.0";
|
|
2333
2431
|
|
|
2334
2432
|
// src/utils/uuid.ts
|
|
2335
2433
|
import { v4 as uuidv4 } from "uuid";
|
|
@@ -2346,7 +2444,7 @@ var Composio = class {
|
|
|
2346
2444
|
client;
|
|
2347
2445
|
/**
|
|
2348
2446
|
* The configuration for the Composio SDK.
|
|
2349
|
-
* @type {ComposioConfig<
|
|
2447
|
+
* @type {ComposioConfig<TProvider>}
|
|
2350
2448
|
*/
|
|
2351
2449
|
config;
|
|
2352
2450
|
telemetry;
|
|
@@ -2356,7 +2454,7 @@ var Composio = class {
|
|
|
2356
2454
|
tools;
|
|
2357
2455
|
toolkits;
|
|
2358
2456
|
triggers;
|
|
2359
|
-
|
|
2457
|
+
provider;
|
|
2360
2458
|
// auth configs
|
|
2361
2459
|
authConfigs;
|
|
2362
2460
|
createAuthConfig;
|
|
@@ -2370,7 +2468,7 @@ var Composio = class {
|
|
|
2370
2468
|
* @param {string} config.runtime The runtime for the Composio SDK.
|
|
2371
2469
|
* @param {boolean} config.allowTracking Whether to allow analytics / tracking. Defaults to true.
|
|
2372
2470
|
* @param {boolean} config.allowTracing Whether to allow tracing. Defaults to true.
|
|
2373
|
-
* @param {
|
|
2471
|
+
* @param {TProvider} config.provider The provider to use for this Composio instance.
|
|
2374
2472
|
*/
|
|
2375
2473
|
constructor(config) {
|
|
2376
2474
|
const { baseURL: baseURLParsed, apiKey: apiKeyParsed } = getSDKConfig(
|
|
@@ -2388,9 +2486,9 @@ var Composio = class {
|
|
|
2388
2486
|
...config,
|
|
2389
2487
|
allowTracking: config.allowTracking ?? true
|
|
2390
2488
|
};
|
|
2391
|
-
this.
|
|
2392
|
-
this.tools = new Tools(this.client, this.
|
|
2393
|
-
this.
|
|
2489
|
+
this.provider = config.provider ?? new OpenAIProvider();
|
|
2490
|
+
this.tools = new Tools(this.client, this.provider);
|
|
2491
|
+
this.provider._setExecuteToolFn(this.tools.execute);
|
|
2394
2492
|
this.toolkits = new Toolkits(this.client);
|
|
2395
2493
|
this.triggers = new Triggers(this.client);
|
|
2396
2494
|
this.authConfigs = new AuthConfigs(this.client);
|
|
@@ -2428,7 +2526,7 @@ var Composio = class {
|
|
|
2428
2526
|
this.telemetry.instrumentTelemetry(this.triggers);
|
|
2429
2527
|
this.telemetry.instrumentTelemetry(this.authConfigs);
|
|
2430
2528
|
this.telemetry.instrumentTelemetry(this.connectedAccounts);
|
|
2431
|
-
this.telemetry.instrumentTelemetry(this.
|
|
2529
|
+
this.telemetry.instrumentTelemetry(this.provider);
|
|
2432
2530
|
}
|
|
2433
2531
|
/**
|
|
2434
2532
|
* Get the Composio SDK client.
|
|
@@ -2443,8 +2541,8 @@ var Composio = class {
|
|
|
2443
2541
|
/**
|
|
2444
2542
|
* Fetch all the tools from Composio.
|
|
2445
2543
|
* @param {ToolListParams} params Parameters to fetch the tools.
|
|
2446
|
-
* @param {
|
|
2447
|
-
* @returns {Promise<ReturnType<
|
|
2544
|
+
* @param {ProviderOptions<TProvider>} modifiers Modifiers to apply to the tools.
|
|
2545
|
+
* @returns {Promise<ReturnType<TProvider['getTools']>>} The tools from the provider.
|
|
2448
2546
|
*/
|
|
2449
2547
|
getTools(userId, filters, modifiers) {
|
|
2450
2548
|
return this.tools.get(userId, filters, modifiers);
|
|
@@ -2452,17 +2550,17 @@ var Composio = class {
|
|
|
2452
2550
|
/**
|
|
2453
2551
|
* Fetch a tool from Composio by its slug.
|
|
2454
2552
|
* @param {string} slug slug of the tool
|
|
2455
|
-
* @param {
|
|
2456
|
-
* @returns {Promise<ReturnType<
|
|
2553
|
+
* @param {ProviderOptions<TProvider>} modifiers to be applied to the tool
|
|
2554
|
+
* @returns {Promise<ReturnType<TProvider['getToolBySlug']>>} The tool from the provider.
|
|
2457
2555
|
*/
|
|
2458
2556
|
getToolBySlug(userId, slug, modifiers) {
|
|
2459
2557
|
return this.tools.get(userId, slug, modifiers);
|
|
2460
2558
|
}
|
|
2461
2559
|
};
|
|
2462
2560
|
|
|
2463
|
-
// src/
|
|
2464
|
-
var
|
|
2465
|
-
name = "
|
|
2561
|
+
// src/provider/ComposioProvider.ts
|
|
2562
|
+
var ComposioProvider = class extends BaseNonAgenticProvider {
|
|
2563
|
+
name = "ComposioProvider";
|
|
2466
2564
|
wrapTool = (tool) => {
|
|
2467
2565
|
return tool;
|
|
2468
2566
|
};
|
|
@@ -2586,12 +2684,12 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
2586
2684
|
export {
|
|
2587
2685
|
AuthConfigTypes,
|
|
2588
2686
|
AuthSchemeTypes,
|
|
2589
|
-
|
|
2590
|
-
|
|
2687
|
+
BaseAgenticProvider,
|
|
2688
|
+
BaseNonAgenticProvider,
|
|
2591
2689
|
BaseTelemetryTransport,
|
|
2592
2690
|
Composio,
|
|
2593
|
-
|
|
2594
|
-
|
|
2691
|
+
ComposioProvider,
|
|
2692
|
+
OpenAIProvider,
|
|
2595
2693
|
ToolListParamsSchema,
|
|
2596
2694
|
jsonSchemaToModel
|
|
2597
2695
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@composio/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11-alpha.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
],
|
|
23
23
|
"scripts": {
|
|
24
24
|
"build": "tsup",
|
|
25
|
-
"test": "
|
|
25
|
+
"test": "vitest run"
|
|
26
26
|
},
|
|
27
27
|
"keywords": [],
|
|
28
28
|
"author": "",
|
|
@@ -31,15 +31,16 @@
|
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"tsup": "^8.4.0",
|
|
33
33
|
"tsx": "^4.19.3",
|
|
34
|
-
"typescript": "^5.8.3"
|
|
34
|
+
"typescript": "^5.8.3",
|
|
35
|
+
"vitest": "^3.1.3"
|
|
35
36
|
},
|
|
36
37
|
"dependencies": {
|
|
37
|
-
"@composio/client": "0.1.0-alpha.
|
|
38
|
+
"@composio/client": "^0.1.0-alpha.10",
|
|
38
39
|
"openai": "^4.94.0",
|
|
39
40
|
"pusher-js": "^8.4.0",
|
|
40
41
|
"uuid": "^11.1.0",
|
|
41
42
|
"zod": "^3.24.2",
|
|
42
43
|
"zod-to-json-schema": "^3.24.5"
|
|
43
44
|
},
|
|
44
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "a4e9ff190c198e6a20797c0bf35762b149ae081c"
|
|
45
46
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// Core exports
|
|
2
2
|
export { Composio } from './composio';
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export type {
|
|
6
|
-
export {
|
|
3
|
+
export { ComposioProvider } from './provider/ComposioProvider';
|
|
4
|
+
export { BaseAgenticProvider, BaseNonAgenticProvider } from './provider/BaseProvider';
|
|
5
|
+
export type { BaseComposioProvider } from './provider/BaseProvider';
|
|
6
|
+
export { OpenAIProvider } from './provider/OpenAIProvider';
|
|
7
7
|
export { BaseTelemetryTransport } from './telemetry/TelemetryTransport';
|
|
8
8
|
export { jsonSchemaToModel } from './utils/jsonSchema';
|
|
9
9
|
export { ToolListParamsSchema } from './types/tool.types';
|
|
10
10
|
export type { Tool, ToolListParams, ToolExecuteParams } from './types/tool.types';
|
|
11
|
-
export type {
|
|
11
|
+
export type { Provider, ExecuteToolFn, ExecuteToolFnOptions } from './types/provider.types';
|
|
12
12
|
export type { ExecuteMetadata } from './types/customTool.types';
|
|
13
13
|
export { AuthConfigTypes, AuthSchemeTypes } from './types/authConfigs.types';
|
|
14
14
|
export type { AuthConfigType, AuthSchemeType } from './types/authConfigs.types';
|