@composio/core 0.2.6 → 0.2.7-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/dist/index.cjs CHANGED
@@ -112,6 +112,7 @@ __export(index_exports, {
112
112
  MCPServerCreateResponseSchema: () => MCPServerCreateResponseSchema,
113
113
  MCPServerListResponseSchema: () => MCPServerListResponseSchema,
114
114
  MCPServerSchema: () => MCPServerSchema,
115
+ MCPServerTypeSchema: () => MCPServerTypeSchema,
115
116
  MCPServerUpdateParamsSchema: () => MCPServerUpdateParamsSchema,
116
117
  MCPSingleAppServerSchema: () => MCPSingleAppServerSchema,
117
118
  MCPToolkitConfigSchema: () => MCPToolkitConfigSchema,
@@ -146,15 +147,25 @@ __export(index_exports, {
146
147
  ToolListParamsSchema: () => ToolListParamsSchema,
147
148
  ToolListResponseSchema: () => ToolListResponseSchema,
148
149
  ToolProxyParamsSchema: () => ToolProxyParamsSchema,
149
- ToolRouter: () => ToolRouter,
150
- ToolRouterConfigSchema: () => ToolRouterConfigSchema,
151
- ToolRouterSessionSchema: () => ToolRouterSessionSchema,
152
- ToolRouterToolkitConfigSchema: () => ToolRouterToolkitConfigSchema,
150
+ ToolRouterConfigManageConnectionsSchema: () => ToolRouterConfigManageConnectionsSchema,
151
+ ToolRouterConfigTagsSchema: () => ToolRouterConfigTagsSchema,
152
+ ToolRouterConfigToolsSchema: () => ToolRouterConfigToolsSchema,
153
+ ToolRouterCreateSessionConfigSchema: () => ToolRouterCreateSessionConfigSchema,
154
+ ToolRouterDisabledTagsConfigSchema: () => ToolRouterDisabledTagsConfigSchema,
155
+ ToolRouterEnabledTagsConfigSchema: () => ToolRouterEnabledTagsConfigSchema,
156
+ ToolRouterManageConnectionsConfigSchema: () => ToolRouterManageConnectionsConfigSchema,
157
+ ToolRouterTagsParamSchema: () => ToolRouterTagsParamSchema,
158
+ ToolRouterToolkitsDisabledConfigSchema: () => ToolRouterToolkitsDisabledConfigSchema,
159
+ ToolRouterToolkitsEnabledConfigSchema: () => ToolRouterToolkitsEnabledConfigSchema,
160
+ ToolRouterToolkitsParamSchema: () => ToolRouterToolkitsParamSchema,
161
+ ToolRouterToolsParamSchema: () => ToolRouterToolsParamSchema,
153
162
  ToolSchema: () => ToolSchema,
154
163
  ToolkitAuthConfigDetailsSchema: () => ToolkitAuthConfigDetailsSchema,
155
164
  ToolkitAuthFieldSchema: () => ToolkitAuthFieldSchema,
156
165
  ToolkitAuthFieldsResponseSchema: () => ToolkitAuthFieldsResponseSchema,
157
166
  ToolkitCategorySchema: () => ToolkitCategorySchema,
167
+ ToolkitConnectionStateSchema: () => ToolkitConnectionStateSchema,
168
+ ToolkitConnectionsDetailsSchema: () => ToolkitConnectionsDetailsSchema,
158
169
  ToolkitErrorCodes: () => ToolkitErrorCodes,
159
170
  ToolkitMangedByEnumSchema: () => ToolkitMangedByEnumSchema,
160
171
  ToolkitRetrieveCategoriesResponseSchema: () => ToolkitRetrieveCategoriesResponseSchema,
@@ -213,7 +224,9 @@ var AuthSchemeTypes = {
213
224
  NO_AUTH: "NO_AUTH",
214
225
  BASIC_WITH_JWT: "BASIC_WITH_JWT",
215
226
  CALCOM_AUTH: "CALCOM_AUTH",
216
- SERVICE_ACCOUNT: "SERVICE_ACCOUNT"
227
+ SERVICE_ACCOUNT: "SERVICE_ACCOUNT",
228
+ SAML: "SAML",
229
+ DCR_OAUTH: "DCR_OAUTH"
217
230
  };
218
231
  var AuthConfigCreationToolAccessConfigSchema = import_v3.z.object({
219
232
  toolsForConnectedAccountCreation: import_v3.z.array(import_v3.z.string()).optional()
@@ -233,7 +246,9 @@ var AuthSchemeEnum = import_v3.z.enum([
233
246
  "NO_AUTH",
234
247
  "BASIC_WITH_JWT",
235
248
  "CALCOM_AUTH",
236
- "SERVICE_ACCOUNT"
249
+ "SERVICE_ACCOUNT",
250
+ "SAML",
251
+ "DCR_OAUTH"
237
252
  ]);
238
253
  var CreateCustomAuthConfigParamsSchema = import_v3.z.object({
239
254
  type: import_v3.z.literal("use_custom_auth"),
@@ -380,7 +395,14 @@ var BaseSchemeRaw = import_v32.z.object({
380
395
  // for generic api key
381
396
  generic_api_key: import_v32.z.string().optional(),
382
397
  // for bearer token
383
- bearer_token: import_v32.z.string().optional()
398
+ bearer_token: import_v32.z.string().optional(),
399
+ // for basic auth encoded
400
+ basic_encoded: import_v32.z.string().optional(),
401
+ // for dcr oauth
402
+ long_redirect_url: import_v32.z.boolean().optional(),
403
+ state_prefix: import_v32.z.string().optional(),
404
+ registration_access_token: import_v32.z.string().optional(),
405
+ registration_client_uri: import_v32.z.string().optional()
384
406
  }).catchall(import_v32.z.unknown());
385
407
  var Oauth2InitiatingConnectionDataSchema = BaseSchemeRaw.extend({
386
408
  status: import_v32.z.literal(ConnectionStatuses.INITIALIZING)
@@ -656,6 +678,98 @@ var BasicWithJwtConnectionDataSchema = import_v32.z.discriminatedUnion("status",
656
678
  var CustomBasicWithJwtConnectionDataSchema = BasicWithJwtInitiatingSchema.omit({
657
679
  status: true
658
680
  });
681
+ var ServiceAccountInitiatingSchema = BaseSchemeRaw.extend({
682
+ status: import_v32.z.literal(ConnectionStatuses.INITIALIZING)
683
+ }).catchall(import_v32.z.unknown());
684
+ var ServiceAccountConnectionDataSchema = import_v32.z.discriminatedUnion("status", [
685
+ ServiceAccountInitiatingSchema,
686
+ ServiceAccountInitiatingSchema.extend({
687
+ status: import_v32.z.literal(ConnectionStatuses.INITIATED)
688
+ }).catchall(import_v32.z.unknown()),
689
+ ServiceAccountInitiatingSchema.extend({
690
+ status: import_v32.z.literal(ConnectionStatuses.ACTIVE),
691
+ application_id: import_v32.z.string(),
692
+ installation_id: import_v32.z.string(),
693
+ private_key: import_v32.z.string()
694
+ }).catchall(import_v32.z.unknown()),
695
+ ServiceAccountInitiatingSchema.extend({
696
+ status: import_v32.z.literal(ConnectionStatuses.INACTIVE),
697
+ application_id: import_v32.z.string(),
698
+ installation_id: import_v32.z.string(),
699
+ private_key: import_v32.z.string()
700
+ }).catchall(import_v32.z.unknown())
701
+ ]);
702
+ var CustomServiceAccountConnectionDataSchema = import_v32.z.object({
703
+ application_id: import_v32.z.string(),
704
+ installation_id: import_v32.z.string(),
705
+ private_key: import_v32.z.string()
706
+ }).merge(BaseSchemeRaw).catchall(import_v32.z.unknown());
707
+ var SamlInitiatingSchema = BaseSchemeRaw.extend({
708
+ status: import_v32.z.literal(ConnectionStatuses.INITIALIZING)
709
+ }).catchall(import_v32.z.unknown());
710
+ var SamlConnectionDataSchema = import_v32.z.discriminatedUnion("status", [
711
+ SamlInitiatingSchema,
712
+ SamlInitiatingSchema.extend({
713
+ status: import_v32.z.literal(ConnectionStatuses.INITIATED)
714
+ }).catchall(import_v32.z.unknown()),
715
+ SamlInitiatingSchema.extend({
716
+ status: import_v32.z.literal(ConnectionStatuses.ACTIVE)
717
+ }).catchall(import_v32.z.unknown()),
718
+ SamlInitiatingSchema.extend({
719
+ status: import_v32.z.literal(ConnectionStatuses.INACTIVE)
720
+ }).catchall(import_v32.z.unknown()),
721
+ SamlInitiatingSchema.extend({
722
+ status: import_v32.z.literal(ConnectionStatuses.FAILED),
723
+ error: import_v32.z.string().optional(),
724
+ error_description: import_v32.z.string().optional()
725
+ }).catchall(import_v32.z.unknown()),
726
+ SamlInitiatingSchema.extend({
727
+ status: import_v32.z.literal(ConnectionStatuses.EXPIRED),
728
+ expired_at: import_v32.z.string().optional()
729
+ }).catchall(import_v32.z.unknown())
730
+ ]);
731
+ var CustomSamlConnectionDataSchema = BaseSchemeRaw.catchall(import_v32.z.unknown());
732
+ var DcrOauthInitiatingSchema = BaseSchemeRaw.extend({
733
+ status: import_v32.z.literal(ConnectionStatuses.INITIALIZING)
734
+ }).catchall(import_v32.z.unknown());
735
+ var DcrOauthConnectionDataSchema = import_v32.z.discriminatedUnion("status", [
736
+ DcrOauthInitiatingSchema,
737
+ DcrOauthInitiatingSchema.extend({
738
+ status: import_v32.z.literal(ConnectionStatuses.INITIATED),
739
+ client_id: import_v32.z.string(),
740
+ client_secret: import_v32.z.string(),
741
+ redirectUrl: import_v32.z.string()
742
+ }).catchall(import_v32.z.unknown()),
743
+ DcrOauthInitiatingSchema.extend({
744
+ status: import_v32.z.literal(ConnectionStatuses.ACTIVE),
745
+ access_token: import_v32.z.string(),
746
+ client_id: import_v32.z.string(),
747
+ token_type: import_v32.z.string().optional(),
748
+ refresh_token: import_v32.z.string().nullish(),
749
+ expires_in: import_v32.z.union([import_v32.z.string(), import_v32.z.number(), import_v32.z.null()]).optional(),
750
+ scope: import_v32.z.union([import_v32.z.string(), import_v32.z.array(import_v32.z.string()), import_v32.z.null()]).optional(),
751
+ id_token: import_v32.z.string().optional(),
752
+ client_secret: import_v32.z.string().optional()
753
+ }).catchall(import_v32.z.unknown()),
754
+ DcrOauthInitiatingSchema.extend({
755
+ status: import_v32.z.literal(ConnectionStatuses.INACTIVE),
756
+ access_token: import_v32.z.string(),
757
+ client_id: import_v32.z.string()
758
+ }).catchall(import_v32.z.unknown()),
759
+ DcrOauthInitiatingSchema.extend({
760
+ status: import_v32.z.literal(ConnectionStatuses.FAILED),
761
+ error: import_v32.z.string().optional(),
762
+ error_description: import_v32.z.string().optional()
763
+ }).catchall(import_v32.z.unknown()),
764
+ DcrOauthInitiatingSchema.extend({
765
+ status: import_v32.z.literal(ConnectionStatuses.EXPIRED),
766
+ expired_at: import_v32.z.string().optional()
767
+ }).catchall(import_v32.z.unknown())
768
+ ]);
769
+ var CustomDcrOauthConnectionDataSchema = import_v32.z.object({
770
+ access_token: import_v32.z.string(),
771
+ client_id: import_v32.z.string()
772
+ }).merge(BaseSchemeRaw).catchall(import_v32.z.unknown());
659
773
  var ConnectionDataSchema = import_v32.z.discriminatedUnion("authScheme", [
660
774
  import_v32.z.object({
661
775
  authScheme: import_v32.z.literal(AuthSchemeTypes.OAUTH1),
@@ -733,6 +847,27 @@ var ConnectionDataSchema = import_v32.z.discriminatedUnion("authScheme", [
733
847
  * the main connection data discriminated by auth scheme
734
848
  */
735
849
  val: BasicWithJwtConnectionDataSchema
850
+ }),
851
+ import_v32.z.object({
852
+ authScheme: import_v32.z.literal(AuthSchemeTypes.SERVICE_ACCOUNT),
853
+ /**
854
+ * the main connection data discriminated by auth scheme
855
+ */
856
+ val: ServiceAccountConnectionDataSchema
857
+ }),
858
+ import_v32.z.object({
859
+ authScheme: import_v32.z.literal(AuthSchemeTypes.SAML),
860
+ /**
861
+ * the main connection data discriminated by auth scheme
862
+ */
863
+ val: SamlConnectionDataSchema
864
+ }),
865
+ import_v32.z.object({
866
+ authScheme: import_v32.z.literal(AuthSchemeTypes.DCR_OAUTH),
867
+ /**
868
+ * the main connection data discriminated by auth scheme
869
+ */
870
+ val: DcrOauthConnectionDataSchema
736
871
  })
737
872
  ]);
738
873
  var CustomConnectionDataSchema = import_v32.z.discriminatedUnion("authScheme", [
@@ -741,6 +876,11 @@ var CustomConnectionDataSchema = import_v32.z.discriminatedUnion("authScheme", [
741
876
  toolkitSlug: import_v32.z.string(),
742
877
  val: CustomOauth2ConnectionDataSchema
743
878
  }),
879
+ import_v32.z.object({
880
+ authScheme: import_v32.z.literal(AuthSchemeTypes.DCR_OAUTH),
881
+ toolkitSlug: import_v32.z.string(),
882
+ val: CustomDcrOauthConnectionDataSchema
883
+ }),
744
884
  import_v32.z.object({
745
885
  authScheme: import_v32.z.literal(AuthSchemeTypes.API_KEY),
746
886
  toolkitSlug: import_v32.z.string(),
@@ -770,6 +910,11 @@ var CustomConnectionDataSchema = import_v32.z.discriminatedUnion("authScheme", [
770
910
  authScheme: import_v32.z.literal(AuthSchemeTypes.NO_AUTH),
771
911
  toolkitSlug: import_v32.z.string(),
772
912
  val: CustomNoAuthConnectionDataSchema
913
+ }),
914
+ import_v32.z.object({
915
+ authScheme: import_v32.z.literal(AuthSchemeTypes.SERVICE_ACCOUNT),
916
+ toolkitSlug: import_v32.z.string(),
917
+ val: CustomServiceAccountConnectionDataSchema
773
918
  })
774
919
  ]);
775
920
 
@@ -920,7 +1065,12 @@ var ToolProxyParamsSchema = import_v33.z.object({
920
1065
  })
921
1066
  ).optional(),
922
1067
  connectedAccountId: import_v33.z.string().optional(),
923
- customConnectionData: CustomConnectionDataSchema.optional()
1068
+ /**
1069
+ * @deprecated
1070
+ */
1071
+ customConnectionData: CustomConnectionDataSchema.describe(
1072
+ "DEPRECATED: This field is deprecated and will be removed in the future."
1073
+ ).optional()
924
1074
  });
925
1075
 
926
1076
  // src/models/CustomTools.ts
@@ -2327,6 +2477,14 @@ var CustomTools = class {
2327
2477
  parameters,
2328
2478
  body: data.body,
2329
2479
  connected_account_id: connectedAccountId,
2480
+ /**
2481
+ * @deprecated
2482
+ * @description
2483
+ * This parameter is deprecated and will be removed in the future.
2484
+ * Please use custom_auth_params instead.
2485
+ *
2486
+ */
2487
+ // @ts-ignore
2330
2488
  custom_connection_data: data.customConnectionData
2331
2489
  });
2332
2490
  return {
@@ -2787,16 +2945,16 @@ var Tools = class {
2787
2945
  provider;
2788
2946
  autoUploadDownloadFiles;
2789
2947
  toolkitVersions;
2790
- constructor(client, provider, config) {
2948
+ constructor(client, config) {
2791
2949
  if (!client) {
2792
2950
  throw new Error("ComposioClient is required");
2793
2951
  }
2794
- if (!provider) {
2952
+ if (!config?.provider) {
2795
2953
  throw new ComposioProviderNotDefinedError("Provider not passed into Tools instance");
2796
2954
  }
2797
2955
  this.client = client;
2798
2956
  this.customTools = new CustomTools(client);
2799
- this.provider = provider;
2957
+ this.provider = config.provider;
2800
2958
  this.autoUploadDownloadFiles = config?.autoUploadDownloadFiles ?? true;
2801
2959
  this.toolkitVersions = config?.toolkitVersions ?? "latest";
2802
2960
  this.execute = this.execute.bind(this);
@@ -3146,17 +3304,24 @@ var Tools = class {
3146
3304
  */
3147
3305
  async get(userId, arg2, arg3) {
3148
3306
  const options = arg3;
3149
- const executeToolFn = this.createExecuteToolFn(userId, options);
3150
3307
  if (typeof arg2 === "string") {
3151
3308
  const tool = await this.getRawComposioToolBySlug(arg2, {
3152
3309
  modifySchema: options?.modifySchema
3153
3310
  });
3154
- return this.provider.wrapTools([tool], executeToolFn);
3311
+ return this.wrapToolsForProvider(
3312
+ userId,
3313
+ [tool],
3314
+ options
3315
+ );
3155
3316
  } else {
3156
3317
  const tools = await this.getRawComposioTools(arg2, {
3157
3318
  modifySchema: options?.modifySchema
3158
3319
  });
3159
- return this.provider.wrapTools(tools, executeToolFn);
3320
+ return this.wrapToolsForProvider(
3321
+ userId,
3322
+ tools,
3323
+ options
3324
+ );
3160
3325
  }
3161
3326
  }
3162
3327
  /**
@@ -3175,6 +3340,19 @@ var Tools = class {
3175
3340
  );
3176
3341
  };
3177
3342
  }
3343
+ /**
3344
+ * @inte
3345
+ * Utility to wrap a given set of tools in the format expected by the provider
3346
+ *
3347
+ * @param userId - The user id to get the tools for
3348
+ * @param tools - The tools to wrap
3349
+ * @param modifiers - The modifiers to be applied to the tools
3350
+ * @returns The wrapped tools
3351
+ */
3352
+ wrapToolsForProvider(userId, tools, modifiers) {
3353
+ const executeToolFn = this.createExecuteToolFn(userId, modifiers);
3354
+ return this.provider.wrapTools(tools, executeToolFn);
3355
+ }
3178
3356
  /**
3179
3357
  * @internal
3180
3358
  * @description
@@ -3218,6 +3396,13 @@ var Tools = class {
3218
3396
  allow_tracing: body.allowTracing,
3219
3397
  connected_account_id: body.connectedAccountId,
3220
3398
  custom_auth_params: body.customAuthParams,
3399
+ /**
3400
+ * @deprecated: customConnectionData
3401
+ * @description
3402
+ * This parameter is deprecated and will be removed in the future.
3403
+ * Please use custom_connection_data instead.
3404
+ *
3405
+ */
3221
3406
  custom_connection_data: body.customConnectionData,
3222
3407
  arguments: body.arguments,
3223
3408
  user_id: body.userId,
@@ -3423,6 +3608,14 @@ var Tools = class {
3423
3608
  body: toolProxyParams.data.body,
3424
3609
  connected_account_id: toolProxyParams.data.connectedAccountId,
3425
3610
  parameters,
3611
+ /**
3612
+ * @deprecated: customConnectionData
3613
+ * @description
3614
+ * This parameter is deprecated and will be removed in the future.
3615
+ * Please use custom_auth_params instead.
3616
+ *
3617
+ */
3618
+ // @ts-ignore
3426
3619
  custom_connection_data: toolProxyParams.data.customConnectionData
3427
3620
  });
3428
3621
  }
@@ -7400,7 +7593,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
7400
7593
  };
7401
7594
 
7402
7595
  // package.json
7403
- var version = "0.2.6";
7596
+ var version = "0.2.7-alpha.0";
7404
7597
 
7405
7598
  // src/models/Files.ts
7406
7599
  var Files = class {
@@ -7496,77 +7689,337 @@ var getDefaultHeaders = (headers, provider) => {
7496
7689
 
7497
7690
  // src/types/toolRouter.types.ts
7498
7691
  var import_v312 = __toESM(require("zod/v3"), 1);
7499
- var ToolRouterToolkitConfigSchema = import_v312.default.object({
7500
- toolkit: import_v312.default.string(),
7501
- authConfigId: import_v312.default.string().optional()
7502
- });
7503
- var ToolRouterConfigSchema = import_v312.default.object({
7504
- toolkits: import_v312.default.array(import_v312.default.union([import_v312.default.string(), ToolRouterToolkitConfigSchema])).optional(),
7505
- manuallyManageConnections: import_v312.default.boolean().optional()
7692
+ var MCPServerTypeSchema = import_v312.default.enum(["HTTP", "SSE"]);
7693
+ var ToolRouterConfigManageConnectionsSchema = import_v312.default.object({
7694
+ enabled: import_v312.default.boolean().optional().default(true).describe(
7695
+ "Whether to use tools to manage connections in the tool router session. Defaults to true, if set to false, you need to manage connections manually"
7696
+ ),
7697
+ callbackUri: import_v312.default.string().optional().describe("The callback uri to use in the tool router session"),
7698
+ inferScopesFromTools: import_v312.default.boolean().optional().default(false).describe(
7699
+ "Whether to infer scopes from tools in the tool router session. Defaults to false, if set to true, tool router will infer scopes from allowed tools"
7700
+ )
7701
+ }).strict();
7702
+ var ToolRouterToolkitsParamSchema = import_v312.default.array(import_v312.default.string()).describe("List of toolkits to enable in the tool router session");
7703
+ var ToolRouterToolkitsDisabledConfigSchema = import_v312.default.object({
7704
+ disabled: ToolRouterToolkitsParamSchema.describe(
7705
+ "List of toolkits to disable in the tool router session"
7706
+ )
7707
+ }).strict();
7708
+ var ToolRouterToolkitsEnabledConfigSchema = import_v312.default.object({
7709
+ enabled: ToolRouterToolkitsParamSchema.describe(
7710
+ "List of toolkits to enable in the tool router session"
7711
+ )
7712
+ }).strict();
7713
+ var ToolRouterManageConnectionsConfigSchema = import_v312.default.object({
7714
+ enabled: import_v312.default.boolean().optional().describe(
7715
+ "Whether to use tools to manage connections in the tool router session. Defaults to true, if set to false, you need to manage connections manually"
7716
+ ).default(true),
7717
+ callbackUrl: import_v312.default.string().optional().describe("The callback url to use in the tool router session")
7506
7718
  });
7507
- var ToolRouterSessionSchema = import_v312.default.object({
7508
- sessionId: import_v312.default.string(),
7509
- url: import_v312.default.string()
7719
+ var ToolRouterTagsParamSchema = import_v312.default.array(import_v312.default.string()).describe("The tags to use in the tool router session");
7720
+ var ToolRouterEnabledTagsConfigSchema = import_v312.default.object({
7721
+ enabled: ToolRouterTagsParamSchema.describe("The tags to enable in the tool router session")
7722
+ }).strict();
7723
+ var ToolRouterDisabledTagsConfigSchema = import_v312.default.object({
7724
+ disabled: ToolRouterTagsParamSchema.describe("The tags to disable in the tool router session")
7725
+ }).strict();
7726
+ var ToolRouterConfigTagsSchema = import_v312.default.union([
7727
+ ToolRouterTagsParamSchema,
7728
+ ToolRouterEnabledTagsConfigSchema,
7729
+ ToolRouterDisabledTagsConfigSchema
7730
+ ]).describe("The tags to use in the tool router session");
7731
+ var ToolRouterToolsParamSchema = import_v312.default.array(import_v312.default.string()).describe("The tools to use in the tool router session");
7732
+ var ToolRouterConfigToolsSchema = import_v312.default.object({
7733
+ overrides: import_v312.default.record(
7734
+ import_v312.default.string(),
7735
+ import_v312.default.union([
7736
+ ToolRouterToolsParamSchema,
7737
+ import_v312.default.object({
7738
+ enabled: ToolRouterToolsParamSchema.describe(
7739
+ "The tools to enable in the tool router session"
7740
+ )
7741
+ }).strict(),
7742
+ import_v312.default.object({
7743
+ disabled: ToolRouterToolsParamSchema.describe(
7744
+ "The tools to disable in the tool router session"
7745
+ )
7746
+ }).strict()
7747
+ ])
7748
+ ).describe("The tools to override in the tool router session").optional(),
7749
+ tags: ToolRouterConfigTagsSchema.optional().describe("The tags to filter the tools by")
7750
+ }).strict();
7751
+ var ToolRouterCreateSessionConfigSchema = import_v312.default.object({
7752
+ tools: ToolRouterConfigToolsSchema.optional().describe(
7753
+ "The tools to use in the tool router session"
7754
+ ),
7755
+ toolkits: import_v312.default.union([
7756
+ ToolRouterToolkitsParamSchema,
7757
+ ToolRouterToolkitsDisabledConfigSchema,
7758
+ ToolRouterToolkitsEnabledConfigSchema
7759
+ ]).optional().describe("The toolkits to use in the tool router session"),
7760
+ authConfigs: import_v312.default.record(import_v312.default.string(), import_v312.default.string()).describe(
7761
+ "The auth configs to use in the tool router session. The key is the toolkit slug, the value is the auth config id."
7762
+ ).default({}),
7763
+ connectedAccounts: import_v312.default.record(import_v312.default.string(), import_v312.default.string()).describe(
7764
+ "The connected accounts to use in the tool router session. The key is the toolkit slug, the value is the connected account id."
7765
+ ).default({}),
7766
+ manageConnections: import_v312.default.union([import_v312.default.boolean(), ToolRouterConfigManageConnectionsSchema]).optional().default(true).describe(
7767
+ "The config for the manage connections in the tool router session. Defaults to true, if set to false, you need to manage connections manually. If set to an object, you can configure the manage connections settings."
7768
+ ),
7769
+ execution: import_v312.default.object({
7770
+ proxyExecutionEnabled: import_v312.default.boolean().optional().describe("Whether to enable proxy execution in the tool router session"),
7771
+ timeoutSeconds: import_v312.default.number().optional().describe("The timeout in seconds for the tool router session")
7772
+ }).optional().describe("The execution config for the tool router session")
7773
+ }).partial().describe("The config for the tool router session");
7774
+ var ToolkitConnectionStateSchema = import_v312.default.object({
7775
+ slug: import_v312.default.string().describe("The slug of a toolkit"),
7776
+ name: import_v312.default.string().describe("The name of a toolkit"),
7777
+ logo: import_v312.default.string().optional().describe("The logo of a toolkit"),
7778
+ isNoAuth: import_v312.default.boolean().default(false).describe("Whether the toolkit is no auth or not"),
7779
+ connection: import_v312.default.object({
7780
+ isActive: import_v312.default.boolean().describe("Whether the connection is active or not"),
7781
+ authConfig: import_v312.default.object({
7782
+ id: import_v312.default.string().describe("The id of the auth config"),
7783
+ mode: import_v312.default.string().describe("The auth scheme used by the auth config"),
7784
+ isComposioManaged: import_v312.default.boolean().describe("Whether the auth config is managed by Composio")
7785
+ }).nullish().describe("The auth config of a toolkit"),
7786
+ connectedAccount: import_v312.default.object({
7787
+ id: import_v312.default.string().describe("The id of the connected account"),
7788
+ status: import_v312.default.string().describe("The status of the connected account")
7789
+ }).optional().describe("The connected account of a toolkit")
7790
+ })
7791
+ }).describe("The connection state of a toolkit");
7792
+ var ToolkitConnectionsDetailsSchema = import_v312.default.object({
7793
+ items: import_v312.default.array(ToolkitConnectionStateSchema),
7794
+ nextCursor: import_v312.default.string().optional(),
7795
+ totalPages: import_v312.default.number()
7510
7796
  });
7511
7797
 
7512
- // src/models/ToolRouter.experimental.ts
7798
+ // src/lib/toolRouterParams.ts
7799
+ var transformToolRouterToolsParams = (params) => {
7800
+ if (!params) {
7801
+ return void 0;
7802
+ }
7803
+ const { overrides, tags } = params;
7804
+ const toolOverrides = overrides ? Object.keys(overrides).reduce(
7805
+ (acc, key) => {
7806
+ const override = overrides[key];
7807
+ if (Array.isArray(override)) {
7808
+ acc[key] = { enabled: override };
7809
+ } else if (override !== void 0) {
7810
+ if ("enabled" in override && override.enabled) {
7811
+ acc[key] = { enabled: override.enabled };
7812
+ } else if ("disabled" in override && override.disabled) {
7813
+ acc[key] = { disabled: override.disabled };
7814
+ }
7815
+ }
7816
+ return acc;
7817
+ },
7818
+ {}
7819
+ ) : void 0;
7820
+ const tagFilters = tags ? (() => {
7821
+ if (Array.isArray(tags)) {
7822
+ return { include: tags };
7823
+ } else if ("enabled" in tags && tags.enabled) {
7824
+ return { include: tags.enabled };
7825
+ } else if ("disabled" in tags && tags.disabled) {
7826
+ return { exclude: tags.disabled };
7827
+ }
7828
+ return void 0;
7829
+ })() : void 0;
7830
+ return {
7831
+ overrides: toolOverrides,
7832
+ filters: tagFilters ? {
7833
+ tags: tagFilters
7834
+ } : void 0
7835
+ };
7836
+ };
7837
+
7838
+ // src/models/ToolRouter.ts
7513
7839
  var ToolRouter = class {
7514
- constructor(client) {
7515
- this.client = client;
7840
+ constructor(client, config) {
7516
7841
  this.client = client;
7842
+ this.config = config;
7517
7843
  telemetry.instrument(this, "ToolRouter");
7518
7844
  }
7519
7845
  /**
7520
- * Creates a new Session for the tool router
7846
+ * Creates a function that authorizes a toolkit for a user.
7847
+ * @param sessionId {string} The session id to create the authorize function for
7848
+ * @returns {ToolRouterAuthorizeFn} The authorize function
7849
+ *
7850
+ */
7851
+ createAuthorizeFn = (sessionId) => {
7852
+ const authorizeFn = async (toolkit, options) => {
7853
+ const response = await this.client.toolRouter.session.link(sessionId, {
7854
+ ...options ?? {},
7855
+ toolkit
7856
+ });
7857
+ return createConnectionRequest(
7858
+ this.client,
7859
+ response.connected_account_id,
7860
+ ConnectedAccountStatuses.INITIATED,
7861
+ response.redirect_url
7862
+ );
7863
+ };
7864
+ return authorizeFn;
7865
+ };
7866
+ /**
7867
+ *
7868
+ * @param sessionId {string} The session id to create the connections function for
7869
+ * @returns {ToolRouterConectionsFn} The connections function
7870
+ *
7871
+ * @example
7872
+ * ```typescript
7873
+ * import { Composio } from '@composio/core';
7874
+ *
7875
+ * const composio = new Composio();
7876
+ * const sessionId = 'session_123';
7877
+ *
7878
+ * const session = await composio.create(sessionId);
7879
+ * console.log(connections);
7880
+ * ```
7881
+ */
7882
+ createToolkitsFn = (sessionId) => {
7883
+ const connectionsFn = async (options) => {
7884
+ const result = await this.client.toolRouter.session.toolkits(sessionId, {
7885
+ cursor: options?.nextCursor,
7886
+ limit: options?.limit
7887
+ });
7888
+ const toolkitConnectedStates = result.items.map((item) => {
7889
+ const connectedState = transform(item).with(ToolkitConnectionStateSchema).using((item2) => ({
7890
+ slug: item2.slug,
7891
+ name: item2.name,
7892
+ logo: item2.meta.logo,
7893
+ isNoAuth: false,
7894
+ connection: {
7895
+ isActive: item2.connected_account?.status === "ACTIVE",
7896
+ authConfig: item2.connected_account && {
7897
+ id: item2.connected_account?.auth_config.id,
7898
+ mode: item2.connected_account?.auth_config.auth_scheme,
7899
+ isComposioManaged: item2.connected_account?.auth_config.is_composio_managed
7900
+ },
7901
+ connectedAccount: item2.connected_account ? {
7902
+ id: item2.connected_account.id,
7903
+ status: item2.connected_account.status
7904
+ } : void 0
7905
+ }
7906
+ }));
7907
+ return connectedState;
7908
+ });
7909
+ return {
7910
+ items: toolkitConnectedStates,
7911
+ nextCursor: result.next_cursor,
7912
+ totalPages: result.total_pages
7913
+ };
7914
+ };
7915
+ return connectionsFn;
7916
+ };
7917
+ /**
7918
+ * @internal
7919
+ * Creates a function that wraps the tools based on the provider.
7920
+ * The returned tools will be of the type the frameworks expects.
7921
+ *
7922
+ * @param userId - The user id to get the tools for
7923
+ * @param tools - The tools to wrap
7924
+ * @returns A function that wraps the tools based on the provider.
7925
+ */
7926
+ createToolsFn = (userId, toolSlugs) => {
7927
+ return async (modifiers) => {
7928
+ const ToolsModel = new Tools(this.client, this.config);
7929
+ const tools = await ToolsModel.get(
7930
+ userId,
7931
+ {
7932
+ tools: toolSlugs
7933
+ },
7934
+ modifiers
7935
+ );
7936
+ return tools;
7937
+ };
7938
+ };
7939
+ /**
7940
+ * Creates a new tool router session for a user.
7521
7941
  *
7522
7942
  * @param userId {string} The user id to create the session for
7523
- * @param routerConfig {ToolRouterConfig} The router config to use
7524
- * @returns {Promise<ToolRouterSession>} The tool router session
7943
+ * @param config {ToolRouterConfig} The config for the tool router session
7944
+ * @returns {Promise<ToolRouterSession<TToolCollection, TTool, TProvider>>} The tool router session
7525
7945
  *
7526
7946
  * @example
7527
7947
  * ```typescript
7528
- * import { Composio } form "@composio/core"
7948
+ * import { Composio } from '@composio/core';
7529
7949
  *
7530
- * const composio = new Composio()
7531
- * const userId = "xxx-ooo-xxxx"
7950
+ * const composio = new Composio();
7951
+ * const userId = 'user_123';
7532
7952
  *
7533
- * const mcpSession = await composio.experimental.toolRouter.createSession(userId, {
7534
- * toolkits: ["github", "hackernews", "slack"]
7535
- * })
7953
+ * const session = await composio.create(userId, {
7954
+ * manageConnections: true,
7955
+ * });
7536
7956
  *
7537
- * // with auth configs
7538
- * const mcpSession = await composio.experimental.toolRouter.createSession(userId, {
7539
- * toolkits: [{ toolkit: "github", authConfingId: "ac_123455344"}]
7957
+ * console.log(session.sessionId);
7958
+ * console.log(session.url);
7959
+ * console.log(session.tools());
7960
+ * console.log(session.toolkits());
7540
7961
  * ```
7541
7962
  */
7542
- async createSession(userId, routerConfig) {
7543
- const config = ToolRouterConfigSchema.safeParse(routerConfig ?? {});
7544
- if (config.error) {
7545
- throw new ValidationError("Failed to parse tool router config", {
7546
- cause: config.error
7547
- });
7548
- }
7549
- const toolkitConfig = config.data.toolkits?.map((config2) => {
7550
- if (typeof config2 === "string") {
7551
- return { toolkit: config2 };
7552
- } else {
7553
- return {
7554
- toolkit: config2.toolkit,
7555
- auth_config_id: config2.authConfigId
7556
- };
7557
- }
7558
- });
7559
- const session = await this.client.toolRouter.createSession({
7963
+ async create(userId, config) {
7964
+ const routerConfig = ToolRouterCreateSessionConfigSchema.parse(config ?? {});
7965
+ const manageConnectedAccounts = typeof routerConfig.manageConnections === "boolean" ? routerConfig.manageConnections : routerConfig.manageConnections?.enabled ?? true;
7966
+ const toolkits = Array.isArray(routerConfig.toolkits) ? { enabled: routerConfig.toolkits } : routerConfig.toolkits;
7967
+ const tools = transformToolRouterToolsParams(routerConfig.tools);
7968
+ const inferScopesFromTools = typeof routerConfig.manageConnections === "object" ? routerConfig.manageConnections.inferScopesFromTools : false;
7969
+ const payload = {
7560
7970
  user_id: userId,
7561
- config: {
7562
- toolkits: toolkitConfig,
7563
- manually_manage_connections: config.data.manuallyManageConnections
7564
- }
7565
- });
7566
- return transform(session).with(ToolRouterSessionSchema).using((raw) => ({
7567
- sessionId: raw.session_id,
7568
- url: raw.chat_session_mcp_url
7569
- }));
7971
+ toolkits,
7972
+ auth_configs: routerConfig.authConfigs,
7973
+ connected_accounts: routerConfig.connectedAccounts,
7974
+ tools,
7975
+ connections: {
7976
+ infer_scopes_from_tools: inferScopesFromTools,
7977
+ auto_manage_connections: manageConnectedAccounts,
7978
+ callback_uri: typeof routerConfig.manageConnections === "object" ? routerConfig.manageConnections.callbackUri : void 0
7979
+ },
7980
+ execution: routerConfig.execution ? {
7981
+ proxy_execution_enabled: routerConfig.execution?.proxyExecutionEnabled,
7982
+ timeout_seconds: routerConfig.execution?.timeoutSeconds
7983
+ } : void 0
7984
+ };
7985
+ const session = await this.client.toolRouter.session.create(payload);
7986
+ return {
7987
+ sessionId: session.session_id,
7988
+ mcp: {
7989
+ type: session.mcp.type,
7990
+ url: session.mcp.url
7991
+ },
7992
+ tools: this.createToolsFn(userId, session.tool_router_tools),
7993
+ authorize: this.createAuthorizeFn(session.session_id),
7994
+ toolkits: this.createToolkitsFn(session.session_id)
7995
+ };
7996
+ }
7997
+ /**
7998
+ * Use an existing session
7999
+ * @param id {string} The id of the session to use
8000
+ * @returns {Promise<ToolRouterSession<TToolCollection, TTool, TProvider>>} The tool router session
8001
+ *
8002
+ * @example
8003
+ * ```typescript
8004
+ * import { Composio } from '@composio/core';
8005
+ *
8006
+ * const composio = new Composio();
8007
+ * const id = 'session_123';
8008
+ * const session = await composio.toolRouter.use(id);
8009
+ *```
8010
+ */
8011
+ async use(id) {
8012
+ const session = await this.client.toolRouter.session.retrieve(id);
8013
+ return {
8014
+ sessionId: session.session_id,
8015
+ mcp: {
8016
+ type: session.mcp.type,
8017
+ url: session.mcp.url
8018
+ },
8019
+ tools: this.createToolsFn(session.config.user_id, session.tool_router_tools),
8020
+ authorize: this.createAuthorizeFn(session.session_id),
8021
+ toolkits: this.createToolkitsFn(session.session_id)
8022
+ };
7570
8023
  }
7571
8024
  };
7572
8025
 
@@ -7593,6 +8046,11 @@ var Composio = class _Composio {
7593
8046
  authConfigs;
7594
8047
  connectedAccounts;
7595
8048
  mcp;
8049
+ /**
8050
+ * Experimental feature, use with caution
8051
+ * @experimental
8052
+ */
8053
+ toolRouter;
7596
8054
  /**
7597
8055
  * Experimental features
7598
8056
  */
@@ -7656,21 +8114,21 @@ var Composio = class _Composio {
7656
8114
  defaultHeaders,
7657
8115
  logLevel: COMPOSIO_LOG_LEVEL
7658
8116
  });
7659
- this.tools = new Tools(this.client, this.provider, this.config);
8117
+ this.tools = new Tools(this.client, this.config);
7660
8118
  this.mcp = new MCP(this.client);
7661
8119
  this.toolkits = new Toolkits(this.client);
7662
8120
  this.triggers = new Triggers(this.client, this.config);
7663
8121
  this.authConfigs = new AuthConfigs(this.client);
7664
8122
  this.files = new Files(this.client);
7665
8123
  this.connectedAccounts = new ConnectedAccounts(this.client);
8124
+ this.toolRouter = new ToolRouter(this.client, this.config);
7666
8125
  this.experimental = {
7667
- /**
7668
- * Experimental tool router
7669
- * Helps you create a single MCP server containing all the tools with smart routing.
7670
- *
7671
- * @description Allows you to create an isolated toolRouter MCP session for a user
7672
- */
7673
- toolRouter: new ToolRouter(this.client)
8126
+ create: async (userId, routerConfig) => {
8127
+ return this.toolRouter.create(userId, routerConfig);
8128
+ },
8129
+ use: async (id) => {
8130
+ return this.toolRouter.use(id);
8131
+ }
7674
8132
  };
7675
8133
  this.deprecated = {
7676
8134
  /**
@@ -8029,6 +8487,7 @@ var AuthScheme = class {
8029
8487
  MCPServerCreateResponseSchema,
8030
8488
  MCPServerListResponseSchema,
8031
8489
  MCPServerSchema,
8490
+ MCPServerTypeSchema,
8032
8491
  MCPServerUpdateParamsSchema,
8033
8492
  MCPSingleAppServerSchema,
8034
8493
  MCPToolkitConfigSchema,
@@ -8063,15 +8522,25 @@ var AuthScheme = class {
8063
8522
  ToolListParamsSchema,
8064
8523
  ToolListResponseSchema,
8065
8524
  ToolProxyParamsSchema,
8066
- ToolRouter,
8067
- ToolRouterConfigSchema,
8068
- ToolRouterSessionSchema,
8069
- ToolRouterToolkitConfigSchema,
8525
+ ToolRouterConfigManageConnectionsSchema,
8526
+ ToolRouterConfigTagsSchema,
8527
+ ToolRouterConfigToolsSchema,
8528
+ ToolRouterCreateSessionConfigSchema,
8529
+ ToolRouterDisabledTagsConfigSchema,
8530
+ ToolRouterEnabledTagsConfigSchema,
8531
+ ToolRouterManageConnectionsConfigSchema,
8532
+ ToolRouterTagsParamSchema,
8533
+ ToolRouterToolkitsDisabledConfigSchema,
8534
+ ToolRouterToolkitsEnabledConfigSchema,
8535
+ ToolRouterToolkitsParamSchema,
8536
+ ToolRouterToolsParamSchema,
8070
8537
  ToolSchema,
8071
8538
  ToolkitAuthConfigDetailsSchema,
8072
8539
  ToolkitAuthFieldSchema,
8073
8540
  ToolkitAuthFieldsResponseSchema,
8074
8541
  ToolkitCategorySchema,
8542
+ ToolkitConnectionStateSchema,
8543
+ ToolkitConnectionsDetailsSchema,
8075
8544
  ToolkitErrorCodes,
8076
8545
  ToolkitMangedByEnumSchema,
8077
8546
  ToolkitRetrieveCategoriesResponseSchema,