@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.js CHANGED
@@ -36,7 +36,9 @@ var AuthSchemeTypes = {
36
36
  NO_AUTH: "NO_AUTH",
37
37
  BASIC_WITH_JWT: "BASIC_WITH_JWT",
38
38
  CALCOM_AUTH: "CALCOM_AUTH",
39
- SERVICE_ACCOUNT: "SERVICE_ACCOUNT"
39
+ SERVICE_ACCOUNT: "SERVICE_ACCOUNT",
40
+ SAML: "SAML",
41
+ DCR_OAUTH: "DCR_OAUTH"
40
42
  };
41
43
  var AuthConfigCreationToolAccessConfigSchema = z.object({
42
44
  toolsForConnectedAccountCreation: z.array(z.string()).optional()
@@ -56,7 +58,9 @@ var AuthSchemeEnum = z.enum([
56
58
  "NO_AUTH",
57
59
  "BASIC_WITH_JWT",
58
60
  "CALCOM_AUTH",
59
- "SERVICE_ACCOUNT"
61
+ "SERVICE_ACCOUNT",
62
+ "SAML",
63
+ "DCR_OAUTH"
60
64
  ]);
61
65
  var CreateCustomAuthConfigParamsSchema = z.object({
62
66
  type: z.literal("use_custom_auth"),
@@ -203,7 +207,14 @@ var BaseSchemeRaw = z2.object({
203
207
  // for generic api key
204
208
  generic_api_key: z2.string().optional(),
205
209
  // for bearer token
206
- bearer_token: z2.string().optional()
210
+ bearer_token: z2.string().optional(),
211
+ // for basic auth encoded
212
+ basic_encoded: z2.string().optional(),
213
+ // for dcr oauth
214
+ long_redirect_url: z2.boolean().optional(),
215
+ state_prefix: z2.string().optional(),
216
+ registration_access_token: z2.string().optional(),
217
+ registration_client_uri: z2.string().optional()
207
218
  }).catchall(z2.unknown());
208
219
  var Oauth2InitiatingConnectionDataSchema = BaseSchemeRaw.extend({
209
220
  status: z2.literal(ConnectionStatuses.INITIALIZING)
@@ -479,6 +490,98 @@ var BasicWithJwtConnectionDataSchema = z2.discriminatedUnion("status", [
479
490
  var CustomBasicWithJwtConnectionDataSchema = BasicWithJwtInitiatingSchema.omit({
480
491
  status: true
481
492
  });
493
+ var ServiceAccountInitiatingSchema = BaseSchemeRaw.extend({
494
+ status: z2.literal(ConnectionStatuses.INITIALIZING)
495
+ }).catchall(z2.unknown());
496
+ var ServiceAccountConnectionDataSchema = z2.discriminatedUnion("status", [
497
+ ServiceAccountInitiatingSchema,
498
+ ServiceAccountInitiatingSchema.extend({
499
+ status: z2.literal(ConnectionStatuses.INITIATED)
500
+ }).catchall(z2.unknown()),
501
+ ServiceAccountInitiatingSchema.extend({
502
+ status: z2.literal(ConnectionStatuses.ACTIVE),
503
+ application_id: z2.string(),
504
+ installation_id: z2.string(),
505
+ private_key: z2.string()
506
+ }).catchall(z2.unknown()),
507
+ ServiceAccountInitiatingSchema.extend({
508
+ status: z2.literal(ConnectionStatuses.INACTIVE),
509
+ application_id: z2.string(),
510
+ installation_id: z2.string(),
511
+ private_key: z2.string()
512
+ }).catchall(z2.unknown())
513
+ ]);
514
+ var CustomServiceAccountConnectionDataSchema = z2.object({
515
+ application_id: z2.string(),
516
+ installation_id: z2.string(),
517
+ private_key: z2.string()
518
+ }).merge(BaseSchemeRaw).catchall(z2.unknown());
519
+ var SamlInitiatingSchema = BaseSchemeRaw.extend({
520
+ status: z2.literal(ConnectionStatuses.INITIALIZING)
521
+ }).catchall(z2.unknown());
522
+ var SamlConnectionDataSchema = z2.discriminatedUnion("status", [
523
+ SamlInitiatingSchema,
524
+ SamlInitiatingSchema.extend({
525
+ status: z2.literal(ConnectionStatuses.INITIATED)
526
+ }).catchall(z2.unknown()),
527
+ SamlInitiatingSchema.extend({
528
+ status: z2.literal(ConnectionStatuses.ACTIVE)
529
+ }).catchall(z2.unknown()),
530
+ SamlInitiatingSchema.extend({
531
+ status: z2.literal(ConnectionStatuses.INACTIVE)
532
+ }).catchall(z2.unknown()),
533
+ SamlInitiatingSchema.extend({
534
+ status: z2.literal(ConnectionStatuses.FAILED),
535
+ error: z2.string().optional(),
536
+ error_description: z2.string().optional()
537
+ }).catchall(z2.unknown()),
538
+ SamlInitiatingSchema.extend({
539
+ status: z2.literal(ConnectionStatuses.EXPIRED),
540
+ expired_at: z2.string().optional()
541
+ }).catchall(z2.unknown())
542
+ ]);
543
+ var CustomSamlConnectionDataSchema = BaseSchemeRaw.catchall(z2.unknown());
544
+ var DcrOauthInitiatingSchema = BaseSchemeRaw.extend({
545
+ status: z2.literal(ConnectionStatuses.INITIALIZING)
546
+ }).catchall(z2.unknown());
547
+ var DcrOauthConnectionDataSchema = z2.discriminatedUnion("status", [
548
+ DcrOauthInitiatingSchema,
549
+ DcrOauthInitiatingSchema.extend({
550
+ status: z2.literal(ConnectionStatuses.INITIATED),
551
+ client_id: z2.string(),
552
+ client_secret: z2.string(),
553
+ redirectUrl: z2.string()
554
+ }).catchall(z2.unknown()),
555
+ DcrOauthInitiatingSchema.extend({
556
+ status: z2.literal(ConnectionStatuses.ACTIVE),
557
+ access_token: z2.string(),
558
+ client_id: z2.string(),
559
+ token_type: z2.string().optional(),
560
+ refresh_token: z2.string().nullish(),
561
+ expires_in: z2.union([z2.string(), z2.number(), z2.null()]).optional(),
562
+ scope: z2.union([z2.string(), z2.array(z2.string()), z2.null()]).optional(),
563
+ id_token: z2.string().optional(),
564
+ client_secret: z2.string().optional()
565
+ }).catchall(z2.unknown()),
566
+ DcrOauthInitiatingSchema.extend({
567
+ status: z2.literal(ConnectionStatuses.INACTIVE),
568
+ access_token: z2.string(),
569
+ client_id: z2.string()
570
+ }).catchall(z2.unknown()),
571
+ DcrOauthInitiatingSchema.extend({
572
+ status: z2.literal(ConnectionStatuses.FAILED),
573
+ error: z2.string().optional(),
574
+ error_description: z2.string().optional()
575
+ }).catchall(z2.unknown()),
576
+ DcrOauthInitiatingSchema.extend({
577
+ status: z2.literal(ConnectionStatuses.EXPIRED),
578
+ expired_at: z2.string().optional()
579
+ }).catchall(z2.unknown())
580
+ ]);
581
+ var CustomDcrOauthConnectionDataSchema = z2.object({
582
+ access_token: z2.string(),
583
+ client_id: z2.string()
584
+ }).merge(BaseSchemeRaw).catchall(z2.unknown());
482
585
  var ConnectionDataSchema = z2.discriminatedUnion("authScheme", [
483
586
  z2.object({
484
587
  authScheme: z2.literal(AuthSchemeTypes.OAUTH1),
@@ -556,6 +659,27 @@ var ConnectionDataSchema = z2.discriminatedUnion("authScheme", [
556
659
  * the main connection data discriminated by auth scheme
557
660
  */
558
661
  val: BasicWithJwtConnectionDataSchema
662
+ }),
663
+ z2.object({
664
+ authScheme: z2.literal(AuthSchemeTypes.SERVICE_ACCOUNT),
665
+ /**
666
+ * the main connection data discriminated by auth scheme
667
+ */
668
+ val: ServiceAccountConnectionDataSchema
669
+ }),
670
+ z2.object({
671
+ authScheme: z2.literal(AuthSchemeTypes.SAML),
672
+ /**
673
+ * the main connection data discriminated by auth scheme
674
+ */
675
+ val: SamlConnectionDataSchema
676
+ }),
677
+ z2.object({
678
+ authScheme: z2.literal(AuthSchemeTypes.DCR_OAUTH),
679
+ /**
680
+ * the main connection data discriminated by auth scheme
681
+ */
682
+ val: DcrOauthConnectionDataSchema
559
683
  })
560
684
  ]);
561
685
  var CustomConnectionDataSchema = z2.discriminatedUnion("authScheme", [
@@ -564,6 +688,11 @@ var CustomConnectionDataSchema = z2.discriminatedUnion("authScheme", [
564
688
  toolkitSlug: z2.string(),
565
689
  val: CustomOauth2ConnectionDataSchema
566
690
  }),
691
+ z2.object({
692
+ authScheme: z2.literal(AuthSchemeTypes.DCR_OAUTH),
693
+ toolkitSlug: z2.string(),
694
+ val: CustomDcrOauthConnectionDataSchema
695
+ }),
567
696
  z2.object({
568
697
  authScheme: z2.literal(AuthSchemeTypes.API_KEY),
569
698
  toolkitSlug: z2.string(),
@@ -593,6 +722,11 @@ var CustomConnectionDataSchema = z2.discriminatedUnion("authScheme", [
593
722
  authScheme: z2.literal(AuthSchemeTypes.NO_AUTH),
594
723
  toolkitSlug: z2.string(),
595
724
  val: CustomNoAuthConnectionDataSchema
725
+ }),
726
+ z2.object({
727
+ authScheme: z2.literal(AuthSchemeTypes.SERVICE_ACCOUNT),
728
+ toolkitSlug: z2.string(),
729
+ val: CustomServiceAccountConnectionDataSchema
596
730
  })
597
731
  ]);
598
732
 
@@ -743,7 +877,12 @@ var ToolProxyParamsSchema = z3.object({
743
877
  })
744
878
  ).optional(),
745
879
  connectedAccountId: z3.string().optional(),
746
- customConnectionData: CustomConnectionDataSchema.optional()
880
+ /**
881
+ * @deprecated
882
+ */
883
+ customConnectionData: CustomConnectionDataSchema.describe(
884
+ "DEPRECATED: This field is deprecated and will be removed in the future."
885
+ ).optional()
747
886
  });
748
887
 
749
888
  // src/models/CustomTools.ts
@@ -2150,6 +2289,14 @@ var CustomTools = class {
2150
2289
  parameters,
2151
2290
  body: data.body,
2152
2291
  connected_account_id: connectedAccountId,
2292
+ /**
2293
+ * @deprecated
2294
+ * @description
2295
+ * This parameter is deprecated and will be removed in the future.
2296
+ * Please use custom_auth_params instead.
2297
+ *
2298
+ */
2299
+ // @ts-ignore
2153
2300
  custom_connection_data: data.customConnectionData
2154
2301
  });
2155
2302
  return {
@@ -2610,16 +2757,16 @@ var Tools = class {
2610
2757
  provider;
2611
2758
  autoUploadDownloadFiles;
2612
2759
  toolkitVersions;
2613
- constructor(client, provider, config) {
2760
+ constructor(client, config) {
2614
2761
  if (!client) {
2615
2762
  throw new Error("ComposioClient is required");
2616
2763
  }
2617
- if (!provider) {
2764
+ if (!config?.provider) {
2618
2765
  throw new ComposioProviderNotDefinedError("Provider not passed into Tools instance");
2619
2766
  }
2620
2767
  this.client = client;
2621
2768
  this.customTools = new CustomTools(client);
2622
- this.provider = provider;
2769
+ this.provider = config.provider;
2623
2770
  this.autoUploadDownloadFiles = config?.autoUploadDownloadFiles ?? true;
2624
2771
  this.toolkitVersions = config?.toolkitVersions ?? "latest";
2625
2772
  this.execute = this.execute.bind(this);
@@ -2969,17 +3116,24 @@ var Tools = class {
2969
3116
  */
2970
3117
  async get(userId, arg2, arg3) {
2971
3118
  const options = arg3;
2972
- const executeToolFn = this.createExecuteToolFn(userId, options);
2973
3119
  if (typeof arg2 === "string") {
2974
3120
  const tool = await this.getRawComposioToolBySlug(arg2, {
2975
3121
  modifySchema: options?.modifySchema
2976
3122
  });
2977
- return this.provider.wrapTools([tool], executeToolFn);
3123
+ return this.wrapToolsForProvider(
3124
+ userId,
3125
+ [tool],
3126
+ options
3127
+ );
2978
3128
  } else {
2979
3129
  const tools = await this.getRawComposioTools(arg2, {
2980
3130
  modifySchema: options?.modifySchema
2981
3131
  });
2982
- return this.provider.wrapTools(tools, executeToolFn);
3132
+ return this.wrapToolsForProvider(
3133
+ userId,
3134
+ tools,
3135
+ options
3136
+ );
2983
3137
  }
2984
3138
  }
2985
3139
  /**
@@ -2998,6 +3152,19 @@ var Tools = class {
2998
3152
  );
2999
3153
  };
3000
3154
  }
3155
+ /**
3156
+ * @inte
3157
+ * Utility to wrap a given set of tools in the format expected by the provider
3158
+ *
3159
+ * @param userId - The user id to get the tools for
3160
+ * @param tools - The tools to wrap
3161
+ * @param modifiers - The modifiers to be applied to the tools
3162
+ * @returns The wrapped tools
3163
+ */
3164
+ wrapToolsForProvider(userId, tools, modifiers) {
3165
+ const executeToolFn = this.createExecuteToolFn(userId, modifiers);
3166
+ return this.provider.wrapTools(tools, executeToolFn);
3167
+ }
3001
3168
  /**
3002
3169
  * @internal
3003
3170
  * @description
@@ -3041,6 +3208,13 @@ var Tools = class {
3041
3208
  allow_tracing: body.allowTracing,
3042
3209
  connected_account_id: body.connectedAccountId,
3043
3210
  custom_auth_params: body.customAuthParams,
3211
+ /**
3212
+ * @deprecated: customConnectionData
3213
+ * @description
3214
+ * This parameter is deprecated and will be removed in the future.
3215
+ * Please use custom_connection_data instead.
3216
+ *
3217
+ */
3044
3218
  custom_connection_data: body.customConnectionData,
3045
3219
  arguments: body.arguments,
3046
3220
  user_id: body.userId,
@@ -3246,6 +3420,14 @@ var Tools = class {
3246
3420
  body: toolProxyParams.data.body,
3247
3421
  connected_account_id: toolProxyParams.data.connectedAccountId,
3248
3422
  parameters,
3423
+ /**
3424
+ * @deprecated: customConnectionData
3425
+ * @description
3426
+ * This parameter is deprecated and will be removed in the future.
3427
+ * Please use custom_auth_params instead.
3428
+ *
3429
+ */
3430
+ // @ts-ignore
3249
3431
  custom_connection_data: toolProxyParams.data.customConnectionData
3250
3432
  });
3251
3433
  }
@@ -7223,7 +7405,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
7223
7405
  };
7224
7406
 
7225
7407
  // package.json
7226
- var version = "0.2.6";
7408
+ var version = "0.2.7-alpha.0";
7227
7409
 
7228
7410
  // src/models/Files.ts
7229
7411
  var Files = class {
@@ -7319,77 +7501,337 @@ var getDefaultHeaders = (headers, provider) => {
7319
7501
 
7320
7502
  // src/types/toolRouter.types.ts
7321
7503
  import z10 from "zod/v3";
7322
- var ToolRouterToolkitConfigSchema = z10.object({
7323
- toolkit: z10.string(),
7324
- authConfigId: z10.string().optional()
7325
- });
7326
- var ToolRouterConfigSchema = z10.object({
7327
- toolkits: z10.array(z10.union([z10.string(), ToolRouterToolkitConfigSchema])).optional(),
7328
- manuallyManageConnections: z10.boolean().optional()
7504
+ var MCPServerTypeSchema = z10.enum(["HTTP", "SSE"]);
7505
+ var ToolRouterConfigManageConnectionsSchema = z10.object({
7506
+ enabled: z10.boolean().optional().default(true).describe(
7507
+ "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"
7508
+ ),
7509
+ callbackUri: z10.string().optional().describe("The callback uri to use in the tool router session"),
7510
+ inferScopesFromTools: z10.boolean().optional().default(false).describe(
7511
+ "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"
7512
+ )
7513
+ }).strict();
7514
+ var ToolRouterToolkitsParamSchema = z10.array(z10.string()).describe("List of toolkits to enable in the tool router session");
7515
+ var ToolRouterToolkitsDisabledConfigSchema = z10.object({
7516
+ disabled: ToolRouterToolkitsParamSchema.describe(
7517
+ "List of toolkits to disable in the tool router session"
7518
+ )
7519
+ }).strict();
7520
+ var ToolRouterToolkitsEnabledConfigSchema = z10.object({
7521
+ enabled: ToolRouterToolkitsParamSchema.describe(
7522
+ "List of toolkits to enable in the tool router session"
7523
+ )
7524
+ }).strict();
7525
+ var ToolRouterManageConnectionsConfigSchema = z10.object({
7526
+ enabled: z10.boolean().optional().describe(
7527
+ "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"
7528
+ ).default(true),
7529
+ callbackUrl: z10.string().optional().describe("The callback url to use in the tool router session")
7329
7530
  });
7330
- var ToolRouterSessionSchema = z10.object({
7331
- sessionId: z10.string(),
7332
- url: z10.string()
7531
+ var ToolRouterTagsParamSchema = z10.array(z10.string()).describe("The tags to use in the tool router session");
7532
+ var ToolRouterEnabledTagsConfigSchema = z10.object({
7533
+ enabled: ToolRouterTagsParamSchema.describe("The tags to enable in the tool router session")
7534
+ }).strict();
7535
+ var ToolRouterDisabledTagsConfigSchema = z10.object({
7536
+ disabled: ToolRouterTagsParamSchema.describe("The tags to disable in the tool router session")
7537
+ }).strict();
7538
+ var ToolRouterConfigTagsSchema = z10.union([
7539
+ ToolRouterTagsParamSchema,
7540
+ ToolRouterEnabledTagsConfigSchema,
7541
+ ToolRouterDisabledTagsConfigSchema
7542
+ ]).describe("The tags to use in the tool router session");
7543
+ var ToolRouterToolsParamSchema = z10.array(z10.string()).describe("The tools to use in the tool router session");
7544
+ var ToolRouterConfigToolsSchema = z10.object({
7545
+ overrides: z10.record(
7546
+ z10.string(),
7547
+ z10.union([
7548
+ ToolRouterToolsParamSchema,
7549
+ z10.object({
7550
+ enabled: ToolRouterToolsParamSchema.describe(
7551
+ "The tools to enable in the tool router session"
7552
+ )
7553
+ }).strict(),
7554
+ z10.object({
7555
+ disabled: ToolRouterToolsParamSchema.describe(
7556
+ "The tools to disable in the tool router session"
7557
+ )
7558
+ }).strict()
7559
+ ])
7560
+ ).describe("The tools to override in the tool router session").optional(),
7561
+ tags: ToolRouterConfigTagsSchema.optional().describe("The tags to filter the tools by")
7562
+ }).strict();
7563
+ var ToolRouterCreateSessionConfigSchema = z10.object({
7564
+ tools: ToolRouterConfigToolsSchema.optional().describe(
7565
+ "The tools to use in the tool router session"
7566
+ ),
7567
+ toolkits: z10.union([
7568
+ ToolRouterToolkitsParamSchema,
7569
+ ToolRouterToolkitsDisabledConfigSchema,
7570
+ ToolRouterToolkitsEnabledConfigSchema
7571
+ ]).optional().describe("The toolkits to use in the tool router session"),
7572
+ authConfigs: z10.record(z10.string(), z10.string()).describe(
7573
+ "The auth configs to use in the tool router session. The key is the toolkit slug, the value is the auth config id."
7574
+ ).default({}),
7575
+ connectedAccounts: z10.record(z10.string(), z10.string()).describe(
7576
+ "The connected accounts to use in the tool router session. The key is the toolkit slug, the value is the connected account id."
7577
+ ).default({}),
7578
+ manageConnections: z10.union([z10.boolean(), ToolRouterConfigManageConnectionsSchema]).optional().default(true).describe(
7579
+ "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."
7580
+ ),
7581
+ execution: z10.object({
7582
+ proxyExecutionEnabled: z10.boolean().optional().describe("Whether to enable proxy execution in the tool router session"),
7583
+ timeoutSeconds: z10.number().optional().describe("The timeout in seconds for the tool router session")
7584
+ }).optional().describe("The execution config for the tool router session")
7585
+ }).partial().describe("The config for the tool router session");
7586
+ var ToolkitConnectionStateSchema = z10.object({
7587
+ slug: z10.string().describe("The slug of a toolkit"),
7588
+ name: z10.string().describe("The name of a toolkit"),
7589
+ logo: z10.string().optional().describe("The logo of a toolkit"),
7590
+ isNoAuth: z10.boolean().default(false).describe("Whether the toolkit is no auth or not"),
7591
+ connection: z10.object({
7592
+ isActive: z10.boolean().describe("Whether the connection is active or not"),
7593
+ authConfig: z10.object({
7594
+ id: z10.string().describe("The id of the auth config"),
7595
+ mode: z10.string().describe("The auth scheme used by the auth config"),
7596
+ isComposioManaged: z10.boolean().describe("Whether the auth config is managed by Composio")
7597
+ }).nullish().describe("The auth config of a toolkit"),
7598
+ connectedAccount: z10.object({
7599
+ id: z10.string().describe("The id of the connected account"),
7600
+ status: z10.string().describe("The status of the connected account")
7601
+ }).optional().describe("The connected account of a toolkit")
7602
+ })
7603
+ }).describe("The connection state of a toolkit");
7604
+ var ToolkitConnectionsDetailsSchema = z10.object({
7605
+ items: z10.array(ToolkitConnectionStateSchema),
7606
+ nextCursor: z10.string().optional(),
7607
+ totalPages: z10.number()
7333
7608
  });
7334
7609
 
7335
- // src/models/ToolRouter.experimental.ts
7610
+ // src/lib/toolRouterParams.ts
7611
+ var transformToolRouterToolsParams = (params) => {
7612
+ if (!params) {
7613
+ return void 0;
7614
+ }
7615
+ const { overrides, tags } = params;
7616
+ const toolOverrides = overrides ? Object.keys(overrides).reduce(
7617
+ (acc, key) => {
7618
+ const override = overrides[key];
7619
+ if (Array.isArray(override)) {
7620
+ acc[key] = { enabled: override };
7621
+ } else if (override !== void 0) {
7622
+ if ("enabled" in override && override.enabled) {
7623
+ acc[key] = { enabled: override.enabled };
7624
+ } else if ("disabled" in override && override.disabled) {
7625
+ acc[key] = { disabled: override.disabled };
7626
+ }
7627
+ }
7628
+ return acc;
7629
+ },
7630
+ {}
7631
+ ) : void 0;
7632
+ const tagFilters = tags ? (() => {
7633
+ if (Array.isArray(tags)) {
7634
+ return { include: tags };
7635
+ } else if ("enabled" in tags && tags.enabled) {
7636
+ return { include: tags.enabled };
7637
+ } else if ("disabled" in tags && tags.disabled) {
7638
+ return { exclude: tags.disabled };
7639
+ }
7640
+ return void 0;
7641
+ })() : void 0;
7642
+ return {
7643
+ overrides: toolOverrides,
7644
+ filters: tagFilters ? {
7645
+ tags: tagFilters
7646
+ } : void 0
7647
+ };
7648
+ };
7649
+
7650
+ // src/models/ToolRouter.ts
7336
7651
  var ToolRouter = class {
7337
- constructor(client) {
7338
- this.client = client;
7652
+ constructor(client, config) {
7339
7653
  this.client = client;
7654
+ this.config = config;
7340
7655
  telemetry.instrument(this, "ToolRouter");
7341
7656
  }
7342
7657
  /**
7343
- * Creates a new Session for the tool router
7658
+ * Creates a function that authorizes a toolkit for a user.
7659
+ * @param sessionId {string} The session id to create the authorize function for
7660
+ * @returns {ToolRouterAuthorizeFn} The authorize function
7661
+ *
7662
+ */
7663
+ createAuthorizeFn = (sessionId) => {
7664
+ const authorizeFn = async (toolkit, options) => {
7665
+ const response = await this.client.toolRouter.session.link(sessionId, {
7666
+ ...options ?? {},
7667
+ toolkit
7668
+ });
7669
+ return createConnectionRequest(
7670
+ this.client,
7671
+ response.connected_account_id,
7672
+ ConnectedAccountStatuses.INITIATED,
7673
+ response.redirect_url
7674
+ );
7675
+ };
7676
+ return authorizeFn;
7677
+ };
7678
+ /**
7679
+ *
7680
+ * @param sessionId {string} The session id to create the connections function for
7681
+ * @returns {ToolRouterConectionsFn} The connections function
7682
+ *
7683
+ * @example
7684
+ * ```typescript
7685
+ * import { Composio } from '@composio/core';
7686
+ *
7687
+ * const composio = new Composio();
7688
+ * const sessionId = 'session_123';
7689
+ *
7690
+ * const session = await composio.create(sessionId);
7691
+ * console.log(connections);
7692
+ * ```
7693
+ */
7694
+ createToolkitsFn = (sessionId) => {
7695
+ const connectionsFn = async (options) => {
7696
+ const result = await this.client.toolRouter.session.toolkits(sessionId, {
7697
+ cursor: options?.nextCursor,
7698
+ limit: options?.limit
7699
+ });
7700
+ const toolkitConnectedStates = result.items.map((item) => {
7701
+ const connectedState = transform(item).with(ToolkitConnectionStateSchema).using((item2) => ({
7702
+ slug: item2.slug,
7703
+ name: item2.name,
7704
+ logo: item2.meta.logo,
7705
+ isNoAuth: false,
7706
+ connection: {
7707
+ isActive: item2.connected_account?.status === "ACTIVE",
7708
+ authConfig: item2.connected_account && {
7709
+ id: item2.connected_account?.auth_config.id,
7710
+ mode: item2.connected_account?.auth_config.auth_scheme,
7711
+ isComposioManaged: item2.connected_account?.auth_config.is_composio_managed
7712
+ },
7713
+ connectedAccount: item2.connected_account ? {
7714
+ id: item2.connected_account.id,
7715
+ status: item2.connected_account.status
7716
+ } : void 0
7717
+ }
7718
+ }));
7719
+ return connectedState;
7720
+ });
7721
+ return {
7722
+ items: toolkitConnectedStates,
7723
+ nextCursor: result.next_cursor,
7724
+ totalPages: result.total_pages
7725
+ };
7726
+ };
7727
+ return connectionsFn;
7728
+ };
7729
+ /**
7730
+ * @internal
7731
+ * Creates a function that wraps the tools based on the provider.
7732
+ * The returned tools will be of the type the frameworks expects.
7733
+ *
7734
+ * @param userId - The user id to get the tools for
7735
+ * @param tools - The tools to wrap
7736
+ * @returns A function that wraps the tools based on the provider.
7737
+ */
7738
+ createToolsFn = (userId, toolSlugs) => {
7739
+ return async (modifiers) => {
7740
+ const ToolsModel = new Tools(this.client, this.config);
7741
+ const tools = await ToolsModel.get(
7742
+ userId,
7743
+ {
7744
+ tools: toolSlugs
7745
+ },
7746
+ modifiers
7747
+ );
7748
+ return tools;
7749
+ };
7750
+ };
7751
+ /**
7752
+ * Creates a new tool router session for a user.
7344
7753
  *
7345
7754
  * @param userId {string} The user id to create the session for
7346
- * @param routerConfig {ToolRouterConfig} The router config to use
7347
- * @returns {Promise<ToolRouterSession>} The tool router session
7755
+ * @param config {ToolRouterConfig} The config for the tool router session
7756
+ * @returns {Promise<ToolRouterSession<TToolCollection, TTool, TProvider>>} The tool router session
7348
7757
  *
7349
7758
  * @example
7350
7759
  * ```typescript
7351
- * import { Composio } form "@composio/core"
7760
+ * import { Composio } from '@composio/core';
7352
7761
  *
7353
- * const composio = new Composio()
7354
- * const userId = "xxx-ooo-xxxx"
7762
+ * const composio = new Composio();
7763
+ * const userId = 'user_123';
7355
7764
  *
7356
- * const mcpSession = await composio.experimental.toolRouter.createSession(userId, {
7357
- * toolkits: ["github", "hackernews", "slack"]
7358
- * })
7765
+ * const session = await composio.create(userId, {
7766
+ * manageConnections: true,
7767
+ * });
7359
7768
  *
7360
- * // with auth configs
7361
- * const mcpSession = await composio.experimental.toolRouter.createSession(userId, {
7362
- * toolkits: [{ toolkit: "github", authConfingId: "ac_123455344"}]
7769
+ * console.log(session.sessionId);
7770
+ * console.log(session.url);
7771
+ * console.log(session.tools());
7772
+ * console.log(session.toolkits());
7363
7773
  * ```
7364
7774
  */
7365
- async createSession(userId, routerConfig) {
7366
- const config = ToolRouterConfigSchema.safeParse(routerConfig ?? {});
7367
- if (config.error) {
7368
- throw new ValidationError("Failed to parse tool router config", {
7369
- cause: config.error
7370
- });
7371
- }
7372
- const toolkitConfig = config.data.toolkits?.map((config2) => {
7373
- if (typeof config2 === "string") {
7374
- return { toolkit: config2 };
7375
- } else {
7376
- return {
7377
- toolkit: config2.toolkit,
7378
- auth_config_id: config2.authConfigId
7379
- };
7380
- }
7381
- });
7382
- const session = await this.client.toolRouter.createSession({
7775
+ async create(userId, config) {
7776
+ const routerConfig = ToolRouterCreateSessionConfigSchema.parse(config ?? {});
7777
+ const manageConnectedAccounts = typeof routerConfig.manageConnections === "boolean" ? routerConfig.manageConnections : routerConfig.manageConnections?.enabled ?? true;
7778
+ const toolkits = Array.isArray(routerConfig.toolkits) ? { enabled: routerConfig.toolkits } : routerConfig.toolkits;
7779
+ const tools = transformToolRouterToolsParams(routerConfig.tools);
7780
+ const inferScopesFromTools = typeof routerConfig.manageConnections === "object" ? routerConfig.manageConnections.inferScopesFromTools : false;
7781
+ const payload = {
7383
7782
  user_id: userId,
7384
- config: {
7385
- toolkits: toolkitConfig,
7386
- manually_manage_connections: config.data.manuallyManageConnections
7387
- }
7388
- });
7389
- return transform(session).with(ToolRouterSessionSchema).using((raw) => ({
7390
- sessionId: raw.session_id,
7391
- url: raw.chat_session_mcp_url
7392
- }));
7783
+ toolkits,
7784
+ auth_configs: routerConfig.authConfigs,
7785
+ connected_accounts: routerConfig.connectedAccounts,
7786
+ tools,
7787
+ connections: {
7788
+ infer_scopes_from_tools: inferScopesFromTools,
7789
+ auto_manage_connections: manageConnectedAccounts,
7790
+ callback_uri: typeof routerConfig.manageConnections === "object" ? routerConfig.manageConnections.callbackUri : void 0
7791
+ },
7792
+ execution: routerConfig.execution ? {
7793
+ proxy_execution_enabled: routerConfig.execution?.proxyExecutionEnabled,
7794
+ timeout_seconds: routerConfig.execution?.timeoutSeconds
7795
+ } : void 0
7796
+ };
7797
+ const session = await this.client.toolRouter.session.create(payload);
7798
+ return {
7799
+ sessionId: session.session_id,
7800
+ mcp: {
7801
+ type: session.mcp.type,
7802
+ url: session.mcp.url
7803
+ },
7804
+ tools: this.createToolsFn(userId, session.tool_router_tools),
7805
+ authorize: this.createAuthorizeFn(session.session_id),
7806
+ toolkits: this.createToolkitsFn(session.session_id)
7807
+ };
7808
+ }
7809
+ /**
7810
+ * Use an existing session
7811
+ * @param id {string} The id of the session to use
7812
+ * @returns {Promise<ToolRouterSession<TToolCollection, TTool, TProvider>>} The tool router session
7813
+ *
7814
+ * @example
7815
+ * ```typescript
7816
+ * import { Composio } from '@composio/core';
7817
+ *
7818
+ * const composio = new Composio();
7819
+ * const id = 'session_123';
7820
+ * const session = await composio.toolRouter.use(id);
7821
+ *```
7822
+ */
7823
+ async use(id) {
7824
+ const session = await this.client.toolRouter.session.retrieve(id);
7825
+ return {
7826
+ sessionId: session.session_id,
7827
+ mcp: {
7828
+ type: session.mcp.type,
7829
+ url: session.mcp.url
7830
+ },
7831
+ tools: this.createToolsFn(session.config.user_id, session.tool_router_tools),
7832
+ authorize: this.createAuthorizeFn(session.session_id),
7833
+ toolkits: this.createToolkitsFn(session.session_id)
7834
+ };
7393
7835
  }
7394
7836
  };
7395
7837
 
@@ -7416,6 +7858,11 @@ var Composio = class _Composio {
7416
7858
  authConfigs;
7417
7859
  connectedAccounts;
7418
7860
  mcp;
7861
+ /**
7862
+ * Experimental feature, use with caution
7863
+ * @experimental
7864
+ */
7865
+ toolRouter;
7419
7866
  /**
7420
7867
  * Experimental features
7421
7868
  */
@@ -7479,21 +7926,21 @@ var Composio = class _Composio {
7479
7926
  defaultHeaders,
7480
7927
  logLevel: COMPOSIO_LOG_LEVEL
7481
7928
  });
7482
- this.tools = new Tools(this.client, this.provider, this.config);
7929
+ this.tools = new Tools(this.client, this.config);
7483
7930
  this.mcp = new MCP(this.client);
7484
7931
  this.toolkits = new Toolkits(this.client);
7485
7932
  this.triggers = new Triggers(this.client, this.config);
7486
7933
  this.authConfigs = new AuthConfigs(this.client);
7487
7934
  this.files = new Files(this.client);
7488
7935
  this.connectedAccounts = new ConnectedAccounts(this.client);
7936
+ this.toolRouter = new ToolRouter(this.client, this.config);
7489
7937
  this.experimental = {
7490
- /**
7491
- * Experimental tool router
7492
- * Helps you create a single MCP server containing all the tools with smart routing.
7493
- *
7494
- * @description Allows you to create an isolated toolRouter MCP session for a user
7495
- */
7496
- toolRouter: new ToolRouter(this.client)
7938
+ create: async (userId, routerConfig) => {
7939
+ return this.toolRouter.create(userId, routerConfig);
7940
+ },
7941
+ use: async (id) => {
7942
+ return this.toolRouter.use(id);
7943
+ }
7497
7944
  };
7498
7945
  this.deprecated = {
7499
7946
  /**
@@ -7851,6 +8298,7 @@ export {
7851
8298
  MCPServerCreateResponseSchema,
7852
8299
  MCPServerListResponseSchema,
7853
8300
  MCPServerSchema,
8301
+ MCPServerTypeSchema,
7854
8302
  MCPServerUpdateParamsSchema,
7855
8303
  MCPSingleAppServerSchema,
7856
8304
  MCPToolkitConfigSchema,
@@ -7885,15 +8333,25 @@ export {
7885
8333
  ToolListParamsSchema,
7886
8334
  ToolListResponseSchema,
7887
8335
  ToolProxyParamsSchema,
7888
- ToolRouter,
7889
- ToolRouterConfigSchema,
7890
- ToolRouterSessionSchema,
7891
- ToolRouterToolkitConfigSchema,
8336
+ ToolRouterConfigManageConnectionsSchema,
8337
+ ToolRouterConfigTagsSchema,
8338
+ ToolRouterConfigToolsSchema,
8339
+ ToolRouterCreateSessionConfigSchema,
8340
+ ToolRouterDisabledTagsConfigSchema,
8341
+ ToolRouterEnabledTagsConfigSchema,
8342
+ ToolRouterManageConnectionsConfigSchema,
8343
+ ToolRouterTagsParamSchema,
8344
+ ToolRouterToolkitsDisabledConfigSchema,
8345
+ ToolRouterToolkitsEnabledConfigSchema,
8346
+ ToolRouterToolkitsParamSchema,
8347
+ ToolRouterToolsParamSchema,
7892
8348
  ToolSchema,
7893
8349
  ToolkitAuthConfigDetailsSchema,
7894
8350
  ToolkitAuthFieldSchema,
7895
8351
  ToolkitAuthFieldsResponseSchema,
7896
8352
  ToolkitCategorySchema,
8353
+ ToolkitConnectionStateSchema,
8354
+ ToolkitConnectionsDetailsSchema,
7897
8355
  ToolkitErrorCodes,
7898
8356
  ToolkitMangedByEnumSchema,
7899
8357
  ToolkitRetrieveCategoriesResponseSchema,